Added Git Hash To Build
This commit is contained in:
parent
94b5fd47a4
commit
b4d9f24f0e
@ -1,3 +1,24 @@
|
||||
idf_component_register(SRCS "main.c" "uart_handler.c" "communication_handler.c" "uart_prot.c"
|
||||
idf_component_register(SRCS "main.c" "uart_handler.c" "communication_handler.c" "uart_prot.c" "client_handler.c" "message_parser.c" "message_builder.c" "message_handler.c"
|
||||
INCLUDE_DIRS ".")
|
||||
|
||||
# Get the short Git commit hash of the current HEAD.
|
||||
# If not in a Git repository or git command fails, it will default to "N/A".
|
||||
execute_process(
|
||||
COMMAND git rev-parse --short HEAD
|
||||
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
|
||||
OUTPUT_VARIABLE GIT_COMMIT_HASH_SHORT
|
||||
OUTPUT_STRIP_TRAILING_WHITESPACE
|
||||
RESULT_VARIABLE GIT_HASH_RESULT
|
||||
)
|
||||
# Fallback if git is not available or not in a git repo
|
||||
if(GIT_HASH_RESULT_CODE)
|
||||
set(GIT_COMMIT_HASH_SHORT "N/A")
|
||||
endif()
|
||||
|
||||
# Add the Git hash as a preprocessor definition to your component.
|
||||
# This makes BUILD_GIT_HASH available in your C/C++ source files.
|
||||
target_compile_definitions(${COMPONENT_LIB} PRIVATE
|
||||
BUILD_GIT_HASH="${GIT_COMMIT_HASH_SHORT}"
|
||||
)
|
||||
|
||||
|
||||
|
||||
@ -29,6 +29,9 @@ void SendClientInfoTask() {
|
||||
}
|
||||
|
||||
void app_main(void) {
|
||||
ESP_LOGI(TAG, "Starting Alox Powerpod Version %d Build: %s", version,
|
||||
BUILD_GIT_HASH);
|
||||
|
||||
esp_err_t ret = nvs_flash_init();
|
||||
if (ret == ESP_ERR_NVS_NO_FREE_PAGES ||
|
||||
ret == ESP_ERR_NVS_NEW_VERSION_FOUND) {
|
||||
|
||||
14
tests/Makefile
Normal file
14
tests/Makefile
Normal file
@ -0,0 +1,14 @@
|
||||
CC=gcc
|
||||
CFLAGS=-Wall -Wextra -I../main
|
||||
SRC = Unity/src/unity.c test_parser.c \
|
||||
../main/message_parser.c
|
||||
TARGET = test_runner
|
||||
|
||||
all: $(TARGET)
|
||||
|
||||
$(TARGET): $(SRC)
|
||||
$(CC) $(CFLAGS) -o $@ $^
|
||||
./$(TARGET)
|
||||
|
||||
clean:
|
||||
rm -f $(TARGET)
|
||||
9
tests/main_tests.c
Normal file
9
tests/main_tests.c
Normal file
@ -0,0 +1,9 @@
|
||||
#include "Unity/src/unity.h"
|
||||
|
||||
void setUp(void) {} // optional
|
||||
void tearDown(void) {} // optional
|
||||
|
||||
int main(void) {
|
||||
UNITY_BEGIN();
|
||||
return UNITY_END();
|
||||
}
|
||||
85
tests/test_parser.c
Normal file
85
tests/test_parser.c
Normal file
@ -0,0 +1,85 @@
|
||||
#include "Unity/src/unity.h"
|
||||
#include "message_parser.h"
|
||||
#include <stdint.h>
|
||||
|
||||
void setUp(void) {} // optional
|
||||
void tearDown(void) {} // optional
|
||||
|
||||
// Gültige Nachricht mit Payload
|
||||
void test_valid_message_parses_correctly(void) {
|
||||
struct MessageRecieve mr = {
|
||||
.state = WaitingForStartByte,
|
||||
.messageid = 0,
|
||||
.index = 0,
|
||||
.checksum = 0,
|
||||
};
|
||||
|
||||
uint8_t msg[] = {0xAA, 0x01, 0x03, 0x01, 0x02, 0x03, 0x00};
|
||||
msg[6] = msg[1] ^ msg[2] ^ msg[3] ^ msg[4] ^ msg[5]; // korrekte Checksumme
|
||||
|
||||
for (uint8_t i = 0; i < sizeof(msg); ++i)
|
||||
parse_byte(&mr, msg[i]);
|
||||
|
||||
TEST_ASSERT_EQUAL_UINT8(1, mr.messageid);
|
||||
TEST_ASSERT_EQUAL_UINT8(3, mr.length);
|
||||
uint8_t expected[] = {1, 2, 3};
|
||||
TEST_ASSERT_EQUAL_UINT8_ARRAY(expected, mr.message, 3);
|
||||
}
|
||||
|
||||
// Ungültige Checksumme – Zustand wird zurückgesetzt
|
||||
void test_invalid_checksum_resets_state(void) {
|
||||
struct MessageRecieve mr = {
|
||||
.state = WaitingForStartByte,
|
||||
.messageid = 0,
|
||||
.index = 0,
|
||||
.checksum = 0,
|
||||
};
|
||||
|
||||
uint8_t msg[] = {
|
||||
0xAA, 0x02, 0x02,
|
||||
0x10, 0x20, 0x00}; // falsche Checksumme (korr. wäre 0x10 ^ 0x20 ^ 2 ^ 2)
|
||||
|
||||
for (uint8_t i = 0; i < sizeof(msg); ++i)
|
||||
parse_byte(&mr, msg[i]);
|
||||
|
||||
TEST_ASSERT_EQUAL_UINT8(WaitingForStartByte, mr.state);
|
||||
}
|
||||
|
||||
// Kein Startbyte – Nachricht ignorieren
|
||||
void test_no_startbyte_ignored(void) {
|
||||
struct MessageRecieve mr = {
|
||||
.state = WaitingForStartByte, .index = 0, .checksum = 0};
|
||||
|
||||
uint8_t msg[] = {2, 0x10, 0x20, 0x30}; // kein Startbyte
|
||||
|
||||
for (uint8_t i = 0; i < sizeof(msg); ++i)
|
||||
parse_byte(&mr, msg[i]);
|
||||
|
||||
TEST_ASSERT_EQUAL_UINT8(WaitingForStartByte, mr.state);
|
||||
TEST_ASSERT_EQUAL_UINT8(0, mr.index);
|
||||
}
|
||||
|
||||
// Länge 0 – gültige Nachricht ohne Payload
|
||||
void test_zero_length_message(void) {
|
||||
struct MessageRecieve mr = {
|
||||
.state = WaitingForStartByte, .index = 0, .checksum = 0};
|
||||
|
||||
uint8_t msg[] = {0xAA, 3, 0, 0}; // Länge = 0, Checksumme = 3 ^ 0 = 3
|
||||
msg[3] = msg[1] ^ msg[2];
|
||||
|
||||
for (uint8_t i = 0; i < sizeof(msg); ++i)
|
||||
parse_byte(&mr, msg[i]);
|
||||
|
||||
TEST_ASSERT_EQUAL_UINT8(0, mr.index);
|
||||
TEST_ASSERT_EQUAL_UINT8(3, mr.messageid);
|
||||
TEST_ASSERT_EQUAL_UINT8(WaitingForStartByte, mr.state);
|
||||
}
|
||||
|
||||
int main(void) {
|
||||
UNITY_BEGIN();
|
||||
RUN_TEST(test_valid_message_parses_correctly);
|
||||
RUN_TEST(test_invalid_checksum_resets_state);
|
||||
RUN_TEST(test_no_startbyte_ignored);
|
||||
RUN_TEST(test_zero_length_message);
|
||||
return UNITY_END();
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user