| 154 | } |
| 155 | |
| 156 | TEST(memory_tests, receive_messages) { |
| 157 | |
| 158 | // Test steps: |
| 159 | // 1: Start measuring memory load |
| 160 | // 2: Send requests for 20 different events |
| 161 | // 3: Wait for receiving all responses from service |
| 162 | // 4: Stop measuring load and evaluate load increase |
| 163 | // |
| 164 | // At the end evaluate if the threshold of 5% increase in memory load was not surpassed |
| 165 | |
| 166 | std::map<vsomeip::event_t, int> events_to_subscribe; |
| 167 | |
| 168 | for (vsomeip::event_t i = 0; i < TEST_EVENT_NUMBER; i++) { |
| 169 | events_to_subscribe[MEMORY_EVENT + i] = 0; |
| 170 | } |
| 171 | |
| 172 | memory_test_client memory_test_client("memory_tests_client", events_to_subscribe); |
| 173 | |
| 174 | std::atomic<bool> stop_checking{false}; |
| 175 | |
| 176 | // 1. Measure load until stop_checking is triggered |
| 177 | std::thread memory_checker_thread; |
| 178 | memory_checker_thread = std::thread([&stop_checking] { |
| 179 | std::vector<std::uint64_t> test_memory_array; |
| 180 | std::uint64_t sum{0}; |
| 181 | |
| 182 | check_memory(test_memory_array, stop_checking); |
| 183 | |
| 184 | for (auto memory_stat : test_memory_array) { |
| 185 | sum += memory_stat; |
| 186 | VSOMEIP_INFO << memory_stat; |
| 187 | } |
| 188 | double memory_average = static_cast<double>(sum) / static_cast<double>(test_memory_array.size()); |
| 189 | VSOMEIP_INFO << memory_average; |
| 190 | |
| 191 | // 4. Evaluate memory load increase |
| 192 | for (auto memory_stat : test_memory_array) { |
| 193 | EXPECT_LT(static_cast<double>(memory_stat), (static_cast<double>(memory_average) * MEMORY_LOAD_LIMIT)) |
| 194 | << "memory not lesser than " << (static_cast<double>(memory_average) * MEMORY_LOAD_LIMIT); |
| 195 | } |
| 196 | }); |
| 197 | |
| 198 | // 2. Send a request and wait until all the messages are sent by the service |
| 199 | memory_test_client.send_request(stop_checking); |
| 200 | |
| 201 | if (memory_checker_thread.joinable()) { |
| 202 | memory_checker_thread.join(); |
| 203 | } |
| 204 | } |
| 205 | |
| 206 | int main(int argc, char** argv) { |
| 207 | return test_main(argc, argv, std::chrono::seconds(300)); |
nothing calls this directly
no test coverage detected