1 #!/bin/sh 2 # 3 # Copyright (c) International Business Machines Corp., 2000 4 # 5 # This program is free software; you can redistribute it and/or modify 6 # it under the terms of the GNU General Public License as published by 7 # the Free Software Foundation; either version 2 of the License, or 8 # (at your option) any later version. 9 # 10 # This program is distributed in the hope that it will be useful, 11 # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See 13 # the GNU General Public License for more details. 14 # 15 # You should have received a copy of the GNU General Public License 16 # along with this program; if not, write to the Free Software 17 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 18 # 19 # 20 # 21 # FILE : nm01 22 # 23 # PURPOSE: To test the basic functionality of the `nm` command. 24 # 25 # HISTORY: 26 # 06/01 Robbie Williamson (robbiew (at] us.ibm.com) 27 # -Ported 28 # 29 # 30 #--------------------------------------------------------------------------- 31 #Uncomment line below for debug output 32 #trace_logic=${trace_logic:-"set -x"} 33 34 CC=${CC:=gcc} 35 NM=${NM:=nm} 36 TCtmp=${TCtmp:-/tmp/nm$$} 37 TCdat=${TCdat:-`pwd`} 38 LOOP=1 39 do_setup() 40 { 41 $trace_logic 42 mkdir $TCtmp 43 $CC -o $TCtmp/nmfile $TCdat/nmfile.c 44 $CC -o $TCtmp/nmfile1 $TCdat/nmfile1.c 45 $CC -o $TCtmp/nmfile2 $TCdat/nmfile2.c 46 $CC -o $TCtmp/nmfile3 $TCdat/nmfile3.c 47 } 48 49 do_cleanup() 50 { 51 $trace_logic 52 rm -rf $TCtmp 53 } 54 55 do_test() 56 { 57 $trace_logic 58 TCRESULT=0 59 while [ $LOOP -gt 0 ] 60 do 61 echo "-------System test for $NM command------" 62 cd $TCdat 63 ar -cr $TCtmp/lib.a nmfile1.obj nmfile1.obj nmfile2.obj nmfile3.obj 64 65 # -A Displays either the full path name or library name of an object 66 # on each line. 67 68 # CODE 69 RC1=0 70 RC2=0 71 72 mkdir -p $TCtmp/a/b/c/d 73 74 $NM -f posix -A $TCtmp/lib.a | grep "$TCtmp/lib.a\[nmfile2.obj\]\:" 2>&1 1>/dev/null 75 RC1=$? 76 cp $TCtmp/lib.a $TCtmp/a/b/c/d/ 77 $NM -f posix -A $TCtmp/a/b/c/d/lib.a | grep "$TCtmp/a/b/c/d/lib.a\[nmfile2.obj\]\:" 2>&1 1>/dev/null 78 RC2=$? 79 80 81 if [ $RC1 -eq '0' ] && [ $RC2 -eq '0' ] 82 then 83 echo "-)1" 84 else 85 echo "nm -A: FAIL" 86 do_cleanup 87 exit 1 88 fi 89 #------------------------------------------------------------------------------- 90 91 #The nm -g Displays only external (global)symbols. 92 93 # CODE 94 95 COUNT=`$NM -f posix -g $TCtmp/nmfile1 | awk '{print $2 }' | grep "[a,b,d,f,t]" | wc -l` 2>&1 1>/dev/null 96 if [ $COUNT -eq 0 ] 97 then 98 echo "-)2" 99 else 100 echo "nm -g: FAIL" 101 do_cleanup 102 exit 1 103 fi 104 #------------------------------------------------------------------------------- 105 # -t o Displays a symbol's value as an octal rather than 106 # a decimal number. 107 108 # CODE 109 $NM -f posix -t o $TCtmp/nmfile1 | awk '{print $3}' | grep "[8-9]" >/dev/null 2>&1 110 if [ $? -eq "1" ] 111 then 112 echo "-)3" 113 else 114 echo "nm -t o: FAIL" 115 do_cleanup 116 exit 1 117 fi 118 #------------------------------------------------------------------------------- 119 120 # -f sysv Displays information in a SysV output format 121 # CODE 122 123 count=0 124 $NM -f sysv $TCtmp/nmfile1 | grep Name > /dev/null 2>&1 125 count=$? 126 if [ $count -eq 0 ] 127 then 128 echo "-)4" 129 else 130 echo "nm -f sysv: FAIL" 131 do_cleanup 132 exit 1 133 fi 134 135 #------------------------------------------------------------------------------- 136 137 # -f bsd Displays information in a BSD output format 138 # CODE 139 $NM -f bsd $TCtmp/nmfile1 | grep printf | awk '{print $2}' > $TCtmp/nm.diff1 140 $NM -f posix $TCtmp/nmfile1 | grep printf | awk '{print $1}' > $TCtmp/nm.diff2 141 diff $TCtmp/nm.diff1 $TCtmp/nm.diff2 142 if [ $? -eq 0 ] 143 then 144 echo "-)5" 145 else 146 echo "nm -f bsd: FAIL" 147 do_cleanup 148 exit 1 149 fi 150 151 #----------------------------------------------------------------------------- 152 #-u Displays only undefined symbols.Local and Global 153 154 # CODE 155 COUNT=0 156 $NM -f sysv -u $TCtmp/nmfile1 | grep "Undefined symbols from" 2>&1 1>/dev/null 157 if [ $? -eq 0 ] 158 then 159 echo "-)6" 160 else 161 echo "nm -u: FAIL" 162 do_cleanup 163 exit 1 164 fi 165 166 #----------------------------------------------------------------------------- 167 168 # -v Sorts output by value instead of alphabetically. 169 # CODE 170 $NM $TCtmp/nmfile1 | sort | awk '{print $1}'| grep [0-9] > $TCtmp/nm.res1 171 $NM -v $TCtmp/nmfile1 | awk '{print $1}' | grep [0-9] > $TCtmp/nm.res2 172 diff $TCtmp/nm.res1 $TCtmp/nm.res2 2>&1 1>/dev/null 173 174 if [ $? -eq 0 ] 175 then 176 echo "-)7" 177 else 178 echo "nm -v: FAIL" 179 do_cleanup 180 exit 1 181 fi 182 #------------------------------------------------------------------------------ 183 # -s Print archive index. 184 # CODE 185 186 $NM -s $TCtmp/lib.a | grep "index" 2>&1 1>/dev/null 187 if [ $? -eq 0 ] 188 then 189 echo "-)8" 190 else 191 echo "nm -s: FAIL" 192 do_cleanup 193 exit 1 194 fi 195 #----------------------------------------------------------------------------- 196 197 : $(( LOOP -= 1 )) 198 done 199 200 echo "nm01: PASS" 201 do_cleanup 202 exit 0 203 } 204 205 #MAIN 206 do_setup 207 do_test 208 209 210