1 # $NetBSD: t_script.sh,v 1.7 2014/11/16 04:47:18 uebayasi Exp $
3 # Copyright (c) 2014 The NetBSD Foundation, Inc.
6 # Redistribution and use in source and binary forms, with or without
7 # modification, are permitted provided that the following conditions
9 # 1. Redistributions of source code must retain the above copyright
10 # notice, this list of conditions and the following disclaimer.
11 # 2. Redistributions in binary form must reproduce the above copyright
12 # notice, this list of conditions and the following disclaimer in the
13 # documentation and/or other materials provided with the distribution.
15 # THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
16 # ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
17 # TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
18 # PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
19 # BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20 # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21 # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22 # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23 # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24 # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25 # POSSIBILITY OF SUCH DAMAGE.
28 ################################################################################
30 atf_test_case order_default
31 order_default_head
() {
32 atf_set
"descr" "check if default object ordering works"
33 atf_set
"require.progs" "cc" "ld" "readelf" "nm" "sed" "grep"
36 order_default_body
() {
39 /* do nothing; but ld has implicit scripts internally */
40 /* which usually do: *(.data) *(.data.*) */
43 order_assert_descending
46 ################################################################################
48 atf_test_case order_merge
50 atf_set
"descr" "check if glob merge keeps object ordering"
51 atf_set
"require.progs" ${order_require_progs}
62 order_assert_descending
65 ################################################################################
67 atf_test_case order_reorder
68 order_reorder_head
() {
69 atf_set
"descr" "check if object reordering works"
70 atf_set
"require.progs" ${order_require_progs}
73 order_reorder_body
() {
84 order_assert_ascending
87 ################################################################################
89 atf_test_case order_sort
91 atf_set
"descr" "check if object sort works"
92 atf_set
"require.progs" ${order_require_progs}
105 order_assert_ascending
108 ################################################################################
110 atf_test_case multisec
112 atf_set
"descr" "check if multiple SECTIONS commands work"
113 atf_set
"require.progs" ${order_require_progs}
118 #include <sys/cdefs.h>
119 char a __section(".data.a") = 'a';
120 char b __section(".data.b") = 'b';
121 char c __section(".data.c") = 'c';
123 atf_check
-s exit:0 -o ignore
-e ignore cc
-c test.c
139 atf_check
-s exit:0 -o ignore
-e ignore \
140 ld
-r -T test.x
-Map test.map
-o test.ro
test.o
141 extract_section_names
test.ro
>test.secs
142 extract_symbol_names
test.ro
>test.syms
143 assert_nosec
'\.data\.a'
144 assert_nosec
'\.data\.b'
145 assert_sec
'\.data\.c'
148 ################################################################################
150 order_require_progs
="cc ld readelf nm sed grep"
152 order_assert_ascending
() {
153 order_assert_order a b c
156 order_assert_descending
() {
157 order_assert_order c b a
160 order_assert_order
() {
164 match
$1 && match
$2 && match
$3
166 atf_check
test "$?" -eq 0
172 #include <sys/cdefs.h>
173 char $i __section(".data.$i") = '$i';
175 atf_check
-s exit:0 -o ignore
-e ignore cc
-c $i.c
178 int main(void) { return 0; }
180 atf_check
-s exit:0 -o ignore
-e ignore cc
-c test.c
185 atf_check
-s exit:0 -o ignore
-e ignore \
186 ld
-r -T test.x
-Map test.map
-o x.o c.o b.o a.o
187 atf_check
-s exit:0 -o ignore
-e ignore \
188 cc
-o test test.o x.o
189 extract_symbol_names
test |
190 grep '^[abc]$' >test.syms
193 extract_section_names
() {
195 sed -ne '/\] \./ { s/^.*\] //; s/ .*$//; p }'
198 extract_symbol_names
() {
212 atf_check
-s exit:0 -o ignore
-e ignore \
213 grep "^$1\$" test.secs
217 atf_check
-s exit:1 -o ignore
-e ignore \
218 grep "^$1\$" test.secs
221 ################################################################################
223 atf_init_test_cases
()
225 atf_add_test_case order_default
226 atf_add_test_case order_merge
227 atf_add_test_case order_reorder
228 atf_add_test_case order_sort
229 atf_add_test_case multisec