ca13734bf0
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.
198 lines
4.4 KiB
C
198 lines
4.4 KiB
C
/**
|
|
* @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();
|
|
}
|