From 5521823176b358204bd031cfd7873421ce8c6b0a Mon Sep 17 00:00:00 2001 From: Geoffrey Challen Date: Wed, 10 Feb 2016 17:03:53 -0500 Subject: [PATCH] Menu changes and test fixes for ASST1. --- kern/include/test.h | 2 + kern/main/menu.c | 28 ++-- kern/test/synchtest.c | 346 ++++++++++++++++++++++++++---------------- 3 files changed, 237 insertions(+), 139 deletions(-) diff --git a/kern/include/test.h b/kern/include/test.h index 998d25e..1e7f9ef 100644 --- a/kern/include/test.h +++ b/kern/include/test.h @@ -59,6 +59,8 @@ int threadtest2(int, char **); int threadtest3(int, char **); int semtest(int, char **); int locktest(int, char **); +int locktest2(int, char **); +int locktest3(int, char **); int cvtest(int, char **); int cvtest2(int, char **); int rwtest(int, char **); diff --git a/kern/main/menu.c b/kern/main/menu.c index 6f69a14..83f96db 100644 --- a/kern/main/menu.c +++ b/kern/main/menu.c @@ -475,14 +475,16 @@ static const char *testmenu[] = { #if OPT_NET "[net] Network test ", #endif - "[sy1] Semaphore test ", - "[sy2] Lock test (1) ", - "[sy3] CV test (1) ", - "[sy4] CV test #2 (1) ", - "[sy5] RW lock test (1) ", + "[sem1] Semaphore test ", + "[lt1] Lock test 1 (1) ", + "[lt2] Lock test 2 (panics) (1) ", + "[lt3] Lock test 3 (panics) (1) ", + "[cvt1] CV test 1 (1) ", + "[cvt2] CV test 2 (1) ", + "[rwt1] RW lock test (1) ", #if OPT_SYNCHPROBS - "[sp1] Whalemating test (1) ", - "[sp2] Stoplight test (1) ", + "[sp1] Whalemating test (1) ", + "[sp2] Stoplight test (1) ", #endif "[semu1-22] Semaphore unit tests ", "[fs1] Filesystem test ", @@ -607,13 +609,15 @@ static struct { { "tt1", threadtest }, { "tt2", threadtest2 }, { "tt3", threadtest3 }, - { "sy1", semtest }, /* synchronization assignment tests */ - { "sy2", locktest }, - { "sy3", cvtest }, - { "sy4", cvtest2 }, - { "sy5", rwtest }, + { "sem1", semtest }, + { "lt1", locktest }, + { "lt2", locktest2 }, + { "lt3", locktest3 }, + { "cvt1", cvtest }, + { "cvt2", cvtest2 }, + { "rwt1", rwtest }, #if OPT_SYNCHPROBS { "sp1", whalemating }, { "sp2", stoplight }, diff --git a/kern/test/synchtest.c b/kern/test/synchtest.c index 6290921..627f30b 100644 --- a/kern/test/synchtest.c +++ b/kern/test/synchtest.c @@ -40,75 +40,47 @@ #include #include +#define CREATELOOPS 8 #define NSEMLOOPS 63 #define NLOCKLOOPS 120 #define NCVLOOPS 5 #define NTHREADS 32 +#define SYNCHTEST_YIELDER_MAX 16 static volatile unsigned long testval1; static volatile unsigned long testval2; static volatile unsigned long testval3; static volatile int32_t testval4; -static struct semaphore *testsem; -static struct lock *testlock; -static struct cv *testcv; -static struct semaphore *donesem; +static struct semaphore *testsem = NULL; +static struct lock *testlock = NULL; +static struct cv *testcv = NULL; +static struct semaphore *donesem = NULL; struct spinlock status_lock; -static bool test_status; +static bool test_status = FAIL; static unsigned long semtest_current; -static -void -inititems(void) -{ - if (testsem==NULL) { - testsem = sem_create("testsem", 2); - if (testsem == NULL) { - panic("synchtest: sem_create failed\n"); - } - } - if (testlock==NULL) { - testlock = lock_create("testlock"); - if (testlock == NULL) { - panic("synchtest: lock_create failed\n"); - } - } - if (testcv==NULL) { - testcv = cv_create("testlock"); - if (testcv == NULL) { - panic("synchtest: cv_create failed\n"); - } - } - if (donesem==NULL) { - donesem = sem_create("donesem", 0); - if (donesem == NULL) { - panic("synchtest: sem_create failed\n"); - } - } - spinlock_init(&status_lock); -} - - static void semtestthread(void *junk, unsigned long num) { - int i; (void)junk; + int i; + + random_yielder(4); + /* * Only one of these should print at a time. */ - random_yielder(4); P(testsem); semtest_current = num; - kprintf_n("Thread %2lu: ", num); + kprintf_n("Thread %2lu: ", num); for (i=0; i