1 /* ---------------------------------------------------------------------- 2 * Project: CMSIS DSP Library 3 * Title: Semihosting.cpp 4 * Description: Semihosting io 5 * 6 * IO for a platform supporting semihosting. 7 * (Several input and output files) 8 * 9 * $Date: 20. June 2019 10 * $Revision: V1.0.0 11 * 12 * Target Processor: Cortex-M cores 13 * -------------------------------------------------------------------- */ 14 /* 15 * Copyright (C) 2010-2019 ARM Limited or its affiliates. All rights reserved. 16 * 17 * SPDX-License-Identifier: Apache-2.0 18 * 19 * Licensed under the Apache License, Version 2.0 (the License); you may 20 * not use this file except in compliance with the License. 21 * You may obtain a copy of the License at 22 * 23 * www.apache.org/licenses/LICENSE-2.0 24 * 25 * Unless required by applicable law or agreed to in writing, software 26 * distributed under the License is distributed on an AS IS BASIS, WITHOUT 27 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 28 * See the License for the specific language governing permissions and 29 * limitations under the License. 30 */ 31 #include "Test.h" 32 33 #include <string> 34 #include <cstddef> 35 #include <cstdio> 36 #include <cstring> 37 #include <cstdlib> 38 #include "Generators.h" 39 #include "Semihosting.h" 40 #include "arm_math_types.h" 41 #include "arm_math_types_f16.h" 42 43 44 namespace Client 45 { 46 47 struct pathOrGen { 48 int kind; 49 std::string path; 50 Testing::param_t *data; 51 Testing::nbSamples_t nbInputSamples; 52 Testing::nbSamples_t nbOutputSamples; 53 int dimensions; 54 }; 55 Semihosting(std::string path,std::string patternRootPath,std::string outputRootPath,std::string parameterRootPath)56 Semihosting::Semihosting(std::string path,std::string patternRootPath,std::string outputRootPath,std::string parameterRootPath) 57 { 58 // Open the driver file 59 this->infile=fopen(path.c_str(), "r"); 60 this->path=new std::vector<std::string>(); 61 this->patternRootPath=patternRootPath; 62 this->outputRootPath=outputRootPath; 63 this->parameterRootPath=parameterRootPath; 64 this->patternFilenames=new std::vector<std::string>(); 65 this->outputNames=new std::vector<std::string>(); 66 this->parameterNames=new std::vector<struct pathOrGen>(); 67 this->m_hasParam = false; 68 } 69 DeleteParams()70 void Semihosting::DeleteParams() 71 { 72 for (std::vector<struct pathOrGen>::iterator it = this->parameterNames->begin() ; it != this->parameterNames->end(); ++it) 73 { 74 if (it->kind==1) 75 { 76 if (it->data) 77 { 78 free(it->data); 79 it->data = NULL; 80 } 81 } 82 } 83 } 84 ~Semihosting()85 Semihosting::~Semihosting() 86 { 87 fclose(this->infile); 88 delete(this->path); 89 delete(this->patternFilenames); 90 delete(this->outputNames); 91 this->DeleteParams(); 92 delete(this->parameterNames); 93 } 94 95 /** 96 Read the list of patterns from the driver file. 97 98 This list is for the current suite. 99 100 */ ReadPatternList()101 void Semihosting::ReadPatternList() 102 { 103 char tmp[256]; 104 int nbPatterns; 105 fscanf(this->infile,"%d\n",&nbPatterns); 106 // Reset the list for the current suite 107 this->patternFilenames->clear(); 108 std::string tmpstr; 109 110 for(int i=0;i<nbPatterns;i++) 111 { 112 fgets(tmp,256,this->infile); 113 // Remove end of line 114 if (tmp[strlen(tmp)-1] == '\n') 115 { 116 tmp[strlen(tmp)-1]=0; 117 } 118 tmpstr.assign(tmp); 119 this->patternFilenames->push_back(tmpstr); 120 } 121 } 122 123 /** 124 Read the list of parameters from the driver file. 125 126 This list is for the current suite. 127 128 */ ReadParameterList(Testing::nbParameters_t nbParams)129 void Semihosting::ReadParameterList(Testing::nbParameters_t nbParams) 130 { 131 char tmp[256]; 132 char paramKind; 133 std::string tmpstr; 134 135 // It is the number of samples in the file. 136 // Not the number of parameters controlling the function 137 int nbValues; 138 fscanf(this->infile,"%d\n",&nbValues); 139 140 // Reset the list for the current suite 141 this->DeleteParams(); 142 this->parameterNames->clear(); 143 144 for(int i=0;i<nbValues;i++) 145 { 146 fscanf(this->infile,"%c\n",¶mKind); 147 struct pathOrGen gen; 148 149 if (paramKind == 'p') 150 { 151 fgets(tmp,256,this->infile); 152 // Remove end of line 153 if (tmp[strlen(tmp)-1] == '\n') 154 { 155 tmp[strlen(tmp)-1]=0; 156 } 157 tmpstr.assign(tmp); 158 159 std::string tmp; 160 tmp += this->parameterRootPath; 161 tmp += this->testDir; 162 tmp += "/"; 163 tmp += tmpstr; 164 165 166 gen.kind=0; 167 gen.path=tmp; 168 169 gen.nbInputSamples = this->GetFileSize(tmp); 170 gen.dimensions = nbParams; 171 172 } 173 // Generator 174 // Generator kind (only 1 = cartesian product generator) 175 // Number of samples generated when run 176 // Number of dimensions 177 // For each dimension 178 // Length 179 // Samples 180 else 181 { 182 int kind,nbInputSamples,nbOutputSamples,dimensions,sample; 183 Testing::param_t *p,*current; 184 185 // Generator kind. Not yet used since there is only one kind of generator 186 fscanf(this->infile,"%d\n",&kind); 187 // Input data in config file 188 fscanf(this->infile,"%d\n",&nbInputSamples); 189 190 // Number of output combinations 191 // And each output has dimensions parameters 192 fscanf(this->infile,"%d\n",&nbOutputSamples); 193 fscanf(this->infile,"%d\n",&dimensions); 194 195 p=(Testing::param_t*)malloc(sizeof(Testing::param_t)*(nbInputSamples)); 196 current=p; 197 for(int i=0;i < nbInputSamples; i ++) 198 { 199 200 fscanf(this->infile,"%d\n",&sample); 201 *current++ = (Testing::param_t)sample; 202 } 203 204 gen.kind=1; 205 gen.data=p; 206 gen.nbInputSamples = nbInputSamples; 207 gen.nbOutputSamples = nbOutputSamples; 208 gen.dimensions = dimensions; 209 } 210 this->parameterNames->push_back(gen); 211 212 } 213 } 214 215 /** 216 Read the list of output from the driver file. 217 218 This list is for the current suite. 219 220 */ ReadOutputList()221 void Semihosting::ReadOutputList() 222 { 223 char tmp[256]; 224 int nbOutputs; 225 fscanf(this->infile,"%d\n",&nbOutputs); 226 // Reset the list for the current suite 227 this->outputNames->clear(); 228 std::string tmpstr; 229 230 for(int i=0;i<nbOutputs;i++) 231 { 232 fgets(tmp,256,this->infile); 233 // Remove end of line 234 if (tmp[strlen(tmp)-1] == '\n') 235 { 236 tmp[strlen(tmp)-1]=0; 237 } 238 tmpstr.assign(tmp); 239 this->outputNames->push_back(tmpstr); 240 } 241 } 242 243 244 /** Read the number of parameters for all the tests in a suite 245 246 Used for benchmarking. Same functions executed with 247 different initializations controlled by the parameters. 248 249 It is not the number of parameters in a file 250 but the number of arguments (parameters) to control a function. 251 252 */ ReadNbParameters()253 Testing::nbParameters_t Semihosting::ReadNbParameters() 254 { 255 unsigned long nb; 256 fscanf(this->infile,"%ld\n",&nb); 257 258 return(nb); 259 } 260 recomputeTestDir()261 void Semihosting::recomputeTestDir() 262 { 263 this->testDir = "."; 264 int start = 1; 265 std::vector<std::string>::const_iterator iter; 266 for (iter = this->path->begin(); iter != this->path->end(); ++iter) 267 { 268 if (start) 269 { 270 this->testDir = *iter; 271 start =0; 272 } 273 else 274 { 275 if (!(*iter).empty()) 276 { 277 this->testDir += "/" + *iter; 278 } 279 } 280 } 281 } 282 283 ReadTestIdentification()284 void Semihosting::ReadTestIdentification() 285 { 286 287 char tmp[255]; 288 int kind; 289 Testing::testID_t theId; 290 char hasPath; 291 char hasParamID; 292 Testing::PatternID_t paramID; 293 294 295 fscanf(this->infile,"%d %ld\n",&kind,&theId); 296 297 fscanf(this->infile,"%c\n",&hasParamID); 298 this->m_hasParam=false; 299 if (hasParamID == 'y') 300 { 301 this->m_hasParam=true; 302 fscanf(this->infile,"%ld\n",¶mID); 303 this->currentParam=paramID; 304 } 305 306 fscanf(this->infile,"%c\n",&hasPath); 307 if (hasPath == 'y') 308 { 309 fgets(tmp,256,this->infile); 310 // Remove end of line 311 if (tmp[strlen(tmp)-1] == '\n') 312 { 313 tmp[strlen(tmp)-1]=0; 314 } 315 currentPath.assign(tmp); 316 } 317 318 this->currentKind=kind; 319 this->currentId=theId; 320 switch(kind) 321 { 322 case 1: 323 printf("t \n"); 324 break; 325 case 2: 326 printf("s %ld\n",this->currentId); 327 break; 328 case 3: 329 printf("g %ld\n",this->currentId); 330 break; 331 default: 332 printf("u\n"); 333 } 334 335 } 336 CurrentTestID()337 Testing::testID_t Semihosting::CurrentTestID() 338 { 339 return(this->currentId); 340 } 341 342 /** 343 Read identification of a group or suite. 344 345 The difference with a test node is that the current folder 346 can be changed by a group or suite. 347 348 */ ReadIdentification()349 void Semihosting::ReadIdentification() 350 { 351 this->ReadTestIdentification(); 352 this->path->push_back(currentPath); 353 this->recomputeTestDir(); 354 } 355 356 /** 357 Dump the test status into the output (stdout) 358 359 */ DispStatus(Testing::TestStatus status,Testing::errorID_t error,unsigned long lineNb,Testing::cycles_t cycles)360 void Semihosting::DispStatus(Testing::TestStatus status 361 ,Testing::errorID_t error 362 ,unsigned long lineNb 363 ,Testing::cycles_t cycles) 364 { 365 if (status == Testing::kTestFailed) 366 { 367 printf("%ld %ld %ld 0 N\n",this->currentId,error,lineNb); 368 } 369 else 370 { 371 #ifdef EXTBENCH 372 printf("%ld 0 0 t Y\n",this->currentId); 373 #else 374 printf("%ld 0 0 %u Y\n",this->currentId,cycles); 375 #endif 376 } 377 } 378 DispErrorDetails(const char * details)379 void Semihosting::DispErrorDetails(const char* details) 380 { 381 printf("E: %s\n",details); 382 } 383 384 /** 385 Signal end of group 386 387 (Used by scripts parsing the output to display the results) 388 */ EndGroup()389 void Semihosting::EndGroup() 390 { 391 printf("p\n"); 392 this->path->pop_back(); 393 } 394 395 /** 396 Get pattern path. 397 398 399 */ getPatternPath(Testing::PatternID_t id)400 std::string Semihosting::getPatternPath(Testing::PatternID_t id) 401 { 402 std::string tmp; 403 tmp += this->patternRootPath; 404 tmp += this->testDir; 405 tmp += "/"; 406 tmp += (*this->patternFilenames)[id]; 407 408 return(tmp); 409 } 410 411 /** 412 Get parameter path. 413 414 415 */ getParameterDesc(Testing::PatternID_t id)416 struct pathOrGen Semihosting::getParameterDesc(Testing::PatternID_t id) 417 { 418 419 420 421 return((*this->parameterNames)[id]); 422 423 } 424 425 /** 426 Get output path. 427 428 The test ID (currentId) is used in the name 429 */ getOutputPath(Testing::outputID_t id)430 std::string Semihosting::getOutputPath(Testing::outputID_t id) 431 { 432 char fmt[256]; 433 434 std::string tmp; 435 tmp += this->outputRootPath; 436 tmp += this->testDir; 437 sprintf(fmt,"/%s_%ld.txt",(*this->outputNames)[id].c_str(),this->currentId); 438 tmp += std::string(fmt); 439 //printf("%s\n",tmp.c_str()); 440 441 return(tmp); 442 } 443 GetPatternSize(Testing::PatternID_t id)444 Testing::nbSamples_t Semihosting::GetPatternSize(Testing::PatternID_t id) 445 { 446 char tmp[256]; 447 Testing::nbSamples_t len; 448 std::string fileName = this->getPatternPath(id); 449 450 FILE *pattern=fopen(fileName.c_str(), "r"); 451 452 if (pattern==NULL) 453 { 454 return(0); 455 } 456 457 // Ignore word size format 458 fgets(tmp,256,pattern); 459 460 // Get nb of samples 461 fgets(tmp,256,pattern); 462 463 fclose(pattern); 464 465 466 len=atoi(tmp); 467 return(len); 468 469 } 470 GetFileSize(std::string & filepath)471 Testing::nbSamples_t Semihosting::GetFileSize(std::string &filepath) 472 { 473 char tmp[256]; 474 Testing::nbSamples_t len; 475 476 477 FILE *params=fopen(filepath.c_str(), "r"); 478 if (params==NULL) 479 { 480 return(0); 481 } 482 // Get nb of samples 483 fgets(tmp,256,params); 484 fclose(params); 485 486 len=atoi(tmp); 487 return(len); 488 489 } 490 DumpParams(std::vector<Testing::param_t> & params)491 void Semihosting::DumpParams(std::vector<Testing::param_t>& params) 492 { 493 bool begin=true; 494 printf("b "); 495 for(std::vector<Testing::param_t>::iterator it = params.begin(); it != params.end(); ++it) 496 { 497 if (!begin) 498 { 499 printf(","); 500 } 501 printf("%d",*it); 502 begin=false; 503 } 504 printf("\n"); 505 } 506 ImportParams(Testing::PatternID_t id,Testing::nbParameterEntries_t & nbEntries,Testing::ParameterKind & paramKind)507 Testing::param_t* Semihosting::ImportParams(Testing::PatternID_t id,Testing::nbParameterEntries_t &nbEntries,Testing::ParameterKind ¶mKind) 508 { 509 nbEntries = 0; 510 511 char tmp[256]; 512 513 Testing::param_t *p; 514 uint32_t val; 515 516 Testing::nbSamples_t len; 517 struct pathOrGen gen = this->getParameterDesc(id); 518 519 if (gen.kind == 0) 520 { 521 char *result=NULL; 522 paramKind=Testing::kDynamicBuffer; 523 FILE *params=fopen(gen.path.c_str(), "r"); 524 525 if (params==NULL) 526 { 527 return(NULL); 528 } 529 // Get nb of samples 530 fgets(tmp,256,params); 531 532 533 len=gen.nbInputSamples; 534 result=(char*)malloc(len*sizeof(Testing::param_t)); 535 p = (Testing::param_t*)result; 536 nbEntries = len / gen.dimensions; 537 538 for(uint32_t i=0; i < len; i++) 539 { 540 fscanf(params,"%d\n",&val); 541 *p++ = val; 542 } 543 544 545 fclose(params); 546 return((Testing::param_t*)result); 547 } 548 else 549 { 550 551 Testing::param_t* result; 552 paramKind=Testing::kDynamicBuffer; 553 // Output samples is number of parameter line 554 len=gen.nbOutputSamples * gen.dimensions; 555 556 result=(Testing::param_t*)malloc(len*sizeof(Testing::param_t)); 557 558 559 switch(gen.dimensions) 560 { 561 case 1: 562 generate1(result,gen.data,nbEntries); 563 break; 564 case 2: 565 generate2(result,gen.data,nbEntries); 566 break; 567 case 3: 568 generate3(result,gen.data,nbEntries); 569 break; 570 case 4: 571 generate4(result,gen.data,nbEntries); 572 break; 573 default: 574 generate1(result,gen.data,nbEntries); 575 break; 576 } 577 578 return(result); 579 } 580 581 } 582 hasParam()583 bool Semihosting::hasParam() 584 { 585 return(this->m_hasParam); 586 } 587 getParamID()588 Testing::PatternID_t Semihosting::getParamID() 589 { 590 return(this->currentParam); 591 } 592 ImportPattern_f64(Testing::PatternID_t id,char * p,Testing::nbSamples_t nb)593 void Semihosting::ImportPattern_f64(Testing::PatternID_t id,char* p,Testing::nbSamples_t nb) 594 { 595 char tmp[256]; 596 Testing::nbSamples_t len; 597 Testing::nbSamples_t i=0; 598 599 uint64_t val; 600 float64_t *ptr=(float64_t*)p; 601 602 std::string fileName = this->getPatternPath(id); 603 FILE *pattern=fopen(fileName.c_str(), "r"); 604 // Ignore word size format 605 // word size format is used when generating include files with python scripts 606 fgets(tmp,256,pattern); 607 // Get nb of samples 608 fgets(tmp,256,pattern); 609 len=atoi(tmp); 610 611 if ((nb != MAX_NB_SAMPLES) && (nb < len)) 612 { 613 len = nb; 614 } 615 616 if (ptr) 617 { 618 for(i=0;i<len;i++) 619 { 620 // Ignore comment 621 fgets(tmp,256,pattern); 622 fscanf(pattern,"0x%16llx\n",&val); 623 *ptr = TOTYP(float64_t,val); 624 ptr++; 625 } 626 } 627 628 fclose(pattern); 629 630 } 631 ImportPattern_f32(Testing::PatternID_t id,char * p,Testing::nbSamples_t nb)632 void Semihosting::ImportPattern_f32(Testing::PatternID_t id,char* p,Testing::nbSamples_t nb) 633 { 634 char tmp[256]; 635 Testing::nbSamples_t len; 636 Testing::nbSamples_t i=0; 637 638 uint32_t val; 639 float32_t *ptr=(float32_t*)p; 640 641 std::string fileName = this->getPatternPath(id); 642 FILE *pattern=fopen(fileName.c_str(), "r"); 643 // Ignore word size format 644 fgets(tmp,256,pattern); 645 // Get nb of samples 646 fgets(tmp,256,pattern); 647 len=atoi(tmp); 648 649 if ((nb != MAX_NB_SAMPLES) && (nb < len)) 650 { 651 len = nb; 652 } 653 654 //printf(":::: %s\n",fileName.c_str()); 655 656 if (ptr) 657 { 658 for(i=0;i<len;i++) 659 { 660 // Ignore comment 661 fgets(tmp,256,pattern); 662 fscanf(pattern,"0x%08X\n",&val); 663 //printf(":::: %08X %f\n",val, TOTYP(float32_t,val)); 664 *ptr = TOTYP(float32_t,val); 665 ptr++; 666 } 667 } 668 669 fclose(pattern); 670 671 } 672 673 #if !defined( __CC_ARM ) && defined(ARM_FLOAT16_SUPPORTED) ImportPattern_f16(Testing::PatternID_t id,char * p,Testing::nbSamples_t nb)674 void Semihosting::ImportPattern_f16(Testing::PatternID_t id,char* p,Testing::nbSamples_t nb) 675 { 676 char tmp[256]; 677 Testing::nbSamples_t len; 678 Testing::nbSamples_t i=0; 679 680 uint32_t val; 681 float16_t *ptr=(float16_t*)p; 682 683 std::string fileName = this->getPatternPath(id); 684 FILE *pattern=fopen(fileName.c_str(), "r"); 685 // Ignore word size format 686 fgets(tmp,256,pattern); 687 // Get nb of samples 688 fgets(tmp,256,pattern); 689 len=atoi(tmp); 690 691 if ((nb != MAX_NB_SAMPLES) && (nb < len)) 692 { 693 len = nb; 694 } 695 696 //printf(":::: %s\n",fileName.c_str()); 697 698 if (ptr) 699 { 700 for(i=0;i<len;i++) 701 { 702 // Ignore comment 703 fgets(tmp,256,pattern); 704 fscanf(pattern,"0x%08X\n",&val); 705 //printf(":::: %08X %f\n",val, TOTYP(float32_t,val)); 706 *ptr = TOTYP(float16_t,val); 707 ptr++; 708 } 709 } 710 711 fclose(pattern); 712 713 } 714 #endif 715 ImportPattern_q63(Testing::PatternID_t id,char * p,Testing::nbSamples_t nb)716 void Semihosting::ImportPattern_q63(Testing::PatternID_t id,char* p,Testing::nbSamples_t nb) 717 { 718 char tmp[256]; 719 Testing::nbSamples_t len; 720 Testing::nbSamples_t i=0; 721 722 uint64_t val; 723 q63_t *ptr=(q63_t*)p; 724 725 std::string fileName = this->getPatternPath(id); 726 FILE *pattern=fopen(fileName.c_str(), "r"); 727 // Ignore word size format 728 fgets(tmp,256,pattern); 729 // Get nb of samples 730 fgets(tmp,256,pattern); 731 len=atoi(tmp); 732 733 if ((nb != MAX_NB_SAMPLES) && (nb < len)) 734 { 735 len = nb; 736 } 737 738 if (ptr) 739 { 740 for(i=0;i<len;i++) 741 { 742 // Ignore comment 743 fgets(tmp,256,pattern); 744 fscanf(pattern,"0x%016llX\n",&val); 745 *ptr = TOTYP(q63_t,val); 746 ptr++; 747 } 748 } 749 750 fclose(pattern); 751 752 } 753 ImportPattern_q31(Testing::PatternID_t id,char * p,Testing::nbSamples_t nb)754 void Semihosting::ImportPattern_q31(Testing::PatternID_t id,char* p,Testing::nbSamples_t nb) 755 { 756 char tmp[256]; 757 Testing::nbSamples_t len; 758 Testing::nbSamples_t i=0; 759 760 uint32_t val; 761 q31_t *ptr=(q31_t*)p; 762 763 std::string fileName = this->getPatternPath(id); 764 FILE *pattern=fopen(fileName.c_str(), "r"); 765 // Ignore word size format 766 fgets(tmp,256,pattern); 767 // Get nb of samples 768 fgets(tmp,256,pattern); 769 len=atoi(tmp); 770 771 if ((nb != MAX_NB_SAMPLES) && (nb < len)) 772 { 773 len = nb; 774 } 775 776 if (ptr) 777 { 778 for(i=0;i<len;i++) 779 { 780 // Ignore comment 781 fgets(tmp,256,pattern); 782 fscanf(pattern,"0x%08X\n",&val); 783 *ptr = TOTYP(q31_t,val); 784 ptr++; 785 } 786 } 787 788 fclose(pattern); 789 790 } 791 ImportPattern_q15(Testing::PatternID_t id,char * p,Testing::nbSamples_t nb)792 void Semihosting::ImportPattern_q15(Testing::PatternID_t id,char* p,Testing::nbSamples_t nb) 793 { 794 char tmp[256]; 795 Testing::nbSamples_t len; 796 Testing::nbSamples_t i=0; 797 798 uint32_t val; 799 q15_t *ptr=(q15_t*)p; 800 801 std::string fileName = this->getPatternPath(id); 802 FILE *pattern=fopen(fileName.c_str(), "r"); 803 // Ignore word size format 804 fgets(tmp,256,pattern); 805 // Get nb of samples 806 fgets(tmp,256,pattern); 807 len=atoi(tmp); 808 809 if ((nb != MAX_NB_SAMPLES) && (nb < len)) 810 { 811 len = nb; 812 } 813 814 if (ptr) 815 { 816 for(i=0;i<len;i++) 817 { 818 // Ignore comment 819 fgets(tmp,256,pattern); 820 fscanf(pattern,"0x%08X\n",&val); 821 *ptr = TOTYP(q15_t,val); 822 ptr++; 823 } 824 } 825 826 fclose(pattern); 827 828 } 829 ImportPattern_q7(Testing::PatternID_t id,char * p,Testing::nbSamples_t nb)830 void Semihosting::ImportPattern_q7(Testing::PatternID_t id,char* p,Testing::nbSamples_t nb) 831 { 832 char tmp[256]; 833 Testing::nbSamples_t len; 834 Testing::nbSamples_t i=0; 835 836 uint32_t val; 837 q7_t *ptr=(q7_t*)p; 838 839 std::string fileName = this->getPatternPath(id); 840 FILE *pattern=fopen(fileName.c_str(), "r"); 841 // Ignore word size format 842 fgets(tmp,256,pattern); 843 // Get nb of samples 844 fgets(tmp,256,pattern); 845 len=atoi(tmp); 846 847 if ((nb != MAX_NB_SAMPLES) && (nb < len)) 848 { 849 len = nb; 850 } 851 852 if (ptr) 853 { 854 for(i=0;i<len;i++) 855 { 856 // Ignore comment 857 fgets(tmp,256,pattern); 858 fscanf(pattern,"0x%08X\n",&val); 859 *ptr = TOTYP(q7_t,val); 860 ptr++; 861 } 862 } 863 864 fclose(pattern); 865 866 } 867 ImportPattern_u64(Testing::PatternID_t id,char * p,Testing::nbSamples_t nb)868 void Semihosting::ImportPattern_u64(Testing::PatternID_t id,char* p,Testing::nbSamples_t nb) 869 { 870 char tmp[256]; 871 Testing::nbSamples_t len; 872 Testing::nbSamples_t i=0; 873 874 uint64_t val; 875 uint64_t *ptr=(uint64_t*)p; 876 877 std::string fileName = this->getPatternPath(id); 878 FILE *pattern=fopen(fileName.c_str(), "r"); 879 // Ignore word size format 880 fgets(tmp,256,pattern); 881 // Get nb of samples 882 fgets(tmp,256,pattern); 883 len=atoi(tmp); 884 885 if ((nb != MAX_NB_SAMPLES) && (nb < len)) 886 { 887 len = nb; 888 } 889 890 if (ptr) 891 { 892 for(i=0;i<len;i++) 893 { 894 // Ignore comment 895 fgets(tmp,256,pattern); 896 fscanf(pattern,"0x%016llX\n",&val); 897 *ptr = val; 898 ptr++; 899 } 900 } 901 902 fclose(pattern); 903 904 } 905 ImportPattern_u32(Testing::PatternID_t id,char * p,Testing::nbSamples_t nb)906 void Semihosting::ImportPattern_u32(Testing::PatternID_t id,char* p,Testing::nbSamples_t nb) 907 { 908 char tmp[256]; 909 Testing::nbSamples_t len; 910 Testing::nbSamples_t i=0; 911 912 uint32_t val; 913 uint32_t *ptr=(uint32_t*)p; 914 915 std::string fileName = this->getPatternPath(id); 916 FILE *pattern=fopen(fileName.c_str(), "r"); 917 // Ignore word size format 918 fgets(tmp,256,pattern); 919 // Get nb of samples 920 fgets(tmp,256,pattern); 921 len=atoi(tmp); 922 923 if ((nb != MAX_NB_SAMPLES) && (nb < len)) 924 { 925 len = nb; 926 } 927 928 if (ptr) 929 { 930 for(i=0;i<len;i++) 931 { 932 // Ignore comment 933 fgets(tmp,256,pattern); 934 fscanf(pattern,"0x%08X\n",&val); 935 *ptr = val; 936 ptr++; 937 } 938 } 939 940 fclose(pattern); 941 942 } 943 ImportPattern_u16(Testing::PatternID_t id,char * p,Testing::nbSamples_t nb)944 void Semihosting::ImportPattern_u16(Testing::PatternID_t id,char* p,Testing::nbSamples_t nb) 945 { 946 char tmp[256]; 947 Testing::nbSamples_t len; 948 Testing::nbSamples_t i=0; 949 950 uint32_t val; 951 uint16_t *ptr=(uint16_t*)p; 952 953 std::string fileName = this->getPatternPath(id); 954 FILE *pattern=fopen(fileName.c_str(), "r"); 955 // Ignore word size format 956 fgets(tmp,256,pattern); 957 // Get nb of samples 958 fgets(tmp,256,pattern); 959 len=atoi(tmp); 960 961 if ((nb != MAX_NB_SAMPLES) && (nb < len)) 962 { 963 len = nb; 964 } 965 966 if (ptr) 967 { 968 for(i=0;i<len;i++) 969 { 970 // Ignore comment 971 fgets(tmp,256,pattern); 972 fscanf(pattern,"0x%08X\n",&val); 973 *ptr = (uint16_t)val; 974 ptr++; 975 } 976 } 977 978 fclose(pattern); 979 980 } 981 ImportPattern_u8(Testing::PatternID_t id,char * p,Testing::nbSamples_t nb)982 void Semihosting::ImportPattern_u8(Testing::PatternID_t id,char* p,Testing::nbSamples_t nb) 983 { 984 char tmp[256]; 985 Testing::nbSamples_t len; 986 Testing::nbSamples_t i=0; 987 988 uint32_t val; 989 uint8_t *ptr=(uint8_t*)p; 990 991 std::string fileName = this->getPatternPath(id); 992 FILE *pattern=fopen(fileName.c_str(), "r"); 993 // Ignore word size format 994 fgets(tmp,256,pattern); 995 // Get nb of samples 996 fgets(tmp,256,pattern); 997 len=atoi(tmp); 998 999 if ((nb != MAX_NB_SAMPLES) && (nb < len)) 1000 { 1001 len = nb; 1002 } 1003 1004 if (ptr) 1005 { 1006 for(i=0;i<len;i++) 1007 { 1008 // Ignore comment 1009 fgets(tmp,256,pattern); 1010 fscanf(pattern,"0x%08X\n",&val); 1011 *ptr = (uint8_t)val; 1012 ptr++; 1013 } 1014 } 1015 1016 fclose(pattern); 1017 1018 } 1019 DumpPattern_f64(Testing::outputID_t id,Testing::nbSamples_t nb,float64_t * data)1020 void Semihosting::DumpPattern_f64(Testing::outputID_t id,Testing::nbSamples_t nb, float64_t* data) 1021 { 1022 std::string fileName = this->getOutputPath(id); 1023 if (data) 1024 { 1025 FILE *f = fopen(fileName.c_str(),"w"); 1026 Testing::nbSamples_t i=0; 1027 uint64_t t; 1028 float64_t v; 1029 for(i=0; i < nb; i++) 1030 { 1031 v = data[i]; 1032 t = TOINT64(v); 1033 fprintf(f,"0x%016llx\n",t); 1034 } 1035 fclose(f); 1036 } 1037 1038 } DumpPattern_f32(Testing::outputID_t id,Testing::nbSamples_t nb,float32_t * data)1039 void Semihosting::DumpPattern_f32(Testing::outputID_t id,Testing::nbSamples_t nb, float32_t* data) 1040 { 1041 std::string fileName = this->getOutputPath(id); 1042 if (data) 1043 { 1044 FILE *f = fopen(fileName.c_str(),"w"); 1045 Testing::nbSamples_t i=0; 1046 uint32_t t; 1047 float32_t v; 1048 for(i=0; i < nb; i++) 1049 { 1050 v = data[i]; 1051 t = TOINT32(v); 1052 fprintf(f,"0x%08x\n",t); 1053 } 1054 fclose(f); 1055 } 1056 } 1057 1058 #if !defined( __CC_ARM ) && defined(ARM_FLOAT16_SUPPORTED) DumpPattern_f16(Testing::outputID_t id,Testing::nbSamples_t nb,float16_t * data)1059 void Semihosting::DumpPattern_f16(Testing::outputID_t id,Testing::nbSamples_t nb, float16_t* data) 1060 { 1061 std::string fileName = this->getOutputPath(id); 1062 if (data) 1063 { 1064 FILE *f = fopen(fileName.c_str(),"w"); 1065 Testing::nbSamples_t i=0; 1066 uint16_t t; 1067 float16_t v; 1068 for(i=0; i < nb; i++) 1069 { 1070 v = data[i]; 1071 t = TOINT16(v); 1072 fprintf(f,"0x0000%04x\n",t); 1073 } 1074 fclose(f); 1075 } 1076 } 1077 #endif 1078 DumpPattern_q63(Testing::outputID_t id,Testing::nbSamples_t nb,q63_t * data)1079 void Semihosting::DumpPattern_q63(Testing::outputID_t id,Testing::nbSamples_t nb, q63_t* data) 1080 { 1081 std::string fileName = this->getOutputPath(id); 1082 if (data) 1083 { 1084 FILE *f = fopen(fileName.c_str(),"w"); 1085 Testing::nbSamples_t i=0; 1086 uint64_t t; 1087 for(i=0; i < nb; i++) 1088 { 1089 t = (uint64_t)data[i]; 1090 fprintf(f,"0x%016llx\n",t); 1091 } 1092 fclose(f); 1093 } 1094 } 1095 DumpPattern_q31(Testing::outputID_t id,Testing::nbSamples_t nb,q31_t * data)1096 void Semihosting::DumpPattern_q31(Testing::outputID_t id,Testing::nbSamples_t nb, q31_t* data) 1097 { 1098 std::string fileName = this->getOutputPath(id); 1099 if (data) 1100 { 1101 FILE *f = fopen(fileName.c_str(),"w"); 1102 Testing::nbSamples_t i=0; 1103 uint32_t t; 1104 for(i=0; i < nb; i++) 1105 { 1106 t = (uint32_t)data[i]; 1107 fprintf(f,"0x%08x\n",t); 1108 } 1109 fclose(f); 1110 } 1111 } DumpPattern_q15(Testing::outputID_t id,Testing::nbSamples_t nb,q15_t * data)1112 void Semihosting::DumpPattern_q15(Testing::outputID_t id,Testing::nbSamples_t nb, q15_t* data) 1113 { 1114 std::string fileName = this->getOutputPath(id); 1115 if (data) 1116 { 1117 FILE *f = fopen(fileName.c_str(),"w"); 1118 Testing::nbSamples_t i=0; 1119 uint32_t t; 1120 for(i=0; i < nb; i++) 1121 { 1122 t = (uint32_t)data[i]; 1123 fprintf(f,"0x%08x\n",t); 1124 } 1125 fclose(f); 1126 } 1127 } DumpPattern_q7(Testing::outputID_t id,Testing::nbSamples_t nb,q7_t * data)1128 void Semihosting::DumpPattern_q7(Testing::outputID_t id,Testing::nbSamples_t nb, q7_t* data) 1129 { 1130 std::string fileName = this->getOutputPath(id); 1131 if (data) 1132 { 1133 FILE *f = fopen(fileName.c_str(),"w"); 1134 Testing::nbSamples_t i=0; 1135 uint32_t t; 1136 for(i=0; i < nb; i++) 1137 { 1138 t = (uint32_t)data[i]; 1139 fprintf(f,"0x%08x\n",t); 1140 } 1141 fclose(f); 1142 } 1143 } 1144 DumpPattern_u64(Testing::outputID_t id,Testing::nbSamples_t nb,uint64_t * data)1145 void Semihosting::DumpPattern_u64(Testing::outputID_t id,Testing::nbSamples_t nb, uint64_t* data) 1146 { 1147 std::string fileName = this->getOutputPath(id); 1148 if (data) 1149 { 1150 FILE *f = fopen(fileName.c_str(),"w"); 1151 Testing::nbSamples_t i=0; 1152 uint64_t t; 1153 for(i=0; i < nb; i++) 1154 { 1155 t = (uint64_t)data[i]; 1156 fprintf(f,"0x%016llx\n",t); 1157 } 1158 fclose(f); 1159 } 1160 } 1161 DumpPattern_u32(Testing::outputID_t id,Testing::nbSamples_t nb,uint32_t * data)1162 void Semihosting::DumpPattern_u32(Testing::outputID_t id,Testing::nbSamples_t nb, uint32_t* data) 1163 { 1164 std::string fileName = this->getOutputPath(id); 1165 if (data) 1166 { 1167 FILE *f = fopen(fileName.c_str(),"w"); 1168 Testing::nbSamples_t i=0; 1169 uint32_t t; 1170 for(i=0; i < nb; i++) 1171 { 1172 t = (uint32_t)data[i]; 1173 fprintf(f,"0x%08x\n",t); 1174 } 1175 fclose(f); 1176 } 1177 } DumpPattern_u16(Testing::outputID_t id,Testing::nbSamples_t nb,uint16_t * data)1178 void Semihosting::DumpPattern_u16(Testing::outputID_t id,Testing::nbSamples_t nb, uint16_t* data) 1179 { 1180 std::string fileName = this->getOutputPath(id); 1181 if (data) 1182 { 1183 FILE *f = fopen(fileName.c_str(),"w"); 1184 Testing::nbSamples_t i=0; 1185 uint32_t t; 1186 for(i=0; i < nb; i++) 1187 { 1188 t = (uint32_t)data[i]; 1189 fprintf(f,"0x%08x\n",t); 1190 } 1191 fclose(f); 1192 } 1193 } DumpPattern_u8(Testing::outputID_t id,Testing::nbSamples_t nb,uint8_t * data)1194 void Semihosting::DumpPattern_u8(Testing::outputID_t id,Testing::nbSamples_t nb, uint8_t* data) 1195 { 1196 std::string fileName = this->getOutputPath(id); 1197 if (data) 1198 { 1199 FILE *f = fopen(fileName.c_str(),"w"); 1200 Testing::nbSamples_t i=0; 1201 uint32_t t; 1202 for(i=0; i < nb; i++) 1203 { 1204 t = (uint32_t)data[i]; 1205 fprintf(f,"0x%08x\n",t); 1206 } 1207 fclose(f); 1208 } 1209 } 1210 1211 1212 1213 1214 } 1215