From 258972f7148e10f14deda0ffaf0dfbd8df262372 Mon Sep 17 00:00:00 2001 From: Charlie Kushelevsky Date: Thu, 22 Aug 2024 21:37:37 -0700 Subject: [PATCH] chore: implemented changes from last review --- .github/workflows/test.yml | 2 +- .vscode/c_cpp_properties.json | 3 +- .vscode/launch.json | 21 ----- src/abstractScheduler.hpp | 1 + src/rideTask.cpp | 14 ++-- src/rideTask.hpp | 9 ++- src/scheduler.cpp | 139 +++++++++++++++++--------------- src/scheduler.hpp | 86 +++++++++++--------- tests/examine_behavior.cpp | 5 +- tests/file_google_tests.cpp | 4 +- tests/fixed_google_tests.cpp | 8 +- tests/fixed_google_tests_v2.cpp | 45 ----------- tests/scheduler_proccessor.py | 8 +- tests/scheduler_test_flog.cpp | 1 + tests/scheduler_test_system.cpp | 2 +- tests/test_ensembles.hpp | 1 - 16 files changed, 158 insertions(+), 191 deletions(-) delete mode 100644 tests/fixed_google_tests_v2.cpp diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 8d33b92f..d17775b0 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -21,7 +21,7 @@ jobs: - name: add googletest run: | git submodule init - git submodule update + git submodule --recursive update diff --git a/.vscode/c_cpp_properties.json b/.vscode/c_cpp_properties.json index 691ed412..57178b72 100644 --- a/.vscode/c_cpp_properties.json +++ b/.vscode/c_cpp_properties.json @@ -41,7 +41,8 @@ "includePath": [ "${workspaceFolder}/src", "${workspaceFolder}/tests", - "${workspaceFolder}/src/cli" + "${workspaceFolder}/src/cli", + "${workspaceFolder}/external/googletest/googletest/include" ], "defines": [ "_DEBUG", diff --git a/.vscode/launch.json b/.vscode/launch.json index 50d0c821..135eb5ce 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -1,27 +1,6 @@ { "version": "0.2.0", "configurations": [ - - { - "name": "Python Debugger: Current File", - "type": "debugpy", - "request": "launch", - "program": "${file}", - "console": "integratedTerminal", - "cwd": "${workspaceRoot}/tests" - }, - { - "name": "Semantic Release", - "type": "debugpy", - "request": "launch", - "program": "semantic_release_prepare.py", - "console": "integratedTerminal", - "args": [ - "1.2.3", - "37-feat-semver", - "src/vers.hpp" - ] - }, { "type": "cortex-debug", "request": "attach", diff --git a/src/abstractScheduler.hpp b/src/abstractScheduler.hpp index afc921c3..b605f8c9 100644 --- a/src/abstractScheduler.hpp +++ b/src/abstractScheduler.hpp @@ -3,6 +3,7 @@ #include #include #include + #include "deploymentSchedule.hpp" typedef enum error_ diff --git a/src/rideTask.cpp b/src/rideTask.cpp index 9f0d8fa4..1d2dd84e 100644 --- a/src/rideTask.cpp +++ b/src/rideTask.cpp @@ -3,22 +3,22 @@ * @brief Contains definitions for functions defined in @ref rideTask.hpp * @version 1 */ + + #include "rideTask.hpp" #include "Particle.h" -#include -#include "cli/conio.hpp" #include "consts.hpp" - -#include "system.hpp" -#include "sleepTask.hpp" +#include "cli/conio.hpp" #include "util.hpp" #include "vers.hpp" #include "ensembles.hpp" #include "cli/flog.hpp" -#include "charlie_scheduler.hpp" -#include "antara_scheduler.hpp" +#include "system.hpp" +#include "sleepTask.hpp" #include "scheduler.hpp" +#include + /** * @brief creates file name for log * @todo implement RIDE_setFileName diff --git a/src/rideTask.hpp b/src/rideTask.hpp index 52f0413a..374fa6e1 100644 --- a/src/rideTask.hpp +++ b/src/rideTask.hpp @@ -6,10 +6,12 @@ #ifndef __RIDE_HPP__ #define __RIDE_HPP__ #include "task.hpp" - -#include "Particle.h" #include "product.hpp" + +#include + + /** * @class RideTask * @brief Manages deployment of measurements and recording @@ -33,8 +35,9 @@ class RideTask : public Task */ void exit(void); private: + //! TODO: implement LEDStatus + //LEDStatus ledStatus; //!< manages led behavior - LEDStatus ledStatus; /**< manages led behavior*/ system_tick_t startTime; /**< start time at initialization */ }; diff --git a/src/scheduler.cpp b/src/scheduler.cpp index d6cd12bb..7305b041 100644 --- a/src/scheduler.cpp +++ b/src/scheduler.cpp @@ -4,39 +4,49 @@ * @author Charlie Kushelevsky (ckushelevsky@ucsd.edu) * @version 1 */ +#include "scheduler.hpp" +#include "cli/conio.hpp" +#include "ensembles.hpp" +#include "consts.hpp" +#include "cli/flog.hpp" + +#include +#include #ifndef TEST_VERSION #include "Particle.h" #else #include "scheduler_test_system.hpp" #endif -#include -#include "cli/conio.hpp" -#include "ensembles.hpp" -#include "scheduler.hpp" -#include "consts.hpp" -#include -#include - +/** + * @brief constructor for scheduler + * + * @param schedule the schedule table +*/ Scheduler::Scheduler(DeploymentSchedule_t schedule[]) - : scheduleTable(schedule){} - /** - * @brief Initializes ensembles within schedule table. - * - */ + : scheduleTable(schedule) {} +/** + * @brief Initializes ensembles within schedule table. + * + */ void Scheduler::initializeScheduler() { - DeploymentSchedule_t* pDeployment = scheduleTable; - uint32_t lastEndTime = 0; + DeploymentSchedule_t* pDeployment = this->scheduleTable; + std::uint32_t lastEndTime = 0; tableSize = 0; + if (this->scheduleTable == nullptr) + { + return; + } while (pDeployment->init) { - tableSize++; - memset(&(pDeployment->state), 0, - sizeof(StateInformation)); + memset(&(pDeployment->state), 0, + sizeof(StateInformation)); + pDeployment->init(pDeployment); + tableSize++; pDeployment++; } } @@ -49,36 +59,35 @@ void Scheduler::initializeScheduler() * This function iterates through a schedule table to find the event that * should run next based on the current system time. * It ensures that no overlapping events are scheduled by checking with - * @ref SCH_willOverlap(). * - * @see tests/gtest.cpp for intended behavior + * @see tests/googletests.cpp for intended behavior * - * @param scheduleTable Pointer to the first element of an array of - * DeploymentSchedule_t, which contains the scheduling information. + * * @param p_nextEvent Pointer to a pointer where the next event to be executed * will be stored. * @param p_nextTime Pointer to where the time for the next event will * be stored. * + * @param currentTime The current system time * @return Returns SUCCESS if a suitable event is found, * TASK_SEARCH_FAIL otherwise. */ -SCH_error_e Scheduler::getNextTask(DeploymentSchedule_t** p_nextEvent, +SCH_error_e Scheduler::getNextTask(DeploymentSchedule_t** p_nextEvent, std::uint32_t* p_nextTime, std::uint32_t currentTime) { - uint32_t minNextTime = UINT32_MAX; + std::uint32_t minNextTime = UINT32_MAX; DeploymentSchedule_t* nextEvent = nullptr; - - // Iterate through each event in the schedule table. - - for(int idx = tableSize - 1; idx>=0; idx--) + + // Iterate through each event in the schedule table in reverse order. + + for (int idx = tableSize - 1; idx >= 0; idx--) { bool canSet = true; DeploymentSchedule_t& currentEvent = scheduleTable[idx]; - StateInformation& state = scheduleTable[idx].state; - std::uint32_t runTime = state.nextRunTime; + StateInformation& currentEventState = scheduleTable[idx].state; + std::uint32_t runTime = currentEventState.nextRunTime; int delay = currentTime - runTime; if (delay > 0) { @@ -90,58 +99,60 @@ SCH_error_e Scheduler::getNextTask(DeploymentSchedule_t** p_nextEvent, } if (delay >= currentEvent.maxDelay) { - //send warning + //! TODO: send warning } - int completion = runTime + currentEvent.maxDuration; + int expected_completion = runTime + currentEvent.maxDuration; int j = 0; - while (j < idx && canSet) + for (int j = 0; (j < idx) && canSet; j++) { - if (scheduleTable[j].state.nextRunTime < completion) + if (scheduleTable[j].state.nextRunTime < expected_completion) { canSet = false; } - j++; } if (canSet) { *p_nextEvent = ¤tEvent; - state.nextRunTime = runTime + currentEvent.ensembleInterval; - - state.measurementCount++; *p_nextTime = runTime; - if(delay>0){ + currentEventState.nextRunTime = runTime + + currentEvent.ensembleInterval; + + currentEventState.measurementCount++; + + if (delay > 0) + { FLOG_AddError(FLOG_SCHEDULER_DELAY_EXCEEDED, - state.measurementCount); - #ifdef TEST_VERSION - std::ofstream logfile; - if (currentTime == 0) - { - logfile = std::ofstream("scheduler.log"); - - } - else - { - logfile = std::ofstream("scheduler.log", std::ios::app); - } - if (logfile.is_open()) - { - logfile << currentEvent.taskName - << "|" - << state.measurementCount - <<"\n"; - logfile.close(); - } - #endif - + currentEventState.measurementCount); + #ifdef TEST_VERSION + std::ofstream logfile; + if (currentTime == 0) + { + logfile = std::ofstream("scheduler.log"); + + } + else + { + logfile = std::ofstream("scheduler.log", std::ios::app); + } + if (logfile.is_open()) + { + logfile << currentEvent.taskName + << "|" + << currentEventState.measurementCount + << "\n"; + logfile.close(); + } + #endif + } return SCHEDULER_SUCCESS; } - - + + } - return TASK_SEARCH_FAIL; + return TASK_SEARCH_FAIL; } diff --git a/src/scheduler.hpp b/src/scheduler.hpp index cfa82ede..80bd4adc 100644 --- a/src/scheduler.hpp +++ b/src/scheduler.hpp @@ -4,21 +4,22 @@ * @brief Header file for scheduler defined in @ref scheduler.cpp * @version 1 */ -#ifndef __CONSOLODATED_SCHEDULER__HPP__ -#define __CONSOLODATED_SCHEDULER__HPP__ +#ifndef __SCHEDULER_HPP__ +#define __SCHEDULER_HPP__ #include "product.hpp" - - -#include -#include - #include "deploymentSchedule.hpp" #include "abstractScheduler.hpp" #include "cli/conio.hpp" + #ifndef TEST_VERSION #include "Particle.h" #else #include "scheduler_test_system.hpp" + +#include +#include + + #endif // TEST_VERSION @@ -36,6 +37,7 @@ * @param pDeployment the schedule table */ typedef void (*EnsembleFunction)(DeploymentSchedule_t* pDeployment); + /** * @brief Ensemble initialization function. * @@ -43,55 +45,66 @@ typedef void (*EnsembleFunction)(DeploymentSchedule_t* pDeployment); * @param pDeployment the schedule table */ typedef void (*EnsembleInit)(DeploymentSchedule_t* pDeployment); + /** -* @brief contains stat information for each ensemble -*/ + * @brief Records and writes ensemble + * @param pDeployment the schedule table + */ +typedef void (*EnsembleProccess)(DeploymentSchedule_t* pDeployment); +/** +* @brief contains state information for each ensemble +*/ struct StateInformation { - //! how many times ensemble was scheduled std::uint32_t measurementCount; - //! store the next time the task should run std::uint32_t nextRunTime; }; -/** - * @brief Records and writes ensemble - * @param pDeployment the schedule table - */ -typedef void (*EnsembleProccess)(DeploymentSchedule_t* pDeployment); + struct DeploymentSchedule_ { EnsembleFunction measure; //!< measurement function EnsembleInit init; //!< initialization function - //EnsembleProccess process; //!< processing function - - uint32_t measurementsToAccumulate; //!< measurements before processing - uint32_t ensembleDelay; //!< delay after deployment start - uint32_t ensembleInterval; //!< time between ensembles - //! store max running time of measurement - uint32_t maxDuration; - //! maximum delay before throwing flag and resetting - uint32_t maxDelay; + + //! measurements before processing + const std::uint32_t measurementsToAccumulate; + + //! time between ensembles + const std::uint32_t ensembleInterval; + + //! max running time of measurement + const std::uint32_t maxDuration; + + //! max delay before throwing flag and resetting + const std::uint32_t maxDelay; + //! task name of ensemble - const char* taskName; + const char* taskName; + //! state information - StateInformation state; + StateInformation state; }; class Scheduler : public AbstractScheduler { private: + //! schedule table size uint32_t tableSize; public: + //! the schedule table DeploymentSchedule_t* scheduleTable; - + /** + * @brief constructor for scheduler + * + * @param schedule the schedule table + */ Scheduler(DeploymentSchedule_t* scheduler); /** @@ -103,11 +116,7 @@ class Scheduler : public AbstractScheduler { void initializeScheduler(); /** - * @brief Determines if a task will overlap with other scheduled tasks. - * - * This function checks if the proposed start and end times of a task - * overlap with any other tasks in the schedule table. It ensures that - * tasks are scheduled without conflicts. + * @brief Determines the next task to run * * @param scheduleTable The table containing all scheduled tasks. * @param idx The index of the current task in the schedule table. @@ -115,13 +124,12 @@ class Scheduler : public AbstractScheduler { * @param nextStartTime The proposed start time of the current task. * @return True if there is an overlap with another task; false otherwise. */ - SCH_error_e getNextTask(DeploymentSchedule_t** p_next_task, - uint32_t* p_next_runtime, - uint32_t current_time); + SCH_error_e getNextTask(DeploymentSchedule_t** p_nextEvent, + std::uint32_t* p_nextTime, + std::uint32_t currentTime); - bool willOverlap(uint32_t i, system_tick_t currentTime, - uint32_t nextStartTime); + }; -#endif //__CONSOLODATED_SCHEDULER__HPP__ \ No newline at end of file +#endif //__SCHEDULER_HPP__ \ No newline at end of file diff --git a/tests/examine_behavior.cpp b/tests/examine_behavior.cpp index cd67a6b4..d6376854 100644 --- a/tests/examine_behavior.cpp +++ b/tests/examine_behavior.cpp @@ -16,6 +16,7 @@ #include + class ExamineBehavior { public: @@ -135,7 +136,7 @@ class ExamineBehavior DeploymentSchedule_t e; for (size_t i = 0; i < input.ensembles.size(); i++) { - e = { SS_ensembleAFunc, SS_ensembleAInit, 1, 0, + e = { SS_ensembleAFunc, SS_ensembleAInit, 1, input.ensembles[i].interval, input.ensembles[i].duration, input.ensembles[i].delay, @@ -143,7 +144,7 @@ class ExamineBehavior {0} }; deploymentSchedule.emplace_back(e); } - e = { nullptr, nullptr, 0, 0, 0, 0, 0, "", {0}}; + e = { nullptr, nullptr, 0, 0, 0, 0, "", {0}}; deploymentSchedule.emplace_back(e); scheduler = std::make_unique(deploymentSchedule.data()); diff --git a/tests/file_google_tests.cpp b/tests/file_google_tests.cpp index b1288c9b..4070e85f 100644 --- a/tests/file_google_tests.cpp +++ b/tests/file_google_tests.cpp @@ -3,11 +3,13 @@ * @author Charlie Kushelevsky (ckushelevsky@ucsd.edu) * @brief Google Tests for scheduler.cpp */ -#include + #include "scheduler_test_system.hpp" #include "test_ensembles.hpp" #include "scheduler.hpp" +#include + #include #include #include diff --git a/tests/fixed_google_tests.cpp b/tests/fixed_google_tests.cpp index 4e615783..8ccedc74 100644 --- a/tests/fixed_google_tests.cpp +++ b/tests/fixed_google_tests.cpp @@ -3,17 +3,21 @@ * @author Charlie Kushelevsky (ckushelevsky@ucsd.edu) * @brief Google Tests for scheduler.cpp */ -#include + #include "scheduler_test_system.hpp" #include "scheduler.hpp" #include "test_ensembles.hpp" +#include "cli/flog.hpp" + +#include + #include #include #include #include #include #include -#include "cli/flog.hpp" + class SchedulerFixedTests : public ::testing::Test diff --git a/tests/fixed_google_tests_v2.cpp b/tests/fixed_google_tests_v2.cpp deleted file mode 100644 index 026ed405..00000000 --- a/tests/fixed_google_tests_v2.cpp +++ /dev/null @@ -1,45 +0,0 @@ -#include -#include -#include -/** - * name of test class: ClassName -*/ - -class ClassName : public ::testing::Test -{ -//required -protected: - std::vector test; - - ClassName() - { - test.reserve(5); - test.emplace_back(5); - } - void SetUp() override{ - test.emplace_back(10); - } - void TearDown() override{ - for (int i = 0; i < get_size(); i++) - { - std::cout << test[i] << "\t"; - } - std::cout << "\n"; - - } - - - int get_size() - { - return test.size(); - } - - -}; - -TEST_F(ClassName, Test1) -{ - test.emplace_back(20); - ASSERT_EQ(test[1], 20); - -}; diff --git a/tests/scheduler_proccessor.py b/tests/scheduler_proccessor.py index 15da40b8..b784807c 100644 --- a/tests/scheduler_proccessor.py +++ b/tests/scheduler_proccessor.py @@ -1,6 +1,5 @@ -import re +from pathlib import Path import matplotlib as mpl -mpl.use('Agg') import matplotlib.pyplot as plt import numpy as np import os @@ -8,8 +7,11 @@ import os.path import cv2 import json -from pathlib import Path + import glob + +mpl.use('Agg') + def comparelogs(): actual_json, expected_json = parse_logs() diff --git a/tests/scheduler_test_flog.cpp b/tests/scheduler_test_flog.cpp index 3f3403d3..d523bcf0 100644 --- a/tests/scheduler_test_flog.cpp +++ b/tests/scheduler_test_flog.cpp @@ -2,6 +2,7 @@ #include "cli/conio.hpp" #include "consts.hpp" #include "scheduler_test_system.hpp" + #include #include diff --git a/tests/scheduler_test_system.cpp b/tests/scheduler_test_system.cpp index 3693c354..e53584d6 100644 --- a/tests/scheduler_test_system.cpp +++ b/tests/scheduler_test_system.cpp @@ -7,8 +7,8 @@ #include "scheduler_test_system.hpp" #include "cli/conio.hpp" #include "cli/flog.hpp" -#include +#include #include #include #include diff --git a/tests/test_ensembles.hpp b/tests/test_ensembles.hpp index 65a7a301..1f518ccd 100644 --- a/tests/test_ensembles.hpp +++ b/tests/test_ensembles.hpp @@ -8,7 +8,6 @@ #include "product.hpp" #include "scheduler.hpp" -#include "scheduler.hpp" /** * @brief dummy ensemble init function * @param pDeployment schedule table