Skip to content

Commit 88a3ebb

Browse files
committed
examples/sotest: support packaged shared library fixtures.
Extend the examples/sotest packaging path so the shared-library test fixtures can also be prepared through nxpkg-style package artifacts. Generate shared-index.json and pkgsotest.nsh from the built modprint and sotest shared objects, recording the correct target arch/compat metadata and SHA-256 digests for the packaged shared-library fixtures. Allow sotest to run in either its existing builtin-ROMFS flow or from explicit shared-library paths, with a --mount helper mode for preparing the builtin test mount separately. Keep the paired fixture outputs in one grouped make step so parallel builds do not re-enter the generator independently. This makes the sotest shared-library example usable as a package-style fixture producer for the Dynamic ELF/nxpkg series, useful for validating the shared-library side of the packaging flow where the loader should consume installed artifacts rather than only the default builtin test paths. The existing builtin-ROMFS path is preserved with no regression to the normal sotest example flow. Assisted-by: Claude:claude-sonnet-5 Assisted-by: OpenAI Codex:gpt-5.6-sol Signed-off-by: aviralgarg05 <gargaviral99@gmail.com>
1 parent 094b988 commit 88a3ebb

8 files changed

Lines changed: 729 additions & 31 deletions

File tree

examples/sotest/Make.defs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,11 @@
2020
#
2121
############################################################################
2222

