From ed169b2f9479dc6654a6afc759413ab1e9b2a1ed Mon Sep 17 00:00:00 2001 From: mahi Date: Tue, 8 Jun 2010 22:18:03 +0200 Subject: [PATCH] Updated testsystem. Added test suites. Added Autostart tests. Autotester with T32. --- include/Os.h | 8 +- include/os_config_funcs.h | 2 +- system/kernel/alarm.c | 34 +- system/kernel/counter.c | 37 +- system/kernel/event.c | 25 +- system/kernel/sched_table.c | 5 +- system/kernel/testsystem/build_config.mk | 2 +- system/kernel/testsystem/config/Os_Cfg.c | 2 +- system/kernel/testsystem/config/Os_Cfg.h | 2 +- system/kernel/testsystem/os_test.h | 18 +- system/kernel/testsystem/suite_01/Os_Cfg.c | 23 +- system/kernel/testsystem/suite_01/Os_Cfg.h | 6 +- .../testsystem/suite_01/build_config.mk | 7 + .../testsystem/suite_01/config_01.arxml | 28 +- system/kernel/testsystem/suite_01/makefile | 8 +- .../kernel/testsystem/suite_01/test_master.c | 200 ++++++++++ system/kernel/testsystem/suite_02/Os_Cfg.c | 163 +++++++- system/kernel/testsystem/suite_02/Os_Cfg.h | 37 +- .../testsystem/suite_02/build_config.mk | 7 + .../testsystem/suite_02/config_02.arxml | 365 ++++++++++++++++- system/kernel/testsystem/suite_02/makefile | 9 +- .../kernel/testsystem/suite_02/test_master.c | 369 ++++++++++++++++++ system/kernel/testsystem/test_03_alarm.c | 2 +- system/kernel/testsystem/test_framework.c | 84 +++- system/kernel/testsystem/test_framework.h | 22 +- tools/t32/load.cmm | 13 +- tools/t32/term.cmm | 11 +- tools/t32/test.cmm | 64 +++ 28 files changed, 1418 insertions(+), 135 deletions(-) create mode 100644 system/kernel/testsystem/suite_01/build_config.mk create mode 100644 system/kernel/testsystem/suite_01/test_master.c create mode 100644 system/kernel/testsystem/suite_02/build_config.mk create mode 100644 system/kernel/testsystem/suite_02/test_master.c create mode 100644 tools/t32/test.cmm diff --git a/include/Os.h b/include/Os.h index c8c3568e..b714805e 100644 --- a/include/Os.h +++ b/include/Os.h @@ -347,21 +347,21 @@ typedef enum { OSServiceId_GetTaskState, } OsServiceIdType;; -typedef struct os_error_s { +typedef struct OsError { OsServiceIdType serviceId; uint32_t param1; uint32_t param2; uint32_t param3; -} os_error_t; +} OsErrorType; -extern os_error_t os_error; +extern OsErrorType os_error; // TODO: Add the service id to all OS service methods. static inline OsServiceIdType OSErrorGetServiceId(void) { return os_error.serviceId; } -extern os_error_t os_error; +extern OsErrorType os_error; #define OSError_ActivateTask_TaskID ((TaskType) os_error.param1) #define OSError_ChainTask_TaskID ((TaskType) os_error.param1) diff --git a/include/os_config_funcs.h b/include/os_config_funcs.h index 9cdd1445..3e7daa20 100644 --- a/include/os_config_funcs.h +++ b/include/os_config_funcs.h @@ -49,7 +49,7 @@ void Os_CfgValidate(void ) { #endif } -os_error_t os_error; +OsErrorType os_error; //------------------------------------------------------------------- diff --git a/system/kernel/alarm.c b/system/kernel/alarm.c index 12b62329..ce53f725 100644 --- a/system/kernel/alarm.c +++ b/system/kernel/alarm.c @@ -147,6 +147,37 @@ StatusType SetRelAlarm(AlarmType AlarmId, TickType Increment, TickType Cycle){ OS_STD_END_3(OSServiceId_SetRelAlarm,AlarmId, Increment, Cycle); } + +/** + * The system service occupies the alarm element. + * When ticks are reached, the task assigned to the alarm + * + * If the absolute value is very close to the current counter + * value, the alarm may expire, and the task may become ready or + * the alarm-callback may be called before the system service + * returns to the user. + * If the absolute value already was reached before the + * system call, the alarm shall only expire when the absolute value + * is reached again, i.e. after the next overrun of the + * counter. + * + * If is unequal zero, the alarm element is logged on again + * immediately after expiry with the relative value . + * + * The alarm shall not already be in use. + * To change values of alarms already in use the alarm shall be + * cancelled first. + * + * If the alarm is already in use, this call will be ignored and the + * error E_OS_STATE is returned. + * + * Allowed on task level and in ISR, but not in hook routines. + * + * @param AlarmId + * @param Start + * @param Cycle + * @return + */ StatusType SetAbsAlarm(AlarmType AlarmId, TickType Start, TickType Cycle) { @@ -176,7 +207,8 @@ StatusType SetAbsAlarm(AlarmType AlarmId, TickType Start, TickType Cycle) { Irq_Save(flags); if( aPtr->active == 1 ) { - rv = E_OS_STATE; + rv = E_OS_STATE; + Irq_Restore(flags); goto err; } diff --git a/system/kernel/counter.c b/system/kernel/counter.c index f44c7ed7..d4abacb5 100644 --- a/system/kernel/counter.c +++ b/system/kernel/counter.c @@ -202,30 +202,23 @@ TickType GetOsTick( void ) { * Initialize alarms and schedule-tables for the counters */ void Os_CounterInit( void ) { - OsCounterType *counter; - OsAlarmType *alarm_obj; - OsSchTblType *sched_obj; - /* Create a list from the counter to the alarms */ - for(int i=0; i < Os_CfgGetCounterCnt() ; i++) { - counter = Os_CfgGetCounter(i); - // Alarms - SLIST_INIT(&counter->alarm_head); - for(int j=0; j < Os_CfgGetAlarmCnt(); j++ ) { - alarm_obj = Os_CfgGetAlarmObj(j); - // Add the alarms - SLIST_INSERT_HEAD(&counter->alarm_head,alarm_obj, alarm_list); - } - // Schedule tables - SLIST_INIT(&counter->sched_head); - for(int j=0; j < Os_CfgGetSchedCnt(); j++ ) { - sched_obj = Os_CfgGetSched(j); - // Add the alarms - SLIST_INSERT_HEAD(&counter->sched_head, - sched_obj, - sched_list); - } + OsCounterType *cPtr; + OsAlarmType *aPtr; + OsSchTblType *sPtr; + + /* Add the alarms to counters */ + for(int i=0; i < Os_CfgGetAlarmCnt(); i++ ) { + aPtr = Os_CfgGetAlarmObj(i); + cPtr = aPtr->counter; + SLIST_INSERT_HEAD(&cPtr->alarm_head,aPtr, alarm_list); + } + /* Add the schedule tables to counters */ + for(int i=0; i < Os_CfgGetSchedCnt(); i++ ) { + sPtr = Os_CfgGetSched(i); + cPtr = sPtr->counter; + SLIST_INSERT_HEAD(&cPtr->sched_head, sPtr, sched_list); } } diff --git a/system/kernel/event.c b/system/kernel/event.c index bfe20a06..44678bfd 100644 --- a/system/kernel/event.c +++ b/system/kernel/event.c @@ -142,7 +142,20 @@ StatusType SetEvent( TaskType TaskID, EventMaskType Mask ) { OS_STD_END_2(OSServiceId_SetEvent,TaskID, Mask); } - + + +/** + * This service returns the current state of all event bits of the task + * , not the events that the task is waiting for. + * The service may be called from interrupt service routines, task + * level and some hook routines (see Figure 12-1). + * The current status of the event mask of task is copied + * to . + * + * @param TaskId Task whose event mask is to be returned. + * @param Mask Reference to the memory of the return data. + * @return + */ StatusType GetEvent( TaskType TaskId, EventMaskRefType Mask) { OsPcbType *dest_pcb; @@ -160,7 +173,15 @@ StatusType GetEvent( TaskType TaskId, EventMaskRefType Mask) { OS_STD_END_2(OSServiceId_GetEvent,TaskId, Mask); } - + +/** + * The events of the extended task calling ClearEvent are cleared + * according to the event mask . + * + * + * @param Mask + * @return + */ StatusType ClearEvent( EventMaskType Mask) { StatusType rv = E_OK; OsPcbType *pcb; diff --git a/system/kernel/sched_table.c b/system/kernel/sched_table.c index 9aa5edb7..885f1d17 100644 --- a/system/kernel/sched_table.c +++ b/system/kernel/sched_table.c @@ -125,7 +125,10 @@ static void ScheduleTableConsistenyCheck( OsSchTblType *sTblPtr ) { /** @req OS408 */ for(iter=0; iter < SA_LIST_CNT(&sTblPtr->expirePointList) ; iter++) { delta = SA_LIST_GET(&sTblPtr->expirePointList,iter)->offset - delta; - assert( delta >= minCycle ); + /* initial offset may be zero (OS443) */ + if(iter!=0) { + assert( delta >= minCycle ); + } assert( delta <= maxValue ); } diff --git a/system/kernel/testsystem/build_config.mk b/system/kernel/testsystem/build_config.mk index f03986eb..c418f947 100644 --- a/system/kernel/testsystem/build_config.mk +++ b/system/kernel/testsystem/build_config.mk @@ -1,7 +1,7 @@ # Figure out the most of the modules to use. OPTIMAL_USE = T32_TERM SIMPLE_PRINTF RAMLOG -MOD_USE+=KERNEL MCU ECUM $(filter $(OPTIMAL_USE),$(MOD_AVAIL)) +MOD_USE+=KERNEL MCU COMMON NEWLIB DET ECUM $(filter $(OPTIMAL_USE),$(MOD_AVAIL)) $(warning $(MOD_USE)) #MOD_USE+=KERNEL MCU T32_TERM SIMPLE_PRINTF RAMLOG diff --git a/system/kernel/testsystem/config/Os_Cfg.c b/system/kernel/testsystem/config/Os_Cfg.c index d3bcc746..919a2d4f 100644 --- a/system/kernel/testsystem/config/Os_Cfg.c +++ b/system/kernel/testsystem/config/Os_Cfg.c @@ -9,7 +9,7 @@ * * * Generated by Arctic Studio (http://arccore.com) -* on Wed May 05 23:09:13 CEST 2010 +* on Tue Jun 08 08:30:59 CEST 2010 */ diff --git a/system/kernel/testsystem/config/Os_Cfg.h b/system/kernel/testsystem/config/Os_Cfg.h index 39603564..f71ef2a4 100644 --- a/system/kernel/testsystem/config/Os_Cfg.h +++ b/system/kernel/testsystem/config/Os_Cfg.h @@ -9,7 +9,7 @@ * * * Generated by Arctic Studio (http://arccore.com) -* on Wed May 05 23:09:13 CEST 2010 +* on Tue Jun 08 08:30:59 CEST 2010 */ diff --git a/system/kernel/testsystem/os_test.h b/system/kernel/testsystem/os_test.h index 3087bd28..d1c438a2 100644 --- a/system/kernel/testsystem/os_test.h +++ b/system/kernel/testsystem/os_test.h @@ -12,19 +12,31 @@ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * for more details. * -------------------------------- Arctic Core ------------------------------*/ - +/* + * Contains mostly macros for the test-system. Most macro's have the same + * name as in embUnit, to make it easier to use. + * + */ + #ifndef OS_TEST_H_ #define OS_TEST_H_ #include "test_framework.h" #include "debug.h" -typedef void (*test_func_t)( void ); +typedef void (*test_func_t)( void ); + +#define TEST_INIT() printf("Test init\n"); #define TEST_FAIL(_text) test_fail((_text), __FILE__, __LINE__, __FUNCTION__ ) -#define TEST_OK() test_ok(); +#define TEST_OK() test_ok(); #define TEST_ASSERT(_cond) if(!(_cond)) { TEST_FAIL(#_cond); } +/* Start to run a test */ #define TEST_RUN() printf("Running test %d\n",test_nr); +/* Indicate that a test is done */ +//#define TEST_DONE() +#define TEST_START(_str,_nr) testStart(_str,_nr) +#define TEST_NEXT(_str,_next_nr) testEnd(); testStart(_str,_next_nr); extern int test_suite; diff --git a/system/kernel/testsystem/suite_01/Os_Cfg.c b/system/kernel/testsystem/suite_01/Os_Cfg.c index 9ae17419..8e61f323 100644 --- a/system/kernel/testsystem/suite_01/Os_Cfg.c +++ b/system/kernel/testsystem/suite_01/Os_Cfg.c @@ -9,7 +9,7 @@ * * * Generated by Arctic Studio (http://arccore.com) -* on Tue May 04 16:38:43 CEST 2010 +* on Tue Jun 08 20:51:20 CEST 2010 */ @@ -82,7 +82,7 @@ GEN_ALARM_HEAD { NULL, ALARM_ACTION_SETEVENT, TASK_ID_etask_sup_m, - EVENT_MASK_NOTIF, + EVENT_MASK_notif, NULL ), GEN_ALARM( ALARM_ID_c_sys_1_setevent_etask_m, "c_sys_1_setevent", @@ -90,7 +90,7 @@ GEN_ALARM_HEAD { NULL, ALARM_ACTION_SETEVENT, TASK_ID_etask_sup_m, - EVENT_MASK_NOTIF, + EVENT_MASK_notif, NULL ), GEN_ALARM( ALARM_ID_c_sys_activate_btask_h, "c_sys_activate_b", @@ -104,11 +104,6 @@ GEN_ALARM_HEAD { // ################################ RESOURCES ############################### GEN_RESOURCE_HEAD { - GEN_RESOURCE( - RES_SCHEDULER, - RESOURCE_TYPE_STANDARD, - 0 - ), GEN_RESOURCE( RES_ID_int_1, RESOURCE_TYPE_INTERNAL, @@ -251,7 +246,7 @@ GEN_SCHTBL_TASK_LIST_HEAD( 0, 5 ) { GEN_SCHTBL_EVENT_LIST_HEAD( 0, 7 ) { { - EVENT_MASK_NOTIF, + EVENT_MASK_notif, TASK_ID_etask_sup_m }, @@ -267,7 +262,7 @@ GEN_SCHTBL_TASK_LIST_HEAD( 0, 11 ) { GEN_SCHTBL_EVENT_LIST_HEAD( 0, 11 ) { { - EVENT_MASK_NOTIF, + EVENT_MASK_notif, TASK_ID_etask_sup_m }, @@ -281,12 +276,6 @@ GEN_SCHTBL_EXPIRY_POINT_HEAD( 0 ) { }; -GEN_SCHTBL_AUTOSTART( - 0, - SCHTBL_AUTOSTART_ABSOLUTE, - 1, - OSDEFAULTAPPMODE -); // Table data 1 @@ -312,7 +301,7 @@ GEN_SCHTBL_HEAD { COUNTER_ID_soft_1, SINGLE_SHOT, 15, - GEN_SCHTBL_AUTOSTART_NAME(0) + NULL ), GEN_SCHEDULETABLE( 1, diff --git a/system/kernel/testsystem/suite_01/Os_Cfg.h b/system/kernel/testsystem/suite_01/Os_Cfg.h index 092af50e..14e9d15b 100644 --- a/system/kernel/testsystem/suite_01/Os_Cfg.h +++ b/system/kernel/testsystem/suite_01/Os_Cfg.h @@ -9,7 +9,7 @@ * * * Generated by Arctic Studio (http://arccore.com) -* on Tue May 04 16:38:43 CEST 2010 +* on Tue Jun 08 20:51:20 CEST 2010 */ @@ -40,8 +40,8 @@ // Event masks -#define EVENT_MASK_KILL 32768 -#define EVENT_MASK_NOTIF 1 +#define EVENT_MASK_kill 32768 +#define EVENT_MASK_notif 1 // Isr Id's diff --git a/system/kernel/testsystem/suite_01/build_config.mk b/system/kernel/testsystem/suite_01/build_config.mk new file mode 100644 index 00000000..c418f947 --- /dev/null +++ b/system/kernel/testsystem/suite_01/build_config.mk @@ -0,0 +1,7 @@ + +# Figure out the most of the modules to use. +OPTIMAL_USE = T32_TERM SIMPLE_PRINTF RAMLOG +MOD_USE+=KERNEL MCU COMMON NEWLIB DET ECUM $(filter $(OPTIMAL_USE),$(MOD_AVAIL)) +$(warning $(MOD_USE)) +#MOD_USE+=KERNEL MCU T32_TERM SIMPLE_PRINTF RAMLOG + diff --git a/system/kernel/testsystem/suite_01/config_01.arxml b/system/kernel/testsystem/suite_01/config_01.arxml index 546dfbb2..0d4d303e 100644 --- a/system/kernel/testsystem/suite_01/config_01.arxml +++ b/system/kernel/testsystem/suite_01/config_01.arxml @@ -12,7 +12,7 @@ - testsystem + config_01 @@ -450,7 +450,7 @@ - NOTIF + notif /ArcCore/Os/OsEvent @@ -460,7 +460,7 @@ - KILL + kill /ArcCore/Os/OsEvent @@ -527,7 +527,7 @@ /ArcCore/Os/OsScheduleTable/OsScheduleTableExpiryPoint/OsScheduleTableEventSetting/OsScheduleTableSetEventRef - /testsystem/Os/NOTIF + /testsystem/Os/notif /ArcCore/Os/OsScheduleTable/OsScheduleTableExpiryPoint/OsScheduleTableEventSetting/OsScheduleTableSetEventTaskRef @@ -553,7 +553,7 @@ /ArcCore/Os/OsScheduleTable/OsScheduleTableExpiryPoint/OsScheduleTableEventSetting/OsScheduleTableSetEventRef - /testsystem/Os/NOTIF + /testsystem/Os/notif /ArcCore/Os/OsScheduleTable/OsScheduleTableExpiryPoint/OsScheduleTableEventSetting/OsScheduleTableSetEventTaskRef @@ -573,20 +573,6 @@ - - OsScheduleTableAutostart - /ArcCore/Os/OsScheduleTable/OsScheduleTableAutostart - - - /ArcCore/Os/OsScheduleTable/OsScheduleTableAutostart/OsScheduleTableAutostartType - ABSOLUTE - - - /ArcCore/Os/OsScheduleTable/OsScheduleTableAutostart/ArcCoreOsScheduleTableOffset - 1 - - - @@ -715,7 +701,7 @@ /ArcCore/Os/OsAlarm/OsAlarmAction/OsAlarmSetEvent/OsAlarmSetEventRef - /testsystem/Os/NOTIF + /testsystem/Os/notif /ArcCore/Os/OsAlarm/OsAlarmAction/OsAlarmSetEvent/OsAlarmSetEventTaskRef @@ -741,7 +727,7 @@ /ArcCore/Os/OsAlarm/OsAlarmAction/OsAlarmSetEvent/OsAlarmSetEventRef - /testsystem/Os/NOTIF + /testsystem/Os/notif /ArcCore/Os/OsAlarm/OsAlarmAction/OsAlarmSetEvent/OsAlarmSetEventTaskRef diff --git a/system/kernel/testsystem/suite_01/makefile b/system/kernel/testsystem/suite_01/makefile index ab199d7b..ccf8090a 100644 --- a/system/kernel/testsystem/suite_01/makefile +++ b/system/kernel/testsystem/suite_01/makefile @@ -12,12 +12,7 @@ obj-y += test_04_stable.o obj-y += test_05_const.o obj-y += test_06_event.o -#obj-y += test_sup_01.o -#obj-y += test_sup_02.o -#obj-y += test_sup_03.o -#obj-y += test_sup_04.o obj-y += test_framework.o - obj-y += Os_Cfg.o # Not supported yet... @@ -44,7 +39,7 @@ vpath-y += $(ROOTDIR)/boards/$(BOARDDIR) vpath-y += $(ROOTDIR)/boards/$(BOARDDIR)/config VPATH += $(vpath-y) VPATH += $(ROOTDIR)/$(SUBDIR)/config - +VPATH += $(realpath ../..) # libs needed by us libitem-y += $(ROOTDIR)/libs/libkernel_$(ARCH_MCU).a @@ -54,6 +49,7 @@ ldcmdfile-y = $(ROOTDIR)/$(ARCH_PATH-y)/scripts/linkscript_gcc.ldf #ldcmdfile-y = $(ROOTDIR)/$(ARCH_PATH-y)/scripts/linkscript_gcc.ldf inc-y += .. +inc-y += ../.. inc-y += $(ROOTDIR)/system/kernel/$(objdir) inc-y += $(ROOTDIR)/system/kernel/include inc-y += $(ROOTDIR)/$(ARCH_PATH-y) diff --git a/system/kernel/testsystem/suite_01/test_master.c b/system/kernel/testsystem/suite_01/test_master.c new file mode 100644 index 00000000..8abe3354 --- /dev/null +++ b/system/kernel/testsystem/suite_01/test_master.c @@ -0,0 +1,200 @@ +/* -------------------------------- Arctic Core ------------------------------ + * Arctic Core - the open source AUTOSAR platform http://arccore.com + * + * Copyright (C) 2009 ArcCore AB + * + * This source code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 as published by the + * Free Software Foundation; See . + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * for more details. + * -------------------------------- Arctic Core ------------------------------*/ + +/* CONFIGURATION + * - The "etask_master" should be the only autostarted task. + * - It can hold at most 3 extended task and 3 basic tasks. They must be called + * etask_sup_l, etask_sup_m, etask_sup_h, + * btask_sup_l, btask_sup_m, btask_sup_h + */ + + + + + +#include +#include "Os.h" +#include "os_test.h" +#include "Mcu.h" +#if defined(USE_GPT) +#include "Gpt.h" +#endif + + +//#define USE_LDEBUG_PRINTF +#include "debug.h" +#include "arc.h" + + +typedef struct { + uint32 nr; + uint32 sub_nr; + uint32 failed; +} test_master_cfg_t; + +TaskType test_activate_pid_list[] = +{ +/* 01*/ TASK_ID_etask_sup_l, +/* 02*/ TASK_ID_etask_sup_l, +/* 03*/ TASK_ID_etask_sup_l, +/* 04*/ TASK_ID_etask_sup_l, +}; + +static int test_case = 0; + +/* + * Master test process, everything is controlled from here. + */ +void etask_master( void ) { + TaskType pid; + + for( ; test_case < sizeof(test_activate_pid_list)/sizeof(TaskType); test_case++) + { + test_nr = 1; + printf("-----> Test Suite %02d\n",test_suite); + pid = test_activate_pid_list[test_case]; + ActivateTask(pid); + /* We are lowest prio task in the system (apart from idle) so + * all tasks in the test are now terminated... + */ + test_suite++; + } + + // Test complete.. + testExit(0); +} + +extern test_func_t etask_sup_matrix[][3]; +extern test_func_t btask_sup_matrix[][3]; + +//-------------------------------------------------------------------- +//-------------------------------------------------------------------- + +void etask_sup_l( void ) +{ + test_func_t func; + func = etask_sup_matrix[test_case][0]; + if( func != NULL ) + func(); + + TerminateTask(); +} + +void etask_sup_m( void ) +{ + test_func_t func; + func = etask_sup_matrix[test_case][1]; + if( func != NULL ) + func(); + + TerminateTask(); +} + +void etask_sup_h( void ) +{ + test_func_t func; + func = etask_sup_matrix[test_case][2]; + if( func != NULL ) + func(); + + TerminateTask(); +} + +//-------------------------------------------------------------------- +//-------------------------------------------------------------------- + +void btask_sup_l( void ) { + test_func_t func; + func = btask_sup_matrix[test_case][0]; + if( func != NULL ) + func(); +} +void btask_sup_m( void ) { + test_func_t func; + func = btask_sup_matrix[test_case][1]; + if( func != NULL ) + func(); +} +void btask_sup_h( void ) { + test_func_t func; + func = btask_sup_matrix[test_case][2]; + if( func != NULL ) + func(); +} + + +void OsIdle(void ) { + for(;;); +} + + +/* Global hooks */ +ProtectionReturnType ProtectionHook( StatusType FatalError ) { + printf("## ProtectionHook\n"); + return PRO_KILLAPPL; +} + +void StartupHook( void ) { +// LDEBUG_PRINTF("## StartupHook\n"); + +#ifdef USE_MCU + uint32_t sys_freq = McuE_GetSystemClock(); + (void)sys_freq; + LDEBUG_PRINTF("Sys clock %d Hz\n",sys_freq); +#endif +} + +void ShutdownHook( StatusType Error ) { + LDEBUG_PRINTF("## ShutdownHook\n"); + const char *err; + err = Arc_StatusToString(Error); + while(1) { + err = err; + } +} + +void ErrorHook( StatusType Error ) { + LDEBUG_PRINTF("## ErrorHook err=%d\n",Error); + const char *err; + err = Arc_StatusToString(Error); +// while(1); +} + +void PreTaskHook( void ) { + TaskType task; + GetTaskID(&task); + if( task > 10 ) { + while(1); + } + LDEBUG_PRINTF("## PreTaskHook, taskid=%d\n",task); +} + +void PostTaskHook( void ) { + TaskType task; + GetTaskID(&task); + if( task > 10 ) { + while(1); + } + + LDEBUG_PRINTF("## PostTaskHook, taskid=%d\n",task); +#if 0 + { + StackInfoType si; + Os_Arc_GetStackInfo(task,&si); +// LDEBUG_PRINTF("Stack usage %d%% (this=%08x, top=%08x, size=%08x,usage=%08x )\n",OS_STACK_USAGE(&si),si.curr, si.top,si.size,si.usage); + } +#endif +} + diff --git a/system/kernel/testsystem/suite_02/Os_Cfg.c b/system/kernel/testsystem/suite_02/Os_Cfg.c index e06ce62f..d349d3a8 100644 --- a/system/kernel/testsystem/suite_02/Os_Cfg.c +++ b/system/kernel/testsystem/suite_02/Os_Cfg.c @@ -9,7 +9,7 @@ * * * Generated by Arctic Studio (http://arccore.com) -* on Tue May 04 22:55:40 CEST 2010 +* on Tue Jun 08 08:23:43 CEST 2010 */ @@ -37,27 +37,62 @@ uint32 os_dbg_mask = D_RESOURCE |D_SCHTBL |D_EVENT |D_TASK |D_ALARM; // ################################# COUNTERS ############################### GEN_COUNTER_HEAD { + GEN_COUNTER( COUNTER_ID_Counter1, + "Counter1", + COUNTER_TYPE_HARD, + COUNTER_UNIT_NANO, + 0xffff, + 1, + 1, + 0), + GEN_COUNTER( COUNTER_ID_Counter2, + "Counter2", + COUNTER_TYPE_SOFT, + COUNTER_UNIT_NANO, + 65535, + 1, + 1, + 0), }; -CounterType Os_Arc_OsTickCounter = -1; +CounterType Os_Arc_OsTickCounter = COUNTER_ID_Counter1; // ################################## ALARMS ################################ +GEN_ALARM_AUTOSTART(ALARM_ID_Alarm1, ALARM_AUTOSTART_ABSOLUTE, 1, 0, OSDEFAULTAPPMODE ); + +GEN_ALARM_AUTOSTART(ALARM_ID_Alarm2, ALARM_AUTOSTART_ABSOLUTE, 1, 0, OSDEFAULTAPPMODE ); + GEN_ALARM_HEAD { + GEN_ALARM( ALARM_ID_Alarm1, + "Alarm1", + COUNTER_ID_Counter2, + GEN_ALARM_AUTOSTART_NAME(ALARM_ID_Alarm1), + ALARM_ACTION_SETEVENT, + TASK_ID_etask_master, + EVENT_MASK_Alarm_1, + NULL ), + GEN_ALARM( ALARM_ID_Alarm2, + "Alarm2", + COUNTER_ID_Counter2, + GEN_ALARM_AUTOSTART_NAME(ALARM_ID_Alarm2), + ALARM_ACTION_SETEVENT, + TASK_ID_etask_master, + EVENT_MASK_Alarm_2, + NULL ), }; // ################################ RESOURCES ############################### GEN_RESOURCE_HEAD { - GEN_RESOURCE( - RES_SCHEDULER, - RESOURCE_TYPE_STANDARD, - 0 - ), }; // ############################## STACKS (TASKS) ############################ DECLARE_STACK(OsIdle,OS_OSIDLE_STACK_SIZE); -DECLARE_STACK(btask_l,2048); +DECLARE_STACK(btask_2,2048); +DECLARE_STACK(btask_4,2048); +DECLARE_STACK(etask_3,2048); +DECLARE_STACK(etask_5,2048); +DECLARE_STACK(etask_master,2048); // ################################## TASKS ################################# GEN_TASK_HEAD { @@ -69,10 +104,50 @@ GEN_TASK_HEAD { 0 ), GEN_ETASK( - btask_l, - 1, + btask_2, + 2, FULL, - FALSE, + TRUE, + NULL, + 0 + ), + + + GEN_BTASK( + btask_4, + 4, + FULL, + TRUE, + NULL, + 0, + 1 + ), + + GEN_ETASK( + etask_3, + 3, + FULL, + TRUE, + NULL, + 0 + ), + + + GEN_ETASK( + etask_5, + 5, + FULL, + TRUE, + NULL, + 0 + ), + + + GEN_ETASK( + etask_master, + 10, + FULL, + TRUE, NULL, 0 ), @@ -95,8 +170,74 @@ GEN_HOOKS( // ############################ SCHEDULE TABLES ############################# +// Table data ScheduleTable_1 + + +GEN_SCHTBL_EVENT_LIST_HEAD( 0, 0 ) { + + { + EVENT_MASK_SchTbl_1, + TASK_ID_etask_master + }, + +}; + + +GEN_SCHTBL_EXPIRY_POINT_HEAD( 0 ) { + GEN_SCHTBL_EXPIRY_POINT_W_EVENT(0, 0), + +}; + +GEN_SCHTBL_AUTOSTART( + 0, + SCHTBL_AUTOSTART_ABSOLUTE, + 1, + OSDEFAULTAPPMODE +); + +// Table data ScheduleTable_2 + + +GEN_SCHTBL_EVENT_LIST_HEAD( 1, 0 ) { + + { + EVENT_MASK_SchTbl_2, + TASK_ID_etask_master + }, + +}; + + +GEN_SCHTBL_EXPIRY_POINT_HEAD( 1 ) { + GEN_SCHTBL_EXPIRY_POINT_W_EVENT(1, 0), + +}; + +GEN_SCHTBL_AUTOSTART( + 1, + SCHTBL_AUTOSTART_ABSOLUTE, + 1, + OSDEFAULTAPPMODE +); + // Table heads GEN_SCHTBL_HEAD { + GEN_SCHEDULETABLE( + 0, + "ScheduleTable_1", + COUNTER_ID_Counter2, + SINGLE_SHOT, + 10, + GEN_SCHTBL_AUTOSTART_NAME(0) + ), + GEN_SCHEDULETABLE( + 1, + "ScheduleTable_2", + COUNTER_ID_Counter2, + SINGLE_SHOT, + 10, + GEN_SCHTBL_AUTOSTART_NAME(1) + ), }; GEN_PCB_LIST() diff --git a/system/kernel/testsystem/suite_02/Os_Cfg.h b/system/kernel/testsystem/suite_02/Os_Cfg.h index 43d949e3..d54e2e22 100644 --- a/system/kernel/testsystem/suite_02/Os_Cfg.h +++ b/system/kernel/testsystem/suite_02/Os_Cfg.h @@ -9,7 +9,7 @@ * * * Generated by Arctic Studio (http://arccore.com) -* on Tue May 04 22:55:40 CEST 2010 +* on Tue Jun 08 08:23:43 CEST 2010 */ @@ -23,13 +23,24 @@ // Alarm Id's +#define ALARM_ID_Alarm1 0 +#define ALARM_ID_Alarm2 1 // Counter Id's +#define COUNTER_ID_Counter1 0 +#define COUNTER_ID_Counter2 1 // Counter macros +#define OSMAXALLOWEDVALUE_Counter1 65535 +#define OSMAXALLOWEDVALUE_Counter2 65535 // Event masks +#define EVENT_MASK_Alarm_1 1 +#define EVENT_MASK_Alarm_2 2 +#define EVENT_MASK_Event1 1 +#define EVENT_MASK_SchTbl_1 4 +#define EVENT_MASK_SchTbl_2 8 // Isr Id's @@ -41,23 +52,33 @@ // Task Id's #define TASK_ID_OsIdle 0 -#define TASK_ID_btask_l 1 +#define TASK_ID_btask_2 1 +#define TASK_ID_btask_4 2 +#define TASK_ID_etask_3 3 +#define TASK_ID_etask_5 4 +#define TASK_ID_etask_master 5 // Task entry points void OsIdle( void ); -void btask_l( void ); +void btask_2( void ); +void btask_4( void ); +void etask_3( void ); +void etask_5( void ); +void etask_master( void ); // Schedule table id's +#define SCHTBL_ID_ScheduleTable_1 0 +#define SCHTBL_ID_ScheduleTable_2 1 // Stack size #define OS_INTERRUPT_STACK_SIZE 2048 #define OS_OSIDLE_STACK_SIZE 512 -#define OS_ALARM_CNT 0 -#define OS_TASK_CNT 2 -#define OS_SCHTBL_CNT 0 -#define OS_COUNTER_CNT 0 -#define OS_EVENTS_CNT 0 +#define OS_ALARM_CNT 2 +#define OS_TASK_CNT 6 +#define OS_SCHTBL_CNT 2 +#define OS_COUNTER_CNT 2 +#define OS_EVENTS_CNT 5 #define OS_ISRS_CNT 0 #define OS_RESOURCE_CNT 0 #define OS_LINKED_RESOURCE_CNT 0 diff --git a/system/kernel/testsystem/suite_02/build_config.mk b/system/kernel/testsystem/suite_02/build_config.mk new file mode 100644 index 00000000..c418f947 --- /dev/null +++ b/system/kernel/testsystem/suite_02/build_config.mk @@ -0,0 +1,7 @@ + +# Figure out the most of the modules to use. +OPTIMAL_USE = T32_TERM SIMPLE_PRINTF RAMLOG +MOD_USE+=KERNEL MCU COMMON NEWLIB DET ECUM $(filter $(OPTIMAL_USE),$(MOD_AVAIL)) +$(warning $(MOD_USE)) +#MOD_USE+=KERNEL MCU T32_TERM SIMPLE_PRINTF RAMLOG + diff --git a/system/kernel/testsystem/suite_02/config_02.arxml b/system/kernel/testsystem/suite_02/config_02.arxml index 321acc30..49ec540f 100644 --- a/system/kernel/testsystem/suite_02/config_02.arxml +++ b/system/kernel/testsystem/suite_02/config_02.arxml @@ -136,7 +136,7 @@ - btask_l + btask_2 /ArcCore/Os/OsTask @@ -145,7 +145,7 @@ /ArcCore/Os/OsTask/OsTaskPriority - 1 + 2 /ArcCore/Os/OsTask/OsTaskProcessType @@ -160,6 +160,12 @@ FULL + + + OsTaskAutostart + /ArcCore/Os/OsTask/OsTaskAutostart + + Alarm1 @@ -167,8 +173,43 @@ /ArcCore/Os/OsAlarm/OsAlarmCounterRef + /suite_02/Os/Counter2 + + + OsAlarmAutostart + /ArcCore/Os/OsAlarm/OsAlarmAutostart + + + /ArcCore/Os/OsAlarm/OsAlarmAutostart/OsAlarmAlarmTime + 1 + + + /ArcCore/Os/OsAlarm/OsAlarmAutostart/OsAlarmAutostartType + ABSOLUTE + + + /ArcCore/Os/OsAlarm/OsAlarmAutostart/OsAlarmCycleTime + 0 + + + + + OsAlarmSetEvent + /ArcCore/Os/OsAlarm/OsAlarmAction/OsAlarmSetEvent + + + /ArcCore/Os/OsAlarm/OsAlarmAction/OsAlarmSetEvent/OsAlarmSetEventRef + /suite_02/Os/Alarm_1 + + + /ArcCore/Os/OsAlarm/OsAlarmAction/OsAlarmSetEvent/OsAlarmSetEventTaskRef + /suite_02/Os/etask_master + + + + Alarm2 @@ -176,8 +217,43 @@ /ArcCore/Os/OsAlarm/OsAlarmCounterRef + /suite_02/Os/Counter2 + + + OsAlarmAutostart + /ArcCore/Os/OsAlarm/OsAlarmAutostart + + + /ArcCore/Os/OsAlarm/OsAlarmAutostart/OsAlarmAlarmTime + 1 + + + /ArcCore/Os/OsAlarm/OsAlarmAutostart/OsAlarmAutostartType + ABSOLUTE + + + /ArcCore/Os/OsAlarm/OsAlarmAutostart/OsAlarmCycleTime + 0 + + + + + OsAlarmSetEvent + /ArcCore/Os/OsAlarm/OsAlarmAction/OsAlarmSetEvent + + + /ArcCore/Os/OsAlarm/OsAlarmAction/OsAlarmSetEvent/OsAlarmSetEventRef + /suite_02/Os/Alarm_2 + + + /ArcCore/Os/OsAlarm/OsAlarmAction/OsAlarmSetEvent/OsAlarmSetEventTaskRef + /suite_02/Os/etask_master + + + + ScheduleTable_1 @@ -185,7 +261,7 @@ /ArcCore/Os/OsScheduleTable/OsScheduleTableDuration - 0 + 10 /ArcCore/Os/OsScheduleTable/OsScheduleTableRepeating @@ -195,6 +271,7 @@ /ArcCore/Os/OsScheduleTable/OsScheduleTableCounterRef + /suite_02/Os/Counter2 @@ -208,17 +285,36 @@ - - TaskActivation1 - /ArcCore/Os/OsScheduleTable/OsScheduleTableExpiryPoint/OsScheduleTableTaskActivation + + EventSetting1 + /ArcCore/Os/OsScheduleTable/OsScheduleTableExpiryPoint/OsScheduleTableEventSetting - /ArcCore/Os/OsScheduleTable/OsScheduleTableExpiryPoint/OsScheduleTableTaskActivation/OsScheduleTableActivateTaskRef + /ArcCore/Os/OsScheduleTable/OsScheduleTableExpiryPoint/OsScheduleTableEventSetting/OsScheduleTableSetEventRef + /suite_02/Os/SchTbl_1 + + + /ArcCore/Os/OsScheduleTable/OsScheduleTableExpiryPoint/OsScheduleTableEventSetting/OsScheduleTableSetEventTaskRef + /suite_02/Os/etask_master + + OsScheduleTableAutostart + /ArcCore/Os/OsScheduleTable/OsScheduleTableAutostart + + + /ArcCore/Os/OsScheduleTable/OsScheduleTableAutostart/OsScheduleTableAutostartType + ABSOLUTE + + + /ArcCore/Os/OsScheduleTable/OsScheduleTableAutostart/ArcCoreOsScheduleTableOffset + 1 + + + @@ -227,7 +323,7 @@ /ArcCore/Os/OsScheduleTable/OsScheduleTableDuration - 0 + 10 /ArcCore/Os/OsScheduleTable/OsScheduleTableRepeating @@ -237,6 +333,7 @@ /ArcCore/Os/OsScheduleTable/OsScheduleTableCounterRef + /suite_02/Os/Counter2 @@ -249,9 +346,261 @@ 0 + + + EventSetting1 + /ArcCore/Os/OsScheduleTable/OsScheduleTableExpiryPoint/OsScheduleTableEventSetting + + + /ArcCore/Os/OsScheduleTable/OsScheduleTableExpiryPoint/OsScheduleTableEventSetting/OsScheduleTableSetEventRef + /suite_02/Os/SchTbl_2 + + + /ArcCore/Os/OsScheduleTable/OsScheduleTableExpiryPoint/OsScheduleTableEventSetting/OsScheduleTableSetEventTaskRef + /suite_02/Os/etask_master + + + + + + + OsScheduleTableAutostart + /ArcCore/Os/OsScheduleTable/OsScheduleTableAutostart + + + /ArcCore/Os/OsScheduleTable/OsScheduleTableAutostart/OsScheduleTableAutostartType + ABSOLUTE + + + /ArcCore/Os/OsScheduleTable/OsScheduleTableAutostart/ArcCoreOsScheduleTableOffset + 1 + + + + Counter1 + /ArcCore/Os/OsCounter + + + /ArcCore/Os/OsCounter/OsCounterMaxAllowedValue + 65535 + + + /ArcCore/Os/OsCounter/OsCounterMinCycle + 0 + + + /ArcCore/Os/OsCounter/OsCounterTicksPerBase + 0 + + + /ArcCore/Os/OsCounter/OsCounterType + OS_TICK + + + + + Counter2 + /ArcCore/Os/OsCounter + + + /ArcCore/Os/OsCounter/OsCounterMaxAllowedValue + 65535 + + + /ArcCore/Os/OsCounter/OsCounterMinCycle + 0 + + + /ArcCore/Os/OsCounter/OsCounterTicksPerBase + 0 + + + /ArcCore/Os/OsCounter/OsCounterType + SOFTWARE + + + + + Event1 + /ArcCore/Os/OsEvent + + + /ArcCore/Os/OsEvent/OsEventMask + 1 + + + + + btask_4 + /ArcCore/Os/OsTask + + + /ArcCore/Os/OsTask/OsTaskActivation + 1 + + + /ArcCore/Os/OsTask/OsTaskPriority + 4 + + + /ArcCore/Os/OsTask/OsTaskProcessType + BASIC + + + /ArcCore/Os/OsTask/ArcCoreOsTaskStackSize + 2048 + + + /ArcCore/Os/OsTask/OsTaskSchedule + FULL + + + + + OsTaskAutostart + /ArcCore/Os/OsTask/OsTaskAutostart + + + + + etask_3 + /ArcCore/Os/OsTask + + + /ArcCore/Os/OsTask/OsTaskActivation + 1 + + + /ArcCore/Os/OsTask/OsTaskPriority + 3 + + + /ArcCore/Os/OsTask/OsTaskProcessType + EXTENDED + + + /ArcCore/Os/OsTask/ArcCoreOsTaskStackSize + 2048 + + + /ArcCore/Os/OsTask/OsTaskSchedule + FULL + + + + + OsTaskAutostart + /ArcCore/Os/OsTask/OsTaskAutostart + + + + + etask_5 + /ArcCore/Os/OsTask + + + /ArcCore/Os/OsTask/OsTaskActivation + 1 + + + /ArcCore/Os/OsTask/OsTaskPriority + 5 + + + /ArcCore/Os/OsTask/OsTaskProcessType + EXTENDED + + + /ArcCore/Os/OsTask/ArcCoreOsTaskStackSize + 2048 + + + /ArcCore/Os/OsTask/OsTaskSchedule + FULL + + + + + OsTaskAutostart + /ArcCore/Os/OsTask/OsTaskAutostart + + + + + etask_master + /ArcCore/Os/OsTask + + + /ArcCore/Os/OsTask/OsTaskActivation + 1 + + + /ArcCore/Os/OsTask/OsTaskPriority + 10 + + + /ArcCore/Os/OsTask/OsTaskProcessType + EXTENDED + + + /ArcCore/Os/OsTask/ArcCoreOsTaskStackSize + 2048 + + + /ArcCore/Os/OsTask/OsTaskSchedule + FULL + + + + + OsTaskAutostart + /ArcCore/Os/OsTask/OsTaskAutostart + + + + + Alarm_1 + /ArcCore/Os/OsEvent + + + /ArcCore/Os/OsEvent/OsEventMask + 1 + + + + + Alarm_2 + /ArcCore/Os/OsEvent + + + /ArcCore/Os/OsEvent/OsEventMask + 2 + + + + + SchTbl_1 + /ArcCore/Os/OsEvent + + + /ArcCore/Os/OsEvent/OsEventMask + 4 + + + + + SchTbl_2 + /ArcCore/Os/OsEvent + + + /ArcCore/Os/OsEvent/OsEventMask + 8 + + + diff --git a/system/kernel/testsystem/suite_02/makefile b/system/kernel/testsystem/suite_02/makefile index 7d906f5a..9449ccd4 100644 --- a/system/kernel/testsystem/suite_02/makefile +++ b/system/kernel/testsystem/suite_02/makefile @@ -21,8 +21,8 @@ MOD_USE+=KERNEL MCU MOD_USE+=T32_TERM #MOD_USE+=PROTECTIONHOOK STARTUPHOOK SHUTDOWNHOOK ERRORHOOK 1 #MOD_USE+=PRETASKHOOK POSTTASKHOOK -CFG+=CONSOLE_T32 -CFG+=CONSOLE_WINIDEA +#CFG+=CONSOLE_T32 +#CFG+=CONSOLE_WINIDEA # TODO: Fix this.... @@ -33,16 +33,17 @@ vpath-y += $(ROOTDIR)/boards/$(BOARDDIR) vpath-y += $(ROOTDIR)/boards/$(BOARDDIR)/config VPATH += $(vpath-y) VPATH += $(ROOTDIR)/$(SUBDIR)/config - +VPATH += $(realpath ../..) # libs needed by us -libitem-y += $(ROOTDIR)/libs/libkernel_$(ARCH_MCU).a +#libitem-y += $(ROOTDIR)/libs/libkernel_$(ARCH_MCU).a #linkfile ldcmdfile-y = $(ROOTDIR)/$(ARCH_PATH-y)/scripts/linkscript_gcc.ldf #ldcmdfile-y = $(ROOTDIR)/$(ARCH_PATH-y)/scripts/linkscript_gcc.ldf inc-y += .. +inc-y += ../.. inc-y += $(ROOTDIR)/system/kernel/$(objdir) inc-y += $(ROOTDIR)/system/kernel/include inc-y += $(ROOTDIR)/$(ARCH_PATH-y) diff --git a/system/kernel/testsystem/suite_02/test_master.c b/system/kernel/testsystem/suite_02/test_master.c new file mode 100644 index 00000000..cb74fa5e --- /dev/null +++ b/system/kernel/testsystem/suite_02/test_master.c @@ -0,0 +1,369 @@ +/* -------------------------------- Arctic Core ------------------------------ + * Arctic Core - the open source AUTOSAR platform http://arccore.com + * + * Copyright (C) 2009 ArcCore AB + * + * This source code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 as published by the + * Free Software Foundation; See . + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * for more details. + * -------------------------------- Arctic Core ------------------------------*/ + +/* Tests + * Autostart bananza.. + * 1. Autostart of tasks + * 2. Autostart of alarms + * 3. Autostart of scheduletables. + */ + + + + + +#include +#include "Os.h" +#include "os_test.h" +#include "Mcu.h" +#if defined(USE_GPT) +#include "Gpt.h" +#endif + + +//#define USE_LDEBUG_PRINTF +#include "debug.h" +#include "arc.h" +#include "test_framework.h" + + +#define ERROR_LOG_SIZE 1 + +typedef struct ErrorEntry { + StatusType error; + OsErrorType info; + TaskType taskId; + OsServiceIdType serviceId; +} ErrorEntryType; + + +typedef struct ErrorLog { + int index; + ErrorEntryType log[ERROR_LOG_SIZE]; +} ErrorLogType; + +ErrorLogType ErrorLog; + +ErrorEntryType *errorLogGetEntry( int backlog ) { + + + int index = ErrorLog.index - backlog; + + if( index < 0 ) { + index = ERROR_LOG_SIZE + index; + } + return &ErrorLog.log[index]; +} + + +static _Bool started[OS_TASK_CNT]; + +static TaskType prioList[OS_TASK_CNT] = { + TASK_ID_etask_master, + TASK_ID_etask_5, + TASK_ID_btask_4, + TASK_ID_etask_3, + TASK_ID_btask_2, + TASK_ID_OsIdle }; + +static void setStarted( void ) { + TaskType taskId; + GetTaskID(&taskId); + for(int i=0;ierror ); + if(param1 != TEST_VALUE_NC ) { + TEST_ASSERT(param1 == entry->info.param1 ); + } + if(param2 != TEST_VALUE_NC ) { + TEST_ASSERT(param2 == entry->info.param2 ); + } + if(param2 != TEST_VALUE_NC ) { + TEST_ASSERT(param3 == entry->info.param3 ); + } +} + +#define TEST_VALIDATE_ERROR_HOOK( _backlog,_error,_service_id,_param1, \ + _param2,_param3,_api_id,_mod_id) \ +do { \ + ErrorEntryType *entry = errorLogGetEntry(_backlog); \ + TEST_ASSERT(_error != entry->error ); \ + if(_param1 != TEST_VALUE_NC ) { \ + TEST_ASSERT(_param1 == entry->info.param1 ); \ + } \ + if(_param2 != TEST_VALUE_NC ) { \ + TEST_ASSERT(_param2 == entry->info.param2 ); \ + } \ + if(_param2 != TEST_VALUE_NC ) { \ + TEST_ASSERT(_param3 == entry->info.param3 ); \ + } \ +} while(0) + +/* + * Master test process, everything is controlled from here. + */ +void etask_master( void ) { + StatusType rv; + uint32_t mask; + TEST_INIT(); + + TEST_START("Autostart, priority tasks",test_nr); + setStarted(); + TEST_ASSERT(checkStarted()); + WaitEvent(EVENT_MASK_Event1); + ClearEvent(EVENT_MASK_Event1); + + TEST_NEXT("Autostart, Alarms and Scheduletables",++test_nr); + + + /* Autostart + * SetRelAlarm Increment: Must != 0 + * SetAbsAlarm No limit + * StartScheduleTableAbs + * .. + * ... + * + */ + + + rv = IncrementCounter(COUNTER_ID_Counter2); + +#if 0 + validateErrorHook( 0, /* backlog */ + E_OS_LIMIT, /* error */ + OSServiceId_ActivateTask, /* Service Id */ + COUNTER_ID_Counter2, /* param1 */ + TEST_VALUE_NC, /* param2 */ + TEST_VALUE_NC, /* param3 */ + TEST_VALUE_NC, /* API id */ + TEST_VALUE_NC ); /* Module id */ +#endif + + validateErrorHook( 0,0,0,0, /* backlog */ + TEST_VALUE_NC, /* param2 */ + TEST_VALUE_NC, /* param3 */ + TEST_VALUE_NC, /* API id */ + TEST_VALUE_NC ); /* Module id */ + + mask = EVENT_MASK_Alarm_1 | EVENT_MASK_Alarm_2 | EVENT_MASK_SchTbl_1 | EVENT_MASK_SchTbl_2; + WaitEvent( mask ); + + TaskType currTask; + EventMaskType evMask; + + GetTaskID(&currTask); + GetEvent(currTask,&evMask); + TEST_ASSERT( evMask == mask); + + testExit(0); +} + +//-------------------------------------------------------------------- + +void etask_3( void ) +{ + setStarted(); + TEST_ASSERT(checkStarted()); + TerminateTask(); +} + +void etask_5( void ) +{ + setStarted(); + TEST_ASSERT(checkStarted()); + TerminateTask(); +} + + +//-------------------------------------------------------------------- + +void btask_2( void ) { + setStarted(); + TEST_ASSERT(checkStarted()); + TerminateTask(); +} + +void btask_4( void ) { + setStarted(); + TEST_ASSERT(checkStarted()); + TerminateTask(); +} + +void OsIdle(void ) { + setStarted(); + TEST_ASSERT(checkStarted()); + SetEvent(TASK_ID_etask_master, EVENT_MASK_Event1); + for(;;); +} + + +/* Global hooks */ +ProtectionReturnType ProtectionHook( StatusType FatalError ) { + printf("## ProtectionHook\n"); + return PRO_KILLAPPL; +} + +void StartupHook( void ) { +// LDEBUG_PRINTF("## StartupHook\n"); + +#ifdef USE_MCU + uint32_t sys_freq = McuE_GetSystemClock(); + (void)sys_freq; + LDEBUG_PRINTF("Sys clock %d Hz\n",sys_freq); +#endif +} + +void ShutdownHook( StatusType Error ) { + LDEBUG_PRINTF("## ShutdownHook\n"); + const char *err; + err = Arc_StatusToString(Error); + while(1) { + err = err; + } +} + + +void ErrorHook( StatusType error ) { + + TaskType task; + ErrorEntryType *errEntry; + + GetTaskID(&task); + + OsServiceIdType service = OSErrorGetServiceId(); + + /* Grab the arguments to the functions + * This is the standard way, see 11.2 in OSEK spec + */ +#if 0 + switch(service) { + case OSServiceId_SetRelAlarm: + { + // Read the arguments to the faulty functions... + AlarmType alarm_id = OSError_SetRelAlarm_AlarmId; + TickType increment = OSError_SetRelAlarm_Increment; + TickType cycle = OSError_SetRelAlarm_Cycle; + (void)alarm_id; + (void)increment; + (void)cycle; + + // ... Handle this some way. + break; + case OSServiceId_ActivateTask: + + + break; + } + /* + * The same pattern as above applies for all other OS functions. + * See Os.h for names and definitions. + */ + + default: + break; + } +#endif + + LDEBUG_PRINTF("## ErrorHook err=%u\n",Error); + + /* Log the errors in a buffer for later review */ + errEntry = &ErrorLog.log[ErrorLog.index]; + + errEntry->info.param1 = os_error.param1; + errEntry->info.param2 = os_error.param2; + errEntry->info.param3 = os_error.param3; + errEntry->info.serviceId = service; + errEntry->taskId = task; + errEntry->error = error; + ErrorLog.index = (ErrorLog.index + 1) % ERROR_LOG_SIZE ; +} + +#if 0 +void ErrorHook( StatusType Error ) { + + LDEBUG_PRINTF("## ErrorHook err=%d\n",Error); + const char *err; + err = Arc_StatusToString(Error); +// while(1); +} +#endif + +void PreTaskHook( void ) { + TaskType task; + GetTaskID(&task); + if( task > 10 ) { + while(1); + } + LDEBUG_PRINTF("## PreTaskHook, taskid=%d\n",task); +} + +void PostTaskHook( void ) { + TaskType task; + GetTaskID(&task); + if( task > 10 ) { + while(1); + } + + LDEBUG_PRINTF("## PostTaskHook, taskid=%d\n",task); +#if 0 + { + StackInfoType si; + Os_Arc_GetStackInfo(task,&si); +// LDEBUG_PRINTF("Stack usage %d%% (this=%08x, top=%08x, size=%08x,usage=%08x )\n",OS_STACK_USAGE(&si),si.curr, si.top,si.size,si.usage); + } +#endif +} + diff --git a/system/kernel/testsystem/test_03_alarm.c b/system/kernel/testsystem/test_03_alarm.c index 7499821e..b7c0dce8 100644 --- a/system/kernel/testsystem/test_03_alarm.c +++ b/system/kernel/testsystem/test_03_alarm.c @@ -368,7 +368,7 @@ void etask_sup_m_03(void) { TerminateTask(); break; default: - assert(0); + TEST_ASSERT(0); } } diff --git a/system/kernel/testsystem/test_framework.c b/system/kernel/testsystem/test_framework.c index 4327970c..ce47697e 100644 --- a/system/kernel/testsystem/test_framework.c +++ b/system/kernel/testsystem/test_framework.c @@ -14,23 +14,35 @@ * -------------------------------- Arctic Core ------------------------------*/ #include -#include +#include #include "Platform_Types.h" +#include "test_framework.h" +#include "Cpu.h" int test_suite = 1; int test_nr = 1; int _test_ok = 0; int _test_failed = 0; + int testCnt = 0; + + + struct test { uint8_t testSuite; uint8_t testNr; uint16_t status; + const char *description; + uint32_t expectedErrMask; }; struct test testTable[50] = { {0} }; + +void testInit( void ) { + +} void test_done( void ) { printf( "\nTest summary\n" @@ -39,16 +51,75 @@ void test_done( void ) { "FAIL : %d\n", _test_ok + _test_failed, _test_ok, _test_failed); } - + +/** + * + * @param text + * @param file + * @param line + * @param function + */ void test_fail( const char *text,char *file, int line, const char *function ) { printf("%02d %02d FAILED, %s , %d, %s\n",test_suite, test_nr, file, line, function); testTable[testCnt].testSuite = test_suite; testTable[testCnt].testNr = test_nr; - testTable[testCnt].status = 0; - testCnt++; - _test_failed++; + testTable[testCnt].status = TEST_FLG_ASSERT; +// testCnt++; +// _test_failed++; } - + + +/** + * Set errors that are expected during the test + * @param errMask + */ +void testSetErrorMask( uint32_t errMask ) { + +} + + +void testValidateHook( void ) { + +} +/** + * Start a test + */ +void testStart( const char *str, int testNr ) { + testTable[testCnt].status = TEST_FLG_RUNNING; + testTable[testCnt].testNr = testNr; + testTable[testCnt].description = str; + printf("%3d %3d %s\n",testCnt,testNr,str); +} + +void testInc( void ) { + testCnt++; +} + +/** + * End a testcase. + */ +void testEnd( void ) { + uint16_t status = testTable[testCnt].status; + + if( status & TEST_FLG_RUNNING ) { + if( status & TEST_FLG_ASSERT ) { + + } else { + /* All is OK */ + testTable[testCnt].status &= TEST_FLG_RUNNING; + testTable[testCnt].status |= TEST_FLG_OK; + } + } else { + printf("testEnd() on a test that is not running\n"); + } + testCnt++; +} + +void testExit( int rv ) { + Irq_Disable(); + exit(rv); +} + void test_ok( void ) { printf("%02d %02d OK\n",test_suite, test_nr); @@ -58,3 +129,4 @@ void test_ok( void ) { testCnt++; _test_ok++; } + diff --git a/system/kernel/testsystem/test_framework.h b/system/kernel/testsystem/test_framework.h index 18e9f5ea..c0a5050f 100644 --- a/system/kernel/testsystem/test_framework.h +++ b/system/kernel/testsystem/test_framework.h @@ -14,12 +14,6 @@ * -------------------------------- Arctic Core ------------------------------*/ - - - - - - /* * test_framework.h * @@ -29,10 +23,22 @@ #ifndef TEST_FRAMEWORK_H_ #define TEST_FRAMEWORK_H_ - + +/* Test flags */ +#define TEST_FLG_RUNNING 1 +#define TEST_FLG_ASSERT (1<<1) +#define TEST_FLG_DONE (1<<2) +#define TEST_FLG_OK (1<<3) + +#define TEST_VALUE_NC (-1) void test_done( void ); -void test_fail( char *text,char *file, int line , const char *function ); +void test_fail( const char *text,char *file, int line, const char *function ); void test_ok( void ); + +void testStart( const char *str, int testNr ); +void testInc( void ); +void testEnd( void ); +void testExit( int rv ); #endif /* TEST_FRAMEWORK_H_ */ diff --git a/tools/t32/load.cmm b/tools/t32/load.cmm index af3a36ef..1b396a27 100644 --- a/tools/t32/load.cmm +++ b/tools/t32/load.cmm @@ -9,7 +9,7 @@ if CPU()=="HC12DG128A" gosub &var ) ELSE - gosub &cmd + gosub &cmd &arg1 @@ -32,10 +32,13 @@ dialog: //------------------------------------------------------------- load: LOCAL &file - dialog.file "&cfg_project_path_g"/*.elf ENTRY &file - - IF OS.FILE(&file) + IF "&file"=="" + ( + dialog.file "&cfg_project_path_g"/*.elf + ENTRY &file + ) + IF OS.FILE("&file") &cfg_loadfile_g="&file" do config save @@ -163,6 +166,8 @@ path: + + diff --git a/tools/t32/term.cmm b/tools/t32/term.cmm index 1764c1ad..749aeaa5 100644 --- a/tools/t32/term.cmm +++ b/tools/t32/term.cmm @@ -1,3 +1,10 @@ +// Manage T32 terminal +// +// args +// 1 - file, if non-empty output is also written to this file. + +LOCAL &file +ENtry &file winclear my_term WinPOS 50% 50% 50% 50% 1. 1. my_term term.size 80. 300. @@ -12,7 +19,8 @@ IF CPUFAMILY()=="ARM" ELSE ( term.view e:address.offset(v.address(t32_outport)) e:0 - term.write e:address.offset(v.address(t32_outport)) hoppsan.log + IF "&file"!="" + term.write e:address.offset(v.address(t32_outport)) "&file" ) enddo @@ -26,3 +34,4 @@ enddo + diff --git a/tools/t32/test.cmm b/tools/t32/test.cmm new file mode 100644 index 00000000..b98f61c0 --- /dev/null +++ b/tools/t32/test.cmm @@ -0,0 +1,64 @@ +//&cmdline="OS.area dir" +//print &cmdline + +screen.always +LOCAL &datafile &file &rfile &data &tmpfile &stop + +&stop="no" +&datafile="va1.txt" +&rfile="test_result.txt" +&tdir="&cfg_project_path_g\system\kernel\testsystem" +os cmd /c dir &tdir/B /A:D> &datafile + +os cmd /c del &rfile + +// Start file at #10 to make space for others to use #1..#9 +OPEN #10 &datafile /read +READ #10 &data +WHILE "&data"!="" +( + &file="&cfg_project_path_g"+"/binaries/system_kernel_testsystem_"+"&data"+".elf" + IF OS.FILE("&file") + ( + &tmpfile=os.tmpfile() + GOSUB testrun &file "hopp.txt" + os cmd /c type hopp.txt >> &rfile + ) + IF "&stop"=="yes" + ( + print "Press any key" + inkey + ) + + READ #10 &data +) + +CLOSE #10 + +type "&rfile" + +enddo + +//------------------------------------- +testrun: + LOCAL &file &term_file + ENTRY &file &term_file + + IF ("&file"=="")||!OS.FILE("&file") + RETURN + + sys.up + do load load &file + do term &term_file + b.s exit + b.s _exit + go + wait !run() + b.d /all + term.close + RETURN + + + + + -- 2.39.2