cloudFPGA (cF) API  1.0
The documentation of the source code of cloudFPGA (cF)
Memtest Testbench

This is a subgroup of Memtest accelerated function with only testbench-related functions/classes. More...

Collaboration diagram for Memtest Testbench:

Files

file  memtest_host_fwd_tb.cpp
 Testbench for Memtest userspace application for cF (x86, ppc64).
 
file  test_memtest.cpp
 : Testbench for Memtest.
 

Macros

#define THIS_NAME   "TB"
 
#define TRACE_OFF   0x0000
 
#define TRACE_URIF   1 << 1
 
#define TRACE_UAF   1 << 2
 
#define TRACE_MMIO   1 << 3
 
#define TRACE_ALL   0xFFFF
 
#define DEBUG_MULTI_RUNS   True
 
#define TB_MULTI_RUNS_ITERATIONS   2
 
#define DEBUG_LEVEL   (TRACE_ALL)
 
#define OK   true
 
#define KO   false
 
#define VALID   true
 
#define UNVALID   false
 
#define DEBUG_TRACE   true
 
#define ENABLED   (ap_uint<1>)1
 
#define DISABLED   (ap_uint<1>)0
 
#define MEMORY_LINES_512   TOTMEMDW_512 /* 64 KiB */
 

Functions

int main (int argc, char *argv[])
 
stream< UdpWordsSHL_Uaf_Data ("sSHL_Uaf_Data")
 
stream< UdpWordsUAF_Shl_Data ("sUAF_Shl_Data")
 
stream< UdpWordimage_stream_from_memtest ("image_stream_from_memtest")
 
stream< NetworkMetaStreamsiUdp_meta ("siUdp_meta")
 
stream< NetworkMetaStreamsoUdp_meta ("soUdp_meta")
 
void stepDut ()
 Run a single iteration of the DUT model. More...
 
int main (int argc, char **argv)
 Main testbench of Hrris. More...
 

Variables

ap_uint< 1 > piSHL_This_MmioPostPktEn
 
ap_uint< 1 > piSHL_This_MmioCaptPktEn
 
ap_uint< 32 > s_udp_rx_ports = 0x0
 
ap_uint< 32 > node_rank
 
ap_uint< 32 > cluster_size
 
unsigned int simCnt
 
membus_t lcl_mem0 [16384]
 
membus_t lcl_mem1 [16384]
 

Detailed Description

This is a subgroup of Memtest accelerated function with only testbench-related functions/classes.

Macro Definition Documentation

◆ DEBUG_LEVEL

#define DEBUG_LEVEL   (TRACE_ALL)

Definition at line 39 of file test_memtest.cpp.

◆ DEBUG_MULTI_RUNS

#define DEBUG_MULTI_RUNS   True

Definition at line 37 of file test_memtest.cpp.

◆ DEBUG_TRACE

#define DEBUG_TRACE   true

Definition at line 49 of file test_memtest.cpp.

◆ DISABLED

#define DISABLED   (ap_uint<1>)0

Definition at line 52 of file test_memtest.cpp.

◆ ENABLED

#define ENABLED   (ap_uint<1>)1

Definition at line 51 of file test_memtest.cpp.

◆ KO

#define KO   false

Definition at line 46 of file test_memtest.cpp.

◆ MEMORY_LINES_512

#define MEMORY_LINES_512   TOTMEMDW_512 /* 64 KiB */

Definition at line 86 of file test_memtest.cpp.

◆ OK

#define OK   true

Definition at line 45 of file test_memtest.cpp.

◆ TB_MULTI_RUNS_ITERATIONS

#define TB_MULTI_RUNS_ITERATIONS   2

Definition at line 38 of file test_memtest.cpp.

◆ THIS_NAME

#define THIS_NAME   "TB"

Definition at line 30 of file test_memtest.cpp.

◆ TRACE_ALL

#define TRACE_ALL   0xFFFF

Definition at line 36 of file test_memtest.cpp.

◆ TRACE_MMIO

#define TRACE_MMIO   1 << 3

Definition at line 35 of file test_memtest.cpp.

◆ TRACE_OFF

#define TRACE_OFF   0x0000

Definition at line 32 of file test_memtest.cpp.

◆ TRACE_UAF

#define TRACE_UAF   1 << 2

Definition at line 34 of file test_memtest.cpp.

◆ TRACE_URIF

#define TRACE_URIF   1 << 1

Definition at line 33 of file test_memtest.cpp.

◆ UNVALID

#define UNVALID   false

Definition at line 48 of file test_memtest.cpp.

◆ VALID

#define VALID   true

Definition at line 47 of file test_memtest.cpp.

Function Documentation

◆ image_stream_from_memtest()

stream<UdpWord> image_stream_from_memtest ( "image_stream_from_memtest"  )

◆ main() [1/2]

int main ( int  argc,
char **  argv 
)

Main testbench of Hrris.

Returns
0 upon success, nrErr else.

Definition at line 119 of file test_memtest.cpp.

