mirror of
https://github.com/apache/nuttx-apps.git
synced 2026-08-23 22:48:20 +00:00
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>
335 lines
9.4 KiB
C
335 lines
9.4 KiB
C
/****************************************************************************
|
|
* apps/testing/ostest/ostest.h
|
|
*
|
|
* 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.
|
|
*
|
|
****************************************************************************/
|
|
|
|
#ifndef __APPS_TESTING_OSTEST_OSTEST_H
|
|
#define __APPS_TESTING_OSTEST_OSTEST_H
|
|
|
|
/****************************************************************************
|
|
* Included Files
|
|
****************************************************************************/
|
|
|
|
#include <nuttx/config.h>
|
|
#include <stdbool.h>
|
|
#include <inttypes.h>
|
|
#include <signal.h>
|
|
|
|
/****************************************************************************
|
|
* Pre-processor Definitions
|
|
****************************************************************************/
|
|
|
|
/* The task_create task size can be specified in the defconfig file */
|
|
|
|
#ifdef CONFIG_TESTING_OSTEST_STACKSIZE
|
|
# define STACKSIZE CONFIG_TESTING_OSTEST_STACKSIZE
|
|
#else
|
|
# define STACKSIZE 8192
|
|
#endif
|
|
|
|
/* The number of times to execute the test can be specified in the defconfig
|
|
* file.
|
|
*/
|
|
|
|
#ifndef CONFIG_TESTING_OSTEST_LOOPS
|
|
# define CONFIG_TESTING_OSTEST_LOOPS 1
|
|
#endif
|
|
|
|
/* This is the number of threads that are created in the barrier test.
|
|
* A smaller number should be selected on systems without sufficient memory
|
|
* to start so many threads.
|
|
*/
|
|
|
|
#ifndef CONFIG_TESTING_OSTEST_NBARRIER_THREADS
|
|
# define CONFIG_TESTING_OSTEST_NBARRIER_THREADS 8
|
|
#endif
|
|
|
|
/* Priority inheritance */
|
|
|
|
#if defined(CONFIG_DEBUG_FEATURES) && defined(CONFIG_PRIORITY_INHERITANCE) && defined(CONFIG_SEM_PHDEBUG)
|
|
# define dump_nfreeholders(s) printf(s " nfreeholders: %d\n", sem_nfreeholders())
|
|
#else
|
|
# define dump_nfreeholders(s)
|
|
#endif
|
|
|
|
/* If CONFIG_STDIO_LINEBUFFER is defined, the STDIO buffer will be flushed
|
|
* on each new line. Otherwise, STDIO needs to be explicitly flushed to
|
|
* see the output in context.
|
|
*/
|
|
|
|
#ifndef CONFIG_STDIO_BUFFER_SIZE
|
|
# define CONFIG_STDIO_BUFFER_SIZE 0
|
|
#endif
|
|
|
|
#if defined(CONFIG_FILE_STREAM) && CONFIG_STDIO_BUFFER_SIZE > 0 && \
|
|
!defined(CONFIG_STDIO_LINEBUFFER)
|
|
# define FFLUSH() fflush(stdout)
|
|
#else
|
|
# define FFLUSH()
|
|
#endif
|
|
|
|
/****************************************************************************
|
|
* Public Function Prototypes
|
|
****************************************************************************/
|
|
|
|
/* getopt.c *****************************************************************/
|
|
|
|
int getopt_test(void);
|
|
|
|
/* libc_memmem.c ************************************************************/
|
|
|
|
int memmem_test(void);
|
|
|
|
/* setvbuf.c ****************************************************************/
|
|
|
|
#ifndef CONFIG_STDIO_DISABLE_BUFFERING
|
|
int setvbuf_test(void);
|
|
#endif
|
|
|
|
/* dev_null.c ***************************************************************/
|
|
|
|
#ifdef CONFIG_DEV_NULL
|
|
int dev_null_test(void);
|
|
#endif
|
|
|
|
/* multiuser.c **************************************************************/
|
|
|
|
#if defined(CONFIG_TESTING_OSTEST_MULTIUSER) && defined(CONFIG_SCHED_USER_IDENTITY)
|
|
int multiuser_test(void);
|
|
#endif
|
|
|
|
/* fpu.c ********************************************************************/
|
|
|
|
void fpu_test(void);
|
|
|
|
/* aio.c ********************************************************************/
|
|
|
|
#ifdef CONFIG_TESTING_OSTEST_AIO
|
|
void aio_test(void);
|
|
#endif
|
|
|
|
/* restart.c ****************************************************************/
|
|
|
|
#ifndef CONFIG_BUILD_KERNEL
|
|
void restart_test(void);
|
|
#endif
|
|
|
|
/* waitpid.c ****************************************************************/
|
|
|
|
#ifdef CONFIG_SCHED_WAITPID
|
|
int waitpid_test(void);
|
|
#endif
|
|
|
|
/* wqueue.c *****************************************************************/
|
|
|
|
#if defined(CONFIG_SCHED_LPWORK) || defined(CONFIG_SCHED_HPWORK)
|
|
void wqueue_test(void);
|
|
#endif
|
|
|
|
/* mutex.c ******************************************************************/
|
|
|
|
void mutex_test(void);
|
|
|
|
/* timedmutex.c *************************************************************/
|
|
|
|
void timedmutex_test(void);
|
|
|
|
/* rmutex.c *****************************************************************/
|
|
|
|
void recursive_mutex_test(void);
|
|
|
|
/* sem.c ********************************************************************/
|
|
|
|
void sem_test(void);
|
|
|
|
/* semtimed.c ***************************************************************/
|
|
|
|
void semtimed_test(void);
|
|
|
|
/* nsem.c *******************************************************************/
|
|
|
|
void nsem_test(void);
|
|
|
|
/* cond.c *******************************************************************/
|
|
|
|
void cond_test(void);
|
|
|
|
/* specific.c ***************************************************************/
|
|
|
|
void specific_test(void);
|
|
|
|
/* mqueue.c *****************************************************************/
|
|
|
|
void mqueue_test(void);
|
|
|
|
/* timedmqueue.c ************************************************************/
|
|
|
|
void timedmqueue_test(void);
|
|
|
|
/* cancel.c *****************************************************************/
|
|
|
|
void cancel_test(void);
|
|
|
|
/* robust.c *****************************************************************/
|
|
|
|
#ifndef CONFIG_PTHREAD_MUTEX_UNSAFE
|
|
void robust_test(void);
|
|
#endif
|
|
|
|
/* timedwait.c **************************************************************/
|
|
|
|
void timedwait_test(void);
|
|
|
|
/* sigprocmask.c ************************************************************/
|
|
|
|
void sigprocmask_test(void);
|
|
|
|
/* sighelper.c **************************************************************/
|
|
|
|
bool sigset_isequal(FAR const sigset_t *left, FAR const sigset_t *right);
|
|
|
|
/* sighand.c ****************************************************************/
|
|
|
|
void sighand_test(void);
|
|
|
|
/* signest.c ****************************************************************/
|
|
|
|
void signest_test(void);
|
|
|
|
/* suspend.c ****************************************************************/
|
|
|
|
void suspend_test(void);
|
|
|
|
/* wdog.c *******************************************************************/
|
|
|
|
void wdog_test(void);
|
|
|
|
/* hrtimer.c ****************************************************************/
|
|
|
|
#ifdef CONFIG_HRTIMER
|
|
void hrtimer_test(void);
|
|
#endif
|
|
|
|
/* posixtimers.c ************************************************************/
|
|
|
|
void timer_test(void);
|
|
void sigev_thread_test(void);
|
|
|
|
/* roundrobin.c *************************************************************/
|
|
|
|
void rr_test(void);
|
|
|
|
/* sporadic.c ***************************************************************/
|
|
|
|
void sporadic_test(void);
|
|
|
|
/* sporadic2.c **************************************************************/
|
|
|
|
void sporadic2_test(void);
|
|
|
|
/* tls.c ********************************************************************/
|
|
|
|
void tls_test(void);
|
|
|
|
/* sched_thread_local.c *****************************************************/
|
|
|
|
void sched_thread_local_test(void);
|
|
|
|
/* pthread_rwlock.c *********************************************************/
|
|
|
|
void pthread_rwlock_test(void);
|
|
|
|
/* pthread_rwlock_cancel.c **************************************************/
|
|
|
|
void pthread_rwlock_cancel_test(void);
|
|
|
|
/* pthread_exit.c ***********************************************************/
|
|
|
|
#ifdef CONFIG_SCHED_WAITPID
|
|
void pthread_exit_test(void);
|
|
#endif
|
|
|
|
/* pthread_cleanup.c ********************************************************/
|
|
|
|
void pthread_cleanup_test(void);
|
|
|
|
/* barrier.c ****************************************************************/
|
|
|
|
void barrier_test(void);
|
|
|
|
/* prioinherit.c ************************************************************/
|
|
|
|
void priority_inheritance(void);
|
|
|
|
/* schedlock.c **************************************************************/
|
|
|
|
void sched_lock_test(void);
|
|
|
|
/* vfork.c ******************************************************************/
|
|
|
|
#ifdef CONFIG_ARCH_HAVE_VFORK
|
|
int vfork_test(void);
|
|
#endif
|
|
|
|
/* fork.c *******************************************************************/
|
|
|
|
#ifdef CONFIG_ARCH_HAVE_FORK
|
|
int fork_test(void);
|
|
#endif
|
|
|
|
/* setjmp.c *****************************************************************/
|
|
|
|
void setjmp_test(void);
|
|
|
|
/* smp_call.c ***************************************************************/
|
|
|
|
#ifdef CONFIG_SMP
|
|
void smp_call_test(void);
|
|
#endif
|
|
|
|
/* spinlock.c ***************************************************************/
|
|
|
|
void spinlock_test(void);
|
|
|
|
/* perf_gettime.c ***********************************************************/
|
|
|
|
#if defined(CONFIG_ARCH_HAVE_PERF_EVENTS) && defined(CONFIG_BUILD_FLAT)
|
|
void perf_gettime_test(void);
|
|
#endif
|
|
|
|
/* APIs exported (conditionally) by the OS specifically for testing of
|
|
* priority inheritance
|
|
*/
|
|
|
|
#if defined(CONFIG_DEBUG_FEATURES) && defined(CONFIG_PRIORITY_INHERITANCE) && defined(CONFIG_SEM_PHDEBUG)
|
|
void sem_enumholders(FAR sem_t *sem);
|
|
int sem_nfreeholders(void);
|
|
#else
|
|
# define sem_enumholders(sem)
|
|
# define sem_nfreeholders()
|
|
#endif
|
|
|
|
/* nxevent.c ****************************************************************/
|
|
|
|
#if defined(CONFIG_SCHED_EVENTS) && defined(CONFIG_BUILD_FLAT)
|
|
void nxevent_test(void);
|
|
#endif
|
|
|
|
#endif /* __APPS_TESTING_OSTEST_OSTEST_H */
|