cloudFPGA (cF) API  1.0
The documentation of the source code of cloudFPGA (cF)
test_uppercase.cpp
Go to the documentation of this file.
1 
17 
36 #include "../../uppercase/include/uppercase.hpp"
37 #include "../../common/src/common.cpp"
38 
39 using namespace std;
40 
41 //---------------------------------------------------------
42 // HELPERS FOR THE DEBUGGING TRACES
43 // .e.g: DEBUG_LEVEL = (MDL_TRACE | IPS_TRACE)
44 //---------------------------------------------------------
45 #define THIS_NAME "TB"
46 
47 #define TRACE_OFF 0x0000
48 #define TRACE_URIF 1 << 1
49 #define TRACE_UAF 1 << 2
50 #define TRACE_MMIO 1 << 3
51 #define TRACE_ALL 0xFFFF
52 
53 #define DEBUG_LEVEL (TRACE_ALL)
54 
55 
56 //------------------------------------------------------
57 //-- TESTBENCH DEFINES
58 //------------------------------------------------------
59 #define OK true
60 #define KO false
61 #define VALID true
62 #define UNVALID false
63 #define DEBUG_TRACE true
64 #define DEBUG_MULTI_RUNS True
65 #define TB_MULTI_RUNS_ITERATIONS 2
66 
67 #define ENABLED (ap_uint<1>)1
68 #define DISABLED (ap_uint<1>)0
69 
70 
71 //------------------------------------------------------
72 //-- DUT INTERFACES AS GLOBAL VARIABLES
73 //------------------------------------------------------
74 
75 //-- SHELL / Uaf / Mmio / Config Interfaces
76 //ap_uint<2> piSHL_This_MmioEchoCtrl;
79 
80 //-- SHELL / Uaf / Udp Interfaces
81 stream<UdpWord> sSHL_Uaf_Data ("sSHL_Uaf_Data");
82 stream<UdpWord> sUAF_Shl_Data ("sUAF_Shl_Data");
83 stream<UdpWord> image_stream_from_uppercase ("image_stream_from_uppercase");
84 
85 ap_uint<32> s_udp_rx_ports = 0x0;
86 stream<NetworkMetaStream> siUdp_meta ("siUdp_meta");
87 stream<NetworkMetaStream> soUdp_meta ("soUdp_meta");
88 ap_uint<32> node_rank;
89 ap_uint<32> cluster_size;
90 
91 //------------------------------------------------------
92 //-- TESTBENCH GLOBAL VARIABLES
93 //------------------------------------------------------
94 unsigned int simCnt;
95 //------------------------------------------------------
96 //-- SHELL / Role / Mem / Mp1 Interface
97 //------------------------------------------------------
98 #ifdef ENABLE_DDR
99 #define MEMORY_LINES_512 TOTMEMDW_512 /* 100 Byte */
102 #endif
103 
104 
108 void stepDut() {
109  uppercase(
110  &node_rank,
111  &cluster_size,
114  siUdp_meta,
115  soUdp_meta,
117  #ifdef ENABLE_DDR
118  ,
119  lcl_mem0,
120  lcl_mem0
121  #endif
122  );
123  simCnt++;
124  //memcpy(lcl_mem1,lcl_mem0,MEMORY_LINES_512*sizeof(membus_t));
125  printf("[%4.4d] STEP DUT \n", simCnt);
126 }
127 
128 
129 
130 
135 int main(int argc, char** argv) {
136 
137  //------------------------------------------------------
138  //-- TESTBENCH LOCAL VARIABLES
139  //------------------------------------------------------
140  int nrErr = 0;
141 
142  printf("#####################################################\n");
143  printf("## TESTBENCH STARTS HERE ##\n");
144  printf("#####################################################\n");
145 
146  simCnt = 0;
147  nrErr = 0;
148 
149  if (argc != 2) {
150  printf("Usage : %s <input string> , provided %d\n", argv[0], argc);
151  return -1;
152  }
153 
154  string tmp_string= argv[1];
155  string strInput;
156 
157  //clean the corners if make or other utilities insert this weird ticks at the beginning of the string
158  if(isCornerPresent(tmp_string,"'") or isCornerPresent(tmp_string,"`") or isCornerPresent(tmp_string,"\"") ){
159  tmp_string = tmp_string.substr(1,tmp_string.length()-2);
160  }
161 
162  strInput = tmp_string;
163  if (!strInput.length()) {
164  printf("ERROR: Empty string provided. Aborting...\n");
165  return -1;
166  }
167  else {
168  printf("Succesfully loaded string ... %s\n", argv[1]);
169  // Ensure that the selection of MTU is a multiple of 8 (Bytes per transaction)
170  assert(PACK_SIZE % 8 == 0);
171  }
172 
173  //------------------------------------------------------
174  //-- TESTBENCH LOCAL VARIABLES FOR UPPERCASE
175  //------------------------------------------------------
176  unsigned int sim_time = 2 * CEIL(strInput.length(), 8) + 10;
177  unsigned int tot_trasnfers = (CEIL(strInput.length(), PACK_SIZE));
178  char *charOutput = (char*)malloc(strInput.length() * sizeof(char));
179  char *charInput = (char*)malloc(strInput.length() * sizeof(char));
180  if (!charOutput || !charInput) {
181  printf("ERROR: Cannot allocate memory for output string. Aborting...\n");
182  return -1;
183  }
184 
185 
186  //------------------------------------------------------
187  //-- STEP-1.1 : CREATE MEMORY FOR OUTPUT IMAGES
188  //------------------------------------------------------
189  if (!dumpStringToFile(strInput, "ifsSHL_Uaf_Data.dat", simCnt)) {
190  nrErr++;
191  }
192  //std::string strGold = createUppercaseGoldenOutput(strInput);
193  //if (!dumpStringToFile(strGold, "verify_UAF_Shl_Data.dat", simCnt)){
194  // nrErr++;
195  //}
200  #ifdef DEBUG_MULTI_RUNS // test if the HLS kernel has reinit issues with streams leftovers or other stuffs
201  for(int iterations=0; iterations < TB_MULTI_RUNS_ITERATIONS; iterations++){
202  #endif //DEBUG_MULTI_RUNS
203  #ifdef ENABLE_DDR
204  for(int i=0; i < MEMORY_LINES_512; i++){
205  lcl_mem0[i]=0;
206  lcl_mem1[i]=0;
207  }
208  #endif//ENABLE_DDR
209 
210  //------------------------------------------------------
211  //-- STEP-2.1 : CREATE TRAFFIC AS INPUT STREAMS
212  //------------------------------------------------------
213  if (nrErr == 0) {
214  if (!setInputDataStream(sSHL_Uaf_Data, "sSHL_Uaf_Data", "ifsSHL_Uaf_Data.dat", simCnt)) {
215  printf("### ERROR : Failed to set input data stream \"sSHL_Uaf_Data\". \n");
216  nrErr++;
217  }
218 
219  //there are tot_trasnfers streams from the the App to the Role
221  for (unsigned int i=0; i<tot_trasnfers; i++) {
222  siUdp_meta.write(NetworkMetaStream(tmp_meta));
223  }
224  //set correct node_rank and cluster_size
225  node_rank = 1;
226  cluster_size = 2;
227  }
228 
229  //------------------------------------------------------
230  //-- STEP-2.2 : SET THE PASS-THROUGH MODE
231  //------------------------------------------------------
232  //piSHL_This_MmioEchoCtrl.write(ECHO_PATH_THRU);
233  //[TODO] piSHL_This_MmioPostPktEn.write(DISABLED);
234  //[TODO] piSHL_This_MmioCaptPktEn.write(DISABLED);
235 
236  //------------------------------------------------------
237  //-- STEP-3 : MAIN TRAFFIC LOOP
238  //------------------------------------------------------
239  while (!nrErr) {
240 
241  // Keep enough simulation time for sequntially executing the FSMs of the main 3 functions
242  // (Rx-Tx)
243  if (simCnt < sim_time)
244  {
245  stepDut();
246 
247  if(simCnt > 2)
248  {
249  assert(s_udp_rx_ports == 0x1);
250  }
251 
252  //if( !soUdp_meta.empty())
253  //{
254  // NetworkMetaStream tmp_meta = soUdp_meta.read();
255  // printf("NRC received NRCmeta stream from node_rank %d.\n", (int) tmp_meta.tdata.src_rank);
256  //}
257 
258 
259  } else {
260  printf("## End of simulation at cycle=%3d. \n", simCnt);
261  break;
262  }
263 
264  } // End: while()
265 
266  //-------------------------------------------------------
267  //-- STEP-4 : DRAIN AND WRITE OUTPUT FILE STREAMS
268  //-------------------------------------------------------
269  //---- UAF-->SHELL Data ----
270  if (!getOutputDataStream(sUAF_Shl_Data, "sUAF_Shl_Data", "ofsUAF_Shl_Data.dat", simCnt))
271  {
272  nrErr++;
273  }
274  //---- UAF-->SHELL META ----
275  if( !soUdp_meta.empty())
276  {
277  unsigned int i = 0;
278  while( !soUdp_meta.empty())
279  {
280  i++;
281  NetworkMetaStream tmp_meta = soUdp_meta.read();
282  printf("NRC received NRCmeta stream from rank %d to rank %d.\n", (int) tmp_meta.tdata.src_rank, (int) tmp_meta.tdata.dst_rank);
283  assert(tmp_meta.tdata.src_rank == node_rank);
284  //ensure forwarding behavior
285  assert(tmp_meta.tdata.dst_rank == ((tmp_meta.tdata.src_rank + 1) % cluster_size));
286  }
287  assert(i == tot_trasnfers);
288  }
289  else {
290  printf("Error No metadata received...\n");
291  nrErr++;
292  }
293 
294  //-------------------------------------------------------
295  //-- STEP-5 : FROM THE OUTPUT FILE CREATE AN ARRAY
296  //-------------------------------------------------------
297  if (!dumpFileToString("ifsSHL_Uaf_Data.dat", charInput, simCnt)) {
298  printf("### ERROR : Failed to set string from file \"ofsUAF_Shl_Data.dat\". \n");
299  nrErr++;
300  }
301  printf("Input string : ");
302  for (unsigned int i = 0; i < strInput.length(); i++)
303  printf("%c", charInput[i]);
304  printf("\n");
305  if (!dumpFileToString("ofsUAF_Shl_Data.dat", charOutput, simCnt)) {
306  printf("### ERROR : Failed to set string from file \"ofsUAF_Shl_Data.dat\". \n");
307  nrErr++;
308  }
309  __file_write("./hls_out.txt", charOutput, strInput.length());
310  printf("Output string: ");
311  for (unsigned int i = 0; i < strInput.length(); i++)
312  printf("%c", charOutput[i]);
313  printf("\n");
314 
315  //------------------------------------------------------
316  //-- STEP-6 : COMPARE INPUT AND OUTPUT FILE STREAMS
317  //------------------------------------------------------
318  int rc1 = system("diff --brief -w -i -y ../../../../test/ofsUAF_Shl_Data.dat \
319  ../../../../test/verify_UAF_Shl_Data.dat");
320  if (rc1)
321  {
322  printf("## Error : File \'ofsUAF_Shl_Data.dat\' does not match \'verify_UAF_Shl_Data.dat\'.\n");
323  } else {
324  printf("Output data in file \'ofsUAF_Shl_Data.dat\' verified.\n");
325  }
326 
327  cout<< endl << " End the TB with iteration " << iterations << endl << endl;
328  nrErr += rc1;
329 
330  printf("#####################################################\n");
331  if (nrErr)
332  {
333  printf("## ERROR - TESTBENCH FAILED (RC=%d) !!! ##\n", nrErr);
334  } else {
335  printf("## SUCCESSFULL END OF TESTBENCH (RC=0) ##\n");
336  }
337  printf("#####################################################\n");
338 
339  simCnt = 0;//reset sim counter
340  nrErr=0;
341  #ifdef DEBUG_MULTI_RUNS
342  }
343  #endif//DEBUG_MULTI_RUNS
344 
345  //free dynamic memory
346  if(charOutput != NULL){
347  free(charOutput);
348  charOutput = NULL;
349  }
350  if(charInput != NULL){
351  free(charInput);
352  charInput = NULL;
353  }
354  return(nrErr);
355 }
356 
357 
358 
359 
bool dumpFileToString(const std::string inpFileName, std::string strOutput, int simCnt)
Initialize an input data stream from a file.
bool isCornerPresent(std::string str, std::string corner)
Check the presence of a given corner value at the begin and the end of a string.
bool dumpStringToFile(std::string s, const std::string outFileName, int simCnt)
Initialize an input data stream from a file.
#define ENABLE_DDR
Definition: memtest.hpp:42
membus_512_t membus_t
Definition: memtest.hpp:92
membus_t lcl_mem0[16384]
membus_t lcl_mem1[16384]
#define MEMORY_LINES_512
#define PACK_SIZE
Definition: config.h:51
#define CEIL(a, b)
Definition: config.h:37
bool setInputDataStream(stream< UdpAppData > &sDataStream, const string dataStreamName, const string inpFileName)
Initialize an input data stream from a file.
Definition: tb_nal.cpp:214
#define DEFAULT_RX_PORT
Definition: nal.hpp:139
bool getOutputDataStream(stream< UdpAppData > &sDataStream, const string dataStreamName, const string outFileName)
Fill an output file with data from an output stream.
Definition: tb_nal.cpp:526
void uppercase(ap_uint< 32 > *pi_rank, ap_uint< 32 > *pi_size, stream< NetworkWord > &siSHL_This_Data, stream< NetworkWord > &soTHIS_Shl_Data, stream< NetworkMetaStream > &siNrc_meta, stream< NetworkMetaStream > &soNrc_meta, ap_uint< 32 > *po_rx_ports)
Main process of the Uppercase Application directives.
Definition: uppercase.cpp:335
unsigned int simCnt
stream< NetworkMetaStream > siUdp_meta("siUdp_meta")
int main(int argc, char **argv)
Main testbench of Hrris.
stream< NetworkMetaStream > soUdp_meta("soUdp_meta")
#define TB_MULTI_RUNS_ITERATIONS
ap_uint< 1 > piSHL_This_MmioCaptPktEn
ap_uint< 1 > piSHL_This_MmioPostPktEn
stream< UdpWord > sUAF_Shl_Data("sUAF_Shl_Data")
stream< UdpWord > image_stream_from_uppercase("image_stream_from_uppercase")
void stepDut()
Run a single iteration of the DUT model.
stream< UdpWord > sSHL_Uaf_Data("sSHL_Uaf_Data")
ap_uint< 32 > cluster_size
ap_uint< 32 > s_udp_rx_ports
ap_uint< 32 > node_rank
NetworkMeta tdata
Definition: network.hpp:109
NodeId dst_rank
Definition: network.hpp:95
NodeId src_rank
Definition: network.hpp:97