t_integration.sh revision 1.77 1 # $NetBSD: t_integration.sh,v 1.77 2023/02/06 21:01:55 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"] = "uchar 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["riscv32"] = "schar ilp32 int ldbl-64"
56 platform["riscv64"] = "schar lp64 long ldbl-64"
57 platform["sh3"] = "schar ilp32 int ldbl-64"
58 platform["sparc"] = "schar ilp32 long ldbl-64"
59 platform["sparc64"] = "schar lp64 long ldbl-128"
60 platform["vax"] = "schar ilp32 long ldbl-64"
61 platform["x86_64"] = "schar lp64 long ldbl-128"
62 }
63
64 function platform_has(prop) {
65 if (!match(prop, /^(schar|uchar|ilp32|lp64|int|long|ldbl-64|ldbl-96|ldbl-128)$/)) {
66 printf("bad property '\''%s'\''\n", prop) > "/dev/stderr"
67 exit(1)
68 }
69 if (platform[archsubdir] == "") {
70 printf("bad archsubdir '\''%s'\''\n", archsubdir) > "/dev/stderr"
71 exit(1)
72 }
73 return match(" " platform[archsubdir] " ", " " prop " ")
74 }
75
76 BEGIN {
77 archsubdir = "'"$archsubdir"'"
78 flags = "-g -S -w"
79 skip = "no"
80 }
81 $1 == "/*" && $2 ~ /^lint1-/ && $NF == "*/" {
82 if ($2 == "lint1-flags:" || $2 == "lint1-extra-flags:") {
83 if ($2 == "lint1-flags:")
84 flags = ""
85 for (i = 3; i < NF; i++)
86 flags = flags " " $i
87 } else if ($2 == "lint1-only-if:") {
88 for (i = 3; i < NF; i++)
89 if (!platform_has($i))
90 skip = "yes"
91 } else if ($2 == "lint1-skip-if:") {
92 for (i = 3; i < NF; i++)
93 if (platform_has($i))
94 skip = "yes"
95 } else {
96 printf("bad lint1 comment '\''%s'\''\n", $2) > "/dev/stderr"
97 exit(1)
98 }
99 }
100
101 END {
102 printf("flags='\''%s'\''\n", flags)
103 printf("skip=%s\n", skip)
104 }
105 '
106
107 local config
108 config="$(awk "$awk" "$1")" || exit 1
109 eval "$config"
110 }
111
112 # shellcheck disable=SC2155
113 check_lint1()
114 {
115 local src="$(atf_get_srcdir)/$1"
116 local exp="${1%.c}.exp"
117 local exp_ln="${src%.c}.exp-ln"
118 local wrk_ln="${1%.c}.ln"
119 local flags=""
120 local skip=""
121
122 if [ ! -f "$exp_ln" ]; then
123 exp_ln='/dev/null'
124 wrk_ln='/dev/null'
125 fi
126
127 configure_test_case "$src" # sets 'skip' and 'flags'
128
129 if [ "$skip" = "yes" ]; then
130 atf_skip "unsuitable platform"
131 fi
132
133 # shellcheck disable=SC2086
134 atf_check -s 'exit' -o "save:$exp" \
135 "$lint1" $flags "$src" "$wrk_ln"
136 atf_check lua "$(atf_get_srcdir)/check-expect.lua" "$src"
137
138 if [ "$exp_ln" != '/dev/null' ]; then
139 atf_check -o "file:$exp_ln" cat "$wrk_ln"
140 fi
141 }
142
143 atf_init_test_cases()
144 {
145 local src name
146
147 for src in "$(atf_get_srcdir)"/*.c; do
148 src=${src##*/}
149 name=${src%.c}
150
151 atf_test_case "$name"
152 eval "${name}_head() {
153 atf_set 'require.progs' '$lint1'
154 }"
155 eval "${name}_body() {
156 check_lint1 '$name.c'
157 }"
158 atf_add_test_case "$name"
159 done
160 }
161