2
0

unit_tests.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. /* Example test application for testable component.
  2. This example code is in the Public Domain (or CC0 licensed, at your option.)
  3. Unless required by applicable law or agreed to in writing, this
  4. software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
  5. CONDITIONS OF ANY KIND, either express or implied.
  6. */
  7. #include <stdio.h>
  8. #include <string.h>
  9. #include "unity.h"
  10. /*
  11. * Squeezelite for esp32
  12. *
  13. * (c) Sebastien 2019
  14. * Philippe G. 2019, philippe_44@outlook.com
  15. *
  16. * This software is released under the MIT License.
  17. * https://opensource.org/licenses/MIT
  18. *
  19. */
  20. #include "platform_esp32.h"
  21. #include "led.h"
  22. #include <stdio.h>
  23. #include <string.h>
  24. #include "freertos/FreeRTOS.h"
  25. #include "driver/gpio.h"
  26. #include "driver/spi_master.h"
  27. #include "freertos/task.h"
  28. #include "esp_system.h"
  29. #include "esp_spi_flash.h"
  30. #include "esp_wifi.h"
  31. #include "esp_system.h"
  32. #include <esp_event.h>
  33. #include "nvs_flash.h"
  34. #include "esp_log.h"
  35. #include "freertos/event_groups.h"
  36. #include "mdns.h"
  37. #include "lwip/api.h"
  38. #include "lwip/err.h"
  39. #include "lwip/netdb.h"
  40. #include "nvs_utilities.h"
  41. #include "trace.h"
  42. #include "network_manager.h"
  43. #include "squeezelite-ota.h"
  44. #include <math.h>
  45. #include "audio_controls.h"
  46. #include "platform_config.h"
  47. #include "telnet.h"
  48. #include "messaging.h"
  49. #include "gds.h"
  50. #include "gds_default_if.h"
  51. #include "gds_draw.h"
  52. #include "gds_text.h"
  53. #include "gds_font.h"
  54. #include "display.h"
  55. #include "accessors.h"
  56. #include "cmd_system.h"
  57. #include "cmd_config.h"
  58. #include "cmd_i2ctools.h"
  59. #include "cmd_nvs.h"
  60. const char unknown_string_placeholder[] = "unknown";
  61. const char null_string_placeholder[] = "null";
  62. // as an exception _init function don't need include
  63. extern void services_init(void);
  64. const char * str_or_unknown(const char * str) { return (str?str:unknown_string_placeholder); }
  65. const char * str_or_null(const char * str) { return (str?str:null_string_placeholder); }
  66. bool is_recovery_running;
  67. extern void initialize_console();
  68. /* brief this is an exemple of a callback that you can setup in your own app to get notified of wifi manager event */
  69. esp_err_t update_certificates(bool force){return ESP_OK; }
  70. void init_commands(){
  71. initialize_console();
  72. /* Register commands */
  73. register_system();
  74. register_config_cmd();
  75. register_nvs();
  76. register_i2ctools();
  77. }
  78. void test_init()
  79. {
  80. const esp_partition_t *running = esp_ota_get_running_partition();
  81. is_recovery_running = (running->subtype == ESP_PARTITION_SUBTYPE_APP_FACTORY);
  82. initialize_nvs();
  83. config_init();
  84. services_init();
  85. init_commands();
  86. }
  87. static void print_banner(const char* text);
  88. void app_main()
  89. {
  90. test_init();
  91. print_banner("Running tests with [config] tag");
  92. UNITY_BEGIN();
  93. unity_run_tests_by_tag("[config]", false);
  94. UNITY_END();
  95. // print_banner("Running all the registered tests");
  96. // UNITY_BEGIN();
  97. // unity_run_all_tests();
  98. // UNITY_END();
  99. print_banner("Starting interactive test menu");
  100. /* This function will not return, and will be busy waiting for UART input.
  101. * Make sure that task watchdog is disabled if you use this function.
  102. */
  103. unity_run_menu();
  104. }
  105. static void print_banner(const char* text)
  106. {
  107. printf("\n#### %s #####\n\n", text);
  108. }