diff options
Diffstat (limited to 'offload/unittests/OffloadAPI/common')
-rw-r--r-- | offload/unittests/OffloadAPI/common/Fixtures.hpp | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/offload/unittests/OffloadAPI/common/Fixtures.hpp b/offload/unittests/OffloadAPI/common/Fixtures.hpp index 24ce1a0..43240fa 100644 --- a/offload/unittests/OffloadAPI/common/Fixtures.hpp +++ b/offload/unittests/OffloadAPI/common/Fixtures.hpp @@ -9,6 +9,7 @@ #include <OffloadAPI.h> #include <OffloadPrint.hpp> #include <gtest/gtest.h> +#include <thread> #include "Environment.hpp" @@ -57,6 +58,23 @@ inline std::string SanitizeString(const std::string &Str) { return NewStr; } +template <typename Fn> inline void threadify(Fn body) { + std::vector<std::thread> Threads; + for (size_t I = 0; I < 20; I++) { + Threads.emplace_back( + [&body](size_t I) { + std::string ScopeMsg{"Thread #"}; + ScopeMsg.append(std::to_string(I)); + SCOPED_TRACE(ScopeMsg); + body(I); + }, + I); + } + for (auto &T : Threads) { + T.join(); + } +} + struct OffloadTest : ::testing::Test { ol_device_handle_t Host = TestEnvironment::getHostDevice(); }; |