New CV test.

This commit is contained in:
Geoffrey Challen
2016-02-18 16:14:48 -05:00
parent 08fd92507d
commit 00eb1b44fb
4 changed files with 149 additions and 55 deletions

View File

@@ -56,7 +56,9 @@ static volatile unsigned long testval3;
static volatile int32_t testval4;
static struct semaphore *testsem = NULL;
static struct semaphore *testsem2 = NULL;
static struct lock *testlock = NULL;
static struct lock *testlock2 = NULL;
static struct cv *testcv = NULL;
static struct semaphore *donesem = NULL;
@@ -292,18 +294,12 @@ locktest2(int nargs, char **args) {
(void)nargs;
(void)args;
int i;
kprintf_n("Starting lt2...\n");
kprintf_n("(This test panics on success!)\n");
for (i=0; i<CREATELOOPS; i++) {
testlock = lock_create("testlock");
if (testlock == NULL) {
panic("lt2: lock_create failed\n");
}
if (i != CREATELOOPS - 1) {
lock_destroy(testlock);
}
testlock = lock_create("testlock");
if (testlock == NULL) {
panic("lt2: lock_create failed\n");
}
ksecprintf(SECRET, "Should panic...", "lt2");
@@ -324,18 +320,12 @@ locktest3(int nargs, char **args) {
(void)nargs;
(void)args;
int i;
kprintf_n("Starting lt3...\n");
kprintf_n("(This test panics on success!)\n");
for (i=0; i<CREATELOOPS; i++) {
testlock = lock_create("testlock");
if (testlock == NULL) {
panic("lt3: lock_create failed\n");
}
if (i != CREATELOOPS - 1) {
lock_destroy(testlock);
}
testlock = lock_create("testlock");
if (testlock == NULL) {
panic("lt3: lock_create failed\n");
}
ksecprintf(SECRET, "Should panic...", "lt3");
@@ -419,7 +409,7 @@ cvtest(int nargs, char **args)
kprintf_t(".");
testlock = lock_create("testlock");
if (testlock == NULL) {
panic("lockt1: lock_create failed\n");
panic("cvt1: lock_create failed\n");
}
testcv = cv_create("testcv");
if (testcv == NULL) {
@@ -489,7 +479,7 @@ sleepthread(void *junk1, unsigned long junk2)
(void)junk2;
unsigned i, j;
random_yielder(4);
for (j=0; j<NLOOPS; j++) {
@@ -546,7 +536,7 @@ cvtest2(int nargs, char **args)
{
(void)nargs;
(void)args;
unsigned i;
int result;
@@ -607,23 +597,16 @@ cvtest3(int nargs, char **args) {
(void)nargs;
(void)args;
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);
}
testlock = lock_create("testlock");
if (testlock == NULL) {
panic("cvt3: lock_create failed\n");
}
testcv = cv_create("testcv");
if (testcv == NULL) {
panic("cvt3: cv_create failed\n");
}
ksecprintf(SECRET, "Should panic...", "cvt3");
@@ -646,23 +629,16 @@ 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);
}
testlock = lock_create("testlock");
if (testlock == NULL) {
panic("cvt4: lock_create failed\n");
}
testcv = cv_create("testcv");
if (testcv == NULL) {
panic("cvt4: cv_create failed\n");
}
ksecprintf(SECRET, "Should panic...", "cvt4");
@@ -679,3 +655,118 @@ cvtest4(int nargs, char **args) {
return 0;
}
static
void
sleeperthread(void *junk1, unsigned long junk2) {
(void)junk1;
(void)junk2;
random_yielder(4);
lock_acquire(testlock);
random_yielder(4);
failif((testval1 != 0));
testval1 = 1;
cv_signal(testcv, testlock);
random_yielder(4);
cv_wait(testcv, testlock);
failif((testval1 != 3));
testval1 = 4;
random_yielder(4);
lock_release(testlock);
random_yielder(4);
V(exitsem);
}
static
void
wakerthread(void *junk1, unsigned long junk2) {
(void)junk1;
(void)junk2;
random_yielder(4);
lock_acquire(testlock2);
failif((testval1 != 2));
testval1 = 3;
random_yielder(4);
cv_signal(testcv, testlock2);
random_yielder(4);
lock_release(testlock2);
random_yielder(4);
V(exitsem);
}
int
cvtest5(int nargs, char **args) {
(void)nargs;
(void)args;
int result;
kprintf_n("Starting cvt5...\n");
testlock = lock_create("testlock");
if (testlock == NULL) {
panic("cvt5: lock_create failed\n");
}
testlock2 = lock_create("testlock2");
if (testlock == NULL) {
panic("cvt5: lock_create failed\n");
}
testcv = cv_create("testcv");
if (testcv == NULL) {
panic("cvt5: cv_create failed\n");
}
exitsem = sem_create("exitsem", 0);
if (exitsem == NULL) {
panic("cvt5: sem_create failed\n");
}
spinlock_init(&status_lock);
test_status = SUCCESS;
testval1 = 0;
lock_acquire(testlock);
lock_acquire(testlock2);
result = thread_fork("cvt5", NULL, sleeperthread, NULL, 0);
if (result) {
panic("cvt5: thread_fork failed\n");
}
result = thread_fork("cvt5", NULL, wakerthread, NULL, 0);
if (result) {
panic("cvt5: thread_fork failed\n");
}
random_yielder(4);
cv_wait(testcv, testlock);
failif((testval1 != 1));
testval1 = 2;
random_yielder(4);
lock_release(testlock);
random_yielder(4);
lock_release(testlock2);
P(exitsem);
P(exitsem);
failif((testval1 != 4));
sem_destroy(exitsem);
cv_destroy(testcv);
lock_destroy(testlock2);
lock_destroy(testlock);
success(test_status, SECRET, "cvt5");
exitsem = NULL;
testcv = NULL;
testlock2 = NULL;
testlock = NULL;
testsem2 = NULL;
testsem = NULL;
return 0;
}