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,197 @@
|
||||
/**
|
||||
* @file test_full_system.c
|
||||
* @brief Full system integration tests
|
||||
*/
|
||||
|
||||
#include "unity.h"
|
||||
#include "kernel.h"
|
||||
#include "task.h"
|
||||
#include "semaphore.h"
|
||||
#include "mutex.h"
|
||||
#include "queue.h"
|
||||
#include "can_driver.h"
|
||||
#include "gpio_driver.h"
|
||||
#include "adc_driver.h"
|
||||
#include "pwm_driver.h"
|
||||
#include "dtc_manager.h"
|
||||
#include "watchdog_manager.h"
|
||||
#include <string.h>
|
||||
|
||||
/* System test variables */
|
||||
static volatile bool system_running = false;
|
||||
static volatile uint32_t system_ticks = 0;
|
||||
static Queue_t command_queue;
|
||||
static Semaphore_t system_semaphore;
|
||||
|
||||
/* System tasks */
|
||||
static void sensor_task(void* params) {
|
||||
(void)params;
|
||||
while (1) {
|
||||
/* Read sensors */
|
||||
uint16_t adc_value;
|
||||
adc_read_channel(0, 0, &adc_value, 10);
|
||||
|
||||
kernel_delay(10);
|
||||
}
|
||||
}
|
||||
|
||||
static void control_task(void* params) {
|
||||
(void)params;
|
||||
while (1) {
|
||||
/* Control loop */
|
||||
pwm_set_duty_cycle(0, 0, 5000); /* 50% duty */
|
||||
|
||||
kernel_delay(5);
|
||||
}
|
||||
}
|
||||
|
||||
static void communication_task(void* params) {
|
||||
(void)params;
|
||||
while (1) {
|
||||
CanMessage_t msg = {
|
||||
.id = {.id = 0x100, .is_extended = false},
|
||||
.length = 8,
|
||||
.data = {1, 2, 3, 4, 5, 6, 7, 8}
|
||||
};
|
||||
|
||||
can_send_message(&msg, 100);
|
||||
kernel_delay(50);
|
||||
}
|
||||
}
|
||||
|
||||
static void monitor_task(void* params) {
|
||||
(void)params;
|
||||
while (1) {
|
||||
system_ticks++;
|
||||
watchdog_task_alive(scheduler_get_current_task());
|
||||
kernel_delay(100);
|
||||
}
|
||||
}
|
||||
|
||||
/* Setup */
|
||||
void setUp(void) {
|
||||
kernel_init();
|
||||
system_running = false;
|
||||
system_ticks = 0;
|
||||
|
||||
/* Initialize subsystems */
|
||||
dtc_manager_init();
|
||||
watchdog_manager_init(1000);
|
||||
}
|
||||
|
||||
/* Teardown */
|
||||
void tearDown(void) {
|
||||
kernel_stop();
|
||||
}
|
||||
|
||||
/* ============================================================================
|
||||
* Test Cases
|
||||
* ============================================================================ */
|
||||
|
||||
/**
|
||||
* @brief Test full system startup
|
||||
*/
|
||||
void test_system_startup(void) {
|
||||
/* Create all system tasks */
|
||||
TaskConfig_t sensor_config = {
|
||||
.name = "sensor",
|
||||
.function = sensor_task,
|
||||
.parameters = NULL,
|
||||
.stack_size = 1024,
|
||||
.priority = 2,
|
||||
.period_ticks = 0
|
||||
};
|
||||
task_create(&sensor_config);
|
||||
|
||||
TaskConfig_t control_config = {
|
||||
.name = "control",
|
||||
.function = control_task,
|
||||
.parameters = NULL,
|
||||
.stack_size = 1024,
|
||||
.priority = 1,
|
||||
.period_ticks = 0
|
||||
};
|
||||
task_create(&control_config);
|
||||
|
||||
TaskConfig_t comm_config = {
|
||||
.name = "comm",
|
||||
.function = communication_task,
|
||||
.parameters = NULL,
|
||||
.stack_size = 2048,
|
||||
.priority = 3,
|
||||
.period_ticks = 0
|
||||
};
|
||||
task_create(&comm_config);
|
||||
|
||||
TaskConfig_t monitor_config = {
|
||||
.name = "monitor",
|
||||
.function = monitor_task,
|
||||
.parameters = NULL,
|
||||
.stack_size = 1024,
|
||||
.priority = 4,
|
||||
.period_ticks = 0
|
||||
};
|
||||
task_create(&monitor_config);
|
||||
|
||||
/* Start system */
|
||||
kernel_start();
|
||||
system_running = true;
|
||||
|
||||
/* Let system run */
|
||||
kernel_delay(500);
|
||||
|
||||
TEST_ASSERT_TRUE(system_running);
|
||||
TEST_ASSERT_GREATER_THAN(0, system_ticks);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Test system communication
|
||||
*/
|
||||
void test_system_communication(void) {
|
||||
/* Create communication test */
|
||||
CanMessage_t test_msg = {
|
||||
.id = {.id = 0x200, .is_extended = false},
|
||||
.length = 4,
|
||||
.data = {0xAA, 0xBB, 0xCC, 0xDD}
|
||||
};
|
||||
|
||||
TEST_ASSERT_EQUAL(KERNEL_OK, can_send_message(&test_msg, 1000));
|
||||
|
||||
kernel_delay(10);
|
||||
|
||||
CanStatistics_t stats;
|
||||
can_get_statistics(&stats);
|
||||
TEST_ASSERT_GREATER_THAN(0, stats.tx_messages);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Test system diagnostics
|
||||
*/
|
||||
void test_system_diagnostics(void) {
|
||||
/* Add test DTC */
|
||||
DtcCode_t dtc = {
|
||||
.high_byte = 0x01,
|
||||
.middle_byte = 0x02,
|
||||
.low_byte = 0x03
|
||||
};
|
||||
|
||||
TEST_ASSERT_EQUAL(KERNEL_OK, dtc_manager_add_dtc(&dtc, 3));
|
||||
TEST_ASSERT_EQUAL(1, dtc_manager_get_count());
|
||||
|
||||
/* Clear DTCs */
|
||||
TEST_ASSERT_EQUAL(KERNEL_OK, dtc_manager_clear_all());
|
||||
TEST_ASSERT_EQUAL(0, dtc_manager_get_count());
|
||||
}
|
||||
|
||||
/* ============================================================================
|
||||
* Test Runner
|
||||
* ============================================================================ */
|
||||
int main(void) {
|
||||
UNITY_BEGIN();
|
||||
|
||||
RUN_TEST(test_system_startup);
|
||||
RUN_TEST(test_system_communication);
|
||||
RUN_TEST(test_system_diagnostics);
|
||||
|
||||
return UNITY_END();
|
||||
}
|
||||
@@ -0,0 +1,183 @@
|
||||
/**
|
||||
* @file test_stress.c
|
||||
* @brief Stress tests for system
|
||||
*/
|
||||
|
||||
#include "unity.h"
|
||||
#include "kernel.h"
|
||||
#include "task.h"
|
||||
#include "semaphore.h"
|
||||
#include "queue.h"
|
||||
#include <string.h>
|
||||
|
||||
/* Stress test constants */
|
||||
#define STRESS_TEST_DURATION 5000 /* 5 seconds */
|
||||
#define MAX_STRESS_TASKS 20
|
||||
#define STRESS_QUEUE_SIZE 100
|
||||
|
||||
/* Stress test variables */
|
||||
static TaskHandle_t stress_tasks[MAX_STRESS_TASKS];
|
||||
static Semaphore_t stress_semaphores[MAX_STRESS_TASKS];
|
||||
static Queue_t stress_queue;
|
||||
static volatile uint32_t task_counts[MAX_STRESS_TASKS];
|
||||
static volatile uint32_t total_executions = 0;
|
||||
static volatile bool stress_test_passed = true;
|
||||
|
||||
/* Stress task function */
|
||||
static void stress_task(void* params) {
|
||||
uint32_t task_id = (uint32_t)params;
|
||||
|
||||
while (1) {
|
||||
/* Increment counters */
|
||||
task_counts[task_id]++;
|
||||
total_executions++;
|
||||
|
||||
/* Semaphore operations */
|
||||
semaphore_take(&stress_semaphores[task_id], 10);
|
||||
semaphore_give(&stress_semaphores[task_id]);
|
||||
|
||||
/* Queue operations */
|
||||
uint32_t data = task_id;
|
||||
queue_send(&stress_queue, &data, 0);
|
||||
queue_receive(&stress_queue, &data, 0);
|
||||
|
||||
/* Random delay */
|
||||
kernel_delay((task_id % 5) + 1);
|
||||
}
|
||||
}
|
||||
|
||||
/* Setup */
|
||||
void setUp(void) {
|
||||
kernel_init();
|
||||
total_executions = 0;
|
||||
stress_test_passed = true;
|
||||
|
||||
/* Initialize stress test resources */
|
||||
queue_create(&stress_queue, malloc(STRESS_QUEUE_SIZE * sizeof(uint32_t)),
|
||||
sizeof(uint32_t), STRESS_QUEUE_SIZE);
|
||||
|
||||
for (int i = 0; i < MAX_STRESS_TASKS; i++) {
|
||||
semaphore_create(&stress_semaphores[i], SEMAPHORE_BINARY, 1, 1);
|
||||
task_counts[i] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
/* Teardown */
|
||||
void tearDown(void) {
|
||||
kernel_stop();
|
||||
}
|
||||
|
||||
/* ============================================================================
|
||||
* Test Cases
|
||||
* ============================================================================ */
|
||||
|
||||
/**
|
||||
* @brief Test with maximum tasks
|
||||
*/
|
||||
void test_max_tasks_stress(void) {
|
||||
/* Create maximum number of tasks */
|
||||
for (int i = 0; i < MAX_STRESS_TASKS; i++) {
|
||||
TaskConfig_t config = {
|
||||
.name = "stress_task",
|
||||
.function = stress_task,
|
||||
.parameters = (void*)(uint32_t)i,
|
||||
.stack_size = 1024,
|
||||
.priority = i % MAX_PRIORITY_LEVELS,
|
||||
.period_ticks = 0
|
||||
};
|
||||
|
||||
stress_tasks[i] = task_create(&config);
|
||||
TEST_ASSERT_NOT_NULL(stress_tasks[i]);
|
||||
}
|
||||
|
||||
/* Run stress test */
|
||||
kernel_start();
|
||||
kernel_delay(STRESS_TEST_DURATION);
|
||||
|
||||
/* Verify all tasks executed */
|
||||
for (int i = 0; i < MAX_STRESS_TASKS; i++) {
|
||||
TEST_ASSERT_GREATER_THAN(0, task_counts[i]);
|
||||
}
|
||||
|
||||
TEST_ASSERT_GREATER_THAN(1000, total_executions);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Test context switching stress
|
||||
*/
|
||||
void test_context_switch_stress(void) {
|
||||
/* Create tasks that cause frequent context switches */
|
||||
for (int i = 0; i < 5; i++) {
|
||||
TaskConfig_t config = {
|
||||
.name = "ctx_switch",
|
||||
.function = stress_task,
|
||||
.parameters = (void*)(uint32_t)i,
|
||||
.stack_size = 512,
|
||||
.priority = i,
|
||||
.period_ticks = 0
|
||||
};
|
||||
|
||||
stress_tasks[i] = task_create(&config);
|
||||
}
|
||||
|
||||
kernel_start();
|
||||
kernel_delay(1000);
|
||||
|
||||
SchedulerStatistics_t stats;
|
||||
scheduler_get_statistics(&stats);
|
||||
|
||||
TEST_ASSERT_GREATER_THAN(100, stats.context_switches);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Test memory stress
|
||||
*/
|
||||
void test_memory_stress(void) {
|
||||
/* Allocate and free memory repeatedly */
|
||||
void* pointers[100];
|
||||
|
||||
for (int iteration = 0; iteration < 100; iteration++) {
|
||||
for (int i = 0; i < 100; i++) {
|
||||
pointers[i] = malloc(128);
|
||||
TEST_ASSERT_NOT_NULL(pointers[i]);
|
||||
}
|
||||
|
||||
for (int i = 0; i < 100; i++) {
|
||||
free(pointers[i]);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_ASSERT_TRUE(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Test interrupt stress
|
||||
*/
|
||||
void test_interrupt_stress(void) {
|
||||
/* Enable maximum interrupts */
|
||||
kernel_start();
|
||||
|
||||
/* Generate interrupt load */
|
||||
for (int i = 0; i < 1000; i++) {
|
||||
/* Trigger software interrupts */
|
||||
__asm volatile("SVC #0");
|
||||
}
|
||||
|
||||
kernel_delay(100);
|
||||
|
||||
TEST_ASSERT_TRUE(stress_test_passed);
|
||||
}
|
||||
|
||||
/* ============================================================================
|
||||
* Test Runner
|
||||
* ============================================================================ */
|
||||
int main(void) {
|
||||
UNITY_BEGIN();
|
||||
|
||||
RUN_TEST(test_max_tasks_stress);
|
||||
RUN_TEST(test_context_switch_stress);
|
||||
RUN_TEST(test_memory_stress);
|
||||
RUN_TEST(test_interrupt_stress);
|
||||
|
||||
return UNITY_END();
|
||||
}
|
||||
Reference in New Issue
Block a user