1#!/bin/sh 2# SPDX-License-Identifier: GPL-2.0-or-later 3# Copyright (c) International Business Machines Corp., 2000 4# Copyright (c) 2016 Cyril Hrubis <chrubis@suse.cz> 5# Author: Robbie Williamson <robbiew@us.ibm.com> 6# 7# Tests the basic functionality of the `nm` command. 8 9NM=${NM:=nm} 10 11TST_CNT=7 12TST_TESTFUNC=test 13TST_SETUP=setup 14TST_NEEDS_TMPDIR=1 15TST_NEEDS_CMDS="$NM" 16 17setup() 18{ 19 ROD cp "$TST_DATAROOT/lib.a" "." 20 ROD mkdir "dir" 21 ROD cp "$TST_DATAROOT/lib.a" "dir/" 22} 23 24test1() 25{ 26 EXPECT_PASS $NM -f posix -A "lib.a" \> nm.out 27 28 if grep -q "lib.a\[f2.o\]\:" nm.out; then 29 tst_res TPASS "Got correct listing" 30 else 31 tst_res TFAIL "Got incorrect listing" 32 cat nm.out 33 fi 34 35 EXPECT_PASS $NM -f posix -A "dir/lib.a" \> nm.out 36 37 if grep -q "dir/lib.a\[f2.o\]\:" nm.out; then 38 tst_res TPASS "Got correct listing" 39 else 40 tst_res TFAIL "Got incorrect listing" 41 cat nm.out 42 fi 43} 44 45test2() 46{ 47 EXPECT_PASS $NM -f posix -g $TST_DATAROOT/f1 \> nm.out 48 49 if grep -q "^[^ ]\+ [abdft]" nm.out; then 50 tst_res TFAIL "Got internal symbols with -g" 51 cat nm.out 52 else 53 tst_res TPASS "Got only external symbols with -g" 54 fi 55} 56 57test3() 58{ 59 EXPECT_PASS $NM -f posix -t o $TST_DATAROOT/f1 \> nm.out 60 61 if awk '{print $3}' nm.out | grep -q "[8-9a-f]"; then 62 tst_res TFAIL "Got non-octal symbol values with -f" 63 cat nm.out 64 else 65 tst_res TPASS "Got an octal symbol values with -f" 66 fi 67} 68 69test4() 70{ 71 EXPECT_PASS $NM -f sysv $TST_DATAROOT/f1 \> nm.out 72 73 if grep -q "Name" nm.out; then 74 tst_res TPASS "Got SysV format with -f sysv" 75 else 76 tst_res TFAIL "Got wrong format with -f sysv" 77 cat nm.out 78 fi 79} 80 81test5() 82{ 83 EXPECT_PASS $NM -f bsd $TST_DATAROOT/f1 \> nm_bsd.out 84 EXPECT_PASS $NM -f posix $TST_DATAROOT/f1 \> nm_posix.out 85 86 ROD awk '{print gensub(/\y(0+)([0-9a-fA-F]+)\y/, "\\2", "g")}' nm_bsd.out \> trimmed_nm_bsd.out 87 ROD awk '{print gensub(/\y(0+)([0-9a-fA-F]+)\y/, "\\2", "g")}' nm_posix.out \> trimmed_nm_posix.out 88 89 ROD awk '{print $3 $2 $1}' trimmed_nm_bsd.out \> nm1.out 90 ROD awk '{print $1 $2 $3}' trimmed_nm_posix.out \> nm2.out 91 92 if diff nm1.out nm2.out > /dev/null; then 93 tst_res TPASS "Got BSD format with -f bsd" 94 else 95 tst_res TFAIL "Got wrong format with -f bsd" 96 cat nm_bsd.out 97 fi 98} 99 100test6() 101{ 102 EXPECT_PASS $NM -f sysv -u $TST_DATAROOT/f1 \> nm.out 103 104 if grep -q "Undefined symbols from" nm.out; then 105 tst_res TPASS "Got undefined symbols with -u" 106 else 107 tst_res TFAIL "Haven't got undefined symbols with -u" 108 cat nm.out 109 fi 110} 111 112test7() 113{ 114 EXPECT_PASS $NM -s $TST_DATAROOT/lib.a \> nm.out 115 116 if grep -q "index" nm.out; then 117 tst_res TPASS "Got index with -s" 118 else 119 tst_res TFAIL "Haven't got index with -s" 120 fi 121} 122 123. tst_test.sh 124tst_run 125