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