Improvements to synchronization tests.
This commit is contained in:
parent
01f2d3ea2c
commit
875b75bf24
@ -442,6 +442,7 @@ file test/threadlisttest.c
|
|||||||
file test/threadtest.c
|
file test/threadtest.c
|
||||||
file test/tt3.c
|
file test/tt3.c
|
||||||
file test/synchtest.c
|
file test/synchtest.c
|
||||||
|
file test/rwtest.c
|
||||||
file test/semunit.c
|
file test/semunit.c
|
||||||
file test/hmacunit.c
|
file test/hmacunit.c
|
||||||
file test/kmalloctest.c
|
file test/kmalloctest.c
|
||||||
|
@ -45,6 +45,6 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#undef SECRET_TESTING
|
#undef SECRET_TESTING
|
||||||
#define SECRET ""
|
#define SECRET "TEST"
|
||||||
|
|
||||||
#endif /* _SECRET_H_ */
|
#endif /* _SECRET_H_ */
|
||||||
|
@ -63,6 +63,8 @@ int locktest2(int, char **);
|
|||||||
int locktest3(int, char **);
|
int locktest3(int, char **);
|
||||||
int cvtest(int, char **);
|
int cvtest(int, char **);
|
||||||
int cvtest2(int, char **);
|
int cvtest2(int, char **);
|
||||||
|
int cvtest3(int, char **);
|
||||||
|
int cvtest4(int, char **);
|
||||||
int rwtest(int, char **);
|
int rwtest(int, char **);
|
||||||
|
|
||||||
/* semaphore unit tests */
|
/* semaphore unit tests */
|
||||||
|
@ -481,6 +481,8 @@ static const char *testmenu[] = {
|
|||||||
"[lt3] Lock test 3 (panics) (1) ",
|
"[lt3] Lock test 3 (panics) (1) ",
|
||||||
"[cvt1] CV test 1 (1) ",
|
"[cvt1] CV test 1 (1) ",
|
||||||
"[cvt2] CV test 2 (1) ",
|
"[cvt2] CV test 2 (1) ",
|
||||||
|
"[cvt3] CV test 3 (panics) (1) ",
|
||||||
|
"[cvt4] CV test 4 (panics) (1) ",
|
||||||
"[rwt1] RW lock test (1) ",
|
"[rwt1] RW lock test (1) ",
|
||||||
#if OPT_SYNCHPROBS
|
#if OPT_SYNCHPROBS
|
||||||
"[sp1] Whalemating test (1) ",
|
"[sp1] Whalemating test (1) ",
|
||||||
@ -617,6 +619,8 @@ static struct {
|
|||||||
{ "lt3", locktest3 },
|
{ "lt3", locktest3 },
|
||||||
{ "cvt1", cvtest },
|
{ "cvt1", cvtest },
|
||||||
{ "cvt2", cvtest2 },
|
{ "cvt2", cvtest2 },
|
||||||
|
{ "cvt3", cvtest3 },
|
||||||
|
{ "cvt4", cvtest4 },
|
||||||
{ "rwt1", rwtest },
|
{ "rwt1", rwtest },
|
||||||
#if OPT_SYNCHPROBS
|
#if OPT_SYNCHPROBS
|
||||||
{ "sp1", whalemating },
|
{ "sp1", whalemating },
|
||||||
|
18
kern/test/rwtest.c
Normal file
18
kern/test/rwtest.c
Normal 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;
|
||||||
|
}
|
@ -80,6 +80,7 @@ semtestthread(void *junk, unsigned long num)
|
|||||||
|
|
||||||
kprintf_n("Thread %2lu: ", num);
|
kprintf_n("Thread %2lu: ", num);
|
||||||
for (i=0; i<NSEMLOOPS; i++) {
|
for (i=0; i<NSEMLOOPS; i++) {
|
||||||
|
kprintf_t(".");
|
||||||
kprintf_n("%2lu", num);
|
kprintf_n("%2lu", num);
|
||||||
random_yielder(4);
|
random_yielder(4);
|
||||||
if (semtest_current != num) {
|
if (semtest_current != num) {
|
||||||
@ -122,6 +123,7 @@ semtest(int nargs, char **args)
|
|||||||
P(testsem);
|
P(testsem);
|
||||||
P(testsem);
|
P(testsem);
|
||||||
kprintf_n("OK\n");
|
kprintf_n("OK\n");
|
||||||
|
kprintf_t(".");
|
||||||
test_status = SUCCESS;
|
test_status = SUCCESS;
|
||||||
|
|
||||||
for (i=0; i<NTHREADS; i++) {
|
for (i=0; i<NTHREADS; i++) {
|
||||||
@ -140,6 +142,7 @@ semtest(int nargs, char **args)
|
|||||||
sem_destroy(donesem);
|
sem_destroy(donesem);
|
||||||
testsem = donesem = NULL;
|
testsem = donesem = NULL;
|
||||||
|
|
||||||
|
kprintf_t("\n");
|
||||||
success(test_status, SECRET, "sem1");
|
success(test_status, SECRET, "sem1");
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
@ -154,6 +157,7 @@ locktestthread(void *junk, unsigned long num)
|
|||||||
int i;
|
int i;
|
||||||
|
|
||||||
for (i=0; i<NLOCKLOOPS; i++) {
|
for (i=0; i<NLOCKLOOPS; i++) {
|
||||||
|
kprintf_t(".");
|
||||||
lock_acquire(testlock);
|
lock_acquire(testlock);
|
||||||
random_yielder(4);
|
random_yielder(4);
|
||||||
|
|
||||||
@ -202,6 +206,7 @@ locktestthread(void *junk, unsigned long num)
|
|||||||
/* Check for solutions that don't track ownership properly */
|
/* Check for solutions that don't track ownership properly */
|
||||||
|
|
||||||
for (i=0; i<NLOCKLOOPS; i++) {
|
for (i=0; i<NLOCKLOOPS; i++) {
|
||||||
|
kprintf_t(".");
|
||||||
if (lock_do_i_hold(testlock)) {
|
if (lock_do_i_hold(testlock)) {
|
||||||
goto fail2;
|
goto fail2;
|
||||||
}
|
}
|
||||||
@ -261,6 +266,7 @@ locktest(int nargs, char **args)
|
|||||||
testlock = NULL;
|
testlock = NULL;
|
||||||
donesem = NULL;
|
donesem = NULL;
|
||||||
|
|
||||||
|
kprintf_t("\n");
|
||||||
success(test_status, SECRET, "lt1");
|
success(test_status, SECRET, "lt1");
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
@ -285,10 +291,14 @@ locktest2(int nargs, char **args) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
success(SUCCESS, SECRET, "lt2");
|
ksecprintf(SECRET, "Should panic...", "lt2");
|
||||||
lock_release(testlock);
|
lock_release(testlock);
|
||||||
|
|
||||||
/* Should not get here on success. */
|
/* Should not get here on success. */
|
||||||
|
|
||||||
success(FAIL, SECRET, "lt2");
|
success(FAIL, SECRET, "lt2");
|
||||||
|
|
||||||
|
lock_destroy(testlock);
|
||||||
testlock = NULL;
|
testlock = NULL;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
@ -302,7 +312,7 @@ locktest3(int nargs, char **args) {
|
|||||||
int i;
|
int i;
|
||||||
|
|
||||||
kprintf_n("Starting lt3...\n");
|
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++) {
|
for (i=0; i<CREATELOOPS; i++) {
|
||||||
testlock = lock_create("testlock");
|
testlock = lock_create("testlock");
|
||||||
if (testlock == NULL) {
|
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_acquire(testlock);
|
||||||
lock_destroy(testlock);
|
lock_destroy(testlock);
|
||||||
|
|
||||||
/* Should not get here on success. */
|
/* Should not get here on success. */
|
||||||
|
|
||||||
success(FAIL, SECRET, "lt3");
|
success(FAIL, SECRET, "lt3");
|
||||||
|
|
||||||
testlock = NULL;
|
testlock = NULL;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
@ -334,6 +347,7 @@ cvtestthread(void *junk, unsigned long num)
|
|||||||
struct timespec ts1, ts2;
|
struct timespec ts1, ts2;
|
||||||
|
|
||||||
for (i=0; i<NCVLOOPS; i++) {
|
for (i=0; i<NCVLOOPS; i++) {
|
||||||
|
kprintf_t(".");
|
||||||
lock_acquire(testlock);
|
lock_acquire(testlock);
|
||||||
while (testval1 != num) {
|
while (testval1 != num) {
|
||||||
testval2 = 0;
|
testval2 = 0;
|
||||||
@ -432,6 +446,7 @@ cvtest(int nargs, char **args)
|
|||||||
testcv = NULL;
|
testcv = NULL;
|
||||||
donesem = NULL;
|
donesem = NULL;
|
||||||
|
|
||||||
|
kprintf_t("\n");
|
||||||
success(test_status, SECRET, "cvt1");
|
success(test_status, SECRET, "cvt1");
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
@ -466,6 +481,7 @@ sleepthread(void *junk1, unsigned long junk2)
|
|||||||
random_yielder(4);
|
random_yielder(4);
|
||||||
|
|
||||||
for (j=0; j<NLOOPS; j++) {
|
for (j=0; j<NLOOPS; j++) {
|
||||||
|
kprintf_t(".");
|
||||||
for (i=0; i<NCVS; i++) {
|
for (i=0; i<NCVS; i++) {
|
||||||
lock_acquire(testlocks[i]);
|
lock_acquire(testlocks[i]);
|
||||||
random_yielder(4);
|
random_yielder(4);
|
||||||
@ -495,6 +511,7 @@ wakethread(void *junk1, unsigned long junk2)
|
|||||||
random_yielder(4);
|
random_yielder(4);
|
||||||
|
|
||||||
for (j=0; j<NLOOPS; j++) {
|
for (j=0; j<NLOOPS; j++) {
|
||||||
|
kprintf_t(".");
|
||||||
for (i=0; i<NCVS; i++) {
|
for (i=0; i<NCVS; i++) {
|
||||||
random_yielder(4);
|
random_yielder(4);
|
||||||
P(gatesem);
|
P(gatesem);
|
||||||
@ -567,18 +584,86 @@ cvtest2(int nargs, char **args)
|
|||||||
testcvs[i] = NULL;
|
testcvs[i] = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
kprintf_t("\n");
|
||||||
success(test_status, SECRET, "cvt2");
|
success(test_status, SECRET, "cvt2");
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int
|
||||||
int rwtest(int nargs, char **args) {
|
cvtest3(int nargs, char **args) {
|
||||||
(void)nargs;
|
(void)nargs;
|
||||||
(void)args;
|
(void)args;
|
||||||
|
|
||||||
kprintf_n("rwt1 unimplemented\n");
|
int i;
|
||||||
success(FAIL, SECRET, "rwt1");
|
|
||||||
|
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;
|
return 0;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user