Skip to content

Commit

Permalink
test/affinity: Made use of more brace initialisation in the suite
Browse files Browse the repository at this point in the history
  • Loading branch information
dragonmux committed Jun 7, 2023
1 parent 34b6522 commit 83f03b1
Showing 1 changed file with 26 additions and 20 deletions.
46 changes: 26 additions & 20 deletions test/affinity.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -158,32 +158,38 @@ TEST_CASE("pinning", "[affinity_t]")
#if defined(_POSIX_THREADS) && !defined(__WINPTHREADS_VERSION)
for (const auto &processor : *affinity)
{
const auto result = std::async(std::launch::async,
[&](const uint32_t currentProcessor) noexcept -> int32_t
{
try
{ affinity->pinThreadTo(currentProcessor); }
catch (const std::out_of_range &)
{ return INT32_MAX; }
return sched_getcpu();
}, processor
).get();
const auto result
{
std::async(std::launch::async,
[&](const uint32_t currentProcessor) noexcept -> int32_t
{
try
{ affinity->pinThreadTo(currentProcessor); }
catch (const std::out_of_range &)
{ return INT32_MAX; }
return sched_getcpu();
}, processor
).get()
};
REQUIRE(result != -1);
REQUIRE(result == static_cast<int32_t>(processor));
}
#elif defined(_WIN32)
uint32_t count{0};
for (const auto &processor : *affinity)
{
const auto result = std::async(std::launch::async,
[&](const uint32_t currentProcessor) -> GROUP_AFFINITY
{
affinity->pinThreadTo(currentProcessor);
GROUP_AFFINITY res{};
REQUIRE(GetThreadGroupAffinity(GetCurrentThread(), &res));
return res;
}, count++
).get();
const auto result
{
std::async(std::launch::async,
[&](const uint32_t currentProcessor) -> GROUP_AFFINITY
{
affinity->pinThreadTo(currentProcessor);
GROUP_AFFINITY res{};
REQUIRE(GetThreadGroupAffinity(GetCurrentThread(), &res));
return res;
}, count++
).get()
};
REQUIRE(result.Mask == UINT64_C(1) << processor.second);
REQUIRE(result.Group == processor.first);
}
Expand Down Expand Up @@ -344,7 +350,7 @@ TEST_CASE("pin second core", "[affinity_t]")
return UINT32_MAX;
}()
};
const std::initializer_list<uint32_t> processorList {uint32_t(processor)};
const std::initializer_list<uint32_t> processorList{uint32_t(processor)};

REQUIRE(processor != UINT32_MAX);
auto affinity{substrate::make_unique_nothrow<substrate::affinity_t>(0U, processorList)};
Expand Down

0 comments on commit 83f03b1

Please sign in to comment.