added new lock test to check do i hold functionality. tested on incorrect implementation, fails. tested on correct implementation, passed.

This commit is contained in:
zsmoore
2017-02-16 01:41:05 -05:00
parent 398e4eb90a
commit b51f2a88de
3 changed files with 72 additions and 1 deletions

View File

@@ -238,6 +238,29 @@ fail2:
return;
}
static
void
locktestthread2(void *junk, unsigned long num)
{
(void)junk;
if(num == 0){
lock_acquire(testlock);
}
else{
if(lock_do_i_hold(testlock)){
goto fail;
}
}
V(donesem);
return;
fail:
failif(true);
V(donesem);
return;
}
int
locktest(int nargs, char **args)
@@ -314,7 +337,7 @@ locktest2(int nargs, char **args) {
return 0;
}
int
locktest3(int nargs, char **args) {
(void)nargs;
@@ -341,6 +364,51 @@ locktest3(int nargs, char **args) {
return 0;
}
int
locktest4(int nargs, char **args) {
(void) nargs;
(void) args;
kprintf_n("Starting lt4...\n");
test_status = TEST161_SUCCESS;
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("lt1: sem_create failed\n");
}
int i, result;
for (i=0; i<2; i++) {
kprintf_t(".");
result = thread_fork("lt4", NULL, locktestthread2, NULL, i);
if (result) {
panic("lt1: thread_fork failed: %s\n", strerror(result));
}
}
for(i=0; i<2; i++) {
kprintf_t(".");
P(donesem);
}
lock_destroy(testlock);
sem_destroy(donesem);
testlock = NULL;
donesem = NULL;
kprintf_t("\n");
success(test_status, SECRET, "lt1");
return 0;
}
static
void
cvtestthread(void *junk, unsigned long num)