From b51f2a88de40627eae1edb36a693c2f98ef731b9 Mon Sep 17 00:00:00 2001 From: zsmoore Date: Thu, 16 Feb 2017 01:41:05 -0500 Subject: [PATCH] added new lock test to check do i hold functionality. tested on incorrect implementation, fails. tested on correct implementation, passed. --- kern/include/test.h | 1 + kern/main/menu.c | 2 ++ kern/test/synchtest.c | 70 ++++++++++++++++++++++++++++++++++++++++++- 3 files changed, 72 insertions(+), 1 deletion(-) diff --git a/kern/include/test.h b/kern/include/test.h index 9445a5c..1d3ce16 100644 --- a/kern/include/test.h +++ b/kern/include/test.h @@ -61,6 +61,7 @@ int semtest(int, char **); int locktest(int, char **); int locktest2(int, char **); int locktest3(int, char **); +int locktest4(int, char **); int cvtest(int, char **); int cvtest2(int, char **); int cvtest3(int, char **); diff --git a/kern/main/menu.c b/kern/main/menu.c index c104187..1638448 100644 --- a/kern/main/menu.c +++ b/kern/main/menu.c @@ -593,6 +593,7 @@ static const char *testmenu[] = { "[lt1] Lock test 1 (1) ", "[lt2] Lock test 2 (1*) ", "[lt3] Lock test 3 (1*) ", + "[lt4] Lock test 4 (1) ", "[cvt1] CV test 1 (1) ", "[cvt2] CV test 2 (1) ", "[cvt3] CV test 3 (1*) ", @@ -743,6 +744,7 @@ static struct { { "lt1", locktest }, { "lt2", locktest2 }, { "lt3", locktest3 }, + { "lt4", locktest4 }, { "cvt1", cvtest }, { "cvt2", cvtest2 }, { "cvt3", cvtest3 }, diff --git a/kern/test/synchtest.c b/kern/test/synchtest.c index 23bb151..1a8d2a9 100644 --- a/kern/test/synchtest.c +++ b/kern/test/synchtest.c @@ -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)