Home | History | Annotate | Line # | Download | only in lint1
t_integration.sh revision 1.80
      1 # $NetBSD: t_integration.sh,v 1.80 2023/05/22 20:11:24 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 : "${archsubdir:=archsubdir_must_be_set}"
     30 
     31 
     32 configure_test_case()
     33 {
     34 	local awk
     35 
     36 	# shellcheck disable=SC2016
     37 	awk='
     38 		BEGIN {
     39 			# see ./gen-platforms.sh
     40 			platform["aarch64"]	= "uchar lp64  long ldbl-128"
     41 			platform["alpha"]	= "schar lp64  long ldbl-64"
     42 			platform["arm"]		= "uchar ilp32 long ldbl-64"
     43 			platform["coldfire"]	= "schar ilp32 int  ldbl-64"
     44 			platform["hppa"]	= "schar ilp32 long ldbl-64"
     45 			platform["i386"]	= "schar ilp32 int  ldbl-96"
     46 			platform["ia64"]	= "schar lp64  long ldbl-128"
     47 			platform["m68000"]	= "schar ilp32 int  ldbl-64"
     48 			platform["m68k"]	= "schar ilp32 int  ldbl-96"
     49 			platform["mips"]	= "schar ilp32 ???? ldbl-64"
     50 			platform["mips64"]	= "schar ilp32 long ldbl-128"
     51 			platform["mipsn64"]	= "schar lp64  long ldbl-128"
     52 			platform["or1k"]	= "schar ilp32 int  ldbl-64"
     53 			platform["powerpc"]	= "uchar ilp32 int  ldbl-64"
     54 			platform["powerpc64"]	= "uchar lp64  long ldbl-64"
     55 			platform["riscv32"]	= "schar ilp32 int  ldbl-64"
     56 			platform["riscv64"]	= "schar lp64  long ldbl-64"
     57 			platform["sh3"]		= "schar ilp32 int  ldbl-64"
     58 			platform["sparc"]	= "schar ilp32 long ldbl-64"
     59 			platform["sparc64"]	= "schar lp64  long ldbl-128"
     60 			platform["vax"]		= "schar ilp32 long ldbl-64"
     61 			platform["x86_64"]	= "schar lp64  long ldbl-128"
     62 		}
     63 
     64 		function platform_has(prop) {
     65 			if (platform[prop] != "")
     66 				return prop == archsubdir
     67 			if (!match(prop, /^(schar|uchar|ilp32|lp64|int|long|ldbl-64|ldbl-96|ldbl-128)$/)) {
     68 				printf("bad property '\''%s'\''\n", prop) > "/dev/stderr"
     69 				exit(1)
     70 			}
     71 			if (platform[archsubdir] == "") {
     72 				printf("bad archsubdir '\''%s'\''\n", archsubdir) > "/dev/stderr"
     73 				exit(1)
     74 			}
     75 			return match(" " platform[archsubdir] " ", " " prop " ")
     76 		}
     77 
     78 		BEGIN {
     79 			archsubdir = "'"$archsubdir"'"
     80 			flags = "-g -S -w"
     81 			skip = "no"
     82 		}
     83 		$1 == "/*" && $2 ~ /^lint1-/ && $NF == "*/" {
     84 			if ($2 == "lint1-flags:" || $2 == "lint1-extra-flags:") {
     85 				if ($2 == "lint1-flags:")
     86 					flags = ""
     87 				for (i = 3; i < NF; i++)
     88 					flags = flags " " $i
     89 			} else if ($2 == "lint1-only-if:") {
     90 				for (i = 3; i < NF; i++)
     91 					if (!platform_has($i))
     92 						skip = "yes"
     93 			} else if ($2 == "lint1-skip-if:") {
     94 				for (i = 3; i < NF; i++)
     95 					if (platform_has($i))
     96 						skip = "yes"
     97 			} else {
     98 				printf("bad lint1 comment '\''%s'\''\n", $2) > "/dev/stderr"
     99 				exit(1)
    100 			}
    101 		}
    102 
    103 		END {
    104 			printf("flags='\''%s'\''\n", flags)
    105 			printf("skip=%s\n", skip)
    106 		}
    107 	'
    108 
    109 	local config
    110 	config="$(awk "$awk" "$1")" || exit 1
    111 	eval "$config"
    112 }
    113 
    114 # shellcheck disable=SC2155
    115 check_lint1()
    116 {
    117 	local src="$(atf_get_srcdir)/$1"
    118 	local exp="${1%.c}.exp"
    119 	local exp_ln="${src%.c}.exp-ln"
    120 	local wrk_ln="${1%.c}.ln"
    121 	local flags=""
    122 	local skip=""
    123 
    124 	if [ ! -f "$exp_ln" ]; then
    125 		exp_ln='/dev/null'
    126 		wrk_ln='/dev/null'
    127 	fi
    128 
    129 	configure_test_case "$src"	# sets 'skip' and 'flags'
    130 
    131 	if [ "$skip" = "yes" ]; then
    132 		atf_skip "unsuitable platform"
    133 	fi
    134 
    135 	# shellcheck disable=SC2086
    136 	atf_check -s 'exit' -o "save:$exp" \
    137 	    "$lint1" $flags "$src" "$wrk_ln"
    138 	atf_check lua "$(atf_get_srcdir)/check-expect.lua" "$src"
    139 
    140 	if [ "$exp_ln" != '/dev/null' ]; then
    141 		# Remove comments and whitespace from the .exp-ln file.
    142 		sed \
    143 		    -e '/^#/d' \
    144 		    -e '/^$/d' \
    145 		    -e 's,^#.*,,' \
    146 		    -e 's,\([^%]\)[[:space:]],\1,g' \
    147 		    < "$exp_ln" > "./${exp_ln##*/}"
    148 
    149 		atf_check -o "file:${exp_ln##*/}" cat "$wrk_ln"
    150 	fi
    151 }
    152 
    153 atf_init_test_cases()
    154 {
    155 	local src name
    156 
    157 	for src in "$(atf_get_srcdir)"/*.c; do
    158 		src=${src##*/}
    159 		name=${src%.c}
    160 
    161 		atf_test_case "$name"
    162 		eval "${name}_head() {
    163 			atf_set 'require.progs' '$lint1'
    164 		}"
    165 		eval "${name}_body() {
    166 			check_lint1 '$name.c'
    167 		}"
    168 		atf_add_test_case "$name"
    169 	done
    170 }
    171