summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/Makefile3
-rw-r--r--tests/Template.c1
-rw-r--r--tests/errno1.c145
-rw-r--r--tests/runall.bat1
4 files changed, 149 insertions, 1 deletions
diff --git a/tests/Makefile b/tests/Makefile
index a696bf9..21309e5 100644
--- a/tests/Makefile
+++ b/tests/Makefile
@@ -39,7 +39,7 @@ TESTS = mutex1 condvar1 condvar2 exit1 create1 equal1 \
exit2 exit3 \
join1 mutex2 mutex3 \
count1 once1 tsd1 self1 self2 eyal1 \
- condvar3 condvar4
+ condvar3 condvar4 errno1
PASSES = $(TESTS:%=%.pass)
@@ -65,6 +65,7 @@ self2.pass: create1.pass
eyal1.pass: tsd1.pass
condvar3.pass: create1.pass
condvar4.pass: create1.pass
+errno1.pass: mutex3.pass
%.pass: %.exe $(LIB) $(DLL) $(HDR)
$*
diff --git a/tests/Template.c b/tests/Template.c
index c98bbac..4bee7e1 100644
--- a/tests/Template.c
+++ b/tests/Template.c
@@ -75,6 +75,7 @@ int
main()
{
int failed = 0;
+ int i;
pthread_t t[NUMTHREADS + 1];
assert((t[0] = pthread_self()) != NULL);
diff --git a/tests/errno1.c b/tests/errno1.c
new file mode 100644
index 0000000..983b37c
--- /dev/null
+++ b/tests/errno1.c
@@ -0,0 +1,145 @@
+/*
+ * File: errn1.c
+ *
+ * Test Synopsis: Test thread-safety of errno
+ * -
+ *
+ * Test Method (Validation or Falsification):
+ * - Validation
+ *
+ * Requirements Tested:
+ * -
+ *
+ * Features Tested:
+ * -
+ *
+ * Cases Tested:
+ * -
+ *
+ * Description:
+ * -
+ *
+ * Environment:
+ * -
+ *
+ * Input:
+ * - None.
+ *
+ * Output:
+ * - File name, Line number, and failed expression on failure.
+ * - No output on success.
+ *
+ * Assumptions:
+ * -
+ *
+ * Pass Criteria:
+ * - Process returns zero exit status.
+ *
+ * Fail Criteria:
+ * - Process returns non-zero exit status.
+ */
+
+#include "test.h"
+
+/*
+ * Create NUMTHREADS threads in addition to the Main thread.
+ */
+enum {
+ NUMTHREADS = 3
+};
+
+typedef struct bag_t_ bag_t;
+struct bag_t_ {
+ int threadnum;
+ int started;
+ /* Add more per-thread state variables here */
+};
+
+static bag_t threadbag[NUMTHREADS + 1];
+
+pthread_mutex_t stop_here = PTHREAD_MUTEX_INITIALIZER;
+
+void *
+mythread(void * arg)
+{
+ bag_t * bag = (bag_t *) arg;
+
+ assert(bag == &threadbag[bag->threadnum]);
+ assert(bag->started == 0);
+ bag->started = 1;
+
+ errno = bag->threadnum;
+
+ Sleep(1000);
+
+ pthread_mutex_lock(&stop_here);
+
+ assert(errno == bag->threadnum);
+
+ pthread_mutex_unlock(&stop_here);
+
+ Sleep(1000);
+
+ return 0;
+}
+
+int
+main()
+{
+ int failed = 0;
+ int i;
+ pthread_t t[NUMTHREADS + 1];
+
+ pthread_mutex_lock(&stop_here);
+ errno = 0;
+
+ assert((t[0] = pthread_self()) != NULL);
+
+ for (i = 1; i <= NUMTHREADS; i++)
+ {
+ threadbag[i].started = 0;
+ threadbag[i].threadnum = i;
+ assert(pthread_create(&t[i], NULL, mythread, (void *) &threadbag[i]) == 0);
+ }
+
+ /*
+ * Code to control or munipulate child threads should probably go here.
+ */
+ Sleep(2000);
+ pthread_mutex_unlock(&stop_here);
+
+ /*
+ * Give threads time to run.
+ */
+ Sleep(NUMTHREADS * 1000);
+
+ /*
+ * Standard check that all threads started.
+ */
+ for (i = 1; i <= NUMTHREADS; i++)
+ {
+ failed = !threadbag[i].started;
+
+ if (failed)
+ {
+ fprintf(stderr, "Thread %d: started %d\n", i, threadbag[i].started);
+ }
+ }
+
+ assert(!failed);
+
+ /*
+ * Check any results here. Set "failed" and only print ouput on failure.
+ */
+ for (i = 1; i <= NUMTHREADS; i++)
+ {
+ /* ... */
+ }
+
+ assert(!failed);
+
+ /*
+ * Success.
+ */
+ return 0;
+}
diff --git a/tests/runall.bat b/tests/runall.bat
index 3f5498d..f061f3a 100644
--- a/tests/runall.bat
+++ b/tests/runall.bat
@@ -21,3 +21,4 @@ call runtest cl self2
call runtest cl eyal1
call runtest cl condvar3
call runtest cl condvar4
+call runtest cl errno1