source: rtems-docs/eng/test-framework.rst @ b6c61e3

5
Last change on this file since b6c61e3 was b6c61e3, checked in by Sebastian Huber <sebastian.huber@…>, on 02/09/20 at 10:19:24

eng: Mention test framework buffer configuration

Update #3199.

  • Property mode set to 100644
File size: 69.1 KB
Line 
1.. SPDX-License-Identifier: CC-BY-SA-4.0
2
3.. Copyright (C) 2018, 2019 embedded brains GmbH
4.. Copyright (C) 2018, 2019 Sebastian Huber
5
6Software Test Framework
7***********************
8
9.. _RTEMSTestFramework:
10
11The RTEMS Test Framework
12========================
13
14The `RTEMS Test Framework` helps you to write test suites.  It has the following
15features:
16
17* Implemented in standard C11
18
19* Runs on at least FreeBSD, MSYS2, Linux and RTEMS
20
21* Test runner and test case code can be in separate translation units
22
23* Test cases are automatically registered at link-time
24
25* Test cases may have a test fixture
26
27* Test checks for various standard types
28
29* Supports test case planning
30
31* Test case scoped dynamic memory
32
33* Test case destructors
34
35* Test case resource accounting to show that no resources are leaked
36  during the test case execution
37
38* Supports early test case exit, e.g. in case a malloc() fails
39
40* Individual test case and overall test suite duration is reported
41
42* Procedures for code runtime measurements in RTEMS
43
44* Easy to parse test report to generate for example human readable test reports
45
46* Low overhead time measurement of short time sequences (using cycle counter
47  hardware if a available)
48
49* Configurable time service provider for a monotonic clock
50
51* Low global memory overhead for test cases and test checks
52
53* Supports multi-threaded execution and interrupts in test cases
54
55* A simple (polled) put character function is sufficient to produce the test report
56
57* Only text, global data and a stack pointer must be set up to run a test suite
58
59* No dynamic memory is used by the framework itself
60
61* No memory is aggregated throughout the test case execution
62
63Nomenclature
64------------
65
66A `test suite` is a collection of test cases.  A `test case` consists of
67individual test actions and checks.  A `test check` determines if the outcome
68of a test action meets its expectation.  A `test action` is a program sequence
69with an observable outcome, for example a function invocation with a return
70status.  If the test action outcome is all right, then the test check passes,
71otherwise the test check fails.  The test check failures of a test case are
72summed up.  A test case passes, if the failure count of this test case is zero,
73otherwise the test case fails.  The test suite passes if all test cases pass,
74otherwise it fails.
75
76Test Cases
77----------
78
79You can write a test case with the `T_TEST_CASE()` macro followed by a function
80body:
81
82.. code-block:: c
83
84   T_TEST_CASE(name)
85   {
86      /* Your test case code */
87   }
88
89The test case `name` must be a valid C designator.  The test case names must be
90unique within the test suite.  Just link modules with test cases to the test
91runner to form a test suite.  The test cases are automatically registered via
92static constructors.
93
94.. code-block:: c
95    :caption: Test Case Example
96
97    #include <t.h>
98
99    static int add(int a, int b)
100    {
101        return a + b;
102    }
103
104    T_TEST_CASE(a_test_case)
105    {
106        int actual_value;
107
108        actual_value = add(1, 1);
109        T_eq_int(actual_value, 2);
110        T_true(false, "a test failure message");
111    }
112
113.. code-block:: none
114    :caption: Test Case Report
115
116    B:a_test_case
117    P:0:8:UI1:test-simple.c:13
118    F:1:8:UI1:test-simple.c:14:a test failure message
119    E:a_test_case:N:2:F:1:D:0.001657
120
121The `B` line indicates the begin of test case `a_test_case`.  The `P` line
122shows that the test check in file `test-simple.c` at line 13 executed by task
123`UI1` on processor 0 as the test step 0 passed.  The invocation of `add()` in
124line 12 is the test action of test step 0.  The `F` lines shows that the test
125check in file `test-simple.c` at line 14 executed by task `UI1` on processor 0
126as the test step 1 failed with a message of `"a test failure message"`.  The
127`E` line indicates the end of test case `a_test_case` resulting in a total of
128two test steps (`N`) and one test failure (`F`).  The test case execution
129duration (`D`) was 0.001657 seconds.  For test report details see:
130:ref:`Test Reporting <RTEMSTestFrameworkTestReporting>`.
131
132Test Fixture
133------------
134
135You can write a test case with a test fixture with the `T_TEST_CASE_FIXTURE()`
136macro followed by a function body:
137
138.. code-block:: c
139
140   T_TEST_CASE_FIXTURE(name, fixture)
141   {
142      /* Your test case code */
143   }
144
145The test case `name` must be a valid C designator.  The test case names must be
146unique within the test suite.  The `fixture` must point to a statically
147initialized read-only object of type `T_fixture`.  The test fixture
148provides methods to setup, stop and tear down a test case.  A context is passed
149to the methods.  The initial context is defined by the read-only fixture
150object.  The context can be obtained by the `T_fixture_context()`
151function.  It can be set within the scope of one test case by the
152`T_set_fixture_context()` function.  This can be used for example to
153dynamically allocate a test environment in the setup method.
154
155.. code-block:: c
156    :caption: Test Fixture Example
157
158    #include <t.h>
159
160    static int initial_value = 3;
161
162    static int counter;
163
164    static void
165    setup(void *ctx)
166    {
167        int *c;
168
169        T_log(T_QUIET, "setup begin");
170        T_eq_ptr(ctx, &initial_value);
171        T_eq_ptr(ctx, T_fixture_context());
172        c = ctx;
173        counter = *c;
174        T_set_fixture_context(&counter);
175        T_eq_ptr(&counter, T_fixture_context());
176        T_log(T_QUIET, "setup end");
177    }
178
179    static void
180    stop(void *ctx)
181    {
182        int *c;
183
184        T_log(T_QUIET, "stop begin");
185        T_eq_ptr(ctx, &counter);
186        c = ctx;
187        ++(*c);
188        T_log(T_QUIET, "stop end");
189    }
190
191    static void
192    teardown(void *ctx)
193    {
194        int *c;
195
196        T_log(T_QUIET, "teardown begin");
197        T_eq_ptr(ctx, &counter);
198        c = ctx;
199        T_eq_int(*c, 4);
200        T_log(T_QUIET, "teardown end");
201    }
202
203    static const T_fixture fixture = {
204        .setup = setup,
205        .stop = stop,
206        .teardown = teardown,
207        .initial_context = &initial_value
208    };
209
210    T_TEST_CASE_FIXTURE(fixture, &fixture)
211    {
212        T_assert_true(true, "all right");
213        T_assert_true(false, "test fails and we stop the test case");
214        T_log(T_QUIET, "not reached");
215    }
216
217.. code-block:: none
218    :caption: Test Fixture Report
219
220    B:fixture
221    L:setup begin
222    P:0:0:UI1:test-fixture.c:13
223    P:1:0:UI1:test-fixture.c:14
224    P:2:0:UI1:test-fixture.c:18
225    L:setup end
226    P:3:0:UI1:test-fixture.c:55
227    F:4:0:UI1:test-fixture.c:56:test fails and we stop the test case
228    L:stop begin
229    P:5:0:UI1:test-fixture.c:28
230    L:stop end
231    L:teardown begin
232    P:6:0:UI1:test-fixture.c:40
233    P:7:0:UI1:test-fixture.c:42
234    L:teardown end
235    E:fixture:N:8:F:1
236
237Test Case Planning
238------------------
239
240Each non-quiet test check fetches and increments the test step counter
241atomically.  For each test case execution the planned steps can be specified
242with the `T_plan()` function.
243
244.. code-block:: c
245
246    void T_plan(unsigned int planned_steps);
247
248This function must be invoked at most once in each test case execution.  If the
249planned test steps are set with this function, then the final test steps after
250the test case execution must be equal to the planned steps, otherwise the test
251case fails.
252
253Use the `T_step_*(step, ...)` test check variants to ensure that the test case
254execution follows exactly the planned steps.
255
256.. code-block:: c
257    :caption: Test Planning Example
258
259    #include <t.h>
260
261    T_TEST_CASE(wrong_step)
262    {
263        T_plan(2);
264        T_step_true(0, true, "all right");
265        T_step_true(2, true, "wrong step");
266    }
267
268    T_TEST_CASE(plan_ok)
269    {
270        T_plan(1);
271        T_step_true(0, true, "all right");
272    }
273
274    T_TEST_CASE(plan_failed)
275    {
276        T_plan(2);
277        T_step_true(0, true, "not enough steps");
278        T_quiet_true(true, "quiet test do not count");
279    }
280
281    T_TEST_CASE(double_plan)
282    {
283        T_plan(99);
284        T_plan(2);
285    }
286
287    T_TEST_CASE(steps)
288    {
289        T_step(0, "a");
290        T_plan(3);
291        T_step(1, "b");
292        T_step(2, "c");
293    }
294
295.. code-block:: none
296    :caption: Test Planning Report
297
298    B:wrong_step
299    P:0:0:UI1:test-plan.c:6
300    F:1:0:UI1:test-plan.c:7:planned step (2)
301    E:wrong_step:N:2:F:1
302    B:plan_ok
303    P:0:0:UI1:test-plan.c:13
304    E:plan_ok:N:1:F:0
305    B:plan_failed
306    P:0:0:UI1:test-plan.c:19
307    F:*:0:UI1:*:*:actual steps (1), planned steps (2)
308    E:plan_failed:N:1:F:1
309    B:double_plan
310    F:*:0:UI1:*:*:planned steps (99) already set
311    E:double_plan:N:0:F:1
312    B:steps
313    P:0:0:UI1:test-plan.c:31
314    P:1:0:UI1:test-plan.c:33
315    P:2:0:UI1:test-plan.c:34
316    E:steps:N:3:F:0
317
318Test Case Resource Accounting
319-----------------------------
320
321The framework can check if various resources are leaked during a test case
322execution.  The resource checkers are specified by the test run configuration.
323On RTEMS, checks for the following resources are available
324
325* workspace and heap memory,
326* file descriptors,
327* POSIX keys and key value pairs,
328* RTEMS barriers,
329* RTEMS user extensions,
330* RTEMS message queues,
331* RTEMS partitions,
332* RTEMS periods,
333* RTEMS regions,
334* RTEMS semaphores,
335* RTEMS tasks, and
336* RTEMS timers.
337
338.. code-block:: c
339    :caption: Resource Accounting Example
340
341    #include <t.h>
342
343    #include <stdlib.h>
344
345    #include <rtems.h>
346
347    T_TEST_CASE(missing_sema_delete)
348    {
349        rtems_status_code sc;
350        rtems_id id;
351
352        sc = rtems_semaphore_create(rtems_build_name('S', 'E', 'M', 'A'), 0,
353            RTEMS_COUNTING_SEMAPHORE, 0, &id);
354        T_rsc_success(sc);
355    }
356
357    T_TEST_CASE(missing_free)
358    {
359        void *p;
360
361        p = malloc(1);
362        T_not_null(p);
363    }
364
365.. code-block:: none
366    :caption: Resource Accounting Report
367
368    B:missing_sema_delete
369    P:0:0:UI1:test-leak.c:14
370    F:*:0:UI1:*:*:RTEMS semaphore leak (1)
371    E:missing_sema_delete:N:1:F:1:D:0.004013
372    B:missing_free
373    P:0:0:UI1:test-leak.c:22
374    F:*:0:UI1:*:*:memory leak in workspace or heap
375    E:missing_free:N:1:F:1:D:0.003944
376
377Test Case Scoped Dynamic Memory
378-------------------------------
379
380You can allocate dynamic memory which is automatically freed after the current
381test case execution.  You can provide an optional destroy function to
382`T_zalloc()` which is called right before the memory is freed.  The
383`T_zalloc()` function initializes the memory to zero.
384
385.. code-block:: c
386
387   void *T_malloc(size_t size);
388
389   void *T_calloc(size_t nelem, size_t elsize);
390
391   void *T_zalloc(size_t size, void (*destroy)(void *));
392
393   void T_free(void *ptr);
394
395.. code-block:: c
396    :caption: Test Case Scoped Dynamic Memory Example
397
398    #include <t.h>
399
400    T_TEST_CASE(malloc_free)
401    {
402        void *p;
403
404        p = T_malloc(1);
405        T_assert_not_null(p);
406        T_free(p);
407    }
408
409    T_TEST_CASE(malloc_auto)
410    {
411        void *p;
412
413        p = T_malloc(1);
414        T_assert_not_null(p);
415    }
416
417    static void
418    destroy(void *p)
419    {
420        int *i;
421
422        i = p;
423        T_step_eq_int(2, *i, 1);
424    }
425
426    T_TEST_CASE(zalloc_auto)
427    {
428        int *i;
429
430        T_plan(3);
431        i = T_zalloc(sizeof(*i), destroy);
432        T_step_assert_not_null(0, i);
433        T_step_eq_int(1, *i, 0);
434        *i = 1;
435    }
436
437.. code-block:: none
438    :caption: Test Case Scoped Dynamic Memory Report
439
440    B:malloc_free
441    P:0:0:UI1:test-malloc.c:8
442    E:malloc_free:N:1:F:0:D:0.005200
443    B:malloc_auto
444    P:0:0:UI1:test-malloc.c:17
445    E:malloc_auto:N:1:F:0:D:0.004790
446    B:zalloc_auto
447    P:0:0:UI1:test-malloc.c:35
448    P:1:0:UI1:test-malloc.c:36
449    P:2:0:UI1:test-malloc.c:26
450    E:zalloc_auto:N:3:F:0:D:0.006583
451
452Test Case Destructors
453---------------------
454
455You can add test case destructors with `T_add_destructor()`.  They are called
456automatically at the test case end before the resource accounting takes place.
457Optionally, a registered destructor can be removed before the test case end
458with `T_remove_destructor()`.  The `T_destructor` structure of a destructor
459must exist after the return from the test case body.  Do not use stack memory
460or dynamic memory obtained via `T_malloc()`, `T_calloc()` or `T_zalloc()` for
461the `T_destructor` structure.
462
463.. code-block:: c
464
465    void T_add_destructor(T_destructor *destructor,
466       void (*destroy)(T_destructor *));
467
468    void T_remove_destructor(T_destructor *destructor);
469
470.. code-block:: c
471    :caption: Test Case Destructor Example
472
473    #include <t.h>
474
475    static void
476    destroy(T_destructor *dtor)
477    {
478        (void)dtor;
479        T_step(0, "destroy");
480    }
481
482    T_TEST_CASE(destructor)
483    {
484        static T_destructor dtor;
485
486        T_plan(1);
487        T_add_destructor(&dtor, destroy);
488    }
489
490.. code-block:: none
491    :caption: Test Case Destructor Report
492
493    B:destructor
494    P:0:0:UI1:test-destructor.c:7
495    E:destructor:N:1:F:0:D:0.003714
496
497Test Checks
498-----------
499
500A `test check` determines if the actual value presented to the test check meets
501its expectation.  The actual value should represent the outcome of a test
502action.  If the actual value is all right, then the test check passes,
503otherwise the test check fails.  A failed test check does not stop the test
504case execution immediately unless the `T_assert_*()` test variant is used.
505Each test check increments the test step counter unless the `T_quiet_*()` test
506variant is used.  The test step counter is initialized to zero before the test
507case begins to execute.  The `T_step_*(step, ...)` test check variants verify
508that the test step counter is equal to the planned test step value, otherwise
509the test check fails.
510
511Test Check Parameter Conventions
512~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
513
514The following names for test check parameters are used throughout the test
515checks:
516
517step
518    The planned test step for this test check.
519
520a
521    The actual value to check against an expected value.  It is usually the
522    first parameter in all test checks, except in the `T_step_*(step, ...)`
523    test check variants, here it is the second parameter.
524
525e
526    The expected value of a test check.  This parameter is optional.  Some test
527    checks have an implicit expected value.  If present, then this parameter is
528    directly after the actual value parameter of the test check.
529
530fmt
531    A printf()-like format string.  Floating-point and exotic formats may be
532    not supported.
533
534Test Check Condition Conventions
535~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
536
537The following names for test check conditions are used:
538
539eq
540    The actual value must equal the expected value.
541
542ne
543    The actual value must not equal the value of the second parameter.
544
545ge
546    The actual value must be greater than or equal to the expected value.
547
548gt
549    The actual value must be greater than the expected value.
550
551le
552    The actual value must be less than or equal to the expected value.
553
554lt
555    The actual value must be less than the expected value.
556
557If the actual value satisfies the test check condition, then the test check
558passes, otherwise it fails.
559
560Test Check Variant Conventions
561~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
562
563The `T_quiet_*()` test check variants do not increment the test step counter
564and only print a message if the test check fails.  This is helpful in case a
565test check appears in a tight loop.
566
567The `T_step_*(step, ...)` test check variants check in addition that the test
568step counter is equal to the specified test step value, otherwise the test
569check fails.
570
571The `T_assert_*()` and `T_step_assert_*(step, ...)` test check variants stop
572the current test case execution if the test check fails.
573
574The following names for test check type variants are used:
575
576ptr
577    The test value must be a pointer (`void *`).
578
579mem
580    The test value must be a memory area with a specified length.
581
582str
583    The test value must be a null byte terminated string.
584
585nstr
586    The length of the test value string is limited to a specified maximum.
587
588char
589    The test value must be a character (`char`).
590
591schar
592    The test value must be a signed character (`signed char`).
593
594uchar
595    The test value must be an unsigned character (`unsigned char`).
596
597short
598    The test value must be a short integer (`short`).
599
600ushort
601    The test value must be an unsigned short integer (`unsigned short`).
602
603int
604    The test value must be an integer (`int`).
605
606uint
607    The test value must be an unsigned integer (`unsigned int`).
608
609long
610    The test value must be a long integer (`long`).
611
612ulong
613    The test value must be an unsigned long integer (`unsigned long`).
614
615ll
616    The test value must be a long long integer (`long long`).
617
618ull
619    The test value must be an unsigned long long integer (`unsigned long long`).
620
621i8
622    The test value must be a signed 8-bit integer (`int8_t`).
623
624u8
625    The test value must be an unsigned 8-bit integer (`uint8_t`).
626
627i16
628    The test value must be a signed 16-bit integer (`int16_t`).
629
630u16
631    The test value must be an unsigned 16-bit integer (`uint16_t`).
632
633i32
634    The test value must be a signed 32-bit integer (`int32_t`).
635
636u32
637    The test value must be an unsigned 32-bit integer (`uint32_t`).
638
639i64
640    The test value must be a signed 64-bit integer (`int64_t`).
641
642u64
643    The test value must be an unsigned 64-bit integer (`uint64_t`).
644
645iptr
646    The test value must be of type `intptr_t`.
647
648uptr
649    The test value must be of type `uintptr_t`.
650
651ssz
652    The test value must be of type `ssize_t`.
653
654sz
655    The test value must be of type `size_t`.
656
657Boolean Expressions
658~~~~~~~~~~~~~~~~~~~
659
660The following test checks for boolean expressions are available:
661
662.. code-block:: c
663
664    void T_true(bool a, const char *fmt, ...);
665    void T_assert_true(bool a, const char *fmt, ...);
666    void T_quiet_true(bool a, const char *fmt, ...);
667    void T_step_true(unsigned int step, bool a, const char *fmt, ...);
668    void T_step_assert_true(unsigned int step, bool a, const char *fmt, ...);
669
670    void T_false(bool a, const char *fmt, ...);
671    void T_assert_false(bool a, const char *fmt, ...);
672    void T_quiet_true(bool a, const char *fmt, ...);
673    void T_step_true(unsigned int step, bool a, const char *fmt, ...);
674    void T_step_assert_true(unsigned int step, bool a, const char *fmt, ...);
675
676The message is only printed in case the test check fails.  The format parameter
677is mandatory.
678
679.. code-block:: c
680    :caption: Boolean Test Checks Example
681
682    #include <t.h>
683
684    T_TEST_CASE(example)
685    {
686        T_true(true, "test passes, no message output");
687        T_true(false, "test fails");
688        T_quiet_true(true, "quiet test passes, no output at all");
689        T_quiet_true(false, "quiet test fails");
690        T_step_true(2, true, "step test passes, no message output");
691        T_step_true(3, false, "step test fails");
692        T_assert_false(true, "this is a format %s", "string");
693    }
694
695.. code-block:: none
696    :caption: Boolean Test Checks Report
697
698    B:example
699    P:0:0:UI1:test-example.c:5
700    F:1:0:UI1:test-example.c:6:test fails
701    F:*:0:UI1:test-example.c:8:quiet test fails
702    P:2:0:UI1:test-example.c:9
703    F:3:0:UI1:test-example.c:10:step test fails
704    F:4:0:UI1:test-example.c:11:this is a format string
705    E:example:N:5:F:4
706
707Generic Types
708~~~~~~~~~~~~~
709
710The following test checks for data types with an equality (`==`) or inequality
711(`!=`) operator are available:
712
713.. code-block:: c
714
715    void T_eq(T a, T e, const char *fmt, ...);
716    void T_assert_eq(T a, T e, const char *fmt, ...);
717    void T_quiet_eq(T a, T e, const char *fmt, ...);
718    void T_step_eq(unsigned int step, T a, T e, const char *fmt, ...);
719    void T_step_assert_eq(unsigned int step, T a, T e, const char *fmt, ...);
720
721    void T_ne(T a, T e, const char *fmt, ...);
722    void T_assert_ne(T a, T e, const char *fmt, ...);
723    void T_quiet_ne(T a, T e, const char *fmt, ...);
724    void T_step_ne(unsigned int step, T a, T e, const char *fmt, ...);
725    void T_step_assert_ne(unsigned int step, T a, T e, const char *fmt, ...);
726
727The type name `T` specifies an arbitrary type which must support the
728corresponding operator.  The message is only printed in case the test check
729fails.  The format parameter is mandatory.
730
731Pointers
732~~~~~~~~
733
734The following test checks for pointers are available:
735
736.. code-block:: c
737
738    void T_eq_ptr(const void *a, const void *e);
739    void T_assert_eq_ptr(const void *a, const void *e);
740    void T_quiet_eq_ptr(const void *a, const void *e);
741    void T_step_eq_ptr(unsigned int step, const void *a, const void *e);
742    void T_step_assert_eq_ptr(unsigned int step, const void *a, const void *e);
743
744    void T_ne_ptr(const void *a, const void *e);
745    void T_assert_ne_ptr(const void *a, const void *e);
746    void T_quiet_ne_ptr(const void *a, const void *e);
747    void T_step_ne_ptr(unsigned int step, const void *a, const void *e);
748    void T_step_assert_ne_ptr(unsigned int step, const void *a, const void *e);
749
750    void T_null(const void *a);
751    void T_assert_null(const void *a);
752    void T_quiet_null(const void *a);
753    void T_step_null(unsigned int step, const void *a);
754    void T_step_assert_null(unsigned int step, const void *a);
755
756    void T_not_null(const void *a);
757    void T_assert_not_null(const void *a);
758    void T_quiet_not_null(const void *a);
759    void T_step_not_null(unsigned int step, const void *a);
760    void T_step_assert_not_null(unsigned int step, const void *a);
761
762An automatically generated message is printed in case the test check fails.
763
764Memory Areas
765~~~~~~~~~~~~
766
767The following test checks for memory areas are available:
768
769.. code-block:: c
770
771    void T_eq_mem(const void *a, const void *e, size_t n);
772    void T_assert_eq_mem(const void *a, const void *e, size_t n);
773    void T_quiet_eq_mem(const void *a, const void *e, size_t n);
774    void T_step_eq_mem(unsigned int step, const void *a, const void *e, size_t n);
775    void T_step_assert_eq_mem(unsigned int step, const void *a, const void *e, size_t n);
776
777    void T_ne_mem(const void *a, const void *e, size_t n);
778    void T_assert_ne_mem(const void *a, const void *e, size_t n);
779    void T_quiet_ne_mem(const void *a, const void *e, size_t n);
780    void T_step_ne_mem(unsigned int step, const void *a, const void *e, size_t n);
781    void T_step_assert_ne_mem(unsigned int step, const void *a, const void *e, size_t n);
782
783The `memcmp()` function is used to compare the memory areas.  An automatically
784generated message is printed in case the test check fails.
785
786Strings
787~~~~~~~
788
789The following test checks for strings are available:
790
791.. code-block:: c
792
793    void T_eq_str(const char *a, const char *e);
794    void T_assert_eq_str(const char *a, const char *e);
795    void T_quiet_eq_str(const char *a, const char *e);
796    void T_step_eq_str(unsigned int step, const char *a, const char *e);
797    void T_step_assert_eq_str(unsigned int step, const char *a, const char *e);
798
799    void T_ne_str(const char *a, const char *e);
800    void T_assert_ne_str(const char *a, const char *e);
801    void T_quiet_ne_str(const char *a, const char *e);
802    void T_step_ne_str(unsigned int step, const char *a, const char *e);
803    void T_step_assert_ne_str(unsigned int step, const char *a, const char *e);
804
805    void T_eq_nstr(const char *a, const char *e, size_t n);
806    void T_assert_eq_nstr(const char *a, const char *e, size_t n);
807    void T_quiet_eq_nstr(const char *a, const char *e, size_t n);
808    void T_step_eq_nstr(unsigned int step, const char *a, const char *e, size_t n);
809    void T_step_assert_eq_nstr(unsigned int step, const char *a, const char *e, size_t n);
810
811    void T_ne_nstr(const char *a, const char *e, size_t n);
812    void T_assert_ne_nstr(const char *a, const char *e, size_t n);
813    void T_quiet_ne_nstr(const char *a, const char *e, size_t n);
814    void T_step_ne_nstr(unsigned int step, const char *a, const char *e, size_t n);
815    void T_step_assert_ne_nstr(unsigned int step, const char *a, const char *e, size_t n);
816
817The `strcmp()` and `strncmp()` functions are used to compare the strings.  An
818automatically generated message is printed in case the test check fails.
819
820Characters
821~~~~~~~~~~
822
823The following test checks for characters (`char`) are available:
824
825.. code-block:: c
826
827    void T_eq_char(char a, char e);
828    void T_assert_eq_char(char a, char e);
829    void T_quiet_eq_char(char a, char e);
830    void T_step_eq_char(unsigned int step, char a, char e);
831    void T_step_assert_eq_char(unsigned int step, char a, char e);
832
833    void T_ne_char(char a, char e);
834    void T_assert_ne_char(char a, char e);
835    void T_quiet_ne_char(char a, char e);
836    void T_step_ne_char(unsigned int step, char a, char e);
837    void T_step_assert_ne_char(unsigned int step, char a, char e);
838
839An automatically generated message is printed in case the test check fails.
840
841Integers
842~~~~~~~~
843
844The following test checks for integers are available:
845
846.. code-block:: c
847
848    void T_eq_xyz(I a, I e);
849    void T_assert_eq_xyz(I a, I e);
850    void T_quiet_eq_xyz(I a, I e);
851    void T_step_eq_xyz(unsigned int step, I a, I e);
852    void T_step_assert_eq_xyz(unsigned int step, I a, I e);
853
854    void T_ne_xyz(I a, I e);
855    void T_assert_ne_xyz(I a, I e);
856    void T_quiet_ne_xyz(I a, I e);
857    void T_step_ne_xyz(unsigned int step, I a, I e);
858    void T_step_assert_ne_xyz(unsigned int step, I a, I e);
859
860    void T_ge_xyz(I a, I e);
861    void T_assert_ge_xyz(I a, I e);
862    void T_quiet_ge_xyz(I a, I e);
863    void T_step_ge_xyz(unsigned int step, I a, I e);
864    void T_step_assert_ge_xyz(unsigned int step, I a, I e);
865
866    void T_gt_xyz(I a, I e);
867    void T_assert_gt_xyz(I a, I e);
868    void T_quiet_gt_xyz(I a, I e);
869    void T_step_gt_xyz(unsigned int step, I a, I e);
870    void T_step_assert_gt_xyz(unsigned int step, I a, I e);
871
872    void T_le_xyz(I a, I e);
873    void T_assert_le_xyz(I a, I e);
874    void T_quiet_le_xyz(I a, I e);
875    void T_step_le_xyz(unsigned int step, I a, I e);
876    void T_step_assert_le_xyz(unsigned int step, I a, I e);
877
878    void T_lt_xyz(I a, I e);
879    void T_assert_lt_xyz(I a, I e);
880    void T_quiet_lt_xyz(I a, I e);
881    void T_step_lt_xyz(unsigned int step, I a, I e);
882    void T_step_assert_lt_xyz(unsigned int step, I a, I e);
883
884The type variant `xyz` must be `schar`, `uchar`, `short`, `ushort`, `int`,
885`uint`, `long`, `ulong`, `ll`, `ull`, `i8`, `u8`, `i16`, `u16`, `i32`, `u32`,
886`i64`, `u64`, `iptr`, `uptr`, `ssz`, or `sz`.
887
888The type name `I` must be compatible to the type variant.
889
890An automatically generated message is printed in case the test check fails.
891
892RTEMS Status Codes
893~~~~~~~~~~~~~~~~~~
894
895The following test checks for RTEMS status codes are available:
896
897.. code-block:: c
898
899    void T_rsc(rtems_status_code a, rtems_status_code e);
900    void T_assert_rsc(rtems_status_code a, rtems_status_code e);
901    void T_quiet_rsc(rtems_status_code a, rtems_status_code e);
902    void T_step_rsc(unsigned int step, rtems_status_code a, rtems_status_code e);
903    void T_step_assert_rsc(unsigned int step, rtems_status_code a, rtems_status_code e);
904
905    void T_rsc_success(rtems_status_code a);
906    void T_assert_rsc_success(rtems_status_code a);
907    void T_quiet_rsc_success(rtems_status_code a);
908    void T_step_rsc_success(unsigned int step, rtems_status_code a);
909    void T_step_assert_rsc_success(unsigned int step, rtems_status_code a);
910
911An automatically generated message is printed in case the test check fails.
912
913POSIX Error Numbers
914~~~~~~~~~~~~~~~~~~~
915
916The following test checks for POSIX error numbers are available:
917
918.. code-block:: c
919
920    void T_eno(int a, int e);
921    void T_assert_eno(int a, int e);
922    void T_quiet_eno(int a, int e);
923    void T_step_eno(unsigned int step, int a, int e);
924    void T_step_assert_eno(unsigned int step, int a, int e);
925
926    void T_eno_success(int a);
927    void T_assert_eno_success(int a);
928    void T_quiet_eno_success(int a);
929    void T_step_eno_success(unsigned int step, int a);
930    void T_step_assert_eno_success(unsigned int step, int a);
931
932The actual and expected value must be a POSIX error number, e.g. EINVAL,
933ENOMEM, etc.  An automatically generated message is printed in case the test
934check fails.
935
936POSIX Status Codes
937~~~~~~~~~~~~~~~~~~
938
939The following test checks for POSIX status codes are available:
940
941.. code-block:: c
942
943    void T_psx_error(int a, int eno);
944    void T_assert_psx_error(int a, int eno);
945    void T_quiet_psx_error(int a, int eno);
946    void T_step_psx_error(unsigned int step, int a, int eno);
947    void T_step_assert_psx_error(unsigned int step, int a, int eno);
948
949    void T_psx_success(int a);
950    void T_assert_psx_success(int a);
951    void T_quiet_psx_success(int a);
952    void T_step_psx_success(unsigned int step, int a);
953    void T_step_assert_psx_success(unsigned int step, int a);
954
955The `eno` value must be a POSIX error number, e.g. EINVAL, ENOMEM, etc.  An
956actual value of zero indicates success.  An actual value of minus one indicates
957an error.  An automatically generated message is printed in case the test check
958fails.
959
960.. code-block:: c
961    :caption: POSIX Status Code Example
962
963    #include <t.h>
964
965    #include <sys/stat.h>
966    #include <errno.h>
967
968    T_TEST_CASE(stat)
969    {
970        struct stat st;
971        int status;
972
973        errno = 0;
974        status = stat("foobar", &st);
975        T_psx_error(status, ENOENT);
976    }
977
978.. code-block:: none
979    :caption: POSIX Status Code Report
980
981    B:stat
982    P:0:0:UI1:test-psx.c:13
983    E:stat:N:1:F:0
984
985Log Messages and Formatted Output
986---------------------------------
987
988You can print log messages with the `T_log()` function:
989
990.. code-block:: c
991
992    void T_log(T_verbosity verbosity, char const *fmt, ...);
993
994A newline is automatically added to terminate the log message line.
995
996.. code-block:: c
997    :caption: Log Message Example
998
999    #include <t.h>
1000
1001    T_TEST_CASE(log)
1002    {
1003        T_log(T_NORMAL, "a log message %i, %i, %i", 1, 2, 3);
1004        T_set_verbosity(T_QUIET);
1005        T_log(T_NORMAL, "not verbose enough");
1006    }
1007
1008.. code-block:: none
1009    :caption: Log Message Report
1010
1011    B:log
1012    L:a log message 1, 2, 3
1013    E:log:N:0:F:0
1014
1015You can use the following functions to print formatted output:
1016
1017.. code-block:: c
1018
1019    int T_printf(char const *, ...);
1020
1021    int T_vprintf(char const *, va_list);
1022
1023    int T_snprintf(char *, size_t, const char *, ...);
1024
1025In contrast to the corresponding standard C library functions, floating-point
1026and exotic formats may be not supported.  On some architectures supported by
1027RTEMS, floating-point operations are only supported in special tasks and may be
1028forbidden in interrupt context.  The formatted output functions provided by the
1029test framework work in every context.
1030
1031Time Services
1032-------------
1033
1034The test framework provides two unsigned integer types for time values.  The
1035`T_ticks` unsigned integer type is used by the `T_tick()` function which
1036measures time using the highest frequency counter available on the platform.
1037It should only be used to measure small time intervals.  The `T_time` unsigned
1038integer type is used by the `T_now()` function which returns the current
1039monotonic clock value of the platform, e.g. `CLOCK_MONOTONIC`.
1040
1041.. code-block:: c
1042
1043   T_ticks T_tick(void);
1044
1045   T_time T_now(void);
1046
1047The reference time point for these two clocks is unspecified.  You can obtain
1048the test case begin time with the `T_case_begin_time()` function.
1049
1050.. code-block:: c
1051
1052   T_time T_case_begin_time(void);
1053
1054You can convert time into ticks with the `T_time_to_ticks()` function and vice
1055versa with the `T_ticks_to_time()` function.
1056
1057.. code-block:: c
1058
1059    T_time T_ticks_to_time(T_ticks ticks);
1060
1061    T_ticks T_time_to_ticks(T_time time);
1062
1063You can convert seconds and nanoseconds values into a combined time value with
1064the `T_seconds_and_nanoseconds_to_time()` function.  You can convert a time
1065value into separate seconds and nanoseconds values with the
1066`T_time_to_seconds_and_nanoseconds()` function.
1067
1068.. code-block:: c
1069
1070    T_time T_seconds_and_nanoseconds_to_time(uint32_t s, uint32_t ns);
1071
1072    void T_time_to_seconds_and_nanoseconds(T_time time, uint32_t *s, uint32_t *ns);
1073
1074You can convert a time value into a string represention.  The time unit of the
1075string representation is seconds.  The precision of the string represention may
1076be nanoseconds, microseconds, milliseconds, or seconds.  You have to provide a
1077buffer for the string (`T_time_string`).
1078
1079.. code-block:: c
1080
1081    const char *T_time_to_string_ns(T_time time, T_time_string buffer);
1082
1083    const char *T_time_to_string_us(T_time time, T_time_string buffer);
1084
1085    const char *T_time_to_string_ms(T_time time, T_time_string buffer);
1086
1087    const char *T_time_to_string_s(T_time time, T_time_string buffer);
1088
1089.. code-block:: c
1090    :caption: Time String Example
1091
1092    #include <t.h>
1093
1094    T_TEST_CASE(time_to_string)
1095    {
1096        T_time_string ts;
1097        T_time t;
1098        uint32_t s;
1099        uint32_t ns;
1100
1101        t = T_seconds_and_nanoseconds_to_time(0, 123456789);
1102        T_eq_str(T_time_to_string_ns(t, ts), "0.123456789");
1103        T_eq_str(T_time_to_string_us(t, ts), "0.123456");
1104        T_eq_str(T_time_to_string_ms(t, ts), "0.123");
1105        T_eq_str(T_time_to_string_s(t, ts), "0");
1106
1107        T_time_to_seconds_and_nanoseconds(t, &s, &ns);
1108        T_eq_u32(s, 0);
1109        T_eq_u32(ns, 123456789);
1110    }
1111
1112.. code-block:: none
1113    :caption: Time String Report
1114
1115    B:time_to_string
1116    P:0:0:UI1:test-time.c:11
1117    P:1:0:UI1:test-time.c:12
1118    P:2:0:UI1:test-time.c:13
1119    P:3:0:UI1:test-time.c:14
1120    P:4:0:UI1:test-time.c:17
1121    P:5:0:UI1:test-time.c:18
1122    E:time_to_string:N:6:F:0:D:0.005250
1123
1124You can convert a tick value into a string represention.  The time unit of the
1125string representation is seconds.  The precision of the string represention may
1126be nanoseconds, microseconds, milliseconds, or seconds.  You have to provide a
1127buffer for the string (`T_time_string`).
1128
1129.. code-block:: c
1130
1131    const char *T_ticks_to_string_ns(T_ticks ticks, T_time_string buffer);
1132
1133    const char *T_ticks_to_string_us(T_ticks ticks, T_time_string buffer);
1134
1135    const char *T_ticks_to_string_ms(T_ticks ticks, T_time_string buffer);
1136
1137    const char *T_ticks_to_string_s(T_ticks ticks, T_time_string buffer);
1138
1139Code Runtime Measurements
1140-------------------------
1141
1142You can measure the runtime of code fragments in several execution environment
1143variants with the `T_measure_runtime()` function.  This function needs a
1144context which must be created with the `T_measure_runtime_create()` function.
1145The context is automatically destroyed after the test case execution.
1146
1147.. code-block:: c
1148
1149    typedef struct {
1150        size_t sample_count;
1151    } T_measure_runtime_config;
1152
1153    typedef struct {
1154        const char *name;
1155        int flags;
1156        void (*setup)(void *arg);
1157        void (*body)(void *arg);
1158        bool (*teardown)(void *arg, T_ticks *delta, uint32_t tic, uint32_t toc,
1159            unsigned int retry);
1160        void *arg;
1161    } T_measure_runtime_request;
1162
1163    T_measure_runtime_context *T_measure_runtime_create(
1164        const T_measure_runtime_config *config);
1165
1166    void T_measure_runtime(T_measure_runtime_context *ctx,
1167        const T_measure_runtime_request *request);
1168
1169The runtime measurement is performed for the `body` request handler of the
1170measurement request (`T_measure_runtime_request`).  The optional `setup`
1171request handler is called before each invocation of the `body` request handler.
1172The optional `teardown` request handler is called after each invocation of the
1173`body` request handler.  It has several parameters and a return status.  If it
1174returns true, then this measurement sample value is recorded, otherwise the
1175measurement is retried.  The `delta` parameter is the current measurement
1176sample value.  It can be altered by the `teardown` request handler.  The `tic`
1177and `toc` parameters are the system tick values before and after the request
1178body invocation.  The `retry` parameter is the current retry counter.  The
1179runtime of the operational `setup` and `teardown` request handlers is not
1180measured.
1181
1182You can control some aspects of the measurement through the request flags (use
1183zero for the default):
1184
1185T_MEASURE_RUNTIME_ALLOW_CLOCK_ISR
1186    Allow clock interrupts during the measurement.  By default, measurements
1187    during which a clock interrupt happened are discarded unless it happens two
1188    times in a row.
1189
1190T_MEASURE_RUNTIME_REPORT_SAMPLES
1191    Report all measurement samples.
1192
1193T_MEASURE_RUNTIME_DISABLE_VALID_CACHE
1194    Disable the `ValidCache` execution environment variant.
1195
1196T_MEASURE_RUNTIME_DISABLE_HOT_CACHE
1197    Disable the `HotCache` execution environment variant.
1198
1199T_MEASURE_RUNTIME_DISABLE_DIRTY_CACHE
1200    Disable the `DirtyCache` execution environment variant.
1201
1202T_MEASURE_RUNTIME_DISABLE_MINOR_LOAD
1203    Disable the `Load` execution environment variants with a load worker count
1204    less than the processor count.
1205
1206T_MEASURE_RUNTIME_DISABLE_MAX_LOAD
1207    Disable the `Load` execution environment variant with a load worker count
1208    equal to the processor count.
1209
1210The execution environment variants (`M:V`) are:
1211
1212ValidCache
1213    Before the `body` request handler is invoked a memory area with twice the
1214    size of the outer-most data cache is completely read.  This fills the data
1215    cache with valid cache lines which are unrelated to the `body` request
1216    handler.
1217
1218    You can disable this variant with the
1219    `T_MEASURE_RUNTIME_DISABLE_VALID_CACHE` request flag.
1220
1221HotCache
1222    Before the `body` request handler is invoked the `body` request handler is
1223    called without measuring the runtime.  The aim is to load all data used by
1224    the `body` request handler to the cache.
1225
1226    You can disable this variant with the
1227    `T_MEASURE_RUNTIME_DISABLE_HOT_CACHE` request flag.
1228
1229DirtyCache
1230    Before the `body` request handler is invoked a memory area with twice the
1231    size of the outer-most data cache is completely written with new data.
1232    This should produce a data cache with dirty cache lines which are unrelated
1233    to the `body` request handler.  In addition, the entire instruction cache
1234    is invalidated.
1235
1236    You can disable this variant with the
1237    `T_MEASURE_RUNTIME_DISABLE_DIRTY_CACHE` request flag.
1238
1239Load
1240    This variant tries to get close to worst-case conditions.  The cache is set
1241    up according to the `DirtyCache` variant.  In addition, other processors
1242    try to fully load the memory system.  The load is produced through writes
1243    to a memory area with twice the size of the outer-most data cache.  The
1244    load variant is performed multiple times with a different set of active
1245    load worker threads (`M:L`).  The active workers range from one up to the
1246    processor count.
1247
1248    You can disable these variants with the
1249    `T_MEASURE_RUNTIME_DISABLE_MINOR_LOAD` and
1250    `T_MEASURE_RUNTIME_DISABLE_MAX_LOAD` request flags.
1251
1252    On SPARC, the `body` request handler is called with a register window
1253    setting so that window overflow traps will occur in the next level function
1254    call.
1255
1256Each execution in an environment variant produces a sample set of `body`
1257request handler runtime measurements.  The minimum (`M:MI`), first quartile
1258(`M:Q1`), median (`M:Q2`), third quartile (`M:Q3`), maximum (`M:MX`), median
1259absolute deviation (`M:MAD`), and the sum of the sample values (`M:D`) is
1260reported.
1261
1262.. code-block:: c
1263    :caption: Code Runtime Measurement Example
1264
1265    #include <t.h>
1266
1267    static void
1268    empty(void *arg)
1269    {
1270        (void)arg;
1271    }
1272
1273    T_TEST_CASE(measure_empty)
1274    {
1275        static const T_measure_runtime_config config = {
1276            .sample_count = 1024
1277        };
1278        T_measure_runtime_context *ctx;
1279        T_measure_runtime_request req;
1280
1281        ctx = T_measure_runtime_create(&config);
1282        T_assert_not_null(ctx);
1283
1284        memset(&req, 0, sizeof(req));
1285        req.name = "Empty";
1286        req.body = empty;
1287        T_measure_runtime(ctx, &req);
1288    }
1289
1290.. code-block:: none
1291    :caption: Code Runtime Measurement Report
1292
1293    B:measure_empty
1294    P:0:0:UI1:test-rtems-measure.c:18
1295    M:B:Empty
1296    M:V:ValidCache
1297    M:N:1024
1298    M:MI:0.000000000
1299    M:Q1:0.000000000
1300    M:Q2:0.000000000
1301    M:Q3:0.000000000
1302    M:MX:0.000000009
1303    M:MAD:0.000000000
1304    M:D:0.000000485
1305    M:E:Empty:D:0.208984183
1306    M:B:Empty
1307    M:V:HotCache
1308    M:N:1024
1309    M:MI:0.000000003
1310    M:Q1:0.000000003
1311    M:Q2:0.000000003
1312    M:Q3:0.000000003
1313    M:MX:0.000000006
1314    M:MAD:0.000000000
1315    M:D:0.000002626
1316    M:E:Empty:D:0.000017046
1317    M:B:Empty
1318    M:V:DirtyCache
1319    M:N:1024
1320    M:MI:0.000000007
1321    M:Q1:0.000000007
1322    M:Q2:0.000000007
1323    M:Q3:0.000000008
1324    M:MX:0.000000559
1325    M:MAD:0.000000000
1326    M:D:0.000033244
1327    M:E:Empty:D:1.887834875
1328    M:B:Empty
1329    M:V:Load
1330    M:L:1
1331    M:N:1024
1332    M:MI:0.000000000
1333    M:Q1:0.000000002
1334    M:Q2:0.000000002
1335    M:Q3:0.000000003
1336    M:MX:0.000000288
1337    M:MAD:0.000000000
1338    M:D:0.000002421
1339    M:E:Empty:D:0.001798809
1340    [... 22 more load variants ...]
1341    M:E:Empty:D:0.021252583
1342    M:B:Empty
1343    M:V:Load
1344    M:L:24
1345    M:N:1024
1346    M:MI:0.000000001
1347    M:Q1:0.000000002
1348    M:Q2:0.000000002
1349    M:Q3:0.000000003
1350    M:MX:0.000001183
1351    M:MAD:0.000000000
1352    M:D:0.000003406
1353    M:E:Empty:D:0.015188063
1354    E:measure_empty:N:1:F:0:D:14.284869
1355
1356
1357Test Runner
1358-----------
1359
1360You can call the `T_main()` function to run all registered test cases.
1361
1362.. code-block:: c
1363
1364    int T_main(const T_config *config);
1365
1366The `T_main()` function returns 0 if all test cases passed, otherwise it
1367returns 1.  Concurrent execution of the `T_main()` function is undefined
1368behaviour.
1369
1370You can ask if you execute within the context of the test runner with the
1371`T_is_runner()` function:
1372
1373.. code-block:: c
1374
1375    bool T_is_runner(void);
1376
1377It returns `true` if you execute within the context of the test runner (the
1378context which executes for example `T_main()`).  Otherwise it returns `false`,
1379for example if you execute in another task, in interrupt context, nobody
1380executes `T_main()`, or during system initialization on another processor.
1381
1382On RTEMS, you have to register the test cases with the `T_register()` function
1383before you call `T_main()`.  This makes it possible to run low level tests, for
1384example without the operating system directly in `boot_card()` or during device
1385driver initialization.  On other platforms, the `T_register()` is a no
1386operation.
1387
1388.. code-block:: c
1389
1390    void T_register(void);
1391
1392You can run test cases also individually.  Use `T_run_initialize()` to
1393initialize the test runner.  Call `T_run_all()` to run all or `T_run_by_name()`
1394to run specific registered test cases.  Call `T_case_begin()` to begin a
1395freestanding test case and call `T_case_end()` to finish it.  Finally,
1396call `T_run_finalize()`.
1397
1398.. code-block:: c
1399
1400    void T_run_initialize(const T_config *config);
1401
1402    void T_run_all(void);
1403
1404    void T_run_by_name(const char *name);
1405
1406    void T_case_begin(const char *name, const T_fixture *fixture);
1407
1408    void T_case_end(void);
1409
1410    bool T_run_finalize(void);
1411
1412The `T_run_finalize()` function returns `true` if all test cases passed,
1413otherwise it returns `false`.  Concurrent execution of the runner functions
1414(including `T_main()`) is undefined behaviour.  The test suite configuration
1415must be persistent throughout the test run.
1416
1417.. code-block:: c
1418
1419    typedef enum {
1420        T_EVENT_RUN_INITIALIZE,
1421        T_EVENT_CASE_EARLY,
1422        T_EVENT_CASE_BEGIN,
1423        T_EVENT_CASE_END,
1424        T_EVENT_CASE_LATE,
1425        T_EVENT_RUN_FINALIZE
1426    } T_event;
1427
1428    typedef void (*T_action)(T_event, const char *);
1429
1430    typedef void (*T_putchar)(int, void *);
1431
1432    typedef struct {
1433        const char *name;
1434        char *buf;
1435        size_t buf_size;
1436        T_putchar putchar;
1437        void *putchar_arg;
1438        T_verbosity verbosity;
1439        T_time (*now)(void);
1440        size_t action_count;
1441        const T_action *actions;
1442    } T_config;
1443
1444With the test suite configuration you can specifiy the test suite name, the put
1445character handler used the output the test report, the initial verbosity, the
1446monotonic time provider and an optional set of test suite actions.  Only the
1447test runner calls the put character handler, other tasks or interrupt handlers
1448write to a buffer which is emptied by the test runner on demand.  You have to
1449specifiy this buffer in the test configuration.  The test suite actions are
1450called with the test suite name for test suite run events
1451(`T_EVENT_RUN_INITIALIZE` and `T_EVENT_RUN_FINALIZE`) and the test case name
1452for the test case events (`T_EVENT_CASE_EARLY`, `T_EVENT_CASE_BEGIN`,
1453`T_EVENT_CASE_END` and `T_EVENT_CASE_LATE`).
1454
1455Test Verbosity
1456--------------
1457
1458Three test verbosity levels are defined:
1459
1460T_QUIET
1461    Only the test suite begin, system, test case end, and test suite end lines
1462    are printed.
1463
1464T_NORMAL
1465    Prints everything except passed test lines.
1466
1467T_VERBOSE
1468    Prints everything.
1469
1470The test verbosity level can be set within the scope of one test case with the
1471`T_set_verbosity()` function:
1472
1473.. code-block:: c
1474
1475    T_verbosity T_set_verbosity(T_verbosity new_verbosity);
1476
1477The function returns the previous verbosity.  After the test case, the
1478configured verbosity is automatically restored.
1479
1480An example with `T_QUIET` verbosity:
1481
1482    .. code-block:: none
1483
1484        A:xyz
1485        S:Platform:RTEMS
1486        [...]
1487        E:a:N:2:F:1
1488        E:b:N:0:F:1
1489        E:c:N:1:F:1
1490        E:d:N:6:F:0
1491        Z:xyz:C:4:N:9:F:3
1492
1493The same example with `T_NORMAL` verbosity:
1494
1495    .. code-block:: none
1496
1497        A:xyz
1498        S:Platform:RTEMS
1499        [...]
1500        B:a
1501        F:1:0:UI1:test-verbosity.c:6:test fails
1502        E:a:N:2:F:1
1503        B:b
1504        F:*:0:UI1:test-verbosity.c:12:quiet test fails
1505        E:b:N:0:F:1
1506        B:c
1507        F:0:0:UI1:test-verbosity.c:17:this is a format string
1508        E:c:N:1:F:1
1509        B:d
1510        E:d:N:6:F:0
1511        Z:xyz:C:4:N:9:F:3
1512
1513The same example with `T_VERBOSE` verbosity:
1514
1515    .. code-block:: none
1516
1517        A:xyz
1518        S:Platform:RTEMS
1519        [...]
1520        B:a
1521        P:0:0:UI1:test-verbosity.c:5
1522        F:1:0:UI1:test-verbosity.c:6:test fails
1523        E:a:N:2:F:1
1524        B:b
1525        F:*:0:UI1:test-verbosity.c:12:quiet test fails
1526        E:b:N:0:F:1
1527        B:c
1528        F:0:0:UI1:test-verbosity.c:17:this is a format string
1529        E:c:N:1:F:1
1530        B:d
1531        P:0:0:UI1:test-verbosity.c:22
1532        P:1:0:UI1:test-verbosity.c:23
1533        P:2:0:UI1:test-verbosity.c:24
1534        P:3:0:UI1:test-verbosity.c:25
1535        P:4:0:UI1:test-verbosity.c:26
1536        P:5:0:UI1:test-verbosity.c:27
1537        E:d:N:6:F:0
1538        Z:xyz:C:4:N:9:F:3
1539
1540.. _RTEMSTestFrameworkTestReporting:
1541
1542Test Reporting
1543--------------
1544
1545The test reporting is line based which should be easy to parse with a simple
1546state machine. Each line consists of a set of fields separated by colon
1547characters (`:`).  The first character of the line determines the line format:
1548
1549A
1550    A test suite begin line.  It has the format:
1551
1552    **A:<TestSuite>**
1553
1554    A description of the field follows:
1555
1556    <TestSuite>
1557        The test suite name.  Must not contain colon characters (`:`).
1558
1559S
1560    A test suite system line.  It has the format:
1561
1562    **S:<Key>:<Value>**
1563
1564    A description of the fields follows:
1565
1566    <Key>
1567        A key string.  Must not contain colon characters (`:`).
1568
1569    <Value>
1570        An arbitrary key value string.  May contain colon characters (`:`).
1571
1572B
1573    A test case begin line.  It has the format:
1574
1575    **B:<TestCase>**
1576
1577    A description of the field follows:
1578
1579    <TestCase>
1580        A test case name.  Must not contain colon characters (`:`).
1581
1582P
1583    A test pass line.  It has the format:
1584
1585    **P:<Step>:<Processor>:<Task>:<File>:<Line>**
1586
1587    A description of the fields follows:
1588
1589    <Step>
1590        Each non-quiet test has a unique test step counter value in each test case
1591        execution.  The test step counter is set to zero before the test case
1592        executes.  For quiet test checks, there is no associated test step and the
1593        character `*` instead of an integer is used to indicate this.
1594
1595    <Processor>
1596        The processor index of the processor which executed at least one
1597        instruction of the corresponding test.
1598
1599    <Task>
1600        The name of the task which executed the corresponding test if the test
1601        executed in task context.  The name `ISR` indicates that the test executed
1602        in interrupt context.  The name `?` indicates that the test executed in an
1603        arbitrary context with no valid executing task.
1604
1605    <File>
1606        The name of the source file which contains the corresponding test.  A
1607        source file of `*` indicates that no test source file is associated
1608        with the test, e.g. it was produced by the test framework itself.
1609
1610    <Line>
1611        The line of the test statement in the source file which contains the
1612        corresponding test.  A line number of `*` indicates that no test source
1613        file is associated with the test, e.g. it was produced by the test
1614        framework itself.
1615
1616F
1617    A test failure line.  It has the format:
1618
1619    **F:<Step>:<Processor>:<Task>:<File>:<Line>:<Message>**
1620
1621    A description of the fields follows:
1622
1623    <Step> <Processor> <Task> <File> <Line>
1624        See above **P** line.
1625
1626    <Message>
1627        An arbitrary message string.  May contain colon characters (`:`).
1628
1629L
1630    A log message line.  It has the format:
1631
1632    **L:<Message>**
1633
1634    A description of the field follows:
1635
1636    <Message>
1637        An arbitrary message string.  May contain colon characters (`:`).
1638
1639E
1640    A test case end line.  It has the format:
1641
1642    **E:<TestCase>:N:<Steps>:F:<Failures>:D:<Duration>**
1643
1644    A description of the fields follows:
1645
1646    <TestCase>
1647        A test case name.  Must not contain colon characters (`:`).
1648
1649    <Steps>
1650        The final test step counter of a test case.  Quiet test checks produce
1651        no test steps.
1652
1653    <Failures>
1654        The count of failed test checks of a test case.
1655
1656    <Duration>
1657        The test case duration in seconds.
1658
1659Z
1660    A test suite end line. It has the format:
1661
1662    **Z:<TestSuite>:C:<TestCases>:N:<OverallSteps>:F:<OverallFailures>:D:<Duration>**
1663
1664    A description of the fields follows:
1665
1666    <TestSuite>
1667        The test suite name.  Must not contain colon characters (`:`).
1668
1669    <TestCases>
1670        The count of test cases in the test suite.
1671
1672    <OverallSteps>
1673        The overall count of test steps in the test suite.
1674
1675    <OverallFailures>
1676        The overall count of failed test cases in the test suite.
1677
1678    <Duration>
1679        The test suite duration in seconds.
1680
1681Y
1682    Auxiliary information line.  Issued after the test suite end. It has the format:
1683
1684    **Y:ReportHash:SHA256:<Hash>**
1685
1686    A description of the fields follows:
1687
1688    <Hash>
1689        The SHA256 hash value of the test suite report from the begin to the
1690        end of the test suite.
1691
1692M
1693    A code runtime measurement line.  It has the formats:
1694
1695    **M:B:<Name>**
1696
1697    **M:V:<Variant>**
1698
1699    **M:L:<Load>**
1700
1701    **M:N:<SampleCount>**
1702
1703    **M:S:<Count>:<Value>**
1704
1705    **M:MI:<Minimum>**
1706
1707    **M:Q1:<FirstQuartile>**
1708
1709    **M:Q2:<Median>**
1710
1711    **M:Q3:<ThirdQuartile>**
1712
1713    **M:MX:<Maximum>**
1714
1715    **M:MAD:<MedianAbsoluteDeviation>**
1716
1717    **M:D:<SumOfSampleValues>**
1718
1719    **M:E:<Name>:D:<Duration>**
1720
1721    A description of the fields follows:
1722
1723    <Name>
1724        A code runtime measurement name.  Must not contain colon characters
1725        (`:`).
1726
1727    <Variant>
1728        The execution variant which is one of **ValidCache**, **HotCache**,
1729        **DirtyCache**, or **Load**.
1730
1731    <Load>
1732        The active load workers count which ranges from one to the processor
1733        count.
1734
1735    <SampleCount>
1736        The sample count as defined by the runtime measurement configuration.
1737
1738    <Count>
1739        The count of samples with the same value.
1740
1741    <Value>
1742        A sample value in seconds.
1743
1744    <Minimum>
1745        The minimum of the sample set in seconds.
1746
1747    <FirstQuartile>
1748        The first quartile of the sample set in seconds.
1749
1750    <Median>
1751        The median of the sample set in seconds.
1752
1753    <ThirdQuartile>
1754        The third quartile of the sample set in seconds.
1755
1756    <Maximum>
1757        The maximum of the sample set in seconds.
1758
1759    <MedianAbsoluteDeviation>
1760        The median absolute deviation of the sample set in seconds.
1761
1762    <SumOfSampleValues>
1763        The sum of all sample values of the sample set in seconds.
1764
1765    <Duration>
1766        The runtime measurement duration in seconds.  It includes time to set
1767        up the execution environment variant.
1768
1769.. code-block:: none
1770    :caption: Example Test Report
1771
1772    A:xyz
1773    S:Platform:RTEMS
1774    S:Compiler:7.4.0 20181206 (RTEMS 5, RSB e0aec65182449a4e22b820e773087636edaf5b32, Newlib 1d35a003f)
1775    S:Version:5.0.0.820977c5af17c1ca2f79800d64bd87ce70a24c68
1776    S:BSP:erc32
1777    S:RTEMS_DEBUG:1
1778    S:RTEMS_MULTIPROCESSING:0
1779    S:RTEMS_POSIX_API:1
1780    S:RTEMS_PROFILING:0
1781    S:RTEMS_SMP:1
1782    B:timer
1783    P:0:0:UI1:test-rtems.c:26
1784    P:1:0:UI1:test-rtems.c:29
1785    P:2:0:UI1:test-rtems.c:33
1786    P:3:0:ISR:test-rtems.c:14
1787    P:4:0:ISR:test-rtems.c:15
1788    P:5:0:UI1:test-rtems.c:38
1789    P:6:0:UI1:test-rtems.c:39
1790    P:7:0:UI1:test-rtems.c:42
1791    E:timer:N:8:F:0:D:0.019373
1792    B:rsc_success
1793    P:0:0:UI1:test-rtems.c:59
1794    F:1:0:UI1:test-rtems.c:60:RTEMS_INVALID_NUMBER == RTEMS_SUCCESSFUL
1795    F:*:0:UI1:test-rtems.c:62:RTEMS_INVALID_NUMBER == RTEMS_SUCCESSFUL
1796    P:2:0:UI1:test-rtems.c:63
1797    F:3:0:UI1:test-rtems.c:64:RTEMS_INVALID_NUMBER == RTEMS_SUCCESSFUL
1798    E:rsc_success:N:4:F:3:D:0.011128
1799    B:rsc
1800    P:0:0:UI1:test-rtems.c:48
1801    F:1:0:UI1:test-rtems.c:49:RTEMS_INVALID_NUMBER == RTEMS_INVALID_ID
1802    F:*:0:UI1:test-rtems.c:51:RTEMS_INVALID_NUMBER == RTEMS_INVALID_ID
1803    P:2:0:UI1:test-rtems.c:52
1804    F:3:0:UI1:test-rtems.c:53:RTEMS_INVALID_NUMBER == RTEMS_INVALID_ID
1805    E:rsc:N:4:F:3:D:0.011083
1806    Z:xyz:C:3:N:16:F:6:D:0.047201
1807    Y:ReportHash:SHA256:e5857c520dd9c9b7c15d4a76d78c21ccc46619c30a869ecd11bbcd1885155e0b
1808
1809Test Report Validation
1810----------------------
1811
1812You can add the `T_report_hash_sha256()` test suite action to the test suite
1813configuration to generate and report the SHA256 hash value of the test suite
1814report.  The hash value covers everything reported by the test suite run from
1815the begin to the end.  This can be used to check that the report generated on
1816the target is identical to the report received on the report consumer side.
1817The hash value is reported after the end of test suite line (`Z`) as auxiliary
1818information in a `Y` line.  Consumers may have to reverse a `\\n` to `\\r\\n`
1819conversion before the hash is calculated.  Such a conversion could be performed
1820by a particular put character handler provided by the test suite configuration.
1821
1822Supported Platforms
1823-------------------
1824
1825The framework runs on FreeBSD, MSYS2, Linux and RTEMS.
1826
1827Test Framework Requirements for RTEMS
1828=====================================
1829
1830The requirements on a test framework suitable for RTEMS are:
1831
1832License Requirements
1833--------------------
1834
1835TF.License.Permissive
1836    The test framework shall have a permissive open source license such as
1837    BSD-2-Clause.
1838
1839Portability Requirements
1840------------------------
1841
1842TF.Portability
1843    The test framework shall be portable.
1844
1845    TF.Portability.RTEMS
1846        The test framework shall run on RTEMS.
1847
1848    TF.Portability.POSIX
1849        The test framework shall be portable to POSIX compatible operating
1850        systems.  This allows to run test cases of standard C/POSIX/etc. APIs
1851        on multiple platforms.
1852
1853        TF.Portability.POSIX.Linux
1854            The test framework shall run on Linux.
1855
1856        TF.Portability.POSIX.FreeBSD
1857            The test framework shall run on FreeBSD.
1858
1859    TF.Portability.C11
1860        The test framework shall be written in C11.
1861
1862    TF.Portability.Static
1863        Test framework shall not use dynamic memory for basic services.
1864
1865    TF.Portability.Small
1866        The test framework shall be small enough to support low-end platforms
1867        (e.g. 64KiB of RAM/ROM should be sufficient to test the architecture
1868        port, e.g. no complex stuff such as file systems, etc.).
1869
1870    TF.Portability.Small.LinkTimeConfiguration
1871        The test framework shall be configured at link-time.
1872
1873    TF.Portability.Small.Modular
1874        The test framework shall be modular so that only necessary parts end up
1875        in the final executable.
1876
1877    TF.Portability.Small.Memory
1878        The test framework shall not aggregate data during test case executions.
1879
1880Reporting Requirements
1881----------------------
1882
1883TF.Reporting
1884    Test results shall be reported.
1885
1886    TF.Reporting.Verbosity
1887        The test report verbosity shall be configurable.  This allows different
1888        test run scenarios, e.g. regression test runs, full test runs with test
1889        report verification against the planned test output.
1890
1891    TF.Reporting.Verification
1892        It shall be possible to use regular expressions to verify test reports
1893        line by line.
1894
1895    TF.Reporting.Compact
1896        Test output shall be compact to avoid long test runs on platforms with
1897        a slow output device, e.g. 9600 Baud UART.
1898
1899    TF.Reporting.PutChar
1900        A simple output one character function provided by the platform shall be
1901        sufficient to report the test results.
1902
1903    TF.Reporting.NonBlocking
1904        The ouptut functions shall be non-blocking.
1905
1906    TF.Reporting.Printf
1907        The test framework shall provide printf()-like output functions.
1908
1909        TF.Reporting.Printf.WithFP
1910            There shall be a printf()-like output function with floating point
1911            support.
1912
1913        TF.Reporting.Printf.WithoutFP
1914            There shall be a printf()-like output function without floating
1915            point support on RTEMS.
1916
1917    TF.Reporting.Platform
1918        The test platform shall be reported.
1919
1920        TF.Reporting.Platform.RTEMS.Git
1921            The RTEMS source Git commit shall be reported.
1922
1923        TF.Reporting.Platform.RTEMS.Arch
1924            The RTEMS architecture name shall be reported.
1925
1926        TF.Reporting.Platform.RTEMS.BSP
1927            The RTEMS BSP name shall be reported.
1928
1929        TF.Reporting.Platform.RTEMS.Tools
1930            The RTEMS tool chain version shall be reported.
1931
1932        TF.Reporting.Platform.RTEMS.Config.Debug
1933            The shall be reported if RTEMS_DEBUG is defined.
1934
1935        TF.Reporting.Platform.RTEMS.Config.Multiprocessing
1936            The shall be reported if RTEMS_MULTIPROCESSING is defined.
1937
1938        TF.Reporting.Platform.RTEMS.Config.POSIX
1939            The shall be reported if RTEMS_POSIX_API is defined.
1940
1941        TF.Reporting.Platform.RTEMS.Config.Profiling
1942            The shall be reported if RTEMS_PROFILING is defined.
1943
1944        TF.Reporting.Platform.RTEMS.Config.SMP
1945            The shall be reported if RTEMS_SMP is defined.
1946
1947    TF.Reporting.TestCase
1948        The test cases shall be reported.
1949
1950        TF.Reporting.TestCase.Begin
1951            The test case begin shall be reported.
1952
1953        TF.Reporting.TestCase.End
1954            The test case end shall be reported.
1955
1956        TF.Reporting.TestCase.Tests
1957            The count of test checks of the test case shall be reported.
1958
1959        TF.Reporting.TestCase.Failures
1960            The count of failed test checks of the test case shall be reported.
1961
1962        TF.Reporting.TestCase.Timing
1963            Test case timing shall be reported.
1964
1965        TF.Reporting.TestCase.Tracing
1966            Automatic tracing and reporting of thread context switches and
1967            interrupt service routines shall be optionally performed.
1968
1969Environment Requirements
1970------------------------
1971
1972TF.Environment
1973    The test framework shall support all environment conditions of the platform.
1974
1975    TF.Environment.SystemStart
1976        The test framework shall run during early stages of the system start,
1977        e.g. valid stack pointer, initialized data and cleared BSS, nothing
1978        more.
1979
1980    TF.Environment.BeforeDeviceDrivers
1981        The test framework shall run before device drivers are initialized.
1982
1983    TF.Environment.InterruptContext
1984        The test framework shall support test case code in interrupt context.
1985
1986Usability Requirements
1987----------------------
1988
1989TF.Usability
1990    The test framework shall be easy to use.
1991
1992    TF.Usability.TestCase
1993        It shall be possible to write test cases.
1994
1995        TF.Usability.TestCase.Independence
1996            It shall be possible to write test cases in modules independent of
1997            the test runner.
1998
1999        TF.Usability.TestCase.AutomaticRegistration
2000            Test cases shall be registered automatically, e.g. via constructors
2001            or linker sets.
2002
2003        TF.Usability.TestCase.Order
2004            It shall be possible to sort the registered test cases (e.g. random,
2005            by name) before they are executed.
2006
2007        TF.Usability.TestCase.Resources
2008            It shall be possible to use resources with a life time restricted to
2009            the test case.
2010
2011            TF.Usability.TestCase.Resources.Memory
2012                It shall be possible to dynamically allocate memory which is
2013                automatically freed once the test case completed.
2014
2015            TF.Usability.TestCase.Resources.File
2016                It shall be possible to create a file which is automatically
2017                unlinked once the test case completed.
2018
2019            TF.Usability.TestCase.Resources.Directory
2020                It shall be possible to create a directory which is automatically
2021                removed once the test case completed.
2022
2023            TF.Usability.TestCase.Resources.FileDescriptor
2024                It shall be possible to open a file descriptor which is
2025                automatically closed once the test case completed.
2026
2027        TF.Usability.TestCase.Fixture
2028            It shall be possible to use a text fixture for test cases.
2029
2030            TF.Usability.TestCase.Fixture.SetUp
2031                It shall be possible to provide a set up handler for each test case.
2032
2033            TF.Usability.TestCase.Fixture.TearDown
2034                It shall be possible to provide a tear down handler for each test
2035                case.
2036
2037        TF.Usability.TestCase.Context
2038            The test case context shall be verified a certain points.
2039
2040            TF.Usability.TestCase.Context.VerifyAtEnd
2041                After a test case exection it shall be verified that the context
2042                is equal to the context at the test case begin.  This helps to
2043                ensure that test cases are independent of each other.
2044
2045            TF.Usability.TestCase.Context.VerifyThread
2046                The test framework shall provide a function to ensure that the
2047                test case code executes in normal thread context.  This helps
2048                to ensure that operating system service calls return to a sane
2049                context.
2050
2051            TF.Usability.TestCase.Context.Configurable
2052                The context verified in test case shall be configurable at link-time.
2053
2054            TF.Usability.TestCase.Context.ThreadDispatchDisableLevel
2055                It shall be possible to verify the thread dispatch disable level.
2056
2057            TF.Usability.TestCase.Context.ISRNestLevel
2058                It shall be possible to verify the ISR nest level.
2059
2060            TF.Usability.TestCase.Context.InterruptLevel
2061                It shall be possible to verify the interrupt level (interrupts
2062                enabled/disabled).
2063
2064            TF.Usability.TestCase.Context.Workspace
2065                It shall be possible to verify the workspace.
2066
2067            TF.Usability.TestCase.Context.Heap
2068                It shall be possible to verify the heap.
2069
2070            TF.Usability.TestCase.Context.OpenFileDescriptors
2071                It shall be possible to verify the open file descriptors.
2072
2073            TF.Usability.TestCase.Context.Classic
2074                It shall be possible to verify Classic API objects.
2075
2076                TF.Usability.TestCase.Context.Classic.Barrier
2077                    It shall be possible to verify Classic API Barrier objects.
2078
2079                TF.Usability.TestCase.Context.Classic.Extensions
2080                    It shall be possible to verify Classic API User Extensions
2081                    objects.
2082
2083                TF.Usability.TestCase.Context.Classic.MessageQueues
2084                    It shall be possible to verify Classic API Message Queue
2085                    objects.
2086
2087                TF.Usability.TestCase.Context.Classic.Partitions
2088                    It shall be possible to verify Classic API Partition objects.
2089
2090                TF.Usability.TestCase.Context.Classic.Periods
2091                    It shall be possible to verify Classic API Rate Monotonic
2092                    Period objects.
2093
2094                TF.Usability.TestCase.Context.Classic.Regions
2095                    It shall be possible to verify Classic API Region objects.
2096
2097                TF.Usability.TestCase.Context.Classic.Semaphores
2098                    It shall be possible to verify Classic API Semaphore
2099                    objects.
2100
2101                TF.Usability.TestCase.Context.Classic.Tasks
2102                    It shall be possible to verify Classic API Task objects.
2103
2104                TF.Usability.TestCase.Context.Classic.Timers
2105                    It shall be possible to verify Classic API Timer objects.
2106
2107            TF.Usability.TestCase.Context.POSIX
2108                It shall be possible to verify POSIX API objects.
2109
2110                TF.Usability.TestCase.Context.POSIX.Keys
2111                    It shall be possible to verify POSIX API Key objects.
2112
2113                TF.Usability.TestCase.Context.POSIX.KeyValuePairs
2114                    It shall be possible to verify POSIX API Key Value Pair
2115                    objects.
2116
2117                TF.Usability.TestCase.Context.POSIX.MessageQueues
2118                    It shall be possible to verify POSIX API Message Queue
2119                    objects.
2120
2121                TF.Usability.TestCase.Context.POSIX.Semaphores
2122                    It shall be possible to verify POSIX API Named Semaphores
2123                    objects.
2124
2125                TF.Usability.TestCase.Context.POSIX.Shms
2126                    It shall be possible to verify POSIX API Shared Memory
2127                    objects.
2128
2129                TF.Usability.TestCase.Context.POSIX.Threads
2130                    It shall be possible to verify POSIX API Thread objects.
2131
2132                TF.Usability.TestCase.Context.POSIX.Timers
2133                    It shall be possible to verify POSIX API Timer objects.
2134
2135    TF.Usability.Assert
2136        There shall be functions to assert test objectives.
2137
2138        TF.Usability.Assert.Safe
2139            Test assert functions shall be safe to use, e.g. assert(a == b) vs.
2140            assert(a = b) vs. assert_eq(a, b).
2141
2142        TF.Usability.Assert.Continue
2143            There shall be assert functions which allow the test case to
2144            continue in case of an assertion failure.
2145
2146        TF.Usability.Assert.Abort
2147            There shall be assert functions which abourt the test case in case
2148            of an assertion failure.
2149
2150    TF.Usability.EasyToWrite
2151        It shall be easy to write test code, e.g. avoid long namespace prefix
2152        rtems_test_*.
2153
2154    TF.Usability.Threads
2155        The test framework shall support multi-threading.
2156
2157    TF.Usability.Pattern
2158        The test framework shall support test patterns.
2159
2160        TF.Usability.Pattern.Interrupts
2161            The test framework shall support test cases which use interrupts,
2162            e.g. spintrcritical*.
2163
2164        TF.Usability.Pattern.Parallel
2165            The test framework shall support test cases which want to run code
2166            in parallel on SMP machines.
2167
2168        TF.Usability.Pattern.Timing
2169            The test framework shall support test cases which want to measure
2170            the timing of code sections under various platform conditions, e.g.
2171            dirty cache, empty cache, hot cache, with load from other
2172            processors, etc..
2173
2174    TF.Usability.Configuration
2175        The test framework shall be configurable.
2176
2177        TF.Usability.Configuration.Time
2178            The timestamp function shall be configurable, e.g. to allow test
2179            runs without a clock driver.
2180
2181Performance Requirements
2182------------------------
2183
2184TF.Performance.RTEMS.No64BitDivision
2185    The test framework shall not use 64-bit divisions on RTEMS.
2186
2187Off-the-shelf Test Frameworks
2188=============================
2189
2190There are several
2191`off-the-shelf test frameworks for C/C++ <https://en.wikipedia.org/wiki/List_of_unit_testing_frameworks#C>`_.
2192The first obstacle for test frameworks is the license requirement
2193(`TF.License.Permissive`).
2194
2195bdd-for-c
2196---------
2197
2198In the `bdd-for-c <https://github.com/grassator/bdd-for-c>`_ framework the
2199complete test suite must be contained in one file and the main function is
2200generated.  This violates `TF.Usability.TestCase.Independence`.
2201
2202CBDD
2203----
2204
2205The `CBDD <https://github.com/nassersala/cbdd>`_ framework uses the
2206`C blocks <https://clang.llvm.org/docs/BlockLanguageSpec.html>`_ extension from
2207clang.  This violates `TF.Portability.C11`.
2208
2209Google Test
2210-----------
2211
2212`Google Test 1.8.1 <https://git.rtems.org/sebh/rtems-gtest.git/>`_
2213is supported by RTEMS.  Unfortunately, it is written in C++ and is to heavy
2214weight for low-end platforms.  Otherwise it is a nice framework.
2215
2216Unity
2217-----
2218
2219The `Unity Test API <https://github.com/ThrowTheSwitch/Unity>`_ does not meet
2220our requirements.  There was a `discussion on the mailing list in 2013
2221<https://lists.rtems.org/pipermail/devel/2013-September/004499.html>`_.
2222
2223Standard Test Report Formats
2224============================
2225
2226JUnit XML
2227---------
2228
2229A common test report format is `JUnit XML <http://llg.cubic.org/docs/junit/>`_.
2230
2231.. code-block:: xml
2232
2233    <?xml version="1.0" encoding="UTF-8" ?>
2234    <testsuites id="xyz" name="abc" tests="225" failures="1262" time="0.001">
2235      <testsuite id="def" name="ghi" tests="45" failures="17" time="0.001">
2236        <testcase id="jkl" name="mno" time="0.001">
2237          <failure message="pqr" type="stu"></failure>
2238          <system-out>stdout</system-out>
2239          <system-err>stderr</system-err>
2240        </testcase>
2241      </testsuite>
2242    </testsuites>
2243
2244The major problem with this format is that you have to output the failure count
2245of all test suites and the individual test suite before the test case output.
2246You know the failure count only after a complete test run.  This runs contrary
2247to requirement `TF.Portability.Small.Memory`.  It is also a bit verbose
2248(`TF.Reporting.Compact`).
2249
2250It is easy to convert a full test report generated by :ref:`The RTEMS Test
2251Framework <RTEMSTestFramework>` to the JUnit XML format.
2252
2253Test Anything Protocol
2254----------------------
2255
2256The
2257`Test Anything Protocol <http://testanything.org/>`_
2258(TAP) is easy to consume and produce.
2259
2260.. code-block:: none
2261
2262    1..4
2263    ok 1 - Input file opened
2264    not ok 2 - First line of the input valid
2265    ok 3 - Read the rest of the file
2266    not ok 4 - Summarized correctly # TODO Not written yet
2267
2268You have to know in advance how many test statements you want to execute in a
2269test case.  The problem with this format is that there is no standard way to
2270provide auxiliary data such as test timing or a tracing report.
2271
2272It is easy to convert a full test report generated by :ref:`The RTEMS Test
2273Framework <RTEMSTestFramework>` to the TAP format.
Note: See TracBrowser for help on using the repository browser.