5 #include "lock_client.h"
9 char log_thread_prefix = 'c';
12 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.
14 lock_client **lc = new lock_client * [nt];
15 lock_protocol::lockid_t a = "1";
16 lock_protocol::lockid_t b = "2";
17 lock_protocol::lockid_t c = "3";
19 // check_grant() and check_release() check that the lock server
20 // doesn't grant the same lock to both clients.
21 // it assumes that lock names are distinct in the first byte.
25 void check_grant(lock_protocol::lockid_t lid) {
27 int x = lid[0] & 0x0f;
29 cout << "error: server granted " << lid << " twice" << endl;
30 cerr << "error: server granted " << lid << " twice" << endl;
36 void check_release(lock_protocol::lockid_t lid) {
38 int x = lid[0] & 0x0f;
40 cerr << "error: client released un-held lock " << lid << endl;
47 LOG_NONMEMBER("acquire a release a acquire a release a");
57 LOG_NONMEMBER("acquire a acquire b release b release a");
69 LOG_NONMEMBER("test2: client " << i << " acquire a release a");
71 LOG_NONMEMBER("test2: client " << i << " acquire done");
74 LOG_NONMEMBER("test2: client " << i << " release");
77 LOG_NONMEMBER("test2: client " << i << " release done");
81 LOG_NONMEMBER("test3: client " << i << " acquire a release a concurrent");
82 for (int j = 0; j < 10; j++) {
85 LOG_NONMEMBER("test3: client " << i << " got lock");
92 LOG_NONMEMBER("test4: thread " << i << " acquire a release a concurrent; same clnt");
93 for (int j = 0; j < 10; j++) {
96 LOG_NONMEMBER("test4: thread " << i << " on client 0 got lock");
103 LOG_NONMEMBER("test5: client " << i << " acquire a release a concurrent; same and diff clnt");
104 for (int j = 0; j < 10; j++) {
105 if (i < 5) lc[0]->acquire(a);
106 else lc[1]->acquire(a);
108 LOG_NONMEMBER("test5: client " << i << " got lock");
110 if (i < 5) lc[0]->release(a);
111 else lc[1]->release(a);
116 main(int argc, char *argv[])
121 setvbuf(stdout, NULL, _IONBF, 0);
122 setvbuf(stderr, NULL, _IONBF, 0);
123 srandom((uint32_t)getpid());
126 cerr << "Usage: " << argv[0] << " [host:]port [test]" << endl;
133 test = atoi(argv[2]);
134 if (test < 1 || test > 5) {
135 LOG_NONMEMBER("Test number must be between 1 and 5");
140 LOG_NONMEMBER("cache lock client");
141 for (int i = 0; i < nt; i++) lc[i] = new lock_client(dst);
143 if (!test || test == 1) {
147 if (!test || test == 2) {
149 for (int i = 0; i < nt; i++)
150 th[i] = thread(test2, i);
151 for (int i = 0; i < nt; i++)
155 if (!test || test == 3) {
156 LOG_NONMEMBER("test 3");
158 for (int i = 0; i < nt; i++)
159 th[i] = thread(test3, i);
160 for (int i = 0; i < nt; i++)
164 if (!test || test == 4) {
165 LOG_NONMEMBER("test 4");
167 for (int i = 0; i < 2; i++)
168 th[i] = thread(test4, i);
169 for (int i = 0; i < 2; i++)
173 if (!test || test == 5) {
174 LOG_NONMEMBER("test 5");
176 for (int i = 0; i < nt; i++)
177 th[i] = thread(test5, i);
178 for (int i = 0; i < nt; i++)
182 LOG_NONMEMBER(argv[0] << ": passed all tests successfully");