test_utils.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. // Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. #pragma once
  15. // Utilities for esp-idf unit tests
  16. #include <stdint.h>
  17. #include <esp_partition.h>
  18. /* Return the 'flash_test' custom data partition (type 0x55)
  19. defined in the custom partition table.
  20. */
  21. const esp_partition_t *get_test_data_partition();
  22. /**
  23. * @brief Initialize reference clock
  24. *
  25. * Reference clock provides timestamps at constant 1 MHz frequency, even when
  26. * the APB frequency is changing.
  27. */
  28. void ref_clock_init();
  29. /**
  30. * @brief Deinitialize reference clock
  31. */
  32. void ref_clock_deinit();
  33. /**
  34. * @brief Get reference clock timestamp
  35. * @return number of microseconds since the reference clock was initialized
  36. */
  37. uint64_t ref_clock_get();
  38. /**
  39. * @brief Reset automatic leak checking which happens in unit tests.
  40. *
  41. * Updates recorded "before" free memory values to the free memory values
  42. * at time of calling. Resets leak checker if tracing is enabled in
  43. * config.
  44. *
  45. * This can be called if a test case does something which allocates
  46. * memory on first use, for example.
  47. *
  48. * @note Use with care as this can mask real memory leak problems.
  49. */
  50. void unity_reset_leak_checks(void);
  51. /**
  52. * @brief Call this function from a test case which requires TCP/IP or
  53. * LWIP functionality.
  54. *
  55. * @note This should be the first function the test case calls, as it will
  56. * allocate memory on first use (and also reset the test case leak checker).
  57. */
  58. void test_case_uses_tcpip(void);
  59. /**
  60. * @brief wait for signals.
  61. *
  62. * for multiple devices test cases, DUT might need to wait for other DUTs before continue testing.
  63. * As all DUTs are independent, need user (or test script) interaction to make test synchronized.
  64. *
  65. * Here we provide signal functions for this.
  66. * For example, we're testing GPIO, DUT1 has one pin connect to with DUT2.
  67. * DUT2 will output high level and then DUT1 will read input.
  68. * DUT1 should call `unity_wait_for_signal("output high level");` before it reads input.
  69. * DUT2 should call `unity_send_signal("output high level");` after it finished setting output high level.
  70. * According to the console logs:
  71. *
  72. * DUT1 console:
  73. *
  74. * ```
  75. * Waiting for signal: [output high level]!
  76. * Please press "Enter" key to once any board send this signal.
  77. * ```
  78. *
  79. * DUT2 console:
  80. *
  81. * ```
  82. * Send signal: [output high level]!
  83. * ```
  84. *
  85. * Then we press Enter key on DUT1's console, DUT1 starts to read input and then test success.
  86. *
  87. * @param signal_name signal name which DUT expected to wait before proceed testing
  88. */
  89. void unity_wait_for_signal(const char* signal_name);
  90. /**
  91. * @brief DUT send signal.
  92. *
  93. * @param signal_name signal name which DUT send once it finished preparing.
  94. */
  95. void unity_send_signal(const char* signal_name);