test.ini 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430
  1. /******************************************************************************/
  2. /* test.ini: Initialization file to test the debug functionality */
  3. /******************************************************************************/
  4. /* This file is part of the uVision/ARM development tools. */
  5. /* Copyright (c) 2012-2017 Keil Software. All rights reserved. */
  6. /* This software may only be used under the terms of a valid, current, */
  7. /* end user license from KEIL for a compatible version of KEIL software */
  8. /* development tools. Nothing else gives you the right to use this software. */
  9. /******************************************************************************/
  10. // ensure logging into file is turned off
  11. LOG OFF
  12. // overall test success flag
  13. define int testSuccess;
  14. testSuccess = 0;
  15. // flags to show which particular tests succeeded
  16. define char bpExecSuccess;
  17. bpExecSuccess = 0;
  18. define char bpReadSuccess;
  19. bpReadSuccess = 0;
  20. define char bpWriteSuccess;
  21. bpWriteSuccess = 0;
  22. define char memReadSuccess;
  23. memReadSuccess = 0;
  24. define char memWriteSuccess;
  25. memWriteSuccess = 0;
  26. define char regReadSuccess;
  27. regReadSuccess = 0;
  28. define char regWriteSuccess;
  29. regWriteSuccess = 0;
  30. // function to read and write registers
  31. FUNC void RegReadWrite(void) {
  32. unsigned long VR0, VR1, VR2, VR3, VR4, VR5, VR6, VR7, VR8, VR9;
  33. unsigned long VR10, VR11, VR12, VR13, VR14, VR15, VxPSR;
  34. unsigned long VR_0, VR_1, VR_2, VR_3, VR_4, VR_5, VR_6, VR_7, VR_8, VR_9;
  35. unsigned long VR_10, VR_11, VR_12, VR_13, VR_14, VR_15, V_xPSR;
  36. unsigned long bogus;
  37. bogus = 0x0badF00D;
  38. printf("Register read started\n");
  39. // initialize temporary variables with bogus value
  40. VR0 = bogus;
  41. VR1 = bogus;
  42. VR2 = bogus;
  43. VR3 = bogus;
  44. VR4 = bogus;
  45. VR5 = bogus;
  46. VR6 = bogus;
  47. VR7 = bogus;
  48. VR8 = bogus;
  49. VR9 = bogus;
  50. VR10 = bogus;
  51. VR11 = bogus;
  52. VR12 = bogus;
  53. VR13 = bogus;
  54. VR14 = bogus;
  55. VR15 = bogus;
  56. VxPSR = bogus;
  57. // read and save current register values
  58. VR0 = R0;
  59. VR1 = R1;
  60. VR2 = R2;
  61. VR3 = R3;
  62. VR4 = R4;
  63. VR5 = R5;
  64. VR6 = R6;
  65. VR7 = R7;
  66. VR8 = R8;
  67. VR9 = R9;
  68. VR10 = R10;
  69. VR11 = R11;
  70. VR12 = R12;
  71. VR13 = R13;
  72. VR14 = R14;
  73. VR15 = R15;
  74. VxPSR = xPSR;
  75. // print read register values
  76. printf("R0 = 0x%x\n", VR0);
  77. printf("R1 = 0x%x\n", VR1);
  78. printf("R2 = 0x%x\n", VR2);
  79. printf("R3 = 0x%x\n", VR3);
  80. printf("R4 = 0x%x\n", VR4);
  81. printf("R5 = 0x%x\n", VR5);
  82. printf("R6 = 0x%x\n", VR6);
  83. printf("R7 = 0x%x\n", VR7);
  84. printf("R8 = 0x%x\n", VR8);
  85. printf("R9 = 0x%x\n", VR9);
  86. printf("R10 = 0x%x\n", VR10);
  87. printf("R11 = 0x%x\n", VR11);
  88. printf("R12 = 0x%x\n", VR12);
  89. printf("R13 = 0x%x\n", VR13);
  90. printf("R14 = 0x%x\n", VR14);
  91. printf("R15 = 0x%x\n", VR15);
  92. printf("xPSR = 0x%x\n", VxPSR);
  93. // check if all values differ from bogus value
  94. regReadSuccess =
  95. (VR0 != bogus) &&
  96. (VR1 != bogus) &&
  97. (VR2 != bogus) &&
  98. (VR3 != bogus) &&
  99. (VR4 != bogus) &&
  100. (VR5 != bogus) &&
  101. (VR6 != bogus) &&
  102. (VR7 != bogus) &&
  103. (VR8 != bogus) &&
  104. (VR9 != bogus) &&
  105. (VR10 != bogus) &&
  106. (VR11 != bogus) &&
  107. (VR12 != bogus) &&
  108. (VR13 != bogus) &&
  109. (VR14 != bogus) &&
  110. (VR15 != bogus) &&
  111. (VxPSR != bogus);
  112. if (regReadSuccess != 0) {
  113. printf("Register read passed\n");
  114. } else {
  115. printf("Register read failed\n");
  116. // there is no reason to test write if read fails
  117. return;
  118. }
  119. printf("Register write started\n");
  120. // fill all registers with bogus value
  121. R0 = bogus;
  122. R1 = bogus;
  123. R2 = bogus;
  124. R3 = bogus;
  125. R4 = bogus;
  126. R5 = bogus;
  127. R6 = bogus;
  128. R7 = bogus;
  129. R8 = bogus;
  130. R9 = bogus;
  131. R10 = bogus;
  132. R11 = bogus;
  133. R12 = bogus;
  134. // register R13-R15 and xPSR on hardware do not accept 0x0badf00d, use 0x0 instead
  135. R13 = 0x0;
  136. R14 = 0x0;
  137. R15 = 0x0;
  138. xPSR = 0x0;
  139. // read back into another array
  140. VR_0 = R0;
  141. VR_1 = R1;
  142. VR_2 = R2;
  143. VR_3 = R3;
  144. VR_4 = R4;
  145. VR_5 = R5;
  146. VR_6 = R6;
  147. VR_7 = R7;
  148. VR_8 = R8;
  149. VR_9 = R9;
  150. VR_10 = R10;
  151. VR_11 = R11;
  152. VR_12 = R12;
  153. VR_13 = R13;
  154. VR_14 = R14;
  155. VR_15 = R15;
  156. V_xPSR = xPSR;
  157. // print the values again
  158. printf("R0 = 0x%x\n", VR_0);
  159. printf("R1 = 0x%x\n", VR_1);
  160. printf("R2 = 0x%x\n", VR_2);
  161. printf("R3 = 0x%x\n", VR_3);
  162. printf("R4 = 0x%x\n", VR_4);
  163. printf("R5 = 0x%x\n", VR_5);
  164. printf("R6 = 0x%x\n", VR_6);
  165. printf("R7 = 0x%x\n", VR_7);
  166. printf("R8 = 0x%x\n", VR_8);
  167. printf("R9 = 0x%x\n", VR_9);
  168. printf("R10 = 0x%x\n", VR_10);
  169. printf("R11 = 0x%x\n", VR_11);
  170. printf("R12 = 0x%x\n", VR_12);
  171. printf("R13 = 0x%x\n", VR_13);
  172. printf("R14 = 0x%x\n", VR_14);
  173. printf("R15 = 0x%x\n", VR_15);
  174. printf("xPSR = 0x%x\n", V_xPSR);
  175. // check if new values are bogus
  176. regWriteSuccess =
  177. (VR_0 == bogus) &&
  178. (VR_1 == bogus) &&
  179. (VR_2 == bogus) &&
  180. (VR_3 == bogus) &&
  181. (VR_4 == bogus) &&
  182. (VR_5 == bogus) &&
  183. (VR_6 == bogus) &&
  184. (VR_7 == bogus) &&
  185. (VR_8 == bogus) &&
  186. (VR_9 == bogus) &&
  187. (VR_10 == bogus) &&
  188. (VR_11 == bogus) &&
  189. (VR_12 == bogus) &&
  190. (VR_13 == 0x0) &&
  191. (VR_14 == 0x0) &&
  192. (VR_15 == 0x0) &&
  193. (V_xPSR == 0x0);
  194. if (regWriteSuccess != 0) {
  195. printf("Register write passed\n");
  196. } else {
  197. printf("Register write failed\n");
  198. }
  199. // write saved values back into registers
  200. // values are required to be written correctly for the rest of the test
  201. R0 = VR0;
  202. R1 = VR1;
  203. R2 = VR2;
  204. R3 = VR3;
  205. R4 = VR4;
  206. R5 = VR5;
  207. R6 = VR6;
  208. R7 = VR7;
  209. R8 = VR8;
  210. R9 = VR9;
  211. R10 = VR10;
  212. R11 = VR11;
  213. R12 = VR12;
  214. R13 = VR13;
  215. R14 = VR14;
  216. R15 = VR15;
  217. xPSR = VxPSR;
  218. }
  219. // function to write predefined numbers into test_array1
  220. FUNC void MemWrite(unsigned long address) {
  221. unsigned int i;
  222. unsigned int val;
  223. printf("Memory write started\n");
  224. val = 0x1000;
  225. for (i = 0; i < 256; i++) {
  226. _WWORD(address, val);
  227. val++;
  228. address += 4;
  229. }
  230. printf("Memory write completed\n");
  231. }
  232. // function to read from test_array2 and check if write and read was successful
  233. FUNC void MemRead(unsigned long address) {
  234. unsigned int i;
  235. unsigned int val, v;
  236. printf("Memory read started\n");
  237. val = 0x1000;
  238. memReadSuccess = 1; // assume it is true
  239. for (i = 0; i < 256; i++) {
  240. v = _RWORD(address);
  241. if (v != val) {
  242. memReadSuccess = 0;
  243. }
  244. val++;
  245. address += 4;
  246. }
  247. if (memReadSuccess != 0) {
  248. printf("Memory read passed\n");
  249. } else {
  250. printf("Memory read failed\n");
  251. }
  252. }
  253. // check execution breakpoint
  254. FUNC void CheckBpExec(unsigned long address) {
  255. // PC should be at address and value of bpTestCounter variable should be 9
  256. if ((R15 == address) && (`bpTestCounter == 9)) {
  257. bpExecSuccess = 1;
  258. }
  259. printf("Execution breakpoint (%d): %d\n", `bpTestCounter, bpExecSuccess);
  260. }
  261. // check breakpoint on read
  262. FUNC void CheckBpRead(int test_state) {
  263. // PC should be at address
  264. if (`test_state == test_state) {
  265. bpReadSuccess = 1;
  266. }
  267. printf("Breakpoint on read: %d\n",bpReadSuccess);
  268. }
  269. // check breakpoint on write
  270. FUNC void CheckBpWrite(int test_state) {
  271. // PC should be at address
  272. if (`test_state == test_state) {
  273. bpWriteSuccess = 1;
  274. }
  275. printf("Breakpoint on write: %d\n", bpWriteSuccess);
  276. }
  277. // evaluate test
  278. FUNC void EvalSuccess(void) {
  279. char success;
  280. success = testSuccess &&
  281. bpExecSuccess && bpReadSuccess && bpWriteSuccess &&
  282. regReadSuccess && regWriteSuccess &&
  283. memReadSuccess && memWriteSuccess;
  284. exec("LOG >.\\test_results.txt");
  285. // print test results to log file
  286. if (success) {
  287. printf("Test passed!\n");
  288. } else {
  289. printf("Test failed!\n");
  290. }
  291. printf("\nIndividual test results:\n");
  292. printf("Execution breakpoint: ");
  293. if (bpExecSuccess) {
  294. printf("passed\n");
  295. } else {
  296. printf("failed\n");
  297. }
  298. printf("Breakpoint on read: ");
  299. if (bpReadSuccess) {
  300. printf("passed\n");
  301. } else {
  302. printf("failed\n");
  303. }
  304. printf("Breakpoint on write: ");
  305. if (bpWriteSuccess) {
  306. printf("passed\n");
  307. } else {
  308. printf("failed\n");
  309. }
  310. printf("Register read: ");
  311. if (regReadSuccess) {
  312. printf("passed\n");
  313. } else {
  314. printf("failed\n");
  315. }
  316. printf("Register write: ");
  317. if (regWriteSuccess) {
  318. printf("passed\n");
  319. } else {
  320. printf("failed\n");
  321. }
  322. printf("Memory read: ");
  323. if (memReadSuccess) {
  324. printf("passed\n");
  325. } else {
  326. printf("failed\n");
  327. }
  328. printf("Memory write: ");
  329. if (memWriteSuccess) {
  330. printf("passed\n");
  331. } else {
  332. printf("failed\n");
  333. }
  334. printf("Control flow: ");
  335. if (testSuccess) {
  336. printf("passed\n");
  337. } else {
  338. printf("failed\n");
  339. }
  340. exec("LOG OFF");
  341. }
  342. LOG >.\\test.log // start logging
  343. RegReadWrite(); // check register read/write
  344. BK * // remove all existing breakpoints
  345. BS \test.c\43, 9 // set execution breakpoint (hit count=9)
  346. G // run to break point
  347. CheckBpExec(\test.c\43); // check execution breakpoint
  348. BK * // remove all existing breakpoints
  349. BS READ test_success // set a read access breakpoint
  350. G // run to break point
  351. CheckBpRead(11); // check breakpoint on read
  352. BK * // remove all existing breakpoints
  353. BS WRITE test_success // set a write access breakpoint
  354. G // run to break point
  355. CheckBpWrite(12); // check breakpoint on write
  356. BK * // remove all existing breakpoints
  357. G,\test.c\61 // run until line 61
  358. MemWrite(&test_array1[0]); // test memory write
  359. G,\test.c\69 // run until line 69
  360. memWriteSuccess = `mem_rw_success; // application memory test result
  361. MemRead(&test_array2[0]); // test memory read
  362. T 3 // step 3 times
  363. `test_state -= 16; // modify 'test_state' application variable
  364. G,\test.c\88 // run until line 88
  365. testSuccess = `test_success; // read 'test_success' application variable
  366. LOG OFF // stop logging
  367. EvalSuccess(); // evaluate test results
  368. EXIT // exit debug mode