1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
|
/*
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
*
* <h2>Description</h2>
* This module implements the test sequence for the @ref system subsystem.
*
* <h2>Objective</h2>
* Objective of the test module is to cover 100% of the @ref system
* subsystem code.
*
* <h2>Preconditions</h2>
* None.
*
* <h2>Test Cases</h2>
* - @subpage test_sys_001
* - @subpage test_sys_002
* - @subpage test_sys_003
* .
* @file testsys.c
* @brief System test source file
* @file testsys.h
* @brief System header file
*/
/**
* @page test_sys_001 Critical zones check
*
* <h2>Description</h2>
* 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 Interrupts handling
*
* <h2>Description</h2>
* The interrupts handling API is invoked for coverage.
*/
static void sys2_execute(void) {
chSysSuspend();
chSysDisable();
chSysSuspend();
chSysEnable();
}
ROMCONST struct testcase testsys2 = {
"System, interrupts handling",
NULL,
NULL,
sys2_execute
};
/**
* @page test_sys_003 System integrity check
*
* <h2>Description</h2>
* The chSysIntegrityCheckI() API is invoked in order to asses the state of the
* system data structures.
*/
static void sys3_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 testsys3 = {
"System, integrity",
NULL,
NULL,
sys3_execute
};
/**
* @brief Test sequence for messages.
*/
ROMCONST struct testcase * ROMCONST patternsys[] = {
&testsys1,
&testsys2,
&testsys3,
NULL
};
|