New lock tests.
This commit is contained in:
@@ -238,7 +238,6 @@ fail2:
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
locktest(int nargs, char **args)
|
||||
{
|
||||
@@ -289,6 +288,13 @@ locktest(int nargs, char **args)
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* Note that the following tests that panic on success do minimal cleanup
|
||||
* afterward. This is to avoid causing a panic that could be unintentiontally
|
||||
* considered a success signal by test161. As a result, they leak memory,
|
||||
* don't destroy synchronization primitives, etc.
|
||||
*/
|
||||
|
||||
int
|
||||
locktest2(int nargs, char **args) {
|
||||
(void)nargs;
|
||||
@@ -309,9 +315,9 @@ locktest2(int nargs, char **args) {
|
||||
|
||||
success(TEST161_FAIL, SECRET, "lt2");
|
||||
|
||||
lock_destroy(testlock);
|
||||
testlock = NULL;
|
||||
/* Don't do anything that could panic. */
|
||||
|
||||
testlock = NULL;
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -336,11 +342,110 @@ locktest3(int nargs, char **args) {
|
||||
|
||||
success(TEST161_FAIL, SECRET, "lt3");
|
||||
|
||||
testlock = NULL;
|
||||
/* Don't do anything that could panic. */
|
||||
|
||||
testlock = NULL;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* Used by both lt4 and lt5 below. Simply acquires a lock in a separate
|
||||
* thread. Uses a semaphore as a barrier to make sure it gets the lock before
|
||||
* the driver completes.
|
||||
*/
|
||||
|
||||
static
|
||||
void
|
||||
locktestacquirer(void * junk, unsigned long num)
|
||||
{
|
||||
(void)junk;
|
||||
(void)num;
|
||||
|
||||
lock_acquire(testlock);
|
||||
V(donesem);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
locktest4(int nargs, char **args) {
|
||||
(void) nargs;
|
||||
(void) args;
|
||||
|
||||
kprintf_n("Starting lt4...\n");
|
||||
kprintf_n("(This test panics on success!)\n");
|
||||
|
||||
testlock = lock_create("testlock");
|
||||
if (testlock == NULL) {
|
||||
panic("lt4: lock_create failed\n");
|
||||
}
|
||||
|
||||
donesem = sem_create("donesem", 0);
|
||||
if (donesem == NULL) {
|
||||
lock_destroy(testlock);
|
||||
panic("lt4: sem_create failed\n");
|
||||
}
|
||||
|
||||
result = thread_fork("lt4", NULL, locktestacquirer, NULL, 0);
|
||||
if (result) {
|
||||
panic("lt4: thread_fork failed: %s\n", strerror(result));
|
||||
}
|
||||
|
||||
P(donesem);
|
||||
secprintf(SECRET, "Should panic...", "lt4");
|
||||
lock_release(testlock);
|
||||
|
||||
/* Should not get here on success. */
|
||||
|
||||
success(TEST161_FAIL, SECRET, "lt4");
|
||||
|
||||
/* Don't do anything that could panic. */
|
||||
|
||||
testlock = NULL;
|
||||
donesem = NULL;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
locktest5(int nargs, char **args) {
|
||||
(void) nargs;
|
||||
(void) args;
|
||||
|
||||
kprintf_n("Starting lt5...\n");
|
||||
kprintf_n("(This test panics on success!)\n");
|
||||
|
||||
testlock = lock_create("testlock");
|
||||
if (testlock == NULL) {
|
||||
panic("lt5: lock_create failed\n");
|
||||
}
|
||||
|
||||
donesem = sem_create("donesem", 0);
|
||||
if (donesem == NULL) {
|
||||
lock_destroy(testlock);
|
||||
panic("lt5: sem_create failed\n");
|
||||
}
|
||||
|
||||
result = thread_fork("lt5", NULL, locktestacquirer, NULL, 0);
|
||||
if (result) {
|
||||
panic("lt5: thread_fork failed: %s\n", strerror(result));
|
||||
}
|
||||
|
||||
P(donesem);
|
||||
secprintf(SECRET, "Should panic...", "lt5");
|
||||
KASSERT(!(lock_do_i_hold(testlock)));
|
||||
|
||||
/* Should not get here on success. */
|
||||
|
||||
success(TEST161_FAIL, SECRET, "lt5");
|
||||
|
||||
/* Don't do anything that could panic. */
|
||||
|
||||
testlock = NULL;
|
||||
donesem = NULL;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static
|
||||
void
|
||||
cvtestthread(void *junk, unsigned long num)
|
||||
|
Reference in New Issue
Block a user