Skip to content

testing/ostest: drop the pre-split fork() fallbacks - #3685

Draft
casaroli wants to merge 2 commits into
apache:masterfrom
casaroli:fork-semantics-ostest-cleanup
Draft

testing/ostest: drop the pre-split fork() fallbacks#3685
casaroli wants to merge 2 commits into
apache:masterfrom
casaroli:fork-semantics-ostest-cleanup

Conversation

@casaroli

@casaroli casaroli commented Jul 31, 2026

Copy link
Copy Markdown
Contributor

Important

Merge order — this PR is last:

  1. testing/ostest: split the fork test into task_fork, vfork and fork #3673 — the apps-side split. Tolerant of NuttX with and without the core change, so it goes first.
  2. sched/arch/libc: give fork(), vfork() and task_fork() their real, separate semantics nuttx#19562 — the NuttX core split, which creates TASK_FORK, ARCH_HAVE_VFORK and ARCH_HAVE_FORK.
  3. this PR — removes the compatibility layer that step 1 needed. Merged any earlier it deletes the fork tests from every configuration.

Also stacked: the first of the two commits below is #3673 and is not for review here. Only testing/ostest: drop the pre-split fork() fallbacks belongs to this PR.

Open as a draft while #3673 is in review, because several comments there ask for exactly this end state.

Summary

#3673 has every fork-family test also accept CONFIG_ARCH_HAVE_FORK, because the NuttX symbols do not exist yet. Once #19562 lands that is unnecessary, and each test gates on the one primitive it tests:

test gate
task_fork_test() CONFIG_TASK_FORK
vfork_test() CONFIG_ARCH_HAVE_VFORK
fork_test() CONFIG_ARCH_HAVE_FORK

The OSTEST_HAVE_* indirection and the task_fork() -> fork() shim in nand_sim_main.c go with the fallbacks. task_fork.c's whole-file #ifdef goes too — the build files already decide whether it compiles, which is why fork.c and vfork.c carry none. The same || ARCH_HAVE_FORK fallbacks are dropped from interpreters/python, netutils/libwebsockets, testing/fs/fdsantest and testing/drivers/nand_sim.

task_fork_test() keys on CONFIG_TASK_FORK, not the capability symbol: ARCH_HAVE_TASK_FORK says the architecture can clone a task, TASK_FORK says this build asked for it, and task_fork() is declared only under the latter — so gating on the capability alone fails to compile a TASK_FORK=n build. TESTING_NAND_SIM depends on it for the same reason.

Impact

Testing

macOS 15 on Apple Silicon, QEMU 11.0.3, xPack riscv-none-elf-gcc 14.2.0-3. ostest built and run against a NuttX carrying the split:

config verdict task_fork vfork fork
rv-virt:nsh64 (FLAT) PASS, exit 0 PASS PASS absent
rv-virt:knsh64 (KERNEL) PASS, exit 0 PASS PASS PASS
task_fork_test: Child 6 ran successfully
vfork_test: Child 7 ran and exited before the parent resumed
fork_test: Parent and child had independent memory
ostest_main: Exiting with status 0

fork_test absent on FLAT and present on KERNEL is intended: ARCH_HAVE_FORK follows ARCH_ADDRENV && ARCH_HAVE_ADDRENV_FORK, so only a configuration with an address environment provides POSIX fork().

../nuttx/tools/checkpatch.sh -c -u -m -g <base>..HEAD✔️ All checks pass.

PR verification self-check

  • This PR introduces one focused functional change.
  • All required PR description fields are completed.
  • The commit has a descriptive topic/body, Signed-off-by, and Assisted-by trailer.
  • This PR is a draft, and its merge order is stated above.

casaroli added 2 commits July 31, 2026 14:35
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>
The previous commit had task_fork_test() also accept CONFIG_ARCH_HAVE_FORK,
because the nuttx symbols naming the three primitives did not exist yet.  nuttx
now has them, so each test gates on the one primitive it tests and nothing
stands in for anything.

The OSTEST_HAVE_* indirection goes with the fallbacks, as does the
task_fork()->fork() shim in nand_sim_main.c.  The whole-file #ifdef in
task_fork.c goes too:  the build files already decide whether the file is
compiled, which is why fork.c and vfork.c do not carry one either.

task_fork_test() keys on CONFIG_TASK_FORK rather than the capability symbol.
ARCH_HAVE_TASK_FORK says the architecture can clone a task; TASK_FORK says this
build asked for it, and task_fork() is declared only under the latter, so
gating on the capability alone would fail to compile a TASK_FORK=n build.
TESTING_NAND_SIM depends on the same symbol for the same reason.  vfork_test()
and fork_test() have no such split and key on ARCH_HAVE_VFORK and
ARCH_HAVE_FORK directly.

This must not be merged before the nuttx side.

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

Assisted-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant