IORunner.cpp 9.3 KB

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