[BACK]Return to t_integration.sh CVS log [TXT][DIR] Up to [cvs.NetBSD.org] / src / tests / usr.bin / xlint / lint1

Annotation of src/tests/usr.bin/xlint/lint1/t_integration.sh, Revision 1.74

1.74    ! rillig      1: # $NetBSD: t_integration.sh,v 1.73 2021/10/10 18:16:12 rillig Exp $
1.1       jruoho      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:
1.51      rillig     28: lint1=/usr/libexec/lint1
1.68      rillig     29: : "${archsubdir:=archsubdir_must_be_set}"
1.1       jruoho     30:
                     31:
1.59      rillig     32: configure_test_case()
1.25      rillig     33: {
1.59      rillig     34:        local awk
1.25      rillig     35:
                     36:        # shellcheck disable=SC2016
1.59      rillig     37:        awk='
1.66      rillig     38:                BEGIN {
1.68      rillig     39:                        # see usr.bin/xlint/arch/*/targparam.h
1.72      skrll      40:                        platform["aarch64"]     = "uchar lp64  long ldbl-128"
1.66      rillig     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"
1.64      rillig     62:                }
                     63:
1.66      rillig     64:                function platform_has(prop) {
                     65:                        if (!match(prop, /^(schar|uchar|ilp32|lp64|int|long|ldbl-64|ldbl-96|ldbl-128)$/)) {
1.67      rillig     66:                                printf("bad property '\''%s'\''\n", prop) > "/dev/stderr"
                     67:                                exit(1)
1.66      rillig     68:                        }
1.68      rillig     69:                        if (platform[archsubdir] == "") {
                     70:                                printf("bad archsubdir '\''%s'\''\n", archsubdir) > "/dev/stderr"
1.67      rillig     71:                                exit(1)
1.66      rillig     72:                        }
1.68      rillig     73:                        return match(" " platform[archsubdir] " ", " " prop " ")
1.64      rillig     74:                }
                     75:
1.25      rillig     76:                BEGIN {
1.68      rillig     77:                        archsubdir = "'"$archsubdir"'"
1.25      rillig     78:                        flags = "-g -S -w"
1.67      rillig     79:                        skip = "no"
1.25      rillig     80:                }
1.64      rillig     81:                $1 == "/*" && $2 ~ /^lint1-/ && $NF == "*/" {
                     82:                        if ($2 == "lint1-flags:" || $2 == "lint1-extra-flags:") {
                     83:                                if ($2 == "lint1-flags:")
                     84:                                        flags = ""
                     85:                                for (i = 3; i < NF; i++)
                     86:                                        flags = flags " " $i
1.69      rillig     87:                        } else if ($2 == "lint1-only-if:") {
1.71      rillig     88:                                for (i = 3; i < NF; i++)
                     89:                                        if (!platform_has($i))
                     90:                                                skip = "yes"
1.69      rillig     91:                        } else if ($2 == "lint1-skip-if:") {
1.71      rillig     92:                                for (i = 3; i < NF; i++)
                     93:                                        if (platform_has($i))
                     94:                                                skip = "yes"
1.69      rillig     95:                        } else {
                     96:                                printf("bad lint1 comment '\''%s'\''\n", $2) > "/dev/stderr"
                     97:                                exit(1)
1.64      rillig     98:                        }
1.59      rillig     99:                }
1.64      rillig    100:
1.25      rillig    101:                END {
1.59      rillig    102:                        printf("flags='\''%s'\''\n", flags)
1.67      rillig    103:                        printf("skip=%s\n", skip)
1.25      rillig    104:                }
                    105:        '
                    106:
1.67      rillig    107:        local config
                    108:        config="$(awk "$awk" "$1")" || exit 1
                    109:        eval "$config"
1.25      rillig    110: }
                    111:
                    112: # shellcheck disable=SC2155
1.9       rillig    113: check_lint1()
1.1       jruoho    114: {
1.6       rillig    115:        local src="$(atf_get_srcdir)/$1"
                    116:        local exp="${src%.c}.exp"
1.63      rillig    117:        local exp_ln="${src%.c}.exp-ln"
1.43      rillig    118:        local wrk_ln="${1%.c}.ln"
1.59      rillig    119:        local flags=""
                    120:        local skip=""
1.6       rillig    121:
1.58      rillig    122:        if [ ! -f "$exp_ln" ]; then
                    123:                exp_ln='/dev/null'
1.51      rillig    124:                wrk_ln='/dev/null'
1.43      rillig    125:        fi
                    126:
1.67      rillig    127:        configure_test_case "$src"      # sets 'skip' and 'flags'
1.59      rillig    128:
                    129:        if [ "$skip" = "yes" ]; then
1.67      rillig    130:                atf_skip "unsuitable platform"
1.59      rillig    131:        fi
                    132:
1.51      rillig    133:        if [ -f "$exp" ]; then
1.25      rillig    134:                # shellcheck disable=SC2086
1.51      rillig    135:                atf_check -s not-exit:0 -o "file:$exp" -e empty \
                    136:                    "$lint1" $flags "$src" "$wrk_ln"
1.9       rillig    137:        else
1.25      rillig    138:                # shellcheck disable=SC2086
1.9       rillig    139:                atf_check -s exit:0 \
1.51      rillig    140:                    "$lint1" $flags "$src" "$wrk_ln"
1.43      rillig    141:        fi
                    142:
1.59      rillig    143:        if [ "$exp_ln" != '/dev/null' ]; then
1.58      rillig    144:                atf_check -o "file:$exp_ln" cat "$wrk_ln"
1.9       rillig    145:        fi
1.1       jruoho    146: }
                    147:
1.74    ! rillig    148: atf_test_case 'assertion_failures'
        !           149: assertion_failures_body()
        !           150: {
        !           151:        # seen in sys/external/bsd/drm2/include/linux/kref.h:73
        !           152:
        !           153:        cat <<'EOF' > input.c
        !           154: # 2 "input.c"
        !           155: void
        !           156: fn(unsigned int u)
        !           157: {
        !           158:        u = ({
        !           159:                do {} while (0);
        !           160:                u;
        !           161:        });
        !           162: }
        !           163: EOF
        !           164:
        !           165:        atf_check -s 'signal' -e 'match:lint: assertion ".*" failed' \
        !           166:            "$lint1" -gS 'input.c' '/dev/null'
        !           167: }
        !           168:
1.62      rillig    169: atf_init_test_cases()
1.1       jruoho    170: {
1.62      rillig    171:        local src name
1.18      rillig    172:
1.62      rillig    173:        for src in "$(atf_get_srcdir)"/*.c; do
                    174:                src=${src##*/}
                    175:                name=${src%.c}
                    176:
                    177:                atf_test_case "$name"
                    178:                eval "${name}_head() {
                    179:                        atf_set 'require.progs' '$lint1'
                    180:                }"
                    181:                eval "${name}_body() {
                    182:                        check_lint1 '$name.c'
                    183:                }"
1.51      rillig    184:                atf_add_test_case "$name"
1.1       jruoho    185:        done
1.74    ! rillig    186:
        !           187:        atf_add_test_case 'assertion_failures'
1.1       jruoho    188: }

CVSweb <webmaster@jp.NetBSD.org>