From 8731bb7b2e6229a4fe2234796d0371d01cc22835 Mon Sep 17 00:00:00 2001 From: Josh Triplett Date: Thu, 29 Jun 2006 15:31:04 -0700 Subject: [PATCH] [PATCH] Add test cases for __context__ statement and context attribute Add validation/context.c, which includes various test cases for __context__(...) and __attribute__((context(...))). These test cases include both correct usage, in the functions named good_*, and incorrect usage, in the functions named warn_*. Signed-off-by: Josh Triplett Signed-off-by: Linus Torvalds --- validation/context.c | 296 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 296 insertions(+) create mode 100644 validation/context.c diff --git a/validation/context.c b/validation/context.c new file mode 100644 index 00000000..165d4f63 --- /dev/null +++ b/validation/context.c @@ -0,0 +1,296 @@ +void a(void) __attribute__((context(0,1))) +{ + __context__(1); +} + +void r(void) __attribute__((context(1,0))) +{ + __context__(-1); +} + +void good_paired1(void) +{ + a(); + r(); +} + +void good_paired2(void) +{ + a(); + r(); + a(); + r(); +} + +void good_paired3(void) +{ + a(); + a(); + r(); + r(); +} + +void good_lock1(void) __attribute__((context(0,1))) +{ + a(); +} + +void good_lock2(void) __attribute__((context(0,1))) +{ + a(); + r(); + a(); +} + +void good_lock3(void) __attribute__((context(0,1))) +{ + a(); + a(); + r(); +} + +void good_unlock1(void) __attribute__((context(1,0))) +{ + r(); +} + +void good_unlock2(void) __attribute__((context(1,0))) +{ + a(); + r(); + r(); +} + +void warn_lock1(void) +{ + a(); +} + +void warn_lock2(void) +{ + a(); + r(); + a(); +} + +void warn_lock3(void) +{ + a(); + a(); + r(); +} + +void warn_unlock1(void) +{ + r(); +} + +void warn_unlock2(void) +{ + a(); + r(); + r(); +} + +extern int condition, condition2; + +int good_if1(void) +{ + a(); + if(condition) { + r(); + return -1; + } + r(); + return 0; +} + +void good_if2(void) +{ + if(condition) { + a(); + r(); + } +} + +void good_if3(void) +{ + a(); + if(condition) { + a(); + r(); + } + r(); +} + +int warn_if1(void) +{ + a(); + if(condition) + return -1; + r(); + return 0; +} + +int warn_if2(void) +{ + a(); + if(condition) { + r(); + return -1; + } + return 0; +} + +void good_while1(void) +{ + a(); + while(condition) + ; + r(); +} + +void good_while2(void) +{ + while(condition) { + a(); + r(); + } +} + +void good_while3(void) +{ + while(condition) { + a(); + r(); + if(condition2) + break; + a(); + r(); + } +} + +void good_while4(void) +{ + a(); + while(1) { + if(condition2) { + r(); + break; + } + } +} + +void good_while5(void) +{ + a(); + while(1) { + r(); + if(condition2) + break; + a(); + } +} + +void warn_while1(void) +{ + while(condition) { + a(); + } +} + +void warn_while2(void) +{ + while(condition) { + r(); + } +} + +void warn_while3(void) +{ + while(condition) { + a(); + if(condition2) + break; + r(); + } +} + +void good_goto1(void) +{ + a(); + goto label; +label: + r(); +} + +void good_goto2(void) +{ + a(); + goto label; + a(); + r(); +label: + r(); +} + +void good_goto3(void) +{ + a(); + if(condition) + goto label; + a(); + r(); +label: + r(); +} + +void good_goto4(void) +{ + if(condition) + goto label; + a(); + r(); +label: + ; +} + +void good_goto5(void) +{ + a(); + if(condition) + goto label; + r(); + return; +label: + r(); +} + +void warn_goto1(void) +{ + a(); + goto label; + r(); +label: + ; +} + +void warn_goto2(void) +{ + a(); + goto label; + r(); +label: + a(); + r(); +} + +void warn_goto3(void) +{ + a(); + if(condition) + goto label; + r(); +label: + r(); +} -- 2.11.4.GIT