Improvements to synchronization tests.

This commit is contained in:
Geoffrey Challen 2016-02-11 13:55:09 -05:00
parent 01f2d3ea2c
commit 875b75bf24
6 changed files with 120 additions and 10 deletions

View File

@ -442,6 +442,7 @@ file test/threadlisttest.c
file test/threadtest.c
file test/tt3.c
file test/synchtest.c
file test/rwtest.c
file test/semunit.c
file test/hmacunit.c
file test/kmalloctest.c

View File

@ -45,6 +45,6 @@
*/
#undef SECRET_TESTING
#define SECRET ""
#define SECRET "TEST"
#endif /* _SECRET_H_ */

View File

@ -63,6 +63,8 @@ int locktest2(int, char **);
int locktest3(int, char **);
int cvtest(int, char **);
int cvtest2(int, char **);
int cvtest3(int, char **);
int cvtest4(int, char **);
int rwtest(int, char **);
/* semaphore unit tests */

View File

@ -481,6 +481,8 @@ static const char *testmenu[] = {
"[lt3] Lock test 3 (panics) (1) ",
"[cvt1] CV test 1 (1) ",
"[cvt2] CV test 2 (1) ",
"[cvt3] CV test 3 (panics) (1) ",
"[cvt4] CV test 4 (panics) (1) ",
"[rwt1] RW lock test (1) ",
#if OPT_SYNCHPROBS
"[sp1] Whalemating test (1) ",
@ -617,6 +619,8 @@ static struct {
{ "lt3", locktest3 },
{ "cvt1", cvtest },
{ "cvt2", cvtest2 },
{ "cvt3", cvtest3 },
{ "cvt4", cvtest4 },
{ "rwt1", rwtest },
#if OPT_SYNCHPROBS
{ "sp1", whalemating },

18
kern/test/rwtest.c Normal file
View File

@ -0,0 +1,18 @@
#include <types.h>
#include <lib.h>
#include <clock.h>
#include <thread.h>
#include <synch.h>
#include <test.h>
#include <kern/secret.h>
#include <spinlock.h>
int rwtest(int nargs, char **args) {
(void)nargs;
(void)args;
kprintf_n("rwt1 unimplemented\n");
success(FAIL, SECRET, "rwt1");
return 0;
}

View File

@ -80,6 +80,7 @@ semtestthread(void *junk, unsigned long num)
kprintf_n("Thread %2lu: ", num);
for (i=0; i<NSEMLOOPS; i++) {
kprintf_t(".");
kprintf_n("%2lu", num);
random_yielder(4);
if (semtest_current != num) {
@ -122,6 +123,7 @@ semtest(int nargs, char **args)
P(testsem);
P(testsem);
kprintf_n("OK\n");
kprintf_t(".");
test_status = SUCCESS;
for (i=0; i<NTHREADS; i++) {
@ -140,6 +142,7 @@ semtest(int nargs, char **args)
sem_destroy(donesem);
testsem = donesem = NULL;
kprintf_t("\n");
success(test_status, SECRET, "sem1");
return 0;
@ -154,6 +157,7 @@ locktestthread(void *junk, unsigned long num)
int i;
for (i=0; i<NLOCKLOOPS; i++) {
kprintf_t(".");
lock_acquire(testlock);
random_yielder(4);
@ -202,6 +206,7 @@ locktestthread(void *junk, unsigned long num)
/* Check for solutions that don't track ownership properly */
for (i=0; i<NLOCKLOOPS; i++) {
kprintf_t(".");
if (lock_do_i_hold(testlock)) {
goto fail2;
}
@ -261,6 +266,7 @@ locktest(int nargs, char **args)
testlock = NULL;
donesem = NULL;
kprintf_t("\n");
success(test_status, SECRET, "lt1");
return 0;
@ -285,10 +291,14 @@ locktest2(int nargs, char **args) {
}
}
success(SUCCESS, SECRET, "lt2");
ksecprintf(SECRET, "Should panic...", "lt2");
lock_release(testlock);
/* Should not get here on success. */
success(FAIL, SECRET, "lt2");
lock_destroy(testlock);
testlock = NULL;
return 0;
@ -302,7 +312,7 @@ locktest3(int nargs, char **args) {
int i;
kprintf_n("Starting lt3...\n");
kprintf_n("(This test panics on success!){\n");
kprintf_n("(This test panics on success!)\n");
for (i=0; i<CREATELOOPS; i++) {
testlock = lock_create("testlock");
if (testlock == NULL) {
@ -313,11 +323,14 @@ locktest3(int nargs, char **args) {
}
}
success(SUCCESS, SECRET, "lt3");
ksecprintf(SECRET, "Should panic...", "lt3");
lock_acquire(testlock);
lock_destroy(testlock);
/* Should not get here on success. */
success(FAIL, SECRET, "lt3");
testlock = NULL;
return 0;
@ -334,6 +347,7 @@ cvtestthread(void *junk, unsigned long num)
struct timespec ts1, ts2;
for (i=0; i<NCVLOOPS; i++) {
kprintf_t(".");
lock_acquire(testlock);
while (testval1 != num) {
testval2 = 0;
@ -432,6 +446,7 @@ cvtest(int nargs, char **args)
testcv = NULL;
donesem = NULL;
kprintf_t("\n");
success(test_status, SECRET, "cvt1");
return 0;
@ -466,6 +481,7 @@ sleepthread(void *junk1, unsigned long junk2)
random_yielder(4);
for (j=0; j<NLOOPS; j++) {
kprintf_t(".");
for (i=0; i<NCVS; i++) {
lock_acquire(testlocks[i]);
random_yielder(4);
@ -495,6 +511,7 @@ wakethread(void *junk1, unsigned long junk2)
random_yielder(4);
for (j=0; j<NLOOPS; j++) {
kprintf_t(".");
for (i=0; i<NCVS; i++) {
random_yielder(4);
P(gatesem);
@ -567,18 +584,86 @@ cvtest2(int nargs, char **args)
testcvs[i] = NULL;
}
kprintf_t("\n");
success(test_status, SECRET, "cvt2");
return 0;
}
int rwtest(int nargs, char **args) {
int
cvtest3(int nargs, char **args) {
(void)nargs;
(void)args;
kprintf_n("rwt1 unimplemented\n");
success(FAIL, SECRET, "rwt1");
int i;
kprintf_n("Starting cvt3...\n");
kprintf_n("(This test panics on success!)\n");
for (i=0; i<CREATELOOPS; i++) {
testlock = lock_create("testlock");
if (testlock == NULL) {
panic("lockt1: lock_create failed\n");
}
testcv = cv_create("testcv");
if (testcv == NULL) {
panic("cvt1: cv_create failed\n");
}
if (i != CREATELOOPS - 1) {
lock_destroy(testlock);
cv_destroy(testcv);
}
}
ksecprintf(SECRET, "Should panic...", "cvt3");
cv_wait(testcv, testlock);
/* Should not get here on success. */
success(FAIL, SECRET, "cvt3");
lock_destroy(testlock);
cv_destroy(testcv);
testcv = NULL;
testlock = NULL;
return 0;
}
int
cvtest4(int nargs, char **args) {
(void)nargs;
(void)args;
int i;
kprintf_n("Starting cvt4...\n");
kprintf_n("(This test panics on success!)\n");
for (i=0; i<CREATELOOPS; i++) {
testlock = lock_create("testlock");
if (testlock == NULL) {
panic("lockt1: lock_create failed\n");
}
testcv = cv_create("testcv");
if (testcv == NULL) {
panic("cvt1: cv_create failed\n");
}
if (i != CREATELOOPS - 1) {
lock_destroy(testlock);
cv_destroy(testcv);
}
}
ksecprintf(SECRET, "Should panic...", "cvt4");
cv_broadcast(testcv, testlock);
/* Should not get here on success. */
success(FAIL, SECRET, "cvt4");
lock_destroy(testlock);
cv_destroy(testcv);
testcv = NULL;
testlock = NULL;
return 0;
}