cloudFPGA (cF) API  1.0
The documentation of the source code of cloudFPGA (cF)
test_udp_shell_if_top.cpp
Go to the documentation of this file.
1 /*
2  * Copyright 2016 -- 2021 IBM Corporation
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 
44 
45 using namespace hls;
46 using namespace std;
47 
48 //---------------------------------------------------------
49 // HELPERS FOR THE DEBUGGING TRACES
50 //---------------------------------------------------------
51 #define THIS_NAME "TB_USIF_TOP"
52 
53 #ifndef __SYNTHESIS__
54  extern unsigned int gSimCycCnt;
55  extern unsigned int gMaxSimCycles;
56 #endif
57 
58 
59 
69 int main(int argc, char *argv[]) {
70 
71  //------------------------------------------------------
72  //-- TESTBENCH GLOBAL VARIABLES
73  //------------------------------------------------------
74  gSimCycCnt = 0; // Simulation cycle counter as a global variable
75 
76  //------------------------------------------------------
77  //-- DUT SIGNAL INTERFACES
78  //------------------------------------------------------
79  //-- SHL / Mmio Interface
80  CmdBit sMMIO_USIF_Enable;
81  //-- UOE->MMIO / Ready Signal
82  StsBit sUOE_MMIO_Ready;
83  //------------------------------------------------------
84  //-- DUT STREAM INTERFACES
85  //------------------------------------------------------
86  //-- UAF->USIF / UDP Tx Data Interface
87  stream<UdpAppData> ssUAF_USIF_Data ("ssUAF_USIF_Data");
88  stream<UdpAppMeta> ssUAF_USIF_Meta ("ssUAF_USIF_Meta");
89  stream<UdpAppDLen> ssUAF_USIF_DLen ("ssUAF_USIF_DLen");
90  //-- USIF->UOE / UDP Tx Data Interface
91  stream<UdpAppData> ssUSIF_UOE_Data ("ssUSIF_UOE_Data");
92  stream<UdpAppMeta> ssUSIF_UOE_Meta ("ssUSIF_UOE_Meta");
93  stream<UdpAppDLen> ssUSIF_UOE_DLen ("ssUSIF_UOE_DLen");
94  //-- UOE->USIF / UDP Rx Data Interface
95  stream<UdpAppData> ssUOE_USIF_Data ("ssUOE_USIF_Data");
96  stream<UdpAppMeta> ssUOE_USIF_Meta ("ssUOE_USIF_Meta");
97  stream<UdpAppDLen> ssUOE_USIF_DLen ("ssUOE_USIF_DLen");
98  //-- USIF->UAF / UDP Rx Data Interface
99  stream<UdpAppData> ssUSIF_UAF_Data ("ssUSIF_UAF_Data");
100  stream<UdpAppMeta> ssUSIF_UAF_Meta ("ssUSIF_UAF_Meta");
101  stream<UdpAppDLen> ssUSIF_UAF_DLen ("ssUSIF_UAF_DLen");
102  //-- UOE / Control Port Interfaces
103  stream<UdpPort> ssUSIF_UOE_LsnReq ("ssUSIF_UOE_LsnReq");
104  stream<StsBool> ssUOE_USIF_LsnRep ("ssUOE_USIF_LsnRep");
105  stream<UdpPort> ssUSIF_UOE_ClsReq ("ssUSIF_UOE_ClsReq");
106  stream<StsBool> ssUOE_USIF_ClsRep ("ssUOE_USIF_ClsRep");
107 
108  //------------------------------------------------------
109  //-- TESTBENCH VARIABLES
110  //------------------------------------------------------
111  int nrErr = 0; // Total number of testbench errors
112  ofstream ofUOE_Data; // Data streams delivered to UOE
113  ofstream ofUOE_Meta; // Meta streams delivered to UOE
114  string ofUOE_DataName = "../../../../test/simOutFiles/soUOE_Data.dat";
115  string ofUOE_MetaName = "../../../../test/simOutFiles/soUOE_Meta.dat";
116  ofstream ofUOE_DataGold; // Data gold streams to compare with
117  ofstream ofUOE_MetaGold; // Meta gold streams to compare with
118  string ofUOE_DataGoldName = "../../../../test/simOutFiles/soUOE_DataGold.dat";
119  string ofUOE_MetaGoldName = "../../../../test/simOutFiles/soUOE_MetaGold.dat";
120 
121  const int defaultLenOfDatagramEcho = 42;
122  const int defaultDestHostIpv4Test = 0xC0A80096; // 192.168.0.150
123  const int defaultDestHostPortTest = 2718;
124  const int defaultLenOfDatagramTest = 43;
125 
126  int echoLenOfDatagram = defaultLenOfDatagramEcho;
127  ap_uint<32> testDestHostIpv4 = defaultDestHostIpv4Test;
128  ap_uint<16> testDestHostPort = defaultDestHostIpv4Test;
129  int testLenOfDatagram = defaultLenOfDatagramTest;
130 
131  //------------------------------------------------------
132  //-- PARSING THE TESBENCH ARGUMENTS
133  //------------------------------------------------------
134  if (argc >= 2) {
135  echoLenOfDatagram = atoi(argv[1]);
136  if ((echoLenOfDatagram < 1) or (echoLenOfDatagram >= 0x10000)) {
137  printFatal(THIS_NAME, "Argument 'len' is out of range [1:65535].\n");
138  return NTS_KO;
139  }
140  }
141  if (argc >= 3) {
142  if (isDottedDecimal(argv[2])) {
143  testDestHostIpv4 = myDottedDecimalIpToUint32(argv[2]);
144  }
145  else {
146  testDestHostIpv4 = atoi(argv[2]);
147  }
148  if ((testDestHostIpv4 < 0x00000000) or (testDestHostIpv4 > 0xFFFFFFFF)) {
149  printFatal(THIS_NAME, "Argument 'IPv4' is out of range [0x00000000:0xFFFFFFFF].\n");
150  return NTS_KO;
151  }
152  }
153  if (argc >= 4) {
154  testDestHostPort = atoi(argv[3]);
155  if ((testDestHostPort < 0x0000) or (testDestHostPort >= 0x10000)) {
156  printFatal(THIS_NAME, "Argument 'port' is out of range [0:65535].\n");
157  return NTS_KO;
158  }
159  }
160  if (argc >= 5) {
161  testLenOfDatagram = atoi(argv[4]);
162  if ((testLenOfDatagram <= 0) or (testLenOfDatagram >= 0x10000)) {
163  printFatal(THIS_NAME, "Argument 'len' is out of range [0:65535].\n");
164  return NTS_KO;
165  }
166  }
167 
168  SockAddr testSock(testDestHostIpv4, testDestHostPort);
169 
170  //------------------------------------------------------
171  //-- REMOVE PREVIOUS OLD SIM FILES and OPEN NEW ONES
172  //------------------------------------------------------
173  remove(ofUOE_DataName.c_str());
174  if (!ofUOE_Data.is_open()) {
175  ofUOE_Data.open(ofUOE_DataName.c_str(), ofstream::out);
176  if (!ofUOE_Data) {
177  printError(THIS_NAME, "Cannot open the file: \'%s\'.\n", ofUOE_DataName.c_str());
178  return(NTS_KO);
179  }
180  }
181  remove(ofUOE_MetaName.c_str());
182  if (!ofUOE_Meta.is_open()) {
183  ofUOE_Meta.open(ofUOE_MetaName.c_str(), ofstream::out);
184  if (!ofUOE_Meta) {
185  printError(THIS_NAME, "Cannot open the file: \'%s\'.\n", ofUOE_MetaName.c_str());
186  return(NTS_KO);
187  }
188  }
189  remove(ofUOE_DataGoldName.c_str());
190  if (!ofUOE_DataGold.is_open()) {
191  ofUOE_DataGold.open(ofUOE_DataGoldName.c_str(), ofstream::out);
192  if (!ofUOE_DataGold) {
193  printError(THIS_NAME, "Cannot open the file: \'%s\'.\n", ofUOE_DataGoldName.c_str());
194  return(NTS_KO);
195  }
196  }
197  remove(ofUOE_MetaGoldName.c_str());
198  if (!ofUOE_MetaGold.is_open()) {
199  ofUOE_MetaGold.open(ofUOE_MetaGoldName.c_str(), ofstream::out);
200  if (!ofUOE_MetaGold) {
201  printError(THIS_NAME, "Cannot open the file: \'%s\'.\n", ofUOE_MetaGoldName.c_str());
202  return(NTS_KO);
203  }
204  }
205 
207  "############################################################################\n");
209  "## TESTBENCH 'test_udp_shell' STARTS HERE ##\n");
211  "############################################################################\n\n");
212  if (argc > 1) {
214  "This testbench will be executed with the following parameters: \n");
215  for (int i = 1; i < argc; i++) {
216  printInfo(THIS_NAME, "\t==> Param[%d] = %s\n", (i - 1), argv[i]);
217  }
218  }
219 
220  //-----------------------------------------------------
221  //-- MAIN LOOP
222  //-----------------------------------------------------
223  do {
224  //-------------------------------------------------
225  //-- EMULATE SHELL/NTS/UOE
226  //-------------------------------------------------
227  pUOE(
228  nrErr,
229  ofUOE_DataGold,
230  ofUOE_Data,
231  ofUOE_MetaGold,
232  ofUOE_Meta,
233  echoLenOfDatagram,
234  testSock,
235  testLenOfDatagram,
236  //-- UOE / Ready Signal
237  &sUOE_MMIO_Ready,
238  //-- UOE->USIF / UDP Rx Data Interfaces
239  ssUOE_USIF_Data,
240  ssUOE_USIF_Meta,
241  ssUOE_USIF_DLen,
242  //-- USIF->UOE / UDP Tx Data Interfaces
243  ssUSIF_UOE_Data,
244  ssUSIF_UOE_Meta,
245  ssUSIF_UOE_DLen,
246  //-- USIF<->UOE / Listen Interfaces
247  ssUSIF_UOE_LsnReq,
248  ssUOE_USIF_LsnRep,
249  //-- USIF<->UOE / Close Interfaces
250  ssUSIF_UOE_ClsReq);
251 
252  //-------------------------------------------------
253  //-- EMULATE SHELL/MMIO
254  //-------------------------------------------------
255  pMMIO(
256  //-- UOE / Ready Signal
257  &sUOE_MMIO_Ready,
258  //-- MMIO / Enable Layer-7 (.i.e APP alias ROLE)
259  &sMMIO_USIF_Enable);
260 
261  //-------------------------------------------------
262  //-- RUN DUT
263  //-------------------------------------------------
265  //-- SHELL / Mmio Interface
266  &sMMIO_USIF_Enable,
267  //-- SHELL / Control Port Interfaces
268  ssUSIF_UOE_LsnReq,
269  ssUOE_USIF_LsnRep,
270  ssUSIF_UOE_ClsReq,
271  ssUOE_USIF_ClsRep,
272  //-- SHELL / Rx Data Interfaces
273  ssUOE_USIF_Data,
274  ssUOE_USIF_Meta,
275  ssUOE_USIF_DLen,
276  //-- SHELL / Tx Data Interfaces
277  ssUSIF_UOE_Data,
278  ssUSIF_UOE_Meta,
279  ssUSIF_UOE_DLen,
280  //-- UAF / Tx Data Interfaces
281  ssUAF_USIF_Data,
282  ssUAF_USIF_Meta,
283  ssUAF_USIF_DLen,
284  //-- UAF / Rx Data Interfaces
285  ssUSIF_UAF_Data,
286  ssUSIF_UAF_Meta,
287  ssUSIF_UAF_DLen);
288 
289  //-------------------------------------------------
290  //-- EMULATE ROLE/UdpApplicationFlash (UAF)
291  //-------------------------------------------------
292  pUAF(
293  //-- USIF / Data Interface
294  ssUSIF_UAF_Data,
295  ssUSIF_UAF_Meta,
296  //-- UAF / Data Interface
297  ssUAF_USIF_Data,
298  ssUAF_USIF_Meta,
299  ssUAF_USIF_DLen);
300 
301  //------------------------------------------------------
302  //-- INCREMENT SIMULATION COUNTER
303  //------------------------------------------------------
304  stepSim();
305 
306  } while ( (gSimCycCnt < gMaxSimCycles) or gFatalError or (nrErr > 10) );
307 
308  //---------------------------------
309  //-- CLOSING OPEN FILES
310  //---------------------------------
311  ofUOE_DataGold.close();
312  ofUOE_Data.close();
313  ofUOE_MetaGold.close();
314  ofUOE_Meta.close();
315 
316  printf("-- [@%4.4d] -----------------------------\n", gSimCycCnt);
317  printf("############################################################################\n");
318  printf("## TESTBENCH 'test_udp_shell_if' ENDS HERE ##\n");
319  printf("############################################################################\n");
320 
321  //---------------------------------------------------------------
322  //-- PRINT TESTBENCH STATUS
323  //---------------------------------------------------------------
324  printf("\n");
325  printInfo(THIS_NAME, "This testbench was executed with the following parameters: \n");
326  for (int i=1; i<argc; i++) {
327  printInfo(THIS_NAME, "\t==> Param[%d] = %s\n", (i-1), argv[i]);
328  }
329  printf("\n");
330 
331  //---------------------------------------------------------------
332  //-- COMPARE THE RESULTS FILES WITH GOLDEN FILES
333  //---------------------------------------------------------------
334  int res = myDiffTwoFiles(std::string(ofUOE_DataName),
335  std::string(ofUOE_DataGoldName));
336  if (res) {
337  printError(THIS_NAME, "File \'%s\' does not match \'%s\'.\n", \
338  ofUOE_DataName.c_str(), ofUOE_DataGoldName.c_str());
339  nrErr += 1;
340  }
341  res = myDiffTwoFiles(std::string(ofUOE_MetaName),
342  std::string(ofUOE_MetaGoldName));
343  if (res) {
344  printError(THIS_NAME, "File \'%s\' does not match \'%s\'.\n", \
345  ofUOE_MetaName.c_str(), ofUOE_MetaGoldName.c_str());
346  nrErr += 1;
347  }
348 
349  if (nrErr) {
350  printError(THIS_NAME, "###################################################################################\n");
351  printError(THIS_NAME, "#### TESTBENCH 'test_udp_shell_if_top' FAILED : TOTAL NUMBER OF ERROR(S) = %2d ####\n", nrErr);
352  printError(THIS_NAME, "###################################################################################\n");
353 
354  printInfo(THIS_NAME, "FYI - You may want to check for \'ERROR\' and/or \'WARNING\' alarms in the LOG file...\n\n");
355  }
356  else {
357  printInfo(THIS_NAME, "#################################################################\n");
358  printInfo(THIS_NAME, "#### SUCCESSFUL END OF 'test_udp_shell_if_top' ####\n");
359  printInfo(THIS_NAME, "#################################################################\n");
360  }
361 
362  return(nrErr);
363 
364 }
365 
int main()
Definition: tb_fmc.cpp:380
bool gFatalError
Definition: tb_nal.cpp:152
void stepSim()
Increment the simulation counter.
Definition: test_arp.cpp:54
bool isDottedDecimal(string ipStr)
Checks if a string contains an IP address represented in dot-decimal notation.
Definition: SimNtsUtils.cpp:72
int myDiffTwoFiles(string dataFileName, string goldFileName)
Compares 2 files line-by-line, up to length of the 2nd file.
ap_uint< 32 > myDottedDecimalIpToUint32(string ipStr)
Converts an IPv4 address represented with a dotted-decimal string into an UINT32.
#define NTS_KO
Definition: nts_types.hpp:56
#define printError(callerName, format,...)
A macro to print an error message.
Definition: nts_utils.hpp:195
ap_uint< 1 > StsBit
Definition: nts_types.hpp:116
#define printInfo(callerName, format,...)
A macro to print an information message.
Definition: nts_utils.hpp:169
ap_uint< 1 > CmdBit
Definition: nts_types.hpp:108
#define printFatal(callerName, format,...)
A macro to print a fatal error message and exit.
Definition: nts_utils.hpp:208
void pMMIO(StsBit *piSHL_Ready, CmdBit *poTSIF_Enable)
Emulate the behavior of the SHELL & MMIO.
void pUAF(stream< UdpAppData > &siUSIF_Data, stream< UdpAppMeta > &siUSIF_Meta, stream< UdpAppData > &soUSIF_Data, stream< UdpAppMeta > &soUSIF_Meta, stream< UdpAppDLen > &soUSIF_DLen)
Emulate the behavior of the ROLE/UdpAppFlash (UAF).
void udp_shell_if_top(CmdBit *piSHL_Mmio_En, stream< UdpPort > &soSHL_LsnReq, stream< StsBool > &siSHL_LsnRep, stream< UdpPort > &soSHL_ClsReq, stream< StsBool > &siSHL_ClsRep, stream< UdpAppData > &siSHL_Data, stream< UdpAppMeta > &siSHL_Meta, stream< UdpAppDLen > &siSHL_DLen, stream< UdpAppData > &soSHL_Data, stream< UdpAppMeta > &soSHL_Meta, stream< UdpAppDLen > &soSHL_DLen, stream< UdpAppData > &siUAF_Data, stream< UdpAppMeta > &siUAF_Meta, stream< UdpAppDLen > &siUAF_DLen, stream< UdpAppData > &soUAF_Data, stream< UdpAppMeta > &soUAF_Meta, stream< UdpAppDLen > &soUAF_DLen)
Top of UDP Shell Interface (USIF)
unsigned int gMaxSimCycles
Definition: test_arp.hpp:69
unsigned int gSimCycCnt
Definition: tb_nal.cpp:150
#define THIS_NAME
void pUOE(int &nrErr, ofstream &dataGoldFile, ofstream &dataFile, ofstream &metaGoldFile, ofstream &metaFile, int echoDgrmLen, SockAddr testSock, int testDgrmLen, StsBit *poMMIO_Ready, stream< UdpAppData > &soUSIF_Data, stream< UdpAppMeta > &soUSIF_Meta, stream< UdpAppDLen > &soUSIF_DLen, stream< UdpAppData > &siUSIF_Data, stream< UdpAppMeta > &siUSIF_Meta, stream< UdpAppDLen > &siUSIF_DLen, stream< UdpPort > &siUSIF_LsnReq, stream< StsBool > &soUSIF_LsnRep, stream< UdpPort > &siUSIF_ClsReq)
Emulate behavior of the SHELL/NTS/UDP Offload Engine (UOE).
out
Definition: test.py:12
: Testbench for the toplevel of UDP Shell Interface (USIF).