commit ebd47a8df4c2ef0e44e2ea2d62b55bf7c6162adb
parent fe639bc4740f64a561e308f9e5a30e35c8aec0ec
Author: Vincent Forest <vincent.forest@meso-star.com>
Date: Thu, 14 Aug 2025 17:14:45 +0200
stardis: plugin function test
It checks API calls and that getters return the correct time-dependent
data. The test relies on an input smeteo file instead of generating its
own test file, which would have been not only too laborious, but also
unreadable, and ultimately pointless given the simple solution of
providing a file in the expected format.
Diffstat:
3 files changed, 284 insertions(+), 1 deletion(-)
diff --git a/Makefile b/Makefile
@@ -185,7 +185,8 @@ clean: clean_test
################################################################################
# Tests
################################################################################
-TEST_SRC = src/test_smeteo.c src/test_smeteo_load.c
+TEST_SRC_stardis = src/test_stardis_smeteo.c
+TEST_SRC = src/test_smeteo.c src/test_smeteo_load.c $(TEST_SRC_$(PLUGIN))
TEST_OBJ = $(TEST_SRC:.c=.o)
TEST_DEP = $(TEST_SRC:.c=.d)
TEST_TGT = $(TEST_SRC:.c=.t)
@@ -250,6 +251,12 @@ test_smeteo_load \
: config.mk smeteo-local.pc $(LIBNAME)
$(CC) $(CFLAGS_TEST) -o $@ src/$@.o $(LDFLAGS_TEST)
+# There is no pkg-config file for the stardis plugin, as it must be
+# loaded at runtime by Stardis. Therefore, provide the library name
+# directly for link editing.
+test_stardis_smeteo: config.mk smeteo-local.pc $(LIBNAME) stardis
+ $(CC) $(CFLAGS_TEST) -o $@ src/$@.o $(LDFLAGS_TEST) -lstardis_smeteo
+
clean_test:
rm -f $(TEST_DEP) $(TEST_OBJ) $(TEST_TGT)
rm -f test.txt
diff --git a/samples/star-meteo_input.txt b/samples/star-meteo_input.txt
@@ -0,0 +1,100 @@
+# Albedo de surface:
+ 0.31659812657071051
+# Longitude [deg] :
+ 10.428827285766602
+# Latitude [deg] :
+ 16.388128280639648
+# Ndata :
+ 733408
+# Date Hour Tsrf Tatm Ahum Rhum SWdn direct diffus SWup Trad h LE day/1850
+01-JAN-1850 01:30:00 287.85 289.62 4.23 12.28 0.00 0.00 0.00 0.00 271.21 12.60 0.51 0.0625
+01-JAN-1850 04:30:00 286.18 287.77 0.00 0.00 0.00 0.00 0.00 0.00 269.50 8.74 0.52 0.1875
+01-JAN-1850 07:30:00 293.25 291.16 0.00 0.00 175.08 175.08 0.00 55.43 268.62 7.32 0.87 0.3125
+01-JAN-1850 10:30:00 307.28 298.31 0.00 0.00 679.01 679.01 0.00 213.37 271.61 17.80 1.78 0.4375
+01-JAN-1850 13:30:00 307.74 301.79 0.00 0.00 618.20 618.20 0.00 194.27 276.21 15.15 2.14 0.5625
+01-JAN-1850 16:30:00 295.96 297.65 0.00 0.00 106.49 106.49 0.00 33.83 276.93 3.33 1.40 0.6875
+01-JAN-1850 19:30:00 291.76 293.74 0.00 0.00 0.00 0.00 0.00 0.00 274.43 9.14 0.52 0.8125
+01-JAN-1850 22:30:00 289.69 292.19 0.00 0.00 0.00 0.00 0.00 0.00 272.30 9.43 0.55 0.9375
+02-JAN-1850 01:30:00 287.86 289.84 0.00 0.00 0.00 0.00 0.00 0.00 270.52 10.31 0.52 1.0625
+02-JAN-1850 04:30:00 286.21 287.64 0.00 0.00 0.00 0.00 0.00 0.00 269.05 10.33 0.54 1.1875
+02-JAN-1850 07:30:00 292.96 290.63 0.00 0.00 174.34 174.34 0.00 55.03 268.29 4.76 0.87 1.3125
+02-JAN-1850 10:30:00 306.47 297.44 0.00 0.00 675.26 675.26 0.00 211.31 271.35 19.03 1.69 1.4375
+02-JAN-1850 13:30:00 307.16 300.79 0.00 0.00 615.21 615.21 0.00 192.54 275.93 15.52 2.12 1.5625
+02-JAN-1850 16:30:00 295.48 297.00 0.00 0.00 105.23 105.23 0.00 33.30 276.72 4.38 1.35 1.6875
+02-JAN-1850 19:30:00 291.40 293.26 0.00 0.00 0.00 0.00 0.00 0.00 274.57 8.05 0.58 1.8125
+02-JAN-1850 22:30:00 289.14 290.93 0.00 0.00 0.00 0.00 0.00 0.00 272.74 9.08 0.51 1.9375
+03-JAN-1850 01:30:00 287.37 289.22 0.00 0.00 0.00 0.00 0.00 0.00 271.09 8.38 0.45 2.0625
+03-JAN-1850 04:30:00 286.12 288.63 0.00 0.00 0.00 0.00 0.00 0.00 269.64 7.60 0.52 2.1875
+03-JAN-1850 07:30:00 292.99 290.65 0.00 0.00 174.26 174.26 0.00 54.93 268.73 1.41 0.90 2.3125
+03-JAN-1850 10:30:00 306.61 297.27 0.00 0.00 675.37 675.37 0.00 211.22 271.55 18.15 1.70 2.4375
+03-JAN-1850 13:30:00 307.06 300.22 0.00 0.00 614.22 614.22 0.00 192.25 276.05 14.74 2.12 2.5625
+03-JAN-1850 16:30:00 295.38 296.86 0.00 0.00 104.77 104.77 0.00 33.15 276.69 4.82 1.35 2.6875
+03-JAN-1850 19:30:00 291.25 293.02 0.00 0.00 0.00 0.00 0.00 0.00 274.35 7.95 0.52 2.8125
+03-JAN-1850 22:30:00 288.97 290.79 0.00 0.00 0.00 0.00 0.00 0.00 272.22 9.02 0.52 2.9375
+04-JAN-1850 01:30:00 287.37 289.71 0.00 0.00 0.00 0.00 0.00 0.00 270.53 8.82 0.53 3.0625
+04-JAN-1850 04:30:00 286.12 288.28 0.00 0.00 0.00 0.00 0.00 0.00 269.18 8.86 0.52 3.1875
+04-JAN-1850 07:30:00 292.74 290.17 0.00 0.00 177.25 177.25 0.00 56.05 268.33 12.93 0.93 3.3125
+04-JAN-1850 10:30:00 306.09 296.28 0.00 0.00 686.55 686.55 0.00 215.55 271.03 19.08 1.69 3.4375
+04-JAN-1850 13:30:00 306.36 299.33 0.00 0.00 620.66 620.66 0.00 194.53 275.28 15.44 2.12 3.5625
+04-JAN-1850 16:30:00 294.93 296.33 0.00 0.00 107.35 107.35 0.00 34.09 275.86 6.08 1.37 3.6875
+04-JAN-1850 19:30:00 290.76 292.49 0.00 0.00 0.00 0.00 0.00 0.00 273.25 9.58 0.57 3.8125
+04-JAN-1850 22:30:00 288.56 290.28 0.00 0.00 0.00 0.00 0.00 0.00 271.34 9.70 0.46 3.9375
+05-JAN-1850 01:30:00 287.12 289.07 0.00 0.00 0.00 0.00 0.00 0.00 269.84 11.96 0.54 4.0625
+05-JAN-1850 04:30:00 285.42 286.51 0.00 0.00 0.00 0.00 0.00 0.00 268.55 9.32 0.48 4.1875
+05-JAN-1850 07:30:00 292.12 288.97 0.00 0.00 184.40 184.40 0.00 59.09 267.81 8.90 0.93 4.3125
+05-JAN-1850 10:30:00 305.00 294.71 0.00 0.00 691.57 691.57 0.00 217.92 270.22 19.42 1.67 4.4375
+05-JAN-1850 13:30:00 305.24 297.95 0.00 0.00 625.52 625.52 0.00 197.10 274.21 16.10 2.09 4.5625
+05-JAN-1850 16:30:00 294.18 295.60 0.00 0.00 107.16 107.16 0.00 34.13 275.00 7.22 1.38 4.6875
+05-JAN-1850 19:30:00 290.05 291.54 0.00 0.00 0.00 0.00 0.00 0.00 272.66 9.17 0.56 4.8125
+05-JAN-1850 22:30:00 288.12 290.34 0.00 0.00 0.00 0.00 0.00 0.00 270.69 9.58 0.52 4.9375
+06-JAN-1850 01:30:00 286.42 287.76 0.00 0.00 0.00 0.00 0.00 0.00 269.37 10.53 0.59 5.0625
+06-JAN-1850 04:30:00 284.93 286.02 0.00 0.00 0.00 0.00 0.00 0.00 268.19 10.94 0.40 5.1875
+06-JAN-1850 07:30:00 291.34 288.20 0.00 0.00 177.64 177.64 0.00 56.44 267.26 9.54 0.91 5.3125
+06-JAN-1850 10:30:00 304.03 293.64 0.00 0.00 685.43 685.43 0.00 215.57 269.30 19.48 1.60 5.4375
+06-JAN-1850 13:30:00 303.74 296.25 0.00 0.00 630.22 630.22 0.00 199.13 272.76 17.36 2.01 5.5625
+06-JAN-1850 16:30:00 293.07 294.39 0.00 0.00 109.06 109.06 0.00 34.77 273.21 8.57 1.36 5.6875
+06-JAN-1850 19:30:00 289.01 290.47 0.00 0.00 0.00 0.00 0.00 0.00 271.40 8.64 0.57 5.8125
+06-JAN-1850 22:30:00 286.92 288.42 0.00 0.00 0.00 0.00 0.00 0.00 269.86 8.46 0.45 5.9375
+07-JAN-1850 01:30:00 285.31 286.41 0.00 0.00 0.00 0.00 0.00 0.00 268.86 8.78 0.52 6.0625
+07-JAN-1850 04:30:00 284.09 285.13 0.00 0.00 0.00 0.00 0.00 0.00 268.30 8.29 0.52 6.1875
+07-JAN-1850 07:30:00 291.57 288.35 0.00 0.00 184.42 184.42 0.00 59.22 268.24 8.16 0.88 6.3125
+07-JAN-1850 10:30:00 304.94 293.85 0.00 0.00 700.00 700.00 0.00 222.64 270.40 17.36 1.62 6.4375
+07-JAN-1850 13:30:00 304.95 296.98 0.00 0.00 634.26 634.26 0.00 201.01 273.85 14.81 2.06 6.5625
+07-JAN-1850 16:30:00 293.68 295.13 0.00 0.00 108.04 108.04 0.00 34.38 274.72 6.96 1.35 6.6875
+07-JAN-1850 19:30:00 289.78 292.29 0.00 0.00 0.00 0.00 0.00 0.00 273.35 5.28 0.53 6.8125
+07-JAN-1850 22:30:00 287.79 290.24 0.00 0.00 0.00 0.00 0.00 0.00 272.13 5.43 0.51 6.9375
+08-JAN-1850 01:30:00 286.31 287.76 0.00 0.00 0.00 0.00 0.00 0.00 271.15 6.47 0.53 7.0625
+08-JAN-1850 04:30:00 285.10 286.37 0.00 0.00 0.00 0.00 0.00 0.00 270.54 7.21 0.45 7.1875
+08-JAN-1850 07:30:00 292.54 289.99 0.00 0.00 173.85 173.85 0.00 54.71 270.28 7.52 0.95 7.3125
+08-JAN-1850 10:30:00 306.38 296.82 0.00 0.00 671.47 671.47 0.00 209.95 272.91 16.56 1.68 7.4375
+08-JAN-1850 13:30:00 306.25 299.75 0.00 0.00 613.38 613.38 0.00 191.86 276.62 15.89 2.07 7.5625
+08-JAN-1850 16:30:00 295.25 297.09 0.00 0.00 106.43 106.43 0.00 33.65 277.45 6.40 1.32 7.6875
+08-JAN-1850 19:30:00 291.30 294.03 0.00 0.00 0.00 0.00 0.00 0.00 275.41 6.92 0.56 7.8125
+08-JAN-1850 22:30:00 289.27 292.12 0.00 0.00 0.00 0.00 0.00 0.00 273.72 6.68 0.52 7.9375
+09-JAN-1850 01:30:00 287.49 289.02 0.00 0.00 0.00 0.00 0.00 0.00 272.27 7.91 0.52 8.0625
+09-JAN-1850 04:30:00 286.08 287.53 0.00 0.00 0.00 0.00 0.00 0.00 271.07 8.51 0.46 8.1875
+09-JAN-1850 07:30:00 293.57 291.41 0.00 0.00 177.02 177.02 0.00 55.83 270.60 5.89 0.93 8.3125
+09-JAN-1850 10:30:00 307.47 298.31 0.00 0.00 679.36 679.36 0.00 212.31 273.79 17.70 1.70 8.4375
+09-JAN-1850 13:30:00 307.58 301.09 0.00 0.00 618.79 618.79 0.00 193.53 278.28 16.15 2.12 8.5625
+09-JAN-1850 16:30:00 296.33 298.42 0.00 0.00 108.47 108.47 0.00 34.31 279.01 6.25 1.33 8.6875
+09-JAN-1850 19:30:00 292.16 294.89 0.00 0.00 0.00 0.00 0.00 0.00 277.05 5.37 0.56 8.8125
+09-JAN-1850 22:30:00 290.05 293.07 0.00 0.00 0.00 0.00 0.00 0.00 275.61 4.82 0.46 8.9375
+10-JAN-1850 01:30:00 288.40 290.23 0.00 0.00 0.00 0.00 0.00 0.00 274.31 5.48 0.54 9.0625
+10-JAN-1850 04:30:00 287.23 288.88 0.00 0.00 0.00 0.00 0.00 0.00 273.18 7.91 0.46 9.1875
+10-JAN-1850 07:30:00 294.75 292.77 0.00 0.00 176.67 176.67 0.00 55.46 272.60 4.55 0.82 9.3125
+10-JAN-1850 10:30:00 308.31 299.51 0.00 0.00 679.31 679.31 0.00 211.58 275.78 19.07 1.76 9.4375
+10-JAN-1850 13:30:00 308.25 301.78 0.00 0.00 622.12 622.12 0.00 193.95 280.10 17.70 2.09 9.5625
+10-JAN-1850 16:30:00 297.23 299.32 0.00 0.00 108.42 108.42 0.00 34.17 280.37 7.24 1.36 9.6875
+10-JAN-1850 19:30:00 293.22 296.05 0.00 0.00 0.00 0.00 0.00 0.00 278.16 6.74 0.51 9.8125
+10-JAN-1850 22:30:00 291.21 293.74 0.00 0.00 0.00 0.00 0.00 0.00 276.46 7.63 0.46 9.9375
+11-JAN-1850 01:30:00 289.38 290.86 0.00 0.00 0.00 0.00 0.00 0.00 274.88 9.31 0.46 10.0625
+11-JAN-1850 04:30:00 287.95 289.72 0.00 0.00 0.00 0.00 0.00 0.00 273.41 8.85 0.39 10.1875
+11-JAN-1850 07:30:00 295.31 293.22 0.00 0.00 175.68 175.68 0.00 54.88 273.06 0.40 0.84 10.3125
+11-JAN-1850 10:30:00 308.32 299.07 0.00 0.00 674.07 674.07 0.00 208.96 276.18 19.14 1.57 10.4375
+11-JAN-1850 13:30:00 307.81 300.96 0.00 0.00 616.93 616.93 0.00 191.32 279.98 18.21 1.88 10.5625
+11-JAN-1850 16:30:00 297.06 298.71 0.00 0.00 107.82 107.82 0.00 33.79 280.13 8.28 1.19 10.6875
+11-JAN-1850 19:30:00 292.84 295.47 0.00 0.00 0.00 0.00 0.00 0.00 277.78 5.64 0.48 10.8125
+11-JAN-1850 22:30:00 290.65 293.15 0.00 0.00 0.00 0.00 0.00 0.00 275.82 5.52 0.40 10.9375
+12-JAN-1850 01:30:00 288.98 291.59 0.00 0.00 0.00 0.00 0.00 0.00 273.82 5.80 0.45 11.0625
+12-JAN-1850 04:30:00 287.62 290.18 0.00 0.00 0.00 0.00 0.00 0.00 271.95 6.72 0.40 11.1875
+12-JAN-1850 07:30:00 294.40 292.06 0.00 0.00 180.16 180.16 0.00 56.62 270.08 0.20 0.81 11.3125
diff --git a/src/test_stardis_smeteo.c b/src/test_stardis_smeteo.c
@@ -0,0 +1,176 @@
+/* Copyright (C) 2025 |Méso|Star> (contact@meso-star.com)
+ *
+ * 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 dismshbuted 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/>. */
+
+#define _POSIX_C_SOURCE 200809L /* strdup */
+
+#include "smeteo.h"
+#include "stardis_smeteo.h"
+
+#include <rsys/mem_allocator.h>
+
+/* FIXME required by the UINT_MAX constant used in the stardis-prog-properties
+ * header. It should by stardis, not by the caller. */
+#include <limits.h>
+
+#include <string.h> /* strdup */
+
+/*******************************************************************************
+ * Helper functions
+ ******************************************************************************/
+static void*
+check_lib_api(const char* filename)
+{
+ struct stardis_program_context ctx = {0};
+ char* argv[2] = {NULL};
+ void* lib = NULL;
+
+ /* Input strings cannot be constants, so they must be duplicated */
+ CHK(argv[0] = strdup("stardis-plugin")); /* dummy string */
+ CHK(argv[1] = strdup(filename));
+
+ ctx.name = argv[0];
+ ctx.verbosity_level = 3;
+
+ /* Invalid function calls */
+ CHK(stardis_create_library_data(NULL, 2, argv) == NULL);
+ CHK(stardis_create_library_data(&ctx, 1, argv) == NULL);
+ CHK(stardis_create_library_data(&ctx, 2, NULL) == NULL);
+
+ /* Valid function call */
+ CHK((lib = stardis_create_library_data(&ctx, 2, argv)) != NULL);
+
+ /* Verify that, on a valid lib, the legal functions return a valid result */
+ CHK(get_copyright_notice(lib) != NULL);
+ CHK(get_license_short(lib) != NULL);
+ CHK(get_license_text(lib) != NULL);
+
+ CHK(stardis_finalize_library_data(lib) == STARDIS_SUCCESS);
+
+ /* Check for error if file is invalid */
+ free(argv[1]);
+ CHK(argv[1] = strdup("invalid_filename.txt"));
+ CHK(stardis_create_library_data(&ctx, 2, argv) == NULL);
+
+ /* Clean-up allocated memory */
+ free(argv[0]);
+ free(argv[1]);
+
+ return lib; /* Return the created library */
+}
+
+static void*
+check_data_api(void* lib)
+{
+ struct stardis_description_create_context ctx = {0};
+ char* argv[1] = {NULL};
+ void* data = NULL;
+
+ /* The input string cannot be constant, so it must be duplicated */
+ CHK(argv[0] = strdup("boundary-condition")); /* dummy string */
+ ctx.name = argv[0];
+
+ /* Invalid function calls */
+ CHK(stardis_create_data(NULL, lib, 1, argv) == NULL);
+ CHK(stardis_create_data(&ctx, NULL, 1, argv) == NULL);
+ CHK(stardis_create_data(&ctx, lib, 0, argv) == NULL);
+ CHK(stardis_create_data(&ctx, lib, 1, NULL) == NULL);
+
+ /* Valid function call */
+ CHK((data = stardis_create_data(&ctx, lib, 1, argv)) != NULL);
+
+ free(argv[0]);
+
+ return data;
+}
+
+static double /* in [0-1[ */
+rand_canonical(void)
+{
+ return rand() / (double)(RAND_MAX-1);
+}
+
+static void
+check_getters(void* data, const struct smeteo* smeteo)
+{
+ struct smeteo_desc desc = SMETEO_DESC_NULL;
+ double interval_duration = 0; /* [s] */
+
+ size_t i = 0;
+ size_t nqueries = 1000;
+
+ struct stardis_vertex vtx = {0};
+ struct stardis_interface_fragment frag = {0};
+
+ CHK(smeteo_get_desc(smeteo, &desc) == RES_OK);
+
+ /* Multiplier to convert a time in day_1850 to seconds */
+ #define M_DAY1850_TO_H (24/*[h]*/ * 3600/*[s]*/)
+
+ /* The dates of the intervals are relative to midnight on January 1, 1850. In
+ * addition, their time is defined at the center of the interval. Thus, for
+ * the first interval, calculate its duration by multiplying its date relative
+ * to January 1, 1850 by 2 */
+ interval_duration = desc.entries[0].day_1850 * 2 * M_DAY1850_TO_H;
+
+ FOR_EACH(i, 0, nqueries) {
+ /* Randomly select a time interval */
+ const size_t ientry = (size_t)(rand_canonical() * (double)desc.nentries);
+ const struct smeteo_entry* entry = desc.entries + ientry;
+
+ /* Randomly sample a time [s] in the selected interval */
+ const double start = entry->day_1850*M_DAY1850_TO_H - interval_duration*0.5;
+ const double time = start + rand_canonical() * interval_duration;
+
+ vtx.time = frag.time = time;
+
+ /* query data */
+ CHK(stardis_convection_coefficient(&frag, data) == entry->H);
+ CHK(stardis_reference_temperature(&frag, data) == entry->Tsrf);
+ CHK(stardis_boundary_temperature(&frag, data) == entry->Tsrf);
+ CHK(stardis_medium_temperature(&vtx, data) == entry->Tatm);
+ CHK(stardis_emissivity(&frag, STARDIS_INTERN_SOURCE_ID, data)
+ == 1.0 - desc.albedo);
+ }
+}
+
+/*******************************************************************************
+ * The test
+ ******************************************************************************/
+int
+main(void)
+{
+ const char* filename = "samples/star-meteo_input.txt";
+
+ struct smeteo* smeteo = NULL;
+ void* lib = NULL;
+ void* data = NULL;
+
+ CHK(smeteo_create(&SMETEO_CREATE_ARGS_DEFAULT, &smeteo) == RES_OK);
+ CHK(smeteo_load(smeteo, filename) == RES_OK);
+
+ lib = check_lib_api(filename);
+ data = check_data_api(lib);
+
+ check_getters(data, smeteo);
+
+ stardis_release_library_data(lib);
+ stardis_release_data(data);
+
+ CHK(smeteo_ref_put(smeteo) == RES_OK);
+
+ CHK(mem_allocated_size() == 0);
+
+ return 0;
+}