Select one of the symbols to view example projects that use it.
 
Outline
#include <string.h>
#include <stdbool.h>
#include "unity.h"
#include "sdkconfig.h"
#include "esp_cpu.h"
#include "esp_rom_uart.h"
#include "esp_private/esp_clk.h"
s_test_start
s_test_stop
unity_putc(int)
unity_flush()
#define iscontrol
esp_unity_readline(char *, size_t)
unity_input_from_gdb
unity_gets(char *, size_t)
unity_exec_time_start()
unity_exec_time_stop()
unity_exec_time_get_ms()
Files
loading...
SourceVuESP-IDF Framework and ExamplesESP-IDFcomponents/unity/unity_port_esp32.c
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
/* * SPDX-FileCopyrightText: 2016-2024 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 *//* ... */ #include <string.h> #include <stdbool.h> #include "unity.h" #include "sdkconfig.h" #include "esp_cpu.h" #include "esp_rom_uart.h" #include "esp_private/esp_clk.h"7 includes static uint32_t s_test_start, s_test_stop; void unity_putc(int c) { if (c == '\n') { esp_rom_output_tx_one_char('\r'); esp_rom_output_tx_one_char('\n'); }{...} else if (c == '\r') { }{...} else { esp_rom_output_tx_one_char(c); }{...} }{ ... } void unity_flush(void) { if(CONFIG_ESP_CONSOLE_ROM_SERIAL_PORT_NUM != -1) { esp_rom_output_tx_wait_idle(CONFIG_ESP_CONSOLE_ROM_SERIAL_PORT_NUM); }{...} }{ ... } #define iscontrol(c) ((c) <= '\x1f' || (c) == '\x7f') static void esp_unity_readline(char* dst, size_t len) { /* Read line from console with support for echoing and backspaces */ size_t write_index = 0; for (;;) { char c = 0; bool got_char = esp_rom_output_rx_one_char((uint8_t*)&c) == 0; if (!got_char) { continue; }{...} if (c == '\r' || c == '\n') { /* Add null terminator and return on newline */ unity_putc('\n'); dst[write_index] = '\0'; return; }{...} else if (c == '\b') { if (write_index > 0) { /* Delete previously entered character */ write_index--; esp_rom_output_tx_one_char('\b'); esp_rom_output_tx_one_char(' '); esp_rom_output_tx_one_char('\b'); }{...} }{...} else if (len > 0 && write_index < len - 1 && !iscontrol(c)) { /* Write a max of len - 1 characters to allow for null terminator */ unity_putc(c); dst[write_index++] = c; }{...} }{...} }{ ... } /* To start a unit test from a GDB session without console input, * - set a break at unity_gets ('hb unity_gets') * - resume the program ('c') * - modify this value to the desired command line ('set {char[64]} unity_input_from_gdb = "5"') * - optionally set a break point in the test being debugged * - resume the program ('c') *//* ... */ char unity_input_from_gdb[64]; void unity_gets(char *dst, size_t len) { size_t unity_input_from_gdb_len = strlen(unity_input_from_gdb); if (unity_input_from_gdb_len > 0 && unity_input_from_gdb_len < len - 1) { memcpy(dst, unity_input_from_gdb, unity_input_from_gdb_len); dst[unity_input_from_gdb_len] = '\n'; dst[unity_input_from_gdb_len + 1] = 0; memset(unity_input_from_gdb, 0, sizeof(unity_input_from_gdb)); return; }{...} /* Flush anything already in the RX buffer */ uint8_t ignore; while (esp_rom_output_rx_one_char(&ignore) == 0) { } /* Read input */ esp_unity_readline(dst, len); }{ ... } void unity_exec_time_start(void) { s_test_start = esp_cpu_get_cycle_count(); }{ ... } void unity_exec_time_stop(void) { s_test_stop = esp_cpu_get_cycle_count(); }{ ... } uint32_t unity_exec_time_get_ms(void) { return (s_test_stop - s_test_start) / (esp_clk_cpu_freq() / 1000); }{ ... }
Details