20 #include "../../memtest/include/memtest.hpp"
21 #include "../../common/src/common.cpp"
30 #define THIS_NAME "TB"
32 #define TRACE_OFF 0x0000
33 #define TRACE_URIF 1 << 1
34 #define TRACE_UAF 1 << 2
35 #define TRACE_MMIO 1 << 3
36 #define TRACE_ALL 0xFFFF
37 #define DEBUG_MULTI_RUNS True
38 #define TB_MULTI_RUNS_ITERATIONS 2
39 #define DEBUG_LEVEL (TRACE_ALL)
49 #define DEBUG_TRACE true
51 #define ENABLED (ap_uint<1>)1
52 #define DISABLED (ap_uint<1>)0
86 #define MEMORY_LINES_512 TOTMEMDW_512
107 #if DEBUG_LEVEL > TRACE_OFF
108 printf(
"[%4.4d] STEP DUT \n",
simCnt);
119 int main(
int argc,
char** argv) {
126 printf(
"#####################################################\n");
127 printf(
"## TESTBENCH STARTS HERE ##\n");
128 printf(
"#####################################################\n");
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);
140 string strInput_memaddrUT = argv[1];
141 string strInput_nmbrTest = argv[2];
142 string strInput_burstSize = argv[3];
143 string strInput_commandstring=
"";
146 strInput_commandstring.assign(argv[4]);
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");
158 memory_addr_under_test = stoull(strInput_memaddrUT);
160 catch(
const std::exception& e)
162 std::cerr << e.what() <<
'\n';
163 memory_addr_under_test = 65;
167 testingNumber = stoul(strInput_nmbrTest);
169 catch(
const std::exception& e)
171 std::cerr << e.what() <<
'\n';
177 burst_size = stoul(strInput_burstSize);
179 catch(
const std::exception& e)
181 std::cerr << e.what() <<
'\n';
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);
196 unsigned int sim_time = 1 + 3 + testingNumber * (1 + 2 + 5) + 1 + 2 + 10;
197 size_t charInputSize = 8*2;
198 size_t charOutputSize = 8*1+((8 * (2 + 1 + 1 + 1)) * testingNumber);
200 unsigned int tot_input_transfers =
CEIL(( 2 ) * 8,
PACK_SIZE);
206 char *charOutput = (
char*)malloc((charOutputSize)*
sizeof(char));
208 char *charInput = (
char*)malloc(charInputSize*
sizeof(
char));
211 if (!charOutput || !charInput) {
212 printf(
"ERROR: Cannot allocate memory for output string. Aborting...\n");
215 std::vector<MemoryTestResult> testResults_vector;
220 unsigned int bytes_per_line = 8;
222 strInput.reserve(charInputSize+1);
224 strGold.reserve(charOutputSize+1);
226 #ifdef SIM_STOP_COMPUTATION
229 char stop_cmd [bytes_per_line];
230 for (
unsigned int k = 0; k < bytes_per_line; k++) {
232 stop_cmd[k] = (char)0;
235 stop_cmd[k] = (char)2;
238 strStop.append(stop_cmd,8);
246 if(!strInput_commandstring.length()){
253 char * char_command = (
char*)malloc((strInput_commandstring.length()+1)*
sizeof(char));
254 char_command[0]=
'\0';
255 char tmp_char_cmd [1];
256 tmp_char_cmd[1] = (char)0;
257 unsigned int tmp_int_cmd = 0;
273 if(char_command != NULL){
274 cout <<
"Clearing the char command" << endl;
275 delete[] char_command;
290 #ifdef SIM_STOP_COMPUTATION
297 #ifdef DEBUG_MULTI_RUNS
312 printf(
"### ERROR : Failed to set input data stream \"sSHL_Uaf_Data\". \n");
317 for (
unsigned int i=0; i<tot_input_transfers; i++) {
340 #ifdef SIM_STOP_COMPUTATION
341 if(
simCnt == testingNumber * ((2 * (memory_addr_under_test+1))) + 2){
343 printf(
"### ERROR : Failed to set input data stream \"sSHL_Uaf_Data\". \n");
348 for (
unsigned int i=0; i<tot_input_transfers; i++) {
357 printf(
"## End of simulation at cycle=%3d. \n",
simCnt);
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);
385 assert(i == tot_output_transfers);
388 printf(
"Error No metadata received...\n");
396 printf(
"### ERROR : Failed to set string from file \"ofsUAF_Shl_Data.dat\". \n");
399 printf(
"Input string : ");
400 for (
unsigned int i = 0; i < charInputSize; i++)
401 printf(
"%x", charInput[i]);
404 printf(
"### ERROR : Failed to set string from file \"ofsUAF_Shl_Data.dat\". \n");
410 out_string.reserve(charOutputSize);
411 string tmpToDebug = string(charOutput,charOutputSize);
412 out_string.append(tmpToDebug,0, charOutputSize);
414 printf(
"Output string: ");
415 for (
unsigned int i = 0; i < charOutputSize; i++)
416 printf(
"%x", charOutput[i]);
423 int rc1 = system(
"diff --brief -w -i -y ../../../../test/ofsUAF_Shl_Data.dat \
424 ../../../../test/verify_UAF_Shl_Data.dat");
428 printf(
"## Error : File \'ofsUAF_Shl_Data.dat\' does not match \'verify_UAF_Shl_Data.dat\'.\n");
430 printf(
"Output data in file \'ofsUAF_Shl_Data.dat\' verified.\n");
446 const string ouf_file =
"./hls_out.txt";
448 string longbuf_string;
449 longbuf_string.reserve(charOutputSize);
456 longbuf_string.clear();
457 testResults_vector.clear();
458 cout<< endl <<
" End the TB with iteration " << iterations << endl << endl;
462 printf(
"#####################################################\n");
465 printf(
"## ERROR - TESTBENCH FAILED (RC=%d) !!! ##\n", nrErr);
467 printf(
"## SUCCESSFULL END OF TESTBENCH (RC=0) ##\n");
469 printf(
"#####################################################\n");
473 #ifdef DEBUG_MULTI_RUNS
479 if(charOutput != NULL){
483 if(charInput != NULL){
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.
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.
stream< NetworkMetaStream > siUdp_meta("siUdp_meta")
int main(int argc, char **argv)
Main testbench of Hrris.
stream< NetworkMetaStream > soUdp_meta("soUdp_meta")
stream< UdpWord > image_stream_from_memtest("image_stream_from_memtest")
#define TB_MULTI_RUNS_ITERATIONS
ap_uint< 1 > piSHL_This_MmioCaptPktEn
ap_uint< 1 > piSHL_This_MmioPostPktEn
void stepDut()
Run a single iteration of the DUT model.
ap_uint< 32 > cluster_size
ap_uint< 32 > s_udp_rx_ports
stream< UdpWord > sSHL_Uaf_Data("sSHL_Uaf_Data")
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.
string dumpFileToStringRawDataString(const string inpFileName, int *rawdatalines, size_t outputSize)
Initialize an input data stream from a file with only data.
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.
bool setInputDataStream(stream< UdpAppData > &sDataStream, const string dataStreamName, const string inpFileName)
Initialize an input data stream from a file.
bool getOutputDataStream(stream< UdpAppData > &sDataStream, const string dataStreamName, const string outFileName)
Fill an output file with data from an output stream.