|
10 | 10 | #include <string>
|
11 | 11 | #include <utility>
|
12 | 12 |
|
| 13 | +using namespace std::chrono; |
| 14 | + |
13 | 15 | ppc::core::Task::Task(StateOfTesting state_of_testing) : state_of_testing_(state_of_testing) {
|
14 | 16 | functions_order_.clear();
|
15 | 17 | }
|
16 | 18 |
|
17 | 19 | bool ppc::core::Task::Validation() {
|
18 |
| - InternalOrderTest(); |
| 20 | + InternalOrderTest(__builtin_FUNCTION()); |
19 | 21 | return ValidationImpl();
|
20 | 22 | }
|
21 | 23 |
|
22 | 24 | bool ppc::core::Task::PreProcessing() {
|
23 |
| - InternalOrderTest(); |
| 25 | + InternalOrderTest(__builtin_FUNCTION()); |
| 26 | + if (state_of_testing_ == StateOfTesting::kFunc) { |
| 27 | + InternalTimeTest(__builtin_FUNCTION()); |
| 28 | + } |
24 | 29 | return PreProcessingImpl();
|
25 | 30 | }
|
26 | 31 |
|
27 | 32 | bool ppc::core::Task::Run() {
|
28 |
| - InternalOrderTest(); |
| 33 | + InternalOrderTest(__builtin_FUNCTION()); |
29 | 34 | return RunImpl();
|
30 | 35 | }
|
31 | 36 |
|
32 | 37 | bool ppc::core::Task::PostProcessing() {
|
33 |
| - InternalOrderTest(); |
| 38 | + InternalOrderTest(__builtin_FUNCTION()); |
| 39 | + if (state_of_testing_ == StateOfTesting::kFunc) { |
| 40 | + InternalTimeTest(__builtin_FUNCTION()); |
| 41 | + } |
34 | 42 | return PostProcessingImpl();
|
35 | 43 | }
|
36 | 44 |
|
37 |
| -void ppc::core::Task::InternalOrderTest(const std::string& str) { |
38 |
| - if (!functions_order_.empty() && str == functions_order_.back() && str == "Run") { |
39 |
| - return; |
40 |
| - } |
41 |
| - |
| 45 | +void ppc::core::Task::InternalOrderTest(const std::string &str) { |
| 46 | + was_worked = true; |
42 | 47 | functions_order_.push_back(str);
|
43 |
| - |
44 |
| - for (size_t i = 0; i < functions_order_.size(); i++) { |
45 |
| - if (functions_order_[i] != right_functions_order_[i % right_functions_order_.size()]) { |
46 |
| - functions_order_validation_ = false; |
47 |
| - throw std::invalid_argument("ORDER OF FUNCTIONS IS NOT RIGHT: \n" + std::string("Serial number: ") + |
48 |
| - std::to_string(i + 1) + "\n" + std::string("Your function: ") + functions_order_[i] + |
49 |
| - "\n" + std::string("Expected function: ") + right_functions_order_[i]); |
50 |
| - } |
| 48 | + if (str == "PostProcessing" && IsFullPipelineStage()) { |
| 49 | + functions_order_.clear(); |
51 | 50 | }
|
52 |
| - |
53 |
| - if (str == "PreProcessing" && state_of_testing_ == StateOfTesting::kFunc) { |
| 51 | +} |
| 52 | +void ppc::core::Task::InternalTimeTest(const std::string &str) { |
| 53 | + if (str == "PreProcessing") { |
54 | 54 | tmp_time_point_ = std::chrono::high_resolution_clock::now();
|
55 | 55 | }
|
56 | 56 |
|
57 |
| - if (str == "PostProcessing" && state_of_testing_ == StateOfTesting::kFunc) { |
58 |
| - auto end = std::chrono::high_resolution_clock::now(); |
59 |
| - auto duration = std::chrono::duration_cast<std::chrono::nanoseconds>(end - tmp_time_point_).count(); |
60 |
| - auto current_time = static_cast<double>(duration) * 1e-9; |
| 57 | + if (str == "PostProcessing") { |
| 58 | + auto duration = duration_cast<nanoseconds>(high_resolution_clock::now() - tmp_time_point_).count(); |
| 59 | + auto diff = static_cast<double>(duration) * 1e-9; |
| 60 | + |
61 | 61 | std::stringstream err_msg;
|
62 |
| - if (current_time < kMaxTestTime) { |
63 |
| - err_msg << "Test time:" << std::fixed << std::setprecision(10) << current_time; |
| 62 | + if (diff < kMaxTestTime) { |
| 63 | + err_msg << "Test time:" << std::fixed << std::setprecision(10) << diff; |
64 | 64 | } else {
|
65 | 65 | err_msg << "\nTask execute time need to be: ";
|
66 | 66 | err_msg << "time < " << kMaxTestTime << " secs.\n";
|
67 |
| - err_msg << "Original time in secs: " << current_time << '\n'; |
| 67 | + err_msg << "Original time in secs: " << diff << '\n'; |
68 | 68 | throw std::runtime_error(err_msg.str().c_str());
|
69 | 69 | }
|
70 | 70 | }
|
71 | 71 | }
|
72 | 72 |
|
| 73 | +bool ppc::core::Task::IsFullPipelineStage() { |
| 74 | + auto it = std::adjacent_find(functions_order_.begin() + 2, functions_order_.begin() + (functions_order_.size() - 2), |
| 75 | + std::not_equal_to<>()); |
| 76 | + |
| 77 | + return (functions_order_.size() >= 4 && functions_order_[0] == "Validation" && |
| 78 | + functions_order_[1] == "PreProcessing" && functions_order_[2] == "Run" && |
| 79 | + it == (functions_order_.begin() + (functions_order_.size() - 2)) && |
| 80 | + functions_order_[functions_order_.size() - 1] == "PostProcessing"); |
| 81 | +} |
| 82 | + |
73 | 83 | ppc::core::Task::~Task() {
|
74 |
| - if (functions_order_.empty()) { |
75 |
| - std::cerr << "ORDER OF FUNCTIONS IS NOT RIGHT: No task functions were executed\n"; |
| 84 | + if (!functions_order_.empty() || !was_worked) { |
| 85 | + std::cerr << "ORDER OF FUNCTIONS IS NOT RIGHT! \n" |
| 86 | + "Expected - \"Validation\", \"PreProcessing\", \"Run\", \"PostProcessing\" \n"; |
76 | 87 | std::terminate();
|
| 88 | + } else { |
| 89 | + functions_order_.clear(); |
77 | 90 | }
|
78 |
| - if (functions_order_validation_) { |
79 |
| - for (size_t i = 0; i < functions_order_.size(); i++) { |
80 |
| - if (functions_order_[i] != right_functions_order_[i % right_functions_order_.size()]) { |
81 |
| - std::cerr << "ORDER OF FUNCTIONS IS NOT RIGHT: \n" |
82 |
| - << std::string("Serial number: ") << std::to_string(i + 1) << "\n" |
83 |
| - << std::string("Your function: ") << functions_order_[i] << "\n" |
84 |
| - << std::string("Expected function: ") << right_functions_order_[i] << "\n"; |
85 |
| - std::terminate(); |
86 |
| - } |
87 |
| - } |
88 |
| - } |
89 |
| - functions_order_.clear(); |
90 | 91 | }
|
0 commit comments