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

Last change on this file since 88 was 88, checked in by rosiere, 15 years ago

Almost complete design
with Test and test platform

  • Property svn:keywords set to Id
File size: 3.8 KB
Line 
1#ifndef Morpheo_Test_h
2#define Morpheo_Test_h
3
4/*
5 * $Id: Test.h 88 2008-12-10 18:31:39Z 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
19namespace morpheo {
20
21#define STR_OK "Test OK"
22#define STR_KO "Test KO"
23
24static uint32_t num_test;
25
26inline void test_ko_error (void)
27{
28  std::string msg = "Test ko : error in test \""+morpheo::toString(num_test)+"\"";
29  throw (morpheo::ErrorMorpheo (msg));
30}
31 
32template <class T>
33inline void test_ko (char * file, uint32_t line, T exp1, T exp2)
34{
35  fflush (stdout);
36  fflush (stderr);
37
38  std::cerr << "[" << num_test << "] : " << STR_KO
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;
46
47  test_ko_error ();
48};
49
50inline void test_ko (char * file, uint32_t line)
51{
52  fflush (stdout);
53  fflush (stderr);
54
55  std::cerr << "[" << num_test << "] : " << STR_KO
56       << "\tline " << line                           << std::endl
57       << " * Localisation"                           << std::endl
58       << "   - File : " << file                      << std::endl
59       << "   - Line : " << line                      << std::endl;
60 
61  test_ko_error ();
62};
63
64inline void test_ok ()
65{
66  fflush (stdout);
67  fflush (stderr);
68
69  msg (_("[%d] : %s\n"), num_test,STR_OK);
70
71  num_test ++;
72};
73
74inline void test_ok (char * file, uint32_t line)
75{
76  fflush (stdout);
77  fflush (stderr);
78
79  msg (_("[%d] : %s\n"), num_test,STR_OK);
80  msg (_("\tline %d\n"), line);
81
82  num_test ++;
83};
84
85template <class T>
86inline void test_ok (char * file, uint32_t line, T exp)
87{
88  fflush (stdout);
89  fflush (stderr);
90
91  msg (_("[%d] : %s\n"), num_test, STR_OK);
92  msg (_("\tline %d\n"), line);
93  msg (_("\tvalue %s\n"), (morpheo::toString(exp)).c_str());
94
95  num_test ++;
96}
97
98template <class T>
99inline void test(char * file, uint32_t line, T exp1, T exp2)
100{
101  if (exp1 != exp2)
102    test_ko <T> (file,line,exp1,exp2);
103  else
104    test_ok <T> (file,line,exp1);
105};
106
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)
111
112#define LABEL(str...)                                                   \
113  {                                                                     \
114    msg (_("{%d} "),static_cast<uint32_t>(sc_simulation_time()));       \
115    msg (str);                                                          \
116    msg (_("\n"));                                                      \
117    fflush (stdout);                                                    \
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                                                                        \
135      if ((CYCLE_MAX != 0) and (cycle_current > CYCLE_MAX))             \
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
147};
148#endif
Note: See TracBrowser for help on using the repository browser.