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
RevLine 
[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]11namespace morpheo {
12
[2]13//-----[ Routine de test ]---------------------------------------
14
15static uint32_t num_test;
16
[71]17inline 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]23template <class T>
[71]24inline void test_ko (char * file, uint32_t line, T exp1, T exp2)
[2]25{
[75]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;
[53]34
35  test_ko_error ();
[2]36};
37
[71]38inline 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]49inline void test_ok ()
[2]50{
[71]51  msg (_("[%d] : Test OK\n"), num_test);
[2]52
53  num_test ++;
54};
55
[71]56inline 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]64template <class T>
[71]65inline 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
74template <class T>
[71]75inline 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
[50]88
[81]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
[75]124};
[2]125#endif
Note: See TracBrowser for help on using the repository browser.