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:
root
2026-08-23 03:35:29 -04:00
parent f113bf0a05
commit ca13734bf0
151 changed files with 23945 additions and 0 deletions
+184
View File
@@ -0,0 +1,184 @@
/**
* @file test_task.c
* @brief Unit tests for task management
*/
#include "unity.h"
#include "kernel.h"
#include "task.h"
#include <string.h>
/* Test variables */
static TaskHandle_t test_task_handle;
static volatile bool task_executed = false;
static volatile uint32_t task_execution_count = 0;
/* Test task function */
static void simple_task(void* params) {
(void)params;
task_executed = true;
task_execution_count++;
/* Task should terminate after execution */
while (1) {
kernel_delay(1000);
}
}
/* Setup */
void setUp(void) {
task_executed = false;
task_execution_count = 0;
kernel_init();
}
/* Teardown */
void tearDown(void) {
kernel_stop();
}
/* ============================================================================
* Test Cases
* ============================================================================ */
/**
* @brief Test task creation
*/
void test_task_create(void) {
TaskConfig_t config = {
.name = "test_task",
.function = simple_task,
.parameters = NULL,
.stack_size = 1024,
.priority = 1,
.period_ticks = 0
};
test_task_handle = task_create(&config);
TEST_ASSERT_NOT_NULL(test_task_handle);
TEST_ASSERT_EQUAL_STRING("test_task", test_task_handle->name);
TEST_ASSERT_EQUAL(1, task_get_priority(test_task_handle));
}
/**
* @brief Test task creation with invalid parameters
*/
void test_task_create_invalid(void) {
TaskConfig_t config = {
.name = NULL,
.function = NULL,
.parameters = NULL,
.stack_size = 0,
.priority = 100,
.period_ticks = 0
};
test_task_handle = task_create(&config);
TEST_ASSERT_NULL(test_task_handle);
}
/**
* @brief Test task suspend and resume
*/
void test_task_suspend_resume(void) {
TaskConfig_t config = {
.name = "suspend_test",
.function = simple_task,
.parameters = NULL,
.stack_size = 1024,
.priority = 2,
.period_ticks = 0
};
test_task_handle = task_create(&config);
/* Suspend task */
TEST_ASSERT_EQUAL(KERNEL_OK, task_suspend(test_task_handle));
TEST_ASSERT_EQUAL(TASK_SUSPENDED, task_get_state(test_task_handle));
/* Resume task */
TEST_ASSERT_EQUAL(KERNEL_OK, task_resume(test_task_handle));
TEST_ASSERT_EQUAL(TASK_READY, task_get_state(test_task_handle));
}
/**
* @brief Test task priority change
*/
void test_task_set_priority(void) {
TaskConfig_t config = {
.name = "priority_test",
.function = simple_task,
.parameters = NULL,
.stack_size = 1024,
.priority = 3,
.period_ticks = 0
};
test_task_handle = task_create(&config);
/* Change priority */
TEST_ASSERT_EQUAL(KERNEL_OK, task_set_priority(test_task_handle, 1));
TEST_ASSERT_EQUAL(1, task_get_priority(test_task_handle));
/* Invalid priority */
TEST_ASSERT_EQUAL(KERNEL_INVALID_PARAMETER,
task_set_priority(test_task_handle, 100));
}
/**
* @brief Test task statistics
*/
void test_task_statistics(void) {
TaskConfig_t config = {
.name = "stats_test",
.function = simple_task,
.parameters = NULL,
.stack_size = 1024,
.priority = 4,
.period_ticks = 10
};
test_task_handle = task_create(&config);
kernel_start();
kernel_delay(100);
TaskStatistics_t stats;
TEST_ASSERT_EQUAL(KERNEL_OK, task_get_statistics(test_task_handle, &stats));
TEST_ASSERT_GREATER_THAN(0, stats.execution_count);
}
/**
* @brief Test task deletion
*/
void test_task_delete(void) {
TaskConfig_t config = {
.name = "delete_test",
.function = simple_task,
.parameters = NULL,
.stack_size = 1024,
.priority = 5,
.period_ticks = 0
};
test_task_handle = task_create(&config);
TEST_ASSERT_EQUAL(KERNEL_OK, task_delete(test_task_handle));
}
/* ============================================================================
* Test Runner
* ============================================================================ */
int main(void) {
UNITY_BEGIN();
RUN_TEST(test_task_create);
RUN_TEST(test_task_create_invalid);
RUN_TEST(test_task_suspend_resume);
RUN_TEST(test_task_set_priority);
RUN_TEST(test_task_statistics);
RUN_TEST(test_task_delete);
return UNITY_END();
}