xref: /illumos-gate/usr/src/test/elf-tests/tests/mapfiles/parser/test-parser.sh (revision 1b09309c5ebed5c0bf14e2b396bf626c5aa30034)
1#! /usr/bin/sh
2#
3# This file and its contents are supplied under the terms of the
4# Common Development and Distribution License ("CDDL"), version 1.0.
5# You may only use this file in accordance with the terms of version
6# 1.0 of the CDDL.
7#
8# A full copy of the text of the CDDL should have accompanied this
9# source.  A copy of the CDDL is also available via the Internet at
10# http://www.illumos.org/license/CDDL.
11#
12
13# Copyright 2012, Richard Lowe.
14
15TESTDIR=$(dirname $0)
16
17tmpdir=/tmp/test.$$
18mkdir $tmpdir
19cd $tmpdir
20
21cleanup() {
22	cd /
23	rm -fr $tmpdir
24}
25
26trap 'cleanup' EXIT
27
28if [[ $PWD != $tmpdir ]]; then
29	print -u2 "Failed to create temporary directory: $tmpdir"
30	exit 1;
31fi
32
33if [[ -n $PROTO ]]; then
34	export LD_ALTEXEC=$PROTO/bin/ld
35fi
36
37ret=0
38
39function should_succeed {
40	mapfile=$1
41	msg=$2
42
43	if gcc -m32 -shared -Wl,-M,${TESTDIR}/$mapfile ${TESTDIR}/object.c \
44	    -o object.so; then
45		echo "pass (32): $msg"
46	else
47		echo "FAIL (32): $msg"
48		ret=1
49	fi
50
51	if gcc -m64 -shared -Wl,-M,${TESTDIR}/$mapfile ${TESTDIR}/object.c \
52	    -o object.so; then
53		echo "pass (64): $msg"
54	else
55		echo "FAIL (64): $msg"
56		ret=1
57	fi
58}
59
60function should_fail {
61	mapfile=$1
62	msg=$2
63	error=$3
64
65	if gcc -m32 -shared -Wl,-M,${TESTDIR}/$mapfile ${TESTDIR}/object.c \
66	    -o object.so 2>&1 | /usr/bin/grep -Eq "$error"; then
67		echo "pass (32): $msg"
68	else
69		echo "FAIL (32): $msg"
70		ret=1
71	fi
72
73	if gcc -m64 -shared -Wl,-M,${TESTDIR}/$mapfile ${TESTDIR}/object.c \
74	    -o object.so 2>&1 | /usr/bin/grep -Eq "$error"; then
75		echo "pass (64): $msg"
76	else
77		echo "FAIL (64): $msg"
78		ret=1
79	fi
80}
81
82should_succeed mapfile.sizemult.good "link with integer multiplier syntax"
83
84should_fail mapfile.sizemult.wrong "link with integer multiplier syntax with wrong result" \
85    "assertion failed: size of symbol common should be: [0-9]+ is: [0-9]+"
86should_fail mapfile.sizemult.noterm "link with integer multiplier syntax with no terminating ]" \
87    "expected '.' to terminate multiplier of: 2"
88
89should_fail mapfile.sizemult.twobegin "link with integer multiplier with two [s" \
90    "expected integer value following '.': 2..4"
91
92should_fail mapfile.sizemult.overflow "link with integer multiplier that overflows" \
93    "multiplication overflow"
94
95should_succeed mapfile.addrsize.good "link with addrsized symbol"
96
97should_succeed mapfile.addrsize.mult "link with addrsized symbol with multiplier"
98
99should_fail mapfile.addrsize.wrong "link with addrsized symbol with wrong value" \
100    "assertion failed: size of symbol"
101
102should_fail mapfile.addrsize.substring "link with addrsized symbol with substring of valid name" \
103    "expected integer value following SIZE: addrs"
104
105should_fail mapfile.addrsize.superstring "link with addrsized symbol with superstring of valid name" \
106    "expected integer value following SIZE: addrsizes"
107
108exit $ret
109