Skip to content

Commit 6553880

Browse files
committed
feat(esp_repl): add tests for esp_repl
1 parent d9b1ceb commit 6553880

File tree

1 file changed

+65
-1
lines changed

1 file changed

+65
-1
lines changed

esp_repl/test_apps/main/test_esp_repl.c

Lines changed: 65 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,70 @@
66

77
#include <string.h>
88
#include <stdio.h>
9-
#include <pthread.h>
9+
#include "freertos/FreeRTOS.h"
10+
#include "freertos/task.h"
11+
#include "freertos/semphr.h"
1012
#include "unity.h"
1113
#include "esp_repl.h"
14+
15+
typedef struct esp_linenoise_dummy {
16+
size_t value;
17+
} esp_linenoise_dummy_t;
18+
typedef struct esp_linenoise_dummy *esp_linenoise_handle_t;
19+
20+
typedef struct esp_commands_dummy {
21+
size_t value;
22+
} esp_commands_dummy_t;
23+
typedef struct esp_commands_dummy *esp_commands_handle_t;
24+
25+
esp_err_t test_reader_non_blocking(esp_linenoise_handle_t handle, char *buf, size_t buf_size)
26+
{
27+
return ESP_OK;
28+
}
29+
30+
esp_err_t test_pre_executor(void *ctx, char *buf, const esp_err_t reader_ret_val)
31+
{
32+
return ESP_OK;
33+
}
34+
35+
esp_err_t test_executor(esp_commands_handle_t handle, const char *buf, int *ret_val)
36+
{
37+
return ESP_OK;
38+
}
39+
40+
esp_err_t test_post_executor(void *ctx, const char *buf, const esp_err_t executor_ret_val, const int cmd_ret_val)
41+
{
42+
return ESP_OK;
43+
}
44+
45+
void test_on_stop(void *ctx, esp_repl_instance_handle_t handle)
46+
{
47+
return;
48+
}
49+
50+
void test_on_exit(void *ctx, esp_repl_instance_handle_t handle)
51+
{
52+
return;
53+
}
54+
55+
TEST_CASE("esp_repl() called after successful init, with non blocking reader", "[esp_repl]")
56+
{
57+
esp_commands_dummy_t dummy_esp_linenoise = {.value = 0x01 };
58+
esp_commands_dummy_t dummy_esp_commands = {.value = 0x02 };
59+
esp_repl_config_t config = {
60+
.max_cmd_line_size = 256,
61+
.reader = { .func = (esp_repl_reader_fn)test_reader_non_blocking, .ctx = &dummy_esp_linenoise },
62+
.pre_executor = { .func = test_pre_executor, .ctx = NULL },
63+
.executor = { .func = (esp_repl_executor_fn)test_executor, .ctx = &dummy_esp_commands },
64+
.post_executor = { .func = test_post_executor, .ctx = NULL },
65+
.on_stop = { .func = test_on_stop, .ctx = NULL },
66+
.on_exit = { .func = test_on_exit, .ctx = NULL }
67+
};
68+
69+
esp_repl_instance_handle_t handle = NULL;
70+
TEST_ASSERT_EQUAL(ESP_OK, esp_repl_create(&handle, &config));
71+
TEST_ASSERT_NOT_NULL(handle);
72+
73+
xTaskCreate(esp_apptrace_send_uart_tx_task, "app_trace_uart_tx_task", 2500, hw_data, uart_prio, NULL);
74+
75+
}

0 commit comments

Comments
 (0)