Convert the lint1 tests to atf.

Initial work from the GSoC 2008 project by Lukasz Strzygowski.
This commit is contained in:
jmmv 2010-07-18 10:11:00 +00:00
parent c205fc13c9
commit 7ce6f390a2
39 changed files with 570 additions and 2 deletions

View File

@ -1,10 +1,10 @@
# $NetBSD: Makefile,v 1.8 2010/07/13 21:13:30 jmmv Exp $
# $NetBSD: Makefile,v 1.9 2010/07/18 10:11:00 jmmv Exp $
.include <bsd.own.mk>
TESTSDIR= ${TESTSBASE}/util
TESTS_SUBDIRS= awk bzip2 config cut df grep id m4 make mtree ps sdiff sh
TESTS_SUBDIRS= awk bzip2 config cut df grep id m4 make mtree ps sdiff sh xlint
TESTS_SH= t_basename
TESTS_SH+= t_cp

View File

@ -0,0 +1,9 @@
# $NetBSD: Makefile,v 1.1 2010/07/18 10:11:01 jmmv Exp $
.include <bsd.own.mk>
TESTSDIR= ${TESTSBASE}/util/xlint
TESTS_SUBDIRS= lint1
.include <bsd.test.mk>

View File

@ -0,0 +1,48 @@
# $NetBSD: Makefile,v 1.1 2010/07/18 10:11:01 jmmv Exp $
NOMAN= # defined
.include <bsd.own.mk>
TESTSDIR= ${TESTSBASE}/util/xlint/lint1
TESTS_SH= t_integration
FILESDIR= ${TESTSDIR}
FILES= d_c99_complex_num.c
FILES+= d_alignof.c
FILES+= d_c99_for_loops.c
FILES+= d_c99_func.c
FILES+= d_c99_recursive_init.c
FILES+= d_c99_struct_init.c
FILES+= d_c99_union_init1.c
FILES+= d_c99_union_init2.c
FILES+= d_c99_union_init3.c
FILES+= d_c9x_array_init.c
FILES+= d_c9x_recursive_init.c
FILES+= d_cast_init.c
FILES+= d_cast_init2.c
FILES+= d_cast_lhs.c
FILES+= d_compound_literals1.c
FILES+= d_compound_literals2.c
FILES+= d_constant_conv1.c
FILES+= d_constant_conv2.c
FILES+= d_cvt_in_ternary.c
FILES+= d_ellipsis_in_switch.c
FILES+= d_gcc_compound_statements1.c
FILES+= d_gcc_compound_statements2.c
FILES+= d_gcc_compound_statements3.c
FILES+= d_gcc_func.c
FILES+= d_gcc_variable_array_init.c
FILES+= d_incorrect_array_size.c
FILES+= d_long_double_int.c
FILES+= d_nested_structs.c
FILES+= d_nolimit_init.c
FILES+= d_packed_structs.c
FILES+= d_shift_to_narrower_type.c
FILES+= d_type_conv1.c
FILES+= d_type_conv2.c
FILES+= d_type_conv3.c
FILES+= d_zero_sized_arrays.c
.include <bsd.test.mk>

View File

@ -0,0 +1,6 @@
/* __alignof__ */
int
main(void)
{
return __alignof__(short);
}

View File

@ -0,0 +1,7 @@
double cabs(double _Complex);
double cabs(double _Complex foo)
{
double d = __real__ foo;
return d + 0.1fi;
}

View File

@ -0,0 +1,10 @@
/* c99 for loops */
extern void foo(int);
int
main(void)
{
for (int i = 0; i < 10; i++)
foo(i);
return 0;
}

View File

@ -0,0 +1,7 @@
/* C99 __func__ */
void
foo(const char *p) {
p = __func__;
foo(p);
}

View File

