Semihosting.cpp 29 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087
  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. /**
  322. Signal end of group
  323. (Used by scripts parsing the output to display the results)
  324. */
  325. void Semihosting::EndGroup()
  326. {
  327. printf("p\n");
  328. this->path->pop_back();
  329. }
  330. /**
  331. Get pattern path.
  332. */
  333. std::string Semihosting::getPatternPath(Testing::PatternID_t id)
  334. {
  335. std::string tmp;
  336. tmp += this->patternRootPath;
  337. tmp += this->testDir;
  338. tmp += "/";
  339. tmp += (*this->patternFilenames)[id];
  340. return(tmp);
  341. }
  342. /**
  343. Get parameter path.
  344. */
  345. struct pathOrGen Semihosting::getParameterDesc(Testing::PatternID_t id)
  346. {
  347. return((*this->parameterNames)[id]);
  348. }
  349. /**
  350. Get output path.
  351. The test ID (currentId) is used in the name
  352. */
  353. std::string Semihosting::getOutputPath(Testing::outputID_t id)
  354. {
  355. char fmt[256];
  356. std::string tmp;
  357. tmp += this->outputRootPath;
  358. tmp += this->testDir;
  359. sprintf(fmt,"/%s_%ld.txt",(*this->outputNames)[id].c_str(),this->currentId);
  360. tmp += std::string(fmt);
  361. //printf("%s\n",tmp.c_str());
  362. return(tmp);
  363. }
  364. Testing::nbSamples_t Semihosting::GetPatternSize(Testing::PatternID_t id)
  365. {
  366. char tmp[256];
  367. Testing::nbSamples_t len;
  368. std::string fileName = this->getPatternPath(id);
  369. FILE *pattern=fopen(fileName.c_str(), "r");
  370. if (pattern==NULL)
  371. {
  372. return(0);
  373. }
  374. // Ignore word size format
  375. fgets(tmp,256,pattern);
  376. // Get nb of samples
  377. fgets(tmp,256,pattern);
  378. fclose(pattern);
  379. len=atoi(tmp);
  380. return(len);
  381. }
  382. Testing::nbSamples_t Semihosting::GetFileSize(std::string &filepath)
  383. {
  384. char tmp[256];
  385. Testing::nbSamples_t len;
  386. FILE *params=fopen(filepath.c_str(), "r");
  387. if (params==NULL)
  388. {
  389. return(0);
  390. }
  391. // Get nb of samples
  392. fgets(tmp,256,params);
  393. fclose(params);
  394. len=atoi(tmp);
  395. return(len);
  396. }
  397. void Semihosting::DumpParams(std::vector<Testing::param_t>& params)
  398. {
  399. bool begin=true;
  400. printf("b ");
  401. for(std::vector<Testing::param_t>::iterator it = params.begin(); it != params.end(); ++it)
  402. {
  403. if (!begin)
  404. {
  405. printf(",");
  406. }
  407. printf("%d",*it);
  408. begin=false;
  409. }
  410. printf("\n");
  411. }
  412. Testing::param_t* Semihosting::ImportParams(Testing::PatternID_t id,Testing::nbParameterEntries_t &nbEntries,Testing::ParameterKind &paramKind)
  413. {
  414. nbEntries = 0;
  415. char tmp[256];
  416. Testing::param_t *p;
  417. uint32_t val;
  418. Testing::nbSamples_t len;
  419. struct pathOrGen gen = this->getParameterDesc(id);
  420. if (gen.kind == 0)
  421. {
  422. char *result=NULL;
  423. paramKind=Testing::kDynamicBuffer;
  424. FILE *params=fopen(gen.path.c_str(), "r");
  425. if (params==NULL)
  426. {
  427. return(NULL);
  428. }
  429. // Get nb of samples
  430. fgets(tmp,256,params);
  431. len=gen.nbInputSamples;
  432. result=(char*)malloc(len*sizeof(Testing::param_t));
  433. p = (Testing::param_t*)result;
  434. nbEntries = len / gen.dimensions;
  435. for(uint32_t i=0; i < len; i++)
  436. {
  437. fscanf(params,"%d\n",&val);
  438. *p++ = val;
  439. }
  440. fclose(params);
  441. return((Testing::param_t*)result);
  442. }
  443. else
  444. {
  445. Testing::param_t* result;
  446. paramKind=Testing::kDynamicBuffer;
  447. // Output samples is number of parameter line
  448. len=gen.nbOutputSamples * gen.dimensions;
  449. result=(Testing::param_t*)malloc(len*sizeof(Testing::param_t));
  450. switch(gen.dimensions)
  451. {
  452. case 1:
  453. generate1(result,gen.data,nbEntries);
  454. break;
  455. case 2:
  456. generate2(result,gen.data,nbEntries);
  457. break;
  458. case 3:
  459. generate3(result,gen.data,nbEntries);
  460. break;
  461. case 4:
  462. generate4(result,gen.data,nbEntries);
  463. break;
  464. default:
  465. generate1(result,gen.data,nbEntries);
  466. break;
  467. }
  468. return(result);
  469. }
  470. }
  471. bool Semihosting::hasParam()
  472. {
  473. return(this->m_hasParam);
  474. }
  475. Testing::PatternID_t Semihosting::getParamID()
  476. {
  477. return(this->currentParam);
  478. }
  479. void Semihosting::ImportPattern_f64(Testing::PatternID_t id,char* p,Testing::nbSamples_t nb)
  480. {
  481. char tmp[256];
  482. Testing::nbSamples_t len;
  483. Testing::nbSamples_t i=0;
  484. uint64_t val;
  485. float64_t *ptr=(float64_t*)p;
  486. std::string fileName = this->getPatternPath(id);
  487. FILE *pattern=fopen(fileName.c_str(), "r");
  488. // Ignore word size format
  489. // word size format is used when generating include files with python scripts
  490. fgets(tmp,256,pattern);
  491. // Get nb of samples
  492. fgets(tmp,256,pattern);
  493. len=atoi(tmp);
  494. if ((nb != MAX_NB_SAMPLES) && (nb < len))
  495. {
  496. len = nb;
  497. }
  498. if (ptr)
  499. {
  500. for(i=0;i<len;i++)
  501. {
  502. // Ignore comment
  503. fgets(tmp,256,pattern);
  504. fscanf(pattern,"0x%16llx\n",&val);
  505. *ptr = TOTYP(float64_t,val);
  506. ptr++;
  507. }
  508. }
  509. fclose(pattern);
  510. }
  511. void Semihosting::ImportPattern_f32(Testing::PatternID_t id,char* p,Testing::nbSamples_t nb)
  512. {
  513. char tmp[256];
  514. Testing::nbSamples_t len;
  515. Testing::nbSamples_t i=0;
  516. uint32_t val;
  517. float32_t *ptr=(float32_t*)p;
  518. std::string fileName = this->getPatternPath(id);
  519. FILE *pattern=fopen(fileName.c_str(), "r");
  520. // Ignore word size format
  521. fgets(tmp,256,pattern);
  522. // Get nb of samples
  523. fgets(tmp,256,pattern);
  524. len=atoi(tmp);
  525. if ((nb != MAX_NB_SAMPLES) && (nb < len))
  526. {
  527. len = nb;
  528. }
  529. //printf(":::: %s\n",fileName.c_str());
  530. if (ptr)
  531. {
  532. for(i=0;i<len;i++)
  533. {
  534. // Ignore comment
  535. fgets(tmp,256,pattern);
  536. fscanf(pattern,"0x%08X\n",&val);
  537. //printf(":::: %08X %f\n",val, TOTYP(float32_t,val));
  538. *ptr = TOTYP(float32_t,val);
  539. ptr++;
  540. }
  541. }
  542. fclose(pattern);
  543. }
  544. void Semihosting::ImportPattern_q63(Testing::PatternID_t id,char* p,Testing::nbSamples_t nb)
  545. {
  546. char tmp[256];
  547. Testing::nbSamples_t len;
  548. Testing::nbSamples_t i=0;
  549. uint64_t val;
  550. q63_t *ptr=(q63_t*)p;
  551. std::string fileName = this->getPatternPath(id);
  552. FILE *pattern=fopen(fileName.c_str(), "r");
  553. // Ignore word size format
  554. fgets(tmp,256,pattern);
  555. // Get nb of samples
  556. fgets(tmp,256,pattern);
  557. len=atoi(tmp);
  558. if ((nb != MAX_NB_SAMPLES) && (nb < len))
  559. {
  560. len = nb;
  561. }
  562. if (ptr)
  563. {
  564. for(i=0;i<len;i++)
  565. {
  566. // Ignore comment
  567. fgets(tmp,256,pattern);
  568. fscanf(pattern,"0x%016llX\n",&val);
  569. *ptr = TOTYP(q63_t,val);
  570. ptr++;
  571. }
  572. }
  573. fclose(pattern);
  574. }
  575. void Semihosting::ImportPattern_q31(Testing::PatternID_t id,char* p,Testing::nbSamples_t nb)
  576. {
  577. char tmp[256];
  578. Testing::nbSamples_t len;
  579. Testing::nbSamples_t i=0;
  580. uint32_t val;
  581. q31_t *ptr=(q31_t*)p;
  582. std::string fileName = this->getPatternPath(id);
  583. FILE *pattern=fopen(fileName.c_str(), "r");
  584. // Ignore word size format
  585. fgets(tmp,256,pattern);
  586. // Get nb of samples
  587. fgets(tmp,256,pattern);
  588. len=atoi(tmp);
  589. if ((nb != MAX_NB_SAMPLES) && (nb < len))
  590. {
  591. len = nb;
  592. }
  593. if (ptr)
  594. {
  595. for(i=0;i<len;i++)
  596. {
  597. // Ignore comment
  598. fgets(tmp,256,pattern);
  599. fscanf(pattern,"0x%08X\n",&val);
  600. *ptr = TOTYP(q31_t,val);
  601. ptr++;
  602. }
  603. }
  604. fclose(pattern);
  605. }
  606. void Semihosting::ImportPattern_q15(Testing::PatternID_t id,char* p,Testing::nbSamples_t nb)
  607. {
  608. char tmp[256];
  609. Testing::nbSamples_t len;
  610. Testing::nbSamples_t i=0;
  611. uint32_t val;
  612. q15_t *ptr=(q15_t*)p;
  613. std::string fileName = this->getPatternPath(id);
  614. FILE *pattern=fopen(fileName.c_str(), "r");
  615. // Ignore word size format
  616. fgets(tmp,256,pattern);
  617. // Get nb of samples
  618. fgets(tmp,256,pattern);
  619. len=atoi(tmp);
  620. if ((nb != MAX_NB_SAMPLES) && (nb < len))
  621. {
  622. len = nb;
  623. }
  624. if (ptr)
  625. {
  626. for(i=0;i<len;i++)
  627. {
  628. // Ignore comment
  629. fgets(tmp,256,pattern);
  630. fscanf(pattern,"0x%08X\n",&val);
  631. *ptr = TOTYP(q15_t,val);
  632. ptr++;
  633. }
  634. }
  635. fclose(pattern);
  636. }
  637. void Semihosting::ImportPattern_q7(Testing::PatternID_t id,char* p,Testing::nbSamples_t nb)
  638. {
  639. char tmp[256];
  640. Testing::nbSamples_t len;
  641. Testing::nbSamples_t i=0;
  642. uint32_t val;
  643. q7_t *ptr=(q7_t*)p;
  644. std::string fileName = this->getPatternPath(id);
  645. FILE *pattern=fopen(fileName.c_str(), "r");
  646. // Ignore word size format
  647. fgets(tmp,256,pattern);
  648. // Get nb of samples
  649. fgets(tmp,256,pattern);
  650. len=atoi(tmp);
  651. if ((nb != MAX_NB_SAMPLES) && (nb < len))
  652. {
  653. len = nb;
  654. }
  655. if (ptr)
  656. {
  657. for(i=0;i<len;i++)
  658. {
  659. // Ignore comment
  660. fgets(tmp,256,pattern);
  661. fscanf(pattern,"0x%08X\n",&val);
  662. *ptr = TOTYP(q7_t,val);
  663. ptr++;
  664. }
  665. }
  666. fclose(pattern);
  667. }
  668. void Semihosting::ImportPattern_u32(Testing::PatternID_t id,char* p,Testing::nbSamples_t nb)
  669. {
  670. char tmp[256];
  671. Testing::nbSamples_t len;
  672. Testing::nbSamples_t i=0;
  673. uint32_t val;
  674. uint32_t *ptr=(uint32_t*)p;
  675. std::string fileName = this->getPatternPath(id);
  676. FILE *pattern=fopen(fileName.c_str(), "r");
  677. // Ignore word size format
  678. fgets(tmp,256,pattern);
  679. // Get nb of samples
  680. fgets(tmp,256,pattern);
  681. len=atoi(tmp);
  682. if ((nb != MAX_NB_SAMPLES) && (nb < len))
  683. {
  684. len = nb;
  685. }
  686. if (ptr)
  687. {
  688. for(i=0;i<len;i++)
  689. {
  690. // Ignore comment
  691. fgets(tmp,256,pattern);
  692. fscanf(pattern,"0x%08X\n",&val);
  693. *ptr = val;
  694. ptr++;
  695. }
  696. }
  697. fclose(pattern);
  698. }
  699. void Semihosting::ImportPattern_u16(Testing::PatternID_t id,char* p,Testing::nbSamples_t nb)
  700. {
  701. char tmp[256];
  702. Testing::nbSamples_t len;
  703. Testing::nbSamples_t i=0;
  704. uint32_t val;
  705. uint16_t *ptr=(uint16_t*)p;
  706. std::string fileName = this->getPatternPath(id);
  707. FILE *pattern=fopen(fileName.c_str(), "r");
  708. // Ignore word size format
  709. fgets(tmp,256,pattern);
  710. // Get nb of samples
  711. fgets(tmp,256,pattern);
  712. len=atoi(tmp);
  713. if ((nb != MAX_NB_SAMPLES) && (nb < len))
  714. {
  715. len = nb;
  716. }
  717. if (ptr)
  718. {
  719. for(i=0;i<len;i++)
  720. {
  721. // Ignore comment
  722. fgets(tmp,256,pattern);
  723. fscanf(pattern,"0x%08X\n",&val);
  724. *ptr = (uint16_t)val;
  725. ptr++;
  726. }
  727. }
  728. fclose(pattern);
  729. }
  730. void Semihosting::ImportPattern_u8(Testing::PatternID_t id,char* p,Testing::nbSamples_t nb)
  731. {
  732. char tmp[256];
  733. Testing::nbSamples_t len;
  734. Testing::nbSamples_t i=0;
  735. uint32_t val;
  736. uint8_t *ptr=(uint8_t*)p;
  737. std::string fileName = this->getPatternPath(id);
  738. FILE *pattern=fopen(fileName.c_str(), "r");
  739. // Ignore word size format
  740. fgets(tmp,256,pattern);
  741. // Get nb of samples
  742. fgets(tmp,256,pattern);
  743. len=atoi(tmp);
  744. if ((nb != MAX_NB_SAMPLES) && (nb < len))
  745. {
  746. len = nb;
  747. }
  748. if (ptr)
  749. {
  750. for(i=0;i<len;i++)
  751. {
  752. // Ignore comment
  753. fgets(tmp,256,pattern);
  754. fscanf(pattern,"0x%08X\n",&val);
  755. *ptr = (uint8_t)val;
  756. ptr++;
  757. }
  758. }
  759. fclose(pattern);
  760. }
  761. void Semihosting::DumpPattern_f64(Testing::outputID_t id,Testing::nbSamples_t nb, float64_t* data)
  762. {
  763. std::string fileName = this->getOutputPath(id);
  764. if (data)
  765. {
  766. FILE *f = fopen(fileName.c_str(),"w");
  767. Testing::nbSamples_t i=0;
  768. uint64_t t;
  769. float64_t v;
  770. for(i=0; i < nb; i++)
  771. {
  772. v = data[i];
  773. t = TOINT64(v);
  774. fprintf(f,"0x%016llx\n",t);
  775. }
  776. fclose(f);
  777. }
  778. }
  779. void Semihosting::DumpPattern_f32(Testing::outputID_t id,Testing::nbSamples_t nb, float32_t* data)
  780. {
  781. std::string fileName = this->getOutputPath(id);
  782. if (data)
  783. {
  784. FILE *f = fopen(fileName.c_str(),"w");
  785. Testing::nbSamples_t i=0;
  786. uint32_t t;
  787. float32_t v;
  788. for(i=0; i < nb; i++)
  789. {
  790. v = data[i];
  791. t = TOINT32(v);
  792. fprintf(f,"0x%08x\n",t);
  793. }
  794. fclose(f);
  795. }
  796. }
  797. void Semihosting::DumpPattern_q63(Testing::outputID_t id,Testing::nbSamples_t nb, q63_t* data)
  798. {
  799. std::string fileName = this->getOutputPath(id);
  800. if (data)
  801. {
  802. FILE *f = fopen(fileName.c_str(),"w");
  803. Testing::nbSamples_t i=0;
  804. uint64_t t;
  805. for(i=0; i < nb; i++)
  806. {
  807. t = (uint64_t)data[i];
  808. fprintf(f,"0x%016llx\n",t);
  809. }
  810. fclose(f);
  811. }
  812. }
  813. void Semihosting::DumpPattern_q31(Testing::outputID_t id,Testing::nbSamples_t nb, q31_t* data)
  814. {
  815. std::string fileName = this->getOutputPath(id);
  816. if (data)
  817. {
  818. FILE *f = fopen(fileName.c_str(),"w");
  819. Testing::nbSamples_t i=0;
  820. uint32_t t;
  821. for(i=0; i < nb; i++)
  822. {
  823. t = (uint32_t)data[i];
  824. fprintf(f,"0x%08x\n",t);
  825. }
  826. fclose(f);
  827. }
  828. }
  829. void Semihosting::DumpPattern_q15(Testing::outputID_t id,Testing::nbSamples_t nb, q15_t* data)
  830. {
  831. std::string fileName = this->getOutputPath(id);
  832. if (data)
  833. {
  834. FILE *f = fopen(fileName.c_str(),"w");
  835. Testing::nbSamples_t i=0;
  836. uint32_t t;
  837. for(i=0; i < nb; i++)
  838. {
  839. t = (uint32_t)data[i];
  840. fprintf(f,"0x%08x\n",t);
  841. }
  842. fclose(f);
  843. }
  844. }
  845. void Semihosting::DumpPattern_q7(Testing::outputID_t id,Testing::nbSamples_t nb, q7_t* data)
  846. {
  847. std::string fileName = this->getOutputPath(id);
  848. if (data)
  849. {
  850. FILE *f = fopen(fileName.c_str(),"w");
  851. Testing::nbSamples_t i=0;
  852. uint32_t t;
  853. for(i=0; i < nb; i++)
  854. {
  855. t = (uint32_t)data[i];
  856. fprintf(f,"0x%08x\n",t);
  857. }
  858. fclose(f);
  859. }
  860. }
  861. void Semihosting::DumpPattern_u32(Testing::outputID_t id,Testing::nbSamples_t nb, uint32_t* data)
  862. {
  863. std::string fileName = this->getOutputPath(id);
  864. if (data)
  865. {
  866. FILE *f = fopen(fileName.c_str(),"w");
  867. Testing::nbSamples_t i=0;
  868. uint32_t t;
  869. for(i=0; i < nb; i++)
  870. {
  871. t = (uint32_t)data[i];
  872. fprintf(f,"0x%08x\n",t);
  873. }
  874. fclose(f);
  875. }
  876. }
  877. void Semihosting::DumpPattern_u16(Testing::outputID_t id,Testing::nbSamples_t nb, uint16_t* data)
  878. {
  879. std::string fileName = this->getOutputPath(id);
  880. if (data)
  881. {
  882. FILE *f = fopen(fileName.c_str(),"w");
  883. Testing::nbSamples_t i=0;
  884. uint32_t t;
  885. for(i=0; i < nb; i++)
  886. {
  887. t = (uint32_t)data[i];
  888. fprintf(f,"0x%08x\n",t);
  889. }
  890. fclose(f);
  891. }
  892. }
  893. void Semihosting::DumpPattern_u8(Testing::outputID_t id,Testing::nbSamples_t nb, uint8_t* data)
  894. {
  895. std::string fileName = this->getOutputPath(id);
  896. if (data)
  897. {
  898. FILE *f = fopen(fileName.c_str(),"w");
  899. Testing::nbSamples_t i=0;
  900. uint32_t t;
  901. for(i=0; i < nb; i++)
  902. {
  903. t = (uint32_t)data[i];
  904. fprintf(f,"0x%08x\n",t);
  905. }
  906. fclose(f);
  907. }
  908. }
  909. }