From f1080803f75b3e3c30b1f135c0b5a32317e86dd8 Mon Sep 17 00:00:00 2001 From: Giovanni Di Sirio Date: Tue, 7 Apr 2015 10:37:52 +0000 Subject: Test coverage improvements. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@7869 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- test/rt/test.c | 2 + test/rt/test.mk | 1 + test/rt/testsys.c | 153 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ test/rt/testsys.h | 22 ++++++++ 4 files changed, 178 insertions(+) create mode 100644 test/rt/testsys.c create mode 100644 test/rt/testsys.h (limited to 'test/rt') diff --git a/test/rt/test.c b/test/rt/test.c index 5dc791a0f..d21dd2ffb 100644 --- a/test/rt/test.c +++ b/test/rt/test.c @@ -36,6 +36,7 @@ #include "testpools.h" #include "testdyn.h" #include "testqueues.h" +#include "testsys.h" #include "testbmk.h" /* @@ -52,6 +53,7 @@ static ROMCONST struct testcase * ROMCONST *patterns[] = { patternpools, patterndyn, patternqueues, + patternsys, patternbmk, NULL }; diff --git a/test/rt/test.mk b/test/rt/test.mk index d2dcf355d..03de3c89a 100644 --- a/test/rt/test.mk +++ b/test/rt/test.mk @@ -10,6 +10,7 @@ TESTSRC = ${CHIBIOS}/test/rt/test.c \ ${CHIBIOS}/test/rt/testpools.c \ ${CHIBIOS}/test/rt/testdyn.c \ ${CHIBIOS}/test/rt/testqueues.c \ + ${CHIBIOS}/test/rt/testsys.c \ ${CHIBIOS}/test/rt/testbmk.c # Required include directories diff --git a/test/rt/testsys.c b/test/rt/testsys.c new file mode 100644 index 000000000..c5a9d70e1 --- /dev/null +++ b/test/rt/testsys.c @@ -0,0 +1,153 @@ +/* + ChibiOS - Copyright (C) 2006..2015 Giovanni Di Sirio + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + +#include "ch.h" +#include "test.h" + +/** + * @page test_sys System test + * + * File: @ref testsys.c + * + *

Description

+ * This module implements the test sequence for the @ref system subsystem. + * + *

Objective

+ * Objective of the test module is to cover 100% of the @ref system + * subsystem code. + * + *

Preconditions

+ * None. + * + *

Test Cases

+ * - @subpage test_sys_001 + * - @subpage test_sys_002 + * . + * @file testsys.c + * @brief System test source file + * @file testsys.h + * @brief System header file + */ + +/** + * @page test_sys_001 Critical zones check + * + *

Description

+ * The critical zones API is invoked for coverage. + */ + +static void vtcb(void *p) { + syssts_t sts; + + (void)p; + + /* Testing normal case.*/ + chSysLockFromISR(); + chSysUnlockFromISR(); + + /* Reentrant case.*/ + chSysLockFromISR(); + sts = chSysGetStatusAndLockX(); + chSysRestoreStatusX(sts); + chSysUnlockFromISR(); +} + +static void sys1_execute(void) { + syssts_t sts; + virtual_timer_t vt; + + /* Testing normal case.*/ + sts = chSysGetStatusAndLockX(); + chSysRestoreStatusX(sts); + + /* Reentrant case.*/ + chSysLock(); + sts = chSysGetStatusAndLockX(); + chSysRestoreStatusX(sts); + chSysUnlock(); + + /* Unconditional lock.*/ + chSysUnconditionalLock(); + chSysUnconditionalLock(); + chSysUnlock(); + + /* Unconditional unlock.*/ + chSysLock(); + chSysUnconditionalUnlock(); + chSysUnconditionalUnlock(); + + /*/Testing from ISR context using a virtual timer.*/ + chVTObjectInit(&vt); + chVTSet(&vt, 1, vtcb, NULL); + chThdSleep(10); + + test_assert(1, chVTIsArmed(&vt) == false, "timer still armed"); +} + +ROMCONST struct testcase testsys1 = { + "System, critical zones", + NULL, + NULL, + sys1_execute +}; + +/** + * @page test_sys_002 System integrity check + * + *

Description

+ * The chSysIntegrityCheckI() API is invoked in order to asses the state of the + * system data structures. + */ + +static void sys2_execute(void) { + bool result; + + chSysLock(); + result = chSysIntegrityCheckI(CH_INTEGRITY_RLIST); + chSysUnlock(); + test_assert(1, result == false, "ready list check failed"); + + chSysLock(); + result = chSysIntegrityCheckI(CH_INTEGRITY_VTLIST); + chSysUnlock(); + test_assert(2, result == false, "virtual timers list check failed"); + + chSysLock(); + result = chSysIntegrityCheckI(CH_INTEGRITY_REGISTRY); + chSysUnlock(); + test_assert(3, result == false, "registry list check failed"); + + chSysLock(); + result = chSysIntegrityCheckI(CH_INTEGRITY_PORT); + chSysUnlock(); + test_assert(4, result == false, "port layer check failed"); +} + +ROMCONST struct testcase testsys2 = { + "System, integrity", + NULL, + NULL, + sys2_execute +}; + +/** + * @brief Test sequence for messages. + */ +ROMCONST struct testcase * ROMCONST patternsys[] = { + &testsys1, + &testsys2, + NULL +}; diff --git a/test/rt/testsys.h b/test/rt/testsys.h new file mode 100644 index 000000000..562bf9745 --- /dev/null +++ b/test/rt/testsys.h @@ -0,0 +1,22 @@ +/* + ChibiOS - Copyright (C) 2006..2015 Giovanni Di Sirio + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + +#ifndef _TESTSYS_H_ +#define _TESTSYS_H_ + +extern ROMCONST struct testcase * ROMCONST patternsys[]; + +#endif /* _TESTSYS_H_ */ -- cgit v1.2.3