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
1 change: 1 addition & 0 deletions .clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ Standard: c++20
BasedOnStyle: Google
ColumnLimit: 120
UseTab: Never
AllowShortFunctionsOnASingleLine: Empty
QualifierAlignment: Left
PointerAlignment: Right
ReferenceAlignment: Right
Expand Down
8 changes: 6 additions & 2 deletions modules/performance/include/performance.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@

namespace ppc::performance {

inline double DefaultTimer() { return -1.0; }
inline double DefaultTimer() {
return -1.0;
}

struct PerfAttr {
/// @brief Number of times the task is run for performance evaluation.
Expand Down Expand Up @@ -96,7 +98,9 @@ class Perf {
}
/// @brief Retrieves the performance test results.
/// @return The latest PerfResults structure.
[[nodiscard]] PerfResults GetPerfResults() const { return perf_results_; }
[[nodiscard]] PerfResults GetPerfResults() const {
return perf_results_;
}

private:
PerfResults perf_results_;
Expand Down
48 changes: 36 additions & 12 deletions modules/performance/tests/perf_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,13 @@ namespace ppc::test {
template <typename InType, typename OutType>
class TestPerfTask : public ppc::task::Task<InType, OutType> {
public:
explicit TestPerfTask(const InType& in) { this->GetInput() = in; }
explicit TestPerfTask(const InType& in) {
this->GetInput() = in;
}

bool ValidationImpl() override { return !this->GetInput().empty(); }
bool ValidationImpl() override {
return !this->GetInput().empty();
}

bool PreProcessingImpl() override {
this->GetOutput() = 0;
Expand All @@ -39,7 +43,9 @@ class TestPerfTask : public ppc::task::Task<InType, OutType> {
return true;
}

bool PostProcessingImpl() override { return true; }
bool PostProcessingImpl() override {
return true;
}
};

template <typename InType, typename OutType>
Expand Down Expand Up @@ -203,7 +209,9 @@ class GetStringTaskTypeTest : public ::testing::TestWithParam<TaskTypeTestCase>
std::ofstream(temp_path) << j->dump();
}

void TearDown() override { std::filesystem::remove(temp_path); }
void TearDown() override {
std::filesystem::remove(temp_path);
}
};

TEST_P(GetStringTaskTypeTest, ReturnsExpectedString) {
Expand Down Expand Up @@ -279,10 +287,18 @@ TEST(GetStringTaskStatusTest, HandlesEnabledAndDisabled) {
class DummyTask : public Task<int, int> {
public:
using Task::Task;
bool ValidationImpl() override { return true; }
bool PreProcessingImpl() override { return true; }
bool RunImpl() override { return true; }
bool PostProcessingImpl() override { return true; }
bool ValidationImpl() override {
return true;
}
bool PreProcessingImpl() override {
return true;
}
bool RunImpl() override {
return true;
}
bool PostProcessingImpl() override {
return true;
}
};

TEST(TaskTest, GetDynamicTypeReturnsCorrectEnum) {
Expand Down Expand Up @@ -372,10 +388,18 @@ TEST(PerfTest, GetStringParamNameTest) {
TEST(TaskTest, Destructor_InvalidPipelineOrderTerminates_PartialPipeline) {
{
struct BadTask : Task<int, int> {
bool ValidationImpl() override { return true; }
bool PreProcessingImpl() override { return true; }
bool RunImpl() override { return true; }
bool PostProcessingImpl() override { return true; }
bool ValidationImpl() override {
return true;
}
bool PreProcessingImpl() override {
return true;
}
bool RunImpl() override {
return true;
}
bool PostProcessingImpl() override {
return true;
}
} task;
task.Validation();
}
Expand Down
28 changes: 21 additions & 7 deletions modules/task/include/task.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -164,31 +164,45 @@ class Task {

/// @brief Returns the current testing mode.
/// @return Reference to the current StateOfTesting.
StateOfTesting &GetStateOfTesting() { return state_of_testing_; }
StateOfTesting &GetStateOfTesting() {
return state_of_testing_;
}

/// @brief Sets the dynamic task type.
/// @param type_of_task Task type to set.
void SetTypeOfTask(TypeOfTask type_of_task) { type_of_task_ = type_of_task; }
void SetTypeOfTask(TypeOfTask type_of_task) {
type_of_task_ = type_of_task;
}

/// @brief Returns the dynamic task type.
/// @return Current dynamic task type.
[[nodiscard]] TypeOfTask GetDynamicTypeOfTask() const { return type_of_task_; }
[[nodiscard]] TypeOfTask GetDynamicTypeOfTask() const {
return type_of_task_;
}

/// @brief Returns the current task status.
/// @return Task status (enabled or disabled).
[[nodiscard]] StatusOfTask GetStatusOfTask() const { return status_of_task_; }
[[nodiscard]] StatusOfTask GetStatusOfTask() const {
return status_of_task_;
}

/// @brief Returns the static task type.
/// @return Static task type (default: kUnknown).
static constexpr TypeOfTask GetStaticTypeOfTask() { return TypeOfTask::kUnknown; }
static constexpr TypeOfTask GetStaticTypeOfTask() {
return TypeOfTask::kUnknown;
}

/// @brief Returns a reference to the input data.
/// @return Reference to the task's input data.
InType &GetInput() { return input_; }
InType &GetInput() {
return input_;
}

/// @brief Returns a reference to the output data.
/// @return Reference to the task's output data.
OutType &GetOutput() { return output_; }
OutType &GetOutput() {
return output_;
}

/// @brief Destructor. Verifies that the pipeline was executed in the correct order.
/// @note Terminates the program if the pipeline order is incorrect or incomplete.
Expand Down
96 changes: 72 additions & 24 deletions modules/task/tests/task_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,13 @@ namespace ppc::test {
template <typename InType, typename OutType>
class TestTask : public ppc::task::Task<InType, OutType> {
public:
explicit TestTask(const InType& in) { this->GetInput() = in; }
explicit TestTask(const InType& in) {
this->GetInput() = in;
}

bool ValidationImpl() override { return !this->GetInput().empty(); }
bool ValidationImpl() override {
return !this->GetInput().empty();
}

bool PreProcessingImpl() override {
this->GetOutput() = 0;
Expand All @@ -54,7 +58,9 @@ class TestTask : public ppc::task::Task<InType, OutType> {
return true;
}

bool PostProcessingImpl() override { return true; }
bool PostProcessingImpl() override {
return true;
}
};

template <typename InType, typename OutType>
Expand Down Expand Up @@ -149,9 +155,13 @@ TEST(task_tests, premature_postprocessing_after_preprocessing) {
EXPECT_THROW(test_task.PostProcessing(), std::runtime_error);
}

TEST(TaskTest, GetStringTaskStatus_Disabled) { EXPECT_EQ(GetStringTaskStatus(StatusOfTask::kDisabled), "disabled"); }
TEST(TaskTest, GetStringTaskStatus_Disabled) {
EXPECT_EQ(GetStringTaskStatus(StatusOfTask::kDisabled), "disabled");
}

TEST(TaskTest, GetStringTaskStatus_Enabled) { EXPECT_EQ(GetStringTaskStatus(StatusOfTask::kEnabled), "enabled"); }
TEST(TaskTest, GetStringTaskStatus_Enabled) {
EXPECT_EQ(GetStringTaskStatus(StatusOfTask::kEnabled), "enabled");
}

TEST(TaskTest, GetStringTaskType_InvalidFileThrows) {
EXPECT_THROW({ GetStringTaskType(TypeOfTask::kALL, "non_existing_file.json"); }, std::runtime_error);
Expand Down Expand Up @@ -217,11 +227,21 @@ TEST(TaskTest, TaskDestructor_ThrowsIfStageIncomplete) {
{
std::vector<int32_t> in(20, 1);
struct LocalTask : Task<std::vector<int32_t>, int32_t> {
explicit LocalTask(const std::vector<int32_t>& in) { this->GetInput() = in; }
bool ValidationImpl() override { return true; }
bool PreProcessingImpl() override { return true; }
bool RunImpl() override { return true; }
bool PostProcessingImpl() override { return true; }
explicit LocalTask(const std::vector<int32_t>& in) {
this->GetInput() = in;
}
bool ValidationImpl() override {
return true;
}
bool PreProcessingImpl() override {
return true;
}
bool RunImpl() override {
return true;
}
bool PostProcessingImpl() override {
return true;
}
} task(in);
task.Validation();
}
Expand All @@ -233,11 +253,21 @@ TEST(TaskTest, TaskDestructor_ThrowsIfEmpty) {
{
std::vector<int32_t> in(20, 1);
struct LocalTask : Task<std::vector<int32_t>, int32_t> {
explicit LocalTask(const std::vector<int32_t>& in) { this->GetInput() = in; }
bool ValidationImpl() override { return true; }
bool PreProcessingImpl() override { return true; }
bool RunImpl() override { return true; }
bool PostProcessingImpl() override { return true; }
explicit LocalTask(const std::vector<int32_t>& in) {
this->GetInput() = in;
}
bool ValidationImpl() override {
return true;
}
bool PreProcessingImpl() override {
return true;
}
bool RunImpl() override {
return true;
}
bool PostProcessingImpl() override {
return true;
}
} task(in);
}
EXPECT_TRUE(ppc::util::DestructorFailureFlag::Get());
Expand All @@ -246,14 +276,22 @@ TEST(TaskTest, TaskDestructor_ThrowsIfEmpty) {

TEST(TaskTest, InternalTimeTest_ThrowsIfTimeoutExceeded) {
struct SlowTask : Task<std::vector<int32_t>, int32_t> {
explicit SlowTask(const std::vector<int32_t>& in) { this->GetInput() = in; }
bool ValidationImpl() override { return true; }
explicit SlowTask(const std::vector<int32_t>& in) {
this->GetInput() = in;
}
bool ValidationImpl() override {
return true;
}
bool PreProcessingImpl() override {
std::this_thread::sleep_for(std::chrono::seconds(2));
return true;
}
bool RunImpl() override { return true; }
bool PostProcessingImpl() override { return true; }
bool RunImpl() override {
return true;
}
bool PostProcessingImpl() override {
return true;
}
};

std::vector<int32_t> in(20, 1);
Expand All @@ -268,10 +306,18 @@ TEST(TaskTest, InternalTimeTest_ThrowsIfTimeoutExceeded) {
class DummyTask : public Task<int, int> {
public:
using Task::Task;
bool ValidationImpl() override { return true; }
bool PreProcessingImpl() override { return true; }
bool RunImpl() override { return true; }
bool PostProcessingImpl() override { return true; }
bool ValidationImpl() override {
return true;
}
bool PreProcessingImpl() override {
return true;
}
bool RunImpl() override {
return true;
}
bool PostProcessingImpl() override {
return true;
}
};

TEST(TaskTest, ValidationThrowsIfCalledTwice) {
Expand All @@ -297,4 +343,6 @@ TEST(TaskTest, PostProcessingThrowsIfCalledBeforeRun) {
EXPECT_THROW(task->PostProcessing(), std::runtime_error);
}

int main(int argc, char** argv) { return ppc::runners::SimpleInit(argc, argv); }
int main(int argc, char** argv) {
return ppc::runners::SimpleInit(argc, argv);
}
8 changes: 6 additions & 2 deletions modules/util/include/func_test_util.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,13 @@ class BaseRunFuncTests : public ::testing::TestWithParam<FuncTestParam<InType, O
InitializeAndRunTask(test_param);
}

void ValidateTestName(const std::string& test_name) { EXPECT_FALSE(test_name.find("unknown") != std::string::npos); }
void ValidateTestName(const std::string& test_name) {
EXPECT_FALSE(test_name.find("unknown") != std::string::npos);
}

bool IsTestDisabled(const std::string& test_name) { return test_name.find("disabled") != std::string::npos; }
bool IsTestDisabled(const std::string& test_name) {
return test_name.find("disabled") != std::string::npos;
}

bool ShouldSkipNonMpiTask(const std::string& test_name) {
auto contains_substring = [&](const std::string& substring) {
Expand Down
16 changes: 12 additions & 4 deletions modules/util/include/util.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,20 @@ namespace ppc::util {
class DestructorFailureFlag {
public:
/// @brief Marks that a destructor failure has occurred.
static void Set() { failure_flag.store(true); }
static void Set() {
failure_flag.store(true);
}

/// @brief Clears the destructor failure flag.
static void Unset() { failure_flag.store(false); }
static void Unset() {
failure_flag.store(false);
}

/// @brief Checks if a destructor failure was recorded.
/// @return True if failure occurred, false otherwise.
static bool Get() { return failure_flag.load(); }
static bool Get() {
return failure_flag.load();
}

private:
inline static std::atomic<bool> failure_flag{false};
Expand Down Expand Up @@ -79,7 +85,9 @@ std::string GetNamespace() {
return (pos != std::string::npos) ? name.substr(0, pos) : std::string{};
}

inline std::shared_ptr<nlohmann::json> InitJSONPtr() { return std::make_shared<nlohmann::json>(); }
inline std::shared_ptr<nlohmann::json> InitJSONPtr() {
return std::make_shared<nlohmann::json>();
}

bool IsUnderMpirun();

Expand Down
4 changes: 3 additions & 1 deletion modules/util/src/func_test_util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

#include "util/include/perf_test_util.hpp"

double ppc::util::GetTimeMPI() { return MPI_Wtime(); }
double ppc::util::GetTimeMPI() {
return MPI_Wtime();
}

int ppc::util::GetMPIRank() {
int rank = -1;
Expand Down
4 changes: 3 additions & 1 deletion tasks/common/runners/performance.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#include "runners/include/runners.hpp"

int main(int argc, char** argv) { return ppc::runners::Init(argc, argv); }
int main(int argc, char** argv) {
return ppc::runners::Init(argc, argv);
}
Loading
Loading