57 #define MAX_TESTABLE_ADDRESS 8000000000
58 #define MAX_TEST_REPETITION_BITWIDTH 16
59 #define MAX_BURST_SIZE 4096
73 cout <<
"...build with: " << endl;
74 cout <<
" ██████╗███████╗██████╗ ███╗ ███╗███████╗███╗ ███╗████████╗███████╗███████╗████████╗" << endl;
75 cout <<
"██╔════╝██╔════╝██╔══██╗ ████╗ ████║██╔════╝████╗ ████║╚══██╔══╝██╔════╝██╔════╝╚══██╔══╝" << endl;
76 cout <<
"██║ █████╗ ██████╔╝ ██╔████╔██║█████╗ ██╔████╔██║ ██║ █████╗ ███████╗ ██║ " << endl;
77 cout <<
"██║ ██╔══╝ ██╔═══╝ ██║╚██╔╝██║██╔══╝ ██║╚██╔╝██║ ██║ ██╔══╝ ╚════██║ ██║ " << endl;
78 cout <<
"╚██████╗██║ ██║███████╗██║ ╚═╝ ██║███████╗██║ ╚═╝ ██║ ██║ ███████╗███████║ ██║ " << endl;
79 cout <<
" ╚═════╝╚═╝ ╚═╝╚══════╝╚═╝ ╚═╝╚══════╝╚═╝ ╚═╝ ╚═╝ ╚══════╝╚══════╝ ╚═╝ " << endl;
80 cout <<
"A cloudFPGA project from IBM ZRL v0.1 --dco " << endl;
85 void delay(
unsigned int mseconds)
87 clock_t goal = mseconds +
clock();
88 while (goal >
clock());
100 unsigned char *b = (
unsigned char*) ptr;
104 for (i =
size-1; i >= 0; i--) {
105 for (j = 7; j >= 0; j--) {
106 byte = (b[i] >> j) & 1;
121 std::stringstream sstream;
122 for ( string::const_iterator item = in.begin(); item != in.end(); item++){
123 sstream << std::hex <<
int(*item);
136 template<
unsigned int bytes_per_line = 8>
137 string createMemTestCommands(
unsigned long long int mem_address,
unsigned int testingNumber,
unsigned int burst_size)
140 char start_cmd [bytes_per_line];
141 char stop_cmd [bytes_per_line];
142 char value_cmd[bytes_per_line];
143 char burst_cmd[bytes_per_line];
145 for (
unsigned int k = 0; k < bytes_per_line; k++) {
146 value_cmd[k] = (char)0;
148 stop_cmd[k] = (char)0;
149 start_cmd[k] = (char)0;
150 burst_cmd[k] = (char)0;
153 start_cmd[k] = (char)1;
154 stop_cmd[k] = (char)2;
155 burst_cmd[k] = (char)4;
158 memcpy(start_cmd+1, (
char*)&testingNumber, 2);
159 out =
out.append(start_cmd,3);
160 memcpy(value_cmd, (
char*)&mem_address, 5);
161 out =
out.append(value_cmd,5);
162 memcpy(burst_cmd+1,(
char*)&burst_size,2);
163 out =
out.append(burst_cmd,8);
167 template<
unsigned int bytes_per_line = 8>
171 char stop_cmd [bytes_per_line];
172 for (
unsigned int k = 0; k < bytes_per_line; k++) {
174 stop_cmd[k] = (char)0;
177 stop_cmd[k] = (char)2;
180 out.append(stop_cmd,bytes_per_line);
183 static inline ssize_t
184 __file_size(
const char *fname)
189 rc = lstat(fname, &s);
191 fprintf(stderr,
"err: Cannot find %s!\n", fname);
197 static inline ssize_t
198 __file_read(
const char *fname,
char *buff,
size_t len)
203 if ((fname == NULL) || (buff == NULL) || (len == 0))
206 fp = fopen(fname,
"r");
208 fprintf(stderr,
"err: Cannot open file %s: %s\n",
209 fname, strerror(errno));
212 rc = fread(buff, len, 1, fp);
214 fprintf(stderr,
"err: Cannot read from %s: %s\n",
215 fname, strerror(errno));
236 if (
'0' <= c && c <=
'9')
238 else if (
'a' <= c && c <=
'f')
240 else if (
'A' <= c && c <=
'F')
254 out.reserve(in.length() / 2);
255 for (string::const_iterator p = in.begin(); p != in.end(); p++)
257 unsigned char c =
hexval(*p);
259 if (p == in.end())
break;
260 c = (c << 4) +
hexval(*p);
268 std::sprintf(
out,byteSize,
"%x", (
char*)&in);
278 template<
unsigned int bytes_per_line = 8>
282 ifstream inpFileStream;
283 string datFile = inpFileName;
288 unsigned long long int mylongunsigned;
289 unsigned long long int zero_byte=0;
291 char my_tmp_buf [bytes_per_line];
293 inpFileStream.open(datFile.c_str());
295 if ( !inpFileStream ) {
296 cout <<
"### ERROR : Could not open the input data file " << datFile << endl;
301 while (inpFileStream) {
303 if (!inpFileStream.eof()) {
305 getline(inpFileStream, strLine);
306 memcpy(my_tmp_buf,&zero_byte, bytes_per_line);
307 if (strLine.empty())
continue;
309 mylongunsigned=stoul(strLine,
nullptr,16);
312 memcpy(my_tmp_buf,(
char *)&mylongunsigned,
sizeof(
unsigned long long int));
313 charOutput.append(my_tmp_buf, bytes_per_line);
318 inpFileStream.close();
321 return string(charOutput);
333 std::stringstream sstream;
334 for (
int i=0; i<bytesize; i++){
335 sstream << std::hex <<
int(in[i]);
341 unsigned int len = strlen(
str);
343 for(
unsigned int i=0; i<=len; i++) {
345 printf(
"DEBUG: null character position: %d\n",i+1);
350 printf(
"DEBUG: null character not found\n");
364 #if DEBUG_LEVEL == TRACE_ALL
365 printf(
"Going to print a hex string :D\n");
367 for (
size_t i = 0; i < strSize; i++)
369 printf(
"%x",inStr[i]);
383 #if DEBUG_LEVEL == TRACE_ALL
384 printf(
"Going to prit a hex char buff :D\n");
386 for (
size_t i = 0; i < strSize; i++)
388 printf(
"%x",inStr[i]);
395 printf(
"Going to prit a hex char buff :D\n");
396 for (
size_t i = 0; i < strSize; i++)
407 for (
int i = 0; i < byteSize; i++)
409 std::sprintf(
out+i,
"%d", (
int)in[i]);
423 unsigned long long int target_address,
424 unsigned int fault_cntr,
425 unsigned int first_fault_address,
426 unsigned long long int clock_cycles_write,
427 unsigned long long int clock_cycles_read) :
428 target_address(target_address),
429 fault_cntr(fault_cntr),
430 first_fault_address(first_fault_address),
431 clock_cycles_write(clock_cycles_write),
432 clock_cycles_read(clock_cycles_read) {}
443 template<
unsigned int bytes_per_line=8>
446 std::vector<MemoryTestResult> testResults_vector;
448 int rawiterations = charOutputSize / 8;
449 unsigned int mem_word_size = 512;
450 unsigned int mem_word_byte_size = mem_word_size/8;
451 bool is_stop_present = rawdatalines % (3+1+1) == 0;
454 char myTmpOutBuff [bytes_per_line];
455 for (
int i = 0; i < bytes_per_line; ++i)
457 myTmpOutBuff[i]=(char)0;
459 unsigned int testingNumber_out=0, fault_cntr_out=0, fault_addr_out=0;
460 unsigned long long int max_memory_addr_out=0, clock_cycles_read=0, clock_cycles_write=0;
461 for (
int i = 1; i < rawdatalines+1; i++)
464 tmp_outbuff= longbuf.substr((i-1)*bytes_per_line,bytes_per_line);
465 if(is_stop_present && k==7){
466 cout <<
"DEBUG the stop is present and is here" << endl;
467 }
else if( ( (i == rawdatalines-1) || (i == rawdatalines) ) && k==6){
471 memcpy(&testingNumber_out,tmp_outbuff.c_str()+1,bytes_per_line/2);
473 #if DEBUG_LEVEL == TRACE_ALL
474 cout <<
"DEBUG last command with the iterations " << testingNumber_out << endl;
479 memcpy(&clock_cycles_read,tmp_outbuff.c_str(),bytes_per_line);
481 #if DEBUG_LEVEL == TRACE_ALL
482 cout <<
"DEBUG clock_cycles_read (or the fourth half data pckt) " << clock_cycles_read << endl;
483 cout <<
"DEBUG clock_cycles_write (or the fourth half data pckt) " << clock_cycles_write << endl;
485 MemoryTestResult tmpResult(max_memory_addr_out,fault_cntr_out,fault_addr_out,clock_cycles_write,clock_cycles_read);
486 testResults_vector.push_back(tmpResult);
487 if(!( (i+1 == rawdatalines-1) || (i+1 == rawdatalines) )){
489 #if DEBUG_LEVEL == TRACE_ALL
490 cout <<
"DEBUG reinit the counter" << endl;
493 unsigned int written_words = max_memory_addr_out%mem_word_byte_size == 0 ? max_memory_addr_out/mem_word_byte_size : max_memory_addr_out/mem_word_byte_size + 1;
494 double rd_bndwdth = ( (double)written_words*(
double)mem_word_size / ( (double)tmpResult.
clock_cycles_read * ( 6.4 ) ) );
495 double wr_bndwdth = ( (double)written_words*(
double)mem_word_size / ( (double)tmpResult.
clock_cycles_write * ( 6.4 ) ) );
496 #if DEBUG_LEVEL == TRACE_ALL
497 cout <<
"Written " << written_words <<
" words" << endl;
498 cout <<
"DEBUG overall test results: target address " << tmpResult.
target_address <<
" ";
499 cout <<
"Fault counter: " << tmpResult.
fault_cntr <<
" ";
501 cout <<
" RD BW " << rd_bndwdth <<
"[GBit/s] with cc equal to " << tmpResult.
clock_cycles_read <<
" " << endl;
502 cout <<
" WR BW " << wr_bndwdth <<
"[GBit/s] with cc equal to " << tmpResult.
clock_cycles_write <<
" " << endl;
519 memcpy(&clock_cycles_write,tmp_outbuff.c_str(),bytes_per_line);
525 memcpy(&fault_addr_out,tmp_outbuff.c_str(),bytes_per_line/2);
527 #if DEBUG_LEVEL == TRACE_ALL
528 cout <<
"DEBUG first fault address (or the third data pckt) " << fault_addr_out << endl;
533 memcpy(&fault_cntr_out,tmp_outbuff.c_str(),bytes_per_line/2);
535 #if DEBUG_LEVEL == TRACE_ALL
536 cout <<
"DEBUG the fault counters (or the second data pack) " << fault_cntr_out << endl;
542 memcpy(&max_memory_addr_out,tmp_outbuff.c_str(),bytes_per_line);
543 #if DEBUG_LEVEL == TRACE_ALL
544 cout <<
"DEBUG max address (or the first data pack) " << max_memory_addr_out << endl;
550 return testResults_vector;
562 loggingAVGFile <<
"TimeStamp,Iterations[#],Trgt_Address[Byte],Brst_size[#beats],WrittenWords[512b],AVG_RD_BW[Gbit/s],AVG_WR_BW[Gbit/s],AVG_faults[#],PowOfTwoBytes\n";
568 unsigned int iters,
unsigned long long int trgt_address,
569 unsigned int brst_size,
unsigned int wr_words,
570 double rd_bw,
double wr_bw,
unsigned int faults )
573 std::time_t instant_time = std::time(0);
574 std::tm* now = std::localtime(&instant_time);
575 loggingAVGFile << (now->tm_year + 1900)<<
'-' << (now->tm_mon + 1) <<
'-' << now->tm_mday <<
"," << iters<<
",";
576 loggingAVGFile<<trgt_address<<
","<<brst_size<<
","<<wr_words<<
",";
592 loggingMultiItFile <<
"Brst_size[#beats],WrittenWords[512b],RD_BW[Gbit/s],WR_BW[Gbit/s],";
599 unsigned int iters,
unsigned long long int trgt_address,
600 unsigned int brst_size,
unsigned int wr_words,
601 double rd_bw,
double wr_bw,
unsigned int faults,
602 unsigned long long int first_faulty_address )
605 std::time_t instant_time = std::time(0);
606 std::tm* now = std::localtime(&instant_time);
607 loggingMultiItFile << (now->tm_year + 1900)<<
'-' << (now->tm_mon + 1) <<
'-' << now->tm_mday <<
"," << iters<<
",";
void ascii2hex(const string &in, string &out)
Convert a ascii string to a hexadecimal string.
unsigned char hexval(unsigned char c)
convert a char to its hexadecimal representation.
unsigned long long int clock_cycles_read
const std::string loggingAVGFileName
std::vector< MemoryTestResult > parseMemoryTestOutput(const string longbuf, size_t charOutputSize, int rawdatalines)
Parse the memory test output contained in astring with a given size.
void number2hexString(const T in, char *out, size_t byteSize)
string dumpFileToStringRawDataString(const string inpFileName, int *rawdatalines, size_t outputSize)
Initialize an input data stream from a file with only data.
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.
unsigned int first_fault_address
void printCharBuffHex(const char *inStr, size_t strSize)
print byte-per-byte a given char buff in hexadecimal format
std::ofstream loggingMultiItFile
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)
void ascii2hexWithSize(const string &in, string &out, size_t bytesize)
Convert a ascii string to a hexadecimal string.
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.
void string2hexnumerics(const string &in, char *out, size_t byteSize)
string createMemTestStopCommand()
void logTheAvgResult(unsigned int iters, unsigned long long int trgt_address, unsigned int brst_size, unsigned int wr_words, double rd_bw, double wr_bw, unsigned int faults)
void delay(unsigned int mseconds)
void logTheSingleResult(unsigned int iters, unsigned long long int trgt_address, unsigned int brst_size, unsigned int wr_words, double rd_bw, double wr_bw, unsigned int faults, unsigned long long int first_faulty_address)
unsigned long long int clock_cycles_write
void print_cFpMemtest(void)
void printCharBuffHexSafe(const char *inStr, size_t strSize)
bool findCharNullPos(char *str)
void printStringHex(const string inStr, size_t strSize)
print byte-per-byte a given string in hexadecimal format
std::ofstream loggingAVGFile
void hex2ascii(const string &in, string &out)
Convert a hexadecimal string to a ascii string.
const std::string loggingMultiItFileName
unsigned long long int target_address