Semihosting.cpp 32 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214
  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_u64(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. uint64_t val;
  715. uint64_t *ptr=(uint64_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%016llX\n",&val);
  734. *ptr = val;
  735. ptr++;
  736. }
  737. }
  738. fclose(pattern);
  739. }
  740. void Semihosting::ImportPattern_u32(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. uint32_t *ptr=(uint32_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 = val;
  766. ptr++;
  767. }
  768. }
  769. fclose(pattern);
  770. }
  771. void Semihosting::ImportPattern_u16(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. uint16_t *ptr=(uint16_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 = (uint16_t)val;
  797. ptr++;
  798. }
  799. }
  800. fclose(pattern);
  801. }
  802. void Semihosting::ImportPattern_u8(Testing::PatternID_t id,char* p,Testing::nbSamples_t nb)
  803. {
  804. char tmp[256];
  805. Testing::nbSamples_t len;
  806. Testing::nbSamples_t i=0;
  807. uint32_t val;
  808. uint8_t *ptr=(uint8_t*)p;
  809. std::string fileName = this->getPatternPath(id);
  810. FILE *pattern=fopen(fileName.c_str(), "r");
  811. // Ignore word size format
  812. fgets(tmp,256,pattern);
  813. // Get nb of samples
  814. fgets(tmp,256,pattern);
  815. len=atoi(tmp);
  816. if ((nb != MAX_NB_SAMPLES) && (nb < len))
  817. {
  818. len = nb;
  819. }
  820. if (ptr)
  821. {
  822. for(i=0;i<len;i++)
  823. {
  824. // Ignore comment
  825. fgets(tmp,256,pattern);
  826. fscanf(pattern,"0x%08X\n",&val);
  827. *ptr = (uint8_t)val;
  828. ptr++;
  829. }
  830. }
  831. fclose(pattern);
  832. }
  833. void Semihosting::DumpPattern_f64(Testing::outputID_t id,Testing::nbSamples_t nb, float64_t* data)
  834. {
  835. std::string fileName = this->getOutputPath(id);
  836. if (data)
  837. {
  838. FILE *f = fopen(fileName.c_str(),"w");
  839. Testing::nbSamples_t i=0;
  840. uint64_t t;
  841. float64_t v;
  842. for(i=0; i < nb; i++)
  843. {
  844. v = data[i];
  845. t = TOINT64(v);
  846. fprintf(f,"0x%016llx\n",t);
  847. }
  848. fclose(f);
  849. }
  850. }
  851. void Semihosting::DumpPattern_f32(Testing::outputID_t id,Testing::nbSamples_t nb, float32_t* data)
  852. {
  853. std::string fileName = this->getOutputPath(id);
  854. if (data)
  855. {
  856. FILE *f = fopen(fileName.c_str(),"w");
  857. Testing::nbSamples_t i=0;
  858. uint32_t t;
  859. float32_t v;
  860. for(i=0; i < nb; i++)
  861. {
  862. v = data[i];
  863. t = TOINT32(v);
  864. fprintf(f,"0x%08x\n",t);
  865. }
  866. fclose(f);
  867. }
  868. }
  869. #if !defined( __CC_ARM ) && defined(ARM_FLOAT16_SUPPORTED)
  870. void Semihosting::DumpPattern_f16(Testing::outputID_t id,Testing::nbSamples_t nb, float16_t* data)
  871. {
  872. std::string fileName = this->getOutputPath(id);
  873. if (data)
  874. {
  875. FILE *f = fopen(fileName.c_str(),"w");
  876. Testing::nbSamples_t i=0;
  877. uint16_t t;
  878. float16_t v;
  879. for(i=0; i < nb; i++)
  880. {
  881. v = data[i];
  882. t = TOINT16(v);
  883. fprintf(f,"0x0000%04x\n",t);
  884. }
  885. fclose(f);
  886. }
  887. }
  888. #endif
  889. void Semihosting::DumpPattern_q63(Testing::outputID_t id,Testing::nbSamples_t nb, q63_t* data)
  890. {
  891. std::string fileName = this->getOutputPath(id);
  892. if (data)
  893. {
  894. FILE *f = fopen(fileName.c_str(),"w");
  895. Testing::nbSamples_t i=0;
  896. uint64_t t;
  897. for(i=0; i < nb; i++)
  898. {
  899. t = (uint64_t)data[i];
  900. fprintf(f,"0x%016llx\n",t);
  901. }
  902. fclose(f);
  903. }
  904. }
  905. void Semihosting::DumpPattern_q31(Testing::outputID_t id,Testing::nbSamples_t nb, q31_t* data)
  906. {
  907. std::string fileName = this->getOutputPath(id);
  908. if (data)
  909. {
  910. FILE *f = fopen(fileName.c_str(),"w");
  911. Testing::nbSamples_t i=0;
  912. uint32_t t;
  913. for(i=0; i < nb; i++)
  914. {
  915. t = (uint32_t)data[i];
  916. fprintf(f,"0x%08x\n",t);
  917. }
  918. fclose(f);
  919. }
  920. }
  921. void Semihosting::DumpPattern_q15(Testing::outputID_t id,Testing::nbSamples_t nb, q15_t* data)
  922. {
  923. std::string fileName = this->getOutputPath(id);
  924. if (data)
  925. {
  926. FILE *f = fopen(fileName.c_str(),"w");
  927. Testing::nbSamples_t i=0;
  928. uint32_t t;
  929. for(i=0; i < nb; i++)
  930. {
  931. t = (uint32_t)data[i];
  932. fprintf(f,"0x%08x\n",t);
  933. }
  934. fclose(f);
  935. }
  936. }
  937. void Semihosting::DumpPattern_q7(Testing::outputID_t id,Testing::nbSamples_t nb, q7_t* data)
  938. {
  939. std::string fileName = this->getOutputPath(id);
  940. if (data)
  941. {
  942. FILE *f = fopen(fileName.c_str(),"w");
  943. Testing::nbSamples_t i=0;
  944. uint32_t t;
  945. for(i=0; i < nb; i++)
  946. {
  947. t = (uint32_t)data[i];
  948. fprintf(f,"0x%08x\n",t);
  949. }
  950. fclose(f);
  951. }
  952. }
  953. void Semihosting::DumpPattern_u64(Testing::outputID_t id,Testing::nbSamples_t nb, uint64_t* data)
  954. {
  955. std::string fileName = this->getOutputPath(id);
  956. if (data)
  957. {
  958. FILE *f = fopen(fileName.c_str(),"w");
  959. Testing::nbSamples_t i=0;
  960. uint64_t t;
  961. for(i=0; i < nb; i++)
  962. {
  963. t = (uint64_t)data[i];
  964. fprintf(f,"0x%016llx\n",t);
  965. }
  966. fclose(f);
  967. }
  968. }
  969. void Semihosting::DumpPattern_u32(Testing::outputID_t id,Testing::nbSamples_t nb, uint32_t* data)
  970. {
  971. std::string fileName = this->getOutputPath(id);
  972. if (data)
  973. {
  974. FILE *f = fopen(fileName.c_str(),"w");
  975. Testing::nbSamples_t i=0;
  976. uint32_t t;
  977. for(i=0; i < nb; i++)
  978. {
  979. t = (uint32_t)data[i];
  980. fprintf(f,"0x%08x\n",t);
  981. }
  982. fclose(f);
  983. }
  984. }
  985. void Semihosting::DumpPattern_u16(Testing::outputID_t id,Testing::nbSamples_t nb, uint16_t* data)
  986. {
  987. std::string fileName = this->getOutputPath(id);
  988. if (data)
  989. {
  990. FILE *f = fopen(fileName.c_str(),"w");
  991. Testing::nbSamples_t i=0;
  992. uint32_t t;
  993. for(i=0; i < nb; i++)
  994. {
  995. t = (uint32_t)data[i];
  996. fprintf(f,"0x%08x\n",t);
  997. }
  998. fclose(f);
  999. }
  1000. }
  1001. void Semihosting::DumpPattern_u8(Testing::outputID_t id,Testing::nbSamples_t nb, uint8_t* data)
  1002. {
  1003. std::string fileName = this->getOutputPath(id);
  1004. if (data)
  1005. {
  1006. FILE *f = fopen(fileName.c_str(),"w");
  1007. Testing::nbSamples_t i=0;
  1008. uint32_t t;
  1009. for(i=0; i < nb; i++)
  1010. {
  1011. t = (uint32_t)data[i];
  1012. fprintf(f,"0x%08x\n",t);
  1013. }
  1014. fclose(f);
  1015. }
  1016. }
  1017. }