]> rtime.felk.cvut.cz Git - arc.git/blob - system/kernel/testsystem/test_framework.c
Updated testsystem. Added test suites. Added Autostart tests. Autotester with T32.
[arc.git] / system / kernel / testsystem / test_framework.c
1 /* -------------------------------- Arctic Core ------------------------------
2  * Arctic Core - the open source AUTOSAR platform http://arccore.com
3  *
4  * Copyright (C) 2009  ArcCore AB <contact@arccore.com>
5  *
6  * This source code is free software; you can redistribute it and/or modify it
7  * under the terms of the GNU General Public License version 2 as published by the
8  * Free Software Foundation; See <http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt>.
9  *
10  * This program is distributed in the hope that it will be useful, but
11  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
12  * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
13  * for more details.
14  * -------------------------------- Arctic Core ------------------------------*/
15
16 #include <stdint.h>
17 #include <stdio.h>
18 #include "Platform_Types.h"
19 #include "test_framework.h"
20 #include "Cpu.h"
21 \r
22 int test_suite = 1;\r
23 int test_nr = 1;\r
24 int _test_ok = 0;\r
25 int _test_failed = 0;\r
26
27
28 int testCnt = 0;
29
30
31
32 struct test {
33         uint8_t testSuite;
34         uint8_t testNr;
35         uint16_t status;
36         const char *description;
37         uint32_t expectedErrMask;
38 };
39 \r
40 struct test testTable[50] = { {0} };
41
42
43 void testInit( void ) {
44
45 }
46 \r
47 void test_done( void ) {\r
48         printf( "\nTest summary\n"\r
49                                 "Total: %d\n"\r
50                                 "OK   : %d\n"\r
51                                 "FAIL : %d\n", _test_ok + _test_failed, _test_ok, _test_failed);\r
52 \r
53 }\r
54
55 /**
56  *
57  * @param text
58  * @param file
59  * @param line
60  * @param function
61  */\r
62 void test_fail( const char *text,char *file,  int line, const char *function ) {\r
63         printf("%02d %02d FAILED, %s , %d, %s\n",test_suite, test_nr, file, line, function);\r
64         testTable[testCnt].testSuite = test_suite;
65         testTable[testCnt].testNr = test_nr;
66         testTable[testCnt].status = TEST_FLG_ASSERT;
67 //      testCnt++;
68 //      _test_failed++;\r
69 }\r
70
71
72 /**
73  * Set errors that are expected during the test
74  * @param errMask
75  */
76 void testSetErrorMask( uint32_t errMask ) {
77
78 }
79
80
81 void testValidateHook( void ) {
82
83 }
84 /**
85  * Start a test
86  */
87 void testStart( const char *str, int testNr ) {
88         testTable[testCnt].status = TEST_FLG_RUNNING;
89         testTable[testCnt].testNr = testNr;
90         testTable[testCnt].description = str;
91         printf("%3d %3d %s\n",testCnt,testNr,str);
92 }
93
94 void testInc( void ) {
95         testCnt++;
96 }
97
98 /**
99  * End a testcase.
100  */
101 void testEnd( void ) {
102         uint16_t status = testTable[testCnt].status;
103
104         if( status & TEST_FLG_RUNNING ) {
105                 if( status & TEST_FLG_ASSERT ) {
106
107                 } else {
108                         /* All is OK */
109                         testTable[testCnt].status &= TEST_FLG_RUNNING;
110                         testTable[testCnt].status |= TEST_FLG_OK;
111                 }
112         } else {
113                 printf("testEnd() on a test that is not running\n");
114         }
115         testCnt++;
116 }
117
118 void testExit( int rv ) {
119         Irq_Disable();
120         exit(rv);
121 }
122
123 \r
124 void test_ok( void ) {\r
125         printf("%02d %02d OK\n",test_suite, test_nr);
126         testTable[testCnt].testSuite = test_suite;
127         testTable[testCnt].testNr = test_nr;
128         testTable[testCnt].status = 1;
129         testCnt++;\r
130         _test_ok++;\r
131 }\r
132