commit 1a85e4f06a6017495e057d97cead381d8af542aa
parent 5aba96caf56e4880059dbfb5c8f2502f7fb1e092
Author: Vincent Forest <vincent.forest@meso-star.com>
Date: Mon, 25 May 2026 11:51:21 +0200
Convert the test_rngrd program into a utility
It has been renamed rngrd-lint, as its purpose is to verify the behavior
of the RNGRD library when loading and structuring input data. Its manual
page has been written, and both the program and the manual page are
installed with the library.
The test's source code has been slightly updated. Its short help message
is now limited to the command synopsis, since it now has a detailed
manual page. Additionally, the validation of required arguments has been
updated to make the code more compact and easier to read.
Diffstat:
7 files changed, 286 insertions(+), 204 deletions(-)
diff --git a/.gitignore b/.gitignore
@@ -1,12 +1,11 @@
-.gitignore
-[Bb]uild*
-*.sw[po]
+!test*.[ch]
*.[aod]
+*.pc
*.so
+*.sw[po]
*~
-test*
-!test*.[ch]
.config
-.test
+.gitignore
+rngrd-lint
tags
-*.pc
+test*
diff --git a/Makefile b/Makefile
@@ -29,8 +29,8 @@ LIBNAME_STATIC = librngrd.a
LIBNAME_SHARED = librngrd.so
LIBNAME = $(LIBNAME_$(LIB_TYPE))
-default: library
-all: library tests
+default: library utils
+all: default
################################################################################
# Library building
@@ -81,6 +81,29 @@ librngrd.o: $(OBJ)
$(CC) $(CFLAGS_LIB) -c $< -o $@
################################################################################
+# Utils
+################################################################################
+PKG_CONFIG_LOCAL = PKG_CONFIG_PATH="./:$${PKG_CONFIG_PATH}" $(PKG_CONFIG)
+
+INCS_UTIL = $$($(PKG_CONFIG_LOCAL) $(PCFLAGS) --cflags rngrd-local rsys)
+LIBS_UTIL = $$($(PKG_CONFIG_LOCAL) $(PCFLAGS) --libs rngrd-local rsys)
+
+CFLAGS_UTIL = $(CFLAGS_EXE) $(INCS_UTIL)
+LDFLAGS_UTIL = $(LDFLAGS_EXE) $(LIBS_UTIL)
+
+utils: library src/rngrd_lint.d
+ @$(MAKE) -fMakefile -f src/rngrd_lint.d rngrd-lint
+
+src/rngrd_lint.d: config.mk rngrd-local.pc src/rngrd_lint.c
+ @$(CC) $(CFLAGS_UTIL) -MM -MT "$(@:.d=.o) $@" $(@:.d=.c) -MF $@
+
+src/rngrd_lint.o: config.mk rngrd-local.pc src/rngrd_lint.c
+ $(CC) $(CFLAGS_UTIL) -c $(@:.o=.c) -o $@
+
+rngrd-lint: config.mk rngrd-local.pc src/rngrd_lint.o $(LIBNAME)
+ $(CC) $(CFLAGS_UTIL) -o $@ src/rngrd_lint.o $(LDFLAGS_UTIL)
+
+################################################################################
# Installation
################################################################################
pkg:
@@ -109,7 +132,7 @@ rngrd-local.pc: rngrd.pc.in
-e 's#@SSF_VERSION@#$(SSF_VERSION)#g'\
rngrd.pc.in > $@
-install: library pkg
+install: library utils pkg
install() { mode="$$1"; prefix="$$2"; shift 2; \
mkdir -p "$${prefix}"; \
cp "$$@" "$${prefix}"; \
@@ -119,49 +142,28 @@ install: library pkg
}; \
if [ "$(LIB_TYPE)" = "STATIC" ]; then mode=644; else mode=755; fi; \
install "$${mode}" "$(DESTDIR)$(LIBPREFIX)" $(LIBNAME); \
+ install 755 "$(DESTDIR)$(BINPREFIX)" rngrd-lint; \
install 644 "$(DESTDIR)$(LIBPREFIX)/pkgconfig" rngrd.pc; \
install 644 "$(DESTDIR)$(INCPREFIX)/rad-net" src/rngrd.h; \
- install 644 "$(DESTDIR)$(MANPREFIX)/man5" rnsp.5; \
+ install 644 "$(DESTDIR)$(MANPREFIX)/man1" doc/rngrd-lint.1; \
+ install 644 "$(DESTDIR)$(MANPREFIX)/man5" doc/rnsp.5; \
install 644 "$(DESTDIR)$(PREFIX)/share/doc/rngrd" COPYING README.md
uninstall:
rm -f "$(DESTDIR)$(LIBPREFIX)/$(LIBNAME)"
+ rm -f "$(DESTDIR)$(BINPREFIX)/rngrd-lint"
rm -f "$(DESTDIR)$(LIBPREFIX)/pkgconfig/rngrd.pc"
rm -f "$(DESTDIR)$(INCPREFIX)/rad-net/rngrd.h"
+ rm -f "$(DESTDIR)$(MANPREFIX)/man1/rngrd-lint.1"
rm -f "$(DESTDIR)$(MANPREFIX)/man5/rnsp.5"
rm -f "$(DESTDIR)$(PREFIX)/share/doc/rngrd/COPYING"
rm -f "$(DESTDIR)$(PREFIX)/share/doc/rngrd/README.md"
clean:
rm -f $(OBJ) $(DEP) $(LIBNAME)
- rm -f test_rngrd src/test_rngrd.o src/test_rngrd.d
+ rm -f rngrd-lint src/rngrd_lint.o src/rngrd_lint.d
rm -f .config librngrd.o rngrd.pc rngrd-local.pc
lint:
- mandoc -Tlint -Wwarning rnsp.5
-
-################################################################################
-# Tests
-################################################################################
-TEST_SRC = src/test_rngrd.c
-TEST_OBJ = $(TEST_SRC:.c=.o)
-TEST_DEP = $(TEST_SRC:.c=.d)
-
-PKG_CONFIG_LOCAL = PKG_CONFIG_PATH="./:$${PKG_CONFIG_PATH}" $(PKG_CONFIG)
-INCS_TEST = $$($(PKG_CONFIG_LOCAL) $(PCFLAGS) --cflags rngrd-local rsys)
-LIBS_TEST = $$($(PKG_CONFIG_LOCAL) $(PCFLAGS) --libs rngrd-local rsys)
-
-CFLAGS_TEST = $(CFLAGS_EXE) $(INCS_TEST)
-LDFLAGS_TEST = $(LDFLAGS_EXE) $(LIBS_TEST)
-
-tests: library src/test_rngrd.d
- @$(MAKE) -fMakefile -f src/test_rngrd.d test_rngrd
-
-$(TEST_DEP): config.mk rngrd-local.pc
- @$(CC) $(CFLAGS_TEST) -MM -MT "$(@:.d=.o) $@" $(@:.d=.c) -MF $@
-
-src/test_rngrd.o: config.mk rngrd-local.pc
- $(CC) $(CFLAGS_TEST) -c $(@:.o=.c) -o $@
-
-test_rngrd: src/test_rngrd.o config.mk rngrd-local.pc $(LIBNAME)
- $(CC) $(CFLAGS_TEST) -o $@ src/$@.o $(LDFLAGS_TEST)
+ mandoc -Tlint -Wwarning doc/rnsp.5
+ mandoc -Tlint -Wwarning doc/rngrd-lint.1
diff --git a/config.mk b/config.mk
@@ -1,6 +1,7 @@
VERSION = 0.2.0
PREFIX = /usr/local
+BINPREFIX = $(PREFIX)/bin
LIBPREFIX = $(PREFIX)/lib
INCPREFIX = $(PREFIX)/include
MANPREFIX = $(PREFIX)/share/man
diff --git a/doc/rngrd-lint.1 b/doc/rngrd-lint.1
@@ -0,0 +1,105 @@
+.\" Copyright (C) 2022, 2023, 2025 Centre National de la Recherche Scientifique
+.\" Copyright (C) 2022, 2023, 2025 Institut Pierre-Simon Laplace
+.\" Copyright (C) 2022, 2023, 2025 Institut de Physique du Globe de Paris
+.\" Copyright (C) 2022, 2023, 2025, 2026 |Méso|Star>(contact@meso-star.com)
+.\" Copyright (C) 2022, 2023, 2025 Observatoire de Paris
+.\" Copyright (C) 2022, 2023, 2025 Université de Reims Champagne-Ardenne
+.\" Copyright (C) 2022, 2023, 2025 Université de Versaille Saint-Quentin
+.\" Copyright (C) 2022, 2023, 2025 Université Paul Sabatier
+.\"
+.\" 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/>.
+.Dd May 22, 2026
+.Dt RNGRD-LINT 1
+.Os
+.\""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
+.Sh NAME
+.Nm rngrd-lint
+.Nd check the loading and structuring of a decorated mesh
+.\""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
+.Sh SYNOPSIS
+.Nm
+.Op Fl hVv
+.Fl M Ar material_list
+.Fl m Ar geometry
+.Fl p Ar properties
+.\""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
+.Sh DESCRIPTION
+.Nm
+checks the data used to define a triangular mesh, to which a temperature
+and a spectrally varying Bidirectional Reflectance Distribution Function
+.Pq BRDF
+are associated for each triangle.
+.Pp
+This utility effectively validates the behavior of the Rad-Net GRouD
+library
+.Pq RNGRD
+regarding the loading and internal structuring of this data.
+Its purpose is therefore to verify that the input data is valid and
+conforms to the library's expectations prior to running another program
+that relies on the same library and is intended to process the same
+data.
+.Pp
+The options are as follows:
+.Bl -tag -width Ds
+.\""""""""""""""""""""""""""""""""""
+.It Fl h
+Display short help and exit.
+.\""""""""""""""""""""""""""""""""""
+.It Fl M Ar material_list
+File that lists all the materials used by the geometry.
+It is a text file in
+.Xr rnsl 5
+format, where each line specifies the path to a material file in
+.Xr mrumtl 5
+format.
+.\""""""""""""""""""""""""""""""""""
+.It Fl m Ar mesh
+File that stores triangular mesh data in the
+.Xr smsh 5
+format.
+.\""""""""""""""""""""""""""""""""""
+.It Fl p Ar properties
+File that defines triangle properties in
+.Xr rnsp 5
+format.
+.\""""""""""""""""""""""""""""""""""
+.It Fl V
+Perform more thorough validation tests, such as checking all surface
+properties to verify that they match the mesh they are associated with
+and the list of loaded materials.
+.\""""""""""""""""""""""""""""""""""
+.It Fl v
+Make the program verbose.
+.El
+.\"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
+.Sh EXIT STATUS
+.Ex -std
+.\""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
+.Sh EXAMPLES
+Verify the loading and structure of the triangular mesh geometry
+.Pa geom.smsh
+as well as its triangle-specific properties in
+.Pa props.rnsp .
+The materials referenced in the
+.Pa props.rnsp
+file are listed in the text file
+.Pa mat.rnsl .
+Perform a thorough validation of the loaded data
+.Pq option Fl V
+and make the command verbose
+.Pq option Fl v
+to obtain more information than just its return code:
+.Bd -literal -offset Ds
+rngrd-lint -m geom.smsh -p props.rnsp -M mat.rnsl -Vv
+.Ed
diff --git a/rnsp.5 b/doc/rnsp.5
diff --git a/src/rngrd_lint.c b/src/rngrd_lint.c
@@ -0,0 +1,140 @@
+/* Copyright (C) 2022, 2023, 2025 Centre National de la Recherche Scientifique
+ * Copyright (C) 2022, 2023, 2025 Institut Pierre-Simon Laplace
+ * Copyright (C) 2022, 2023, 2025 Institut de Physique du Globe de Paris
+ * Copyright (C) 2022, 2023, 2025, 2026 |Méso|Star> (contact@meso-star.com)
+ * Copyright (C) 2022, 2023, 2025 Observatoire de Paris
+ * Copyright (C) 2022, 2023, 2025 Université de Reims Champagne-Ardenne
+ * Copyright (C) 2022, 2023, 2025 Université de Versaille Saint-Quentin
+ * Copyright (C) 2022, 2023, 2025 Université Paul Sabatier
+ *
+ * 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/>. */
+
+#include "rngrd.h"
+
+#include <rsys/mem_allocator.h>
+
+#include <getopt.h>
+
+struct args {
+ struct rngrd_create_args rngrd;
+ int validate;
+ int quit;
+};
+#define ARGS_DEFAULT__ {RNGRD_CREATE_ARGS_DEFAULT__, 0, 0}
+static const struct args ARGS_DEFAULT = ARGS_DEFAULT__;
+
+/*******************************************************************************
+ * Helper functions
+ ******************************************************************************/
+static void
+usage(FILE* stream)
+{
+ fprintf(stream,
+ "usage: rngrd-lint [-hVv] -M material_list -m geometry -p properties\n");
+}
+
+static void
+args_release(struct args* args)
+{
+ ASSERT(args);
+ *args = ARGS_DEFAULT;
+}
+
+static res_T
+args_init(struct args* args, int argc, char** argv)
+{
+ res_T res = RES_OK;
+ int opt;
+ ASSERT(args && argc && argv);
+
+ *args = ARGS_DEFAULT;
+
+ while((opt = getopt(argc, argv, "hM:m:n:p:Vv")) != -1) {
+ switch(opt) {
+ case 'h':
+ usage(stdout);
+ args_release(args);
+ args->quit = 1;
+ goto exit;
+ case 'M': args->rngrd.mtllst_filename = optarg; break;
+ case 'm': args->rngrd.smsh_filename = optarg; break;
+ case 'n': args->rngrd.name = optarg; break;
+ case 'p': args->rngrd.props_filename = optarg; break;
+ case 'V': args->validate = 1; break;
+ case 'v': args->rngrd.verbose = 1; break;
+ default: res = RES_BAD_ARG; break;
+ }
+ if(res != RES_OK) {
+ if(optarg) {
+ fprintf(stderr, "%s: invalid option args `%s' -- `%c'\n",
+ argv[0], optarg, opt);
+ }
+ goto error;
+ }
+ }
+ #define MANDATORY(Cond, Name, Opt) { \
+ if(!(Cond)) { \
+ fprintf(stderr, "rngrd-lint: missing %s -- option '-%c'\n", (Name), (Opt)); \
+ res = RES_BAD_ARG; \
+ goto error; \
+ } \
+ } (void)0
+ MANDATORY(args->rngrd.mtllst_filename, "material list", 'M');
+ MANDATORY(args->rngrd.smsh_filename, "mesh", 'm');
+ MANDATORY(args->rngrd.props_filename, "properties", 'p');
+ #undef MANDATORY
+
+exit:
+ return res;
+error:
+ usage(stderr);
+ goto exit;
+}
+
+/*******************************************************************************
+ * Main function
+ ******************************************************************************/
+int
+main(int argc, char** argv)
+{
+ struct args args = ARGS_DEFAULT;
+ struct rngrd* rngrd = NULL;
+ res_T res = RES_OK;
+ int err = 0;
+
+ res = args_init(&args, argc, argv);
+ if(res != RES_OK) goto error;
+ if(args.quit) goto exit;
+
+ res = rngrd_create(&args.rngrd, &rngrd);
+ if(res != RES_OK) goto error;
+
+ if(args.validate) {
+ res = rngrd_validate(rngrd);
+ if(res != RES_OK) goto error;
+ }
+
+exit:
+ args_release(&args);
+ if(rngrd) RNGRD(ref_put(rngrd));
+ if(mem_allocated_size() !=0) {
+ fprintf(stderr, "Memory leaks: %lu bytes\n",
+ (unsigned long)mem_allocated_size());
+ err = -1;
+ }
+ return err;
+error:
+ err = -1;
+ goto exit;
+}
diff --git a/src/test_rngrd.c b/src/test_rngrd.c
@@ -1,165 +0,0 @@
-/* Copyright (C) 2022, 2023, 2025 Centre National de la Recherche Scientifique
- * Copyright (C) 2022, 2023, 2025 Institut Pierre-Simon Laplace
- * Copyright (C) 2022, 2023, 2025 Institut de Physique du Globe de Paris
- * Copyright (C) 2022, 2023, 2025, 2026 |Méso|Star> (contact@meso-star.com)
- * Copyright (C) 2022, 2023, 2025 Observatoire de Paris
- * Copyright (C) 2022, 2023, 2025 Université de Reims Champagne-Ardenne
- * Copyright (C) 2022, 2023, 2025 Université de Versaille Saint-Quentin
- * Copyright (C) 2022, 2023, 2025 Université Paul Sabatier
- *
- * 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/>. */
-
-#include "rngrd.h"
-
-#include <rsys/mem_allocator.h>
-
-#include <getopt.h>
-
-struct args {
- struct rngrd_create_args rngrd;
- int validate;
- int quit;
-};
-#define ARGS_DEFAULT__ {RNGRD_CREATE_ARGS_DEFAULT__, 0, 0}
-static const struct args ARGS_DEFAULT = ARGS_DEFAULT__;
-
-/*******************************************************************************
- * Helper functions
- ******************************************************************************/
-static void
-print_help(const char* cmd)
-{
- ASSERT(cmd);
- printf(
-"Usage: %s -m mesh -p pops -M matlst [ option ... ]\n"
-"Test the Rad-Net GRound library\n\n", cmd);
- printf(
-" -h display this help and exit\n");
- printf(
-" -M matlst path toward the list of ground materials (rnsl(5))\n");
- printf(
-" -m mesh path toward the ground mesh (smsh(5))\n");
- printf(
-" -n name ground name\n");
- printf(
-" -p props path toward the ground properties (rnsp(5))\n");
- printf(
-" -V validate data\n");
- printf(
-" -v make the program verbose\n");
- printf("\n");
- printf(
-"This is free software released under the GNU GPL license, version 3 or\n"
-"later. You are free to change or redistribute it under certain\n"
-"conditions <http://gnu.org.licenses/gpl.html>\n");
-}
-
-static void
-args_release(struct args* args)
-{
- ASSERT(args);
- *args = ARGS_DEFAULT;
-}
-
-static res_T
-args_init(struct args* args, int argc, char** argv)
-{
- res_T res = RES_OK;
- int opt;
- ASSERT(args && argc && argv);
-
- *args = ARGS_DEFAULT;
-
- while((opt = getopt(argc, argv, "hM:m:n:p:Vv")) != -1) {
- switch(opt) {
- case 'h':
- print_help(argv[0]);
- args_release(args);
- args->quit = 1;
- goto exit;
- case 'M': args->rngrd.mtllst_filename = optarg; break;
- case 'm': args->rngrd.smsh_filename = optarg; break;
- case 'n': args->rngrd.name = optarg; break;
- case 'p': args->rngrd.props_filename = optarg; break;
- case 'V': args->validate = 1; break;
- case 'v': args->rngrd.verbose = 1; break;
- default: res = RES_BAD_ARG; break;
- }
- if(res != RES_OK) {
- if(optarg) {
- fprintf(stderr, "%s: invalid option args `%s' -- `%c'\n",
- argv[0], optarg, opt);
- }
- goto error;
- }
- }
- if(!args->rngrd.smsh_filename) {
- fprintf(stderr, "Mesh filename is missing -- option `-m'\n");
- res = RES_BAD_ARG;
- goto error;
- }
- if(!args->rngrd.props_filename) {
- fprintf(stderr, "Properties filename is missing -- option `-p'\n");
- res = RES_BAD_ARG;
- goto error;
- }
- if(!args->rngrd.mtllst_filename) {
- fprintf(stderr, "The material list filename is missing -- option `-M'\n");
- res = RES_BAD_ARG;
- goto error;
- }
-
-exit:
- return res;
-error:
- args_release(args);
- goto exit;
-}
-
-/*******************************************************************************
- * Main function
- ******************************************************************************/
-int
-main(int argc, char** argv)
-{
- struct args args = ARGS_DEFAULT;
- struct rngrd* rngrd = NULL;
- res_T res = RES_OK;
- int err = 0;
-
- res = args_init(&args, argc, argv);
- if(res != RES_OK) goto error;
- if(args.quit) goto exit;
-
- res = rngrd_create(&args.rngrd, &rngrd);
- if(res != RES_OK) goto error;
-
- if(args.validate) {
- res = rngrd_validate(rngrd);
- if(res != RES_OK) goto error;
- }
-
-exit:
- args_release(&args);
- if(rngrd) RNGRD(ref_put(rngrd));
- if(mem_allocated_size() !=0) {
- fprintf(stderr, "Memory leaks: %lu bytes\n",
- (unsigned long)mem_allocated_size());
- err = -1;
- }
- return err;
-error:
- err = -1;
- goto exit;
-}