5 #include "lock_client.h"
10 char log_thread_prefix = 'c';
13 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.
15 lock_client **lc = new lock_client * [nt];
16 lock_protocol::lockid_t a = "1";
17 lock_protocol::lockid_t b = "2";
18 lock_protocol::lockid_t c = "3";
20 // check_grant() and check_release() check that the lock server
21 // doesn't grant the same lock to both clients.
22 // it assumes that lock names are distinct in the first byte.
26 void check_grant(lock_protocol::lockid_t lid) {
28 int x = lid[0] & 0x0f;
30 cout << "error: server granted " << lid << " twice" << endl;
31 cerr << "error: server granted " << lid << " twice" << endl;
37 void check_release(lock_protocol::lockid_t lid) {
39 int x = lid[0] & 0x0f;
41 cerr << "error: client released un-held lock " << lid << endl;
48 LOG_NONMEMBER("acquire a release a acquire a release a");
58 LOG_NONMEMBER("acquire a acquire b release b release a");
70 LOG_NONMEMBER("test2: client " << i << " acquire a release a");
72 LOG_NONMEMBER("test2: client " << i << " acquire done");
75 LOG_NONMEMBER("test2: client " << i << " release");
78 LOG_NONMEMBER("test2: client " << i << " release done");
82 LOG_NONMEMBER("test3: client " << i << " acquire a release a concurrent");
83 for (int j = 0; j < 10; j++) {
86 LOG_NONMEMBER("test3: client " << i << " got lock");
93 LOG_NONMEMBER("test4: thread " << i << " acquire a release a concurrent; same clnt");
94 for (int j = 0; j < 10; j++) {
97 LOG_NONMEMBER("test4: thread " << i << " on client 0 got lock");
104 LOG_NONMEMBER("test5: client " << i << " acquire a release a concurrent; same and diff clnt");
105 for (int j = 0; j < 10; j++) {
106 if (i < 5) lc[0]->acquire(a);
107 else lc[1]->acquire(a);
109 LOG_NONMEMBER("test5: client " << i << " got lock");
111 if (i < 5) lc[0]->release(a);
112 else lc[1]->release(a);
117 main(int argc, char *argv[])
122 setvbuf(stdout, NULL, _IONBF, 0);
123 setvbuf(stderr, NULL, _IONBF, 0);
124 srandom((uint32_t)getpid());
127 cerr << "Usage: " << argv[0] << " [host:]port [test]" << endl;
134 test = atoi(argv[2]);
135 if (test < 1 || test > 5) {
136 LOG_NONMEMBER("Test number must be between 1 and 5");
141 LOG_NONMEMBER("cache lock client");
142 for (int i = 0; i < nt; i++) lc[i] = new lock_client(dst);
144 if (!test || test == 1) {
148 if (!test || test == 2) {
150 for (int i = 0; i < nt; i++)
151 th[i] = thread(test2, i);
152 for (int i = 0; i < nt; i++)
156 if (!test || test == 3) {
157 LOG_NONMEMBER("test 3");
159 for (int i = 0; i < nt; i++)
160 th[i] = thread(test3, i);
161 for (int i = 0; i < nt; i++)
165 if (!test || test == 4) {
166 LOG_NONMEMBER("test 4");
168 for (int i = 0; i < 2; i++)
169 th[i] = thread(test4, i);
170 for (int i = 0; i < 2; i++)
174 if (!test || test == 5) {
175 LOG_NONMEMBER("test 5");
177 for (int i = 0; i < nt; i++)
178 th[i] = thread(test5, i);
179 for (int i = 0; i < nt; i++)
183 LOG_NONMEMBER(argv[0] << ": passed all tests successfully");