23-
include $(wildcard $(APPDIR)/examples/sotest/*/Make.defs)
23+
ifeq ($(CONFIG_EXAMPLES_SOTEST),y)
24+
include $(APPDIR)/examples/sotest/main/Make.defs
25+
endif
26+
27+
ifneq ($(CONFIG_EXAMPLES_SOTEST),n)
28+
include $(APPDIR)/examples/sotest/modprint/Make.defs
29+
include $(APPDIR)/examples/sotest/sotest/Make.defs
30+
endif

examples/sotest/main/CMakeLists.txt

Lines changed: 97 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -21,27 +21,107 @@
2121
# ##############################################################################
2222

2323
if(CONFIG_EXAMPLES_SOTEST)
24+
set(SOTEST_SYMTAB ${CMAKE_CURRENT_BINARY_DIR}/sotest_symtab.c)
25+
set(SOTEST_ROMFS_IMG ${CMAKE_CURRENT_BINARY_DIR}/sotest_romfs.img)
26+
set(SOTEST_ROMFS_SRC ${CMAKE_CURRENT_BINARY_DIR}/sotest_romfs.c)
27+
set(SOTEST_MODPRINT_ELF ${CMAKE_BINARY_DIR}/bin/modprint)
28+
set(SOTEST_SHARED_ELF ${CMAKE_BINARY_DIR}/bin/sotest)
29+
30+
# Dynamic applications are wrapped in ELF_* helper targets when the build uses
31+
# the non-ELF-capable compiler path.
32+
if(CMAKE_C_ELF_COMPILER)
33+
set(SOTEST_MODPRINT_TARGET modprint)
34+
set(SOTEST_SHARED_TARGET sotest)
35+
else()
36+
set(SOTEST_MODPRINT_TARGET ELF_modprint)
37+
set(SOTEST_SHARED_TARGET ELF_sotest)
38+
endif()
2439

25-
# FIXME: fix all empty a after the kernel build is implemented
2640
add_custom_command(
27-
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/sotest_symtab.c
28-
COMMAND
29-
${NUTTX_APPS_DIR}/tools/mksymtab.sh ${CMAKE_CURRENT_BINARY_DIR}/empty
30-
g_sot > ${CMAKE_CURRENT_BINARY_DIR}/sotest_symtab.c)
41+
OUTPUT ${SOTEST_SYMTAB}
42+
COMMAND ${NUTTX_APPS_DIR}/tools/mksymtab.sh ${SOTEST_MODPRINT_ELF}
43+
${SOTEST_SHARED_ELF} g_sot > ${SOTEST_SYMTAB}
44+
DEPENDS ${SOTEST_MODPRINT_TARGET} ${SOTEST_SHARED_TARGET})
3145

32-
add_custom_target(
33-
sotest_romfs
34-
COMMAND genromfs -f sotest_romfs.img -d empty
35-
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
46+
set_source_files_properties(${SOTEST_SYMTAB} PROPERTIES GENERATED TRUE)
3647

37-
add_custom_command(
38-
OUTPUT sotest_romfs.c
39-
COMMAND xxd -i sotest_romfs.img > sotest_romfs.c
40-
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
41-
DEPENDS sotest_romfs)
48+
set(SOTEST_GENERATED_OUTPUTS ${SOTEST_SYMTAB})
49+
set(SOTEST_SRCS sotest_main.c ${SOTEST_SYMTAB})
50+
51+
if(CONFIG_EXAMPLES_SOTEST_BUILTINFS)
52+
set(SOTEST_ROMFS_DEPS ${SOTEST_MODPRINT_TARGET} ${SOTEST_SHARED_TARGET})
53+
54+
if(CONFIG_SYSTEM_NXPKG)
55+
set(SOTEST_SHARED_INDEX ${CMAKE_BINARY_DIR}/bin/shared-index.json)
56+
set(SOTEST_SHARED_SCRIPT ${CMAKE_BINARY_DIR}/bin/pkgsotest.nsh)
57+
set(SOTEST_FIXTURE_HOST_DIR ${CMAKE_CURRENT_BINARY_DIR}/host)
58+
set(SOTEST_FIXTURE_HOST_SRC
59+
${CMAKE_CURRENT_SOURCE_DIR}/host/CMakeLists.txt)
60+
set(SOTEST_FIXTURE_TOOL
61+
${SOTEST_FIXTURE_HOST_DIR}/mk_pkg_fixture_shared${CMAKE_EXECUTABLE_SUFFIX}
62+
)
63+
64+
if(CONFIG_ARCH_BOARD)
65+
set(SOTEST_FIXTURE_COMPAT ${CONFIG_ARCH_BOARD})
66+
else()
67+
set(SOTEST_FIXTURE_COMPAT ${CONFIG_ARCH_BOARD_CUSTOM_NAME})
68+
endif()
69+
70+
add_custom_command(
71+
OUTPUT ${SOTEST_FIXTURE_TOOL}
72+
COMMAND ${CMAKE_COMMAND} -S ${CMAKE_CURRENT_SOURCE_DIR}/host -B
73+
${SOTEST_FIXTURE_HOST_DIR}
74+
COMMAND ${CMAKE_COMMAND} --build ${SOTEST_FIXTURE_HOST_DIR} --target
75+
mk_pkg_fixture_shared
76+
DEPENDS ${SOTEST_FIXTURE_HOST_SRC}
77+
${CMAKE_CURRENT_SOURCE_DIR}/mk_pkg_fixture_shared.c
78+
VERBATIM)
79+
80+
add_custom_command(
81+
OUTPUT ${SOTEST_SHARED_INDEX} ${SOTEST_SHARED_SCRIPT}
82+
COMMAND
83+
${SOTEST_FIXTURE_TOOL} ${SOTEST_MODPRINT_ELF} ${SOTEST_SHARED_ELF}
84+
${SOTEST_SHARED_INDEX} ${SOTEST_SHARED_SCRIPT} ${CONFIG_ARCH}
85+
${SOTEST_FIXTURE_COMPAT}
86+
DEPENDS ${SOTEST_MODPRINT_TARGET} ${SOTEST_SHARED_TARGET}
87+
${SOTEST_FIXTURE_TOOL}
88+
VERBATIM)
89+
90+
list(APPEND SOTEST_ROMFS_DEPS ${SOTEST_SHARED_INDEX}
91+
${SOTEST_SHARED_SCRIPT})
92+
endif()
93+
94+
add_custom_command(
95+
OUTPUT ${SOTEST_ROMFS_IMG}
96+
COMMAND genromfs -f ${SOTEST_ROMFS_IMG} -d ${CMAKE_BINARY_DIR}/bin
97+
DEPENDS ${SOTEST_ROMFS_DEPS}
98+
VERBATIM)
99+
100+
get_filename_component(SOTEST_ROMFS_IMG_NAME ${SOTEST_ROMFS_IMG} NAME)
101+
102+
# xxd -i derives the generated array/length symbol names from the exact path
103+
# it is given - sotest_main.c declares them as plain
104+
# "sotest_romfs_img"/"sotest_romfs_img_len", so xxd must be run against just
105+
# the bare filename (via WORKING_DIRECTORY) rather than the absolute
106+
# ${SOTEST_ROMFS_IMG} path, or every non- alphanumeric character in that
107+
# path (e.g. every "/" in the build directory) gets folded into the symbol
108+
# name instead, leaving the names sotest_main.c expects undefined at link
109+
# time.
110+
111+
add_custom_command(
112+
OUTPUT ${SOTEST_ROMFS_SRC}
113+
COMMAND xxd -i ${SOTEST_ROMFS_IMG_NAME} > ${SOTEST_ROMFS_SRC}
114+
DEPENDS ${SOTEST_ROMFS_IMG}
115+
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
116+
117+
set_source_files_properties(${SOTEST_ROMFS_SRC} PROPERTIES GENERATED TRUE)
118+
119+
list(APPEND SOTEST_GENERATED_OUTPUTS ${SOTEST_ROMFS_SRC})
120+
list(APPEND SOTEST_SRCS ${SOTEST_ROMFS_SRC})
121+
endif()
42122

43-
nuttx_add_application(
44-
NAME sotest SRCS sotest_main.c ${CMAKE_CURRENT_BINARY_DIR}/sotest_symtab.c
45-
${CMAKE_CURRENT_BINARY_DIR}/sotest_romfs.c)
123+
add_custom_target(sotest_artifacts DEPENDS ${SOTEST_GENERATED_OUTPUTS})
46124

125+
nuttx_add_application(NAME sotest SRCS ${SOTEST_SRCS} DEPENDS
126+
sotest_artifacts)
47127
endif()

examples/sotest/main/Makefile

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,34 @@ ifeq ($(CONFIG_EXAMPLES_SOTEST_BUILTINFS),y)
5050
ROMFSIMG = sotest_romfs.img
5151
ROMFSSRC = sotest_romfs.c
5252
ROMFSOBJ = $(ROMFSSRC:.c=$(OBJEXT))
53+
ifdef CONFIG_SYSTEM_NXPKG
54+
HOSTOBJSEXT ?= hobj
55+
PKGSHAREDINDEX = $(BINDIR)/shared-index.json
56+
PKGSHAREDTEST = $(BINDIR)/pkgsotest.nsh
57+
PKG_FIXTURE_GEN = mk_pkg_fixture_shared$(HOSTEXEEXT)
58+
PKG_FIXTURE_SRCS = mk_pkg_fixture_shared.c
59+
PKG_FIXTURE_OBJS = $(PKG_FIXTURE_SRCS:.c=.$(HOSTOBJSEXT))
60+
PKG_FIXTURE_OUTPUTS = $(PKGSHAREDINDEX) $(PKGSHAREDTEST)
61+
PKG_FIXTURE_STAMP = $(BINDIR)/.pkgsotest.stamp
62+
PKG_FIXTURE_COMPAT = $(if $(CONFIG_ARCH_BOARD),$(CONFIG_ARCH_BOARD),$(CONFIG_ARCH_BOARD_CUSTOM_NAME))
63+
64+
$(PKG_FIXTURE_OBJS): %.$(HOSTOBJSEXT): %.c
65+
@echo "CC: $<"
66+
$(Q) $(HOSTCC) -c $(HOSTCFLAGS) $< -o $@
67+
68+
$(PKG_FIXTURE_GEN): $(PKG_FIXTURE_OBJS)
69+
$(Q) $(HOSTCC) $(HOSTLDFLAGS) $(PKG_FIXTURE_OBJS) -o $@
70+
71+
$(PKG_FIXTURE_OUTPUTS): $(PKG_FIXTURE_STAMP)
72+
73+
$(PKG_FIXTURE_STAMP): $(BINDIR)/modprint $(BINDIR)/sotest $(PKG_FIXTURE_GEN)
74+
$(Q) ./$(PKG_FIXTURE_GEN) $(BINDIR)/modprint $(BINDIR)/sotest \
75+
$(PKGSHAREDINDEX) $(PKGSHAREDTEST) $(CONFIG_ARCH) \
76+
$(PKG_FIXTURE_COMPAT)
77+
$(Q) touch $@
78+
endif
5379

54-
$(ROMFSIMG):
80+
$(ROMFSIMG): $(PKG_FIXTURE_OUTPUTS)
5581
$(Q) genromfs -d $(BINDIR) -f $@
5682

5783
$(ROMFSSRC): $(ROMFSIMG)
@@ -67,6 +93,6 @@ postinstall:: $(ROMFSOBJ) $(SYMTABOBJ) $(FSIMG_OBJ)
6793
$(call ARLOCK, $(call CONVERT_PATH,$(BIN)), $^)
6894

6995
distclean::
70-
$(Q) $(call DELFILE, $(SYMTABSRC) $(SYMTABOBJ) $(ROMFSSRC) $(ROMFSIMG) $(ROMFSOBJ))
96+
$(Q) $(call DELFILE, $(SYMTABSRC) $(SYMTABOBJ) $(ROMFSSRC) $(ROMFSIMG) $(ROMFSOBJ) $(PKG_FIXTURE_GEN) $(PKG_FIXTURE_OBJS) $(PKG_FIXTURE_STAMP))
7197

7298
include $(APPDIR)/Application.mk
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# ##############################################################################
2+
# apps/examples/sotest/main/host/CMakeLists.txt
3+
#
4+
# SPDX-License-Identifier: Apache-2.0
5+
#
6+
# Licensed to the Apache Software Foundation (ASF) under one or more contributor
7+
# license agreements. See the NOTICE file distributed with this work for
8+
# additional information regarding copyright ownership. The ASF licenses this
9+
# file to you under the Apache License, Version 2.0 (the "License"); you may not
10+
# use this file except in compliance with the License. You may obtain a copy of
11+
# the License at
12+
#
13+
# http://www.apache.org/licenses/LICENSE-2.0
14+
#
15+
# Unless required by applicable law or agreed to in writing, software
16+
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
17+
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
18+
# License for the specific language governing permissions and limitations under
19+
# the License.
20+
#
21+
# ##############################################################################
22+
23+
cmake_minimum_required(VERSION 3.16)
24+
project(sotest_fixture_host LANGUAGES C)
25+
26+
add_executable(mk_pkg_fixture_shared ../mk_pkg_fixture_shared.c)

0 commit comments

Comments
 (0)