• 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# Test the basic functionality of the `ld` command.
23#
24
25CC=${CC:=gcc}
26LD=${LD:=ld}
27
28TST_CNT=5
29TST_TESTFUNC=test
30TST_SETUP=setup
31TST_NEEDS_TMPDIR=1
32TST_NEEDS_CMDS="$CC $LD"
33. tst_test.sh
34
35setup()
36{
37	for i in rf1 f1 rd1 d1 main; do
38		ROD $CC -fPIC -c -o ${i}.o $TST_DATAROOT/${i}.c
39	done
40}
41
42test1()
43{
44	EXPECT_FAIL $LD x.o y.o 2\> ld.out
45
46	if grep -q "$LD:.*[xy]\.o.*No such file or directory" ld.out; then
47		tst_res TPASS "Missing files were reported"
48	else
49		tst_res TFAIL "Missing files were not reported"
50		cat ld.out
51	fi
52}
53
54test2()
55{
56	EXPECT_FAIL $CC x.o y.o 2\> cc.out
57
58	if grep -q "$CC:.*[xy]\.o.*No such file or directory" cc.out; then
59		tst_res TPASS "Missing files were reported"
60	else
61		tst_res TFAIL "Missing files were not reported"
62		cat cc.out
63	fi
64}
65
66test3()
67{
68	EXPECT_PASS $LD -shared f1.o d1.o -o test.so
69
70	if file test.so |grep -q shared; then
71		tst_res TPASS "Shared library could be build"
72	else
73		tst_res TFAIL "Failed to build shared library"
74	fi
75}
76
77test4()
78{
79	EXPECT_PASS $LD -Bdynamic -shared f1.o d1.o -o test.so
80	EXPECT_FAIL $LD -Bstatic -L. main.o rd1.o test.so -o a.out
81}
82
83test5()
84{
85	EXPECT_PASS $LD -Bdynamic -shared main.o f1.o rf1.o -o test.so -L/usr/lib/
86	EXPECT_FAIL $LD -Bstatic -r main.o f1.o rf1.o test.so -L/usr/lib/ 2\> ld.out
87	cat ld.out
88
89	if grep -q "$LD: attempted static link of dynamic object" ld.out; then
90		tst_res TPASS "Got expected error message"
91	else
92		tst_res TFAIL "Unexpected error message"
93		cat ld.out
94	fi
95}
96
97tst_run
98