Skip to content

Commit d352ce0

Browse files
committed
Refactor task and test initialization methods, improve naming consistency, and clean up MPI-related imports across modules and tasks
1 parent b629680 commit d352ce0

13 files changed

Lines changed: 85 additions & 83 deletions

File tree

modules/core/perf/func_tests/perf_tests.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ TEST(perf_tests, check_perf_task_exception) {
8686
ppc::core::Perf<std::vector<uint32_t>, uint32_t> perf_analyzer(test_task);
8787

8888
// Get perf statistic
89+
// NOLINTNEXTLINE(cppcoreguidelines-avoid-goto)
8990
ASSERT_ANY_THROW(perf_analyzer.PrintPerfStatistic("check_perf_task_exception"));
9091

9192
// Create Perf attributes

modules/core/util/include/func_test_util.hpp

Lines changed: 37 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,11 @@
66

77
#include <concepts>
88
#include <csignal>
9+
#include <cstddef>
910
#include <functional>
1011
#include <string>
1112
#include <tuple>
13+
#include <utility>
1214

1315
#include "core/task/include/task.hpp"
1416
#include "core/util/include/util.hpp"
@@ -45,44 +47,44 @@ class BaseRunFuncTests : public ::testing::TestWithParam<FuncTestParam<InType, O
4547
return std::get<GTestParamIndex::kNameTest>(info.param) + "_" + Derived::PrintTestParam(test_param);
4648
}
4749

