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