@ -0,0 +1,13 @@
/* C99 recursive struct/union initialization */
struct top {
int i;
char c;
union onion {
short us;
char uc;
} u;
char *s;
} c[] = {
{ .s = "foo", .c = 'b', .u = { .uc = 'c' } },
{ .i = 1, .c = 'a', .u = { .us = 2 } },
};

View File

@ -0,0 +1,10 @@
/* C99 struct initialization */
struct {
int i;
char *s;
} c[] = {
{ .i = 2, },
{ .s = "foo" },
{ .i = 1, .s = "bar" },
{ .s = "foo", .i = -1 },
};

View File

@ -0,0 +1,8 @@
/* C99 union initialization */
union {
int i;
char *s;
} c[] = {
{ i: 1 },
{ s: "foo" }
};

View File

@ -0,0 +1,8 @@
/* C99 union initialization */
union {
int i[10];
short s;
} c[] = {
{ s: 2 },
{ i: { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 } },
};

View File

@ -0,0 +1,8 @@
/* C99 union initialization */
struct {
int i[10];
char *s;
} c[] = {
{ { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 },
"foo" },
};

View File

@ -0,0 +1,6 @@
/* C9X array initializers */
int foo[256] = {
[2] = 1,
[3] = 2,
[4 ... 5] = 3
};

View File

@ -0,0 +1,16 @@
/* C9X struct/union member init, with nested union and trailing member */
union node {
void *next;
char *data;
};
struct foo {
int b;
union node n;
int c;
};
struct foo f = {
.b = 1,
.n = { .next = 0, },
.c = 1
};

View File

