cloudFPGA (cF) API  1.0
The documentation of the source code of cloudFPGA (cF)
test_ack_delay.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 
30 #include "test_ack_delay.hpp"
31 
32 using namespace hls;
33 using namespace std;
34 
35 //---------------------------------------------------------
36 // HELPERS FOR THE DEBUGGING TRACES
37 // .e.g: DEBUG_LEVEL = (SND_TRACE | RCV_TRACE)
38 //---------------------------------------------------------
39 #define THIS_NAME "TB"
40 
41 #define TRACE_OFF 0x0000
42 #define TRACE_RCV 1 << 1
43 #define TRACE_SND 1 << 2
44 #define TRACE_ALL 0xFFFF
45 #define DEBUG_LEVEL (TRACE_OFF)
46 
47 
50 void stepSim() {
51  gSimCycCnt++;
52  if (gTraceEvent || ((gSimCycCnt % 100) == 0)) {
53  printInfo(THIS_NAME, "-- [@%4.4d] -----------------------------\n", gSimCycCnt);
54  gTraceEvent = false;
55  }
56  else if (0) {
57  printInfo(THIS_NAME, "------------------- [@%d] ------------\n", gSimCycCnt);
58  }
59 }
60 
61 
64 int main(int argc, char* argv[])
65 {
66 
67  //------------------------------------------------------
68  //-- TESTBENCH GLOBAL VARIABLES
69  //------------------------------------------------------
70  gTraceEvent = false;
71  gFatalError = false;
72  gSimCycCnt = 0;
73  // gMaxSimCycles = TB_STARTUP_DELAY + TB_MAX_SIM_CYCLES;
74 
75  //------------------------------------------------------
76  //-- TESTBENCH LOCAL VARIABLES
77  //------------------------------------------------------
78  int nrErr = 0; // Tb error counter.
79  unsigned int rxEventSig=0;
80  unsigned int txEventSig=0;
81  int nrInpSyn = 0;
82  int nrInpAck = 0;
83  int nrOutSyn = 0;
84  int nrOutAck = 0;
85 
86  //------------------------------------------------------
87  //-- DUT STREAM INTERFACES and RELATED VARIABLEs
88  //------------------------------------------------------
89  //-- Incoming streams
90  stream<ExtendedEvent> ssEVeToAKd_Event;
91  //-- Outgoing streams
92  stream<ExtendedEvent> ssAKdToTXe_Event;
93  stream<SigBit> ssAKdToEVe_RxEventSig;
94  stream<SigBit> ssAKdToEVe_TxEventSig;
95 
96  SessionId sessId = TOE_MAX_SESSIONS-1;
97  ExtendedEvent outEvent;
98 
99 
100 
101  printInfo(THIS_NAME, "############################################################################\n");
102  printInfo(THIS_NAME, "## TESTBENCH 'test_iprx' STARTS HERE ##\n");
103  printInfo(THIS_NAME, "############################################################################\n");
104 
105  int tbRun = 1000;
106  int loop = 0;
107 
108  while (tbRun) {
109 
110  //------------------------------------------------------
111  //-- CREATE DUT INPUT TRAFFIC AS STREAMS
112  //------------------------------------------------------
113  if (loop == 5) {
114  // Create a SYN event
115  ssEVeToAKd_Event.write(Event(SYN_EVENT, sessId));
116  nrInpSyn++;
117  }
118  else if (loop >= 10 and loop < 25) {
119  // Create a burst of 10 ACKs every second clock cycle
120  if (loop % 2 == 0) {
121  ssEVeToAKd_Event.write(Event(ACK_EVENT, sessId));
122  nrInpAck++;
123  }
124  }
125  else if (loop > 100 and loop < 150) {
126  // Create a burst of 10 ACKs every fourth loop
127  if (loop % 4 == 0) {
128  ssEVeToAKd_Event.write(Event(ACK_EVENT, sessId));
129  nrInpAck++;
130  }
131  }
132  else if (loop > 200 and loop < 300) {
133  // Create a burst of ACKs every 10th loop
134  if (loop % 10 == 0) {
135  ssEVeToAKd_Event.write(Event(ACK_EVENT, sessId));
136  nrInpAck++;
137  }
138  }
139  loop++;
140 
141  //------------------------------------------------------
142  //-- RUN DUT
143  //------------------------------------------------------
144  ack_delay(
145  //-- Event Engine Interfaces
146  ssEVeToAKd_Event,
147  ssAKdToEVe_RxEventSig,
148  ssAKdToEVe_TxEventSig,
149  //-- Tx Engine Interface
150  ssAKdToTXe_Event);
151  tbRun--;
152  stepSim();
153 
154  //---------------------------------------------------------------
155  //-- DRAIN DUT OUTPUT STREAMS
156  //---------------------------------------------------------------
157  if (!ssAKdToTXe_Event.empty()) {
158  ssAKdToTXe_Event.read(outEvent);
159  if (outEvent.type == ACK_EVENT) {
160  nrOutAck++;
161  }
162  else if (outEvent.type == SYN_EVENT) {
163  nrOutSyn++;
164  }
165  }
166  if (!ssAKdToEVe_RxEventSig.empty()) {
167  ssAKdToEVe_RxEventSig.read();
168  rxEventSig++;
169  }
170  if (!ssAKdToEVe_TxEventSig.empty()) {
171  ssAKdToEVe_TxEventSig.read();
172  txEventSig++;
173  }
174  }
175 
176  //---------------------------------------------------------------
177  //-- PRINT OVERALL TESTBENCH STATUS
178  //---------------------------------------------------------------
179  printInfo(THIS_NAME, "Number of received SYNs : %5d \n", nrInpSyn);
180  printInfo(THIS_NAME, "Number of forwarded SYNs : %5d \n", nrOutSyn);
181  printInfo(THIS_NAME, "Number of received ACKs : %5d \n", nrInpAck);
182  printInfo(THIS_NAME, "Number of forwarded ACKs : %5d \n", nrOutAck);
183  printInfo(THIS_NAME, "Number of Rx event signals : %5d \n", rxEventSig);
184  printInfo(THIS_NAME, "Number of Tx event signals : %5d \n", txEventSig);
185 
186  //---------------------------------------------------------------
187  //-- ASSESS TESTBENCH RESULTS
188  //---------------------------------------------------------------
189  if (nrInpSyn != nrOutSyn)
190  nrErr++;
191  if (nrInpAck < nrOutAck)
192  nrErr++;
193  if ((nrInpSyn + nrInpAck) != rxEventSig)
194  nrErr++;
195  if ((nrOutSyn + nrOutAck) != txEventSig)
196  nrErr++;
197 
198  if (nrErr) {
199  printError(THIS_NAME, "###########################################################\n");
200  printError(THIS_NAME, "#### TEST BENCH FAILED : TOTAL NUMBER OF ERROR(S) = %2d ####\n", nrErr);
201  printError(THIS_NAME, "###########################################################\n\n");
202 
203  printInfo(THIS_NAME, "FYI - You may want to check for \'ERROR\' and/or \'WARNING\' alarms in the LOG file...\n\n");
204  }
205  else {
206  printInfo(THIS_NAME, "#############################################################\n");
207  printInfo(THIS_NAME, "#### SUCCESSFUL END OF TEST ####\n");
208  printInfo(THIS_NAME, "#############################################################\n");
209  }
210 
211  return nrErr;
212 }
Definition: toe.hpp:661
EventType type
Definition: toe.hpp:663
unsigned int gSimCycCnt
Definition: tb_nal.cpp:150
bool gTraceEvent
Definition: tb_nal.cpp:151
bool gFatalError
Definition: tb_nal.cpp:152
int loop
Definition: tb_nal.cpp:814
int main(int argc, char *argv[])
Main (does use any param).
void stepSim()
Increment the simulation counter.
#define THIS_NAME
void ack_delay(stream< ExtendedEvent > &siEVe_Event, stream< SigBit > &soEVe_RxEventSig, stream< SigBit > &soEVe_TxEventSig, stream< ExtendedEvent > &soTXe_Event)
ACK Delayer (AKd)
Definition: ack_delay.cpp:95
@ SYN_EVENT
Definition: toe.hpp:273
@ ACK_EVENT
Definition: toe.hpp:273
ap_uint< 16 > SessionId
Definition: nts_types.hpp:136
#define printError(callerName, format,...)
A macro to print an error message.
Definition: nts_utils.hpp:195
#define printInfo(callerName, format,...)
A macro to print an information message.
Definition: nts_utils.hpp:169
: Testbench for or ACK delayer (AKd) function of TOE.