rusEFI
The most advanced open source ECU
Loading...
Searching...
No Matches
Data Structures | Functions | Variables
Test

Data Structures

struct  testcase
 Structure representing a test case. More...
 
union  test_buffers
 

Functions

void test_printn (uint32_t n)
 Prints a decimal unsigned number.
 
void test_print (const char *msgp)
 Prints a line without final end-of-line.
 
void test_println (const char *msgp)
 Prints a line.
 
static void clear_tokens (void)
 
static void print_tokens (void)
 
void test_emit_token (char token)
 Emits a token into the tokens buffer.
 
bool _test_fail (unsigned point)
 
bool _test_assert (unsigned point, bool condition)
 
bool _test_assert_sequence (unsigned point, char *expected)
 
bool _test_assert_time_window (unsigned point, systime_t start, systime_t end)
 
void test_terminate_threads (void)
 Sets a termination request in all the test-spawned threads.
 
void test_wait_threads (void)
 Waits for the completion of all the test-spawned threads.
 
void test_cpu_pulse (unsigned duration)
 CPU pulse.
 
systime_t test_wait_tick (void)
 Delays execution until next system time tick.
 
static void tmr (void *p)
 
void test_start_timer (unsigned ms)
 Starts the test timer.
 
static void execute_test (const struct testcase *tcp)
 
static void print_line (void)
 
msg_t TestThread (void *p)
 Test execution thread function.
 
void ChkIntSources (void)
 

Variables

static ROMCONST struct testcase *ROMCONST * patterns []
 
static bool local_fail
 
static bool global_fail
 
static unsigned failpoint
 
static char tokens_buffer [MAX_TOKENS]
 
static chartokp
 
union test_buffers test
 
thread_t * threads [MAX_THREADS]
 
void *ROMCONST wa [5]
 
static BaseSequentialStream * chp
 
bool test_timer_done
 Set to TRUE when the test timer reaches its deadline.
 
static VirtualTimer vt
 
Thread * threads [MAX_THREADS]
 
union test_buffers test
 
void *ROMCONST wa []
 
bool test_timer_done
 Set to TRUE when the test timer reaches its deadline.
 

Detailed Description

Function Documentation

◆ _test_assert()

bool _test_assert ( unsigned  point,
bool  condition 
)

Definition at line 147 of file test.c.

147 {
148
149 if (!condition)
150 return _test_fail(point);
151 return FALSE;
152}
bool _test_fail(unsigned point)
Definition test.c:139

Referenced by _test_assert_time_window().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ _test_assert_sequence()

bool _test_assert_sequence ( unsigned  point,
char expected 
)

Definition at line 154 of file test.c.

154 {
155 char *cp = tokens_buffer;
156 while (cp < tokp) {
157 if (*cp++ != *expected++)
158 return _test_fail(point);
159 }
160 if (*expected)
161 return _test_fail(point);
162 clear_tokens();
163 return FALSE;
164}
static char tokens_buffer[MAX_TOKENS]
Definition test.c:43
static void clear_tokens(void)
Definition test.c:112
static char * tokp
Definition test.c:44
Here is the call graph for this function:

◆ _test_assert_time_window()

bool _test_assert_time_window ( unsigned  point,
systime_t  start,
systime_t  end 
)

Definition at line 166 of file test.c.

166 {
167
168 return _test_assert(point, chTimeIsWithin(start, end));
169}
bool _test_assert(unsigned point, bool condition)
Definition test.c:147
Here is the call graph for this function:

◆ _test_fail()

bool _test_fail ( unsigned  point)

Definition at line 139 of file test.c.

139 {
140
141 local_fail = TRUE;
142 global_fail = TRUE;
143 failpoint = point;
144 return TRUE;
145}
static bool global_fail
Definition test.c:41
static bool local_fail
Definition test.c:41
static unsigned failpoint
Definition test.c:42

Referenced by _test_assert(), and _test_assert_sequence().

Here is the caller graph for this function:

◆ ChkIntSources()

void ChkIntSources ( void  )

◆ clear_tokens()

static void clear_tokens ( void  )
static

Definition at line 112 of file test.c.

112 {
113
115}

Referenced by _test_assert_sequence(), and execute_test().

Here is the caller graph for this function:

◆ execute_test()

static void execute_test ( const struct testcase tcp)
static

Definition at line 264 of file test.c.

