Add full automotive RTOS project
Add kernel (Cortex-M0/M3/M4, Tricore, S32K, RISC-V ports), drivers, middleware (CAN stack, diagnostics, safety), applications, board support, build/test tooling, and documentation.
This commit is contained in:
@@ -0,0 +1,117 @@
|
||||
/**
|
||||
* @file test_fault_handling.c
|
||||
* @brief Integration tests for fault handling
|
||||
*/
|
||||
|
||||
#include "unity.h"
|
||||
#include "kernel.h"
|
||||
#include "task.h"
|
||||
#include "fault_handler.h"
|
||||
#include <string.h>
|
||||
|
||||
/* Fault test variables */
|
||||
static volatile uint32_t fault_count = 0;
|
||||
static volatile uint32_t last_fault_type = 0;
|
||||
|
||||
/* Fault callback */
|
||||
static void test_fault_callback(const FaultInfo_t* fault_info) {
|
||||
fault_count++;
|
||||
last_fault_type = fault_info->type;
|
||||
}
|
||||
|
||||
/* Stack overflow test task */
|
||||
static void stack_overflow_task(void* params) {
|
||||
(void)params;
|
||||
|
||||
/* Allocate large array on stack to cause overflow */
|
||||
uint8_t large_array[10000];
|
||||
memset(large_array, 0, sizeof(large_array));
|
||||
|
||||
while (1) {
|
||||
kernel_delay(100);
|
||||
}
|
||||
}
|
||||
|
||||
/* Setup */
|
||||
void setUp(void) {
|
||||
kernel_init();
|
||||
fault_count = 0;
|
||||
last_fault_type = 0;
|
||||
|
||||
fault_handler_register_callback(test_fault_callback);
|
||||
}
|
||||
|
||||
/* Teardown */
|
||||
void tearDown(void) {
|
||||
kernel_stop();
|
||||
}
|
||||
|
||||
/* ============================================================================
|
||||
* Test Cases
|
||||
* ============================================================================ */
|
||||
|
||||
/**
|
||||
* @brief Test fault handler initialization
|
||||
*/
|
||||
void test_fault_handler_init(void) {
|
||||
fault_handler_init();
|
||||
TEST_ASSERT_TRUE(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Test stack overflow detection
|
||||
*/
|
||||
void test_stack_overflow_detection(void) {
|
||||
TaskConfig_t config = {
|
||||
.name = "overflow",
|
||||
.function = stack_overflow_task,
|
||||
.parameters = NULL,
|
||||
.stack_size = 512, /* Small stack to force overflow */
|
||||
.priority = 1,
|
||||
.period_ticks = 0
|
||||
};
|
||||
|
||||
TaskHandle_t task = task_create(&config);
|
||||
|
||||
kernel_start();
|
||||
kernel_delay(100);
|
||||
|
||||
/* Stack overflow should be detected */
|
||||
TEST_ASSERT_GREATER_THAN(0, fault_count);
|
||||
TEST_ASSERT_EQUAL(FAULT_STACK_OVERFLOW, last_fault_type);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Test fault processing
|
||||
*/
|
||||
void test_fault_process(void) {
|
||||
fault_handler_process(FAULT_HARD_FAULT, 0x20000000, 0x01);
|
||||
|
||||
TEST_ASSERT_EQUAL(1, fault_count);
|
||||
TEST_ASSERT_EQUAL(FAULT_HARD_FAULT, last_fault_type);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Test multiple faults
|
||||
*/
|
||||
void test_multiple_faults(void) {
|
||||
fault_handler_process(FAULT_BUS_FAULT, 0x40000000, 0x02);
|
||||
fault_handler_process(FAULT_USAGE_FAULT, 0x00000000, 0x03);
|
||||
|
||||
TEST_ASSERT_EQUAL(2, fault_count);
|
||||
TEST_ASSERT_EQUAL(FAULT_USAGE_FAULT, last_fault_type);
|
||||
}
|
||||
|
||||
/* ============================================================================
|
||||
* Test Runner
|
||||
* ============================================================================ */
|
||||
int main(void) {
|
||||
UNITY_BEGIN();
|
||||
|
||||
RUN_TEST(test_fault_handler_init);
|
||||
RUN_TEST(test_stack_overflow_detection);
|
||||
RUN_TEST(test_fault_process);
|
||||
RUN_TEST(test_multiple_faults);
|
||||
|
||||
return UNITY_END();
|
||||
}
|
||||
Reference in New Issue
Block a user