test_console.c 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. #include <stdio.h>
  2. #include <string.h>
  3. #include "sdkconfig.h"
  4. #include "unity.h"
  5. #include "test_utils.h"
  6. #include "esp_console.h"
  7. #include "argtable3/argtable3.h"
  8. #include "freertos/FreeRTOS.h"
  9. #include "freertos/task.h"
  10. static int do_hello_cmd(int argc, char **argv)
  11. {
  12. printf("Hello World\n");
  13. return 0;
  14. }
  15. TEST_CASE("esp console init/deinit test", "[console]")
  16. {
  17. esp_console_config_t console_config = ESP_CONSOLE_CONFIG_DEFAULT();
  18. TEST_ESP_OK(esp_console_init(&console_config));
  19. const esp_console_cmd_t cmd = {
  20. .command = "hello",
  21. .help = "Print Hello World",
  22. .hint = NULL,
  23. .func = do_hello_cmd,
  24. };
  25. TEST_ESP_OK(esp_console_cmd_register(&cmd));
  26. // re-register the same command, just for test
  27. TEST_ESP_OK(esp_console_cmd_register(&cmd));
  28. TEST_ESP_OK(esp_console_deinit());
  29. }
  30. static esp_console_repl_t *s_repl = NULL;
  31. /* handle 'quit' command */
  32. static int do_cmd_quit(int argc, char **argv)
  33. {
  34. printf("ByeBye\r\n");
  35. s_repl->del(s_repl);
  36. return 0;
  37. }
  38. // Enter "quit" to exit REPL environment
  39. TEST_CASE("esp console repl test", "[console][ignore]")
  40. {
  41. esp_console_repl_config_t repl_config = ESP_CONSOLE_REPL_CONFIG_DEFAULT();
  42. esp_console_dev_uart_config_t uart_config = ESP_CONSOLE_DEV_UART_CONFIG_DEFAULT();
  43. TEST_ESP_OK(esp_console_new_repl_uart(&uart_config, &repl_config, &s_repl));
  44. esp_console_cmd_t cmd = {
  45. .command = "quit",
  46. .help = "Quit REPL environment",
  47. .func = &do_cmd_quit
  48. };
  49. TEST_ESP_OK(esp_console_cmd_register(&cmd));
  50. TEST_ESP_OK(esp_console_start_repl(s_repl));
  51. vTaskDelay(pdMS_TO_TICKS(2000));
  52. }