Skip to content

Commit 1472579

Browse files
committed
Refactor test suite instantiations, consolidate test name utilities, and streamline MPI-related imports and logic
1 parent d352ce0 commit 1472579

8 files changed

Lines changed: 48 additions & 40 deletions

File tree

modules/core/util/include/func_test_util.hpp

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,10 @@
88
#include <csignal>
99
#include <cstddef>
1010
#include <functional>
11+
#include <iostream>
1112
#include <string>
1213
#include <tuple>
14+
#include <type_traits>
1315
#include <utility>
1416

1517
#include "core/task/include/task.hpp"
@@ -48,11 +50,6 @@ class BaseRunFuncTests : public ::testing::TestWithParam<FuncTestParam<InType, O
4850
}
4951

5052
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-
5653
void ExecuteTest(FuncTestParam<InType, OutType, TestType> test_param) {
5754
const std::string& test_name = std::get<GTestParamIndex::kNameTest>(test_param);
5855

@@ -70,18 +67,16 @@ class BaseRunFuncTests : public ::testing::TestWithParam<FuncTestParam<InType, O
7067
InitializeAndRunTask(test_param);
7168
}
7269

73-
void ValidateTestName(const std::string& test_name) {
74-
EXPECT_FALSE(test_name.find(kUnknownTest) != std::string::npos);
75-
}
70+
void ValidateTestName(const std::string& test_name) { EXPECT_FALSE(test_name.find("unknown") != std::string::npos); }
7671

77-
bool IsTestDisabled(const std::string& test_name) { return test_name.find(kDisabledTest) != std::string::npos; }
72+
bool IsTestDisabled(const std::string& test_name) { return test_name.find("disabled") != std::string::npos; }
7873

7974
bool ShouldSkipNonMpiTask(const std::string& test_name) {
8075
auto contains_substring = [&](const std::string& substring) {
8176
return test_name.find(substring) != std::string::npos;
8277
};
8378

84-
return !ppc::util::IsUnderMpirun() && (contains_substring(kAllTask) || contains_substring(kMpiTask));
79+
return !ppc::util::IsUnderMpirun() && (contains_substring("_all") || contains_substring("_mpi"));
8580
}
8681

