diff --git a/CMakeLists.txt b/CMakeLists.txt index 17e881399..4392153f1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -310,7 +310,7 @@ endif () option(ENABLE_EXAMPLES "Enable Example Builds" ${GR_TOPLEVEL_PROJECT}) option(ENABLE_TESTING "Enable Test Builds" ${GR_TOPLEVEL_PROJECT}) -if (ENABLE_TESTING AND UNIX AND NOT APPLE) +if (ENABLE_TESTING AND (UNIX OR APPLE)) list(APPEND CMAKE_CTEST_ARGUMENTS "--output-on-failure") enable_testing() if (ENABLE_COVERAGE) diff --git a/bench/benchmark.hpp b/bench/benchmark.hpp index fbcf8d6eb..b0e83d38b 100644 --- a/bench/benchmark.hpp +++ b/bench/benchmark.hpp @@ -586,7 +586,7 @@ template std::string to_si_prefix(T value_base, std::string_view unit = "s", std::size_t significant_digits = 0) { static constexpr std::array si_prefixes{'q', 'r', 'y', 'z', 'a', 'f', 'p', 'n', 'u', 'm', ' ', 'k', 'M', 'G', 'T', 'P', 'E', 'Z', 'Y', 'R', 'Q'}; static constexpr long double base = 1000.0L; - long double value = value_base; + auto value = static_cast(value_base); std::size_t exponent = 10U; if (value == 0.0L) { @@ -791,7 +791,7 @@ class benchmark : public ut::detail::test { add_statistics(result_map, time_differences_ns); result_map.try_emplace("total time", duration_s, "s", _precision); - result_map.try_emplace("ops/s", _n_scale_results * N_ITERATIONS / duration_s, "", std::max(1, _precision)); + result_map.try_emplace("ops/s", static_cast(_n_scale_results * N_ITERATIONS) / duration_s, "", std::max(1, _precision)); if constexpr (MARKER_SIZE > 0) { auto transposed_map = utils::convert(marker_iter); diff --git a/blocks/http/test/CMakeLists.txt b/blocks/http/test/CMakeLists.txt index e155e78c8..b1d9f2c63 100644 --- a/blocks/http/test/CMakeLists.txt +++ b/blocks/http/test/CMakeLists.txt @@ -1,6 +1,8 @@ +if (NOT APPLE) add_ut_test(qa_HttpBlock) target_link_libraries(qa_HttpBlock PRIVATE gr-http) if (EMSCRIPTEN) target_link_options(qa_HttpBlock PRIVATE --pre-js=${CMAKE_CURRENT_SOURCE_DIR}/pre.js --emrun) endif () +endif () diff --git a/core/benchmarks/bm_Buffer.cpp b/core/benchmarks/bm_Buffer.cpp index c0354205f..313a9140d 100644 --- a/core/benchmarks/bm_Buffer.cpp +++ b/core/benchmarks/bm_Buffer.cpp @@ -16,7 +16,7 @@ using namespace gr; -#if defined __has_include && not __EMSCRIPTEN__ +#if defined(__has_include) && not defined(__EMSCRIPTEN__) && not defined(__APPLE__) #if __has_include() && __has_include() #include #include diff --git a/core/include/gnuradio-4.0/WaitStrategy.hpp b/core/include/gnuradio-4.0/WaitStrategy.hpp index 321d36fa7..df0e28d93 100644 --- a/core/include/gnuradio-4.0/WaitStrategy.hpp +++ b/core/include/gnuradio-4.0/WaitStrategy.hpp @@ -245,7 +245,7 @@ class SpinWait { yieldProcessor(); } } -#ifndef __EMSCRIPTEN__ +#if not defined(__EMSCRIPTEN__) && not defined(__APPLE__) static void yieldProcessor() noexcept { asm volatile("rep\nnop"); } #else static void yieldProcessor() noexcept { std::this_thread::sleep_for(std::chrono::milliseconds(1)); } diff --git a/core/include/gnuradio-4.0/thread/thread_affinity.hpp b/core/include/gnuradio-4.0/thread/thread_affinity.hpp index 2b555f007..9273f162a 100644 --- a/core/include/gnuradio-4.0/thread/thread_affinity.hpp +++ b/core/include/gnuradio-4.0/thread/thread_affinity.hpp @@ -37,13 +37,9 @@ class thread_exception : public std::error_category { public: constexpr thread_exception() : std::error_category(){}; - const char * - name() const noexcept override { - return "thread_exception"; - }; + const char* name() const noexcept override { return "thread_exception"; }; - std::string - message(int errorCode) const override { + std::string message(int errorCode) const override { switch (errorCode) { case THREAD_UNINITIALISED: return "thread uninitialised or user does not have the appropriate rights (ie. CAP_SYS_NICE capability)"; case THREAD_ERROR_UNKNOWN: return "thread error code 2"; @@ -63,15 +59,13 @@ concept thread_type = std::is_same_v; #endif namespace detail { -#if defined(_POSIX_VERSION) && not defined(__EMSCRIPTEN__) +#if defined(_POSIX_VERSION) && not defined(__EMSCRIPTEN__) && not defined(__APPLE__) template -constexpr decltype(auto) -firstElement(Tp &&t, Us &&...) noexcept { +constexpr decltype(auto) firstElement(Tp&& t, Us&&...) noexcept { return std::forward(t); } -inline constexpr pthread_t -getPosixHandler(thread_type auto &...t) noexcept { +inline constexpr pthread_t getPosixHandler(thread_type auto&... t) noexcept { if constexpr (sizeof...(t) > 0) { return firstElement(t...).native_handle(); } else { @@ -79,8 +73,7 @@ getPosixHandler(thread_type auto &...t) noexcept { } } -inline std::string -getThreadName(const pthread_t &handle) { +inline std::string getThreadName(const pthread_t& handle) { if (handle == 0U) { return "uninitialised thread"; } @@ -88,24 +81,17 @@ getThreadName(const pthread_t &handle) { if (int rc = pthread_getname_np(handle, threadName, THREAD_MAX_NAME_LENGTH); rc != 0) { throw std::system_error(rc, thread_exception(), "getThreadName(thread_type)"); } - return std::string{ threadName, strnlen(threadName, THREAD_MAX_NAME_LENGTH) }; + return std::string{threadName, strnlen(threadName, THREAD_MAX_NAME_LENGTH)}; } -inline int -getPid() { - return getpid(); -} +inline int getPid() { return getpid(); } #else -inline int -getPid() { - return 0; -} +inline int getPid() { return 0; } #endif } // namespace detail -#if defined(_POSIX_VERSION) && not defined(__EMSCRIPTEN__) -inline std::string -getProcessName(const int pid = detail::getPid()) { +#if defined(_POSIX_VERSION) && not defined(__EMSCRIPTEN__) && not defined(__APPLE__) +inline std::string getProcessName(const int pid = detail::getPid()) { if (std::ifstream in(fmt::format("/proc/{}/comm", pid), std::ios::in); in.is_open()) { std::string fileContent; std::getline(in, fileContent, '\n'); @@ -114,15 +100,11 @@ getProcessName(const int pid = detail::getPid()) { return "unknown_process"; } #else -inline std::string -getProcessName(const int /*pid*/ = -1) { - return "unknown_process"; -} +inline std::string getProcessName(const int /*pid*/ = -1) { return "unknown_process"; } #endif -#if defined(_POSIX_VERSION) && not defined(__EMSCRIPTEN__) -inline std::string -getThreadName(thread_type auto &...thread) { +#if defined(_POSIX_VERSION) && not defined(__EMSCRIPTEN__) && not defined(__APPLE__) +inline std::string getThreadName(thread_type auto&... thread) { const pthread_t handle = detail::getPosixHandler(thread...); if (handle == 0U) { throw std::system_error(THREAD_UNINITIALISED, thread_exception(), "getThreadName(thread_type)"); @@ -130,30 +112,24 @@ getThreadName(thread_type auto &...thread) { return detail::getThreadName(handle); } #else -inline std::string -getThreadName(thread_type auto &.../*thread*/) { - return "unknown thread name"; -} +inline std::string getThreadName(thread_type auto&... /*thread*/) { return "unknown thread name"; } #endif -#if defined(_POSIX_VERSION) && not defined(__EMSCRIPTEN__) -inline void -setProcessName(const std::string_view &processName, int pid = detail::getPid()) { +#if defined(_POSIX_VERSION) && not defined(__EMSCRIPTEN__) && not defined(__APPLE__) +inline void setProcessName(const std::string_view& processName, int pid = detail::getPid()) { std::ofstream out(fmt::format("/proc/{}/comm", pid), std::ios::out); if (!out.is_open()) { throw std::system_error(THREAD_UNINITIALISED, thread_exception(), fmt::format("setProcessName({},{})", processName, pid)); } - out << std::string{ processName.cbegin(), std::min(15LU, processName.size()) }; + out << std::string{processName.cbegin(), std::min(15LU, processName.size())}; out.close(); } #else -inline void -setProcessName(const std::string_view & /*processName*/, int /*pid*/ = -1) {} +inline void setProcessName(const std::string_view& /*processName*/, int /*pid*/ = -1) {} #endif -#if defined(_POSIX_VERSION) && not defined(__EMSCRIPTEN__) -inline void -setThreadName(const std::string_view &threadName, thread_type auto &...thread) { +#if defined(_POSIX_VERSION) && not defined(__EMSCRIPTEN__) && not defined(__APPLE__) +inline void setThreadName(const std::string_view& threadName, thread_type auto&... thread) { const pthread_t handle = detail::getPosixHandler(thread...); if (handle == 0U) { throw std::system_error(THREAD_UNINITIALISED, thread_exception(), fmt::format("setThreadName({}, thread_type)", threadName, detail::getThreadName(handle))); @@ -163,14 +139,12 @@ setThreadName(const std::string_view &threadName, thread_type auto &...thread) { } } #else -inline void -setThreadName(const std::string_view & /*threadName*/, thread_type auto &.../*thread*/) {} +inline void setThreadName(const std::string_view& /*threadName*/, thread_type auto&... /*thread*/) {} #endif -#if defined(_POSIX_VERSION) && not defined(__EMSCRIPTEN__) +#if defined(_POSIX_VERSION) && not defined(__EMSCRIPTEN__) && not defined(__APPLE__) namespace detail { -inline std::vector -getAffinityMask(const cpu_set_t &cpuSet) { +inline std::vector getAffinityMask(const cpu_set_t& cpuSet) { std::vector bitMask(std::min(sizeof(cpu_set_t), static_cast(std::thread::hardware_concurrency()))); for (size_t i = 0; i < bitMask.size(); i++) { bitMask[i] = CPU_ISSET(i, &cpuSet); @@ -179,9 +153,8 @@ getAffinityMask(const cpu_set_t &cpuSet) { } template - requires requires(T value) { value[0]; } -inline constexpr cpu_set_t -getAffinityMask(const T &threadMap) { +requires requires(T value) { value[0]; } +inline constexpr cpu_set_t getAffinityMask(const T& threadMap) { cpu_set_t cpuSet; CPU_ZERO(&cpuSet); size_t nMax = std::min(threadMap.size(), static_cast(std::thread::hardware_concurrency())); @@ -197,9 +170,8 @@ getAffinityMask(const T &threadMap) { } // namespace detail #endif -#if defined(_POSIX_VERSION) && not defined(__EMSCRIPTEN__) -inline std::vector -getThreadAffinity(thread_type auto &...thread) { +#if defined(_POSIX_VERSION) && not defined(__EMSCRIPTEN__) && not defined(__APPLE__) +inline std::vector getThreadAffinity(thread_type auto&... thread) { const pthread_t handle = detail::getPosixHandler(thread...); if (handle == 0U) { throw std::system_error(THREAD_UNINITIALISED, thread_exception(), fmt::format("getThreadAffinity(thread_type)")); @@ -211,39 +183,32 @@ getThreadAffinity(thread_type auto &...thread) { return detail::getAffinityMask(cpuSet); } #else -std::vector -getThreadAffinity(thread_type auto &...) { +std::vector getThreadAffinity(thread_type auto&...) { return std::vector(std::thread::hardware_concurrency()); // cannot set affinity for non-posix threads } #endif template - requires requires(T value) { value[0]; } -#if defined(_POSIX_VERSION) && not defined(__EMSCRIPTEN__) -inline constexpr void -setThreadAffinity(const T &threadMap, thread_type auto &...thread) { +requires requires(T value) { value[0]; } +#if defined(_POSIX_VERSION) && not defined(__EMSCRIPTEN__) && not defined(__APPLE__) +inline constexpr void setThreadAffinity(const T& threadMap, thread_type auto&... thread) { const pthread_t handle = detail::getPosixHandler(thread...); if (handle == 0U) { - throw std::system_error(THREAD_UNINITIALISED, thread_exception(), - fmt::format("setThreadAffinity(std::vector = {{{}}}, thread_type)", threadMap.size(), fmt::join(threadMap.begin(), threadMap.end(), ", "))); + throw std::system_error(THREAD_UNINITIALISED, thread_exception(), fmt::format("setThreadAffinity(std::vector = {{{}}}, thread_type)", threadMap.size(), fmt::join(threadMap.begin(), threadMap.end(), ", "))); } cpu_set_t cpuSet = detail::getAffinityMask(threadMap); if (int rc = pthread_setaffinity_np(handle, sizeof(cpu_set_t), &cpuSet); rc != 0) { - throw std::system_error(rc, thread_exception(), - fmt::format("setThreadAffinity(std::vector = {{{}}}, {})", threadMap.size(), fmt::join(threadMap.begin(), threadMap.end(), ", "), - detail::getThreadName(handle))); + throw std::system_error(rc, thread_exception(), fmt::format("setThreadAffinity(std::vector = {{{}}}, {})", threadMap.size(), fmt::join(threadMap.begin(), threadMap.end(), ", "), detail::getThreadName(handle))); } } #else -constexpr bool -setThreadAffinity(const T & /*threadMap*/, thread_type auto &...) { +constexpr bool setThreadAffinity(const T& /*threadMap*/, thread_type auto&...) { return false; // cannot set affinity for non-posix threads } #endif -#if defined(_POSIX_VERSION) && not defined(__EMSCRIPTEN__) -inline std::vector -getProcessAffinity(const int pid = detail::getPid()) { +#if defined(_POSIX_VERSION) && not defined(__EMSCRIPTEN__) && not defined(__APPLE__) +inline std::vector getProcessAffinity(const int pid = detail::getPid()) { if (pid <= 0) { throw std::system_error(THREAD_UNINITIALISED, thread_exception(), fmt::format("getProcessAffinity({}) -- invalid pid", pid)); } @@ -254,34 +219,29 @@ getProcessAffinity(const int pid = detail::getPid()) { return detail::getAffinityMask(cpuSet); } #else -inline std::vector -getProcessAffinity(const int /*pid*/ = -1) { +inline std::vector getProcessAffinity(const int /*pid*/ = -1) { return std::vector(std::thread::hardware_concurrency()); // cannot set affinity for non-posix threads } #endif -#if defined(_POSIX_VERSION) && not defined(__EMSCRIPTEN__) +#if defined(_POSIX_VERSION) && not defined(__EMSCRIPTEN__) && not defined(__APPLE__) template - requires requires(T value) { std::get<0>(value); } -inline constexpr bool -setProcessAffinity(const T &threadMap, const int pid = detail::getPid()) { +requires requires(T value) { std::get<0>(value); } +inline constexpr bool setProcessAffinity(const T& threadMap, const int pid = detail::getPid()) { if (pid <= 0) { - throw std::system_error(THREAD_UNINITIALISED, thread_exception(), - fmt::format("setProcessAffinity(std::vector = {{{}}}, {})", threadMap.size(), fmt::join(threadMap.begin(), threadMap.end(), ", "), pid)); + throw std::system_error(THREAD_UNINITIALISED, thread_exception(), fmt::format("setProcessAffinity(std::vector = {{{}}}, {})", threadMap.size(), fmt::join(threadMap.begin(), threadMap.end(), ", "), pid)); } cpu_set_t cpuSet = detail::getAffinityMask(threadMap); if (int rc = sched_setaffinity(pid, sizeof(cpu_set_t), &cpuSet); rc != 0) { - throw std::system_error(rc, thread_exception(), - fmt::format("setProcessAffinity(std::vector = {{{}}}, {})", threadMap.size(), fmt::join(threadMap.begin(), threadMap.end(), ", "), pid)); + throw std::system_error(rc, thread_exception(), fmt::format("setProcessAffinity(std::vector = {{{}}}, {})", threadMap.size(), fmt::join(threadMap.begin(), threadMap.end(), ", "), pid)); } return true; } #else template - requires requires(T value) { std::get<0>(value); } -inline constexpr bool -setProcessAffinity(const T & /*threadMap*/, const int /*pid*/ = -1) { +requires requires(T value) { std::get<0>(value); } +inline constexpr bool setProcessAffinity(const T& /*threadMap*/, const int /*pid*/ = -1) { return false; // cannot set affinity for non-posix threads } #endif @@ -293,14 +253,12 @@ struct fmt::formatter { using Policy = gr::thread_pool::thread::Policy; template - constexpr auto - parse(ParseContext &ctx) { + constexpr auto parse(ParseContext& ctx) { return ctx.begin(); } template - auto - format(Policy policy, FormatContext &ctx) { + auto format(Policy policy, FormatContext& ctx) { std::string policy_name; switch (policy) { case Policy::UNKNOWN: policy_name = "UNKNOWN"; break; @@ -321,10 +279,9 @@ struct SchedulingParameter { }; namespace detail { -inline Policy -getEnumPolicy(const int policy) { +inline Policy getEnumPolicy(const int policy) { switch (policy) { -#if defined(_POSIX_VERSION) && not defined(__EMSCRIPTEN__) +#if defined(_POSIX_VERSION) && not defined(__EMSCRIPTEN__) && not defined(__APPLE__) case SCHED_FIFO: return Policy::FIFO; case SCHED_RR: return Policy::ROUND_ROBIN; case SCHED_OTHER: return Policy::OTHER; @@ -334,9 +291,8 @@ getEnumPolicy(const int policy) { } } // namespace detail -#if defined(_POSIX_VERSION) && not defined(__EMSCRIPTEN__) -inline struct SchedulingParameter -getProcessSchedulingParameter(const int pid = detail::getPid()) { +#if defined(_POSIX_VERSION) && not defined(__EMSCRIPTEN__) && not defined(__APPLE__) +inline struct SchedulingParameter getProcessSchedulingParameter(const int pid = detail::getPid()) { if (pid <= 0) { throw std::system_error(THREAD_UNINITIALISED, thread_exception(), fmt::format("getProcessSchedulingParameter({}) -- invalid pid", pid)); } @@ -345,26 +301,21 @@ getProcessSchedulingParameter(const int pid = detail::getPid()) { if (int rc = sched_getparam(pid, ¶m); rc != 0) { throw std::system_error(rc, thread_exception(), fmt::format("getProcessSchedulingParameter({}) - sched_getparam error", pid)); } - return SchedulingParameter{ .policy = detail::getEnumPolicy(policy), .priority = param.sched_priority }; + return SchedulingParameter{.policy = detail::getEnumPolicy(policy), .priority = param.sched_priority}; } #else -inline struct SchedulingParameter -getProcessSchedulingParameter(const int /*pid*/ = -1) { - return {}; -} +inline struct SchedulingParameter getProcessSchedulingParameter(const int /*pid*/ = -1) { return {}; } #endif -#if defined(_POSIX_VERSION) && not defined(__EMSCRIPTEN__) -inline void -setProcessSchedulingParameter(Policy scheduler, int priority, const int pid = detail::getPid()) { +#if defined(_POSIX_VERSION) && not defined(__EMSCRIPTEN__) && not defined(__APPLE__) +inline void setProcessSchedulingParameter(Policy scheduler, int priority, const int pid = detail::getPid()) { if (pid <= 0) { throw std::system_error(THREAD_UNINITIALISED, thread_exception(), fmt::format("setProcessSchedulingParameter({}, {}, {}) -- invalid pid", scheduler, priority, pid)); } const int minPriority = sched_get_priority_min(scheduler); const int maxPriority = sched_get_priority_max(scheduler); if (priority < minPriority || priority > maxPriority) { - throw std::system_error(THREAD_VALUE_RANGE, thread_exception(), - fmt::format("setProcessSchedulingParameter({}, {}, {}) -- requested priority out-of-range [{}, {}]", scheduler, priority, pid, minPriority, maxPriority)); + throw std::system_error(THREAD_VALUE_RANGE, thread_exception(), fmt::format("setProcessSchedulingParameter({}, {}, {}) -- requested priority out-of-range [{}, {}]", scheduler, priority, pid, minPriority, maxPriority)); } struct sched_param param { @@ -376,13 +327,11 @@ setProcessSchedulingParameter(Policy scheduler, int priority, const int pid = de } } #else -inline void -setProcessSchedulingParameter(Policy /*scheduler*/, int /*priority*/, const int /*pid*/ = -1) {} +inline void setProcessSchedulingParameter(Policy /*scheduler*/, int /*priority*/, const int /*pid*/ = -1) {} #endif -#if defined(_POSIX_VERSION) && not defined(__EMSCRIPTEN__) -inline struct SchedulingParameter -getThreadSchedulingParameter(thread_type auto &...thread) { +#if defined(_POSIX_VERSION) && not defined(__EMSCRIPTEN__) && not defined(__APPLE__) +inline struct SchedulingParameter getThreadSchedulingParameter(thread_type auto&... thread) { const pthread_t handle = detail::getPosixHandler(thread...); if (handle == 0U) { throw std::system_error(THREAD_UNINITIALISED, thread_exception(), fmt::format("getThreadSchedulingParameter(thread_type) -- invalid thread")); @@ -392,18 +341,14 @@ getThreadSchedulingParameter(thread_type auto &...thread) { if (int rc = pthread_getschedparam(handle, &policy, ¶m); rc != 0) { throw std::system_error(rc, thread_exception(), fmt::format("getThreadSchedulingParameter({}) - sched_getparam error", detail::getThreadName(handle))); } - return { .policy = detail::getEnumPolicy(policy), .priority = param.sched_priority }; + return {.policy = detail::getEnumPolicy(policy), .priority = param.sched_priority}; } #else -inline struct SchedulingParameter -getThreadSchedulingParameter(thread_type auto &.../*thread*/) { - return {}; -} +inline struct SchedulingParameter getThreadSchedulingParameter(thread_type auto&... /*thread*/) { return {}; } #endif -#if defined(_POSIX_VERSION) && not defined(__EMSCRIPTEN__) -inline void -setThreadSchedulingParameter(Policy scheduler, int priority, thread_type auto &...thread) { +#if defined(_POSIX_VERSION) && not defined(__EMSCRIPTEN__) && not defined(__APPLE__) +inline void setThreadSchedulingParameter(Policy scheduler, int priority, thread_type auto&... thread) { const pthread_t handle = detail::getPosixHandler(thread...); if (handle == 0U) { throw std::system_error(THREAD_UNINITIALISED, thread_exception(), fmt::format("setThreadSchedulingParameter({}, {}, thread_type) -- invalid thread", scheduler, priority)); @@ -411,9 +356,7 @@ setThreadSchedulingParameter(Policy scheduler, int priority, thread_type auto &. const int minPriority = sched_get_priority_min(scheduler); const int maxPriority = sched_get_priority_max(scheduler); if (priority < minPriority || priority > maxPriority) { - throw std::system_error(THREAD_VALUE_RANGE, thread_exception(), - fmt::format("setThreadSchedulingParameter({}, {}, {}) -- requested priority out-of-range [{}, {}]", scheduler, priority, detail::getThreadName(handle), minPriority, - maxPriority)); + throw std::system_error(THREAD_VALUE_RANGE, thread_exception(), fmt::format("setThreadSchedulingParameter({}, {}, {}) -- requested priority out-of-range [{}, {}]", scheduler, priority, detail::getThreadName(handle), minPriority, maxPriority)); } struct sched_param param { @@ -421,13 +364,11 @@ setThreadSchedulingParameter(Policy scheduler, int priority, thread_type auto &. }; if (int rc = pthread_setschedparam(handle, scheduler, ¶m); rc != 0) { - throw std::system_error(rc, thread_exception(), - fmt::format("setThreadSchedulingParameter({}, {}, {}) - pthread_setschedparam return code: {}", scheduler, priority, detail::getThreadName(handle), rc)); + throw std::system_error(rc, thread_exception(), fmt::format("setThreadSchedulingParameter({}, {}, {}) - pthread_setschedparam return code: {}", scheduler, priority, detail::getThreadName(handle), rc)); } } #else -inline void -setThreadSchedulingParameter(Policy /*scheduler*/, int /*priority*/, thread_type auto &.../*thread*/) {} +inline void setThreadSchedulingParameter(Policy /*scheduler*/, int /*priority*/, thread_type auto&... /*thread*/) {} #endif } // namespace gr::thread_pool::thread diff --git a/core/test/qa_buffer.cpp b/core/test/qa_buffer.cpp index 6d5b30d6b..51a358723 100644 --- a/core/test/qa_buffer.cpp +++ b/core/test/qa_buffer.cpp @@ -115,7 +115,9 @@ const boost::ut::suite SequenceTests = [] { "Sequence"_test = [] { using namespace gr; using signed_index_type = std::make_signed_t; +#if not defined(__APPLE__) expect(eq(alignof(Sequence), 64UZ)); +#endif expect(eq(0L, kInitialCursorValue)); expect(nothrow([] { Sequence(); })); expect(nothrow([] { Sequence(2); })); @@ -621,8 +623,9 @@ const boost::ut::suite StreamTagConcept = [] { int64_t index; std::string data; }; - +#if not defined(__APPLE__) expect(eq(sizeof(buffer_tag), 64UZ)) << "tag size"; +#endif BufferLike auto buffer = CircularBuffer(1024); BufferLike auto tagBuffer = CircularBuffer(32); expect(ge(buffer.size(), 1024u)); diff --git a/core/test/qa_grc.cpp b/core/test/qa_grc.cpp index 39f56292f..63b621e9b 100644 --- a/core/test/qa_grc.cpp +++ b/core/test/qa_grc.cpp @@ -157,7 +157,7 @@ const boost::ut::suite GrcTests = [] { } }; -#ifndef __EMSCRIPTEN__ +#if not defined(__EMSCRIPTEN__) && not defined(__APPLE__) "Basic graph loading and storing using plugins"_test = [] { try { using namespace gr; diff --git a/core/test/qa_thread_affinity.cpp b/core/test/qa_thread_affinity.cpp index 2be3deea8..8f1212b4d 100644 --- a/core/test/qa_thread_affinity.cpp +++ b/core/test/qa_thread_affinity.cpp @@ -8,7 +8,7 @@ const boost::ut::suite ThreadAffinityTests = [] { using namespace boost::ut; "thread_exception"_test = [] { - expect(nothrow([]{gr::thread_pool::thread::thread_exception();})); + expect(nothrow([] { gr::thread_pool::thread::thread_exception(); })); expect(gr::thread_pool::thread::thread_exception().name() == "thread_exception"_b); expect(gr::thread_pool::thread::thread_exception().message(-1) == "unknown threading error code -1"_b); expect(gr::thread_pool::thread::thread_exception().message(-2) == "unknown threading error code -2"_b); @@ -19,7 +19,7 @@ const boost::ut::suite ThreadAffinityTests = [] { }; "thread_helper"_test = [] { -#if not defined(__EMSCRIPTEN__) +#if not defined(__EMSCRIPTEN__) && not defined(__APPLE__) expect(that % gr::thread_pool::thread::detail::getEnumPolicy(SCHED_FIFO) == gr::thread_pool::thread::Policy::FIFO); expect(that % gr::thread_pool::thread::detail::getEnumPolicy(SCHED_RR) == gr::thread_pool::thread::Policy::ROUND_ROBIN); expect(that % gr::thread_pool::thread::detail::getEnumPolicy(SCHED_OTHER) == gr::thread_pool::thread::Policy::OTHER); @@ -28,14 +28,18 @@ const boost::ut::suite ThreadAffinityTests = [] { expect(that % gr::thread_pool::thread::detail::getEnumPolicy(-2) == gr::thread_pool::thread::Policy::UNKNOWN); }; -#if not defined(__EMSCRIPTEN__) +#if not defined(__EMSCRIPTEN__) && not defined(__APPLE__) "basic thread affinity"_test = [] { using namespace gr::thread_pool; - std::atomic run = true; - const auto dummyAction = [&run]() { while (run) { std::this_thread::sleep_for(std::chrono::milliseconds(50)); } }; - std::thread testThread(dummyAction); + std::atomic run = true; + const auto dummyAction = [&run]() { + while (run) { + std::this_thread::sleep_for(std::chrono::milliseconds(50)); + } + }; + std::thread testThread(dummyAction); - constexpr std::array threadMap = { true, false, false, false }; + constexpr std::array threadMap = {true, false, false, false}; thread::setThreadAffinity(threadMap, testThread); auto affinity = thread::getThreadAffinity(testThread); bool equal = true; @@ -47,7 +51,7 @@ const boost::ut::suite ThreadAffinityTests = [] { expect(equal) << fmt::format("set {{{}}} affinity map does not match get {{{}}} map", fmt::join(threadMap, ", "), fmt::join(affinity, ", ")); // tests w/o thread argument - constexpr std::array threadMapOn = { true, true }; + constexpr std::array threadMapOn = {true, true}; thread::setThreadAffinity(threadMapOn); affinity = thread::getThreadAffinity(); for (size_t i = 0; i < std::min(threadMapOn.size(), affinity.size()); i++) { @@ -58,8 +62,8 @@ const boost::ut::suite ThreadAffinityTests = [] { expect(equal) << fmt::format("set {{{}}} affinity map does not match get {{{}}} map", fmt::join(threadMap, ", "), fmt::join(affinity, ", ")); std::thread bogusThread; - expect(throws([&]{ thread::getThreadAffinity(bogusThread); })); - expect(throws([&]{ thread::setThreadAffinity(threadMapOn, bogusThread); })); + expect(throws([&] { thread::getThreadAffinity(bogusThread); })); + expect(throws([&] { thread::setThreadAffinity(threadMapOn, bogusThread); })); run = false; testThread.join(); @@ -67,7 +71,7 @@ const boost::ut::suite ThreadAffinityTests = [] { "basic process affinity"_test = [] { using namespace gr::thread_pool; - constexpr std::array threadMap = { true, false, false, false }; + constexpr std::array threadMap = {true, false, false, false}; thread::setProcessAffinity(threadMap); auto affinity = thread::getProcessAffinity(); bool equal = true; @@ -77,29 +81,33 @@ const boost::ut::suite ThreadAffinityTests = [] { } } expect(equal) << fmt::format("set {{{}}} affinity map does not match get {{{}}} map", fmt::join(threadMap, ", "), fmt::join(affinity, ", ")); - constexpr std::array threadMapOn = { true, true, true, true }; + constexpr std::array threadMapOn = {true, true, true, true}; thread::setProcessAffinity(threadMapOn); - expect(throws([&]{ thread::getProcessAffinity(-1); })); - expect(throws([&]{ thread::setProcessAffinity(threadMapOn, -1); })); + expect(throws([&] { thread::getProcessAffinity(-1); })); + expect(throws([&] { thread::setProcessAffinity(threadMapOn, -1); })); }; "ThreadName"_test = [] { using namespace gr::thread_pool; expect(!thread::getThreadName().empty()) << "Thread name shouldn't be empty"; - expect(nothrow([]{ thread::setThreadName("testCoreName"); })); + expect(nothrow([] { thread::setThreadName("testCoreName"); })); expect(thread::getThreadName() == "testCoreName"_b); std::atomic run = true; - const auto dummyAction = [&run]() { while (run) { std::this_thread::sleep_for(std::chrono::milliseconds(20)); } }; - std::thread testThread(dummyAction); + const auto dummyAction = [&run]() { + while (run) { + std::this_thread::sleep_for(std::chrono::milliseconds(20)); + } + }; + std::thread testThread(dummyAction); expect(!thread::getThreadName(testThread).empty()) << "Thread Name shouldn't be empty"; - expect(nothrow([&]{ thread::setThreadName("testThreadName", testThread); })); + expect(nothrow([&] { thread::setThreadName("testThreadName", testThread); })); thread::setThreadName("testThreadName", testThread); expect(thread::getThreadName(testThread) == "testThreadName"_b); std::thread uninitialisedTestThread; - expect(throws([&]{ thread::getThreadName(uninitialisedTestThread); })); - expect(throws([&]{ thread::setThreadName("name", uninitialisedTestThread); })); + expect(throws([&] { thread::getThreadName(uninitialisedTestThread); })); + expect(throws([&] { thread::setThreadName("name", uninitialisedTestThread); })); run = false; testThread.join(); }; @@ -109,7 +117,7 @@ const boost::ut::suite ThreadAffinityTests = [] { expect(!thread::getProcessName().empty()) << "Process name shouldn't be empty"; expect(that % thread::getProcessName() == thread::getProcessName(thread::detail::getPid())); - expect(nothrow([]{ thread::setProcessName("TestProcessName"); })); + expect(nothrow([] { thread::setProcessName("TestProcessName"); })); expect(thread::getProcessName() == "TestProcessName"_b); }; @@ -119,16 +127,16 @@ const boost::ut::suite ThreadAffinityTests = [] { expect(that % param.policy == OTHER); expect(that % param.priority == 0); - expect(nothrow([]{ setProcessSchedulingParameter(OTHER, 0); })); - expect(throws([]{ setProcessSchedulingParameter(OTHER, 0, -1); })); - expect(throws([]{ setProcessSchedulingParameter(OTHER, 4); })); - expect(throws([]{ setProcessSchedulingParameter(ROUND_ROBIN, 5); })); // missing rights -- because most users do not have CAP_SYS_NICE rights by default -- hard to unit-test + expect(nothrow([] { setProcessSchedulingParameter(OTHER, 0); })); + expect(throws([] { setProcessSchedulingParameter(OTHER, 0, -1); })); + expect(throws([] { setProcessSchedulingParameter(OTHER, 4); })); + expect(throws([] { setProcessSchedulingParameter(ROUND_ROBIN, 5); })); // missing rights -- because most users do not have CAP_SYS_NICE rights by default -- hard to unit-test param = getProcessSchedulingParameter(); expect(that % param.policy == OTHER); expect(that % param.priority == 0); - expect(throws([]{ getProcessSchedulingParameter(-1); })); - expect(throws([]{ setProcessSchedulingParameter(ROUND_ROBIN, 5, -1); })); + expect(throws([] { getProcessSchedulingParameter(-1); })); + expect(throws([] { setProcessSchedulingParameter(ROUND_ROBIN, 5, -1); })); expect(that % gr::thread_pool::thread::detail::getEnumPolicy(SCHED_FIFO) == gr::thread_pool::thread::FIFO); expect(that % gr::thread_pool::thread::detail::getEnumPolicy(SCHED_RR) == gr::thread_pool::thread::ROUND_ROBIN); @@ -136,10 +144,14 @@ const boost::ut::suite ThreadAffinityTests = [] { }; "ThreadSchedulingParameter"_test = [] { - std::atomic run = true; - const auto dummyAction = [&run]() { while (run) { std::this_thread::sleep_for(std::chrono::milliseconds(50)); } }; - std::thread testThread(dummyAction); - std::thread bogusThread; + std::atomic run = true; + const auto dummyAction = [&run]() { + while (run) { + std::this_thread::sleep_for(std::chrono::milliseconds(50)); + } + }; + std::thread testThread(dummyAction); + std::thread bogusThread; using namespace gr::thread_pool::thread; struct SchedulingParameter param = getThreadSchedulingParameter(testThread); @@ -148,16 +160,16 @@ const boost::ut::suite ThreadAffinityTests = [] { setThreadSchedulingParameter(OTHER, 0, testThread); setThreadSchedulingParameter(OTHER, 0); - expect(throws([&]{ setThreadSchedulingParameter(OTHER, 0, bogusThread); })); - expect(throws([&]{ setThreadSchedulingParameter(OTHER, 4, testThread); })); - expect(throws([&]{ setThreadSchedulingParameter(OTHER, 4); })); - expect(throws([&]{ setThreadSchedulingParameter(ROUND_ROBIN, 5, testThread); })); // missing rights -- because most users do not have CAP_SYS_NICE rights by default -- hard to unit-test - expect(throws([&]{ setThreadSchedulingParameter(ROUND_ROBIN, 5); })); // missing rights -- because most users do not have CAP_SYS_NICE rights by default -- hard to unit-test + expect(throws([&] { setThreadSchedulingParameter(OTHER, 0, bogusThread); })); + expect(throws([&] { setThreadSchedulingParameter(OTHER, 4, testThread); })); + expect(throws([&] { setThreadSchedulingParameter(OTHER, 4); })); + expect(throws([&] { setThreadSchedulingParameter(ROUND_ROBIN, 5, testThread); })); // missing rights -- because most users do not have CAP_SYS_NICE rights by default -- hard to unit-test + expect(throws([&] { setThreadSchedulingParameter(ROUND_ROBIN, 5); })); // missing rights -- because most users do not have CAP_SYS_NICE rights by default -- hard to unit-test param = getThreadSchedulingParameter(testThread); expect(that % param.policy == OTHER); - expect(throws([&]{ getThreadSchedulingParameter(bogusThread); })); - expect(throws([&]{ setThreadSchedulingParameter(ROUND_ROBIN, 5, bogusThread); })); + expect(throws([&] { getThreadSchedulingParameter(bogusThread); })); + expect(throws([&] { setThreadSchedulingParameter(ROUND_ROBIN, 5, bogusThread); })); run = false; testThread.join(); @@ -165,6 +177,4 @@ const boost::ut::suite ThreadAffinityTests = [] { #endif }; -int -main() { /* tests are statically executed */ -} +int main() { /* tests are statically executed */ } diff --git a/core/test/qa_thread_pool.cpp b/core/test/qa_thread_pool.cpp index 8ad5b047b..ee76e70b3 100644 --- a/core/test/qa_thread_pool.cpp +++ b/core/test/qa_thread_pool.cpp @@ -43,7 +43,7 @@ const boost::ut::suite ThreadPoolTests = [] { expect(ret.get() == 42_i); auto taskName = pool.execute<"taskName", 0, -1>([] { return gr::thread_pool::thread::getThreadName(); }); -#ifdef __EMSCRIPTEN__ +#if defined(__EMSCRIPTEN__) || defined(__APPLE__) expect(taskName.get() == "unknown thread name"_b); #else expect(taskName.get() == "taskName"_b);