summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/ChangeLog12
-rw-r--r--tests/benchtest5.c141
-rw-r--r--tests/condvar2.c1
-rw-r--r--tests/condvar2_1.c3
-rw-r--r--tests/condvar3_1.c3
-rw-r--r--tests/condvar3_2.c3
-rw-r--r--tests/count1.c6
-rw-r--r--tests/inherit1.c51
-rw-r--r--tests/priority1.c63
-rw-r--r--tests/priority2.c52
10 files changed, 307 insertions, 28 deletions
diff --git a/tests/ChangeLog b/tests/ChangeLog
index 93e6342..77d81db 100644
--- a/tests/ChangeLog
+++ b/tests/ChangeLog
@@ -1,3 +1,15 @@
+2001-10-25 Ross Johnson <rpj@setup1.ise.canberra.edu.au>
+
+ * condvar2.c: Remove reference to cv->nWaitersUnblocked.
+ * condvar2_1.c: Likewise; lower NUMTHREADS from 60 to 30.
+ * condvar3_1.c: Likewise.
+ * condvar3_2.c: Likewise.
+ * count1.c: lower NUMTHREADS from 60 to 30.
+ * inherit1.c: Determine valid priority values and then
+ assert values returned by POSIX routines are the same.
+ * priority1.c: Likewise.
+ * priority2.c: Likewise.
+
2001-07-12 Ross Johnson <rpj@setup1.ise.canberra.edu.au>
* barrier5.c: Assert that precisely one thread receives
diff --git a/tests/benchtest5.c b/tests/benchtest5.c
new file mode 100644
index 0000000..0bdaf90
--- /dev/null
+++ b/tests/benchtest5.c
@@ -0,0 +1,141 @@
+/*
+ * benchtest5.c
+ *
+ * Measure time taken to complete an elementary operation.
+ *
+ * - Semaphore
+ * Single thread iteration over post/wait for a semaphore.
+ */
+
+#include "test.h"
+#include <sys/timeb.h>
+
+#ifdef __GNUC__
+#include <stdlib.h>
+#endif
+
+#include "benchtest.h"
+
+#define ITERATIONS 10000000L
+
+sem_t sema;
+
+struct _timeb currSysTimeStart;
+struct _timeb currSysTimeStop;
+long durationMilliSecs;
+long overHeadMilliSecs = 0;
+
+#define GetDurationMilliSecs(_TStart, _TStop) ((_TStop.time*1000+_TStop.millitm) \
+ - (_TStart.time*1000+_TStart.millitm))
+
+/*
+ * Dummy use of j, otherwise the loop may be removed by the optimiser
+ * when doing the overhead timing with an empty loop.
+ */
+#define TESTSTART \
+ { int i, j = 0, k = 0; _ftime(&currSysTimeStart); for (i = 0; i < ITERATIONS; i++) { j++;
+
+#define TESTSTOP \
+ }; _ftime(&currSysTimeStop); if (j + k == i) j++; }
+
+
+void
+reportTest (char * testNameString)
+{
+ durationMilliSecs = GetDurationMilliSecs(currSysTimeStart, currSysTimeStop) - overHeadMilliSecs;
+
+ printf( "%-40s %15ld %15.3f\n",
+ testNameString,
+ durationMilliSecs,
+ (float) durationMilliSecs * 1E3 / ITERATIONS);
+}
+
+
+int
+main (int argc, char *argv[])
+{
+ printf( "========================================================================\n");
+ printf( "\nOperations on a semaphore.\n%ld iterations\n\n",
+ ITERATIONS);
+ printf( "%-40s %15s %15s\n",
+ "Test",
+ "Total(msec)",
+ "average(usec)");
+ printf( "------------------------------------------------------------------------\n");
+
+ /*
+ * Time the loop overhead so we can subtract it from the actual test times.
+ */
+
+ TESTSTART
+ assert(1 == 1);
+ TESTSTOP
+
+ durationMilliSecs = GetDurationMilliSecs(currSysTimeStart, currSysTimeStop) - overHeadMilliSecs;
+ overHeadMilliSecs = durationMilliSecs;
+
+
+ /*
+ * Now we can start the actual tests
+ */
+ assert(sem_init(&sema, 0, 0) == 0);
+ TESTSTART
+ assert(sem_post(&sema) == 0);
+ TESTSTOP
+ assert(sem_destroy(&sema) == 0);
+
+ reportTest("Post");
+
+
+ assert(sem_init(&sema, 0, ITERATIONS) == 0);
+ TESTSTART
+ assert(sem_wait(&sema) == 0);
+ TESTSTOP
+ assert(sem_destroy(&sema) == 0);
+
+ reportTest("Wait without blocking");
+
+
+ /*
+ * Time the loop overhead so we can subtract it from the actual test times.
+ */
+
+ TESTSTART
+ assert(1 == 1);
+ assert(1 == 1);
+ TESTSTOP
+
+ durationMilliSecs = GetDurationMilliSecs(currSysTimeStart, currSysTimeStop) - overHeadMilliSecs;
+ overHeadMilliSecs = durationMilliSecs;
+
+
+ /*
+ * Now we can start the actual tests
+ */
+ assert(sem_init(&sema, 0, 0) == 0);
+ TESTSTART
+ assert(sem_post(&sema) == 0);
+ assert(sem_wait(&sema) == 0);
+ TESTSTOP
+ assert(sem_destroy(&sema) == 0);
+
+ reportTest("Post then Wait without blocking");
+
+
+ assert(sem_init(&sema, 0, 1) == 0);
+ TESTSTART
+ assert(sem_wait(&sema) == 0);
+ assert(sem_post(&sema) == 0);
+ TESTSTOP
+ assert(sem_destroy(&sema) == 0);
+
+ reportTest("Wait then Post without blocking");
+
+ printf( "========================================================================\n");
+
+ /*
+ * End of tests.
+ */
+
+ return 0;
+}
diff --git a/tests/condvar2.c b/tests/condvar2.c
index 369cef6..211f0ec 100644
--- a/tests/condvar2.c
+++ b/tests/condvar2.c
@@ -80,7 +80,6 @@ main()
{
fprintf(stderr, "Result = %s\n", error_string[result]);
fprintf(stderr, "\tWaitersBlocked = %ld\n", cv->nWaitersBlocked);
- fprintf(stderr, "\tWaitersUnblocked = %ld\n", cv->nWaitersUnblocked);
fprintf(stderr, "\tWaitersGone = %ld\n", cv->nWaitersGone);
fprintf(stderr, "\tWaitersToUnblock = %ld\n", cv->nWaitersToUnblock);
fflush(stderr);
diff --git a/tests/condvar2_1.c b/tests/condvar2_1.c
index feae128..32bf9fc 100644
--- a/tests/condvar2_1.c
+++ b/tests/condvar2_1.c
@@ -49,7 +49,7 @@ static pthread_mutex_t mutex;
static struct timespec abstime = { 0, 0 };
enum {
- NUMTHREADS = 60
+ NUMTHREADS = 30
};
void *
@@ -108,7 +108,6 @@ main()
{
fprintf(stderr, "Result = %s\n", error_string[result]);
fprintf(stderr, "\tWaitersBlocked = %ld\n", cv->nWaitersBlocked);
- fprintf(stderr, "\tWaitersUnblocked = %ld\n", cv->nWaitersUnblocked);
fprintf(stderr, "\tWaitersGone = %ld\n", cv->nWaitersGone);
fprintf(stderr, "\tWaitersToUnblock = %ld\n", cv->nWaitersToUnblock);
fflush(stderr);
diff --git a/tests/condvar3_1.c b/tests/condvar3_1.c
index ea5f33f..4cf460a 100644
--- a/tests/condvar3_1.c
+++ b/tests/condvar3_1.c
@@ -56,7 +56,7 @@ static int awoken = 0;
static int waiting = 0;
enum {
- NUMTHREADS = 60
+ NUMTHREADS = 30
};
void *
@@ -146,7 +146,6 @@ main()
{
fprintf(stderr, "Result = %s\n", error_string[result]);
fprintf(stderr, "\tWaitersBlocked = %ld\n", cv->nWaitersBlocked);
- fprintf(stderr, "\tWaitersUnblocked = %ld\n", cv->nWaitersUnblocked);
fprintf(stderr, "\tWaitersGone = %ld\n", cv->nWaitersGone);
fprintf(stderr, "\tWaitersToUnblock = %ld\n", cv->nWaitersToUnblock);
fflush(stderr);
diff --git a/tests/condvar3_2.c b/tests/condvar3_2.c
index e5f451b..e2ccfd0 100644
--- a/tests/condvar3_2.c
+++ b/tests/condvar3_2.c
@@ -54,7 +54,7 @@ static int timedout = 0;
static int awoken = 0;
enum {
- NUMTHREADS = 60
+ NUMTHREADS = 30
};
void *
@@ -140,7 +140,6 @@ main()
{
fprintf(stderr, "Result = %s\n", error_string[result]);
fprintf(stderr, "\tWaitersBlocked = %ld\n", cv->nWaitersBlocked);
- fprintf(stderr, "\tWaitersUnblocked = %ld\n", cv->nWaitersUnblocked);
fprintf(stderr, "\tWaitersGone = %ld\n", cv->nWaitersGone);
fprintf(stderr, "\tWaitersToUnblock = %ld\n", cv->nWaitersToUnblock);
fflush(stderr);
diff --git a/tests/count1.c b/tests/count1.c
index ae30ed0..b00f7b3 100644
--- a/tests/count1.c
+++ b/tests/count1.c
@@ -7,11 +7,7 @@
#include "test.h"
-#if ! defined (__MINGW32__) || defined (__MSVCRT__)
-#define NUMTHREADS (60)
-#else
-#define NUMTHREADS (59)
-#endif
+#define NUMTHREADS (30)
static pthread_mutex_t lock = PTHREAD_MUTEX_INITIALIZER;
static pthread_t threads[NUMTHREADS];
diff --git a/tests/inherit1.c b/tests/inherit1.c
index a909eb7..2263cc6 100644
--- a/tests/inherit1.c
+++ b/tests/inherit1.c
@@ -41,6 +41,16 @@
#include "test.h"
+enum {
+ PTW32TEST_THREAD_INIT_PRIO = 0,
+ PTW32TEST_MAXPRIORITIES = 512
+};
+
+int minPrio;
+int maxPrio;
+int validPriorities[PTW32TEST_MAXPRIORITIES];
+
+
void * func(void * arg)
{
int policy;
@@ -50,6 +60,32 @@ void * func(void * arg)
return (void *) param.sched_priority;
}
+
+void *
+getValidPriorities(void * arg)
+{
+ int prioSet;
+ pthread_t threadID = pthread_self();
+ HANDLE threadH = pthread_getw32threadhandle_np(threadID);
+
+ for (prioSet = minPrio;
+ prioSet <= maxPrio;
+ prioSet++)
+ {
+ /*
+ * If prioSet is invalid then the threads priority is unchanged
+ * from the previous value. Make the previous value a known
+ * one so that we can check later.
+ */
+ SetThreadPriority(threadH, PTW32TEST_THREAD_INIT_PRIO);
+ SetThreadPriority(threadH, prioSet);
+ validPriorities[prioSet+(PTW32TEST_MAXPRIORITIES/2)] = GetThreadPriority(threadH);
+ }
+
+ return (void *) 0;
+}
+
+
int
main()
{
@@ -59,29 +95,36 @@ main()
void * result = NULL;
struct sched_param param;
struct sched_param mainParam;
- int maxPrio;
- int minPrio;
int prio;
int policy;
int inheritsched = -1;
+ pthread_t threadID = pthread_self();
+ HANDLE threadH = pthread_getw32threadhandle_np(threadID);
assert((maxPrio = sched_get_priority_max(SCHED_OTHER)) != -1);
assert((minPrio = sched_get_priority_min(SCHED_OTHER)) != -1);
+ assert(pthread_create(&t, NULL, getValidPriorities, NULL) == 0);
+ assert(pthread_join(t, &result) == 0);
+
assert(pthread_attr_init(&attr) == 0);
assert(pthread_attr_setinheritsched(&attr, PTHREAD_INHERIT_SCHED) == 0);
assert(pthread_attr_getinheritsched(&attr, &inheritsched) == 0);
assert(inheritsched == PTHREAD_INHERIT_SCHED);
- for (prio = minPrio; prio < maxPrio; prio++)
+ for (prio = minPrio; prio <= maxPrio; prio++)
{
mainParam.sched_priority = prio;
+ /* Set the thread's priority to a known initial value. */
+ SetThreadPriority(threadH, PTW32TEST_THREAD_INIT_PRIO);
+
/* Change the main thread priority */
assert(pthread_setschedparam(mainThread, SCHED_OTHER, &mainParam) == 0);
assert(pthread_getschedparam(mainThread, &policy, &mainParam) == 0);
assert(policy == SCHED_OTHER);
- assert(mainParam.sched_priority == prio);
+ assert(mainParam.sched_priority ==
+ validPriorities[prio+(PTW32TEST_MAXPRIORITIES/2)]);
for (param.sched_priority = prio;
param.sched_priority <= maxPrio;
diff --git a/tests/priority1.c b/tests/priority1.c
index a311028..1ec9f4d 100644
--- a/tests/priority1.c
+++ b/tests/priority1.c
@@ -41,16 +41,52 @@
#include "test.h"
-void * func(void * arg)
+enum {
+ PTW32TEST_THREAD_INIT_PRIO = 0,
+ PTW32TEST_MAXPRIORITIES = 512
+};
+
+int minPrio;
+int maxPrio;
+int validPriorities[PTW32TEST_MAXPRIORITIES];
+
+void *
+func(void * arg)
{
int policy;
struct sched_param param;
+ pthread_t threadID = pthread_self();
- assert(pthread_getschedparam(pthread_self(), &policy, &param) == 0);
+ assert(pthread_getschedparam(threadID, &policy, &param) == 0);
assert(policy == SCHED_OTHER);
- return (void *) param.sched_priority;
+ return (void *) (param.sched_priority);
+}
+
+void *
+getValidPriorities(void * arg)
+{
+ int prioSet;
+ pthread_t threadID = pthread_self();
+ HANDLE threadH = pthread_getw32threadhandle_np(threadID);
+
+ for (prioSet = minPrio;
+ prioSet <= maxPrio;
+ prioSet++)
+ {
+ /*
+ * If prioSet is invalid then the threads priority is unchanged
+ * from the previous value. Make the previous value a known
+ * one so that we can check later.
+ */
+ SetThreadPriority(threadH, PTW32TEST_THREAD_INIT_PRIO);
+ SetThreadPriority(threadH, prioSet);
+ validPriorities[prioSet+(PTW32TEST_MAXPRIORITIES/2)] = GetThreadPriority(threadH);
+ }
+
+ return (void *) 0;
}
-
+
+
int
main()
{
@@ -58,20 +94,29 @@ main()
pthread_attr_t attr;
void * result = NULL;
struct sched_param param;
- int maxPrio = sched_get_priority_max(SCHED_OTHER);
- int minPrio = sched_get_priority_min(SCHED_OTHER);
+
+ assert((maxPrio = sched_get_priority_max(SCHED_OTHER)) != -1);
+ assert((minPrio = sched_get_priority_min(SCHED_OTHER)) != -1);
+
+ assert(pthread_create(&t, NULL, getValidPriorities, NULL) == 0);
+ assert(pthread_join(t, &result) == 0);
assert(pthread_attr_init(&attr) == 0);
assert(pthread_attr_setinheritsched(&attr, PTHREAD_EXPLICIT_SCHED) == 0);
+ /* Set the thread's priority to a known initial value. */
+ SetThreadPriority(pthread_getw32threadhandle_np(pthread_self()),
+ PTW32TEST_THREAD_INIT_PRIO);
+
for (param.sched_priority = minPrio;
param.sched_priority <= maxPrio;
param.sched_priority++)
{
assert(pthread_attr_setschedparam(&attr, &param) == 0);
- assert(pthread_create(&t, &attr, func, NULL) == 0);
- pthread_join(t, &result);
- assert((int) result == param.sched_priority);
+ assert(pthread_create(&t, &attr, func, (void *) &attr) == 0);
+ assert(pthread_join(t, &result) == 0);
+ assert((int) result ==
+ validPriorities[param.sched_priority+(PTW32TEST_MAXPRIORITIES/2)]);
}
return 0;
diff --git a/tests/priority2.c b/tests/priority2.c
index 4dcf385..06a5a13 100644
--- a/tests/priority2.c
+++ b/tests/priority2.c
@@ -41,6 +41,14 @@
#include "test.h"
+enum {
+ PTW32TEST_THREAD_INIT_PRIO = 0,
+ PTW32TEST_MAXPRIORITIES = 512
+};
+
+int minPrio;
+int maxPrio;
+int validPriorities[PTW32TEST_MAXPRIORITIES];
pthread_mutex_t startMx = PTHREAD_MUTEX_INITIALIZER;
void * func(void * arg)
@@ -54,15 +62,52 @@ void * func(void * arg)
assert(policy == SCHED_OTHER);
return (void *) param.sched_priority;
}
+
+void *
+getValidPriorities(void * arg)
+{
+ int prioSet;
+ pthread_t threadID = pthread_self();
+ HANDLE threadH = pthread_getw32threadhandle_np(threadID);
+
+ for (prioSet = minPrio;
+ prioSet <= maxPrio;
+ prioSet++)
+ {
+ /*
+ * If prioSet is invalid then the threads priority is unchanged
+ * from the previous value. Make the previous value a known
+ * one so that we can check later.
+ */
+ SetThreadPriority(threadH, PTW32TEST_THREAD_INIT_PRIO);
+ SetThreadPriority(threadH, prioSet);
+ validPriorities[prioSet+(PTW32TEST_MAXPRIORITIES/2)] = GetThreadPriority(threadH);
+ }
+
+ return (void *) 0;
+}
+
+
int
main()
{
pthread_t t;
void * result = NULL;
struct sched_param param;
- int maxPrio = sched_get_priority_max(SCHED_OTHER);
- int minPrio = sched_get_priority_min(SCHED_OTHER);
+
+ assert((maxPrio = sched_get_priority_max(SCHED_OTHER)) != -1);
+ assert((minPrio = sched_get_priority_min(SCHED_OTHER)) != -1);
+
+ assert(pthread_create(&t, NULL, getValidPriorities, NULL) == 0);
+ assert(pthread_join(t, &result) == 0);
+
+ /* Set the thread's priority to a known initial value.
+ * If the new priority is invalid then the threads priority
+ * is unchanged from the previous value.
+ */
+ SetThreadPriority(pthread_getw32threadhandle_np(pthread_self()),
+ PTW32TEST_THREAD_INIT_PRIO);
for (param.sched_priority = minPrio;
param.sched_priority <= maxPrio;
@@ -73,7 +118,8 @@ main()
assert(pthread_setschedparam(t, SCHED_OTHER, &param) == 0);
assert(pthread_mutex_unlock(&startMx) == 0);
pthread_join(t, &result);
- assert((int) result == param.sched_priority);
+ assert((int) result ==
+ validPriorities[param.sched_priority+(PTW32TEST_MAXPRIORITIES/2)]);
}
return 0;