Skip to content

Commit 29da4bc

Browse files
committed
Merge remote-tracking branch 'origin/an/increase-coverage-1' into an/increase-coverage-1
2 parents bcb43cb + f82ccfd commit 29da4bc

File tree

9 files changed

+96
-6
lines changed

9 files changed

+96
-6
lines changed

docs/user_guide/environment_variables.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,7 @@ The following environment variables can be used to configure the project's runti
1414

1515
- ``PPC_IGNORE_TEST_TIME_LIMIT``: Specifies that test time limits are ignored. Used by ``scripts/run_tests.py`` to disable time limit enforcement.
1616
Default: ``0``
17+
- ``PPC_TASK_MAX_TIME``: Maximum allowed execution time in seconds for functional tests.
18+
Default: ``1.0``
19+
- ``PPC_PERF_MAX_TIME``: Maximum allowed execution time in seconds for performance tests.
20+
Default: ``10.0``

modules/performance/include/performance.hpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include <string>
1111

1212
#include "task/include/task.hpp"
13+
#include "util/include/util.hpp"
1314

1415
namespace ppc::performance {
1516

@@ -78,14 +79,15 @@ class Perf {
7879
}
7980

8081
auto time_secs = perf_results_.time_sec;
82+
const auto max_time = ppc::util::GetPerfMaxTime();
8183
std::stringstream perf_res_str;
82-
if (time_secs < PerfResults::kMaxTime) {
84+
if (time_secs < max_time) {
8385
perf_res_str << std::fixed << std::setprecision(10) << time_secs;
8486
std::cout << test_id << ":" << type_test_name << ":" << perf_res_str.str() << '\n';
8587
} else {
8688
std::stringstream err_msg;
8789
err_msg << '\n' << "Task execute time need to be: ";
88-
err_msg << "time < " << PerfResults::kMaxTime << " secs." << '\n';
90+
err_msg << "time < " << max_time << " secs." << '\n';
8991
err_msg << "Original time in secs: " << time_secs << '\n';
9092
perf_res_str << std::fixed << std::setprecision(10) << -1.0;
9193
std::cout << test_id << ":" << type_test_name << ":" << perf_res_str.str() << '\n';

modules/performance/tests/perf_tests.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#include <chrono>
44
#include <filesystem>
55
#include <fstream>
6+
#include <libenvpp/detail/environment.hpp>
67
#include <memory>
78
#include <ostream>
89
#include <stdexcept>
@@ -108,6 +109,23 @@ TEST(PerfTest, Pipeline_WithSlowTask_ThrowsOnTimeExceeded) {
108109
ASSERT_ANY_THROW(perf_analyzer.PrintPerfStatistic("check_perf_pipeline_uint8_t_slow_test"));
109110
}
110111

112+
TEST(perf_tests, slow_perf_respects_env_override) {
113+
env::detail::set_scoped_environment_variable scoped("PPC_PERF_MAX_TIME", "12");
114+
std::vector<uint8_t> in(128, 1);
115+
auto test_task = std::make_shared<ppc::test::FakePerfTask<std::vector<uint8_t>, uint8_t>>(in);
116+
Perf<std::vector<uint8_t>, uint8_t> perf_analyzer(test_task);
117+
PerfAttr perf_attr;
118+
perf_attr.num_running = 1;
119+
const auto t0 = std::chrono::high_resolution_clock::now();
120+
perf_attr.current_timer = [&] {
121+
auto current_time_point = std::chrono::high_resolution_clock::now();
122+
auto duration = std::chrono::duration_cast<std::chrono::nanoseconds>(current_time_point - t0).count();
123+
return static_cast<double>(duration) * 1e-9;
124+
};
125+
perf_analyzer.PipelineRun(perf_attr);
126+
EXPECT_NO_THROW(perf_analyzer.PrintPerfStatistic("slow_perf_respects_env_override"));
127+
}
128+
111129
TEST(PerfTest, TaskRun_WithoutPriorExecution_ThrowsException) {
112130
std::vector<uint32_t> in(2000, 1);
113131

modules/runners/src/runners.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,11 @@ void UnreadMessagesDetector::OnTestEnd(const ::testing::TestInfo& /*test_info*/)
2424
int flag = -1;
2525
MPI_Status status;
2626

27-
MPI_Iprobe(MPI_ANY_SOURCE, MPI_ANY_TAG, MPI_COMM_WORLD, &flag, &status);
27+
const int iprobe_res = MPI_Iprobe(MPI_ANY_SOURCE, MPI_ANY_TAG, MPI_COMM_WORLD, &flag, &status);
28+
if (iprobe_res != MPI_SUCCESS) {
29+
std::cerr << std::format("[ PROCESS {} ] [ ERROR ] MPI_Iprobe failed with code {}", rank, iprobe_res) << '\n';
30+
MPI_Abort(MPI_COMM_WORLD, iprobe_res);
31+
}
2832

2933
if (flag != 0) {
3034
std::cerr

modules/task/include/task.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -226,12 +226,13 @@ class Task {
226226
.count();
227227
auto diff = static_cast<double>(duration) * 1e-9;
228228

229+
const auto max_time = ppc::util::GetTaskMaxTime();
229230
std::stringstream err_msg;
230-
if (diff < kMaxTestTime) {
231+
if (diff < max_time) {
231232
err_msg << "Test time:" << std::fixed << std::setprecision(10) << diff << '\n';
232233
} else {
233234
err_msg << "\nTask execute time need to be: ";
234-
err_msg << "time < " << kMaxTestTime << " secs.\n";
235+
err_msg << "time < " << max_time << " secs.\n";
235236
err_msg << "Original time in secs: " << diff << '\n';
236237
throw std::runtime_error(err_msg.str().c_str());
237238
}
@@ -260,7 +261,6 @@ class Task {
260261
StateOfTesting state_of_testing_ = kFunc;
261262
TypeOfTask type_of_task_ = kUnknown;
262263
StatusOfTask status_of_task_ = kEnabled;
263-
static constexpr double kMaxTestTime = 1.0;
264264
std::chrono::high_resolution_clock::time_point tmp_time_point_;
265265
enum class PipelineStage : uint8_t {
266266
kNone,

modules/task/tests/task_tests.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include <exception>
77
#include <filesystem>
88
#include <fstream>
9+
#include <libenvpp/env.hpp>
910
#include <memory>
1011
#include <stdexcept>
1112
#include <string>
@@ -91,6 +92,16 @@ TEST(TaskTest, SlowTask_WithInt32Vector_ThrowsOnTimeout) {
9192
}
9293
}
9394

95+
TEST(TaskTest, SlowTask_RespectsEnvOverride) {
96+
env::detail::set_scoped_environment_variable scoped("PPC_TASK_MAX_TIME", "3");
97+
std::vector<int32_t> in(20, 1);
98+
ppc::test::FakeSlowTask<std::vector<int32_t>, int32_t> test_task(in);
99+
ASSERT_EQ(test_task.Validation(), true);
100+
test_task.PreProcessing();
101+
test_task.Run();
102+
EXPECT_NO_THROW(test_task.PostProcessing());
103+
}
104+
94105
TEST(TaskTest, TestTask_WithEmptyInput_ValidationFails) {
95106
{
96107
std::vector<int32_t> in;

modules/util/include/util.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ enum GTestParamIndex : uint8_t { kTaskGetter, kNameTest, kTestParams };
3333

3434
std::string GetAbsoluteTaskPath(const std::string& id_path, const std::string& relative_path);
3535
int GetNumThreads();
36+
double GetTaskMaxTime();
37+
double GetPerfMaxTime();
3638

3739
template <typename T>
3840
std::string GetNamespace() {

modules/util/src/util.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,22 @@ int ppc::util::GetNumThreads() {
2828
return 1;
2929
}
3030

31+
double ppc::util::GetTaskMaxTime() {
32+
const auto val = env::get<double>("PPC_TASK_MAX_TIME");
33+
if (val.has_value()) {
34+
return val.value();
35+
}
36+
return 1.0;
37+
}
38+
39+
double ppc::util::GetPerfMaxTime() {
40+
const auto val = env::get<double>("PPC_PERF_MAX_TIME");
41+
if (val.has_value()) {
42+
return val.value();
43+
}
44+
return 10.0;
45+
}
46+
3147
// List of environment variables that signal the application is running under
3248
// an MPI launcher. The array size must match the number of entries to avoid
3349
// looking up empty environment variable names.

modules/util/tests/util.cpp

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
#include <gtest/gtest.h>
44

5+
#include <libenvpp/detail/environment.hpp>
56
#include <libenvpp/detail/get.hpp>
67
#include <string>
78

@@ -82,3 +83,35 @@ TEST(GetNamespaceTest, GetNamespace_WithLongTypeName_ReturnsCorrectNamespace) {
8283
std::string k_ns = ppc::util::GetNamespace<crazy::VeryLongTypeNameWithOnlyLettersAndUnderscores>();
8384
EXPECT_EQ(k_ns, "crazy");
8485
}
86+
87+
TEST(GetTaskMaxTime, ReturnsDefaultWhenUnset) {
88+
const auto old = env::get<double>("PPC_TASK_MAX_TIME");
89+
if (old.has_value()) {
90+
env::detail::delete_environment_variable("PPC_TASK_MAX_TIME");
91+
}
92+
EXPECT_DOUBLE_EQ(ppc::util::GetTaskMaxTime(), 1.0);
93+
if (old.has_value()) {
94+
env::detail::set_environment_variable("PPC_TASK_MAX_TIME", std::to_string(*old));
95+
}
96+
}
97+
98+
TEST(GetTaskMaxTime, ReadsFromEnvironment) {
99+
env::detail::set_scoped_environment_variable scoped("PPC_TASK_MAX_TIME", "2.5");
100+
EXPECT_DOUBLE_EQ(ppc::util::GetTaskMaxTime(), 2.5);
101+
}
102+
103+
TEST(GetPerfMaxTime, ReturnsDefaultWhenUnset) {
104+
const auto old = env::get<double>("PPC_PERF_MAX_TIME");
105+
if (old.has_value()) {
106+
env::detail::delete_environment_variable("PPC_PERF_MAX_TIME");
107+
}
108+
EXPECT_DOUBLE_EQ(ppc::util::GetPerfMaxTime(), 10.0);
109+
if (old.has_value()) {
110+
env::detail::set_environment_variable("PPC_PERF_MAX_TIME", std::to_string(*old));
111+
}
112+
}
113+
114+
TEST(GetPerfMaxTime, ReadsFromEnvironment) {
115+
env::detail::set_scoped_environment_variable scoped("PPC_PERF_MAX_TIME", "12.5");
116+
EXPECT_DOUBLE_EQ(ppc::util::GetPerfMaxTime(), 12.5);
117+
}

0 commit comments

Comments
 (0)