From e51b9e42b68c243dbc9b472f7c64c2c0fe821311 Mon Sep 17 00:00:00 2001 From: James Henderson Date: Thu, 23 May 2019 10:17:10 +0000 Subject: [PATCH] [llvm-objdump][test] Improve testing of some switches #2 This patch focuses on adding additional testing for the --source switch. For reference, the source-interleave-x86_64.ll test file has been split into two parts - the input (shared with the other tests) and the test itself. Reviewed by: MaskRay, rupprecht, grimar Differential Revision: https://reviews.llvm.org/D61996 llvm-svn: 361479 --- .../source-interleave.ll} | 19 ++-------- .../X86/source-interleave-invalid-source.test | 16 +++++++++ .../X86/source-interleave-missing-source.test | 15 ++++++++ .../X86/source-interleave-no-debug-info.test | 13 +++++++ .../X86/source-interleave-relative-paths.test | 36 +++++++++++++++++++ .../X86/source-interleave-x86_64.test | 17 +++++++++ 6 files changed, 100 insertions(+), 16 deletions(-) rename llvm/test/tools/llvm-objdump/X86/{source-interleave-x86_64.ll => Inputs/source-interleave.ll} (84%) create mode 100644 llvm/test/tools/llvm-objdump/X86/source-interleave-invalid-source.test create mode 100644 llvm/test/tools/llvm-objdump/X86/source-interleave-missing-source.test create mode 100644 llvm/test/tools/llvm-objdump/X86/source-interleave-no-debug-info.test create mode 100644 llvm/test/tools/llvm-objdump/X86/source-interleave-relative-paths.test create mode 100644 llvm/test/tools/llvm-objdump/X86/source-interleave-x86_64.test diff --git a/llvm/test/tools/llvm-objdump/X86/source-interleave-x86_64.ll b/llvm/test/tools/llvm-objdump/X86/Inputs/source-interleave.ll similarity index 84% rename from llvm/test/tools/llvm-objdump/X86/source-interleave-x86_64.ll rename to llvm/test/tools/llvm-objdump/X86/Inputs/source-interleave.ll index 24a212028bf7..1db42f5aaa8c 100644 --- a/llvm/test/tools/llvm-objdump/X86/source-interleave-x86_64.ll +++ b/llvm/test/tools/llvm-objdump/X86/Inputs/source-interleave.ll @@ -1,13 +1,6 @@ -; RUN: sed -e "s,SRC_COMPDIR,%/p/Inputs,g" %s > %t.ll -; RUN: llc -o %t.o -filetype=obj -mtriple=x86_64-pc-linux %t.ll -; RUN: llvm-objdump -d -l %t.o >%t0 -; RUN: llvm-objdump -dl %t.o >%t1 -; RUN: llvm-objdump -d -S %t.o >%t2 -; RUN: llvm-objdump -dS %t.o >%t3 -; RUN: cmp %t0 %t1 -; RUN: cmp %t2 %t3 -; RUN: FileCheck --check-prefix=LINES %t.ll < %t0 -; RUN: FileCheck --check-prefix=SOURCE --strict-whitespace %t.ll < %t2 +; NOTE: To be able to use this file as an input, the string SRC_CMPDIR needs +; replacing with a directory path by using sed or similar. + ; ModuleID = 'source-interleave-x86_64.bc' source_filename = "source-interleave-x86_64.c" target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128" @@ -71,9 +64,3 @@ attributes #1 = { nounwind readnone } !21 = !DILocation(line: 8, column: 15, scope: !14) !22 = !DILocation(line: 8, column: 13, scope: !14) !23 = !DILocation(line: 8, column: 3, scope: !14) -; LINES: main: -; LINES-NEXT: ; {{[ -\(\)_A-Za-z0-9.\\/:]+}}source-interleave-x86_64.c:6 - -; SOURCE: main: -; SOURCE-NEXT: ; int main() { -; SOURCE: ; int *b = &a; diff --git a/llvm/test/tools/llvm-objdump/X86/source-interleave-invalid-source.test b/llvm/test/tools/llvm-objdump/X86/source-interleave-invalid-source.test new file mode 100644 index 000000000000..e958173d16e9 --- /dev/null +++ b/llvm/test/tools/llvm-objdump/X86/source-interleave-invalid-source.test @@ -0,0 +1,16 @@ +## Test llvm-objdump's --source behaviour when a line number is greater than the +## file length. + +# RUN: sed -e "s,SRC_COMPDIR,%/p/Inputs,g" %p/Inputs/source-interleave.ll > %t.ll +# RUN: sed -e "s,line: 7,line: 9999,g" %t.ll > %t2.ll + +# RUN: llc -o %t.o -filetype=obj -mtriple=x86_64-pc-linux %t.ll +# RUN: llc -o %t2.o -filetype=obj -mtriple=x86_64-pc-linux %t2.ll + +# RUN: llvm-objdump --source %t.o | FileCheck %s --check-prefixes=CHECK,GOOD +# RUN: llvm-objdump --source %t2.o | FileCheck %s --implicit-check-not="int *b = &a;" + +# CHECK: main: +# CHECK-NEXT: ; int main() { +# GOOD: ; int *b = &a; +# CHECK: ; return *b + foo(); diff --git a/llvm/test/tools/llvm-objdump/X86/source-interleave-missing-source.test b/llvm/test/tools/llvm-objdump/X86/source-interleave-missing-source.test new file mode 100644 index 000000000000..166caeb41b50 --- /dev/null +++ b/llvm/test/tools/llvm-objdump/X86/source-interleave-missing-source.test @@ -0,0 +1,15 @@ +## Test that if the source cannot be found that disassembly is still printed, +## and that no source is printed. + +# RUN: sed -e "s,SRC_COMPDIR,%/t,g" %p/Inputs/source-interleave.ll > %t.ll +# RUN: sed -e "s,SRC_COMPDIR,%/p/Inputs,g" %p/Inputs/source-interleave.ll > %t2.ll + +# RUN: llc -o %t.o -filetype=obj -mtriple=x86_64-pc-linux %t.ll +# RUN: llc -o %t2.o -filetype=obj -mtriple=x86_64-pc-linux %t2.ll + +# RUN: llvm-objdump --source %t.o | FileCheck %s --implicit-check-not=main +# RUN: llvm-objdump --source %t2.o | FileCheck %s --check-prefixes=CHECK,SOURCE + +# CHECK: 0000000000000010 main: +# SOURCE-NEXT: ; int main() { +# CHECK-NEXT: 10: 55 pushq %rbp diff --git a/llvm/test/tools/llvm-objdump/X86/source-interleave-no-debug-info.test b/llvm/test/tools/llvm-objdump/X86/source-interleave-no-debug-info.test new file mode 100644 index 000000000000..4a0a34a9eae0 --- /dev/null +++ b/llvm/test/tools/llvm-objdump/X86/source-interleave-no-debug-info.test @@ -0,0 +1,13 @@ +## Test that if an object has no debug information, only the disassembly is +## printed when --source is specified. + +# RUN: sed -e "s,SRC_COMPDIR,%/p/Inputs,g" %p/Inputs/source-interleave.ll > %t.ll +# RUN: llc -o %t.o -filetype=obj -mtriple=x86_64-pc-linux %t.ll +# RUN: llvm-objcopy --strip-debug %t.o %t2.o + +# RUN: llvm-objdump --source %t.o | FileCheck %s --check-prefixes=CHECK,SOURCE +# RUN: llvm-objdump --source %t2.o | FileCheck %s --implicit-check-not=main + +# CHECK: 0000000000000010 main: +# SOURCE-NEXT: ; int main() { +# CHECK-NEXT: 10: 55 pushq %rbp diff --git a/llvm/test/tools/llvm-objdump/X86/source-interleave-relative-paths.test b/llvm/test/tools/llvm-objdump/X86/source-interleave-relative-paths.test new file mode 100644 index 000000000000..f9c69dfc0c06 --- /dev/null +++ b/llvm/test/tools/llvm-objdump/X86/source-interleave-relative-paths.test @@ -0,0 +1,36 @@ +## Test that llvm-objdump prints source and disassembly for relative directory +## paths for appropriate working directories. We also test that when the directory +## string is empty the behaviour is the same as the current working directory. + +# RUN: mkdir -p %t/a/b +# RUN: cp %p/Inputs/source-interleave-x86_64.c %t/a/source-interleave-x86_64.c + +# RUN: sed -e "s,SRC_COMPDIR,a,g" %p/Inputs/source-interleave.ll > %t.ll +# RUN: sed -e "s,SRC_COMPDIR,,g" %p/Inputs/source-interleave.ll > %t2.ll +# RUN: sed -e "s,SRC_COMPDIR,.,g" %p/Inputs/source-interleave.ll > %t3.ll +# RUN: sed -e "s,SRC_COMPDIR,..,g" %p/Inputs/source-interleave.ll > %t4.ll + +# RUN: llc -o %t/a/a.o -filetype=obj -mtriple=x86_64-pc-linux %t.ll +# RUN: llc -o %t/a/b.o -filetype=obj -mtriple=x86_64-pc-linux %t2.ll +# RUN: llc -o %t/a/c.o -filetype=obj -mtriple=x86_64-pc-linux %t3.ll +# RUN: llc -o %t/a/d.o -filetype=obj -mtriple=x86_64-pc-linux %t4.ll + +# RUN: cd %t +# RUN: llvm-objdump --source a/a.o | FileCheck %s --check-prefixes=CHECK,SOURCE +# RUN: llvm-objdump --source a/b.o | FileCheck %s --implicit-check-not=main +# RUN: llvm-objdump --source a/c.o | FileCheck %s --implicit-check-not=main +# RUN: llvm-objdump --source a/d.o | FileCheck %s --implicit-check-not=main +# RUN: cd a +# RUN: llvm-objdump --source a.o | FileCheck %s --implicit-check-not=main +# RUN: llvm-objdump --source b.o | FileCheck %s --check-prefixes=CHECK,SOURCE +# RUN: llvm-objdump --source c.o | FileCheck %s --check-prefixes=CHECK,SOURCE +# RUN: llvm-objdump --source d.o | FileCheck %s --implicit-check-not=main +# RUN: cd b +# RUN: llvm-objdump --source ../a.o | FileCheck %s --implicit-check-not=main +# RUN: llvm-objdump --source ../b.o | FileCheck %s --implicit-check-not=main +# RUN: llvm-objdump --source ../c.o | FileCheck %s --implicit-check-not=main +# RUN: llvm-objdump --source ../d.o | FileCheck %s --check-prefixes=CHECK,SOURCE + +# CHECK: 0000000000000010 main: +# SOURCE-NEXT: ; int main() { +# CHECK-NEXT: 10: 55 pushq %rbp diff --git a/llvm/test/tools/llvm-objdump/X86/source-interleave-x86_64.test b/llvm/test/tools/llvm-objdump/X86/source-interleave-x86_64.test new file mode 100644 index 000000000000..63a6c0571802 --- /dev/null +++ b/llvm/test/tools/llvm-objdump/X86/source-interleave-x86_64.test @@ -0,0 +1,17 @@ +# RUN: sed -e "s,SRC_COMPDIR,%/p/Inputs,g" %p/Inputs/source-interleave.ll > %t.ll +# RUN: llc -o %t.o -filetype=obj -mtriple=x86_64-pc-linux %t.ll +# RUN: llvm-objdump -d -l %t.o >%t0 +# RUN: llvm-objdump -dl %t.o >%t1 +# RUN: llvm-objdump -d -S %t.o >%t2 +# RUN: llvm-objdump -dS %t.o >%t3 +# RUN: cmp %t0 %t1 +# RUN: cmp %t2 %t3 +# RUN: FileCheck --check-prefix=LINES %s < %t0 +# RUN: FileCheck --check-prefix=SOURCE --strict-whitespace %s < %t2 + +# LINES: main: +# LINES-NEXT: ; {{[ -\(\)_A-Za-z0-9.\\/:]+}}source-interleave-x86_64.c:6 + +# SOURCE: main: +# SOURCE-NEXT: ; int main() { +# SOURCE: ; int *b = &a;