commit 0c80fa721c868c765d55ae665508f9333fbf141e
parent db18bccd00d927df1826fc34085852caad94a3c3
Author: Eduardo Fontana Lazzari <edufonlaz@gmail.com>
Date: Tue, 4 Mar 2025 13:31:37 +0100
Add tests to makefile
Diffstat:
5 files changed, 141 insertions(+), 2 deletions(-)
diff --git a/.gitignore b/.gitignore
@@ -1,7 +1,12 @@
*~
*.[abdo]
.config
+.test
+file.txt
*.pc
*.so
*.swp
tags
+test_sphin
+test_sphin_load_volume
+test_sphin_load_surface
diff --git a/Makefile b/Makefile
@@ -31,6 +31,7 @@ LIBNAME = libsphin.so
default: build_library
+all: build_library build_tests
################################################################################
# Library building
################################################################################
@@ -56,6 +57,7 @@ $(LIBNAME): $(OBJ)
.config: config.mk
$(PKG_CONFIG) --atleast-version $(RSYS_VERSION) rsys
+ $(PKG_CONFIG) --atleast-version $(SSTL_VERSION) sstl
echo "config done" > $@
.SUFFIXES: .c .d .o
@@ -72,6 +74,7 @@ pkg:
sed -e 's#@PREFIX@#$(PREFIX)#g'\
-e 's#@VERSION@#$(VERSION)#g'\
-e 's#@RSYS_VERSION@#$(RSYS_VERSION)#g'\
+ -e 's#@SSTL_VERSION@#$(SSTL_VERSION)#g'\
sphin.pc.in > sphin.pc
sphin-local.pc: sphin.pc.in
@@ -80,11 +83,52 @@ sphin-local.pc: sphin.pc.in
-e 's#^libdir=.*#libdir=./#'\
-e 's#@VERSION@#$(VERSION)#g'\
-e 's#@RSYS_VERSION@#$(RSYS_VERSION)#g'\
+ -e 's#@SSTL_VERSION@#$(SSTL_VERSION)#g'\
sphin.pc.in > $@
install:
uninstall:
-clean:
- rm -f $(OBJ) $(LIBNAME) $(DEP) .config
+clean: clean_test
+ rm -f file.txt sphin-local.pc sphin.pc .test test_0.stl test_1.stl test_2.stl test_3.stl
+ rm -f $(OBJ) $(LIBNAME) $(TEST_OBJ) $(DEP) .config
+
+
+################################################################################
+# Tests
+################################################################################
+TEST_SRC =\
+ src/test_sphin.c\
+ src/test_sphin_load_surface.c\
+ src/test_sphin_load_volume.c
+TEST_OBJ = $(TEST_SRC:.c=.o)
+TEST_DEP = $(TEST_SRC:.c=.d)
+
+PKG_CONFIG_LOCAL = PKG_CONFIG_PATH="./:$${PKG_CONFIG_PATH}" $(PKG_CONFIG)
+SPHIN_CFLAGS = $$($(PKG_CONFIG_LOCAL) $(PCFLAGS) --cflags sphin-local.pc)
+SPHIN_LIBS = $$($(PKG_CONFIG_LOCAL) $(PCFLAGS) --libs sphin-local.pc)
+
+build_tests: build_library $(TEST_DEP) .test
+ @$(MAKE) -fMakefile -f.test $$(for i in $(TEST_DEP); do echo -f"$${i}"; done) test_bin
+
+test: build_tests
+ @$(SHELL) make.sh run_test $(TEST_SRC)
+
+.test: Makefile
+ @$(SHELL) make.sh config_test $(TEST_SRC) > $@
+
+clean_test:
+ $(SHELL) make.sh clean_test $(TEST_SRC)
+
+$(TEST_DEP): config.mk sphin-local.pc
+ @$(CC) -std=c89 $(CFLAGS_EXE) $(INCS) $(SPHIN_CFLAGS) \
+ -MM -MT "$(@:.d=.o) $@" $(@:.d=.c) -MF $@
+
+$(TEST_OBJ): config.mk sphin-local.pc
+ $(CC) -std=c89 $(CFLAGS_EXE) $(INCS) $(SPHIN_CFLAGS) -c $(@:.o=.c) -o $@
+
+test_sphin\
+test_sphin_load_surface\
+test_sphin_load_volume: config.mk sphin-local.pc $(LIBNAME)
+ $(CC) -std=c89 $(CFLAGS_EXE) -o $@ src/$@.o $(LDFLAGS_EXE) $(SPHIN_LIBS) $(LIBS) -lm
diff --git a/README.md b/README.md
@@ -22,6 +22,7 @@ providing all the necessary geometries and physical properties for computation.
- C compiler
- pkg-config
- rsys
+- star-stl
## Installation
diff --git a/make.sh b/make.sh
@@ -0,0 +1,77 @@
+# Copyright (C) 2024 Centre National de la Recherche Scientifique
+# Copyright (C) 2024 Clermont Auvergne INP
+# Copyright (C) 2024 INSA Lyon
+# Copyright (C) 2024 Institut Mines Télécom Albi-Carmaux
+# Copyright (C) 2024 Institut National Polytechnique de Toulouse
+# Copyright (C) 2024 |Méso|Star> (contact@meso-star.com)
+# Copyright (C) 2024 PhotonLyX (info@photonlyx.com)
+# Copyright (C) 2024 Université de Lorraine
+# Copyright (C) 2024 Université Paul Sabatier
+# Copyright (C) 2024 Université Toulouse - Jean Jaurès
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+set -e
+
+config_test()
+{
+ for i in "$@"; do
+ test=$(basename "${i}" ".c")
+ test_list="${test_list} ${test}"
+ printf "%s: src/%s.o\n" "${test}" "${test}"
+ done
+ printf "test_bin: %s\n" "${test_list}"
+}
+
+run_test()
+{
+ for i in "$@"; do
+ test=$(basename "${i}" ".c")
+
+ printf "%s " "${test}"
+ if ./"${test}" > /dev/null 2>&1; then
+ printf "\033[1;32mOK\033[m\n"
+ else
+ printf "\033[1;31mError\033[m\n"
+ fi
+ done 2> /dev/null
+}
+
+clean_test()
+{
+ for i in "$@"; do
+ rm -f "$(basename "${i}" ".c")"
+ done
+}
+
+install()
+{
+ prefix=$1
+ shift 1
+
+ mkdir -p "${prefix}"
+
+ for i in "$@"; do
+ dst="${prefix}/${i##*/}"
+
+ if cmp -s "${i}" "${dst}"; then
+ printf "Up to date %s\n" "${dst}"
+ else
+ printf "Installing %s\n" "${dst}"
+ cp "${i}" "${prefix}"
+ fi
+ done
+}
+
+"$@"
diff --git a/sphin.pc.in b/sphin.pc.in
@@ -0,0 +1,12 @@
+prefix=@PREFIX@
+includedir=${prefix}/include
+libdir=${prefix}/lib
+
+Requires: rsys >= @RSYS_VERSION@
+Requires.private: sstl >= @SSTL_VERSION@
+Name: Star-Phor Input
+Description: File reader for the Star-Phor solver
+Version: @VERSION@
+Libs: -L${libdir} -lsphin
+Libs.private: -lm
+CFlags: -I${includedir}