1 #!/bin/sh 2 # 3 # Copyright (c) International Business Machines Corp., 2000 4 # 06/01 Robbie Williamson (robbiew (at] us.ibm.com) 5 # Copyright (c) 2016 Cyril Hrubis <chrubis (at] suse.cz> 6 # 7 # This program is free software; you can redistribute it and/or modify 8 # it under the terms of the GNU General Public License as published by 9 # the Free Software Foundation; either version 2 of the License, or 10 # (at your option) any later version. 11 # 12 # This program is distributed in the hope that it will be useful, 13 # but WITHOUT ANY WARRANTY; without even the implied warranty of 14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See 15 # the GNU General Public License for more details. 16 # 17 # You should have received a copy of the GNU General Public License 18 # along with this program; if not, write to the Free Software 19 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 20 # 21 #--------------------------------------------------------------------------- 22 # 23 # Tests the basic functionality of the `nm` command. 24 # 25 NM=${NM:=nm} 26 27 TST_CNT=7 28 TST_TESTFUNC=test 29 TST_SETUP=setup 30 TST_NEEDS_TMPDIR=1 31 TST_NEEDS_CMDS="$NM" 32 . tst_test.sh 33 34 setup() 35 { 36 ROD cp "$TST_DATAROOT/lib.a" "." 37 ROD mkdir "dir" 38 ROD cp "$TST_DATAROOT/lib.a" "dir/" 39 } 40 41 test1() 42 { 43 EXPECT_PASS $NM -f posix -A "lib.a" \> nm.out 44 45 if grep -q "lib.a\[f2.o\]\:" nm.out; then 46 tst_res TPASS "Got correct listing" 47 else 48 tst_res TFAIL "Got incorrect listing" 49 cat nm.out 50 fi 51 52 EXPECT_PASS $NM -f posix -A "dir/lib.a" \> nm.out 53 54 if grep -q "dir/lib.a\[f2.o\]\:" nm.out; then 55 tst_res TPASS "Got correct listing" 56 else 57 tst_res TFAIL "Got incorrect listing" 58 cat nm.out 59 fi 60 } 61 62 test2() 63 { 64 EXPECT_PASS $NM -f posix -g $TST_DATAROOT/f1 \> nm.out 65 66 if grep -q "\w [a,b,d,f,t]" nm.out; then 67 tst_res TFAIL "Got internal symbols with -g" 68 cat nm.out 69 else 70 tst_res TPASS "Got only external symbols with -g" 71 fi 72 } 73 74 test3() 75 { 76 EXPECT_PASS $NM -f posix -t o $TST_DATAROOT/f1 \> nm.out 77 78 if awk '{print $3}' nm.out | grep -q "[8-9a-f]"; then 79 tst_res TFAIL "Got non-octal symbol values with -f" 80 cat nm.out 81 else 82 tst_res TPASS "Got an octal symbol values with -f" 83 fi 84 } 85 86 test4() 87 { 88 EXPECT_PASS $NM -f sysv $TST_DATAROOT/f1 \> nm.out 89 90 if grep -q "Name" nm.out; then 91 tst_res TPASS "Got SysV format with -f sysv" 92 else 93 tst_res TFAIL "Got wrong format with -f sysv" 94 cat nm.out 95 fi 96 } 97 98 test5() 99 { 100 EXPECT_PASS $NM -f bsd $TST_DATAROOT/f1 \> nm_bsd.out 101 EXPECT_PASS $NM -f posix $TST_DATAROOT/f1 \> nm_posix.out 102 103 ROD awk '{print $3 $2 $1}' nm_bsd.out \> nm1.out 104 ROD awk '{print $1 $2 $3}' nm_posix.out \> nm2.out 105 106 if diff nm1.out nm2.out > /dev/null; then 107 tst_res TPASS "Got BSD format with -f bsd" 108 else 109 tst_res TFAIL "Got wrong format with -f bsd" 110 cat nm_bsd.out 111 fi 112 } 113 114 test6() 115 { 116 EXPECT_PASS $NM -f sysv -u $TST_DATAROOT/f1 \> nm.out 117 118 if grep -q "Undefined symbols from" nm.out; then 119 tst_res TPASS "Got undefined symbols with -u" 120 else 121 tst_res TFAIL "Haven't got undefined symbols with -u" 122 cat nm.out 123 fi 124 } 125 126 test7() 127 { 128 EXPECT_PASS $NM -s $TST_DATAROOT/lib.a \> nm.out 129 130 if grep -q "index" nm.out; then 131 tst_res TPASS "Got index with -s" 132 else 133 tst_res TFAIL "Haven't got index with -s" 134 fi 135 } 136 137 tst_run 138