1 | /* |
---|
2 | * $Id$ |
---|
3 | * |
---|
4 | * [ Description ] |
---|
5 | * |
---|
6 | * Test |
---|
7 | */ |
---|
8 | |
---|
9 | #define NB_ITERATION 1024 |
---|
10 | |
---|
11 | #include "Behavioural/Generic/Counter/SelfTest/include/test.h" |
---|
12 | #include "Common/include/Test.h" |
---|
13 | |
---|
14 | void test (string name, |
---|
15 | morpheo::behavioural::generic::counter::Parameters param) |
---|
16 | { |
---|
17 | cout << "<" << name << "> : Simulation SystemC" << endl; |
---|
18 | |
---|
19 | try |
---|
20 | { |
---|
21 | cout << param.print(1); |
---|
22 | param.test(); |
---|
23 | } |
---|
24 | catch (morpheo::ErrorMorpheo & error) |
---|
25 | { |
---|
26 | cout << "<" << name << "> : " << error.what (); |
---|
27 | return; |
---|
28 | } |
---|
29 | catch (...) |
---|
30 | { |
---|
31 | cerr << "<" << name << "> : This test must generate a error" << endl; |
---|
32 | exit (EXIT_FAILURE); |
---|
33 | } |
---|
34 | Counter * _Counter = new Counter (name.c_str(), |
---|
35 | #ifdef STATISTICS |
---|
36 | morpheo::behavioural::Parameters_Statistics(5,50), |
---|
37 | #endif |
---|
38 | param); |
---|
39 | |
---|
40 | #ifdef SYSTEMC |
---|
41 | /********************************************************************* |
---|
42 | * Déclarations des signaux |
---|
43 | *********************************************************************/ |
---|
44 | sc_clock CLOCK ("clock", 1.0, 0.5); |
---|
45 | sc_signal<Tcontrol_t> RESET; |
---|
46 | sc_signal<Tdata_t> DATA_IN [param._nb_port]; |
---|
47 | sc_signal<Tcontrol_t> ADDSUB [param._nb_port]; |
---|
48 | sc_signal<Tdata_t> DATA_OUT [param._nb_port]; |
---|
49 | |
---|
50 | /******************************************************** |
---|
51 | * Instanciation |
---|
52 | ********************************************************/ |
---|
53 | |
---|
54 | cout << "<" << name << "> Instanciation of _Counter" << endl; |
---|
55 | |
---|
56 | (*(_Counter->in_CLOCK)) (CLOCK); |
---|
57 | (*(_Counter->in_NRESET)) (RESET); |
---|
58 | |
---|
59 | for (uint32_t i=0; i<param._nb_port; i++) |
---|
60 | { |
---|
61 | (*(_Counter-> in_COUNTER_DATA [i])) (DATA_IN [i]); |
---|
62 | (*(_Counter-> in_COUNTER_ADDSUB[i])) (ADDSUB [i]); |
---|
63 | (*(_Counter->out_COUNTER_DATA [i])) (DATA_OUT [i]); |
---|
64 | } |
---|
65 | |
---|
66 | /******************************************************** |
---|
67 | * Simulation - Begin |
---|
68 | ********************************************************/ |
---|
69 | |
---|
70 | cout << "<" << name << "> Start Simulation ............" << endl; |
---|
71 | // Initialisation |
---|
72 | |
---|
73 | srand(0); |
---|
74 | //srand(TIME(NULL)); |
---|
75 | |
---|
76 | Tdata_t data_in [param._nb_port]; |
---|
77 | Tdata_t data_out [param._nb_port]; |
---|
78 | Tcontrol_t addsub [param._nb_port]; |
---|
79 | |
---|
80 | sc_start(0); |
---|
81 | |
---|
82 | RESET.write(1); |
---|
83 | |
---|
84 | cout << "{"+toString(static_cast<uint32_t>(sc_simulation_time()))+"} Initialisation" << endl; |
---|
85 | |
---|
86 | cout << "{"+toString(static_cast<uint32_t>(sc_simulation_time()))+"} Loop of Test" << endl; |
---|
87 | |
---|
88 | for (uint32_t iteration=0; iteration<NB_ITERATION; iteration ++) |
---|
89 | { |
---|
90 | cout << "{" << static_cast<uint32_t>(sc_simulation_time()) << "} Itération " << iteration << endl; |
---|
91 | for (uint32_t i=0; i<param._nb_port; i++) |
---|
92 | { |
---|
93 | Tdata_t data = rand()%param._data_max; |
---|
94 | data_in [i] = data; |
---|
95 | addsub [i] = (rand()%2)==1; |
---|
96 | |
---|
97 | DATA_IN [i].write(data ); |
---|
98 | ADDSUB [i].write(addsub [i]); |
---|
99 | |
---|
100 | data_out [i] = (addsub[i]==1)?((data<param._data_max)?data+1:data):((data>0)?data-1:data); |
---|
101 | } |
---|
102 | |
---|
103 | sc_start(0); |
---|
104 | |
---|
105 | for (uint32_t i=0; i<param._nb_port; i++) |
---|
106 | { |
---|
107 | cout << hex |
---|
108 | << " [" << i << "] " |
---|
109 | << data_in [i]; |
---|
110 | |
---|
111 | if (addsub[i] == 1) |
---|
112 | cout << " ++"; |
---|
113 | else |
---|
114 | cout << " --"; |
---|
115 | |
---|
116 | cout << " = " |
---|
117 | << DATA_OUT [i].read(); |
---|
118 | |
---|
119 | TEST(Tdata_t,DATA_OUT [i].read(),data_out [i]); |
---|
120 | |
---|
121 | cout << dec << endl; |
---|
122 | } |
---|
123 | |
---|
124 | sc_start(1); |
---|
125 | } |
---|
126 | |
---|
127 | sc_start(1); |
---|
128 | |
---|
129 | /******************************************************** |
---|
130 | * Simulation - End |
---|
131 | ********************************************************/ |
---|
132 | |
---|
133 | cout << "<" << name << "> ............ Stop Simulation" << endl; |
---|
134 | |
---|
135 | #endif |
---|
136 | |
---|
137 | delete _Counter; |
---|
138 | } |
---|