|
From: <sv...@va...> - 2007-10-25 17:39:41
|
Author: sewardj
Date: 2007-10-25 18:39:42 +0100 (Thu, 25 Oct 2007)
New Revision: 7034
Log:
Add a (pretty lame) test re doing stupid things with semaphores.
Added:
branches/THRCHECK/thrcheck/tests/tc18_semabuse.c
branches/THRCHECK/thrcheck/tests/tc18_semabuse.stderr.exp
branches/THRCHECK/thrcheck/tests/tc18_semabuse.stdout.exp
branches/THRCHECK/thrcheck/tests/tc18_semabuse.vgtest
Modified:
branches/THRCHECK/thrcheck/tests/Makefile.am
Modified: branches/THRCHECK/thrcheck/tests/Makefile.am
===================================================================
--- branches/THRCHECK/thrcheck/tests/Makefile.am 2007-10-25 16:59:14 UTC (rev 7033)
+++ branches/THRCHECK/thrcheck/tests/Makefile.am 2007-10-25 17:39:42 UTC (rev 7034)
@@ -42,7 +42,9 @@
tc16_byterace.vgtest tc16_byterace.stderr.exp \
tc16_byterace.stdout.exp \
tc17_sembar.vgtest tc17_sembar.stderr.exp \
- tc17_sembar.stdout.exp
+ tc17_sembar.stdout.exp \
+ tc18_semabuse.vgtest tc18_semabuse.stderr.exp \
+ tc18_semabuse.stdout.exp
check_PROGRAMS = \
hg01_all_ok \
@@ -67,7 +69,8 @@
tc14_laog_dinphils \
tc15_laog_lockdel \
tc16_byterace \
- tc17_sembar
+ tc17_sembar \
+ tc18_semabuse
# is this necessary?
AM_CFLAGS = $(WERROR) -Winline -Wall -Wshadow -g $(AM_FLAG_M3264_PRI)
Added: branches/THRCHECK/thrcheck/tests/tc18_semabuse.c
===================================================================
--- branches/THRCHECK/thrcheck/tests/tc18_semabuse.c (rev 0)
+++ branches/THRCHECK/thrcheck/tests/tc18_semabuse.c 2007-10-25 17:39:42 UTC (rev 7034)
@@ -0,0 +1,42 @@
+
+/* Do stupid things with semaphores, and check that Thrcheck doesn't
+ fall over and does report errors appropriately. If nothing else
+ this just checks that the relevant functions are getting
+ intercepted. */
+
+/* This is pretty lame, because making the sem_ functions fail is
+ difficult. Not sure it's really worth having. */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <assert.h>
+#include <pthread.h>
+#include <semaphore.h>
+#include <string.h>
+
+int main ( void )
+{
+ int r;
+ sem_t s1;
+
+ /* Do sem_init with huge initial count */
+ r= sem_init(&s1, 0, ~0);
+
+ /* initialise properly */
+ r= sem_init(&s1, 0, 0);
+
+ /* in glibc, sem_destroy is a no-op; making it fail is
+ impossible. */
+
+ /* Do 'wait' on a bogus semaphore. This should fail, but on glibc
+ it succeeds. */
+ memset(&s1, 0x55, sizeof(s1));
+ r= sem_wait(&s1); /* assert(r != 0); */
+
+ /* this really ought to fail, but it doesn't. */
+ r= sem_post(&s1); assert(!r);
+
+ sem_destroy(&s1);
+
+ return 0;
+}
Added: branches/THRCHECK/thrcheck/tests/tc18_semabuse.stderr.exp
===================================================================
--- branches/THRCHECK/thrcheck/tests/tc18_semabuse.stderr.exp (rev 0)
+++ branches/THRCHECK/thrcheck/tests/tc18_semabuse.stderr.exp 2007-10-25 17:39:42 UTC (rev 7034)
@@ -0,0 +1,14 @@
+
+Thread #1 is the program's root thread
+
+Thread #1's call to sem_init failed
+ with error code 22 (EINVAL: Invalid argument)
+ at 0x........: sem_init@* (tc_intercepts.c:...)
+ by 0x........: main (tc18_semabuse.c:23)
+
+Thread #1: Bug in libpthread: sem_wait succeeded on semaphore without prior sem_post
+ at 0x........: sem_wait_WRK (tc_intercepts.c:...)
+ by 0x........: sem_wait (tc_intercepts.c:...)
+ by 0x........: main (tc18_semabuse.c:34)
+
+ERROR SUMMARY: 2 errors from 2 contexts (suppressed: 0 from 0)
Added: branches/THRCHECK/thrcheck/tests/tc18_semabuse.stdout.exp
===================================================================
Added: branches/THRCHECK/thrcheck/tests/tc18_semabuse.vgtest
===================================================================
--- branches/THRCHECK/thrcheck/tests/tc18_semabuse.vgtest (rev 0)
+++ branches/THRCHECK/thrcheck/tests/tc18_semabuse.vgtest 2007-10-25 17:39:42 UTC (rev 7034)
@@ -0,0 +1 @@
+prog: tc18_semabuse
|