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