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 "../../common/src/common.cpp"
37 
38 using namespace std;
39 
40 //---------------------------------------------------------
41 // HELPERS FOR THE DEBUGGING TRACES
42 // .e.g: DEBUG_LEVEL = (MDL_TRACE | IPS_TRACE)
43 //---------------------------------------------------------
44 #define THIS_NAME "TB"
45 
46 #define TRACE_OFF 0x0000
47 #define TRACE_URIF 1 << 1
48 #define TRACE_UAF 1 << 2
49 #define TRACE_MMIO 1 << 3
50 #define TRACE_ALL 0xFFFF
51 
52 #define DEBUG_LEVEL (TRACE_ALL)
53 
54 
55 //------------------------------------------------------
56 //-- TESTBENCH DEFINES
57 //------------------------------------------------------
58 #define OK true
59 #define KO false
60 #define VALID true
61 #define UNVALID false
62 #define DEBUG_TRACE true
63 
64 #define ENABLED (ap_uint<1>)1
65 #define DISABLED (ap_uint<1>)0
66 
67 
68 //------------------------------------------------------
69 //-- DUT INTERFACES AS GLOBAL VARIABLES
70 //------------------------------------------------------
71 
72 //-- SHELL / Uaf / Mmio / Config Interfaces
73 //ap_uint<2> piSHL_This_MmioEchoCtrl;
76 
77 //-- SHELL / Uaf / Udp Interfaces
78 stream<UdpWord> sSHL_Uaf_Data ("sSHL_Uaf_Data");
79 stream<UdpWord> sUAF_Shl_Data ("sUAF_Shl_Data");
80 stream<UdpWord> image_stream_from_uppercase ("image_stream_from_uppercase");
81 
82 ap_uint<32> s_udp_rx_ports = 0x0;
83 stream<NetworkMetaStream> siUdp_meta ("siUdp_meta");
84 stream<NetworkMetaStream> soUdp_meta ("soUdp_meta");
85 ap_uint<32> node_rank;
86 ap_uint<32> cluster_size;
87 
88 //------------------------------------------------------
89 //-- TESTBENCH GLOBAL VARIABLES
90 //------------------------------------------------------
91 unsigned int simCnt;
92 
93 
94 
98 void stepDut() {
99  uppercase(
103  &s_udp_rx_ports);
104  simCnt++;
105  printf("[%4.4d] STEP DUT \n", simCnt);
106 }
107 
108 
109 
110 
115 int main(int argc, char** argv) {
116 
117  //------------------------------------------------------
118  //-- TESTBENCH LOCAL VARIABLES
119  //------------------------------------------------------
120  int nrErr = 0;
121 
122  printf("#####################################################\n");
123  printf("## TESTBENCH STARTS HERE ##\n");
124  printf("#####################################################\n");
125 
126  simCnt = 0;
127  nrErr = 0;
128 
129  if (argc != 2) {
130  printf("Usage : %s <input string> , provided %d\n", argv[0], argc);
131  return -1;
132  }
133  string strInput = argv[1];
134 
135  //clean the corners if make or other utilities insert this weird ticks at the beginning of the string
136  if(isCornerPresent(strInput,"'") or isCornerPresent(strInput,"`")){
137  strInput = strInput.substr(1,strInput.length()-2);
138  }
139  if (!strInput.length()) {
140  printf("ERROR: Empty string provided. Aborting...\n");
141  return -1;
142  }
143  else {
144  printf("Succesfully loaded string ... %s\n", argv[1]);
145  // Ensure that the selection of MTU is a multiple of 8 (Bytes per transaction)
146  assert(PACK_SIZE % 8 == 0);
147  }
148 
149  //------------------------------------------------------
150  //-- TESTBENCH LOCAL VARIABLES FOR UPPERCASE
151  //------------------------------------------------------
152  unsigned int sim_time = 2 * CEIL(strInput.length(), 8) + 10;
153  unsigned int tot_trasnfers = (CEIL(strInput.length()+1, PACK_SIZE));
154  char *charOutput = (char*)malloc((strInput.length()+8) * sizeof(char));
155  char *charInput = (char*)malloc((strInput.length())+8 * sizeof(char));
156  if (!charOutput || !charInput) {
157  printf("ERROR: Cannot allocate memory for output string. Aborting...\n");
158  return -1;
159  }
160 
161 
162  //------------------------------------------------------
163  //-- STEP-1.1 : CREATE MEMORY FOR OUTPUT IMAGES
164  //------------------------------------------------------
165  if (!dumpStringToFileWithCommands(strInput, "ifsSHL_Uaf_Data.dat", simCnt)) {
166  nrErr++;
167  }
168 
169  //------------------------------------------------------
170  //-- STEP-2.1 : CREATE TRAFFIC AS INPUT STREAMS
171  //------------------------------------------------------
172  if (nrErr == 0) {
173  if (!setInputDataStream(sSHL_Uaf_Data, "sSHL_Uaf_Data", "ifsSHL_Uaf_Data.dat", simCnt)) {
174  printf("### ERROR : Failed to set input data stream \"sSHL_Uaf_Data\". \n");
175  nrErr++;
176  }
177 
178  //there are tot_trasnfers streams from the the App to the Role
180  for (unsigned int i=0; i<tot_trasnfers; i++) {
181  siUdp_meta.write(NetworkMetaStream(tmp_meta));
182  }
183  //set correct node_rank and cluster_size
184  node_rank = 1;
185  cluster_size = 2;
186  }
187 
188  //------------------------------------------------------
189  //-- STEP-2.2 : SET THE PASS-THROUGH MODE
190  //------------------------------------------------------
191  //piSHL_This_MmioEchoCtrl.write(ECHO_PATH_THRU);
192  //[TODO] piSHL_This_MmioPostPktEn.write(DISABLED);
193  //[TODO] piSHL_This_MmioCaptPktEn.write(DISABLED);
194 
195  //------------------------------------------------------
196  //-- STEP-3 : MAIN TRAFFIC LOOP
197  //------------------------------------------------------
198  while (!nrErr) {
199 
200  // Keep enough simulation time for sequntially executing the FSMs of the main 3 functions
201  // (Rx-Tx)
202  if (simCnt < sim_time)
203  {
204  stepDut();
205 
206  if(simCnt > 2)
207  {
208  assert(s_udp_rx_ports == 0x1);
209  }
210 
211  //if( !soUdp_meta.empty())
212  //{
213  // NetworkMetaStream tmp_meta = soUdp_meta.read();
214  // printf("NRC received NRCmeta stream from node_rank %d.\n", (int) tmp_meta.tdata.src_rank);
215  //}
216 
217 
218  } else {
219  printf("## End of simulation at cycle=%3d. \n", simCnt);
220  break;
221  }
222 
223  } // End: while()
224 
225  //-------------------------------------------------------
226  //-- STEP-4 : DRAIN AND WRITE OUTPUT FILE STREAMS
227  //-------------------------------------------------------
228  //---- UAF-->SHELL Data ----
229  if (!getOutputDataStream(sUAF_Shl_Data, "sUAF_Shl_Data", "ofsUAF_Shl_Data.dat", simCnt))
230  {
231  nrErr++;
232  }
233  //---- UAF-->SHELL META ----
234  if( !soUdp_meta.empty())
235  {
236  unsigned int i = 0;
237  while( !soUdp_meta.empty())
238  {
239  i++;
240  NetworkMetaStream tmp_meta = soUdp_meta.read();
241  printf("NRC received NRCmeta stream from rank %d to rank %d.\n", (int) tmp_meta.tdata.src_rank, (int) tmp_meta.tdata.dst_rank);
242  assert(tmp_meta.tdata.src_rank == node_rank);
243  //ensure forwarding behavior
244  assert(tmp_meta.tdata.dst_rank == ((tmp_meta.tdata.src_rank + 1) % cluster_size));
245  }
246  assert(i == tot_trasnfers);
247  }
248  else {
249  printf("Error No metadata received...\n");
250  nrErr++;
251  }
252 
253  //-------------------------------------------------------
254  //-- STEP-5 : FROM THE OUTPUT FILE CREATE AN ARRAY
255  //-------------------------------------------------------
256  if (!dumpFileToStringWithoutCommands("ifsSHL_Uaf_Data.dat", charInput, simCnt)) {
257  printf("### ERROR : Failed to set string from file \"ofsUAF_Shl_Data.dat\". \n");
258  nrErr++;
259  }
260  printf("Input string : ");
261  for (unsigned int i = 0; i < strInput.length(); i++)
262  printf("%c", charInput[i]);
263  printf("\n");
264  if (!dumpFileToStringWithoutCommands("ofsUAF_Shl_Data.dat", charOutput, simCnt)) {
265  printf("### ERROR : Failed to set string from file \"ofsUAF_Shl_Data.dat\". \n");
266  nrErr++;
267  }
268  __file_write("./hls_out.txt", charOutput, strInput.length());
269  printf("Output string: ");
270  for (unsigned int i = 0; i < strInput.length(); i++)
271  printf("%c", charOutput[i]);
272  printf("\n");
273 
274  //------------------------------------------------------
275  //-- STEP-6 : COMPARE INPUT AND OUTPUT FILE STREAMS
276  //------------------------------------------------------
277  int rc1 = system("diff --brief -w -i -y ../../../../test/ofsUAF_Shl_Data.dat \
278  ../../../../test/verify_UAF_Shl_Data.dat");
279  if (rc1)
280  {
281  printf("## Error : File \'ofsUAF_Shl_Data.dat\' does not match \'verify_UAF_Shl_Data.dat\'.\n");
282  } else {
283  printf("Output data in file \'ofsUAF_Shl_Data.dat\' verified.\n");
284  }
285 
286  nrErr += rc1;
287 
288  printf("#####################################################\n");
289  if (nrErr)
290  {
291  printf("## ERROR - TESTBENCH FAILED (RC=%d) !!! ##\n", nrErr);
292  } else {
293  printf("## SUCCESSFULL END OF TESTBENCH (RC=0) ##\n");
294  }
295  printf("#####################################################\n");
296 
297 
298  return(nrErr);
299 }
300 
301 
302 
303 
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.
#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")
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