Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions docs/user_guide/environment_variables.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,7 @@ The following environment variables can be used to configure the project's runti

- ``PPC_IGNORE_TEST_TIME_LIMIT``: Specifies that test time limits are ignored. Used by ``scripts/run_tests.py`` to disable time limit enforcement.
Default: ``0``
- ``PPC_TASK_MAX_TIME``: Maximum allowed execution time in seconds for functional tests.
Default: ``1.0``
- ``PPC_PERF_MAX_TIME``: Maximum allowed execution time in seconds for performance tests.
Default: ``10.0``
6 changes: 4 additions & 2 deletions modules/performance/include/performance.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include <string>

#include "task/include/task.hpp"
#include "util/include/util.hpp"

namespace ppc::performance {

Expand Down Expand Up @@ -78,14 +79,15 @@ class Perf {
}

auto time_secs = perf_results_.time_sec;
const auto max_time = ppc::util::GetPerfMaxTime();
std::stringstream perf_res_str;
if (time_secs < PerfResults::kMaxTime) {
if (time_secs < max_time) {
perf_res_str << std::fixed << std::setprecision(10) << time_secs;
std::cout << test_id << ":" << type_test_name << ":" << perf_res_str.str() << '\n';
} else {
std::stringstream err_msg;
err_msg << '\n' << "Task execute time need to be: ";
err_msg << "time < " << PerfResults::kMaxTime << " secs." << '\n';
err_msg << "time < " << max_time << " secs." << '\n';
err_msg << "Original time in secs: " << time_secs << '\n';
perf_res_str << std::fixed << std::setprecision(10) << -1.0;
std::cout << test_id << ":" << type_test_name << ":" << perf_res_str.str() << '\n';
Expand Down
18 changes: 18 additions & 0 deletions modules/performance/tests/perf_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <cstdint>
#include <filesystem>
#include <fstream>
#include <libenvpp/detail/environment.hpp>
#include <memory>
#include <ostream>
#include <stdexcept>
Expand Down Expand Up @@ -107,6 +108,23 @@ TEST(perf_tests, check_perf_pipeline_uint8_t_slow_test) {
ASSERT_ANY_THROW(perf_analyzer.PrintPerfStatistic("check_perf_pipeline_uint8_t_slow_test"));
}

TEST(perf_tests, slow_perf_respects_env_override) {
env::detail::set_scoped_environment_variable scoped("PPC_PERF_MAX_TIME", "12");
std::vector<uint8_t> in(128, 1);
auto test_task = std::make_shared<ppc::test::FakePerfTask<std::vector<uint8_t>, uint8_t>>(in);
Perf<std::vector<uint8_t>, uint8_t> perf_analyzer(test_task);
PerfAttr perf_attr;
perf_attr.num_running = 1;
const auto t0 = std::chrono::high_resolution_clock::now();
perf_attr.current_timer = [&] {
auto current_time_point = std::chrono::high_resolution_clock::now();
auto duration = std::chrono::duration_cast<std::chrono::nanoseconds>(current_time_point - t0).count();
return static_cast<double>(duration) * 1e-9;
};
perf_analyzer.PipelineRun(perf_attr);
EXPECT_NO_THROW(perf_analyzer.PrintPerfStatistic("slow_perf_respects_env_override"));
}

TEST(perf_tests, check_perf_task_exception) {
std::vector<uint32_t> in(2000, 1);

Expand Down
6 changes: 3 additions & 3 deletions modules/task/include/task.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -215,12 +215,13 @@ class Task {
.count();
auto diff = static_cast<double>(duration) * 1e-9;

const auto max_time = ppc::util::GetTaskMaxTime();
std::stringstream err_msg;
if (diff < kMaxTestTime) {
if (diff < max_time) {
err_msg << "Test time:" << std::fixed << std::setprecision(10) << diff << '\n';
} else {
err_msg << "\nTask execute time need to be: ";
err_msg << "time < " << kMaxTestTime << " secs.\n";
err_msg << "time < " << max_time << " secs.\n";
err_msg << "Original time in secs: " << diff << '\n';
throw std::runtime_error(err_msg.str().c_str());
}
Expand Down Expand Up @@ -249,7 +250,6 @@ class Task {
StateOfTesting state_of_testing_ = kFunc;
TypeOfTask type_of_task_ = kUnknown;
StatusOfTask status_of_task_ = kEnabled;
static constexpr double kMaxTestTime = 1.0;
std::chrono::high_resolution_clock::time_point tmp_time_point_;
enum class PipelineStage : uint8_t {
kNone,
Expand Down
11 changes: 11 additions & 0 deletions modules/task/tests/task_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include <cstdint>
#include <exception>
#include <fstream>
#include <libenvpp/env.hpp>
#include <memory>
#include <stdexcept>
#include <thread>
Expand Down Expand Up @@ -72,6 +73,16 @@ TEST(task_tests, check_int32_t_slow) {
ASSERT_ANY_THROW(test_task.PostProcessing());
}

TEST(task_tests, slow_task_respects_env_override) {
env::detail::set_scoped_environment_variable scoped("PPC_TASK_MAX_TIME", "3");
std::vector<int32_t> in(20, 1);
ppc::test::FakeSlowTask<std::vector<int32_t>, int32_t> test_task(in);
ASSERT_EQ(test_task.Validation(), true);
test_task.PreProcessing();
test_task.Run();
EXPECT_NO_THROW(test_task.PostProcessing());
}

TEST(task_tests, check_validate_func) {
std::vector<int32_t> in;
ppc::test::TestTask<std::vector<int32_t>, int32_t> test_task(in);
Expand Down
2 changes: 2 additions & 0 deletions modules/util/include/util.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ enum GTestParamIndex : uint8_t { kTaskGetter, kNameTest, kTestParams };

std::string GetAbsoluteTaskPath(const std::string& id_path, const std::string& relative_path);
int GetNumThreads();
double GetTaskMaxTime();
double GetPerfMaxTime();

template <typename T>
std::string GetNamespace() {
Expand Down
16 changes: 16 additions & 0 deletions modules/util/src/util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,22 @@ int ppc::util::GetNumThreads() {
return 1;
}

double ppc::util::GetTaskMaxTime() {
const auto val = env::get<double>("PPC_TASK_MAX_TIME");
if (val.has_value()) {
return val.value();
}
return 1.0;
}

double ppc::util::GetPerfMaxTime() {
const auto val = env::get<double>("PPC_PERF_MAX_TIME");
if (val.has_value()) {
return val.value();
}
return 10.0;
}

// List of environment variables that signal the application is running under
// an MPI launcher. The array size must match the number of entries to avoid
// looking up empty environment variable names.
Expand Down
33 changes: 33 additions & 0 deletions modules/util/tests/util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include <gtest/gtest.h>

#include <libenvpp/detail/environment.hpp>
#include <libenvpp/detail/get.hpp>
#include <string>

Expand Down Expand Up @@ -75,3 +76,35 @@ TEST(GetNamespaceTest, NoTerminatorCharactersInPrettyFunction) {
std::string k_ns = ppc::util::GetNamespace<crazy::VeryLongTypeNameWithOnlyLettersAndUnderscores>();
EXPECT_EQ(k_ns, "crazy");
}

TEST(GetTaskMaxTime, ReturnsDefaultWhenUnset) {
const auto old = env::get<double>("PPC_TASK_MAX_TIME");
if (old.has_value()) {
env::detail::delete_environment_variable("PPC_TASK_MAX_TIME");
}
EXPECT_DOUBLE_EQ(ppc::util::GetTaskMaxTime(), 1.0);
if (old.has_value()) {
env::detail::set_environment_variable("PPC_TASK_MAX_TIME", std::to_string(*old));
}
}

TEST(GetTaskMaxTime, ReadsFromEnvironment) {
env::detail::set_scoped_environment_variable scoped("PPC_TASK_MAX_TIME", "2.5");
EXPECT_DOUBLE_EQ(ppc::util::GetTaskMaxTime(), 2.5);
}

TEST(GetPerfMaxTime, ReturnsDefaultWhenUnset) {
const auto old = env::get<double>("PPC_PERF_MAX_TIME");
if (old.has_value()) {
env::detail::delete_environment_variable("PPC_PERF_MAX_TIME");
}
EXPECT_DOUBLE_EQ(ppc::util::GetPerfMaxTime(), 10.0);
if (old.has_value()) {
env::detail::set_environment_variable("PPC_PERF_MAX_TIME", std::to_string(*old));
}
}

TEST(GetPerfMaxTime, ReadsFromEnvironment) {
env::detail::set_scoped_environment_variable scoped("PPC_PERF_MAX_TIME", "12.5");
EXPECT_DOUBLE_EQ(ppc::util::GetPerfMaxTime(), 12.5);
}
Loading