Skip to content
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

Unit Testing Framework #405

Open
wants to merge 58 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 45 commits
Commits
Show all changes
58 commits
Select commit Hold shift + click to select a range
084e238
So make unittest TEST_LEADER=HelloWorld works...
KnockbackNemo Dec 30, 2023
9450609
Messing with makefiles and new unit testing structure; testing the ad…
KnockbackNemo Dec 31, 2023
8206ae3
Makefile unitclean
diyarajon Dec 31, 2023
bf0c830
Unit Test for Contactors written, not working
diyarajon Dec 31, 2023
409b67f
Changed Makefile to use variable TEST instead of TEST_LEADER since TE…
KnockbackNemo Jan 2, 2024
e33eee1
C Source looks for the right (hopefully) file, also added mocking fla…
KnockbackNemo Jan 3, 2024
2aa882c
working pedals and contactors without OS mocking
diyarajon Jan 4, 2024
9f4bb42
Created Mock folder structure and reflected restructure in the makefile
diyarajon Jan 6, 2024
e122e69
Created Mock folder structure and reflected restructure in the makefi…
diyarajon Jan 6, 2024
eb426b7
Moved fff globals and fff.h files in BSP_ADC test files, small fix to…
KnockbackNemo Jan 6, 2024
1e34a3c
Fixed Tests/Test_Pedals.c not found error by removing the TOCOMPILE v…
KnockbackNemo Jan 7, 2024
c710daa
Made BSP_ADC_Init non-static so that leader compiles. The function is…
KnockbackNemo Jan 7, 2024
a2a0eab
Changed Makefile and got Test_Contactors working! Makefile changes: C…
KnockbackNemo Jan 8, 2024
7804bbd
added new mocks to define and declare OS fucntions and macros require…
diyarajon Jan 10, 2024
41a6a18
Continued working on ReadCarCAN unit test, currently not working with…
diyarajon Jan 10, 2024
9f8b490
Fixed problem of gcc including the incorrect Tasks.h. Issue was that …
KnockbackNemo Jan 10, 2024
54594c8
Wrote two tests for ReadCarCAN, mocked UpdateDisplay and Display, cha…
KnockbackNemo Jan 11, 2024
8e45932
Mocked the rest of the relevant os functions; currently doesn't expan…
KnockbackNemo Jan 15, 2024
7efeb40
Fixed mocked os (wrote DECLARE instead of DEFINE), added semicolon to…
KnockbackNemo Jan 16, 2024
667aaec
Uncommented OS functions in ReadCarCAN, still compiles.
KnockbackNemo Jan 16, 2024
163f877
Moved task prototypes to their respective header files.
KnockbackNemo Jan 16, 2024
72fd00c
Mocked/stubbed BSP stm32f4xx.h and _gpio.h/c files from CMSIS- this s…
KnockbackNemo Jan 16, 2024
13265b3
Cleaning up unneeded file changes to decrease the size of the PR.
KnockbackNemo Jan 18, 2024
392c6d6
Merge branch 'master' into feature/unit-testing-framework-394
KnockbackNemo Jan 19, 2024
0d89370
Cleaned up files a bit / added MOCK to mock files because I am easily…
KnockbackNemo Jan 20, 2024
b0e2a36
Finished mocking BSP
KnockbackNemo Jan 20, 2024
4ca872b
Finished mocking the rest of the necessary drivers.
KnockbackNemo Jan 20, 2024
8c177de
Mocked apps, define a LOOP macro which is either '' or while(1) depen…
KnockbackNemo Jan 20, 2024
f0227bd
Cleaned up driver mocks by including real header to avoid copy-pastin…
KnockbackNemo Jan 20, 2024
26f4835
Cleaned up app mocks by including real header to avoid copy-pasting a…
KnockbackNemo Jan 20, 2024
21ddd2b
Cleaned and deleted shared initializations by including it from non-m…
diyarajon Jan 20, 2024
69f956d
Cleaned and deleted shared initializations by including it from non-m…
diyarajon Jan 20, 2024
d8a31ac
Began working on a more thorough unit test example for Contactors.
KnockbackNemo Jan 20, 2024
edb8fdd
Pedals and Contactors Unit Tests working post merge
diyarajon Jan 22, 2024
24abdf6
Merge branch 'feature/unit-testing-framework-394' of github.com:lhr-s…
KnockbackNemo Jan 23, 2024
47e5b4a
Modified mocks used by RCC. RCC unit test merge in progress.
diyarajon Jan 23, 2024
900d269
Merge branch 'feature/unit-testing-framework-394' of github.com:lhr-s…
KnockbackNemo Jan 23, 2024
4fd024b
Renamed functions, tasks, and mock test file and otherwise made chang…
KnockbackNemo Jan 23, 2024
b1a8afe
Added back in the LOOP macro so that we don't infinite loop in unit t…
KnockbackNemo Jan 24, 2024
b50d3d0
Completed (ish?) Contactors unit test. Probably could be improved, bu…
KnockbackNemo Jan 27, 2024
1cef3f2
Used clang checks. Still fails at ASSERT_OS_ERROR.
KnockbackNemo Jan 27, 2024
aa23619
Finished making checks; things now formatted properly
KnockbackNemo Jan 27, 2024
c765def
Small comment changes.
KnockbackNemo Jan 27, 2024
d6520c4
Added more annotations to the test files.
KnockbackNemo Jan 31, 2024
3403375
Merge branch 'master' into feature/unit-testing-framework-394
KnockbackNemo Jan 31, 2024
cd3403e
Removed/restored files that were committed by accident.
KnockbackNemo Mar 2, 2024
b0cc9e3
Changed conditional while(1) to add a break if MOCKING instead of usi…
KnockbackNemo Mar 2, 2024
0bd0a33
Ran make check and make format.
KnockbackNemo Mar 2, 2024
1f4a1c1
Re-removed workspace file associations.
KnockbackNemo Mar 2, 2024
3a02e62
Renamed example unit tests.
KnockbackNemo Mar 2, 2024
7f37ccb
Changed build directory for the unit tests to be the same as the gene…
KnockbackNemo Mar 2, 2024
19f0726
Deleted unnecessary mocks that were only defining things.
KnockbackNemo Mar 2, 2024
18baf1c
Removed defines from mock os.h and used original os.h instead.
KnockbackNemo Mar 2, 2024
0257ebc
Created cpu core function mocks and deleted defines by using them fro…
diyarajon Mar 2, 2024
e967b8d
re-add workspace
diyarajon Mar 2, 2024
834eb41
Added debug macro to BSP makefile to use when testing, but not unit-t…
diyarajon Mar 2, 2024
a61bd83
Updated the ReadMe to include the DEBUG_TESTFILE and created an examp…
diyarajon Mar 2, 2024
28cc35d
Merge branch 'master' into feature/unit-testing-framework-394
KnockbackNemo Mar 10, 2024
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
18 changes: 18 additions & 0 deletions .vscode/LHR.code-workspace
KnockbackNemo marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,24 @@
"args": ["-i"]
},
},
"files.associations": {
"*.db": "sql",
"contactors.h": "c",
"pedals.h": "c",
"bsp_adc.h": "c",
"config.h": "c",
"unity.h": "c",
"fff.h": "c",
"common.h": "c",
"stdio.h": "c",
"stm32f4xx.h": "c",
"bsp_gpio.h": "c",
"os.h": "c",
"tasks.h": "c",
"canbus.h": "c",
"readcarcan.h": "c",
"minions.h": "c"
},
},
"tasks": {
"version": "2.0.0",
Expand Down
5 changes: 5 additions & 0 deletions Apps/Inc/ReadCarCan.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@

#include "common.h"

/**
* Task Prototype
*/
void TaskReadCarCan(void* p_arg);

/**
* Error types
*/
Expand Down
5 changes: 5 additions & 0 deletions Apps/Inc/ReadTritium.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ typedef enum {
kNone = 0x00,
} TritiumErrorCode;

/**
* Task Prototype
*/
void TaskReadTritium(void* p_arg);

float MotorRpmGet();
float MotorVelocityGet();

Expand Down
5 changes: 5 additions & 0 deletions Apps/Inc/SendCarCan.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@

#include "CanBus.h"

/**
* Task Prototype
*/
void TaskSendCarCan(void* p_arg);

/**
* @brief Initialize SendCarCAN
*/
Expand Down
5 changes: 5 additions & 0 deletions Apps/Inc/SendTritium.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ typedef struct TritiumState {
void (*stateDecider)(void);
} TritiumState;

/**
* Task Prototype
*/
void TaskSendTritium(void* p_arg);

// Getter functions for static variables
bool GetCruiseEnable(void);
bool GetCruiseSet(void);
Expand Down
9 changes: 2 additions & 7 deletions Apps/Inc/Tasks.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,6 @@ typedef uint16_t ErrorCode;
* Task Prototypes
*/
void TaskInit(void* p_arg);
void TaskSendTritium(void* p_arg);
void TaskReadCarCan(void* p_arg);
void TaskUpdateDisplay(void* p_arg);
void TaskReadTritium(void* p_arg);
void TaskSendCarCan(void* p_arg);
void TaskDebugDump(void* p_arg);
void TaskCommandLine(void* p_arg);

Expand Down Expand Up @@ -167,7 +162,7 @@ void AssertOsError(OS_ERR err);

#if DEBUG == 1
#define ASSERT_OS_ERROR(err) \
if (err != OS_ERR_NONE) { \
if ((err) != OS_ERR_NONE) { \
printf("Error asserted at %s, line %d: %d\n\r", __FILE__, __LINE__, \
err); \
} \
Expand All @@ -178,4 +173,4 @@ void AssertOsError(OS_ERR err);

#endif

/* @} */
/* @} */
5 changes: 5 additions & 0 deletions Apps/Inc/UpdateDisplay.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@ typedef enum { kState0 = 0, kState1 = 1, kState2 = 2 } TriState;
#define DISP_FORWARD kState1
#define DISP_REVERSE kState2

/**
* Task Prototype
*/
void TaskUpdateDisplay(void* p_arg);

/**
* @brief Initializes UpdateDisplay application
* @returns UpdateDisplayError_t
Expand Down
2 changes: 1 addition & 1 deletion Apps/Src/CommandLine.c
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ void TaskCommandLine(void *p_arg) {
// output welcome/help screen
printf("%s", help);

while (1) {
LOOP {
KnockbackNemo marked this conversation as resolved.
Show resolved Hide resolved
printf("> ");
BspUartRead(kUart2, input);
printf("\n\r");
Expand Down
2 changes: 1 addition & 1 deletion Apps/Src/DebugDump.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ static const char *gear_string[] = {FOREACH_GEAR(GENERATE_STRING)};
void TaskDebugDump(void *p_arg) {
OS_ERR err = 0;

while (1) {
LOOP {
// Get pedal information
int8_t accel_pedal = PedalsRead(kAccelerator);
printf("kAccelerator: %d\n\r", accel_pedal);
Expand Down
8 changes: 5 additions & 3 deletions Apps/Src/ReadCarCan.c
Original file line number Diff line number Diff line change
Expand Up @@ -368,15 +368,17 @@ void TaskReadCarCan(void *p_arg) {
memset(hv_plus_minus_charge_msg_buffer, DISABLE_SATURATION_MSG,
sizeof(hv_plus_minus_charge_msg_buffer));

while (1) {
LOOP {
UpdatePrechargeContactors(); // Sets array and motor controller PBC if
// all conditions (PBC Status, Threshold,
// Precharge Complete) permit

// BPS sent a message
ErrorStatus status = CanBusRead(&data_buf, true, CARCAN);
if (status != SUCCESS) {
#ifndef MOCKING
continue;
#endif
KnockbackNemo marked this conversation as resolved.
Show resolved Hide resolved
}

switch (data_buf.id) { // Switch case based on BPS msg received
Expand Down Expand Up @@ -453,7 +455,7 @@ static void handlerReadCarCanChargeDisable(void) {
if (ret) { // Contactor failed to turn off; display the evac screen and
// infinite loop
DisplayEvac(soc, sbpv);
while (1) {}
LOOP {}
}
}

Expand Down Expand Up @@ -489,7 +491,7 @@ static void handlerReadCarCanContactorsDisable(void) {
if (ret) { // Contactor failed to turn off; display the evac screen and
// infinite loop
DisplayEvac(soc, sbpv);
while (1) {}
LOOP {}
}
}

Expand Down
2 changes: 1 addition & 1 deletion Apps/Src/ReadTritium.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ void TaskReadTritium(void *p_arg) {
// Timer doesn't seem to trigger without initial delay? Might be an RTOS bug
static bool watchdog_created = false;

while (1) {
LOOP {
ErrorStatus status = CanBusRead(&data_buf, true, MOTORCAN);

if (status == SUCCESS) {
Expand Down
4 changes: 2 additions & 2 deletions Apps/Src/SendCarCan.c
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ void TaskSendCarCan(void *p_arg) {
(OS_ERR *)&err);
ASSERT_OS_ERROR(err);

while (1) {
LOOP {
// Check if there's something to send in the queue (either IOState or
// Car state from sendTritium)
OSSemPend(&car_can_sem4, 0, OS_OPT_PEND_BLOCKING, &ticks, &err);
Expand Down Expand Up @@ -168,7 +168,7 @@ static void putIOState(void) {
*/
static void taskPutIoState(void *p_arg) {
OS_ERR err = 0;
while (1) {
LOOP {
putIOState();
OSTimeDlyHMSM(0, 0, 0, IO_STATE_DLY_MS, OS_OPT_TIME_HMSM_STRICT, &err);
ASSERT_OS_ERROR(err);
Expand Down
2 changes: 1 addition & 1 deletion Apps/Src/SendTritium.c
Original file line number Diff line number Diff line change
Expand Up @@ -715,7 +715,7 @@ void TaskSendTritium(void* p_arg) {
};
#endif

while (1) {
LOOP {
prev_state = state;

state.stateHandler(); // do what the current state does
Expand Down
6 changes: 3 additions & 3 deletions Apps/Src/Tasks.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ CPU_STK command_line_stk[TASK_COMMAND_LINE_STACK_SIZE];

// Variables to store error codes, stored and cleared in task error assert
// functions
ErrorCode error_read_car_can = 0; // TODO: change this back to the error
ErrorCode error_read_car_can = kReadCarCanErrNone;
ErrorCode error_read_tritium = kNone; // Initialized to no error
ErrorCode error_update_display = kUpdateDisplayErrNone;

Expand All @@ -61,7 +61,7 @@ void AssertOsError(volatile OS_ERR err) {
// brakelight to indicate an emergency
DisplayFault(err); // Display the location and error code
printf("%d\n\r", err);
while (1) {} // nonrecoverable
LOOP {} // nonrecoverable
KnockbackNemo marked this conversation as resolved.
Show resolved Hide resolved
}
}

Expand Down Expand Up @@ -113,7 +113,7 @@ void ThrowTaskError(ErrorCode error_code, Callback error_callback,
}

if (nonrecoverable == kOptNonrecov) { // Enter an infinite while loop
while (1) {}
LOOP {}
}

if (lock_sched == kOptLockSched) { // Only happens on recoverable errors
Expand Down
4 changes: 1 addition & 3 deletions Apps/Src/UpdateDisplay.c
Original file line number Diff line number Diff line change
Expand Up @@ -320,9 +320,7 @@ void UpdateDisplayClearQueue() {
* @brief Loops through the display queue and sends all messages
*/
void TaskUpdateDisplay(void* p_arg) {
while (1) {
updateDisplayPopNext();
}
LOOP { updateDisplayPopNext(); }
}

/**
Expand Down
5 changes: 4 additions & 1 deletion Apps/Src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@
#include "Display.h"
#include "Minions.h"
#include "Pedals.h"
#include "ReadCarCan.h"
#include "ReadTritium.h"
#include "SendCarCan.h"
#include "SendTritium.h"
#include "Tasks.h"
#include "UpdateDisplay.h"
#include "common.h"
Expand Down Expand Up @@ -46,7 +49,7 @@ int main(void) {
OSStart(&err);
ASSERT_OS_ERROR(err);

while (1) {}
LOOP {}
}

void TaskInit(void *p_arg) {
Expand Down
19 changes: 11 additions & 8 deletions BSP/STM32F413/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -113,23 +113,26 @@ C_INCLUDES = \
-I../../RTOS/uCOS-III-STM32F4/uC-LIB/ \
-I../../Tests/Inc/ \

# compile gcc flags
ASFLAGS = $(MCU) $(AS_DEFS) $(AS_INCLUDES) $(OPT) -Wall -fdata-sections -ffunction-sections

CFLAGS = $(MCU) $(C_DEFS) $(C_INCLUDES) $(OPT) -Wall -Werror -fdata-sections -ffunction-sections

ifeq ($(DEBUG), 1)
CFLAGS += -g3 -gdwarf-2 -DDEBUG
C_DEFS += -g3 -gdwarf-2 -DDEBUG
endif

ifeq ($(MOTOR_LOOPBACK), 1)
CFLAGS += -DMOTOR_LOOPBACK
C_DEFS += -DMOTOR_LOOPBACK
endif

ifeq ($(CAR_LOOPBACK), 1)
CFLAGS += -DCAR_LOOPBACK
C_DEFS += -DCAR_LOOPBACK
endif

# Not mocking -> LOOP = while(1)
C_DEFS += -D'LOOP=while(1)'
KnockbackNemo marked this conversation as resolved.
Show resolved Hide resolved

# compile gcc flags
ASFLAGS = $(MCU) $(AS_DEFS) $(AS_INCLUDES) $(OPT) -Wall -fdata-sections -ffunction-sections

CFLAGS = $(MCU) $(C_DEFS) $(C_INCLUDES) $(OPT) -Wall -Werror -fdata-sections -ffunction-sections

# Generate dependency information
CFLAGS += -MMD -MP -MF"$(@:%.o=%.d)"

Expand Down
15 changes: 15 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,14 @@ else
TEST_LEADER ?= Apps/Src/main.c
endif

#Check if unit test file exists (just to inform user if it isn't found)
#UNITTEST is solely used for echoing purposes
ifneq (,$(wildcard Tests/UnitTests/Tests/Test_$(TEST).c))
UNITTEST ?= Tests/UnitTests/Tests/Test_$(TEST).c
else
UNITTEST ?= no test found
endif

LEADER = controls-leader

all:
Expand All @@ -37,6 +45,12 @@ stm32f413:
$(MAKE) -C BSP -C STM32F413 -j TARGET=$(LEADER) TEST=$(TEST_LEADER)
@echo "${BLUE}Compiled for leader! Jolly Good!${NC}"

unittest:
@echo "${YELLOW}Compiling unit test...${NC}"
@echo "$(UNITTEST)"
$(MAKE) -C Tests -C UnitTests -j TARGET=$(LEADER) TEST=$(TEST)
@echo "${BLUE}Compiled unit test! Jolly Good!${NC}"

flash:
$(MAKE) -C BSP -C STM32F413 flash

Expand All @@ -58,6 +72,7 @@ help:


clean:
rm -fR Tests/UnitTests/Objects
rm -fR Objects
rm -f *.out
rm -fr Docs/doxygen
Expand Down
Loading
Loading