nuttx-apps/netutils
Marco Casaroli 7aac6c5cb8 testing/ostest: split the fork test into task_fork, vfork and fork
nuttx implements fork() and vfork() as the same function, and is gaining the
three separate primitives its issue #19540 describes:  task_fork() (shares
memory, private stack copy, both running), vfork() (shares memory, parent
suspended) and POSIX fork() (child gets its own copy).  This is the apps side
of that, and it lands first:  it works against nuttx with or without the
split, so the tests keep running across the transition rather than silently
compiling out.

ostest's "vfork" test was never testing vfork().  It has the child write a
global and the parent observe the write -- which is the defining property of
*sharing*, not of vfork(), whose defining property is that the parent is
suspended and whose contract forbids the child to write anything at all.  It
is renamed to task_fork.c, unchanged, because that is the primitive it has
always described.

vfork.c is rewritten to test what vfork() promises.  The child does only what
POSIX permits -- it calls _exit(42), and nothing else, not even exit(), which
would run atexit handlers and flush stdio in the parent's address space.  The
observable is therefore the child's exit status rather than a memory write.
Where child status is not retained -- ostest_main() sets SA_NOCLDWAIT for the
whole run, deliberately -- waitpid() returning ECHILD is accepted as equally
good evidence:  it says the child was already gone when the parent asked.

fork.c is new and tests POSIX fork():  the child's writes to .data, .bss and
the heap are invisible to the parent and vice versa, a pointer to a stack
local taken before the fork names the same object in both, and the child does
everything a vfork() child may not -- calls malloc() and printf(), and returns
from the function that called fork().

All three run at the top of user_main() rather than in the middle.  They
exercise the lowest-level machinery in the suite -- address environments,
stack setup, the architecture's register context -- so a fault in one takes
the process down instead of reporting a failure, and finding that out in
seconds rather than after everything else has passed is the difference
between a usable iteration and a coffee break when a port is being brought
up.

The other in-tree callers are audited for which primitive they actually
meant.  nand_sim wants a daemon that outlives its caller and shares its
memory, which is task_fork().  bas's SHELL and EDIT statements, python's
_posixsubprocess and libwebsockets' feature macros want the fork-then-exec
path, which vfork() serves; python's os.fork() and libwebsockets'
LWS_HAVE_FORK stay on fork() proper.  fdsantest's vfork case follows vfork().

Two third-party suites need their source lists narrowed, because they call
fork() from code that is compiled unconditionally:

* system/libuv -- test-fork.c and test-pipe-close-stdout-read-stdin.c are
  filtered out of the test-*.c glob.  Every test they define is already
  excluded from the task list on NuttX by 0001-libuv-port-for-nuttx.patch --
  the nine fork_* entries and pipe_close_stdout_read_stdin -- so they were
  dead code being compiled only because fork() happened to be declared.
* testing/ltp -- the open_posix_testsuite is filtered through the existing
  BLACKWORDS mechanism, which already drops tests for absent features and is
  already conditioned on configuration symbols.  Where fork() is not
  provided this drops 278 of 1943 test files; the pattern is written to spare
  vfork() and task_fork(), which remain available.  Where fork() is provided
  -- which today is everywhere -- nothing is dropped.

Compatibility: the nuttx symbols this keys on do not exist yet.  task_fork.c
is built where CONFIG_TASK_FORK says task_fork() was built and, on a nuttx that
has no CONFIG_ARCH_HAVE_TASK_FORK at all -- which is the pre-split one -- where
CONFIG_ARCH_HAVE_FORK does.  Today's fork() *is* task_fork(), so the test that
has always covered that primitive keeps running, under its own name, and no
coverage is lost across the transition.  Both spellings are needed because
CONFIG_TASK_FORK is optional on the nuttx side:  ARCH_HAVE_TASK_FORK says the
architecture can clone a task, TASK_FORK says this build asked for it.  A
follow-up removes the fallback once the split has landed.

vfork_test() and fork_test() deliberately have no such fallback.  Both check
semantics a pre-split nuttx does not describe -- the parent suspension and the
private copy -- and ARCH_HAVE_VFORK is the evidence that the split has landed.
Mapping them onto ARCH_HAVE_FORK would also add a test to configurations that
never had one, which is not free:  vfork.c costs about 470 bytes of .text on
armv7-m at -Os, and that is what put lm3s6965-ek:qemu-protected over its 128
KiB user flash region.

Signed-off-by: Marco Casaroli <marco.casaroli@gmail.com>

