[llvm] 37c8980 - [llvm-nm][test] Add additional test coverage for llvm-nm options

James Henderson via llvm-commits llvm-commits at lists.llvm.org
Mon Feb 15 05:57:41 PST 2021


Author: James Henderson
Date: 2021-02-15T13:54:08Z
New Revision: 37c89803d860c6dd954cda1480dae6917f006972

URL: https://github.com/llvm/llvm-project/commit/37c89803d860c6dd954cda1480dae6917f006972
DIFF: https://github.com/llvm/llvm-project/commit/37c89803d860c6dd954cda1480dae6917f006972.diff

LOG: [llvm-nm][test] Add additional test coverage for llvm-nm options

Some of these options have a degree of incidental coverage, or are for
Mach-O only. This patch adds dedicated ELF (where applicable) coverage.

Differential Revision: https://reviews.llvm.org/D96602

Reviewed by: rupprecht, Higuoxing

Added: 
    llvm/test/tools/llvm-nm/X86/bitcode.test
    llvm/test/tools/llvm-nm/defined-only.test
    llvm/test/tools/llvm-nm/format-bsd.test
    llvm/test/tools/llvm-nm/just-symbol-name.test
    llvm/test/tools/llvm-nm/reverse-sort.test

Modified: 
    

Removed: 
    


################################################################################
diff  --git a/llvm/test/tools/llvm-nm/X86/bitcode.test b/llvm/test/tools/llvm-nm/X86/bitcode.test
new file mode 100644
index 000000000000..42826c9f9c96
--- /dev/null
+++ b/llvm/test/tools/llvm-nm/X86/bitcode.test
@@ -0,0 +1,16 @@
+;; Show that llvm-nm prints dashes for the symbol value of symbols in values.
+;; Also show that the --no-llvm-bc option prevents loading bitcode files.
+; RUN: llvm-as %s -o %t.bc
+
+; RUN: llvm-nm %t.bc | FileCheck %s --check-prefix=RECOGNISED
+; RUN: not llvm-nm %t.bc --no-llvm-bc 2>&1 | FileCheck %s --check-prefix=UNRECOGNISED -DFILE=%t.bc
+
+; RECOGNISED: ---------------- T foo
+; UNRECOGNISED: error: [[FILE]]: The file was not recognized as a valid object file
+
+target triple = "x86_64-unknown-linux-gnu"
+target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
+
+define void @foo() {
+  ret void
+}

diff  --git a/llvm/test/tools/llvm-nm/defined-only.test b/llvm/test/tools/llvm-nm/defined-only.test
new file mode 100644
index 000000000000..e36297a53e02
--- /dev/null
+++ b/llvm/test/tools/llvm-nm/defined-only.test
@@ -0,0 +1,27 @@
+## Show that the --defined-only option omits undefined symbols.
+
+# RUN: yaml2obj %s -o %t.o
+# RUN: llvm-nm %t.o --defined-only > %t.defonly.txt
+# RUN: llvm-nm %t.o -U > %t.U.txt
+
+# RUN: cmp %t.defonly.txt %t.U.txt
+
+# RUN: FileCheck %s --input-file=%t.defonly.txt --implicit-check-not={{.}}
+
+# CHECK: 0000000000000000 T defined
+
+--- !ELF
+FileHeader:
+  Class:   ELFCLASS64
+  Data:    ELFDATA2LSB
+  Type:    ET_REL
+Sections:
+  - Name:  .text
+    Type:  SHT_PROGBITS
+    Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
+Symbols:
+  - Name:    defined
+    Section: .text
+    Binding: STB_GLOBAL
+  - Name:    undefined
+    Binding: STB_GLOBAL

diff  --git a/llvm/test/tools/llvm-nm/format-bsd.test b/llvm/test/tools/llvm-nm/format-bsd.test
new file mode 100644
index 000000000000..d04ecdc4b25e
--- /dev/null
+++ b/llvm/test/tools/llvm-nm/format-bsd.test
@@ -0,0 +1,35 @@
+## --format-bsd is the default output format of llvm-nm. Show that the default
+## and bsd output (including its aliases) match to confirm this.
+
+# RUN: yaml2obj %s -o %t.o
+# RUN: llvm-nm %t.o --format=bsd > %t.formatbsd.txt
+# RUN: llvm-nm %t.o -f=bsd > %t.fbsd.txt
+# RUN: llvm-nm %t.o -B > %t.b.txt
+# RUN: llvm-nm %t.o > %t.default.txt
+
+# RUN: cmp %t.formatbsd.txt %t.default.txt
+# RUN: cmp %t.formatbsd.txt %t.fbsd.txt
+# RUN: cmp %t.formatbsd.txt %t.b.txt
+
+## Sanity check that some output is actually printed.
+# RUN: FileCheck %s --input-file=%t.default.txt
+
+# CHECK:      0000000000000000 T sym1
+# CHECK-NEXT: 0000000000000000 W sym2
+
+--- !ELF
+FileHeader:
+  Class:   ELFCLASS64
+  Data:    ELFDATA2LSB
+  Type:    ET_REL
+Sections:
+  - Name:  .text
+    Type:  SHT_PROGBITS
+    Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
+Symbols:
+  - Name:    sym1
+    Section: .text
+    Binding: STB_GLOBAL
+  - Name:    sym2
+    Section: .text
+    Binding: STB_WEAK

