Skip to content

Commit 48fd9d9

Browse files
committed
Refactor imports and update JSON pointer initialization across multiple modules and tasks
Standardized header imports, removed unused includes, and introduced a shared JSON pointer initialization method (`InitJSONPtr`) for improved code reusability. Adjusted related logic in task handling for consistency and robustness.
1 parent a4d58a1 commit 48fd9d9

30 files changed

Lines changed: 146 additions & 99 deletions

File tree

3rdparty/stb_image_wrapper.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
#define STB_IMAGE_IMPLEMENTATION
2+
3+
// NOLINTNEXTLINE(misc-include-cleaner)
24
#include "stb_library.hpp"

modules/core/perf/func_tests/perf_tests.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ TEST(perf_tests, check_perf_pipeline_uint8_t_slow_test) {
7171
perf_analyzer.PipelineRun(perf_attr);
7272

7373
// Get perf statistic
74+
// NOLINTNEXTLINE(cppcoreguidelines-avoid-goto)
7475
ASSERT_ANY_THROW(perf_analyzer.PrintPerfStatistic("check_perf_pipeline_uint8_t_slow_test"));
7576
}
7677

modules/core/perf/include/perf.hpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,12 @@
22

33
#include <cstdint>
44
#include <functional>
5+
#include <iomanip>
6+
#include <iostream>
57
#include <memory>
8+
#include <sstream>
9+
#include <stdexcept>
10+
#include <string>
611

712
#include "core/task/include/task.hpp"
813

