preCICE v3.2.0
Loading...
Searching...
No Matches
GenericTestFunctions.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <Eigen/Core>
4#include <boost/test/unit_test.hpp>
5#include <string>
6#include <vector>
7
9#include "testing/Testing.hpp"
10
13
15
16namespace primaryprimary {
17
22
23template <typename T>
25{
26 T com;
27
28 if (context.isNamed("A")) {
29 com.acceptConnection("process0", "process1", "", 0);
30 {
31 std::string msg("testOne");
32 com.send(msg, 0);
33 com.receive(msg, 0);
34 BOOST_TEST(msg == std::string("testTwo"));
35 }
36 {
37 double msg = 0.0;
38 com.send(msg, 0);
39 com.receive(msg, 0);
40 BOOST_TEST(msg == 1.0);
41 }
42 {
43 int msg = 1;
44 com.send(msg, 0);
45 com.receive(msg, 0);
46 BOOST_TEST(msg == 2);
47 }
48 {
49 bool msg = true;
50 com.send(msg, 0);
51 com.receive(msg, 0);
52 BOOST_TEST(msg == false);
53 }
54 com.closeConnection();
55 } else {
56 com.requestConnection("process0", "process1", "", 0, 1);
57 {
58 std::string msg;
59 com.receive(msg, 0);
60 BOOST_TEST(msg == std::string("testOne"));
61 msg = "testTwo";
62 com.send(msg, 0);
63 }
64 {
65 double msg = 1.0;
66 com.receive(msg, 0);
67 BOOST_TEST(msg == 0.0);
68 msg = 1.0;
69 com.send(msg, 0);
70 }
71 {
72 int msg = 0;
73 com.receive(msg, 0);
74 BOOST_TEST(msg == 1);
75 msg = 2;
76 com.send(msg, 0);
77 }
78 {
79 bool msg = false;
80 com.receive(msg, 0);
81 BOOST_TEST(msg == true);
82 msg = false;
83 com.send(msg, 0);
84 }
85 com.closeConnection();
86 }
87}
88
89template <typename T>
91{
92 T com;
93
94 if (context.isNamed("A")) {
95 com.acceptConnection("process0", "process1", "", 0);
96 {
97 Eigen::Vector3d msg = Eigen::Vector3d::Constant(0);
98 com.receive(msg, 0);
99 BOOST_CHECK(testing::equals(msg, Eigen::Vector3d::Constant(1)));
100 msg = Eigen::Vector3d::Constant(2);
101 com.send(msg, 0);
102 }
103 {
104 Eigen::Vector4i msg = Eigen::Vector4i::Constant(0);
105 com.receive(msg, 0);
106 BOOST_CHECK(testing::equals(msg, Eigen::Vector4i::Constant(1)));
107 msg = Eigen::Vector4i::Constant(0);
108 com.send(msg, 0);
109 }
110 com.closeConnection();
111 } else {
112 com.requestConnection("process0", "process1", "", 0, 1);
113 {
114 Eigen::Vector3d msg = Eigen::Vector3d::Constant(1);
115 com.send(msg, 0);
116 com.receive(msg, 0);
117 BOOST_CHECK(testing::equals(msg, Eigen::Vector3d::Constant(2)));
118 }
119 {
120 Eigen::Vector4i msg = Eigen::Vector4i::Constant(1);
121 com.send(msg, 0);
122 com.receive(msg, 0);
123 BOOST_CHECK(testing::equals(msg, Eigen::Vector4i::Zero()));
124 }
125 com.closeConnection();
126 }
127}
128
129template <typename T>
131{
132 T com;
134
135 if (context.isNamed("A")) {
136 com.acceptConnection("process0", "process1", "", 0);
137 {
138 std::vector<int> recv{1, 2, 3};
139 std::vector<int> msg = com.receiveRange(0, asVector<int>);
140 BOOST_TEST(msg == recv);
141 com.sendRange(msg, 0);
142 }
143 {
144 std::vector<double> msg = com.receiveRange(0, asVector<double>);
145 BOOST_TEST(msg == std::vector<double>({1.1, 2.2, 3.3}));
146 com.sendRange(msg, 0);
147 }
148 com.closeConnection();
149 } else {
150 com.requestConnection("process0", "process1", "", 0, 1);
151 {
152 std::vector<int> msg{1, 2, 3};
153 com.sendRange(msg, 0);
154 msg = com.receiveRange(0, asVector<int>);
155 BOOST_CHECK(msg == std::vector<int>({1, 2, 3}));
156 }
157 {
158 std::vector<double> msg{1.1, 2.2, 3.3};
159 com.sendRange(msg, 0);
160 msg = com.receiveRange(0, asVector<double>);
161 BOOST_CHECK(msg == std::vector<double>({1.1, 2.2, 3.3}));
162 }
163 com.closeConnection();
164 }
165}
166
167template <typename T>
169{
170 T communication;
171 int message = -1;
172
173 if (context.isNamed("A")) {
174 if (context.isPrimary()) {
175 communication.acceptConnection("A", "B", "", 0);
176
177 communication.send(10, 0);
178 communication.receive(message, 0);
179 BOOST_TEST(message == 20);
180
181 communication.send(20, 1);
182 communication.receive(message, 1);
183 BOOST_TEST(message == 40);
184
185 communication.closeConnection();
186 }
187 } else {
188 if (context.isPrimary()) {
189 communication.requestConnection("A", "B", "", 0, 2);
190
191 communication.receive(message, 0);
192 BOOST_TEST(message == 10);
193 message *= 2;
194 communication.send(message, 0);
195
196 communication.closeConnection();
197 } else {
198 communication.requestConnection("A", "B", "", 1, 2);
199
200 communication.receive(message, 0);
201 BOOST_TEST(message == 20);
202 message *= 2;
203 communication.send(message, 0);
204
205 communication.closeConnection();
206 }
207 }
208}
209
210template <typename T>
212{
213 T com;
214
215 if (context.isNamed("A")) {
216 com.acceptConnection("process0", "process1", "", 0);
217 {
218 double msg = 0.0;
219 com.broadcast(msg);
220 }
221 {
222 int msg = 1;
223 com.broadcast(msg);
224 }
225 {
226 bool msg = true;
227 com.broadcast(msg);
228 }
229 com.closeConnection();
230 } else {
231 com.requestConnection("process0", "process1", "", 0, 1);
232 {
233 double msg = 1.0;
234 com.broadcast(msg, 0);
235 BOOST_TEST(msg == 0.0);
236 }
237 {
238 int msg = 0;
239 com.broadcast(msg, 0);
240 BOOST_TEST(msg == 1);
241 }
242 {
243 bool msg = false;
244 com.broadcast(msg, 0);
245 BOOST_TEST(msg == true);
246 }
247 com.closeConnection();
248 }
249}
250
251template <typename T>
252void TestBroadcastEigen(TestContext const &context)
253{
254 T com;
255
256 if (context.isNamed("A")) {
257 com.acceptConnection("process0", "process1", "", 0);
258 {
259 Eigen::Vector3d msg = Eigen::Vector3d::Constant(3.1415);
260 com.broadcast(msg);
261 }
262 {
263 Eigen::Vector4i msg = Eigen::Vector4i::Constant(21);
264 com.broadcast(msg);
265 }
266 com.closeConnection();
267 } else {
268 com.requestConnection("process0", "process1", "", 0, 1);
269 {
270 Eigen::Vector3d msg = Eigen::Vector3d::Constant(0);
271 com.broadcast(msg, 0);
272 BOOST_CHECK(testing::equals(msg, Eigen::Vector3d::Constant(3.1415)));
273 }
274 {
275 Eigen::Vector4i msg = Eigen::Vector4i::Constant(0);
276 com.broadcast(msg, 0);
277 BOOST_CHECK(testing::equals(msg, Eigen::Vector4i::Constant(21)));
278 }
279 com.closeConnection();
280 }
281}
282
283template <typename T>
285{
286 T com;
287 if (context.isNamed("A")) {
288 com.acceptConnection("process0", "process1", "", 0);
289 {
290 std::vector<int> msg{2, 3, 5, 8};
291 com.broadcast(msg);
292 }
293 {
294 std::vector<double> msg{1.2, 2.3, 3.5, 4.8};
295 com.broadcast(msg);
296 }
297 com.closeConnection();
298 } else {
299 com.requestConnection("process0", "process1", "", 0, 1);
300 {
301 std::vector<int> msg(4);
302 com.broadcast(msg, 0);
303 BOOST_CHECK(msg == std::vector<int>({2, 3, 5, 8}));
304 }
305 {
306 std::vector<double> msg(4);
307 com.broadcast(msg, 0);
308 BOOST_CHECK(msg == std::vector<double>({1.2, 2.3, 3.5, 4.8}));
309 }
310 com.closeConnection();
311 }
312}
313
314template <typename T>
316{
317 T com;
318
319 if (context.isNamed("A")) {
320 com.acceptConnection("process0", "process1", "", 0);
321 {
322 int msg = 1;
323 int rcv = 0;
324 com.reduceSum(msg, rcv);
325 BOOST_TEST(msg == 1);
326 BOOST_TEST(rcv == 4);
327 }
328 {
329 int msg = 1;
330 int rcv = 0;
331 com.allreduceSum(msg, rcv);
332 BOOST_TEST(msg == 1);
333 BOOST_TEST(rcv == 4);
334 }
335 {
336 double msg = 3;
337 double rcv = 0;
338 com.allreduceSum(msg, rcv);
339 BOOST_TEST(msg == 3);
340 BOOST_TEST(rcv == 3.1415);
341 }
342
343 com.closeConnection();
344 } else {
345 com.requestConnection("process0", "process1", "", 0, 1);
346 {
347 int msg = 3;
348 int rcv = 0;
349 com.reduceSum(msg, rcv, 0);
350 BOOST_TEST(msg == 3);
351 BOOST_TEST(rcv == 0);
352 }
353 {
354 int msg = 3;
355 int rcv = 0;
356 com.allreduceSum(msg, rcv, 0);
357 BOOST_TEST(msg == 3);
358 BOOST_TEST(rcv == 4);
359 }
360 {
361 double msg = 0.1415;
362 double rcv = 0;
363 com.allreduceSum(msg, rcv, 0);
364 BOOST_TEST(msg == 0.1415);
365 BOOST_TEST(rcv == 3.1415);
366 }
367 com.closeConnection();
368 }
369}
370
371template <typename T>
372void TestReduceVectors(TestContext const &context)
373{
374 T com;
375
376 if (context.isNamed("A")) {
377 com.acceptConnection("process0", "process1", "", 0);
378 {
379 std::vector<double> msg{0.1, 0.2, 0.3};
380 std::vector<double> rcv{0, 0, 0};
381 com.reduceSum(msg, rcv);
382 std::vector<double> msg_expected{0.1, 0.2, 0.3};
383 BOOST_CHECK_EQUAL_COLLECTIONS(msg.begin(), msg.end(),
384 msg_expected.begin(), msg_expected.end());
385 std::vector<double> rcv_expected{1.1, 2.2, 3.3};
386 BOOST_CHECK_EQUAL_COLLECTIONS(rcv.begin(), rcv.end(),
387 rcv_expected.begin(), rcv_expected.end());
388 }
389 {
390 std::vector<double> msg{0.1, 0.2, 0.3};
391 std::vector<double> rcv{0, 0, 0};
392 com.allreduceSum(msg, rcv);
393 std::vector<double> msg_expected{0.1, 0.2, 0.3};
394 BOOST_CHECK_EQUAL_COLLECTIONS(msg.begin(), msg.end(),
395 msg_expected.begin(), msg_expected.end());
396 std::vector<double> rcv_expected{1.1, 2.2, 3.3};
397 BOOST_CHECK_EQUAL_COLLECTIONS(rcv.begin(), rcv.end(),
398 rcv_expected.begin(), rcv_expected.end());
399 }
400 com.closeConnection();
401 } else {
402 com.requestConnection("process0", "process1", "", 0, 1);
403 {
404 std::vector<double> msg{1, 2, 3};
405 std::vector<double> rcv{0, 0, 0};
406 com.reduceSum(msg, rcv, 0);
407 std::vector<double> msg_expected{1, 2, 3};
408 BOOST_CHECK_EQUAL_COLLECTIONS(msg.begin(), msg.end(),
409 msg_expected.begin(), msg_expected.end());
410 std::vector<double> rcv_expected{0, 0, 0};
411 BOOST_CHECK_EQUAL_COLLECTIONS(rcv.begin(), rcv.end(),
412 rcv_expected.begin(), rcv_expected.end());
413 }
414 {
415 std::vector<double> msg{1, 2, 3};
416 std::vector<double> rcv{0, 0, 0};
417 com.allreduceSum(msg, rcv, 0);
418 std::vector<double> msg_expected{1, 2, 3};
419 BOOST_CHECK_EQUAL_COLLECTIONS(msg.begin(), msg.end(),
420 msg_expected.begin(), msg_expected.end());
421 std::vector<double> rcv_expected{1.1, 2.2, 3.3};
422 BOOST_CHECK_EQUAL_COLLECTIONS(rcv.begin(), rcv.end(),
423 rcv_expected.begin(), rcv_expected.end());
424 }
425 com.closeConnection();
426 }
427}
428
429} // namespace primaryprimary
430
431namespace intracomm {
432
437
438template <typename T>
440{
441 T com;
442
443 if (context.isPrimary()) {
444 com.acceptConnection("Primary", "Secondary", "", 0, 1);
445 {
446 std::string msg("testOne");
447 com.send(msg, 1);
448 com.receive(msg, 1);
449 BOOST_TEST(msg == std::string("testTwo"));
450 }
451 {
452 double msg = 0.0;
453 com.send(msg, 1);
454 com.receive(msg, 1);
455 BOOST_TEST(msg == 1.0);
456 }
457 {
458 int msg = 1;
459 com.send(msg, 1);
460 com.receive(msg, 1);
461 BOOST_TEST(msg == 2);
462 }
463 {
464 bool msg = true;
465 com.send(msg, 1);
466 com.receive(msg, 1);
467 BOOST_TEST(msg == false);
468 }
469 com.closeConnection();
470 } else {
471 com.requestConnection("Primary", "Secondary", "", 0, 1);
472 {
473 std::string msg;
474 com.receive(msg, 0);
475 BOOST_TEST(msg == std::string("testOne"));
476 msg = "testTwo";
477 com.send(msg, 0);
478 }
479 {
480 double msg = 1.0;
481 com.receive(msg, 0);
482 BOOST_TEST(msg == 0.0);
483 msg = 1.0;
484 com.send(msg, 0);
485 }
486 {
487 int msg = 0;
488 com.receive(msg, 0);
489 BOOST_TEST(msg == 1);
490 msg = 2;
491 com.send(msg, 0);
492 }
493 {
494 bool msg = false;
495 com.receive(msg, 0);
496 BOOST_TEST(msg == true);
497 msg = false;
498 com.send(msg, 0);
499 }
500 com.closeConnection();
501 }
502}
503
504template <typename T>
506{
507 T com;
508
509 if (context.isPrimary()) {
510 com.acceptConnection("Primary", "Secondary", "", 0, 1);
511 {
512 Eigen::Vector3d msg = Eigen::Vector3d::Constant(0);
513 com.receive(msg, 1);
514 BOOST_CHECK(testing::equals(msg, Eigen::Vector3d::Constant(1)));
515 msg = Eigen::Vector3d::Constant(2);
516 com.send(msg, 1);
517 }
518 {
519 Eigen::Vector4i msg = Eigen::Vector4i::Constant(0);
520 com.receive(msg, 1);
521 BOOST_CHECK(testing::equals(msg, Eigen::Vector4i::Constant(1)));
522 msg = Eigen::Vector4i::Constant(0);
523 com.send(msg, 1);
524 }
525 com.closeConnection();
526 } else {
527 com.requestConnection("Primary", "Secondary", "", 0, 1);
528 {
529 Eigen::Vector3d msg = Eigen::Vector3d::Constant(1);
530 com.send(msg, 0);
531 com.receive(msg, 0);
532 BOOST_CHECK(testing::equals(msg, Eigen::Vector3d::Constant(2)));
533 }
534 {
535 Eigen::Vector4i msg = Eigen::Vector4i::Constant(1);
536 com.send(msg, 0);
537 com.receive(msg, 0);
538 BOOST_CHECK(testing::equals(msg, Eigen::Vector4i::Zero()));
539 }
540 com.closeConnection();
541 }
542}
543
544template <typename T>
546{
547 T com;
549
550 if (context.isPrimary()) {
551 com.acceptConnection("Primary", "Secondary", "", 0, 1);
552 {
553 std::vector<int> recv{1, 2, 3};
554 std::vector<int> msg = com.receiveRange(1, asVector<int>);
555 BOOST_TEST(msg == recv);
556 com.sendRange(msg, 1);
557 }
558 {
559 std::vector<double> msg = com.receiveRange(1, asVector<double>);
560 BOOST_TEST(msg == std::vector<double>({1.1, 2.2, 3.3}));
561 com.sendRange(msg, 1);
562 }
563 com.closeConnection();
564 } else {
565 com.requestConnection("Primary", "Secondary", "", 0, 1);
566 {
567 std::vector<int> msg{1, 2, 3};
568 com.sendRange(msg, 0);
569 msg = com.receiveRange(0, asVector<int>);
570 BOOST_CHECK(msg == std::vector<int>({1, 2, 3}));
571 }
572 {
573 std::vector<double> msg{1.1, 2.2, 3.3};
574 com.sendRange(msg, 0);
575 msg = com.receiveRange(0, asVector<double>);
576 BOOST_CHECK(msg == std::vector<double>({1.1, 2.2, 3.3}));
577 }
578 com.closeConnection();
579 }
580}
581
582template <typename T>
584{
585 T com;
586
587 if (context.isPrimary()) {
588 com.acceptConnection("Primary", "Secondary", "", 0, 1);
589 {
590 double msg = 0.0;
591 com.broadcast(msg);
592 }
593 {
594 int msg = 1;
595 com.broadcast(msg);
596 }
597 {
598 bool msg = true;
599 com.broadcast(msg);
600 }
601 com.closeConnection();
602 } else {
603 com.requestConnection("Primary", "Secondary", "", 0, 1);
604 {
605 double msg = 1.0;
606 com.broadcast(msg, 0);
607 BOOST_TEST(msg == 0.0);
608 }
609 {
610 int msg = 0;
611 com.broadcast(msg, 0);
612 BOOST_TEST(msg == 1);
613 }
614 {
615 bool msg = false;
616 com.broadcast(msg, 0);
617 BOOST_TEST(msg == true);
618 }
619 com.closeConnection();
620 }
621}
622
623template <typename T>
625{
626 T com;
627
628 if (context.isPrimary()) {
629 com.acceptConnection("Primary", "Secondary", "", 0, 1);
630 {
631 Eigen::Vector3d msg = Eigen::Vector3d::Constant(3.1415);
632 com.broadcast(msg);
633 }
634 {
635 Eigen::Vector4i msg = Eigen::Vector4i::Constant(21);
636 com.broadcast(msg);
637 }
638 {
639 std::vector<int> msg{2, 3, 5, 8};
640 com.broadcast(msg);
641 }
642 {
643 std::vector<double> msg{1.2, 2.3, 3.5, 4.8};
644 com.broadcast(msg);
645 }
646 com.closeConnection();
647 } else {
648 com.requestConnection("Primary", "Secondary", "", 0, 1);
649 {
650 Eigen::Vector3d msg = Eigen::Vector3d::Constant(0);
651 com.broadcast(msg, 0);
652 BOOST_CHECK(testing::equals(msg, Eigen::Vector3d::Constant(3.1415)));
653 }
654 {
655 Eigen::Vector4i msg = Eigen::Vector4i::Constant(0);
656 com.broadcast(msg, 0);
657 BOOST_CHECK(testing::equals(msg, Eigen::Vector4i::Constant(21)));
658 }
659 {
660 std::vector<int> msg(4);
661 com.broadcast(msg, 0);
662 BOOST_CHECK(msg == std::vector<int>({2, 3, 5, 8}));
663 }
664 {
665 std::vector<double> msg(4);
666 com.broadcast(msg, 0);
667 BOOST_CHECK(msg == std::vector<double>({1.2, 2.3, 3.5, 4.8}));
668 }
669 com.closeConnection();
670 }
671}
672
673template <typename T>
675{
676 T com;
677
678 if (context.isPrimary()) {
679 com.acceptConnection("Primary", "Secondary", "", 0, 1);
680 {
681 int msg = 1;
682 int rcv = 0;
683 com.reduceSum(msg, rcv);
684 BOOST_TEST(msg == 1);
685 BOOST_TEST(rcv == 4);
686 }
687 {
688 int msg = 1;
689 int rcv = 0;
690 com.allreduceSum(msg, rcv);
691 BOOST_TEST(msg == 1);
692 BOOST_TEST(rcv == 4);
693 }
694 {
695 double msg = 3;
696 double rcv = 0;
697 com.allreduceSum(msg, rcv);
698 BOOST_TEST(msg == 3);
699 BOOST_TEST(rcv == 3.1415);
700 }
701
702 com.closeConnection();
703 } else {
704 com.requestConnection("Primary", "Secondary", "", 0, 1);
705 {
706 int msg = 3;
707 int rcv = 0;
708 com.reduceSum(msg, rcv, 0);
709 BOOST_TEST(msg == 3);
710 BOOST_TEST(rcv == 0);
711 }
712 {
713 int msg = 3;
714 int rcv = 0;
715 com.allreduceSum(msg, rcv, 0);
716 BOOST_TEST(msg == 3);
717 BOOST_TEST(rcv == 4);
718 }
719 {
720 double msg = 0.1415;
721 double rcv = 0;
722 com.allreduceSum(msg, rcv, 0);
723 BOOST_TEST(msg == 0.1415);
724 BOOST_TEST(rcv == 3.1415);
725 }
726 com.closeConnection();
727 }
728}
729
730template <typename T>
731void TestReduceVectors(TestContext const &context)
732{
733 T com;
734
735 if (context.isPrimary()) {
736 com.acceptConnection("Primary", "Secondary", "", 0, 1);
737 {
738 std::vector<double> msg{0.1, 0.2, 0.3};
739 std::vector<double> rcv{0, 0, 0};
740 com.reduceSum(msg, rcv);
741 std::vector<double> msg_expected{0.1, 0.2, 0.3};
742 BOOST_CHECK_EQUAL_COLLECTIONS(msg.begin(), msg.end(),
743 msg_expected.begin(), msg_expected.end());
744 std::vector<double> rcv_expected{1.1, 2.2, 3.3};
745 BOOST_CHECK_EQUAL_COLLECTIONS(rcv.begin(), rcv.end(),
746 rcv_expected.begin(), rcv_expected.end());
747 }
748 {
749 std::vector<double> msg{0.1, 0.2, 0.3};
750 std::vector<double> rcv{0, 0, 0};
751 com.allreduceSum(msg, rcv);
752 std::vector<double> msg_expected{0.1, 0.2, 0.3};
753 BOOST_CHECK_EQUAL_COLLECTIONS(msg.begin(), msg.end(),
754 msg_expected.begin(), msg_expected.end());
755 std::vector<double> rcv_expected{1.1, 2.2, 3.3};
756 BOOST_CHECK_EQUAL_COLLECTIONS(rcv.begin(), rcv.end(),
757 rcv_expected.begin(), rcv_expected.end());
758 }
759 com.closeConnection();
760 } else {
761 com.requestConnection("Primary", "Secondary", "", 0, 1);
762 {
763 std::vector<double> msg{1, 2, 3};
764 std::vector<double> rcv{0, 0, 0};
765 com.reduceSum(msg, rcv, 0);
766 std::vector<double> msg_expected{1, 2, 3};
767 BOOST_CHECK_EQUAL_COLLECTIONS(msg.begin(), msg.end(),
768 msg_expected.begin(), msg_expected.end());
769 std::vector<double> rcv_expected{0, 0, 0};
770 BOOST_CHECK_EQUAL_COLLECTIONS(rcv.begin(), rcv.end(),
771 rcv_expected.begin(), rcv_expected.end());
772 }
773 {
774 std::vector<double> msg{1, 2, 3};
775 std::vector<double> rcv{0, 0, 0};
776 com.allreduceSum(msg, rcv, 0);
777 std::vector<double> msg_expected{1, 2, 3};
778 BOOST_CHECK_EQUAL_COLLECTIONS(msg.begin(), msg.end(),
779 msg_expected.begin(), msg_expected.end());
780 std::vector<double> rcv_expected{1.1, 2.2, 3.3};
781 BOOST_CHECK_EQUAL_COLLECTIONS(rcv.begin(), rcv.end(),
782 rcv_expected.begin(), rcv_expected.end());
783 }
784 com.closeConnection();
785 }
786}
787
788} // namespace intracomm
789
790namespace serverclient {
791
797
800template <typename T>
802{
803 T communication;
804 int message = 1;
805 BOOST_REQUIRE(context.hasSize(1));
806
807 if (context.isNamed("A")) {
808 communication.acceptConnectionAsServer("A", "B", "", 0, 1);
809 communication.send(message, 0);
810 communication.receive(message, 0);
811 BOOST_TEST(message == 2);
812 communication.closeConnection();
813 } else {
814 BOOST_REQUIRE(context.isNamed("B"));
815 communication.requestConnectionAsClient("A", "B", "", {0}, 0);
816 communication.receive(message, 0);
817 BOOST_TEST(message == 1);
818 message = 2;
819 communication.send(message, 0);
820 communication.closeConnection();
821 }
822}
823
824template <typename T>
826{
827 T communication;
828 int message = -1;
829 BOOST_REQUIRE(context.hasSize(2));
830
831 if (context.isNamed("A")) {
832 if (context.isPrimary()) {
833 communication.acceptConnectionAsServer("A", "B", "", context.rank, 2);
834
835 communication.send(10, 0);
836 communication.receive(message, 0);
837 BOOST_TEST(message == 20);
838
839 communication.send(20, 1);
840 communication.receive(message, 1);
841 BOOST_TEST(message == 40);
842
843 communication.closeConnection();
844 } else {
845 communication.acceptConnectionAsServer("A", "B", "", context.rank, 0);
846 communication.closeConnection();
847 }
848 } else {
849 BOOST_REQUIRE(context.isNamed("B"));
850 if (context.isPrimary()) {
851 communication.requestConnectionAsClient("A", "B", "", {0}, context.rank);
852
853 communication.receive(message, 0);
854 BOOST_TEST(message == 10);
855 message *= 2;
856 communication.send(message, 0);
857
858 communication.closeConnection();
859 } else {
860 communication.requestConnectionAsClient("A", "B", "", {0}, context.rank);
861
862 communication.receive(message, 0);
863 BOOST_TEST(message == 20);
864 message *= 2;
865 communication.send(message, 0);
866
867 communication.closeConnection();
868 }
869 }
870}
871
872template <typename T>
874{
875 T communication;
876 int message = -1;
877
878 BOOST_REQUIRE(context.hasSize(2));
879
880 if (context.isNamed("A")) {
881 if (context.isPrimary()) {
882
883 communication.acceptConnectionAsServer("A", "B", "", 0, 2);
884
885 communication.send(10, 0);
886 communication.receive(message, 0);
887 BOOST_TEST(message == 20);
888
889 communication.send(100, 1);
890 communication.receive(message, 1);
891 BOOST_TEST(message == 200);
892
893 communication.closeConnection();
894 } else {
895 communication.acceptConnectionAsServer("A", "B", "", 1, 2);
896
897 communication.send(20, 0);
898 communication.receive(message, 0);
899 BOOST_TEST(message == 40);
900
901 communication.send(200, 1);
902 communication.receive(message, 1);
903 BOOST_TEST(message == 400);
904
905 communication.closeConnection();
906 }
907
908 } else {
909 BOOST_REQUIRE(context.isNamed("B"));
910
911 if (context.isPrimary()) {
912 communication.requestConnectionAsClient("A", "B", "", {0, 1}, 0);
913
914 communication.receive(message, 0);
915 BOOST_TEST(message == 10);
916 communication.send(20, 0);
917
918 communication.receive(message, 1);
919 BOOST_TEST(message == 20);
920 communication.send(40, 1);
921
922 communication.closeConnection();
923 } else {
924 communication.requestConnectionAsClient("A", "B", "", {0, 1}, 1);
925
926 communication.receive(message, 0);
927 BOOST_TEST(message == 100);
928 communication.send(200, 0);
929
930 communication.receive(message, 1);
931 BOOST_TEST(message == 200);
932 communication.send(400, 1);
933
934 communication.closeConnection();
935 }
936 }
937}
938
939} // namespace serverclient
940
941} // namespace precice::testing::com
T begin(T... args)
bool isNamed(const std::string &name) const
Check whether this context has a given name.
bool hasSize(int size) const
Check whether this context has a given size.
Rank rank
the rank of the current participant
T end(T... args)
constexpr auto asVector
Allows to use Communication::AsVectorTag in a less verbose way.
void TestSendAndReceiveEigen(TestContext const &context)
void TestReducePrimitiveTypes(TestContext const &context)
void TestSendAndReceiveRanges(TestContext const &context)
void TestBroadcastVectors(TestContext const &context)
void TestBroadcastPrimitiveTypes(TestContext const &context)
void TestSendAndReceivePrimitiveTypes(TestContext const &context)
void TestReduceVectors(TestContext const &context)
void TestSendAndReceiveRanges(TestContext const &context)
void TestSendReceiveFourProcesses(TestContext const &context)
void TestReducePrimitiveTypes(TestContext const &context)
void TestBroadcastVectors(TestContext const &context)
void TestSendAndReceiveEigen(TestContext const &context)
void TestReduceVectors(TestContext const &context)
void TestBroadcastEigen(TestContext const &context)
void TestBroadcastPrimitiveTypes(TestContext const &context)
void TestSendAndReceivePrimitiveTypes(TestContext const &context)
void TestSendReceiveTwoProcessesServerClient(TestContext const &context)
void TestSendReceiveFourProcessesServerClientV2(TestContext const &context)
void TestSendReceiveFourProcessesServerClient(TestContext const &context)
boost::test_tools::predicate_result equals(const std::vector< float > &VectorA, const std::vector< float > &VectorB, float tolerance)
equals to be used in tests. Compares two std::vectors using a given tolerance. Prints both operands o...
Definition Testing.cpp:93