Skip to content

Commit 3837166

Browse files
committed
Refactor for modern C++ features and cleanup.
Replaced legacy I/O functions (`fprintf`, `printf`) with modern `<print>` utilities for improved readability and safety. Updated function signatures to use `const` references where appropriate and removed redundant `else` clauses. Simplified the valgrind command by removing unused suppression file, and deleted the obsolete `valgrind.supp` file.
1 parent c75efb6 commit 3837166

5 files changed

Lines changed: 16 additions & 37 deletions

File tree

modules/core/task/include/task.hpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,20 +25,19 @@ enum StatusOfTask : uint8_t { kEnabled, kDisabled };
2525
inline std::string GetStringTaskStatus(StatusOfTask status_of_task) {
2626
if (status_of_task == kDisabled) {
2727
return "disabled";
28-
} else {
29-
return "enabled";
3028
}
29+
return "enabled";
3130
}
3231

33-
inline std::string GetStringTaskType(TypeOfTask type_of_task, std::string settings_file_path) {
32+
inline std::string GetStringTaskType(TypeOfTask type_of_task, const std::string &settings_file_path) {
3433
std::ifstream file(settings_file_path);
3534
if (!file.is_open()) {
3635
throw std::runtime_error("Failed to open file settings.json");
3736
}
3837
nlohmann::json list_settings;
3938
file >> list_settings;
4039

41-
auto to_type_str = [&](std::string type) -> std::string {
40+
auto to_type_str = [&](const std::string &type) -> std::string {
4241
return type + "_" + std::string(list_settings["tasks"][type]);
4342
};
4443

scripts/run_tests.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,7 @@ def __init__(self):
3131
self.__ppc_env = None
3232
self.work_dir = None
3333

34-
suppression_file = Path(self.__get_project_path()) / "valgrind.supp"
35-
self.valgrind_cmd = (f"valgrind --suppressions={suppression_file} "
36-
f"--error-exitcode=1 --leak-check=full --show-leak-kinds=all")
34+
self.valgrind_cmd = "valgrind --error-exitcode=1 --leak-check=full --show-leak-kinds=all"
3735

3836
if platform.system() == "Windows":
3937
self.mpi_exec = "mpiexec"

tasks/runners/functional.cpp

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
#include <omp.h>
44

55
#include <cstdio>
6-
#include <cstdlib>
76
#include <memory>
7+
#include <print>
88
#include <string>
99
#include <utility>
1010

@@ -27,12 +27,11 @@ class UnreadMessagesDetector : public ::testing::EmptyTestEventListener {
2727
MPI_Iprobe(MPI_ANY_SOURCE, MPI_ANY_TAG, MPI_COMM_WORLD, &flag, &status);
2828

2929
if (flag != 0) {
30-
fprintf(
30+
std::println(
3131
stderr,
32-
"[ PROCESS %d ] [ FAILED ] %s.%s: MPI message queue has an unread message from process %d with tag %d\n",
32+
"[ PROCESS {} ] [ FAILED ] {}.{}: MPI message queue has an unread message from process {} with tag {}",
3333
rank, "test_suite_name", "test_name", status.MPI_SOURCE, status.MPI_TAG);
34-
MPI_Finalize();
35-
std::terminate();
34+
exit(EXIT_FAILURE); // NOLINT
3635
}
3736

3837
MPI_Barrier(MPI_COMM_WORLD);
@@ -65,7 +64,7 @@ class WorkerTestFailurePrinter : public ::testing::EmptyTestEventListener {
6564
static void PrintProcessRank() {
6665
int rank = -1;
6766
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
68-
printf(" [ PROCESS %d ] ", rank);
67+
std::print(" [ PROCESS {} ] ", rank);
6968
}
7069

7170
std::shared_ptr<::testing::TestEventListener> base_;

tasks/runners/performance.cpp

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
#include <omp.h>
44

55
#include <cstdio>
6-
#include <cstdlib>
76
#include <memory>
7+
#include <print>
88
#include <string>
99
#include <utility>
1010

@@ -27,12 +27,11 @@ class UnreadMessagesDetector : public ::testing::EmptyTestEventListener {
2727
MPI_Iprobe(MPI_ANY_SOURCE, MPI_ANY_TAG, MPI_COMM_WORLD, &flag, &status);
2828

2929
if (flag != 0) {
30-
fprintf(
31-
stderr,
32-
"[ PROCESS %d ] [ FAILED ] %s.%s: MPI message queue has an unread message from process %d with tag %d\n",
33-
rank, "test_suite_name", "test_name", status.MPI_SOURCE, status.MPI_TAG);
34-
MPI_Finalize();
35-
std::terminate();
30+
std::println(stderr,
31+
"[ PROCESS {} ] [ FAILED ] MPI message queue has an unread message from process {} with tag {}",
32+
rank, status.MPI_SOURCE, status.MPI_TAG);
33+
34+
exit(EXIT_FAILURE); // NOLINT
3635
}
3736

3837
MPI_Barrier(MPI_COMM_WORLD);
@@ -65,7 +64,7 @@ class WorkerTestFailurePrinter : public ::testing::EmptyTestEventListener {
6564
static void PrintProcessRank() {
6665
int rank = -1;
6766
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
68-
printf(" [ PROCESS %d ] ", rank);
67+
std::print(" [ PROCESS {} ] ", rank);
6968
}
7069

7170
std::shared_ptr<::testing::TestEventListener> base_;

valgrind.supp

Lines changed: 0 additions & 16 deletions
This file was deleted.

0 commit comments

Comments
 (0)