X-Git-Url: http://xvm.mit.edu/gitweb/invirt/third/libt4.git/blobdiff_plain/03b35a9a1bd1f583e32b27d260b223a0989d6c75..c279db4240a3a3c30f069ab9dea8055cf94280da:/lock_tester.cc diff --git a/lock_tester.cc b/lock_tester.cc index 7143401..fbdeeb4 100644 --- a/lock_tester.cc +++ b/lock_tester.cc @@ -6,24 +6,20 @@ #include #include -char log_thread_prefix = 'c'; - // must be >= 2 const int nt = 6; //XXX: lab1's rpc handlers are blocking. Since rpcs uses a thread pool of 10 threads, we cannot test more than 10 blocking rpc. -static string dst; -static lock_client **lc = new lock_client * [nt]; -static lock_protocol::lockid_t a = "1"; -static lock_protocol::lockid_t b = "2"; -static lock_protocol::lockid_t c = "3"; +static lock_client *lc[nt]; +static const char * a = "1"; +static const char * b = "2"; // check_grant() and check_release() check that the lock server // doesn't grant the same lock to both clients. // it assumes that lock names are distinct in the first byte. static int ct[256]; -static std::mutex count_mutex; +static std::mutex * count_mutex; static void check_grant(lock_protocol::lockid_t lid) { - lock ml(count_mutex); + lock ml(*count_mutex); int x = lid[0] & 0x0f; if (ct[x] != 0) { LOG_NONMEMBER << "error: server granted " << lid << " twice"; @@ -33,7 +29,7 @@ static void check_grant(lock_protocol::lockid_t lid) { } static void check_release(lock_protocol::lockid_t lid) { - lock ml(count_mutex); + lock ml(*count_mutex); int x = lid[0] & 0x0f; if (ct[x] != 1) { LOG_NONMEMBER << "error: client released un-held lock " << lid; @@ -69,7 +65,7 @@ static void test2(int i) { lc[i]->acquire(a); LOG_NONMEMBER << "test2: client " << i << " acquire done"; check_grant(a); - usleep(100000); + std::this_thread::sleep_for(milliseconds(100)); LOG_NONMEMBER << "test2: client " << i << " release"; check_release(a); lc[i]->release(a); @@ -114,19 +110,21 @@ static void test5(int i) { int main(int argc, char *argv[]) { + global = new t4_state('c'); + count_mutex = new std::mutex(); + thread th[nt]; int test = 0; setvbuf(stdout, NULL, _IONBF, 0); setvbuf(stderr, NULL, _IONBF, 0); - srandom((uint32_t)getpid()); if (argc < 2) { LOG_NONMEMBER << "Usage: " << argv[0] << " [host:]port [test]"; exit(1); } - dst = argv[1]; + string dst = argv[1]; if (argc > 2) { test = atoi(argv[2]); @@ -180,4 +178,6 @@ main(int argc, char *argv[]) LOG_NONMEMBER << argv[0] << ": passed all tests successfully"; + for (int i = 0; i < nt; i++) + delete lc[i]; }