| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156 |
- /* ----------------------------------------------------------------------
- * Project: CMSIS DSP Library
- * Title: Semihosting.cpp
- * Description: Semihosting io
- *
- * IO for a platform supporting semihosting.
- * (Several input and output files)
- *
- * $Date: 20. June 2019
- * $Revision: V1.0.0
- *
- * Target Processor: Cortex-M cores
- * -------------------------------------------------------------------- */
- /*
- * Copyright (C) 2010-2019 ARM Limited or its affiliates. All rights reserved.
- *
- * SPDX-License-Identifier: Apache-2.0
- *
- * Licensed under the Apache License, Version 2.0 (the License); you may
- * not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an AS IS BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
- #include "Test.h"
- #include <string>
- #include <cstddef>
- #include <stdio.h>
- #include <string.h>
- #include <stdlib.h>
- #include "Generators.h"
- #include "Semihosting.h"
- namespace Client
- {
-
- struct pathOrGen {
- int kind;
- std::string path;
- Testing::param_t *data;
- Testing::nbSamples_t nbInputSamples;
- Testing::nbSamples_t nbOutputSamples;
- int dimensions;
- };
- Semihosting::Semihosting(std::string path,std::string patternRootPath,std::string outputRootPath,std::string parameterRootPath)
- {
- // Open the driver file
- this->infile=fopen(path.c_str(), "r");
- this->path=new std::vector<std::string>();
- this->patternRootPath=patternRootPath;
- this->outputRootPath=outputRootPath;
- this->parameterRootPath=parameterRootPath;
- this->patternFilenames=new std::vector<std::string>();
- this->outputNames=new std::vector<std::string>();
- this->parameterNames=new std::vector<struct pathOrGen>();
- this->m_hasParam = false;
- }
- void Semihosting::DeleteParams()
- {
- for (std::vector<struct pathOrGen>::iterator it = this->parameterNames->begin() ; it != this->parameterNames->end(); ++it)
- {
- if (it->kind==1)
- {
- if (it->data)
- {
- free(it->data);
- it->data = NULL;
- }
- }
- }
- }
- Semihosting::~Semihosting()
- {
- fclose(this->infile);
- delete(this->path);
- delete(this->patternFilenames);
- delete(this->outputNames);
- this->DeleteParams();
- delete(this->parameterNames);
- }
- /**
- Read the list of patterns from the driver file.
- This list is for the current suite.
-
- */
- void Semihosting::ReadPatternList()
- {
- char tmp[256];
- int nbPatterns;
- fscanf(this->infile,"%d\n",&nbPatterns);
- // Reset the list for the current suite
- this->patternFilenames->clear();
- std::string tmpstr;
- for(int i=0;i<nbPatterns;i++)
- {
- fgets(tmp,256,this->infile);
- // Remove end of line
- if (tmp[strlen(tmp)-1] == '\n')
- {
- tmp[strlen(tmp)-1]=0;
- }
- tmpstr.assign(tmp);
- this->patternFilenames->push_back(tmpstr);
- }
- }
- /**
- Read the list of parameters from the driver file.
- This list is for the current suite.
-
- */
- void Semihosting::ReadParameterList(Testing::nbParameters_t nbParams)
- {
- char tmp[256];
- char paramKind;
- std::string tmpstr;
- // It is the number of samples in the file.
- // Not the number of parameters controlling the function
- int nbValues;
- fscanf(this->infile,"%d\n",&nbValues);
-
- // Reset the list for the current suite
- this->DeleteParams();
- this->parameterNames->clear();
- for(int i=0;i<nbValues;i++)
- {
- fscanf(this->infile,"%c\n",¶mKind);
- struct pathOrGen gen;
- if (paramKind == 'p')
- {
- fgets(tmp,256,this->infile);
- // Remove end of line
- if (tmp[strlen(tmp)-1] == '\n')
- {
- tmp[strlen(tmp)-1]=0;
- }
- tmpstr.assign(tmp);
- std::string tmp;
- tmp += this->parameterRootPath;
- tmp += this->testDir;
- tmp += "/";
- tmp += tmpstr;
-
- gen.kind=0;
- gen.path=tmp;
- gen.nbInputSamples = this->GetFileSize(tmp);
- gen.dimensions = nbParams;
- }
- // Generator
- // Generator kind (only 1 = cartesian product generator)
- // Number of samples generated when run
- // Number of dimensions
- // For each dimension
- // Length
- // Samples
- else
- {
- int kind,nbInputSamples,nbOutputSamples,dimensions,sample;
- Testing::param_t *p,*current;
-
- // Generator kind. Not yet used since there is only one kind of generator
- fscanf(this->infile,"%d\n",&kind);
- // Input data in config file
- fscanf(this->infile,"%d\n",&nbInputSamples);
-
- // Number of output combinations
- // And each output has dimensions parameters
- fscanf(this->infile,"%d\n",&nbOutputSamples);
- fscanf(this->infile,"%d\n",&dimensions);
- p=(Testing::param_t*)malloc(sizeof(Testing::param_t)*(nbInputSamples));
- current=p;
- for(int i=0;i < nbInputSamples; i ++)
- {
-
- fscanf(this->infile,"%d\n",&sample);
- *current++ = (Testing::param_t)sample;
- }
- gen.kind=1;
- gen.data=p;
- gen.nbInputSamples = nbInputSamples;
- gen.nbOutputSamples = nbOutputSamples;
- gen.dimensions = dimensions;
- }
- this->parameterNames->push_back(gen);
- }
- }
- /**
- Read the list of output from the driver file.
- This list is for the current suite.
-
- */
- void Semihosting::ReadOutputList()
- {
- char tmp[256];
- int nbOutputs;
- fscanf(this->infile,"%d\n",&nbOutputs);
- // Reset the list for the current suite
- this->outputNames->clear();
- std::string tmpstr;
- for(int i=0;i<nbOutputs;i++)
- {
- fgets(tmp,256,this->infile);
- // Remove end of line
- if (tmp[strlen(tmp)-1] == '\n')
- {
- tmp[strlen(tmp)-1]=0;
- }
- tmpstr.assign(tmp);
- this->outputNames->push_back(tmpstr);
- }
- }
- /** Read the number of parameters for all the tests in a suite
- Used for benchmarking. Same functions executed with
- different initializations controlled by the parameters.
- It is not the number of parameters in a file
- but the number of arguments (parameters) to control a function.
- */
- Testing::nbParameters_t Semihosting::ReadNbParameters()
- {
- unsigned long nb;
- fscanf(this->infile,"%ld\n",&nb);
- return(nb);
- }
- void Semihosting::recomputeTestDir()
- {
- this->testDir = ".";
- int start = 1;
- std::vector<std::string>::const_iterator iter;
- for (iter = this->path->begin(); iter != this->path->end(); ++iter)
- {
- if (start)
- {
- this->testDir = *iter;
- start =0;
- }
- else
- {
- if (!(*iter).empty())
- {
- this->testDir += "/" + *iter;
- }
- }
- }
- }
-
- void Semihosting::ReadTestIdentification()
- {
-
- char tmp[255];
- int kind;
- Testing::testID_t theId;
- char hasPath;
- char hasParamID;
- Testing::PatternID_t paramID;
- fscanf(this->infile,"%d %ld\n",&kind,&theId);
- fscanf(this->infile,"%c\n",&hasParamID);
- this->m_hasParam=false;
- if (hasParamID == 'y')
- {
- this->m_hasParam=true;
- fscanf(this->infile,"%ld\n",¶mID);
- this->currentParam=paramID;
- }
- fscanf(this->infile,"%c\n",&hasPath);
- if (hasPath == 'y')
- {
- fgets(tmp,256,this->infile);
- // Remove end of line
- if (tmp[strlen(tmp)-1] == '\n')
- {
- tmp[strlen(tmp)-1]=0;
- }
- currentPath.assign(tmp);
- }
- this->currentKind=kind;
- this->currentId=theId;
- switch(kind)
- {
- case 1:
- printf("t \n");
- break;
- case 2:
- printf("s %ld\n",this->currentId);
- break;
- case 3:
- printf("g %ld\n",this->currentId);
- break;
- default:
- printf("u\n");
- }
- }
- Testing::testID_t Semihosting::CurrentTestID()
- {
- return(this->currentId);
- }
- /**
- Read identification of a group or suite.
- The difference with a test node is that the current folder
- can be changed by a group or suite.
-
- */
- void Semihosting::ReadIdentification()
- {
- this->ReadTestIdentification();
- this->path->push_back(currentPath);
- this->recomputeTestDir();
- }
- /**
- Dump the test status into the output (stdout)
- */
- void Semihosting::DispStatus(Testing::TestStatus status
- ,Testing::errorID_t error
- ,unsigned long lineNb
- ,Testing::cycles_t cycles)
- {
- if (status == Testing::kTestFailed)
- {
- printf("%ld %ld %ld 0 N\n",this->currentId,error,lineNb);
- }
- else
- {
- #ifdef EXTBENCH
- printf("%ld 0 0 t Y\n",this->currentId);
- #else
- printf("%ld 0 0 %u Y\n",this->currentId,cycles);
- #endif
- }
- }
- void Semihosting::DispErrorDetails(const char* details)
- {
- printf("E: %s\n",details);
- }
- /**
- Signal end of group
- (Used by scripts parsing the output to display the results)
- */
- void Semihosting::EndGroup()
- {
- printf("p\n");
- this->path->pop_back();
- }
- /**
- Get pattern path.
- */
- std::string Semihosting::getPatternPath(Testing::PatternID_t id)
- {
- std::string tmp;
- tmp += this->patternRootPath;
- tmp += this->testDir;
- tmp += "/";
- tmp += (*this->patternFilenames)[id];
-
- return(tmp);
- }
- /**
- Get parameter path.
- */
- struct pathOrGen Semihosting::getParameterDesc(Testing::PatternID_t id)
- {
-
- return((*this->parameterNames)[id]);
-
- }
- /**
- Get output path.
- The test ID (currentId) is used in the name
- */
- std::string Semihosting::getOutputPath(Testing::outputID_t id)
- {
- char fmt[256];
- std::string tmp;
- tmp += this->outputRootPath;
- tmp += this->testDir;
- sprintf(fmt,"/%s_%ld.txt",(*this->outputNames)[id].c_str(),this->currentId);
- tmp += std::string(fmt);
- //printf("%s\n",tmp.c_str());
-
- return(tmp);
- }
- Testing::nbSamples_t Semihosting::GetPatternSize(Testing::PatternID_t id)
- {
- char tmp[256];
- Testing::nbSamples_t len;
- std::string fileName = this->getPatternPath(id);
- FILE *pattern=fopen(fileName.c_str(), "r");
- if (pattern==NULL)
- {
- return(0);
- }
- // Ignore word size format
- fgets(tmp,256,pattern);
-
- // Get nb of samples
- fgets(tmp,256,pattern);
- fclose(pattern);
- len=atoi(tmp);
- return(len);
- }
- Testing::nbSamples_t Semihosting::GetFileSize(std::string &filepath)
- {
- char tmp[256];
- Testing::nbSamples_t len;
-
-
- FILE *params=fopen(filepath.c_str(), "r");
- if (params==NULL)
- {
- return(0);
- }
- // Get nb of samples
- fgets(tmp,256,params);
- fclose(params);
- len=atoi(tmp);
- return(len);
- }
- void Semihosting::DumpParams(std::vector<Testing::param_t>& params)
- {
- bool begin=true;
- printf("b ");
- for(std::vector<Testing::param_t>::iterator it = params.begin(); it != params.end(); ++it)
- {
- if (!begin)
- {
- printf(",");
- }
- printf("%d",*it);
- begin=false;
- }
- printf("\n");
- }
- Testing::param_t* Semihosting::ImportParams(Testing::PatternID_t id,Testing::nbParameterEntries_t &nbEntries,Testing::ParameterKind ¶mKind)
- {
- nbEntries = 0;
- char tmp[256];
-
- Testing::param_t *p;
- uint32_t val;
- Testing::nbSamples_t len;
- struct pathOrGen gen = this->getParameterDesc(id);
- if (gen.kind == 0)
- {
- char *result=NULL;
- paramKind=Testing::kDynamicBuffer;
- FILE *params=fopen(gen.path.c_str(), "r");
-
- if (params==NULL)
- {
- return(NULL);
- }
- // Get nb of samples
- fgets(tmp,256,params);
-
-
- len=gen.nbInputSamples;
- result=(char*)malloc(len*sizeof(Testing::param_t));
- p = (Testing::param_t*)result;
- nbEntries = len / gen.dimensions;
-
- for(uint32_t i=0; i < len; i++)
- {
- fscanf(params,"%d\n",&val);
- *p++ = val;
- }
-
-
- fclose(params);
- return((Testing::param_t*)result);
- }
- else
- {
- Testing::param_t* result;
- paramKind=Testing::kDynamicBuffer;
- // Output samples is number of parameter line
- len=gen.nbOutputSamples * gen.dimensions;
- result=(Testing::param_t*)malloc(len*sizeof(Testing::param_t));
-
-
- switch(gen.dimensions)
- {
- case 1:
- generate1(result,gen.data,nbEntries);
- break;
- case 2:
- generate2(result,gen.data,nbEntries);
- break;
- case 3:
- generate3(result,gen.data,nbEntries);
- break;
- case 4:
- generate4(result,gen.data,nbEntries);
- break;
- default:
- generate1(result,gen.data,nbEntries);
- break;
- }
-
- return(result);
- }
- }
- bool Semihosting::hasParam()
- {
- return(this->m_hasParam);
- }
- Testing::PatternID_t Semihosting::getParamID()
- {
- return(this->currentParam);
- }
- void Semihosting::ImportPattern_f64(Testing::PatternID_t id,char* p,Testing::nbSamples_t nb)
- {
- char tmp[256];
- Testing::nbSamples_t len;
- Testing::nbSamples_t i=0;
- uint64_t val;
- float64_t *ptr=(float64_t*)p;
- std::string fileName = this->getPatternPath(id);
- FILE *pattern=fopen(fileName.c_str(), "r");
- // Ignore word size format
- // word size format is used when generating include files with python scripts
- fgets(tmp,256,pattern);
- // Get nb of samples
- fgets(tmp,256,pattern);
- len=atoi(tmp);
- if ((nb != MAX_NB_SAMPLES) && (nb < len))
- {
- len = nb;
- }
- if (ptr)
- {
- for(i=0;i<len;i++)
- {
- // Ignore comment
- fgets(tmp,256,pattern);
- fscanf(pattern,"0x%16llx\n",&val);
- *ptr = TOTYP(float64_t,val);
- ptr++;
- }
- }
- fclose(pattern);
-
- }
- void Semihosting::ImportPattern_f32(Testing::PatternID_t id,char* p,Testing::nbSamples_t nb)
- {
- char tmp[256];
- Testing::nbSamples_t len;
- Testing::nbSamples_t i=0;
- uint32_t val;
- float32_t *ptr=(float32_t*)p;
- std::string fileName = this->getPatternPath(id);
- FILE *pattern=fopen(fileName.c_str(), "r");
- // Ignore word size format
- fgets(tmp,256,pattern);
- // Get nb of samples
- fgets(tmp,256,pattern);
- len=atoi(tmp);
- if ((nb != MAX_NB_SAMPLES) && (nb < len))
- {
- len = nb;
- }
- //printf(":::: %s\n",fileName.c_str());
- if (ptr)
- {
- for(i=0;i<len;i++)
- {
- // Ignore comment
- fgets(tmp,256,pattern);
- fscanf(pattern,"0x%08X\n",&val);
- //printf(":::: %08X %f\n",val, TOTYP(float32_t,val));
- *ptr = TOTYP(float32_t,val);
- ptr++;
- }
- }
- fclose(pattern);
-
- }
- #if !defined( __CC_ARM )
- void Semihosting::ImportPattern_f16(Testing::PatternID_t id,char* p,Testing::nbSamples_t nb)
- {
- char tmp[256];
- Testing::nbSamples_t len;
- Testing::nbSamples_t i=0;
- uint32_t val;
- float16_t *ptr=(float16_t*)p;
- std::string fileName = this->getPatternPath(id);
- FILE *pattern=fopen(fileName.c_str(), "r");
- // Ignore word size format
- fgets(tmp,256,pattern);
- // Get nb of samples
- fgets(tmp,256,pattern);
- len=atoi(tmp);
- if ((nb != MAX_NB_SAMPLES) && (nb < len))
- {
- len = nb;
- }
- //printf(":::: %s\n",fileName.c_str());
- if (ptr)
- {
- for(i=0;i<len;i++)
- {
- // Ignore comment
- fgets(tmp,256,pattern);
- fscanf(pattern,"0x%08X\n",&val);
- //printf(":::: %08X %f\n",val, TOTYP(float32_t,val));
- *ptr = TOTYP(float16_t,val);
- ptr++;
- }
- }
- fclose(pattern);
-
- }
- #endif
- void Semihosting::ImportPattern_q63(Testing::PatternID_t id,char* p,Testing::nbSamples_t nb)
- {
- char tmp[256];
- Testing::nbSamples_t len;
- Testing::nbSamples_t i=0;
- uint64_t val;
- q63_t *ptr=(q63_t*)p;
- std::string fileName = this->getPatternPath(id);
- FILE *pattern=fopen(fileName.c_str(), "r");
- // Ignore word size format
- fgets(tmp,256,pattern);
- // Get nb of samples
- fgets(tmp,256,pattern);
- len=atoi(tmp);
- if ((nb != MAX_NB_SAMPLES) && (nb < len))
- {
- len = nb;
- }
- if (ptr)
- {
- for(i=0;i<len;i++)
- {
- // Ignore comment
- fgets(tmp,256,pattern);
- fscanf(pattern,"0x%016llX\n",&val);
- *ptr = TOTYP(q63_t,val);
- ptr++;
- }
- }
- fclose(pattern);
-
- }
- void Semihosting::ImportPattern_q31(Testing::PatternID_t id,char* p,Testing::nbSamples_t nb)
- {
- char tmp[256];
- Testing::nbSamples_t len;
- Testing::nbSamples_t i=0;
- uint32_t val;
- q31_t *ptr=(q31_t*)p;
- std::string fileName = this->getPatternPath(id);
- FILE *pattern=fopen(fileName.c_str(), "r");
- // Ignore word size format
- fgets(tmp,256,pattern);
- // Get nb of samples
- fgets(tmp,256,pattern);
- len=atoi(tmp);
- if ((nb != MAX_NB_SAMPLES) && (nb < len))
- {
- len = nb;
- }
- if (ptr)
- {
- for(i=0;i<len;i++)
- {
- // Ignore comment
- fgets(tmp,256,pattern);
- fscanf(pattern,"0x%08X\n",&val);
- *ptr = TOTYP(q31_t,val);
- ptr++;
- }
- }
- fclose(pattern);
-
- }
- void Semihosting::ImportPattern_q15(Testing::PatternID_t id,char* p,Testing::nbSamples_t nb)
- {
- char tmp[256];
- Testing::nbSamples_t len;
- Testing::nbSamples_t i=0;
- uint32_t val;
- q15_t *ptr=(q15_t*)p;
- std::string fileName = this->getPatternPath(id);
- FILE *pattern=fopen(fileName.c_str(), "r");
- // Ignore word size format
- fgets(tmp,256,pattern);
- // Get nb of samples
- fgets(tmp,256,pattern);
- len=atoi(tmp);
- if ((nb != MAX_NB_SAMPLES) && (nb < len))
- {
- len = nb;
- }
- if (ptr)
- {
- for(i=0;i<len;i++)
- {
- // Ignore comment
- fgets(tmp,256,pattern);
- fscanf(pattern,"0x%08X\n",&val);
- *ptr = TOTYP(q15_t,val);
- ptr++;
- }
- }
- fclose(pattern);
-
- }
- void Semihosting::ImportPattern_q7(Testing::PatternID_t id,char* p,Testing::nbSamples_t nb)
- {
- char tmp[256];
- Testing::nbSamples_t len;
- Testing::nbSamples_t i=0;
- uint32_t val;
- q7_t *ptr=(q7_t*)p;
- std::string fileName = this->getPatternPath(id);
- FILE *pattern=fopen(fileName.c_str(), "r");
- // Ignore word size format
- fgets(tmp,256,pattern);
- // Get nb of samples
- fgets(tmp,256,pattern);
- len=atoi(tmp);
- if ((nb != MAX_NB_SAMPLES) && (nb < len))
- {
- len = nb;
- }
- if (ptr)
- {
- for(i=0;i<len;i++)
- {
- // Ignore comment
- fgets(tmp,256,pattern);
- fscanf(pattern,"0x%08X\n",&val);
- *ptr = TOTYP(q7_t,val);
- ptr++;
- }
- }
- fclose(pattern);
-
- }
- void Semihosting::ImportPattern_u32(Testing::PatternID_t id,char* p,Testing::nbSamples_t nb)
- {
- char tmp[256];
- Testing::nbSamples_t len;
- Testing::nbSamples_t i=0;
- uint32_t val;
- uint32_t *ptr=(uint32_t*)p;
- std::string fileName = this->getPatternPath(id);
- FILE *pattern=fopen(fileName.c_str(), "r");
- // Ignore word size format
- fgets(tmp,256,pattern);
- // Get nb of samples
- fgets(tmp,256,pattern);
- len=atoi(tmp);
- if ((nb != MAX_NB_SAMPLES) && (nb < len))
- {
- len = nb;
- }
- if (ptr)
- {
- for(i=0;i<len;i++)
- {
- // Ignore comment
- fgets(tmp,256,pattern);
- fscanf(pattern,"0x%08X\n",&val);
- *ptr = val;
- ptr++;
- }
- }
- fclose(pattern);
-
- }
- void Semihosting::ImportPattern_u16(Testing::PatternID_t id,char* p,Testing::nbSamples_t nb)
- {
- char tmp[256];
- Testing::nbSamples_t len;
- Testing::nbSamples_t i=0;
- uint32_t val;
- uint16_t *ptr=(uint16_t*)p;
- std::string fileName = this->getPatternPath(id);
- FILE *pattern=fopen(fileName.c_str(), "r");
- // Ignore word size format
- fgets(tmp,256,pattern);
- // Get nb of samples
- fgets(tmp,256,pattern);
- len=atoi(tmp);
- if ((nb != MAX_NB_SAMPLES) && (nb < len))
- {
- len = nb;
- }
- if (ptr)
- {
- for(i=0;i<len;i++)
- {
- // Ignore comment
- fgets(tmp,256,pattern);
- fscanf(pattern,"0x%08X\n",&val);
- *ptr = (uint16_t)val;
- ptr++;
- }
- }
- fclose(pattern);
-
- }
- void Semihosting::ImportPattern_u8(Testing::PatternID_t id,char* p,Testing::nbSamples_t nb)
- {
- char tmp[256];
- Testing::nbSamples_t len;
- Testing::nbSamples_t i=0;
- uint32_t val;
- uint8_t *ptr=(uint8_t*)p;
- std::string fileName = this->getPatternPath(id);
- FILE *pattern=fopen(fileName.c_str(), "r");
- // Ignore word size format
- fgets(tmp,256,pattern);
- // Get nb of samples
- fgets(tmp,256,pattern);
- len=atoi(tmp);
- if ((nb != MAX_NB_SAMPLES) && (nb < len))
- {
- len = nb;
- }
-
- if (ptr)
- {
- for(i=0;i<len;i++)
- {
- // Ignore comment
- fgets(tmp,256,pattern);
- fscanf(pattern,"0x%08X\n",&val);
- *ptr = (uint8_t)val;
- ptr++;
- }
- }
- fclose(pattern);
-
- }
- void Semihosting::DumpPattern_f64(Testing::outputID_t id,Testing::nbSamples_t nb, float64_t* data)
- {
- std::string fileName = this->getOutputPath(id);
- if (data)
- {
- FILE *f = fopen(fileName.c_str(),"w");
- Testing::nbSamples_t i=0;
- uint64_t t;
- float64_t v;
- for(i=0; i < nb; i++)
- {
- v = data[i];
- t = TOINT64(v);
- fprintf(f,"0x%016llx\n",t);
- }
- fclose(f);
- }
- }
- void Semihosting::DumpPattern_f32(Testing::outputID_t id,Testing::nbSamples_t nb, float32_t* data)
- {
- std::string fileName = this->getOutputPath(id);
- if (data)
- {
- FILE *f = fopen(fileName.c_str(),"w");
- Testing::nbSamples_t i=0;
- uint32_t t;
- float32_t v;
- for(i=0; i < nb; i++)
- {
- v = data[i];
- t = TOINT32(v);
- fprintf(f,"0x%08x\n",t);
- }
- fclose(f);
- }
- }
- #if !defined( __CC_ARM )
- void Semihosting::DumpPattern_f16(Testing::outputID_t id,Testing::nbSamples_t nb, float16_t* data)
- {
- std::string fileName = this->getOutputPath(id);
- if (data)
- {
- FILE *f = fopen(fileName.c_str(),"w");
- Testing::nbSamples_t i=0;
- uint16_t t;
- float16_t v;
- for(i=0; i < nb; i++)
- {
- v = data[i];
- t = TOINT16(v);
- fprintf(f,"0x0000%04x\n",t);
- }
- fclose(f);
- }
- }
- #endif
-
- void Semihosting::DumpPattern_q63(Testing::outputID_t id,Testing::nbSamples_t nb, q63_t* data)
- {
- std::string fileName = this->getOutputPath(id);
- if (data)
- {
- FILE *f = fopen(fileName.c_str(),"w");
- Testing::nbSamples_t i=0;
- uint64_t t;
- for(i=0; i < nb; i++)
- {
- t = (uint64_t)data[i];
- fprintf(f,"0x%016llx\n",t);
- }
- fclose(f);
- }
- }
- void Semihosting::DumpPattern_q31(Testing::outputID_t id,Testing::nbSamples_t nb, q31_t* data)
- {
- std::string fileName = this->getOutputPath(id);
- if (data)
- {
- FILE *f = fopen(fileName.c_str(),"w");
- Testing::nbSamples_t i=0;
- uint32_t t;
- for(i=0; i < nb; i++)
- {
- t = (uint32_t)data[i];
- fprintf(f,"0x%08x\n",t);
- }
- fclose(f);
- }
- }
- void Semihosting::DumpPattern_q15(Testing::outputID_t id,Testing::nbSamples_t nb, q15_t* data)
- {
- std::string fileName = this->getOutputPath(id);
- if (data)
- {
- FILE *f = fopen(fileName.c_str(),"w");
- Testing::nbSamples_t i=0;
- uint32_t t;
- for(i=0; i < nb; i++)
- {
- t = (uint32_t)data[i];
- fprintf(f,"0x%08x\n",t);
- }
- fclose(f);
- }
- }
- void Semihosting::DumpPattern_q7(Testing::outputID_t id,Testing::nbSamples_t nb, q7_t* data)
- {
- std::string fileName = this->getOutputPath(id);
- if (data)
- {
- FILE *f = fopen(fileName.c_str(),"w");
- Testing::nbSamples_t i=0;
- uint32_t t;
- for(i=0; i < nb; i++)
- {
- t = (uint32_t)data[i];
- fprintf(f,"0x%08x\n",t);
- }
- fclose(f);
- }
- }
- void Semihosting::DumpPattern_u32(Testing::outputID_t id,Testing::nbSamples_t nb, uint32_t* data)
- {
- std::string fileName = this->getOutputPath(id);
- if (data)
- {
- FILE *f = fopen(fileName.c_str(),"w");
- Testing::nbSamples_t i=0;
- uint32_t t;
- for(i=0; i < nb; i++)
- {
- t = (uint32_t)data[i];
- fprintf(f,"0x%08x\n",t);
- }
- fclose(f);
- }
- }
- void Semihosting::DumpPattern_u16(Testing::outputID_t id,Testing::nbSamples_t nb, uint16_t* data)
- {
- std::string fileName = this->getOutputPath(id);
- if (data)
- {
- FILE *f = fopen(fileName.c_str(),"w");
- Testing::nbSamples_t i=0;
- uint32_t t;
- for(i=0; i < nb; i++)
- {
- t = (uint32_t)data[i];
- fprintf(f,"0x%08x\n",t);
- }
- fclose(f);
- }
- }
- void Semihosting::DumpPattern_u8(Testing::outputID_t id,Testing::nbSamples_t nb, uint8_t* data)
- {
- std::string fileName = this->getOutputPath(id);
- if (data)
- {
- FILE *f = fopen(fileName.c_str(),"w");
- Testing::nbSamples_t i=0;
- uint32_t t;
- for(i=0; i < nb; i++)
- {
- t = (uint32_t)data[i];
- fprintf(f,"0x%08x\n",t);
- }
- fclose(f);
- }
- }
-
-
- }
|