Skip to content

Commit cc1cc0b

Browse files
authored
emulation on host: option for FS persistence location (#7424)
* fix warnings * emulation on host: option -P to change FS persistence location * exit on SIGTERM too, with SIGINT
1 parent f1651fb commit cc1cc0b

File tree

3 files changed

+49
-18
lines changed

3 files changed

+49
-18
lines changed

tests/host/Makefile

+1
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,7 @@ DEBUG += -DDEBUG_ESP_SSL -DDEBUG_ESP_TLS_MEM -DDEBUG_ESP_HTTP_CLIENT -DDEBUG_ESP
153153
endif
154154

155155
FLAGS += $(DEBUG) -Wall $(OPTZ) -fno-common -g $(M32)
156+
FLAGS += -fstack-check -fstack-protector-all
156157
FLAGS += -DHTTPCLIENT_1_1_COMPATIBLE=0
157158
FLAGS += -DLWIP_IPV6=0
158159
FLAGS += -DHOST_MOCK=1

tests/host/common/ArduinoMain.cpp

+45-15
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ bool ignore_sigint = false;
4949
bool restore_tty = false;
5050
bool mockdebug = false;
5151
int mock_port_shifter = MOCK_PORT_SHIFTER;
52+
const char* fspath = nullptr;
5253

5354
#define STDIN STDIN_FILENO
5455

@@ -120,19 +121,24 @@ void help (const char* argv0, int exitcode)
120121
printf(
121122
"%s - compiled with esp8266/arduino emulator\n"
122123
"options:\n"
123-
" -h\n"
124-
" -i <interface> - use this interface for IP address\n"
125-
" -l - bind tcp/udp servers to interface only (not 0.0.0.0)\n"
126-
" -s - port shifter (default: %d, when root: 0)\n"
127-
" -c - ignore CTRL-C (send it via Serial)\n"
128-
" -f - no throttle (possibly 100%%CPU)\n"
129-
" -b - blocking tty/mocked-uart (default: not blocking tty)\n"
130-
" -S - spiffs size in KBytes (default: %zd)\n"
131-
" -L - littlefs size in KBytes (default: %zd)\n"
124+
"\t-h\n"
125+
"\tnetwork:\n"
126+
"\t-i <interface> - use this interface for IP address\n"
127+
"\t-l - bind tcp/udp servers to interface only (not 0.0.0.0)\n"
128+
"\t-s - port shifter (default: %d, when root: 0)\n"
129+
"\tterminal:\n"
130+
"\t-b - blocking tty/mocked-uart (default: not blocking tty)\n"
131+
"\t-T - show timestamp on output\n"
132+
"\tFS:\n"
133+
"\t-P - path for fs-persistent files (default: %s-)\n"
134+
"\t-S - spiffs size in KBytes (default: %zd)\n"
135+
"\t-L - littlefs size in KBytes (default: %zd)\n"
132136
"\t (spiffs, littlefs: negative value will force mismatched size)\n"
133-
" -T - show timestamp on output\n"
134-
" -v - verbose\n"
135-
, argv0, MOCK_PORT_SHIFTER, spiffs_kb, littlefs_kb);
137+
"\tgeneral:\n"
138+
"\t-c - ignore CTRL-C (send it via Serial)\n"
139+
"\t-f - no throttle (possibly 100%%CPU)\n"
140+
"\t-v - verbose\n"
141+
, argv0, MOCK_PORT_SHIFTER, argv0, spiffs_kb, littlefs_kb);
136142
exit(exitcode);
137143
}
138144

@@ -146,6 +152,7 @@ static struct option options[] =
146152
{ "verbose", no_argument, NULL, 'v' },
147153
{ "timestamp", no_argument, NULL, 'T' },
148154
{ "interface", required_argument, NULL, 'i' },
155+
{ "fspath", required_argument, NULL, 'P' },
149156
{ "spiffskb", required_argument, NULL, 'S' },
150157
{ "littlefskb", required_argument, NULL, 'L' },
151158
{ "portshifter", required_argument, NULL, 's' },
@@ -158,6 +165,23 @@ void cleanup ()
158165
mock_stop_uart();
159166
}
160167

168+
void make_fs_filename (String& name, const char* fspath, const char* argv0)
169+
{
170+
name.clear();
171+
if (fspath)
172+
{
173+
int lastSlash = -1;
174+
for (int i = 0; argv0[i]; i++)
175+
if (argv0[i] == '/')
176+
lastSlash = i;
177+
name = fspath;
178+
name += '/';
179+
name += &argv0[lastSlash + 1];
180+
}
181+
else
182+
name = argv0;
183+
}
184+
161185
void control_c (int sig)
162186
{
163187
(void)sig;
@@ -177,14 +201,15 @@ int main (int argc, char* const argv [])
177201
blocking_uart = false; // global
178202

179203
signal(SIGINT, control_c);
204+
signal(SIGTERM, control_c);
180205
if (geteuid() == 0)
181206
mock_port_shifter = 0;
182207
else
183208
mock_port_shifter = MOCK_PORT_SHIFTER;
184209

185210
for (;;)
186211
{
187-
int n = getopt_long(argc, argv, "hlcfbvTi:S:s:L:", options, NULL);
212+
int n = getopt_long(argc, argv, "hlcfbvTi:S:s:L:P:", options, NULL);
188213
if (n < 0)
189214
break;
190215
switch (n)
@@ -213,6 +238,9 @@ int main (int argc, char* const argv [])
213238
case 'L':
214239
littlefs_kb = atoi(optarg);
215240
break;
241+
case 'P':
242+
fspath = optarg;
243+
break;
216244
case 'b':
217245
blocking_uart = true;
218246
break;
@@ -231,7 +259,8 @@ int main (int argc, char* const argv [])
231259

232260
if (spiffs_kb)
233261
{
234-
String name = argv[0];
262+
String name;
263+
make_fs_filename(name, fspath, argv[0]);
235264
name += "-spiffs";
236265
name += String(spiffs_kb > 0? spiffs_kb: -spiffs_kb, DEC);
237266
name += "KB";
@@ -240,7 +269,8 @@ int main (int argc, char* const argv [])
240269

241270
if (littlefs_kb)
242271
{
243-
String name = argv[0];
272+
String name;
273+
make_fs_filename(name, fspath, argv[0]);
244274
name += "-littlefs";
245275
name += String(littlefs_kb > 0? littlefs_kb: -littlefs_kb, DEC);
246276
name += "KB";

tests/host/common/UdpContextSocket.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,8 @@ bool mockUDPListen (int sock, uint32_t dstaddr, uint16_t port, uint32_t mcast)
9090
else
9191
mockverbose("UDP server on port %d (sock=%d)\n", mockport, sock);
9292

93-
if (!mcast)
94-
mcast = inet_addr("224.0.0.1"); // all hosts group
93+
if (!mcast)
94+
mcast = inet_addr("224.0.0.1"); // all hosts group
9595
if (mcast)
9696
{
9797
// https://web.cs.wpi.edu/~claypool/courses/4514-B99/samples/multicast.c
@@ -121,7 +121,7 @@ bool mockUDPListen (int sock, uint32_t dstaddr, uint16_t port, uint32_t mcast)
121121
return false;
122122
}
123123
else
124-
mockverbose("joined multicast group addr %08lx\n", ntohl(mcast));
124+
mockverbose("joined multicast group addr %08lx\n", (long)ntohl(mcast));
125125
}
126126

127127
return true;

0 commit comments

Comments
 (0)