Directory: | ./ |
---|---|
File: | tests/unit_tests.cpp |
Date: | 2022-06-30 06:29:57 |
Exec | Total | Coverage | |
---|---|---|---|
Lines: | 484 | 495 | 97.8% |
Branches: | 781 | 1964 | 39.8% |
Line | Branch | Exec | Source |
---|---|---|---|
1 | /** | ||
2 | * @file unit_tests.cpp | ||
3 | * @author Maximilien Naveau (maximilien.naveau@gmail.com) | ||
4 | * @license License BSD-3-Clause | ||
5 | * @copyright Copyright (c) 2019, New York University and Max Planck | ||
6 | * Gesellschaft. | ||
7 | * @date 2019-05-22 | ||
8 | * | ||
9 | * @brief Shared memroy API unittests. | ||
10 | */ | ||
11 | |||
12 | #include <unistd.h> | ||
13 | |||
14 | #include <cstdlib> | ||
15 | #include <sstream> | ||
16 | #include <thread> | ||
17 | |||
18 | #include "gtest/gtest.h" | ||
19 | #include "shared_memory/array.hpp" | ||
20 | #include "shared_memory/condition_variable.hpp" | ||
21 | #include "shared_memory/demos/four_int_values.hpp" | ||
22 | #include "shared_memory/demos/item.hpp" | ||
23 | #include "shared_memory/exchange_manager_consumer.hpp" | ||
24 | #include "shared_memory/exchange_manager_producer.hpp" | ||
25 | #include "shared_memory/lock.hpp" | ||
26 | #include "shared_memory/locked_condition_variable.hpp" | ||
27 | #include "shared_memory/mutex.hpp" | ||
28 | #include "shared_memory/shared_memory.hpp" | ||
29 | #include "shared_memory/tests/tests.h" | ||
30 | |||
31 | // set in the CMakeLists.txt file | ||
32 | // see tests/support/tests_executable.cpp | ||
33 |
1/2✓ Branch 2 taken 28 times.
✗ Branch 3 not taken.
|
28 | static std::string PATH_TO_EXECUTABLE = SHM_PATH_TO_SUPPORT_EXE; |
34 | |||
35 | static unsigned int TIME_SLEEP = 20000; // microseconds | ||
36 | |||
37 | 57 | static inline void clear_memory() | |
38 | { | ||
39 | // destroy the condition variables and mutex | ||
40 | { | ||
41 | // Locked condition variables | ||
42 |
1/2✓ Branch 2 taken 57 times.
✗ Branch 3 not taken.
|
114 | std::stringstream cond_var_name1; |
43 |
2/4✓ Branch 1 taken 57 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 57 times.
✗ Branch 5 not taken.
|
57 | cond_var_name1 << shared_memory_test::segment_id << "_" |
44 |
1/2✓ Branch 1 taken 57 times.
✗ Branch 2 not taken.
|
57 | << shared_memory_test::concurrent_1; |
45 |
1/2✓ Branch 2 taken 57 times.
✗ Branch 3 not taken.
|
114 | std::stringstream cond_var_name2; |
46 |
2/4✓ Branch 1 taken 57 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 57 times.
✗ Branch 5 not taken.
|
57 | cond_var_name2 << shared_memory_test::segment_id << "_" |
47 |
1/2✓ Branch 1 taken 57 times.
✗ Branch 2 not taken.
|
57 | << shared_memory_test::concurrent_2; |
48 |
1/2✓ Branch 1 taken 57 times.
✗ Branch 2 not taken.
|
114 | shared_memory::LockedConditionVariable cond_var1(cond_var_name1.str(), |
49 |
1/2✓ Branch 1 taken 57 times.
✗ Branch 2 not taken.
|
114 | true); |
50 |
1/2✓ Branch 1 taken 57 times.
✗ Branch 2 not taken.
|
114 | shared_memory::LockedConditionVariable cond_var2(cond_var_name2.str(), |
51 |
1/2✓ Branch 1 taken 57 times.
✗ Branch 2 not taken.
|
114 | true); |
52 | shared_memory::LockedConditionVariable cond_var( | ||
53 |
2/4✓ Branch 1 taken 57 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 57 times.
✗ Branch 5 not taken.
|
114 | shared_memory_test::segment_id, true); |
54 | |||
55 | // Mutex | ||
56 |
2/4✓ Branch 1 taken 57 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 57 times.
✗ Branch 5 not taken.
|
57 | shared_memory::Mutex::clean(shared_memory_test::segment_mutex_id); |
57 | |||
58 | // Condition variables | ||
59 | shared_memory::ConditionVariable condition( | ||
60 |
2/4✓ Branch 1 taken 57 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 57 times.
✗ Branch 5 not taken.
|
57 | shared_memory_test::segment_cv_id, true); |
61 | } | ||
62 | |||
63 | 57 | shared_memory::clear_shared_memory(shared_memory_test::segment_id); | |
64 | 57 | } | |
65 | |||
66 | 56 | class SharedMemoryTests : public ::testing::Test | |
67 | { | ||
68 | protected: | ||
69 | 28 | void SetUp() | |
70 | { | ||
71 | 28 | clear_memory(); | |
72 | 28 | shared_memory::set_verbose(false); | |
73 |
1/2✓ Branch 2 taken 28 times.
✗ Branch 3 not taken.
|
56 | shared_memory::get_segment_mutex(shared_memory_test::segment_id) |
74 | 28 | .unlock(); | |
75 | 28 | threads_.clear(); | |
76 | 28 | } | |
77 | |||
78 | 28 | void TearDown() | |
79 | { | ||
80 |
2/2✓ Branch 1 taken 14 times.
✓ Branch 2 taken 28 times.
|
42 | for (unsigned int i = 0; i < threads_.size(); ++i) |
81 | { | ||
82 |
1/2✓ Branch 2 taken 14 times.
✗ Branch 3 not taken.
|
14 | if (threads_[i].joinable()) |
83 | { | ||
84 | 14 | threads_[i].join(); | |
85 | } | ||
86 | } | ||
87 | 28 | threads_.clear(); | |
88 | 28 | clear_memory(); | |
89 | 28 | } | |
90 | |||
91 | 26 | static void _call_executable_blocking(int action) | |
92 | { | ||
93 |
1/2✓ Branch 2 taken 26 times.
✗ Branch 3 not taken.
|
52 | std::stringstream s; |
94 |
4/8✓ Branch 1 taken 26 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 26 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 26 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 26 times.
✗ Branch 11 not taken.
|
26 | s << PATH_TO_EXECUTABLE << " " << action << std::ends; |
95 |
2/4✓ Branch 1 taken 26 times.
✗ Branch 2 not taken.
✓ Branch 5 taken 26 times.
✗ Branch 6 not taken.
|
26 | int r = std::system(s.str().c_str()); |
96 | (void)(r); // avoiding compilation warning | ||
97 | 26 | } | |
98 | |||
99 | 14 | void _call_executable_non_blocking(int action) | |
100 | { | ||
101 |
1/2✓ Branch 1 taken 14 times.
✗ Branch 2 not taken.
|
14 | threads_.emplace_back( |
102 |
1/2✓ Branch 1 taken 14 times.
✗ Branch 2 not taken.
|
28 | std::thread(&SharedMemoryTests::_call_executable_blocking, action)); |
103 | 14 | } | |
104 | |||
105 | std::vector<std::thread> threads_; | ||
106 | }; | ||
107 | |||
108 | class DISABLED_SharedMemoryTests : public ::testing::Test | ||
109 | { | ||
110 | protected: | ||
111 | // Dummy methodes for compilation purposes | ||
112 | static void _call_executable_blocking(int) | ||
113 | { | ||
114 | } | ||
115 | void _call_executable_non_blocking(int) | ||
116 | { | ||
117 | } | ||
118 | }; | ||
119 | |||
120 |
3/6✓ Branch 8 taken 28 times.
✗ Branch 9 not taken.
✓ Branch 11 taken 28 times.
✗ Branch 12 not taken.
✓ Branch 14 taken 28 times.
✗ Branch 15 not taken.
|
32 | TEST_F(SharedMemoryTests, double_test) |
121 | { | ||
122 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | _call_executable_blocking(shared_memory_test::set_double); |
123 | |||
124 | double value; | ||
125 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | shared_memory::get( |
126 | shared_memory_test::segment_id, shared_memory_test::object_id, value); | ||
127 |
3/12✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 1 times.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✓ Branch 19 taken 1 times.
✗ Branch 20 not taken.
|
1 | ASSERT_EQ(value, shared_memory_test::test_double); |
128 | } | ||
129 | |||
130 |
3/6✓ Branch 8 taken 28 times.
✗ Branch 9 not taken.
✓ Branch 11 taken 28 times.
✗ Branch 12 not taken.
✓ Branch 14 taken 28 times.
✗ Branch 15 not taken.
|
32 | TEST_F(SharedMemoryTests, non_existing_segment_exception) |
131 | { | ||
132 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | clear_memory(); |
133 | 1 | bool thrown = false; | |
134 | double value; | ||
135 | try | ||
136 | { | ||
137 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | shared_memory::get<double>(shared_memory_test::segment_id, |
138 | shared_memory_test::object_id, | ||
139 | value, | ||
140 | false); | ||
141 | } | ||
142 | 2 | catch (const shared_memory::Non_existing_segment_exception &) | |
143 | { | ||
144 | 1 | thrown = true; | |
145 | } | ||
146 |
3/14✗ Branch 2 not taken.
✓ Branch 3 taken 1 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✓ Branch 21 taken 1 times.
✗ Branch 22 not taken.
✗ Branch 23 not taken.
✓ Branch 24 taken 1 times.
|
1 | ASSERT_TRUE(thrown); |
147 | } | ||
148 | |||
149 |
3/6✓ Branch 8 taken 28 times.
✗ Branch 9 not taken.
✓ Branch 11 taken 28 times.
✗ Branch 12 not taken.
✓ Branch 14 taken 28 times.
✗ Branch 15 not taken.
|
32 | TEST_F(SharedMemoryTests, int_test) |
150 | { | ||
151 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | _call_executable_blocking(shared_memory_test::set_int); |
152 | |||
153 | int value; | ||
154 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | shared_memory::get( |
155 | shared_memory_test::segment_id, shared_memory_test::object_id, value); | ||
156 |
3/12✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 1 times.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✓ Branch 19 taken 1 times.
✗ Branch 20 not taken.
|
1 | ASSERT_EQ(value, shared_memory_test::test_int); |
157 | } | ||
158 | |||
159 |
3/6✓ Branch 8 taken 28 times.
✗ Branch 9 not taken.
✓ Branch 11 taken 28 times.
✗ Branch 12 not taken.
✓ Branch 14 taken 28 times.
✗ Branch 15 not taken.
|
32 | TEST_F(SharedMemoryTests, test_float) |
160 | { | ||
161 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | _call_executable_blocking(shared_memory_test::set_float); |
162 | |||
163 | float value; | ||
164 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | shared_memory::get( |
165 | shared_memory_test::segment_id, shared_memory_test::object_id, value); | ||
166 |
3/12✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 1 times.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✓ Branch 19 taken 1 times.
✗ Branch 20 not taken.
|
1 | ASSERT_EQ(value, shared_memory_test::test_float); |
167 | } | ||
168 | |||
169 |
3/6✓ Branch 8 taken 28 times.
✗ Branch 9 not taken.
✓ Branch 11 taken 28 times.
✗ Branch 12 not taken.
✓ Branch 14 taken 28 times.
✗ Branch 15 not taken.
|
32 | TEST_F(SharedMemoryTests, test_string) |
170 | { | ||
171 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | _call_executable_blocking(shared_memory_test::set_string); |
172 | |||
173 | 2 | std::string str; | |
174 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | shared_memory::get( |
175 | shared_memory_test::segment_id, shared_memory_test::object_id, str); | ||
176 |
4/14✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 1 times.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✓ Branch 19 taken 1 times.
✗ Branch 20 not taken.
✓ Branch 22 taken 1 times.
✗ Branch 23 not taken.
|
1 | ASSERT_EQ(str, shared_memory_test::test_string); |
177 | } | ||
178 | |||
179 |
3/6✓ Branch 8 taken 28 times.
✗ Branch 9 not taken.
✓ Branch 11 taken 28 times.
✗ Branch 12 not taken.
✓ Branch 14 taken 28 times.
✗ Branch 15 not taken.
|
32 | TEST_F(SharedMemoryTests, test_array) |
180 | { | ||
181 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | _call_executable_blocking(shared_memory_test::set_double_array); |
182 | |||
183 | double a[shared_memory_test::test_array_size]; | ||
184 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | shared_memory::get(shared_memory_test::segment_id, |
185 | shared_memory_test::object_id, | ||
186 | a, | ||
187 | std::size_t{shared_memory_test::test_array_size}); | ||
188 | |||
189 |
2/2✓ Branch 0 taken 4 times.
✓ Branch 1 taken 1 times.
|
5 | for (unsigned int i = 0; i < shared_memory_test::test_array_size; i++) |
190 | { | ||
191 |
3/12✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 4 times.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✓ Branch 19 taken 4 times.
✗ Branch 20 not taken.
|
4 | ASSERT_EQ(a[i], shared_memory_test::test_array[i]); |
192 | } | ||
193 | } | ||
194 | |||
195 |
3/6✓ Branch 8 taken 28 times.
✗ Branch 9 not taken.
✓ Branch 11 taken 28 times.
✗ Branch 12 not taken.
✓ Branch 14 taken 28 times.
✗ Branch 15 not taken.
|
32 | TEST_F(SharedMemoryTests, test_vector) |
196 | { | ||
197 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | _call_executable_blocking(shared_memory_test::set_vector); |
198 | |||
199 |
1/2✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
|
2 | std::vector<double> v(shared_memory_test::test_array_size); |
200 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | shared_memory::get( |
201 | shared_memory_test::segment_id, shared_memory_test::object_id, v); | ||
202 | |||
203 |
3/12✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✗ Branch 5 not taken.
✓ Branch 6 taken 1 times.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✓ Branch 20 taken 1 times.
✗ Branch 21 not taken.
|
1 | ASSERT_EQ(v.size(), shared_memory_test::test_array_size); |
204 |
3/4✓ Branch 0 taken 4 times.
✓ Branch 1 taken 1 times.
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
|
5 | for (unsigned int i = 0; i < shared_memory_test::test_array_size; i++) |
205 | { | ||
206 |
3/12✓ Branch 2 taken 4 times.
✗ Branch 3 not taken.
✗ Branch 5 not taken.
✓ Branch 6 taken 4 times.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✓ Branch 20 taken 4 times.
✗ Branch 21 not taken.
|
4 | ASSERT_EQ(v[i], shared_memory_test::test_array[i]); |
207 | } | ||
208 | } | ||
209 | |||
210 |
3/6✓ Branch 8 taken 28 times.
✗ Branch 9 not taken.
✓ Branch 11 taken 28 times.
✗ Branch 12 not taken.
✓ Branch 14 taken 28 times.
✗ Branch 15 not taken.
|
32 | TEST_F(SharedMemoryTests, test_eigen_vector) |
211 | { | ||
212 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | _call_executable_blocking(shared_memory_test::set_vector); |
213 | |||
214 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
2 | Eigen::VectorXd v(shared_memory_test::test_array_size); |
215 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | shared_memory::get( |
216 | shared_memory_test::segment_id, shared_memory_test::object_id, v); | ||
217 | |||
218 |
4/14✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✗ Branch 7 not taken.
✓ Branch 8 taken 1 times.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
✓ Branch 22 taken 1 times.
✗ Branch 23 not taken.
|
1 | ASSERT_EQ(v.size(), shared_memory_test::test_array_size); |
219 |
3/4✓ Branch 0 taken 4 times.
✓ Branch 1 taken 1 times.
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
|
5 | for (unsigned int i = 0; i < shared_memory_test::test_array_size; i++) |
220 | { | ||
221 |
4/14✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 4 times.
✗ Branch 5 not taken.
✗ Branch 7 not taken.
✓ Branch 8 taken 4 times.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
✓ Branch 22 taken 4 times.
✗ Branch 23 not taken.
|
4 | ASSERT_EQ(v(i), shared_memory_test::test_array[i]); |
222 | } | ||
223 | } | ||
224 | |||
225 |
3/6✓ Branch 8 taken 28 times.
✗ Branch 9 not taken.
✓ Branch 11 taken 28 times.
✗ Branch 12 not taken.
✓ Branch 14 taken 28 times.
✗ Branch 15 not taken.
|
32 | TEST_F(SharedMemoryTests, test_int_double_map) |
226 | { | ||
227 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | _call_executable_blocking(shared_memory_test::set_int_double_map); |
228 | |||
229 | 2 | std::map<int, double> m; | |
230 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | m[shared_memory_test::map_int_keys1] = 0.0; |
231 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | m[shared_memory_test::map_int_keys2] = 0.0; |
232 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | shared_memory::get( |
233 | shared_memory_test::segment_id, shared_memory_test::object_id, m); | ||
234 | |||
235 |
3/12✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✗ Branch 5 not taken.
✓ Branch 6 taken 1 times.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✓ Branch 20 taken 1 times.
✗ Branch 21 not taken.
|
1 | ASSERT_EQ(m.size(), shared_memory_test::test_map_size); |
236 |
4/14✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✗ Branch 7 not taken.
✓ Branch 8 taken 1 times.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
✓ Branch 22 taken 1 times.
✗ Branch 23 not taken.
|
1 | ASSERT_EQ(m[shared_memory_test::map_int_keys1], |
237 | 1 | shared_memory_test::map_value_1); | |
238 |
4/14✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✗ Branch 7 not taken.
✓ Branch 8 taken 1 times.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
✓ Branch 22 taken 1 times.
✗ Branch 23 not taken.
|
1 | ASSERT_EQ(m[shared_memory_test::map_int_keys2], |
239 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | shared_memory_test::map_value_2); |
240 | } | ||
241 | |||
242 |
3/6✓ Branch 8 taken 28 times.
✗ Branch 9 not taken.
✓ Branch 11 taken 28 times.
✗ Branch 12 not taken.
✓ Branch 14 taken 28 times.
✗ Branch 15 not taken.
|
32 | TEST_F(SharedMemoryTests, test_string_double_map) |
243 | { | ||
244 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | _call_executable_blocking(shared_memory_test::set_string_double_map); |
245 | |||
246 | 2 | std::map<std::string, double> m; | |
247 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | m[shared_memory_test::map_string_keys1] = 0.0; |
248 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | m[shared_memory_test::map_string_keys2] = 0.0; |
249 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | shared_memory::get( |
250 | shared_memory_test::segment_id, shared_memory_test::object_id, m); | ||
251 | |||
252 |
3/12✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✗ Branch 5 not taken.
✓ Branch 6 taken 1 times.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✓ Branch 20 taken 1 times.
✗ Branch 21 not taken.
|
1 | ASSERT_EQ(m.size(), shared_memory_test::test_map_size); |
253 |
4/14✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✗ Branch 7 not taken.
✓ Branch 8 taken 1 times.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
✓ Branch 22 taken 1 times.
✗ Branch 23 not taken.
|
1 | ASSERT_EQ(m[shared_memory_test::map_string_keys1], |
254 | 1 | shared_memory_test::map_value_1); | |
255 |
4/14✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✗ Branch 7 not taken.
✓ Branch 8 taken 1 times.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
✓ Branch 22 taken 1 times.
✗ Branch 23 not taken.
|
1 | ASSERT_EQ(m[shared_memory_test::map_string_keys2], |
256 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | shared_memory_test::map_value_2); |
257 | } | ||
258 | |||
259 |
3/6✓ Branch 8 taken 28 times.
✗ Branch 9 not taken.
✓ Branch 11 taken 28 times.
✗ Branch 12 not taken.
✓ Branch 14 taken 28 times.
✗ Branch 15 not taken.
|
32 | TEST_F(SharedMemoryTests, test_string_vector_double_map) |
260 | { | ||
261 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | _call_executable_blocking(shared_memory_test::set_string_vector_double_map); |
262 | |||
263 | 2 | std::map<std::string, std::vector<double>> m; | |
264 | |||
265 |
2/4✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✓ Branch 6 taken 1 times.
✗ Branch 7 not taken.
|
2 | std::vector<double> v1(2); |
266 | 1 | v1[0] = 0.0; | |
267 | 1 | v1[1] = 0.0; | |
268 | |||
269 |
2/4✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✓ Branch 6 taken 1 times.
✗ Branch 7 not taken.
|
2 | std::vector<double> v2(2); |
270 | 1 | v2[0] = 0.0; | |
271 | 1 | v2[1] = 0.0; | |
272 | |||
273 |
2/4✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
|
1 | m[shared_memory_test::map_string_keys1] = v1; |
274 |
2/4✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
|
1 | m[shared_memory_test::map_string_keys2] = v2; |
275 | |||
276 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | shared_memory::get( |
277 | shared_memory_test::segment_id, shared_memory_test::object_id, m); | ||
278 | |||
279 |
3/12✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✗ Branch 5 not taken.
✓ Branch 6 taken 1 times.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✓ Branch 20 taken 1 times.
✗ Branch 21 not taken.
|
1 | ASSERT_EQ(m.size(), shared_memory_test::test_map_size); |
280 |
4/14✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 5 taken 1 times.
✗ Branch 6 not taken.
✗ Branch 8 not taken.
✓ Branch 9 taken 1 times.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
✓ Branch 23 taken 1 times.
✗ Branch 24 not taken.
|
1 | ASSERT_EQ(m[shared_memory_test::map_string_keys1].size(), |
281 | 1 | static_cast<unsigned int>(2)); | |
282 |
4/14✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 5 taken 1 times.
✗ Branch 6 not taken.
✗ Branch 8 not taken.
✓ Branch 9 taken 1 times.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
✓ Branch 23 taken 1 times.
✗ Branch 24 not taken.
|
1 | ASSERT_EQ(m[shared_memory_test::map_string_keys2].size(), |
283 | 1 | static_cast<unsigned int>(2)); | |
284 | |||
285 |
4/14✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 5 taken 1 times.
✗ Branch 6 not taken.
✗ Branch 8 not taken.
✓ Branch 9 taken 1 times.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
✓ Branch 23 taken 1 times.
✗ Branch 24 not taken.
|
1 | ASSERT_EQ(m[shared_memory_test::map_string_keys1][0], |
286 | 1 | shared_memory_test::map_value_1); | |
287 |
4/14✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 5 taken 1 times.
✗ Branch 6 not taken.
✗ Branch 8 not taken.
✓ Branch 9 taken 1 times.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
✓ Branch 23 taken 1 times.
✗ Branch 24 not taken.
|
1 | ASSERT_EQ(m[shared_memory_test::map_string_keys1][1], |
288 | 1 | shared_memory_test::map_value_2); | |
289 | |||
290 |
4/14✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 5 taken 1 times.
✗ Branch 6 not taken.
✗ Branch 8 not taken.
✓ Branch 9 taken 1 times.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
✓ Branch 23 taken 1 times.
✗ Branch 24 not taken.
|
1 | ASSERT_EQ(m[shared_memory_test::map_string_keys2][0], |
291 | 1 | shared_memory_test::map_value_2); | |
292 |
4/14✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 5 taken 1 times.
✗ Branch 6 not taken.
✗ Branch 8 not taken.
✓ Branch 9 taken 1 times.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
✓ Branch 23 taken 1 times.
✗ Branch 24 not taken.
|
1 | ASSERT_EQ(m[shared_memory_test::map_string_keys2][1], |
293 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | shared_memory_test::map_value_1); |
294 | } | ||
295 | |||
296 |
3/6✓ Branch 8 taken 28 times.
✗ Branch 9 not taken.
✓ Branch 11 taken 28 times.
✗ Branch 12 not taken.
✓ Branch 14 taken 28 times.
✗ Branch 15 not taken.
|
32 | TEST_F(SharedMemoryTests, test_string_vector_eigen_map) |
297 | { | ||
298 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | _call_executable_blocking(shared_memory_test::set_string_vector_eigen_map); |
299 | |||
300 | 2 | std::map<std::string, Eigen::VectorXd> m; | |
301 | |||
302 |
4/8✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 1 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 1 times.
✗ Branch 11 not taken.
|
2 | Eigen::VectorXd v1(2), v2(2); |
303 | |||
304 |
2/4✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
|
1 | m[shared_memory_test::map_string_keys1] = v1; |
305 |
2/4✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
|
1 | m[shared_memory_test::map_string_keys2] = v2; |
306 | |||
307 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | shared_memory::get( |
308 | shared_memory_test::segment_id, shared_memory_test::object_id, m); | ||
309 | |||
310 |
3/12✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✗ Branch 5 not taken.
✓ Branch 6 taken 1 times.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✓ Branch 20 taken 1 times.
✗ Branch 21 not taken.
|
1 | ASSERT_EQ(m.size(), shared_memory_test::test_map_size); |
311 |
5/16✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 1 times.
✗ Branch 8 not taken.
✗ Branch 10 not taken.
✓ Branch 11 taken 1 times.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
✓ Branch 25 taken 1 times.
✗ Branch 26 not taken.
|
1 | ASSERT_EQ(m[shared_memory_test::map_string_keys1].size(), 2); |
312 |
5/16✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 1 times.
✗ Branch 8 not taken.
✗ Branch 10 not taken.
✓ Branch 11 taken 1 times.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
✓ Branch 25 taken 1 times.
✗ Branch 26 not taken.
|
1 | ASSERT_EQ(m[shared_memory_test::map_string_keys2].size(), 2); |
313 | |||
314 |
5/16✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 1 times.
✗ Branch 8 not taken.
✗ Branch 10 not taken.
✓ Branch 11 taken 1 times.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
✓ Branch 25 taken 1 times.
✗ Branch 26 not taken.
|
1 | ASSERT_EQ(m[shared_memory_test::map_string_keys1][0], |
315 | 1 | shared_memory_test::map_value_1); | |
316 |
5/16✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 1 times.
✗ Branch 8 not taken.
✗ Branch 10 not taken.
✓ Branch 11 taken 1 times.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
✓ Branch 25 taken 1 times.
✗ Branch 26 not taken.
|
1 | ASSERT_EQ(m[shared_memory_test::map_string_keys1][1], |
317 | 1 | shared_memory_test::map_value_2); | |
318 | |||
319 |
5/16✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 1 times.
✗ Branch 8 not taken.
✗ Branch 10 not taken.
✓ Branch 11 taken 1 times.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
✓ Branch 25 taken 1 times.
✗ Branch 26 not taken.
|
1 | ASSERT_EQ(m[shared_memory_test::map_string_keys2][0], |
320 | 1 | shared_memory_test::map_value_2); | |
321 |
5/16✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 1 times.
✗ Branch 8 not taken.
✗ Branch 10 not taken.
✓ Branch 11 taken 1 times.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
✓ Branch 25 taken 1 times.
✗ Branch 26 not taken.
|
1 | ASSERT_EQ(m[shared_memory_test::map_string_keys2][1], |
322 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | shared_memory_test::map_value_1); |
323 | } | ||
324 | |||
325 |
3/6✓ Branch 8 taken 28 times.
✗ Branch 9 not taken.
✓ Branch 11 taken 28 times.
✗ Branch 12 not taken.
✓ Branch 14 taken 28 times.
✗ Branch 15 not taken.
|
32 | TEST_F(SharedMemoryTests, test_memory_overflow) |
326 | { | ||
327 | 1 | unsigned int max_size = DEFAULT_SHARED_MEMORY_SIZE / sizeof(int) + 1; | |
328 |
2/5✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✓ Branch 6 taken 1 times.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
|
2 | std::vector<int> v(max_size); |
329 |
2/2✓ Branch 1 taken 16385 times.
✓ Branch 2 taken 1 times.
|
1 | for (size_t i = 0; i < v.size(); i++) v[i] = 1; |
330 | |||
331 |
6/36✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 1 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 1 times.
✗ Branch 8 not taken.
✗ Branch 10 not taken.
✓ Branch 11 taken 1 times.
✗ Branch 12 not taken.
✓ Branch 13 taken 1 times.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
✗ Branch 22 not taken.
✗ Branch 23 not taken.
✗ Branch 25 not taken.
✗ Branch 26 not taken.
✓ Branch 30 taken 1 times.
✗ Branch 31 not taken.
✗ Branch 36 not taken.
✗ Branch 37 not taken.
✗ Branch 39 not taken.
✗ Branch 40 not taken.
✗ Branch 42 not taken.
✗ Branch 43 not taken.
✗ Branch 46 not taken.
✗ Branch 47 not taken.
✗ Branch 50 not taken.
✗ Branch 51 not taken.
✗ Branch 53 not taken.
✗ Branch 54 not taken.
✗ Branch 58 not taken.
✗ Branch 59 not taken.
✗ Branch 61 not taken.
✗ Branch 62 not taken.
|
2 | ASSERT_THROW( |
332 | shared_memory::set( | ||
333 | shared_memory_test::segment_id, shared_memory_test::object_id, v), | ||
334 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | shared_memory::Allocation_exception); |
335 | } | ||
336 | |||
337 |
3/6✓ Branch 8 taken 28 times.
✗ Branch 9 not taken.
✓ Branch 11 taken 28 times.
✗ Branch 12 not taken.
✓ Branch 14 taken 28 times.
✗ Branch 15 not taken.
|
32 | TEST_F(SharedMemoryTests, test_wrong_size_vector) |
338 | { | ||
339 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | _call_executable_blocking(shared_memory_test::set_vector); |
340 | |||
341 |
2/5✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✓ Branch 6 taken 1 times.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
|
2 | std::vector<double> v(shared_memory_test::test_array_size + 1); // ! |
342 | |||
343 |
6/36✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 1 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 1 times.
✗ Branch 8 not taken.
✗ Branch 10 not taken.
✓ Branch 11 taken 1 times.
✗ Branch 12 not taken.
✓ Branch 13 taken 1 times.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
✗ Branch 22 not taken.
✗ Branch 23 not taken.
✗ Branch 25 not taken.
✗ Branch 26 not taken.
✓ Branch 30 taken 1 times.
✗ Branch 31 not taken.
✗ Branch 36 not taken.
✗ Branch 37 not taken.
✗ Branch 39 not taken.
✗ Branch 40 not taken.
✗ Branch 42 not taken.
✗ Branch 43 not taken.
✗ Branch 46 not taken.
✗ Branch 47 not taken.
✗ Branch 50 not taken.
✗ Branch 51 not taken.
✗ Branch 53 not taken.
✗ Branch 54 not taken.
✗ Branch 58 not taken.
✗ Branch 59 not taken.
✗ Branch 61 not taken.
✗ Branch 62 not taken.
|
2 | ASSERT_THROW( |
344 | shared_memory::get( | ||
345 | shared_memory_test::segment_id, shared_memory_test::object_id, v), | ||
346 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | shared_memory::Unexpected_size_exception); |
347 | } | ||
348 | |||
349 | 7495 | static inline bool is_one_of(double v, double a1, double a2) | |
350 | { | ||
351 |
2/2✓ Branch 0 taken 3876 times.
✓ Branch 1 taken 3619 times.
|
7495 | if (v == a1) return true; |
352 |
1/2✓ Branch 0 taken 3619 times.
✗ Branch 1 not taken.
|
3619 | if (v == a2) return true; |
353 | ✗ | return false; | |
354 | } | ||
355 | |||
356 |
3/6✓ Branch 8 taken 28 times.
✗ Branch 9 not taken.
✓ Branch 11 taken 28 times.
✗ Branch 12 not taken.
✓ Branch 14 taken 28 times.
✗ Branch 15 not taken.
|
32 | TEST_F(SharedMemoryTests, test_concurrency) |
357 | { | ||
358 | // condition variables' names | ||
359 |
1/2✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
|
2 | std::stringstream cond_var_name1; |
360 |
2/4✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
|
1 | cond_var_name1 << shared_memory_test::segment_id << "_" |
361 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | << shared_memory_test::concurrent_1; |
362 |
2/4✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 1 times.
✗ Branch 6 not taken.
|
2 | std::stringstream cond_var_name2; |
363 |
2/4✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
|
1 | cond_var_name2 << shared_memory_test::segment_id << "_" |
364 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | << shared_memory_test::concurrent_2; |
365 | |||
366 | // Prepare the condition variables | ||
367 |
3/6✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✓ Branch 8 taken 1 times.
✗ Branch 9 not taken.
|
2 | shared_memory::LockedConditionVariable cond_var1(cond_var_name1.str()); |
368 |
3/6✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✓ Branch 8 taken 1 times.
✗ Branch 9 not taken.
|
2 | shared_memory::LockedConditionVariable cond_var2(cond_var_name2.str()); |
369 | |||
370 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | shared_memory::set(shared_memory_test::segment_id, |
371 | shared_memory_test::concurrent_proc1_ready, | ||
372 | false); | ||
373 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | shared_memory::set(shared_memory_test::segment_id, |
374 | shared_memory_test::concurrent_proc2_ready, | ||
375 | false); | ||
376 | |||
377 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | _call_executable_non_blocking(shared_memory_test::concurrent_1); |
378 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | _call_executable_non_blocking(shared_memory_test::concurrent_2); |
379 | |||
380 | // Wait until both sub process are waiting, i.e. | ||
381 | // wait until we lock both condition variables | ||
382 | 1 | bool subproc_ready = false; | |
383 |
2/2✓ Branch 0 taken 2 times.
✓ Branch 1 taken 1 times.
|
5 | while (!subproc_ready) |
384 | { | ||
385 | 2 | bool concurrent_proc1_ready = false; | |
386 | 2 | bool concurrent_proc2_ready = false; | |
387 |
1/2✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
|
2 | shared_memory::get(shared_memory_test::segment_id, |
388 | shared_memory_test::concurrent_proc1_ready, | ||
389 | concurrent_proc1_ready); | ||
390 |
1/2✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
|
2 | shared_memory::get(shared_memory_test::segment_id, |
391 | shared_memory_test::concurrent_proc2_ready, | ||
392 | concurrent_proc2_ready); | ||
393 |
3/4✓ Branch 0 taken 1 times.
✓ Branch 1 taken 1 times.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
|
2 | subproc_ready = concurrent_proc1_ready && concurrent_proc2_ready; |
394 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 1 times.
|
2 | if (!subproc_ready) |
395 | { | ||
396 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | usleep(TIME_SLEEP); |
397 | } | ||
398 | } | ||
399 | |||
400 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | cond_var1.lock_scope(); |
401 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | cond_var2.lock_scope(); |
402 | |||
403 | 1 | bool set_1_observed = false; | |
404 | 1 | bool set_2_observed = false; | |
405 | |||
406 | 1 | int nb_1 = 0; | |
407 | 1 | int nb_2 = 0; | |
408 | |||
409 | double a[shared_memory_test::test_array_size]; | ||
410 | |||
411 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | cond_var1.notify_all(); |
412 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | cond_var2.notify_all(); |
413 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | cond_var1.wait(); |
414 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | cond_var2.wait(); |
415 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | cond_var1.unlock_scope(); |
416 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | cond_var2.unlock_scope(); |
417 | |||
418 | while (true) | ||
419 | { | ||
420 |
1/2✓ Branch 1 taken 7496 times.
✗ Branch 2 not taken.
|
7496 | shared_memory::get(shared_memory_test::segment_id, |
421 | shared_memory_test::object_id, | ||
422 | a, | ||
423 | std::size_t{shared_memory_test::test_array_size}); | ||
424 | |||
425 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 7495 times.
|
7496 | if (a[0] == shared_memory_test::concurrent_stop_value) |
426 | { | ||
427 | 1 | break; // the loop stops here. | |
428 | } | ||
429 | |||
430 |
2/2✓ Branch 0 taken 3876 times.
✓ Branch 1 taken 3619 times.
|
7495 | if (a[0] == shared_memory_test::concurrent_value_1) |
431 | { | ||
432 | 3876 | set_1_observed = true; | |
433 | 3876 | nb_1++; | |
434 | } | ||
435 | |||
436 |
2/2✓ Branch 0 taken 3619 times.
✓ Branch 1 taken 3876 times.
|
7495 | if (a[0] == shared_memory_test::concurrent_value_2) |
437 | { | ||
438 | 3619 | set_2_observed = true; | |
439 | 3619 | nb_2++; | |
440 | } | ||
441 | |||
442 |
3/12✓ Branch 2 taken 7495 times.
✗ Branch 3 not taken.
✗ Branch 5 not taken.
✓ Branch 6 taken 7495 times.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✓ Branch 20 taken 7495 times.
✗ Branch 21 not taken.
|
7495 | ASSERT_EQ(is_one_of(a[0], |
443 | shared_memory_test::concurrent_value_1, | ||
444 | shared_memory_test::concurrent_value_2), | ||
445 | 7495 | true); | |
446 | |||
447 |
2/2✓ Branch 0 taken 22485 times.
✓ Branch 1 taken 7495 times.
|
29980 | for (unsigned int i = 1; i < shared_memory_test::test_array_size; i++) |
448 | { | ||
449 |
3/12✓ Branch 1 taken 22485 times.
✗ Branch 2 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 22485 times.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✓ Branch 19 taken 22485 times.
✗ Branch 20 not taken.
|
22485 | ASSERT_EQ(a[0], a[i]); |
450 | } | ||
451 | |||
452 |
1/2✓ Branch 1 taken 7495 times.
✗ Branch 2 not taken.
|
7495 | usleep(5); |
453 | 7495 | } | |
454 |
3/12✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 1 times.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✓ Branch 19 taken 1 times.
✗ Branch 20 not taken.
|
1 | ASSERT_EQ(set_1_observed, true); |
455 |
4/14✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 1 times.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✓ Branch 19 taken 1 times.
✗ Branch 20 not taken.
✓ Branch 22 taken 1 times.
✗ Branch 23 not taken.
|
1 | ASSERT_EQ(set_2_observed, true); |
456 | } | ||
457 | |||
458 |
3/6✓ Branch 8 taken 28 times.
✗ Branch 9 not taken.
✓ Branch 11 taken 28 times.
✗ Branch 12 not taken.
✓ Branch 14 taken 28 times.
✗ Branch 15 not taken.
|
32 | TEST_F(SharedMemoryTests, test_locked_condition_variable) |
459 | { | ||
460 | // create a data vector | ||
461 | double d[shared_memory_test::test_array_size]; | ||
462 | |||
463 |
2/4✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
|
1 | std::cout << "SHARED_MEMORY_TESTS: Create the cond var." << std::endl; |
464 | shared_memory::LockedConditionVariable cond_var( | ||
465 |
2/4✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
|
2 | shared_memory_test::segment_id); |
466 | |||
467 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | std::cout << "SHARED_MEMORY_TESTS: Call test exec non blocking." |
468 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | << std::endl; |
469 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | _call_executable_non_blocking( |
470 | shared_memory_test::locked_condition_variable); | ||
471 | |||
472 |
2/4✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
|
1 | std::cout << "SHARED_MEMORY_TESTS: lock_scope." << std::endl; |
473 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | cond_var.lock_scope(); |
474 |
2/4✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
|
1 | std::cout << "SHARED_MEMORY_TESTS: wait." << std::endl; |
475 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | cond_var.wait(); |
476 | |||
477 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | std::cout << "SHARED_MEMORY_TESTS: Test shared_memory content." |
478 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | << std::endl; |
479 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | shared_memory::get(shared_memory_test::segment_id, |
480 | shared_memory_test::object_id, | ||
481 | d, | ||
482 | std::size_t{shared_memory_test::test_array_size}); | ||
483 |
2/2✓ Branch 0 taken 4 times.
✓ Branch 1 taken 1 times.
|
5 | for (unsigned int i = 0; i < shared_memory_test::test_array_size; i++) |
484 | { | ||
485 |
3/12✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 4 times.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✓ Branch 19 taken 4 times.
✗ Branch 20 not taken.
|
4 | ASSERT_EQ(d[i], shared_memory_test::concurrent_value_2); |
486 | } | ||
487 | |||
488 |
2/4✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
|
1 | std::cout << "SHARED_MEMORY_TESTS: Notify." << std::endl; |
489 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | cond_var.notify_all(); |
490 |
2/4✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
|
1 | std::cout << "SHARED_MEMORY_TESTS: Wait." << std::endl; |
491 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | cond_var.wait(); |
492 | |||
493 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | std::cout << "SHARED_MEMORY_TESTS: Test shared_memory content." |
494 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | << std::endl; |
495 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | shared_memory::get(shared_memory_test::segment_id, |
496 | shared_memory_test::object_id, | ||
497 | d, | ||
498 | std::size_t{shared_memory_test::test_array_size}); | ||
499 |
2/2✓ Branch 0 taken 4 times.
✓ Branch 1 taken 1 times.
|
5 | for (unsigned int i = 0; i < shared_memory_test::test_array_size; i++) |
500 | { | ||
501 |
3/12✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 4 times.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✓ Branch 19 taken 4 times.
✗ Branch 20 not taken.
|
4 | ASSERT_EQ(d[i], shared_memory_test::concurrent_stop_value); |
502 | } | ||
503 | |||
504 |
2/4✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
|
1 | std::cout << "SHARED_MEMORY_TESTS: Notify." << std::endl; |
505 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | cond_var.notify_all(); |
506 |
2/4✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
|
1 | std::cout << "SHARED_MEMORY_TESTS: Unlock scope." << std::endl; |
507 |
2/4✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
|
1 | cond_var.unlock_scope(); |
508 | } | ||
509 | |||
510 |
3/6✓ Branch 8 taken 28 times.
✗ Branch 9 not taken.
✓ Branch 11 taken 28 times.
✗ Branch 12 not taken.
✓ Branch 14 taken 28 times.
✗ Branch 15 not taken.
|
32 | TEST_F(SharedMemoryTests, test_timed_wait) |
511 | { | ||
512 | // get a condition variable | ||
513 | shared_memory::LockedConditionVariable cond_var( | ||
514 |
2/4✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
|
2 | shared_memory_test::segment_id); |
515 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | cond_var.lock_scope(); |
516 |
3/14✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✗ Branch 5 not taken.
✓ Branch 6 taken 1 times.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
✓ Branch 24 taken 1 times.
✗ Branch 25 not taken.
|
1 | ASSERT_FALSE(cond_var.timed_wait(10)); |
517 |
2/4✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
|
1 | cond_var.unlock_scope(); |
518 | } | ||
519 | |||
520 | 11 | void fill(double v[], int size, double value) | |
521 | { | ||
522 |
2/2✓ Branch 0 taken 44 times.
✓ Branch 1 taken 11 times.
|
55 | for (int i = 0; i < size; i++) |
523 | { | ||
524 | 44 | v[i] = value; | |
525 | } | ||
526 | 11 | } | |
527 | |||
528 |
3/6✓ Branch 8 taken 28 times.
✗ Branch 9 not taken.
✓ Branch 11 taken 28 times.
✗ Branch 12 not taken.
✓ Branch 14 taken 28 times.
✗ Branch 15 not taken.
|
32 | TEST_F(SharedMemoryTests, test_condition_variable) |
529 | { | ||
530 |
2/4✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
|
1 | std::cout << "SHARED_MEMORY_TESTS: Initializing shared array" << std::endl; |
531 | 1 | int value = 1; | |
532 | double v[shared_memory_test::test_array_size]; | ||
533 | 1 | fill(v, shared_memory_test::test_array_size, value); | |
534 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | shared_memory::set(shared_memory_test::segment_id, |
535 | shared_memory_test::object_id, | ||
536 | v, | ||
537 | std::size_t{shared_memory_test::test_array_size}); | ||
538 | |||
539 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
2 | std::string segment_mutex(shared_memory_test::segment_mutex_id); |
540 |
2/4✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
|
1 | std::cout << "SHARED_MEMORY_TESTS: Get a condition variable" << std::endl; |
541 |
3/6✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✓ Branch 8 taken 1 times.
✗ Branch 9 not taken.
|
2 | shared_memory::Mutex mutex(segment_mutex, true); |
542 | shared_memory::ConditionVariable condition( | ||
543 |
3/6✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✓ Branch 8 taken 1 times.
✗ Branch 9 not taken.
|
2 | shared_memory_test::segment_cv_id, true); |
544 | |||
545 | std::cout << "SHARED_MEMORY_TESTS: Starting another process with same " | ||
546 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | "condition variable." |
547 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | << std::endl; |
548 |
2/4✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 1 times.
✗ Branch 6 not taken.
|
1 | shared_memory::set( |
549 | shared_memory_test::segment_id, "cond_var_test_ready", false); | ||
550 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | _call_executable_non_blocking(shared_memory_test::condition_variable); |
551 | |||
552 |
2/4✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
|
1 | std::cout << "SHARED_MEMORY_TESTS: Proc ready!" << std::endl; |
553 |
2/2✓ Branch 0 taken 10 times.
✓ Branch 1 taken 1 times.
|
11 | for (int i = 0; i < 10; i++) |
554 | { | ||
555 | { | ||
556 |
2/4✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 10 times.
✗ Branch 5 not taken.
|
10 | std::cout << "SHARED_MEMORY_TESTS: Notifying one!" << std::endl; |
557 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | condition.notify_one(); |
558 |
2/4✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 10 times.
✗ Branch 5 not taken.
|
10 | std::cout << "SHARED_MEMORY_TESTS: Creating lock." << std::endl; |
559 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
20 | shared_memory::Lock lock(mutex); |
560 |
2/4✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 10 times.
✗ Branch 5 not taken.
|
10 | std::cout << "SHARED_MEMORY_TESTS: Wait!" << std::endl; |
561 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | condition.wait(lock); |
562 | |||
563 | std::cout << "SHARED_MEMORY_TESTS: The other process fill the " | ||
564 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | "array with 2." |
565 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | << std::endl; |
566 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | shared_memory::get( |
567 | shared_memory_test::segment_id, | ||
568 | shared_memory_test::object_id, | ||
569 | v, | ||
570 | std::size_t{shared_memory_test::test_array_size}); | ||
571 |
2/2✓ Branch 0 taken 40 times.
✓ Branch 1 taken 10 times.
|
50 | for (unsigned int i = 0; i < shared_memory_test::test_array_size; |
572 | i++) | ||
573 | { | ||
574 |
3/12✓ Branch 1 taken 40 times.
✗ Branch 2 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 40 times.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✓ Branch 19 taken 40 times.
✗ Branch 20 not taken.
|
40 | ASSERT_EQ(v[i], 2); |
575 | } | ||
576 | |||
577 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | std::cout << "SHARED_MEMORY_TESTS: Fill in the shared array with 1." |
578 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | << std::endl; |
579 | 10 | fill(v, shared_memory_test::test_array_size, value); | |
580 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | shared_memory::set( |
581 | shared_memory_test::segment_id, | ||
582 | shared_memory_test::object_id, | ||
583 | v, | ||
584 | std::size_t{shared_memory_test::test_array_size}); | ||
585 | |||
586 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | shared_memory::get( |
587 | shared_memory_test::segment_id, | ||
588 | shared_memory_test::object_id, | ||
589 | v, | ||
590 | std::size_t{shared_memory_test::test_array_size}); | ||
591 |
3/4✓ Branch 0 taken 40 times.
✓ Branch 1 taken 10 times.
✓ Branch 3 taken 10 times.
✗ Branch 4 not taken.
|
50 | for (unsigned int i = 0; i < shared_memory_test::test_array_size; |
592 | i++) | ||
593 | { | ||
594 |
3/12✓ Branch 1 taken 40 times.
✗ Branch 2 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 40 times.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✓ Branch 19 taken 40 times.
✗ Branch 20 not taken.
|
40 | ASSERT_EQ(v[i], 1); |
595 | } | ||
596 | } | ||
597 | } | ||
598 |
2/4✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
|
1 | std::cout << "SHARED_MEMORY_TESTS: End of test." << std::endl; |
599 |
2/4✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
|
1 | condition.notify_one(); |
600 | } | ||
601 | |||
602 |
3/6✓ Branch 8 taken 28 times.
✗ Branch 9 not taken.
✓ Branch 11 taken 28 times.
✗ Branch 12 not taken.
✓ Branch 14 taken 28 times.
✗ Branch 15 not taken.
|
32 | TEST_F(SharedMemoryTests, exchange_manager) |
603 | { | ||
604 | 1 | bool leading = true; | |
605 | 1 | bool autolock = true; // we will not need to call producer.lock() | |
606 | |||
607 | typedef shared_memory::Exchange_manager_producer< | ||
608 | shared_memory::Four_int_values, | ||
609 | DATA_EXCHANGE_QUEUE_SIZE> | ||
610 | Producer; | ||
611 | |||
612 |
2/4✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
|
1 | Producer::clean_mutex(shared_memory_test::segment_id); |
613 |
2/4✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
|
1 | Producer::clean_memory(shared_memory_test::segment_id); |
614 | |||
615 | Producer producer(shared_memory_test::segment_id, | ||
616 | shared_memory_test::object_id, | ||
617 | leading, | ||
618 |
3/6✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 1 times.
✗ Branch 8 not taken.
|
2 | autolock); |
619 | |||
620 | // several iterations to make sure the producer can manage 2 consumers | ||
621 | // running in a row | ||
622 | |||
623 |
3/4✓ Branch 0 taken 10 times.
✓ Branch 1 taken 1 times.
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
|
11 | for (int iteration = 0; iteration < 10; iteration++) |
624 | { | ||
625 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | producer.reset_char_count(); |
626 | |||
627 | // for informing main process if failure occured | ||
628 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | shared_memory::clear_shared_memory( |
629 | shared_memory_test::exchange_manager_segment_id); | ||
630 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | shared_memory::delete_segment( |
631 | shared_memory_test::exchange_manager_segment_id); | ||
632 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | shared_memory::set<bool>( |
633 | shared_memory_test::exchange_manager_segment_id, | ||
634 | shared_memory_test::exchange_manager_object_id, | ||
635 | false); | ||
636 | |||
637 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | _call_executable_non_blocking(shared_memory_test::exchange_manager); |
638 | |||
639 | 10 | int max_wait = 1000000; // 1 seconds | |
640 | 10 | int waited = 0; | |
641 | 10 | bool failed_to_start = false; | |
642 |
3/4✓ Branch 1 taken 252 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 242 times.
✓ Branch 4 taken 10 times.
|
494 | while (!producer.ready_to_produce()) |
643 | { | ||
644 |
1/2✓ Branch 1 taken 242 times.
✗ Branch 2 not taken.
|
242 | usleep(100); |
645 | 242 | waited += 100; | |
646 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 242 times.
|
242 | if (waited > max_wait) |
647 | { | ||
648 | ✗ | failed_to_start = true; | |
649 | } | ||
650 | } | ||
651 |
3/12✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 10 times.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✓ Branch 19 taken 10 times.
✗ Branch 20 not taken.
|
10 | ASSERT_EQ(failed_to_start, false); |
652 | |||
653 | // producing items | ||
654 | |||
655 | 10 | int id = 0; | |
656 | 10 | waited = 0; | |
657 | 10 | bool failed_to_produce_all = false; | |
658 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
20 | std::deque<int> consumed; |
659 | 10 | int consumed_id = 0; | |
660 | |||
661 | 10 | int written = 0; | |
662 | 10 | int previous_written = -1; | |
663 | |||
664 |
4/4✓ Branch 0 taken 32 times.
✓ Branch 1 taken 1000 times.
✓ Branch 2 taken 22 times.
✓ Branch 3 taken 10 times.
|
2086 | while (id < shared_memory_test::nb_to_consume || |
665 | 32 | consumed_id < shared_memory_test::nb_to_consume) | |
666 | { | ||
667 | // producing items | ||
668 |
2/2✓ Branch 0 taken 1000 times.
✓ Branch 1 taken 22 times.
|
1022 | if (id < shared_memory_test::nb_to_consume) |
669 | { | ||
670 | try | ||
671 | { | ||
672 |
1/4✓ Branch 1 taken 1000 times.
✗ Branch 2 not taken.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
|
2000 | shared_memory::Four_int_values p(1, 1, 1, 1); |
673 |
1/2✓ Branch 1 taken 1000 times.
✗ Branch 2 not taken.
|
1000 | p.set_id(id); |
674 |
1/2✓ Branch 1 taken 1000 times.
✗ Branch 2 not taken.
|
1000 | producer.set(p); |
675 | 1000 | id++; | |
676 | 1000 | waited = 0; | |
677 | } | ||
678 | ✗ | catch (const shared_memory::Memory_overflow_exception &) | |
679 | { | ||
680 | ✗ | usleep(200); | |
681 | ✗ | waited += 200; | |
682 | ✗ | if (waited >= max_wait) | |
683 | { | ||
684 | ✗ | failed_to_produce_all = true; | |
685 | ✗ | break; | |
686 | } | ||
687 | } | ||
688 | } | ||
689 | |||
690 | // monitoring consumed items | ||
691 | // should have been consumed in same order | ||
692 | // as produced | ||
693 |
1/2✓ Branch 1 taken 1022 times.
✗ Branch 2 not taken.
|
1022 | producer.get(consumed); |
694 |
2/2✓ Branch 1 taken 1000 times.
✓ Branch 2 taken 1022 times.
|
3022 | while (!consumed.empty()) |
695 | { | ||
696 |
3/12✓ Branch 2 taken 1000 times.
✗ Branch 3 not taken.
✗ Branch 5 not taken.
✓ Branch 6 taken 1000 times.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✓ Branch 20 taken 1000 times.
✗ Branch 21 not taken.
|
1000 | ASSERT_EQ(consumed_id, consumed.front()); |
697 | 1000 | consumed_id++; | |
698 | 1000 | consumed.pop_front(); | |
699 | } | ||
700 | |||
701 | // everything supposed to be produced was produced, | ||
702 | // and consumer died, so exiting | ||
703 |
4/6✓ Branch 0 taken 32 times.
✓ Branch 1 taken 990 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 32 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 1022 times.
|
1054 | if (id >= shared_memory_test::nb_to_consume && |
704 |
1/2✓ Branch 1 taken 32 times.
✗ Branch 2 not taken.
|
32 | !producer.ready_to_produce()) |
705 | { | ||
706 | ✗ | break; | |
707 | } | ||
708 | |||
709 |
1/2✓ Branch 1 taken 1022 times.
✗ Branch 2 not taken.
|
1022 | written = producer.nb_char_written(); |
710 |
2/2✓ Branch 0 taken 1000 times.
✓ Branch 1 taken 22 times.
|
1022 | if (written != previous_written) |
711 | { | ||
712 | 1000 | previous_written = written; | |
713 | } | ||
714 | |||
715 | // letting a chance for the consumer to get the lock | ||
716 |
1/2✓ Branch 1 taken 1022 times.
✗ Branch 2 not taken.
|
1022 | usleep(10); |
717 | } | ||
718 | |||
719 |
3/12✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 10 times.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✓ Branch 19 taken 10 times.
✗ Branch 20 not taken.
|
10 | ASSERT_EQ(failed_to_produce_all, false); |
720 | |||
721 | bool command_failed; | ||
722 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | shared_memory::get<bool>( |
723 | shared_memory_test::exchange_manager_segment_id, | ||
724 | shared_memory_test::exchange_manager_object_id, | ||
725 | command_failed); | ||
726 |
4/14✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 10 times.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✓ Branch 19 taken 10 times.
✗ Branch 20 not taken.
✓ Branch 22 taken 10 times.
✗ Branch 23 not taken.
|
10 | ASSERT_EQ(command_failed, false); |
727 | } | ||
728 | } | ||
729 | |||
730 |
3/6✓ Branch 8 taken 28 times.
✗ Branch 9 not taken.
✓ Branch 11 taken 28 times.
✗ Branch 12 not taken.
✓ Branch 14 taken 28 times.
✗ Branch 15 not taken.
|
32 | TEST_F(SharedMemoryTests, exchange_manager_init) |
731 | { | ||
732 | 1 | bool leading = true; | |
733 | 1 | bool autolock = true; // we will not need to call producer.lock() | |
734 | |||
735 | typedef shared_memory::Exchange_manager_producer< | ||
736 | shared_memory::Four_int_values, | ||
737 | DATA_EXCHANGE_QUEUE_SIZE> | ||
738 | Producer; | ||
739 | |||
740 | typedef shared_memory::Exchange_manager_consumer< | ||
741 | shared_memory::Four_int_values, | ||
742 | DATA_EXCHANGE_QUEUE_SIZE> | ||
743 | Consumer; | ||
744 | |||
745 |
2/4✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
|
1 | Producer::clean_mutex(shared_memory_test::segment_id); |
746 |
2/4✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
|
1 | Producer::clean_memory(shared_memory_test::segment_id); |
747 | |||
748 | Producer producer(shared_memory_test::segment_id, | ||
749 | shared_memory_test::object_id, | ||
750 | leading, | ||
751 |
3/6✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 1 times.
✗ Branch 8 not taken.
|
2 | autolock); |
752 | |||
753 | Consumer consumer(shared_memory_test::segment_id, | ||
754 | shared_memory_test::object_id, | ||
755 |
4/8✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 1 times.
✗ Branch 8 not taken.
✓ Branch 12 taken 1 times.
✗ Branch 13 not taken.
|
2 | !leading); |
756 | |||
757 | bool consumed; | ||
758 |
2/4✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
|
1 | if (consumer.ready_to_consume()) |
759 | { | ||
760 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
2 | shared_memory::Four_int_values fiv; |
761 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | consumed = consumer.consume(fiv); |
762 | } | ||
763 | |||
764 |
4/14✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 1 times.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✓ Branch 19 taken 1 times.
✗ Branch 20 not taken.
✓ Branch 22 taken 1 times.
✗ Branch 23 not taken.
|
1 | ASSERT_EQ(consumed, false); |
765 | } | ||
766 | |||
767 |
3/6✓ Branch 8 taken 28 times.
✗ Branch 9 not taken.
✓ Branch 11 taken 28 times.
✗ Branch 12 not taken.
✓ Branch 14 taken 28 times.
✗ Branch 15 not taken.
|
32 | TEST_F(SharedMemoryTests, serialization) |
768 | { | ||
769 |
2/4✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 1 times.
✗ Branch 6 not taken.
|
1 | shared_memory::clear_shared_memory("test_ser"); |
770 | |||
771 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
2 | shared_memory::Four_int_values in1(1, 1, 2, 1); |
772 |
2/4✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
|
2 | shared_memory::Four_int_values in2(1, 2, 1, 1); |
773 | |||
774 |
2/4✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
|
2 | shared_memory::Four_int_values out1; |
775 |
2/4✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
|
2 | shared_memory::Four_int_values out2; |
776 | |||
777 |
3/6✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✓ Branch 6 taken 1 times.
✗ Branch 7 not taken.
✓ Branch 9 taken 1 times.
✗ Branch 10 not taken.
|
1 | shared_memory::serialize("test_ser", "obj1", in1); |
778 |
3/6✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✓ Branch 6 taken 1 times.
✗ Branch 7 not taken.
✓ Branch 9 taken 1 times.
✗ Branch 10 not taken.
|
1 | shared_memory::serialize("test_ser", "obj2", in2); |
779 | |||
780 |
3/6✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✓ Branch 6 taken 1 times.
✗ Branch 7 not taken.
✓ Branch 9 taken 1 times.
✗ Branch 10 not taken.
|
1 | shared_memory::deserialize("test_ser", "obj1", out1); |
781 |
3/6✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✓ Branch 6 taken 1 times.
✗ Branch 7 not taken.
✓ Branch 9 taken 1 times.
✗ Branch 10 not taken.
|
1 | shared_memory::deserialize("test_ser", "obj2", out2); |
782 | |||
783 |
4/14✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✗ Branch 7 not taken.
✓ Branch 8 taken 1 times.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
✓ Branch 22 taken 1 times.
✗ Branch 23 not taken.
|
1 | ASSERT_EQ(in1.same(out1), true); |
784 |
5/16✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✗ Branch 7 not taken.
✓ Branch 8 taken 1 times.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
✓ Branch 22 taken 1 times.
✗ Branch 23 not taken.
✓ Branch 25 taken 1 times.
✗ Branch 26 not taken.
|
1 | ASSERT_EQ(in2.same(out2), true); |
785 | } | ||
786 | |||
787 |
3/6✓ Branch 8 taken 28 times.
✗ Branch 9 not taken.
✓ Branch 11 taken 28 times.
✗ Branch 12 not taken.
✓ Branch 14 taken 28 times.
✗ Branch 15 not taken.
|
32 | TEST_F(SharedMemoryTests, serialization2) |
788 | { | ||
789 |
2/4✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 1 times.
✗ Branch 6 not taken.
|
1 | shared_memory::clear_shared_memory("test_ser"); |
790 | |||
791 | 2 | shared_memory::Serializer<shared_memory::Item<10>> serializer; | |
792 | |||
793 |
3/4✓ Branch 0 taken 99 times.
✓ Branch 1 taken 1 times.
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
|
100 | for (int v = 1; v < 100; v++) |
794 | { | ||
795 |
1/2✓ Branch 1 taken 99 times.
✗ Branch 2 not taken.
|
99 | shared_memory::Item<10> in(v); |
796 |
1/2✓ Branch 1 taken 99 times.
✗ Branch 2 not taken.
|
99 | shared_memory::Item<10> out; |
797 |
1/2✓ Branch 1 taken 99 times.
✗ Branch 2 not taken.
|
99 | const std::string &s = serializer.serialize(in); |
798 |
1/2✓ Branch 1 taken 99 times.
✗ Branch 2 not taken.
|
99 | serializer.deserialize(s, out); |
799 |
3/12✓ Branch 3 taken 99 times.
✗ Branch 4 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 99 times.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✓ Branch 21 taken 99 times.
✗ Branch 22 not taken.
|
99 | ASSERT_EQ(in.get(), out.get()); |
800 | } | ||
801 | } | ||
802 | |||
803 | 1 | static shared_memory::array<int> get_array_int() | |
804 | { | ||
805 |
2/4✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 1 times.
✗ Branch 6 not taken.
|
1 | shared_memory::array<int> a("test_array", 10, true, true); |
806 | 1 | int value = 5; | |
807 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | a.set(2, value); |
808 | 1 | return a; | |
809 | } | ||
810 | |||
811 |
3/6✓ Branch 8 taken 28 times.
✗ Branch 9 not taken.
✓ Branch 11 taken 28 times.
✗ Branch 12 not taken.
✓ Branch 14 taken 28 times.
✗ Branch 15 not taken.
|
32 | TEST_F(SharedMemoryTests, array_int) |
812 | { | ||
813 |
2/4✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 1 times.
✗ Branch 6 not taken.
|
1 | shared_memory::clear_array("test_array"); |
814 | |||
815 |
2/4✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 1 times.
✗ Branch 6 not taken.
|
2 | shared_memory::array<int> a("test_array", 10, true, true); |
816 | 1 | int value = 5; | |
817 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | a.set(2, value); |
818 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | a.get(2, value); |
819 |
3/12✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 1 times.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✓ Branch 19 taken 1 times.
✗ Branch 20 not taken.
|
1 | ASSERT_EQ(value, 5); |
820 | |||
821 |
2/4✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
|
2 | shared_memory::array<int> b(a); |
822 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | b.get(2, value); |
823 |
3/12✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 1 times.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✓ Branch 19 taken 1 times.
✗ Branch 20 not taken.
|
1 | ASSERT_EQ(value, 5); |
824 | |||
825 |
1/2✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
|
2 | shared_memory::array<int> c = std::move(a); |
826 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | c.get(2, value); |
827 |
3/12✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 1 times.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✓ Branch 19 taken 1 times.
✗ Branch 20 not taken.
|
1 | ASSERT_EQ(value, 5); |
828 | |||
829 |
2/4✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
|
2 | shared_memory::array<int> d = get_array_int(); |
830 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | d.get(2, value); |
831 |
4/14✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 1 times.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✓ Branch 19 taken 1 times.
✗ Branch 20 not taken.
✓ Branch 22 taken 1 times.
✗ Branch 23 not taken.
|
1 | ASSERT_EQ(value, 5); |
832 | } | ||
833 | |||
834 |
3/6✓ Branch 8 taken 28 times.
✗ Branch 9 not taken.
✓ Branch 11 taken 28 times.
✗ Branch 12 not taken.
✓ Branch 14 taken 28 times.
✗ Branch 15 not taken.
|
32 | TEST_F(SharedMemoryTests, array_array_int) |
835 | { | ||
836 |
2/4✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 1 times.
✗ Branch 6 not taken.
|
1 | shared_memory::clear_array("test_array"); |
837 | |||
838 | 1 | int size = 100; | |
839 | |||
840 |
2/4✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 1 times.
✗ Branch 6 not taken.
|
2 | shared_memory::array<int, 10> a("test_array", size, true, true); |
841 | |||
842 | int values0[10]; | ||
843 | int values1[10]; | ||
844 |
2/2✓ Branch 0 taken 10 times.
✓ Branch 1 taken 1 times.
|
11 | for (uint j = 0; j < 10; j++) |
845 | { | ||
846 | 10 | values0[j] = 2; | |
847 | 10 | values1[j] = 3; | |
848 | } | ||
849 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | a.set(0, *values0); |
850 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | a.set(1, *values1); |
851 | |||
852 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | a.get(0, *values1); |
853 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | a.get(1, *values0); |
854 | |||
855 |
2/2✓ Branch 0 taken 10 times.
✓ Branch 1 taken 1 times.
|
11 | for (uint j = 0; j < 10; j++) |
856 | { | ||
857 |
3/12✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 10 times.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✓ Branch 19 taken 10 times.
✗ Branch 20 not taken.
|
10 | ASSERT_EQ(values0[j], 3); |
858 |
3/12✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 10 times.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✓ Branch 19 taken 10 times.
✗ Branch 20 not taken.
|
10 | ASSERT_EQ(values1[j], 2); |
859 | } | ||
860 | |||
861 | int values[10]; | ||
862 |
2/2✓ Branch 0 taken 100 times.
✓ Branch 1 taken 1 times.
|
101 | for (int i = 0; i < size; i++) |
863 | { | ||
864 |
2/2✓ Branch 0 taken 1000 times.
✓ Branch 1 taken 100 times.
|
1100 | for (int j = 0; j < 10; j++) |
865 | { | ||
866 | 1000 | values[j] = (i + j); | |
867 | } | ||
868 |
1/2✓ Branch 1 taken 100 times.
✗ Branch 2 not taken.
|
100 | a.set(i, *values); |
869 | } | ||
870 | |||
871 |
2/4✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
|
2 | shared_memory::array<int, 10> b(a); |
872 | |||
873 |
3/4✓ Branch 0 taken 100 times.
✓ Branch 1 taken 1 times.
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
|
101 | for (int i = 0; i < size; i++) |
874 | { | ||
875 |
1/2✓ Branch 1 taken 100 times.
✗ Branch 2 not taken.
|
100 | a.get(i, *values); |
876 |
2/2✓ Branch 0 taken 1000 times.
✓ Branch 1 taken 100 times.
|
1100 | for (int j = 0; j < 10; j++) |
877 | { | ||
878 |
3/12✓ Branch 1 taken 1000 times.
✗ Branch 2 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 1000 times.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✓ Branch 19 taken 1000 times.
✗ Branch 20 not taken.
|
1000 | ASSERT_EQ(values[j], i + j); |
879 | } | ||
880 |
1/2✓ Branch 1 taken 100 times.
✗ Branch 2 not taken.
|
100 | b.get(i, *values); |
881 |
2/2✓ Branch 0 taken 1000 times.
✓ Branch 1 taken 100 times.
|
1100 | for (int j = 0; j < 10; j++) |
882 | { | ||
883 |
3/12✓ Branch 1 taken 1000 times.
✗ Branch 2 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 1000 times.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✓ Branch 19 taken 1000 times.
✗ Branch 20 not taken.
|
1000 | ASSERT_EQ(values[j], i + j); |
884 | } | ||
885 | } | ||
886 | } | ||
887 | |||
888 |
3/6✓ Branch 8 taken 28 times.
✗ Branch 9 not taken.
✓ Branch 11 taken 28 times.
✗ Branch 12 not taken.
✓ Branch 14 taken 28 times.
✗ Branch 15 not taken.
|
32 | TEST_F(SharedMemoryTests, array_serializable) |
889 | { | ||
890 |
2/4✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 1 times.
✗ Branch 6 not taken.
|
1 | shared_memory::clear_array("test_array"); |
891 | |||
892 | 1 | int size = 100; | |
893 | |||
894 | shared_memory::array<shared_memory::Item<10>> a( | ||
895 |
2/4✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 1 times.
✗ Branch 6 not taken.
|
2 | "test_array", size, true, true); |
896 | |||
897 |
2/2✓ Branch 0 taken 100 times.
✓ Branch 1 taken 1 times.
|
101 | for (int i = 0; i < size; i++) |
898 | { | ||
899 |
1/2✓ Branch 1 taken 100 times.
✗ Branch 2 not taken.
|
100 | shared_memory::Item<10> item(i); |
900 |
1/2✓ Branch 1 taken 100 times.
✗ Branch 2 not taken.
|
100 | a.set(i, item); |
901 | } | ||
902 | |||
903 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | shared_memory::Item<10> item; |
904 |
2/2✓ Branch 0 taken 100 times.
✓ Branch 1 taken 1 times.
|
101 | for (int i = 0; i < size; i++) |
905 | { | ||
906 |
1/2✓ Branch 1 taken 100 times.
✗ Branch 2 not taken.
|
100 | a.get(i, item); |
907 |
3/12✓ Branch 2 taken 100 times.
✗ Branch 3 not taken.
✗ Branch 5 not taken.
✓ Branch 6 taken 100 times.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✓ Branch 20 taken 100 times.
✗ Branch 21 not taken.
|
100 | ASSERT_EQ(item.get(), i); |
908 | } | ||
909 | |||
910 |
2/4✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
|
2 | shared_memory::array<shared_memory::Item<10>> b(a); |
911 |
3/4✓ Branch 0 taken 100 times.
✓ Branch 1 taken 1 times.
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
|
101 | for (int i = 0; i < size; i++) |
912 | { | ||
913 |
1/2✓ Branch 1 taken 100 times.
✗ Branch 2 not taken.
|
100 | b.get(i, item); |
914 |
3/12✓ Branch 2 taken 100 times.
✗ Branch 3 not taken.
✗ Branch 5 not taken.
✓ Branch 6 taken 100 times.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✓ Branch 20 taken 100 times.
✗ Branch 21 not taken.
|
100 | ASSERT_EQ(item.get(), i); |
915 | } | ||
916 | } | ||
917 | |||
918 |
3/6✓ Branch 8 taken 28 times.
✗ Branch 9 not taken.
✓ Branch 11 taken 28 times.
✗ Branch 12 not taken.
✓ Branch 14 taken 28 times.
✗ Branch 15 not taken.
|
32 | TEST_F(SharedMemoryTests, array_serializable_get_serializable) |
919 | { | ||
920 |
2/4✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 1 times.
✗ Branch 6 not taken.
|
1 | shared_memory::clear_array("test_array"); |
921 | |||
922 | 1 | int size = 100; | |
923 | |||
924 | shared_memory::array<shared_memory::Item<10>> a( | ||
925 |
2/4✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 1 times.
✗ Branch 6 not taken.
|
2 | "test_array", size, true, true); |
926 | |||
927 |
2/2✓ Branch 0 taken 100 times.
✓ Branch 1 taken 1 times.
|
101 | for (int i = 0; i < size; i++) |
928 | { | ||
929 |
1/2✓ Branch 1 taken 100 times.
✗ Branch 2 not taken.
|
100 | shared_memory::Item<10> item(i); |
930 |
1/2✓ Branch 1 taken 100 times.
✗ Branch 2 not taken.
|
100 | a.set(i, item); |
931 | } | ||
932 | |||
933 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | shared_memory::Item<10> item; |
934 |
1/2✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
|
2 | shared_memory::Serializer<shared_memory::Item<10>> serializer; |
935 |
3/4✓ Branch 0 taken 100 times.
✓ Branch 1 taken 1 times.
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
|
101 | for (int i = 0; i < size; i++) |
936 | { | ||
937 |
1/2✓ Branch 1 taken 100 times.
✗ Branch 2 not taken.
|
100 | a.get(i, item); |
938 |
1/2✓ Branch 1 taken 100 times.
✗ Branch 2 not taken.
|
200 | std::string item_serialized = a.get_serialized(i); |
939 |
1/2✓ Branch 1 taken 100 times.
✗ Branch 2 not taken.
|
100 | shared_memory::Item<10> item2; |
940 |
1/2✓ Branch 1 taken 100 times.
✗ Branch 2 not taken.
|
100 | serializer.deserialize(item_serialized, item2); |
941 |
4/14✓ Branch 3 taken 100 times.
✗ Branch 4 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 100 times.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✓ Branch 21 taken 100 times.
✗ Branch 22 not taken.
✓ Branch 24 taken 100 times.
✗ Branch 25 not taken.
|
100 | ASSERT_EQ(item.get(), item2.get()); |
942 | } | ||
943 | } | ||
944 | |||
945 |
3/6✓ Branch 8 taken 28 times.
✗ Branch 9 not taken.
✓ Branch 11 taken 28 times.
✗ Branch 12 not taken.
✓ Branch 14 taken 28 times.
✗ Branch 15 not taken.
|
32 | TEST_F(SharedMemoryTests, segment_memory_size) |
946 | { | ||
947 |
2/4✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 1 times.
✗ Branch 6 not taken.
|
1 | shared_memory::clear_array("ut_sg_mem_size"); |
948 | |||
949 | 1 | bool error = false; | |
950 |
2/2✓ Branch 0 taken 9 times.
✓ Branch 1 taken 1 times.
|
10 | for (int i = 1; i < 10; i++) |
951 | { | ||
952 | try | ||
953 | { | ||
954 |
1/2✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
|
9 | shared_memory::set_segment_sizes(i); |
955 |
2/4✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 9 times.
✗ Branch 6 not taken.
|
9 | shared_memory::clear_array("ut_sg_mem_size"); |
956 | } | ||
957 | ✗ | catch (...) | |
958 | { | ||
959 | ✗ | error = true; | |
960 | } | ||
961 |
3/12✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 9 times.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✓ Branch 19 taken 9 times.
✗ Branch 20 not taken.
|
9 | ASSERT_EQ(error, false); |
962 | } | ||
963 | } | ||
964 | |||
965 |
3/6✓ Branch 8 taken 28 times.
✗ Branch 9 not taken.
✓ Branch 11 taken 28 times.
✗ Branch 12 not taken.
✓ Branch 14 taken 28 times.
✗ Branch 15 not taken.
|
32 | TEST_F(SharedMemoryTests, segment_info) |
966 | { | ||
967 |
2/4✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 1 times.
✗ Branch 6 not taken.
|
1 | shared_memory::clear_shared_memory("test_info"); |
968 | |||
969 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | shared_memory::set_default_segment_sizes(); |
970 | |||
971 |
3/6✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✓ Branch 6 taken 1 times.
✗ Branch 7 not taken.
✓ Branch 9 taken 1 times.
✗ Branch 10 not taken.
|
1 | shared_memory::set<double>("test_info", "d1", 5.0); |
972 |
3/6✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✓ Branch 6 taken 1 times.
✗ Branch 7 not taken.
✓ Branch 9 taken 1 times.
✗ Branch 10 not taken.
|
1 | shared_memory::set<double>("test_info", "d2", 10.0); |
973 | |||
974 | shared_memory::SegmentInfo si = | ||
975 |
2/4✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 1 times.
✗ Branch 6 not taken.
|
1 | shared_memory::get_segment_info("test_info"); |
976 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | uint size = si.get_size(); |
977 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | uint free = si.get_free_memory(); |
978 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | bool issues = si.has_issues(); |
979 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | uint nb_objects = si.nb_objects(); |
980 | |||
981 |
3/12✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 1 times.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✓ Branch 19 taken 1 times.
✗ Branch 20 not taken.
|
1 | ASSERT_EQ(size, uint(DEFAULT_SHARED_MEMORY_SIZE)); |
982 |
3/12✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 1 times.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✓ Branch 19 taken 1 times.
✗ Branch 20 not taken.
|
1 | ASSERT_GT(size, free); |
983 |
3/12✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 1 times.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✓ Branch 19 taken 1 times.
✗ Branch 20 not taken.
|
1 | ASSERT_GT(free, uint(0)); |
984 |
3/12✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 1 times.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✓ Branch 19 taken 1 times.
✗ Branch 20 not taken.
|
1 | ASSERT_EQ(nb_objects, uint(2)); |
985 |
2/12✗ Branch 2 not taken.
✓ Branch 3 taken 1 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✓ Branch 21 taken 1 times.
✗ Branch 22 not taken.
|
1 | ASSERT_FALSE(issues); |
986 | |||
987 |
3/6✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✓ Branch 6 taken 1 times.
✗ Branch 7 not taken.
✓ Branch 9 taken 1 times.
✗ Branch 10 not taken.
|
1 | shared_memory::set<double>("test_info", "d3", 2.0); |
988 |
3/6✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✓ Branch 6 taken 1 times.
✗ Branch 7 not taken.
✓ Branch 9 taken 1 times.
✗ Branch 10 not taken.
|
1 | shared_memory::set<double>("test_info", "d4", 3.0); |
989 | |||
990 | shared_memory::SegmentInfo si2 = | ||
991 |
2/4✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 1 times.
✗ Branch 6 not taken.
|
1 | shared_memory::get_segment_info("test_info"); |
992 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | uint size2 = si2.get_size(); |
993 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | uint free2 = si2.get_free_memory(); |
994 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | bool issues2 = si2.has_issues(); |
995 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | uint nb_objects2 = si2.nb_objects(); |
996 | |||
997 |
3/12✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 1 times.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✓ Branch 19 taken 1 times.
✗ Branch 20 not taken.
|
1 | ASSERT_EQ(size, size2); |
998 |
3/12✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 1 times.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✓ Branch 19 taken 1 times.
✗ Branch 20 not taken.
|
1 | ASSERT_LT(free2, free); |
999 |
2/12✗ Branch 2 not taken.
✓ Branch 3 taken 1 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✓ Branch 21 taken 1 times.
✗ Branch 22 not taken.
|
1 | ASSERT_FALSE(issues2); |
1000 |
3/12✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 1 times.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✓ Branch 19 taken 1 times.
✗ Branch 20 not taken.
|
1 | ASSERT_EQ(nb_objects2, uint(4)); |
1001 | |||
1002 | // memory overflow on purpose | ||
1003 |
1/2✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
|
2 | std::vector<char> v(free2 + 1); |
1004 | 1 | bool exception = false; | |
1005 | try | ||
1006 | { | ||
1007 |
3/6✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✓ Branch 6 taken 1 times.
✗ Branch 7 not taken.
✗ Branch 9 not taken.
✓ Branch 10 taken 1 times.
|
2 | shared_memory::set("test_info", "unreasonable", v); |
1008 | } | ||
1009 |
1/2✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
|
2 | catch (...) |
1010 | { | ||
1011 | 1 | exception = true; | |
1012 | } | ||
1013 |
3/14✗ Branch 2 not taken.
✓ Branch 3 taken 1 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✓ Branch 21 taken 1 times.
✗ Branch 22 not taken.
✓ Branch 24 taken 1 times.
✗ Branch 25 not taken.
|
1 | ASSERT_TRUE(exception); |
1014 |
2/4✓ Branch 1 taken 28 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 28 times.
✗ Branch 4 not taken.
|
84 | } |
1015 |