Semihosting.cpp 31 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156
  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. #if !defined( __CC_ARM )
  549. void Semihosting::ImportPattern_f16(Testing::PatternID_t id,char* p,Testing::nbSamples_t nb)
  550. {
  551. char tmp[256];
  552. Testing::nbSamples_t len;
  553. Testing::nbSamples_t i=0;
  554. uint32_t val;
  555. float16_t *ptr=(float16_t*)p;
  556. std::string fileName = this->getPatternPath(id);
  557. FILE *pattern=fopen(fileName.c_str(), "r");
  558. // Ignore word size format
  559. fgets(tmp,256,pattern);
  560. // Get nb of samples
  561. fgets(tmp,256,pattern);
  562. len=atoi(tmp);
  563. if ((nb != MAX_NB_SAMPLES) && (nb < len))
  564. {
  565. len = nb;
  566. }
  567. //printf(":::: %s\n",fileName.c_str());
  568. if (ptr)
  569. {
  570. for(i=0;i<len;i++)
  571. {
  572. // Ignore comment
  573. fgets(tmp,256,pattern);
  574. fscanf(pattern,"0x%08X\n",&val);
  575. //printf(":::: %08X %f\n",val, TOTYP(float32_t,val));
  576. *ptr = TOTYP(float16_t,val);
  577. ptr++;
  578. }
  579. }
  580. fclose(pattern);
  581. }
  582. #endif
  583. void Semihosting::ImportPattern_q63(Testing::PatternID_t id,char* p,Testing::nbSamples_t nb)
  584. {
  585. char tmp[256];
  586. Testing::nbSamples_t len;
  587. Testing::nbSamples_t i=0;
  588. uint64_t val;
  589. q63_t *ptr=(q63_t*)p;
  590. std::string fileName = this->getPatternPath(id);
  591. FILE *pattern=fopen(fileName.c_str(), "r");
  592. // Ignore word size format
  593. fgets(tmp,256,pattern);
  594. // Get nb of samples
  595. fgets(tmp,256,pattern);
  596. len=atoi(tmp);
  597. if ((nb != MAX_NB_SAMPLES) && (nb < len))
  598. {
  599. len = nb;
  600. }
  601. if (ptr)
  602. {
  603. for(i=0;i<len;i++)
  604. {
  605. // Ignore comment
  606. fgets(tmp,256,pattern);
  607. fscanf(pattern,"0x%016llX\n",&val);
  608. *ptr = TOTYP(q63_t,val);
  609. ptr++;
  610. }
  611. }
  612. fclose(pattern);
  613. }
  614. void Semihosting::ImportPattern_q31(Testing::PatternID_t id,char* p,Testing::nbSamples_t nb)
  615. {
  616. char tmp[256];
  617. Testing::nbSamples_t len;
  618. Testing::nbSamples_t i=0;
  619. uint32_t val;
  620. q31_t *ptr=(q31_t*)p;
  621. std::string fileName = this->getPatternPath(id);
  622. FILE *pattern=fopen(fileName.c_str(), "r");
  623. // Ignore word size format
  624. fgets(tmp,256,pattern);
  625. // Get nb of samples
  626. fgets(tmp,256,pattern);
  627. len=atoi(tmp);
  628. if ((nb != MAX_NB_SAMPLES) && (nb < len))
  629. {
  630. len = nb;
  631. }
  632. if (ptr)
  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 = TOTYP(q31_t,val);
  640. ptr++;
  641. }
  642. }
  643. fclose(pattern);
  644. }
  645. void Semihosting::ImportPattern_q15(Testing::PatternID_t id,char* p,Testing::nbSamples_t nb)
  646. {
  647. char tmp[256];
  648. Testing::nbSamples_t len;
  649. Testing::nbSamples_t i=0;
  650. uint32_t val;
  651. q15_t *ptr=(q15_t*)p;
  652. std::string fileName = this->getPatternPath(id);
  653. FILE *pattern=fopen(fileName.c_str(), "r");
  654. // Ignore word size format
  655. fgets(tmp,256,pattern);
  656. // Get nb of samples
  657. fgets(tmp,256,pattern);
  658. len=atoi(tmp);
  659. if ((nb != MAX_NB_SAMPLES) && (nb < len))
  660. {
  661. len = nb;
  662. }
  663. if (ptr)
  664. {
  665. for(i=0;i<len;i++)
  666. {
  667. // Ignore comment
  668. fgets(tmp,256,pattern);
  669. fscanf(pattern,"0x%08X\n",&val);
  670. *ptr = TOTYP(q15_t,val);
  671. ptr++;
  672. }
  673. }
  674. fclose(pattern);
  675. }
  676. void Semihosting::ImportPattern_q7(Testing::PatternID_t id,char* p,Testing::nbSamples_t nb)
  677. {
  678. char tmp[256];
  679. Testing::nbSamples_t len;
  680. Testing::nbSamples_t i=0;
  681. uint32_t val;
  682. q7_t *ptr=(q7_t*)p;
  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. if ((nb != MAX_NB_SAMPLES) && (nb < len))
  691. {
  692. len = nb;
  693. }
  694. if (ptr)
  695. {
  696. for(i=0;i<len;i++)
  697. {
  698. // Ignore comment
  699. fgets(tmp,256,pattern);
  700. fscanf(pattern,"0x%08X\n",&val);
  701. *ptr = TOTYP(q7_t,val);
  702. ptr++;
  703. }
  704. }
  705. fclose(pattern);
  706. }
  707. void Semihosting::ImportPattern_u32(Testing::PatternID_t id,char* p,Testing::nbSamples_t nb)
  708. {
  709. char tmp[256];
  710. Testing::nbSamples_t len;
  711. Testing::nbSamples_t i=0;
  712. uint32_t val;
  713. uint32_t *ptr=(uint32_t*)p;
  714. std::string fileName = this->getPatternPath(id);
  715. FILE *pattern=fopen(fileName.c_str(), "r");
  716. // Ignore word size format
  717. fgets(tmp,256,pattern);
  718. // Get nb of samples
  719. fgets(tmp,256,pattern);
  720. len=atoi(tmp);
  721. if ((nb != MAX_NB_SAMPLES) && (nb < len))
  722. {
  723. len = nb;
  724. }
  725. if (ptr)
  726. {
  727. for(i=0;i<len;i++)
  728. {
  729. // Ignore comment
  730. fgets(tmp,256,pattern);
  731. fscanf(pattern,"0x%08X\n",&val);
  732. *ptr = val;
  733. ptr++;
  734. }
  735. }
  736. fclose(pattern);
  737. }
  738. void Semihosting::ImportPattern_u16(Testing::PatternID_t id,char* p,Testing::nbSamples_t nb)
  739. {
  740. char tmp[256];
  741. Testing::nbSamples_t len;
  742. Testing::nbSamples_t i=0;
  743. uint32_t val;
  744. uint16_t *ptr=(uint16_t*)p;
  745. std::string fileName = this->getPatternPath(id);
  746. FILE *pattern=fopen(fileName.c_str(), "r");
  747. // Ignore word size format
  748. fgets(tmp,256,pattern);
  749. // Get nb of samples
  750. fgets(tmp,256,pattern);
  751. len=atoi(tmp);
  752. if ((nb != MAX_NB_SAMPLES) && (nb < len))
  753. {
  754. len = nb;
  755. }
  756. if (ptr)
  757. {
  758. for(i=0;i<len;i++)
  759. {
  760. // Ignore comment
  761. fgets(tmp,256,pattern);
  762. fscanf(pattern,"0x%08X\n",&val);
  763. *ptr = (uint16_t)val;
  764. ptr++;
  765. }
  766. }
  767. fclose(pattern);
  768. }
  769. void Semihosting::ImportPattern_u8(Testing::PatternID_t id,char* p,Testing::nbSamples_t nb)
  770. {
  771. char tmp[256];
  772. Testing::nbSamples_t len;
  773. Testing::nbSamples_t i=0;
  774. uint32_t val;
  775. uint8_t *ptr=(uint8_t*)p;
  776. std::string fileName = this->getPatternPath(id);
  777. FILE *pattern=fopen(fileName.c_str(), "r");
  778. // Ignore word size format
  779. fgets(tmp,256,pattern);
  780. // Get nb of samples
  781. fgets(tmp,256,pattern);
  782. len=atoi(tmp);
  783. if ((nb != MAX_NB_SAMPLES) && (nb < len))
  784. {
  785. len = nb;
  786. }
  787. if (ptr)
  788. {
  789. for(i=0;i<len;i++)
  790. {
  791. // Ignore comment
  792. fgets(tmp,256,pattern);
  793. fscanf(pattern,"0x%08X\n",&val);
  794. *ptr = (uint8_t)val;
  795. ptr++;
  796. }
  797. }
  798. fclose(pattern);
  799. }
  800. void Semihosting::DumpPattern_f64(Testing::outputID_t id,Testing::nbSamples_t nb, float64_t* data)
  801. {
  802. std::string fileName = this->getOutputPath(id);
  803. if (data)
  804. {
  805. FILE *f = fopen(fileName.c_str(),"w");
  806. Testing::nbSamples_t i=0;
  807. uint64_t t;
  808. float64_t v;
  809. for(i=0; i < nb; i++)
  810. {
  811. v = data[i];
  812. t = TOINT64(v);
  813. fprintf(f,"0x%016llx\n",t);
  814. }
  815. fclose(f);
  816. }
  817. }
  818. void Semihosting::DumpPattern_f32(Testing::outputID_t id,Testing::nbSamples_t nb, float32_t* data)
  819. {
  820. std::string fileName = this->getOutputPath(id);
  821. if (data)
  822. {
  823. FILE *f = fopen(fileName.c_str(),"w");
  824. Testing::nbSamples_t i=0;
  825. uint32_t t;
  826. float32_t v;
  827. for(i=0; i < nb; i++)
  828. {
  829. v = data[i];
  830. t = TOINT32(v);
  831. fprintf(f,"0x%08x\n",t);
  832. }
  833. fclose(f);
  834. }
  835. }
  836. #if !defined( __CC_ARM )
  837. void Semihosting::DumpPattern_f16(Testing::outputID_t id,Testing::nbSamples_t nb, float16_t* data)
  838. {
  839. std::string fileName = this->getOutputPath(id);
  840. if (data)
  841. {
  842. FILE *f = fopen(fileName.c_str(),"w");
  843. Testing::nbSamples_t i=0;
  844. uint16_t t;
  845. float16_t v;
  846. for(i=0; i < nb; i++)
  847. {
  848. v = data[i];
  849. t = TOINT16(v);
  850. fprintf(f,"0x0000%04x\n",t);
  851. }
  852. fclose(f);
  853. }
  854. }
  855. #endif
  856. void Semihosting::DumpPattern_q63(Testing::outputID_t id,Testing::nbSamples_t nb, q63_t* data)
  857. {
  858. std::string fileName = this->getOutputPath(id);
  859. if (data)
  860. {
  861. FILE *f = fopen(fileName.c_str(),"w");
  862. Testing::nbSamples_t i=0;
  863. uint64_t t;
  864. for(i=0; i < nb; i++)
  865. {
  866. t = (uint64_t)data[i];
  867. fprintf(f,"0x%016llx\n",t);
  868. }
  869. fclose(f);
  870. }
  871. }
  872. void Semihosting::DumpPattern_q31(Testing::outputID_t id,Testing::nbSamples_t nb, q31_t* data)
  873. {
  874. std::string fileName = this->getOutputPath(id);
  875. if (data)
  876. {
  877. FILE *f = fopen(fileName.c_str(),"w");
  878. Testing::nbSamples_t i=0;
  879. uint32_t t;
  880. for(i=0; i < nb; i++)
  881. {
  882. t = (uint32_t)data[i];
  883. fprintf(f,"0x%08x\n",t);
  884. }
  885. fclose(f);
  886. }
  887. }
  888. void Semihosting::DumpPattern_q15(Testing::outputID_t id,Testing::nbSamples_t nb, q15_t* data)
  889. {
  890. std::string fileName = this->getOutputPath(id);
  891. if (data)
  892. {
  893. FILE *f = fopen(fileName.c_str(),"w");
  894. Testing::nbSamples_t i=0;
  895. uint32_t t;
  896. for(i=0; i < nb; i++)
  897. {
  898. t = (uint32_t)data[i];
  899. fprintf(f,"0x%08x\n",t);
  900. }
  901. fclose(f);
  902. }
  903. }
  904. void Semihosting::DumpPattern_q7(Testing::outputID_t id,Testing::nbSamples_t nb, q7_t* data)
  905. {
  906. std::string fileName = this->getOutputPath(id);
  907. if (data)
  908. {
  909. FILE *f = fopen(fileName.c_str(),"w");
  910. Testing::nbSamples_t i=0;
  911. uint32_t t;
  912. for(i=0; i < nb; i++)
  913. {
  914. t = (uint32_t)data[i];
  915. fprintf(f,"0x%08x\n",t);
  916. }
  917. fclose(f);
  918. }
  919. }
  920. void Semihosting::DumpPattern_u32(Testing::outputID_t id,Testing::nbSamples_t nb, uint32_t* data)
  921. {
  922. std::string fileName = this->getOutputPath(id);
  923. if (data)
  924. {
  925. FILE *f = fopen(fileName.c_str(),"w");
  926. Testing::nbSamples_t i=0;
  927. uint32_t t;
  928. for(i=0; i < nb; i++)
  929. {
  930. t = (uint32_t)data[i];
  931. fprintf(f,"0x%08x\n",t);
  932. }
  933. fclose(f);
  934. }
  935. }
  936. void Semihosting::DumpPattern_u16(Testing::outputID_t id,Testing::nbSamples_t nb, uint16_t* data)
  937. {
  938. std::string fileName = this->getOutputPath(id);
  939. if (data)
  940. {
  941. FILE *f = fopen(fileName.c_str(),"w");
  942. Testing::nbSamples_t i=0;
  943. uint32_t t;
  944. for(i=0; i < nb; i++)
  945. {
  946. t = (uint32_t)data[i];
  947. fprintf(f,"0x%08x\n",t);
  948. }
  949. fclose(f);
  950. }
  951. }
  952. void Semihosting::DumpPattern_u8(Testing::outputID_t id,Testing::nbSamples_t nb, uint8_t* data)
  953. {
  954. std::string fileName = this->getOutputPath(id);
  955. if (data)
  956. {
  957. FILE *f = fopen(fileName.c_str(),"w");
  958. Testing::nbSamples_t i=0;
  959. uint32_t t;
  960. for(i=0; i < nb; i++)
  961. {
  962. t = (uint32_t)data[i];
  963. fprintf(f,"0x%08x\n",t);
  964. }
  965. fclose(f);
  966. }
  967. }
  968. }