Skip to content

Commit 363a6bd

Browse files
committed
increase coverage
1 parent 6d21a85 commit 363a6bd

File tree

4 files changed

+47
-9
lines changed

4 files changed

+47
-9
lines changed

modules/core/perf/src/perf.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ void ppc::core::Perf::PrintPerfStatistic(const std::shared_ptr<PerfResults>& per
7272
type_test_name = "task_run";
7373
} else if (perf_results->type_of_running == PerfResults::TypeOfRunning::kPipeline) {
7474
type_test_name = "pipeline";
75-
} else if (perf_results->type_of_running == PerfResults::TypeOfRunning::kNone) {
75+
} else {
7676
type_test_name = "none";
7777
}
7878

modules/core/task/func_tests/task_tests.cpp

+22
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,28 @@ TEST(task_tests, check_int32_t) {
3030
ASSERT_EQ(static_cast<size_t>(out[0]), in.size());
3131
}
3232

33+
TEST(task_tests, check_int32_t_slow) {
34+
// Create data
35+
std::vector<int32_t> in(20, 1);
36+
std::vector<int32_t> out(1, 0);
37+
38+
// Create TaskData
39+
auto task_data = std::make_shared<ppc::core::TaskData>();
40+
task_data->inputs.emplace_back(reinterpret_cast<uint8_t *>(in.data()));
41+
task_data->inputs_count.emplace_back(in.size());
42+
task_data->outputs.emplace_back(reinterpret_cast<uint8_t *>(out.data()));
43+
task_data->outputs_count.emplace_back(out.size());
44+
45+
// Create Task
46+
ppc::test::task::FakeSlowTask<int32_t> test_task(task_data);
47+
bool is_valid = test_task.Validation();
48+
ASSERT_EQ(is_valid, true);
49+
test_task.PreProcessing();
50+
test_task.Run();
51+
ASSERT_ANY_THROW(test_task.PostProcessing());
52+
ASSERT_EQ(static_cast<size_t>(out[0]), in.size());
53+
}
54+
3355
TEST(task_tests, check_validate_func) {
3456
// Create data
3557
std::vector<int32_t> in(20, 1);

modules/core/task/func_tests/test_task.hpp

+14
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
#pragma once
22

3+
#include <thread>
34
#include <vector>
45

56
#include "core/task/include/task.hpp"
67

8+
using namespace std::chrono_literals;
9+
710
namespace ppc::test::task {
811

912
template <class T>
@@ -33,4 +36,15 @@ class TestTask : public ppc::core::Task {
3336
T *output_{};
3437
};
3538

39+
template <class T>
40+
class FakeSlowTask : public TestTask<T> {
41+
public:
42+
explicit FakeSlowTask(ppc::core::TaskDataPtr perf_task_data) : TestTask<T>(perf_task_data) {}
43+
44+
bool RunImpl() override {
45+
std::this_thread::sleep_for(5000ms);
46+
return TestTask<T>::RunImpl();
47+
}
48+
};
49+
3650
} // namespace ppc::test::task

modules/core/task/src/task.cpp

+10-8
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
11
#include "core/task/include/task.hpp"
22

3-
#include <gtest/gtest.h>
4-
5-
#include <chrono>
63
#include <cstddef>
4+
#include <iomanip>
75
#include <iostream>
86
#include <stdexcept>
97
#include <string>
10-
#include <utility>
118

129
void ppc::core::Task::SetData(TaskDataPtr task_data_ptr) {
1310
task_data_ptr->state_of_testing = TaskData::StateOfTesting::kFunc;
@@ -58,13 +55,18 @@ void ppc::core::Task::InternalOrderTest(const std::string& str) {
5855
tmp_time_point_ = std::chrono::high_resolution_clock::now();
5956
}
6057

61-
if (str == "post_processing" && task_data->state_of_testing == TaskData::StateOfTesting::kFunc) {
58+
if (str == "PostProcessing" && task_data->state_of_testing == TaskData::StateOfTesting::kFunc) {
6259
auto end = std::chrono::high_resolution_clock::now();
6360
auto duration = std::chrono::duration_cast<std::chrono::nanoseconds>(end - tmp_time_point_).count();
6461
auto current_time = static_cast<double>(duration) * 1e-9;
65-
if (current_time > max_test_time_) {
66-
std::cerr << "Current test work more than " << max_test_time_ << " secs: " << current_time << '\n';
67-
EXPECT_TRUE(current_time < max_test_time_);
62+
if (current_time < max_test_time_) {
63+
std::cout << "Test time:" << std::fixed << std::setprecision(10) << current_time;
64+
} else {
65+
std::stringstream err_msg;
66+
err_msg << "\nTask execute time need to be: ";
67+
err_msg << "time < " << max_test_time_ << " secs.\n";
68+
err_msg << "Original time in secs: " << current_time << '\n';
69+
throw std::runtime_error(err_msg.str().c_str());
6870
}
6971
}
7072
}

0 commit comments

Comments
 (0)