264 {
265 int i;
266
267 /* Initialization */
268 clear_tokens();
269 local_fail = FALSE;
270 for (i = 0; i < MAX_THREADS; i++)
271 threads[i] = NULL;
272
273 if (tcp->setup != NULL)
274 tcp->setup();
275 tcp->execute();
276 if (tcp->teardown != NULL)
277 tcp->teardown();
278
280}
void test_wait_threads(void)
Waits for the completion of all the test-spawned threads.
Definition test.c:189
thread_t * threads[MAX_THREADS]
Definition test.c:55
void(* execute)(void)
Test case execution function.
Definition test.h:62
void(* setup)(void)
Test case preparation function.
Definition test.h:60
void(* teardown)(void)
Test case clean up function.
Definition test.h:61

Referenced by TestThread().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ print_line()

static void print_line ( void  )
static

Definition at line 282 of file test.c.

282 {
283 unsigned i;
284
285 for (i = 0; i < 76; i++)
286 chSequentialStreamPut(chp, '-');
287 chSequentialStreamWrite(chp, (const uint8_t *)"\r\n", 2);
288}
static BaseSequentialStream * chp
Definition test.c:66

Referenced by TestThread().

Here is the caller graph for this function:

◆ print_tokens()

static void print_tokens ( void  )
static

Definition at line 117 of file test.c.

117 {
118 char *cp = tokens_buffer;
119
120 while (cp < tokp)
121 chSequentialStreamPut(chp, *cp++);
122}

Referenced by TestThread().

Here is the caller graph for this function:

◆ test_cpu_pulse()

void test_cpu_pulse ( unsigned  duration)

CPU pulse.

Note
The current implementation is not totally reliable.
Parameters
[in]durationCPU pulse duration in milliseconds

Definition at line 206 of file test.c.

206 {
207 systime_t start, end, now;
208
209 start = chThdSelf()->p_time;
210 end = start + TIME_MS2I(duration);
211 do {
212 now = chThdSelf()->p_time;
213#if defined(SIMULATOR)
215#endif
216 }
217 while (end > start ? (now >= start) && (now < end) :
218 (now >= start) || (now < end));
219}
void ChkIntSources(void)
Here is the call graph for this function:

◆ test_emit_token()

void test_emit_token ( char  token)

Emits a token into the tokens buffer.

Parameters
[in]tokenthe token as a char

Definition at line 129 of file test.c.

129 {
130
131 chSysLock();
132 *tokp++ = token;
133 chSysUnlock();
134}

◆ test_print()

void test_print ( const char msgp)

Prints a line without final end-of-line.

Parameters
[in]msgpthe message

Definition at line 92 of file test.c.

92 {
93
94 while (*msgp)
95 chSequentialStreamPut(chp, *msgp++);
96}

Referenced by bmk10_execute(), bmk11_execute(), bmk12_execute(), bmk13_execute(), bmk1_execute(), bmk2_execute(), bmk3_execute(), bmk4_execute(), bmk5_execute(), bmk6_execute(), bmk7_execute(), bmk8_execute(), bmk9_execute(), test_println(), and TestThread().

Here is the caller graph for this function:

◆ test_println()

void test_println ( const char msgp)

Prints a line.

Parameters
[in]msgpthe message

Definition at line 103 of file test.c.

103 {
104
105 test_print(msgp);
106 chSequentialStreamWrite(chp, (const uint8_t *)"\r\n", 2);
107}
void test_print(const char *msgp)
Prints a line without final end-of-line.
Definition test.c:92

Referenced by bmk10_execute(), bmk11_execute(), bmk12_execute(), bmk13_execute(), bmk1_execute(), bmk2_execute(), bmk3_execute(), bmk4_execute(), bmk5_execute(), bmk6_execute(), bmk7_execute(), bmk8_execute(), bmk9_execute(), and TestThread().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ test_printn()

void test_printn ( uint32_t  n)

Prints a decimal unsigned number.

Parameters
[in]nthe number to be printed

Definition at line 73 of file test.c.

73 {
74 char buf[16], *p;
75
76 if (!n)
77 chSequentialStreamPut(chp, '0');
78 else {
79 p = buf;
80 while (n)
81 *p++ = (n % 10) + '0', n /= 10;
82 while (p > buf)
83 chSequentialStreamPut(chp, *--p);
84 }
85}

Referenced by bmk10_execute(), bmk11_execute(), bmk12_execute(), bmk13_execute(), bmk1_execute(), bmk2_execute(), bmk3_execute(), bmk4_execute(), bmk5_execute(), bmk6_execute(), bmk7_execute(), bmk8_execute(), bmk9_execute(), and TestThread().

Here is the caller graph for this function:

◆ test_start_timer()

void test_start_timer ( unsigned  ms)

Starts the test timer.

