ChimeraTK-cppext 01.05.02
Loading...
Searching...
No Matches
threadsafe_unit_test.hpp
Go to the documentation of this file.
1// SPDX-FileCopyrightText: Deutsches Elektronen-Synchrotron DESY, MSK, ChimeraTK Project <chimeratk-support@desy.de>
2// SPDX-License-Identifier: LGPL-3.0-or-later
3#pragma once
4
5#include <mutex>
6
7// define thread-safe variants of BOOST_CHECK etc.
8std::mutex boostCheckMutex;
9
10#define BOOST_CHECK_TS(condition) \
11 if(!(condition)) { \
12 std::unique_lock<std::mutex> lock(boostCheckMutex); \
13 BOOST_CHECK(condition); \
14 }
15
16#define BOOST_CHECK_EQUAL_TS(a, b) \
17 if((a) != (b)) { \
18 std::unique_lock<std::mutex> lock(boostCheckMutex); \
19 BOOST_CHECK_EQUAL(a, b); \
20 }
21
22#define BOOST_ERROR_TS(message) \
23 { \
24 std::unique_lock<std::mutex> lock(boostCheckMutex); \
25 BOOST_ERROR(message); \
26 }
27
28#define BOOST_CHECK_TIMEOUT(condition) \
29 { \
30 bool isOk = false; \
31 for(size_t i = 0; i < 1000; ++i) { \
32 if(condition) { \
33 isOk = true; \
34 break; \
35 } \
36 usleep(10000); \
37 } \
38 if(!isOk) BOOST_ERROR_TS("Check with timeout on condition failed: " #condition); \
39 }
std::mutex boostCheckMutex