Skip to content

Commit ecc3a80

Browse files
authored
[ThreadPool] Fix Windows failures in the AffinityMask unit test (#155614)
These thread pool tests are typed and one was failing due to the setting of environment variable `LLVM_THREADPOOL_AFFINITYMASK` leaking out of a previous run of the test. I suspect that this has mainly succeeded because the tests have run in separate shards. Also the re-invocation of the unit test with the process affinity mask set was not actually running the test because `--gtest_filter=` was not set correctly. This has been fixed. The use of the test type (TypeParam) in the AsyncBarrier test has been restored. Without this the typing of these tests would be completely redundant. I suspect that some of these unit tests do not work if `LLVM_ENABLE_THREADS == 0` but that is beyond the scope of this fix.
1 parent bd54233 commit ecc3a80

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

llvm/unittests/Support/ThreadPool.cpp

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ TYPED_TEST(ThreadPoolTest, AsyncBarrier) {
140140

141141
std::atomic_int checked_in{0};
142142

143-
DefaultThreadPool Pool;
143+
TypeParam Pool;
144144
for (size_t i = 0; i < 5; ++i) {
145145
Pool.async([this, &checked_in] {
146146
this->waitForMainThread();
@@ -453,15 +453,19 @@ TYPED_TEST(ThreadPoolTest, AffinityMask) {
453453
[](auto &T) { return T.getData().front() < 16UL; }) &&
454454
"Threads ran on more CPUs than expected! The affinity mask does not "
455455
"seem to work.");
456-
GTEST_SKIP();
456+
return;
457457
}
458458
std::string Executable =
459459
sys::fs::getMainExecutable(TestMainArgv0, &ThreadPoolTestStringArg1);
460-
StringRef argv[] = {Executable, "--gtest_filter=ThreadPoolTest.AffinityMask"};
460+
const auto *TestInfo = testing::UnitTest::GetInstance()->current_test_info();
461+
std::string Arg = (Twine("--gtest_filter=") + TestInfo->test_suite_name() +
462+
"." + TestInfo->name())
463+
.str();
464+
StringRef argv[] = {Executable, Arg};
461465

462466
// Add environment variable to the environment of the child process.
463467
int Res = setenv("LLVM_THREADPOOL_AFFINITYMASK", "1", false);
464-
ASSERT_EQ(Res, 0);
468+
ASSERT_EQ(0, Res);
465469

466470
std::string Error;
467471
bool ExecutionFailed;
@@ -470,6 +474,8 @@ TYPED_TEST(ThreadPoolTest, AffinityMask) {
470474
Affinity.set(0, 4); // Use CPUs 0,1,2,3.
471475
int Ret = sys::ExecuteAndWait(Executable, argv, {}, {}, 0, 0, &Error,
472476
&ExecutionFailed, nullptr, &Affinity);
477+
Res = setenv("LLVM_THREADPOOL_AFFINITYMASK", "", false);
478+
ASSERT_EQ(0, Res);
473479
ASSERT_EQ(0, Ret);
474480
}
475481

0 commit comments

Comments
 (0)