00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #include <Basics.H>
00020 #include <SRPC.H>
00021 #include <MultiSRPC.H>
00022
00023 using std::endl;
00024 using std::cout;
00025 using std::cerr;
00026
00027 const Text CLIENT_PROG = "TestClient";
00028 const Text SERVER_PROG = "TestServer";
00029 const Text INTERFACE_1 = "9873";
00030
00031 int ints[] = {17, -12, 43, 95, 0, 301, 768, -903, 1017, 3, 4097};
00032 char *chars[] = {"Hello,", " there", " big", " boy", "."};
00033
00034
00035 float floats[] = {42.525, 18.0, -83.5, 31.25};
00036
00037 int port_nums[] = {5678, 9876, 11234};
00038
00039 const int nports = sizeof(port_nums) / sizeof(int);
00040
00041 Text ports[nports];
00042
00043 int minor;
00044
00045 Basics::int16 int16s[10];
00046
00047 Basics::int32 int32s[10];
00048
00049 Basics::int64 int64s[10];
00050
00051 void new_test(const Text &ident)
00052 {
00053 minor = 0;
00054 cerr << ident + "...";
00055 }
00056
00057 void ok()
00058 {
00059 cerr << " ok.\n";
00060 }
00061
00062 void print_connection(SRPC &s)
00063 {
00064 Text me(s.local_socket());
00065 cerr << ((me != "") ? me.chars() : "???");
00066 cerr << "=>";
00067 Text him(s.remote_socket());
00068 cerr << ((him != "") ? him.chars() : "???");
00069 }
00070
00071 void fatal(SRPC::failure f)
00072 {
00073 char buff[20];
00074 sprintf(buff, "%d", minor);
00075 cerr << buff;
00076 sprintf(buff, "%d", f.r);
00077 cerr << Text(": failure(") + buff + ", " + f.msg + ")\n";
00078 exit(1);
00079 }
00080
00081 void die(char *m)
00082 {
00083 SRPC::failure f;
00084 f.r = 0;
00085 f.msg = m;
00086 fatal(f);
00087 }
00088
00089 void wait_for_server()
00090 {
00091 Basics::thread::pause(2);
00092 }
00093
00094 void init_random()
00095 {
00096 srandom(time(0));
00097 }
00098
00099 Basics::int16 rand16()
00100 {
00101
00102
00103 Basics::uint32 r1 = random();
00104
00105 return (Basics::int16) r1 & 0xffff;
00106 }
00107
00108 Basics::int32 rand32()
00109 {
00110
00111
00112 Basics::uint32 r1 = random();
00113 Basics::uint32 r2 = random();
00114
00115 return (Basics::int32) (r1 ^ (r2 << 1));
00116 }
00117
00118 Basics::int32 rand64()
00119 {
00120
00121
00122 Basics::uint64 r1 = random();
00123 Basics::uint64 r2 = random();
00124 Basics::uint64 r3 = random();
00125
00126 return (Basics::int64) (r1 ^ (r2 << 24) ^ (r3 << 33));
00127 }
00128
00129 void init_arrays()
00130 {
00131 unsigned int len;
00132
00133 len = sizeof(int16s) / sizeof(int16s[0]);
00134 for(unsigned int i = 0; i < len; i++)
00135 {
00136 int16s[i] = rand16();
00137 }
00138
00139 len = sizeof(int32s) / sizeof(int32s[0]);
00140 for(unsigned int i = 0; i < len; i++)
00141 {
00142 int32s[i] = rand32();
00143 }
00144
00145 len = sizeof(int64s) / sizeof(int64s[0]);
00146 for(unsigned int i = 0; i < len; i++)
00147 {
00148 int64s[i] = rand64();
00149 }
00150 }
00151
00152
00153
00154 void C_Add2(SRPC &s)
00155 {
00156
00157 new_test("C_Add2");
00158 s.send_int(ints[0]); minor++;
00159 s.send_int(ints[1]); minor++;
00160 s.send_end(); minor++;
00161 int ires = s.recv_int(); minor++;
00162 s.recv_end();
00163 if (ires == ints[0]+ints[1]) ok();
00164 else die("Callee can't add");
00165 }
00166
00167 void S_Add2(SRPC &s)
00168 {
00169
00170 new_test("S_Add2");
00171 int i1 = s.recv_int(); minor++;
00172 int i2 = s.recv_int(); minor++;
00173 s.recv_end(); minor++;
00174 s.send_int(i1+i2); minor++;
00175 s.send_end();
00176 ok();
00177 }
00178
00179 void C_Add2f(SRPC &s)
00180 {
00181
00182 new_test("C_Add2f");
00183 s.send_float(floats[0]); minor++;
00184 s.send_float(floats[1]); minor++;
00185 s.send_end(); minor++;
00186 float fres = s.recv_float(); minor++;
00187 s.recv_end();
00188 if (fres == floats[0]+floats[1]) ok();
00189 else die("Callee can't add");
00190 }
00191
00192 void S_Add2f(SRPC &s)
00193 {
00194
00195 new_test("S_Add2f");
00196 float f1 = s.recv_float(); minor++;
00197 float f2 = s.recv_float(); minor++;
00198 s.recv_end(); minor++;
00199 s.send_float(f1+f2); minor++;
00200 s.send_end();
00201 ok();
00202 }
00203
00204
00205
00206
00207 void C_Addna(SRPC &s)
00208 {
00209 new_test("C_Addna");
00210 int ints_len = sizeof(ints)/sizeof(int);
00211 int_seq is;
00212 int i;
00213 for (i = 0; i < ints_len; i++) is.append(ints[i]);
00214 s.send_int_seq(is); minor++;
00215 s.send_end(); minor++;
00216 int rsum = s.recv_int(); minor++;
00217 int sum = 0;
00218 for (i = 0; i < ints_len; i++) sum += ints[i];
00219 s.recv_end();
00220 if (sum == rsum) ok();
00221 else die("Callee can't sum");
00222 }
00223
00224 void S_Addna(SRPC &s)
00225 {
00226 new_test("S_Addna");
00227 int sum = 0, i;
00228 int_seq is;
00229 s.recv_int_seq(is); minor++;
00230 s.recv_end(); minor++;
00231 for (i = 0; i < is.length(); i++) sum += is[i];
00232 s.send_int(sum); minor++;
00233 s.send_end();
00234 ok();
00235 }
00236
00237 void C_Addnf(SRPC &s)
00238 {
00239 new_test("C_Addnf");
00240 int ints_len = sizeof(ints)/sizeof(int);
00241 int_seq is((const int *)ints, ints_len);
00242 s.send_int_seq(is); minor++;
00243 s.send_end(); minor++;
00244 int rsum = s.recv_int(); minor++;
00245 int sum = 0;
00246 for (int i = 0; i < ints_len; i++) sum += ints[i];
00247 s.recv_end();
00248 if (sum == rsum) ok();
00249 else die("Callee can't sum");
00250 }
00251
00252 void S_Addnf(SRPC &s)
00253 {
00254 new_test("S_Addnf");
00255 int sum = 0;
00256 int buff_bytes = int_seq::min_size(sizeof(ints)/sizeof(int));
00257 int *buff = NEW_PTRFREE_ARRAY(int, buff_bytes/sizeof(int));
00258 {
00259 int_seq is(buff, buff_bytes);
00260 s.recv_int_seq(is); minor++;
00261 s.recv_end(); minor++;
00262 for (int i = 0; i < is.length(); i++) sum += is[i];
00263 s.send_int(sum); minor++;
00264 s.send_end();
00265 ok();
00266 }
00267 delete[] buff;
00268 }
00269
00270 void C_Addnfp(SRPC &s)
00271 {
00272 new_test("C_Addnfp");
00273 int floats_len = sizeof(floats)/sizeof(float);
00274 int i;
00275 s.send_int(floats_len);
00276 for (i = 0; i < floats_len; i++) {
00277 s.send_float(floats[i]);
00278 minor++;
00279 }
00280 s.send_end(); minor++;
00281 float rsum = s.recv_float(); minor++;
00282 float sum = 0;
00283 for (i = 0; i < floats_len; i++) sum += floats[i];
00284 s.recv_end();
00285 if (sum == rsum) ok();
00286 else die("Callee can't sum");
00287 }
00288
00289 void S_Addnfp(SRPC &s)
00290 {
00291 new_test("S_Addnfp");
00292 float sum = 0;
00293 int floats_len = s.recv_int();
00294 for (int i = 0; i < floats_len; i++)
00295 sum += s.recv_float();
00296 s.recv_end(); minor++;
00297 s.send_float(sum); minor++;
00298 s.send_end();
00299 ok();
00300 }
00301
00302
00303
00304 void C_Cat2(SRPC &s)
00305 {
00306
00307 new_test("C_Cat2");
00308 int exp_len = strlen(chars[0]) + strlen(chars[1]) + 1;
00309 char *cres = NEW_PTRFREE_ARRAY(char, exp_len);
00310 s.send_chars(chars[0]); minor++;
00311 s.send_chars(chars[1]); minor++;
00312 s.send_end(); minor++;
00313 s.recv_chars_here(cres, exp_len); minor++;
00314 s.recv_end();
00315 if (Text(cres) == Text(chars[0])+Text(chars[1])) ok();
00316 else die("Callee can't cat");
00317 delete[] cres;
00318 }
00319
00320 void S_Cat2(SRPC &s)
00321 {
00322
00323 new_test("S_Cat2");
00324 char *s1 = s.recv_chars(); minor++;
00325 char *s2 = s.recv_chars(); minor++;
00326 Text t1(s1);
00327 Text t2(s2);
00328 delete[] s1;
00329 delete[] s2;
00330 s.recv_end(); minor++;
00331 Text t(t1+t2);
00332 s.send_chars(t.cchars()); minor++;
00333 s.send_end();
00334 ok();
00335 }
00336
00337
00338
00339 void C_Catna(SRPC &s)
00340 {
00341 new_test("C_Catna");
00342 int chars_len = sizeof(chars)/sizeof(char*);
00343 chars_seq cs(3, 10);
00344 int i;
00345 for (i = 0; i < chars_len; i++) cs.append(chars[i]);
00346 s.send_chars_seq(cs); minor++;
00347 s.send_end(); minor++;
00348 char *rres = s.recv_chars(); minor++;
00349 Text lres = "";
00350 for (i = 0; i < chars_len; i++) lres += chars[i];
00351 s.recv_end();
00352 if (lres == rres) ok();
00353 else die("Callee can't cat");
00354 delete [] rres;
00355 }
00356
00357 void S_Catna(SRPC &s)
00358 {
00359 new_test("S_Catna");
00360 chars_seq cs;
00361 s.recv_chars_seq(cs); minor++;
00362 s.recv_end(); minor++;
00363 Text res = "";
00364 for (int i = 0; i < cs.length(); i++) res += cs[i];
00365 s.send_chars(res.cchars()); minor++;
00366 s.send_end();
00367 ok();
00368 }
00369
00370 void C_Catnf(SRPC &s)
00371 {
00372 new_test("C_Catnf");
00373 int chars_len = sizeof(chars)/sizeof(char*);
00374 chars_seq cs((const char**)&chars, chars_len);
00375 s.send_chars_seq(cs); minor++;
00376 s.send_end(); minor++;
00377 Text rres; s.recv_Text( rres); minor++;
00378 Text lres = "";
00379 for (int i = 0; i < chars_len; i++) lres += chars[i];
00380 s.recv_end();
00381 if (lres == rres) ok();
00382 else die("Callee can't cat");
00383 }
00384
00385 void S_Catnf(SRPC &s)
00386 {
00387 new_test("S_Catnf");
00388 int sum = 0;
00389 int chars_len = sizeof(chars)/sizeof(char*);
00390 int i;
00391 for (i = 0; i < chars_len; i++) sum += strlen(chars[i])+1;
00392 int buff_bytes = chars_seq::min_size(sum);
00393 char *buff = NEW_PTRFREE_ARRAY(char, buff_bytes);
00394 {
00395 chars_seq cs((void**)buff, buff_bytes);
00396 s.recv_chars_seq(cs); minor++;
00397 s.recv_end(); minor++;
00398 Text res = "";
00399 for (i = 0; i < cs.length(); i++) res += cs[i];
00400 s.send_Text(res); minor++;
00401 s.send_end();
00402 ok();
00403 }
00404 delete[] buff;
00405 }
00406
00407
00408
00409 void C_Cat2T(SRPC &s)
00410 {
00411
00412 new_test("C_Cat2T");
00413 Text t0 = chars[0];
00414 Text t1 = chars[1];
00415 s.send_Text(t0); minor++;
00416 s.send_Text(t1); minor++;
00417 s.send_end(); minor++;
00418 Text tr; s.recv_Text( tr); minor++;
00419 s.recv_end();
00420 if (tr == t0 + t1) ok();
00421 else die("Callee can't cat");
00422 }
00423
00424 void S_Cat2T(SRPC &s)
00425 {
00426
00427 new_test("S_Cat2T");
00428 Text t0; s.recv_Text( t0); minor++;
00429 Text t1; s.recv_Text( t1); minor++;
00430 s.recv_end(); minor++;
00431 s.send_Text(t0+t1); minor++;
00432 s.send_end();
00433 ok();
00434 }
00435
00436
00437
00438 void C_CatnT(SRPC &s)
00439 {
00440
00441 new_test("C_CatnT");
00442 int chars_len = sizeof(chars)/sizeof(char*);
00443 chars_seq cs(3, 10);
00444 int i;
00445 for (i = 0; i < chars_len; i++) {
00446 Text t(chars[i]);
00447 cs.append(t);
00448 }
00449 s.send_chars_seq(cs); minor++;
00450 s.send_end(); minor++;
00451 char *rres = s.recv_chars(); minor++;
00452 Text lres = "";
00453 for (i = 0; i < chars_len; i++) lres += chars[i];
00454 s.recv_end();
00455 if (lres == rres) ok();
00456 else die("Callee can't cat");
00457 delete [] rres;
00458 }
00459
00460 void S_CatnT(SRPC &s)
00461 {
00462
00463 new_test("S_CatnT");
00464 chars_seq cs;
00465 s.recv_chars_seq(cs); minor++;
00466 s.recv_end(); minor++;
00467 Text res = "";
00468 for (int i = 0; i < cs.length(); i++) res += cs[i];
00469 s.send_chars(res.cchars()); minor++;
00470 s.send_end();
00471 ok();
00472 }
00473
00474
00475
00476 void C_Seq1(SRPC &s)
00477 {
00478 int ints_len = sizeof(ints)/sizeof(int);
00479 new_test("C_Seq1");
00480 s.send_seq_start();
00481 for (int i = 0; i < ints_len; i++) s.send_int(ints[i]);
00482 s.send_seq_end();
00483 s.send_end();
00484 int res = s.recv_int();
00485 s.recv_end();
00486 if (res == ints_len) ok();
00487 else die("Wrong sequence length");
00488 }
00489
00490 void S_Seq1(SRPC &s)
00491 {
00492 int len = 0;
00493 new_test("S_Seq1");
00494 s.recv_seq_start();
00495 while (true) {
00496 bool got_end;
00497 int i = s.recv_int(&got_end);
00498 if (got_end) break;
00499 len++;
00500 }
00501 s.recv_seq_end();
00502 s.recv_end();
00503 s.send_int(len);
00504 s.send_end();
00505 ok();
00506 }
00507
00508
00509
00510 void C_Seq2(SRPC &s)
00511 {
00512 int ints_len = sizeof(ints)/sizeof(int);
00513 int chars_len = sizeof(chars)/sizeof(char*);
00514 int tot = 0;
00515 int ncopies = 10;
00516 new_test("C_Seq2");
00517 s.send_seq_start();
00518 s.send_int(ncopies);
00519 for (; ncopies > 0; ncopies--) {
00520 int_seq is((const int *)&ints, ints_len);
00521 chars_seq cs((const char **)&chars, chars_len);
00522 s.send_int_seq(is);
00523 tot += is.length();
00524 s.send_chars_seq(cs);
00525 tot += cs.length();
00526 }
00527 s.send_seq_end();
00528 s.send_end();
00529 int res = s.recv_int();
00530 s.recv_end();
00531 if (res == tot) ok();
00532 else die("Wrong received length");
00533 }
00534
00535 void S_Seq2(SRPC &s)
00536 {
00537 int tot = 0;
00538 new_test("S_Seq2");
00539 s.recv_seq_start();
00540 for (int ncopies = s.recv_int(); ncopies > 0; ncopies--) {
00541 int_seq is;
00542 chars_seq cs;
00543 s.recv_int_seq(is);
00544 tot += is.length();
00545 s.recv_chars_seq(cs);
00546 tot += cs.length();
00547 }
00548 s.recv_seq_end();
00549 s.recv_end();
00550 s.send_int(tot);
00551 s.send_end();
00552 ok();
00553 }
00554
00555
00556
00557 void C_Add2_64(SRPC &s)
00558 {
00559
00560 new_test("C_Add2_64");
00561 s.send_int64(int64s[0]); minor++;
00562 s.send_int64(int64s[1]); minor++;
00563 s.send_end(); minor++;
00564 Basics::int64 ires = s.recv_int64(); minor++;
00565 s.recv_end();
00566 if (ires == int64s[0]+int64s[1]) ok();
00567 else die("Callee can't add");
00568 }
00569
00570 void S_Add2_64(SRPC &s)
00571 {
00572
00573 new_test("S_Add2_64");
00574 Basics::int64 i1 = s.recv_int64(); minor++;
00575 Basics::int64 i2 = s.recv_int64(); minor++;
00576 s.recv_end(); minor++;
00577 s.send_int64(i1+i2); minor++;
00578 s.send_end();
00579 ok();
00580 }
00581
00582
00583
00584
00585 void C_Add_Int16Array(SRPC &s)
00586 {
00587 Basics::int16 expected = 0;
00588 int len = sizeof(int16s) / sizeof(int16s[0]);
00589 for(unsigned int i = 0; i < len; i++)
00590 {
00591 expected += int16s[i];
00592 }
00593
00594 new_test("C_Add_Int16Array");
00595 s.send_int16_array(int16s, len); minor++;
00596 s.send_end(); minor++;
00597 Basics::int16 result = s.recv_int16(); minor++;
00598 s.recv_end();
00599 if (result == expected) ok();
00600 else die("Callee can't sum");
00601 }
00602
00603 void S_Add_Int16Array(SRPC &s)
00604 {
00605
00606 new_test("S_Add_Int16Array");
00607 int len;
00608 Basics::int16 *array = s.recv_int16_array(len); minor++;
00609 s.recv_end(); minor++;
00610 Basics::int16 result = 0;
00611 for(unsigned int i = 0; i < len; i++)
00612 {
00613 result += array[i];
00614 }
00615 delete [] array;
00616 s.send_int16(result); minor++;
00617 s.send_end();
00618 ok();
00619 }
00620
00621
00622
00623 void C_Add_Int32Array(SRPC &s)
00624 {
00625 Basics::int32 expected = 0;
00626 int len = sizeof(int32s) / sizeof(int32s[0]);
00627 for(unsigned int i = 0; i < len; i++)
00628 {
00629 expected += int32s[i];
00630 }
00631
00632 new_test("C_Add_Int32Array");
00633 s.send_int32_array(int32s, len); minor++;
00634 s.send_end(); minor++;
00635 Basics::int32 result = s.recv_int32(); minor++;
00636 s.recv_end();
00637 if (result == expected) ok();
00638 else die("Callee can't sum");
00639 }
00640
00641 void S_Add_Int32Array(SRPC &s)
00642 {
00643
00644 new_test("S_Add_Int32Array");
00645 int len;
00646 Basics::int32 *array = s.recv_int32_array(len); minor++;
00647 s.recv_end(); minor++;
00648 Basics::int32 result = 0;
00649 for(unsigned int i = 0; i < len; i++)
00650 {
00651 result += array[i];
00652 }
00653 delete [] array;
00654 s.send_int32(result); minor++;
00655 s.send_end();
00656 ok();
00657 }
00658
00659
00660
00661 void C_Add_Int64Array(SRPC &s)
00662 {
00663 Basics::int64 expected = 0;
00664 int len = sizeof(int64s) / sizeof(int64s[0]);
00665 for(unsigned int i = 0; i < len; i++)
00666 {
00667 expected += int64s[i];
00668 }
00669
00670 new_test("C_Add_Int64Array");
00671 s.send_int64_array(int64s, len); minor++;
00672 s.send_end(); minor++;
00673 Basics::int64 result = s.recv_int64(); minor++;
00674 s.recv_end();
00675 if (result == expected) ok();
00676 else die("Callee can't sum");
00677 }
00678
00679 void S_Add_Int64Array(SRPC &s)
00680 {
00681
00682 new_test("S_Add_Int64Array");
00683 int len;
00684 Basics::int64 *array = s.recv_int64_array(len); minor++;
00685 s.recv_end(); minor++;
00686 Basics::int64 result = 0;
00687 for(unsigned int i = 0; i < len; i++)
00688 {
00689 result += array[i];
00690 }
00691 delete [] array;
00692 s.send_int64(result); minor++;
00693 s.send_end();
00694 ok();
00695 }
00696
00697
00698
00699 void C_Bool(SRPC &s)
00700 {
00701
00702 new_test("C_Bool");
00703 s.send_bool(true); minor++;
00704 s.send_bool(false); minor++;
00705 s.send_end(); minor++;
00706 bool result1 = s.recv_bool(); minor++;
00707 bool result2 = s.recv_bool(); minor++;
00708 s.recv_end();
00709 if (!result1 && result2) ok();
00710 else die("Callee can't invert booleans");
00711 }
00712
00713 void S_Bool(SRPC &s)
00714 {
00715
00716 new_test("S_Bool");
00717 bool b1 = s.recv_bool(); minor++;
00718 bool b2 = s.recv_bool(); minor++;
00719 s.recv_end(); minor++;
00720 s.send_bool(!b1); minor++;
00721 s.send_bool(!b2); minor++;
00722 s.send_end();
00723 ok();
00724 }
00725
00726
00727
00728 void C_Fail1(SRPC &s)
00729 {
00730 new_test("C_Fail1");
00731 if (!s.alive())
00732 die("SRPC::alive incorrectly reports failure");
00733 s.send_failure(ints[0], chars[0], true);
00734 if (s.alive())
00735 die("SRPC::alive fails to report failure");
00736 ok();
00737 }
00738
00739 void S_Fail1(SRPC &s)
00740 {
00741 new_test("S_Fail1");
00742 try {
00743 int i = s.recv_int();
00744 die("Expected failure wasn't thrown.");
00745 } catch (SRPC::failure f) {
00746 if (f.r == ints[0] && f.msg == Text(chars[0])) ok();
00747 else throw;
00748 };
00749 }
00750
00751
00752
00753
00754 void C_Conn2(const char *server_host)
00755 {
00756 new_test("C_Conn2");
00757 SRPC s(SRPC::caller, INTERFACE_1, server_host);
00758 print_connection(s);
00759
00760 s.send_end(); minor++;
00761 s.recv_end();
00762 ok();
00763 }
00764
00765 void S_Conn2()
00766 {
00767 new_test("S_Conn2");
00768 SRPC s(SRPC::callee, INTERFACE_1);
00769 int proc = SRPC::default_proc_id;
00770 int intf = SRPC::default_intf_version;
00771
00772 s.await_call(proc, intf); minor++;
00773 print_connection(s);
00774 if (proc != SRPC::default_proc_id) die("Proc id mismatch");
00775 if (intf != SRPC::default_intf_version) die("Interface version mismatch");
00776 s.recv_end(); minor++;
00777 s.send_end();
00778 ok();
00779 }
00780
00781
00782
00783 void C_Conn3(const char *server_host)
00784 {
00785 new_test("C_Conn3");
00786 SRPC s(SRPC::caller, INTERFACE_1, server_host);
00787 print_connection(s);
00788
00789 s.start_call();
00790 s.send_end(); minor++;
00791 s.recv_end();
00792 ok();
00793 }
00794
00795 void S_Conn3()
00796 {
00797 new_test("S_Conn3");
00798 SRPC s(SRPC::callee, INTERFACE_1);
00799 int proc = SRPC::default_proc_id;
00800 int intf = SRPC::default_intf_version;
00801
00802 s.await_call(proc, intf); minor++;
00803 print_connection(s);
00804 if (proc != SRPC::default_proc_id) die("Proc id mismatch");
00805 if (intf != SRPC::default_intf_version) die("Interface version mismatch");
00806 s.recv_end(); minor++;
00807 s.send_end();
00808 ok();
00809 }
00810
00811
00812
00813 void C_Conn4(const char *server_host)
00814 {
00815 new_test("C_Conn4");
00816 SRPC s(SRPC::caller, INTERFACE_1, server_host);
00817 print_connection(s);
00818
00819 s.start_call(ints[0], ints[1]);
00820 s.send_end(); minor++;
00821 if (!s.alive()) die("Connection reported dead");
00822 s.recv_end();
00823 wait_for_server();
00824 if (s.alive()) die("Connection not reported dead");
00825 ok();
00826 }
00827
00828 void S_Conn4()
00829 {
00830 new_test("S_Conn4");
00831 SRPC s(SRPC::callee, INTERFACE_1);
00832 int proc = SRPC::default_proc_id;
00833 int intf = SRPC::default_intf_version;
00834
00835 s.await_call(proc, intf); minor++;
00836 print_connection(s);
00837 if (!s.alive()) die("Connection reported dead");
00838 if (proc != ints[0]) die("Proc id mismatch");
00839 if (intf != ints[1]) die("Interface version mismatch");
00840 s.recv_end(); minor++;
00841 s.send_end();
00842 ok();
00843 }
00844
00845
00846
00847 void C_Conn5(const char *server_host)
00848 {
00849 new_test("C_Conn5");
00850 SRPC s(SRPC::caller, INTERFACE_1, server_host);
00851 print_connection(s);
00852
00853 s.start_call(ints[0], ints[1]);
00854 s.send_end(); minor++;
00855 s.recv_end();
00856 ok();
00857 }
00858
00859 void S_Conn5()
00860 {
00861 new_test("S_Conn5");
00862 SRPC s(SRPC::callee, INTERFACE_1);
00863 int proc = ints[0];
00864 int intf = ints[1];
00865
00866 s.await_call(proc, intf); minor++;
00867 print_connection(s);
00868 if (proc != ints[0]) die("Proc id mismatch");
00869 if (intf != ints[1]) die("Interface version mismatch");
00870 s.recv_end(); minor++;
00871 s.send_end();
00872 ok();
00873 }
00874
00875
00876
00877 void C_Conn6(const char *server_host)
00878 {
00879 new_test("C_Conn6");
00880 SRPC s(SRPC::caller, INTERFACE_1, server_host);
00881 print_connection(s);
00882
00883 try {
00884 s.start_call(ints[0], ints[1]);
00885 s.send_end();
00886 s.recv_end();
00887 die("Version skew not detected");
00888 } catch (SRPC::failure f) {
00889 if (f.r == SRPC::version_skew) ok();
00890 else throw;
00891 }
00892 }
00893
00894 void S_Conn6()
00895 {
00896 new_test("S_Conn6");
00897 SRPC s(SRPC::callee, INTERFACE_1);
00898 int proc = ints[0];
00899 int intf = ints[1]+1;
00900
00901 try {
00902 s.await_call(proc, intf);
00903 print_connection(s);
00904 s.recv_end();
00905 s.send_end();
00906 die("Version skew not detected");
00907 } catch (SRPC::failure f) {
00908 if (f.r == SRPC::version_skew) ok();
00909 else throw;
00910 }
00911 }
00912
00913
00914
00915 void C_Conn7(const char *server_host)
00916 {
00917 new_test("C_Conn7");
00918 SRPC s(SRPC::caller, INTERFACE_1, server_host);
00919 print_connection(s);
00920
00921 s.start_call();
00922 s.send_end();
00923 int dummy = s.recv_int();
00924
00925 ok();
00926 }
00927
00928 void S_Conn7()
00929 {
00930 new_test("S_Conn7");
00931 SRPC s(SRPC::callee, INTERFACE_1);
00932 int proc = SRPC::default_proc_id;
00933 int intf = SRPC::default_intf_version;
00934
00935 try {
00936 s.await_call(proc, intf);
00937 print_connection(s);
00938 s.recv_end();
00939 s.send_int(ints[0]);
00940 s.send_end();
00941 die("Disappearing partner not detected");
00942 } catch (SRPC::failure f) {
00943 if (f.r == SRPC::partner_went_away) ok();
00944 else throw;
00945 }
00946 }
00947
00948
00949
00950
00951 typedef SRPC *SRPCp;
00952
00953 void C_Multi1(const char *server_host)
00954 {
00955 new_test("C_Multi1");
00956 MultiSRPC m("");
00957 int i;
00958
00959 MultiSRPC::ConnId ids[nports];
00960 SRPCp sps[nports];
00961
00962 for (i = 0; i < nports; i++) {
00963 ids[i] = m.Start(server_host, ports[i], sps[i]); minor++;
00964 sps[i]->start_call();
00965 sps[i]->send_end();
00966 (void)sps[i]->recv_int();
00967 sps[i]->recv_end();
00968 }
00969 for (i = 0; i < nports; i++)
00970 m.End(ids[i]);
00971 for (i = 0; i < nports; i++) {
00972 SRPCp sp;
00973 MultiSRPC::ConnId id = m.Start(server_host, ports[i], sp); minor++;
00974 if (id != ids[i]) die("Cache failure");
00975 sp->send_int(i);
00976 sp->send_end();
00977 sp->recv_end();
00978 m.End(id);
00979 }
00980 ok();
00981 }
00982
00983 void S_Multi1()
00984 {
00985 SRPCp sps[nports];
00986 new_test("S_Multi1");
00987 int i;
00988 for (i = 0; i < nports; i++) {
00989 sps[i] = NEW_CONSTR(SRPC, (SRPC::callee, ports[i]));
00990 minor++;
00991 }
00992 for (i = 0; i < nports; i++) {
00993 int proc = SRPC::default_proc_id;
00994 int intf = SRPC::default_intf_version;
00995
00996 sps[i]->await_call(proc, intf);
00997 sps[i]->recv_end();
00998 sps[i]->send_int(i);
00999 sps[i]->send_end();
01000 minor++;
01001 }
01002 for (i = 0; i < nports; i++) {
01003 (void)sps[i]->recv_int(); minor++;
01004 sps[i]->recv_end();
01005 sps[i]->send_end();
01006 delete sps[i];
01007 }
01008 ok();
01009 }
01010
01011
01012
01013
01014
01015
01016 void be_client(const char *server_host)
01017 {
01018 init_random();
01019 init_arrays();
01020 try {
01021 {
01022 new_test("C_Conn1");
01023 SRPC s(SRPC::caller, INTERFACE_1, server_host);
01024 print_connection(s);
01025 ok();
01026
01027 C_Add2(s);
01028 C_Add2f(s);
01029 C_Add2_64(s);
01030 C_Addna(s);
01031 C_Addnf(s);
01032 C_Addnfp(s);
01033 C_Add_Int16Array(s);
01034 C_Add_Int32Array(s);
01035 C_Add_Int64Array(s);
01036
01037 C_Cat2(s);
01038 C_Catna(s);
01039 C_Catnf(s);
01040 C_Cat2T(s);
01041 C_CatnT(s);
01042
01043 C_Seq1(s);
01044 C_Seq2(s);
01045
01046 C_Bool(s);
01047
01048 C_Fail1(s);
01049 }
01050
01051 wait_for_server();
01052 C_Conn2(server_host);
01053 wait_for_server();
01054 C_Conn3(server_host);
01055 wait_for_server();
01056 C_Conn4(server_host);
01057 wait_for_server();
01058 C_Conn5(server_host);
01059 wait_for_server();
01060 C_Conn6(server_host);
01061 wait_for_server();
01062 C_Conn7(server_host);
01063
01064 wait_for_server();
01065 C_Multi1(server_host);
01066 wait_for_server();
01067
01068 } catch (SRPC::failure f) { fatal(f); };
01069 }
01070
01071
01072
01073
01074
01075 void be_server()
01076 {
01077 try {
01078 {
01079 new_test("S_Conn1");
01080 SRPC s(SRPC::callee, INTERFACE_1);
01081 ok();
01082
01083 S_Add2(s);
01084 S_Add2f(s);
01085 S_Add2_64(s);
01086 S_Addna(s);
01087 S_Addnf(s);
01088 S_Addnfp(s);
01089 S_Add_Int16Array(s);
01090 S_Add_Int32Array(s);
01091 S_Add_Int64Array(s);
01092
01093 S_Cat2(s);
01094 S_Catna(s);
01095 S_Catnf(s);
01096 S_Cat2T(s);
01097 S_CatnT(s);
01098
01099 S_Seq1(s);
01100 S_Seq2(s);
01101
01102 S_Bool(s);
01103
01104 S_Fail1(s);
01105 }
01106
01107 S_Conn2();
01108 S_Conn3();
01109 S_Conn4();
01110 S_Conn5();
01111 S_Conn6();
01112 S_Conn7();
01113
01114 S_Multi1();
01115
01116 } catch (SRPC::failure f) { fatal(f); };
01117 }
01118
01119 void init() {
01120 char buff[20];
01121 for (int i = 0; i < nports; i++) {
01122 sprintf(buff, "%d", port_nums[i]);
01123 ports[i] = Text(buff);
01124 }
01125 }
01126
01127 int main(int argc, char *argv[])
01128 {
01129 init();
01130 assert(argc > 0);
01131 Text prog(argv[0]);
01132 const char *host = (argc > 1) ? argv[1] : "localhost";
01133
01134
01135 int name_begin = prog.FindCharR(PathnameSep)+1;
01136 if (prog.Sub(name_begin, CLIENT_PROG.Length()) == CLIENT_PROG)
01137 be_client(host);
01138 else if (prog.Sub(name_begin, SERVER_PROG.Length()) == SERVER_PROG)
01139 be_server();
01140 else {
01141 cerr << "Unrecognized program name: "; cerr << argv[0]; cerr << endl;
01142 exit(1);
01143 }
01144
01145 return 0;
01146 }