main.cpp 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439
  1. /*
  2. * Copyright (c) 2017-2018,2020 The Linux Foundation. All rights reserved.
  3. *
  4. * Redistribution and use in source and binary forms, with or without
  5. * modification, are permitted provided that the following conditions are
  6. * met:
  7. * * Redistributions of source code must retain the above copyright
  8. * notice, this list of conditions and the following disclaimer.
  9. * * Redistributions in binary form must reproduce the above
  10. * copyright notice, this list of conditions and the following
  11. * disclaimer in the documentation and/or other materials provided
  12. * with the distribution.
  13. * * Neither the name of The Linux Foundation nor the names of its
  14. * contributors may be used to endorse or promote products derived
  15. * from this software without specific prior written permission.
  16. *
  17. * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
  18. * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  19. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
  20. * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
  21. * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  22. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  23. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
  24. * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
  25. * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
  26. * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
  27. * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  28. *
  29. * Changes from Qualcomm Innovation Center are provided under the following license:
  30. *
  31. * Copyright (c) 2022 Qualcomm Innovation Center, Inc. All rights reserved.
  32. *
  33. * Redistribution and use in source and binary forms, with or without
  34. * modification, are permitted (subject to the limitations in the
  35. * disclaimer below) provided that the following conditions are met:
  36. *
  37. * * Redistributions of source code must retain the above copyright
  38. * notice, this list of conditions and the following disclaimer.
  39. *
  40. * * Redistributions in binary form must reproduce the above
  41. * copyright notice, this list of conditions and the following
  42. * disclaimer in the documentation and/or other materials provided
  43. * with the distribution.
  44. *
  45. * * Neither the name of Qualcomm Innovation Center, Inc. nor the names of its
  46. * contributors may be used to endorse or promote products derived
  47. * from this software without specific prior written permission.
  48. *
  49. * NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE
  50. * GRANTED BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT
  51. * HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
  52. * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  53. * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  54. * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
  55. * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  56. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
  57. * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  58. * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
  59. * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
  60. * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
  61. * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE
  62. */
  63. #include <getopt.h>
  64. #include "Logger.h"
  65. #include "TestManager.h"
  66. #include "TestsUtils.h"
  67. #include <stdio.h>
  68. #include <iostream>
  69. #include <set>
  70. ///////////////////////////////////////////////////////////
  71. Logger g_Logger(LOG_ERROR);
  72. #define CHOOSER_MODE "--chooser"
  73. #define SHOW_TEST_FLAG "--show_tests"
  74. #define SHOW_SUIT_FLAG "--show_suites"
  75. #define RUN_TEST_FLAG "--test"
  76. #define RUN_SUIT_FLAG "--suite"
  77. string sFormat = "ip_accelerator <control_flag> <suit/name>, ..., <suit/name>\n"
  78. "contorl_flag = " RUN_TEST_FLAG " or " RUN_SUIT_FLAG "\n"
  79. "ip_accelerator " SHOW_TEST_FLAG "\n"
  80. "ip_accelerator " SHOW_SUIT_FLAG "\n"
  81. "or ip_accelerator --chooser "
  82. "for menu chooser interface\n";
  83. #define MAX_SUITES 19
  84. #undef strcasesame
  85. #define strcasesame(x, y) \
  86. (! strcasecmp((x), (y)))
  87. #undef legal_nat_mem_type
  88. #define legal_nat_mem_type(mt) \
  89. ( strcasesame(mt, "DDR") || \
  90. strcasesame(mt, "SRAM") || \
  91. strcasesame(mt, "HYBRID") )
  92. TestManager *testmanager = NULL;
  93. enum ipa_test_type{
  94. TEST = 1,
  95. SUITE,
  96. EXIT,
  97. MAX_TYPE
  98. };
  99. const char *ipa_hw_type_name[] = {
  100. "None",
  101. "1.0",
  102. "1.1",
  103. "2.0",
  104. "2.1",
  105. "2.5/2.6",
  106. "2.6L",
  107. "Unused",
  108. "Unused",
  109. "Unused",
  110. "3.0",
  111. "3.1",
  112. "3.5",
  113. "3.5.1",
  114. "4.0",
  115. "4.1",
  116. "4.2",
  117. "4.5",
  118. "4.7",
  119. "4.9",
  120. "4.11",
  121. "5.0",
  122. "5.1",
  123. "5.5",
  124. "MAX"
  125. };
  126. void BuildRegressionTestSuite()
  127. {
  128. TestBase *test;
  129. for (unsigned int i = 0; i < testmanager->m_testList.size(); i++) {
  130. test = testmanager->m_testList[i];
  131. if (test->m_runInRegression) {
  132. test->m_testSuiteName.push_back("Regression");
  133. }
  134. }
  135. }
  136. ///////////////////////////////////////////////////////////
  137. void showTests()
  138. {
  139. TestBase *test = testmanager->m_testList[0];
  140. for (unsigned i = 0; i < testmanager->m_testList.size(); i++) {
  141. test = testmanager->m_testList[i];
  142. string name = test->m_name, index = test->m_testSuiteName[0];
  143. printf("%d) %s (part of %s suite" ,i+1, name.c_str(), index.c_str());
  144. for (unsigned j = 0; j < test->m_testSuiteName.size(); ++j) {
  145. if ( test->m_testSuiteName[j] == index)
  146. continue;
  147. printf(", %s suite",
  148. test->m_testSuiteName[j].c_str());
  149. index = test->m_testSuiteName[j];
  150. }
  151. printf("), (%s <= HW Version <= %s)\n",
  152. ipa_hw_type_name[test->m_minIPAHwType],
  153. ipa_hw_type_name[test->m_maxIPAHwType]);
  154. }
  155. // Example:
  156. // 15) DmaModeMBIMggregationLoopTest (part of DmaMbim16Agg suite), (1.0 <= HW Version <= 2.1)
  157. }
  158. void showSuits()
  159. {
  160. TestBase *test;
  161. std::set<string> suiteSet;
  162. int suiteIndex = 1;
  163. test = testmanager->m_testList[0];
  164. for (unsigned i = 0; i < testmanager->m_testList.size(); i++) {
  165. test = testmanager->m_testList[i];
  166. for (unsigned j = 0; j < test->m_testSuiteName.size() ; j++)
  167. suiteSet.insert(test->m_testSuiteName[j]);
  168. }
  169. for (std::set<string>::iterator i = suiteSet.begin();
  170. i != suiteSet.end(); suiteIndex++) {
  171. printf("%d) %s\n", suiteIndex, (*i).c_str());
  172. ++i;
  173. }
  174. }
  175. void preparTests(int argc, char* argv[],
  176. vector<string>& list)
  177. {
  178. for (int i = 2; i < argc; i++)
  179. list.push_back(argv[i]);
  180. }
  181. const char* getSuite(int suite_num) {
  182. int count = 0, suiteIndex = 1;
  183. string result = "error";
  184. TestBase *test = testmanager->m_testList[0];
  185. set<string> suiteSet;
  186. if (testmanager->m_testList.size() < 1)
  187. return NULL;
  188. if (count == suite_num)
  189. return testmanager->m_testList[0]->m_testSuiteName[0].c_str();
  190. for (unsigned i = 0; i < testmanager->m_testList.size(); i++) {
  191. test = testmanager->m_testList[i];
  192. for (unsigned j = 0; j < test->m_testSuiteName.size() ; j++)
  193. suiteSet.insert(test->m_testSuiteName[j]);
  194. }
  195. for (std::set<string>::iterator i = suiteSet.begin();
  196. i != suiteSet.end(); suiteIndex++) {
  197. printf("%d) %s\n", suiteIndex, (*i).c_str());
  198. if (suiteIndex == suite_num)
  199. return (*i).c_str();
  200. ++i;
  201. }
  202. return NULL;
  203. }
  204. int chooserMode() {
  205. vector<string> testSuiteList;
  206. vector<string> testNameList;
  207. unsigned int test_num;
  208. int suite_num;
  209. int type;
  210. TestBase *test;
  211. const char* res;
  212. int result = 0;
  213. char input_str[4];
  214. char* temp;
  215. printf("Welcome to the ip_accelerator\nChoose an option:\n");
  216. printf("1) Run tests\n2) Run suites\n3) Exit\nChoose an option: ");
  217. temp = fgets(input_str, sizeof(input_str), stdin);
  218. if (!temp) {
  219. printf("Error: fgets returned nullptr !!");
  220. return -1;
  221. }
  222. type = atoi(input_str);
  223. switch((enum ipa_test_type)type) {
  224. case TEST:
  225. BuildRegressionTestSuite();
  226. showTests();
  227. printf("Choose which test you wish to run: \n");
  228. fflush(stdin);
  229. temp = fgets(input_str, sizeof(input_str), stdin);
  230. if (!temp) {
  231. printf("Error: fgets returned nullptr !!");
  232. return -1;
  233. }
  234. test_num = atoi(input_str);
  235. if ( test_num > testmanager->m_testList.size()) {
  236. printf("Invalid test number. Try again\n");
  237. result = -1;
  238. break;
  239. }
  240. test = testmanager->m_testList[test_num-1];
  241. printf("Running Test %s\n",
  242. test->m_name.
  243. c_str());
  244. testNameList.push_back(test->m_name.c_str());
  245. BuildRegressionTestSuite();
  246. testmanager->Run(testSuiteList, testNameList);
  247. testNameList.clear();
  248. break;
  249. case SUITE:
  250. BuildRegressionTestSuite();
  251. showSuits();
  252. printf("Choose which suite you wish to run: \n");
  253. fflush(stdin);
  254. temp = fgets(input_str, sizeof(input_str), stdin);
  255. if (!temp) {
  256. printf("Error: fgets returned nullptr !!");
  257. return -1;
  258. }
  259. suite_num = atoi(input_str);
  260. if (suite_num < 0 || suite_num > MAX_SUITES) {
  261. printf("Invalid test number. Try again\n");
  262. result = -1;
  263. break;
  264. }
  265. res = getSuite(suite_num);
  266. if (!res) {
  267. printf("Error in getSuite. Exiting\n");
  268. result = -1;
  269. break;
  270. }
  271. testSuiteList.push_back(res);
  272. testmanager->Run(testSuiteList, testNameList);
  273. testSuiteList.clear();
  274. break;
  275. default:
  276. printf("Exiting\n");
  277. break;
  278. }
  279. return result;
  280. }
  281. int scriptMode(int argc, char* argv[]) {
  282. vector<string> testSuiteList;
  283. vector<string> testNameList;
  284. string sControlFlag;
  285. if (argc < 2) {
  286. printf("please use correct format:\n%s", sFormat.c_str());
  287. return -1;
  288. }
  289. sControlFlag = argv[1];
  290. if (sControlFlag.find("--") == string::npos) {
  291. printf("please use correct format:\n%s", sFormat.c_str());
  292. return -1;
  293. }
  294. BuildRegressionTestSuite();
  295. if (sControlFlag.compare(SHOW_TEST_FLAG) == 0) {
  296. showTests();
  297. return 0;
  298. } else if (sControlFlag.compare(SHOW_SUIT_FLAG) == 0) {
  299. showSuits();
  300. return 0;
  301. }
  302. if (sControlFlag.compare(RUN_TEST_FLAG) == 0) {
  303. preparTests(argc, argv, testNameList);
  304. } else if (sControlFlag.compare(RUN_SUIT_FLAG) == 0) {
  305. preparTests(argc, argv, testSuiteList);
  306. } else {
  307. printf("please use correct format:\n%s", sFormat.c_str());
  308. return -1;
  309. }
  310. testmanager->Run(testSuiteList, testNameList);
  311. return 0;
  312. }
  313. int main(int argc, char* argv[])
  314. {
  315. string nat_mem_type = DFLT_NAT_MEM_TYPE;
  316. int c, result = 0, what = 0;
  317. int opt_idx = 0;
  318. struct option opts[] = {
  319. /* These options set a flag. */
  320. {"chooser", no_argument, &what, 1},
  321. {"show_tests", no_argument, &what, 2},
  322. {"show_suites", no_argument, &what, 3},
  323. {"test", no_argument, &what, 4},
  324. {"suite", no_argument, &what, 5},
  325. {"mem", required_argument, 0, 'm'},
  326. {0, 0, 0, 0}
  327. };
  328. if (argc <= 1) {
  329. printf("please use correct format:\n%s", sFormat.c_str());
  330. return -1;
  331. }
  332. while ( (c = getopt_long(argc, argv, "", opts, &opt_idx)) != -1 )
  333. {
  334. switch ( c )
  335. {
  336. case 0:
  337. break;
  338. case 'm':
  339. if ( legal_nat_mem_type(optarg) )
  340. {
  341. nat_mem_type = optarg;
  342. }
  343. else
  344. {
  345. fprintf(stderr, "Illegal: --mem %s\n", optarg);
  346. exit(1);
  347. }
  348. break;
  349. default:
  350. fprintf(stderr, "Illegal command line argument passed\n");
  351. printf("please use correct format:\n%s", sFormat.c_str());
  352. exit(1);
  353. }
  354. }
  355. if ( what == 0 ) {
  356. printf("please use correct format:\n%s", sFormat.c_str());
  357. return -1;
  358. }
  359. argc = 2;
  360. switch ( what )
  361. {
  362. case 1:
  363. argv[1] = (char*) CHOOSER_MODE;
  364. break;
  365. case 2:
  366. argv[1] = (char*) SHOW_TEST_FLAG;
  367. break;
  368. case 3:
  369. argv[1] = (char*) SHOW_SUIT_FLAG;
  370. break;
  371. case 4:
  372. argv[1] = (char*) RUN_TEST_FLAG;
  373. break;
  374. case 5:
  375. argv[1] = (char*) RUN_SUIT_FLAG;
  376. break;
  377. default:
  378. printf("please use correct format:\n%s", sFormat.c_str());
  379. exit(1);
  380. }
  381. testmanager = TestManager::GetInstance(nat_mem_type.c_str());
  382. string sControlFlag = argv[1];
  383. if (sControlFlag.compare(CHOOSER_MODE) == 0) {
  384. result = chooserMode();
  385. } else {
  386. result = scriptMode(argc, argv);
  387. }
  388. return result;
  389. }//main
  390. ////////////////////////////////////////////////////////////////////