summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/Makefile139
-rw-r--r--tests/condvar2.c156
-rw-r--r--tests/condvar3.c212
-rw-r--r--tests/condvar4.c227
4 files changed, 383 insertions, 351 deletions
diff --git a/tests/Makefile b/tests/Makefile
index 14228b7..dcbb7e0 100644
--- a/tests/Makefile
+++ b/tests/Makefile
@@ -1,69 +1,70 @@
-# Makefile for the pthreads test suite.
-# If all of the .pass files can be created, the test suite has passed.
-
-
-CP = copy
-RM = erase
-MKDIR = mkdir
-TOUCH = echo Passed >
-ECHO = @echo
-
-#
-# Mingw32
-#
-CC = gcc
-CFLAGS = -g -O2 -UNDEBUG -Wall -o $@ $^
-BUILD_DIR = ..
-INCLUDES = -I./include
-LIBS = ./lib/libpthread32.a
-
-##
-## MSVC
-##
-#CC = cl
-#CFLAGS = /W3 /MT /nologo /Yd /Zi /Fe$@ $^
-#BUILD_DIR = ..
-#INCLUDES = -I.\include
-#LIBS = .\lib\pthread.lib
-
-HDR = .\include\pthread.h
-LIB = .\lib\libpthread32.a
-DLL = pthread.dll
-
-# If a test case returns a non-zero exit code to the shell, make will
-# stop.
-
-TESTS = count1 create1 equal1 exit1 exit2 exit3 \
- join1 eyal1 mutex1 mutex2 mutex3 \
- once1 self1 self2 condvar1 condvar2 condvar3 condvar4 tsd1
-
-PASSES = $(TESTS:%=%.pass)
-
-all: $(PASSES)
- @ $(ECHO) ALL TESTS PASSED! Congratulations!
-
-%.pass: %.exe $(LIB) $(DLL) $(HDR)
- $*
- @$(ECHO) Passed
- @ $(TOUCH) $@
-
-%.exe: %.c
- @ $(CC) $(CFLAGS) $(INCLUDES) $(LIBS)
-
-$(LIB):
- @- $(MKDIR) .\lib
- @ $(CP) $(BUILD_DIR)\$@ .\$@
-
-$(HDR):
- @- $(MKDIR) .\include
- @ $(CP) $(BUILD_DIR)\$@ .\$@
-
-$(DLL):
- @ $(CP) $(BUILD_DIR)\$@ .\$@
-
-clean:
- - $(RM) *.dll
- - $(RM) $(LIB)
- - $(RM) $(HDR)
- - $(RM) *.exe
- - $(RM) *.pass
+# Makefile for the pthreads test suite.
+# If all of the .pass files can be created, the test suite has passed.
+
+
+CP = copy
+RM = erase
+MKDIR = mkdir
+TOUCH = echo Passed >
+ECHO = @echo
+
+#
+# Mingw32
+#
+CC = gcc
+CFLAGS = -g -O2 -UNDEBUG -Wall -o $@ $^
+BUILD_DIR = ..
+INCLUDES = -I.
+LIBS = ./libpthread32.a
+
+##
+## MSVC
+##
+#CC = cl
+#CFLAGS = /W3 /MT /nologo /Yd /Zi /Fe$@ $^
+#BUILD_DIR = ..
+#INCLUDES = -I.
+#LIBS = pthread.lib
+
+HDR = pthread.h
+LIB = libpthread32.a
+DLL = pthread.dll
+
+# If a test case returns a non-zero exit code to the shell, make will
+# stop.
+
+TESTS = count1 create1 equal1 exit1 exit2 exit3 \
+ join1 mutex1 mutex2 mutex3 \
+ once1 self1 self2 condvar1 condvar2 condvar3 condvar4 tsd1
+
+PASSES = $(TESTS:%=%.pass)
+
+all: $(PASSES)
+ @ $(ECHO) ALL TESTS PASSED! Congratulations!
+
+%.pass: %.exe $(LIB) $(DLL) $(HDR)
+ $*
+ @$(ECHO) Passed
+ @ $(TOUCH) $@
+
+%.exe: %.c
+ @ $(CC) $(CFLAGS) $(INCLUDES) $(LIBS)
+
+$(LIB):
+ @ $(ECHO) Copying the library
+ @ $(CP) $(BUILD_DIR)\$@ .
+
+$(HDR):
+ @ $(ECHO) Copying the header file
+ @ $(CP) $(BUILD_DIR)\$@ .
+
+$(DLL):
+ @ $(ECHO) Copying the DLL
+ @ $(CP) $(BUILD_DIR)\$@ .
+
+clean:
+ - $(RM) *.dll
+ - $(RM) $(LIB)
+ - $(RM) $(HDR)
+ - $(RM) *.exe
+ - $(RM) *.pass
diff --git a/tests/condvar2.c b/tests/condvar2.c
index 107ed8f..66f3d7b 100644
--- a/tests/condvar2.c
+++ b/tests/condvar2.c
@@ -1,73 +1,83 @@
-/*
- * File: condvar1.c
- *
- * Test Synopsis:
- * - Test timed wait on a CV.
- *
- * Test Method (Validation or Falsification):
- * - Validation
- *
- * Requirements Tested:
- * -
- *
- * Features Tested:
- * -
- *
- * Cases Tested:
- * -
- *
- * Description:
- * - Because the CV is never signaled, we expect the wait to time out.
- *
- * Environment:
- * -
- *
- * Input:
- * - None.
- *
- * Output:
- * - File name, Line number, and failed expression on failure.
- * - No output on success.
- *
- * Assumptions:
- * -
- *
- * Pass Criteria:
- * - pthread_cond_timedwait returns ETIMEDOUT.
- * - Process returns zero exit status.
- *
- * Fail Criteria:
- * - pthread_cond_timedwait does not return ETIMEDOUT.
- * - Process returns non-zero exit status.
- */
-
-#include "test.h"
-
-pthread_cond_t cv;
-pthread_mutex_t mutex;
-
-int
-main()
-{
- struct timespec abstime = { 0, 0 };
- struct timeval curtime;
-
- assert(pthread_cond_init(&cv, NULL) == 0);
-
- assert(pthread_mutex_init(&mutex) == 0);
-
- assert(pthread_mutex_lock(&mutex) == 0);
-
- assert(gettimeofday(&curtime, NULL) == 0);
-
- abstime.tv_sec = curtime.tv_sec + 5;
-
- assert(pthread_cond_timedwait(&cv, &mutex, &abstime) == ETIMEDOUT);
-
- assert(pthread_mutex_unlock(&mutex) == 0);
-
- assert(pthread_cond_destroy(&cv) == 0);
-
- return 0;
-}
-
+/*
+ * File: condvar1.c
+ *
+ * Test Synopsis:
+ * - Test timed wait on a CV.
+ *
+ * Test Method (Validation or Falsification):
+ * - Validation
+ *
+ * Requirements Tested:
+ * -
+ *
+ * Features Tested:
+ * -
+ *
+ * Cases Tested:
+ * -
+ *
+ * Description:
+ * - Because the CV is never signaled, we expect the wait to time out.
+ *
+ * Environment:
+ * -
+ *
+ * Input:
+ * - None.
+ *
+ * Output:
+ * - File name, Line number, and failed expression on failure.
+ * - No output on success.
+ *
+ * Assumptions:
+ * -
+ *
+ * Pass Criteria:
+ * - pthread_cond_timedwait returns ETIMEDOUT.
+ * - Process returns zero exit status.
+ *
+ * Fail Criteria:
+ * - pthread_cond_timedwait does not return ETIMEDOUT.
+ * - Process returns non-zero exit status.
+ */
+
+#include "test.h"
+#include <sys/timeb.h>
+
+pthread_cond_t cv;
+pthread_mutex_t mutex;
+
+int
+main()
+{
+ struct timespec abstime = { 0, 0 };
+#if defined(__MINGW32__)
+ struct timeb currSysTime;
+#else
+ struct _timeb currSysTime;
+#endif
+ const DWORD NANOSEC_PER_MILLISEC = 1000000;
+
+ assert(pthread_cond_init(&cv, NULL) == 0);
+
+ assert(pthread_mutex_init(&mutex, NULL) == 0);
+
+ assert(pthread_mutex_lock(&mutex) == 0);
+
+ /* get current system time */
+ _ftime(&currSysTime);
+
+ abstime.tv_sec = currSysTime.time;
+ abstime.tv_nsec = NANOSEC_PER_MILLISEC * currSysTime.millitm;
+
+ abstime.tv_sec += 5;
+
+ assert(pthread_cond_timedwait(&cv, &mutex, &abstime) == ETIMEDOUT);
+
+ assert(pthread_mutex_unlock(&mutex) == 0);
+
+ assert(pthread_cond_destroy(&cv) == 0);
+
+ return 0;
+}
+
diff --git a/tests/condvar3.c b/tests/condvar3.c
index 97a17cf..8dc56af 100644
--- a/tests/condvar3.c
+++ b/tests/condvar3.c
@@ -1,103 +1,109 @@
-/*
- * File: condvar1.c
- *
- * Test Synopsis:
- * - Test basic function of a CV
- *
- * Test Method (Validation or Falsification):
- * - Validation
- *
- * Requirements Tested:
- * -
- *
- * Features Tested:
- * -
- *
- * Cases Tested:
- * -
- *
- * Description:
- * - The primary thread takes the lock before creating any threads.
- * The secondary thread blocks on the lock allowing the primary
- * thread to enter the cv wait state which releases the lock.
- * The secondary thread then takes the lock and signals the waiting
- * primary thread.
- *
- * Environment:
- * -
- *
- * Input:
- * - None.
- *
- * Output:
- * - File name, Line number, and failed expression on failure.
- * - No output on success.
- *
- * Assumptions:
- * -
- *
- * Pass Criteria:
- * - pthread_cond_timedwait returns 0.
- * - Process returns zero exit status.
- *
- * Fail Criteria:
- * - pthread_cond_timedwait returns ETIMEDOUT.
- * - Process returns non-zero exit status.
- */
-
-#include "test.h"
-
-typedef struct cvthing_t_ cvthing_t;
-
-struct cvthing_t_ {
- pthread_cond_t notbusy;
- pthread_mutex_t lock;
-};
-
-static cvthing_t cvthing;
-
-static enum {
- NUMTHREADS = 2 /* Including the primary thread. */
-};
-
-void *
-mythread(void * arg)
-{
- assert(pthread_mutex_lock(&cvthing.lock) == 0);
-
- assert(pthread_cond_signal(&cvthing.notbusy) == 0);
-
- assert(pthread_mutex_unlock(&cvthing.lock) == 0);
-
- return 0;
-}
-
-int
-main()
-{
- pthread_t t[NUMTHREADS];
- struct timespec abstime = { 0, 0 };
- struct timeval curtime;
-
- assert((t[0] = pthread_self()) != NULL);
-
- assert(pthread_cond_init(&cvthing, NULL) == 0);
-
- assert(pthread_mutex_init(&cvthing.lock) == 0);
-
- assert(pthread_mutex_lock(&cvthing.lock) == 0);
-
- assert(gettimeofday(&curtime, NULL) == 0);
-
- abstime.tv_sec = curtime.tv_sec + 5;
-
- assert(pthread_create(&t[1], NULL, mythread, (void *) 1) == 0);
-
- assert(pthread_cond_timedwait(&cvthing.notbusy, &cvthing.lock, &abstime) == 0);
-
- assert(pthread_mutex_unlock(&cvthing.lock) == 0);
-
- assert(pthread_cond_destroy(&cvthing) == 0);
-
- return 0;
-}
+/*
+ * File: condvar3.c
+ *
+ * Test Synopsis:
+ * - Test basic function of a CV
+ *
+ * Test Method (Validation or Falsification):
+ * - Validation
+ *
+ * Requirements Tested:
+ * -
+ *
+ * Features Tested:
+ * -
+ *
+ * Cases Tested:
+ * -
+ *
+ * Description:
+ * - The primary thread takes the lock before creating any threads.
+ * The secondary thread blocks on the lock allowing the primary
+ * thread to enter the cv wait state which releases the lock.
+ * The secondary thread then takes the lock and signals the waiting
+ * primary thread.
+ *
+ * Environment:
+ * -
+ *
+ * Input:
+ * - None.
+ *
+ * Output:
+ * - File name, Line number, and failed expression on failure.
+ * - No output on success.
+ *
+ * Assumptions:
+ * -
+ *
+ * Pass Criteria:
+ * - pthread_cond_timedwait returns 0.
+ * - Process returns zero exit status.
+ *
+ * Fail Criteria:
+ * - pthread_cond_timedwait returns ETIMEDOUT.
+ * - Process returns non-zero exit status.
+ */
+
+#include "test.h"
+#include <sys/timeb.h>
+
+pthread_cond_t cv;
+pthread_mutex_t mutex;
+
+enum {
+ NUMTHREADS = 2 /* Including the primary thread. */
+};
+
+void *
+mythread(void * arg)
+{
+ Sleep(1);
+
+ assert(pthread_mutex_lock(&mutex) == 0);
+
+ assert(pthread_cond_signal(&cv) == 0);
+
+ assert(pthread_mutex_unlock(&mutex) == 0);
+
+ return 0;
+}
+
+int
+main()
+{
+ pthread_t t[NUMTHREADS];
+ struct timespec abstime = { 0, 0 };
+#if defined(__MINGW32__)
+ struct timeb currSysTime;
+#else
+ struct _timeb currSysTime;
+#endif
+ const DWORD NANOSEC_PER_MILLISEC = 1000000;
+
+ assert((t[0] = pthread_self()) != NULL);
+
+ assert(pthread_cond_init(&cv, NULL) == 0);
+
+ assert(pthread_mutex_init(&mutex, NULL) == 0);
+
+ assert(pthread_mutex_lock(&mutex) == 0);
+
+ /* get current system time */
+ _ftime(&currSysTime);
+
+ abstime.tv_sec = currSysTime.time;
+ abstime.tv_nsec = NANOSEC_PER_MILLISEC * currSysTime.millitm;
+
+ assert(pthread_create(&t[1], NULL, mythread, (void *) 1) == 0);
+
+ abstime.tv_sec += 5;
+
+ assert(pthread_cond_timedwait(&cv, &mutex, &abstime) == 0);
+
+ assert(pthread_mutex_unlock(&mutex) == 0);
+
+ assert(pthread_cond_destroy(&cv) == 0);
+
+ return 0;
+}
diff --git a/tests/condvar4.c b/tests/condvar4.c
index 867746b..4c5fc38 100644
--- a/tests/condvar4.c
+++ b/tests/condvar4.c
@@ -1,106 +1,121 @@
-/*
- * File: condvar1.c
- *
- * Test Synopsis:
- * - Test PTHREAD_COND_INITIALIZER.
- *
- * Test Method (Validation or Falsification):
- * - Validation
- *
- * Requirements Tested:
- * -
- *
- * Features Tested:
- * -
- *
- * Cases Tested:
- * -
- *
- * Description:
- * - Test basic CV function but starting with a static initialised
- * CV.
- *
- * Environment:
- * -
- *
- * Input:
- * - None.
- *
- * Output:
- * - File name, Line number, and failed expression on failure.
- * - No output on success.
- *
- * Assumptions:
- * -
- *
- * Pass Criteria:
- * - pthread_cond_timedwait returns 0.
- * - Process returns zero exit status.
- *
- * Fail Criteria:
- * - pthread_cond_timedwait returns ETIMEDOUT.
- * - Process returns non-zero exit status.
- */
-
-#include "test.h"
-
-typedef struct cvthing_t_ cvthing_t;
-
-struct cvthing_t_ {
- pthread_cond_t notbusy;
- pthread_mutex_t lock;
- int busy;
- int count;
-};
-
-static cvthing_t cvthing = {
- PTHREAD_MUTEX_INITIALIZER,
- PTHREAD_COND_INITIALIZER,
-};
-
-static enum {
- NUMTHREADS = 2
-};
-
-void *
-mythread(void * arg)
-{
- assert(pthread_mutex_lock(&cvthing.lock) == 0);
-
- assert(pthread_cond_signal(&cvthing.notbusy) == 0);
-
- assert(pthread_mutex_unlock(&cvthing.lock) == 0);
-
- return 0;
-}
-
-int
-main()
-{
- pthread_t t[NUMTHREADS];
- int result[NUMTHREADS];
- struct timespec abstime = { 0, 0 };
- struct timeval curtime;
-
- assert((t[0] = pthread_self()) != NULL);
-
- assert(pthread_mutex_lock(&cvthing.lock) == 0);
-
- gettimeofday(&curtime, NULL);
- abstime.tv_sec = curtime.tv_sec + 5;
-
- assert(pthread_cond_timedwait(&cvthing.notbusy, &cvthing.lock, &abstime) == ETIMEDOUT);
-
- assert(pthread_create(&t[1], NULL, mythread, (void *) 1) == 0);
-
- gettimeofday(&curtime, NULL);
- abstime.tv_sec = curtime.tv_sec + 10;
-
- assert(pthread_cond_timedwait(&cvthing.notbusy, &cvthing.lock, &abstime) == 0);
-
- assert(pthread_mutex_unlock(&cvthing.lock) == 0);
-
- assert(pthread_cond_destroy(&cvthing) == 0);
-
- return 0;
-}
+/*
+ * File: condvar1.c
+ *
+ * Test Synopsis:
+ * - Test PTHREAD_COND_INITIALIZER.
+ *
+ * Test Method (Validation or Falsification):
+ * - Validation
+ *
+ * Requirements Tested:
+ * -
+ *
+ * Features Tested:
+ * -
+ *
+ * Cases Tested:
+ * -
+ *
+ * Description:
+ * - Test basic CV function but starting with a static initialised
+ * CV.
+ *
+ * Environment:
+ * -
+ *
+ * Input:
+ * - None.
+ *
+ * Output:
+ * - File name, Line number, and failed expression on failure.
+ * - No output on success.
+ *
+ * Assumptions:
+ * -
+ *
+ * Pass Criteria:
+ * - pthread_cond_timedwait returns 0.
+ * - Process returns zero exit status.
+ *
+ * Fail Criteria:
+ * - pthread_cond_timedwait returns ETIMEDOUT.
+ * - Process returns non-zero exit status.
+ */
+
+#include "test.h"
+#include <sys/timeb.h>
+
+typedef struct cvthing_t_ cvthing_t;
+
+struct cvthing_t_ {
+ pthread_cond_t notbusy;
+ pthread_mutex_t lock;
+};
+
+static cvthing_t cvthing = {
+ PTHREAD_MUTEX_INITIALIZER,
+ PTHREAD_COND_INITIALIZER,
+};
+
+enum {
+ NUMTHREADS = 2
+};
+
+void *
+mythread(void * arg)
+{
+ assert(pthread_mutex_lock(&cvthing.lock) == 0);
+
+ assert(pthread_cond_signal(&cvthing.notbusy) == 0);
+
+ assert(pthread_mutex_unlock(&cvthing.lock) == 0);
+
+ return 0;
+}
+
+int
+main()
+{
+ pthread_t t[NUMTHREADS];
+ struct timespec abstime = { 0, 0 };
+#if defined(__MINGW32__)
+ struct timeb currSysTime;
+#else
+ struct _timeb currSysTime;
+#endif
+ const DWORD NANOSEC_PER_MILLISEC = 1000000;
+
+ assert(cvthing.notbusy.staticinit == 1);
+ assert(cvthing.notbusy.valid == 1);
+
+ assert((t[0] = pthread_self()) != NULL);
+
+ assert(pthread_mutex_lock(&cvthing.lock) == 0);
+
+ /* get current system time */
+ _ftime(&currSysTime);
+
+ abstime.tv_sec = currSysTime.time;
+ abstime.tv_nsec = NANOSEC_PER_MILLISEC * currSysTime.millitm;
+
+ abstime.tv_sec += 5;
+
+ assert(pthread_cond_timedwait(&cvthing.notbusy, &cvthing.lock, &abstime) == ETIMEDOUT);
+
+ assert(pthread_create(&t[1], NULL, mythread, (void *) 1) == 0);
+
+ _ftime(&currSysTime);
+
+ abstime.tv_sec = currSysTime.time;
+ abstime.tv_nsec = NANOSEC_PER_MILLISEC * currSysTime.millitm;
+
+ abstime.tv_sec += 5;
+
+ assert(pthread_cond_timedwait(&cvthing.notbusy, &cvthing.lock, &abstime) == 0);
+
+ assert(pthread_mutex_unlock(&cvthing.lock) == 0);
+
+ assert(pthread_cond_destroy(&cvthing.notbusy) == 0);
+
+ return 0;
+}