119  {
120 
121  //------------------------------------------------------
122  //-- TESTBENCH LOCAL VARIABLES
123  //------------------------------------------------------
124  int nrErr = 0;
125 
126  printf("#####################################################\n");
127  printf("## TESTBENCH STARTS HERE ##\n");
128  printf("#####################################################\n");
129 // consider to execute : ulimit -s unlimited
130 // if any stack/memory related issue before executing
131 
132  if (argc < 3 || argc > 5) {
133  printf("Usage : %s <number of address to test> , <testing times> , <burst size> <command string ready2go> ;provided %d\n", argv[0], argc);
134  return -1;
135  }
136 
137  //------------------------------------------------------
138  //-- TESTBENCH Input parsing
139  //------------------------------------------------------
140  string strInput_memaddrUT = argv[1];
141  string strInput_nmbrTest = argv[2];
142  string strInput_burstSize = argv[3];
143  string strInput_commandstring= "";
144  if(argc > 4)
145  {
146  strInput_commandstring.assign(argv[4]);
147  }
148  unsigned long long int memory_addr_under_test=0;
149  unsigned int testingNumber = 1;
150  unsigned int burst_size = 1;
151  if (!strInput_memaddrUT.length() || !strInput_nmbrTest.length()) {
152  printf("ERROR: Empty string provided. Aborting...\n");
153  return -1;
154  }
155  else {
156  try
157  {
158  memory_addr_under_test = stoull(strInput_memaddrUT);
159  }
160  catch(const std::exception& e)
161  {
162  std::cerr << e.what() << '\n';
163  memory_addr_under_test = 65; //at least a fault
164  }
165  try
166  {
167  testingNumber = stoul(strInput_nmbrTest);
168  }
169  catch(const std::exception& e)
170  {
171  std::cerr << e.what() << '\n';
172  testingNumber = 3; //at least see the fault
173  }
174 
175  try
176  {
177  burst_size = stoul(strInput_burstSize);
178  }
179  catch(const std::exception& e)
180  {
181  std::cerr << e.what() << '\n';
182  burst_size = 1; //at least see the fault
183  }
184 
185 
186  printf("Succesfully loaded string ... %s\n", argv[1]);
187  printf("Succesfully loaded the address number %u and the number of testings %u, with busrt size %u\n", memory_addr_under_test, testingNumber, burst_size);
188  // Ensure that the selection of MTU is a multiple of 8 (Bytes per transaction)
189  assert(PACK_SIZE % 8 == 0);
190  }
191 
192  //------------------------------------------------------
193  //-- TESTBENCH LOCAL VARIABLES FOR MEMTEST
194  //------------------------------------------------------
195  //unsigned int sim_time = testingNumber * ((2 * (memory_addr_under_test/64+2)) + 5 + 1) + 2 + 1 + 20; // # of tests*((2*(rd/wr addresses + 2 state update))+start+out*4) + meta+start + 10 random cycles
196  unsigned int sim_time = 1 + 3 + testingNumber * (1 + 2 + 5) + 1 + 2 + 10; // meta-pckt-brst testnmbr*(strt-wr-rd-out1-out2-out3-out4-out5) + final cntstart + 2 tx + 10 rand
197  size_t charInputSize = 8*2; //a single tdata is the current command dimension for this test, plus the burst cmd
198  size_t charOutputSize = 8*1+((8 * (2 + 1 + 1 + 1)) * testingNumber); //overdimensioned: eventual stop, 4 (address, fault cntr, flt addr, ccs) for each test foreach test
199 
200  unsigned int tot_input_transfers = CEIL(( 2 ) * 8,PACK_SIZE);// only a single tx + 1
201  unsigned int tot_output_transfers = charOutputSize%PACK_SIZE==0 ? charOutputSize/PACK_SIZE : charOutputSize/PACK_SIZE + 1; // check if bigger output than mtu
202  // if(charOutputSize>PACK_SIZE){
203  // tot_output_transfers = charOutputSize%PACK_SIZE==0 ? charOutputSize/PACK_SIZE : charOutputSize/PACK_SIZE + 1;
204  // }
205 
206  char *charOutput = (char*)malloc((charOutputSize)* sizeof(char)); //
207  //char * charOutput = new char[(charOutputSize)* sizeof(char)];
208  char *charInput = (char*)malloc(charInputSize* sizeof(char)); //
209  //char * charInput = new char[(charInputSize)* sizeof(char)]; //
210 
211  if (!charOutput || !charInput) {
212  printf("ERROR: Cannot allocate memory for output string. Aborting...\n");
213  return -1;
214  }
215  std::vector<MemoryTestResult> testResults_vector;
216 
217  //------------------------------------------------------
218  //-- STEP-1.1 : CREATE MEMORY FOR OUTPUT IMAGES
219  //------------------------------------------------------
220  unsigned int bytes_per_line = 8;
221  string strInput;
222  strInput.reserve(charInputSize+1);
223  string strGold;
224  strGold.reserve(charOutputSize+1);
225 
226 #ifdef SIM_STOP_COMPUTATION // stop the comptuation with a stop command after some CCs
227 
228  std::string strStop;
229  char stop_cmd [bytes_per_line];
230  for (unsigned int k = 0; k < bytes_per_line; k++) {
231  if (k != 0) {
232  stop_cmd[k] = (char)0;
233  }
234  else {
235  stop_cmd[k] = (char)2;
236  }
237  }
238  strStop.append(stop_cmd,8);
239 #endif //SIM_STOP_COMPUTATION
240 
241 
242  simCnt = 0;
243  nrErr = 0;
244 // Assumption: if the user knows how to format the command stream she/he does by itself (
245 // otheriwse the TB takes care and create the commands based on the inputs
246  if(!strInput_commandstring.length()){
247  strInput=createMemTestCommands(memory_addr_under_test, testingNumber, burst_size);
248  }else{
252  //char * char_command = new char[strInput_commandstring.length()+1];
253  char * char_command = (char*)malloc((strInput_commandstring.length()+1)* sizeof(char));
254  char_command[0]='\0';//initi just for the sake
255  char tmp_char_cmd [1];
256  tmp_char_cmd[1] = (char)0;
257  unsigned int tmp_int_cmd = 0;
258  //char_command = new char[strInput_commandstring.length()];
259  // cout << strInput_commandstring << endl;
260  // for (int i = 0; i < strInput_commandstring.length(); i++)
261  // {
262  // tmp_char_cmd[1] = strInput_commandstring[i];
263  // tmp_int_cmd = (unsigned int)atoi(tmp_char_cmd);
264  // memcpy(char_command+i,(char*)&tmp_int_cmd, sizeof(char));
265  // tmp_char_cmd[1] = (char)0;
266  // tmp_int_cmd = 0;
267  // }
268  // strInput.append(char_command,strInput_commandstring.length());
269  // printStringHex(strInput_commandstring, strInput_commandstring.length());
270  // printCharBuffHex(char_command, strInput_commandstring.length());
271  // printStringHex(strInput, strInput_commandstring.length());
272  strInput=createMemTestCommands(memory_addr_under_test, testingNumber, burst_size);
273  if(char_command != NULL){
274  cout << "Clearing the char command" << endl;
275  delete[] char_command;
276  char_command = NULL;
277  }
278  }
279  //Create the expected result
280  strGold = createMemTestGoldenOutput(memory_addr_under_test, testingNumber, true);
281 
282  if (!dumpStringToFile(strInput, "ifsSHL_Uaf_Data.dat", simCnt)) {
283  nrErr++;
284  }
285  //Set the tlast every PACK_SIZE/8 commands if big output tests
286  if (!dumpStringToFileWithLastSetEveryGnoPackets(strGold, "verify_UAF_Shl_Data.dat", simCnt, PACK_SIZE/8)){
287  nrErr++;
288  }
289 
290 #ifdef SIM_STOP_COMPUTATION // stop the comptuation with a stop command after some CCs
291  if (!dumpStringToFile(strStop, "ifsSHL_Uaf_STOPData.dat", simCnt)){
292  nrErr++;
293  }
294 #endif // SIM_STOP_COMPUTATION
295 
296 
297 #ifdef DEBUG_MULTI_RUNS // test if the HLS kernel has reinit issues with streams leftovers or other stuffs
298 for(int iterations=0; iterations < TB_MULTI_RUNS_ITERATIONS; iterations++){
299 #endif //DEBUG_MULTI_RUNS
300 
301 #ifdef ENABLE_DDR
302 for(int i=0; i < MEMORY_LINES_512; i++){
303  lcl_mem0[i]=0;
304  lcl_mem1[i]=0;
305 }
306 #endif//ENABLE_DDR
307  //------------------------------------------------------
308  //-- STEP-2.1 : CREATE TRAFFIC AS INPUT STREAMS
309  //------------------------------------------------------
310  if (nrErr == 0) {
311  if (!setInputDataStream(sSHL_Uaf_Data, "sSHL_Uaf_Data", "ifsSHL_Uaf_Data.dat", simCnt)) {
312  printf("### ERROR : Failed to set input data stream \"sSHL_Uaf_Data\". \n");
313  nrErr++;
314  }
315  //there are tot_input_transfers streams from the the App to the Role
317  for (unsigned int i=0; i<tot_input_transfers; i++) {
318  siUdp_meta.write(NetworkMetaStream(tmp_meta));
319  }
320 
321  //set correct node_rank and cluster_size
322  node_rank = 1;
323  cluster_size = 2;
324  }
325  //------------------------------------------------------
326  //-- STEP-3 : MAIN TRAFFIC LOOP
327  //------------------------------------------------------
328  while (!nrErr) {
329  // Keep enough simulation time for sequntially executing the FSMs of the main functions
330  // (Rx-Tx)
331  if (simCnt < sim_time)
332  {
333  //+1
334  stepDut();
335  if(simCnt > 2)
336  {
337  assert(s_udp_rx_ports == 0x1);
338  }
339 
340  #ifdef SIM_STOP_COMPUTATION // stop the comptuation with a stop command after some CCs manual insertion with define
341  if(simCnt == testingNumber * ((2 * (memory_addr_under_test+1))) + 2){
342  if (!setInputDataStream(sSHL_Uaf_Data, "sSHL_Uaf_Data", "ifsSHL_Uaf_STOPData.dat", simCnt)) {
343  printf("### ERROR : Failed to set input data stream \"sSHL_Uaf_Data\". \n");
344  nrErr++;
345  }
346  //there are tot_input_transfers streams from the the App to the Role
348  for (unsigned int i=0; i<tot_input_transfers; i++) {
349  siUdp_meta.write(NetworkMetaStream(tmp_meta));
350  }
351  //set correct node_rank and cluster_size
352  node_rank = 1;
353  cluster_size = 2;
354  }
355  #endif //SIM_STOP_COMPUTATION
356  } else {
357  printf("## End of simulation at cycle=%3d. \n", simCnt);
358  break;
359  }
360 
361  } // End: while()
362 
363  //-------------------------------------------------------
364  //-- STEP-4 : DRAIN AND WRITE OUTPUT FILE STREAMS
365  //-------------------------------------------------------
366  //---- UAF-->SHELL Data ----
367  if (!getOutputDataStream(sUAF_Shl_Data, "sUAF_Shl_Data", "ofsUAF_Shl_Data.dat", simCnt))
368  {
369  nrErr++;
370  }
371  //---- UAF-->SHELL META ----
372  if( !soUdp_meta.empty())
373  {
374  unsigned int i = 0;
375  while( !soUdp_meta.empty())
376  {
377  i++;
378  NetworkMetaStream tmp_meta = soUdp_meta.read();
379  printf("NRC received NRCmeta stream from rank %d to rank %d.\n", (int) tmp_meta.tdata.src_rank, (int) tmp_meta.tdata.dst_rank);
380  assert(tmp_meta.tdata.src_rank == node_rank);
381  //ensure forwarding behavior
382  assert(tmp_meta.tdata.dst_rank == ((tmp_meta.tdata.src_rank + 1) % cluster_size));
383  }
384  //verify the output prediction
385  assert(i == tot_output_transfers);
386  }
387  else {
388  printf("Error No metadata received...\n");
389  nrErr++;
390  }
391 
392  //-------------------------------------------------------
393  //-- STEP-5 : FROM THE OUTPUT FILE CREATE AN ARRAY
394  //-------------------------------------------------------
395  if (!dumpFileToString("ifsSHL_Uaf_Data.dat", charInput, simCnt)) {
396  printf("### ERROR : Failed to set string from file \"ofsUAF_Shl_Data.dat\". \n");
397  nrErr++;
398  }
399  printf("Input string : ");
400  for (unsigned int i = 0; i < charInputSize; i++)
401  printf("%x", charInput[i]); //hex print since not real chars
402  printf("\n");
403  if (!dumpFileToString("ofsUAF_Shl_Data.dat", charOutput, simCnt)) {
404  printf("### ERROR : Failed to set string from file \"ofsUAF_Shl_Data.dat\". \n");
405  nrErr++;
406  }
407 
408  //__file_write("./hls_out.txt", charOutput, charOutputSize);
409  string out_string;
410  out_string.reserve(charOutputSize);
411  string tmpToDebug = string(charOutput,charOutputSize);
412  out_string.append(tmpToDebug,0, charOutputSize);
413  dumpStringToFileOnlyRawData(out_string, "./hls_out.txt", simCnt, charOutputSize);
414  printf("Output string: ");
415  for (unsigned int i = 0; i < charOutputSize; i++)
416  printf("%x", charOutput[i]); //hex print since not real chars
417  printf("\n");
418  out_string.clear();
419 
420  //------------------------------------------------------
421  //-- STEP-6 : COMPARE GOLD AND OUTPUT FILE STREAMS
422  //------------------------------------------------------
423  int rc1 = system("diff --brief -w -i -y ../../../../test/ofsUAF_Shl_Data.dat \
424  ../../../../test/verify_UAF_Shl_Data.dat");
425 
426  if (rc1)
427  {
428  printf("## Error : File \'ofsUAF_Shl_Data.dat\' does not match \'verify_UAF_Shl_Data.dat\'.\n");
429  } else {
430  printf("Output data in file \'ofsUAF_Shl_Data.dat\' verified.\n");
431  }
432 
433 // #ifdef ENABLE_DDR
434 // for(int i=0; i < MEMORY_LINES_512; i++){
435 // if(lcl_mem0[i]!=lcl_mem1[i]){
436 // cout << "Main mem difference :" << lcl_mem0[i] << " " << lcl_mem1[i] << endl;
437 // }else{
438 // cout << "ok ";
439 // }
440 // }
441 // #endif//ENABLE_DDR
442 
443  //------------------------------------------------------
444  //-- STEP-7 [OPTIONAL] : Parse the output stream
445  //------------------------------------------------------
446  const string ouf_file ="./hls_out.txt";
447  int rawdatalines=0;
448  string longbuf_string;
449  longbuf_string.reserve(charOutputSize);
450  longbuf_string = dumpFileToStringRawDataString(ouf_file, &rawdatalines, charOutputSize);
451 
452  testResults_vector=parseMemoryTestOutput(longbuf_string,charOutputSize,rawdatalines);
453  //------------------------------------------------------
454  //-- STEP-8 : Clear everything
455  //------------------------------------------------------
456  longbuf_string.clear();
457  testResults_vector.clear();
458  cout<< endl << " End the TB with iteration " << iterations << endl << endl;
459 
460  nrErr += rc1;
461 
462  printf("#####################################################\n");
463  if (nrErr)
464  {
465  printf("## ERROR - TESTBENCH FAILED (RC=%d) !!! ##\n", nrErr);
466  } else {
467  printf("## SUCCESSFULL END OF TESTBENCH (RC=0) ##\n");
468  }
469  printf("#####################################################\n");
470 
471  simCnt = 0;//reset sim counter
472  nrErr=0;
473 #ifdef DEBUG_MULTI_RUNS
474 }
475  #endif//DEBUG_MULTI_RUNS
476 
477 
478 //free dynamic memory
479 if(charOutput != NULL){
480  free(charOutput);
481  charOutput = NULL;
482 }
483 if(charInput != NULL){
484  free(charInput);
485  charInput = NULL;
486 }
487  return(nrErr);
488 }
bool dumpStringToFileOnlyRawData(const std::string s, const std::string outFileName, int simCnt, size_t out_size)
Fill an output file with data from an image.
bool dumpFileToString(const std::string inpFileName, std::string strOutput, int simCnt)
Initialize an input data stream from a file.
bool dumpStringToFileWithLastSetEveryGnoPackets(std::string s, const std::string outFileName, int simCnt, int gno)
Fill an output file with data from a string and set the tlast every gno packets.
std::string createMemTestGoldenOutput(unsigned long long int mem_address, int testingNumber)
Create the expected output results for the memory test (with FAULT INJECTION)
bool dumpStringToFile(std::string s, const std::string outFileName, int simCnt)
Initialize an input data stream from a file.
unsigned int simCnt
stream< NetworkMetaStream > siUdp_meta("siUdp_meta")
stream< NetworkMetaStream > soUdp_meta("soUdp_meta")
#define TB_MULTI_RUNS_ITERATIONS
membus_t lcl_mem0[16384]
membus_t lcl_mem1[16384]
void stepDut()
Run a single iteration of the DUT model.
#define MEMORY_LINES_512
ap_uint< 32 > cluster_size
ap_uint< 32 > s_udp_rx_ports
stream< UdpWord > sSHL_Uaf_Data("sSHL_Uaf_Data")
ap_uint< 32 > node_rank
stream< UdpWord > sUAF_Shl_Data("sUAF_Shl_Data")
std::vector< MemoryTestResult > parseMemoryTestOutput(const string longbuf, size_t charOutputSize, int rawdatalines)
Parse the memory test output contained in astring with a given size.
Definition: common.hpp:444
string dumpFileToStringRawDataString(const string inpFileName, int *rawdatalines, size_t outputSize)
Initialize an input data stream from a file with only data.
Definition: common.hpp:279
string createMemTestCommands(unsigned long long int mem_address, unsigned int testingNumber, unsigned int burst_size)
Create the commands for a memory test with start/max address to test-nop to execute-stop.
Definition: common.hpp:137
#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
NetworkMeta tdata
Definition: network.hpp:109
NodeId dst_rank
Definition: network.hpp:95
NodeId src_rank
Definition: network.hpp:97
Here is the call graph for this function:

