Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[![Build application](https://github.com/learning-process/ppc-2025-processes-informatics/actions/workflows/main.yml/badge.svg?branch=master)](https://github.com/learning-process/ppc-2025-processes-informatics/actions/workflows/main.yml)
[![Pages](https://github.com/learning-process/ppc-2025-processes-informatics/actions/workflows/pages.yml/badge.svg?branch=master)](https://github.com/learning-process/ppc-2025-processes-informatics/actions/workflows/pages.yml)
[![Pages](https://github.com/learning-process/parallel_programming_course/actions/workflows/pages.yml/badge.svg?branch=master)](https://github.com/learning-process/parallel_programming_course/actions/workflows/pages.yml)
[![CodeQL](https://github.com/learning-process/ppc-2025-processes-informatics/actions/workflows/codeql.yml/badge.svg?branch=master)](https://github.com/learning-process/ppc-2025-processes-informatics/actions/workflows/codeql.yml)
[![codecov](https://codecov.io/gh/learning-process/ppc-2025-processes-informatics/graph/badge.svg?token=qCOtqeFyIz)](https://codecov.io/gh/learning-process/ppc-2025-processes-informatics)
[![OpenSSF Scorecard](https://api.scorecard.dev/projects/github.com/learning-process/ppc-2025-processes-informatics/badge)](https://scorecard.dev/viewer/?uri=github.com/learning-process/ppc-2025-processes-informatics)
Expand Down
8 changes: 4 additions & 4 deletions cmake/gtest.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ ExternalProject_Add(
$<$<BOOL:MSVC>:-Dgtest_force_shared_crt=ON>
BUILD_COMMAND
"${CMAKE_COMMAND}" --build
"${CMAKE_CURRENT_BINARY_DIR}/ppc_googletest/build" --config
${CMAKE_BUILD_TYPE} --parallel
"${CMAKE_CURRENT_BINARY_DIR}/ppc_googletest/build" --config $<CONFIG>
--parallel
INSTALL_COMMAND
"${CMAKE_COMMAND}" --install
"${CMAKE_CURRENT_BINARY_DIR}/ppc_googletest/build" --prefix
"${CMAKE_CURRENT_BINARY_DIR}/ppc_googletest/install")
"${CMAKE_CURRENT_BINARY_DIR}/ppc_googletest/build" --config $<CONFIG>
--prefix "${CMAKE_CURRENT_BINARY_DIR}/ppc_googletest/install")

function(ppc_link_gtest exec_func_lib)
# Add external project include directories
Expand Down
4 changes: 2 additions & 2 deletions cmake/json.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ ExternalProject_Add(
-DJSON_BuildTests=OFF
BUILD_COMMAND
"${CMAKE_COMMAND}" --build "${CMAKE_CURRENT_BINARY_DIR}/ppc_json/build"
--config ${CMAKE_BUILD_TYPE} --parallel
--config $<CONFIG> --parallel
INSTALL_COMMAND
"${CMAKE_COMMAND}" --install "${CMAKE_CURRENT_BINARY_DIR}/ppc_json/build"
--prefix "${CMAKE_CURRENT_BINARY_DIR}/ppc_json/install")
--config $<CONFIG> --prefix "${CMAKE_CURRENT_BINARY_DIR}/ppc_json/install")

function(ppc_link_json exec_func_lib)
# Add external project include directories
Expand Down
9 changes: 5 additions & 4 deletions cmake/libenvpp.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ ExternalProject_Add(
-DLIBENVPP_EXAMPLES=OFF
BUILD_COMMAND
"${CMAKE_COMMAND}" --build "${CMAKE_CURRENT_BINARY_DIR}/ppc_libenvpp/build"
--config ${CMAKE_BUILD_TYPE} --parallel
--config $<CONFIG> --parallel
INSTALL_COMMAND
"${CMAKE_COMMAND}" --install
"${CMAKE_CURRENT_BINARY_DIR}/ppc_libenvpp/build" --prefix
"${CMAKE_CURRENT_BINARY_DIR}/ppc_libenvpp/install")
"${CMAKE_CURRENT_BINARY_DIR}/ppc_libenvpp/build" --config $<CONFIG>
--prefix "${CMAKE_CURRENT_BINARY_DIR}/ppc_libenvpp/install")

string(TOLOWER "${CMAKE_BUILD_TYPE}" cmake_build_type_lower)
if(cmake_build_type_lower STREQUAL "debug")
Expand Down Expand Up @@ -48,5 +48,6 @@ function(ppc_link_envpp exec_func_lib)
target_link_directories(${exec_func_lib} PUBLIC
"${CMAKE_BINARY_DIR}/ppc_libenvpp/build")
target_link_libraries(${exec_func_lib} PUBLIC ${PPC_ENVPP_LIB_NAME})
target_link_libraries(${exec_func_lib} PUBLIC ${PPC_FMT_LIB_NAME})
target_link_libraries(${exec_func_lib} PUBLIC $<$<CONFIG:Debug>:fmtd>
$<$<NOT:$<CONFIG:Debug>>:fmt>)
endfunction()
4 changes: 2 additions & 2 deletions cmake/onetbb.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ if(NOT ENABLE_SYSTEM_TBB)
-DTBB_TEST=OFF
BUILD_COMMAND
"${CMAKE_COMMAND}" --build "${CMAKE_CURRENT_BINARY_DIR}/ppc_onetbb/build"
--config ${CMAKE_BUILD_TYPE} --parallel
--config $<CONFIG> --parallel
INSTALL_COMMAND
"${CMAKE_COMMAND}" --install
"${CMAKE_CURRENT_BINARY_DIR}/ppc_onetbb/build" --prefix
"${CMAKE_CURRENT_BINARY_DIR}/ppc_onetbb/build" --config $<CONFIG> --prefix
"${CMAKE_CURRENT_BINARY_DIR}/ppc_onetbb/install"
TEST_COMMAND ${ppc_onetbb_TEST_COMMAND})

Expand Down
73 changes: 71 additions & 2 deletions modules/runners/src/runners.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,17 @@
#include <gtest/gtest.h>
#include <mpi.h>

#include <chrono>
#include <cstdint>
#include <cstdlib>
#include <exception>
#include <format>
#include <iostream>
#include <memory>
#include <random>
#include <stdexcept>
#include <string>
#include <string_view>

#include "oneapi/tbb/global_control.h"
#include "util/include/util.hpp"
Expand Down Expand Up @@ -48,6 +53,8 @@ void WorkerTestFailurePrinter::OnTestEnd(const ::testing::TestInfo &test_info) {
}
PrintProcessRank();
base_->OnTestEnd(test_info);
// Abort the whole MPI job on any test failure to avoid other ranks hanging on barriers.
MPI_Abort(MPI_COMM_WORLD, EXIT_FAILURE);
}

void WorkerTestFailurePrinter::OnTestPartResult(const ::testing::TestPartResult &test_part_result) {
Expand All @@ -73,6 +80,63 @@ int RunAllTests() {
}
return status;
}

void SyncGTestSeed() {
unsigned int seed = 0;
int rank = -1;
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
if (rank == 0) {
try {
seed = std::random_device{}();
} catch (...) {
seed = 0;
}
if (seed == 0) {
const auto now = static_cast<std::uint64_t>(std::chrono::steady_clock::now().time_since_epoch().count());
seed = static_cast<unsigned int>(((now & 0x7fffffffULL) | 1ULL));
}
}
MPI_Bcast(&seed, 1, MPI_UNSIGNED, 0, MPI_COMM_WORLD);
::testing::GTEST_FLAG(random_seed) = static_cast<int>(seed);
}

void SyncGTestFilter() {
int rank = -1;
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
std::string filter = (rank == 0) ? ::testing::GTEST_FLAG(filter) : std::string{};
int len = static_cast<int>(filter.size());
MPI_Bcast(&len, 1, MPI_INT, 0, MPI_COMM_WORLD);
if (rank != 0) {
filter.resize(static_cast<std::size_t>(len));
}
if (len > 0) {
MPI_Bcast(filter.data(), len, MPI_CHAR, 0, MPI_COMM_WORLD);
}
::testing::GTEST_FLAG(filter) = filter;
}

bool HasFlag(int argc, char **argv, std::string_view flag) {
for (int i = 1; i < argc; ++i) {
if (argv[i] != nullptr && std::string_view(argv[i]) == flag) {
return true;
}
}
return false;
}

int RunAllTestsSafely() {
try {
return RunAllTests();
} catch (const std::exception &e) {
std::cerr << std::format("[ ERROR ] Exception after tests: {}", e.what()) << '\n';
MPI_Abort(MPI_COMM_WORLD, EXIT_FAILURE);
return EXIT_FAILURE;
} catch (...) {
std::cerr << "[ ERROR ] Unknown exception after tests" << '\n';
MPI_Abort(MPI_COMM_WORLD, EXIT_FAILURE);
return EXIT_FAILURE;
}
}
} // namespace

int Init(int argc, char **argv) {
Expand All @@ -88,16 +152,21 @@ int Init(int argc, char **argv) {

::testing::InitGoogleTest(&argc, argv);

// Synchronize GoogleTest internals across ranks to avoid divergence
SyncGTestSeed();
SyncGTestFilter();

auto &listeners = ::testing::UnitTest::GetInstance()->listeners();
int rank = -1;
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
if (rank != 0 && (argc < 2 || argv[1] != std::string("--print-workers"))) {
const bool print_workers = HasFlag(argc, argv, "--print-workers");
if (rank != 0 && !print_workers) {
auto *listener = listeners.Release(listeners.default_result_printer());
listeners.Append(new WorkerTestFailurePrinter(std::shared_ptr<::testing::TestEventListener>(listener)));
}
listeners.Append(new UnreadMessagesDetector());

auto status = RunAllTests();
const int status = RunAllTestsSafely();

const int finalize_res = MPI_Finalize();
if (finalize_res != MPI_SUCCESS) {
Expand Down
2 changes: 2 additions & 0 deletions modules/util/include/func_test_util.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ class BaseRunFuncTests : public ::testing::TestWithParam<FuncTestParam<InType, O

ValidateTestName(test_name);

const auto test_env_scope = ppc::util::test::MakePerTestEnvForCurrentGTest(test_name);

if (IsTestDisabled(test_name)) {
GTEST_SKIP();
}
Expand Down
2 changes: 2 additions & 0 deletions modules/util/include/perf_test_util.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ class BaseRunPerfTests : public ::testing::TestWithParam<PerfTestParam<InType, O
GTEST_SKIP();
}

const auto test_env_scope = ppc::util::test::MakePerTestEnvForCurrentGTest(test_name);

task_ = task_getter(GetTestInputData());
ppc::performance::Perf perf(task_);
ppc::performance::PerfAttr perf_attr;
Expand Down
76 changes: 76 additions & 0 deletions modules/util/include/util.hpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
#pragma once

#include <algorithm>
#include <array>
#include <atomic>
#include <cctype>
#include <cstdint>
#include <cstdlib>
#include <filesystem>
#include <memory>
#include <sstream>
#include <string>
#include <string_view>
#include <system_error>
#include <typeinfo>
#ifdef __GNUG__
# include <cxxabi.h>
Expand All @@ -17,6 +24,10 @@
# pragma warning(disable : 4459)
#endif

#include <gtest/gtest.h>

#include <libenvpp/detail/environment.hpp>
#include <libenvpp/detail/get.hpp>
#include <nlohmann/json.hpp>

/// @brief JSON namespace used for settings and config parsing.
Expand Down Expand Up @@ -90,4 +101,69 @@ inline std::shared_ptr<nlohmann::json> InitJSONPtr() {

bool IsUnderMpirun();

namespace test {

[[nodiscard]] inline std::string SanitizeToken(std::string_view token_sv) {
std::string token{token_sv};
auto is_allowed = [](char c) {
return std::isalnum(static_cast<unsigned char>(c)) || c == '_' || c == '-' || c == '.';
};
std::ranges::replace(token, ' ', '_');
for (char &ch : token) {
if (!is_allowed(ch)) {
ch = '_';
}
}
return token;
}

class ScopedPerTestEnv {
public:
explicit ScopedPerTestEnv(const std::string &token)
: set_uid_("PPC_TEST_UID", token), set_tmp_("PPC_TEST_TMPDIR", CreateTmpDir(token)) {}

private:
static std::string CreateTmpDir(const std::string &token) {
namespace fs = std::filesystem;
auto make_rank_suffix = []() -> std::string {
// Derive rank from common MPI env vars without including MPI headers
constexpr std::array<std::string_view, 5> kRankVars = {"OMPI_COMM_WORLD_RANK", "PMI_RANK", "PMIX_RANK",
"SLURM_PROCID", "MSMPI_RANK"};
for (auto name : kRankVars) {
if (auto r = env::get<int>(name); r.has_value() && r.value() >= 0) {
return std::string("_rank_") + std::to_string(r.value());
}
}
return std::string{};
};
const std::string rank_suffix = IsUnderMpirun() ? make_rank_suffix() : std::string{};
const fs::path tmp = fs::temp_directory_path() / (std::string("ppc_test_") + token + rank_suffix);
std::error_code ec;
fs::create_directories(tmp, ec);
(void)ec;
return tmp.string();
}

env::detail::set_scoped_environment_variable set_uid_;
env::detail::set_scoped_environment_variable set_tmp_;
};

[[nodiscard]] inline std::string MakeCurrentGTestToken(std::string_view fallback_name) {
const auto *unit = ::testing::UnitTest::GetInstance();
const auto *info = (unit != nullptr) ? unit->current_test_info() : nullptr;
std::ostringstream os;
if (info != nullptr) {
os << info->test_suite_name() << "." << info->name();
} else {
os << fallback_name;
}
return SanitizeToken(os.str());
}

inline ScopedPerTestEnv MakePerTestEnvForCurrentGTest(std::string_view fallback_name) {
return ScopedPerTestEnv(MakeCurrentGTestToken(fallback_name));
}

} // namespace test

} // namespace ppc::util
6 changes: 3 additions & 3 deletions scoreboard/data/deadlines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ threads:

processes:
# Use integer offsets for tasks; default 0.
task_1: 0
task_2: 0
task_3: 0
task_1: 17
task_2: 17
task_3: 17
Loading
Loading