test_utils.h 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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 wait for signals.
  40. *
  41. * for multiple devices test cases, DUT might need to wait for other DUTs before continue testing.
  42. * As all DUTs are independent, need user (or test script) interaction to make test synchronized.
  43. *
  44. * Here we provide signal functions for this.
  45. * For example, we're testing GPIO, DUT1 has one pin connect to with DUT2.
  46. * DUT2 will output high level and then DUT1 will read input.
  47. * DUT1 should call `unity_wait_for_signal("output high level");` before it reads input.
  48. * DUT2 should call `unity_send_signal("output high level");` after it finished setting output high level.
  49. * According to the console logs:
  50. *
  51. * DUT1 console:
  52. *
  53. * ```
  54. * Waiting for signal: [output high level]!
  55. * Please press "Enter" key to once any board send this signal.
  56. * ```
  57. *
  58. * DUT2 console:
  59. *
  60. * ```
  61. * Send signal: [output high level]!
  62. * ```
  63. *
  64. * Then we press Enter key on DUT1's console, DUT1 starts to read input and then test success.
  65. *
  66. * @param signal_name signal name which DUT expected to wait before proceed testing
  67. */
  68. void unity_wait_for_signal(const char* signal_name);
  69. /**
  70. * @brief DUT send signal.
  71. *
  72. * @param signal_name signal name which DUT send once it finished preparing.
  73. */
  74. void unity_send_signal(const char* signal_name);