Skip to content

Commit d040851

Browse files
allnesaobolensk
andauthored
[HOT FIX] Stabilize macOS CI tests: OpenMP linking, MPI env, per-test isolation (#669)
- MPI runs: propagate PPC_NUM_THREADS and OMP_NUM_THREADS via mpirun -x …; fix gtest filters for _all_/_mpi_ across functional/perf runs. - Per-test isolation: add ScopedPerTestEnv that sets PPC_TEST_UID and PPC_TEST_TMPDIR; integrated into functional and performance test runners. --------- Co-authored-by: Arseniy Obolenskiy <[email protected]>
1 parent c83f0ef commit d040851

File tree

4 files changed

+69
-3
lines changed

4 files changed

+69
-3
lines changed

modules/util/include/func_test_util.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ class BaseRunFuncTests : public ::testing::TestWithParam<FuncTestParam<InType, O
6161

6262
ValidateTestName(test_name);
6363

64+
const auto test_env_scope = ppc::util::test::MakePerTestEnvForCurrentGTest(test_name);
65+
6466
if (IsTestDisabled(test_name)) {
6567
GTEST_SKIP();
6668
}

modules/util/include/perf_test_util.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,8 @@ class BaseRunPerfTests : public ::testing::TestWithParam<PerfTestParam<InType, O
7777
GTEST_SKIP();
7878
}
7979

80+
const auto test_env_scope = ppc::util::test::MakePerTestEnvForCurrentGTest(test_name);
81+
8082
task_ = task_getter(GetTestInputData());
8183
ppc::performance::Perf perf(task_);
8284
ppc::performance::PerfAttr perf_attr;

modules/util/include/util.hpp

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,16 @@
11
#pragma once
22

3+
#include <algorithm>
34
#include <atomic>
5+
#include <cctype>
46
#include <cstdint>
57
#include <cstdlib>
8+
#include <filesystem>
69
#include <memory>
10+
#include <sstream>
711
#include <string>
12+
#include <string_view>
13+
#include <system_error>
814
#include <typeinfo>
915
#ifdef __GNUG__
1016
# include <cxxabi.h>
@@ -17,6 +23,9 @@
1723
# pragma warning(disable : 4459)
1824
#endif
1925

26+
#include <gtest/gtest.h>
27+
28+
#include <libenvpp/detail/environment.hpp>
2029
#include <nlohmann/json.hpp>
2130

2231
/// @brief JSON namespace used for settings and config parsing.
@@ -90,4 +99,57 @@ inline std::shared_ptr<nlohmann::json> InitJSONPtr() {
9099

91100
bool IsUnderMpirun();
92101

102+
namespace test {
103+
104+
[[nodiscard]] inline std::string SanitizeToken(std::string_view token_sv) {
105+
std::string token{token_sv};
106+
auto is_allowed = [](char c) {
107+
return std::isalnum(static_cast<unsigned char>(c)) || c == '_' || c == '-' || c == '.';
108+
};
109+
std::ranges::replace(token, ' ', '_');
110+
for (char &ch : token) {
111+
if (!is_allowed(ch)) {
112+
ch = '_';
113+
}
114+
}
115+
return token;
116+
}
117+
118+
class ScopedPerTestEnv {
119+
public:
120+
explicit ScopedPerTestEnv(const std::string &token)
121+
: set_uid_("PPC_TEST_UID", token), set_tmp_("PPC_TEST_TMPDIR", CreateTmpDir(token)) {}
122+
123+
private:
124+
static std::string CreateTmpDir(const std::string &token) {
125+
namespace fs = std::filesystem;
126+
const fs::path tmp = fs::temp_directory_path() / (std::string("ppc_test_") + token);
127+
std::error_code ec;
128+
fs::create_directories(tmp, ec);
129+
(void)ec;
130+
return tmp.string();
131+
}
132+
133+
env::detail::set_scoped_environment_variable set_uid_;
134+
env::detail::set_scoped_environment_variable set_tmp_;
135+
};
136+
137+
[[nodiscard]] inline std::string MakeCurrentGTestToken(std::string_view fallback_name) {
138+
const auto *unit = ::testing::UnitTest::GetInstance();
139+
const auto *info = (unit != nullptr) ? unit->current_test_info() : nullptr;
140+
std::ostringstream os;
141+
if (info != nullptr) {
142+
os << info->test_suite_name() << "." << info->name();
143+
} else {
144+
os << fallback_name;
145+
}
146+
return SanitizeToken(os.str());
147+
}
148+
149+
inline ScopedPerTestEnv MakePerTestEnvForCurrentGTest(std::string_view fallback_name) {
150+
return ScopedPerTestEnv(MakeCurrentGTestToken(fallback_name));
151+
}
152+
153+
} // namespace test
154+
93155
} // namespace ppc::util

scripts/run_tests.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ def run_processes(self, additional_mpi_args):
142142
self.__run_exec(
143143
mpi_running
144144
+ [str(self.work_dir / "ppc_func_tests")]
145-
+ self.__get_gtest_settings(1, "_" + task_type)
145+
+ self.__get_gtest_settings(1, "_" + task_type + "_")
146146
)
147147

148148
def run_performance(self):
@@ -152,13 +152,13 @@ def run_performance(self):
152152
self.__run_exec(
153153
mpi_running
154154
+ [str(self.work_dir / "ppc_perf_tests")]
155-
+ self.__get_gtest_settings(1, "_" + task_type)
155+
+ self.__get_gtest_settings(1, "_" + task_type + "_")
156156
)
157157

158158
for task_type in ["omp", "seq", "stl", "tbb"]:
159159
self.__run_exec(
160160
[str(self.work_dir / "ppc_perf_tests")]
161-
+ self.__get_gtest_settings(1, "_" + task_type)
161+
+ self.__get_gtest_settings(1, "_" + task_type + "_")
162162
)
163163

164164

0 commit comments

Comments
 (0)