@ -0,0 +1,27 @@
/* cast initialization */
typedef unsigned char u_char;
typedef unsigned int size_t;
struct sockaddr_x25 {
u_char x25_len;
u_char x25_family;
short x25_net;
char x25_addr[16];
struct x25opts {
char op_flags;
char op_psize;
char op_wsize;
char op_speed;
} x25_opts;
short x25_udlen;
char x25_udata[16];
};
struct sockaddr_x25 x25_dgmask = {
(unsigned char)(unsigned char)(unsigned int)(unsigned long)(&((( struct sockaddr_x25 *)0)->x25_udata[1])) ,
0,
0,
{-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
{0, 0, 0, 0},
-1,
{-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
};

View File

@ -0,0 +1,7 @@
/* cast initialization as the rhs of a - operand */
struct sockaddr_dl {
char sdl_data[2];
};
int npdl_datasize = sizeof(struct sockaddr_dl) -
((int) ((unsigned long)&((struct sockaddr_dl *) 0)->sdl_data[0]));

View File

@ -0,0 +1,7 @@
/* pointer casts are valid lhs lvalues */
struct sockaddr { };
void
foo() {
unsigned long p = 6;
((struct sockaddr *)p) = 0;
}

View File

@ -0,0 +1,11 @@
/* compound literals */
struct p {
short a, b, c, d;
};
foo()
{
struct p me = (struct p) {1, 2, 3, 4};
me.a = me.b;
}

View File

@ -0,0 +1,18 @@
/* compound literals */
struct p {
short a, b, c, d;
} zz = {
1, 2, 3, 4
};
struct p *bar(int i)
{
static struct p q[10];
return &q[i];
}
foo()
{
*bar(1) = (struct p) { 1, 2, 3, 4 };
}

View File

@ -0,0 +1,9 @@
/* Flag information-losing constant conversion in argument lists */
int f(unsigned int);
void
should_fail()
{
f(-1);
}

View File

@ -0,0 +1,9 @@
/* Flag information-losing constant conversion in argument lists */
int f(unsigned int);
void
should_fail()
{
f(2.1);
}

View File

@ -0,0 +1,13 @@
/* CVT node handling in ?: operator */
typedef unsigned long int size_t;
struct filecore_direntry {
unsigned len:32;
};
int
main(void)
{
struct filecore_direntry dirent = { 0 };
size_t uio_resid = 0;
size_t bytelen = (((dirent.len)<(uio_resid))?(dirent.len):(uio_resid));
return bytelen;
}

View File

@ -0,0 +1,11 @@
int x(void)
{
int i = 33;
switch (i) {
case 1 ... 40:
break;
default:
break;
}
return 0;
}

View File

@ -0,0 +1,7 @@
/* GCC compound statements */
foo(unsigned long z)
{
z = ({ unsigned long tmp; tmp = 1; tmp; });
foo(z);
}

View File

@ -0,0 +1,14 @@
/* GCC compound statements with non-expressions */
struct cpu_info {
int bar;
};
int
main(void)
{
return ({
struct cpu_info *__ci;
__asm__ volatile("movl %%fs:4,%0":"=r" (__ci));
__ci;
})->bar;
}

View File

@ -0,0 +1,10 @@
/* GCC compound statements with void type */
void
main(void)
{
({
void *v;
__asm__ volatile("noop");
});
}

View File

@ -0,0 +1,7 @@
/* gcc __FUNCTION__ */
void
foo(const char *p) {
p = __FUNCTION__;
foo(p);
}

View File

@ -0,0 +1,7 @@
/* gcc: variable array initializer */
void foo(int i)
{
int array[i];
while (i--)
foo(array[i] = 0);
}

View File

@ -0,0 +1,3 @@
struct foo {
int a[-1];
};

View File

@ -0,0 +1,7 @@
/* PR 39639: writing "long double" gave "long int" */
int
fail(long double *a, long int *b)
{
return a == b;
}

View File

@ -0,0 +1,21 @@
/* Nested struct */
typedef void *EditLine;
typedef void *History;
typedef struct {
EditLine *el;
History *hist;
} el_mode_t;
struct el_modes_s {
el_mode_t command;
el_mode_t string;
el_mode_t filec;
el_mode_t mime_enc;
};
struct el_modes_s elm = {
.command = { .el = 0, .hist = 0, },
.string = { .el = 0, .hist = 0, },
.filec = { .el = 0, .hist = 0, },
};

View File

@ -0,0 +1,4 @@
/* no limit initializers */
char foo[][4] = {
"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"
};

View File

@ -0,0 +1,35 @@
/* packed tests */
struct in_addr {
int x;
};
struct ip_timestamp {
char ipt_code;
char ipt_len;
char ipt_ptr;
unsigned int ipt_flg:4,
ipt_oflw:4;
union ipt_timestamp {
int ipt_time[1];
struct ipt_ta {
struct in_addr ipt_addr;
int ipt_time;
} ipt_ta[1] __packed;
} ipt_timestamp __packed;
} __packed;
typedef struct __packed {
int x;
} t;
struct x {
char c;
long l;
} __packed;
struct y {
char c;
long l;
};
int a[sizeof(struct y) - sizeof(struct x) - 1];

View File

@ -0,0 +1,24 @@
// Test that type shifts that result to narrower types don't produce warnings.
void
foo(void) {
unsigned long l = 100;
unsigned long long ll = 100;
unsigned int i = 100;
unsigned short s = 100;
unsigned char c = 1;
l = ll >> 32;
// i = ll >> 31;
i = ll >> 32;
s = ll >> 48;
c = ll >> 56;
s = i >> 16;
c = i >> 24;
c = s >> 8;
(void)&ll;
(void)&l;
(void)&i;
(void)&s;
(void)&c;
}

View File

@ -0,0 +1,11 @@
/* Flag information-losing type conversion in argument lists */
int f(unsigned int);
void
should_fail()
{
long long x = 20;
f(x);
}

View File

@ -0,0 +1,11 @@
/* Flag information-losing type conversion in argument lists */
int f(float);
void
should_fail()
{
double x = 2.0;
f(x);
}

View File

@ -0,0 +1,10 @@
/* Flag information-losing type conversion in argument lists */
int f(unsigned int);
void
should_fail()
{
f(0x7fffffffffffffffLL);
}

View File

@ -0,0 +1,3 @@
struct foo {
int a[0];
};

View File

@ -0,0 +1,126 @@
# $NetBSD: t_integration.sh,v 1.1 2010/07/18 10:11:01 jmmv Exp $
#
# Copyright (c) 2008, 2010 The NetBSD Foundation, Inc.
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
#
LINT1=/usr/libexec/lint1
Names=
check_valid()
{
atf_check -s exit:0 ${LINT1} -g -S "$(atf_get_srcdir)/$1" /dev/null
}
check_invalid()
{
atf_check -s not-exit:0 -o ignore -e ignore ${LINT1} -g -S -w \
"$(atf_get_srcdir)/$1" /dev/null
}
test_case()
{
local result="${1}"; shift
local name="${1}"; shift
local descr="${*}"
atf_test_case ${name}
eval "${name}_head() {
atf_set \"descr\" \"${descr}\";
}"
eval "${name}_body() {
${result} d_${name}.c;
}"
Names="${Names} ${name}"
}
test_case check_valid c99_struct_init "Checks C99 struct initialization"
test_case check_valid c99_union_init1 "Checks C99 union initialization"
test_case check_valid c99_union_init2 "Checks C99 union initialization"
test_case check_valid c99_union_init3 "Checks C99 union initialization"
test_case check_valid c99_recursive_init "Checks C99 recursive struct/union" \
"initialization"
test_case check_valid c9x_recursive_init "Checks C9X struct/union member" \
"init, with nested union and trailing member"
test_case check_valid nested_structs "Checks nested structs"
test_case check_valid packed_structs "Checks packed structs"
test_case check_valid cast_init "Checks cast initialization"
test_case check_valid cast_init2 "Checks cast initialization as the rhs of a" \
"- operand"
test_case check_valid cast_lhs "Checks whether pointer casts are valid lhs" \
"lvalues"
test_case check_valid gcc_func "Checks GCC __FUNCTION__"
test_case check_valid c99_func "Checks C99 __func__"
test_case check_valid gcc_variable_array_init "Checks GCC variable array" \
"initializers"
test_case check_valid c9x_array_init "Checks C9X array initializers"
test_case check_valid nolimit_init "Checks no limit initializers"
test_case check_valid zero_sized_arrays "Checks zero sized arrays"
test_case check_valid compound_literals1 "Checks compound literals"
test_case check_valid compound_literals2 "Checks compound literals"
test_case check_valid gcc_compound_statements1 "Checks GCC compound statements"
test_case check_valid gcc_compound_statements2 "Checks GCC compound" \
"statements with non-expressions"
test_case check_valid gcc_compound_statements3 "Checks GCC compound" \
"statements with void type"
test_case check_valid cvt_in_ternary "Checks CVT nodes handling in ?" \
"operator"
test_case check_valid ellipsis_in_switch "Checks ellipsis in switch()"
test_case check_valid c99_complex_num "Checks C99 complex numbers"
test_case check_valid c99_for_loops "Checks C99 for loops"
test_case check_valid alignof "Checks __alignof__"
test_case check_valid shift_to_narrower_type "Checks that type shifts that" \
"result in narrower types do not produce warnings"
test_case check_invalid constant_conv1 "Checks failing on information-losing" \
"constant conversion in argument lists"
test_case check_invalid constant_conv2 "Checks failing on information-losing" \
"constant conversion in argument lists"
test_case check_invalid type_conv1 "Checks failing on information-losing" \
"type conversion in argument lists"
test_case check_invalid type_conv2 "Checks failing on information-losing" \
"type conversion in argument lists"
test_case check_invalid type_conv3 "Checks failing on information-losing" \
"type conversion in argument lists"
test_case check_invalid incorrect_array_size "Checks failing on incorrect" \
"array sizes"
test_case check_invalid long_double_int "Checks for confusion of 'long" \
"double' with 'long int'; PR 39639"
atf_init_test_cases()
{
for name in ${Names}; do
atf_add_test_case ${name}
done
}