t_integration.sh revision 1.58 1 # $NetBSD: t_integration.sh,v 1.58 2021/06/27 09:22:31 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
30 test_case_names=
31
32
33 extract_flags()
34 {
35 local extract_flags_awk
36
37 # shellcheck disable=SC2016
38 extract_flags_awk='
39 BEGIN {
40 flags = "-g -S -w"
41 }
42 /^\/\* (lint1-flags|lint1-extra-flags): .*\*\/$/ {
43 if ($2 == "lint1-flags:")
44 flags = ""
45 for (i = 3; i < NF; i++)
46 flags = flags " " $i
47 }
48 END {
49 print flags
50 }
51 '
52
53 awk "$extract_flags_awk" "$@"
54 }
55
56 # shellcheck disable=SC2155
57 check_lint1()
58 {
59 local src="$(atf_get_srcdir)/$1"
60 local exp="${src%.c}.exp"
61 local exp_ln="${src%.c}.ln"
62 local wrk_ln="${1%.c}.ln"
63 local flags="$(extract_flags "$src")"
64
65 if [ ! -f "$exp_ln" ]; then
66 exp_ln='/dev/null'
67 wrk_ln='/dev/null'
68 fi
69
70 if [ -f "$exp" ]; then
71 # shellcheck disable=SC2086
72 atf_check -s not-exit:0 -o "file:$exp" -e empty \
73 "$lint1" $flags "$src" "$wrk_ln"
74 else
75 # shellcheck disable=SC2086
76 atf_check -s exit:0 \
77 "$lint1" $flags "$src" "$wrk_ln"
78 fi
79
80 if [ "$src_ln" != '/dev/null' ]; then
81 atf_check -o "file:$exp_ln" cat "$wrk_ln"
82 fi
83 }
84
85 test_case()
86 {
87 local name="$1"
88
89 atf_test_case "$name"
90 eval "${name}_head() {
91 atf_set 'require.progs' '$lint1'
92 }"
93 eval "${name}_body() {
94 check_lint1 '$name.c'
95 }"
96
97 test_case_names="$test_case_names $name"
98 }
99
100
101 test_case all_messages
102 test_case c99_init_designator
103 test_case d_alignof
104 test_case d_bltinoffsetof
105 test_case d_c99_anon_struct
106 test_case d_c99_anon_union
107 test_case d_c99_bool
108 test_case d_c99_bool_strict
109 test_case d_c99_bool_strict_syshdr
110 test_case d_c99_complex_num
111 test_case d_c99_complex_split
112 test_case d_c99_compound_literal_comma
113 test_case d_c99_decls_after_stmt
114 test_case d_c99_decls_after_stmt2
115 test_case d_c99_decls_after_stmt3
116 test_case d_c99_flex_array_packed
117 test_case d_c99_for_loops
118 test_case d_c99_func
119 test_case d_c99_init
120 test_case d_c99_nested_struct
121 test_case d_c99_recursive_init
122 test_case d_c99_struct_init
123 test_case d_c99_union_cast
124 test_case d_c99_union_init1
125 test_case d_c99_union_init2
126 test_case d_c99_union_init3
127 test_case d_c99_union_init4
128 test_case d_c99_union_init5
129 test_case d_c9x_array_init
130 test_case d_c9x_recursive_init
131 test_case d_cast_fun_array_param
132 test_case d_cast_init
133 test_case d_cast_init2
134 test_case d_cast_lhs
135 test_case d_cast_typeof
136 test_case d_compound_literals1
137 test_case d_compound_literals2
138 test_case d_constant_conv1
139 test_case d_constant_conv2
140 test_case d_cvt_constant
141 test_case d_cvt_in_ternary
142 test_case d_decl_old_style_arguments
143 test_case d_ellipsis_in_switch
144 test_case d_fold_test
145 test_case d_gcc_compound_statements1
146 test_case d_gcc_compound_statements2
147 test_case d_gcc_compound_statements3
148 test_case d_gcc_extension
149 test_case d_gcc_func
150 test_case d_gcc_variable_array_init
151 test_case d_incorrect_array_size
152 test_case d_init_array_using_string
153 test_case d_init_pop_member
154 test_case d_lint_assert
155 test_case d_long_double_int
156 test_case d_nested_structs
157 test_case d_nolimit_init
158 test_case d_packed_structs
159 test_case d_pr_22119
160 test_case d_return_type
161 test_case d_shift_to_narrower_type
162 test_case d_struct_init_nested
163 test_case d_type_conv1
164 test_case d_type_conv2
165 test_case d_type_conv3
166 test_case d_type_question_colon
167 test_case d_typefun
168 test_case d_typename_as_var
169 test_case d_zero_sized_arrays
170 test_case decl_struct_member
171 test_case emit
172 test_case expr_range
173 test_case feat_stacktrace
174 test_case gcc_attribute
175 test_case gcc_attribute_aligned
176 test_case gcc_bit_field_types
177 test_case gcc_init_compound_literal
178 test_case gcc_typeof_after_statement
179 test_case lex_char
180 test_case lex_comment
181 test_case lex_floating
182 test_case lex_integer
183 test_case lex_string
184 test_case lex_wide_char
185 test_case lex_wide_string
186 test_case op_colon
187 test_case stmt_for
188
189 all_messages_body()
190 {
191 local failed msg
192
193 failed=""
194
195 for msg in $(seq 0 344); do
196 name="$(printf 'msg_%03d.c' "$msg")"
197 check_lint1 "$name" \
198 || failed="$failed${failed:+ }$name"
199 done
200
201 if [ "$failed" != "" ]; then
202 atf_check "false" "$failed"
203 fi
204 }
205
206
207 atf_init_test_cases()
208 {
209 for name in $test_case_names; do
210 atf_add_test_case "$name"
211 done
212 }
213