cloudFPGA (cF) API  1.0
The documentation of the source code of cloudFPGA (cF)
common.hpp
Go to the documentation of this file.
1 
17 
33 #ifndef _TEST_COMMON_H_
34 #define _TEST_COMMON_H_
35 
36 
37 #include <stdio.h>
38 #include <string>
39 #include <hls_stream.h>
40 #include <sys/stat.h>
41 #include <cstdlib> // For atoi()
42 #include <string> // For to_string
43 #include <cstring>
44 #include <string.h>
45 #include <bitset>
46 #ifdef ROLE_IS_UPPERCASE
47 #include "../../../../../HOST/custom/uppercase/languages/cplusplus/include/config.h"
48 #include "../../uppercase/include/uppercase.hpp"
49 #endif //ROLE_IS_UPPERCASE
50 
51 #ifdef ROLE_IS_MEMTEST
52 #include "../../memtest/include/memtest.hpp"
53 #include "../../../../../HOST/custom/memtest/languages/cplusplus/include/config.h"
54 #endif //ROLE_IS_MEMTEST
55 
56 #include <bits/stdc++.h>
57 #include <typeinfo>
58 
59 //---------------------------------------------------------
60 // HELPERS FOR THE DEBUGGING TRACES
61 // .e.g: DEBUG_LEVEL = (MDL_TRACE | IPS_TRACE)
62 //---------------------------------------------------------
63 #define THIS_NAME "TB"
64 
65 #define TRACE_OFF 0x0000
66 #define TRACE_URIF 1 << 1
67 #define TRACE_UAF 1 << 2
68 #define TRACE_MMIO 1 << 3
69 #define TRACE_ALL 0xFFFF
70 
71 #define DEBUG_LEVEL (TRACE_ALL)
72 
73 
74 //------------------------------------------------------
75 //-- TESTBENCH DEFINES
76 //------------------------------------------------------
77 #define OK true
78 #define KO false
79 #define VALID true
80 #define UNVALID false
81 #define DEBUG_TRACE true
82 
83 #define ENABLED (ap_uint<1>)1
84 #define DISABLED (ap_uint<1>)0
85 
86 
87 //Data structure of a memory test Result
88 struct MemoryTestResult {
89  unsigned long long int target_address;
90  unsigned int fault_cntr;
91  unsigned int first_fault_address;
92  unsigned long long int clock_cycles_read;
93  unsigned long long int clock_cycles_write;
94 
97  unsigned long long int target_address,
98  unsigned int fault_cntr,
99  unsigned int first_fault_address,
100  unsigned long long int clock_cycles_write,
101  unsigned long long int clock_cycles_read) :
107 };
108 
109 
117 bool setInputDataStream(stream<UdpWord> &sDataStream, const std::string dataStreamName,
118  const std::string inpFileName, int simCnt);
119 
120 
121 
130 bool readDataStream(stream <UdpWord> &sDataStream, UdpWord *udpWord);
131 
132 
133 
139 ap_uint<64> pack_ap_uint_64_ (ap_uint<8> *buffer);
140 
141 
142 
149 bool dumpDataToFile(UdpWord *udpWord, std::ofstream &outFileStream);
150 
151 
152 
153 
161 bool getOutputDataStream(stream<UdpWord> &sDataStream,
162  const std::string dataStreamName, const std::string outFileName, int simCnt);
163 
164 
171 bool dumpStringToFile(std::string s, const std::string outFileName, int simCnt);
172 
173 
181 bool dumpStringToFileOnlyRawData(const std::string s, const std::string outFileName, int simCnt, size_t out_size);
182 
183 
194 bool dumpStringToFileWithLastSetEveryGnoPackets(std::string s, const std::string outFileName, int simCnt, int gno);
195 
196 
203 bool dumpFileToString(const std::string inpFileName, std::string strOutput, int simCnt);
204 
205 
212 template<unsigned int bytes_per_line = 8>
213 std::string dumpFileToStringRawDataString(const std::string inpFileName, int * rawdatalines, size_t outputSize);
214 
215 
221 unsigned char hexval(unsigned char c);
222 
223 
229 void hex2ascii(const std::string& in, std::string& out);
230 
231 
237 void ascii2hex(const std::string& in, std::string& out);
238 
239 
246 void ascii2hexWithSize(const std::string& in, std::string& out, size_t bytesize);
247 
248 
255 bool isCornerPresent(std::string str, std::string corner);
256 
257 
264 template<typename T>
265 void string2hexnumerics(const std::string& in, char * out, size_t byteSize);
266 
267 
275 std::string createMemTestCommands(unsigned long long int mem_address, int testingNumber, unsigned int burst_size);
276 
277 
285 std::string createMemTestGoldenOutput(unsigned long long int mem_address, int testingNumber);
286 
287 
294 std::string createUppercaseGoldenOutput(std::string input_string);
295 
296 
302 void reverseStr(std::string& str);
303 
304 
312 template<unsigned int bytes_per_line=8>
313 std::vector<MemoryTestResult> parseMemoryTestOutput(const std::string longbuf, size_t charOutputSize, int rawdatalines);
314 
315 
322 void printStringHex(const std::string inStr, size_t strSize);
323 
324 
331 void printCharBuffHex(const char * inStr, size_t strSize);
332 
333 
340 void printBits(size_t const size, void const * const ptr);
341 
342 static inline ssize_t
343 __file_size(const char *fname);
344 
345 static inline ssize_t
346 __file_read(const char *fname, char *buff, size_t len);
347 
348 static inline ssize_t
349 __file_write(const char *fname, const char *buff, size_t len);
350 
351 #endif
352 
int simCnt
Definition: tb_fmc.cpp:113
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.
ap_uint< 64 > pack_ap_uint_64_(ap_uint< 8 > *buffer)
Pack an array of 8 x ap_uint<8> into a ap_uint<64> word.
Definition: common.cpp:116
bool dumpFileToString(const std::string inpFileName, std::string strOutput, int simCnt)
Initialize an input data stream from a file.
bool isCornerPresent(std::string str, std::string corner)
Check the presence of a given corner value at the begin and the end of a string.
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.
bool setInputDataStream(stream< UdpWord > &sDataStream, const std::string dataStreamName, const std::string inpFileName, int simCnt)
Initialize an input data stream from a file.
bool readDataStream(stream< UdpWord > &sDataStream, UdpWord *udpWord)
Read data from a stream.
Definition: common.cpp:103
void reverseStr(std::string &str)
reverse a given string
bool dumpDataToFile(UdpWord *udpWord, std::ofstream &outFileStream)
Dump a data word to a file.
bool getOutputDataStream(stream< UdpWord > &sDataStream, const std::string dataStreamName, const std::string outFileName, int simCnt)
Fill an output file with data from an output stream.
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.
std::string createUppercaseGoldenOutput(std::string input_string)
Create the expected output results for the uppercase.
Definition: common.cpp:815
void ascii2hex(const string &in, string &out)
Convert a ascii string to a hexadecimal string.
Definition: common.hpp:119
unsigned char hexval(unsigned char c)
convert a char to its hexadecimal representation.
Definition: common.hpp:234
unsigned long long int clock_cycles_read
Definition: common.hpp:418
std::vector< MemoryTestResult > parseMemoryTestOutput(const string longbuf, size_t charOutputSize, int rawdatalines)
Parse the memory test output contained in astring with a given size.
Definition: common.hpp:444
string dumpFileToStringRawDataString(const string inpFileName, int *rawdatalines, size_t outputSize)
Initialize an input data stream from a file with only data.
Definition: common.hpp:279
void printBits(size_t const size, void const *const ptr)
print the binary representation of a target pointer buffer of a given size. Assumes little endian.
Definition: common.hpp:98
unsigned int first_fault_address
Definition: common.hpp:417
void printCharBuffHex(const char *inStr, size_t strSize)
print byte-per-byte a given char buff in hexadecimal format
Definition: common.hpp:382
void ascii2hexWithSize(const string &in, string &out, size_t bytesize)
Convert a ascii string to a hexadecimal string.
Definition: common.hpp:331
string createMemTestCommands(unsigned long long int mem_address, unsigned int testingNumber, unsigned int burst_size)
Create the commands for a memory test with start/max address to test-nop to execute-stop.
Definition: common.hpp:137
void string2hexnumerics(const string &in, char *out, size_t byteSize)
Definition: common.hpp:405
unsigned long long int clock_cycles_write
Definition: common.hpp:419
unsigned int fault_cntr
Definition: common.hpp:416
void printStringHex(const string inStr, size_t strSize)
print byte-per-byte a given string in hexadecimal format
Definition: common.hpp:363
void hex2ascii(const string &in, string &out)
Convert a hexadecimal string to a ascii string.
Definition: common.hpp:251
unsigned long long int target_address
Definition: common.hpp:415
out
Definition: test.py:12
MemoryTestResult(unsigned long long int target_address, unsigned int fault_cntr, unsigned int first_fault_address, unsigned long long int clock_cycles_write, unsigned long long int clock_cycles_read)
Definition: common.hpp:96
ap_uint< 32 > size