source: trunk/IPs/systemC/processor/Morpheo/Common/include/Test.h @ 81

Last change on this file since 81 was 81, checked in by rosiere, 16 years ago
  • Finish Environment (and test)
  • Continue predictor_unit
  • Add external tools
  • svn keyword "Id" set
  • Property svn:keywords set to Id
File size: 3.5 KB
Line 
1#ifndef TEST_H
2#define TEST_H
3
4#include <iostream>
5#include <sstream>
6#include <stdint.h>
7#include "Common/include/Message.h"
8#include "Common/include/ErrorMorpheo.h"
9#include "Common/include/ToString.h"
10
11namespace morpheo {
12
13//-----[ Routine de test ]---------------------------------------
14
15static uint32_t num_test;
16
17inline void test_ko_error (void)
18{
19  std::string msg = "Test ko : error in test \""+morpheo::toString(num_test)+"\"";
20  throw (morpheo::ErrorMorpheo (msg));
21}
22 
23template <class T>
24inline void test_ko (char * file, uint32_t line, T exp1, T exp2)
25{
26  std::cerr << "[" << num_test << "] : Test KO"
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;
34
35  test_ko_error ();
36};
37
38inline void test_ko (char * file, uint32_t line)
39{
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;
45 
46  test_ko_error ();
47};
48
49inline void test_ok ()
50{
51  msg (_("[%d] : Test OK\n"), num_test);
52
53  num_test ++;
54};
55
56inline void test_ok (char * file, uint32_t line)
57{
58  msg (_("[%d] : Test OK\n"), num_test);
59  msg (_("\tline %d\n"), line);
60
61  num_test ++;
62};
63
64template <class T>
65inline void test_ok (char * file, uint32_t line, T exp)
66{
67  msg (_("[%d] : Test OK\n"), num_test);
68  msg (_("\tline %d\n"), line);
69  msg (_("\tvalue %s\n"), (morpheo::toString(exp)).c_str());
70
71  num_test ++;
72}
73
74template <class T>
75inline void test(char * file, uint32_t line, T exp1, T exp2)
76{
77  if (exp1 != exp2)
78    test_ko <T> (file,line,exp1,exp2);
79  else
80    test_ok <T> (file,line,exp1);
81};
82
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)
87
88
89#define LABEL(str...)                                                   \
90  {                                                                     \
91    msg (_("{%d} "),static_cast<uint32_t>(sc_simulation_time()));       \
92    msg (str);                                                          \
93    msg (_("\n"));                                                      \
94  } while(0)
95
96
97#ifndef CYCLE_MAX
98# error "CYCLE_MAX must be defined";
99#endif
100
101#define SC_START(cycle_offset)                                          \
102  do                                                                    \
103    {                                                                   \
104      /*cout << "SC_START (begin)" << endl;*/                           \
105                                                                        \
106      uint32_t cycle_current = static_cast<uint32_t>(sc_simulation_time()); \
107      if (cycle_offset != 0)                                            \
108        {                                                               \
109          cout << "##########[ cycle "<< cycle_current+cycle_offset << " ] (" << __LINE__ << ")" << endl; \
110        }                                                               \
111                                                                        \
112      if (cycle_current > CYCLE_MAX)                                    \
113        {                                                               \
114          TEST_KO("Maximal cycles Reached");                            \
115        }                                                               \
116                                                                        \
117      sc_start(cycle_offset);                                           \
118                                                                        \
119      /*cout << "SC_START (end  )" << endl;*/                           \
120    } while(0)
121
122
123
124};
125#endif
Note: See TracBrowser for help on using the repository browser.