Skip to content
Open
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
20 changes: 20 additions & 0 deletions .github/workflows/test-check.yml
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion Core/Inc/bms.h
Original file line number Diff line number Diff line change
@@ -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 */
Expand Down
4 changes: 2 additions & 2 deletions Core/Inc/can_handler.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion Core/Inc/dti.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down
3 changes: 2 additions & 1 deletion Core/Inc/fault.h
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
#ifndef CERBERUS_FAULT_H
#define CERBERUS_FAULT_H

#include "cmsis_os.h"
#include "ner_cmsis_os.h"
#include <stdbool.h>
#include "stm32xx_hal.h"

typedef enum {
/* START CRIT FAULTS HERE */
Expand Down
2 changes: 1 addition & 1 deletion Core/Inc/main.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ extern "C" {
#endif

/* Includes ------------------------------------------------------------------*/
#include "stm32f4xx_hal.h"
#include "stm32xx_hal.h"

/* Private includes ----------------------------------------------------------*/
/* USER CODE BEGIN Includes */
Expand Down
2 changes: 1 addition & 1 deletion Core/Inc/monitor.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

#include <stdbool.h>

#include "cmsis_os.h"
#include "ner_cmsis_os.h"
#include "mpu.h"
#include "pdu.h"

Expand Down
4 changes: 2 additions & 2 deletions Core/Inc/mpu.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@

#include <stdbool.h>

#include "cmsis_os.h"
#include "stm32f4xx_hal.h"
#include "ner_cmsis_os.h"
#include "stm32xx_hal.h"

typedef struct {
I2C_HandleTypeDef *hi2c;
Expand Down
9 changes: 7 additions & 2 deletions Core/Inc/pdu.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
#define PDU_H

#include <stdbool.h>
#include "cmsis_os.h"
#include "ner_cmsis_os.h"
#include "tca9539.h"
#include "INA226.h"
#include <stdbool.h>
#include <stdint.h>
#include "bitstream.h"
#include "c_utils.h"
#include "stm32f4xx_hal.h"
#include "stm32xx_hal.h"

typedef struct {
I2C_HandleTypeDef *hi2c;
Expand Down Expand Up @@ -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.
*
Expand Down
6 changes: 6 additions & 0 deletions Core/Inc/pedals.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there is absolutely no way these can remain private right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah unfortunately the downside is that if we want to test the file it has to be exposed in a header

float accel2_norm);

#endif
13 changes: 13 additions & 0 deletions Core/Inc/state_machine.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Empty file added Core/Src/cerb_tasks.c
Empty file.
5 changes: 5 additions & 0 deletions Core/Src/pdu.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Comment on lines +282 to +286
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can revert this, I thought I had to do this originally to test but it was unnecessary

int8_t write_pump_1(pdu_t *pdu, bool state)
{
return write_ctrl(pdu, state, PIN_PUMP_CTRL_1, TCA_OUTPUT_PORT_0);
Expand Down
9 changes: 4 additions & 5 deletions Core/Src/state_machine.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "monitor.h"
#include "pedals.h"
#include "can_handler.h"
#include "pdu.h"

#define STATE_TRANS_QUEUE_SIZE 4

Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this so sound_rtds can be tested?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I though so originally, but then realized it can be tested without doing this so I can revert it

}

printf("ACTIVE STATE\r\n");
break;
default:
Expand Down
6 changes: 0 additions & 6 deletions Test/unity/tests/can_handler_test.c

This file was deleted.

16 changes: 0 additions & 16 deletions Test/unity/tests/cerberus_test.c

This file was deleted.

17 changes: 0 additions & 17 deletions Test/unity/tests/cerberus_test.h

This file was deleted.

9 changes: 9 additions & 0 deletions Tests/Inc/test_pedals.h
Original file line number Diff line number Diff line change
@@ -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
9 changes: 9 additions & 0 deletions Tests/Inc/test_state_machine.h
Original file line number Diff line number Diff line change
@@ -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
31 changes: 31 additions & 0 deletions Tests/Src/test_pedals.c
Original file line number Diff line number Diff line change
@@ -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);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these change too often to always be right, perhaps within a certain threshold?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah there are definitely ways we can test if values are within certain thresholds with the Unity functions, I can try to expand on this as a proof of concept

}

int main(void) {
UNITY_BEGIN();
RUN_TEST(test_calc_pedal_faults);
return UNITY_END();
}
35 changes: 35 additions & 0 deletions Tests/Src/test_state_machine.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@

#include "mock_mpu.h"
#include "mock_pdu.h"
#include "test_state_machine.h"

#include <stdbool.h>
#include <stdlib.h>

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();
}
5 changes: 5 additions & 0 deletions Tests/mock_configs/test_pedals.txt
Original file line number Diff line number Diff line change
@@ -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
5 changes: 5 additions & 0 deletions Tests/mock_configs/test_state_machine.txt
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ya fix b4 merge

build: .
network_mode: host
privileged: true
Expand Down