Skip to content

Commit 6845d7f

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. Signed-off-by: aviralgarg05 <gargaviral99@gmail.com>
1 parent 75ee4d9 commit 6845d7f

8 files changed

Lines changed: 712 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: 91 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -21,27 +21,101 @@
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+
add_custom_command(
65+
OUTPUT ${SOTEST_FIXTURE_TOOL}
66+
COMMAND ${CMAKE_COMMAND} -S ${CMAKE_CURRENT_SOURCE_DIR}/host -B
67+
${SOTEST_FIXTURE_HOST_DIR}
68+
COMMAND ${CMAKE_COMMAND} --build ${SOTEST_FIXTURE_HOST_DIR} --target
69+
mk_pkg_fixture_shared
70+
DEPENDS ${SOTEST_FIXTURE_HOST_SRC}
71+
${CMAKE_CURRENT_SOURCE_DIR}/mk_pkg_fixture_shared.c
72+
VERBATIM)
73+
74+
add_custom_command(
75+
OUTPUT ${SOTEST_SHARED_INDEX} ${SOTEST_SHARED_SCRIPT}
76+
COMMAND
77+
${SOTEST_FIXTURE_TOOL} ${SOTEST_MODPRINT_ELF} ${SOTEST_SHARED_ELF}
78+
${SOTEST_SHARED_INDEX} ${SOTEST_SHARED_SCRIPT} ${CONFIG_ARCH}
79+
${CONFIG_ARCH_BOARD}
80+
DEPENDS ${SOTEST_MODPRINT_TARGET} ${SOTEST_SHARED_TARGET}
81+
${SOTEST_FIXTURE_TOOL}
82+
VERBATIM)
83+
84+
list(APPEND SOTEST_ROMFS_DEPS ${SOTEST_SHARED_INDEX}
85+
${SOTEST_SHARED_SCRIPT})
86+
endif()
87+
88+
add_custom_command(
89+
OUTPUT ${SOTEST_ROMFS_IMG}
90+
COMMAND genromfs -f ${SOTEST_ROMFS_IMG} -d ${CMAKE_BINARY_DIR}/bin
91+
DEPENDS ${SOTEST_ROMFS_DEPS}
92+
VERBATIM)
93+
94+
get_filename_component(SOTEST_ROMFS_IMG_NAME ${SOTEST_ROMFS_IMG} NAME)
95+
96+
# xxd -i derives the generated array/length symbol names from the exact path
97+
# it is given - sotest_main.c declares them as plain
98+
# "sotest_romfs_img"/"sotest_romfs_img_len", so xxd must be run against just
99+
# the bare filename (via WORKING_DIRECTORY) rather than the absolute
100+
# ${SOTEST_ROMFS_IMG} path, or every non- alphanumeric character in that
101+
# path (e.g. every "/" in the build directory) gets folded into the symbol
102+
# name instead, leaving the names sotest_main.c expects undefined at link
103+
# time.
104+
105+
add_custom_command(
106+
OUTPUT ${SOTEST_ROMFS_SRC}
107+
COMMAND xxd -i ${SOTEST_ROMFS_IMG_NAME} > ${SOTEST_ROMFS_SRC}
108+
DEPENDS ${SOTEST_ROMFS_IMG}
109+
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
110+
111+
set_source_files_properties(${SOTEST_ROMFS_SRC} PROPERTIES GENERATED TRUE)
112+
113+
list(APPEND SOTEST_GENERATED_OUTPUTS ${SOTEST_ROMFS_SRC})
114+
list(APPEND SOTEST_SRCS ${SOTEST_ROMFS_SRC})
115+
endif()
42116

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)
117+
add_custom_target(sotest_artifacts DEPENDS ${SOTEST_GENERATED_OUTPUTS})
46118

119+
nuttx_add_application(NAME sotest SRCS ${SOTEST_SRCS} DEPENDS
120+
sotest_artifacts)
47121
endif()

examples/sotest/main/Makefile

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,29 @@ 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+
62+
$(PKG_FIXTURE_OBJS): %.$(HOSTOBJSEXT): %.c
63+
@echo "CC: $<"
64+
$(Q) $(HOSTCC) -c $(HOSTCFLAGS) $< -o $@
65+
66+
$(PKG_FIXTURE_GEN): $(PKG_FIXTURE_OBJS)
67+
$(Q) $(HOSTCC) $(HOSTLDFLAGS) $(PKG_FIXTURE_OBJS) -o $@
68+
69+
$(PKG_FIXTURE_OUTPUTS) &: $(BINDIR)/modprint $(BINDIR)/sotest $(PKG_FIXTURE_GEN)
70+
$(Q) ./$(PKG_FIXTURE_GEN) $(BINDIR)/modprint $(BINDIR)/sotest \
71+
$(PKGSHAREDINDEX) $(PKGSHAREDTEST) $(CONFIG_ARCH) \
72+
$(CONFIG_ARCH_BOARD)
73+
endif
5374

54-
$(ROMFSIMG):
75+
$(ROMFSIMG): $(PKG_FIXTURE_OUTPUTS)
5576
$(Q) genromfs -d $(BINDIR) -f $@
5677

5778
$(ROMFSSRC): $(ROMFSIMG)
@@ -67,6 +88,6 @@ postinstall:: $(ROMFSOBJ) $(SYMTABOBJ) $(FSIMG_OBJ)
6788
$(call ARLOCK, $(call CONVERT_PATH,$(BIN)), $^)
6889

6990
distclean::
70-
$(Q) $(call DELFILE, $(SYMTABSRC) $(SYMTABOBJ) $(ROMFSSRC) $(ROMFSIMG) $(ROMFSOBJ))
91+
$(Q) $(call DELFILE, $(SYMTABSRC) $(SYMTABOBJ) $(ROMFSSRC) $(ROMFSIMG) $(ROMFSOBJ) $(PKG_FIXTURE_GEN) $(PKG_FIXTURE_OBJS))
7192

7293
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)