• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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@us.ibm.com)
27#     -Ported
28#
29#
30#---------------------------------------------------------------------------
31#Uncomment line below for debug output
32#trace_logic=${trace_logic:-"set -x"}
33
34CC=${CC:=gcc}
35NM=${NM:=nm}
36TCtmp=${TCtmp:-/tmp/nm$$}
37TCdat=${TCdat:-`pwd`}
38LOOP=1
39do_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
49do_cleanup()
50{
51$trace_logic
52  rm -rf $TCtmp
53}
54
55do_test()
56{
57$trace_logic
58TCRESULT=0
59while [ $LOOP -gt 0 ]
60do
61echo "-------System test for $NM command------"
62cd $TCdat
63ar -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
69RC1=0
70RC2=0
71
72mkdir -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
75RC1=$?
76cp $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
78RC2=$?
79
80
81if [ $RC1 -eq  '0' ] && [ $RC2 -eq '0' ]
82then
83	echo "-)1"
84else
85	echo "nm -A: FAIL"
86	do_cleanup
87	exit 1
88fi
89#-------------------------------------------------------------------------------
90
91#The nm -g Displays only external (global)symbols.
92
93# CODE
94
95COUNT=`$NM -f posix -g $TCtmp/nmfile1 | awk '{print $2 }' | grep "[a,b,d,f,t]"  | wc -l` 2>&1 1>/dev/null
96if [ $COUNT -eq 0 ]
97then
98	echo "-)2"
99else
100	echo "nm -g: FAIL"
101	do_cleanup
102	exit 1
103fi
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
110if [ $? -eq "1" ]
111then
112	echo "-)3"
113else
114	echo "nm -t o: FAIL"
115	do_cleanup
116	exit 1
117fi
118#-------------------------------------------------------------------------------
119
120# -f sysv Displays information in a SysV output format
121# CODE
122
123count=0
124$NM -f sysv $TCtmp/nmfile1 | grep Name > /dev/null 2>&1
125count=$?
126if [ $count -eq 0 ]
127then
128	echo "-)4"
129else
130	echo "nm -f sysv: FAIL"
131	do_cleanup
132	exit 1
133fi
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
141diff $TCtmp/nm.diff1 $TCtmp/nm.diff2
142if [ $? -eq 0  ]
143then
144	echo "-)5"
145else
146	echo "nm -f bsd: FAIL"
147	do_cleanup
148	exit 1
149fi
150
151#-----------------------------------------------------------------------------
152#-u Displays only undefined symbols.Local and Global
153
154# CODE
155COUNT=0
156$NM -f sysv -u $TCtmp/nmfile1 | grep "Undefined symbols from" 2>&1 1>/dev/null
157if [ $? -eq 0 ]
158then
159	echo "-)6"
160else
161	echo "nm -u: FAIL"
162	do_cleanup
163	exit 1
164fi
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
172diff $TCtmp/nm.res1 $TCtmp/nm.res2 2>&1 1>/dev/null
173
174if [ $? -eq 0 ]
175then
176	echo "-)7"
177else
178	echo "nm -v: FAIL"
179	do_cleanup
180	exit 1
181fi
182#------------------------------------------------------------------------------
183# -s Print archive index.
184# CODE
185
186$NM -s $TCtmp/lib.a | grep "index" 2>&1 1>/dev/null
187if [ $? -eq 0 ]
188then
189	echo "-)8"
190else
191     	echo "nm -s: FAIL"
192	do_cleanup
193	exit 1
194fi
195#-----------------------------------------------------------------------------
196
197: $(( LOOP -= 1 ))
198done
199
200echo "nm01: PASS"
201do_cleanup
202exit 0
203}
204
205#MAIN
206do_setup
207do_test
208
209
210