1 | #ifndef Morpheo_Test_h |
---|
2 | #define Morpheo_Test_h |
---|
3 | |
---|
4 | /* |
---|
5 | * $Id: Test.h 131 2009-07-08 18:40:08Z rosiere $ |
---|
6 | * |
---|
7 | * [ Description ] |
---|
8 | * |
---|
9 | * Macro / function to test |
---|
10 | */ |
---|
11 | |
---|
12 | #include <iostream> |
---|
13 | #include <sstream> |
---|
14 | #include <stdint.h> |
---|
15 | #include "Common/include/Message.h" |
---|
16 | #include "Common/include/ErrorMorpheo.h" |
---|
17 | #include "Common/include/ToString.h" |
---|
18 | #include "Common/include/Systemc.h" |
---|
19 | namespace morpheo { |
---|
20 | |
---|
21 | #define STR_OK "Test OK" |
---|
22 | #define STR_KO "Test KO" |
---|
23 | |
---|
24 | static uint32_t num_test; |
---|
25 | |
---|
26 | inline void test_ko_error (void) |
---|
27 | { |
---|
28 | std::string msg = morpheo::toString(_("Test ko : error in test \"%d\""),num_test); |
---|
29 | throw (morpheo::ErrorMorpheo (msg)); |
---|
30 | } |
---|
31 | |
---|
32 | template <class T> |
---|
33 | inline void test_ko (char * file, uint32_t line, T exp1, T exp2) |
---|
34 | { |
---|
35 | msgError(_("[%d] : %s\n"),num_test,STR_KO); |
---|
36 | msgError(_(" * Localisation\n")); |
---|
37 | msgError(_(" - File : %s\n"),file); |
---|
38 | msgError(_(" - Line : %d\n"),line); |
---|
39 | msgError(_(" * Expression is different\n")); |
---|
40 | msgError(_(" - exp1 : %s\n"),morpheo::toString(exp1).c_str()); |
---|
41 | msgError(_(" - exp2 : %s\n"),morpheo::toString(exp2).c_str()); |
---|
42 | |
---|
43 | test_ko_error (); |
---|
44 | }; |
---|
45 | |
---|
46 | inline void test_ko (char * file, uint32_t line) |
---|
47 | { |
---|
48 | msgError(_("[%d] : %s\n"),num_test,STR_KO); |
---|
49 | msgError(_(" * Localisation\n")); |
---|
50 | msgError(_(" - File : %s\n"),file); |
---|
51 | msgError(_(" - Line : %d\n"),line); |
---|
52 | |
---|
53 | test_ko_error (); |
---|
54 | }; |
---|
55 | |
---|
56 | inline void test_ok () |
---|
57 | { |
---|
58 | msgInformation (_("[%d] : %s\n"), num_test,STR_OK); |
---|
59 | |
---|
60 | num_test ++; |
---|
61 | }; |
---|
62 | |
---|
63 | inline void test_ok (char * file, uint32_t line) |
---|
64 | { |
---|
65 | msgInformation (_("[%d] : %s (line %d)\n"), num_test,STR_OK,line); |
---|
66 | msgInformation (_(" - Line : %d\n"), line); |
---|
67 | |
---|
68 | num_test ++; |
---|
69 | }; |
---|
70 | |
---|
71 | template <class T> |
---|
72 | inline void test_ok (char * file, uint32_t line, T exp) |
---|
73 | { |
---|
74 | msgInformation (_("[%d] : %s\n"), num_test, STR_OK); |
---|
75 | msgInformation (_(" - Line : %d\n"), line); |
---|
76 | msgInformation (_(" - Value : %s\n"), (morpheo::toString(exp)).c_str()); |
---|
77 | |
---|
78 | num_test ++; |
---|
79 | } |
---|
80 | |
---|
81 | template <class T> |
---|
82 | inline void test(char * file, uint32_t line, T exp1, T exp2) |
---|
83 | { |
---|
84 | if (exp1 != exp2) |
---|
85 | test_ko <T> (file,line,exp1,exp2); |
---|
86 | else |
---|
87 | test_ok <T> (file,line,exp1); |
---|
88 | }; |
---|
89 | |
---|
90 | #define TEST(type,exp1,exp2) do {morpheo::test<type> (__FILE__,__LINE__,exp1,exp2);} while(0) |
---|
91 | #define TEST_STR(type,exp1,exp2,str...) do {fprintf(stdout,str); fprintf(stdout,"\n"); morpheo::test<type> (__FILE__,__LINE__,exp1,exp2);} while(0) |
---|
92 | #define TEST_OK(str...) do {fprintf(stdout,str); fprintf(stdout,"\n"); morpheo::test_ok(__FILE__,__LINE__);} while(0) |
---|
93 | #define TEST_KO(str...) do {fprintf(stdout,str); fprintf(stdout,"\n"); morpheo::test_ko(__FILE__,__LINE__);} while(0) |
---|
94 | |
---|
95 | #define LABEL(str...) \ |
---|
96 | { \ |
---|
97 | msgInformation (_("{%.0f} "),simulation_cycle()); \ |
---|
98 | msg (str); \ |
---|
99 | msg (_("\n")); \ |
---|
100 | } while(0) |
---|
101 | |
---|
102 | #ifndef CYCLE_MAX |
---|
103 | # error "CYCLE_MAX must be defined"; |
---|
104 | #endif |
---|
105 | |
---|
106 | #define SC_CYCLE(cycle_offset) \ |
---|
107 | do \ |
---|
108 | { \ |
---|
109 | /*cout << "SC_CYCLE (begin)" << endl;*/ \ |
---|
110 | \ |
---|
111 | double cycle_current = simulation_cycle(); \ |
---|
112 | if (cycle_offset != 0) \ |
---|
113 | { \ |
---|
114 | msgInformation(_("##########[ cycle %.0f ] (%d)\n"),cycle_current+cycle_offset,__LINE__); \ |
---|
115 | } \ |
---|
116 | \ |
---|
117 | if ((CYCLE_MAX != 0) and (cycle_current > CYCLE_MAX)) \ |
---|
118 | { \ |
---|
119 | TEST_KO("Maximal cycles Reached"); \ |
---|
120 | } \ |
---|
121 | \ |
---|
122 | simulation_run(cycle_offset); \ |
---|
123 | \ |
---|
124 | /*cout << "SC_CYCLE (end )" << endl;*/ \ |
---|
125 | } while(0) |
---|
126 | |
---|
127 | // old support |
---|
128 | #ifndef MTI_SYSTEMC |
---|
129 | # define SC_START(x) SC_CYCLE(x) |
---|
130 | #endif |
---|
131 | |
---|
132 | }; |
---|
133 | #endif |
---|