◆ main() [2/2]

int main ( int  argc,
char *  argv[] 
)

Main testbench for the user-application for Memtest on host. Server

Returns
O on success, 1 on fail

Definition at line 54 of file memtest_host_fwd_tb.cpp.

54  {
55 
56  if ((argc < 2) || (argc > 3)) { // Test for correct number of parameters
57  cerr << "Usage: " << argv[0] << " <Server Port> <optional simulation mode>" << endl;
58  exit(1);
59  }
60 
61  unsigned short servPort = atoi(argv[1]); // First arg: local port
62  unsigned int num_batch = 0;
63  string clean_cmd, synth_cmd;
64  unsigned int testingNumber=3;
65  string strInput_nmbrTest="";
66 
67 
68 //Infinite Loop Logic
69 bool endOfLooping=false;
70 while(!endOfLooping){
71 
72  //------------------------------------------------------
73  //-- Setup the RX
74  //------------------------------------------------------
75  try {
76  #if NET_TYPE == udp
77  UDPSocket sock(servPort);
78  #else
79  TCPServerSocket servSock(servPort); // Server Socket object
80  TCPSocket *servsock = servSock.accept(); // Wait for a client to connect
81  #endif
82  char buffer[BUF_LEN]; // Buffer for echo string
83  unsigned int recvMsgSize; // Size of received message
84  string sourceAddress; // Address of datagram source
85  unsigned short sourcePort; // Port of datagram source
86 
87  #if NET_TYPE == tcp
88  // TCP client handling
89  cout << "Handling client ";
90  try {
91  cout << servsock->getForeignAddress() << ":";
92  } catch (SocketException e) {
93  cerr << "Unable to get foreign address" << endl;
94  }
95  try {
96  cout << servsock->getForeignPort();
97  } catch (SocketException e) {
98  cerr << "Unable to get foreign port" << endl;
99  }
100  cout << endl;
101  #endif
102 
103  //------------------------------------------------------
104  //-- RX Step
105  //------------------------------------------------------
106  clock_t last_cycle_rx = clock();
107  // Block until receive message from a client
108  int input_string_total_len = 0;
109  //int receiving_now = PACK_SIZE;
110  int total_pack = 1;
111  int bytes_in_last_pack;
112  size_t total_size =0;
113  bool msg_received = false;
114  cout << " ___________________________________________________________________ " << endl;
115  cout << "/ \\" << endl;
116  cout << "INFO: Proxy tb batch # " << ++num_batch << endl;
117  char * longbuf = new char[PACK_SIZE * (total_pack+1)];
118  // RX Loop
119  for (int i = 0; msg_received != true; i++, total_pack++) {
120  #if NET_TYPE == udp
121  recvMsgSize = sock.recvFrom(buffer, BUF_LEN, sourceAddress, sourcePort);
122  #else
123  recvMsgSize = servsock->recv(buffer, receiving_now);
124  #endif
125  input_string_total_len += recvMsgSize;
126  bytes_in_last_pack = recvMsgSize;
127  bool nullcharfound = findCharNullPos(buffer);
128  memcpy(longbuf+(i*PACK_SIZE), buffer, recvMsgSize);
129  total_size += recvMsgSize;
130  longbuf[total_size+1]='\0';
131 
132  if (nullcharfound != true) {
133  cout << "INFO: The string is not entirely fit in packet " << total_pack << endl;
134  }
135  else {
136  msg_received = true;
137  }
138  }
139 
140  cout << "INFO: Received packet from " << sourceAddress << ":" << sourcePort << endl;
141 
142  string input_string;
143  input_string.append(longbuf,total_size);
144  if (input_string.length() == 0) {
145  cerr << "ERROR: received an empty string! Aborting..." << endl;
146  return -1;
147  }
148  //------------------------------------------------------
149  //-- DECODING LOGIC for output size determination and end of looping
150  //------------------------------------------------------
151  unsigned long long int memory_addr_under_test = 0;
152  testingNumber = 0;
153  unsigned int burst_size = 0;
154 
155  cout << "Begin the decoding step" << endl;
156  //printStringHex(input_string,input_string.length());
157  //printBits(input_string.length(),input_string.c_str());
158 
159  // revert the input string and extract substring
160  reverse(input_string.begin(), input_string.end());
161 
162  //------------------------------------------------------
163  //-- DECODING LOGIC check which command was
164  //------------------------------------------------------
165  string substr_tmp, to_translate_String;
166  substr_tmp = input_string.substr(7,1);
167  ascii2hexWithSize(substr_tmp,to_translate_String,1);
169  if(to_translate_String.compare("2")==0){
170  endOfLooping=true;
171  string cmd_string = createMemTestStopCommand();
172  char cmd_stop [8];
173  strncpy(cmd_stop,cmd_string.c_str(),8);
174  unsigned int sending_bytes=8;
175  #if NET_TYPE == udp
176  sock.sendTo( cmd_stop, sending_bytes, sourceAddress, sourcePort);
177  #else
178  servsock->send(cmd_stop, sending_bytes);
179  #endif
180  cout << "A stop received, going to sleep the EMU :)" << endl;
181  cout << "\\___________________________________________________________________/" << endl;
182  #if NET_TYPE == tcp
183  delete servsock;
184  #endif
185  continue;
186  }
187  reverse(input_string.begin(), input_string.end());
188  //printStringHex(input_string,input_string.length());
189  //printBits(input_string.length(),input_string.c_str());
190 
191  //------------------------------------------------------
192  //-- DECODING LOGIC for output and TB setup
193  //------------------------------------------------------
194  char myTmpOutBuff[8];
195  //how many test to perform
196  substr_tmp = input_string.substr(1,2);
197  for(int i=0; i < 8; i++){myTmpOutBuff[i]=(char)0;}
198  strncpy(myTmpOutBuff,substr_tmp.c_str(),2);
199  testingNumber = *reinterpret_cast<unsigned long long*>(myTmpOutBuff);
200  substr_tmp.clear();
201 
202  //the maximum address to test
203  for(int i=0; i < 8; i++){myTmpOutBuff[i]=(char)0;}
204  substr_tmp=input_string.substr(3,5);
205  memcpy(myTmpOutBuff,substr_tmp.c_str(),5);
206  memory_addr_under_test = *reinterpret_cast<unsigned long long*>(myTmpOutBuff);
207  substr_tmp.clear();
208 
209  //the selected burst size
210  substr_tmp = input_string.substr(9,2);
211  printBits(2,substr_tmp.c_str());
212  for(int i=0; i < 8; i++){myTmpOutBuff[i]=(char)0;}
213  memcpy(myTmpOutBuff,substr_tmp.c_str(),2);
214  burst_size = *reinterpret_cast<unsigned long long*>(myTmpOutBuff);
215  substr_tmp.clear();
216  for(int i=0; i < 8; i++){myTmpOutBuff[i]=(char)0;}
217 
218 
219  reverse(input_string.begin(), input_string.end());
220  cout << input_string << endl;
221  //------------------------------------------------------
222  //-- EMULATION preparing the emulation mode, default is fcsim
223  //------------------------------------------------------
224  synth_cmd = " ";
225  string exec_cmd = "make fcsim ";
226  string ouf_file = "../../../../../../ROLE/custom/hls/memtest/memtest_prj/solution1/fcsim/build/hls_out.txt";
227  if (argc >= 3) {
228  if (atoi(argv[2]) == 2) {
229  exec_cmd = "make csim";
230  ouf_file = "../../../../../../ROLE/custom/hls/memtest/memtest_prj/solution1/csim/build/hls_out.txt";
231  }
232  else if (atoi(argv[2]) == 3) {
233  synth_cmd = "make csynth && ";
234  exec_cmd = "make cosim";
235  ouf_file = "../../../../../../ROLE/custom/hls/memtest/memtest_prj/solution1/sim/wrapc_pc/build/hls_out.txt";
236  }
237  else if (atoi(argv[2]) == 4) {
238  exec_cmd = "make kcachegrind";
239  ouf_file = "../../../../../../ROLE/custom/hls/memtest/memtest_prj/solution1/fcsim/build/hls_out.txt";
240  }
241  }
242  // Calling the actual TB over its typical makefile procedure, but passing the save file
243  // Skip the rebuilding phase on the 2nd run. However ensure that it's a clean recompile
244  // the first time.
245  clean_cmd = " ";
246  if (num_batch == 1) {
247  clean_cmd = "make clean && ";
248  }
249  string str_command = "cd ../../../../../../ROLE/custom/hls/memtest/ && ";
250  str_command = str_command.append(clean_cmd + synth_cmd+ exec_cmd);
251  size_t str_command_size = str_command.length();
252  string final_cmd = " TEST_NUMBER=" + std::to_string(testingNumber) + " INPUT_STRING=" + std::to_string(memory_addr_under_test) + " BURST_SIZE=" + std::to_string(burst_size) + " && cd ../../../../HOST/custom/memtest/languages/cplusplus/build/ ";
253  str_command = str_command.append(final_cmd);
254  str_command_size+=final_cmd.length();
255 
256  char *command =(char*)malloc((str_command_size+1)* sizeof(char));
257  for(int i=0; i < (str_command_size+1); i++){
258  command[i]=str_command[i];
259  }
260  cout << "Calling TB with command:" << command << endl;
261  system(command);
262 
263  //clean dynamic memory
264  input_string.clear();
265  str_command.clear();
266  final_cmd.clear();
267  free(command);
268 
269  //------------------------------------------------------
270  //-- TB output parsing
271  //------------------------------------------------------
272  ssize_t size = __file_size(ouf_file.c_str());
273  size_t charOutputSize = 8*1+((8 * (2 + 1+ 1 + 1)) * testingNumber); //stop, 4 for each test, potential stop?
274 
275  int rawdatalines=0;
276  int rc = 0;
277  string out_string;
278  delete [] longbuf;
279 
280  longbuf = new char[charOutputSize+1];
281  out_string.reserve(charOutputSize);
282  out_string = dumpFileToStringRawDataString(ouf_file.c_str(), &rawdatalines, charOutputSize);
283  memcpy(longbuf,out_string.data(),charOutputSize);
284 
285  if (rc < 0) {
286  cerr << "ERROR: Cannot read file " << ouf_file << " . Aborting..."<< endl;
287  return -1;
288  }
289 
290  clock_t next_cycle_rx = clock();
291  double duration_rx = (next_cycle_rx - last_cycle_rx) / (double) CLOCKS_PER_SEC;
292  cout << "INFO: Effective FPS RX:" << (1 / duration_rx) << " \tkbps:" << (PACK_SIZE *
293  total_pack / duration_rx / 1024 * 8) << endl;
294  last_cycle_rx = next_cycle_rx;
295 
296 
297  //------------------------------------------------------
298  //-- TX step
299  //------------------------------------------------------
300 
301  unsigned int total_retx_pack = 1;
302  total_retx_pack = charOutputSize%PACK_SIZE==0 ? charOutputSize/PACK_SIZE : charOutputSize/PACK_SIZE + 1;
303  if (out_string.length() == 0) {
304  cerr << "ERROR: Received empty string!" << endl;
305  return -1;
306  }
307  else {
308  cout << "INFO: Succesfully received string from TB : " << out_string << endl;
309  //printStringHex(out_string, charOutputSize);
310  cout << "INFO: Will forward it back to host app ... total_pack=" << total_retx_pack << endl;
311  }
312 
313  // TX Loop
314  unsigned int sending_now = PACK_SIZE;
315  clock_t last_cycle_tx = clock();
316  unsigned int bytes_in_last_pack_in = charOutputSize - (total_retx_pack - 1) * PACK_SIZE;
317  for (int i = 0; i < total_retx_pack; i++) {
318  if ( i == total_retx_pack - 1 ) {
319  sending_now = bytes_in_last_pack_in;
320  }
321  #if NET_TYPE == udp
322  sock.sendTo( longbuf+(i * PACK_SIZE), sending_now, sourceAddress, sourcePort);
323  #else
324  servsock->send( & longbuf[i * PACK_SIZE], sending_now);
325  #endif
326  }
327  clock_t next_cycle_tx = clock();
328  double duration_tx = (next_cycle_tx - last_cycle_tx) / (double) CLOCKS_PER_SEC;
329  cout << "INFO: Effective FPS TX:" << (1 / duration_tx) << " \tkbps:" << (PACK_SIZE *
330  total_retx_pack / duration_tx / 1024 * 8) << endl;
331  last_cycle_tx = next_cycle_tx;
332  delete [] longbuf;
333  cout << "\\___________________________________________________________________/" << endl;
334  #if NET_TYPE == tcp
335  delete servsock;
336  #endif
337  out_string.clear();
338  } catch (SocketException & e) {
339  cerr << e.what() << endl;
340  exit(1);
341  }
342 
343  //------------------------------------------------------
344  //-- Now loop until stop or crash :D
345  //------------------------------------------------------
346  }//while
347  return 0;
348 }
void printBits(size_t const size, void const *const ptr)
print the binary representation of a target pointer buffer of a given size. Assumes little endian.
Definition: common.hpp:98
void ascii2hexWithSize(const string &in, string &out, size_t bytesize)
Convert a ascii string to a hexadecimal string.
Definition: common.hpp:331
#define BUF_LEN
Definition: config.h:54
string createMemTestStopCommand()
Definition: common.hpp:168
bool findCharNullPos(char *str)
Definition: common.hpp:340
def clock()
Definition: common.py:174
ap_uint< 32 > size
Here is the call graph for this function:

