• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright (C) 2013 Alain Miniussi <alain.miniussi@oca.eu>
2 
3 // Use, modification and distribution is subject to the Boost Software
4 // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
5 // http://www.boost.org/LICENSE_1_0.txt)
6 
7 // test threading::level operations
8 
9 #include <boost/mpi/environment.hpp>
10 #include <iostream>
11 #include <sstream>
12 
13 #define BOOST_TEST_MODULE mpi_level_test
14 #include <boost/test/included/unit_test.hpp>
15 
16 namespace mpi = boost::mpi;
17 
18 void
test_threading_level_io(mpi::threading::level orig)19 test_threading_level_io(mpi::threading::level orig) {
20   std::ostringstream out;
21   namespace mt = boost::mpi::threading;
22   mt::level printed = mt::level(-1);
23 
24   out << orig;
25   BOOST_CHECK(out.good());
26   std::string orig_str(out.str());
27   std::cout << "orig string:" << orig_str << '\n';
28   std::istringstream in(orig_str);
29   in >> printed;
30   BOOST_CHECK(!in.bad());
31   std::cout << "orig: " << orig << ", printed: " << printed << std::endl;
32   BOOST_CHECK(orig == printed);
33 }
34 
35 void
test_threading_levels_io()36 test_threading_levels_io() {
37   namespace mt = boost::mpi::threading;
38   test_threading_level_io(mt::single);
39   test_threading_level_io(mt::funneled);
40   test_threading_level_io(mt::serialized);
41   test_threading_level_io(mt::multiple);
42 }
43 
44 void
test_threading_level_cmp()45 test_threading_level_cmp() {
46   namespace mt = boost::mpi::threading;
47   BOOST_CHECK(mt::single == mt::single);
48   BOOST_CHECK(mt::funneled == mt::funneled);
49   BOOST_CHECK(mt::serialized == mt::serialized);
50   BOOST_CHECK(mt::multiple == mt::multiple);
51 
52   BOOST_CHECK(mt::single != mt::funneled);
53   BOOST_CHECK(mt::single != mt::serialized);
54   BOOST_CHECK(mt::single != mt::multiple);
55 
56   BOOST_CHECK(mt::funneled != mt::single);
57   BOOST_CHECK(mt::funneled != mt::serialized);
58   BOOST_CHECK(mt::funneled != mt::multiple);
59 
60   BOOST_CHECK(mt::serialized != mt::single);
61   BOOST_CHECK(mt::serialized != mt::funneled);
62   BOOST_CHECK(mt::serialized != mt::multiple);
63 
64   BOOST_CHECK(mt::multiple != mt::single);
65   BOOST_CHECK(mt::multiple != mt::funneled);
66   BOOST_CHECK(mt::multiple != mt::serialized);
67 
68   BOOST_CHECK(mt::single < mt::funneled);
69   BOOST_CHECK(mt::funneled > mt::single);
70   BOOST_CHECK(mt::single < mt::serialized);
71   BOOST_CHECK(mt::serialized > mt::single);
72   BOOST_CHECK(mt::single < mt::multiple);
73   BOOST_CHECK(mt::multiple > mt::single);
74 
75   BOOST_CHECK(mt::funneled < mt::serialized);
76   BOOST_CHECK(mt::serialized > mt::funneled);
77   BOOST_CHECK(mt::funneled < mt::multiple);
78   BOOST_CHECK(mt::multiple > mt::funneled);
79 
80   BOOST_CHECK(mt::serialized < mt::multiple);
81   BOOST_CHECK(mt::multiple > mt::serialized);
82 
83   BOOST_CHECK(mt::single <= mt::single);
84   BOOST_CHECK(mt::single <= mt::funneled);
85   BOOST_CHECK(mt::funneled >= mt::single);
86   BOOST_CHECK(mt::single <= mt::serialized);
87   BOOST_CHECK(mt::serialized >= mt::single);
88   BOOST_CHECK(mt::single <= mt::multiple);
89   BOOST_CHECK(mt::multiple >= mt::single);
90 
91   BOOST_CHECK(mt::funneled <= mt::funneled);
92   BOOST_CHECK(mt::funneled <= mt::serialized);
93   BOOST_CHECK(mt::serialized >= mt::funneled);
94   BOOST_CHECK(mt::funneled <= mt::multiple);
95   BOOST_CHECK(mt::multiple >= mt::funneled);
96 
97   BOOST_CHECK(mt::serialized <= mt::serialized);
98   BOOST_CHECK(mt::serialized <= mt::multiple);
99   BOOST_CHECK(mt::multiple >= mt::serialized);
100 
101   BOOST_CHECK(mt::multiple <= mt::multiple);
102 }
103 
BOOST_AUTO_TEST_CASE(mt_level)104 BOOST_AUTO_TEST_CASE(mt_level)
105 {
106   test_threading_levels_io();
107   test_threading_level_cmp();
108 }
109