Parameters
[in]mstime in milliseconds

Definition at line 254 of file test.c.

254 {
255
256 systime_t duration = TIME_MS2I(ms);
257 test_timer_done = FALSE;
258 chVTSet(&vt, duration, tmr, NULL);
259}
static VirtualTimer vt
Definition test.c:242
static void tmr(void *p)
Definition test.c:243
bool test_timer_done
Set to TRUE when the test timer reaches its deadline.
Definition test.c:240

Referenced by __attribute__(), bmk10_execute(), bmk11_execute(), bmk12_execute(), bmk4_execute(), bmk5_execute(), bmk6_execute(), bmk7_execute(), and bmk9_execute().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ test_terminate_threads()

void test_terminate_threads ( void  )

Sets a termination request in all the test-spawned threads.

Definition at line 178 of file test.c.

178 {
179 int i;
180
181 for (i = 0; i < MAX_THREADS; i++)
182 if (threads[i])
183 chThdTerminate(threads[i]);
184}

Referenced by bmk7_execute(), and bmk8_execute().

Here is the caller graph for this function:

◆ test_wait_threads()

void test_wait_threads ( void  )

Waits for the completion of all the test-spawned threads.

Definition at line 189 of file test.c.

189 {
190 int i;
191
192 for (i = 0; i < MAX_THREADS; i++)
193 if (threads[i] != NULL) {
194 chThdWait(threads[i]);
195 threads[i] = NULL;
196 }
197}

Referenced by bmk1_execute(), bmk2_execute(), bmk3_execute(), bmk4_execute(), bmk7_execute(), bmk8_execute(), and execute_test().

Here is the caller graph for this function:

◆ test_wait_tick()

systime_t test_wait_tick ( void  )

Delays execution until next system time tick.

Returns
The system time.

Definition at line 227 of file test.c.

227 {
228
229 chThdSleep(1);
230 return chTimeNow();
231}

Referenced by __attribute__(), bmk10_execute(), bmk11_execute(), bmk12_execute(), bmk4_execute(), bmk5_execute(), bmk6_execute(), bmk7_execute(), bmk8_execute(), and bmk9_execute().

Here is the caller graph for this function:

◆ TestThread()

msg_t TestThread ( void *  p)

Test execution thread function.

Parameters
[in]ppointer to a BaseChannel object for test output
Returns
A failure boolean value.

Definition at line 296 of file test.c.

296 {
297 int i, j;
298
299 chp = p;
300 test_println("");
301 test_println("*** ChibiOS/RT test suite");
302 test_println("***");
303 test_print("*** Kernel: ");
304 test_println(CH_KERNEL_VERSION);
305 test_print("*** Compiled: ");
306 test_println(__DATE__ " - " __TIME__);
307#ifdef CH_COMPILER_NAME
308 test_print("*** Compiler: ");
309 test_println(CH_COMPILER_NAME);
310#endif
311 test_print("*** Architecture: ");
312 test_println(CH_ARCHITECTURE_NAME);
313#ifdef CH_CORE_VARIANT_NAME
314 test_print("*** Core Variant: ");
315 test_println(CH_CORE_VARIANT_NAME);
316#endif
317#ifdef CH_PORT_INFO
318 test_print("*** Port Info: ");
319 test_println(CH_PORT_INFO);
320#endif
321#ifdef PLATFORM_NAME
322 test_print("*** Platform: ");
323 test_println(PLATFORM_NAME);
324#endif
325#ifdef BOARD_NAME
326 test_print("*** Test Board: ");
327 test_println(BOARD_NAME);
328#endif
329 test_println("");
330
331 global_fail = FALSE;
332 i = 0;
333 while (patterns[i]) {
334 j = 0;
335 while (patterns[i][j]) {
336 print_line();
337 test_print("--- Test Case ");
338 test_printn(i + 1);
339 test_print(".");
340 test_printn(j + 1);
341 test_print(" (");
342 test_print(patterns[i][j]->name);
343 test_println(")");
344#if DELAY_BETWEEN_TESTS > 0
345 chThdSleepMilliseconds(DELAY_BETWEEN_TESTS);
346#endif
347 execute_test(patterns[i][j]);
348 if (local_fail) {
349 test_print("--- Result: FAILURE (#");
351 test_print(" [");
352 print_tokens();
353 test_println("])");
354 }
355 else
356 test_println("--- Result: SUCCESS");
357 j++;
358 }
359 i++;
360 }
361 print_line();
362 test_println("");
363 test_print("Final result: ");
364 if (global_fail)
365 test_println("FAILURE");
366 else
367 test_println("SUCCESS");
368
369 return (msg_t)global_fail;
370}
static void execute_test(const struct testcase *tcp)
Definition test.c:264
void test_printn(uint32_t n)
Prints a decimal unsigned number.
Definition test.c:73
static void print_line(void)
Definition test.c:282
static void print_tokens(void)
Definition test.c:117
static ROMCONST struct testcase *ROMCONST * patterns[]
Definition test.c:36
void test_println(const char *msgp)
Prints a line.
Definition test.c:103