50+
protected:
51+
const std::string kUnknownTest = "unknown";
52+
const std::string kDisabledTest = "disabled";
53+
const std::string kAllTask = "_all";
54+
const std::string kMpiTask = "_mpi";
55+
4856
void ExecuteTest(FuncTestParam<InType, OutType, TestType> test_param) {
4957
const std::string& test_name = std::get<GTestParamIndex::kNameTest>(test_param);
5058

51-
validateTestName(test_name);
59+
ValidateTestName(test_name);
5260

53-
if (isTestDisabled(test_name)) {
61+
if (IsTestDisabled(test_name)) {
5462
GTEST_SKIP();
5563
}
5664

57-
if (shouldSkipNonMpiTask(test_name)) {
65+
if (ShouldSkipNonMpiTask(test_name)) {
5866
std::cerr << "kALL and kMPI tasks are not under mpirun\n";
5967
GTEST_SKIP();
6068
}
6169

62-
initializeAndRunTask(test_param);
70+
InitializeAndRunTask(test_param);
6371
}
6472

65-
private:
66-
static constexpr std::string UNKNOWN_TEST = "unknown";
67-
static constexpr std::string DISABLED_TEST = "disabled";
68-
static constexpr std::string ALL_TASK = "_all";
69-
static constexpr std::string MPI_TASK = "_mpi";
70-
71-
void validateTestName(const std::string& test_name) {
72-
EXPECT_FALSE(test_name.find(UNKNOWN_TEST) != std::string::npos);
73+
void ValidateTestName(const std::string& test_name) {
74+
EXPECT_FALSE(test_name.find(kUnknownTest) != std::string::npos);
7375
}
7476

75-
bool isTestDisabled(const std::string& test_name) { return test_name.find(DISABLED_TEST) != std::string::npos; }
77+
bool IsTestDisabled(const std::string& test_name) { return test_name.find(kDisabledTest) != std::string::npos; }
7678

77-
bool shouldSkipNonMpiTask(const std::string& test_name) {
78-
auto containsSubstring = [&](const std::string& substring) {
79+
bool ShouldSkipNonMpiTask(const std::string& test_name) {
80+
auto contains_substring = [&](const std::string& substring) {
7981
return test_name.find(substring) != std::string::npos;
8082
};
8183

82-
return !ppc::util::IsUnderMpirun() && (containsSubstring(ALL_TASK) || containsSubstring(MPI_TASK));
84+
return !ppc::util::IsUnderMpirun() && (contains_substring(kAllTask) || contains_substring(kMpiTask));
8385
}
8486

85-
void initializeAndRunTask(const FuncTestParam<InType, OutType, TestType>& test_param) {
87+
void InitializeAndRunTask(const FuncTestParam<InType, OutType, TestType>& test_param) {
8688
task_ = std::get<GTestParamIndex::kTaskGetter>(test_param)(GetTestInputData());
8789

8890
EXPECT_TRUE(task_->Validation());
@@ -92,6 +94,7 @@ class BaseRunFuncTests : public ::testing::TestWithParam<FuncTestParam<InType, O
9294
EXPECT_TRUE(CheckTestOutputData(task_->GetOutput()));
9395
}
9496

97+
private:
9598
ppc::core::TaskPtr<InType, OutType> task_;
9699
};
97100

@@ -106,21 +109,23 @@ auto ExpandToValues(const Tuple& t) {
106109
return ExpandToValuesImpl(t, std::make_index_sequence<kN>{});
107110
}
108111

109-
#define INIT_FUNC_TASK_GENERATOR(InTypeParam, SizesParam, SettingsPath) \
110-
template <typename Task, std::size_t... Is> \
111-
auto GenTaskTuplesImpl(std::index_sequence<Is...>) { \
112-
return std::make_tuple( \
113-
std::make_tuple(ppc::core::TaskGetter<Task, InTypeParam>, \
114-
std::string(ppc::util::GetNamespace<Task>()) + std::string("_") + \
115-
ppc::core::GetStringTaskType(Task::GetStaticTypeOfTask(), SettingsPath), \
116-
SizesParam[Is])...); \
117-
} \
118-
\
119-
template <typename Task> \
120-
auto TaskListGenerator() { \
121-
return GenTaskTuplesImpl<Task>(std::make_index_sequence<SizesParam.size()>{}); \
122-
}
112+
template <typename Task, typename InType, typename SizesContainer, std::size_t... Is>
113+
auto GenTaskTuplesImpl(const SizesContainer& sizes, const std::string& settings_path, std::index_sequence<Is...>) {
114+
return std::make_tuple(std::make_tuple(ppc::core::TaskGetter<Task, InType>,
115+
std::string(GetNamespace<Task>()) + "_" +
116+
ppc::core::GetStringTaskType(Task::GetStaticTypeOfTask(), settings_path),
117+
sizes[Is])...);
118+
}
119+
120+
template <typename Task, typename InType, typename SizesContainer>
121+
auto TaskListGenerator(const SizesContainer& sizes, const std::string& settings_path) {
122+
return GenTaskTuplesImpl<Task, InType>(sizes, settings_path,
123+
std::make_index_sequence<std::tuple_size_v<std::decay_t<SizesContainer>>>{});
124+
}
123125

124-
#define ADD_FUNC_TASK(TASK) TaskListGenerator<TASK>() // std::tuple<>()
126+
template <typename Task, typename InType, typename SizesContainer>
127+
constexpr auto AddFuncTask(const SizesContainer& sizes, const std::string& settings_path) {
128+
return TaskListGenerator<Task, InType>(sizes, settings_path);
129+
}
125130

126131
} // namespace ppc::util

modules/core/util/include/perf_test_util.hpp

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,16 @@
33
#include <gtest/gtest.h>
44
#include <mpi.h>
55
#include <omp.h>
6+
#include <tbb/tbb.h>
67
#include <tbb/tick_count.h>
78

89
#include <chrono>
910
#include <csignal>
1011
#include <cstddef>
1112
#include <functional>
13+
#include <sstream>
1214
#include <stdexcept>
1315
#include <string>
14-
#include <strstream>
1516
#include <tuple>
1617
#include <type_traits>
1718
#include <utility>
@@ -101,17 +102,16 @@ class BaseRunPerfTests : public ::testing::TestWithParam<PerfTestParam<InType, O
101102
ppc::core::TaskPtr<InType, OutType> task_;
102103
};
103104

104-
#define ADD_PERF_TASK(TaskType, InputTypeParam, SettingsPath) \
105-
std::tuple(std::make_tuple(ppc::core::TaskGetter<TaskType, InputTypeParam>, \
106-
std::string(ppc::util::GetNamespace<TaskType>()) + "_" + \
107-
ppc::core::GetStringTaskType(TaskType::GetStaticTypeOfTask(), SettingsPath), \
108-
ppc::core::PerfResults::TypeOfRunning::kPipeline), \
109-
std::make_tuple(ppc::core::TaskGetter<TaskType, InputTypeParam>, \
110-
std::string(ppc::util::GetNamespace<TaskType>()) + "_" + \
111-
ppc::core::GetStringTaskType(TaskType::GetStaticTypeOfTask(), SettingsPath), \
112-
ppc::core::PerfResults::TypeOfRunning::kTaskRun))
105+
template <typename TaskType, typename InputType>
106+
auto MakePerfTaskTuples(const std::string& settings_path) {
107+
const auto name = std::string(GetNamespace<TaskType>()) + "_" +
108+
ppc::core::GetStringTaskType(TaskType::GetStaticTypeOfTask(), settings_path);
113109

114-
// #define ADD_PERF_TASK(TaskType, InputTypeParam, SettingsPath) std::make_tuple()
110+
return std::make_tuple(std::make_tuple(ppc::core::TaskGetter<TaskType, InputType>, name,
111+
ppc::core::PerfResults::TypeOfRunning::kPipeline),
112+
std::make_tuple(ppc::core::TaskGetter<TaskType, InputType>, name,
113+
ppc::core::PerfResults::TypeOfRunning::kTaskRun));
114+
}
115115

116116
template <typename Tuple, std::size_t... I>
117117
auto TupleToGTestValuesImpl(Tuple&& tup, std::index_sequence<I...> /*unused*/) {
@@ -124,12 +124,9 @@ auto TupleToGTestValues(Tuple&& tup) {
124124
return TupleToGTestValuesImpl(std::forward<Tuple>(tup), std::make_index_sequence<kSize>{});
125125
}
126126

127-
#define INIT_PERF_TASK_GENERATOR(InType, EnvVarSettingsPath) \
128-
template <typename... Ts> \
129-
struct perf_tasks_type_list {}; \
130-
template <typename... Ts> \
131-
auto MakeTask(perf_tasks_type_list<Ts...>) { \
132-
return std::tuple_cat(ADD_PERF_TASK(Ts, InType, EnvVarSettingsPath)...); \
133-
}
127+
template <typename InputType, typename... TaskTypes>
128+
auto MakeAllPerfTasks(const std::string& settings_path) {
129+
return std::tuple_cat(MakePerfTaskTuples<TaskTypes, InputType>(settings_path)...);
130+
}
134131

135132
} // namespace ppc::util

modules/core/util/include/util.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
#pragma warning(disable : 4459)
1212
#endif
1313

14-
#include <nlohmann/json.hpp>
14+
#include <nlohmann/json.hpp> // NOLINT(misc-include-cleaner)
1515

1616
#ifdef _MSC_VER
1717
#pragma warning(pop)
@@ -91,6 +91,7 @@ constexpr std::string_view GetNamespace() {
9191
#endif
9292
}
9393

94+
// NOLINTNEXTLINE(misc-include-cleaner)
9495
inline std::shared_ptr<nlohmann::json> InitJSONPtr() { return std::make_shared<nlohmann::json>(); }
9596

9697
bool IsUnderMpirun();

tasks/common/runners/functional.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#include <fmt/core.h>
22
#include <gtest/gtest.h>
3+
#include <mpi.h>
34
#include <omp.h>
45

56
#include <cstdio>
@@ -8,7 +9,6 @@
89
#include <utility>
910

1011
#include "core/util/include/util.hpp"
11-
#include "mpi.h"
1212
#include "oneapi/tbb/global_control.h"
1313

1414
class UnreadMessagesDetector : public ::testing::EmptyTestEventListener {

tasks/common/runners/performance.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#include <fmt/core.h>
22
#include <gtest/gtest.h>
3+
#include <mpi.h>
34
#include <omp.h>
45

56
#include <cstdio>
@@ -8,7 +9,6 @@
89
#include <utility>
910

1011
#include "core/util/include/util.hpp"
11-
#include "mpi.h"
1212
#include "oneapi/tbb/global_control.h"
1313

1414
class UnreadMessagesDetector : public ::testing::EmptyTestEventListener {

tasks/example_processes/mpi/src/ops_mpi.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
#include "example_processes/mpi/include/ops_mpi.hpp"
22

3+
#include <mpi.h>
4+
35
#include <cmath>
46
#include <numeric>
57
#include <vector>
68

79
#include "core/util/include/util.hpp"
810
#include "example_processes/common/include/common.hpp"
9-
#include "mpi.h"
1011

1112
namespace nesterov_a_test_task_processes {
1213

tasks/example_processes/seq/src/ops_seq.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,7 @@ bool NesterovATestTaskSEQ::PreProcessingImpl() {
2323
}
2424

2525
bool NesterovATestTaskSEQ::RunImpl() {
26-
auto input = GetInput();
27-
if (input == 0) {
26+
if (GetInput() == 0) {
2827
return false;
2928
}
3029

@@ -46,7 +45,9 @@ bool NesterovATestTaskSEQ::RunImpl() {
4645
counter++;
4746
}
4847

49-
GetOutput() /= counter;
48+
if (counter != 0) {
49+
GetOutput() /= counter;
50+
}
5051
return GetOutput() > 0;
5152
}
5253

tasks/example_processes/tests/functional/main.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,9 @@ TEST_P(NesterovARunFuncTestsProcesses, MatmulFromPic) { ExecuteTest(GetParam());
6464

6565
const std::array<TestType, 3> kTestParam = {std::make_tuple(3, "3"), std::make_tuple(5, "5"), std::make_tuple(7, "7")};
6666

67-
INIT_FUNC_TASK_GENERATOR(InType, kTestParam, PPC_SETTINGS_example_processes)
68-
69-
const auto kTestTasksList = std::tuple_cat(ADD_FUNC_TASK(NesterovATestTaskMPI), ADD_FUNC_TASK(NesterovATestTaskSEQ));
67+
const auto kTestTasksList =
68+
std::tuple_cat(ppc::util::AddFuncTask<NesterovATestTaskMPI, InType>(kTestParam, PPC_SETTINGS_example_processes),
69+
ppc::util::AddFuncTask<NesterovATestTaskSEQ, InType>(kTestParam, PPC_SETTINGS_example_processes));
7070

7171
INSTANTIATE_TEST_SUITE_P_NOLINT(PicMatrixTests, NesterovARunFuncTestsProcesses,
7272
ppc::util::ExpandToValues(kTestTasksList),

tasks/example_processes/tests/performance/main.cpp

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,12 @@ class ExampleRunPerfTestProcesses : public ppc::util::BaseRunPerfTests<InType, O
2121
InType GetTestInputData() final { return input_data_; }
2222
};
2323

24-
INIT_PERF_TASK_GENERATOR(InType, PPC_SETTINGS_example_processes)
25-
26-
using PerfTasks = perf_tasks_type_list<NesterovATestTaskMPI, NesterovATestTaskSEQ>;
27-
28-
const auto kAllPerfTasks = std::tuple_cat(MakeTask(PerfTasks{}));
29-
3024
TEST_P(ExampleRunPerfTestProcesses, RunPerfModes) { ExecuteTest(GetParam()); }
3125

32-
INSTANTIATE_TEST_SUITE_P_NOLINT(RunModeTests, ExampleRunPerfTestProcesses, ppc::util::TupleToGTestValues(kAllPerfTasks),
33-
ExampleRunPerfTestProcesses::CustomPerfTestName);
26+
const auto kAllPerfTasks =
27+
ppc::util::MakeAllPerfTasks<InType, NesterovATestTaskMPI, NesterovATestTaskSEQ>(PPC_SETTINGS_example_processes);
28+
29+
INSTANTIATE_TEST_SUITE_P(RunModeTests, ExampleRunPerfTestProcesses, ppc::util::TupleToGTestValues(kAllPerfTasks),
30+
ExampleRunPerfTestProcesses::CustomPerfTestName);
3431

3532
} // namespace nesterov_a_test_task_processes

0 commit comments

Comments
 (0)