testing/fs/xipfs: Add a test suite for the xipfs file system.

Twelve sections, selected by name on the command line because the power loss
sweeps run for minutes while everything else runs in seconds.

The routine part covers the VFS paths, the write-once rules (reopen for
write, append, seek during write, truncate of a written file are all refused)
and both mmap variants: that a plain mapping lands inside the media window
with no heap growth, that MAP_XIP_STRICT fails with ENXIO rather than
copying, and that N mappings of one file produce N pins on one extent.

The rest is aimed at the two properties that are easy to get wrong and quiet
when they are:

Pin release.  A pin taken by one task and a task that dies with a mapping
still live both have to end with the extent movable again -- the second
without the task ever calling munmap, since a module that faults never will.
Both are checked by asking the defragmenter to move the extent afterwards.

Power-loss atomicity.  With CONFIG_FS_XIPFS_FAULT_INJECT the suite fails the
Nth flash operation, remounts, and checks the volume is consistent and every
file that had been committed is byte-for-byte intact.  It sweeps N across
create, unlink and defragmentation, and repeats the sweep with the failing
write torn -- a partial program rather than a clean refusal -- which is what
a real power loss mid-program leaves behind.

Assisted-by: Claude Code:claude-opus-5
Signed-off-by: Marco Casaroli <marco.casaroli@gmail.com>
This commit is contained in:
Marco Casaroli 2026-07-25 13:53:16 +02:00 committed by Xiang Xiao
parent b695ec057f
commit 3a03552c6a
5 changed files with 2164 additions and 0 deletions

View file

@ -0,0 +1,33 @@
# ##############################################################################
# apps/testing/fs/xipfs/CMakeLists.txt
#
# 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.
#
# ##############################################################################
if(CONFIG_TESTING_FS_XIPFS)
nuttx_add_application(
NAME
xipfs_test
STACKSIZE
${CONFIG_DEFAULT_TASK_STACKSIZE}
MODULE
${CONFIG_TESTING_FS_XIPFS}
SRCS
xipfs_main.c)
endif()

38
testing/fs/xipfs/Kconfig Normal file
View file

@ -0,0 +1,38 @@
#
# For a description of the syntax of this configuration file,
# see the file kconfig-language.txt in the NuttX tools repository.
#
config TESTING_FS_XIPFS
tristate "XIPFS file system test"
depends on FS_XIPFS
default n
---help---
Exercise the XIPFS filesystem: the routine VFS paths, the
write-once rules, the in-place mmap and its strict variant, and
then the corners that actually carry risk -- power loss atomicity
of the metadata commit, and release of XIP pins when a task dies
without unmapping.
Takes an optional section name to run just one part, since the
power loss sweeps take minutes and everything else takes seconds:
xipfs_test everything
xipfs_test xip just the execute-in-place mapping tests
Sections: basic writeonce strict xip multimap crosstask teardown
dirs defrag powerloss powertorn unlink dirloss defraglos
The power loss sections need CONFIG_FS_XIPFS_FAULT_INJECT.
if TESTING_FS_XIPFS
config TESTING_FS_XIPFS_MOUNTPT
string "XIPFS mountpoint"
default "/mnt/xipfs"
config TESTING_FS_XIPFS_MTD
string "MTD device backing the filesystem"
default "/dev/rammtd"
endif # TESTING_FS_XIPFS

View file

@ -0,0 +1,25 @@
############################################################################
# apps/testing/fs/xipfs/Make.defs
#
# 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.
#
############################################################################
ifneq ($(CONFIG_TESTING_FS_XIPFS),)
CONFIGURED_APPS += $(APPDIR)/testing/fs/xipfs
endif

34
testing/fs/xipfs/Makefile Normal file
View file

@ -0,0 +1,34 @@
############################################################################
# apps/testing/fs/xipfs/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
# XIPFS file system test
PROGNAME = xipfs_test
PRIORITY = SCHED_PRIORITY_DEFAULT
STACKSIZE = $(CONFIG_DEFAULT_TASK_STACKSIZE)
MODULE = $(CONFIG_TESTING_FS_XIPFS)
MAINSRC = xipfs_main.c
include $(APPDIR)/Application.mk

File diff suppressed because it is too large Load diff