Skip to content

Commit

Permalink
emulation on host: option for FS persistence location (#7424)
Browse files Browse the repository at this point in the history
* fix warnings
* emulation on host: option -P to change FS persistence location
* exit on SIGTERM too, with SIGINT
  • Loading branch information
d-a-v committed Jul 3, 2020
1 parent f1651fb commit cc1cc0b
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 18 deletions.
1 change: 1 addition & 0 deletions tests/host/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ DEBUG += -DDEBUG_ESP_SSL -DDEBUG_ESP_TLS_MEM -DDEBUG_ESP_HTTP_CLIENT -DDEBUG_ESP
endif

FLAGS += $(DEBUG) -Wall $(OPTZ) -fno-common -g $(M32)
FLAGS += -fstack-check -fstack-protector-all
FLAGS += -DHTTPCLIENT_1_1_COMPATIBLE=0
FLAGS += -DLWIP_IPV6=0
FLAGS += -DHOST_MOCK=1
Expand Down
60 changes: 45 additions & 15 deletions tests/host/common/ArduinoMain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ bool ignore_sigint = false;
bool restore_tty = false;
bool mockdebug = false;
int mock_port_shifter = MOCK_PORT_SHIFTER;
const char* fspath = nullptr;

#define STDIN STDIN_FILENO

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

Expand All @@ -146,6 +152,7 @@ static struct option options[] =
{ "verbose", no_argument, NULL, 'v' },
{ "timestamp", no_argument, NULL, 'T' },
{ "interface", required_argument, NULL, 'i' },
{ "fspath", required_argument, NULL, 'P' },
{ "spiffskb", required_argument, NULL, 'S' },
{ "littlefskb", required_argument, NULL, 'L' },
{ "portshifter", required_argument, NULL, 's' },
Expand All @@ -158,6 +165,23 @@ void cleanup ()
mock_stop_uart();
}

void make_fs_filename (String& name, const char* fspath, const char* argv0)
{
name.clear();
if (fspath)
{
int lastSlash = -1;
for (int i = 0; argv0[i]; i++)
if (argv0[i] == '/')
lastSlash = i;
name = fspath;
name += '/';
name += &argv0[lastSlash + 1];
}
else
name = argv0;
}

void control_c (int sig)
{
(void)sig;
Expand All @@ -177,14 +201,15 @@ int main (int argc, char* const argv [])
blocking_uart = false; // global

signal(SIGINT, control_c);
signal(SIGTERM, control_c);
if (geteuid() == 0)
mock_port_shifter = 0;
else
mock_port_shifter = MOCK_PORT_SHIFTER;

for (;;)
{
int n = getopt_long(argc, argv, "hlcfbvTi:S:s:L:", options, NULL);
int n = getopt_long(argc, argv, "hlcfbvTi:S:s:L:P:", options, NULL);
if (n < 0)
break;
switch (n)
Expand Down Expand Up @@ -213,6 +238,9 @@ int main (int argc, char* const argv [])
case 'L':
littlefs_kb = atoi(optarg);
break;
case 'P':
fspath = optarg;
break;
case 'b':
blocking_uart = true;
break;
Expand All @@ -231,7 +259,8 @@ int main (int argc, char* const argv [])

if (spiffs_kb)
{
String name = argv[0];
String name;
make_fs_filename(name, fspath, argv[0]);
name += "-spiffs";
name += String(spiffs_kb > 0? spiffs_kb: -spiffs_kb, DEC);
name += "KB";
Expand All @@ -240,7 +269,8 @@ int main (int argc, char* const argv [])

if (littlefs_kb)
{
String name = argv[0];
String name;
make_fs_filename(name, fspath, argv[0]);
name += "-littlefs";
name += String(littlefs_kb > 0? littlefs_kb: -littlefs_kb, DEC);
name += "KB";
Expand Down
6 changes: 3 additions & 3 deletions tests/host/common/UdpContextSocket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,8 @@ bool mockUDPListen (int sock, uint32_t dstaddr, uint16_t port, uint32_t mcast)
else
mockverbose("UDP server on port %d (sock=%d)\n", mockport, sock);

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

return true;
Expand Down

0 comments on commit cc1cc0b

Please sign in to comment.