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