/************************************************************************* * * Copyright (c) 2023 Fabian Posch * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. * ************************************************************************** */ #ifndef __TASK_H__ #define __TASK_H__ #include #include #include #include "db_types.hpp" /** * @brief Representation of the current status of a job. * */ enum class JobStatusType {NOT_STARTED, IN_PROGRESS, FINISHED, HALTED, UNKNOWN}; // string mapping for job status type enum static std::unordered_map job_status_type_st { {JobStatusType::NOT_STARTED, "not_started"}, {JobStatusType::IN_PROGRESS, "in_progress"}, {JobStatusType::FINISHED, "finished"}, {JobStatusType::HALTED, "halted"}, {JobStatusType::UNKNOWN, "unknown"} }; inline std::string to_string(JobStatusType const &value) { return job_status_type_st[value]; }; inline std::ostream& operator<<(std::ostream& os, JobStatusType& value) { os << to_string(value); return os; }; JobStatusType convert_to_job_status(std::string status_string); /** * @brief Defines if a simulation task should be executed a single time or * dependent on a central coverage model. The latter task type can also be * executed by more than just a single node to hasten progress. */ enum class TaskTypeType {UNKNOWN, SINGLE, MULTI_COV}; // string mapping for task type enum static std::unordered_map task_type_type_st { {TaskTypeType::UNKNOWN, "unknown"}, {TaskTypeType::SINGLE, "single"}, {TaskTypeType::MULTI_COV, "multi_cov"} }; inline std::string to_string(TaskTypeType const &value) { return task_type_type_st[value]; }; inline std::ostream& operator<<(std::ostream& os, TaskTypeType& value) { os << to_string(value); return os; }; TaskTypeType convert_to_task_type(std::string type_string); // TODO check if this is complete /** * @brief If a task simulation was aborted or completed with an error, * this type represents the types of error encountered. */ enum class TaskErrorType {UNKNOWN, NONE, SYNTAX, VALUE, CODE, METASTABLE, TIMING, DEADLOCK}; // string mapping for task error type enum static std::unordered_map task_error_type_st { {TaskErrorType::UNKNOWN, "unknown"}, {TaskErrorType::NONE, "none"}, {TaskErrorType::SYNTAX, "syntax"}, {TaskErrorType::VALUE, "value"}, {TaskErrorType::CODE, "code"}, {TaskErrorType::METASTABLE, "metastable"}, {TaskErrorType::TIMING, "timing"}, {TaskErrorType::DEADLOCK, "deadlock"} }; inline std::string to_string(TaskErrorType const &value) { return task_error_type_st[value]; }; inline std::ostream& operator<<(std::ostream& os, TaskErrorType& value) { os << to_string(value); return os; }; TaskErrorType convert_to_task_error(std::string error_string); /** * @brief Representation of teh current status of a task. * */ enum class TaskStatusType {UNKNOWN, OPEN, IN_PROGRESS, DONE}; // string mapping for task status enum static std::unordered_map task_status_type_st { {TaskStatusType::UNKNOWN, "unknown"}, {TaskStatusType::OPEN, "open"}, {TaskStatusType::IN_PROGRESS, "in_progress"}, {TaskStatusType::DONE, "done"} }; inline std::string to_string(TaskStatusType const &value) { return task_status_type_st[value]; }; inline std::ostream& operator<<(std::ostream& os, TaskStatusType& value) { os << to_string(value); return os; }; TaskStatusType convert_to_task_status(std::string status_string); /** * @brief Task class represents one simulation task and its settings. */ class Task { public: Task( db::uuid_t task_uuid, TaskStatusType status, TaskTypeType type, bool is_reference, db::uuid_t reference_uuid, float max_plf, TaskErrorType error, std::string sim_log ); Task( db::uuid_t task_uuid, TaskTypeType type, bool is_reference, db::uuid_t reference_uuid, float max_plf ); /** * @brief Get the UUID of this task * * @return db::uuid_t Task UUID */ const db::uuid_t& uuid = task_uuid; /** * @brief Get information whether this task is a one shot simulation or contributes * to a central coverage model. * * @return TaskType */ const TaskTypeType& task_type = task_type_; /** * @brief Does this simulation task have a reference task to compare to? * * @return true It does * @return false It does not */ const bool& is_reference_run = is_reference_; /** * @brief Get the reference object UUID * * @return The UUID of the reference simulation task */ const db::uuid_t& reference_uuid = reference_uuid_; /** * @brief Get the status of this task * * @return TaskStatusType The task status */ const TaskStatusType& status = status_; /** * @brief Set the status of the task * * @param new_status The new status this task should be set to */ void set_status(TaskStatusType new_status) { this->status_ = new_status; }; /** * @brief Get the value of the maximum allowed pipeline load factor * * @return float */ const float& max_plf = max_plf_; /** * @brief Get the error with which this simulation task was completed * * @return TaskErrorType */ const TaskErrorType& error = error_; /** * @brief Set the error with which this task was completed * * @param error */ void set_error(TaskErrorType error) { this->error_ = error; }; /** * @brief Get the simulation log of this task. Empty if not yet simulated. * * @return std::string The simulation log in JSON format */ const std::string& sim_log = sim_log_; /** * @brief Set the simulation log * * @param log */ void set_log(std::string log) { this->sim_log_ = log; }; /** * @brief Get the simulation trace of this task. Empty if not yet simulated. * * @return std::string The simulation log in TODO format */ const std::string& trace = trace_; /** * @brief Set the simulation trace * * @param trace */ void set_trace(std::string trace) { this->trace_ = trace; }; ///////////////////////////////////// private: // UUID of this task in the database db::uuid_t task_uuid; // Is this task a single shot or does it depend on central coverage metrics? TaskTypeType task_type_; // Does this task have a reference run which we should compare the trace to? bool is_reference_; TaskStatusType status_; db::uuid_t reference_uuid_; // maximum pipeline load factor float max_plf_; // error with which this task was completed TaskErrorType error_; // simulation output std::string sim_log_; std::string trace_; }; #endif