cloudFPGA (cF) API  1.0
The documentation of the source code of cloudFPGA (cF)
tb_fmc.cpp
Go to the documentation of this file.
1 
17 
30 #define DEBUG
31 
32 #ifdef COSIM
33 //to disable asserts
34 #define NDEBUG
35 #endif
36 
37 #include <stdio.h>
38 #include <stdlib.h>
39 #include <assert.h>
40 #include "../src/fmc.hpp"
41 #include "../../../../../hls/cfdk.hpp"
42 #include "../../../../../hls/network.hpp"
43 #include "../../../../../hls/axi_utils.hpp"
44 #include "../../NAL/src/nal.hpp" //AFTER fmc.hpp
45 
46 #include <stdint.h>
47 
48 #include <hls_stream.h>
49 
50 using namespace std;
51 
52 #ifndef COSIM
53 #include <sys/time.h>
54 #define HWICAP_SEQ_SIZE ((16*IN_BUFFER_SIZE + 512)/4)
55 #else
56 #define HWICAP_SEQ_SIZE ((4*IN_BUFFER_SIZE + 512)/4)
57 #endif
58 #define HWICAP_SEQ_START_ADDRESS 1024
59 
60 //------------------------------------------------------
61 //-- DUT INTERFACES AS GLOBAL VARIABLES
62 //------------------------------------------------------
63 ap_uint<32> MMIO_in = 0x0;
64 ap_uint<32> MMIO;
65 ap_uint<32> MMIO_in_BE, MMIO_out_BE;
66 ap_uint<1> layer_4_enabled = 0b1;
67 ap_uint<1> layer_6_enabled = 0b0;
68 ap_uint<1> layer_7_enabled = 0b0;
69 ap_uint<1> nts_ready = 0b1;
70 ap_uint<16> role_mmio = 0x1DEA;
71 ap_uint<16> uoe_drop_cnt = 0x0;
72 ap_uint<8> toe_notif_drop_cnt = 0;
73 ap_uint<8> toe_meta_drop_cnt = 0;
74 ap_uint<8> toe_data_drop_cnt = 0;
75 ap_uint<8> toe_crc_drop_cnt = 0;
76 ap_uint<8> toe_sess_drop_cnt = 0;
77 ap_uint<8> toe_ooo_drop_cnt = 0;
78 ap_uint<32> sim_fpga_time_seconds = 0;
79 ap_uint<32> sim_fpga_time_minutes = 0;
80 ap_uint<32> sim_fpga_time_hours = 0;
81 ap_uint<1> decoupActive = 0b0;
82 ap_uint<1> decoupStatus = 0b0;
83 ap_uint<1> softReset = 0b0;
84 ap_uint<32> nodeRank_out;
85 ap_uint<32> clusterSize_out;
86 ap_uint<32> HWICAP[512];
89 ap_uint<32> xmem[XMEM_SIZE];
91 ap_uint<1> disable_ctrl_link = 0b0;
92 ap_uint<1> disable_pyro_link = 0b0;
93 stream<Axis<8> > FMC_Debug_Pyrolink ("FMC_Debug_Pyrolink"); //soPYROLINK
94 stream<Axis<8> > Debug_FMC_Pyrolink ("Debug_FMC_Pyrolink"); //siPYROLINK
95 stream<TcpWord> sFMC_NAL_Tcp_data ("sFMC_Nal_Tcp_data");
96 stream<AppMeta> sFMC_NAL_Tcp_sessId ("sFMC_Nal_Tcp_sessId");
97 stream<TcpWord> sNAL_FMC_Tcp_data ("sNAL_FMC_Tcp_data");
98 stream<AppMeta> sNAL_FMC_Tcp_sessId ("sNAL_FMC_Tcp_sessId");
99 
100 ap_uint<32> reverse_byte_order(ap_uint<32> input)
101 {
102  ap_uint<32> output = 0x0;
103  output = (ap_uint<32>) ((input >> 24) & 0xFF);
104  output |= (ap_uint<32>) ((input >> 8) & 0xFF00);
105  output |= (ap_uint<32>) ((input << 8) & 0xFF0000);
106  output |= (ap_uint<32>) ((input << 24) & 0xFF000000);
107  return output;
108 }
109 
110 //------------------------------------------------------
111 //-- TESTBENCH GLOBAL VARIABLES
112 //------------------------------------------------------
113 int simCnt;
114 
115 void stepDut() {
116  ap_uint<32> *used_hwicap_buffer = HWICAP;
118  {
119  used_hwicap_buffer = HWICAP_seq_OUT;
120  }
127  used_hwicap_buffer, decoupStatus, &decoupActive,
128  &softReset, xmem,
132 #ifdef INCLUDE_PYROLINK
134 #endif
137  simCnt++;
138  printf("[%4.4d] STEP DUT \n", simCnt);
139  fflush(stdin);
140  fflush(stdout);
141 }
142 
143 
144 bool checkResult(ap_uint<32> MMIO, ap_uint<32> expected)
145 {
146  if (MMIO == expected)
147  {
148  printf("expected result: %#010x\n", (int) MMIO);
149  return true;
150  }
151 
152  printf("[%4.4d] ERROR: Got %#010x instead of %#010x\n", simCnt, (int) MMIO, (int) expected);
153  //return false;
154  exit(-1);
155 }
156 
157 void printBuffer(volatile uint8_t *buffer_int, char* msg, int max_pages)
158 {
159  printf("%s: \n",msg);
160  for( int i = 0; i < BYTES_PER_PAGE*max_pages; i++)
161  {
162  uint8_t cur_elem = (ap_uint<8>) buffer_int[i];
163  printf("%02x ", cur_elem);
164 
165  if(i % 8 == 7)
166  {
167  printf("\n");
168  }
169 
170  }
171 }
172 
173 void printBuffer32(ap_uint<32> buffer_int[XMEM_SIZE], char* msg, int max_pages)
174 {
175  printf("%s: \n",msg);
176  for( int i = 0; i < LINES_PER_PAGE*max_pages; i++)
177  {
178  int cur_elem = (int) buffer_int[i];
179  printf("%08x ", cur_elem);
180 
181  if(i % 8 == 7)
182  {
183  printf("\n");
184  }
185 
186  }
187 }
188 
189 bool checkSeqHwicap(uint32_t *true_buffer, ap_uint<32> *out_buffer, uint32_t start_address, uint32_t end_address, bool not_to_swap)
190 {
191  uint32_t max_address = end_address;
192  if(max_address > HWICAP_SEQ_SIZE)
193  {
194  max_address = HWICAP_SEQ_SIZE;
195  printf("set max verify address to %d.\n",max_address);
196  }
197  for(int i = start_address; i<max_address; i++)
198  {
199  ap_uint<32> true_buffer_BE = 0x0;
200  if(not_to_swap)
201  {
202  true_buffer_BE = true_buffer[i];
203  } else {
204  true_buffer_BE = (ap_uint<32>) ((true_buffer[i] >> 24) & 0xFF);
205  true_buffer_BE |= (ap_uint<32>) ((true_buffer[i] >> 8) & 0xFF00);
206  true_buffer_BE |= (ap_uint<32>) ((true_buffer[i] << 8) & 0xFF0000);
207  true_buffer_BE |= (ap_uint<32>) ((true_buffer[i] << 24) & 0xFF000000);
208  }
209  if(true_buffer_BE != out_buffer[i])
210  {
211  printf("HWICAP OUT is different at position %d: should be %#010x, but is %#010x\n", i, (int) true_buffer_BE, (int) out_buffer[i]);
212  printf("relative position: %d; end address: %d\n",(int) (i - start_address), max_address);
213  printf("Context:\n\tShould:\n");
214  for(int j = i-3; j<i+3; j++)
215  {
216  ap_uint<32> true_buffer_BE_2 = 0x0;
217  if(not_to_swap)
218  {
219  true_buffer_BE_2 = true_buffer[j];
220  } else {
221  true_buffer_BE_2 = (ap_uint<32>) ((true_buffer[j] >> 24) & 0xFF);
222  true_buffer_BE_2 |= (ap_uint<32>) ((true_buffer[j] >> 8) & 0xFF00);
223  true_buffer_BE_2 |= (ap_uint<32>) ((true_buffer[j] << 8) & 0xFF0000);
224  true_buffer_BE_2 |= (ap_uint<32>) ((true_buffer[j] << 24) & 0xFF000000);
225  }
226  printf("\t%4.4d: %#010x\n",j,(int) true_buffer_BE_2);
227  }
228  printf("\tIs:\n");
229  for(int j = i-3; j<i+3; j++)
230  {
231  printf("\t%4.4d: %#010x\n",j,(int) out_buffer[j]);
232  }
233  printf("\n");
234  return false;
235  }
236  }
237  printf("[HWICAP OUT is valid from address %d to %d]\n",start_address, max_address);
238  return true;
239 }
240 
241 void initBuffer(ap_uint<4> cnt,ap_uint<32> xmem[XMEM_SIZE], bool lastPage, bool withPattern)
242 {
243  ap_uint<32> ctrlWord = 0;
244  for(int i = 0; i<8; i++)
245  {
246  ctrlWord |= ((ap_uint<32>) cnt) << (i*4);
247  }
248 
249  for(int i = 0; i<LINES_PER_PAGE; i++)
250  {
251  if (withPattern)
252  {
253  xmem[i] = ctrlWord;
254  } else {
255  //xmem[i] = ctrlWord+i;
256  // xmem[i] = (ctrlWord << 16) + (rand() % 65536);
257  xmem[i] = (((ap_uint<32>) cnt) << 24) | 0x0A0B00 | ((ap_uint<32>) i);
258  }
259  }
260  //printf("CtrlWord: %#010x\n",(int) ctrlWord);
261 
262  //Set Header and Footer
263  ap_uint<8> header = (ap_uint<8>) cnt;
264  if (lastPage)
265  {
266  header |= 0xf0;
267  }
268  //ap_uint<32> headerLine = header | (ctrlWord & 0xFFFFFF00);
269  ap_uint<32> headerLine = header | (xmem[0] & 0xFFFFFF00);
270  //ap_uint<32> footerLine = (((ap_uint<32>) header) << 24) | (ctrlWord & 0x00FFFFFF);
271  ap_uint<32> footerLine = (((ap_uint<32>) header) << 24) | (xmem[LINES_PER_PAGE-1] & 0x00FFFFFF);
272  xmem[0] = headerLine;
273  xmem[LINES_PER_PAGE-1] = footerLine;
274 
275 }
276 
277 ap_uint<64> initStream(ap_uint<4> cnt, stream<NetworkWord> &tcp_data, int nr_words, bool with_pattern, bool inverse_upper, bool insert_tlast)
278 {
279  ap_uint<32> ctrlWord = 0;
280  for(int i = 0; i<8; i++)
281  {
282  if(with_pattern)
283  {
284  ctrlWord |= ((ap_uint<32>) ++cnt) << (i*4);
285  } else {
286  ctrlWord |= ((ap_uint<32>) cnt) << (i*4);
287  }
288  }
289 
290  ap_uint<64> data_word = 0;
291  if(inverse_upper)
292  {
293  data_word = (((ap_uint<64>) ~ctrlWord) << 32) | ctrlWord;
294  } else {
295  data_word = ((ap_uint<64>) ctrlWord << 32) | ctrlWord;
296  }
297 
298  printf("Writing to Stream: 0x%llx\n",(unsigned long long) data_word);
299 
300  for(int i = 0; i<nr_words; i++)
301  {
303  tmp.tdata = data_word;
304  tmp.tkeep = 0xFF;
305  if(i == nr_words -1 && insert_tlast)
306  {
307  tmp.tlast = 1;
308  } else {
309  tmp.tlast = 0;
310  }
311  tcp_data.write(tmp);
312  }
313 
314  return data_word;
315 }
316 
317 void copyBufferToXmem(char* buffer_int, ap_uint<32> xmem[XMEM_SIZE])
318 {
319  for(int i = 0; i<LINES_PER_PAGE; i++)
320  {
321  ap_uint<32> tmp = 0;
322  tmp = ((ap_uint<32>) (uint8_t) buffer_int[i*4 + 0]);
323  tmp |= ((ap_uint<32>)(uint8_t) buffer_int[i*4 + 1]) << 8;
324  tmp |= ((ap_uint<32>)(uint8_t) buffer_int[i*4 + 2]) << 16;
325  tmp |= ((ap_uint<32>)(uint8_t) buffer_int[i*4 + 3]) << 24;
326  xmem[i] = tmp;;
327  }
328 }
329 
330 void copyBufferToStream(char *buffer_int, stream<NetworkWord> &tcp_data, int content_len)
331 {
332  printf("Writing %d bytes to Stream: (in hex)\n", content_len);
333  for(int i = 0; i<content_len; i+=8)
334  {
335  ap_uint<64> new_word = 0;
336  ap_uint<8> tkeep = 0;
337  for(int j = 0; j<8; j++)
338  {
339  if(i+j < content_len)
340  {
341  new_word |= ((ap_uint<64>) ((uint8_t) buffer_int[i+j])) << (j*8);
342  tkeep |= ((ap_uint<8>) 1) << j;
343  } else {
344  new_word |= ((ap_uint<64>) ((uint8_t) 0 ))<< (j*8);
345  tkeep |= ((ap_uint<8>) 0) << j;
346  }
347  }
348  //printf("Writing to Stream: 0x%llx\n",(unsigned long long) new_word);
349  //printf("%016llx\n",(unsigned long long) new_word);
350 
352  tmp.tdata = new_word;
353  tmp.tkeep = tkeep;
354  if(i >= (content_len - 8))
355  {
356  tmp.tlast = 1;
357  } else {
358  tmp.tlast = 0;
359  }
360 
361  printf("%016llx | %02x | %d \n",(unsigned long long) new_word, (int) tkeep, (int) tmp.tlast);
362  tcp_data.write(tmp);
363 
364  }
365 
366 }
367 
368 void drainStream(stream<NetworkWord> &tcp_data)
369 {
370  printf("Draining NetworkStream: (in hex)\n");
371 
372  while(!tcp_data.empty())
373  {
374  NetworkWord tmp = tcp_data.read();
375  printf("%016llx\n",(unsigned long long) tmp.tdata);
376  }
377 
378 }
379 
380 int main(){
381 
382  ap_uint<32> SR;
383  ap_uint<32> ISR;
384  ap_uint<32> WFV;
385 
386  SR=0x5;
387  ISR=0x4;
388  WFV=0x7FF;
389 
390  HWICAP[SR_OFFSET] = SR;
391  HWICAP[ISR_OFFSET] = ISR;
392  HWICAP[WFV_OFFSET] = WFV;
393  HWICAP[ASR_OFFSET] = 0;
394  HWICAP[CR_OFFSET] = 0;
395  //HWICAP[RFO_OFFSET] = 0x3FF;
396 
397  bool succeded = true;
398 
399  decoupStatus = 0b1;
400  stepDut();
401  printf("%#010x\n", (int) MMIO);
402  succeded = (MMIO == 0xBEBAFECA) && succeded;
403 
404 //===========================================================
405 //Test Displays
406  MMIO_in = 0x1 << DSEL_SHIFT;
407  decoupStatus = 0b0;
408  stepDut();
409  printf("%#010x\n", (int) MMIO);
410  succeded = (MMIO == 0x1007FF07) && succeded && (decoupActive == 0);
411 
412  MMIO_in = 0x2 << DSEL_SHIFT;
413  stepDut();
414  printf("%#010x\n", (int) MMIO);
415  succeded = (MMIO == 0x20000000) && succeded && (decoupActive == 0);
416 
417  MMIO_in = 0x1 << DSEL_SHIFT | 0b1 << DECOUP_CMD_SHIFT;
418  decoupStatus = 0b1;
419  stepDut();
420  printf("%#010x\n", (int) MMIO);
421  succeded = (MMIO == 0x100FFF07) && succeded && (decoupActive == 1);
422 
423  MMIO_in = 0x3 << DSEL_SHIFT | 0b1 << DECOUP_CMD_SHIFT;
424  stepDut();
425  printf("%#010x\n", (int) MMIO);
426  succeded = (MMIO == 0x3f49444C) && succeded && (decoupActive == 1);
427 
428  MMIO_in = 0x1 << DSEL_SHIFT;
429  stepDut();
430  printf("%#010x\n", (int) MMIO);
431  succeded = (MMIO == 0x100FFF07) && succeded && (decoupActive == 0);
432  assert(succeded);
433  printf("== Display and Decoup Test passed == \n");
434 
435 //===========================================================
436 //Test Counter & Xmem
437  printf("===== XMEM =====\n");
438 
439  int cnt = 0;
440  MMIO_in = 0x3 << DSEL_SHIFT | ( 1 << START_SHIFT);
441  initBuffer((ap_uint<4>) cnt, xmem, false, false);
442  decoupStatus = 0b0;
443  stepDut(); //simCnt 7
444  succeded &= checkResult(MMIO, 0x30204F4B);
445 
446  cnt = 1;
447  //MMIO_in = 0x3 << DSEL_SHIFT | ( 1 << START_SHIFT);
448  initBuffer((ap_uint<4>) cnt, xmem, false, false);
449  stepDut();
450  succeded &= checkResult(MMIO, 0x31204F4B);
451 
452  cnt = 2;
453  stepDut();
454  succeded &= checkResult(MMIO, 0x31555444);
455 
456  initBuffer((ap_uint<4>) cnt, xmem, false, false);
457  stepDut();
458  succeded &= checkResult(MMIO, 0x32204F4B);
459 
460  cnt = 3;
461  initBuffer((ap_uint<4>) cnt, xmem, false, false);
462  xmem[2] = 42;
463  stepDut();
464  succeded &= checkResult(MMIO, 0x33204F4B);
465 
466  //RST
467  MMIO_in = 0x3 << DSEL_SHIFT | ( 1 << RST_SHIFT);
468  stepDut(); //12
469  succeded &= checkResult(MMIO, 0x3349444C);
470 
471  cnt = 0;
472  MMIO_in = 0x3 << DSEL_SHIFT | ( 1 << START_SHIFT);
473  initBuffer((ap_uint<4>) cnt, xmem, false, false);
474  stepDut();
475  succeded &= checkResult(MMIO, 0x30204F4B);
476 
477  cnt = 1;
478  initBuffer((ap_uint<4>) cnt, xmem, false, false);
479  xmem[0] = 42;
480  stepDut();
481  succeded &= checkResult(MMIO, 0x30494E56);
482 
483  //Test RST
484  MMIO_in = 0x3 << DSEL_SHIFT | (1 << RST_SHIFT);
485  stepDut();
486  succeded &= checkResult(MMIO, 0x3049444C);
487 
488  //Test ABR
489  cnt = 0;
490  MMIO_in = 0x3 << DSEL_SHIFT | ( 1 << START_SHIFT);
491  initBuffer((ap_uint<4>) cnt, xmem, false, false);
492  //HWICAP[CR_OFFSET] = CR_ABORT;
493  HWICAP[ASR_OFFSET] = 0x42;
494  stepDut();
495  succeded &= checkResult(MMIO, 0x3f414252);
496 
497  HWICAP[ASR_OFFSET] = 0x0;
498  MMIO_in = 0x3 << DSEL_SHIFT | (1 << RST_SHIFT);
499  stepDut();
500  succeded &= checkResult(MMIO, 0x3f49444C);
501  assert(succeded);
502 
503  //RST again (BOR)
504  MMIO_in = 0x3 << DSEL_SHIFT | (1 << RST_SHIFT);
505  stepDut(); //18
506  //succeded &= checkResult(MMIO, 0x3f424f52);
507  succeded &= checkResult(MMIO & 0xFF000000, 0x3f000000);
508 
509  HWICAP[CR_OFFSET] = 0x0;
510  //one complete transfer with overflow
511  //LOOP
512  MMIO_in = 0x3 << DSEL_SHIFT | ( 1 << START_SHIFT);
513  //MMIO_in = 0x3 << DSEL_SHIFT | ( 1 << START_SHIFT) | ( 1 << CHECK_PATTERN_SHIFT);
514  for(int i = 0; i<0xf; i++)
515  {
516  cnt = i;
517  initBuffer((ap_uint<4>) cnt, xmem, false, false);
518  stepDut();
519  assert(decoupActive == 1);
520 
521  //printBuffer(bufferIn, "bufferIn", 7);
522  //printBuffer32(xmem,"Xmem",1);
523  //printf("currentBufferInPtr: %#010x\n",(int) currentBufferInPtr);
524  printf("WF: %#010x\n",(int) HWICAP[WF_OFFSET]);
525  //printf("xmem: %#010x\n",(int) xmem[LINES_PER_PAGE-1]);
526  int WF_should = 0;
527  if ( i % 2 == 0)
528  {
529  WF_should = (((xmem[LINES_PER_PAGE-2] & 0xff00) >>8) << 24);
530  WF_should |= (xmem[LINES_PER_PAGE-2] & 0xff0000);
531  WF_should |= ((xmem[LINES_PER_PAGE-2] & 0xff000000) >> 16); //24-8
532  WF_should |= (xmem[LINES_PER_PAGE-1] & 0xff);
533  } else {
534  WF_should = (xmem[LINES_PER_PAGE-2] & 0xff000000);
535  WF_should |= (xmem[LINES_PER_PAGE-1] & 0xff) << 16;
536  WF_should |= (xmem[LINES_PER_PAGE-1] & 0xff00);
537  WF_should |= ((xmem[LINES_PER_PAGE-1] & 0xff0000) >> 16);
538  }
539  printf("WF_should: %#010x\n", WF_should);
540  assert((int) HWICAP[WF_OFFSET] == WF_should);
541 
542  }
543 
544  printBuffer(bufferIn, "buffer after 0xf transfers:",8);
545 
546  printf("CR: %#010x\n", CR_OFFSET);
547  assert(HWICAP[CR_OFFSET] == CR_WRITE);
548 
549  cnt = 0xf;
550  initBuffer((ap_uint<4>) cnt, xmem, false, false);
551  stepDut(); //34
552  succeded &= checkResult(MMIO, 0x3f204f4b);
553  //printBuffer32(xmem, "Xmem:");
554 
555 // MMIO_in = 0x3 << DSEL_SHIFT | ( 1 << START_SHIFT) | ( 1 << CHECK_PATTERN_SHIFT);
556  cnt = 0x0;
557  initBuffer((ap_uint<4>) cnt, xmem, false, false);
558  HWICAP[WF_OFFSET] = 42;
559  HWICAP[CR_OFFSET] = 0;
560  stepDut();
561  //succeded &= checkResult(MMIO, 0x30204F4B) && (HWICAP[WF_OFFSET] == 42);
562  succeded &= checkResult(MMIO, 0x30204F4B);
563  assert(HWICAP[WF_OFFSET] != 42);
564  assert(HWICAP[CR_OFFSET] == CR_WRITE);
565 
566  MMIO_in = 0x3 << DSEL_SHIFT |(126 << LAST_PAGE_CNT_SHIFT) | ( 1 << START_SHIFT);
567  cnt = 0x1;
568  initBuffer((ap_uint<4>) cnt, xmem, true, false);
569  stepDut();
570  succeded &= checkResult(MMIO, 0x31535543);
571  assert(HWICAP[CR_OFFSET] == CR_WRITE);
572 
573  //Check CR_WRITE
574  HWICAP[CR_OFFSET] = 0;
575  stepDut(); //37
576  succeded &= checkResult(MMIO, 0x31535543);
577  assert(HWICAP[CR_OFFSET] == 0);
578 
579  //RST
580  MMIO_in = 0x3 << DSEL_SHIFT | (1 << RST_SHIFT);
581  stepDut();
582  succeded &= checkResult(MMIO, 0x3149444C);
583  assert(decoupActive == 0);
584 
585  //one complete transfer with overflow and Memcheck
586  //LOOP
587  //MMIO_in = 0x3 << DSEL_SHIFT | ( 1 << START_SHIFT) | (1 << SWAP_SHIFT);
588  //MMIO_in = 0x3 << DSEL_SHIFT | ( 1 << START_SHIFT);
589  MMIO_in = 0x3 << DSEL_SHIFT | ( 1 << START_SHIFT) | ( 1 << CHECK_PATTERN_SHIFT);
590 
591  xmem[0] = 0xAABBCC00;
592  xmem[4] = 0x12121212;
593  xmem[127] = 0xAABBCCFF;
594  stepDut();
595  assert(checkResult(MMIO, 0x3f494e56));
596  assert(decoupActive == 0);
597 
598  for(int i = 0; i<0xf; i++)
599  {
600  cnt = i;
601  initBuffer((ap_uint<4>) cnt, xmem, false, true);
602  stepDut();
603 
604  //printBuffer(bufferIn, "bufferIn", 7);
605  //printBuffer32(xmem,"Xmem",1);
606  printf("MMIO out: %#010x\n", (int) MMIO);
607  //assert((MMIO & 0xf0ffffff) == 0x30204F4B);
608  //msg could also be UTD instead of OK
609  //assert((MMIO & 0xf0ffffff) == (0x30204F4B | 0x30555444));
610  assert(decoupActive == 0);
611  }
612 
613  cnt = 0xf;
614  initBuffer((ap_uint<4>) cnt, xmem, false, true);
615  stepDut(); //55
616  assert(checkResult(MMIO & 0xf0ffffff, 0x30555444));
617 
618  printBuffer(bufferIn, "buffer after 16 check pattern transfers:",8);
619 
620  printf("== XMEM Test passed == \n");
621 //===========================================================
622 //Test HTTP
623 
624  printf("===== HTTP =====\n");
625 
626  MMIO_in = 0x3 << DSEL_SHIFT | (1 << RST_SHIFT);
627  stepDut();
628  succeded &= checkResult(MMIO, 0x3f49444C);
629 
630  // GET TEST
631  char *httpBuffer = new char[1024];
632  char* getStatus = "GET /status HTTP/1.1\r\nHost: localhost:8080\r\nUser-Agent: curl/7.47.0\r\nAccept: */*\r\n\r\n";
633  httpBuffer[0] = 0xF0;
634  strcpy(&httpBuffer[1],getStatus);
635  httpBuffer[strlen(getStatus)+1] = 0x0;
636  httpBuffer[127] = 0xF0;
637  //printBuffer((ap_uint<8>*)(uint8_t*) httpBuffer, "httpBuffer");
638  copyBufferToXmem(httpBuffer,xmem );
639  xmem[XMEM_ANSWER_START] = 42;
640  int lastPageBytes = strlen(getStatus) % 126;
641  MMIO_in = 0x3 << DSEL_SHIFT |(lastPageBytes << LAST_PAGE_CNT_SHIFT) | ( 1 << START_SHIFT) | ( 1 << PARSE_HTTP_SHIFT);
642  stepDut();
643  succeded &= checkResult(MMIO, 0x30535543);
644  assert(decoupActive == 0);
645  //printBuffer(bufferIn, "buffer after GET transfers:",2);
646  MMIO_in = 0x4 << DSEL_SHIFT | ( 1 << START_SHIFT) | ( 1 << PARSE_HTTP_SHIFT);
647  stepDut(); //58
648  succeded &= checkResult(MMIO & 0xFF00FFF0, 0x43000070);
649  assert(decoupActive == 0);
650  printBuffer(bufferOut, "Valid HTTP GET: BufferOut:",4);
651  printf("XMEM_ANSWER_START: %#010x\n",(int) xmem[XMEM_ANSWER_START]);
652  //printBuffer32(xmem, "Xmem:");
653  assert(xmem[XMEM_ANSWER_START] == 0x50545448);
654 
655 
656  //RST
657  MMIO_in = 0x3 << DSEL_SHIFT | (1 << RST_SHIFT);
658  stepDut();
659  succeded &= checkResult(MMIO & 0xf0ffffff, 0x3049444C);
660  assert(decoupActive == 0);
661 
662  // INVALID TEST
663  getStatus = "GET /theWorldAndEveryghing HTTP/1.1\r\nHost: localhost:8080\r\nUser-Agent: curl/7.47.0\r\nAccept: */*\r\n\r\n";
664  httpBuffer[0] = 0xF0;
665  strcpy(&httpBuffer[1],getStatus);
666  httpBuffer[strlen(getStatus)+1] = 0x0;
667  httpBuffer[127] = 0xF0;
668  //printBuffer((ap_uint<8>*)(uint8_t*) httpBuffer, "httpBuffer");
669  copyBufferToXmem(httpBuffer,xmem );
670  xmem[XMEM_ANSWER_START] = 42;
671  lastPageBytes = strlen(getStatus) % 126;
672  MMIO_in = 0x3 << DSEL_SHIFT |(lastPageBytes << LAST_PAGE_CNT_SHIFT) | ( 1 << START_SHIFT) | ( 1 << PARSE_HTTP_SHIFT);
673  stepDut(); //60
674  succeded &= checkResult(MMIO, 0x30535543);
675  assert(decoupActive == 0);
676  //printBuffer(bufferIn, "buffer after Invalid GET transfers:",2);
677 
678  MMIO_in = 0x4 << DSEL_SHIFT | ( 1 << START_SHIFT) | ( 1 << PARSE_HTTP_SHIFT);
679  stepDut();
680  succeded &= checkResult(MMIO, 0x43000061);
681  assert(decoupActive == 0);
682 
683  printBuffer(bufferOut, "INVALID REQUEST; BufferOut:",2);
684  // printf("XMEM_ANSWER_START: %#010x\n",(int) xmem[XMEM_ANSWER_START]);
685  //printBuffer32(xmem, "Xmem:");
686  assert(xmem[XMEM_ANSWER_START] == 0x50545448);
687 
688  HWICAP[WFV_OFFSET] = 0x710;
689 
690  //RST
691  MMIO_in = 0x3 << DSEL_SHIFT | (1 << RST_SHIFT);
692  stepDut();
693  succeded &= checkResult(MMIO & 0xf0ffffff, 0x3049444C);
694  assert(decoupActive == 0);
695 
696  // INVALID TEST 2
697  getStatus = "GET /theWorldAndEveryghing HTTP/1.1\r\nHost: localhost:8080\r\nUser-Agent: curl/7.47.0\r\nAccept: */*\r\n"; //i.e. missing second \r\n
698  httpBuffer[0] = 0xF0;
699  strcpy(&httpBuffer[1],getStatus);
700  httpBuffer[strlen(getStatus)+1] = 0x0;
701  httpBuffer[127] = 0xF0;
702  //printBuffer((ap_uint<8>*)(uint8_t*) httpBuffer, "httpBuffer");
703  copyBufferToXmem(httpBuffer,xmem );
704  xmem[XMEM_ANSWER_START] = 42;
705  lastPageBytes = strlen(getStatus) % 126;
706  MMIO_in = 0x3 << DSEL_SHIFT |(lastPageBytes << LAST_PAGE_CNT_SHIFT) | ( 1 << START_SHIFT) | ( 1 << PARSE_HTTP_SHIFT);
707  stepDut();
708  succeded &= checkResult(MMIO, 0x30535543);
709  assert(decoupActive == 0);
710  //printBuffer(bufferIn, "buffer after 2. Invalid GET transfers:",2);
711 
712  MMIO_in = 0x4 << DSEL_SHIFT | ( 1 << START_SHIFT) | ( 1 << PARSE_HTTP_SHIFT);
713  stepDut();
714  succeded &= checkResult(MMIO, 0x43000061);
715  assert(decoupActive == 0);
716 
717  //printBuffer(bufferOut, "BufferOut:",2);
718  //printf("XMEM_ANSWER_START: %#010x\n",(int) xmem[XMEM_ANSWER_START]);
719  //printBuffer32(xmem, "Xmem:");
720  assert(xmem[XMEM_ANSWER_START] == 0x50545448);
721 
722  HWICAP[WFV_OFFSET] = 0x710;
723 
724 
725  //RST
726  MMIO_in = 0x3 << DSEL_SHIFT | (1 << RST_SHIFT);
727  stepDut(); //65
728  succeded &= checkResult(MMIO & 0xf0ffffff, 0x3049444C);
729 
730  // POST TEST
731  getStatus = "POST /configure HTTP/1.1\r\nHost: localhost:8080\r\nUser-Agent: curl/7.47.0\r\nContent-Length: 1607\r\n \
732 Content-Type: application/x-www-form-urlencodedAB\r\n\r\nffffffffffbb11220044ffffffffffffffffaa99556620000000200000002000";
733  printf("%s\n",getStatus);
734  httpBuffer[0] = 0x00;
735  strcpy(&httpBuffer[1],getStatus);
736  httpBuffer[strlen(getStatus)+1] = 0x0;
737  httpBuffer[127] = 0x00; //this will damage some payload, but should be ok here
738  httpBuffer[128] = 0xF1;
739  httpBuffer[255] = 0XF1;
740  //printBuffer((ap_uint<8>*)(uint8_t*) httpBuffer, "POST httpBuffer", 3);
741  copyBufferToXmem(httpBuffer,xmem );
742  xmem[XMEM_ANSWER_START] = 42;
743  HWICAP[WF_OFFSET] = 0x42;
744  HWICAP[WFV_OFFSET] = 0x1FE; //to not trigger the "empty FIFO" counter
745  //printBuffer32(xmem, "Xmem:",2);
746  lastPageBytes = strlen(getStatus) % 126;
747  MMIO_in = 0x3 << DSEL_SHIFT |(lastPageBytes << LAST_PAGE_CNT_SHIFT) | ( 1 << START_SHIFT) | ( 1 << PARSE_HTTP_SHIFT);
748  stepDut();
749  succeded &= checkResult(MMIO, 0x30204F4B);
750  printBuffer(bufferIn, "buffer IN after POST 1/2:",3);
751  copyBufferToXmem(&httpBuffer[128],xmem );
752  // printBuffer32(xmem, "Xmem:",2);
753  stepDut();
754  succeded &= checkResult(MMIO, 0x31535543);
755  printBuffer(bufferIn, "buffer IN after POST 2/2:",3);
756  MMIO_in = 0x4 << DSEL_SHIFT | ( 1 << START_SHIFT) | ( 1 << PARSE_HTTP_SHIFT);
757  stepDut();
758  printBuffer(bufferOut, "POST TEST 1; BufferOut:",2);
759  succeded &= checkResult(MMIO, 0x43000072);
760  printf("XMEM_ANSWER_START: %#010x\n",(int) xmem[XMEM_ANSWER_START]);
761  printf("WF: %#010x\n",(int) HWICAP[WF_OFFSET]);
762  //printBuffer32(xmem, "Xmem:");
763  assert(decoupActive == 0);
764  assert(xmem[XMEM_ANSWER_START] == 0x50545448);
765  //assert(HWICAP[WF_OFFSET] == 0x32303030);
766 
767  //RST
768  MMIO_in = 0x3 << DSEL_SHIFT | (1 << RST_SHIFT);
769  stepDut(); //69
770  succeded &= checkResult(MMIO & 0xf0ffffff, 0x3049444C);
771 
772  // POST TEST 2
773  //getStatus = "POST /configure HTTP/1.1\r\nHost: localhost:8080\r\nUser-Agent: curl/7.47.0\r\nContent-Length: 1607\r\nContent-Type: application/x-www-form-urlencoded\r\n\r\nffff000000bb11220044ffffffffffffffffaa995566200000002000000020000000200000002000000020000000200000002000000020000000200000002000000020000000200000002000000000200000002000000020000000200000002000";
774  getStatus = "POST /configure HTTP/1.1\r\nUser-Agent: curl/7.47.0\r\nContent-Type: application/x-www-form-urlencoded\r\n\r\nffff000000bb11220044ffffffffffffffffaa995566200000002000000020000000200000002000000020000000200000002000000020000000200000002000000020000000200000002000000000200000002000000020000000200000002000";
775 
776  printf("%s\n",getStatus);
777 
778  httpBuffer[0] = 0x00;
779  strcpy(&httpBuffer[1],getStatus);
780  httpBuffer[strlen(getStatus)+1] = 0x0;
781  httpBuffer[127] = 0x00; //this will damage some payload, but should be ok here
782  httpBuffer[128] = 0x01;
783  httpBuffer[255] = 0X01;
784  httpBuffer[256] = 0xF2;
785  httpBuffer[383] = 0xF2;
786  //printBuffer((ap_uint<8>*)(uint8_t*) httpBuffer, "POST httpBuffer", 3);
787  copyBufferToXmem(httpBuffer,xmem );
788  xmem[XMEM_ANSWER_START] = 42;
789  HWICAP[WF_OFFSET] = 0x42;
790  //printBuffer32(xmem, "Xmem:",2);
791  lastPageBytes = strlen(getStatus) % 126;
792  MMIO_in = 0x3 << DSEL_SHIFT |(lastPageBytes << LAST_PAGE_CNT_SHIFT) | ( 1 << START_SHIFT) | ( 1 << PARSE_HTTP_SHIFT);
793  stepDut(); //70
794  succeded &= checkResult(MMIO, 0x30204F4B);
795  printBuffer(bufferIn, "buffer IN after POST 1/3:",3);
796  copyBufferToXmem(&httpBuffer[128],xmem );
797  //printBuffer32(xmem, "Xmem:",2);
798  stepDut();
799  succeded &= checkResult(MMIO, 0x31204F4B);
800  assert(decoupActive == 1);
801 
802  printBuffer(bufferIn, "buffer IN after POST 2/3:",3);
803  printf("WF: %#010x\n",(int) HWICAP[WF_OFFSET]);
804 
805  for(int i = 2; i<0x1f; i++)
806  {
807  cnt = i;
808  initBuffer((ap_uint<4>) cnt, xmem, false, false);
809  HWICAP[CR_OFFSET] = 0;
810  //printBuffer32(xmem,"Xmem",1);
811  stepDut();
812  //test double call --> nothing should change
813  for(int j = 0; j< 4; j++)
814  {
815  stepDut();
816  }
817 
818  assert(decoupActive == 1);
819  assert(HWICAP[CR_OFFSET] == CR_WRITE);
820 
821 
822  }
823  cnt = 0xf;
824  initBuffer((ap_uint<4>) cnt, xmem, true, false);
825  stepDut(); //217
826  succeded &= checkResult(MMIO, 0x3f535543);
827 
828  stepDut();
829  int WF_should = 0;
830  WF_should = (xmem[LINES_PER_PAGE-3] & 0xff000000);
831  WF_should |= (xmem[LINES_PER_PAGE-2] & 0xff) << 16;
832  WF_should |= (xmem[LINES_PER_PAGE-2] & 0xff00);
833  WF_should |= ((xmem[LINES_PER_PAGE-2] & 0xff0000) >> 16);
834  //printf("WF_should: %#010x\n", WF_should);
835 
836  // printBuffer32(xmem,"Xmem",1);
837  stepDut();
838  printBuffer(bufferIn, "bufferIn after 15 HTTP transfer", 8);
839 
840  //Check CR_WRITE
841  HWICAP[CR_OFFSET] = 0;
842  stepDut(); //220
843  succeded &= checkResult(MMIO, 0x3f535543);
844  assert(HWICAP[CR_OFFSET] == 0);
845 
846 
847  MMIO_in = 0x4 << DSEL_SHIFT;
848  stepDut();
849  succeded &= checkResult(MMIO, 0x40000072);
850  assert(decoupActive == 0);
851 
852  printBuffer(bufferOut, "BufferOut:",2);
853  printf("XMEM_ANSWER_START: %#010x\n",(int) xmem[XMEM_ANSWER_START]);
854  printf("WF: %#010x\n",(int) HWICAP[WF_OFFSET]);
855 
856  //printBuffer32(xmem, "Xmem:");
857  assert(xmem[XMEM_ANSWER_START] == 0x50545448);
858 
859  //RST
860  MMIO_in = 0x3 << DSEL_SHIFT | (1 << RST_SHIFT);
861  stepDut();
862  //succeded &= checkResult(MMIO & 0xf0ffffff, 0x30424f52); //FMC is already boring
863  succeded &= checkResult(MMIO & 0xFF000000, 0x3f000000);
864  assert(decoupActive == 0);
865 
866  // PUT RANK TEST
867  getStatus = "PUT /rank/42 HTTP/1.1\r\nUser-Agent: curl/7.47.0\r\nAccept: */*\r\n\r\n";
868  httpBuffer[0] = 0xF0;
869  strcpy(&httpBuffer[1],getStatus);
870  httpBuffer[strlen(getStatus)+1] = 0x0;
871  httpBuffer[127] = 0xF0;
872  //printBuffer((ap_uint<8>*)(uint8_t*) httpBuffer, "httpBuffer");
873  copyBufferToXmem(httpBuffer,xmem );
874  xmem[XMEM_ANSWER_START] = 42;
875  lastPageBytes = strlen(getStatus) % 126;
876  MMIO_in = 0x3 << DSEL_SHIFT |(lastPageBytes << LAST_PAGE_CNT_SHIFT) | ( 1 << START_SHIFT) | ( 1 << PARSE_HTTP_SHIFT);
877  stepDut();
878  succeded &= checkResult(MMIO, 0x30535543);
879  assert(decoupActive == 0);
880  //printBuffer(bufferIn, "buffer after PUT RANK transfers:",2);
881  MMIO_in = 0x4 << DSEL_SHIFT | ( 1 << PARSE_HTTP_SHIFT);
882  stepDut();
883  succeded &= checkResult(MMIO, 0x40000071);
884  assert(decoupActive == 0);
885  printBuffer(bufferOut, "PUT RANK: BufferOut:",2);
886  //printf("XMEM_ANSWER_START: %#010x\n",(int) xmem[XMEM_ANSWER_START]);
887  //printBuffer32(xmem, "Xmem:");
888  assert(xmem[XMEM_ANSWER_START] == 0x50545448);
889  assert(nodeRank_out == 42);
890 
891  //RST
892  MMIO_in = 0x3 << DSEL_SHIFT | (1 << RST_SHIFT);
893  stepDut(); //225
894  //succeded &= checkResult(MMIO & 0xf0ffffff, 0x30424f52);
895  succeded &= checkResult(MMIO & 0xFF000000, 0x30000000);
896  assert(decoupActive == 0);
897 
898  // PUT RANK INVALID TEST
899  getStatus = "PUT /rank/abc HTTP/1.1\r\nUser-Agent: curl/7.47.0\r\nAccept: */*\r\n\r\n";
900  httpBuffer[0] = 0xF0;
901  strcpy(&httpBuffer[1],getStatus);
902  httpBuffer[strlen(getStatus)+1] = 0x0;
903  httpBuffer[127] = 0xF0;
904  //printBuffer((ap_uint<8>*)(uint8_t*) httpBuffer, "httpBuffer");
905  copyBufferToXmem(httpBuffer,xmem );
906  xmem[XMEM_ANSWER_START] = 42;
907  lastPageBytes = strlen(getStatus) % 126;
908  MMIO_in = 0x3 << DSEL_SHIFT |(lastPageBytes << LAST_PAGE_CNT_SHIFT) | ( 1 << START_SHIFT) | ( 1 << PARSE_HTTP_SHIFT);
909  stepDut();
910  succeded &= checkResult(MMIO, 0x30535543);
911  assert(decoupActive == 0);
912  // printBuffer(bufferIn, "buffer after PUT RANK transfers:",2);
913  MMIO_in = 0x4 << DSEL_SHIFT | ( 1 << PARSE_HTTP_SHIFT);
914  stepDut();
915  succeded &= checkResult(MMIO, 0x40000061);
916  assert(decoupActive == 0);
917  printBuffer(bufferOut, "PUT RANK INVALID: BufferOut:",2);
918  //printf("XMEM_ANSWER_START: %#010x\n",(int) xmem[XMEM_ANSWER_START]);
919  //printBuffer32(xmem, "Xmem:");
920  assert(xmem[XMEM_ANSWER_START] == 0x50545448);
921  //assert(nodeRank_out == 0);
922 
923 
924  //RST
925  MMIO_in = 0x3 << DSEL_SHIFT | (1 << RST_SHIFT);
926  stepDut();
927  succeded &= checkResult(MMIO & 0xFF000000, 0x30000000);
928  assert(decoupActive == 0);
929 
930  // PUT SIZE TEST
931  getStatus = "PUT /size/5 HTTP/1.1\r\nUser-Agent: curl/7.47.0\r\nAccept: */*\r\n\r\n";
932  httpBuffer[0] = 0xF0;
933  strcpy(&httpBuffer[1],getStatus);
934  httpBuffer[strlen(getStatus)+1] = 0x0;
935  httpBuffer[127] = 0xF0;
936  //printBuffer((ap_uint<8>*)(uint8_t*) httpBuffer, "httpBuffer");
937  copyBufferToXmem(httpBuffer,xmem );
938  xmem[XMEM_ANSWER_START] = 42;
939  lastPageBytes = strlen(getStatus) % 126;
940  MMIO_in = 0x3 << DSEL_SHIFT |(lastPageBytes << LAST_PAGE_CNT_SHIFT) | ( 1 << START_SHIFT) | ( 1 << PARSE_HTTP_SHIFT);
941  stepDut();
942  succeded &= checkResult(MMIO, 0x30535543);
943  assert(decoupActive == 0);
944  //printBuffer(bufferIn, "buffer after PUT SIZE transfers:",2);
945  MMIO_in = 0x4 << DSEL_SHIFT | ( 1 << PARSE_HTTP_SHIFT);
946  stepDut();
947  succeded &= checkResult(MMIO, 0x40000071);
948  assert(decoupActive == 0);
949  printBuffer(bufferOut, "PUT SIZE: BufferOut:",2);
950  //printf("XMEM_ANSWER_START: %#010x\n",(int) xmem[XMEM_ANSWER_START]);
951  //printBuffer32(xmem, "Xmem:");
952  assert(xmem[XMEM_ANSWER_START] == 0x50545448);
953  assert(clusterSize_out == 5);
954 
955  printf("== HTTP Test passed == \n");
956 
957 //===========================================================
958 //Test PYROLINK
959 #ifdef INCLUDE_PYROLINK
960 
961  assert(succeded);
962  printf("===== PYROLINK TEST =====\n");
963 
964  //RST ...BOR
965  MMIO_in = 0x3 << DSEL_SHIFT | (1 << RST_SHIFT);
966  stepDut(); //231
967  succeded &= checkResult(MMIO & 0xf0ffffff, 0x30424f52); //TODO: msg filed may have changed
968 
969  MMIO_in = 0x3 << DSEL_SHIFT | ( 1 << PYRO_MODE_SHIFT) | 10 << LAST_PAGE_CNT_SHIFT;
970 
971  for(int i = 0; i<0xf; i++)
972  {
973  cnt = i;
974  initBuffer((ap_uint<4>) cnt, xmem, false, true);
975  stepDut();
976 
977  ap_uint<8> ctrlByte = ((cnt & 0xf) << 4) | (cnt & 0xf);
978  for(int j = 0; j <126; j++)
979  {
980  assert(!FMC_Debug_Pyrolink.empty());
981  Axis<8> tmp = FMC_Debug_Pyrolink.read();
982  assert(tmp.tdata == ctrlByte);
983  }
984 
985  }
986 
987  assert(decoupActive == 0);
988  cnt = 0xf;
989  initBuffer((ap_uint<4>) cnt, xmem, true, true);
990  stepDut();
991  assert(checkResult(MMIO & 0xf0ffffff, 0x30535543));
992 
993  //10 Byte only on the last page
994  ap_uint<8> ctrlByte = ((cnt & 0xf) << 4) | (cnt & 0xf);
995  for(int j = 0; j <10; j++)
996  {
997  assert(!FMC_Debug_Pyrolink.empty());
998  Axis<8> tmp = FMC_Debug_Pyrolink.read();
999  //printf("last page byte %d: .tdata: %d .tkeep: %d .tlast: %d\n",j, (int) tmp.tdata, (int) tmp.tkeep, (int) tmp.tlast);
1000 
1001  assert(tmp.tdata == ctrlByte);
1002  if(j == 9)
1003  {
1004  assert(tmp.tlast == 1);
1005  }
1006  }
1007  //assert nothing left
1008  assert(FMC_Debug_Pyrolink.empty());
1009 
1010  //RST
1011  MMIO_in = 0x3 << DSEL_SHIFT | (1 << RST_SHIFT);
1012  stepDut(); //248
1013  succeded &= checkResult(MMIO & 0xf0ffffff, 0x3049444C);
1014 
1015  for(int j = 0; j<(3*128 + 14); j++)
1016  {
1017  Axis<8> tmp = Axis<8>();
1018  tmp.tkeep = 1;
1019  tmp.tlast = 0;
1020  tmp.tdata = j;
1021  Debug_FMC_Pyrolink.write(tmp);
1022  }
1023 
1024  Axis<8> tmp = Axis<8>();
1025  tmp.tkeep = 1;
1026  tmp.tlast = 1;
1027  tmp.tdata = 3*128 + 15;
1028  Debug_FMC_Pyrolink.write(tmp);
1029 
1030  //test read request
1031  MMIO_in = 0x6 << DSEL_SHIFT;
1032  stepDut();
1033  succeded &= checkResult(MMIO & 0xf0800000, 0x60800000); //we are only interested in the pyro send request bit
1034 
1035  MMIO_in = 0x6 << DSEL_SHIFT | (1 << PYRO_READ_REQUEST_SHIFT);
1036  stepDut(); //250
1037  succeded &= checkResult(MMIO & 0xf0ff0000, 0x600F0000);
1038 
1039  printBuffer(bufferOut, "buffer OUT after Pyrolink READ:",4);
1040  assert(bufferOut[3*128+15 - 1] == (3*128 + 15) % 256);
1041 
1042  printf("== PYROLINK Test passed == \n");
1043 #else
1044  printf("-- Skipping PYROLINK Test (+20 stepDut) -- \n");
1045  simCnt += 20;
1046 #endif
1047 
1048 //===========================================================
1049 //Test NAL
1050 
1051  printf("===== NAL =====\n");
1052  layer_6_enabled = 0b1;
1054 
1055  //RST
1056  MMIO_in = 0x3 << DSEL_SHIFT | (1 << RST_SHIFT);
1057  stepDut(); //251
1058  succeded &= checkResult(MMIO & 0xf0f0f000, (0x3049444C | 0x30424f52) & 0xf0f0f000); //FMC is somehow bored
1059  assert(decoupActive == 0);
1060 
1061  //POST ROUTING TABLE
1062  getStatus = "POST /routing HTTP/1.1\r\nUser-Agent: curl/7.47.0\r\nContent-Type: application/x-www-form-urlencoded\r\n\r\n";
1063 
1064  printf("%s\n",getStatus);
1065 
1066  httpBuffer[0] = 0x00;
1067  strcpy(&httpBuffer[1],getStatus);
1068  int startTable = strlen(getStatus);
1069  int routingTable[25] = {0x30,0x20, 0x0a, 0x0b, 0x0c, 0x01, 0x0a, 0x31,0x20, 0x0a, 0x0b, 0x0c, 0x02, 0x0a, 0x32,0x20, 0x0a, 0x0b, 0x0c, 0x05, 0x0a, 0x0d, 0x0a, 0x0d, 0x0a};
1070  {
1071  int j = startTable + 1;
1072  int i = 0;
1073  while(i<25)
1074  {
1075  if(j == 127)
1076  {
1077  httpBuffer[j] = 0x00;
1078  httpBuffer[j + 1] = 0xF1;
1079  j += 2;
1080  continue;
1081  }
1082 
1083  httpBuffer[j] = routingTable[i];
1084  i++;
1085  j++;
1086 
1087  }
1088  //to be sure
1089  httpBuffer[127] = 0x00;
1090  httpBuffer[128] = 0xF1;
1091  httpBuffer[255] = 0xF1;
1092  }
1093  printBuffer((uint8_t*) httpBuffer, "POST ROUTING httpBuffer", 3);
1094  copyBufferToXmem(httpBuffer,xmem );
1095  xmem[XMEM_ANSWER_START] = 42;
1096  lastPageBytes = (strlen(getStatus) + 25) % 126;
1097 
1099 
1100  //MMIO_in = 0x3 << DSEL_SHIFT | ( 1 << START_SHIFT) | ( 1 << PARSE_HTTP_SHIFT);
1101  MMIO_in = 0x3 << DSEL_SHIFT |(lastPageBytes << LAST_PAGE_CNT_SHIFT) | ( 1 << START_SHIFT) | ( 1 << PARSE_HTTP_SHIFT);
1102  stepDut();
1103  succeded &= checkResult(MMIO, 0x30204F4B);
1104  copyBufferToXmem(&httpBuffer[128],xmem );
1105  stepDut();
1106  succeded &= checkResult(MMIO, 0x30535543);
1107  assert(decoupActive == 0);
1108 
1109  MMIO_in = 0x4 << DSEL_SHIFT | ( 1 << PARSE_HTTP_SHIFT);
1110  stepDut();
1111  succeded &= checkResult(MMIO, 0x40000071);
1112  assert(decoupActive == 0);
1113  printBuffer(bufferIn, "POST_ROUTING: BufferIn:",3);
1114  printBuffer(bufferOut, "POST_ROUTING: BufferOut:",2);
1115  assert(xmem[XMEM_ANSWER_START] == 0x50545448);
1116 
1117  stepDut(); //255 //for coping MRT
1118  stepDut();
1119  stepDut(); //257
1120  assert(nalCtrl[NAL_CTRL_LINK_MRT_START_ADDR + 0] == 0x0a0b0c01);
1121  assert(nalCtrl[NAL_CTRL_LINK_MRT_START_ADDR + 1] == 0x0a0b0c02);
1122  assert(nalCtrl[NAL_CTRL_LINK_MRT_START_ADDR + 2] == 0x0a0b0c05);
1123 
1124  printf("== NAL Test passed == \n");
1125 //===========================================================
1126 //Test TCP
1127 
1128  printf("===== TCP =====\n");
1129 
1130 
1131 //RST again (BOR)
1132  MMIO_in = 0x3 << DSEL_SHIFT | (1 << RST_SHIFT);
1133  stepDut(); //258
1134  succeded &= checkResult(MMIO & 0xFF000000, 0x30000000);
1135 
1136  HWICAP[CR_OFFSET] = 0x0;
1137  ap_uint<32> WF_ctrl = 0;
1138 
1139  getStatus = "GET /status HTTP/1.1\r\nHost: localhost:8080\r\nUser-Agent: curl/7.47.0\r\nAccept: */*\r\n\r\n";
1140  strcpy(&httpBuffer[0],getStatus);
1141  copyBufferToStream(httpBuffer,sNAL_FMC_Tcp_data,strlen(getStatus));
1142 
1143  Axis<16> sessId = Axis<16>(43);
1144  sessId.setTLast(1);
1145  //sNAL_FMC_Tcp_sessId.write(sessId);
1146  sNAL_FMC_Tcp_sessId.write(sessId.getTData());
1147 
1148  MMIO_in = 0x3 << DSEL_SHIFT | ( 1 << ENABLE_TCP_MODE_SHIFT) | ( 1 << PARSE_HTTP_SHIFT);
1149 
1150  //new TCP FSM: should take only 4 cycles
1151  stepDut();
1152  stepDut(); //260
1153  stepDut();
1154  stepDut();
1155  printBuffer(bufferIn, "Valid HTTP GET: BufferIn:",2);
1156  printBuffer(bufferOut, "Valid HTTP GET: BufferOut:",4);
1157 
1158  Axis<16> sessId_back = sFMC_NAL_Tcp_sessId.read();
1159  assert(sessId.getTData() == sessId_back.getTData());
1161  assert(sFMC_NAL_Tcp_data.empty());
1162 
1163  //"self reset"
1164  stepDut();
1165  stepDut();
1166 
1167  // POST TEST via TCP
1168  // first chunk
1169  getStatus = "POST /configure HTTP/1.1\r\nUser-Agent: curl/7.47.0\r\nContent-Type: application/x-www-form-urlencoded\r\n\r\nffff000000bb11220044ffffffffffffffffaa9955662000000021000000220000002300000024000000250000002600000027000000280abcd";
1170 
1171  printf("%s\n",getStatus);
1172 
1173  strcpy(&httpBuffer[0],getStatus);
1174  copyBufferToStream(httpBuffer,sNAL_FMC_Tcp_data,strlen(getStatus));
1175 
1176  sessId = Axis<16>(45);
1177  sessId.setTLast(1);
1178  sNAL_FMC_Tcp_sessId.write(sessId.getTData());
1179 
1180  HWICAP[WFV_OFFSET] = 0x3FF;
1181  HWICAP[WF_OFFSET] = 0x42;
1182  HWICAP[CR_OFFSET] = 0;
1183  stepDut(); //265
1184  stepDut();
1185  stepDut();
1186  assert(decoupActive == 1); //should be there immediately
1187  assert(HWICAP[CR_OFFSET] == CR_WRITE);
1188  //printBuffer(bufferIn, "bufferIn after TCP HTTP transfer", 2);
1189 
1190  //second chunk
1191  getStatus = "e290000002000000021000000220000002300000000240000002500000026000002700123456789AB\r\n\r\n";
1192  // -> 196 payload bytes
1193 
1194  printf("%s\n",getStatus);
1195 
1196  strcpy(&httpBuffer[0],getStatus);
1197  copyBufferToStream(httpBuffer,sNAL_FMC_Tcp_data,strlen(getStatus));
1198 
1199  //check telomere (should NOT be used)
1200  assert(bufferInPtrNextRead > 0);
1201  stepDut();
1202  printBuffer(bufferIn, "bufferIn after TCP HTTP transfer", 4);
1203 
1204  //process remaining
1205  //HWICAP[WFV_OFFSET] = 0x1DE;
1206  for(int j = 0; j< 3; j++)
1207  {
1208  stepDut();
1209  }
1210 
1211  //printBuffer(bufferOut, "Valid HTTP POST: BufferOut:",4);
1212 
1213  assert(decoupActive == 0);
1214  printf("WF: %#010x\n",(int) HWICAP[WF_OFFSET]);
1215  //WF_should = 0;
1216  //WF_should = 0x00002000;
1217  WF_should = 0x38394142; //we test in Ascii...
1218  printf("WF_should: %#010x\n", WF_should);
1219  assert((int) HWICAP[WF_OFFSET] == WF_should);
1220 
1221  //Check CR_WRITE
1222  HWICAP[CR_OFFSET] = 0;
1223  stepDut(); //271
1224  succeded &= checkResult(MMIO, 0x30574154); //WAT
1225  assert(decoupActive == 0);
1226  assert(HWICAP[CR_OFFSET] == 0);
1227 
1228  sessId_back = sFMC_NAL_Tcp_sessId.read();
1229  assert(sessId.getTData() == sessId_back.getTData());
1231  assert(sFMC_NAL_Tcp_data.empty());
1232  assert(sFMC_NAL_Tcp_sessId.empty());
1233 
1234  //"self reset"
1235  stepDut(); //272
1236  stepDut();
1237 
1238  //POST ROUTING via TCP
1239  getStatus = "POST /routing HTTP/1.1\r\nUser-Agent: curl/7.47.0\r\nContent-Type: application/x-www-form-urlencoded\r\n\r\n";
1240 
1241  printf("%s\n",getStatus);
1242 
1243  strcpy(&httpBuffer[0],getStatus);
1244  startTable = strlen(getStatus);
1245  //int routingTable[25] = {0x30,0x20, 0x0a, 0x0b, 0x0c, 0x01, 0x0a, 0x31,0x20, 0x0a, 0x0b, 0x0c, 0x02, 0x0a, 0x32,0x20, 0x0a, 0x0b, 0x0c, 0x05, 0x0a, 0x0d, 0x0a, 0x0d, 0x0a};
1246  //reuse routing table
1247  {
1248  int j = startTable;
1249  int i = 0;
1250  while(i<25)
1251  {
1252  httpBuffer[j] = routingTable[i];
1253  i++;
1254  j++;
1255  }
1256  }
1257  copyBufferToStream(httpBuffer,sNAL_FMC_Tcp_data,strlen(getStatus) + 25);
1258 
1262 
1263  sessId = Axis<16>(46);
1264  sessId.setTLast(1);
1265  sNAL_FMC_Tcp_sessId.write(sessId.getTData());
1266 
1267  stepDut(); //three step only for TCP
1268  stepDut(); //275
1269  stepDut();
1270  stepDut();
1271  //sim_fpga_time_seconds += 4;
1272 
1273  printBuffer(bufferIn, "bufferIn after TCP HTTP POST /routing", 2);
1274 
1275  sessId_back = sFMC_NAL_Tcp_sessId.read();
1276  assert(sessId.getTData() == sessId_back.getTData());
1278  assert(sFMC_NAL_Tcp_data.empty());
1279  assert(decoupActive == 0);
1280 
1281  //some for updating MRT
1282  for(int j = 0; j< 2; j++)
1283  {
1284  stepDut();
1285  }
1286 
1287  assert(nalCtrl[NAL_CTRL_LINK_MRT_START_ADDR + 0] == 0x0a0b0c01);
1288  assert(nalCtrl[NAL_CTRL_LINK_MRT_START_ADDR + 1] == 0x0a0b0c02);
1289  assert(nalCtrl[NAL_CTRL_LINK_MRT_START_ADDR + 2] == 0x0a0b0c05);
1290 
1291  //"self reset"
1292  stepDut(); //279
1293  stepDut();
1294 
1295  //INVALID POST ROUTING via TCP
1296  getStatus = "POST /routing HTTP/1.1\r\nUser-Agent: curl/7.47.0\r\nContent-Type: application/x-www-form-urlencoded\r\nbla\r\n\r\n";
1297 
1298  printf("%s\n",getStatus);
1299 
1300  strcpy(&httpBuffer[0],getStatus);
1301  startTable = strlen(getStatus);
1302  //int routingTable[25] = {0x30,0x20, 0x0a, 0x0b, 0x0c, 0x01, 0x0a, 0x31,0x20, 0x0a, 0x0b, 0x0c, 0x02, 0x0a, 0x32,0x20, 0x0a, 0x0b, 0x0c, 0x05, 0x0a, 0x0d, 0x0a, 0x0d, 0x0a};
1303  //reuse routing table
1304  {
1305  int j = startTable + 3;//this should be enought to become invalid
1306  int i = 0;
1307  while(i<25)
1308  {
1309  httpBuffer[j] = routingTable[i];
1310  i++;
1311  j++;
1312  }
1313  }
1314  copyBufferToStream(httpBuffer,sNAL_FMC_Tcp_data,strlen(getStatus) + 25 + 3);
1315 
1319 
1320  sessId = Axis<16>(47);
1321  sessId.setTLast(1);
1322  sNAL_FMC_Tcp_sessId.write(sessId.getTData());
1323 
1324  stepDut(); //three step only for TCP
1325  stepDut();
1326  stepDut(); //283
1327 
1328  //printBuffer(bufferIn, "bufferIn after TCP HTTP POST /routing", 2);
1329 
1330  sessId_back = sFMC_NAL_Tcp_sessId.read();
1331  assert(sessId.getTData() == sessId_back.getTData());
1332 
1333  //check 422
1334  printf("Check stream:\n0x312e312f50545448\n0x706e552032323420\n0x6261737365636f72\n0x7469746e4520656c\n0x65686361430a0d79\n");
1335  assert(sFMC_NAL_Tcp_data.read().tdata == 0x312e312f50545448);
1336  assert(sFMC_NAL_Tcp_data.read().tdata == 0x706e552032323420);
1337  assert(sFMC_NAL_Tcp_data.read().tdata == 0x6261737365636f72);
1338  assert(sFMC_NAL_Tcp_data.read().tdata == 0x7469746e4520656c);
1339  assert(sFMC_NAL_Tcp_data.read().tdata == 0x65686361430a0d79);
1340  //drain remaining
1341  printf("Partial ");
1343  assert(sFMC_NAL_Tcp_data.empty());
1344 
1345  //nothing should have happened
1346  assert(decoupActive == 0);
1347  assert(nalCtrl[NAL_CTRL_LINK_MRT_START_ADDR + 0] == 0x0);
1348  assert(nalCtrl[NAL_CTRL_LINK_MRT_START_ADDR + 1] == 0x0);
1349  assert(nalCtrl[NAL_CTRL_LINK_MRT_START_ADDR + 2] == 0x0);
1350 
1351  //"self reset"
1352  stepDut();
1353  stepDut(); //285
1354 
1355  // POST config via TCP with hangover
1356  use_sequential_hwicap = true;
1358  uint32_t hwicap_in_address = HWICAP_SEQ_START_ADDRESS*4;
1359 
1360  // first chunk
1361  getStatus = "POST /configure HTTP/1.1\r\nUser-Agent: curl/7.47.01\r\nContent-Type: application/x-www-form-urlencoded\r\n\r\nffff000000bb11220044ffffffffffffffffaa9955662000000021000000220000002300000024000000250000002600000027000000280abcd";
1362 
1363  strcpy((char*) &HWICAP_seq_IN[hwicap_in_address],"ffff000000bb11220044ffffffffffffffffaa9955662000000021000000220000002300000024000000250000002600000027000000280abcd");
1364  hwicap_in_address += strlen("ffff000000bb11220044ffffffffffffffffaa9955662000000021000000220000002300000024000000250000002600000027000000280abcd");
1365 
1366  printf("%s\n",getStatus);
1367  printf("\t....with large payload\n\n");
1368 
1369  strcpy(&httpBuffer[0],getStatus);
1370  copyBufferToStream(httpBuffer,sNAL_FMC_Tcp_data,strlen(getStatus));
1371  int message_size = strlen(getStatus);
1372 
1373  sessId = Axis<16>(73);
1374  sessId.setTLast(1);
1375  sNAL_FMC_Tcp_sessId.write(sessId.getTData());
1376 
1377  HWICAP_seq_OUT[SR_OFFSET] = SR;
1378  HWICAP_seq_OUT[WF_OFFSET] = 0x42;
1380  //HWICAP_seq_OUT[WFV_OFFSET] = 0x1DE;
1381  HWICAP_seq_OUT[WFV_OFFSET] = 0x3FF;
1382  stepDut();
1383  stepDut();
1384  stepDut();
1385  assert(decoupActive == 1); //should be there immediately
1386  assert(HWICAP_seq_OUT[CR_OFFSET] == CR_WRITE);
1387 
1388  //second chunk
1389  getStatus = "e2900000020000000210000002200000023000000002400000025000000260002700123456789AB";
1390  // -> 194 payload bytes (first and second)
1391 
1392  //printf("%s\n",getStatus);
1393 
1394  strcpy(&httpBuffer[0],getStatus);
1395  strcpy((char*) &HWICAP_seq_IN[hwicap_in_address],getStatus);
1396  hwicap_in_address += strlen(getStatus);
1397  copyBufferToStream(httpBuffer,sNAL_FMC_Tcp_data,strlen(getStatus));
1398  message_size += strlen(getStatus);
1399 
1400  stepDut();
1401  printBuffer(bufferIn, "bufferIn after TCP HTTP transfer", 4);
1402 
1403  for(int j = 0; j< 3; j++)
1404  {
1405  stepDut();
1406  }
1407 
1408  //printBuffer(bufferOut, "Valid HTTP POST: BufferOut:",4);
1409 
1410  assert(decoupActive == 1);
1411  printf("WF: %#010x\n",(int) HWICAP_seq_OUT[WF_OFFSET]);
1412  WF_should = 0x36373839;
1413  printf("WF_should: %#010x\n", WF_should);
1414  assert((int) HWICAP_seq_OUT[WF_OFFSET] == WF_should);
1415 
1417 
1418  //HWICAP_seq_OUT[WFV_OFFSET] = 0x2DE;
1419  //now, we post more than BUFFER_SIZE
1420  bool overflow_happened = false;
1421  while(message_size < IN_BUFFER_SIZE + 20)
1422  {
1423  //next chunk
1424  //getStatus = "abcdefgh20000000210000002200000023000000002400000025abcdef26ghijk2700123456789AB";
1425  // -> 80 payload bytes
1426  getStatus = "abcdefgh20000000210000002200000023000000002400000025abcdef26ghijk2700123456789ABabcdefgh20000000210000002200000023000000002400000025abcdef26ghijk2700123456789ABabcdefgh20000000210000002200000023000000002400000025abcdef26ghijk2700123456789ABabcdefgh20000000210000002200000023000000002400000025abcdef26ghijk2700123456789ABabcdefgh20000000210000002200000023000000002400000025abcdef26ghijk2700123456789ABabcdefgh20000000210000002200000023000000002400000025abcdef26ghijk2700123456789AB";
1427  // --> 460 payload bytes
1428 
1429  strcpy((char*) &HWICAP_seq_IN[hwicap_in_address],getStatus);
1430  hwicap_in_address += strlen(getStatus);
1431 
1432  strcpy(&httpBuffer[0],getStatus);
1433  copyBufferToStream(httpBuffer,sNAL_FMC_Tcp_data,strlen(getStatus));
1434  message_size += strlen(getStatus);
1435  //printf("------- message size %d ------------\n", (int) message_size);
1436 
1437  stepDut();
1438  assert(decoupActive == 1);
1439  //printf("WF: %#010x\n",(int) HWICAP_seq_OUT[WF_OFFSET]);
1440  //WF_should = 0x38394142;
1441  WF_should = 0x36373839;
1442  //printf("WF_should: %#010x\n", WF_should);
1443  if(!(message_size > IN_BUFFER_SIZE) && !overflow_happened)
1444  {
1445  assert((int) HWICAP_seq_OUT[WF_OFFSET] == WF_should);
1446  } else {
1447  overflow_happened = true;
1448  }
1449  }
1450 
1451  //write what's left
1452  stepDut();
1453  //to activate and see context, add +1 for the end address
1455 
1456  //test WFV feedback
1457  HWICAP_seq_OUT[WFV_OFFSET] = 0x3;
1458  //next chunk
1459  getStatus = "abcdefgh20000000210000002200000023000000002400000025abcdef26ghijk2700123456789AB";
1460  // -> 80 payload bytes
1461 
1462  strcpy((char*) &HWICAP_seq_IN[hwicap_in_address],getStatus);
1463  hwicap_in_address += strlen(getStatus);
1464 
1465  strcpy(&httpBuffer[0],getStatus);
1466  copyBufferToStream(httpBuffer,sNAL_FMC_Tcp_data,strlen(getStatus));
1467  message_size += strlen(getStatus);
1468 
1469  stepDut();
1470  assert(decoupActive == 1);
1471  printf("WF: %#010x\n",(int) HWICAP_seq_OUT[WF_OFFSET]);
1472  WF_should = 0x67683230; //only 3 words
1473  printf("WF_should: %#010x\n", WF_should);
1474  assert((int) HWICAP_seq_OUT[WF_OFFSET] == WF_should);
1475 
1476 
1477  //now, we set HWICAP to blocking and wait until an overflow
1478  HWICAP_seq_OUT[WFV_OFFSET] = 0x0;
1479  overflow_happened = false;
1480  message_size = 0;
1481  while(message_size < IN_BUFFER_SIZE + 300)
1482  {
1483  //next chunk
1484  //getStatus = "abcdefgh20000000210000002200000023000000002400000025abcdef26ghijk2700123456789ABabcdefgh20000000210000002200000023000000002400000025abcdef26ghijk2700123456789ABabcdefgh20000000210000002200000023000000002400000025abcdef26ghijk2700123456789AB";
1485  // -> 240 payload bytes
1486 
1487  getStatus = "abcdefgh20000000210000002200000023000000002400000025abcdef26ghijk2700123456789ABabcdefgh20000000210000002200000023000000002400000025abcdef26ghijk2700123456789ABabcdefgh20000000210000002200000023000000002400000025abcdef26ghijk2700123456789ABabcdefgh20000000210000002200000023000000002400000025abcdef26ghijk2700123456789ABabcdefgh20000000210000002200000023000000002400000025abcdef26ghijk2700123456789ABabcdefgh20000000210000002200000023000000002400000025abcdef26ghijk2700123456789AB";
1488  // --> 460 payload bytes
1489 
1490  strcpy((char*) &HWICAP_seq_IN[hwicap_in_address],getStatus);
1491  hwicap_in_address += strlen(getStatus);
1492 
1493  strcpy(&httpBuffer[0],getStatus);
1494  copyBufferToStream(httpBuffer,sNAL_FMC_Tcp_data,strlen(getStatus));
1495  message_size += strlen(getStatus);
1496  //printf("------- message size %d ------------\n", (int) message_size);
1497 
1498  stepDut();
1499  assert(decoupActive == 1);
1500  printf("WF: %#010x\n",(int) HWICAP_seq_OUT[WF_OFFSET]);
1501  //WF_should = 0x36373839;
1502  WF_should = 0x67683230; //nothing should change
1503  printf("WF_should: %#010x\n", WF_should);
1504  assert((int) HWICAP_seq_OUT[WF_OFFSET] == WF_should);
1505  }
1506 
1507  //one word only
1508  HWICAP_seq_OUT[WFV_OFFSET] = 0x1;
1509  stepDut();
1510  assert(decoupActive == 1);
1511  WF_should = 0x30303030;
1512  assert((int) HWICAP_seq_OUT[WF_OFFSET] == WF_should);
1513 
1514  stepDut();
1515  assert(decoupActive == 1);
1516  WF_should = 0x30303231;
1517  assert((int) HWICAP_seq_OUT[WF_OFFSET] == WF_should);
1518 
1519  //hangover test
1520  HWICAP_seq_OUT[WFV_OFFSET] = 0x1E1;
1521  stepDut();
1522  assert(decoupActive == 1);
1523  WF_should = 0x30303030;
1524  assert((int) HWICAP_seq_OUT[WF_OFFSET] == WF_should);
1525  //one word only
1526  HWICAP_seq_OUT[WFV_OFFSET] = 0x1;
1527  stepDut();
1528  assert(decoupActive == 1);
1529  WF_should = 0x30303232;
1530  assert((int) HWICAP_seq_OUT[WF_OFFSET] == WF_should);
1531 
1532  //now, we let it go
1533  HWICAP_seq_OUT[WFV_OFFSET] = 0x3FF;
1534  stepDut();
1535  stepDut();
1536  stepDut();
1537  stepDut();
1538  assert(decoupActive == 1);
1539  //printf("WF: %#010x\n",(int) HWICAP_seq_OUT[WF_OFFSET]);
1540  WF_should = 0x36373839; //everything should be processed
1541  //printf("WF_should: %#010x\n", WF_should);
1542  assert((int) HWICAP_seq_OUT[WF_OFFSET] == WF_should);
1543 
1544  //to activate and see context, add +1 for the end address
1546 
1547 #ifndef COSIM
1548  //test random pattern
1549  printf("----------- Random Test -----------\n");
1550  HWICAP_seq_OUT[WFV_OFFSET] = 0x3FF;
1551  message_size = 0;
1552  char stringBuffer[512];
1553  uint32_t max_message_size = 5*IN_BUFFER_SIZE + 300;
1554  bool correction_done = false;
1555  struct timeval now;
1556  gettimeofday(&now, NULL);
1557  uint32_t random_seed = now.tv_sec + now.tv_usec;
1558  printf("\tSeed %d\n", random_seed);
1559  srand(random_seed);
1560  while(message_size < max_message_size)
1561  {
1562  //next chunk
1563  //getStatus = "abcdefgh20000000210000002200000023000000002400000025abcdef26ghijk2700123456789ABabcdefgh20000000210000002200000023000000002400000025abcdef26ghijk2700123456789ABabcdefgh20000000210000002200000023000000002400000025abcdef26ghijk2700123456789AB";
1564  // -> 240 payload bytes
1565 
1566  getStatus = "abcdefgh20000000210000002200000023000000002400000025abcdef26ghijk2700123456789ABabcdefgh20000000210000002200000023000000002400000025abcdef26ghijk2700123456789ABabcdefgh20000000210000002200000023000000002400000025abcdef26ghijk2700123456789ABabcdefgh20000000210000002200000023000000002400000025abcdef26ghijk2700123456789ABabcdefgh20000000210000002200000023000000002400000025abcdef26ghijk2700123456789ABabcdefgh20000000210000002200000023000000002400000025abcdef26ghijk2700123456789AB";
1567  // --> 460 payload bytes
1568 
1569  strcpy(stringBuffer,getStatus);
1570 
1571  //to check every packet size
1572  if(message_size > 1024 && message_size < (max_message_size - 1024) )
1573  {
1574  uint16_t stop_byte = rand() % (strlen(getStatus) - 1);
1575  //if(stop_byte < 2*NETWORK_WORD_BYTE_WIDTH)
1576  //{
1577  // stop_byte += 2*NETWORK_WORD_BYTE_WIDTH;
1578  //}
1579  if(stop_byte < 3)
1580  {
1581  stop_byte += 3;
1582  }
1583  printf("cutting payload at %d\n", stop_byte);
1584  stringBuffer[stop_byte] = '\0';
1585  } else if( (message_size > (max_message_size - 1024)) && !correction_done)
1586  {
1587  correction_done = true;
1588  uint16_t stop_byte = 32 + ( 4 - (message_size % 4));
1589  printf("correcting payload with length %d\n", stop_byte);
1590  stringBuffer[stop_byte] = '\0';
1591  }
1592 
1593  strcpy((char*) &HWICAP_seq_IN[hwicap_in_address],stringBuffer);
1594  hwicap_in_address += strlen(stringBuffer);
1595 
1596  strcpy(&httpBuffer[0],stringBuffer);
1597  copyBufferToStream(httpBuffer,sNAL_FMC_Tcp_data,strlen(stringBuffer));
1598  message_size += strlen(stringBuffer);
1599  //printf("------- message size %d ------------\n", (int) message_size);
1600 
1601  stepDut();
1602 
1603  uint8_t multiple_iterations = rand() % 8;
1604  for(int k = 0; k < multiple_iterations; k++)
1605  {
1606  printf("multiple FMC calls with no input %d.\n",multiple_iterations);
1607  stepDut();
1608  }
1609  assert(decoupActive == 1);
1610  //we cant test the last word, but we can test the total
1612  }
1613 
1614  //to write all remaining stuff (including possible wrap around)
1615  stepDut();
1616  stepDut();
1617  assert(decoupActive == 1);
1618 #endif
1619 
1620  //last chunk
1621  //HWICAP_seq_OUT[WFV_OFFSET] = 0x710;
1622  getStatus = "0012345678abcdefgh\r\n\r\n";
1623  // -> 18 payload bytes
1624 
1625  strcpy((char*) &HWICAP_seq_IN[hwicap_in_address],"0012345678abcdefgh");
1626  hwicap_in_address += strlen(getStatus);
1627 
1628  strcpy(&httpBuffer[0],getStatus);
1629  copyBufferToStream(httpBuffer,sNAL_FMC_Tcp_data,strlen(getStatus));
1630 
1631  stepDut();
1632  stepDut();
1633  //now, we are done
1634  assert(decoupActive == 0);
1635  printf("WF: %#010x\n",(int) HWICAP_seq_OUT[WF_OFFSET]);
1636  WF_should = 0x65666768;
1637  printf("WF_should: %#010x\n", WF_should);
1638  assert((int) HWICAP_seq_OUT[WF_OFFSET] == WF_should);
1639 
1640  //now, we can check the complete buffer, it should be also empty afterwards...
1642 
1643  //Check CR_WRITE
1645  stepDut(); //to finish
1646  stepDut(); //334 (if buffer = 2048)
1647  succeded &= checkResult(MMIO, 0x30574154); //WAT
1648  assert(decoupActive == 0);
1649  assert(HWICAP_seq_OUT[CR_OFFSET] == 0);
1650 
1651  sessId_back = sFMC_NAL_Tcp_sessId.read();
1652  assert(sessId.getTData() == sessId_back.getTData());
1653  printf("Check stream:\n0x312e312f50545448\n0x0d4b4f2030303220\n");
1654  assert(sFMC_NAL_Tcp_data.read().tdata == 0x312e312f50545448);
1655  assert(sFMC_NAL_Tcp_data.read().tdata == 0x0d4b4f2030303220);
1656  //drain remaining
1657  printf("Partial ");
1659  assert(sFMC_NAL_Tcp_data.empty());
1660 
1661  //TODO: test if FMC stays operational after a failed request
1662 
1663  printf("== TCP Test passed == \n");
1664 
1665 
1666 #ifndef COSIM
1667  return succeded? 0 : -1;
1668 #else
1669  //since some vectors and their timestamps shift during cosim...
1670  return 0;
1671 #endif
1672 }
1673 
1674 
#define RST_SHIFT
Definition: fmc.hpp:107
ap_uint< 64 > initStream(ap_uint< 4 > cnt, stream< NetworkWord > &tcp_data, int nr_words, bool with_pattern, bool inverse_upper, bool insert_tlast)
Definition: tb_fmc.cpp:277
ap_uint< 1 > nts_ready
Definition: tb_fmc.cpp:69
#define PYRO_MODE_SHIFT
Definition: fmc.hpp:115
ap_uint< 1 > decoupActive
Definition: tb_fmc.cpp:81
#define LINES_PER_PAGE
Definition: fmc.hpp:122
ap_uint< 32 > sim_fpga_time_seconds
Definition: tb_fmc.cpp:78
#define LAST_PAGE_CNT_SHIFT
Definition: fmc.hpp:119
uint8_t bufferOut[1024]
Definition: fmc.cpp:59
ap_uint< 1 > layer_7_enabled
Definition: tb_fmc.cpp:68
ap_uint< 1 > disable_pyro_link
Definition: tb_fmc.cpp:92
#define PARSE_HTTP_SHIFT
Definition: fmc.hpp:113
ap_uint< 16 > role_mmio
Definition: tb_fmc.cpp:70
#define BYTES_PER_PAGE
Definition: fmc.hpp:125
void copyBufferToXmem(char *buffer_int, ap_uint< 32 > xmem[(32 *16)])
Definition: tb_fmc.cpp:317
ap_uint< 32 > sim_fpga_time_minutes
Definition: tb_fmc.cpp:79
#define CR_WRITE
Definition: fmc.hpp:141
ap_uint< 32 > MMIO
Definition: tb_fmc.cpp:64
ap_uint< 32 > HWICAP_seq_OUT[((16 *4096+512)/4)]
Definition: tb_fmc.cpp:88
#define XMEM_SIZE
Definition: fmc.hpp:124
#define ENABLE_TCP_MODE_SHIFT
Definition: fmc.hpp:117
ap_uint< 1 > disable_ctrl_link
Definition: tb_fmc.cpp:91
#define XMEM_ANSWER_START
Definition: fmc.hpp:134
int simCnt
Definition: tb_fmc.cpp:113
ap_uint< 8 > toe_sess_drop_cnt
Definition: tb_fmc.cpp:76
bool checkSeqHwicap(uint32_t *true_buffer, ap_uint< 32 > *out_buffer, uint32_t start_address, uint32_t end_address, bool not_to_swap)
Definition: tb_fmc.cpp:189
ap_uint< 32 > MMIO_in_BE
Definition: tb_fmc.cpp:65
#define PYRO_READ_REQUEST_SHIFT
Definition: fmc.hpp:116
stream< Axis< 8 > > FMC_Debug_Pyrolink("FMC_Debug_Pyrolink")
stream< TcpWord > sFMC_NAL_Tcp_data("sFMC_Nal_Tcp_data")
#define WFV_OFFSET
Definition: fmc.hpp:96
#define WF_OFFSET
Definition: fmc.hpp:100
uint8_t HWICAP_seq_IN[((16 *4096+512)/4) *4]
Definition: tb_fmc.cpp:87
#define ISR_OFFSET
Definition: fmc.hpp:95
void drainStream(stream< NetworkWord > &tcp_data)
Definition: tb_fmc.cpp:368
ap_uint< 32 > MMIO_out_BE
Definition: tb_fmc.cpp:65
void initBuffer(ap_uint< 4 > cnt, ap_uint< 32 > xmem[(32 *16)], bool lastPage, bool withPattern)
Definition: tb_fmc.cpp:241
ap_uint< 8 > toe_meta_drop_cnt
Definition: tb_fmc.cpp:73
#define CHECK_PATTERN_SHIFT
Definition: fmc.hpp:112
ap_uint< 8 > toe_notif_drop_cnt
Definition: tb_fmc.cpp:72
ap_uint< 32 > xmem[(32 *16)]
Definition: tb_fmc.cpp:89
ap_uint< 16 > uoe_drop_cnt
Definition: tb_fmc.cpp:71
ap_uint< 1 > layer_4_enabled
Definition: tb_fmc.cpp:66
void fmc(ap_uint< 32 > *MMIO_in, ap_uint< 32 > *MMIO_out, ap_uint< 1 > *layer_4_enabled, ap_uint< 1 > *layer_6_enabled, ap_uint< 1 > *layer_7_enabled, ap_uint< 1 > *nts_ready, ap_uint< 32 > *in_time_seconds, ap_uint< 32 > *in_time_minutes, ap_uint< 32 > *in_time_hours, ap_uint< 16 > *role_mmio_in, ap_uint< 16 > *uoe_drop_cnt_in, ap_uint< 8 > *toe_notif_drop_cnt_in, ap_uint< 8 > *toe_meta_drop_cnt_in, ap_uint< 8 > *toe_data_drop_cnt_in, ap_uint< 8 > *toe_crc_drop_cnt_in, ap_uint< 8 > *toe_sess_drop_cnt_in, ap_uint< 8 > *toe_ooo_drop_cnt_in, ap_uint< 32 > *HWICAP, ap_uint< 1 > decoupStatus, ap_uint< 1 > *setDecoup, ap_uint< 1 > *setSoftReset, ap_uint< 32 > xmem[(32 *16)], ap_uint< 32 > nalCtrl[(0x3ff/4)], ap_uint< 1 > *disable_ctrl_link, stream< TcpWord > &siNAL_Tcp_data, stream< AppMeta > &siNAL_Tcp_SessId, stream< TcpWord > &soNAL_Tcp_data, stream< AppMeta > &soNAL_Tcp_SessId, ap_uint< 32 > *role_rank, ap_uint< 32 > *cluster_size)
Definition: fmc.cpp:564
ap_uint< 8 > toe_data_drop_cnt
Definition: tb_fmc.cpp:74
uint32_t sequential_hwicap_address
Definition: fmc.cpp:68
#define IN_BUFFER_SIZE
Definition: fmc.hpp:131
ap_uint< 1 > layer_6_enabled
Definition: tb_fmc.cpp:67
ap_uint< 8 > toe_ooo_drop_cnt
Definition: tb_fmc.cpp:77
stream< AppMeta > sNAL_FMC_Tcp_sessId("sNAL_FMC_Tcp_sessId")
ap_uint< 32 > clusterSize_out
Definition: tb_fmc.cpp:85
#define ASR_OFFSET
Definition: fmc.hpp:97
stream< TcpWord > sNAL_FMC_Tcp_data("sNAL_FMC_Tcp_data")
bool checkResult(ap_uint< 32 > MMIO, ap_uint< 32 > expected)
Definition: tb_fmc.cpp:144
ap_uint< 1 > softReset
Definition: tb_fmc.cpp:83
stream< AppMeta > sFMC_NAL_Tcp_sessId("sFMC_Nal_Tcp_sessId")
ap_uint< 1 > decoupStatus
Definition: tb_fmc.cpp:82
#define DSEL_SHIFT
Definition: fmc.hpp:108
void printBuffer32(ap_uint< 32 > buffer_int[(32 *16)], char *msg, int max_pages)
Definition: tb_fmc.cpp:173
ap_uint< 32 > MMIO_in
Definition: tb_fmc.cpp:63
ap_uint< 8 > toe_crc_drop_cnt
Definition: tb_fmc.cpp:75
stream< Axis< 8 > > Debug_FMC_Pyrolink("Debug_FMC_Pyrolink")
void stepDut()
Run a single iteration of the DUT model.
Definition: tb_fmc.cpp:115
#define HWICAP_SEQ_SIZE
Definition: tb_fmc.cpp:54
uint32_t bufferInPtrNextRead
Definition: fmc.cpp:56
ap_uint< 32 > HWICAP[512]
Definition: tb_fmc.cpp:86
void printBuffer(volatile uint8_t *buffer_int, char *msg, int max_pages)
Definition: tb_fmc.cpp:157
uint8_t bufferIn[4096]
Definition: fmc.cpp:52
ap_uint< 32 > reverse_byte_order(ap_uint< 32 > input)
Definition: tb_fmc.cpp:100
#define START_SHIFT
Definition: fmc.hpp:110
#define DECOUP_CMD_SHIFT
Definition: fmc.hpp:106
#define HWICAP_SEQ_START_ADDRESS
Definition: tb_fmc.cpp:58
void copyBufferToStream(char *buffer_int, stream< NetworkWord > &tcp_data, int content_len)
Definition: tb_fmc.cpp:330
int main()
Definition: tb_fmc.cpp:380
ap_uint< 32 > sim_fpga_time_hours
Definition: tb_fmc.cpp:80
ap_uint< 32 > nodeRank_out
Definition: tb_fmc.cpp:84
#define SR_OFFSET
Definition: fmc.hpp:94
ap_uint< 32 > nalCtrl[(0x3ff/4)]
Definition: tb_fmc.cpp:90
#define CR_OFFSET
Definition: fmc.hpp:98
bool use_sequential_hwicap
Definition: fmc.cpp:67
#define NAL_CTRL_LINK_SIZE
Definition: nal.hpp:82
#define NAL_CTRL_LINK_MRT_START_ADDR
Definition: nal.hpp:87
string input
Definition: test.py:9
string output
Definition: test.py:10
ap_uint< D > getTData()
Definition: axi_utils.hpp:55
void setTLast(ap_uint< 1 > new_last)
Definition: axi_utils.hpp:70