nuttx-apps/testing/ostest/Makefile

197 lines
4.1 KiB
Makefile
Raw Normal View History

############################################################################
# apps/testing/ostest/Makefile
#
# SPDX-License-Identifier: Apache-2.0
#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership. The
# ASF licenses this file to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance with the
# License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
#
############################################################################
include $(APPDIR)/Make.defs
# ostest built-in application info
PROGNAME = ostest
PRIORITY = SCHED_PRIORITY_DEFAULT
STACKSIZE = $(CONFIG_DEFAULT_TASK_STACKSIZE)
MODULE = $(CONFIG_TESTING_OSTEST)
# NuttX OS Test
CSRCS = getopt.c libc_memmem.c libc_strto.c restart.c sighelper.c
ifeq ($(CONFIG_ENABLE_ALL_SIGNALS),y)
CSRCS += sighand.c signest.c
endif
ifneq ($(CONFIG_DISABLE_ALL_SIGNALS),y)
CSRCS += sigprocmask.c
endif
MAINSRC = ostest_main.c
ifeq ($(CONFIG_DEV_NULL),y)
CSRCS += dev_null.c
endif
ifeq ($(CONFIG_SIG_SIGSTOP_ACTION),y)
ifeq ($(CONFIG_SIG_SIGKILL_ACTION),y)
CSRCS += suspend.c
endif
endif
ifeq ($(CONFIG_ARCH_FPU),y)
ifneq ($(CONFIG_TESTING_OSTEST_FPUTESTDISABLE),y)
CSRCS += fpu.c
endif
endif
ifneq ($(CONFIG_STDIO_DISABLE_BUFFERING),y)
CSRCS += setvbuf.c
endif
ifneq ($(CONFIG_TLS_NELEM),0)
CSRCS += tls.c
endif
ifeq ($(CONFIG_SCHED_THREAD_LOCAL),y)
CSRCS += sched_thread_local.c
endif
ifeq ($(CONFIG_TESTING_OSTEST_AIO),y)
2014-10-05 13:24:03 -06:00
CSRCS += aio.c
endif
ifeq ($(CONFIG_TESTING_OSTEST_MULTIUSER),y)
CSRCS += multiuser.c
endif
ifeq ($(CONFIG_SCHED_WAITPID),y)
CSRCS += waitpid.c
endif
ifeq ($(CONFIG_FS_CHROOT),y)
ifeq ($(CONFIG_SCHED_WAITPID),y)
ifneq ($(CONFIG_BUILD_KERNEL),y)
CSRCS += chroot.c
endif
endif
endif
ifneq ($(CONFIG_DISABLE_PTHREAD),y)
CSRCS += cancel.c cond.c mutex.c timedmutex.c sem.c semtimed.c barrier.c
CSRCS += timedwait.c pthread_rwlock.c pthread_rwlock_cancel.c schedlock.c
ifeq ($(CONFIG_SCHED_WAITPID),y)
CSRCS += pthread_exit.c
endif
ifneq ($(CONFIG_TLS_NELEM),0)
CSRCS += specific.c
endif
ifneq ($(CONFIG_TLS_NCLEANUP),0)
CSRCS += pthread_cleanup.c
endif
2015-07-24 13:50:31 -06:00
ifneq ($(CONFIG_PTHREAD_MUTEX_UNSAFE),y)
CSRCS += robust.c
endif
2015-07-24 13:50:31 -06:00
ifeq ($(CONFIG_PTHREAD_MUTEX_TYPES),y)
CSRCS += rmutex.c
2015-07-24 13:50:31 -06:00
endif
ifeq ($(CONFIG_FS_NAMED_SEMAPHORES),y)
CSRCS += nsem.c
endif
2015-07-24 13:50:31 -06:00
ifneq ($(CONFIG_RR_INTERVAL),0)
CSRCS += roundrobin.c
endif
ifeq ($(CONFIG_SCHED_SPORADIC),y)
CSRCS += sporadic.c sporadic2.c
2015-07-24 13:50:31 -06:00
endif
ifeq ($(CONFIG_PRIORITY_INHERITANCE),y)
CSRCS += prioinherit.c
endif
endif # CONFIG_DISABLE_PTHREAD
ifeq ($(CONFIG_TESTING_OSTEST_WQUEUE),y)
CSRCS += wqueue.c
endif
ifneq ($(CONFIG_DISABLE_MQUEUE),y)
ifneq ($(CONFIG_DISABLE_PTHREAD),y)
CSRCS += timedmqueue.c
ifneq ($(CONFIG_DISABLE_ALL_SIGNALS),y)
CSRCS += mqueue.c
endif
endif # CONFIG_DISABLE_PTHREAD
endif # CONFIG_DISABLE_MQUEUE
ifneq ($(CONFIG_DISABLE_POSIX_TIMERS),y)
CSRCS += posixtimer.c
ifeq ($(CONFIG_SIG_EVTHREAD),y)
CSRCS += sigev_thread.c
endif
endif
testing/ostest: Split the fork test into vfork and fork. 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 simulator is the one exception. It selects ARCH_HAVE_VFORK, but ostest takes the sim down as soon as the test runs there, so the call keeps the !ARCH_SIM guard that apps ee7642793 put on the old test in 2024. The old gate hid this: ARCH_HAVE_FORK is not set on the sim, so the test was not built there at all. 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>
2026-08-07 13:03:08 +02:00
# Each test is built where the primitive it tests exists.
ifeq ($(CONFIG_ARCH_HAVE_VFORK),y)
CSRCS += vfork.c
endif
testing/ostest: Split the fork test into vfork and fork. 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 simulator is the one exception. It selects ARCH_HAVE_VFORK, but ostest takes the sim down as soon as the test runs there, so the call keeps the !ARCH_SIM guard that apps ee7642793 put on the old test in 2024. The old gate hid this: ARCH_HAVE_FORK is not set on the sim, so the test was not built there at all. 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>
2026-08-07 13:03:08 +02:00
ifeq ($(CONFIG_ARCH_HAVE_FORK),y)
CSRCS += fork.c
endif
ifeq ($(CONFIG_ARCH_SETJMP_H),y)
CSRCS += setjmp.c
endif
ifeq ($(CONFIG_SMP),y)
CSRCS += smp_call.c
endif
ifeq ($(CONFIG_SCHED_EVENTS),y)
ifeq ($(CONFIG_BUILD_FLAT),y)
CSRCS += nxevent.c
endif
endif
# perf_gettime() and perf_getfreq() live in the kernel and are not system
# calls, so only a flat build can reach them from here.
ifeq ($(CONFIG_ARCH_HAVE_PERF_EVENTS),y)
ifeq ($(CONFIG_BUILD_FLAT),y)
CSRCS += perf_gettime.c
endif
endif
ifeq ($(CONFIG_BUILD_FLAT),y)
CSRCS += wdog.c spinlock.c
ifeq ($(CONFIG_HRTIMER),y)
CSRCS += hrtimer.c
endif
endif
include $(APPDIR)/Application.mk