t_integration.sh revision 1.71 1 # $NetBSD: t_integration.sh,v 1.71 2021/09/26 03:17:59 rillig Exp $
2 #
3 # Copyright (c) 2008, 2010 The NetBSD Foundation, Inc.
4 # All rights reserved.
5 #
6 # Redistribution and use in source and binary forms, with or without
7 # modification, are permitted provided that the following conditions
8 # are met:
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.
14 #
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.
26 #
27
28 lint1=/usr/libexec/lint1
29 : "${archsubdir:=archsubdir_must_be_set}"
30
31
32 configure_test_case()
33 {
34 local awk
35
36 # shellcheck disable=SC2016
37 awk='
38 BEGIN {
39 # see usr.bin/xlint/arch/*/targparam.h
40 platform["aarch64"] = "schar lp64 long ldbl-128"
41 platform["alpha"] = "schar lp64 long ldbl-64"
42 platform["arm"] = "uchar ilp32 long ldbl-64"
43 platform["coldfire"] = "schar ilp32 int ldbl-64"
44 platform["hppa"] = "schar ilp32 long ldbl-64"
45 platform["i386"] = "schar ilp32 int ldbl-96"
46 platform["ia64"] = "schar lp64 long ldbl-128"
47 platform["m68000"] = "schar ilp32 int ldbl-64"
48 platform["m68k"] = "schar ilp32 int ldbl-96"
49 platform["mips"] = "schar ilp32 ???? ldbl-64"
50 platform["mips64"] = "schar ilp32 long ldbl-128"
51 platform["mipsn64"] = "schar lp64 long ldbl-128"
52 platform["or1k"] = "schar ilp32 int ldbl-64"
53 platform["powerpc"] = "uchar ilp32 int ldbl-64"
54 platform["powerpc64"] = "uchar lp64 long ldbl-64"
55 platform["powerpc64"] = "uchar lp64 long ldbl-64"
56 platform["riscv32"] = "schar ilp32 int ldbl-64"
57 platform["riscv64"] = "schar lp64 long ldbl-64"
58 platform["sh3"] = "schar ilp32 int ldbl-64"
59 platform["sparc"] = "schar ilp32 long ldbl-64"
60 platform["sparc64"] = "schar lp64 long ldbl-128"
61 platform["vax"] = "schar ilp32 long ldbl-64"
62 platform["x86_64"] = "schar lp64 long ldbl-128"
63 }
64
65 function platform_has(prop) {
66 if (!match(prop, /^(schar|uchar|ilp32|lp64|int|long|ldbl-64|ldbl-96|ldbl-128)$/)) {
67 printf("bad property '\''%s'\''\n", prop) > "/dev/stderr"
68 exit(1)
69 }
70 if (platform[archsubdir] == "") {
71 printf("bad archsubdir '\''%s'\''\n", archsubdir) > "/dev/stderr"
72 exit(1)
73 }
74 return match(" " platform[archsubdir] " ", " " prop " ")
75 }
76
77 BEGIN {
78 archsubdir = "'"$archsubdir"'"
79 flags = "-g -S -w"
80 skip = "no"
81 }
82 $1 == "/*" && $2 ~ /^lint1-/ && $NF == "*/" {
83 if ($2 == "lint1-flags:" || $2 == "lint1-extra-flags:") {
84 if ($2 == "lint1-flags:")
85 flags = ""
86 for (i = 3; i < NF; i++)
87 flags = flags " " $i
88 } else if ($2 == "lint1-only-if:") {
89 for (i = 3; i < NF; i++)
90 if (!platform_has($i))
91 skip = "yes"
92 } else if ($2 == "lint1-skip-if:") {
93 for (i = 3; i < NF; i++)
94 if (platform_has($i))
95 skip = "yes"
96 } else {
97 printf("bad lint1 comment '\''%s'\''\n", $2) > "/dev/stderr"
98 exit(1)
99 }
100 }
101
102 END {
103 printf("flags='\''%s'\''\n", flags)
104 printf("skip=%s\n", skip)
105 }
106 '
107
108 local config
109 config="$(awk "$awk" "$1")" || exit 1
110 eval "$config"
111 }
112
113 # shellcheck disable=SC2155
114 check_lint1()
115 {
116 local src="$(atf_get_srcdir)/$1"
117 local exp="${src%.c}.exp"
118 local exp_ln="${src%.c}.exp-ln"
119 local wrk_ln="${1%.c}.ln"
120 local flags=""
121 local skip=""
122
123 if [ ! -f "$exp_ln" ]; then
124 exp_ln='/dev/null'
125 wrk_ln='/dev/null'
126 fi
127
128 configure_test_case "$src" # sets 'skip' and 'flags'
129
130 if [ "$skip" = "yes" ]; then
131 atf_skip "unsuitable platform"
132 fi
133
134 if [ -f "$exp" ]; then
135 # shellcheck disable=SC2086
136 atf_check -s not-exit:0 -o "file:$exp" -e empty \
137 "$lint1" $flags "$src" "$wrk_ln"
138 else
139 # shellcheck disable=SC2086
140 atf_check -s exit:0 \
141 "$lint1" $flags "$src" "$wrk_ln"
142 fi
143
144 if [ "$exp_ln" != '/dev/null' ]; then
145 atf_check -o "file:$exp_ln" cat "$wrk_ln"
146 fi
147 }
148
149 atf_init_test_cases()
150 {
151 local src name
152
153 for src in "$(atf_get_srcdir)"/*.c; do
154 src=${src##*/}
155 name=${src%.c}
156
157 atf_test_case "$name"
158 eval "${name}_head() {
159 atf_set 'require.progs' '$lint1'
160 }"
161 eval "${name}_body() {
162 check_lint1 '$name.c'
163 }"
164 atf_add_test_case "$name"
165 done
166 }
167