blob: 54c7d458b3d62cc77c6b0db633989d5b76bed788 [file] [log] [blame]
BerengerBerthoul8aeb7982020-10-29 14:49:02 +01001#include <doctest/extensions/doctest_mpi.h>
2
3int f_for_test(int rank);
4
5int f_for_test(int rank) {
6 if (rank == 0) {
7 return 10;
8 }
9 else if (rank == 1) {
10 return 11;
11 }
12 return 0;
13}
14
15
16
17MPI_TEST_CASE("Parallel test on 2 processes",2) { // if MPI_SIZE < 2, report test can't be run
18 // 3 objects accessible in the test:
19 // test_comm: MPI_Comm of size 2
20 // test_rank: integer of value the rank of the process in test_comm
21 // test_nb_procs: integer of value the size of the process (here: 2)
22
23 int x = f_for_test(test_rank);
24
25 MPI_CHECK( 0, x==10 ); // CHECK for rank 0, that x==10
26 MPI_CHECK( 1, x==11 ); // CHECK for rank 1, that x==11
27 //MPI_CHECK( 2, x==0 ); // will trigger a static assert because non-existing rank
28}
29
30MPI_TEST_CASE("Parallel test on 3 processes (failing)",3) {
31 int x = f_for_test(test_rank);
32
33 MPI_CHECK( 0, x==10 ); // CHECK for rank 0, that x==10
34 MPI_CHECK( 1, x==11 ); // CHECK for rank 1, that x==11
35 MPI_CHECK( 2, x==-1 ); // CHECK for rank 2, that x==-1 (which is not the case -> will trigger a failure report)
36}
BerengerBerthoul90ba0a92022-02-08 16:36:32 +010037
38MPI_TEST_CASE("Parallel tests with subcases",2) {
39
40 SUBCASE("sub_case 0") {
41 CHECK( test_nb_procs == 2 );
42 }
43 SUBCASE("sub_case 1") {
44 CHECK( test_rank == 0 ); // should fail on proc 1
45 }
46}