@@ -58,7 +63,7 @@ class Perf {
5863
task_->PostProcessing();
5964
}
6065
// Pint results for automation checkers
61-
void PrintPerfStatistic(std::string test_id) const {
66+
void PrintPerfStatistic(const std::string& test_id) const {
6267
std::string type_test_name;
6368
if (perf_results_.type_of_running == PerfResults::TypeOfRunning::kTaskRun) {
6469
type_test_name = "task_run";

modules/core/task/include/task.hpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,17 @@
33
#include <algorithm>
44
#include <chrono>
55
#include <core/util/include/util.hpp>
6-
#include <cstddef>
6+
#include <cstdint>
77
#include <cstdlib>
88
#include <exception>
99
#include <fstream>
1010
#include <functional>
1111
#include <iomanip>
1212
#include <iostream>
13+
#include <memory>
1314
#include <sstream>
1415
#include <stdexcept>
1516
#include <string>
16-
#include <utility>
1717

1818
using namespace std::chrono;
1919

@@ -34,11 +34,12 @@ inline std::string GetStringTaskType(TypeOfTask type_of_task, const std::string
3434
if (!file.is_open()) {
3535
throw std::runtime_error("Failed to open file settings.json");
3636
}
37-
nlohmann::json list_settings;
38-
file >> list_settings;
37+
38+
auto list_settings = ppc::util::InitJSONPtr();
39+
file >> *list_settings;
3940

4041
auto to_type_str = [&](const std::string &type) -> std::string {
41-
return type + "_" + std::string(list_settings["tasks"][type]);
42+
return type + "_" + std::string((*list_settings)["tasks"][type]);
4243
};
4344

4445
if (type_of_task == TypeOfTask::kALL) {

modules/core/util/func_tests/util.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@
22

33
#include <gtest/gtest.h>
44

5-
#include <cstddef>
6-
#include <cstdint>
7-
#include <vector>
5+
#include <string_view>
86

97
#include "omp.h"
108

modules/core/util/include/func_test_util.hpp

Lines changed: 43 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
#pragma once
22

33
#include <gtest/gtest.h>
4-
#include <mpi.h>
54
#include <omp.h>
65
#include <tbb/tick_count.h>
76

7+
#include <concepts>
88
#include <csignal>
9-
#include <filesystem>
10-
#include <fstream>
9+
#include <functional>
10+
#include <string>
11+
#include <tuple>
1112

12-
#include "core/perf/include/perf.hpp"
13+
#include "core/task/include/task.hpp"
1314
#include "core/util/include/util.hpp"
1415

1516
namespace ppc::util {
@@ -44,31 +45,53 @@ class BaseRunFuncTests : public ::testing::TestWithParam<FuncTestParam<InType, O
4445
return std::get<GTestParamIndex::kNameTest>(info.param) + "_" + Derived::PrintTestParam(test_param);
4546
}
4647

47-
protected:
4848
void ExecuteTest(FuncTestParam<InType, OutType, TestType> test_param) {
49-
ASSERT_FALSE(std::get<GTestParamIndex::kNameTest>(test_param).find("unknown") != std::string::npos);
50-
if (std::get<GTestParamIndex::kNameTest>(test_param).find("disabled") != std::string::npos) {
49+
const std::string& test_name = std::get<GTestParamIndex::kNameTest>(test_param);
50+
51+
validateTestName(test_name);
52+
53+
if (isTestDisabled(test_name)) {
5154
GTEST_SKIP();
5255
}
5356

54-
auto which_task = [&](const std::string& substring) {
55-
return std::get<GTestParamIndex::kNameTest>(test_param).find(substring) != std::string::npos;
56-
};
57-
58-
if (!ppc::util::IsUnderMpirun() && (which_task("_all") || which_task("_mpi"))) {
59-
std::cerr << "kALL and kMPI tasks are not under mpirun" << '\n';
57+
if (shouldSkipNonMpiTask(test_name)) {
58+
std::cerr << "kALL and kMPI tasks are not under mpirun\n";
6059
GTEST_SKIP();
6160
}
6261

63-
task_ = std::get<GTestParamIndex::kTaskGetter>(test_param)(GetTestInputData());
64-
ASSERT_TRUE(task_->Validation());
65-
ASSERT_TRUE(task_->PreProcessing());
66-
ASSERT_TRUE(task_->Run());
67-
ASSERT_TRUE(task_->PostProcessing());
68-
ASSERT_TRUE(CheckTestOutputData(task_->GetOutput()));
62+
initializeAndRunTask(test_param);
6963
}
7064

7165
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+
}
74+
75+
bool isTestDisabled(const std::string& test_name) { return test_name.find(DISABLED_TEST) != std::string::npos; }
76+
77+
bool shouldSkipNonMpiTask(const std::string& test_name) {
78+
auto containsSubstring = [&](const std::string& substring) {
79+
return test_name.find(substring) != std::string::npos;
80+
};
81+
82+
return !ppc::util::IsUnderMpirun() && (containsSubstring(ALL_TASK) || containsSubstring(MPI_TASK));
83+
}
84+
85+
void initializeAndRunTask(const FuncTestParam<InType, OutType, TestType>& test_param) {
86+
task_ = std::get<GTestParamIndex::kTaskGetter>(test_param)(GetTestInputData());
87+
88+
EXPECT_TRUE(task_->Validation());
89+
EXPECT_TRUE(task_->PreProcessing());
90+
EXPECT_TRUE(task_->Run());
91+
EXPECT_TRUE(task_->PostProcessing());
92+
EXPECT_TRUE(CheckTestOutputData(task_->GetOutput()));
93+
}
94+
7295
ppc::core::TaskPtr<InType, OutType> task_;
7396
};
7497

@@ -98,10 +121,6 @@ auto ExpandToValues(const Tuple& t) {
98121
return GenTaskTuplesImpl<Task>(std::make_index_sequence<SizesParam.size()>{}); \
99122
}
100123

101-
#if 1
102-
#define ADD_FUNC_TASK(TASK) TaskListGenerator<TASK>()
103-
#else
104-
#define ADD_FUNC_TASK(TASK) std::tuple<>()
105-
#endif
124+
#define ADD_FUNC_TASK(TASK) TaskListGenerator<TASK>() // std::tuple<>()
106125

107126
} // namespace ppc::util

modules/core/util/include/perf_test_util.hpp

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,19 @@
55
#include <omp.h>
66
#include <tbb/tick_count.h>
77

8+
#include <chrono>
89
#include <csignal>
9-
#include <filesystem>
10-
#include <fstream>
10+
#include <cstddef>
11+
#include <functional>
12+
#include <stdexcept>
13+
#include <string>
14+
#include <strstream>
15+
#include <tuple>
16+
#include <type_traits>
17+
#include <utility>
1118

1219
#include "core/perf/include/perf.hpp"
20+
#include "core/task/include/task.hpp"
1321
#include "core/util/include/util.hpp"
1422

1523
namespace ppc::util {
@@ -93,7 +101,6 @@ class BaseRunPerfTests : public ::testing::TestWithParam<PerfTestParam<InType, O
93101
ppc::core::TaskPtr<InType, OutType> task_;
94102
};
95103

96-
#if 1
97104
#define ADD_PERF_TASK(TaskType, InputTypeParam, SettingsPath) \
98105
std::tuple(std::make_tuple(ppc::core::TaskGetter<TaskType, InputTypeParam>, \
99106
std::string(ppc::util::GetNamespace<TaskType>()) + "_" + \
@@ -103,19 +110,18 @@ class BaseRunPerfTests : public ::testing::TestWithParam<PerfTestParam<InType, O
103110
std::string(ppc::util::GetNamespace<TaskType>()) + "_" + \
104111
ppc::core::GetStringTaskType(TaskType::GetStaticTypeOfTask(), SettingsPath), \
105112
ppc::core::PerfResults::TypeOfRunning::kTaskRun))
106-
#else
107-
#define ADD_PERF_TASK(TaskType, InputTypeParam, SettingsPath) std::make_tuple()
108-
#endif
113+
114+
// #define ADD_PERF_TASK(TaskType, InputTypeParam, SettingsPath) std::make_tuple()
109115

110116
template <typename Tuple, std::size_t... I>
111-
auto TupleToGTestValuesImpl(Tuple&& tup, std::index_sequence<I...>) {
117+
auto TupleToGTestValuesImpl(Tuple&& tup, std::index_sequence<I...> /*unused*/) {
112118
return ::testing::Values(std::get<I>(std::forward<Tuple>(tup))...);
113119
}
114120

115121
template <typename Tuple>
116122
auto TupleToGTestValues(Tuple&& tup) {
117-
constexpr size_t size = std::tuple_size<std::decay_t<Tuple>>::value;
118-
return TupleToGTestValuesImpl(std::forward<Tuple>(tup), std::make_index_sequence<size>{});
123+
constexpr size_t kSize = std::tuple_size<std::decay_t<Tuple>>::value;
124+
return TupleToGTestValuesImpl(std::forward<Tuple>(tup), std::make_index_sequence<kSize>{});
119125
}
120126

121127
#define INIT_PERF_TASK_GENERATOR(InType, EnvVarSettingsPath) \

modules/core/util/include/util.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
#include <cstdint>
44
#include <cstdlib>
5+
#include <memory>
56
#include <string>
67
#include <string_view>
78

@@ -90,6 +91,8 @@ constexpr std::string_view GetNamespace() {
9091
#endif
9192
}
9293

94+
inline std::shared_ptr<nlohmann::json> InitJSONPtr() { return std::make_shared<nlohmann::json>(); }
95+
9396
bool IsUnderMpirun();
9497

9598
} // namespace ppc::util

modules/core/util/src/util.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@
33
#include <algorithm>
44
#include <array>
55
#include <filesystem>
6-
#include <libenvpp/env.hpp>
6+
#include <libenvpp/detail/get.hpp>
77
#include <string>
88

99
namespace {
1010

11-
static std::string GetAbsolutePath(const std::string& relative_path) {
11+
std::string GetAbsolutePath(const std::string& relative_path) {
1212
const std::filesystem::path path = std::string(PPC_PATH_TO_PROJECT) + "/tasks/" + relative_path;
1313
return path.string();
1414
}

tasks/common/runners/functional.cpp

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

65
#include <cstdio>
@@ -9,6 +8,7 @@
98
#include <utility>
109

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

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

0 commit comments

Comments
 (0)