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