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

Last change on this file since 71 was 71, checked in by rosiere, 16 years ago

Modification of Statisctics
Add a new systemC component : Load_Store_Queue (tested with one benchmark and one configuration). Store don't supported the Data Buss Error (Load is supported)

File size: 2.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
11//-----[ Routine de test ]---------------------------------------
12
13static uint32_t num_test;
14
15inline void test_ko_error (void)
16{
17  string msg = "Test ko : error in test \""+morpheo::toString(num_test)+"\"";
18  throw (morpheo::ErrorMorpheo (msg));
19}
20 
21template <class T>
22inline void test_ko (char * file, uint32_t line, T exp1, T exp2)
23{
24  cerr << "[" << num_test << "] : Test KO"
25       << "\tline " << line                           << endl
26       << " * Localisation"                           << endl
27       << "   - File : " << file                      << endl
28       << "   - Line : " << line                      << endl
29       << " * Expression is different"                << endl
30       << "   - exp1 : "+morpheo::toString(exp1)               << endl
31       << "   - exp2 : "+morpheo::toString(exp2)               << endl;
32
33  test_ko_error ();
34};
35
36inline void test_ko (char * file, uint32_t line)
37{
38  cerr << "[" << num_test << "] : Test KO"
39       << "\tline " << line                           << endl
40       << " * Localisation"                           << endl
41       << "   - File : " << file                      << endl
42       << "   - Line : " << line                      << endl;
43 
44  test_ko_error ();
45};
46
47inline void test_ok ()
48{
49  msg (_("[%d] : Test OK\n"), num_test);
50
51  num_test ++;
52};
53
54inline void test_ok (char * file, uint32_t line)
55{
56  msg (_("[%d] : Test OK\n"), num_test);
57  msg (_("\tline %d\n"), line);
58
59  num_test ++;
60};
61
62template <class T>
63inline void test_ok (char * file, uint32_t line, T exp)
64{
65  msg (_("[%d] : Test OK\n"), num_test);
66  msg (_("\tline %d\n"), line);
67  msg (_("\tvalue %s\n"), (morpheo::toString(exp)).c_str());
68
69  num_test ++;
70}
71
72template <class T>
73inline void test(char * file, uint32_t line, T exp1, T exp2)
74{
75  if (exp1 != exp2)
76    test_ko <T> (file,line,exp1,exp2);
77  else
78    test_ok <T> (file,line,exp1);
79};
80
81#define TEST(type,exp1,exp2)            do {test<type> (__FILE__,__LINE__,exp1,exp2);} while(0)
82#define TEST_STR(type,exp1,exp2,str...) do {fprintf(stdout,str); fprintf(stdout,"\n"); test<type> (__FILE__,__LINE__,exp1,exp2);} while(0)
83#define TEST_OK(str...)                 do {fprintf(stdout,str); fprintf(stdout,"\n"); test_ok(__FILE__,__LINE__);} while(0)
84#define TEST_KO(str...)                 do {fprintf(stdout,str); fprintf(stdout,"\n"); test_ko(__FILE__,__LINE__);} while(0)
85
86
87#endif
Note: See TracBrowser for help on using the repository browser.