stardis-test

Test Stardis behaviors
git clone git://git.meso-star.fr/stardis-test.git
Log | Files | Refs | README | LICENSE

commit 0333e1bf05eb29a0474a38584f04131cc10fedb8
parent d174aeccffd25880d63c721ad89b90bef48d629a
Author: Vincent Forest <vincent.forest@meso-star.com>
Date:   Mon,  8 Sep 2025 15:21:21 +0200

Rewriting the Makefile

Delete the make.sh script. It implemented a function which, while
contributing to the clarity of the Makefile, made the build system less
compact. This function can be implemented with just a few lines of
shell code, without any major impact on the clarity of the Makefile.
Perhaps on the contrary, since it's all in one place.

Automate test creation using inference rules and automatic detection of
dependencies for each C file. This avoids having to explicitly write the
generation rules for each program. Adding new tests will thus become a
trivial task. On the other hand, all tests are created in the same way
and therefore depend on the same libraries, even if some libraries are
not used by all tests.

Diffstat:
MMakefile | 182+++++++++++++++++++++++++++++++++++++++++++-------------------------------------
Mconfig.mk | 19++++---------------
2 files changed, 102 insertions(+), 99 deletions(-)

diff --git a/Makefile b/Makefile @@ -18,13 +18,6 @@ include config.mk -TESTS =\ - sadist_conducto_radiative\ - sadist_custom_conductive_path\ - sadist_external_flux\ - sadist_probe_boundary\ - sadist_unsteady - LIBS =\ libsadist_radenv_1d.so\ libsadist_solid_fluid.so\ @@ -34,19 +27,14 @@ LIBS =\ libsadist_unsteady_profile.so\ # Default target -default: .config $(TESTS) $(LIBS) +default: .config tests $(LIBS) .config: - @if ! $(PKG_CONFIG) --atleast-version $(RSYS_VERSION) rsys; then \ - echo "rsys $(RSYS_VERSION) not found" >&2; exit 1; fi - @if ! $(PKG_CONFIG) --atleast-version $(S3D_VERSION) s3d; then \ - echo "s3d $(S3D_VERSION) not found" >&2; exit 1; fi - @if ! $(PKG_CONFIG) --atleast-version $(S3DUT_VERSION) s3dut; then \ - echo "s3dut $(S3DUT_VERSION) not found" >&2; exit 1; fi - @if ! $(PKG_CONFIG) --atleast-version $(SSP_VERSION) star-sp; then \ - echo "star-sp $(SSP_VERSION) not found" >&2; exit 1; fi - @if ! $(PKG_CONFIG) --atleast-version $(SSTL_VERSION) sstl; then \ - echo "sstl $(SSTL_VERSION) not found" >&2; exit 1; fi + $(PKG_CONFIG) --atleast-version $(RSYS_VERSION) rsys + $(PKG_CONFIG) --atleast-version $(S3D_VERSION) s3d + $(PKG_CONFIG) --atleast-version $(S3DUT_VERSION) s3dut + $(PKG_CONFIG) --atleast-version $(SSP_VERSION) star-sp + $(PKG_CONFIG) --atleast-version $(SSTL_VERSION) sstl @echo "config done" > $@ clean: @@ -54,102 +42,128 @@ clean: rm -f cube.stl ground.stl sphere.stl sshape.stl wall.stl rm -f adiabatic_boundary.stl radiative_boundary.stl rm -f probes.txt scene.txt scene2.txt - rm -f $(TESTS) $(LIBS) - -test: $(TESTS) $(LIBS) - @$(SHELL) make.sh check sadist_conducto_radiative ./sadist_conducto_radiative - @$(SHELL) make.sh check sadist_custom_conductive_path ./sadist_custom_conductive_path - @$(SHELL) make.sh check sadist_probe_boundary ./sadist_probe_boundary - @$(SHELL) make.sh check sadist_probe_boundary_list ./sadist_probe_boundary -p4 - @$(SHELL) make.sh check sadist_external_flux ./sadist_external_flux - @$(SHELL) make.sh check sadist_unsteady ./sadist_unsteady + rm -f cuboid*.stl + rm -f $(LIBS) + for i in $(TEST_SRC); do rm -f "$$(basename "$${i}" ".c")"; done + +test: tests $(LIBS) + @err=0; \ + check() { \ + cmd="$$1"; shift 1; \ + if [ -n "$$1" ]; then \ + printf '%s %s' "$${cmd}" "$$@"; \ + else \ + printf '%s' "$${cmd}"; \ + fi; \ + if "$${cmd}" "$$@" > /dev/null 2>&1; then \ + printf '\n'; \ + else \ + printf ': error %d\n' "$$?"; \ + err="$$((err+1))"; \ + fi \ + }; \ + check ./sadist_conducto_radiative; \ + check ./sadist_custom_conductive_path; \ + check ./sadist_probe_boundary; \ + check ./sadist_probe_boundary -p4; \ + check ./sadist_external_flux; \ + check ./sadist_flux_with_h; \ + check ./sadist_unsteady; \ + [ "$${err}" -eq 0 ] ################################################################################ # Libraries ################################################################################ src/sadist_lib_radenv_1d.o: config.mk src/sadist_lib_radenv_1d.c - $(CC) $(CFLAGS_SO) $(RSYS_CFLAGS) -c $(@:.o=.c) -o $@ + $(CC) $(CFLAGS_SO) $$($(PC_CFLAGS) rsys) -c $(@:.o=.c) -o $@ libsadist_radenv_1d.so: config.mk src/sadist_lib_radenv_1d.o - $(CC) $(CFLAGS_SO) $(RSYS_CFLAGS) -o $@ src/sadist_lib_radenv_1d.o \ - $(LDFLAGS_SO) $(RSYS_LIBS) + $(CC) $(CFLAGS_SO) $$($(PC_CFLAGS) rsys) -o $@ src/sadist_lib_radenv_1d.o \ + $(LDFLAGS_SO) $$($(PC_LIBS) rsys) src/sadist_lib_solid_fluid.o: config.mk src/sadist_lib_solid_fluid.c - $(CC) $(CFLAGS_SO) $(RSYS_CFLAGS) -c $(@:.o=.c) -o $@ + $(CC) $(CFLAGS_SO) $$($(PC_CFLAGS) rsys) -c $(@:.o=.c) -o $@ libsadist_solid_fluid.so: config.mk src/sadist_lib_solid_fluid.o - $(CC) $(CFLAGS_SO) $(RSYS_CFLAGS) -o $@ src/sadist_lib_solid_fluid.o \ - $(LDFLAGS_SO) $(RSYS_LIBS) + $(CC) $(CFLAGS_SO) $$($(PC_CFLAGS) rsys) -o $@ src/sadist_lib_solid_fluid.o \ + $(LDFLAGS_SO) $$($(PC_LIBS) rsys) src/sadist_lib_solid_sphere.o: config.mk src/sadist_lib_solid_sphere.c - $(CC) $(CFLAGS_SO) $(S3D_CFLAGS) $(SSP_CFLAGS) $(SSTL_CFLAGS) $(RSYS_CFLAGS) \ - -c $(@:.o=.c) -o $@ + $(CC) $(CFLAGS_SO) $$($(PC_CFLAGS) s3d star-sp sstl rsys) -c $(@:.o=.c) -o $@ libsadist_solid_sphere.so: config.mk src/sadist_lib_solid_sphere.o - $(CC) $(CFLAGS_SO) $(S3D_CFLAGS) $(SSP_CFLAGS) $(SSTL_CFLAGS) $(RSYS_CFLAGS) \ - -o $@ src/sadist_lib_solid_sphere.o $(LDFLAGS_SO) $(S3D_LIBS) $(SSP_LIBS) \ - $(SSTL_LIBS) $(RSYS_LIBS) -lm + $(CC) $(CFLAGS_SO) $$($(PC_CFLAGS) s3d star-sp sstl rsys) \ + -o $@ src/sadist_lib_solid_sphere.o \ + $(LDFLAGS_SO) $$($(PC_LIBS) s3d star-sp sstl rsys) -lm src/sadist_lib_spherical_source.o: config.mk src/sadist_lib_spherical_source.c - $(CC) $(CFLAGS_SO) $(RSYS_CFLAGS) -c $(@:.o=.c) -o $@ + $(CC) $(CFLAGS_SO) $$($(PC_CFLAGS) rsys) -c $(@:.o=.c) -o $@ libsadist_spherical_source.so: config.mk src/sadist_lib_spherical_source.o - $(CC) $(CFLAGS_SO) $(RSYS_CFLAGS) -o $@ src/sadist_lib_spherical_source.o \ - $(LDFLAGS_SO) $(RSYS_LIBS) + $(CC) $(CFLAGS_SO) $$($(PC_CFLAGS) rsys) -o $@ src/sadist_lib_spherical_source.o \ + $(LDFLAGS_SO) $$($(PC_LIBS) rsys) src/sadist_lib_trilinear_profile.o:\ config.mk src/sadist.h src/sadist_lib_trilinear_profile.c - $(CC) $(CFLAGS_SO) $(RSYS_CFLAGS) -c $(@:.o=.c) -o $@ + $(CC) $(CFLAGS_SO) $$($(PC_CFLAGS) rsys) -c $(@:.o=.c) -o $@ libsadist_trilinear_profile.so: src/sadist_lib_trilinear_profile.o - $(CC) $(CFLAGS_SO) $(RSYS_CFLAGS) -o $@ src/sadist_lib_trilinear_profile.o \ - $(LDFLAGS_SO) $(RSYS_LIBS) + $(CC) $(CFLAGS_SO) $$($(PC_CFLAGS) rsys) -o $@ src/sadist_lib_trilinear_profile.o \ + $(LDFLAGS_SO) $$($(PC_LIBS) rsys) src/sadist_lib_unsteady_profile.o:\ config.mk src/sadist.h src/sadist_lib_unsteady_profile.c - $(CC) $(CFLAGS_SO) $(RSYS_CFLAGS) -c $(@:.o=.c) -o $@ + $(CC) $(CFLAGS_SO) $$($(PC_CFLAGS) rsys) -c $(@:.o=.c) -o $@ libsadist_unsteady_profile.so: src/sadist_lib_unsteady_profile.o - $(CC) $(CFLAGS_SO) $(RSYS_CFLAGS) -o $@ src/sadist_lib_unsteady_profile.o \ - $(LDFLAGS_SO) $(RSYS_LIBS) -lm + $(CC) $(CFLAGS_SO) $$($(PC_CFLAGS) rsys) -o $@ src/sadist_lib_unsteady_profile.o \ + $(LDFLAGS_SO) $$($(PC_LIBS) rsys) -lm ################################################################################ # Tests ################################################################################ -src/sadist_conducto_radiative.o:\ - config.mk src/sadist.h src/sadist_conducto_radiative.c - $(CC) $(CFLAGS_EXE) -c $(@:.o=.c) -o $@ - -sadist_conducto_radiative: config.mk src/sadist_conducto_radiative.o - $(CC) $(CFLAGS_EXE) -o $@ src/$@.o $(LDFLAGS_EXE) $(RSYS_LIBS) - -src/sadist_custom_conductive_path.o:\ - config.mk src/sadist.h src/sadist_custom_conductive_path.c - $(CC) $(CFLAGS_EXE) $(S3DUT_CFLAGS) $(RSYS_CFLAGS) -c $(@:.o=.c) -o $@ - -sadist_custom_conductive_path: config.mk src/sadist_custom_conductive_path.o - $(CC) $(CFLAGS_EXE) $(S3DUT_CFLAGS) $(RSYS_CFLAGS) -o $@ src/$@.o \ - $(LDFLAGS_EXE) $(S3DUT_LIBS) $(RSYS_LIBS) - -src/sadist_external_flux.o:\ - config.mk src/sadist.h src/sadist_external_flux.c - $(CC) $(CFLAGS_EXE) -c $(@:.o=.c) -o $@ - -sadist_external_flux: config.mk src/sadist_external_flux.o - $(CC) $(CFLAGS_EXE) -o $@ src/$@.o $(LDFLAGS_EXE) $(RSYS_LIBS) -lm - -src/sadist_probe_boundary.o:\ - config.mk src/sadist.h src/sadist_probe_boundary.c - $(CC) $(CFLAGS_EXE) $(S3DUT_CFLAGS) $(RSYS_CFLAGS) -c $(@:.o=.c) -o $@ - -sadist_probe_boundary: config.mk src/sadist_probe_boundary.o - $(CC) $(CFLAGS_EXE) $(S3DUT_CFLAGS) $(RSYS_CFLAGS) -o $@ src/$@.o \ - $(LDFLAGS_EXE) $(S3DUT_LIBS) $(RSYS_LIBS) -lm - -src/sadist_unsteady.o:\ - config.mk src/sadist.h src/sadist_unsteady.c - $(CC) $(CFLAGS_EXE) $(S3DUT_CFLAGS) $(RSYS_CFLAGS) -c $(@:.o=.c) -o $@ - -sadist_unsteady: config.mk src/sadist_unsteady.o - $(CC) $(CFLAGS_EXE) $(S3DUT_CFLAGS) $(RSYS_CFLAGS) -o $@ src/$@.o \ - $(LDFLAGS_EXE) $(S3DUT_LIBS) $(RSYS_LIBS) -lm +TEST_SRC=\ + src/sadist_conducto_radiative.c\ + src/sadist_custom_conductive_path.c\ + src/sadist_external_flux.c\ + src/sadist_probe_boundary.c\ + src/sadist_unsteady.c +TEST_OBJ=$(TEST_SRC:.c=.o) +TEST_DEP=$(TEST_SRC:.c=.d) +TEST_TGT=$(TEST_SRC:.c=.t) + +INCS_TEST = $$($(PKG_CONFIG) $(PCFLAGS) --cflags s3dut star-sp sstl rsys) +LIBS_TEST = $$($(PKG_CONFIG) $(PCFLAGS) --libs s3dut star-sp sstl rsys) -lm +CFLAGS_TEST = $(CFLAGS_EXE) $(INCS_TEST) +LDFLAGS_TEST = $(LDFLAGS_EXE) $(LIBS_TEST) + +tests: $(TEST_DEP) $(TEST_TGT) + @$(MAKE) -fMakefile \ + $$(for i in $(TEST_DEP); do echo -f"$${i}"; done) \ + $$(for i in $(TEST_TGT); do echo -f"$${i}"; done) \ + test_list + +$(TEST_OBJ) $(TEST_DEP): config.mk + +.SUFFIXES: .c .d .o .t + +.c.d: + @$(CC) $(CFLAGS_TEST) -MM -MT "$(@:.d=.o) $@" $< -MF $@ + +.c.o: + $(CC) $(CFLAGS_TEST) -c $< -o $@ + +.c.t: + @{ \ + exe="$$(basename "$@" ".t")"; \ + printf '%s: %s\n' "$${exe}" $(@:.t=.o); \ + printf 'test_list: %s\n' "$${exe}"; \ + } > $@ + +sadist_conducto_radiative \ +sadist_custom_conductive_path \ +sadist_external_flux \ +sadist_probe_boundary \ +sadist_unsteady \ +: config.mk + $(CC) $(CFLAGS_TEST) -o $@ src/$@.o $(LDFLAGS_TEST) diff --git a/config.mk b/config.mk @@ -21,25 +21,14 @@ PCFLAGS_SHARED = PCFLAGS_STATIC = --static PCFLAGS = $(PCFLAGS_$(LIB_TYPE)) -RSYS_VERSION = 0.14 -RSYS_CFLAGS = $$($(PKG_CONFIG) $(PCFLAGS) --cflags rsys) -RSYS_LIBS = $$($(PKG_CONFIG) $(PCFLAGS) --libs rsys) +PC_CFLAGS = $(PKG_CONFIG) $(PCFLAGS) --cflags +PC_LIBS = $(PKG_CONFIG) $(PCFLAGS) --libs +RSYS_VERSION = 0.14 S3D_VERSION = 0.10 -S3D_CFLAGS = $$($(PKG_CONFIG) $(PCFLAGS) --cflags s3d) -S3D_LIBS = $$($(PKG_CONFIG) $(PCFLAGS) --libs s3d) - S3DUT_VERSION = 0.4 -S3DUT_CFLAGS = $$($(PKG_CONFIG) $(PCFLAGS) --cflags s3dut) -S3DUT_LIBS = $$($(PKG_CONFIG) $(PCFLAGS) --libs s3dut) - SSP_VERSION = 0.14 -SSP_CFLAGS = $$($(PKG_CONFIG) $(PCFLAGS) --cflags star-sp) -SSP_LIBS = $$($(PKG_CONFIG) $(PCFLAGS) --libs star-sp) - -SSTL_VERSION = 0.5 -SSTL_CFLAGS = $$($(PKG_CONFIG) $(PCFLAGS) --cflags sstl) -SSTL_LIBS = $$($(PKG_CONFIG) $(PCFLAGS) --libs sstl) +SSTL_VERSION = 0.7 ################################################################################ # Compilation options