From f54b2f0f0961fe15ec1f371f879726aebd797a7c Mon Sep 17 00:00:00 2001 From: Alexander Nesterov Date: Sun, 9 Feb 2025 01:31:08 +0100 Subject: [PATCH 1/2] increase coverage --- modules/core/perf/src/perf.cpp | 2 +- modules/core/task/func_tests/task_tests.cpp | 22 +++++++++++++++++++++ modules/core/task/func_tests/test_task.hpp | 15 ++++++++++++++ modules/core/task/src/task.cpp | 19 ++++++++++-------- scripts/run_tests.py | 4 ++-- 5 files changed, 51 insertions(+), 11 deletions(-) diff --git a/modules/core/perf/src/perf.cpp b/modules/core/perf/src/perf.cpp index 4f1f3c490..b0244605a 100644 --- a/modules/core/perf/src/perf.cpp +++ b/modules/core/perf/src/perf.cpp @@ -72,7 +72,7 @@ void ppc::core::Perf::PrintPerfStatistic(const std::shared_ptr& per type_test_name = "task_run"; } else if (perf_results->type_of_running == PerfResults::TypeOfRunning::kPipeline) { type_test_name = "pipeline"; - } else if (perf_results->type_of_running == PerfResults::TypeOfRunning::kNone) { + } else { type_test_name = "none"; } diff --git a/modules/core/task/func_tests/task_tests.cpp b/modules/core/task/func_tests/task_tests.cpp index 6f8065908..d68d2ad1a 100644 --- a/modules/core/task/func_tests/task_tests.cpp +++ b/modules/core/task/func_tests/task_tests.cpp @@ -30,6 +30,28 @@ TEST(task_tests, check_int32_t) { ASSERT_EQ(static_cast(out[0]), in.size()); } +TEST(task_tests, check_int32_t_slow) { + // Create data + std::vector in(20, 1); + std::vector out(1, 0); + + // Create TaskData + auto task_data = std::make_shared(); + task_data->inputs.emplace_back(reinterpret_cast(in.data())); + task_data->inputs_count.emplace_back(in.size()); + task_data->outputs.emplace_back(reinterpret_cast(out.data())); + task_data->outputs_count.emplace_back(out.size()); + + // Create Task + ppc::test::task::FakeSlowTask test_task(task_data); + bool is_valid = test_task.Validation(); + ASSERT_EQ(is_valid, true); + test_task.PreProcessing(); + test_task.Run(); + ASSERT_ANY_THROW(test_task.PostProcessing()); + ASSERT_EQ(static_cast(out[0]), in.size()); +} + TEST(task_tests, check_validate_func) { // Create data std::vector in(20, 1); diff --git a/modules/core/task/func_tests/test_task.hpp b/modules/core/task/func_tests/test_task.hpp index 873b98bd6..6eb72e9ea 100644 --- a/modules/core/task/func_tests/test_task.hpp +++ b/modules/core/task/func_tests/test_task.hpp @@ -1,9 +1,13 @@ #pragma once +#include +#include #include #include "core/task/include/task.hpp" +using namespace std::chrono_literals; + namespace ppc::test::task { template @@ -33,4 +37,15 @@ class TestTask : public ppc::core::Task { T *output_{}; }; +template +class FakeSlowTask : public TestTask { + public: + explicit FakeSlowTask(ppc::core::TaskDataPtr perf_task_data) : TestTask(perf_task_data) {} + + bool RunImpl() override { + std::this_thread::sleep_for(5000ms); + return TestTask::RunImpl(); + } +}; + } // namespace ppc::test::task diff --git a/modules/core/task/src/task.cpp b/modules/core/task/src/task.cpp index ff0689d6d..16586025a 100644 --- a/modules/core/task/src/task.cpp +++ b/modules/core/task/src/task.cpp @@ -1,13 +1,11 @@ #include "core/task/include/task.hpp" -#include - -#include #include +#include #include +#include #include #include -#include void ppc::core::Task::SetData(TaskDataPtr task_data_ptr) { task_data_ptr->state_of_testing = TaskData::StateOfTesting::kFunc; @@ -58,13 +56,18 @@ void ppc::core::Task::InternalOrderTest(const std::string& str) { tmp_time_point_ = std::chrono::high_resolution_clock::now(); } - if (str == "post_processing" && task_data->state_of_testing == TaskData::StateOfTesting::kFunc) { + if (str == "PostProcessing" && task_data->state_of_testing == TaskData::StateOfTesting::kFunc) { auto end = std::chrono::high_resolution_clock::now(); auto duration = std::chrono::duration_cast(end - tmp_time_point_).count(); auto current_time = static_cast(duration) * 1e-9; - if (current_time > max_test_time_) { - std::cerr << "Current test work more than " << max_test_time_ << " secs: " << current_time << '\n'; - EXPECT_TRUE(current_time < max_test_time_); + if (current_time < max_test_time_) { + std::cout << "Test time:" << std::fixed << std::setprecision(10) << current_time; + } else { + std::stringstream err_msg; + err_msg << "\nTask execute time need to be: "; + err_msg << "time < " << max_test_time_ << " secs.\n"; + err_msg << "Original time in secs: " << current_time << '\n'; + throw std::runtime_error(err_msg.str().c_str()); } } } diff --git a/scripts/run_tests.py b/scripts/run_tests.py index 331b7c32c..b903201c5 100644 --- a/scripts/run_tests.py +++ b/scripts/run_tests.py @@ -109,8 +109,8 @@ def run_core(self): self.__run_exec(f"{self.valgrind_cmd} {self.work_dir / 'core_func_tests'} {self.__get_gtest_settings(1)}") self.__run_exec(f"{self.valgrind_cmd} {self.work_dir / 'ref_func_tests'} {self.__get_gtest_settings(1)}") - self.__run_exec(f"{self.work_dir / 'core_func_tests'} {self.__get_gtest_settings(3)}") - self.__run_exec(f"{self.work_dir / 'ref_func_tests'} {self.__get_gtest_settings(3)}") + self.__run_exec(f"{self.work_dir / 'core_func_tests'} {self.__get_gtest_settings(1)}") + self.__run_exec(f"{self.work_dir / 'ref_func_tests'} {self.__get_gtest_settings(1)}") def run_processes(self, additional_mpi_args): if os.environ.get("CLANG_BUILD") == "1": From 2495f4e9aa77f9fc09802211c71d306244e949a6 Mon Sep 17 00:00:00 2001 From: Alexander Nesterov Date: Sun, 9 Feb 2025 13:10:28 +0100 Subject: [PATCH 2/2] fix clang tidy --- modules/core/perf/func_tests/test_task.hpp | 2 +- modules/core/task/func_tests/test_task.hpp | 6 ++---- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/modules/core/perf/func_tests/test_task.hpp b/modules/core/perf/func_tests/test_task.hpp index 8e35cfe16..80325225e 100644 --- a/modules/core/perf/func_tests/test_task.hpp +++ b/modules/core/perf/func_tests/test_task.hpp @@ -43,7 +43,7 @@ class FakePerfTask : public TestTask { explicit FakePerfTask(ppc::core::TaskDataPtr perf_task_data) : TestTask(perf_task_data) {} bool RunImpl() override { - std::this_thread::sleep_for(std::chrono::milliseconds(21000)); + std::this_thread::sleep_for(std::chrono::seconds(11)); return TestTask::RunImpl(); } }; diff --git a/modules/core/task/func_tests/test_task.hpp b/modules/core/task/func_tests/test_task.hpp index 6eb72e9ea..5a31990db 100644 --- a/modules/core/task/func_tests/test_task.hpp +++ b/modules/core/task/func_tests/test_task.hpp @@ -1,13 +1,11 @@ #pragma once -#include +#include #include #include #include "core/task/include/task.hpp" -using namespace std::chrono_literals; - namespace ppc::test::task { template @@ -43,7 +41,7 @@ class FakeSlowTask : public TestTask { explicit FakeSlowTask(ppc::core::TaskDataPtr perf_task_data) : TestTask(perf_task_data) {} bool RunImpl() override { - std::this_thread::sleep_for(5000ms); + std::this_thread::sleep_for(std::chrono::seconds(2)); return TestTask::RunImpl(); } };