From 0ca744c8454de17a9907d1b3430d1a1b9f315bd8 Mon Sep 17 00:00:00 2001 From: James Henderson Date: Thu, 31 Jan 2019 14:17:33 +0000 Subject: [PATCH] [llvm-symbolizer][test] Extract tests from llvm-symbolizer.test and simplify (#2) This is the third of a series of patches simplifying llvm-symbolizer tests. See r352752 and r352753 for the previous two. This patch splits out a number of distinct test cases from llvm-symbolizer.test into separate tests, and simplifies them in various ways including: 1) using --obj/positional arguments for the input file and addresses instead of stdin, 2) using runtime-generated inputs rather than a pre-canned binary, and 3) testing more specifically (i.e. checking only what is interesting to the behaviour changed in the original commit for that test case). This patch also removes the test case for using --obj. The tools/llvm-symbolizer/basic.s test already tests this case. Finally, this patch adds a simple test case to the demangle switch test case to show that demangling happens by default. See https://bugs.llvm.org/show_bug.cgi?id=40070#c1 for the motivation. Reviewed by: dblaikie Differential Revision: https://reviews.llvm.org/D57446 llvm-svn: 352754 --- .../DebugInfo/Inputs/llvm-symbolizer-test.c | 18 ------ llvm/test/DebugInfo/llvm-symbolizer.test | 56 +------------------ llvm/test/DebugInfo/symbolize-demangling.s | 24 ++++++++ ...ymbolize-macho-universal-unknown-arch.test | 5 ++ .../DebugInfo/symbolize-macho-universal.test | 7 +++ llvm/test/tools/llvm-symbolizer/demangle.s | 29 ++++++++++ 6 files changed, 66 insertions(+), 73 deletions(-) create mode 100644 llvm/test/DebugInfo/symbolize-demangling.s create mode 100644 llvm/test/DebugInfo/symbolize-macho-universal-unknown-arch.test create mode 100644 llvm/test/DebugInfo/symbolize-macho-universal.test create mode 100644 llvm/test/tools/llvm-symbolizer/demangle.s diff --git a/llvm/test/DebugInfo/Inputs/llvm-symbolizer-test.c b/llvm/test/DebugInfo/Inputs/llvm-symbolizer-test.c index 4c40c00c6736..e69de29bb2d1 100644 --- a/llvm/test/DebugInfo/Inputs/llvm-symbolizer-test.c +++ b/llvm/test/DebugInfo/Inputs/llvm-symbolizer-test.c @@ -1,18 +0,0 @@ -int f(int a, int b) { - return a + b; -} - -int g(int a) { - return a + 1; -} - - -int main() { - return f(2, g(2)); -} - -// Built with Clang 3.3: -// $ mkdir -p /tmp/dbginfo -// $ cp llvm-symbolizer-test.c /tmp/dbginfo -// $ cd /tmp/dbginfo -// $ clang -g llvm-symbolizer-test.c -o diff --git a/llvm/test/DebugInfo/llvm-symbolizer.test b/llvm/test/DebugInfo/llvm-symbolizer.test index ff39ccc1c490..cbd15859327d 100644 --- a/llvm/test/DebugInfo/llvm-symbolizer.test +++ b/llvm/test/DebugInfo/llvm-symbolizer.test @@ -15,13 +15,10 @@ RUN: cp "%p/Inputs/dwarfdump-test3.elf-x86-64-space" "%t/dwarfdump-test3.elf-x86 RUN: echo "\"%t/dwarfdump-test3.elf-x86-64 space\" 0x640" >> %t.input RUN: echo "\"%t/dwarfdump-test3.elf-x86-64 space\" 0x633" >> %t.input RUN: echo "\"%t/dwarfdump-test3.elf-x86-64 space\" 0x62d" >> %t.input -RUN: echo "%p/Inputs/macho-universal 0x1f84" >> %t.input -RUN: echo "%p/Inputs/macho-universal:i386 0x1f67" >> %t.input -RUN: echo "%p/Inputs/macho-universal:x86_64 0x100000f05" >> %t.input RUN: cd %t RUN: llvm-symbolizer --functions=linkage --inlining --demangle=false \ -RUN: --default-arch=i386 < %t.input | FileCheck --check-prefix=CHECK --check-prefix=SPLIT --check-prefix=DWO %s +RUN: < %t.input | FileCheck --check-prefix=CHECK --check-prefix=SPLIT --check-prefix=DWO %s CHECK: main CHECK-NEXT: /tmp/dbginfo{{[/\\]}}dwarfdump-test.cc:16 @@ -76,58 +73,7 @@ CHECK-NEXT: /tmp/include{{[/\\]}}dwarfdump-test3-decl.h:7 CHECK: _Z3do2v CHECK-NEXT: /tmp/dbginfo{{[/\\]}}include{{[/\\]}}dwarfdump-test3-decl2.h:1 -CHECK: main -CHECK: _Z3inci -CHECK: _Z3inci - RUN: echo "unexisting-file 0x1234" > %t.input2 RUN: llvm-symbolizer < %t.input2 2>&1 | FileCheck %s --check-prefix=MISSING-FILE MISSING-FILE: LLVMSymbolizer: error reading file: {{[Nn]}}o such file or directory - -RUN: echo "%p/Inputs/macho-universal 0x1f84" > %t.input3 -RUN: llvm-symbolizer < %t.input3 | FileCheck %s --check-prefix=UNKNOWN-ARCH - -UNKNOWN-ARCH-NOT: main -UNKNOWN-ARCH: ?? -UNKNOWN-ARCH-NOT: main - -RUN: echo "0x40113f" > %t.input4 -RUN: echo "0x401020" >> %t.input4 -RUN: llvm-symbolizer --obj %p/Inputs/dwarfdump-test.elf-x86-64 < %t.input4 \ -RUN: | FileCheck %s --check-prefix=BINARY - -BINARY: main -BINARY-NEXT: /tmp/dbginfo{{[/\\]}}dwarfdump-test.cc:16 -BINARY: _start - -RUN: echo "0x401140" > %t.input5 -RUN: echo "0x401020" >> %t.input5 -RUN: echo "0x401120" >> %t.input5 -RUN: llvm-symbolizer --obj %p/Inputs/llvm-symbolizer-test.elf-x86-64 < %t.input5 \ -RUN: | FileCheck %s --check-prefix=BINARY_C - -BINARY_C: main -BINARY_C-NEXT: /tmp/dbginfo{{[/\\]}}llvm-symbolizer-test.c:10 -BINARY_C: _start -BINARY_C: {{g$}} - -; Check that the last of --demangle and --no-demangle wins. -RUN: echo "%p/Inputs/dwarfdump-test4.elf-x86-64 0x62c" > %t.input7 -RUN: llvm-symbolizer --demangle < %t.input7 \ -RUN: | FileCheck %s --check-prefix=DEMANGLED_FUNCTION_NAME -RUN: llvm-symbolizer -C < %t.input7 \ -RUN: | FileCheck %s --check-prefix=DEMANGLED_FUNCTION_NAME -RUN: llvm-symbolizer --no-demangle < %t.input7 \ -RUN: | FileCheck %s --check-prefix=MANGLED_FUNCTION_NAME -RUN: llvm-symbolizer --demangle --no-demangle < %t.input7 \ -RUN: | FileCheck %s --check-prefix=MANGLED_FUNCTION_NAME -RUN: llvm-symbolizer -C --no-demangle < %t.input7 \ -RUN: | FileCheck %s --check-prefix=MANGLED_FUNCTION_NAME -RUN: llvm-symbolizer --no-demangle --demangle < %t.input7 \ -RUN: | FileCheck %s --check-prefix=DEMANGLED_FUNCTION_NAME -RUN: llvm-symbolizer --no-demangle -C < %t.input7 \ -RUN: | FileCheck %s --check-prefix=DEMANGLED_FUNCTION_NAME - -MANGLED_FUNCTION_NAME: _Z1cv -DEMANGLED_FUNCTION_NAME: c() diff --git a/llvm/test/DebugInfo/symbolize-demangling.s b/llvm/test/DebugInfo/symbolize-demangling.s new file mode 100644 index 000000000000..acd769a286ff --- /dev/null +++ b/llvm/test/DebugInfo/symbolize-demangling.s @@ -0,0 +1,24 @@ +# REQUIRES: x86-registered-target + +# RUN: llvm-mc --filetype=obj --triple=x86_64-pc-linux %s -o %t.o -g + +# RUN: llvm-symbolizer --obj=%t.o 0 1 2 | FileCheck %s + +# CHECK: f() +# CHECK-NEXT: symbolize-demangling.s:20 +# CHECK-EMPTY: +# CHECK-NEXT: {{^g$}} +# CHECK-NEXT: symbolize-demangling.s:22 +# CHECK-EMPTY: +# CHECK-NEXT: {{^baz$}} +# CHECK-NEXT: symbolize-demangling.s:24 + +.type _Z1fv,@function +.type g,@function +.type baz,@function +_Z1fv: + nop +g: + nop +baz: + nop diff --git a/llvm/test/DebugInfo/symbolize-macho-universal-unknown-arch.test b/llvm/test/DebugInfo/symbolize-macho-universal-unknown-arch.test new file mode 100644 index 000000000000..744a0d3e5492 --- /dev/null +++ b/llvm/test/DebugInfo/symbolize-macho-universal-unknown-arch.test @@ -0,0 +1,5 @@ +RUN: llvm-symbolizer --obj=%p/Inputs/macho-universal 0x1f84 | FileCheck %s + +CHECK-NOT: main +CHECK: ?? +CHECK-NOT: main diff --git a/llvm/test/DebugInfo/symbolize-macho-universal.test b/llvm/test/DebugInfo/symbolize-macho-universal.test new file mode 100644 index 000000000000..f775f68f93a7 --- /dev/null +++ b/llvm/test/DebugInfo/symbolize-macho-universal.test @@ -0,0 +1,7 @@ +RUN: llvm-symbolizer --no-demangle --default-arch=i386 --obj=%p/Inputs/macho-universal 0x1f84 | FileCheck %s --check-prefix=DEFAULT +RUN: llvm-symbolizer --no-demangle --obj=%p/Inputs/macho-universal:i386 0x1f67 | FileCheck %s --check-prefix=I386 +RUN: llvm-symbolizer --no-demangle --obj=%p/Inputs/macho-universal:x86_64 0x100000f05 | FileCheck %s --check-prefix=X86-64 + +DEFAULT: main +I386: _Z3inci +X86-64: _Z3inci diff --git a/llvm/test/tools/llvm-symbolizer/demangle.s b/llvm/test/tools/llvm-symbolizer/demangle.s new file mode 100644 index 000000000000..744e78eb8aa1 --- /dev/null +++ b/llvm/test/tools/llvm-symbolizer/demangle.s @@ -0,0 +1,29 @@ +# REQUIRES: x86-registered-target + +# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t.o -g + +.type _Z1cv,@function +_Z1cv: + nop + +# Check the default is to demangle and that the last of --demangle and +# --no-demangle wins. +# RUN: llvm-symbolizer --obj %t.o 0 \ +# RUN: | FileCheck %s --check-prefix=DEMANGLED_FUNCTION_NAME +# RUN: llvm-symbolizer --demangle --obj %t.o 0 \ +# RUN: | FileCheck %s --check-prefix=DEMANGLED_FUNCTION_NAME +# RUN: llvm-symbolizer -C --obj %t.o 0 \ +# RUN: | FileCheck %s --check-prefix=DEMANGLED_FUNCTION_NAME +# RUN: llvm-symbolizer --no-demangle --obj %t.o 0 \ +# RUN: | FileCheck %s --check-prefix=MANGLED_FUNCTION_NAME +# RUN: llvm-symbolizer --demangle --no-demangle --obj %t.o 0 \ +# RUN: | FileCheck %s --check-prefix=MANGLED_FUNCTION_NAME +# RUN: llvm-symbolizer -C --no-demangle --obj %t.o 0 \ +# RUN: | FileCheck %s --check-prefix=MANGLED_FUNCTION_NAME +# RUN: llvm-symbolizer --no-demangle --demangle --obj %t.o 0 \ +# RUN: | FileCheck %s --check-prefix=DEMANGLED_FUNCTION_NAME +# RUN: llvm-symbolizer --no-demangle -C --obj %t.o 0 \ +# RUN: | FileCheck %s --check-prefix=DEMANGLED_FUNCTION_NAME + +# MANGLED_FUNCTION_NAME: _Z1cv +# DEMANGLED_FUNCTION_NAME: c()