Skip to content

Commit 96e21ef

Browse files
committed
Refactor and extend tests and configurations:
- Update `codecov.yml` and GitHub workflow exclusions for improved coverage and build precision. - Add new parameterized and edge case tests for utility and task-related functionality. - Standardize and clean up `NOLINT` macros in `util.hpp`. - Improve test readability by removing redundant comments and enhancing structure. - Extend `GetStringTaskType` tests with additional scenarios and file-based validation cases. - Introduce `GetNamespaceTest` for namespace extraction validations.
1 parent fa7e0f4 commit 96e21ef

File tree

5 files changed

+241
-32
lines changed

5 files changed

+241
-32
lines changed

.github/workflows/ubuntu.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -586,6 +586,7 @@ jobs:
586586
--exclude '.*tasks/.*/tests/.*' \
587587
--exclude '.*modules/.*/tests/.*' \
588588
--exclude '.*tasks/common/runners/.*' \
589+
--exclude '.*modules/core/runners/.*' \
589590
--exclude '.*modules/core/util/include/perf_test_util.hpp' \
590591
--exclude '.*modules/core/util/include/func_test_util.hpp' \
591592
--exclude '.*modules/core/util/src/func_test_util.cpp' \

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
/build*
2+
docs/build*
23
/xml
4+
docs/xml
35
out
46
mpich
57
cmake-build-*

codecov.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ ignore:
22
- "tasks/**/tests/**"
33
- "modules/**/tests/**"
44
- "tasks/common/runners/**"
5+
- "modules/core/runners/**"
56
- "modules/core/util/include/perf_test_util.hpp"
67
- "modules/core/util/include/func_test_util.hpp"
78
- "modules/core/util/src/func_test_util.cpp"

modules/core/performance/tests/perf_tests.cpp

Lines changed: 227 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -9,56 +9,56 @@
99
#include "core/performance/tests/test_task.hpp"
1010

1111
TEST(perf_tests, check_perf_pipeline) {
12-
// Create data
12+
1313
std::vector<uint32_t> in(2000, 1);
1414

15-
// Create Task
15+
1616
auto test_task = std::make_shared<ppc::test::perf::TestTask<std::vector<uint32_t>, uint32_t>>(in);
1717

18-
// Create Perf analyzer
18+
1919
ppc::core::Perf<std::vector<uint32_t>, uint32_t> perf_analyzer(test_task);
2020

21-
// Create Perf attributes
21+
2222
ppc::core::PerfAttr perf_attr;
2323
perf_analyzer.PipelineRun(perf_attr);
2424

25-
// Get perf statistic
25+
2626
perf_analyzer.PrintPerfStatistic("check_perf_pipeline");
2727
ASSERT_LE(perf_analyzer.GetPerfResults().time_sec, ppc::core::PerfResults::kMaxTime);
2828
EXPECT_EQ(test_task->GetOutput(), in.size());
2929
}
3030

3131
TEST(perf_tests, check_perf_pipeline_float) {
32-
// Create data
32+
3333
std::vector<float> in(2000, 1);
3434

35-
// Create Task
35+
3636
auto test_task = std::make_shared<ppc::test::perf::TestTask<std::vector<float>, float>>(in);
3737

38-
// Create Perf analyzer
38+
3939
ppc::core::Perf<std::vector<float>, float> perf_analyzer(test_task);
4040

41-
// Create Perf attributes
41+
4242
ppc::core::PerfAttr perf_attr;
4343
perf_analyzer.PipelineRun(perf_attr);
4444

45-
// Get perf statistic
45+
4646
perf_analyzer.PrintPerfStatistic("check_perf_pipeline_float");
4747
ASSERT_LE(perf_analyzer.GetPerfResults().time_sec, ppc::core::PerfResults::kMaxTime);
4848
EXPECT_EQ(test_task->GetOutput(), in.size());
4949
}
5050

