| #!/bin/sh |
| # |
| # Copyright (c) International Business Machines Corp., 2000 |
| # |
| # This program is free software; you can redistribute it and/or modify |
| # it under the terms of the GNU General Public License as published by |
| # the Free Software Foundation; either version 2 of the License, or |
| # (at your option) any later version. |
| # |
| # This program is distributed in the hope that it will be useful, |
| # but WITHOUT ANY WARRANTY; without even the implied warranty of |
| # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See |
| # the GNU General Public License for more details. |
| # |
| # You should have received a copy of the GNU General Public License |
| # along with this program; if not, write to the Free Software |
| # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| # |
| # |
| # |
| # FILE : nm01 |
| # |
| # PURPOSE: To test the basic functionality of the `nm` command. |
| # |
| # HISTORY: |
| # 06/01 Robbie Williamson (robbiew@us.ibm.com) |
| # -Ported |
| # |
| # |
| #--------------------------------------------------------------------------- |
| #Uncomment line below for debug output |
| #trace_logic=${trace_logic:-"set -x"} |
| |
| CC=${CC:=gcc} |
| NM=${NM:=nm} |
| TCtmp=${TCtmp:-/tmp/nm$$} |
| TCdat=${TCdat:-`pwd`} |
| LOOP=1 |
| do_setup() |
| { |
| $trace_logic |
| mkdir $TCtmp |
| $CC -o $TCtmp/nmfile $TCdat/nmfile.c |
| $CC -o $TCtmp/nmfile1 $TCdat/nmfile1.c |
| $CC -o $TCtmp/nmfile2 $TCdat/nmfile2.c |
| $CC -o $TCtmp/nmfile3 $TCdat/nmfile3.c |
| } |
| |
| do_cleanup() |
| { |
| $trace_logic |
| rm -rf $TCtmp |
| } |
| |
| do_test() |
| { |
| $trace_logic |
| TCRESULT=0 |
| while [ $LOOP -gt 0 ] |
| do |
| echo "-------System test for $NM command------" |
| cd $TCdat |
| ar -cr $TCtmp/lib.a nmfile1.obj nmfile1.obj nmfile2.obj nmfile3.obj |
| |
| # -A Displays either the full path name or library name of an object |
| # on each line. |
| |
| # CODE |
| RC1=0 |
| RC2=0 |
| |
| mkdir -p $TCtmp/a/b/c/d |
| |
| $NM -f posix -A $TCtmp/lib.a | grep "$TCtmp/lib.a\[nmfile2.obj\]\:" 2>&1 1>/dev/null |
| RC1=$? |
| cp $TCtmp/lib.a $TCtmp/a/b/c/d/ |
| $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 |
| RC2=$? |
| |
| |
| if [ $RC1 -eq '0' ] && [ $RC2 -eq '0' ] |
| then |
| echo "-)1" |
| else |
| echo "nm -A: FAIL" |
| do_cleanup |
| exit 1 |
| fi |
| #------------------------------------------------------------------------------- |
| |
| #The nm -g Displays only external (global)symbols. |
| |
| # CODE |
| |
| COUNT=`$NM -f posix -g $TCtmp/nmfile1 | awk '{print $2 }' | grep "[a,b,d,f,t]" | wc -l` 2>&1 1>/dev/null |
| if [ $COUNT -eq 0 ] |
| then |
| echo "-)2" |
| else |
| echo "nm -g: FAIL" |
| do_cleanup |
| exit 1 |
| fi |
| #------------------------------------------------------------------------------- |
| # -t o Displays a symbol's value as an octal rather than |
| # a decimal number. |
| |
| # CODE |
| $NM -f posix -t o $TCtmp/nmfile1 | awk '{print $3}' | grep "[8-9]" >/dev/null 2>&1 |
| if [ $? -eq "1" ] |
| then |
| echo "-)3" |
| else |
| echo "nm -t o: FAIL" |
| do_cleanup |
| exit 1 |
| fi |
| #------------------------------------------------------------------------------- |
| |
| # -f sysv Displays information in a SysV output format |
| # CODE |
| |
| count=0 |
| $NM -f sysv $TCtmp/nmfile1 | grep Name > /dev/null 2>&1 |
| count=$? |
| if [ $count -eq 0 ] |
| then |
| echo "-)4" |
| else |
| echo "nm -f sysv: FAIL" |
| do_cleanup |
| exit 1 |
| fi |
| |
| #------------------------------------------------------------------------------- |
| |
| # -f bsd Displays information in a BSD output format |
| # CODE |
| $NM -f bsd $TCtmp/nmfile1 | grep printf | awk '{print $2}' > $TCtmp/nm.diff1 |
| $NM -f posix $TCtmp/nmfile1 | grep printf | awk '{print $1}' > $TCtmp/nm.diff2 |
| diff $TCtmp/nm.diff1 $TCtmp/nm.diff2 |
| if [ $? -eq 0 ] |
| then |
| echo "-)5" |
| else |
| echo "nm -f bsd: FAIL" |
| do_cleanup |
| exit 1 |
| fi |
| |
| #----------------------------------------------------------------------------- |
| #-u Displays only undefined symbols.Local and Global |
| |
| # CODE |
| COUNT=0 |
| $NM -f sysv -u $TCtmp/nmfile1 | grep "Undefined symbols from" 2>&1 1>/dev/null |
| if [ $? -eq 0 ] |
| then |
| echo "-)6" |
| else |
| echo "nm -u: FAIL" |
| do_cleanup |
| exit 1 |
| fi |
| |
| #----------------------------------------------------------------------------- |
| |
| # -v Sorts output by value instead of alphabetically. |
| # CODE |
| $NM $TCtmp/nmfile1 | sort | awk '{print $1}'| grep [0-9] > $TCtmp/nm.res1 |
| $NM -v $TCtmp/nmfile1 | awk '{print $1}' | grep [0-9] > $TCtmp/nm.res2 |
| diff $TCtmp/nm.res1 $TCtmp/nm.res2 2>&1 1>/dev/null |
| |
| if [ $? -eq 0 ] |
| then |
| echo "-)7" |
| else |
| echo "nm -v: FAIL" |
| do_cleanup |
| exit 1 |
| fi |
| #------------------------------------------------------------------------------ |
| # -s Print archive index. |
| # CODE |
| |
| $NM -s $TCtmp/lib.a | grep "index" 2>&1 1>/dev/null |
| if [ $? -eq 0 ] |
| then |
| echo "-)8" |
| else |
| echo "nm -s: FAIL" |
| do_cleanup |
| exit 1 |
| fi |
| #----------------------------------------------------------------------------- |
| |
| : $(( LOOP -= 1 )) |
| done |
| |
| echo "nm01: PASS" |
| do_cleanup |
| exit 0 |
| } |
| |
| #MAIN |
| do_setup |
| do_test |
| |
| |