Semihosting.cpp 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975
  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 "Semihosting.h"
  35. #include <stdio.h>
  36. #include <string.h>
  37. #include "Generators.h"
  38. namespace Client
  39. {
  40. struct pathOrGen {
  41. int kind;
  42. std::string path;
  43. Testing::param_t *data;
  44. Testing::nbSamples_t nbInputSamples;
  45. Testing::nbSamples_t nbOutputSamples;
  46. int dimensions;
  47. };
  48. Semihosting::Semihosting(std::string path,std::string patternRootPath,std::string outputRootPath,std::string parameterRootPath)
  49. {
  50. // Open the driver file
  51. this->infile=fopen(path.c_str(), "r");
  52. this->path=new std::vector<std::string>();
  53. this->patternRootPath=patternRootPath;
  54. this->outputRootPath=outputRootPath;
  55. this->parameterRootPath=parameterRootPath;
  56. this->patternFilenames=new std::vector<std::string>();
  57. this->outputNames=new std::vector<std::string>();
  58. this->parameterNames=new std::vector<struct pathOrGen>();
  59. this->m_hasParam = false;
  60. }
  61. void Semihosting::DeleteParams()
  62. {
  63. for (std::vector<struct pathOrGen>::iterator it = this->parameterNames->begin() ; it != this->parameterNames->end(); ++it)
  64. {
  65. if (it->kind==1)
  66. {
  67. if (it->data)
  68. {
  69. free(it->data);
  70. it->data = NULL;
  71. }
  72. }
  73. }
  74. }
  75. Semihosting::~Semihosting()
  76. {
  77. fclose(this->infile);
  78. delete(this->path);
  79. delete(this->patternFilenames);
  80. delete(this->outputNames);
  81. this->DeleteParams();
  82. delete(this->parameterNames);
  83. }
  84. /**
  85. Read the list of patterns from the driver file.
  86. This list is for the current suite.
  87. */
  88. void Semihosting::ReadPatternList()
  89. {
  90. char tmp[256];
  91. int nbPatterns;
  92. fscanf(this->infile,"%d\n",&nbPatterns);
  93. // Reset the list for the current suite
  94. this->patternFilenames->clear();
  95. std::string tmpstr;
  96. for(int i=0;i<nbPatterns;i++)
  97. {
  98. fgets(tmp,256,this->infile);
  99. // Remove end of line
  100. if (tmp[strlen(tmp)-1] == '\n')
  101. {
  102. tmp[strlen(tmp)-1]=0;
  103. }
  104. tmpstr.assign(tmp);
  105. this->patternFilenames->push_back(tmpstr);
  106. }
  107. }
  108. /**
  109. Read the list of parameters from the driver file.
  110. This list is for the current suite.
  111. */
  112. void Semihosting::ReadParameterList(Testing::nbParameters_t nbParams)
  113. {
  114. char tmp[256];
  115. char paramKind;
  116. std::string tmpstr;
  117. // It is the number of samples in the file.
  118. // Not the number of parameters controlling the function
  119. int nbValues;
  120. fscanf(this->infile,"%d\n",&nbValues);
  121. // Reset the list for the current suite
  122. this->DeleteParams();
  123. this->parameterNames->clear();
  124. for(int i=0;i<nbValues;i++)
  125. {
  126. fscanf(this->infile,"%c\n",&paramKind);
  127. struct pathOrGen gen;
  128. if (paramKind == 'p')
  129. {
  130. fgets(tmp,256,this->infile);
  131. // Remove end of line
  132. if (tmp[strlen(tmp)-1] == '\n')
  133. {
  134. tmp[strlen(tmp)-1]=0;
  135. }
  136. tmpstr.assign(tmp);
  137. std::string tmp;
  138. tmp += this->parameterRootPath;
  139. tmp += this->testDir;
  140. tmp += "/";
  141. tmp += tmpstr;
  142. gen.kind=0;
  143. gen.path=tmp;
  144. gen.nbInputSamples = this->GetFileSize(tmp);
  145. gen.dimensions = nbParams;
  146. }
  147. // Generator
  148. // Generator kind (only 1 = cartesian product generator)
  149. // Number of samples generated when run
  150. // Number of dimensions
  151. // For each dimension
  152. // Length
  153. // Samples
  154. else
  155. {
  156. int kind,nbInputSamples,nbOutputSamples,dimensions,len,sample;
  157. Testing::param_t *p,*current;
  158. size_t length;
  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. printf("%ld 0 0 %u Y\n",this->currentId,cycles);
  315. }
  316. }
  317. /**
  318. Signal end of group
  319. (Used by scripts parsing the output to display the results)
  320. */
  321. void Semihosting::EndGroup()
  322. {
  323. printf("p\n");
  324. this->path->pop_back();
  325. }
  326. /**
  327. Get pattern path.
  328. */
  329. std::string Semihosting::getPatternPath(Testing::PatternID_t id)
  330. {
  331. std::string tmp;
  332. tmp += this->patternRootPath;
  333. tmp += this->testDir;
  334. tmp += "/";
  335. tmp += (*this->patternFilenames)[id];
  336. return(tmp);
  337. }
  338. /**
  339. Get parameter path.
  340. */
  341. struct pathOrGen Semihosting::getParameterDesc(Testing::PatternID_t id)
  342. {
  343. return((*this->parameterNames)[id]);
  344. }
  345. /**
  346. Get output path.
  347. The test ID (currentId) is used in the name
  348. */
  349. std::string Semihosting::getOutputPath(Testing::outputID_t id)
  350. {
  351. char fmt[256];
  352. std::string tmp;
  353. tmp += this->outputRootPath;
  354. tmp += this->testDir;
  355. sprintf(fmt,"/%s_%ld.txt",(*this->outputNames)[id].c_str(),this->currentId);
  356. tmp += std::string(fmt);
  357. //printf("%s\n",tmp.c_str());
  358. return(tmp);
  359. }
  360. Testing::nbSamples_t Semihosting::GetPatternSize(Testing::PatternID_t id)
  361. {
  362. char tmp[256];
  363. Testing::nbSamples_t len;
  364. std::string fileName = this->getPatternPath(id);
  365. FILE *pattern=fopen(fileName.c_str(), "r");
  366. if (pattern==NULL)
  367. {
  368. return(0);
  369. }
  370. // Ignore word size format
  371. fgets(tmp,256,pattern);
  372. // Get nb of samples
  373. fgets(tmp,256,pattern);
  374. fclose(pattern);
  375. len=atoi(tmp);
  376. return(len);
  377. }
  378. Testing::nbSamples_t Semihosting::GetFileSize(std::string &filepath)
  379. {
  380. char tmp[256];
  381. Testing::nbSamples_t len;
  382. FILE *params=fopen(filepath.c_str(), "r");
  383. if (params==NULL)
  384. {
  385. return(0);
  386. }
  387. // Get nb of samples
  388. fgets(tmp,256,params);
  389. fclose(params);
  390. len=atoi(tmp);
  391. return(len);
  392. }
  393. void Semihosting::DumpParams(std::vector<Testing::param_t>& params)
  394. {
  395. bool begin=true;
  396. printf("b ");
  397. for(std::vector<Testing::param_t>::iterator it = params.begin(); it != params.end(); ++it)
  398. {
  399. if (!begin)
  400. {
  401. printf(",");
  402. }
  403. printf("%d",*it);
  404. begin=false;
  405. }
  406. printf("\n");
  407. }
  408. Testing::param_t* Semihosting::ImportParams(Testing::PatternID_t id,Testing::nbParameterEntries_t &nbEntries)
  409. {
  410. nbEntries = 0;
  411. char tmp[256];
  412. Testing::param_t *p;
  413. uint32_t val;
  414. Testing::nbSamples_t len;
  415. struct pathOrGen gen = this->getParameterDesc(id);
  416. if (gen.kind == 0)
  417. {
  418. char *result=NULL;
  419. FILE *params=fopen(gen.path.c_str(), "r");
  420. if (params==NULL)
  421. {
  422. return(NULL);
  423. }
  424. // Get nb of samples
  425. fgets(tmp,256,params);
  426. len=gen.nbInputSamples;
  427. result=(char*)malloc(len*sizeof(Testing::param_t));
  428. p = (Testing::param_t*)result;
  429. nbEntries = len / gen.dimensions;
  430. for(uint32_t i=0; i < len; i++)
  431. {
  432. fscanf(params,"%d\n",&val);
  433. *p++ = val;
  434. }
  435. fclose(params);
  436. return((Testing::param_t*)result);
  437. }
  438. else
  439. {
  440. Testing::param_t* result;
  441. // Output samples is number of parameter line
  442. len=gen.nbOutputSamples * gen.dimensions;
  443. result=(Testing::param_t*)malloc(len*sizeof(Testing::param_t));
  444. switch(gen.dimensions)
  445. {
  446. case 1:
  447. generate1(result,gen.data,nbEntries);
  448. break;
  449. case 2:
  450. generate2(result,gen.data,nbEntries);
  451. break;
  452. case 3:
  453. generate3(result,gen.data,nbEntries);
  454. break;
  455. case 4:
  456. generate4(result,gen.data,nbEntries);
  457. break;
  458. default:
  459. generate1(result,gen.data,nbEntries);
  460. break;
  461. }
  462. return(result);
  463. }
  464. }
  465. bool Semihosting::hasParam()
  466. {
  467. return(this->m_hasParam);
  468. }
  469. Testing::PatternID_t Semihosting::getParamID()
  470. {
  471. return(this->currentParam);
  472. }
  473. void Semihosting::ImportPattern_f64(Testing::PatternID_t id,char* p,Testing::nbSamples_t nb)
  474. {
  475. char tmp[256];
  476. Testing::nbSamples_t len;
  477. Testing::nbSamples_t i=0;
  478. uint64_t val;
  479. float64_t *ptr=(float64_t*)p;
  480. std::string fileName = this->getPatternPath(id);
  481. FILE *pattern=fopen(fileName.c_str(), "r");
  482. // Ignore word size format
  483. // word size format is used when generating include files with python scripts
  484. fgets(tmp,256,pattern);
  485. // Get nb of samples
  486. fgets(tmp,256,pattern);
  487. len=atoi(tmp);
  488. if ((nb != MAX_NB_SAMPLES) && (nb < len))
  489. {
  490. len = nb;
  491. }
  492. for(i=0;i<len;i++)
  493. {
  494. // Ignore comment
  495. fgets(tmp,256,pattern);
  496. fscanf(pattern,"0x%16llx\n",&val);
  497. *ptr = TOTYP(float64_t,val);
  498. ptr++;
  499. }
  500. fclose(pattern);
  501. }
  502. void Semihosting::ImportPattern_f32(Testing::PatternID_t id,char* p,Testing::nbSamples_t nb)
  503. {
  504. char tmp[256];
  505. Testing::nbSamples_t len;
  506. Testing::nbSamples_t i=0;
  507. uint32_t val;
  508. float32_t *ptr=(float32_t*)p;
  509. std::string fileName = this->getPatternPath(id);
  510. FILE *pattern=fopen(fileName.c_str(), "r");
  511. // Ignore word size format
  512. fgets(tmp,256,pattern);
  513. // Get nb of samples
  514. fgets(tmp,256,pattern);
  515. len=atoi(tmp);
  516. if ((nb != MAX_NB_SAMPLES) && (nb < len))
  517. {
  518. len = nb;
  519. }
  520. //printf(":::: %s\n",fileName.c_str());
  521. for(i=0;i<len;i++)
  522. {
  523. // Ignore comment
  524. fgets(tmp,256,pattern);
  525. fscanf(pattern,"0x%08X\n",&val);
  526. //printf(":::: %08X %f\n",val, TOTYP(float32_t,val));
  527. *ptr = TOTYP(float32_t,val);
  528. ptr++;
  529. }
  530. fclose(pattern);
  531. }
  532. void Semihosting::ImportPattern_q31(Testing::PatternID_t id,char* p,Testing::nbSamples_t nb)
  533. {
  534. char tmp[256];
  535. Testing::nbSamples_t len;
  536. Testing::nbSamples_t i=0;
  537. uint32_t val;
  538. q31_t *ptr=(q31_t*)p;
  539. std::string fileName = this->getPatternPath(id);
  540. FILE *pattern=fopen(fileName.c_str(), "r");
  541. // Ignore word size format
  542. fgets(tmp,256,pattern);
  543. // Get nb of samples
  544. fgets(tmp,256,pattern);
  545. len=atoi(tmp);
  546. if ((nb != MAX_NB_SAMPLES) && (nb < len))
  547. {
  548. len = nb;
  549. }
  550. for(i=0;i<len;i++)
  551. {
  552. // Ignore comment
  553. fgets(tmp,256,pattern);
  554. fscanf(pattern,"0x%08X\n",&val);
  555. *ptr = TOTYP(q31_t,val);
  556. ptr++;
  557. }
  558. fclose(pattern);
  559. }
  560. void Semihosting::ImportPattern_q15(Testing::PatternID_t id,char* p,Testing::nbSamples_t nb)
  561. {
  562. char tmp[256];
  563. Testing::nbSamples_t len;
  564. Testing::nbSamples_t i=0;
  565. uint32_t val;
  566. q15_t *ptr=(q15_t*)p;
  567. std::string fileName = this->getPatternPath(id);
  568. FILE *pattern=fopen(fileName.c_str(), "r");
  569. // Ignore word size format
  570. fgets(tmp,256,pattern);
  571. // Get nb of samples
  572. fgets(tmp,256,pattern);
  573. len=atoi(tmp);
  574. if ((nb != MAX_NB_SAMPLES) && (nb < len))
  575. {
  576. len = nb;
  577. }
  578. for(i=0;i<len;i++)
  579. {
  580. // Ignore comment
  581. fgets(tmp,256,pattern);
  582. fscanf(pattern,"0x%08X\n",&val);
  583. *ptr = TOTYP(q15_t,val);
  584. ptr++;
  585. }
  586. fclose(pattern);
  587. }
  588. void Semihosting::ImportPattern_q7(Testing::PatternID_t id,char* p,Testing::nbSamples_t nb)
  589. {
  590. char tmp[256];
  591. Testing::nbSamples_t len;
  592. Testing::nbSamples_t i=0;
  593. uint32_t val;
  594. q7_t *ptr=(q7_t*)p;
  595. std::string fileName = this->getPatternPath(id);
  596. FILE *pattern=fopen(fileName.c_str(), "r");
  597. // Ignore word size format
  598. fgets(tmp,256,pattern);
  599. // Get nb of samples
  600. fgets(tmp,256,pattern);
  601. len=atoi(tmp);
  602. if ((nb != MAX_NB_SAMPLES) && (nb < len))
  603. {
  604. len = nb;
  605. }
  606. for(i=0;i<len;i++)
  607. {
  608. // Ignore comment
  609. fgets(tmp,256,pattern);
  610. fscanf(pattern,"0x%08X\n",&val);
  611. *ptr = TOTYP(q7_t,val);
  612. ptr++;
  613. }
  614. fclose(pattern);
  615. }
  616. void Semihosting::ImportPattern_u32(Testing::PatternID_t id,char* p,Testing::nbSamples_t nb)
  617. {
  618. char tmp[256];
  619. Testing::nbSamples_t len;
  620. Testing::nbSamples_t i=0;
  621. uint32_t val;
  622. uint32_t *ptr=(uint32_t*)p;
  623. std::string fileName = this->getPatternPath(id);
  624. FILE *pattern=fopen(fileName.c_str(), "r");
  625. // Ignore word size format
  626. fgets(tmp,256,pattern);
  627. // Get nb of samples
  628. fgets(tmp,256,pattern);
  629. len=atoi(tmp);
  630. if ((nb != MAX_NB_SAMPLES) && (nb < len))
  631. {
  632. len = nb;
  633. }
  634. for(i=0;i<len;i++)
  635. {
  636. // Ignore comment
  637. fgets(tmp,256,pattern);
  638. fscanf(pattern,"0x%08X\n",&val);
  639. *ptr = val;
  640. ptr++;
  641. }
  642. fclose(pattern);
  643. }
  644. void Semihosting::ImportPattern_u16(Testing::PatternID_t id,char* p,Testing::nbSamples_t nb)
  645. {
  646. char tmp[256];
  647. Testing::nbSamples_t len;
  648. Testing::nbSamples_t i=0;
  649. uint32_t val;
  650. uint16_t *ptr=(uint16_t*)p;
  651. std::string fileName = this->getPatternPath(id);
  652. FILE *pattern=fopen(fileName.c_str(), "r");
  653. // Ignore word size format
  654. fgets(tmp,256,pattern);
  655. // Get nb of samples
  656. fgets(tmp,256,pattern);
  657. len=atoi(tmp);
  658. if ((nb != MAX_NB_SAMPLES) && (nb < len))
  659. {
  660. len = nb;
  661. }
  662. for(i=0;i<len;i++)
  663. {
  664. // Ignore comment
  665. fgets(tmp,256,pattern);
  666. fscanf(pattern,"0x%08X\n",&val);
  667. *ptr = (uint16_t)val;
  668. ptr++;
  669. }
  670. fclose(pattern);
  671. }
  672. void Semihosting::ImportPattern_u8(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. uint8_t *ptr=(uint8_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. for(i=0;i<len;i++)
  691. {
  692. // Ignore comment
  693. fgets(tmp,256,pattern);
  694. fscanf(pattern,"0x%08X\n",&val);
  695. *ptr = (uint8_t)val;
  696. ptr++;
  697. }
  698. fclose(pattern);
  699. }
  700. void Semihosting::DumpPattern_f64(Testing::outputID_t id,Testing::nbSamples_t nb, float64_t* data)
  701. {
  702. std::string fileName = this->getOutputPath(id);
  703. FILE *f = fopen(fileName.c_str(),"w");
  704. Testing::nbSamples_t i=0;
  705. uint64_t t;
  706. float64_t v;
  707. for(i=0; i < nb; i++)
  708. {
  709. v = data[i];
  710. t = TOINT64(v);
  711. fprintf(f,"0x%016llx\n",t);
  712. }
  713. fclose(f);
  714. }
  715. void Semihosting::DumpPattern_f32(Testing::outputID_t id,Testing::nbSamples_t nb, float32_t* data)
  716. {
  717. std::string fileName = this->getOutputPath(id);
  718. FILE *f = fopen(fileName.c_str(),"w");
  719. Testing::nbSamples_t i=0;
  720. uint32_t t;
  721. float32_t v;
  722. for(i=0; i < nb; i++)
  723. {
  724. v = data[i];
  725. t = TOINT32(v);
  726. fprintf(f,"0x%08x\n",t);
  727. }
  728. fclose(f);
  729. }
  730. void Semihosting::DumpPattern_q31(Testing::outputID_t id,Testing::nbSamples_t nb, q31_t* data)
  731. {
  732. std::string fileName = this->getOutputPath(id);
  733. FILE *f = fopen(fileName.c_str(),"w");
  734. Testing::nbSamples_t i=0;
  735. uint32_t t;
  736. for(i=0; i < nb; i++)
  737. {
  738. t = (uint32_t)data[i];
  739. fprintf(f,"0x%08x\n",t);
  740. }
  741. fclose(f);
  742. }
  743. void Semihosting::DumpPattern_q15(Testing::outputID_t id,Testing::nbSamples_t nb, q15_t* data)
  744. {
  745. std::string fileName = this->getOutputPath(id);
  746. FILE *f = fopen(fileName.c_str(),"w");
  747. Testing::nbSamples_t i=0;
  748. uint32_t t;
  749. for(i=0; i < nb; i++)
  750. {
  751. t = (uint32_t)data[i];
  752. fprintf(f,"0x%08x\n",t);
  753. }
  754. fclose(f);
  755. }
  756. void Semihosting::DumpPattern_q7(Testing::outputID_t id,Testing::nbSamples_t nb, q7_t* data)
  757. {
  758. std::string fileName = this->getOutputPath(id);
  759. FILE *f = fopen(fileName.c_str(),"w");
  760. Testing::nbSamples_t i=0;
  761. uint32_t t;
  762. for(i=0; i < nb; i++)
  763. {
  764. t = (uint32_t)data[i];
  765. fprintf(f,"0x%08x\n",t);
  766. }
  767. fclose(f);
  768. }
  769. void Semihosting::DumpPattern_u32(Testing::outputID_t id,Testing::nbSamples_t nb, uint32_t* data)
  770. {
  771. std::string fileName = this->getOutputPath(id);
  772. FILE *f = fopen(fileName.c_str(),"w");
  773. Testing::nbSamples_t i=0;
  774. uint32_t t;
  775. for(i=0; i < nb; i++)
  776. {
  777. t = (uint32_t)data[i];
  778. fprintf(f,"0x%08x\n",t);
  779. }
  780. fclose(f);
  781. }
  782. void Semihosting::DumpPattern_u16(Testing::outputID_t id,Testing::nbSamples_t nb, uint16_t* data)
  783. {
  784. std::string fileName = this->getOutputPath(id);
  785. FILE *f = fopen(fileName.c_str(),"w");
  786. Testing::nbSamples_t i=0;
  787. uint32_t t;
  788. for(i=0; i < nb; i++)
  789. {
  790. t = (uint32_t)data[i];
  791. fprintf(f,"0x%08x\n",t);
  792. }
  793. fclose(f);
  794. }
  795. void Semihosting::DumpPattern_u8(Testing::outputID_t id,Testing::nbSamples_t nb, uint8_t* data)
  796. {
  797. std::string fileName = this->getOutputPath(id);
  798. FILE *f = fopen(fileName.c_str(),"w");
  799. Testing::nbSamples_t i=0;
  800. uint32_t t;
  801. for(i=0; i < nb; i++)
  802. {
  803. t = (uint32_t)data[i];
  804. fprintf(f,"0x%08x\n",t);
  805. }
  806. fclose(f);
  807. }
  808. }