test_utils.c 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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. #include <string.h>
  15. #include "unity.h"
  16. #include "test_utils.h"
  17. #include "rom/ets_sys.h"
  18. #include "rom/uart.h"
  19. #include "freertos/FreeRTOS.h"
  20. #include "freertos/task.h"
  21. #include "tcpip_adapter.h"
  22. #include "lwip/sockets.h"
  23. const esp_partition_t *get_test_data_partition()
  24. {
  25. /* This finds "flash_test" partition defined in partition_table_unit_test_app.csv */
  26. const esp_partition_t *result = esp_partition_find_first(ESP_PARTITION_TYPE_DATA,
  27. ESP_PARTITION_SUBTYPE_ANY, "flash_test");
  28. TEST_ASSERT_NOT_NULL(result); /* means partition table set wrong */
  29. return result;
  30. }
  31. // wait user to send "Enter" key
  32. static void wait_user_control()
  33. {
  34. char sign[5] = {0};
  35. while(strlen(sign) == 0)
  36. {
  37. /* Flush anything already in the RX buffer */
  38. while(uart_rx_one_char((uint8_t *) sign) == OK) {
  39. }
  40. /* Read line */
  41. UartRxString((uint8_t*) sign, sizeof(sign) - 1);
  42. }
  43. }
  44. void test_case_uses_tcpip()
  45. {
  46. // Can be called more than once, does nothing on subsequent calls
  47. tcpip_adapter_init();
  48. // Allocate all sockets then free them
  49. // (First time each socket is allocated some one-time allocations happen.)
  50. int sockets[CONFIG_LWIP_MAX_SOCKETS];
  51. for (int i = 0; i < CONFIG_LWIP_MAX_SOCKETS; i++) {
  52. int type = (i % 2 == 0) ? SOCK_DGRAM : SOCK_STREAM;
  53. int family = (i % 3 == 0) ? PF_INET6 : PF_INET;
  54. sockets[i] = socket(family, type, IPPROTO_IP);
  55. }
  56. for (int i = 0; i < CONFIG_LWIP_MAX_SOCKETS; i++) {
  57. close(sockets[i]);
  58. }
  59. // Allow LWIP tasks to finish initialising themselves
  60. vTaskDelay(25 / portTICK_RATE_MS);
  61. printf("Note: tcpip_adapter_init() has been called. Until next reset, TCP/IP task will periodicially allocate memory and consume CPU time.\n");
  62. // Reset the leak checker as LWIP allocates a lot of memory on first run
  63. unity_reset_leak_checks();
  64. }
  65. // signal functions, used for sync between unity DUTs for multiple devices cases
  66. void unity_wait_for_signal(const char* signal_name)
  67. {
  68. printf("Waiting for signal: [%s]!\n"
  69. "Please press \"Enter\" key to once any board send this signal.\n", signal_name);
  70. wait_user_control();
  71. }
  72. void unity_send_signal(const char* signal_name)
  73. {
  74. printf("Send signal: [%s]!\n", signal_name);
  75. }