Skip to content

Commit 5f46dca

Browse files
authored
fix building for linux (#1)
1 parent 28fed19 commit 5f46dca

File tree

3 files changed

+63
-50
lines changed

3 files changed

+63
-50
lines changed

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
cmake_minimum_required(VERSION 0.1)
1+
cmake_minimum_required(VERSION 3.8)
22
project("cpp_systematic_testing" CXX)
33

44
set(CMAKE_CXX_STANDARD 17)

include/systematic_testing.h

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@
55
#define SYSTEMATIC_TESTING_H
66

77
#include <algorithm>
8+
#include <atomic>
89
#include <chrono>
10+
#include <cmath>
911
#include <condition_variable>
1012
#include <functional>
1113
#include <iostream>
@@ -21,10 +23,24 @@
2123
#include <tuple>
2224
#include <vector>
2325

24-
#ifdef SYSTEST_EXPORT
25-
# define SYSTEST_API __declspec(dllexport)
26-
#else
27-
# define SYSTEST_API __declspec(dllimport)
26+
#ifdef __linux__
27+
# ifdef SYSTEST_EXPORT
28+
# define SYSTEST_API __attribute__((visibility("default")))
29+
# else
30+
# define SYSTEST_API
31+
# endif
32+
#elif _WIN32
33+
# ifdef SYSTEST_EXPORT
34+
# define SYSTEST_API __declspec(dllexport)
35+
# else
36+
# define SYSTEST_API __declspec(dllimport)
37+
# endif
38+
#else
39+
# ifdef SYSTEST_EXPORT
40+
# define SYSTEST_API
41+
# else
42+
# define SYSTEST_API
43+
# endif
2844
#endif
2945

3046
namespace SystematicTesting
@@ -289,7 +305,7 @@ namespace SystematicTesting
289305
{
290306
private:
291307
// Give private access to the test engine.
292-
friend class TestEngine;
308+
friend class SystematicTesting::TestEngine;
293309

294310
public:
295311
// Returns the number of iterations performed.
@@ -666,7 +682,7 @@ namespace SystematicTesting
666682
{
667683
private:
668684
// Give private access to the test engine.
669-
friend class TestEngine;
685+
friend class SystematicTesting::TestEngine;
670686

671687
// The creation sequence vector of this operation.
672688
std::vector<size_t> m_creation_seq;

test/controlled_task.h

Lines changed: 40 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -15,60 +15,57 @@
1515
using namespace std::chrono_literals;
1616
using namespace SystematicTesting;
1717

18-
namespace
18+
template<typename ResultType>
19+
class ControlledTaskBase
1920
{
20-
template<typename ResultType>
21-
class ControlledTaskBase
21+
public:
22+
explicit ControlledTaskBase(std::function<ResultType()> func) :
23+
m_test_engine(GetTestEngine()),
24+
m_thread(),
25+
m_func(func),
26+
m_result(std::nullopt)
2227
{
23-
public:
24-
explicit ControlledTaskBase(std::function<ResultType()> func) :
25-
m_test_engine(GetTestEngine()),
26-
m_thread(),
27-
m_func(func),
28-
m_result(std::nullopt)
29-
{
30-
31-
}
28+
29+
}
3230

33-
virtual ~ControlledTaskBase()
31+
virtual ~ControlledTaskBase()
32+
{
33+
if (m_thread->joinable())
3434
{
35-
if (m_thread->joinable())
36-
{
37-
m_thread->join();
38-
}
35+
m_thread->join();
3936
}
37+
}
4038

41-
void start()
39+
void start()
40+
{
41+
size_t op_id = m_test_engine->create_next_operation().value();
42+
m_thread = std::make_unique<std::thread>([this, op_id]()
4243
{
43-
size_t op_id = m_test_engine->create_next_operation().value();
44-
m_thread = std::make_unique<std::thread>([this, op_id]()
45-
{
46-
m_test_engine->start_operation(op_id);
47-
execute(m_func, op_id);
48-
m_test_engine->complete_current_operation();
49-
});
50-
51-
m_test_engine->schedule_next_operation();
52-
}
44+
m_test_engine->start_operation(op_id);
45+
execute(m_func, op_id);
46+
m_test_engine->complete_current_operation();
47+
});
5348

54-
void wait()
55-
{
56-
m_test_engine->pause_operation_until_condition([this]() {
57-
return m_result.has_value();
58-
});
59-
}
49+
m_test_engine->schedule_next_operation();
50+
}
51+
52+
void wait()
53+
{
54+
m_test_engine->pause_operation_until_condition([this]() {
55+
return m_result.has_value();
56+
});
57+
}
6058

61-
protected:
62-
std::optional<std::any> m_result;
59+
protected:
60+
std::optional<std::any> m_result;
6361

64-
virtual void execute(std::function<ResultType()>& func, size_t op_id) = 0;
62+
virtual void execute(std::function<ResultType()>& func, size_t op_id) = 0;
6563

66-
private:
67-
TestEngine* m_test_engine;
68-
std::unique_ptr<std::thread> m_thread;
69-
std::function<ResultType()> m_func;
70-
};
71-
}
64+
private:
65+
TestEngine* m_test_engine;
66+
std::unique_ptr<std::thread> m_thread;
67+
std::function<ResultType()> m_func;
68+
};
7269

7370
template<typename ResultType>
7471
class ControlledTask final : public ControlledTaskBase<ResultType>

0 commit comments

Comments
 (0)