Skip to content

Commit 3b0f92c

Browse files
committed
Add env-based time limits
1 parent 8b3e8fb commit 3b0f92c

5 files changed

Lines changed: 28 additions & 5 deletions

File tree

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: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,14 +78,15 @@ class Perf {
7878
}
7979

8080
auto time_secs = perf_results_.time_sec;
81+
const auto max_time = ppc::util::GetPerfMaxTime();
8182
std::stringstream perf_res_str;
82-
if (time_secs < PerfResults::kMaxTime) {
83+
if (time_secs < max_time) {
8384
perf_res_str << std::fixed << std::setprecision(10) << time_secs;
8485
std::cout << test_id << ":" << type_test_name << ":" << perf_res_str.str() << '\n';
8586
} else {
8687
std::stringstream err_msg;
8788
err_msg << '\n' << "Task execute time need to be: ";
88-
err_msg << "time < " << PerfResults::kMaxTime << " secs." << '\n';
89+
err_msg << "time < " << max_time << " secs." << '\n';
8990
err_msg << "Original time in secs: " << time_secs << '\n';
9091
perf_res_str << std::fixed << std::setprecision(10) << -1.0;
9192
std::cout << test_id << ":" << type_test_name << ":" << perf_res_str.str() << '\n';

modules/task/include/task.hpp

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

218+
const auto max_time = ppc::util::GetTaskMaxTime();
218219
std::stringstream err_msg;
219-
if (diff < kMaxTestTime) {
220+
if (diff < max_time) {
220221
err_msg << "Test time:" << std::fixed << std::setprecision(10) << diff << '\n';
221222
} else {
222223
err_msg << "\nTask execute time need to be: ";
223-
err_msg << "time < " << kMaxTestTime << " secs.\n";
224+
err_msg << "time < " << max_time << " secs.\n";
224225
err_msg << "Original time in secs: " << diff << '\n';
225226
throw std::runtime_error(err_msg.str().c_str());
226227
}
@@ -249,7 +250,6 @@ class Task {
249250
StateOfTesting state_of_testing_ = kFunc;
250251
TypeOfTask type_of_task_ = kUnknown;
251252
StatusOfTask status_of_task_ = kEnabled;
252-
static constexpr double kMaxTestTime = 1.0;
253253
std::chrono::high_resolution_clock::time_point tmp_time_point_;
254254
enum class PipelineStage : uint8_t {
255255
kNone,

modules/util/include/util.hpp

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

5353
std::string GetAbsoluteTaskPath(const std::string& id_path, const std::string& relative_path);
5454
int GetNumThreads();
55+
double GetTaskMaxTime();
56+
double GetPerfMaxTime();
5557

5658
template <typename T>
5759
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.

0 commit comments

Comments
 (0)