t_integration.sh revision 1.33 1 1.33 rillig # $NetBSD: t_integration.sh,v 1.33 2021/03/07 19:42:54 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.1 jruoho LINT1=/usr/libexec/lint1
29 1.1 jruoho
30 1.1 jruoho Names=
31 1.1 jruoho
32 1.25 rillig extract_flags()
33 1.25 rillig {
34 1.25 rillig local extract_flags_awk
35 1.25 rillig
36 1.25 rillig # shellcheck disable=SC2016
37 1.25 rillig extract_flags_awk='
38 1.25 rillig BEGIN {
39 1.25 rillig flags = "-g -S -w"
40 1.25 rillig }
41 1.25 rillig /^\/\* (lint1-flags|lint1-extra-flags): .*\*\/$/ {
42 1.25 rillig if ($2 == "lint1-flags:")
43 1.25 rillig flags = ""
44 1.25 rillig for (i = 3; i < NF; i++)
45 1.25 rillig flags = flags " " $i
46 1.25 rillig }
47 1.25 rillig END {
48 1.25 rillig print flags
49 1.25 rillig }
50 1.25 rillig '
51 1.25 rillig
52 1.25 rillig awk "$extract_flags_awk" "$@"
53 1.25 rillig }
54 1.25 rillig
55 1.25 rillig # shellcheck disable=SC2155
56 1.9 rillig check_lint1()
57 1.1 jruoho {
58 1.6 rillig local src="$(atf_get_srcdir)/$1"
59 1.6 rillig local exp="${src%.c}.exp"
60 1.25 rillig local flags="$(extract_flags "${src}")"
61 1.6 rillig
62 1.9 rillig if [ -f "${exp}" ]; then
63 1.25 rillig # shellcheck disable=SC2086
64 1.9 rillig atf_check -s not-exit:0 -o "file:${exp}" -e empty \
65 1.25 rillig ${LINT1} ${flags} "${src}" /dev/null
66 1.9 rillig else
67 1.25 rillig # shellcheck disable=SC2086
68 1.9 rillig atf_check -s exit:0 \
69 1.25 rillig ${LINT1} ${flags} "${src}" /dev/null
70 1.9 rillig fi
71 1.1 jruoho }
72 1.1 jruoho
73 1.1 jruoho test_case()
74 1.1 jruoho {
75 1.1 jruoho local name="${1}"; shift
76 1.1 jruoho local descr="${*}"
77 1.1 jruoho
78 1.1 jruoho atf_test_case ${name}
79 1.1 jruoho eval "${name}_head() {
80 1.11 rillig if [ \"${descr}\" ]; then
81 1.11 rillig atf_set \"descr\" \"${descr}\"
82 1.11 rillig fi
83 1.9 rillig atf_set \"require.progs\" \"${LINT1}\"
84 1.1 jruoho }"
85 1.1 jruoho eval "${name}_body() {
86 1.9 rillig check_lint1 d_${name}.c
87 1.1 jruoho }"
88 1.1 jruoho
89 1.1 jruoho Names="${Names} ${name}"
90 1.1 jruoho }
91 1.1 jruoho
92 1.11 rillig test_case bltinoffsetof
93 1.11 rillig test_case c99_anon_struct
94 1.11 rillig test_case c99_anon_union
95 1.22 rillig test_case c99_bool
96 1.23 rillig test_case c99_bool_strict
97 1.27 rillig test_case c99_bool_strict_syshdr
98 1.11 rillig test_case c99_compound_literal_comma
99 1.11 rillig test_case c99_decls_after_stmt2
100 1.11 rillig test_case c99_flex_array_packed
101 1.30 rillig test_case c99_init
102 1.11 rillig test_case c99_nested_struct
103 1.11 rillig test_case c99_union_cast
104 1.11 rillig test_case c99_union_init4
105 1.31 rillig test_case c99_union_init5
106 1.11 rillig test_case cast_fun_array_param
107 1.11 rillig test_case cast_typeof
108 1.13 rillig test_case decl_old_style_arguments
109 1.15 rillig test_case fold_test
110 1.11 rillig test_case gcc_extension
111 1.17 rillig test_case init_pop_member
112 1.24 rillig test_case lint_assert
113 1.16 rillig test_case return_type
114 1.11 rillig test_case type_question_colon
115 1.11 rillig test_case typefun
116 1.11 rillig test_case typename_as_var
117 1.11 rillig
118 1.12 rillig test_case c99_struct_init
119 1.12 rillig test_case c99_union_init1
120 1.12 rillig test_case c99_union_init2
121 1.12 rillig test_case c99_union_init3
122 1.14 rillig test_case c99_recursive_init
123 1.14 rillig test_case c9x_recursive_init
124 1.12 rillig test_case nested_structs
125 1.12 rillig test_case packed_structs
126 1.32 rillig test_case pr_22119
127 1.14 rillig test_case struct_init_nested
128 1.10 rillig
129 1.12 rillig test_case cast_init
130 1.10 rillig test_case cast_init2 "Checks cast initialization as the rhs of a" \
131 1.10 rillig "- operand"
132 1.10 rillig test_case cast_lhs "Checks whether pointer casts are valid lhs" \
133 1.10 rillig "lvalues"
134 1.1 jruoho
135 1.10 rillig test_case gcc_func "Checks GCC __FUNCTION__"
136 1.10 rillig test_case c99_func "Checks C99 __func__"
137 1.1 jruoho
138 1.9 rillig test_case gcc_variable_array_init "Checks GCC variable array initializers"
139 1.12 rillig test_case c9x_array_init
140 1.12 rillig test_case c99_decls_after_stmt
141 1.12 rillig test_case c99_decls_after_stmt3
142 1.10 rillig test_case nolimit_init "Checks no limit initializers"
143 1.12 rillig test_case zero_sized_arrays
144 1.9 rillig
145 1.12 rillig test_case compound_literals1
146 1.12 rillig test_case compound_literals2
147 1.12 rillig test_case gcc_compound_statements1
148 1.10 rillig test_case gcc_compound_statements2 "Checks GCC compound statements with" \
149 1.10 rillig "non-expressions"
150 1.10 rillig test_case gcc_compound_statements3 "Checks GCC compound statements with" \
151 1.10 rillig "void type"
152 1.4 christos # XXX: Because of polymorphic __builtin_isnan and expression has null effect
153 1.9 rillig # test_case gcc_extension "Checks GCC __extension__ and __typeof__"
154 1.1 jruoho
155 1.10 rillig test_case cvt_in_ternary "Checks CVT nodes handling in ?"
156 1.10 rillig test_case cvt_constant "Checks constant conversion"
157 1.10 rillig test_case ellipsis_in_switch "Checks ellipsis in switch()"
158 1.10 rillig test_case c99_complex_num "Checks C99 complex numbers"
159 1.10 rillig test_case c99_complex_split "Checks C99 complex access"
160 1.12 rillig test_case c99_for_loops
161 1.10 rillig test_case alignof "Checks __alignof__"
162 1.10 rillig test_case shift_to_narrower_type "Checks that type shifts that result in" \
163 1.10 rillig "narrower types do not produce warnings"
164 1.10 rillig
165 1.10 rillig test_case constant_conv1 "Checks failing on information-losing" \
166 1.10 rillig "constant conversion in argument lists"
167 1.10 rillig test_case constant_conv2 "Checks failing on information-losing" \
168 1.10 rillig "constant conversion in argument lists"
169 1.10 rillig
170 1.10 rillig test_case type_conv1 "Checks failing on information-losing" \
171 1.10 rillig "type conversion in argument lists"
172 1.10 rillig test_case type_conv2 "Checks failing on information-losing" \
173 1.10 rillig "type conversion in argument lists"
174 1.10 rillig test_case type_conv3 "Checks failing on information-losing" \
175 1.10 rillig "type conversion in argument lists"
176 1.1 jruoho
177 1.14 rillig test_case incorrect_array_size
178 1.1 jruoho
179 1.10 rillig test_case long_double_int "Checks for confusion of 'long double' with" \
180 1.10 rillig "'long int'; PR bin/39639"
181 1.1 jruoho
182 1.18 rillig test_case all_messages
183 1.28 rillig all_messages_body()
184 1.28 rillig {
185 1.20 rillig local srcdir ok msg base flags
186 1.18 rillig
187 1.18 rillig srcdir="$(atf_get_srcdir)"
188 1.20 rillig ok="true"
189 1.18 rillig
190 1.33 rillig for msg in $(seq 0 340); do
191 1.18 rillig base="$(printf '%s/msg_%03d' "${srcdir}" "${msg}")"
192 1.25 rillig flags="$(extract_flags "${base}.c")"
193 1.18 rillig
194 1.19 rillig # shellcheck disable=SC2154 disable=SC2086
195 1.18 rillig ${Atf_Check} -s not-exit:0 -o "file:${base}.exp" -e empty \
196 1.19 rillig ${LINT1} ${flags} "${base}.c" /dev/null \
197 1.20 rillig || ok="false"
198 1.18 rillig done
199 1.20 rillig
200 1.20 rillig atf_check "${ok}"
201 1.18 rillig }
202 1.18 rillig
203 1.18 rillig
204 1.1 jruoho atf_init_test_cases()
205 1.1 jruoho {
206 1.1 jruoho for name in ${Names}; do
207 1.1 jruoho atf_add_test_case ${name}
208 1.1 jruoho done
209 1.1 jruoho }
210