summaryrefslogtreecommitdiff
path: root/tests/errno1.c
diff options
context:
space:
mode:
authorrpj <rpj>1999-04-06 22:02:54 +0000
committerrpj <rpj>1999-04-06 22:02:54 +0000
commit5ad9bc631048467dba8964ab840a71990aabeae3 (patch)
treee1d0a9bb098ab9d46ed460b0343a9792e38355aa /tests/errno1.c
parent5d920cbde2800a019934b7a3748c7afc070a3505 (diff)
Wed Apr 7 14:09:52 1999 Ross Johnson <rpj@swan.canberra.edu.au>snap-1999-04-07
* errno.c (_REENTRANT || _MT): Invert #if condition. * pthread.h (_errno): Conditionally include prototype.
Diffstat (limited to 'tests/errno1.c')
-rw-r--r--tests/errno1.c145
1 files changed, 145 insertions, 0 deletions
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;
+}