Fix the creation of the dumpdir directory in stress_floppy Makefile
[ltp-debian.git] / testcases / commands / ade / nm / nm01
blob1a592ed8a3c133479b9bdeb406726c2f60a97be0
1 #!/bin/sh
3 # Copyright (c) International Business Machines Corp., 2000
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.
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.
15 # You should have received a copy of the GNU General Public License
16 # along with this pronram; if not, write to the Free Software
17 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 # FILE : nm01
23 # PURPOSE: To test the basic functionality of the `nm` command.
25 # HISTORY:
26 # 06/01 Robbie Williamson (robbiew@us.ibm.com)
27 # -Ported
30 #---------------------------------------------------------------------------
31 #Uncomment line below for debug output
32 #trace_logic=${trace_logic:-"set -x"}
34 CC=${CC:=gcc}
35 NM=${NM:=nm}
36 TCtmp=${TCtmp:-/tmp/nm$$}
37 TCdat=${TCdat:-`pwd`}
38 LOOP=1
39 do_setup()
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
49 do_cleanup()
51 $trace_logic
52 rm -rf $TCtmp
55 do_test()
57 $trace_logic
58 TCRESULT=0
59 while [ $LOOP -gt 0 ]
61 echo "-------System test for $NM command------"
62 cd $TCdat
63 ar -cr $TCtmp/lib.a nmfile1.obj nmfile1.obj nmfile2.obj nmfile3.obj
65 # -A Displays either the full path name or library name of an object
66 # on each line.
68 # CODE
69 RC1=0
70 RC2=0
72 mkdir -p $TCtmp/a/b/c/d
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=$?
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
89 #-------------------------------------------------------------------------------
91 #The nm -g Displays only external (global)symbols.
93 # CODE
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
104 #-------------------------------------------------------------------------------
105 # -t o Displays a symbol's value as an octal rather than
106 # a decimal number.
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
118 #-------------------------------------------------------------------------------
120 # -f sysv Displays information in a SysV output format
121 # CODE
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
135 #-------------------------------------------------------------------------------
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
151 #-----------------------------------------------------------------------------
152 #-u Displays only undefined symbols.Local and Global
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
166 #-----------------------------------------------------------------------------
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
174 if [ $? -eq 0 ]
175 then
176 echo "-)7"
177 else
178 echo "nm -v: FAIL"
179 do_cleanup
180 exit 1
182 #------------------------------------------------------------------------------
183 # -s Print archive index.
184 # CODE
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
195 #-----------------------------------------------------------------------------
197 : $(( LOOP -= 1 ))
198 done
200 echo "nm01: PASS"
201 do_cleanup
202 exit 0
205 #MAIN
206 do_setup
207 do_test