Bitfield without explicit sign should be a warning, not an error
Subsystems (3)
PATCH 1/6 Bitfield without explicit sign should be a warning, not an error
The -Wdefault-bitfield-sign is supposed to control a warning, just like other -W options.
---
parse.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
parse.c +1 -1
@@ -1282,7 +1282,7 @@ static struct token *handle_bitfield(struct token *token, struct symbol *decl) !(bitfield_type->ctype.modifiers & MOD_EXPLICITLY_SIGNED) && is_signed) {// The sign of bitfields is unspecified by default. -sparse_error (token->pos,"dubious bitfield without explicit `signed' or `unsigned'" ); +warning (token->pos,"dubious bitfield without explicit `signed' or `unsigned'" ); } } bitfield->bit_size = width;
PATCH 2/6 Hardcode actual type sizes, add -m32 support
Use the actual sizeof values at the compile time to describe the default target. If sparse is compiled on a 64-bit system, it will default to a 64-bit system now.
To force 32-bit operation on 64-bit systems, recognize -m32. Reject machine options other than -m32 and -m64.
---
lib.c | 13 +++++++------ target.c | 45 +++++++++++++++++++++++++++++++-------------- target.h | 6 ++++++ 3 files changed, 44 insertions(+), 20 deletions(-)
lib.c +7 -6
@@ -320,12 +320,13 @@ static char **handle_switch_M(char *arg, char **next)static char **handle_switch_m (char *arg,char **next) { -if (!strcmp (arg,"m64" )) { - bits_in_long =64 ; - max_int_alignment =8 ; - bits_in_pointer =64 ; - pointer_alignment =8 ; - } +if (!strcmp (arg,"m32" )) +target_set_m32 (); +else if (!strcmp (arg,"m64" )) +target_set_m64 (); +else +die ("unsupported machine specification: -%s" , arg); +return next; }
target.c +31 -14
66 lines not on this page · raw message
target.h +6 -0
@@ -42,4 +42,10 @@ extern int pointer_alignment;extern int bits_in_enum;extern int enum_alignment; +/* +* Functions +*/ +void target_set_m32 (void ); +void target_set_m64 (void ); +#endif
Re: [PATCH 2/6] Hardcode actual type sizes, add -m32 support
Quoted 6 lines · Pavel Roskin
Use the actual sizeof values at the compile time to describe the default target. If sparse is compiled on a 64-bit system, it will default to a 64-bit system now.
To force 32-bit operation on 64-bit systems, recognize -m32. Reject machine options other than -m32 and -m64.
NAK. That makes life very painful for cross-builds.
Re: [PATCH 2/6] Hardcode actual type sizes, add -m32 support
Quoted 9 lines · Al Viro
Quoted 6 lines · Pavel Roskin
Use the actual sizeof values at the compile time to describe the default target. If sparse is compiled on a 64-bit system, it will default to a 64-bit system now.
To force 32-bit operation on 64-bit systems, recognize -m32. Reject machine options other than -m32 and -m64.
NAK. That makes life very painful for cross-builds.
And the current approach of hard-coding all the sizes doesn't?
While I agree that I'd like a better approach (specifically, I want any Sparse build to support any target arch), I don't yet have a solution for that, and this patch does at least seem like an improvement over the current hardcoded values.
- Josh Triplett
Re: [PATCH 2/6] Hardcode actual type sizes, add -m32 support
Quoted 9 lines · Josh Triplett
Quoted 8 lines · Al Viro
Quoted 6 lines · Pavel Roskin
Use the actual sizeof values at the compile time to describe the default target. If sparse is compiled on a 64-bit system, it will default to a 64-bit system now.
To force 32-bit operation on 64-bit systems, recognize -m32. Reject machine options other than -m32 and -m64.
Quoted 8 lines
Quoted 1 line
NAK. That makes life very painful for cross-builds.
And the current approach of hard-coding all the sizes doesn't?
While I agree that I'd like a better approach (specifically, I want any Sparse build to support any target arch), I don't yet have a solution for that, and this patch does at least seem like an improvement over the current hardcoded values.
At least it guarantees behaviour that depends only on the arguments you pass to sparse and is consistent between the boxen you run sparse _on_.
FWIW, one of the pending patches in my tree makes default size_t unsigned int, switches it upon -m64 and adds explicit -msize-long for forcing the same in absense of -m64 (i.e. for 32bit target that has size_t declared as unsigned long).
The reason why it becomes needed is that with proper typechecking on comparisons we get every bloody target with size_t declared as unsigned int (i.e. practically all 32bit ones; the only exception I've seen is s390 31bit which uses unsigned long) complaining about every min((size_t)n, sizeof(v)) in the kernel - the second argument becomes sparse idea of size_t, the first one - kernel idea of size_t and safety check in min() consist of comparing pointers to types of arguments.
That rule (no m64 => size_t is unsigned int, m64 => unsigned long) gives a very good approximation and all deviations from it are for 32bit targets with unsigned long instead of unsigned int.
Having types based on the host sparse is built on is utter insanity - if anything, we need to be very careful about leaking them into sparse operations. Just take a look at what portability nightmare binutils had become due to that approach...
Re: [PATCH 2/6] Hardcode actual type sizes, add -m32 support
Quoted 1 line · Al Viro
Having types based on the host sparse is built on is utter insanity -
Definitely agree here.
Jeff
Re: [PATCH 2/6] Hardcode actual type sizes, add -m32 support
In reply to Al ViroQuoted 19 lines · Al Viro
Quoted 8 lines · Josh Triplett
Quoted 7 lines · Al Viro
Quoted 6 lines · Pavel Roskin
Use the actual sizeof values at the compile time to describe the default target. If sparse is compiled on a 64-bit system, it will default to a 64-bit system now.
To force 32-bit operation on 64-bit systems, recognize -m32. Reject machine options other than -m32 and -m64.
Quoted 7 lines
Quoted 1 line
NAK. That makes life very painful for cross-builds.
And the current approach of hard-coding all the sizes doesn't?
While I agree that I'd like a better approach (specifically, I want any Sparse build to support any target arch), I don't yet have a solution for that, and this patch does at least seem like an improvement over the current hardcoded values.
At least it guarantees behaviour that depends only on the arguments you pass to sparse and is consistent between the boxen you run sparse _on_.
[...]
Quoted 4 lines
Having types based on the host sparse is built on is utter insanity - if anything, we need to be very careful about leaking them into sparse operations. Just take a look at what portability nightmare binutils had become due to that approach...
Hmmm. OK, I buy that argument.
Quoted 4 lines
FWIW, one of the pending patches in my tree makes default
size_tunsigned int, switches it upon -m64 and adds explicit -msize-long for forcing the same in absense of -m64 (i.e. for 32bit target that hassize_tdeclared as unsigned long).
Sounds good.
- Josh Triplett
Re: [PATCH 2/6] Hardcode actual type sizes, add -m32 support
In reply to Josh TriplettQuoted 4 lines · Josh Triplett
While I agree that I'd like a better approach (specifically, I want any Sparse build to support any target arch), I don't yet have a solution for that, and this patch does at least seem like an improvement over the current hardcoded values.
That's my desire as well: My ideal sparse backend should be able to compile x86, x86-64, ppc64, ia64, arm, etc. with just a change of command line switches.
The gcc approach is just bloody awful.
Jeff
Re: [PATCH 2/6] Hardcode actual type sizes, add -m32 support
Quoted 9 lines · Jeff Garzik
Quoted 4 lines · Josh Triplett
While I agree that I'd like a better approach (specifically, I want any Sparse build to support any target arch), I don't yet have a solution for that, and this patch does at least seem like an improvement over the current hardcoded values.
That's my desire as well: My ideal sparse backend should be able to compile x86, x86-64, ppc64, ia64, arm, etc. with just a change of command line switches.
That would probably mean having some runtime-loadable files describing the architectures, as you would not want to describe the architecture with several switches.
Perhaps some machine options could be described in those files, namely whether they are acceptable and how they affect the architecture description.
Quoted 1 line
The gcc approach is just bloody awful.
Ironically, gcc specfiles do something like that. Of course, they are not sufficient to actually _compile_ the code, but they may be sufficient to verify that code.
Signature · 2 lines
Regards, Pavel Roskin
Re: [PATCH 2/6] Hardcode actual type sizes, add -m32 support
Quoted 10 lines · Pavel Roskin
Quoted 6 lines · Jeff Garzik
Quoted 4 lines · Josh Triplett
While I agree that I'd like a better approach (specifically, I want any Sparse build to support any target arch), I don't yet have a solution for that, and this patch does at least seem like an improvement over the current hardcoded values.
That's my desire as well: My ideal sparse backend should be able to compile x86, x86-64, ppc64, ia64, arm, etc. with just a change of command line switches.
That would probably mean having some runtime-loadable files describing the architectures,
Runtime-loadable, or compiled in. But in general... agreed.
Quoted 5 lines
Quoted 1 line
The gcc approach is just bloody awful.
Ironically, gcc specfiles do something like that. Of course, they are not sufficient to actually _compile_ the code, but they may be sufficient to verify that code.
I was mainly grousing about having to recompile gcc for each target, which is insanely silly.
Jeff
Re: [PATCH 2/6] Hardcode actual type sizes, add -m32 support
Quoted 7 lines · Jeff Garzik
Quoted 6 lines · Pavel Roskin
Quoted 5 lines · Jeff Garzik
Quoted 4 lines · Josh Triplett
While I agree that I'd like a better approach (specifically, I want any Sparse build to support any target arch), I don't yet have a solution for that, and this patch does at least seem like an improvement over the current hardcoded values.
Quoted 7 lines
Quoted 5 lines
Quoted 3 lines
That's my desire as well: My ideal sparse backend should be able to compile x86, x86-64, ppc64, ia64, arm, etc. with just a change of command line switches.
That would probably mean having some runtime-loadable files describing the architectures,
Runtime-loadable, or compiled in. But in general... agreed.
Yes, I definitely want the ability to compile them in.
- Josh Triplett
Re: [PATCH 2/6] Hardcode actual type sizes, add -m32 support
In reply to Jeff GarzikQuoted 11 lines · Jeff Garzik
Quoted 4 lines · Josh Triplett
While I agree that I'd like a better approach (specifically, I want any Sparse build to support any target arch), I don't yet have a solution for that, and this patch does at least seem like an improvement over the current hardcoded values.
That's my desire as well: My ideal sparse backend should be able to compile x86, x86-64, ppc64, ia64, arm, etc. with just a change of command line switches.
The gcc approach is just bloody awful.
I agree that the GCC approach to cross-compilation could use significant improvement. In particular, I'd like to just specify a set of architectures, or "all of them", at compile time, and have GCC support all of those architectures in the same GCC binary. Combined with GCC's existing "sysroot" approach to multiple architecture support, this would make cross-compilation much easier.
However, in the meantime, GCC doesn't seem to have any such thing. How do we want to implement it in Sparse? I don't think we have enough information on the GCC command line. I suppose we could allow specifying an architecture explicitly; for cgcc, we could also allow specifying the compiler name for cross-compilation and then deriving the architecture name from the compiler name if not explicitly specified.
I'd like to see much of cgcc disappear; it should do nothing except invoke GCC and Sparse, and Sparse should handle the architecture issues that cgcc currently handles.
- Josh Triplett
Re: [PATCH 2/6] Hardcode actual type sizes, add -m32 support
Quoted 6 lines · Josh Triplett
However, in the meantime, GCC doesn't seem to have any such thing. How do we want to implement it in Sparse? I don't think we have enough information on the GCC command line. I suppose we could allow specifying an architecture explicitly; for cgcc, we could also allow specifying the compiler name for cross-compilation and then deriving the architecture name from the compiler name if not explicitly specified.
Judging from existing software, "--target foo" to set the target arch should be familiar to many. If not specified, detect the current arch at runtime, and use the results of the detection as the target arch.
Jeff
Re: [PATCH 2/6] Hardcode actual type sizes, add -m32 support
Quoted 11 lines · Jeff Garzik
Quoted 6 lines · Josh Triplett
However, in the meantime, GCC doesn't seem to have any such thing. How do we want to implement it in Sparse? I don't think we have enough information on the GCC command line. I suppose we could allow specifying an architecture explicitly; for cgcc, we could also allow specifying the compiler name for cross-compilation and then deriving the architecture name from the compiler name if not explicitly specified.
Judging from existing software, "--target foo" to set the target arch should be familiar to many. If not specified, detect the current arch at runtime, and use the results of the detection as the target arch.
Sounds reasonable.
- Josh Triplett
Re: [PATCH 2/6] Hardcode actual type sizes, add -m32 support
In reply to Josh TriplettQuoted 6 lines · Josh Triplett
And the current approach of hard-coding all the sizes doesn't?
While I agree that I'd like a better approach (specifically, I want any Sparse build to support any target arch), I don't yet have a solution for that, and this patch does at least seem like an improvement over the current hardcoded values.
Another problem with this patch is that sparse is actually fed many "-m" options that it's supposed to ignore, such as "-march=nocona" on my x86_64. That's makes live painful for native builds too. So, adding strict verification was a bit premature.
Ideally, sparse should know all "-m" options it's given. I was wrong that I only tested this change on userspace programs.
So please drop the patch for now. However, this is not an attempt to stop the discussion, as it may be very useful.
Signature · 2 lines
Regards, Pavel Roskin
PATCH 3/6 cgcc: preserve sparse exit code if -no-compile is used
In reply to Pavel Roskin---
cgcc | 7 +++++-- 1 files changed, 5 insertions(+), 2 deletions(-)
cgcc +5 -2
@@ -50,8 +50,11 @@ if ($do_check) { $check .= &add_specs ('host_os_specs'); } print "$check\n" if $verbose; -# exit 1; - system ($check); + if ($do_compile) { + system ($check); + } else { + exec ($check); + } } if ($do_compile) {
Josh Triplett
AppliedRe: [PATCH 3/6] cgcc: preserve sparse exit code if -no-compile is used
Applied; thanks!
- Josh Triplett
PATCH 4/6 Avoid use of libc headers in the validation suite
In reply to Pavel RoskinWe don't want libc to affect the validation suite. Compatibility with libc headers can be checked by other means, e.g. by compiling some significant program (even sparse itself) using cgcc as the compiler.
---
validation/check_byte_count-ice.c | 2 +- validation/double-semicolon.c | 2 +- validation/test-be.c | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-)
validation/check_byte_count-ice.c +1 -1
@@ -1,4 +1,4 @@ -#include <string.h> +extern void *memset (void *s,int c,int n);static void foo (void *a) {
validation/double-semicolon.c +1 -1
@@ -1,4 +1,4 @@ -#include <string.h> +extern void *memset (void *s,int c,int n);static void test (void ) { struct { int foo;; } val;
validation/test-be.c +2 -2
@@ -1,5 +1,5 @@ -#include <stdio.h> -#include <stdlib.h> +int printf (char *c, ...); +void exit (int c);#undef PRINT_OUTPUTS
Re: [PATCH 4/6] Avoid use of libc headers in the validation suite
Quoted 3 lines · Pavel Roskin
We don't want libc to affect the validation suite. Compatibility with libc headers can be checked by other means, e.g. by compiling some significant program (even sparse itself) using cgcc as the compiler.
Agreed. Applied; thanks!
- Josh Triplett
PATCH 5/6 Fix warnings about undeclared globals, they are irrelevant to the test
In reply to Pavel Roskin---
validation/bitfields.c | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-)
validation/bitfields.c +2 -2
@@ -5,13 +5,13 @@* * "warning: a.c:16:10: incompatible types for operation" */ -struct { +static struct {int x:4 ; } y;extern int a[]; -int b (void ) +static int b (void ) {return a[y.x]; }
Josh Triplett
AppliedRe: [PATCH 5/6] Fix warnings about undeclared globals, they are irrelevant to the test
Quoted 5 lines · Pavel Roskin
Signed-off-by Pavel Roskin <[email protected]>---
validation/bitfields.c | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-)
Applied; thanks!
- Josh Triplett
PATCH 6/6 Add a simple test script, embed expected results into test files
In reply to Pavel Roskin---
validation/.gitignore | 3 + validation/address_space.c | 6 +++ validation/bad-array-designated-initializer.c | 6 +++ validation/bad-assignment.c | 5 ++ validation/bad-cast.c | 6 +++ validation/bad-ternary-cond.c | 5 ++ validation/badtype2.c | 11 +++++ validation/badtype3.c | 13 ++++++ validation/badtype4.c | 5 ++ validation/builtin_safe1.c | 12 +++++ validation/check_byte_count-ice.c | 5 ++ validation/choose_expr.c | 10 ++++ validation/cond_expr.c | 5 ++ validation/context.c | 17 +++++++ validation/foul-bitwise.c | 7 +++ validation/initializer-entry-defined-twice.c | 7 +++ validation/noderef.c | 6 +++ validation/non-pointer-null.c | 4 ++ validation/old-initializer.c | 4 ++ validation/preprocessor-loop.c | 4 ++ validation/preprocessor1.c | 5 ++ validation/preprocessor10.c | 5 ++ validation/preprocessor11.c | 12 +++++ validation/preprocessor12.c | 5 ++ validation/preprocessor13.c | 7 +++ validation/preprocessor14.c | 5 ++ validation/preprocessor15.c | 5 ++ validation/preprocessor18.c | 5 ++ validation/preprocessor19.c | 7 +++ validation/preprocessor2.c | 5 ++ validation/preprocessor20.c | 5 ++ validation/preprocessor3.c | 6 +++ validation/preprocessor4.c | 5 ++ validation/preprocessor5.c | 5 ++ validation/preprocessor7.c | 5 ++ validation/preprocessor8.c | 9 ++++ validation/preprocessor9.c | 5 ++ validation/run-tests | 58 +++++++++++++++++++++++++ 38 files changed, 300 insertions(+), 0 deletions(-)
validation/.gitignore new file +3 -0
@@ -0,0 +1,3 @@ +*.diff +*.exp +*.res
validation/address_space.c +6 -0
@@ -6,3 +6,9 @@ static int sys_do_stuff(void __user *user_addr) {return poke_memory (user_addr); } + +/* SPARSE +address_space.c:7:21: warning: incorrect type in argument 1 (different address spaces) +address_space.c:7:21: expected void *addr +address_space.c:7:21: got void *user_addr<asn:1> +SPARSE */
validation/bad-array-designated-initializer.c +6 -0
@@ -2,3 +2,9 @@ static int a[] = { [0 ] =0 ,// OK [\0] = 1, // KO }; + +/* SPARSE +bad-array-designated-initializer.c:3:3: error: Expected constant expression +bad-array-designated-initializer.c:3:3: error: Expected } at end of initializer +bad-array-designated-initializer.c:3:3: error: got \ +SPARSE */
validation/bad-assignment.c +5 -0
@@ -4,3 +4,8 @@ static int foo(int a)return a; } + +/* SPARSE +bad-assignment.c:3:6: error: Expected ; at end of statement +bad-assignment.c:3:6: error: got \ +SPARSE */
validation/bad-cast.c +6 -0
@@ -4,3 +4,9 @@ static int foo(int a) { return (struct/st *) a; } + +/* SPARSE +bad-cast.c:5:16: error: expected declaration +bad-cast.c:5:16: error: Expected ) at end of cast operator +bad-cast.c:5:16: error: got / +SPARSE */
validation/bad-ternary-cond.c +5 -0
@@ -5,3 +5,8 @@ static int foo(int a) { return a ?? 1 : 0; } + +/* SPARSE +bad-ternary-cond.c:6:12: error: Expected : in conditional expression +bad-ternary-cond.c:6:12: error: got ? +SPARSE */
validation/badtype2.c +11 -0
@@ -8,3 +8,14 @@ static undef foo(char *c)return bar (); } } + +/* SPARSE +badtype2.c:2:14: error: Expected ; at end of declaration +badtype2.c:2:14: error: got bar +badtype2.c:3:14: error: Expected ; at end of declaration +badtype2.c:3:14: error: got foo +badtype2.c:6:3: error: Trying to use reserved word 'switch' as identifier +badtype2.c:7:3: error: not in switch scope +badtype2.c:10:1: error: Expected ; end of type declaration +badtype2.c:10:1: error: got } +SPARSE */
validation/badtype3.c +13 -0
@@ -8,3 +8,16 @@ foo (int (*func) (undef, void *), void *data) }return err; } + +/* SPARSE +badtype3.c:2:19: error: Expected ) in nested declarator +badtype3.c:2:19: error: got undef +badtype3.c:5:3: error: Trying to use reserved word 'while' as identifier +badtype3.c:7:7: error: break/continue not in iterator scope +badtype3.c:9:3: error: Trying to use reserved word 'return' as identifier +badtype3.c:9:10: error: Expected ; at end of declaration +badtype3.c:9:10: error: got err +badtype3.c:10:1: error: Expected ; end of type declaration +badtype3.c:10:1: error: got } +badtype3.c:6:11: error: undefined identifier 'func' +SPARSE */
validation/badtype4.c +5 -0
@@ -5,3 +5,8 @@ void a(void)break ; } } + +/* SPARSE +badtype4.c:3:9: error: undefined identifier 'x' +badtype4.c:4:7: error: incompatible types for 'case' statement +SPARSE */
validation/builtin_safe1.c +12 -0
@@ -24,3 +24,15 @@ static int foo(int x, int y)return x; } + +/* SPARSE +builtin_safe1.c:13:3: warning: Macro argument with side effects +builtin_safe1.c:14:3: warning: Macro argument with side effects +builtin_safe1.c:15:3: warning: Macro argument with side effects +builtin_safe1.c:16:3: warning: Macro argument with side effects +builtin_safe1.c:17:3: warning: Macro argument with side effects +builtin_safe1.c:18:3: warning: Macro argument with side effects +builtin_safe1.c:19:3: warning: Macro argument with side effects +builtin_safe1.c:22:3: warning: Macro argument with side effects +builtin_safe1.c:23:3: warning: Macro argument with side effects +SPARSE */
validation/check_byte_count-ice.c +5 -0
@@ -4,3 +4,8 @@ static void foo(void *a) { memset(foo, + ', 20); } + +/* SPARSE +check_byte_count-ice.c:5:18: error: Bad character constant +check_byte_count-ice.c:5:8: error: not enough arguments for function memset +SPARSE */
validation/choose_expr.c +10 -0
@@ -2,3 +2,13 @@ static int x = __builtin_choose_expr(0,(char *)0,(void)0);static int y =__builtin_choose_expr (1 ,(char *)0 ,(void )0 );static char s[42 ];static int z =1 /(sizeof (__builtin_choose_expr (1 ,s,0 )) -42 ); + +/* SPARSE +choose_expr.c:1:51: warning: incorrect type in initializer (different types) +choose_expr.c:1:51: expected int static [signed] [toplevel] x +choose_expr.c:1:51: got void <noident> +choose_expr.c:2:41: warning: incorrect type in initializer (different base types) +choose_expr.c:2:41: expected int static [signed] [toplevel] y +choose_expr.c:2:41: got char *<noident> +choose_expr.c:4:17: warning: division by zero +SPARSE */
validation/cond_expr.c +5 -0
@@ -9,3 +9,8 @@ int a(void) {return ~(y ? : x);/* should warn */ } + +/* SPARSE +cond_expr.c:10:9: error: incompatible types for operation (~) +cond_expr.c:10:9: argument has type double +SPARSE */
validation/context.c +17 -0
@@ -314,3 +314,20 @@ static void warn_cond_lock1(void) condition2 =1 ;/* do stuff */ r (); } + +/* SPARSE +context.c:69:13: warning: context imbalance in 'warn_lock1' - wrong count at exit +context.c:74:13: warning: context imbalance in 'warn_lock2' - wrong count at exit +context.c:81:13: warning: context imbalance in 'warn_lock3' - wrong count at exit +context.c:88:13: warning: context imbalance in 'warn_unlock1' - unexpected unlock +context.c:93:13: warning: context imbalance in 'warn_unlock2' - unexpected unlock +context.c:131:12: warning: context imbalance in 'warn_if1' - wrong count at exit +context.c:140:12: warning: context imbalance in 'warn_if2' - different lock contexts for basic block +context.c:202:2: warning: context imbalance in 'warn_while1' - different lock contexts for basic block +context.c:210:3: warning: context imbalance in 'warn_while2' - unexpected unlock +context.c:216:2: warning: context imbalance in 'warn_while3' - wrong count at exit +context.c:274:13: warning: context imbalance in 'warn_goto1' - wrong count at exit +context.c:283:13: warning: context imbalance in 'warn_goto2' - wrong count at exit +context.c:300:5: warning: context imbalance in 'warn_goto3' - different lock contexts for basic block +context.c:315:5: warning: context imbalance in 'warn_cond_lock1' - different lock contexts for basic block +SPARSE */
validation/foul-bitwise.c +7 -0
@@ -18,3 +18,10 @@ static __le16 bar(__le16 a) {return -a; } + +/* SPARSE +foul-bitwise.c:9:9: warning: restricted degrades to integer +foul-bitwise.c:9:15: warning: restricted degrades to integer +foul-bitwise.c:19:9: error: incompatible types for operation (-) +foul-bitwise.c:19:9: argument has type restricted unsigned short [usertype] a +SPARSE */
validation/initializer-entry-defined-twice.c +7 -0
@@ -41,3 +41,10 @@ static struct same_offset not_an_error = { .field1 = { }, .field2 = 0 }; + +/* SPARSE +initializer-entry-defined-twice.c:10:3: error: Initializer entry defined twice +initializer-entry-defined-twice.c:11:3: also defined here +initializer-entry-defined-twice.c:26:4: error: Initializer entry defined twice +initializer-entry-defined-twice.c:27:4: also defined here +SPARSE */
validation/noderef.c +6 -0
@@ -40,3 +40,9 @@ static void h(void) r = py->a+1 ; r = &py->a[0 ]; } + +/* SPARSE +noderef.c:24:5: warning: incorrect type in assignment (different modifiers) +noderef.c:24:5: expected char *[noderef] *q2 +noderef.c:24:5: got char [noderef] **<noident> +SPARSE */
validation/non-pointer-null.c +4 -0
@@ -1 +1,5 @@static void *p =0 ; + +/* SPARSE +non-pointer-null.c:1:18: warning: Using plain integer as NULL pointer +SPARSE */
validation/old-initializer.c +4 -0
@@ -3,3 +3,7 @@ struct s { };static struct s the_s = { i:1 }; + +/* SPARSE +old-initializer.c:5:27: warning: obsolete struct initializer, use C99 syntax +SPARSE */
validation/preprocessor-loop.c +4 -0
@@ -1,2 +1,6 @@#if 1 #if + +/* SPARSE +preprocessor-loop.c:2:2: error: unterminated preprocessor conditional +SPARSE */
validation/preprocessor1.c +5 -0
@@ -12,3 +12,8 @@#define bar func(#define foo bar foo foo ) + +/* SPARSE +builtin:0:0: error: Expected ; at end of declaration +builtin:0:0: error: got end-of-input +SPARSE */
validation/preprocessor10.c +5 -0
@@ -11,3 +11,8 @@ defined#else undefined#endif + +/* SPARSE +builtin:0:0: error: Expected ; at end of declaration +builtin:0:0: error: got end-of-input +SPARSE */
validation/preprocessor11.c +12 -0
@@ -8,3 +8,15 @@ #define H(x...,y) #define I(...+#define J (x,y) + +/* SPARSE +preprocessor11.c:1:11: error: "1" may not appear in macro parameter list +preprocessor11.c:2:11: error: missing ')' in macro parameter list +preprocessor11.c:3:12: error: missing ')' in macro parameter list +preprocessor11.c:4:11: error: parameter name missing +preprocessor11.c:5:11: error: __VA_ARGS__ can only appear in the expansion of a C99 variadic macro +preprocessor11.c:6:12: error: "+" may not appear in macro parameter list +preprocessor11.c:7:12: error: missing ')' in macro parameter list +preprocessor11.c:8:12: error: missing ')' in macro parameter list +preprocessor11.c:9:11: error: missing ')' in macro parameter list +SPARSE */
validation/preprocessor12.c +5 -0
@@ -5,3 +5,8 @@ A(1) A(1,2)A (1 ,2 ,3 ) + +/* SPARSE +preprocessor12.c:5:1: error: Expected ; end of type declaration +preprocessor12.c:5:1: error: got 1 +SPARSE */
validation/preprocessor13.c +7 -0
@@ -5,3 +5,10 @@ A(1) A(1,2)A (1 ,2 ,3 ) + +/* SPARSE +preprocessor13.c:6:1: error: '##' failed: concatenation is not a valid token +preprocessor13.c:7:1: error: '##' failed: concatenation is not a valid token +preprocessor13.c:5:1: error: Expected ; end of type declaration +preprocessor13.c:5:1: error: got 1 +SPARSE */
validation/preprocessor14.c +5 -0
@@ -5,3 +5,8 @@ A(,1)#define B (x,y,...) x##,##__VA_ARGS__ B(,1) + +/* SPARSE +preprocessor14.c:5:1: error: Expected ; end of type declaration +preprocessor14.c:5:1: error: got , +SPARSE */
validation/preprocessor15.c +5 -0
@@ -5,3 +5,8 @@ #if D(A,B) BD (1 ,2 )#endif + +/* SPARSE +preprocessor15.c:6:1: error: Expected ; end of type declaration +preprocessor15.c:6:1: error: got 12 +SPARSE */
validation/preprocessor18.c +5 -0
@@ -1,3 +1,8 @@/* one warning for each, please... */ #define 1#undef 1 + +/* SPARSE +preprocessor18.c:2:2: error: expected identifier to 'define' +preprocessor18.c:3:2: error: expected identifier to 'undef' +SPARSE */
validation/preprocessor19.c +7 -0
@@ -3,3 +3,10 @@#define A x#define A yA + +/* SPARSE +preprocessor19.c:4:9: warning: preprocessor token A redefined +preprocessor19.c:3:9: this was the original definition +builtin:0:0: error: Expected ; at end of declaration +builtin:0:0: error: got end-of-input +SPARSE */
validation/preprocessor2.c +5 -0
@@ -13,3 +13,8 @@#define BINARY (x, y) x + yUNARY (TWO ) + +/* SPARSE +preprocessor2.c:15:1: error: Expected ; at end of declaration +preprocessor2.c:15:1: error: got + +SPARSE */
validation/preprocessor20.c +5 -0
@@ -2,3 +2,8 @@#define X #define Y #include "preprocessor20.h" + +/* SPARSE +preprocessor20.h:2:1: error: Expected ; at end of declaration +preprocessor20.h:2:1: error: got B +SPARSE */
validation/preprocessor3.c +6 -0
@@ -35,3 +35,9 @@ A() // B ( ) SCAN( A() ) // A ( ) SCAN(SCAN( A() )) // B ( ) SCAN(SCAN(SCAN( A() ))) // A ( ) + +/* SPARSE +preprocessor3.c:34:1: warning: non-ANSI function declaration of function 'B' +preprocessor3.c:35:1: error: Expected ; at end of declaration +preprocessor3.c:35:1: error: got A +SPARSE */
validation/preprocessor4.c +5 -0
@@ -8,3 +8,8 @@mac (foo) + +/* SPARSE +builtin:0:0: error: Expected ; at end of declaration +builtin:0:0: error: got end-of-input +SPARSE */
validation/preprocessor5.c +5 -0
@@ -7,3 +7,8 @@#define b (x) xb (a) + +/* SPARSE +preprocessor5.c:9:1: error: Expected ; at end of declaration +preprocessor5.c:9:1: error: got | +SPARSE */
validation/preprocessor7.c +5 -0
@@ -3,3 +3,8 @@#define C (x,y) E(y)#define E (y) #y A(2)) + +/* SPARSE +preprocessor7.c:5:1: error: Expected ; end of type declaration +preprocessor7.c:5:1: error: got "\"D\"" +SPARSE */
validation/preprocessor8.c +9 -0
@@ -14,3 +14,12 @@ "x#y" : E "ab GH \"G\" 12" : F(G,H) "a ## b" : I(a,##,b) + +/* SPARSE +preprocessor8.c:1:14: error: '##' cannot appear at the ends of macro expansion +preprocessor8.c:2:16: error: '##' cannot appear at the ends of macro expansion +preprocessor8.c:3:22: error: '##' cannot appear at the ends of macro expansion +preprocessor8.c:4:15: error: '#' is not followed by a macro parameter +preprocessor8.c:10:1: error: Expected ; end of type declaration +preprocessor8.c:10:1: error: got "A(x)" +SPARSE */
validation/preprocessor9.c +5 -0
@@ -8,3 +8,8 @@#define A # define X 1A X + +/* SPARSE +preprocessor9.c:9:1: error: Expected ; end of type declaration +preprocessor9.c:9:1: error: got # +SPARSE */
validation/run-tests new file +58 -0
58 lines not on this page · raw message
Re: [PATCH 6/6] Add a simple test script, embed expected results into test files
Awesome! I plan to merge this tomorrow.
I did notice a few issues. If you get to them before tomorrow then please submit an updated patch, but otherwise I will go ahead and fix them myself and apply the patch; I really want to see this go into Sparse as soon as possible.
* The files starting with "preprocessor" shouldn't run through all of Sparse, just the preprocessor (sparse -E). I've moved them to a validation/preprocessor/ subdirectory to keep them separated.
* Ideally, the test suite should support a SPARSE_FLAGS comment, so you can specify different -Wfoo options and the corresponding output. This would also handle the preprocessor tests.
validation/preprocessor1.c line 19
Quoted 13 lines · Pavel Roskin
validation/preprocessor1.c +5
-0@@ -12,3 +12,8 @@#define bar func(#define foo bar foo foo ) + +/* SPARSE +builtin:0:0: error: Expected ; at end of declaration +builtin:0:0: error: got end-of-input +SPARSE */
Errors in builtin seem strange and probably broken.
validation/preprocessor10.c defined · line 18
Quoted 13 lines
validation/preprocessor10.c +5
-0@@ -11,3 +11,8 @@ defined#else undefined#endif + +/* SPARSE +builtin:0:0: error: Expected ; at end of declaration +builtin:0:0: error: got end-of-input +SPARSE */
Ditto.
validation/preprocessor4.c line 15
Quoted 13 lines
validation/preprocessor4.c +5
-0@@ -8,3 +8,8 @@mac (foo) + +/* SPARSE +builtin:0:0: error: Expected ; at end of declaration +builtin:0:0: error: got end-of-input +SPARSE */
Ditto
Quoted 35 lines
validation/run-tests new file +29
-0@@ -0,0 +1,58 @@ +#!/bin/sh + +: ${SPARSE=../sparse} +: ${SPARSE_FLAGS=} + +# Use "--update" to update test files with the actual output +update= +if test "$1" = "--update"; then + update=1 + shift +fi + +if test -n "$1"; then + tests="$@" +else + tests=`echo *.c` +fi + +bad= +for test in $tests; do + base="`basename $test .c`" + exp="$base.exp" + res="$base.res" + diff="$base.diff" + $SPARSE $SPARSE_FLAGS "$test" 2>"$res" + if test "$?" != 0; then + echo "FATAL: $test" + bad="$bad $test" + continue
validation/run-tests line 39
Quoted 10 lines
validation/run-tests new file +10
-0+ fi + + if test -n "$update"; then + sed -i '/SPARSE/,/SPARSE/d' "$test" + if test -s "$res"; then + echo "/* SPARSE" >>"$test" + cat "$res" >>"$test" + echo " SPARSE */" >>"$test" + fi + fi
Rather than treating the absence of a SPARSE comment as meaning that the test has no output, I think I'd rather explicitly include an empty SPARSE comment in such tests, and then make the absence of a SPARSE comment an error.
Quoted 5 lines
validation/run-tests new file +5
-0+ sed -n '/SPARSE/,/SPARSE/p' "$test" |grep -v SPARSE >"$exp" + diff -u "$exp" "$res" >"$diff" + if test -s "$diff"; then + echo "FAIL: $test" + bad="$bad $test"
validation/run-tests line 55
Quoted 10 lines
validation/run-tests new file +10
-0+ continue + fi + + rm -f "$exp" "$res" "$diff" +done + +if test -n "$bad"; then + echo "Failed tests:$bad" + exit 1 +fi
How about a --verbose that prints the diffs? I'd prefer that with automated build systems, for example, so that I can immediately see the test suite failure in the logs. Also, --verbose --update should print the diffs it applies.
- Josh Triplett
Re: [PATCH 6/6] Add a simple test script, embed expected results into test files
Josh, Pavel,
I happen to have 3 patches in my tree that look like this one. I thought you might
want to have a look as they appear to handle the points you were wanting to fix. Patch 3 is a "documentation patch" that explains what I wanted to do.
I attached those patches as gmail does not allow me to answer a thread and post a patch without losing its formatting.
hope it can help in a way or another.
Signature · 1 line
Damien
From 68d040139383ef69e3d79776815844c14fa3f496 Mon Sep 17 00:00:00 2001
From: Damien Lespiau <[email protected]>
Date: Fri, 15 Jun 2007 18:54:23 +0200
Subject: [PATCH] test-suite: a tiny test automation script
This patch introduces test-suite, a simple script that makes test cases verification easier. Test cases in the validation directory are annotated and this script parses them to check if the actual result is the one expected by the test writer.
--- .gitignore | 5 + Makefile | 4 + validation/test-suite | 239 +++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 248 insertions(+), 0 deletions(-) create mode 100755 validation/test-suite
.gitignore +5 -0
@@ -32,3 +32,8 @@ patches-* patches series +# test-suite +*.diff +*.got +*.expected +
Makefile +4 -0
@@ -168,3 +168,7 @@ dist: exit 1 ; \ fi git archive --format=tar --prefix=sparse-$(VERSION)/ HEAD^{tree} | gzip -9 > sparse-$(VERSION).tar.gz + +check: all + $(Q)cd validation && ./test-suite +
validation/test-suite new file +239 -0
239 lines not on this page · raw message
Signature · 1 line
1.5.2.1.280.g38570
From 2a705ec0c1936bd1effae53184cdf4c9ff7ec73d Mon Sep 17 00:00:00 2001
From: Damien Lespiau <[email protected]>
Date: Fri, 15 Jun 2007 18:57:06 +0200
Subject: [PATCH] Sample test-suite test cases
A few examples meant to show the use of test-suite
--- validation/bad-assignment.c | 11 +++++++++++ validation/preprocessor1.c | 9 +++++++++ validation/preprocessor2.c | 9 +++++++++ validation/preprocessor3.c | 12 ++++++++++++ validation/struct-as.c | 8 ++++++++ 5 files changed, 49 insertions(+), 0 deletions(-)
validation/bad-assignment.c +11 -0
@@ -4,3 +4,14 @@ static int foo(int a)return a; } +/* +* check-name: bad assignement +* +* check-command: ../sparse $file +* check-exit-value: 1 +* +* check-output:bad-assignment.c:3:6: error: Expected ; at end of statement +* check-output:bad-assignment.c:3:6: error: got \ +* +* check-known-to-fail +*/
validation/preprocessor1.c +9 -0
@@ -12,3 +12,12 @@#define bar func(#define foo bar foo foo ) +/* +* check-name: preprocessor 1 +* +* check-command: ../sparse -E $file +* check-exit-value: 0 +* +* check-output: +* check-output:foo +*/
validation/preprocessor2.c +9 -0
@@ -13,3 +13,12 @@#define BINARY (x, y) x + yUNARY (TWO ) +/* +* check-name: preprocessor 2 +* +* check-command: ../sparse -E $file +* check-exit-value: 0 +* +* check-output: +* check-output:a + b +*/
validation/preprocessor3.c +12 -0
@@ -35,3 +35,15 @@ A() // B ( ) SCAN( A() ) // A ( ) SCAN(SCAN( A() )) // B ( ) SCAN(SCAN(SCAN( A() ))) // A ( ) +/* +* check-name: preprocessor 3 +* +* check-command: ../sparse -E $file +* check-exit-value: 0 +* +* check-output: +* check-output:B ( ) +* check-output:A ( ) +* check-output:B ( ) +* check-output:A ( ) +*/
validation/struct-as.c +8 -0
@@ -14,3 +14,11 @@ static int broken(struct hello __user *sp) {test (&sp->a); } +/* +* check-name: address space of structure members +* +* check-command: ../sparse $file +* check-exit-value: 0 +* + +*/
Signature · 1 line
1.5.2.1.280.g38570
From 22e02751dc5e29536f8e015e8c9880d26eb7b3d5 Mon Sep 17 00:00:00 2001
From: Damien Lespiau <[email protected]>
Date: Fri, 15 Jun 2007 18:58:15 +0200
Subject: [PATCH] test-suite documentation
A quick description of test-suite usage.
--- Documentation/test-suite | 112 ++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 112 insertions(+), 0 deletions(-) create mode 100644 Documentation/test-suite
Documentation/test-suite new file +112 -0
112 lines not on this page · raw message
Signature · 1 line
1.5.2.1.280.g38570
Re: [PATCH 6/6] Add a simple test script, embed expected results into test files
Hello Damien,
Quoted 4 lines · Damien Lespiau
I happen to have 3 patches in my tree that look like this one. I thought you might
want to have a look as they appear to handle the points you were wanting to fix. Patch 3 is a "documentation patch" that explains what I wanted to do.
I see your testsuite is much more sophisticated, since it can handle:
- known bad tests
- return codes other than 0
- stdout (combined with stderr)
- test-specific sparse flags
More verbose keywords also look better. And having the documentation is another advantage.
I don't think I'll be able to match what you have done (unless you see a patch from me within the next hour). Maybe your testsuite could be applied instead?
Signature · 2 lines
Regards, Pavel Roskin
Re: [PATCH 6/6] Add a simple test script, embed expected results into test files
In reply to Damien LespiauQuoted 7 lines · Damien Lespiau
I happen to have 3 patches in my tree that look like this one. I thought you might
want to have a look as they appear to handle the points you were wanting to fix. Patch 3 is a "documentation patch" that explains what I wanted to do.I attached those patches as gmail does not allow me to answer a thread and post a patch without losing its formatting.
Will review in more detail later, but at first glance this looks quite good, and very capable.
Two minor things that jump out at me:
* The need to specify the command line as "../sparse args $file" seems somewhat inelegant. I do like the ability to specify a command other than sparse; for example, this could allow checking the output of c2xml. However, I'd prefer not to need a path; how about allowing "sparse args $file"? Also, allowing an alternate option "check-options" that just specifies sparse flags seems useful, and the default command could do something like "sparse $options $file"; that way, you can just say "check-options: -E", or "check-options: -Wthingy".
* The need to prefix every line of output, rather than delimiting the start and end of the output, seems painful with large amounts of output.
Other than that, I really like this test suite. Thanks!
- Josh Triplett
Re: [PATCH 6/6] Add a simple test script, embed expected results into test files
Quoted 2 lines
Will review in more detail later, but at first glance this looks quite good, and very capable.
I rebased the series against current HEAD to make testing easier.
Quoted 3 lines
Two minor things that jump out at me:
* The need to specify the command line as "../sparse args $file" seems somewhat inelegant.
solved: no path in check-command now.
Quoted 5 lines
Also, allowing an
alternate option "check-options" that just specifies sparse flags seems useful, and the default command could do something like "sparse $options $file"; that way, you can just say "check-options: -E", or "check-options: -Wthingy".
Humm, not sure if it's _that_ much useful to have
check-options: -E -Wthingy
instead of
check-command: sparse -E -Wthingy $file
for some reason I find the later less confusing, a matter of taste I guess.
Quoted 3 lines
* The need to prefix every line of output, rather than delimiting the start and end of the output, seems painful with large amounts of output.
Agreed. that's why ./test-suite format helps building such tags
However I still run into a behavior that I cannot explain:
validation$ echo $SHELL/bin/bash
----------
validation$ ../sparse -E preprocessor/preprocessor19.c
preprocessor/preprocessor19.c:4:9: warning: preprocessor token A redefined preprocessor/preprocessor19.c:3:9: this was the original definition y
----------
validation$ ../sparse -E preprocessor/preprocessor19.c 2> o 1> o && cat o
yprocessor/preprocessor19.c:4:9: warning: preprocessor token A redefined preprocessor/preprocessor19.c:3:9: this was the original definition
----------
validation$ ../sparse -E preprocessor/preprocessor19.c &> o && cat o preprocessor/preprocessor19.c:4:9: warning: preprocessor token A redefined preprocessor/preprocessor19.c:3:9: this was the original definition
y
If you look carefully the 2> 1> redirections have eaten "pre" of the first "preprocessor". Using &> show a more suitable behavior but it seems that &> is not supported by every Bourne shell (for instance dash (the default /bin/sh of Ubuntu 7.04 does not support &>) Any idea ?
Signature · 1 line
Damien
From 31cb2f2eafb9e7b88f3fb40500908853bfad24bf Mon Sep 17 00:00:00 2001
From: Damien Lespiau <[email protected]>
Date: Fri, 29 Jun 2007 00:57:36 +0200
Subject: [PATCH] test-suite: a tiny test automation script
This patch introduces test-suite, a simple script that makes test cases verification easier. Test cases in the validation directory are annotated and this script parses them to check if the actual result is the one expected by the test writer.
--- .gitignore | 5 + Makefile | 4 + validation/test-suite | 241 +++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 250 insertions(+), 0 deletions(-) create mode 100755 validation/test-suite
.gitignore +5 -0
@@ -32,3 +32,8 @@ patches-* patches series +# test-suite +*.diff +*.got +*.expected +
Makefile +4 -0
@@ -168,3 +168,7 @@ dist: exit 1 ; \ fi git archive --format=tar --prefix=sparse-$(VERSION)/ HEAD^{tree} | gzip -9 > sparse-$(VERSION).tar.gz + +check: all + $(Q)cd validation && ./test-suite +
validation/test-suite new file +241 -0
241 lines not on this page · raw message
Signature · 1 line
1.5.2.1.280.g38570
From 35fb2463bb71fefdd6865db38cb70bdd0f28d9a4 Mon Sep 17 00:00:00 2001
From: Damien Lespiau <[email protected]>
Date: Fri, 29 Jun 2007 00:57:38 +0200
Subject: [PATCH] Sample test-suite test cases
A few examples meant to show the use of test-suite
--- validation/bad-assignment.c | 11 +++++++++++ validation/preprocessor/preprocessor1.c | 9 +++++++++ validation/preprocessor/preprocessor2.c | 9 +++++++++ validation/preprocessor/preprocessor3.c | 12 ++++++++++++ validation/struct-as.c | 8 ++++++++ 5 files changed, 49 insertions(+), 0 deletions(-)
validation/bad-assignment.c +11 -0
@@ -4,3 +4,14 @@ static int foo(int a)return a; } +/* +* check-name: bad assignement +* +* check-command: sparse $file +* check-exit-value: 1 +* +* check-output:bad-assignment.c:3:6: error: Expected ; at end of statement +* check-output:bad-assignment.c:3:6: error: got \ +* +* check-known-to-fail +*/
validation/preprocessor/preprocessor1.c +9 -0
@@ -12,3 +12,12 @@#define bar func(#define foo bar foo foo ) +/* +* check-name: preprocessor 1 +* +* check-command: sparse -E $file +* check-exit-value: 0 +* +* check-output: +* check-output:foo +*/
validation/preprocessor/preprocessor2.c +9 -0
@@ -13,3 +13,12 @@#define BINARY (x, y) x + yUNARY (TWO ) +/* +* check-name: preprocessor 2 +* +* check-command: sparse -E $file +* check-exit-value: 0 +* +* check-output: +* check-output:a + b +*/
validation/preprocessor/preprocessor3.c +12 -0
@@ -35,3 +35,15 @@ A() // B ( ) SCAN( A() ) // A ( ) SCAN(SCAN( A() )) // B ( ) SCAN(SCAN(SCAN( A() ))) // A ( ) +/* +* check-name: preprocessor 3 +* +* check-command: sparse -E $file +* check-exit-value: 0 +* +* check-output: +* check-output:B ( ) +* check-output:A ( ) +* check-output:B ( ) +* check-output:A ( ) +*/
validation/struct-as.c +8 -0
@@ -14,3 +14,11 @@ static int broken(struct hello __user *sp) {test (&sp->a); } +/* +* check-name: address space of structure members +* +* check-command: sparse $file +* check-exit-value: 0 +* + +*/
Signature · 1 line
1.5.2.1.280.g38570
From 2b5aa5e2525fef36335502eb37462c1ceb93e43d Mon Sep 17 00:00:00 2001
From: Damien Lespiau <[email protected]>
Date: Fri, 29 Jun 2007 01:18:12 +0200
Subject: [PATCH] test-suite documentation
A quick description of test-suite usage.
--- Documentation/test-suite | 113 ++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 113 insertions(+), 0 deletions(-) create mode 100644 Documentation/test-suite
Documentation/test-suite new file +113 -0
113 lines not on this page · raw message
Signature · 1 line
1.5.2.1.280.g38570
Re: [PATCH 6/6] Add a simple test script, embed expected results into test files
Quoted 4 lines · Damien Lespiau
Quoted 2 lines
Will review in more detail later, but at first glance this looks quite good, and very capable.
I rebased the series against current HEAD to make testing easier.
Thanks.
Quoted 4 lines
Quoted 3 lines
Two minor things that jump out at me:
* The need to specify the command line as "../sparse args $file" seems somewhat inelegant.solved: no path in check-command now.
Excellent.
Quoted 10 lines
Quoted 5 lines
Also, allowing an
alternate option "check-options" that just specifies sparse flags seems useful, and the default command could do something like "sparse $options $file"; that way, you can just say "check-options: -E", or "check-options: -Wthingy".Humm, not sure if it's _that_ much useful to have
check-options: -E -Wthingy
instead of
check-command: sparse -E -Wthingy $file
for some reason I find the later less confusing, a matter of taste I guess.
I don't mind going with the latter for now and considering the former for a later patch.
Quoted 4 lines
Quoted 3 lines
* The need to prefix every line of output, rather than delimiting the start and end of the output, seems painful with large amounts of output.
Agreed. that's why ./test-suite format helps building such tags
Yes, but I still prefer the delimited format for readability.
Quoted 21 lines
However I still run into a behavior that I cannot explain:
validation$ echo $SHELL
/bin/bash
----------
validation$ ../sparse -Epreprocessor/preprocessor19.c
preprocessor/preprocessor19.c:4:9: warning: preprocessor token A redefinedpreprocessor/preprocessor19.c:3:9: this was the original definition y
----------
validation$ ../sparse -Epreprocessor/preprocessor19.c2> o 1> o && cat oy
processor/preprocessor19.c:4:9: warning: preprocessor token A redefinedpreprocessor/preprocessor19.c:3:9: this was the original definition
----------
validation$ ../sparse -Epreprocessor/preprocessor19.c&> o && cat opreprocessor/preprocessor19.c:4:9: warning: preprocessor token A redefinedpreprocessor/preprocessor19.c:3:9: this was the original definition
Quoted 6 lines
y
If you look carefully the 2> 1> redirections have eaten "pre" of the first "preprocessor". Using &> show a more suitable behavior but it seems that &> is not supported by every Bourne shell (for instance dash (the default
/bin/shof Ubuntu 7.04 does not support &>) Any idea ?
You can't redirect two things independently to the same file; that will open the file twice, and the writes will conflict, giving exactly the result you saw. > o 2>&1 should work; it has exactly the same effect as &> .
- Josh Triplett
Re: [PATCH 6/6] Add a simple test script, embed expected results into test files
A small update,
Quoted 1 line
Yes, but I still prefer the delimited format for readability.
Ok: expected output is now between check-output-start / check-output-end tags.
I've added a clean-check target in the Makefile, updated the provided test-cases and documentation.
Quoted 4 lines
You can't redirect two things independently to the same file; that will open the file twice, and the writes will conflict, giving exactly the result you saw. > o 2>&1 should work; it has exactly the same effect as &> .
For some reason I was expecting that:
[pid 8877] open("o", O_WRONLY|O_CREAT|O_TRUNC| \
O_LARGEFILE, 0666) = 3
[pid 8877] dup2(3, 1) = 1
[pid 8877] close(3) = 0
[pid 8877] open("o", O_WRONLY|O_CREAT|O_TRUNC| \
O_LARGEFILE, 0666) = 3
[pid 8877] dup2(3, 2) = 2
[pid 8877] close(3) = 0and
[pid 10777] open("o", O_WRONLY|O_CREAT|O_TRUNC| \
O_LARGEFILE, 0666) = 3
[pid 10777] dup2(3, 1) = 1
[pid 10777] close(3) = 0
[pid 10777] dup2(1, 2) = 2followed by:
[pid xxxxx] write(2, "validation/preprocessor19.c:4:9:"..., 73) = 73 [pid xxxxx] write(2, "validation/preprocessor19.c:3:9:"..., 66) = 66 [pid xxxxx] write(1, "\ny\n", 3) = o
to give the same result and that the first one would not eat characters. I was wrong.
Signature · 1 line
Damien
From 4977f1c73fcb53d260facbee0be60c78bdb7af76 Mon Sep 17 00:00:00 2001
From: Damien Lespiau <[email protected]>
Date: Mon, 2 Jul 2007 06:41:34 +0200
Subject: [PATCH] test-suite: a tiny test automation script
This patch introduces test-suite, a simple script that makes test cases verification easier. Test cases in the validation directory are annotated and this script parses them to check if the actual result is the one expected by the test writer.
--- .gitignore | 5 + Makefile | 7 ++ validation/test-suite | 252 +++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 264 insertions(+), 0 deletions(-) create mode 100755 validation/test-suite
.gitignore +5 -0
@@ -32,3 +32,8 @@ patches-* patches series +# test-suite +*.diff +*.got +*.expected +
Makefile +7 -0
@@ -168,3 +168,10 @@ dist: exit 1 ; \ fi git archive --format=tar --prefix=sparse-$(VERSION)/ HEAD^{tree} | gzip -9 > sparse-$(VERSION).tar.gz + +check: all + $(Q)cd validation && ./test-suite + +clean-check: + find validation/ -name "*.c.[egd]*" -exec rm {} \; +
validation/test-suite new file +252 -0
252 lines not on this page · raw message
Signature · 1 line
1.5.2.1.280.g38570
From 922bed97f061491ff2e7ca11e22161726fd6d7e5 Mon Sep 17 00:00:00 2001
From: Damien Lespiau <[email protected]>
Date: Mon, 2 Jul 2007 06:41:39 +0200
Subject: [PATCH] Sample test-suite test cases
A few examples meant to show the use of test-suite
--- validation/bad-assignment.c | 13 +++++++++++++ validation/preprocessor/preprocessor1.c | 11 +++++++++++ validation/preprocessor/preprocessor19.c | 13 +++++++++++++ validation/preprocessor/preprocessor2.c | 11 +++++++++++ validation/preprocessor/preprocessor3.c | 14 ++++++++++++++ validation/struct-as.c | 6 ++++++ 6 files changed, 68 insertions(+), 0 deletions(-)
validation/bad-assignment.c +13 -0
@@ -4,3 +4,16 @@ static int foo(int a)return a; } +/* +* check-name: bad assignement +* +* check-command: sparse $file +* check-exit-value: 1 +* +* check-output-start +bad-assignment.c:3:6: error: Expected ; at end of statement +bad-assignment.c:3:6: error: got \ +* check-output-end +* +* check-known-to-fail +*/
validation/preprocessor/preprocessor1.c +11 -0
@@ -12,3 +12,14 @@#define bar func(#define foo bar foo foo ) +/* +* check-name: Preprocessor #1 +* +* check-command: sparse -E $file +* check-exit-value: 0 +* +* check-output-start + +foo +* check-output-end +*/
validation/preprocessor/preprocessor19.c +13 -0
@@ -3,3 +3,16 @@#define A x#define A yA +/* +* check-name: Preprocessor #19 +* +* check-command: sparse -E $file +* check-exit-value: 0 +* +* check-output-start +preprocessor/preprocessor19.c:4:9: warning: preprocessor token A redefined +preprocessor/preprocessor19.c:3:9: this was the original definition + +y +* check-output-end +*/
validation/preprocessor/preprocessor2.c +11 -0
@@ -13,3 +13,14 @@#define BINARY (x, y) x + yUNARY (TWO ) +/* +* check-name: Preprocessor #2 +* +* check-command: sparse -E $file +* check-exit-value: 0 +* +* check-output-start + +a + b +* check-output-end +*/
validation/preprocessor/preprocessor3.c +14 -0
@@ -35,3 +35,17 @@ A() // B ( ) SCAN( A() ) // A ( ) SCAN(SCAN( A() )) // B ( ) SCAN(SCAN(SCAN( A() ))) // A ( ) +/* +* check-name: Preprocessor #3 +* +* check-command: sparse -E $file +* check-exit-value: 0 +* +* check-output-start + +B ( ) +A ( ) +B ( ) +A ( ) +* check-output-end +*/
validation/struct-as.c +6 -0
@@ -14,3 +14,9 @@ static int broken(struct hello __user *sp) {test (&sp->a); } +/* +* check-name: Address space of a struct member +* +* check-command: sparse $file +* check-exit-value: 0 +*/
Signature · 1 line
1.5.2.1.280.g38570
From 3881b34f3e103aecdc4581bfcef1925d7a8636b6 Mon Sep 17 00:00:00 2001
From: Damien Lespiau <[email protected]>
Date: Mon, 2 Jul 2007 06:49:04 +0200
Subject: [PATCH] test-suite documentation
A quick description of test-suite usage.
--- Documentation/test-suite | 112 ++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 112 insertions(+), 0 deletions(-) create mode 100644 Documentation/test-suite
Documentation/test-suite new file +112 -0
112 lines not on this page · raw message
Signature · 1 line
1.5.2.1.280.g38570
Re: [PATCH 6/6] Add a simple test script, embed expected results into test files
Quoted 8 lines · Damien Lespiau
A small update,
Quoted 1 line
Yes, but I still prefer the delimited format for readability.
Ok: expected output is now between check-output-start / check-output-end tags.
I've added a clean-check target in theMakefile, updated the provided test-cases and documentation.
Thanks! Will review and apply soon.
Quoted 24 lines
Quoted 4 lines
You can't redirect two things independently to the same file; that will open the file twice, and the writes will conflict, giving exactly the result you saw. > o 2>&1 should work; it has exactly the same effect as &> .
For some reason I was expecting that:
[pid 8877] open("o", O_WRONLY|O_CREAT|O_TRUNC| \ O_LARGEFILE, 0666) = 3 [pid 8877] dup2(3, 1) = 1 [pid 8877] close(3) = 0 [pid 8877] open("o", O_WRONLY|O_CREAT|O_TRUNC| \ O_LARGEFILE, 0666) = 3 [pid 8877] dup2(3, 2) = 2 [pid 8877] close(3) = 0and
[pid 10777] open("o", O_WRONLY|O_CREAT|O_TRUNC| \ O_LARGEFILE, 0666) = 3 [pid 10777] dup2(3, 1) = 1 [pid 10777] close(3) = 0 [pid 10777] dup2(1, 2) = 2
Quoted 7 lines
followed by:
[pid xxxxx] write(2, "validation/preprocessor19.c:4:9:"..., 73) = 73 [pid xxxxx] write(2, "validation/preprocessor19.c:3:9:"..., 66) = 66 [pid xxxxx] write(1, "\ny\n", 3) = oto give the same result and that the first one would not eat characters.
In the first case, fd 1 and fd 2 represent separate open files, and have independent file offsets; thus, writes through the two file descriptors overwrite each other. In the second case, fd 1 and fd 2 represent the same open file, and have the same file offset, so writes to either one appear in the file in sequence.
- Josh Triplett
Re: [PATCH 6/6] Add a simple test script, embed expected results into test files
In reply to Damien LespiauI've applied Damien's test-suite patches. I've started making use of the test suite, and adding the test-suite comments to more files in validation. I find it a pleasure to work with; thanks, Damien!
Thanks to Pavel as well, for pushing automated testing to begin with, and for contributing to the final result.
Damien, I noticed one minor issue with test-suite: it seems to eat whitespace in the Sparse output, making "test-suite format" for several of the preprocessor tests (such as preprocessor18.c) not match the actual output. I would guess some kind of quoting problem. Here documents may not do what you want. Could you take a look at that, please?
- Josh Triplett
Re: [PATCH 6/6] Add a simple test script, embed expected results into test files
Quoted 5 lines · Josh Triplett
Damien, I noticed one minor issue with test-suite: it seems to eat whitespace in the Sparse output, making "test-suite format" for several of the preprocessor tests (such as
preprocessor18.c) not match the actual output. I would guess some kind of quoting problem. Here documents may not do what you want. Could you take a look at that, please?
Actually, this led me to a more important issue: I don't think the test suite output can mix stdout and stderr safely, because the order may differ if both have data. Look at preprocessor18.c for an example. I think the test suite needs to have a block for check-stdout-{start,end} and a block for check-stderr-{start,end}.
- Josh Triplett
Re: [PATCH 6/6] Add a simple test script, embed expected results into test files
(I removed Pavel from the cc: list as he probably does not want to read such mails)
Quoted 5 lines
Actually, this led me to a more important issue: I don't think the test suite output can mix stdout and stderr safely, because the order may differ if both have data. Look at
preprocessor18.cfor an example. I think the test suite needs to have a block for check-stdout-{start,end} and a block for check-stderr-{start,end}.
Absolutely !
../sparse -E preprocessor/preprocessor18.c 1> foo 2>&1 && cat foo and
../sparse -E preprocessor/preprocessor18.c
are not giving the same result and I had the same conclusion as yours before going to bed. I was actually thinking about splitting the output between stderr and stdout too. I added 1: or 2: at the beginning of output lines but I think I like check-(stdout|stderr)-(start,end) better.
However I bumped into another issue:
$ hexdump -C bar 00000000 0a 0a 78 78 78 0a 0a 0a |..xxx...| $ foo=`cat bar` $ echo "$foo" | hexdump -C 00000000 0a 0a 78 78 78 0a |..xxx.|
it eats the last new lines but one and not the first '\n's ! I still have to sort this out...
Signature · 1 line
Damien
Re: [PATCH 6/6] Add a simple test script, embed expected results into test files
Quoted 9 lines · Damien Lespiau
However I bumped into another issue:
$ hexdump -C bar 00000000 0a 0a 78 78 78 0a 0a 0a |..xxx...| $ foo=`cat bar` $ echo "$foo" | hexdump -C 00000000 0a 0a 78 78 78 0a |..xxx.|it eats the last new lines but one and not the first '\n's ! I still have to sort this out...
Actually, it eats both newlines... The trailing newline that still appears is from "echo" command, which appends a newline by default. Try:
echo -n "$foo" | hexdump -C
instead. Anyway, this is from "man bash":
"Command Substitution
[...]
Bash performs the expansion by executing command and replacing the command substitution with the standard output of the command, with any trailing newlines deleted. Embedded newlines are not deleted, but they may be removed during word splitting."
So I suppose this is an expected behaviour.
Regards,
Signature · 1 line
Anderson Lizardo
Josh Triplett
AppliedQuoted 2 lines · Pavel Roskin
The -Wdefault-bitfield-sign is supposed to control a warning, just like other -W options.
I've applied this patch; thanks!
- Josh Triplett