IORunner.cpp 8.7 KB

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