Files
@ 0a390cf3bd15
Branch filter:
Location: CSY/reowolf/src/test/connector.rs - annotation
0a390cf3bd15
20.0 KiB
application/rls-services+xml
laying out communications with bitmatrix
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 | 06f259bf8031 06f259bf8031 06f259bf8031 06f259bf8031 06f259bf8031 8fc9f53cc0f5 a226385adc2d 8fc9f53cc0f5 6471206c5c59 6471206c5c59 6471206c5c59 8fc9f53cc0f5 8fc9f53cc0f5 8fc9f53cc0f5 8fc9f53cc0f5 8fc9f53cc0f5 8fc9f53cc0f5 8fc9f53cc0f5 8fc9f53cc0f5 8fc9f53cc0f5 8fc9f53cc0f5 8fc9f53cc0f5 8fc9f53cc0f5 8fc9f53cc0f5 8fc9f53cc0f5 8fc9f53cc0f5 8fc9f53cc0f5 8fc9f53cc0f5 8fc9f53cc0f5 8fc9f53cc0f5 8fc9f53cc0f5 8fc9f53cc0f5 8fc9f53cc0f5 8fc9f53cc0f5 8fc9f53cc0f5 aa88e65c3d92 aa88e65c3d92 aa88e65c3d92 aa88e65c3d92 aa88e65c3d92 aa88e65c3d92 aa88e65c3d92 aa88e65c3d92 8fc9f53cc0f5 aa21d6576f82 8fc9f53cc0f5 aa21d6576f82 aa21d6576f82 aa21d6576f82 aa21d6576f82 aa21d6576f82 aa21d6576f82 aa21d6576f82 aa21d6576f82 8fc9f53cc0f5 8fc9f53cc0f5 8fc9f53cc0f5 8fc9f53cc0f5 8fc9f53cc0f5 8fc9f53cc0f5 8fc9f53cc0f5 49b9c766fe5a 49b9c766fe5a 8fc9f53cc0f5 8fc9f53cc0f5 49b9c766fe5a 49b9c766fe5a 49b9c766fe5a aa21d6576f82 aa21d6576f82 aa21d6576f82 aa21d6576f82 aa21d6576f82 aa21d6576f82 aa21d6576f82 aa21d6576f82 aa21d6576f82 aa21d6576f82 aa21d6576f82 aa21d6576f82 aa21d6576f82 8fc9f53cc0f5 8fc9f53cc0f5 63a9f085c357 8ea9f0e9a5ab 8fc9f53cc0f5 8fc9f53cc0f5 8fc9f53cc0f5 8fc9f53cc0f5 63a9f085c357 8fc9f53cc0f5 d7e889432d9a 8fc9f53cc0f5 8fc9f53cc0f5 8fc9f53cc0f5 8fc9f53cc0f5 8fc9f53cc0f5 a226385adc2d 8fc9f53cc0f5 8fc9f53cc0f5 8fc9f53cc0f5 8fc9f53cc0f5 a226385adc2d 8fc9f53cc0f5 a226385adc2d 8fc9f53cc0f5 b7be5c34cd3a 06f259bf8031 b788ae5c2251 b788ae5c2251 8ea9f0e9a5ab 8fc9f53cc0f5 8fc9f53cc0f5 8fc9f53cc0f5 8fc9f53cc0f5 b788ae5c2251 8fc9f53cc0f5 d7e889432d9a 8fc9f53cc0f5 8fc9f53cc0f5 8fc9f53cc0f5 8fc9f53cc0f5 8fc9f53cc0f5 8fc9f53cc0f5 8fc9f53cc0f5 8fc9f53cc0f5 8fc9f53cc0f5 8fc9f53cc0f5 8fc9f53cc0f5 8fc9f53cc0f5 8fc9f53cc0f5 8fc9f53cc0f5 8fc9f53cc0f5 8fc9f53cc0f5 b7be5c34cd3a b788ae5c2251 58e19b42641f 58e19b42641f 8ea9f0e9a5ab 8fc9f53cc0f5 8fc9f53cc0f5 8fc9f53cc0f5 8fc9f53cc0f5 8fc9f53cc0f5 8fc9f53cc0f5 8fc9f53cc0f5 8fc9f53cc0f5 8fc9f53cc0f5 8fc9f53cc0f5 8fc9f53cc0f5 d7e889432d9a 8fc9f53cc0f5 8fc9f53cc0f5 8fc9f53cc0f5 8fc9f53cc0f5 8fc9f53cc0f5 8fc9f53cc0f5 8fc9f53cc0f5 8fc9f53cc0f5 8fc9f53cc0f5 8fc9f53cc0f5 8fc9f53cc0f5 8fc9f53cc0f5 8fc9f53cc0f5 8fc9f53cc0f5 b7be5c34cd3a 8fc9f53cc0f5 8fc9f53cc0f5 8ea9f0e9a5ab 8fc9f53cc0f5 8fc9f53cc0f5 8fc9f53cc0f5 8fc9f53cc0f5 8fc9f53cc0f5 8fc9f53cc0f5 8fc9f53cc0f5 d7e889432d9a 8fc9f53cc0f5 8fc9f53cc0f5 8fc9f53cc0f5 8fc9f53cc0f5 8fc9f53cc0f5 8fc9f53cc0f5 8fc9f53cc0f5 8fc9f53cc0f5 8fc9f53cc0f5 8fc9f53cc0f5 8fc9f53cc0f5 8fc9f53cc0f5 b7be5c34cd3a 58e19b42641f a226385adc2d 8fc9f53cc0f5 8ea9f0e9a5ab 8fc9f53cc0f5 8fc9f53cc0f5 8fc9f53cc0f5 8fc9f53cc0f5 8fc9f53cc0f5 8fc9f53cc0f5 d7e889432d9a 8fc9f53cc0f5 8fc9f53cc0f5 8fc9f53cc0f5 8fc9f53cc0f5 8fc9f53cc0f5 8fc9f53cc0f5 8fc9f53cc0f5 8fc9f53cc0f5 8fc9f53cc0f5 8fc9f53cc0f5 8fc9f53cc0f5 8fc9f53cc0f5 8fc9f53cc0f5 8fc9f53cc0f5 b7be5c34cd3a 8fc9f53cc0f5 ce6bcc0a0c26 a226385adc2d 8ea9f0e9a5ab 8fc9f53cc0f5 8fc9f53cc0f5 8fc9f53cc0f5 8fc9f53cc0f5 8fc9f53cc0f5 8fc9f53cc0f5 8fc9f53cc0f5 8fc9f53cc0f5 8fc9f53cc0f5 8fc9f53cc0f5 d7e889432d9a 8fc9f53cc0f5 8fc9f53cc0f5 8fc9f53cc0f5 8fc9f53cc0f5 8fc9f53cc0f5 8fc9f53cc0f5 8fc9f53cc0f5 8fc9f53cc0f5 8fc9f53cc0f5 8fc9f53cc0f5 8fc9f53cc0f5 b7be5c34cd3a 8fc9f53cc0f5 8fc9f53cc0f5 8fc9f53cc0f5 8ea9f0e9a5ab 8fc9f53cc0f5 8fc9f53cc0f5 8fc9f53cc0f5 8fc9f53cc0f5 a226385adc2d a226385adc2d 8fc9f53cc0f5 8fc9f53cc0f5 b7be5c34cd3a d7e889432d9a a226385adc2d 8fc9f53cc0f5 a226385adc2d a226385adc2d a226385adc2d 8fc9f53cc0f5 8fc9f53cc0f5 8fc9f53cc0f5 8fc9f53cc0f5 a226385adc2d a226385adc2d 8fc9f53cc0f5 a226385adc2d a226385adc2d a226385adc2d 8fc9f53cc0f5 8fc9f53cc0f5 8fc9f53cc0f5 8fc9f53cc0f5 8fc9f53cc0f5 a226385adc2d b7be5c34cd3a a226385adc2d a226385adc2d a226385adc2d 8ea9f0e9a5ab 8fc9f53cc0f5 8fc9f53cc0f5 8fc9f53cc0f5 8fc9f53cc0f5 8fc9f53cc0f5 a226385adc2d a226385adc2d 8fc9f53cc0f5 8fc9f53cc0f5 d7e889432d9a a226385adc2d 8fc9f53cc0f5 8fc9f53cc0f5 a226385adc2d 8fc9f53cc0f5 a226385adc2d 8fc9f53cc0f5 8fc9f53cc0f5 8fc9f53cc0f5 8fc9f53cc0f5 a226385adc2d a226385adc2d 8fc9f53cc0f5 8fc9f53cc0f5 8fc9f53cc0f5 a226385adc2d a226385adc2d 8fc9f53cc0f5 8fc9f53cc0f5 8fc9f53cc0f5 8fc9f53cc0f5 8fc9f53cc0f5 a226385adc2d b7be5c34cd3a a226385adc2d ce6bcc0a0c26 ce6bcc0a0c26 8ea9f0e9a5ab 8fc9f53cc0f5 ce6bcc0a0c26 ce6bcc0a0c26 ce6bcc0a0c26 ce6bcc0a0c26 ce6bcc0a0c26 ce6bcc0a0c26 8fc9f53cc0f5 d7e889432d9a ce6bcc0a0c26 ce6bcc0a0c26 8fc9f53cc0f5 8fc9f53cc0f5 ce6bcc0a0c26 ce6bcc0a0c26 ce6bcc0a0c26 ce6bcc0a0c26 8fc9f53cc0f5 ce6bcc0a0c26 ce6bcc0a0c26 ce6bcc0a0c26 ce6bcc0a0c26 8fc9f53cc0f5 8fc9f53cc0f5 ce6bcc0a0c26 ce6bcc0a0c26 ce6bcc0a0c26 8fc9f53cc0f5 8fc9f53cc0f5 8fc9f53cc0f5 8fc9f53cc0f5 8fc9f53cc0f5 8fc9f53cc0f5 8fc9f53cc0f5 8fc9f53cc0f5 b7be5c34cd3a 8fc9f53cc0f5 ce6bcc0a0c26 8fc9f53cc0f5 8ea9f0e9a5ab 8fc9f53cc0f5 8fc9f53cc0f5 8fc9f53cc0f5 8fc9f53cc0f5 8fc9f53cc0f5 8fc9f53cc0f5 8fc9f53cc0f5 8fc9f53cc0f5 d7e889432d9a 8fc9f53cc0f5 8fc9f53cc0f5 8fc9f53cc0f5 8fc9f53cc0f5 8fc9f53cc0f5 8fc9f53cc0f5 8fc9f53cc0f5 8fc9f53cc0f5 8fc9f53cc0f5 8fc9f53cc0f5 ce6bcc0a0c26 8fc9f53cc0f5 8fc9f53cc0f5 8fc9f53cc0f5 8fc9f53cc0f5 8fc9f53cc0f5 8fc9f53cc0f5 8fc9f53cc0f5 8fc9f53cc0f5 8fc9f53cc0f5 8fc9f53cc0f5 8fc9f53cc0f5 ce6bcc0a0c26 8fc9f53cc0f5 8fc9f53cc0f5 ce6bcc0a0c26 ce6bcc0a0c26 b7be5c34cd3a ce6bcc0a0c26 ce6bcc0a0c26 ce6bcc0a0c26 8ea9f0e9a5ab 8fc9f53cc0f5 8fc9f53cc0f5 ce6bcc0a0c26 ce6bcc0a0c26 ce6bcc0a0c26 ce6bcc0a0c26 ce6bcc0a0c26 ce6bcc0a0c26 ce6bcc0a0c26 8fc9f53cc0f5 d7e889432d9a ce6bcc0a0c26 ce6bcc0a0c26 ce6bcc0a0c26 8fc9f53cc0f5 ce6bcc0a0c26 ce6bcc0a0c26 ce6bcc0a0c26 ce6bcc0a0c26 ce6bcc0a0c26 ce6bcc0a0c26 ce6bcc0a0c26 8fc9f53cc0f5 ce6bcc0a0c26 ce6bcc0a0c26 ce6bcc0a0c26 ce6bcc0a0c26 ce6bcc0a0c26 ce6bcc0a0c26 8fc9f53cc0f5 ce6bcc0a0c26 ce6bcc0a0c26 ce6bcc0a0c26 ce6bcc0a0c26 ce6bcc0a0c26 ce6bcc0a0c26 ce6bcc0a0c26 8fc9f53cc0f5 ce6bcc0a0c26 ce6bcc0a0c26 ce6bcc0a0c26 ce6bcc0a0c26 ce6bcc0a0c26 ce6bcc0a0c26 ce6bcc0a0c26 ce6bcc0a0c26 8fc9f53cc0f5 ce6bcc0a0c26 ce6bcc0a0c26 ce6bcc0a0c26 ce6bcc0a0c26 ce6bcc0a0c26 ce6bcc0a0c26 ce6bcc0a0c26 ce6bcc0a0c26 ce6bcc0a0c26 ce6bcc0a0c26 ce6bcc0a0c26 ce6bcc0a0c26 8fc9f53cc0f5 ce6bcc0a0c26 ce6bcc0a0c26 b7be5c34cd3a ce6bcc0a0c26 ce6bcc0a0c26 3e63b3973c47 8ea9f0e9a5ab 8fc9f53cc0f5 3e63b3973c47 7e1dc225d7f4 3e63b3973c47 7e1dc225d7f4 7e1dc225d7f4 7e1dc225d7f4 7e1dc225d7f4 7e1dc225d7f4 7e1dc225d7f4 7e1dc225d7f4 7e1dc225d7f4 7e1dc225d7f4 7e1dc225d7f4 7e1dc225d7f4 7e1dc225d7f4 7e1dc225d7f4 7e1dc225d7f4 7e1dc225d7f4 7e1dc225d7f4 7e1dc225d7f4 7e1dc225d7f4 7e1dc225d7f4 7e1dc225d7f4 7e1dc225d7f4 7e1dc225d7f4 7e1dc225d7f4 7e1dc225d7f4 7e1dc225d7f4 7e1dc225d7f4 7e1dc225d7f4 7e1dc225d7f4 7e1dc225d7f4 7e1dc225d7f4 7e1dc225d7f4 5e11ebce9bc0 7e1dc225d7f4 7e1dc225d7f4 8ea9f0e9a5ab 7e1dc225d7f4 7e1dc225d7f4 7e1dc225d7f4 7e1dc225d7f4 3e63b3973c47 3e63b3973c47 3e63b3973c47 5e11ebce9bc0 d7e889432d9a 3e63b3973c47 3e63b3973c47 3e63b3973c47 8fc9f53cc0f5 3e63b3973c47 3e63b3973c47 3e63b3973c47 3e63b3973c47 3e63b3973c47 3e63b3973c47 3e63b3973c47 3e63b3973c47 3e63b3973c47 3e63b3973c47 7e1dc225d7f4 3e63b3973c47 3e63b3973c47 3e63b3973c47 3e63b3973c47 3e63b3973c47 3e63b3973c47 3e63b3973c47 3e63b3973c47 3e63b3973c47 3e63b3973c47 b7be5c34cd3a 3e63b3973c47 3e63b3973c47 ce6bcc0a0c26 8ea9f0e9a5ab 8fc9f53cc0f5 aa88e65c3d92 aa88e65c3d92 aa88e65c3d92 ce6bcc0a0c26 ce6bcc0a0c26 ce6bcc0a0c26 ce6bcc0a0c26 d7e889432d9a ce6bcc0a0c26 ce6bcc0a0c26 8fc9f53cc0f5 aa88e65c3d92 8fc9f53cc0f5 aa88e65c3d92 aa88e65c3d92 aa88e65c3d92 ce6bcc0a0c26 8fc9f53cc0f5 aa88e65c3d92 aa88e65c3d92 8fc9f53cc0f5 aa88e65c3d92 ce6bcc0a0c26 ce6bcc0a0c26 ce6bcc0a0c26 8fc9f53cc0f5 aa88e65c3d92 8fc9f53cc0f5 aa88e65c3d92 aa88e65c3d92 aa88e65c3d92 ce6bcc0a0c26 ce6bcc0a0c26 aa88e65c3d92 aa88e65c3d92 8fc9f53cc0f5 aa88e65c3d92 8fc9f53cc0f5 8fc9f53cc0f5 b7be5c34cd3a 8fc9f53cc0f5 8fc9f53cc0f5 8fc9f53cc0f5 8ea9f0e9a5ab aa21d6576f82 aa21d6576f82 aa21d6576f82 8fc9f53cc0f5 aa21d6576f82 8fc9f53cc0f5 800041f16514 8fc9f53cc0f5 800041f16514 d7e889432d9a 8fc9f53cc0f5 8fc9f53cc0f5 8fc9f53cc0f5 aa21d6576f82 8fc9f53cc0f5 8fc9f53cc0f5 aa21d6576f82 8fc9f53cc0f5 8fc9f53cc0f5 8fc9f53cc0f5 aa21d6576f82 aa21d6576f82 aa21d6576f82 aa21d6576f82 aa21d6576f82 ce6bcc0a0c26 aa21d6576f82 aa21d6576f82 8fc9f53cc0f5 aa21d6576f82 ce6bcc0a0c26 aa21d6576f82 aa21d6576f82 ce6bcc0a0c26 ce6bcc0a0c26 ce6bcc0a0c26 ce6bcc0a0c26 ce6bcc0a0c26 8fc9f53cc0f5 aa21d6576f82 8fc9f53cc0f5 ce6bcc0a0c26 ce6bcc0a0c26 ce6bcc0a0c26 aa21d6576f82 ce6bcc0a0c26 aa21d6576f82 aa21d6576f82 ce6bcc0a0c26 ce6bcc0a0c26 aa21d6576f82 aa21d6576f82 ce6bcc0a0c26 ce6bcc0a0c26 ce6bcc0a0c26 ce6bcc0a0c26 b7be5c34cd3a ce6bcc0a0c26 aa21d6576f82 aa21d6576f82 8ea9f0e9a5ab aa21d6576f82 aa21d6576f82 aa21d6576f82 aa21d6576f82 aa21d6576f82 aa21d6576f82 aa21d6576f82 aa21d6576f82 aa21d6576f82 aa21d6576f82 aa21d6576f82 aa21d6576f82 aa21d6576f82 aa21d6576f82 aa21d6576f82 aa21d6576f82 aa21d6576f82 aa21d6576f82 aa21d6576f82 aa21d6576f82 aa21d6576f82 aa21d6576f82 aa21d6576f82 aa21d6576f82 05c5f19eb371 aa21d6576f82 aa21d6576f82 aa21d6576f82 aa21d6576f82 | extern crate test_generator;
use super::*;
use crate::common::*;
use crate::runtime::{errors::*, PortBinding::*};
static PDL: &[u8] = b"
primitive forward_once(in i, out o) {
synchronous() put(o, get(i));
}
primitive blocked(in i, out o) {
while(true) synchronous {}
}
primitive forward(in i, out o) {
while(true) synchronous {
put(o, get(i));
}
}
primitive sync(in i, out o) {
while(true) synchronous {
if (fires(i)) put(o, get(i));
}
}
primitive alternator_2(in i, out a, out b) {
while(true) {
synchronous { put(a, get(i)); }
synchronous { put(b, get(i)); }
}
}
composite sync_2(in i, out o) {
channel x -> y;
new sync(i, x);
new sync(y, o);
}
primitive exchange(in ai, out ao, in bi, out bo) {
// Note the implicit causal relationship
while(true) synchronous {
if(fires(ai)) {
put(bo, get(ai));
put(ao, get(bi));
}
}
}
primitive filter(in i, out ok, out err) {
while(true) synchronous {
if (fires(i)) {
msg m = get(i);
if(m.length > 0) {
put(ok, m);
} else {
put(err, m);
}
}
}
}
primitive token_spout(out o) {
while(true) synchronous {
put(o, create(0));
}
}
primitive wait_n(int to_wait, out o) {
while(to_wait > 0) synchronous() to_wait -= 1;
synchronous { put(o, create(0)); }
}
composite wait_10(out o) {
new wait_n(10, o);
}
primitive fifo_1(msg m, in i, out o) {
while(true) synchronous {
if (m == null && fires(i)) {
m = get(i);
} else if (m != null && fires(o)) {
put(o, m);
m = null;
}
}
}
composite fifo_1_e(in i, out o) {
new fifo_1(null, i, o);
}
";
#[test]
fn connector_connects_ok() {
// Test if we can connect natives using the given PDL
/*
Alice -->silence--P|A-->silence--> Bob
*/
let timeout = Duration::from_millis(1_500);
let addrs = [next_addr()];
assert!(run_connector_set(&[
&|x| {
// Alice
x.configure(PDL, b"blocked").unwrap();
x.bind_port(0, Native).unwrap();
x.bind_port(1, Passive(addrs[0])).unwrap();
x.connect(timeout).unwrap();
},
&|x| {
// Bob
x.configure(PDL, b"blocked").unwrap();
x.bind_port(0, Active(addrs[0])).unwrap();
x.bind_port(1, Native).unwrap();
x.connect(timeout).unwrap();
},
]));
}
#[test]
fn connector_connected_but_silent_natives() {
// Test if we can connect natives and have a trivial sync round
/*
Alice -->silence--P|A-->silence--> Bob
*/
let timeout = Duration::from_millis(1_500);
let addrs = [next_addr()];
assert!(run_connector_set(&[
&|x| {
// Alice
x.configure(PDL, b"blocked").unwrap();
x.bind_port(0, Native).unwrap();
x.bind_port(1, Passive(addrs[0])).unwrap();
x.connect(timeout).unwrap();
assert_eq!(Ok(0), x.sync(timeout));
},
&|x| {
// Bob
x.configure(PDL, b"blocked").unwrap();
x.bind_port(0, Active(addrs[0])).unwrap();
x.bind_port(1, Native).unwrap();
x.connect(timeout).unwrap();
assert_eq!(Ok(0), x.sync(timeout));
},
]));
}
#[test]
fn connector_self_forward_ok() {
// Test a deterministic system
// where a native has no network bindings
// and sends messages to itself
/*
/-->\
Alice forward
\<--/
*/
let timeout = Duration::from_millis(1_500);
const N: usize = 5;
static MSG: &[u8] = b"Echo!";
assert!(run_connector_set(&[
//
&|x| {
// Alice
x.configure(PDL, b"forward").unwrap();
x.bind_port(0, Native).unwrap();
x.bind_port(1, Native).unwrap();
x.connect(timeout).unwrap();
for _ in 0..N {
x.put(0, MSG.to_vec()).unwrap();
x.get(1).unwrap();
assert_eq!(Ok(0), x.sync(timeout));
assert_eq!(Ok(MSG), x.read_gotten(1));
}
},
]));
}
#[test]
fn connector_token_spout_ok() {
// Test a deterministic system where the proto
// creates token messages
/*
Alice<--token_spout
*/
let timeout = Duration::from_millis(1_500);
const N: usize = 5;
assert!(run_connector_set(&[
//
&|x| {
// Alice
x.configure(PDL, b"token_spout").unwrap();
x.bind_port(0, Native).unwrap();
x.connect(timeout).unwrap();
for _ in 0..N {
x.get(0).unwrap();
assert_eq!(Ok(0), x.sync(timeout));
assert_eq!(Ok(&[] as &[u8]), x.read_gotten(0));
}
},
]));
}
#[test]
fn connector_waiter_ok() {
// Test a stateful proto that blocks port 0 for 10 rounds
// and then sends a single token on the 11th
/*
Alice<--token_spout
*/
let timeout = Duration::from_millis(1_500);
assert!(run_connector_set(&[
//
&|x| {
// Alice
x.configure(PDL, b"wait_10").unwrap();
x.bind_port(0, Native).unwrap();
x.connect(timeout).unwrap();
for _ in 0..10 {
assert_eq!(Ok(0), x.sync(timeout));
assert_eq!(Err(ReadGottenErr::DidNotGet), x.read_gotten(0));
}
x.get(0).unwrap();
assert_eq!(Ok(0), x.sync(timeout));
assert_eq!(Ok(&[] as &[u8]), x.read_gotten(0));
},
]));
}
#[test]
fn connector_self_forward_timeout() {
// Test a deterministic system
// where a native has no network bindings
// and sends messages to itself
/*
/-->\
Alice forward
\<--/
*/
let timeout = Duration::from_millis(500);
static MSG: &[u8] = b"Echo!";
assert!(run_connector_set(&[
//
&|x| {
// Sender
x.configure(PDL, b"forward").unwrap();
x.bind_port(0, Native).unwrap();
x.bind_port(1, Native).unwrap();
x.connect(timeout).unwrap();
x.put(0, MSG.to_vec()).unwrap();
// native and forward components cannot find a solution
assert_eq!(Err(SyncErr::Timeout), x.sync(timeout));
},
]));
}
#[test]
fn connector_forward_det() {
// Test if a deterministic protocol and natives can pass one message
/*
Alice -->forward--P|A-->forward--> Bob
*/
let timeout = Duration::from_millis(1_500);
let addrs = [next_addr()];
const N: usize = 5;
static MSG: &[u8] = b"Hello!";
assert!(run_connector_set(&[
&|x| {
x.configure(PDL, b"forward").unwrap();
x.bind_port(0, Native).unwrap();
x.bind_port(1, Passive(addrs[0])).unwrap();
x.connect(timeout).unwrap();
for _ in 0..N {
x.put(0, MSG.to_vec()).unwrap();
assert_eq!(Ok(0), x.sync(timeout));
}
},
&|x| {
x.configure(PDL, b"forward").unwrap();
x.bind_port(0, Active(addrs[0])).unwrap();
x.bind_port(1, Native).unwrap();
x.connect(timeout).unwrap();
for _ in 0..N {
x.get(0).unwrap();
assert_eq!(Ok(0), x.sync(timeout));
assert_eq!(Ok(MSG), x.read_gotten(0));
}
},
]));
}
#[test]
fn connector_nondet_proto_det_natives() {
// Test the use of a nondeterministic protocol
// where Alice decides the choice and the others conform
/*
Alice -->sync--A|P-->sync--> Bob
*/
let timeout = Duration::from_millis(1_500);
let addrs = [next_addr()];
const N: usize = 5;
static MSG: &[u8] = b"Message, here!";
assert!(run_connector_set(&[
&|x| {
// Alice
x.configure(PDL, b"sync").unwrap();
x.bind_port(0, Native).unwrap();
x.bind_port(1, Active(addrs[0])).unwrap();
x.connect(timeout).unwrap();
for _i in 0..N {
x.put(0, MSG.to_vec()).unwrap();
assert_eq!(0, x.sync(timeout).unwrap());
}
},
&|x| {
// Bob
x.configure(PDL, b"sync").unwrap();
x.bind_port(0, Passive(addrs[0])).unwrap();
x.bind_port(1, Native).unwrap();
x.connect(timeout).unwrap();
for _i in 0..N {
x.get(0).unwrap();
assert_eq!(Ok(0), x.sync(timeout));
assert_eq!(Ok(MSG), x.read_gotten(0));
}
},
]));
}
#[test]
fn connector_putter_determines() {
// putter and getter
/*
Alice -->sync--A|P-->sync--> Bob
*/
let timeout = Duration::from_millis(1_500);
let addrs = [next_addr()];
const N: usize = 3;
static MSG: &[u8] = b"Hidey ho!";
assert!(run_connector_set(&[
//
&|x| {
// Alice
x.configure(PDL, b"sync").unwrap();
x.bind_port(0, Native).unwrap();
x.bind_port(1, Active(addrs[0])).unwrap();
x.connect(timeout).unwrap();
for _i in 0..N {
x.put(0, MSG.to_vec()).unwrap();
assert_eq!(0, x.sync(timeout).unwrap());
}
},
&|x| {
// Bob
x.configure(PDL, b"sync").unwrap();
x.bind_port(0, Passive(addrs[0])).unwrap();
x.bind_port(1, Native).unwrap();
x.connect(timeout).unwrap();
for _i in 0..N {
// batches [{0=>*}, {0=>?}]
x.get(0).unwrap();
x.next_batch().unwrap();
assert_eq!(Ok(0), x.sync(timeout));
assert_eq!(Ok(MSG), x.read_gotten(0));
}
},
]));
}
#[test]
fn connector_getter_determines() {
// putter and getter
/*
Alice -->sync--A|P-->sync--> Bob
*/
let timeout = Duration::from_millis(1_500);
let addrs = [next_addr()];
const N: usize = 5;
static MSG: &[u8] = b"Hidey ho!";
assert!(run_connector_set(&[
//
&|x| {
// Alice
x.configure(PDL, b"sync").unwrap();
x.bind_port(0, Native).unwrap();
x.bind_port(1, Active(addrs[0])).unwrap();
x.connect(timeout).unwrap();
for _i in 0..N {
// batches [{0=>?}, {0=>*}]
x.put(0, MSG.to_vec()).unwrap();
x.next_batch().unwrap();
assert_eq!(Ok(0), x.sync(timeout));
}
},
&|x| {
// Bob
x.configure(PDL, b"sync").unwrap();
x.bind_port(0, Passive(addrs[0])).unwrap();
x.bind_port(1, Native).unwrap();
x.connect(timeout).unwrap();
for _i in 0..N {
x.get(0).unwrap();
assert_eq!(Ok(0), x.sync(timeout));
assert_eq!(Ok(MSG), x.read_gotten(0));
}
},
]));
}
#[test]
fn connector_alternator_2() {
// Test a deterministic system which
// alternates sending Sender's messages to A or B
/* /--|-->A
Sender -->alternator_2
\--|-->B
*/
let timeout = Duration::from_millis(1_500);
let addrs = [next_addr(), next_addr()];
const N: usize = 5;
static MSG: &[u8] = b"message";
assert!(run_connector_set(&[
//
&|x| {
// Sender
x.configure(PDL, b"alternator_2").unwrap();
x.bind_port(0, Native).unwrap();
x.bind_port(1, Passive(addrs[0])).unwrap();
x.bind_port(2, Passive(addrs[1])).unwrap();
x.connect(timeout).unwrap();
for _ in 0..N {
for _ in 0..2 {
x.put(0, MSG.to_vec()).unwrap();
assert_eq!(0, x.sync(timeout).unwrap());
}
}
},
&|x| {
// A
x.configure(PDL, b"sync").unwrap();
x.bind_port(0, Active(addrs[0])).unwrap();
x.bind_port(1, Native).unwrap();
x.connect(timeout).unwrap();
for _ in 0..N {
// get msg round
x.get(0).unwrap();
assert_eq!(Ok(0), x.sync(timeout)); // GET ONE
assert_eq!(Ok(MSG), x.read_gotten(0));
// silent round
assert_eq!(Ok(0), x.sync(timeout)); // MISS ONE
assert_eq!(Err(ReadGottenErr::DidNotGet), x.read_gotten(0));
}
},
&|x| {
// B
x.configure(PDL, b"sync").unwrap();
x.bind_port(0, Active(addrs[1])).unwrap();
x.bind_port(1, Native).unwrap();
x.connect(timeout).unwrap();
for _ in 0..N {
// silent round
assert_eq!(Ok(0), x.sync(timeout)); // MISS ONE
assert_eq!(Err(ReadGottenErr::DidNotGet), x.read_gotten(0));
// get msg round
x.get(0).unwrap();
assert_eq!(Ok(0), x.sync(timeout)); // GET ONE
assert_eq!(Ok(MSG), x.read_gotten(0));
}
},
]));
}
#[test]
fn connector_composite_chain_a() {
// Check if composition works. Forward messages through long chains
/*
Alice -->sync-->sync-->A|P-->sync--> Bob
*/
let timeout = Duration::from_millis(1_500);
let addrs = [next_addr(), next_addr()];
const N: usize = 1;
static MSG: &[u8] = b"SSS";
assert!(run_connector_set(&[
//
&|x| {
// Alice
x.configure(PDL, b"sync_2").unwrap();
x.bind_port(0, Native).unwrap();
x.bind_port(1, Active(addrs[0])).unwrap();
x.connect(timeout).unwrap();
for _ in 0..N {
x.put(0, MSG.to_vec()).unwrap();
assert_eq!(0, x.sync(timeout).unwrap());
}
},
&|x| {
// Bob
x.configure(PDL, b"forward").unwrap();
x.bind_port(0, Passive(addrs[0])).unwrap();
x.bind_port(1, Native).unwrap();
x.connect(timeout).unwrap();
for _ in 0..N {
// get msg round
x.get(0).unwrap();
assert_eq!(Ok(0), x.sync(timeout));
assert_eq!(Ok(MSG), x.read_gotten(0));
}
},
]));
}
#[test]
fn connector_composite_chain_b() {
// Check if composition works. Forward messages through long chains
/*
Alice -->sync-->sync-->A|P-->sync-->sync--> Bob
*/
let timeout = Duration::from_millis(1_500);
let addrs = [next_addr(), next_addr()];
const N: usize = 1;
static MSG: &[u8] = b"SSS";
assert!(run_connector_set(&[
//
&|x| {
// Alice
x.configure(PDL, b"sync_2").unwrap();
x.bind_port(0, Native).unwrap();
x.bind_port(1, Active(addrs[0])).unwrap();
x.connect(timeout).unwrap();
for _ in 0..N {
x.put(0, MSG.to_vec()).unwrap();
assert_eq!(0, x.sync(timeout).unwrap());
}
},
&|x| {
// Bob
x.configure(PDL, b"sync_2").unwrap();
x.bind_port(0, Passive(addrs[0])).unwrap();
x.bind_port(1, Native).unwrap();
x.connect(timeout).unwrap();
for _ in 0..N {
// get msg round
x.get(0).unwrap();
assert_eq!(Ok(0), x.sync(timeout));
assert_eq!(Ok(MSG), x.read_gotten(0));
}
},
]));
}
#[test]
fn connector_exchange() {
/*
/-->\ /-->P|A-->\ /-->\
Alice exchange exchange Bob
\<--/ \<--P|A<--/ \<--/
*/
let timeout = Duration::from_millis(1_500);
let addrs = [next_addr(), next_addr()];
const N: usize = 1;
assert!(run_connector_set(&[
//
&|x| {
// Alice
x.configure(PDL, b"exchange").unwrap();
x.bind_port(0, Native).unwrap(); // native in
x.bind_port(1, Native).unwrap(); // native out
x.bind_port(2, Passive(addrs[0])).unwrap(); // peer out
x.bind_port(3, Passive(addrs[1])).unwrap(); // peer in
x.connect(timeout).unwrap();
for _ in 0..N {
assert_eq!(Ok(()), x.put(0, b"A->B".to_vec()));
assert_eq!(Ok(()), x.get(1));
assert_eq!(Ok(0), x.sync(timeout));
assert_eq!(Ok(b"B->A" as &[u8]), x.read_gotten(1));
}
},
&|x| {
// Bob
x.configure(PDL, b"exchange").unwrap();
x.bind_port(0, Native).unwrap(); // native in
x.bind_port(1, Native).unwrap(); // native out
x.bind_port(2, Active(addrs[1])).unwrap(); // peer out
x.bind_port(3, Active(addrs[0])).unwrap(); // peer in
x.connect(timeout).unwrap();
for _ in 0..N {
assert_eq!(Ok(()), x.put(0, b"B->A".to_vec()));
assert_eq!(Ok(()), x.get(1));
assert_eq!(Ok(0), x.sync(timeout));
assert_eq!(Ok(b"A->B" as &[u8]), x.read_gotten(1));
}
},
]));
}
#[test]
fn connector_routing_filter() {
// Make a protocol whose behavior is a function of the contents of
// a message. Here, the putter determines what is sent, and the proto
// determines how it is routed
/*
Sender -->filter-->P|A-->sync--> Receiver
*/
let timeout = Duration::from_millis(3_000);
let addrs = [next_addr()];
const N: usize = 1;
assert!(run_connector_set(&[
//
&|x| {
// Sender
x.configure(PDL, b"filter").unwrap();
x.bind_port(0, Native).unwrap();
x.bind_port(1, Passive(addrs[0])).unwrap();
x.bind_port(2, Native).unwrap(); // err channel
x.connect(timeout).unwrap();
for i in (0..3).cycle().take(N) {
// messages cycle [], [4], [4,4], ...
let msg: Payload = std::iter::repeat(4).take(i).collect();
// batch 0: passes through filter!
x.put(0, msg.clone()).unwrap();
x.next_batch().unwrap();
// batch 1: gets returned!
x.put(0, msg.clone()).unwrap();
x.get(1).unwrap();
match x.sync(timeout).unwrap() {
0 => assert_ne!(msg.len(), 0), // ok
1 => assert_eq!(msg.len(), 0), // err
_ => unreachable!(),
}
}
},
&|x| {
// Receiver
x.configure(PDL, b"sync").unwrap();
x.bind_port(0, Active(addrs[0])).unwrap();
x.bind_port(1, Native).unwrap();
x.connect(timeout).unwrap();
for _ in 0..N {
// empty batch
x.next_batch().unwrap();
// got a message
x.get(0).unwrap();
match x.sync(timeout).unwrap() {
0 => assert_eq!(Err(ReadGottenErr::DidNotGet), x.read_gotten(0)),
1 => assert_ne!(Ok(&[] as &[u8]), x.read_gotten(0)),
_ => unreachable!(),
}
}
},
]));
}
#[test]
fn connector_fifo_1_e() {
/*
/-->\
Alice fifo_1
\<--/
*/
let timeout = Duration::from_millis(1_500);
const N: usize = 10;
assert!(run_connector_set(&[
//
&|x| {
// Alice
x.configure(PDL, b"fifo_1_e").unwrap();
x.bind_port(0, Native).unwrap();
x.bind_port(1, Native).unwrap();
x.connect(timeout).unwrap();
for _ in 0..N {
// put
assert_eq!(Ok(()), x.put(0, b"message~".to_vec()));
assert_eq!(Ok(0), x.sync(timeout));
// get
assert_eq!(Ok(()), x.get(1));
assert_eq!(Ok(0), x.sync(timeout));
assert_eq!(Ok(b"message~" as &[u8]), x.read_gotten(1));
}
},
]));
}
|