Event cleanup

This commit is contained in:
Cabooman 2024-02-07 08:36:28 +01:00
parent 32378df03e
commit b528c8917f
25 changed files with 45 additions and 138 deletions

View file

@ -1,5 +1,5 @@
# Include the directory with your source files
include_directories(${CMAKE_SOURCE_DIR}/Software/src/devboard/utils .)
include_directories(${CMAKE_SOURCE_DIR}/Software/src/devboard ${CMAKE_SOURCE_DIR}/Software/src/devboard/utils . )
# Create a variable to store the list of test files
file(GLOB TEST_SOURCES utils/*.cpp)

View file

@ -201,7 +201,7 @@ class Runtime {
return 0; \
} else { \
double percentage = 100.0 * num_failed / mt::TestsManager::tests().size(); \
fprintf(stderr, "%s{ summary} %lu tests failed (%.2f%%)%s\n", mt::red(), num_failed, percentage, mt::def()); \
fprintf(stderr, "%s{ summary} %zu tests failed (%.2f%%)%s\n", mt::red(), num_failed, percentage, mt::def()); \
return -1; \
} \
}

View file

@ -1,6 +1,11 @@
#include "test_lib.h"
#include <cstdint>
#include "config.h"
MySerial Serial;
unsigned long testlib_millis = 0;
uint8_t bms_status = ACTIVE;

View file

@ -2,14 +2,20 @@
#define __TEST_LIB_H__
#include <stdint.h>
#include <algorithm>
#include <cstdint>
#include <cstdio>
#include "config.h"
#include "microtest.h"
using namespace std;
class MySerial;
extern unsigned long testlib_millis;
extern MySerial Serial;
extern uint8_t bms_status;
/* Mock millis() */
static inline unsigned long millis(void) {
@ -38,6 +44,4 @@ class MySerial {
}
};
extern MySerial Serial;
#endif

View file

@ -58,13 +58,14 @@ TEST(set_event_test) {
ASSERT_EQ(entries[EVENT_CELL_OVER_VOLTAGE].data, 0);
ASSERT_EQ(entries[EVENT_CELL_OVER_VOLTAGE].occurences, 0);
ASSERT_EQ(entries[EVENT_CELL_OVER_VOLTAGE].timestamp, 0);
// Set current time and overvoltage event for cell 23
// Set current time and overvoltage event for cell 23 (RED color, bms_status == FAULT)
time_seconds = 345;
set_event(EVENT_CELL_OVER_VOLTAGE, 123);
// Ensure proper event data
ASSERT_EQ(entries[EVENT_CELL_OVER_VOLTAGE].data, 123);
ASSERT_EQ(entries[EVENT_CELL_OVER_VOLTAGE].occurences, 1);
ASSERT_EQ(entries[EVENT_CELL_OVER_VOLTAGE].timestamp, 345);
ASSERT_EQ(bms_status, FAULT);
}
TEST(event_message_test) {