8782
void InitializeAndRunTask(const FuncTestParam<InType, OutType, TestType>& test_param) {
@@ -110,7 +105,8 @@ auto ExpandToValues(const Tuple& t) {
110105
}
111106

112107
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...>) {
108+
auto GenTaskTuplesImpl(const SizesContainer& sizes, const std::string& settings_path,
109+
std::index_sequence<Is...> /*unused*/) {
114110
return std::make_tuple(std::make_tuple(ppc::core::TaskGetter<Task, InType>,
115111
std::string(GetNamespace<Task>()) + "_" +
116112
ppc::core::GetStringTaskType(Task::GetStaticTypeOfTask(), settings_path),

modules/core/util/include/perf_test_util.hpp

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

33
#include <gtest/gtest.h>
4-
#include <mpi.h>
54
#include <omp.h>
6-
#include <tbb/tbb.h>
7-
#include <tbb/tick_count.h>
85

96
#include <chrono>
107
#include <csignal>
@@ -23,6 +20,9 @@
2320

2421
namespace ppc::util {
2522

23+
double GetTimeMPI();
24+
int GetMPIRank();
25+
2626
template <typename InType, typename OutType>
2727
using PerfTestParam = std::tuple<std::function<ppc::core::TaskPtr<InType, OutType>(InType)>, std::string,
2828
ppc::core::PerfResults::TypeOfRunning>;
@@ -40,18 +40,16 @@ class BaseRunPerfTests : public ::testing::TestWithParam<PerfTestParam<InType, O
4040
virtual InType GetTestInputData() = 0;
4141

4242
virtual void SetPerfAttributes(ppc::core::PerfAttr& perf_attrs) {
43-
if (task_->GetDynamicTypeOfTask() == ppc::core::TypeOfTask::kTBB) {
44-
const tbb::tick_count t0 = tbb::tick_count::now();
45-
perf_attrs.current_timer = [t0] { return (tbb::tick_count::now() - t0).seconds(); };
46-
} else if (task_->GetDynamicTypeOfTask() == ppc::core::TypeOfTask::kMPI ||
47-
task_->GetDynamicTypeOfTask() == ppc::core::TypeOfTask::kALL) {
48-
const double t0 = MPI_Wtime();
49-
perf_attrs.current_timer = [t0] { return MPI_Wtime() - t0; };
43+
if (task_->GetDynamicTypeOfTask() == ppc::core::TypeOfTask::kMPI ||
44+
task_->GetDynamicTypeOfTask() == ppc::core::TypeOfTask::kALL) {
45+
const double t0 = GetTimeMPI();
46+
perf_attrs.current_timer = [t0] { return GetTimeMPI() - t0; };
5047
} else if (task_->GetDynamicTypeOfTask() == ppc::core::TypeOfTask::kOMP) {
5148
const double t0 = omp_get_wtime();
5249
perf_attrs.current_timer = [t0] { return omp_get_wtime() - t0; };
5350
} else if (task_->GetDynamicTypeOfTask() == ppc::core::TypeOfTask::kSEQ ||
54-
task_->GetDynamicTypeOfTask() == ppc::core::TypeOfTask::kSTL) {
51+
task_->GetDynamicTypeOfTask() == ppc::core::TypeOfTask::kSTL ||
52+
task_->GetDynamicTypeOfTask() == ppc::core::TypeOfTask::kTBB) {
5553
const auto t0 = std::chrono::high_resolution_clock::now();
5654
perf_attrs.current_timer = [&] {
5755
auto now = std::chrono::high_resolution_clock::now();
@@ -88,9 +86,7 @@ class BaseRunPerfTests : public ::testing::TestWithParam<PerfTestParam<InType, O
8886
throw std::runtime_error(err_msg.str().c_str());
8987
}
9088

91-
int rank = -1;
92-
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
93-
if (rank == 0) {
89+
if (GetMPIRank() == 0) {
9490
perf.PrintPerfStatistic(test_name);
9591
}
9692

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#include <mpi.h>
2+
3+
#include "core/util/include/perf_test_util.hpp"
4+
5+
double ppc::util::GetTimeMPI() { return MPI_Wtime(); }
6+
7+
int ppc::util::GetMPIRank() {
8+
int rank = -1;
9+
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
10+
return rank;
11+
}

tasks/example_processes/mpi/include/ops_mpi.hpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
#pragma once
22

3-
#include <vector>
4-
53
#include "core/task/include/task.hpp"
64
#include "example_processes/common/include/common.hpp"
75

tasks/example_processes/tests/functional/main.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,11 @@ const auto kTestTasksList =
6868
std::tuple_cat(ppc::util::AddFuncTask<NesterovATestTaskMPI, InType>(kTestParam, PPC_SETTINGS_example_processes),
6969
ppc::util::AddFuncTask<NesterovATestTaskSEQ, InType>(kTestParam, PPC_SETTINGS_example_processes));
7070

71-
INSTANTIATE_TEST_SUITE_P_NOLINT(PicMatrixTests, NesterovARunFuncTestsProcesses,
72-
ppc::util::ExpandToValues(kTestTasksList),
73-
NesterovARunFuncTestsProcesses::PrintFuncTestName<NesterovARunFuncTestsProcesses>);
71+
const auto kGtestValues = ppc::util::ExpandToValues(kTestTasksList);
72+
73+
const auto kPerfTestName = NesterovARunFuncTestsProcesses::PrintFuncTestName<NesterovARunFuncTestsProcesses>;
74+
75+
INSTANTIATE_TEST_SUITE_P_NOLINT(PicMatrixTests, NesterovARunFuncTestsProcesses, kGtestValues, kPerfTestName);
7476

7577
} // namespace
7678

tasks/example_processes/tests/performance/main.cpp

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

55
#include "core/util/include/perf_test_util.hpp"
6-
#include "core/util/include/util.hpp"
76
#include "example_processes/common/include/common.hpp"
87
#include "example_processes/mpi/include/ops_mpi.hpp"
98
#include "example_processes/seq/include/ops_seq.hpp"
@@ -26,7 +25,10 @@ TEST_P(ExampleRunPerfTestProcesses, RunPerfModes) { ExecuteTest(GetParam()); }
2625
const auto kAllPerfTasks =
2726
ppc::util::MakeAllPerfTasks<InType, NesterovATestTaskMPI, NesterovATestTaskSEQ>(PPC_SETTINGS_example_processes);
2827

29-
INSTANTIATE_TEST_SUITE_P(RunModeTests, ExampleRunPerfTestProcesses, ppc::util::TupleToGTestValues(kAllPerfTasks),
30-
ExampleRunPerfTestProcesses::CustomPerfTestName);
28+
const auto kGtestValues = ppc::util::TupleToGTestValues(kAllPerfTasks);
29+
30+
const auto kPerfTestName = ExampleRunPerfTestProcesses::CustomPerfTestName;
31+
32+
INSTANTIATE_TEST_SUITE_P(RunModeTests, ExampleRunPerfTestProcesses, kGtestValues, kPerfTestName);
3133

3234
} // namespace nesterov_a_test_task_processes

tasks/example_threads/tests/functional/main.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,11 @@ const auto kTestTasksList =
7474
ppc::util::AddFuncTask<NesterovATestTaskSTL, InType>(kTestParam, PPC_SETTINGS_example_threads),
7575
ppc::util::AddFuncTask<NesterovATestTaskTBB, InType>(kTestParam, PPC_SETTINGS_example_threads));
7676

77-
INSTANTIATE_TEST_SUITE_P_NOLINT(PicMatrixTests, NesterovARunFuncTestsThreads, ppc::util::ExpandToValues(kTestTasksList),
78-
NesterovARunFuncTestsThreads::PrintFuncTestName<NesterovARunFuncTestsThreads>);
77+
const auto kGtestValues = ppc::util::ExpandToValues(kTestTasksList);
78+
79+
const auto kPerfTestName = NesterovARunFuncTestsThreads::PrintFuncTestName<NesterovARunFuncTestsThreads>;
80+
81+
INSTANTIATE_TEST_SUITE_P_NOLINT(PicMatrixTests, NesterovARunFuncTestsThreads, kGtestValues, kPerfTestName);
7982

8083
} // namespace
8184

tasks/example_threads/tests/performance/main.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
#include <gtest/gtest.h>
22

3-
#include <tuple>
4-
53
#include "core/util/include/perf_test_util.hpp"
6-
#include "core/util/include/util.hpp"
74
#include "example_threads/all/include/ops_all.hpp"
85
#include "example_threads/common/include/common.hpp"
96
#include "example_threads/omp/include/ops_omp.hpp"
@@ -30,7 +27,10 @@ const auto kAllPerfTasks =
3027
ppc::util::MakeAllPerfTasks<InType, NesterovATestTaskALL, NesterovATestTaskOMP, NesterovATestTaskSEQ,
3128
NesterovATestTaskSTL, NesterovATestTaskTBB>(PPC_SETTINGS_example_threads);
3229

33-
INSTANTIATE_TEST_SUITE_P(RunModeTests, ExampleRunPerfTestThreads, ppc::util::TupleToGTestValues(kAllPerfTasks),
34-
ExampleRunPerfTestThreads::CustomPerfTestName);
30+
const auto kGtestValues = ppc::util::TupleToGTestValues(kAllPerfTasks);
31+
32+
const auto kPerfTestName = ExampleRunPerfTestThreads::CustomPerfTestName;
33+
34+
INSTANTIATE_TEST_SUITE_P(RunModeTests, ExampleRunPerfTestThreads, kGtestValues, kPerfTestName);
3535

3636
} // namespace nesterov_a_test_task_threads

0 commit comments

Comments
 (0)