• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/bin/sh
2#
3# Copyright (c) International Business Machines  Corp., 2000
4#  06/01 Robbie Williamson (robbiew@us.ibm.com)
5# Copyright (c) 2016 Cyril Hrubis <chrubis@suse.cz>
6#
7# This program is free software;  you can redistribute it and/or modify
8# it under the terms of the GNU General Public License as published by
9# the Free Software Foundation; either version 2 of the License, or
10# (at your option) any later version.
11#
12# This program is distributed in the hope that it will be useful,
13# but WITHOUT ANY WARRANTY;  without even the implied warranty of
14# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
15# the GNU General Public License for more details.
16#
17# You should have received a copy of the GNU General Public License
18# along with this program;  if not, write to the Free Software
19# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20#
21#---------------------------------------------------------------------------
22#
23# Tests the basic functionality of the `nm` command.
24#
25NM=${NM:=nm}
26
27TST_ID="nm01"
28TST_CNT=7
29TST_TESTFUNC=test
30TST_SETUP=setup
31TST_NEEDS_TMPDIR=1
32TST_NEEDS_CMDS="$NM"
33. tst_test.sh
34
35setup()
36{
37	ROD cp "$TST_DATAROOT/lib.a" "."
38	ROD mkdir "dir"
39	ROD cp "$TST_DATAROOT/lib.a" "dir/"
40}
41
42test1()
43{
44	EXPECT_PASS $NM -f posix -A "lib.a" \> nm.out
45
46	if grep -q "lib.a\[f2.o\]\:" nm.out; then
47		tst_res TPASS "Got correct listing"
48	else
49		tst_res TFAIL "Got incorrect listing"
50		cat nm.out
51	fi
52
53	EXPECT_PASS $NM -f posix -A "dir/lib.a" \> nm.out
54
55	if grep -q "dir/lib.a\[f2.o\]\:" nm.out; then
56		tst_res TPASS "Got correct listing"
57	else
58		tst_res TFAIL "Got incorrect listing"
59		cat nm.out
60	fi
61}
62
63test2()
64{
65	EXPECT_PASS $NM -f posix -g $TST_DATAROOT/f1 \> nm.out
66
67	if grep -q "\w [a,b,d,f,t]" nm.out; then
68		tst_res TFAIL "Got internal symbols with -g"
69		cat nm.out
70	else
71		tst_res TPASS "Got only external symbols with -g"
72	fi
73}
74
75test3()
76{
77	EXPECT_PASS $NM -f posix -t o $TST_DATAROOT/f1 \> nm.out
78
79	if awk '{print $3}' nm.out | grep -q "[8-9a-f]"; then
80		tst_res TFAIL "Got non-octal symbol values with -f"
81		cat nm.out
82	else
83		tst_res TPASS "Got an octal symbol values with -f"
84	fi
85}
86
87test4()
88{
89	EXPECT_PASS $NM -f sysv $TST_DATAROOT/f1 \> nm.out
90
91	if grep -q "Name" nm.out; then
92		tst_res TPASS "Got SysV format with -f sysv"
93	else
94		tst_res TFAIL "Got wrong format with -f sysv"
95		cat nm.out
96	fi
97}
98
99test5()
100{
101	EXPECT_PASS $NM -f bsd $TST_DATAROOT/f1 \> nm_bsd.out
102	EXPECT_PASS $NM -f posix $TST_DATAROOT/f1 \> nm_posix.out
103
104	ROD awk '{print $3 $2 $1}' nm_bsd.out \> nm1.out
105	ROD awk '{print $1 $2 $3}' nm_posix.out \> nm2.out
106
107	if diff nm1.out nm2.out > /dev/null; then
108		tst_res TPASS "Got BSD format with -f bsd"
109	else
110		tst_res TFAIL "Got wrong format with -f bsd"
111		cat nm_bsd.out
112	fi
113}
114
115test6()
116{
117	EXPECT_PASS $NM -f sysv -u $TST_DATAROOT/f1 \> nm.out
118
119	if grep -q "Undefined symbols from" nm.out; then
120		tst_res TPASS "Got undefined symbols with -u"
121	else
122		tst_res TFAIL "Haven't got undefined symbols with -u"
123		cat nm.out
124	fi
125}
126
127test7()
128{
129	EXPECT_PASS $NM -s $TST_DATAROOT/lib.a \> nm.out
130
131	if grep -q "index" nm.out; then
132		tst_res TPASS "Got index with -s"
133	else
134		tst_res TFAIL "Haven't got index with -s"
135	fi
136}
137
138tst_run
139