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