5151
TEST(perf_tests, check_perf_pipeline_uint8_t_slow_test) {
52-
// Create data
52+
5353
std::vector<uint8_t> in(128, 1);
5454

55-
// Create Task
55+
5656
auto test_task = std::make_shared<ppc::test::perf::FakePerfTask<std::vector<uint8_t>, uint8_t>>(in);
5757

58-
// Create Perf analyzer
58+
5959
ppc::core::Perf<std::vector<uint8_t>, uint8_t> perf_analyzer(test_task);
6060

61-
// Create Perf attributes
61+
6262
ppc::core::PerfAttr perf_attr;
6363
perf_attr.num_running = 1;
6464

@@ -70,46 +70,244 @@ TEST(perf_tests, check_perf_pipeline_uint8_t_slow_test) {
7070
};
7171
perf_analyzer.PipelineRun(perf_attr);
7272

73-
// Get perf statistic
74-
// NOLINTNEXTLINE(cppcoreguidelines-avoid-goto)
75-
ASSERT_ANY_THROW(perf_analyzer.PrintPerfStatistic("check_perf_pipeline_uint8_t_slow_test"));
73+
74+
75+
ASSERT_ANY_THROW_NOLINT(perf_analyzer.PrintPerfStatistic("check_perf_pipeline_uint8_t_slow_test"));
7676
}
7777

7878
TEST(perf_tests, check_perf_task_exception) {
79-
// Create data
79+
8080
std::vector<uint32_t> in(2000, 1);
8181

82-
// Create Task
82+
8383
auto test_task = std::make_shared<ppc::test::perf::TestTask<std::vector<uint32_t>, uint32_t>>(in);
8484

85-
// Create Perf analyzer
85+
8686
ppc::core::Perf<std::vector<uint32_t>, uint32_t> perf_analyzer(test_task);
8787

88-
// Get perf statistic
89-
// NOLINTNEXTLINE(cppcoreguidelines-avoid-goto)
90-
ASSERT_ANY_THROW(perf_analyzer.PrintPerfStatistic("check_perf_task_exception"));
88+
89+
90+
ASSERT_ANY_THROW_NOLINT(perf_analyzer.PrintPerfStatistic("check_perf_task_exception"));
9191

92-
// Create Perf attributes
92+
9393
ppc::core::PerfAttr perf_attr;
9494
perf_analyzer.TaskRun(perf_attr);
9595
}
9696

