Skip to content

Commit

Permalink
[llvm-objdump][test] Improve testing of some switches #2
Browse files Browse the repository at this point in the history
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
  • Loading branch information
jh7370 committed May 23, 2019
1 parent f5d9d23 commit e51b9e4
Show file tree
Hide file tree
Showing 6 changed files with 100 additions and 16 deletions.
Original file line number Diff line number Diff line change
@@ -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"
Expand Down Expand Up @@ -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;
Original file line number Diff line number Diff line change
@@ -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();
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
17 changes: 17 additions & 0 deletions llvm/test/tools/llvm-objdump/X86/source-interleave-x86_64.test
Original file line number Diff line number Diff line change
@@ -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;

0 comments on commit e51b9e4

Please sign in to comment.