Main testbench for the user-application for Memtest on host. Server
56 if ((argc < 2) || (argc > 3)) {
57 cerr <<
"Usage: " << argv[0] <<
" <Server Port> <optional simulation mode>" << endl;
61 unsigned short servPort = atoi(argv[1]);
62 unsigned int num_batch = 0;
63 string clean_cmd, synth_cmd;
64 unsigned int testingNumber=3;
65 string strInput_nmbrTest=
"";
69 bool endOfLooping=
false;
77 UDPSocket sock(servPort);
79 TCPServerSocket servSock(servPort);
80 TCPSocket *servsock = servSock.accept();
83 unsigned int recvMsgSize;
85 unsigned short sourcePort;
89 cout <<
"Handling client ";
91 cout << servsock->getForeignAddress() <<
":";
92 }
catch (SocketException e) {
93 cerr <<
"Unable to get foreign address" << endl;
96 cout << servsock->getForeignPort();
97 }
catch (SocketException e) {
98 cerr <<
"Unable to get foreign port" << endl;
106 clock_t last_cycle_rx =
clock();
108 int input_string_total_len = 0;
111 int bytes_in_last_pack;
113 bool msg_received =
false;
114 cout <<
" ___________________________________________________________________ " << endl;
115 cout <<
"/ \\" << endl;
116 cout <<
"INFO: Proxy tb batch # " << ++num_batch << endl;
117 char * longbuf =
new char[
PACK_SIZE * (total_pack+1)];
119 for (
int i = 0; msg_received !=
true; i++, total_pack++) {
121 recvMsgSize = sock.recvFrom(buffer,
BUF_LEN, sourceAddress, sourcePort);
123 recvMsgSize = servsock->recv(buffer, receiving_now);
125 input_string_total_len += recvMsgSize;
126 bytes_in_last_pack = recvMsgSize;
128 memcpy(longbuf+(i*
PACK_SIZE), buffer, recvMsgSize);
132 if (nullcharfound !=
true) {
133 cout <<
"INFO: The string is not entirely fit in packet " << total_pack << endl;
140 cout <<
"INFO: Received packet from " << sourceAddress <<
":" << sourcePort << endl;
144 if (input_string.length() == 0) {
145 cerr <<
"ERROR: received an empty string! Aborting..." << endl;
151 unsigned long long int memory_addr_under_test = 0;
153 unsigned int burst_size = 0;
155 cout <<
"Begin the decoding step" << endl;
160 reverse(input_string.begin(), input_string.end());
165 string substr_tmp, to_translate_String;
166 substr_tmp = input_string.substr(7,1);
169 if(to_translate_String.compare(
"2")==0){
173 strncpy(cmd_stop,cmd_string.c_str(),8);
174 unsigned int sending_bytes=8;
176 sock.sendTo( cmd_stop, sending_bytes, sourceAddress, sourcePort);
178 servsock->send(cmd_stop, sending_bytes);
180 cout <<
"A stop received, going to sleep the EMU :)" << endl;
181 cout <<
"\\___________________________________________________________________/" << endl;
187 reverse(input_string.begin(), input_string.end());
194 char myTmpOutBuff[8];
196 substr_tmp = input_string.substr(1,2);
197 for(
int i=0; i < 8; i++){myTmpOutBuff[i]=(char)0;}
198 strncpy(myTmpOutBuff,substr_tmp.c_str(),2);
199 testingNumber = *
reinterpret_cast<unsigned long long*
>(myTmpOutBuff);
203 for(
int i=0; i < 8; i++){myTmpOutBuff[i]=(char)0;}
204 substr_tmp=input_string.substr(3,5);
205 memcpy(myTmpOutBuff,substr_tmp.c_str(),5);
206 memory_addr_under_test = *
reinterpret_cast<unsigned long long*
>(myTmpOutBuff);
210 substr_tmp = input_string.substr(9,2);
212 for(
int i=0; i < 8; i++){myTmpOutBuff[i]=(char)0;}
213 memcpy(myTmpOutBuff,substr_tmp.c_str(),2);
214 burst_size = *
reinterpret_cast<unsigned long long*
>(myTmpOutBuff);
216 for(
int i=0; i < 8; i++){myTmpOutBuff[i]=(char)0;}
219 reverse(input_string.begin(), input_string.end());
220 cout << input_string << endl;
225 string exec_cmd =
"make fcsim ";
226 string ouf_file =
"../../../../../../ROLE/custom/hls/memtest/memtest_prj/solution1/fcsim/build/hls_out.txt";
228 if (atoi(argv[2]) == 2) {
229 exec_cmd =
"make csim";
230 ouf_file =
"../../../../../../ROLE/custom/hls/memtest/memtest_prj/solution1/csim/build/hls_out.txt";
232 else if (atoi(argv[2]) == 3) {
233 synth_cmd =
"make csynth && ";
234 exec_cmd =
"make cosim";
235 ouf_file =
"../../../../../../ROLE/custom/hls/memtest/memtest_prj/solution1/sim/wrapc_pc/build/hls_out.txt";
237 else if (atoi(argv[2]) == 4) {
238 exec_cmd =
"make kcachegrind";
239 ouf_file =
"../../../../../../ROLE/custom/hls/memtest/memtest_prj/solution1/fcsim/build/hls_out.txt";
246 if (num_batch == 1) {
247 clean_cmd =
"make clean && ";
249 string str_command =
"cd ../../../../../../ROLE/custom/hls/memtest/ && ";
250 str_command = str_command.append(clean_cmd + synth_cmd+ exec_cmd);
251 size_t str_command_size = str_command.length();
252 string final_cmd =
" TEST_NUMBER=" + std::to_string(testingNumber) +
" INPUT_STRING=" + std::to_string(memory_addr_under_test) +
" BURST_SIZE=" + std::to_string(burst_size) +
" && cd ../../../../HOST/custom/memtest/languages/cplusplus/build/ ";
253 str_command = str_command.append(final_cmd);
254 str_command_size+=final_cmd.length();
256 char *command =(
char*)malloc((str_command_size+1)*
sizeof(char));
257 for(
int i=0; i < (str_command_size+1); i++){
258 command[i]=str_command[i];
260 cout <<
"Calling TB with command:" << command << endl;
264 input_string.clear();
272 ssize_t
size = __file_size(ouf_file.c_str());
273 size_t charOutputSize = 8*1+((8 * (2 + 1+ 1 + 1)) * testingNumber);
280 longbuf =
new char[charOutputSize+1];
281 out_string.reserve(charOutputSize);
283 memcpy(longbuf,out_string.data(),charOutputSize);
286 cerr <<
"ERROR: Cannot read file " << ouf_file <<
" . Aborting..."<< endl;
290 clock_t next_cycle_rx =
clock();
291 double duration_rx = (next_cycle_rx - last_cycle_rx) / (
double) CLOCKS_PER_SEC;
292 cout <<
"INFO: Effective FPS RX:" << (1 / duration_rx) <<
" \tkbps:" << (
PACK_SIZE *
293 total_pack / duration_rx / 1024 * 8) << endl;
294 last_cycle_rx = next_cycle_rx;
301 unsigned int total_retx_pack = 1;
303 if (out_string.length() == 0) {
304 cerr <<
"ERROR: Received empty string!" << endl;
308 cout <<
"INFO: Succesfully received string from TB : " << out_string << endl;
310 cout <<
"INFO: Will forward it back to host app ... total_pack=" << total_retx_pack << endl;
315 clock_t last_cycle_tx =
clock();
316 unsigned int bytes_in_last_pack_in = charOutputSize - (total_retx_pack - 1) *
PACK_SIZE;
317 for (
int i = 0; i < total_retx_pack; i++) {
318 if ( i == total_retx_pack - 1 ) {
319 sending_now = bytes_in_last_pack_in;
322 sock.sendTo( longbuf+(i *
PACK_SIZE), sending_now, sourceAddress, sourcePort);
324 servsock->send( & longbuf[i *
PACK_SIZE], sending_now);
327 clock_t next_cycle_tx =
clock();
328 double duration_tx = (next_cycle_tx - last_cycle_tx) / (
double) CLOCKS_PER_SEC;
329 cout <<
"INFO: Effective FPS TX:" << (1 / duration_tx) <<
" \tkbps:" << (
PACK_SIZE *
330 total_retx_pack / duration_tx / 1024 * 8) << endl;
331 last_cycle_tx = next_cycle_tx;
333 cout <<
"\\___________________________________________________________________/" << endl;
338 }
catch (SocketException & e) {
339 cerr << e.what() << endl;
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.
void ascii2hexWithSize(const string &in, string &out, size_t bytesize)
Convert a ascii string to a hexadecimal string.
string createMemTestStopCommand()
bool findCharNullPos(char *str)