test.c 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. /*
  2. * Copyright (c) 2013-2017 ARM Limited. All rights reserved.
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Licensed under the Apache License, Version 2.0 (the License); you may
  7. * not use this file except in compliance with the License.
  8. * You may obtain a copy of the License at
  9. *
  10. * www.apache.org/licenses/LICENSE-2.0
  11. *
  12. * Unless required by applicable law or agreed to in writing, software
  13. * distributed under the License is distributed on an AS IS BASIS, WITHOUT
  14. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15. * See the License for the specific language governing permissions and
  16. * limitations under the License.
  17. *
  18. * ----------------------------------------------------------------------
  19. *
  20. * $Date: 1. December 2017
  21. * $Revision: V2.0.0
  22. *
  23. * Project: CMSIS-DAP Validation
  24. * Title: test.c CMSIS-DAP debug unit test module
  25. *
  26. *---------------------------------------------------------------------------*/
  27. // Debug Variables
  28. volatile int test_state = 0;
  29. volatile int test_success = 0;
  30. volatile int bpTestCounter = 0;
  31. volatile char mem_rw_success = 0;
  32. int test_array1[256] = {0};
  33. int test_array2[256] = {0};
  34. // Breakpoint Test function
  35. static void BP_Test (void) {
  36. int i;
  37. for (i = 0; i < 10; i++) {
  38. // increment counter so we know on which iteration breakpoint is hit
  39. bpTestCounter++;
  40. test_state++;
  41. }
  42. }
  43. // Test function
  44. static void Test(void) {
  45. int i;
  46. test_state++; // 'test_state' = 11
  47. i = test_success; // 'test_success' read access
  48. test_state++; // 'test_state' = 12
  49. test_success = i; // 'test_success' write access
  50. test_state++; // 'test_state' = 13
  51. // test_array1 should have already been written by debugger
  52. // copy test_array1 into test_array2 for future comparison
  53. mem_rw_success = 1; // assume all values were written correctly
  54. for (i = 0; i < 256; i++) {
  55. if (test_array1[i] != (0x1000+i)) {
  56. mem_rw_success = 0;
  57. }
  58. test_array2[i] = test_array1[i];
  59. }
  60. test_state++; // 'test_state' = 14
  61. test_state++; // 'test_state' = 15
  62. test_state++; // 'test_state' = 16
  63. // execute 'test_state -= 16' from debugger
  64. test_state++; // 'test_state' = 1
  65. if (test_state == 1) {
  66. test_success = 1;
  67. } else {
  68. test_success = 0;
  69. }
  70. }
  71. // 'main' function
  72. int main (void) {
  73. BP_Test();
  74. Test();
  75. for (;;) {};
  76. }