Semihosting.cpp 31 KB

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