diff  --git a/llvm/test/tools/llvm-nm/just-symbol-name.test b/llvm/test/tools/llvm-nm/just-symbol-name.test
new file mode 100644
index 000000000000..85be79a6a240
--- /dev/null
+++ b/llvm/test/tools/llvm-nm/just-symbol-name.test
@@ -0,0 +1,38 @@
+## Show that the -j/--just-symbol-name prints only the the symbol name (except
+## in posix output).
+
+# RUN: yaml2obj %s -o %t.o
+
+# RUN: llvm-nm --just-symbol-name %t.o > %t.bsd.txt
+# RUN: llvm-nm -j %t.o > %t.j.txt
+# RUN: cmp %t.bsd.txt %t.j.txt
+
+# RUN: FileCheck %s --input-file=%t.bsd.txt --implicit-check-not={{.}} --check-prefix=COMMON
+# RUN: llvm-nm -j %t.o --format=sysv | \
+# RUN:   FileCheck %s --implicit-check-not={{.}} --check-prefixes=COMMON,SYSV -DFILE=%t.o
+# RUN: llvm-nm -j %t.o --format=posix | FileCheck %s --implicit-check-not={{.}} --check-prefix=POSIX
+
+# SYSV:        Symbols from [[FILE]]:
+# SYSV-EMPTY:
+# SYSV-NEXT:   Name Value Class Type Size Line Section
+# COMMON:      {{^}}defined{{$}}
+# COMMON-NEXT: {{^}}undefined{{$}}
+
+# POSIX:      defined T 0 0
+# POSIX-NEXT: undefined U 0 0
+
+--- !ELF
+FileHeader:
+  Class:   ELFCLASS64
+  Data:    ELFDATA2LSB
+  Type:    ET_REL
+Sections:
+  - Name:  .text
+    Type:  SHT_PROGBITS
+    Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
+Symbols:
+  - Name:    defined
+    Section: .text
+    Binding: STB_GLOBAL
+  - Name:    undefined
+    Binding: STB_GLOBAL

diff  --git a/llvm/test/tools/llvm-nm/reverse-sort.test b/llvm/test/tools/llvm-nm/reverse-sort.test
new file mode 100644
index 000000000000..6cbf6745a049
--- /dev/null
+++ b/llvm/test/tools/llvm-nm/reverse-sort.test
@@ -0,0 +1,37 @@
+## Show that the --reverse-sort option reverses the selected sort order.
+# RUN: yaml2obj %s -o %t.o
+# RUN: llvm-nm %t.o --reverse-sort | FileCheck %s --check-prefix=SORTED
+# RUN: llvm-nm %t.o --reverse-sort --numeric-sort | FileCheck %s --check-prefix=SORTED
+# RUN: llvm-nm %t.o --reverse-sort --size-sort | FileCheck %s --check-prefix=SORTED
+# RUN: llvm-nm %t.o --reverse-sort --no-sort | FileCheck %s --check-prefix=UNSORTED
+
+# SORTED:      third
+# SORTED-NEXT: second
+# SORTED-NEXT: first
+
+# UNSORTED:      second
+# UNSORTED-NEXT: third
+# UNSORTED-NEXT: first
+
+--- !ELF
+FileHeader:
+  Class:   ELFCLASS64
+  Data:    ELFDATA2LSB
+  Type:    ET_REL
+Sections:
+  - Name:  .text
+    Type:  SHT_PROGBITS
+    Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
+Symbols:
+  - Name:    second
+    Section: .text
+    Value:   2
+    Size:    2
+  - Name:    third
+    Section: .text
+    Value:   3
+    Size:    3
+  - Name:    first
+    Section: .text
+    Value:   1
+    Size:    1


        


More information about the llvm-commits mailing list