◆ siUdp_meta()

stream<NetworkMetaStream> siUdp_meta ( "siUdp_meta"  )
Here is the caller graph for this function:

◆ soUdp_meta()

stream<NetworkMetaStream> soUdp_meta ( "soUdp_meta"  )
Here is the caller graph for this function:

◆ sSHL_Uaf_Data()

stream< UdpWord > sSHL_Uaf_Data ( "sSHL_Uaf_Data"  )
Here is the caller graph for this function:

◆ stepDut()

void stepDut ( )

Run a single iteration of the DUT model.

Returns
Nothing.

Definition at line 94 of file test_memtest.cpp.

94  {
95  memtest(
100  #ifdef ENABLE_DDR
101  ,
102  lcl_mem0,
103  lcl_mem0
104  #endif
105  );
106  simCnt++;
107  #if DEBUG_LEVEL > TRACE_OFF
108  printf("[%4.4d] STEP DUT \n", simCnt);
109  #endif
110 }
void memtest(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, membus_t *lcl_mem0, membus_t *lcl_mem1)
Main process of the Memtest Application directives.
Definition: memtest.cpp:39
#define ENABLE_DDR
Definition: memtest.hpp:42
Here is the call graph for this function:
Here is the caller graph for this function:

◆ sUAF_Shl_Data()

stream< UdpWord > sUAF_Shl_Data ( "sUAF_Shl_Data"  )
Here is the caller graph for this function:

Variable Documentation

◆ cluster_size

ap_uint<32> cluster_size

Definition at line 74 of file test_memtest.cpp.

◆ lcl_mem0

membus_t lcl_mem0[ 16384]

Definition at line 87 of file test_memtest.cpp.

◆ lcl_mem1

membus_t lcl_mem1[ 16384]

Definition at line 88 of file test_memtest.cpp.

◆ node_rank

ap_uint<32> node_rank

Definition at line 73 of file test_memtest.cpp.

◆ piSHL_This_MmioCaptPktEn

ap_uint<1> piSHL_This_MmioCaptPktEn

Definition at line 63 of file test_memtest.cpp.

◆ piSHL_This_MmioPostPktEn

ap_uint<1> piSHL_This_MmioPostPktEn

Definition at line 62 of file test_memtest.cpp.

◆ s_udp_rx_ports

ap_uint<32> s_udp_rx_ports = 0x0

Definition at line 70 of file test_memtest.cpp.

◆ simCnt

unsigned int simCnt

Definition at line 79 of file test_memtest.cpp.