IORunner.cpp 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  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. namespace Client
  39. {
  40. IORunner::IORunner(IO *io,PatternMgr *mgr, Testing::RunningMode runningMode):m_io(io), m_mgr(mgr)
  41. {
  42. this->m_runningMode = runningMode;
  43. // Set running mode on PatternMgr.
  44. if (runningMode == Testing::kDumpOnly)
  45. {
  46. mgr->setDumpMode();
  47. }
  48. if (runningMode == Testing::kTestAndDump)
  49. {
  50. mgr->setTestAndDumpMode();
  51. }
  52. initCycleMeasurement();
  53. }
  54. // Testing.
  55. // When false we are in dump mode and the failed assertion are ignored
  56. // (But exception is taken so assert should be at end of the test and not in the
  57. // middle )
  58. IORunner::IORunner(IO *io,PatternMgr *mgr):m_io(io), m_mgr(mgr)
  59. {
  60. this->m_runningMode = Testing::kTestOnly;
  61. }
  62. IORunner::~IORunner()
  63. {
  64. }
  65. /** Read driver data to control execution of a suite
  66. */
  67. Testing::TestStatus IORunner::run(Suite *s)
  68. {
  69. Testing::TestStatus finalResult = Testing::kTestPassed;
  70. int nbTests = s->getNbTests();
  71. int failedTests=0;
  72. Testing::errorID_t error=0;
  73. unsigned long line = 0;
  74. Testing::cycles_t cycles=0;
  75. Testing::nbParameters_t nbParams;
  76. // Read node identification (suite)
  77. m_io->ReadIdentification();
  78. // Read suite nb of parameters
  79. nbParams = m_io->ReadNbParameters();
  80. // Read list of patterns
  81. m_io->ReadPatternList();
  82. // Read list of output
  83. m_io->ReadOutputList();
  84. // Read list of parameters
  85. m_io->ReadParameterList(nbParams);
  86. // Iterate on tests
  87. for(int i=1; i <= nbTests; i++)
  88. {
  89. test t = s->getTest(i);
  90. Testing::TestStatus result = Testing::kTestPassed;
  91. error = UNKNOWN_ERROR;
  92. line = 0;
  93. cycles = 0;
  94. Testing::param_t *paramData=NULL;
  95. Testing::nbParameterEntries_t entries=0;
  96. std::vector<Testing::param_t> params(nbParams);
  97. bool canExecute=true;
  98. int dataIndex=0;
  99. // Read test identification (test ID)
  100. m_io->ReadTestIdentification();
  101. if (m_io->hasParam())
  102. {
  103. Testing::PatternID_t paramID=m_io->getParamID();
  104. paramData = m_io->ImportParams(paramID,entries);
  105. dataIndex = 0;
  106. }
  107. while(canExecute)
  108. {
  109. canExecute = false;
  110. if (m_io->hasParam() && paramData)
  111. {
  112. // Load new params
  113. for(int j=0; j < nbParams ; j++)
  114. {
  115. params[j] = paramData[nbParams*dataIndex+j];
  116. }
  117. // Update condition for new execution
  118. dataIndex += 1;
  119. canExecute = dataIndex < entries;
  120. }
  121. // Execute test
  122. try {
  123. // Prepare memory for test
  124. // setUp will generally load patterns
  125. // and do specific initialization for the tests
  126. s->setUp(m_io->CurrentTestID(),params,m_mgr);
  127. // Run the test
  128. cycleMeasurementStart();
  129. (s->*t)();
  130. cycles=getCycles();
  131. cycleMeasurementStop();
  132. }
  133. catch(Error &ex)
  134. {
  135. // In dump only mode we ignore the tests
  136. // since the reference patterns are not loaded
  137. // so tests will fail.
  138. if (this->m_runningMode != Testing::kDumpOnly)
  139. {
  140. error = ex.errorID;
  141. line = ex.lineNumber;
  142. result=Testing::kTestFailed;
  143. }
  144. }
  145. catch (...) {
  146. // In dump only mode we ignore the tests
  147. // since the reference patterns are not loaded
  148. // so tests will fail.
  149. if (this->m_runningMode != Testing::kDumpOnly)
  150. {
  151. result = Testing::kTestFailed;
  152. error = UNKNOWN_ERROR;
  153. line = 0;
  154. }
  155. }
  156. try {
  157. // Clean memory after this test
  158. // May dump output and do specific cleaning for a test
  159. s->tearDown(m_io->CurrentTestID(),m_mgr);
  160. }
  161. catch(...)
  162. {
  163. }
  164. // Free all memory of memory manager so that next test
  165. // is starting in a clean and controlled tests
  166. m_mgr->freeAll();
  167. // Dump test status to output
  168. m_io->DispStatus(result,error,line,cycles);
  169. m_io->DumpParams(params);
  170. }
  171. if (paramData)
  172. {
  173. free(paramData);
  174. paramData = NULL;
  175. }
  176. if (result == Testing::kTestFailed)
  177. {
  178. failedTests ++;
  179. finalResult = Testing::kTestFailed;
  180. }
  181. }
  182. // Signal end of group processing to output
  183. m_io->EndGroup();
  184. return(finalResult);
  185. }
  186. /** Read driver data to control execution of a group
  187. */
  188. Testing::TestStatus IORunner::run(Group *g)
  189. {
  190. int nbTests = g->getNbContainer();
  191. int failedTests=0;
  192. // Read Node identification
  193. m_io->ReadIdentification();
  194. Testing::TestStatus finalResult = Testing::kTestPassed;
  195. // Iterate on group elements
  196. for(int i=1; i <= nbTests; i++)
  197. {
  198. TestContainer *c = g->getContainer(i);
  199. if (c != NULL)
  200. {
  201. // Execute runner for this group
  202. Testing::TestStatus result = c->accept(this);
  203. if (result == Testing::kTestFailed)
  204. {
  205. failedTests ++;
  206. finalResult = Testing::kTestFailed;
  207. }
  208. }
  209. }
  210. // Signal to output that processing of this group has finished.
  211. m_io->EndGroup();
  212. return(finalResult);
  213. }
  214. }