Skip to content

Commit e8c853a

Browse files
authored
Fix pipeline stage check and add tests (#451)
- Avoid invalid iterators in `IsFullPipelineStage` - Test premature `PostProcessing` calls
1 parent 0cdc845 commit e8c853a

File tree

3 files changed

+26
-3
lines changed

3 files changed

+26
-3
lines changed

modules/core/task/include/task.hpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -246,12 +246,16 @@ class Task {
246246
bool was_worked_ = false;
247247

248248
bool IsFullPipelineStage() {
249+
if (functions_order_.size() < 4) {
250+
return false;
251+
}
252+
249253
auto it = std::adjacent_find(functions_order_.begin() + 2,
250254
functions_order_.begin() + static_cast<long>(functions_order_.size() - 2),
251255
std::not_equal_to<>());
252256

253-
return (functions_order_.size() >= 4 && functions_order_[0] == "Validation" &&
254-
functions_order_[1] == "PreProcessing" && functions_order_[2] == "Run" &&
257+
return (functions_order_[0] == "Validation" && functions_order_[1] == "PreProcessing" &&
258+
functions_order_[2] == "Run" &&
255259
it == (functions_order_.begin() + static_cast<long>(functions_order_.size() - 2)) &&
256260
functions_order_[functions_order_.size() - 1] == "PostProcessing");
257261
}

modules/core/task/tests/.clang-tidy

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,4 @@ Checks: >
3838
3939
CheckOptions:
4040
- key: readability-function-cognitive-complexity.Threshold
41-
value: 50 # default: 25
41+
value: 100 # default: 25

modules/core/task/tests/task_tests.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,25 @@ TEST(task_tests, check_empty_order_disabled_valgrind) {
153153
EXPECT_DEATH_IF_SUPPORTED(destroy_function(), ".*ORDER OF FUNCTIONS IS NOT RIGHT.*");
154154
}
155155

156+
TEST(task_tests, premature_postprocessing_no_steps) {
157+
auto destroy_function = [] {
158+
std::vector<float> in(20, 1);
159+
ppc::test::task::TestTask<std::vector<float>, float> test_task(in);
160+
ASSERT_NO_THROW(test_task.PostProcessing());
161+
};
162+
EXPECT_DEATH_IF_SUPPORTED(destroy_function(), ".*ORDER OF FUNCTIONS IS NOT RIGHT.*");
163+
}
164+
165+
TEST(task_tests, premature_postprocessing_after_preprocessing) {
166+
auto destroy_function = [] {
167+
std::vector<float> in(20, 1);
168+
ppc::test::task::TestTask<std::vector<float>, float> test_task(in);
169+
ASSERT_NO_THROW(test_task.PreProcessing());
170+
ASSERT_NO_THROW(test_task.PostProcessing());
171+
};
172+
EXPECT_DEATH_IF_SUPPORTED(destroy_function(), ".*ORDER OF FUNCTIONS IS NOT RIGHT.*");
173+
}
174+
156175
int main(int argc, char **argv) {
157176
testing::InitGoogleTest(&argc, argv);
158177
return RUN_ALL_TESTS();

0 commit comments

Comments
 (0)