t_integration.sh revision 1.58 1 1.58 rillig # $NetBSD: t_integration.sh,v 1.58 2021/06/27 09:22:31 rillig Exp $
2 1.1 jruoho #
3 1.1 jruoho # Copyright (c) 2008, 2010 The NetBSD Foundation, Inc.
4 1.1 jruoho # All rights reserved.
5 1.1 jruoho #
6 1.1 jruoho # Redistribution and use in source and binary forms, with or without
7 1.1 jruoho # modification, are permitted provided that the following conditions
8 1.1 jruoho # are met:
9 1.1 jruoho # 1. Redistributions of source code must retain the above copyright
10 1.1 jruoho # notice, this list of conditions and the following disclaimer.
11 1.1 jruoho # 2. Redistributions in binary form must reproduce the above copyright
12 1.1 jruoho # notice, this list of conditions and the following disclaimer in the
13 1.1 jruoho # documentation and/or other materials provided with the distribution.
14 1.1 jruoho #
15 1.1 jruoho # THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
16 1.1 jruoho # ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
17 1.1 jruoho # TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
18 1.1 jruoho # PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
19 1.1 jruoho # BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20 1.1 jruoho # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21 1.1 jruoho # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22 1.1 jruoho # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23 1.1 jruoho # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24 1.1 jruoho # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25 1.1 jruoho # POSSIBILITY OF SUCH DAMAGE.
26 1.1 jruoho #
27 1.1 jruoho
28 1.51 rillig lint1=/usr/libexec/lint1
29 1.51 rillig
30 1.51 rillig test_case_names=
31 1.1 jruoho
32 1.1 jruoho
33 1.25 rillig extract_flags()
34 1.25 rillig {
35 1.25 rillig local extract_flags_awk
36 1.25 rillig
37 1.25 rillig # shellcheck disable=SC2016
38 1.25 rillig extract_flags_awk='
39 1.25 rillig BEGIN {
40 1.25 rillig flags = "-g -S -w"
41 1.25 rillig }
42 1.25 rillig /^\/\* (lint1-flags|lint1-extra-flags): .*\*\/$/ {
43 1.25 rillig if ($2 == "lint1-flags:")
44 1.25 rillig flags = ""
45 1.25 rillig for (i = 3; i < NF; i++)
46 1.25 rillig flags = flags " " $i
47 1.25 rillig }
48 1.25 rillig END {
49 1.25 rillig print flags
50 1.25 rillig }
51 1.25 rillig '
52 1.25 rillig
53 1.25 rillig awk "$extract_flags_awk" "$@"
54 1.25 rillig }
55 1.25 rillig
56 1.25 rillig # shellcheck disable=SC2155
57 1.9 rillig check_lint1()
58 1.1 jruoho {
59 1.6 rillig local src="$(atf_get_srcdir)/$1"
60 1.6 rillig local exp="${src%.c}.exp"
61 1.58 rillig local exp_ln="${src%.c}.ln"
62 1.43 rillig local wrk_ln="${1%.c}.ln"
63 1.51 rillig local flags="$(extract_flags "$src")"
64 1.6 rillig
65 1.58 rillig if [ ! -f "$exp_ln" ]; then
66 1.58 rillig exp_ln='/dev/null'
67 1.51 rillig wrk_ln='/dev/null'
68 1.43 rillig fi
69 1.43 rillig
70 1.51 rillig if [ -f "$exp" ]; then
71 1.25 rillig # shellcheck disable=SC2086
72 1.51 rillig atf_check -s not-exit:0 -o "file:$exp" -e empty \
73 1.51 rillig "$lint1" $flags "$src" "$wrk_ln"
74 1.9 rillig else
75 1.25 rillig # shellcheck disable=SC2086
76 1.9 rillig atf_check -s exit:0 \
77 1.51 rillig "$lint1" $flags "$src" "$wrk_ln"
78 1.43 rillig fi
79 1.43 rillig
80 1.51 rillig if [ "$src_ln" != '/dev/null' ]; then
81 1.58 rillig atf_check -o "file:$exp_ln" cat "$wrk_ln"
82 1.9 rillig fi
83 1.1 jruoho }
84 1.1 jruoho
85 1.1 jruoho test_case()
86 1.1 jruoho {
87 1.51 rillig local name="$1"
88 1.1 jruoho
89 1.51 rillig atf_test_case "$name"
90 1.1 jruoho eval "${name}_head() {
91 1.51 rillig atf_set 'require.progs' '$lint1'
92 1.1 jruoho }"
93 1.1 jruoho eval "${name}_body() {
94 1.51 rillig check_lint1 '$name.c'
95 1.1 jruoho }"
96 1.1 jruoho
97 1.51 rillig test_case_names="$test_case_names $name"
98 1.1 jruoho }
99 1.1 jruoho
100 1.51 rillig
101 1.52 rillig test_case all_messages
102 1.57 rillig test_case c99_init_designator
103 1.52 rillig test_case d_alignof
104 1.35 rillig test_case d_bltinoffsetof
105 1.35 rillig test_case d_c99_anon_struct
106 1.35 rillig test_case d_c99_anon_union
107 1.35 rillig test_case d_c99_bool
108 1.35 rillig test_case d_c99_bool_strict
109 1.35 rillig test_case d_c99_bool_strict_syshdr
110 1.52 rillig test_case d_c99_complex_num
111 1.52 rillig test_case d_c99_complex_split
112 1.35 rillig test_case d_c99_compound_literal_comma
113 1.52 rillig test_case d_c99_decls_after_stmt
114 1.35 rillig test_case d_c99_decls_after_stmt2
115 1.52 rillig test_case d_c99_decls_after_stmt3
116 1.35 rillig test_case d_c99_flex_array_packed
117 1.52 rillig test_case d_c99_for_loops
118 1.52 rillig test_case d_c99_func
119 1.35 rillig test_case d_c99_init
120 1.35 rillig test_case d_c99_nested_struct
121 1.52 rillig test_case d_c99_recursive_init
122 1.52 rillig test_case d_c99_struct_init
123 1.35 rillig test_case d_c99_union_cast
124 1.52 rillig test_case d_c99_union_init1
125 1.52 rillig test_case d_c99_union_init2
126 1.52 rillig test_case d_c99_union_init3
127 1.35 rillig test_case d_c99_union_init4
128 1.35 rillig test_case d_c99_union_init5
129 1.52 rillig test_case d_c9x_array_init
130 1.52 rillig test_case d_c9x_recursive_init
131 1.35 rillig test_case d_cast_fun_array_param
132 1.52 rillig test_case d_cast_init
133 1.52 rillig test_case d_cast_init2
134 1.52 rillig test_case d_cast_lhs
135 1.35 rillig test_case d_cast_typeof
136 1.52 rillig test_case d_compound_literals1
137 1.52 rillig test_case d_compound_literals2
138 1.52 rillig test_case d_constant_conv1
139 1.52 rillig test_case d_constant_conv2
140 1.52 rillig test_case d_cvt_constant
141 1.52 rillig test_case d_cvt_in_ternary
142 1.35 rillig test_case d_decl_old_style_arguments
143 1.52 rillig test_case d_ellipsis_in_switch
144 1.35 rillig test_case d_fold_test
145 1.52 rillig test_case d_gcc_compound_statements1
146 1.52 rillig test_case d_gcc_compound_statements2
147 1.52 rillig test_case d_gcc_compound_statements3
148 1.35 rillig test_case d_gcc_extension
149 1.52 rillig test_case d_gcc_func
150 1.52 rillig test_case d_gcc_variable_array_init
151 1.52 rillig test_case d_incorrect_array_size
152 1.35 rillig test_case d_init_array_using_string
153 1.35 rillig test_case d_init_pop_member
154 1.35 rillig test_case d_lint_assert
155 1.52 rillig test_case d_long_double_int
156 1.35 rillig test_case d_nested_structs
157 1.52 rillig test_case d_nolimit_init
158 1.35 rillig test_case d_packed_structs
159 1.35 rillig test_case d_pr_22119
160 1.52 rillig test_case d_return_type
161 1.52 rillig test_case d_shift_to_narrower_type
162 1.35 rillig test_case d_struct_init_nested
163 1.36 rillig test_case d_type_conv1
164 1.36 rillig test_case d_type_conv2
165 1.36 rillig test_case d_type_conv3
166 1.52 rillig test_case d_type_question_colon
167 1.52 rillig test_case d_typefun
168 1.52 rillig test_case d_typename_as_var
169 1.52 rillig test_case d_zero_sized_arrays
170 1.54 rillig test_case decl_struct_member
171 1.43 rillig test_case emit
172 1.49 rillig test_case expr_range
173 1.51 rillig test_case feat_stacktrace
174 1.45 rillig test_case gcc_attribute
175 1.46 rillig test_case gcc_attribute_aligned
176 1.47 rillig test_case gcc_bit_field_types
177 1.42 rillig test_case gcc_init_compound_literal
178 1.44 rillig test_case gcc_typeof_after_statement
179 1.53 rillig test_case lex_char
180 1.56 rillig test_case lex_comment
181 1.53 rillig test_case lex_floating
182 1.53 rillig test_case lex_integer
183 1.53 rillig test_case lex_string
184 1.53 rillig test_case lex_wide_char
185 1.53 rillig test_case lex_wide_string
186 1.38 rillig test_case op_colon
187 1.55 rillig test_case stmt_for
188 1.38 rillig
189 1.28 rillig all_messages_body()
190 1.28 rillig {
191 1.37 rillig local failed msg
192 1.18 rillig
193 1.37 rillig failed=""
194 1.18 rillig
195 1.50 rillig for msg in $(seq 0 344); do
196 1.51 rillig name="$(printf 'msg_%03d.c' "$msg")"
197 1.51 rillig check_lint1 "$name" \
198 1.37 rillig || failed="$failed${failed:+ }$name"
199 1.18 rillig done
200 1.20 rillig
201 1.37 rillig if [ "$failed" != "" ]; then
202 1.37 rillig atf_check "false" "$failed"
203 1.37 rillig fi
204 1.18 rillig }
205 1.18 rillig
206 1.18 rillig
207 1.1 jruoho atf_init_test_cases()
208 1.1 jruoho {
209 1.51 rillig for name in $test_case_names; do
210 1.51 rillig atf_add_test_case "$name"
211 1.1 jruoho done
212 1.1 jruoho }
213