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. tst_test.sh 17 18setup() 19{ 20 ROD cp "$TST_DATAROOT/lib.a" "." 21 ROD mkdir "dir" 22 ROD cp "$TST_DATAROOT/lib.a" "dir/" 23} 24 25test1() 26{ 27 EXPECT_PASS $NM -f posix -A "lib.a" \> nm.out 28 29 if grep -q "lib.a\[f2.o\]\:" nm.out; then 30 tst_res TPASS "Got correct listing" 31 else 32 tst_res TFAIL "Got incorrect listing" 33 cat nm.out 34 fi 35 36 EXPECT_PASS $NM -f posix -A "dir/lib.a" \> nm.out 37 38 if grep -q "dir/lib.a\[f2.o\]\:" nm.out; then 39 tst_res TPASS "Got correct listing" 40 else 41 tst_res TFAIL "Got incorrect listing" 42 cat nm.out 43 fi 44} 45 46test2() 47{ 48 EXPECT_PASS $NM -f posix -g $TST_DATAROOT/f1 \> nm.out 49 50 if grep -q "\w [a,b,d,f,t]" nm.out; then 51 tst_res TFAIL "Got internal symbols with -g" 52 cat nm.out 53 else 54 tst_res TPASS "Got only external symbols with -g" 55 fi 56} 57 58test3() 59{ 60 EXPECT_PASS $NM -f posix -t o $TST_DATAROOT/f1 \> nm.out 61 62 if awk '{print $3}' nm.out | grep -q "[8-9a-f]"; then 63 tst_res TFAIL "Got non-octal symbol values with -f" 64 cat nm.out 65 else 66 tst_res TPASS "Got an octal symbol values with -f" 67 fi 68} 69 70test4() 71{ 72 EXPECT_PASS $NM -f sysv $TST_DATAROOT/f1 \> nm.out 73 74 if grep -q "Name" nm.out; then 75 tst_res TPASS "Got SysV format with -f sysv" 76 else 77 tst_res TFAIL "Got wrong format with -f sysv" 78 cat nm.out 79 fi 80} 81 82test5() 83{ 84 EXPECT_PASS $NM -f bsd $TST_DATAROOT/f1 \> nm_bsd.out 85 EXPECT_PASS $NM -f posix $TST_DATAROOT/f1 \> nm_posix.out 86 87 ROD awk '{print gensub(/\y(0+)([0-9a-fA-F]+)\y/, "\\2", "g")}' nm_bsd.out \> trimmed_nm_bsd.out 88 ROD awk '{print gensub(/\y(0+)([0-9a-fA-F]+)\y/, "\\2", "g")}' nm_posix.out \> trimmed_nm_posix.out 89 90 ROD awk '{print $3 $2 $1}' trimmed_nm_bsd.out \> nm1.out 91 ROD awk '{print $1 $2 $3}' trimmed_nm_posix.out \> nm2.out 92 93 if diff nm1.out nm2.out > /dev/null; then 94 tst_res TPASS "Got BSD format with -f bsd" 95 else 96 tst_res TFAIL "Got wrong format with -f bsd" 97 cat nm_bsd.out 98 fi 99} 100 101test6() 102{ 103 EXPECT_PASS $NM -f sysv -u $TST_DATAROOT/f1 \> nm.out 104 105 if grep -q "Undefined symbols from" nm.out; then 106 tst_res TPASS "Got undefined symbols with -u" 107 else 108 tst_res TFAIL "Haven't got undefined symbols with -u" 109 cat nm.out 110 fi 111} 112 113test7() 114{ 115 EXPECT_PASS $NM -s $TST_DATAROOT/lib.a \> nm.out 116 117 if grep -q "index" nm.out; then 118 tst_res TPASS "Got index with -s" 119 else 120 tst_res TFAIL "Haven't got index with -s" 121 fi 122} 123 124tst_run 125