9797
TEST(perf_tests, check_perf_task_float) {
98-
// Create data
98+
9999
std::vector<float> in(2000, 1);
100100

101-
// Create Task
101+
102102
auto test_task = std::make_shared<ppc::test::perf::TestTask<std::vector<float>, float>>(in);
103103

104-
// Create Perf analyzer
104+
105105
ppc::core::Perf<std::vector<float>, float> perf_analyzer(test_task);
106106

107-
// Create Perf attributes
107+
108108
ppc::core::PerfAttr perf_attr;
109109
perf_analyzer.TaskRun(perf_attr);
110110

111-
// Get perf statistic
111+
112112
perf_analyzer.PrintPerfStatistic("check_perf_task_float");
113113
ASSERT_LE(perf_analyzer.GetPerfResults().time_sec, ppc::core::PerfResults::kMaxTime);
114114
EXPECT_EQ(test_task->GetOutput(), in.size());
115115
}
116+
117+
struct ParamTestCase {
118+
ppc::core::PerfResults::TypeOfRunning input;
119+
std::string expected_output;
120+
};
121+
122+
class GetStringParamNameParamTest : public ::testing::TestWithParam<ParamTestCase> {};
123+
124+
TEST_P(GetStringParamNameParamTest, ReturnsExpectedString) {
125+
const auto& param = GetParam();
126+
EXPECT_EQ(ppc::core::GetStringParamName(param.input), param.expected_output);
127+
}
128+
129+
INSTANTIATE_TEST_SUITE_P(
130+
ParamTests,
131+
GetStringParamNameParamTest,
132+
::testing::Values(
133+
ParamTestCase{ppc::core::PerfResults::kTaskRun, "task_run"},
134+
ParamTestCase{ppc::core::PerfResults::kPipeline, "pipeline"},
135+
ParamTestCase{static_cast<ppc::core::PerfResults::TypeOfRunning>(999), "none"}));
136+
137+
struct TaskTypeTestCase {
138+
ppc::core::TypeOfTask type;
139+
std::string expected;
140+
std::string label;
141+
};
142+
143+
class GetStringTaskTypeTest : public ::testing::TestWithParam<TaskTypeTestCase> {
144+
protected:
145+
std::string temp_path;
146+
147+
void SetUp() override {
148+
temp_path = std::filesystem::temp_directory_path() / "test_settings.json";
149+
nlohmann::json j;
150+
j["tasks"]["all"] = "ALL";
151+
j["tasks"]["stl"] = "STL";
152+
j["tasks"]["omp"] = "OMP";
153+
j["tasks"]["mpi"] = "MPI";
154+
j["tasks"]["tbb"] = "TBB";
155+
j["tasks"]["seq"] = "SEQ";
156+
157+
std::ofstream(temp_path) << j.dump();
158+
}
159+
160+
void TearDown() override {
161+
std::filesystem::remove(temp_path);
162+
}
163+
};
164+
165+
TEST_P(GetStringTaskTypeTest, ReturnsExpectedString) {
166+
const auto& param = GetParam();
167+
EXPECT_EQ(GetStringTaskType(param.type, temp_path), param.expected) << "Failed on: " << param.label;
168+
}
169+
170+
INSTANTIATE_TEST_SUITE_P_NOLINT(
171+
AllTypeCases,
172+
GetStringTaskTypeTest,
173+
::testing::Values(
174+
TaskTypeTestCase{ppc::core::TypeOfTask::kALL, "all_ALL", "kALL"},
175+
TaskTypeTestCase{ppc::core::TypeOfTask::kSTL, "stl_STL", "kSTL"},
176+
TaskTypeTestCase{ppc::core::TypeOfTask::kOMP, "omp_OMP", "kOMP"},
177+
TaskTypeTestCase{ppc::core::TypeOfTask::kMPI, "mpi_MPI", "kMPI"},
178+
TaskTypeTestCase{ppc::core::TypeOfTask::kTBB, "tbb_TBB", "kTBB"},
179+
TaskTypeTestCase{ppc::core::TypeOfTask::kSEQ, "seq_SEQ", "kSEQ"}));
180+
181+
DEATH_TEST(GetStringTaskTypeStandaloneTest, ThrowsIfFileMissing) {
182+
std::string missing_path = "non_existent_settings.json";
183+
EXPECT_THROW_NOLINT(GetStringTaskType(ppc::core::TypeOfTask::kSEQ, missing_path), std::runtime_error);
184+
}
185+
186+
TEST(GetStringTaskTypeStandaloneTest, ReturnsUnknownForInvalidEnum) {
187+
188+
std::string path = std::filesystem::temp_directory_path() / "tmp_settings.json";
189+
std::ofstream(path) << R"({"tasks":{"seq":"SEQ"}})";
190+
191+
auto result = GetStringTaskType(static_cast<ppc::core::TypeOfTask>(999), path);
192+
EXPECT_EQ(result, "unknown");
193+
194+
std::filesystem::remove(path);
195+
}
196+
197+
TEST(GetStringTaskTypeEdgeCases, ThrowsIfFileCannotBeOpened) {
198+
EXPECT_THROW_NOLINT(GetStringTaskType(ppc::core::TypeOfTask::kSEQ, "definitely_missing_file.json"), std::runtime_error);
199+
}
200+
201+
TEST(GetStringTaskTypeEdgeCases, ThrowsIfJsonIsMalformed) {
202+
std::string path = std::filesystem::temp_directory_path() / "bad_json.json";
203+
std::ofstream(path) << "{ this is not valid json ";
204+
EXPECT_THROW_NOLINT(GetStringTaskType(ppc::core::TypeOfTask::kSEQ, path), nlohmann::json::parse_error);
205+
std::filesystem::remove(path);
206+
}
207+
208+
TEST(GetStringTaskTypeEdgeCases, ThrowsIfJsonValueIsNull) {
209+
std::string path = std::filesystem::temp_directory_path() / "null_value.json";
210+
std::ofstream(path) << R"({"tasks": { "seq": null }})";
211+
212+
EXPECT_THROW(
213+
GetStringTaskType(ppc::core::TypeOfTask::kSEQ, path),
214+
nlohmann::json::type_error);
215+
216+
std::filesystem::remove(path);
217+
}
218+
219+
TEST(GetStringTaskTypeEdgeCases, ReturnsUnknownIfEnumOutOfRange) {
220+
std::string path = std::filesystem::temp_directory_path() / "ok.json";
221+
std::ofstream(path) << R"({"tasks":{"seq":"SEQ"}})";
222+
auto result = GetStringTaskType(static_cast<ppc::core::TypeOfTask>(255), path);
223+
EXPECT_EQ(result, "unknown");
224+
std::filesystem::remove(path);
225+
}
226+
227+
TEST(GetStringTaskStatusTest, HandlesEnabledAndDisabled) {
228+
EXPECT_EQ(GetStringTaskStatus(ppc::core::StatusOfTask::kEnabled), "enabled");
229+
EXPECT_EQ(GetStringTaskStatus(ppc::core::StatusOfTask::kDisabled), "disabled");
230+
}
231+
232+
class DummyTask : public ppc::core::Task<int, int> {
233+
public:
234+
using Task::Task;
235+
bool ValidationImpl() override { return true; }
236+
bool PreProcessingImpl() override { return true; }
237+
bool RunImpl() override { return true; }
238+
bool PostProcessingImpl() override { return true; }
239+
};
240+
241+
class SlowTask : public ppc::core::Task<int, int> {
242+
public:
243+
using Task::Task;
244+
bool ValidationImpl() override { return true; }
245+
bool PreProcessingImpl() override { return true; }
246+
bool RunImpl() override { return true; }
247+
bool PostProcessingImpl() override {
248+
std::this_thread::sleep_for(std::chrono::seconds(2));
249+
return true;
250+
}
251+
};
252+
253+
TEST(TaskTest, GetDynamicTypeReturnsCorrectEnum) {
254+
DummyTask task;
255+
task.SetTypeOfTask(ppc::core::TypeOfTask::kOMP);
256+
task.Validation();
257+
task.PreProcessing();
258+
task.Run();
259+
task.PostProcessing();
260+
EXPECT_EQ(task.GetDynamicTypeOfTask(), ppc::core::TypeOfTask::kOMP);
261+
}
262+
263+
DEATH_TEST(TaskTest, DestructorTerminatesIfWrongOrder) {
264+
testing::FLAGS_gtest_death_test_style = "threadsafe";
265+
ASSERT_DEATH_IF_SUPPORTED({
266+
DummyTask task;
267+
task.Run();
268+
}, "");
269+
}
270+
271+
272+
namespace my {
273+
namespace nested {
274+
struct Type {};
275+
} // namespace nested
276+
277+
class Another {};
278+
} // namespace my
279+
280+
namespace {
281+
struct NoNamespace {};
282+
} // anonymous namespace
283+
284+
template <typename T>
285+
class GetNamespaceTest : public ::testing::Test {};
286+
287+
using TestTypes = ::testing::Types<
288+
my::nested::Type,
289+
my::Another,
290+
NoNamespace,
291+
int,
292+
std::vector<int>
293+
>;
294+
295+
TYPED_TEST_SUITE(GetNamespaceTest, TestTypes);
296+
297+
TYPED_TEST(GetNamespaceTest, ExtractsNamespaceCorrectly) {
298+
constexpr std::string_view ns = ppc::util::GetNamespace<TypeParam>();
299+
300+
if constexpr (std::is_same_v<TypeParam, my::nested::Type>) {
301+
EXPECT_EQ(ns, "my::nested");
302+
} else if constexpr (std::is_same_v<TypeParam, my::Another>) {
303+
EXPECT_EQ(ns, "my");
304+
} else if constexpr (std::is_same_v<TypeParam, NoNamespace>) {
305+
EXPECT_EQ(ns, "");
306+
} else if constexpr (std::is_same_v<TypeParam, int>) {
307+
EXPECT_EQ(ns, "");
308+
} else if constexpr (std::is_same_v<TypeParam, std::vector<int>>) {
309+
EXPECT_EQ(ns, "std");
310+
} else {
311+
FAIL() << "Unhandled type in test";
312+
}
313+
}

