diff --git a/.github/workflows/test-check.yml b/.github/workflows/test-check.yml new file mode 100644 index 00000000..1a471da2 --- /dev/null +++ b/.github/workflows/test-check.yml @@ -0,0 +1,20 @@ +name: Unit Test Check + +on: [push] + +jobs: + test-check: + runs-on: ubuntu-latest + timeout-minutes: 10 + steps: + - name: Checkout Code + uses: actions/checkout@v4 + with: + submodules: recursive + - name: Run UNITY Testing files + run: | + if ! docker compose run --rm ner-gcc-arm \ + bash -c "python3 Drivers/Embedded-Base/ner_environment/build_system/test_runner.py"; then + echo "Unit tests failed." + exit 1 + fi diff --git a/Core/Inc/bms.h b/Core/Inc/bms.h index 80598c40..01df7008 100644 --- a/Core/Inc/bms.h +++ b/Core/Inc/bms.h @@ -1,7 +1,7 @@ #ifndef BMS_H #define BMS_H -#include "cmsis_os.h" +#include "ner_cmsis_os.h" #include "can.h" #define BMS_CANID_CELL_TEMPS 0x84 /* BMS CELL TEMPERATURES */ diff --git a/Core/Inc/can_handler.h b/Core/Inc/can_handler.h index fb075bc1..a1a0e9b4 100644 --- a/Core/Inc/can_handler.h +++ b/Core/Inc/can_handler.h @@ -2,11 +2,11 @@ #define CAN_HANDLER_H #include "can.h" -#include "cmsis_os.h" +#include "ner_cmsis_os.h" #include "control.h" #include "dti.h" #include "bms.h" -#include "stm32f4xx_hal.h" +#include "stm32xx_hal.h" /** * @brief Callback to be called when a message is received on CAN line 1. diff --git a/Core/Inc/dti.h b/Core/Inc/dti.h index a97cf539..92f4b6b1 100644 --- a/Core/Inc/dti.h +++ b/Core/Inc/dti.h @@ -13,7 +13,7 @@ #define DTI_H #include "can.h" -#include "cmsis_os.h" +#include "ner_cmsis_os.h" /* Message IDs from DTI CAN Datasheet */ #define DTI_CANID_ERPM 0x416 /* ERPM, Duty, Input Voltage */ diff --git a/Core/Inc/fault.h b/Core/Inc/fault.h index 87a9671d..3bef4b9d 100644 --- a/Core/Inc/fault.h +++ b/Core/Inc/fault.h @@ -1,8 +1,9 @@ #ifndef CERBERUS_FAULT_H #define CERBERUS_FAULT_H -#include "cmsis_os.h" +#include "ner_cmsis_os.h" #include +#include "stm32xx_hal.h" typedef enum { /* START CRIT FAULTS HERE */ diff --git a/Core/Inc/main.h b/Core/Inc/main.h index e2ed20a1..7e6dcd53 100644 --- a/Core/Inc/main.h +++ b/Core/Inc/main.h @@ -27,7 +27,7 @@ extern "C" { #endif /* Includes ------------------------------------------------------------------*/ -#include "stm32f4xx_hal.h" +#include "stm32xx_hal.h" /* Private includes ----------------------------------------------------------*/ /* USER CODE BEGIN Includes */ diff --git a/Core/Inc/monitor.h b/Core/Inc/monitor.h index 8a27d9ae..8f869a85 100644 --- a/Core/Inc/monitor.h +++ b/Core/Inc/monitor.h @@ -3,7 +3,7 @@ #include -#include "cmsis_os.h" +#include "ner_cmsis_os.h" #include "mpu.h" #include "pdu.h" diff --git a/Core/Inc/mpu.h b/Core/Inc/mpu.h index 9e5baf82..c22046c7 100644 --- a/Core/Inc/mpu.h +++ b/Core/Inc/mpu.h @@ -3,8 +3,8 @@ #include -#include "cmsis_os.h" -#include "stm32f4xx_hal.h" +#include "ner_cmsis_os.h" +#include "stm32xx_hal.h" typedef struct { I2C_HandleTypeDef *hi2c; diff --git a/Core/Inc/pdu.h b/Core/Inc/pdu.h index 60070b91..ffa83a84 100644 --- a/Core/Inc/pdu.h +++ b/Core/Inc/pdu.h @@ -2,14 +2,14 @@ #define PDU_H #include -#include "cmsis_os.h" +#include "ner_cmsis_os.h" #include "tca9539.h" #include "INA226.h" #include #include #include "bitstream.h" #include "c_utils.h" -#include "stm32f4xx_hal.h" +#include "stm32xx_hal.h" typedef struct { I2C_HandleTypeDef *hi2c; @@ -115,6 +115,11 @@ bool verify_tca_config(pdu_t *pdu); */ int8_t read_expander_debug(pdu_t *pdu, uint8_t expander_debug_data[4]); +/** + * @brief sounds rtds by settings its thread flag + */ +void sound_rtds(); + /** * @brief Taskf for sounding RTDS. * diff --git a/Core/Inc/pedals.h b/Core/Inc/pedals.h index b84f5581..d0c403ba 100644 --- a/Core/Inc/pedals.h +++ b/Core/Inc/pedals.h @@ -107,4 +107,10 @@ void toggle_launch_control(); */ bool get_launch_control(); +/** + * @brief determines if APPS should fault based on pedal readings + */ +bool calc_pedal_faults(float accel1, float accel2, float accel1_norm, + float accel2_norm); + #endif diff --git a/Core/Inc/state_machine.h b/Core/Inc/state_machine.h index c811b23f..e78ee069 100644 --- a/Core/Inc/state_machine.h +++ b/Core/Inc/state_machine.h @@ -134,4 +134,17 @@ int set_ready_mode(); */ int fault(); +/** + * @brief tranitions the functional state based on current sate + * + * @param new_state state that is requesting transition + * @param pdu pdu interface + * @param mc dti interface + * @param mpu mpu interface + * + * @return error code + */ +int transition_functional_state(func_state_t new_state, pdu_t *pdu, dti_t *mc, + mpu_t *mpu); + #endif \ No newline at end of file diff --git a/Core/Src/cerb_tasks.c b/Core/Src/cerb_tasks.c new file mode 100644 index 00000000..e69de29b diff --git a/Core/Src/pdu.c b/Core/Src/pdu.c index 1cb8eff4..744612d5 100644 --- a/Core/Src/pdu.c +++ b/Core/Src/pdu.c @@ -279,6 +279,11 @@ static int8_t write_ctrl(pdu_t *pdu, bool state, uint8_t pin, uint8_t reg) return 0; } +void sound_rtds() +{ + osThreadFlagsSet(rtds_thread, SOUND_RTDS_FLAG); +} + int8_t write_pump_1(pdu_t *pdu, bool state) { return write_ctrl(pdu, state, PIN_PUMP_CTRL_1, TCA_OUTPUT_PORT_0); diff --git a/Core/Src/state_machine.c b/Core/Src/state_machine.c index 2b17096c..4a4d86b8 100644 --- a/Core/Src/state_machine.c +++ b/Core/Src/state_machine.c @@ -9,6 +9,7 @@ #include "monitor.h" #include "pedals.h" #include "can_handler.h" +#include "pdu.h" #define STATE_TRANS_QUEUE_SIZE 4 @@ -91,8 +92,8 @@ void sound_reverse_callback(void *pdu) sound = !sound; } -static int transition_functional_state(func_state_t new_state, pdu_t *pdu, - dti_t *mc, mpu_t *mpu) +int transition_functional_state(func_state_t new_state, pdu_t *pdu, dti_t *mc, + mpu_t *mpu) { /* Special case: should be able to fault no matter what conditions */ if (new_state == FAULTED) { @@ -151,11 +152,9 @@ static int transition_functional_state(func_state_t new_state, pdu_t *pdu, return 3; } #endif - if (get_tsms()) { - osThreadFlagsSet(rtds_thread, SOUND_RTDS_FLAG); + sound_rtds(); } - printf("ACTIVE STATE\r\n"); break; default: diff --git a/Drivers/Embedded-Base b/Drivers/Embedded-Base index c7704a99..e4a6bde3 160000 --- a/Drivers/Embedded-Base +++ b/Drivers/Embedded-Base @@ -1 +1 @@ -Subproject commit c7704a998b12cca8d2a7c3880d5b3562ccae41df +Subproject commit e4a6bde3381eff4aabbbc4bf5c252ccd5c21a935 diff --git a/Test/unity/tests/can_handler_test.c b/Test/unity/tests/can_handler_test.c deleted file mode 100644 index 0c0ffd4c..00000000 --- a/Test/unity/tests/can_handler_test.c +++ /dev/null @@ -1,6 +0,0 @@ -#include "unity.h" - -void test_can_handler(void) -{ - //TEST_ASSERT_NOT_NULL(getFunction(0x2010)); -} \ No newline at end of file diff --git a/Test/unity/tests/cerberus_test.c b/Test/unity/tests/cerberus_test.c deleted file mode 100644 index 1c58a5be..00000000 --- a/Test/unity/tests/cerberus_test.c +++ /dev/null @@ -1,16 +0,0 @@ -#include "unity.h" -#include "cerberus_test.h" - -void setUp(void) { - // set stuff up here -} - -void tearDown(void) { - // clean stuff up here -} - -int main(void) { - UNITY_BEGIN(); - RUN_TEST(test_can_handler); - return UNITY_END(); -} \ No newline at end of file diff --git a/Test/unity/tests/cerberus_test.h b/Test/unity/tests/cerberus_test.h deleted file mode 100644 index 57cf964b..00000000 --- a/Test/unity/tests/cerberus_test.h +++ /dev/null @@ -1,17 +0,0 @@ -#ifndef CERBERUS_TEST_H -#define CERBERUS_TEST_H - -/* - * ************** NOTE ************** - * These test files are specifically - * for unit tests, developers can - * make sure that specific functions - * and APIs meet requirements set out. - * This should NOT be used for actually - * simulating drivers and hardware, - * that is what we are using Renode for - */ - -void test_can_handler(void); - -#endif // CERBERUS_TEST_H \ No newline at end of file diff --git a/Tests/Inc/test_pedals.h b/Tests/Inc/test_pedals.h new file mode 100644 index 00000000..8ce34dac --- /dev/null +++ b/Tests/Inc/test_pedals.h @@ -0,0 +1,9 @@ +#ifndef TEST_PEDALS_H +#define TEST_PEDALS_H + +#include "unity.h" +#include "pedals.h" + +void test_calc_pedal_faults(void); + +#endif \ No newline at end of file diff --git a/Tests/Inc/test_state_machine.h b/Tests/Inc/test_state_machine.h new file mode 100644 index 00000000..25fb5e9d --- /dev/null +++ b/Tests/Inc/test_state_machine.h @@ -0,0 +1,9 @@ +#ifndef TEST_STATE_MACHINE_H +#define TEST_STATE_MACHINE_H + +#include "unity.h" +#include "state_machine.h" + +void test_tansition_functional_state(void); + +#endif // TEST_STATE_MACHINE_H \ No newline at end of file diff --git a/Tests/Src/test_pedals.c b/Tests/Src/test_pedals.c new file mode 100644 index 00000000..c5ada7af --- /dev/null +++ b/Tests/Src/test_pedals.c @@ -0,0 +1,31 @@ + +#include "mock_stub_functions.h" +#include "mock_debounce.h" +#include "mock_c_utils.h" +#include "mock_pdu.h" +#include "mock_mpu.h" +#include "mock_can_handler.h" +#include "test_pedals.h" + +void setUp(void) { + +} + +void tearDown(void) { +} + +void test_calc_pedal_faults() { + debounce_Ignore(); + debounce_Ignore(); + TEST_ASSERT_EQUAL_INT(calc_pedal_faults(3.2, 1.2, 0.50, .10), true); + + debounce_Ignore(); + debounce_Ignore(); + TEST_ASSERT_EQUAL_INT(calc_pedal_faults(3.2, 1.2, 0.50, .30), false); +} + +int main(void) { + UNITY_BEGIN(); + RUN_TEST(test_calc_pedal_faults); + return UNITY_END(); +} \ No newline at end of file diff --git a/Tests/Src/test_state_machine.c b/Tests/Src/test_state_machine.c new file mode 100644 index 00000000..396753d2 --- /dev/null +++ b/Tests/Src/test_state_machine.c @@ -0,0 +1,35 @@ + +#include "mock_mpu.h" +#include "mock_pdu.h" +#include "test_state_machine.h" + +#include +#include + +mpu_t *mpu; +pdu_t *pdu; +dti_t *dti; + +void setUp(void) { + mpu = malloc(sizeof(mpu_t)); + pdu = malloc(sizeof(pdu_t)); + dti = malloc(sizeof(dti_t)); +} + +void tearDown(void) { + free(mpu); + free(pdu); + free(dti); +} + +// A simple random test +void test_tansition_functional_state(void) { + write_fault_IgnoreAndReturn(0); + //TEST_ASSERT_EQUAL_INT(transition_functional_state(FAULTED, pdu, dti, mpu), 0); +} + +int main(void) { + UNITY_BEGIN(); + RUN_TEST(test_tansition_functional_state); + return UNITY_END(); +} \ No newline at end of file diff --git a/Tests/mock_configs/test_pedals.txt b/Tests/mock_configs/test_pedals.txt new file mode 100644 index 00000000..3aec91f7 --- /dev/null +++ b/Tests/mock_configs/test_pedals.txt @@ -0,0 +1,5 @@ +Core/Inc/dti.h +Core/Inc/fault.h +Core/Inc/pdu.h +Core/Inc/mpu.h +Core/Inc/can_handler.h diff --git a/Tests/mock_configs/test_state_machine.txt b/Tests/mock_configs/test_state_machine.txt new file mode 100644 index 00000000..5cb11d87 --- /dev/null +++ b/Tests/mock_configs/test_state_machine.txt @@ -0,0 +1,5 @@ +Core/Inc/dti.h +Core/Inc/fault.h +Core/Inc/pdu.h +Core/Inc/mpu.h +Core/Inc/can_handler.h \ No newline at end of file diff --git a/compose.yml b/compose.yml index 71089463..2e358afe 100644 --- a/compose.yml +++ b/compose.yml @@ -2,7 +2,7 @@ name: cerberus services: ner-gcc-arm: - image: ghcr.io/northeastern-electric-racing/embedded-base:main + image: ghcr.io/northeastern-electric-racing/embedded-base:unity-testing build: . network_mode: host privileged: true