[88] | 1 | #ifndef Morpheo_Test_h |
---|
| 2 | #define Morpheo_Test_h |
---|
[2] | 3 | |
---|
[88] | 4 | /* |
---|
| 5 | * $Id: Test.h 88 2008-12-10 18:31:39Z 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" |
---|
[2] | 18 | |
---|
[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 | { |
---|
[75] | 28 | std::string msg = "Test ko : error in test \""+morpheo::toString(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 | { |
---|
[88] | 35 | fflush (stdout); |
---|
| 36 | fflush (stderr); |
---|
| 37 | |
---|
| 38 | std::cerr << "[" << num_test << "] : " << STR_KO |
---|
[83] | 39 | << "\tline " << line << std::endl |
---|
| 40 | << " * Localisation" << std::endl |
---|
| 41 | << " - File : " << file << std::endl |
---|
| 42 | << " - Line : " << line << std::endl |
---|
| 43 | << " * Expression is different" << std::endl |
---|
| 44 | << " - exp1 : "+morpheo::toString(exp1) << std::endl |
---|
| 45 | << " - exp2 : "+morpheo::toString(exp2) << std::endl; |
---|
[53] | 46 | |
---|
| 47 | test_ko_error (); |
---|
[2] | 48 | }; |
---|
| 49 | |
---|
[71] | 50 | inline void test_ko (char * file, uint32_t line) |
---|
[50] | 51 | { |
---|
[88] | 52 | fflush (stdout); |
---|
| 53 | fflush (stderr); |
---|
| 54 | |
---|
| 55 | std::cerr << "[" << num_test << "] : " << STR_KO |
---|
[75] | 56 | << "\tline " << line << std::endl |
---|
| 57 | << " * Localisation" << std::endl |
---|
| 58 | << " - File : " << file << std::endl |
---|
| 59 | << " - Line : " << line << std::endl; |
---|
[50] | 60 | |
---|
[53] | 61 | test_ko_error (); |
---|
[50] | 62 | }; |
---|
| 63 | |
---|
[71] | 64 | inline void test_ok () |
---|
[2] | 65 | { |
---|
[88] | 66 | fflush (stdout); |
---|
| 67 | fflush (stderr); |
---|
[2] | 68 | |
---|
[88] | 69 | msg (_("[%d] : %s\n"), num_test,STR_OK); |
---|
| 70 | |
---|
[2] | 71 | num_test ++; |
---|
| 72 | }; |
---|
| 73 | |
---|
[71] | 74 | inline void test_ok (char * file, uint32_t line) |
---|
[53] | 75 | { |
---|
[88] | 76 | fflush (stdout); |
---|
| 77 | fflush (stderr); |
---|
| 78 | |
---|
| 79 | msg (_("[%d] : %s\n"), num_test,STR_OK); |
---|
[71] | 80 | msg (_("\tline %d\n"), line); |
---|
[53] | 81 | |
---|
| 82 | num_test ++; |
---|
| 83 | }; |
---|
| 84 | |
---|
[2] | 85 | template <class T> |
---|
[71] | 86 | inline void test_ok (char * file, uint32_t line, T exp) |
---|
[2] | 87 | { |
---|
[88] | 88 | fflush (stdout); |
---|
| 89 | fflush (stderr); |
---|
| 90 | |
---|
| 91 | msg (_("[%d] : %s\n"), num_test, STR_OK); |
---|
[71] | 92 | msg (_("\tline %d\n"), line); |
---|
| 93 | msg (_("\tvalue %s\n"), (morpheo::toString(exp)).c_str()); |
---|
[53] | 94 | |
---|
| 95 | num_test ++; |
---|
| 96 | } |
---|
| 97 | |
---|
| 98 | template <class T> |
---|
[71] | 99 | inline void test(char * file, uint32_t line, T exp1, T exp2) |
---|
[53] | 100 | { |
---|
[2] | 101 | if (exp1 != exp2) |
---|
[53] | 102 | test_ko <T> (file,line,exp1,exp2); |
---|
[2] | 103 | else |
---|
[53] | 104 | test_ok <T> (file,line,exp1); |
---|
[2] | 105 | }; |
---|
| 106 | |
---|
[75] | 107 | #define TEST(type,exp1,exp2) do {morpheo::test<type> (__FILE__,__LINE__,exp1,exp2);} while(0) |
---|
| 108 | #define TEST_STR(type,exp1,exp2,str...) do {fprintf(stdout,str); fprintf(stdout,"\n"); morpheo::test<type> (__FILE__,__LINE__,exp1,exp2);} while(0) |
---|
| 109 | #define TEST_OK(str...) do {fprintf(stdout,str); fprintf(stdout,"\n"); morpheo::test_ok(__FILE__,__LINE__);} while(0) |
---|
| 110 | #define TEST_KO(str...) do {fprintf(stdout,str); fprintf(stdout,"\n"); morpheo::test_ko(__FILE__,__LINE__);} while(0) |
---|
[2] | 111 | |
---|
[81] | 112 | #define LABEL(str...) \ |
---|
| 113 | { \ |
---|
| 114 | msg (_("{%d} "),static_cast<uint32_t>(sc_simulation_time())); \ |
---|
| 115 | msg (str); \ |
---|
| 116 | msg (_("\n")); \ |
---|
[88] | 117 | fflush (stdout); \ |
---|
[81] | 118 | } while(0) |
---|
| 119 | |
---|
| 120 | #ifndef CYCLE_MAX |
---|
| 121 | # error "CYCLE_MAX must be defined"; |
---|
| 122 | #endif |
---|
| 123 | |
---|
| 124 | #define SC_START(cycle_offset) \ |
---|
| 125 | do \ |
---|
| 126 | { \ |
---|
| 127 | /*cout << "SC_START (begin)" << endl;*/ \ |
---|
| 128 | \ |
---|
| 129 | uint32_t cycle_current = static_cast<uint32_t>(sc_simulation_time()); \ |
---|
| 130 | if (cycle_offset != 0) \ |
---|
| 131 | { \ |
---|
| 132 | cout << "##########[ cycle "<< cycle_current+cycle_offset << " ] (" << __LINE__ << ")" << endl; \ |
---|
| 133 | } \ |
---|
| 134 | \ |
---|
[88] | 135 | if ((CYCLE_MAX != 0) and (cycle_current > CYCLE_MAX)) \ |
---|
[81] | 136 | { \ |
---|
| 137 | TEST_KO("Maximal cycles Reached"); \ |
---|
| 138 | } \ |
---|
| 139 | \ |
---|
| 140 | sc_start(cycle_offset); \ |
---|
| 141 | \ |
---|
| 142 | /*cout << "SC_START (end )" << endl;*/ \ |
---|
| 143 | } while(0) |
---|
| 144 | |
---|
| 145 | |
---|
| 146 | |
---|
[75] | 147 | }; |
---|
[2] | 148 | #endif |
---|