modules/core/util/include/util.hpp

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,19 @@
1818
#endif
1919

2020
/* NOLINTBEGIN */
21-
#define INSTANTIATE_TEST_SUITE_P_NOLINT(prefix, test_case_name, generator, custom_test_name) \
22-
INSTANTIATE_TEST_SUITE_P(prefix, test_case_name, generator, custom_test_name)
21+
#define ASSERT_ANY_THROW_NOLINT(...) ASSERT_ANY_THROW(__VA_ARGS__)
2322
/* NOLINTEND */
2423

2524
/* NOLINTBEGIN */
26-
#define DEATH_TEST(test_suite_name, test_name) TEST(test_suite_name, test_name)
25+
#define EXPECT_THROW_NOLINT(...) EXPECT_THROW(__VA_ARGS__)
26+
/* NOLINTEND */
27+
28+
/* NOLINTBEGIN */
29+
#define INSTANTIATE_TEST_SUITE_P_NOLINT(...) INSTANTIATE_TEST_SUITE_P(__VA_ARGS__)
30+
/* NOLINTEND */
31+
32+
/* NOLINTBEGIN */
33+
#define DEATH_TEST(...) TEST(__VA_ARGS__)
2734
/* NOLINTEND */
2835

2936
namespace ppc::util {

0 commit comments

Comments
 (0)