-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
adding more tests for the state machine
- Loading branch information
Showing
9 changed files
with
107 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
testing strategy: | ||
- using GTest for mocking systems | ||
- custom re-definitions of interfaces (for now) | ||
- cant use GTest mocking easily for this I dont think | ||
|
||
- the mock interfaces will just be empty classes p much to have something that the systems classes can have pointers to if they own a pointer to an interface | ||
|
||
- the mock systems will use the gmock lib for better mocking of systems for system to system interaction in the test env | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,17 @@ | ||
#include <gtest/gtest.h> | ||
|
||
#include "state_machine_test.h" | ||
#include "pedals_system_test.h" | ||
void setUp(void) | ||
{ | ||
// declare a component obj | ||
// possibly make temp class that is a freind class of PedalsSystem to access private members | ||
// possibly modify the | ||
} | ||
// #include "pedals_system_test.h" | ||
|
||
void tearDown(void) | ||
{ | ||
} | ||
|
||
int main() | ||
{ | ||
|
||
UNITY_BEGIN(); | ||
int main(int argc, char **argv) | ||
{ | ||
|
||
RUN_TEST(test_pedal_is_active); | ||
RUN_TEST(test_state_machine_init_tick); | ||
|
||
|
||
UNITY_END(); // stop unit testing | ||
testing::InitGoogleMock(&argc, argv); | ||
if (RUN_ALL_TESTS()) | ||
; | ||
// Always return zero-code and allow PlatformIO to parse results | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,55 +1,116 @@ | ||
#ifndef STATE_MACHINE_TEST | ||
#define STATE_MACHINE_TEST | ||
#include <unity.h> | ||
#include <gtest/gtest.h> | ||
#include <gmock/gmock.h> | ||
#include "MCUStateMachine.h" | ||
#include "PedalsSystem.h" | ||
|
||
|
||
|
||
|
||
class DrivetrainMock | ||
{ | ||
public: | ||
|
||
|
||
bool drivetrain_ready_; | ||
bool drivetrain_ready() {}; | ||
bool hv_thresh_; | ||
bool drivetrain_ready(){}; | ||
/// @param curr_time current system tick time (millis()) that sets the init phase start time | ||
void enable_drivetrain_hv(unsigned long curr_time){}; | ||
|
||
// startup phase 2 | ||
bool check_drivetrain_quit_dc_on() {}; | ||
bool check_drivetrain_quit_dc_on(){}; | ||
|
||
// on entry logic | ||
void request_enable() {}; | ||
void command_drivetrain_no_torque() {}; | ||
void request_enable(){}; | ||
void command_drivetrain_no_torque(){}; | ||
|
||
// final check for drivetrain initialization to check if quit inverter on | ||
bool drivetrain_enabled(){}; | ||
|
||
// check to see if init time limit has passed | ||
bool inverter_init_timeout(unsigned long curr_time) {}; | ||
bool inverter_init_timeout(unsigned long curr_time){}; | ||
|
||
bool hv_over_threshold_on_drivetrain() {}; | ||
void disable() {}; | ||
bool drivetrain_error_occured() {}; | ||
bool hv_over_threshold_on_drivetrain() { return hv_thresh_; }; | ||
void disable(){}; | ||
bool drivetrain_error_occured(){}; | ||
|
||
void command_drivetrain(const DrivetrainCommand &data) {}; | ||
void command_drivetrain(const DrivetrainCommand &data){}; | ||
}; | ||
|
||
|
||
BuzzerController buzzer(500); | ||
|
||
DrivetrainMock drivetrain; | ||
|
||
|
||
PedalsParams params_for_test = {1, 1, 10, 10, 1, 1, 9, 9}; | ||
PedalsSystem pedals(params_for_test, params_for_test); | ||
|
||
DashboardInterface dash_interface; | ||
|
||
MCUStateMachine<DrivetrainMock> state_machine(&buzzer, &drivetrain, &dash_interface); | ||
MCUStateMachine<DrivetrainMock> state_machine(&buzzer, &drivetrain, &dash_interface, &pedals); | ||
|
||
void test_state_machine_init_tick(void) | ||
TEST(MCUStateMachineTesting, test_state_machine_init_tick) | ||
{ | ||
unsigned long sys_time = 1000; | ||
TEST_ASSERT_TRUE(state_machine.get_state() == CAR_STATE::STARTUP); | ||
EXPECT_EQ(state_machine.get_state(), CAR_STATE::STARTUP); | ||
state_machine.tick_state_machine(sys_time); | ||
TEST_ASSERT_TRUE(state_machine.get_state() == CAR_STATE::TRACTIVE_SYSTEM_NOT_ACTIVE); | ||
EXPECT_EQ(state_machine.get_state(), CAR_STATE::TRACTIVE_SYSTEM_NOT_ACTIVE); | ||
} | ||
|
||
|
||
|
||
TEST(MCUStateMachineTesting, test_state_machine_tractive_system_activation) | ||
{ | ||
unsigned long sys_time = 1000; | ||
|
||
// ticking without hv over threshold testing and ensuring the tractive system not active still | ||
state_machine.tick_state_machine(sys_time); | ||
sys_time += 1; | ||
drivetrain.hv_thresh_ = false; | ||
state_machine.tick_state_machine(sys_time); | ||
sys_time += 1; | ||
EXPECT_EQ(state_machine.get_state(), CAR_STATE::TRACTIVE_SYSTEM_NOT_ACTIVE); | ||
|
||
// hv going over threshold -> tractive system | ||
drivetrain.hv_thresh_ = true; | ||
sys_time +=1; | ||
state_machine.tick_state_machine(sys_time); | ||
EXPECT_EQ(state_machine.get_state(), CAR_STATE::TRACTIVE_SYSTEM_ACTIVE); | ||
|
||
|
||
// hv going under thresh -> tractive system not active | ||
drivetrain.hv_thresh_ =false; | ||
sys_time +=1; | ||
state_machine.tick_state_machine(sys_time); | ||
EXPECT_EQ(state_machine.get_state(), CAR_STATE::TRACTIVE_SYSTEM_NOT_ACTIVE); | ||
} | ||
|
||
TEST(MCUStateMachineTesting, test_state_machine_tractive_system_enabling) | ||
{ | ||
unsigned long sys_time = 1000; | ||
|
||
// ticking without hv over threshold testing and ensuring the tractive system not active still | ||
state_machine.tick_state_machine(sys_time); | ||
sys_time += 1; | ||
drivetrain.hv_thresh_ = false; | ||
state_machine.tick_state_machine(sys_time); | ||
sys_time += 1; | ||
EXPECT_EQ(state_machine.get_state(), CAR_STATE::TRACTIVE_SYSTEM_NOT_ACTIVE); | ||
|
||
// hv going over threshold -> tractive system | ||
drivetrain.hv_thresh_ = true; | ||
sys_time +=1; | ||
state_machine.tick_state_machine(sys_time); | ||
EXPECT_EQ(state_machine.get_state(), CAR_STATE::TRACTIVE_SYSTEM_ACTIVE); | ||
|
||
|
||
sys_time +=1; | ||
dash_interface.start_button_status_ = true; | ||
auto pedals_brake_active_res = pedals.evaluate_pedals({0,0,3,3}, sys_time); | ||
state_machine.tick_state_machine(sys_time); | ||
EXPECT_EQ(state_machine.get_state(), CAR_STATE::ENABLING_INVERTERS); | ||
|
||
|
||
} | ||
|
||
|
||
#endif /* STATE_MACHINE_TEST */ |