Semihosting.cpp 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092
  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. #include <string>
  33. #include <cstddef>
  34. #include <stdio.h>
  35. #include <string.h>
  36. #include <stdlib.h>
  37. #include "Generators.h"
  38. #include "Semihosting.h"
  39. namespace Client
  40. {
  41. struct pathOrGen {
  42. int kind;
  43. std::string path;
  44. Testing::param_t *data;
  45. Testing::nbSamples_t nbInputSamples;
  46. Testing::nbSamples_t nbOutputSamples;
  47. int dimensions;
  48. };
  49. Semihosting::Semihosting(std::string path,std::string patternRootPath,std::string outputRootPath,std::string parameterRootPath)
  50. {
  51. // Open the driver file
  52. this->infile=fopen(path.c_str(), "r");
  53. this->path=new std::vector<std::string>();
  54. this->patternRootPath=patternRootPath;
  55. this->outputRootPath=outputRootPath;
  56. this->parameterRootPath=parameterRootPath;
  57. this->patternFilenames=new std::vector<std::string>();
  58. this->outputNames=new std::vector<std::string>();
  59. this->parameterNames=new std::vector<struct pathOrGen>();
  60. this->m_hasParam = false;
  61. }
  62. void Semihosting::DeleteParams()
  63. {
  64. for (std::vector<struct pathOrGen>::iterator it = this->parameterNames->begin() ; it != this->parameterNames->end(); ++it)
  65. {
  66. if (it->kind==1)
  67. {
  68. if (it->data)
  69. {
  70. free(it->data);
  71. it->data = NULL;
  72. }
  73. }
  74. }
  75. }
  76. Semihosting::~Semihosting()
  77. {
  78. fclose(this->infile);
  79. delete(this->path);
  80. delete(this->patternFilenames);
  81. delete(this->outputNames);
  82. this->DeleteParams();
  83. delete(this->parameterNames);
  84. }
  85. /**
  86. Read the list of patterns from the driver file.
  87. This list is for the current suite.
  88. */
  89. void Semihosting::ReadPatternList()
  90. {
  91. char tmp[256];
  92. int nbPatterns;
  93. fscanf(this->infile,"%d\n",&nbPatterns);
  94. // Reset the list for the current suite
  95. this->patternFilenames->clear();
  96. std::string tmpstr;
  97. for(int i=0;i<nbPatterns;i++)
  98. {
  99. fgets(tmp,256,this->infile);
  100. // Remove end of line
  101. if (tmp[strlen(tmp)-1] == '\n')
  102. {
  103. tmp[strlen(tmp)-1]=0;
  104. }
  105. tmpstr.assign(tmp);
  106. this->patternFilenames->push_back(tmpstr);
  107. }
  108. }
  109. /**
  110. Read the list of parameters from the driver file.
  111. This list is for the current suite.
  112. */
  113. void Semihosting::ReadParameterList(Testing::nbParameters_t nbParams)
  114. {
  115. char tmp[256];
  116. char paramKind;
  117. std::string tmpstr;
  118. // It is the number of samples in the file.
  119. // Not the number of parameters controlling the function
  120. int nbValues;
  121. fscanf(this->infile,"%d\n",&nbValues);
  122. // Reset the list for the current suite
  123. this->DeleteParams();
  124. this->parameterNames->clear();
  125. for(int i=0;i<nbValues;i++)
  126. {
  127. fscanf(this->infile,"%c\n",&paramKind);
  128. struct pathOrGen gen;
  129. if (paramKind == 'p')
  130. {
  131. fgets(tmp,256,this->infile);
  132. // Remove end of line
  133. if (tmp[strlen(tmp)-1] == '\n')
  134. {
  135. tmp[strlen(tmp)-1]=0;
  136. }
  137. tmpstr.assign(tmp);
  138. std::string tmp;
  139. tmp += this->parameterRootPath;
  140. tmp += this->testDir;
  141. tmp += "/";
  142. tmp += tmpstr;
  143. gen.kind=0;
  144. gen.path=tmp;
  145. gen.nbInputSamples = this->GetFileSize(tmp);
  146. gen.dimensions = nbParams;
  147. }
  148. // Generator
  149. // Generator kind (only 1 = cartesian product generator)
  150. // Number of samples generated when run
  151. // Number of dimensions
  152. // For each dimension
  153. // Length
  154. // Samples
  155. else
  156. {
  157. int kind,nbInputSamples,nbOutputSamples,dimensions,sample;
  158. Testing::param_t *p,*current;
  159. // Generator kind. Not yet used since there is only one kind of generator
  160. fscanf(this->infile,"%d\n",&kind);
  161. // Input data in config file
  162. fscanf(this->infile,"%d\n",&nbInputSamples);
  163. // Number of output combinations
  164. // And each output has dimensions parameters
  165. fscanf(this->infile,"%d\n",&nbOutputSamples);
  166. fscanf(this->infile,"%d\n",&dimensions);
  167. p=(Testing::param_t*)malloc(sizeof(Testing::param_t)*(nbInputSamples));
  168. current=p;
  169. for(int i=0;i < nbInputSamples; i ++)
  170. {
  171. fscanf(this->infile,"%d\n",&sample);
  172. *current++ = (Testing::param_t)sample;
  173. }
  174. gen.kind=1;
  175. gen.data=p;
  176. gen.nbInputSamples = nbInputSamples;
  177. gen.nbOutputSamples = nbOutputSamples;
  178. gen.dimensions = dimensions;
  179. }
  180. this->parameterNames->push_back(gen);
  181. }
  182. }
  183. /**
  184. Read the list of output from the driver file.
  185. This list is for the current suite.
  186. */
  187. void Semihosting::ReadOutputList()
  188. {
  189. char tmp[256];
  190. int nbOutputs;
  191. fscanf(this->infile,"%d\n",&nbOutputs);
  192. // Reset the list for the current suite
  193. this->outputNames->clear();
  194. std::string tmpstr;
  195. for(int i=0;i<nbOutputs;i++)
  196. {
  197. fgets(tmp,256,this->infile);
  198. // Remove end of line
  199. if (tmp[strlen(tmp)-1] == '\n')
  200. {
  201. tmp[strlen(tmp)-1]=0;
  202. }
  203. tmpstr.assign(tmp);
  204. this->outputNames->push_back(tmpstr);
  205. }
  206. }
  207. /** Read the number of parameters for all the tests in a suite
  208. Used for benchmarking. Same functions executed with
  209. different initializations controlled by the parameters.
  210. It is not the number of parameters in a file
  211. but the number of arguments (parameters) to control a function.
  212. */
  213. Testing::nbParameters_t Semihosting::ReadNbParameters()
  214. {
  215. unsigned long nb;
  216. fscanf(this->infile,"%ld\n",&nb);
  217. return(nb);
  218. }
  219. void Semihosting::recomputeTestDir()
  220. {
  221. this->testDir = ".";
  222. int start = 1;
  223. std::vector<std::string>::const_iterator iter;
  224. for (iter = this->path->begin(); iter != this->path->end(); ++iter)
  225. {
  226. if (start)
  227. {
  228. this->testDir = *iter;
  229. start =0;
  230. }
  231. else
  232. {
  233. if (!(*iter).empty())
  234. {
  235. this->testDir += "/" + *iter;
  236. }
  237. }
  238. }
  239. }
  240. void Semihosting::ReadTestIdentification()
  241. {
  242. char tmp[255];
  243. int kind;
  244. Testing::testID_t theId;
  245. char hasPath;
  246. char hasParamID;
  247. Testing::PatternID_t paramID;
  248. fscanf(this->infile,"%d %ld\n",&kind,&theId);
  249. fscanf(this->infile,"%c\n",&hasParamID);
  250. this->m_hasParam=false;
  251. if (hasParamID == 'y')
  252. {
  253. this->m_hasParam=true;
  254. fscanf(this->infile,"%ld\n",&paramID);
  255. this->currentParam=paramID;
  256. }
  257. fscanf(this->infile,"%c\n",&hasPath);
  258. if (hasPath == 'y')
  259. {
  260. fgets(tmp,256,this->infile);
  261. // Remove end of line
  262. if (tmp[strlen(tmp)-1] == '\n')
  263. {
  264. tmp[strlen(tmp)-1]=0;
  265. }
  266. currentPath.assign(tmp);
  267. }
  268. this->currentKind=kind;
  269. this->currentId=theId;
  270. switch(kind)
  271. {
  272. case 1:
  273. printf("t \n");
  274. break;
  275. case 2:
  276. printf("s %ld\n",this->currentId);
  277. break;
  278. case 3:
  279. printf("g %ld\n",this->currentId);
  280. break;
  281. default:
  282. printf("u\n");
  283. }
  284. }
  285. Testing::testID_t Semihosting::CurrentTestID()
  286. {
  287. return(this->currentId);
  288. }
  289. /**
  290. Read identification of a group or suite.
  291. The difference with a test node is that the current folder
  292. can be changed by a group or suite.
  293. */
  294. void Semihosting::ReadIdentification()
  295. {
  296. this->ReadTestIdentification();
  297. this->path->push_back(currentPath);
  298. this->recomputeTestDir();
  299. }
  300. /**
  301. Dump the test status into the output (stdout)
  302. */
  303. void Semihosting::DispStatus(Testing::TestStatus status
  304. ,Testing::errorID_t error
  305. ,unsigned long lineNb
  306. ,Testing::cycles_t cycles)
  307. {
  308. if (status == Testing::kTestFailed)
  309. {
  310. printf("%ld %ld %ld 0 N\n",this->currentId,error,lineNb);
  311. }
  312. else
  313. {
  314. #ifdef EXTBENCH
  315. printf("%ld 0 0 t Y\n",this->currentId);
  316. #else
  317. printf("%ld 0 0 %u Y\n",this->currentId,cycles);
  318. #endif
  319. }
  320. }
  321. void Semihosting::DispErrorDetails(const char* details)
  322. {
  323. printf("E: %s\n",details);
  324. }
  325. /**
  326. Signal end of group
  327. (Used by scripts parsing the output to display the results)
  328. */
  329. void Semihosting::EndGroup()
  330. {
  331. printf("p\n");
  332. this->path->pop_back();
  333. }
  334. /**
  335. Get pattern path.
  336. */
  337. std::string Semihosting::getPatternPath(Testing::PatternID_t id)
  338. {
  339. std::string tmp;
  340. tmp += this->patternRootPath;
  341. tmp += this->testDir;
  342. tmp += "/";
  343. tmp += (*this->patternFilenames)[id];
  344. return(tmp);
  345. }
  346. /**
  347. Get parameter path.
  348. */
  349. struct pathOrGen Semihosting::getParameterDesc(Testing::PatternID_t id)
  350. {
  351. return((*this->parameterNames)[id]);
  352. }
  353. /**
  354. Get output path.
  355. The test ID (currentId) is used in the name
  356. */
  357. std::string Semihosting::getOutputPath(Testing::outputID_t id)
  358. {
  359. char fmt[256];
  360. std::string tmp;
  361. tmp += this->outputRootPath;
  362. tmp += this->testDir;
  363. sprintf(fmt,"/%s_%ld.txt",(*this->outputNames)[id].c_str(),this->currentId);
  364. tmp += std::string(fmt);
  365. //printf("%s\n",tmp.c_str());
  366. return(tmp);
  367. }
  368. Testing::nbSamples_t Semihosting::GetPatternSize(Testing::PatternID_t id)
  369. {
  370. char tmp[256];
  371. Testing::nbSamples_t len;
  372. std::string fileName = this->getPatternPath(id);
  373. FILE *pattern=fopen(fileName.c_str(), "r");
  374. if (pattern==NULL)
  375. {
  376. return(0);
  377. }
  378. // Ignore word size format
  379. fgets(tmp,256,pattern);
  380. // Get nb of samples
  381. fgets(tmp,256,pattern);
  382. fclose(pattern);
  383. len=atoi(tmp);
  384. return(len);
  385. }
  386. Testing::nbSamples_t Semihosting::GetFileSize(std::string &filepath)
  387. {
  388. char tmp[256];
  389. Testing::nbSamples_t len;
  390. FILE *params=fopen(filepath.c_str(), "r");
  391. if (params==NULL)
  392. {
  393. return(0);
  394. }
  395. // Get nb of samples
  396. fgets(tmp,256,params);
  397. fclose(params);
  398. len=atoi(tmp);
  399. return(len);
  400. }
  401. void Semihosting::DumpParams(std::vector<Testing::param_t>& params)
  402. {
  403. bool begin=true;
  404. printf("b ");
  405. for(std::vector<Testing::param_t>::iterator it = params.begin(); it != params.end(); ++it)
  406. {
  407. if (!begin)
  408. {
  409. printf(",");
  410. }
  411. printf("%d",*it);
  412. begin=false;
  413. }
  414. printf("\n");
  415. }
  416. Testing::param_t* Semihosting::ImportParams(Testing::PatternID_t id,Testing::nbParameterEntries_t &nbEntries,Testing::ParameterKind &paramKind)
  417. {
  418. nbEntries = 0;
  419. char tmp[256];
  420. Testing::param_t *p;
  421. uint32_t val;
  422. Testing::nbSamples_t len;
  423. struct pathOrGen gen = this->getParameterDesc(id);
  424. if (gen.kind == 0)
  425. {
  426. char *result=NULL;
  427. paramKind=Testing::kDynamicBuffer;
  428. FILE *params=fopen(gen.path.c_str(), "r");
  429. if (params==NULL)
  430. {
  431. return(NULL);
  432. }
  433. // Get nb of samples
  434. fgets(tmp,256,params);
  435. len=gen.nbInputSamples;
  436. result=(char*)malloc(len*sizeof(Testing::param_t));
  437. p = (Testing::param_t*)result;
  438. nbEntries = len / gen.dimensions;
  439. for(uint32_t i=0; i < len; i++)
  440. {
  441. fscanf(params,"%d\n",&val);
  442. *p++ = val;
  443. }
  444. fclose(params);
  445. return((Testing::param_t*)result);
  446. }
  447. else
  448. {
  449. Testing::param_t* result;
  450. paramKind=Testing::kDynamicBuffer;
  451. // Output samples is number of parameter line
  452. len=gen.nbOutputSamples * gen.dimensions;
  453. result=(Testing::param_t*)malloc(len*sizeof(Testing::param_t));
  454. switch(gen.dimensions)
  455. {
  456. case 1:
  457. generate1(result,gen.data,nbEntries);
  458. break;
  459. case 2:
  460. generate2(result,gen.data,nbEntries);
  461. break;
  462. case 3:
  463. generate3(result,gen.data,nbEntries);
  464. break;
  465. case 4:
  466. generate4(result,gen.data,nbEntries);
  467. break;
  468. default:
  469. generate1(result,gen.data,nbEntries);
  470. break;
  471. }
  472. return(result);
  473. }
  474. }
  475. bool Semihosting::hasParam()
  476. {
  477. return(this->m_hasParam);
  478. }
  479. Testing::PatternID_t Semihosting::getParamID()
  480. {
  481. return(this->currentParam);
  482. }
  483. void Semihosting::ImportPattern_f64(Testing::PatternID_t id,char* p,Testing::nbSamples_t nb)
  484. {
  485. char tmp[256];
  486. Testing::nbSamples_t len;
  487. Testing::nbSamples_t i=0;
  488. uint64_t val;
  489. float64_t *ptr=(float64_t*)p;
  490. std::string fileName = this->getPatternPath(id);
  491. FILE *pattern=fopen(fileName.c_str(), "r");
  492. // Ignore word size format
  493. // word size format is used when generating include files with python scripts
  494. fgets(tmp,256,pattern);
  495. // Get nb of samples
  496. fgets(tmp,256,pattern);
  497. len=atoi(tmp);
  498. if ((nb != MAX_NB_SAMPLES) && (nb < len))
  499. {
  500. len = nb;
  501. }
  502. if (ptr)
  503. {
  504. for(i=0;i<len;i++)
  505. {
  506. // Ignore comment
  507. fgets(tmp,256,pattern);
  508. fscanf(pattern,"0x%16llx\n",&val);
  509. *ptr = TOTYP(float64_t,val);
  510. ptr++;
  511. }
  512. }
  513. fclose(pattern);
  514. }
  515. void Semihosting::ImportPattern_f32(Testing::PatternID_t id,char* p,Testing::nbSamples_t nb)
  516. {
  517. char tmp[256];
  518. Testing::nbSamples_t len;
  519. Testing::nbSamples_t i=0;
  520. uint32_t val;
  521. float32_t *ptr=(float32_t*)p;
  522. std::string fileName = this->getPatternPath(id);
  523. FILE *pattern=fopen(fileName.c_str(), "r");
  524. // Ignore word size format
  525. fgets(tmp,256,pattern);
  526. // Get nb of samples
  527. fgets(tmp,256,pattern);
  528. len=atoi(tmp);
  529. if ((nb != MAX_NB_SAMPLES) && (nb < len))
  530. {
  531. len = nb;
  532. }
  533. //printf(":::: %s\n",fileName.c_str());
  534. if (ptr)
  535. {
  536. for(i=0;i<len;i++)
  537. {
  538. // Ignore comment
  539. fgets(tmp,256,pattern);
  540. fscanf(pattern,"0x%08X\n",&val);
  541. //printf(":::: %08X %f\n",val, TOTYP(float32_t,val));
  542. *ptr = TOTYP(float32_t,val);
  543. ptr++;
  544. }
  545. }
  546. fclose(pattern);
  547. }
  548. void Semihosting::ImportPattern_q63(Testing::PatternID_t id,char* p,Testing::nbSamples_t nb)
  549. {
  550. char tmp[256];
  551. Testing::nbSamples_t len;
  552. Testing::nbSamples_t i=0;
  553. uint64_t val;
  554. q63_t *ptr=(q63_t*)p;
  555. std::string fileName = this->getPatternPath(id);
  556. FILE *pattern=fopen(fileName.c_str(), "r");
  557. // Ignore word size format
  558. fgets(tmp,256,pattern);
  559. // Get nb of samples
  560. fgets(tmp,256,pattern);
  561. len=atoi(tmp);
  562. if ((nb != MAX_NB_SAMPLES) && (nb < len))
  563. {
  564. len = nb;
  565. }
  566. if (ptr)
  567. {
  568. for(i=0;i<len;i++)
  569. {
  570. // Ignore comment
  571. fgets(tmp,256,pattern);
  572. fscanf(pattern,"0x%016llX\n",&val);
  573. *ptr = TOTYP(q63_t,val);
  574. ptr++;
  575. }
  576. }
  577. fclose(pattern);
  578. }
  579. void Semihosting::ImportPattern_q31(Testing::PatternID_t id,char* p,Testing::nbSamples_t nb)
  580. {
  581. char tmp[256];
  582. Testing::nbSamples_t len;
  583. Testing::nbSamples_t i=0;
  584. uint32_t val;
  585. q31_t *ptr=(q31_t*)p;
  586. std::string fileName = this->getPatternPath(id);
  587. FILE *pattern=fopen(fileName.c_str(), "r");
  588. // Ignore word size format
  589. fgets(tmp,256,pattern);
  590. // Get nb of samples
  591. fgets(tmp,256,pattern);
  592. len=atoi(tmp);
  593. if ((nb != MAX_NB_SAMPLES) && (nb < len))
  594. {
  595. len = nb;
  596. }
  597. if (ptr)
  598. {
  599. for(i=0;i<len;i++)
  600. {
  601. // Ignore comment
  602. fgets(tmp,256,pattern);
  603. fscanf(pattern,"0x%08X\n",&val);
  604. *ptr = TOTYP(q31_t,val);
  605. ptr++;
  606. }
  607. }
  608. fclose(pattern);
  609. }
  610. void Semihosting::ImportPattern_q15(Testing::PatternID_t id,char* p,Testing::nbSamples_t nb)
  611. {
  612. char tmp[256];
  613. Testing::nbSamples_t len;
  614. Testing::nbSamples_t i=0;
  615. uint32_t val;
  616. q15_t *ptr=(q15_t*)p;
  617. std::string fileName = this->getPatternPath(id);
  618. FILE *pattern=fopen(fileName.c_str(), "r");
  619. // Ignore word size format
  620. fgets(tmp,256,pattern);
  621. // Get nb of samples
  622. fgets(tmp,256,pattern);
  623. len=atoi(tmp);
  624. if ((nb != MAX_NB_SAMPLES) && (nb < len))
  625. {
  626. len = nb;
  627. }
  628. if (ptr)
  629. {
  630. for(i=0;i<len;i++)
  631. {
  632. // Ignore comment
  633. fgets(tmp,256,pattern);
  634. fscanf(pattern,"0x%08X\n",&val);
  635. *ptr = TOTYP(q15_t,val);
  636. ptr++;
  637. }
  638. }
  639. fclose(pattern);
  640. }
  641. void Semihosting::ImportPattern_q7(Testing::PatternID_t id,char* p,Testing::nbSamples_t nb)
  642. {
  643. char tmp[256];
  644. Testing::nbSamples_t len;
  645. Testing::nbSamples_t i=0;
  646. uint32_t val;
  647. q7_t *ptr=(q7_t*)p;
  648. std::string fileName = this->getPatternPath(id);
  649. FILE *pattern=fopen(fileName.c_str(), "r");
  650. // Ignore word size format
  651. fgets(tmp,256,pattern);
  652. // Get nb of samples
  653. fgets(tmp,256,pattern);
  654. len=atoi(tmp);
  655. if ((nb != MAX_NB_SAMPLES) && (nb < len))
  656. {
  657. len = nb;
  658. }
  659. if (ptr)
  660. {
  661. for(i=0;i<len;i++)
  662. {
  663. // Ignore comment
  664. fgets(tmp,256,pattern);
  665. fscanf(pattern,"0x%08X\n",&val);
  666. *ptr = TOTYP(q7_t,val);
  667. ptr++;
  668. }
  669. }
  670. fclose(pattern);
  671. }
  672. void Semihosting::ImportPattern_u32(Testing::PatternID_t id,char* p,Testing::nbSamples_t nb)
  673. {
  674. char tmp[256];
  675. Testing::nbSamples_t len;
  676. Testing::nbSamples_t i=0;
  677. uint32_t val;
  678. uint32_t *ptr=(uint32_t*)p;
  679. std::string fileName = this->getPatternPath(id);
  680. FILE *pattern=fopen(fileName.c_str(), "r");
  681. // Ignore word size format
  682. fgets(tmp,256,pattern);
  683. // Get nb of samples
  684. fgets(tmp,256,pattern);
  685. len=atoi(tmp);
  686. if ((nb != MAX_NB_SAMPLES) && (nb < len))
  687. {
  688. len = nb;
  689. }
  690. if (ptr)
  691. {
  692. for(i=0;i<len;i++)
  693. {
  694. // Ignore comment
  695. fgets(tmp,256,pattern);
  696. fscanf(pattern,"0x%08X\n",&val);
  697. *ptr = val;
  698. ptr++;
  699. }
  700. }
  701. fclose(pattern);
  702. }
  703. void Semihosting::ImportPattern_u16(Testing::PatternID_t id,char* p,Testing::nbSamples_t nb)
  704. {
  705. char tmp[256];
  706. Testing::nbSamples_t len;
  707. Testing::nbSamples_t i=0;
  708. uint32_t val;
  709. uint16_t *ptr=(uint16_t*)p;
  710. std::string fileName = this->getPatternPath(id);
  711. FILE *pattern=fopen(fileName.c_str(), "r");
  712. // Ignore word size format
  713. fgets(tmp,256,pattern);
  714. // Get nb of samples
  715. fgets(tmp,256,pattern);
  716. len=atoi(tmp);
  717. if ((nb != MAX_NB_SAMPLES) && (nb < len))
  718. {
  719. len = nb;
  720. }
  721. if (ptr)
  722. {
  723. for(i=0;i<len;i++)
  724. {
  725. // Ignore comment
  726. fgets(tmp,256,pattern);
  727. fscanf(pattern,"0x%08X\n",&val);
  728. *ptr = (uint16_t)val;
  729. ptr++;
  730. }
  731. }
  732. fclose(pattern);
  733. }
  734. void Semihosting::ImportPattern_u8(Testing::PatternID_t id,char* p,Testing::nbSamples_t nb)
  735. {
  736. char tmp[256];
  737. Testing::nbSamples_t len;
  738. Testing::nbSamples_t i=0;
  739. uint32_t val;
  740. uint8_t *ptr=(uint8_t*)p;
  741. std::string fileName = this->getPatternPath(id);
  742. FILE *pattern=fopen(fileName.c_str(), "r");
  743. // Ignore word size format
  744. fgets(tmp,256,pattern);
  745. // Get nb of samples
  746. fgets(tmp,256,pattern);
  747. len=atoi(tmp);
  748. if ((nb != MAX_NB_SAMPLES) && (nb < len))
  749. {
  750. len = nb;
  751. }
  752. if (ptr)
  753. {
  754. for(i=0;i<len;i++)
  755. {
  756. // Ignore comment
  757. fgets(tmp,256,pattern);
  758. fscanf(pattern,"0x%08X\n",&val);
  759. *ptr = (uint8_t)val;
  760. ptr++;
  761. }
  762. }
  763. fclose(pattern);
  764. }
  765. void Semihosting::DumpPattern_f64(Testing::outputID_t id,Testing::nbSamples_t nb, float64_t* data)
  766. {
  767. std::string fileName = this->getOutputPath(id);
  768. if (data)
  769. {
  770. FILE *f = fopen(fileName.c_str(),"w");
  771. Testing::nbSamples_t i=0;
  772. uint64_t t;
  773. float64_t v;
  774. for(i=0; i < nb; i++)
  775. {
  776. v = data[i];
  777. t = TOINT64(v);
  778. fprintf(f,"0x%016llx\n",t);
  779. }
  780. fclose(f);
  781. }
  782. }
  783. void Semihosting::DumpPattern_f32(Testing::outputID_t id,Testing::nbSamples_t nb, float32_t* data)
  784. {
  785. std::string fileName = this->getOutputPath(id);
  786. if (data)
  787. {
  788. FILE *f = fopen(fileName.c_str(),"w");
  789. Testing::nbSamples_t i=0;
  790. uint32_t t;
  791. float32_t v;
  792. for(i=0; i < nb; i++)
  793. {
  794. v = data[i];
  795. t = TOINT32(v);
  796. fprintf(f,"0x%08x\n",t);
  797. }
  798. fclose(f);
  799. }
  800. }
  801. void Semihosting::DumpPattern_q63(Testing::outputID_t id,Testing::nbSamples_t nb, q63_t* data)
  802. {
  803. std::string fileName = this->getOutputPath(id);
  804. if (data)
  805. {
  806. FILE *f = fopen(fileName.c_str(),"w");
  807. Testing::nbSamples_t i=0;
  808. uint64_t t;
  809. for(i=0; i < nb; i++)
  810. {
  811. t = (uint64_t)data[i];
  812. fprintf(f,"0x%016llx\n",t);
  813. }
  814. fclose(f);
  815. }
  816. }
  817. void Semihosting::DumpPattern_q31(Testing::outputID_t id,Testing::nbSamples_t nb, q31_t* data)
  818. {
  819. std::string fileName = this->getOutputPath(id);
  820. if (data)
  821. {
  822. FILE *f = fopen(fileName.c_str(),"w");
  823. Testing::nbSamples_t i=0;
  824. uint32_t t;
  825. for(i=0; i < nb; i++)
  826. {
  827. t = (uint32_t)data[i];
  828. fprintf(f,"0x%08x\n",t);
  829. }
  830. fclose(f);
  831. }
  832. }
  833. void Semihosting::DumpPattern_q15(Testing::outputID_t id,Testing::nbSamples_t nb, q15_t* data)
  834. {
  835. std::string fileName = this->getOutputPath(id);
  836. if (data)
  837. {
  838. FILE *f = fopen(fileName.c_str(),"w");
  839. Testing::nbSamples_t i=0;
  840. uint32_t t;
  841. for(i=0; i < nb; i++)
  842. {
  843. t = (uint32_t)data[i];
  844. fprintf(f,"0x%08x\n",t);
  845. }
  846. fclose(f);
  847. }
  848. }
  849. void Semihosting::DumpPattern_q7(Testing::outputID_t id,Testing::nbSamples_t nb, q7_t* data)
  850. {
  851. std::string fileName = this->getOutputPath(id);
  852. if (data)
  853. {
  854. FILE *f = fopen(fileName.c_str(),"w");
  855. Testing::nbSamples_t i=0;
  856. uint32_t t;
  857. for(i=0; i < nb; i++)
  858. {
  859. t = (uint32_t)data[i];
  860. fprintf(f,"0x%08x\n",t);
  861. }
  862. fclose(f);
  863. }
  864. }
  865. void Semihosting::DumpPattern_u32(Testing::outputID_t id,Testing::nbSamples_t nb, uint32_t* data)
  866. {
  867. std::string fileName = this->getOutputPath(id);
  868. if (data)
  869. {
  870. FILE *f = fopen(fileName.c_str(),"w");
  871. Testing::nbSamples_t i=0;
  872. uint32_t t;
  873. for(i=0; i < nb; i++)
  874. {
  875. t = (uint32_t)data[i];
  876. fprintf(f,"0x%08x\n",t);
  877. }
  878. fclose(f);
  879. }
  880. }
  881. void Semihosting::DumpPattern_u16(Testing::outputID_t id,Testing::nbSamples_t nb, uint16_t* data)
  882. {
  883. std::string fileName = this->getOutputPath(id);
  884. if (data)
  885. {
  886. FILE *f = fopen(fileName.c_str(),"w");
  887. Testing::nbSamples_t i=0;
  888. uint32_t t;
  889. for(i=0; i < nb; i++)
  890. {
  891. t = (uint32_t)data[i];
  892. fprintf(f,"0x%08x\n",t);
  893. }
  894. fclose(f);
  895. }
  896. }
  897. void Semihosting::DumpPattern_u8(Testing::outputID_t id,Testing::nbSamples_t nb, uint8_t* data)
  898. {
  899. std::string fileName = this->getOutputPath(id);
  900. if (data)
  901. {
  902. FILE *f = fopen(fileName.c_str(),"w");
  903. Testing::nbSamples_t i=0;
  904. uint32_t t;
  905. for(i=0; i < nb; i++)
  906. {
  907. t = (uint32_t)data[i];
  908. fprintf(f,"0x%08x\n",t);
  909. }
  910. fclose(f);
  911. }
  912. }
  913. }