Referenced by runChibioTest().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ tmr()

static void tmr ( void *  p)
static

Definition at line 243 of file test.c.

243 {
244 (void)p;
245
246 test_timer_done = TRUE;
247}

Referenced by test_start_timer().

Here is the caller graph for this function:

Variable Documentation

◆ chp

BaseSequentialStream* chp
static

Definition at line 66 of file test.c.

Referenced by print_line(), print_tokens(), test_print(), test_println(), test_printn(), and TestThread().

◆ failpoint

unsigned failpoint
static

Definition at line 42 of file test.c.

Referenced by _test_fail(), and TestThread().

◆ global_fail

bool global_fail
static

Definition at line 41 of file test.c.

Referenced by _test_fail(), and TestThread().

◆ local_fail

bool local_fail
static

Definition at line 41 of file test.c.

Referenced by _test_fail(), execute_test(), and TestThread().

◆ patterns

ROMCONST struct testcase* ROMCONST* patterns[]
static
Initial value:
= {
NULL
}
ROMCONST struct testcase *ROMCONST patternbmk[]
Test sequence for benchmarks.
Definition testbmk.c:700

Definition at line 36 of file test.c.

36 {
38 NULL
39};

Referenced by TestThread().

◆ test [1/2]

union test_buffers test

Definition at line 50 of file test.c.

Referenced by isBigEndian(), isPhaseInRange(), and Hysteresis::test().

◆ test [2/2]

union test_buffers test
extern

Definition at line 50 of file test.c.

Referenced by isBigEndian(), isPhaseInRange(), and Hysteresis::test().

◆ test_timer_done [1/2]

bool test_timer_done

Set to TRUE when the test timer reaches its deadline.

Definition at line 240 of file test.c.

Referenced by __attribute__(), bmk10_execute(), bmk11_execute(), bmk12_execute(), bmk4_execute(), bmk5_execute(), bmk6_execute(), bmk7_execute(), bmk9_execute(), test_start_timer(), and tmr().

◆ test_timer_done [2/2]

bool test_timer_done
extern

Set to TRUE when the test timer reaches its deadline.

Definition at line 240 of file test.c.

Referenced by __attribute__(), bmk10_execute(), bmk11_execute(), bmk12_execute(), bmk4_execute(), bmk5_execute(), bmk6_execute(), bmk7_execute(), bmk9_execute(), test_start_timer(), and tmr().

◆ threads [1/2]

thread_t* threads[MAX_THREADS]

◆ threads [2/2]

Thread* threads[MAX_THREADS]
extern

◆ tokens_buffer

char tokens_buffer[MAX_TOKENS]
static

Definition at line 43 of file test.c.

Referenced by _test_assert_sequence(), clear_tokens(), and print_tokens().

◆ tokp

char* tokp
static

Definition at line 44 of file test.c.

Referenced by _test_assert_sequence(), clear_tokens(), print_tokens(), and test_emit_token().

◆ vt

VirtualTimer vt
static

Definition at line 242 of file test.c.

Referenced by test_start_timer().

◆ wa [1/2]

void* ROMCONST wa[5]
Initial value:
= {test.wa.T0, test.wa.T1, test.wa.T2,
test.wa.T3, test.wa.T4}
union test_buffers test
Definition test.c:50
struct test_buffers::@28 wa

Definition at line 60 of file test.c.

60 {test.wa.T0, test.wa.T1, test.wa.T2,
61 test.wa.T3, test.wa.T4};

Referenced by bmk1_execute(), bmk2_execute(), bmk3_execute(), bmk4_execute(), bmk5_execute(), bmk6_execute(), bmk7_execute(), and bmk8_execute().

◆ wa [2/2]

void* ROMCONST wa[]
extern

Definition at line 60 of file test.c.

60 {test.wa.T0, test.wa.T1, test.wa.T2,
61 test.wa.T3, test.wa.T4};

Referenced by bmk1_execute(), bmk2_execute(), bmk3_execute(), bmk4_execute(), bmk5_execute(), bmk6_execute(), bmk7_execute(), and bmk8_execute().