Assisted-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-07-31 14:35:25 +02:00
..
bare netutils: Add BARE 2026-01-23 11:05:48 -03:00
chat apps: Fix unchecked strdup()/asprintf() as requested in #1727 2026-05-23 16:30:52 -04:00
cjson netutils/cjson: fix apps path in CMake 2026-03-26 20:18:52 -04:00
cmux include/debug.h: Use <nuttx/debug.h> in apps 2026-04-11 10:39:27 -03:00
codecs !fsutils/passwd: Replace TEA with PBKDF2-HMAC-SHA256 2026-07-22 17:21:22 +08:00
connectedhomeip netutils: migrate the license to ASF 2024-12-21 13:53:10 +08:00
cwebsocket netutils: migrate the license to ASF 2024-12-21 13:53:10 +08:00
dhcp6c include/debug.h: Use <nuttx/debug.h> in apps 2026-04-11 10:39:27 -03:00
dhcpc netutils/dhcpc: parse DHCP NTP server option 2026-04-24 10:44:08 -03:00
dhcpd !apps: replace sclock_t with clock_t and drop redundant time_t/off_t casts 2026-05-11 17:38:32 +08:00
discover include/debug.h: Use <nuttx/debug.h> in apps 2026-04-11 10:39:27 -03:00
dropbear netutils/dropbear: back chacha20-poly1305 with NuttX /dev/crypto 2026-07-26 07:54:11 -03:00
esp8266 include/debug.h: Use <nuttx/debug.h> in apps 2026-04-11 10:39:27 -03:00
ftpc apps: Fix unchecked strdup()/asprintf() as requested in #1727 2026-05-23 16:30:52 -04:00
ftpd apps: Fix unchecked strdup()/asprintf() as requested in #1727 2026-05-23 16:30:52 -04:00
iperf iperf: compatible work with no IPv4 2026-01-04 00:06:17 +08:00
iptables netutils: migrate the license to ASF 2024-12-21 13:53:10 +08:00
jsoncpp netutils: migrate the license to ASF 2024-12-21 13:53:10 +08:00
libcoap netutils: migrate the license to ASF 2024-12-21 13:53:10 +08:00
libcurl4nx include/debug.h: Use <nuttx/debug.h> in apps 2026-04-11 10:39:27 -03:00
libshvc apps: fix distclean for partial builds and residual .kconfig files 2026-07-09 09:25:33 +08:00
libulut apps: fix distclean for partial builds and residual .kconfig files 2026-07-09 09:25:33 +08:00
libwebsockets testing/ostest: split the fork test into task_fork, vfork and fork 2026-07-31 14:35:25 +02:00
mdns include/debug.h: Use <nuttx/debug.h> in apps 2026-04-11 10:39:27 -03:00
mqttc netutils/mqttc: fix patch and add mbedtls dependency 2026-04-10 12:23:37 -03:00
nanopb netutils/nanopb: fix unpack step for MACOS 2025-07-14 15:48:08 -03:00
netcat netutils: migrate the license to ASF 2024-12-21 13:53:10 +08:00
netinit !apps: drop CONFIG_SYSTEM_TIME64 conditionals 2026-05-11 17:38:32 +08:00
netlib netlib: replace DNS ping with gateway ping for connectivity check 2026-05-14 11:58:15 +08:00
nng netutils/nng: Update help for NETUTILS_NNG 2026-01-21 09:48:11 +08:00
ntpclient !apps: drop redundant casts on tv_sec/tv_nsec and fix printf formats 2026-05-22 13:38:25 +08:00
paho_mqtt paho_mqtt: Add mqtt compilation files 2025-12-25 12:20:17 +08:00
ping icmpv6_ping.c: change socket type from SOCK_DGRAM to SOCK_RAW. 2026-01-19 22:52:06 +08:00
plcatool netutils: Add plcatool 2025-09-17 19:29:10 +08:00
pppd include/debug.h: Use <nuttx/debug.h> in apps 2026-04-11 10:39:27 -03:00
ptpd !apps: drop redundant casts on tv_sec/tv_nsec and fix printf formats 2026-05-22 13:38:25 +08:00
rexec netutils/rexec: initialize ret to avoid maybe-uninitialized 2026-06-27 08:47:46 -03:00
rexecd netutils/rexecd: forward PRIORITY/STACKSIZE config in CMake build 2026-07-23 17:18:08 -03:00
rtptools netutils: migrate the license to ASF 2024-12-21 13:53:10 +08:00
smtp netutils: smtp: treat recv EOF as an error 2026-07-09 09:29:57 +08:00
telnetc Remove unused header files across multiple source files 2025-01-10 21:42:00 +08:00
telnetd include/debug.h: Use <nuttx/debug.h> in apps 2026-04-11 10:39:27 -03:00
tftpc include/debug.h: Use <nuttx/debug.h> in apps 2026-04-11 10:39:27 -03:00
thttpd netutils/thttpd: Apply the same check to related allocation sites 2026-05-23 16:30:52 -04:00
wakaama wakaama: add support for TLV 2026-05-18 16:18:53 -04:00
wakeonlan netutils: migrate the license to ASF 2024-12-21 13:53:10 +08:00
webclient include/debug.h: Use <nuttx/debug.h> in apps 2026-04-11 10:39:27 -03:00
webserver apps: Fix unchecked strdup()/asprintf() as requested in #1727 2026-05-23 16:30:52 -04:00
xedge netutils/xedge: refactor Makefile to use git clone instead of zip downloads 2025-08-02 10:00:20 -03:00
xmlrpc netutils: migrate the license to ASF 2024-12-21 13:53:10 +08:00
.gitignore build: Remve the unnecessary .gitignore 2020-05-23 15:56:35 +01:00
CMakeLists.txt netutils: migrate the license to ASF 2024-12-21 13:53:10 +08:00
Make.defs netutils: migrate the license to ASF 2024-12-21 13:53:10 +08:00
Makefile netutils: migrate the license to ASF 2024-12-21 13:53:10 +08:00