-
Notifications
You must be signed in to change notification settings - Fork 0
Unity testing #338
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Unity testing #338
Changes from all commits
18d93e3
a218ca8
b76b4ed
630747a
e424c3e
8b46626
33af3d8
8ba1248
290f55a
910d647
d9ce20a
3a21a8a
dd3ccf6
b555557
2e55352
7fb2060
31418b0
129f64d
a465927
6864149
c8c4397
2b7ff66
c2a2b6e
f727684
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ah?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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(); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is this so sound_rtds can be tested?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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: | ||
|
|
||
| +4 −1 | .gitignore | |
| +108 −2 | cangen/can-messages/bms.json | |
| +88 −16 | cangen/can-messages/msb.json | |
| +9 −2 | dev/Dockerfile | |
| +11 −0 | dev/scripts/mock.sh | |
| +12 −0 | general/include/ner_cmsis_os.h | |
| +6 −1 | general/include/stm32xx_hal.h | |
| +0 −1 | general/include/tca9539.h | |
| +5 −2 | middleware/include/i2c_utility.h | |
| +1 −1 | middleware/include/pid.h | |
| +1 −1 | middleware/include/timer.h | |
| +33 −0 | ner_environment/build_system/build_system.py | |
| +99 −0 | ner_environment/build_system/test_runner.py | |
| +1 −1 | os/inc/rtos_utils.h | |
| +6 −1 | platforms/stm32f405/include/stm32xx_hal.h | |
| +5 −0 | platforms/stm32g431/include/stm32xx_hal.h | |
| +98 −0 | testing/Makefile | |
| +14 −0 | testing/cmock_config.yml | |
| +84 −0 | testing/manual_mocks/stub_functions.h | |
| +92 −0 | testing/manual_mocks/stub_typedefs.h |
This file was deleted.
This file was deleted.
This file was deleted.
| 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 |
| 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 |
| 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); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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(); | ||
| } | ||
| 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(); | ||
| } |
| 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 |
| 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 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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 | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ya fix b4 merge |
||
| build: . | ||
| network_mode: host | ||
| privileged: true | ||
|
|
||
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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