IORunner.cpp 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360
  1. /* ----------------------------------------------------------------------
  2. * Project: CMSIS DSP Library
  3. * Title: IORunner.cpp
  4. * Description: IORunner
  5. *
  6. * Runner implementation for runner running on device
  7. * under test
  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 <stdlib.h>
  35. #include <stdio.h>
  36. #include "IORunner.h"
  37. #include "Error.h"
  38. #include "Timing.h"
  39. #include "arm_math.h"
  40. #include "Calibrate.h"
  41. #define CALIBNB 20
  42. namespace Client
  43. {
  44. IORunner::IORunner(IO *io,PatternMgr *mgr, Testing::RunningMode runningMode):m_io(io), m_mgr(mgr)
  45. {
  46. Testing::cycles_t current;
  47. this->m_runningMode = runningMode;
  48. // Set running mode on PatternMgr.
  49. if (runningMode == Testing::kDumpOnly)
  50. {
  51. mgr->setDumpMode();
  52. }
  53. if (runningMode == Testing::kTestAndDump)
  54. {
  55. mgr->setTestAndDumpMode();
  56. }
  57. initCycleMeasurement();
  58. /*
  59. For calibration :
  60. Calibration means, in this context, removing the overhad of calling
  61. a C++ function pointer from the cycle measurements.
  62. */
  63. Calibrate c((Testing::testID_t)0);
  64. Client::Suite *s=(Client::Suite *)&c;
  65. Client::test t = (Client::test)&Calibrate::empty;
  66. calibration = 0;
  67. /*
  68. EXTBENCH is set when benchmarking is done through external traces
  69. instead of using internal counters.
  70. Currently the post-processing scripts are only supporting traces generated from
  71. fast models.
  72. */
  73. #ifdef EXTBENCH
  74. startSection();
  75. #endif
  76. /*
  77. For calibration, we measure the time it takes to call 20 times an empty benchmark and compute
  78. the average.
  79. (20 is an arbitrary value.)
  80. This overhead is removed from benchmarks in the Runner..
  81. Calibration is removed from the python script when external trace is used for the cycles.
  82. Indeed, in that case the calibration value can only be measured by parsing the trace.
  83. Otherwise, the calibration is measured below.
  84. */
  85. for(int i=0;i < CALIBNB;i++)
  86. {
  87. cycleMeasurementStart();
  88. if (!m_mgr->HasMemError())
  89. {
  90. (s->*t)();
  91. }
  92. #ifndef EXTBENCH
  93. current = getCycles();
  94. #endif
  95. calibration += current;
  96. cycleMeasurementStop();
  97. }
  98. #ifdef EXTBENCH
  99. stopSection();
  100. #endif
  101. #ifndef EXTBENCH
  102. calibration=calibration / CALIBNB;
  103. #endif
  104. }
  105. // Testing.
  106. // When false we are in dump mode and the failed assertion are ignored
  107. // (But exception is taken so assert should be at end of the test and not in the
  108. // middle )
  109. IORunner::IORunner(IO *io,PatternMgr *mgr):m_io(io), m_mgr(mgr)
  110. {
  111. this->m_runningMode = Testing::kTestOnly;
  112. }
  113. IORunner::~IORunner()
  114. {
  115. }
  116. /** Read driver data to control execution of a suite
  117. */
  118. Testing::TestStatus IORunner::run(Suite *s)
  119. {
  120. Testing::TestStatus finalResult = Testing::kTestPassed;
  121. int nbTests = s->getNbTests();
  122. int failedTests=0;
  123. Testing::errorID_t error=0;
  124. unsigned long line = 0;
  125. char details[200];
  126. Testing::cycles_t cycles=0;
  127. Testing::nbParameters_t nbParams;
  128. // Read node identification (suite)
  129. m_io->ReadIdentification();
  130. // Read suite nb of parameters
  131. nbParams = m_io->ReadNbParameters();
  132. // Read list of patterns
  133. m_io->ReadPatternList();
  134. // Read list of output
  135. m_io->ReadOutputList();
  136. // Read list of parameters
  137. m_io->ReadParameterList(nbParams);
  138. // Iterate on tests
  139. for(int i=1; i <= nbTests; i++)
  140. {
  141. test t = s->getTest(i);
  142. Testing::TestStatus result = Testing::kTestPassed;
  143. error = UNKNOWN_ERROR;
  144. line = 0;
  145. cycles = 0;
  146. details[0]='\0';
  147. Testing::param_t *paramData=NULL;
  148. Testing::nbParameterEntries_t entries=0;
  149. std::vector<Testing::param_t> params(nbParams);
  150. bool canExecute=true;
  151. int dataIndex=0;
  152. Testing::ParameterKind paramKind;
  153. // Read test identification (test ID)
  154. m_io->ReadTestIdentification();
  155. if (m_io->hasParam())
  156. {
  157. Testing::PatternID_t paramID=m_io->getParamID();
  158. paramData = m_io->ImportParams(paramID,entries,paramKind);
  159. dataIndex = 0;
  160. }
  161. while(canExecute)
  162. {
  163. canExecute = false;
  164. if (m_io->hasParam() && paramData)
  165. {
  166. // Load new params
  167. for(int j=0; j < nbParams ; j++)
  168. {
  169. params[j] = paramData[nbParams*dataIndex+j];
  170. }
  171. // Update condition for new execution
  172. dataIndex += 1;
  173. canExecute = dataIndex < entries;
  174. }
  175. // Execute test
  176. try {
  177. // Prepare memory for test
  178. // setUp will generally load patterns
  179. // and do specific initialization for the tests
  180. s->setUp(m_io->CurrentTestID(),params,m_mgr);
  181. // Run the test once to force the code to be in cache.
  182. // By default it is disabled in the suite.
  183. if (s->isForcedInCache())
  184. {
  185. if (!m_mgr->HasMemError())
  186. {
  187. (s->*t)();
  188. }
  189. }
  190. // Run the test
  191. cycleMeasurementStart();
  192. #ifdef EXTBENCH
  193. startSection();
  194. #endif
  195. if (!m_mgr->HasMemError())
  196. {
  197. (s->*t)();
  198. }
  199. #ifdef EXTBENCH
  200. stopSection();
  201. #endif
  202. #ifndef EXTBENCH
  203. cycles=getCycles();
  204. cycles=cycles-calibration;
  205. #endif
  206. cycleMeasurementStop();
  207. }
  208. catch(Error &ex)
  209. {
  210. cycleMeasurementStop();
  211. // In dump only mode we ignore the tests
  212. // since the reference patterns are not loaded
  213. // so tests will fail.
  214. if (this->m_runningMode != Testing::kDumpOnly)
  215. {
  216. error = ex.errorID;
  217. line = ex.lineNumber;
  218. strcpy(details,ex.details);
  219. result=Testing::kTestFailed;
  220. }
  221. }
  222. catch (...) {
  223. cycleMeasurementStop();
  224. // In dump only mode we ignore the tests
  225. // since the reference patterns are not loaded
  226. // so tests will fail.
  227. if (this->m_runningMode != Testing::kDumpOnly)
  228. {
  229. result = Testing::kTestFailed;
  230. error = UNKNOWN_ERROR;
  231. line = 0;
  232. }
  233. }
  234. try {
  235. // Clean memory after this test
  236. // May dump output and do specific cleaning for a test
  237. s->tearDown(m_io->CurrentTestID(),m_mgr);
  238. }
  239. catch(...)
  240. {
  241. }
  242. if (m_mgr->HasMemError())
  243. {
  244. /* We keep the current error if set.
  245. */
  246. if (result == Testing::kTestPassed)
  247. {
  248. result = Testing::kTestFailed;
  249. error = MEMORY_ALLOCATION_ERROR;
  250. line = 0;
  251. }
  252. }
  253. // Free all memory of memory manager so that next test
  254. // is starting in a clean and controlled tests
  255. m_mgr->freeAll();
  256. // Dump test status to output
  257. m_io->DispStatus(result,error,line,cycles);
  258. m_io->DispErrorDetails(details);
  259. m_io->DumpParams(params);
  260. }
  261. if (paramData)
  262. {
  263. if (paramKind == Testing::kDynamicBuffer)
  264. {
  265. free(paramData);
  266. }
  267. paramData = NULL;
  268. }
  269. if (result == Testing::kTestFailed)
  270. {
  271. failedTests ++;
  272. finalResult = Testing::kTestFailed;
  273. }
  274. }
  275. // Signal end of group processing to output
  276. m_io->EndGroup();
  277. return(finalResult);
  278. }
  279. /** Read driver data to control execution of a group
  280. */
  281. Testing::TestStatus IORunner::run(Group *g)
  282. {
  283. int nbTests = g->getNbContainer();
  284. int failedTests=0;
  285. // Read Node identification
  286. m_io->ReadIdentification();
  287. Testing::TestStatus finalResult = Testing::kTestPassed;
  288. // Iterate on group elements
  289. for(int i=1; i <= nbTests; i++)
  290. {
  291. TestContainer *c = g->getContainer(i);
  292. if (c != NULL)
  293. {
  294. // Execute runner for this group
  295. Testing::TestStatus result = c->accept(this);
  296. if (result == Testing::kTestFailed)
  297. {
  298. failedTests ++;
  299. finalResult = Testing::kTestFailed;
  300. }
  301. }
  302. }
  303. // Signal to output that processing of this group has finished.
  304. m_io->EndGroup();
  305. return(finalResult);
  306. }
  307. }