testing/ostest: Split the fork test into vfork and fork. - #3685
Draft
casaroli wants to merge 1 commit into
Draft
Conversation
This was referenced Jul 31, 2026
casaroli
force-pushed
the
fork-semantics-ostest-cleanup
branch
from
August 2, 2026 10:35
d3b7722 to
bbc21fe
Compare
acassis
previously approved these changes
Aug 2, 2026
casaroli
force-pushed
the
fork-semantics-ostest-cleanup
branch
from
August 2, 2026 13:57
bbc21fe to
45b4ba7
Compare
| else | ||
| @echo "export ac_cv_func_fork=\"no\"" >> $@ | ||
| endif | ||
| ifneq ($(CONFIG_ARCH_HAVE_VFORK),) |
|
|
||
| /* Define to 1 if you have the `fork' function. */ | ||
|
|
||
| #ifdef CONFIG_ARCH_HAVE_FORK |
| assert_int_equal(open_count, close_count); | ||
| } | ||
|
|
||
| #ifdef CONFIG_ARCH_HAVE_VFORK |
casaroli
force-pushed
the
fork-semantics-ostest-cleanup
branch
2 times, most recently
from
August 2, 2026 17:19
ce27719 to
1f61625
Compare
ostest's "vfork" test was never testing vfork(). It has the child write a global and the parent observe the write -- 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 passed because NuttX implemented fork() and vfork() as the same sharing primitive, which apache/nuttx#19562 separates. 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. Since the child may not write memory and the parent cannot run while the child lives, the observable is the child's exit status: had the parent not been suspended, it would have reached waitpid() while the child was still alive. Where child status is not retained -- ostest_main() sets SA_NOCLDWAIT for the whole run, deliberately -- ECHILD is accepted as equally good evidence, since 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(). Both run at the top of user_main(). 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. Learning that in seconds rather than after everything else has passed matters when a port is being brought up. Each test gates on the one primitive it tests, ARCH_HAVE_VFORK and ARCH_HAVE_FORK respectively. There is no compatibility layer and no mapping between symbols. vfork.c no longer requires SCHED_WAITPID: the suspension is in the kernel primitive now, so the test's core assertion holds without it and only the status check is conditional. The other in-tree callers are audited for which primitive they actually meant: * interpreters/python's _posixsubprocess and netutils/libwebsockets' LWS_HAVE_WORKING_VFORK want the fork-then-exec path -- ARCH_HAVE_VFORK. * python's os.fork() and libwebsockets' LWS_HAVE_FORK mean real fork() and stay on ARCH_HAVE_FORK, so they become *absent* rather than silently wrong. * testing/fs/fdsantest's vfork case follows ARCH_HAVE_VFORK. interpreters/bas is deliberately left alone. Its SHELL and EDIT statements reach for vfork() under an ARCH_HAVE_FORK guard and want the same treatment, but checkpatch.sh checks the whole of any file a patch touches and bas_statement.c produces 1681 pre-existing findings against master, so a one-line change there fails CI on its own. The consequence is small: EXAMPLES_BAS_SHELL is EXPERIMENTAL and already depends on ARCH_HAVE_FORK, so it becomes unselectable rather than misbehaving. Assisted-by: Claude Code:claude-opus-5 Signed-off-by: Marco Casaroli <marco.casaroli@gmail.com>
casaroli
force-pushed
the
fork-semantics-ostest-cleanup
branch
from
August 8, 2026 07:48
1f61625 to
ae340d5
Compare
🔗 Cross-repo PR dependenciesThe read-only Build run reported the following dependent PR(s) and fetched head SHA(s): CI run: https://github.com/apache/nuttx-apps/actions/runs/31246994111 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Depends-On: apache/nuttx#19562
Summary
apache/nuttx#19562 separates
fork()andvfork(), which NuttX implements as the same function. This gives each one a test of its own.ostest's "vfork" test was never testingvfork(). It has the child write a global and the parent observe the write — the defining property of sharing, not ofvfork(), whose defining property is that the parent is suspended and whose contract forbids the child to write anything at all. It passed because both names resolved to the same sharing primitive.vfork.cis rewritten to test whatvfork()promises. The child does only what POSIX permits — it calls_exit(42)and nothing else, not evenexit(), which would runatexithandlers and flush stdio in the parent's address space. Since the child may not write memory and the parent cannot run while the child lives, the observable is the child's exit status: had the parent not been suspended, it would have reachedwaitpid()while the child was still alive. Where child status is not retained —ostest_main()setsSA_NOCLDWAITfor the whole run, deliberately —ECHILDis accepted as equally good evidence, since it says the child was already gone when the parent asked.fork.cis new and tests POSIXfork(): the child's writes to.data,.bssand 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 avfork()child may not — callsmalloc()andprintf(), and returns from the function that calledfork().Both run at the top of
user_main(). 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. That matters more than usual right now, becauseostestdoes not currently run to completion on any target: it aborts later intimedmutex_timeout_regression_test()attimedmutex.c:185, added by master eea8384 and unrelated to this PR. Running first is the only reason the fork tests run at all.Each test gates on the one primitive it tests,
ARCH_HAVE_VFORKandARCH_HAVE_FORKrespectively. There is no compatibility layer and no mapping between symbols.vfork.cno longer requiresSCHED_WAITPID: the suspension lives in the kernel primitive now, so the test's core assertion holds without it and only the status check is conditional.The other in-tree callers are audited for which primitive they actually meant:
interpreters/python's_posixsubprocessandnetutils/libwebsockets'LWS_HAVE_WORKING_VFORKwant the fork-then-exec path —ARCH_HAVE_VFORK.python'sos.fork()andlibwebsockets'LWS_HAVE_FORKmean realfork()and stay onARCH_HAVE_FORK, so they become absent rather than silently wrong.testing/fs/fdsantest'svforkcase followsARCH_HAVE_VFORK.interpreters/basis deliberately left alone. ItsSHELLandEDITstatements reach forvfork()under anARCH_HAVE_FORKguard and want the same treatment, butcheckpatch.shchecks the whole of any file a patch touches andbas_statement.cproduces 1681 pre-existing findings against master, so a one-line change there fails CI on its own. The consequence is small:EXAMPLES_BAS_SHELLisEXPERIMENTALand alreadydepends on ARCH_HAVE_FORK, so it becomes unselectable rather than misbehaving.Ordering
This PR must merge after apache/nuttx#19562, because the symbols each test keys on do not exist until it lands.
It is not a blocker for that PR's CI. The
appschanges that unblocked it were #3673, which merged on 2026-08-03 — nothing inappsmaster callsfork()unconditionally any more, soappsmaster builds against #19562 as it stands. Two commits from this branch's earlier revision were part of that PR and have been dropped in a rebase onto current master; what remains is one commit.Between apache/nuttx#19562 merging and this PR merging,
ostesthas no fork test. That is the deliberate cost of carrying no compatibility layer.fork_test()costs nothing on size-constrained configurations, because it is not built on them. It keys onARCH_HAVE_FORK, which no architecture sets untilup_addrenv_fork()lands for it, solm3s6965-ek:qemu-protected— the configuration with the tightest user flash region — never compiles it. It is exercised by the per-architecture PRs that follow, which are what turnARCH_HAVE_FORKback on.Testing
Host: macOS 15 (Darwin 25.5.0) on Apple Silicon. QEMU 11.0.3, xPack
riscv-none-elf-gcc14.2.0-3, Arm GNUarm-none-eabi-gcc/aarch64-none-elf-gcc14.2.rel1,xtensa-esp32s3-elf-gcc12.2.0.../nuttx/tools/checkpatch.sh -c -u -m -g <base>..HEAD, the exact command.github/workflows/check.ymlruns — ✔️ All checks pass, withcodespell,cvt2utf,cmake-formatandnxstyleinstalled.vfork_test()passes onraspberrypi-pico-2:nsh(real RP2350),qemu-armv7a:nsh,qemu-armv8a:nsh,rv-virt:nsh64andsim:nsh, built against apache/nuttx#19562:esp32s3-devkit:osteston real ESP32-S3 hardware builds and boots clean with neither test compiled in — Xtensa selects neitherARCH_HAVE_VFORKnorARCH_HAVE_FORKand has no fork entry point, so it is the "architecture this does not touch" case.fork_test()is not exercised yet by construction: no architecture selectsARCH_HAVE_FORKuntil a per-architecture PR implementsup_addrenv_fork().