From 3eeab5a9a19013be0630da630df0155636f66a1d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20P=C3=ADsa=C5=99?= Date: Thu, 12 Jun 2025 17:24:10 +0200 Subject: [PATCH] tests: Respect compression formats rpmio supports in module_index test If rpm does not support all compression formats and libmodulemd is configured with rpmio support, module_index_release test failed: $ MESON_SOURCE_ROOT=/tmp/libmodulemd-2.15.0 TEST_DATA_PATH=/tmp/libmodulemd-2.15.0/modulemd/tests/test_data /tmp/b/modulemd/module_index TAP version 14 # random seed: R02Sf9e05b79de9e908ae8cb3de188499581 1..18 # Start of modulemd tests # Start of v2 tests # Start of module tests # Start of index tests ok 1 /modulemd/v2/module/index/dump ok 2 /modulemd/v2/module/index/read ok 3 /modulemd/v2/module/index/remove_module ok 4 /modulemd/v2/module/index/custom_read ok 5 /modulemd/v2/module/index/custom_write ok 6 /modulemd/v2/module/index/get_default_streams ok 7 /modulemd/v2/module/index/empty ** libmodulemd:ERROR:../libmodulemd-2.15.0/modulemd/tests/test-modulemd-moduleindex.c:1493:test_module_index_read_compressed: assertion failed (error == NULL): Parser error (modulemd-yaml-error-quark, 2) not ok /modulemd/v2/module/index/compressed - libmodulemd:ERROR:../libmodulemd-2.15.0/modulemd/tests/test-modulemd-moduleindex.c:1493:test_module_index_read_compressed: assertion failed (error == NULL): Parser +error (modulemd-yaml-error-quark, 2) Bail out! The test assumed that rpmio library supports all compression formats. That's not guaranteed, the support is optional for each format. This patch fixes it by probing rpmio library for each compression format and if that does not work (rpmio returns compressed data), the test will assume that that format is not supported. Implementation details: The probing happens at run-time and thus links the rpmio library to the the tests. Probing at configure time would not work when crosscompiling. Resolve: #630 --- modulemd/meson.build | 1 + modulemd/tests/test-modulemd-moduleindex.c | 65 ++++++++++++++++++++-- 2 files changed, 61 insertions(+), 5 deletions(-) diff --git a/modulemd/meson.build b/modulemd/meson.build index d58ea8f1..1c75002e 100644 --- a/modulemd/meson.build +++ b/modulemd/meson.build @@ -377,6 +377,7 @@ foreach name, sources : c_tests sources, dependencies : [ modulemd_dep, + rpm, ], link_with : [ test_utils_lib, diff --git a/modulemd/tests/test-modulemd-moduleindex.c b/modulemd/tests/test-modulemd-moduleindex.c index d4787ecf..2020ba52 100644 --- a/modulemd/tests/test-modulemd-moduleindex.c +++ b/modulemd/tests/test-modulemd-moduleindex.c @@ -11,13 +11,18 @@ * For more information on free software, see . */ +#include "config.h" + #include #include #include #include #include -#include "config.h" +#ifdef HAVE_RPMIO +#include +#endif + #include "modulemd.h" #include "modulemd-defaults.h" #include "modulemd-obsoletes.h" @@ -1377,6 +1382,10 @@ module_index_test_dump_empty_index (void) struct expected_compressed_read_t { const gchar *filename; +#ifdef HAVE_RPMIO + /* Determines a compression type */ + const gchar *rpmio_mode; +#endif /* Whether this should succeed at reading */ gboolean succeeds; @@ -1386,6 +1395,33 @@ struct expected_compressed_read_t int error_code; }; +#ifdef HAVE_RPMIO +/* Probe whether rpmio library supports that type of compression. + * @file_path is a file name to open + * @compression_type is rpmio mode string specifying the desired compression + * format. + * It assumes that an uncompressed content of the file starts with "---\n" + * string and checks the first chararter is '-'. That's because rpmio library + * silenty returns original, undecompressed, content if it does not support + * the compression format. */ +static gboolean +rpmio_can_read_compressed_file (const gchar *file_path, + const gchar *compression_type) +{ + FD_t rpmfd; + ssize_t read; + unsigned char buffer; + + rpmfd = Fopen ((const char *)file_path, (const char *)compression_type); + g_assert_nonnull (rpmfd); + read = Fread (&buffer, sizeof (buffer), 1, rpmfd); + Fclose (rpmfd); + g_assert_cmpint (read, ==, 1); + + return (buffer == (unsigned char)'-'); +} +#endif + static void test_module_index_read_compressed (void) { @@ -1402,16 +1438,22 @@ test_module_index_read_compressed (void) struct expected_compressed_read_t expected[] = { { .filename = "bzipped", + .rpmio_mode = "r.bzdio", .succeeds = TRUE, }, { .filename = "bzipped.yaml.bz2", + .rpmio_mode = "r.bzdio", .succeeds = TRUE, }, - { .filename = "gzipped", .succeeds = TRUE }, - { .filename = "gzipped.yaml.gz", .succeeds = TRUE }, - { .filename = "xzipped", .succeeds = TRUE }, - { .filename = "xzipped.yaml.xz", .succeeds = TRUE }, + { .filename = "gzipped", .rpmio_mode = "r.gzdio", .succeeds = TRUE }, + { .filename = "gzipped.yaml.gz", + .rpmio_mode = "r.gzdio", + .succeeds = TRUE }, + { .filename = "xzipped", .rpmio_mode = "r.xzdio", .succeeds = TRUE }, + { .filename = "xzipped.yaml.xz", + .rpmio_mode = "r.xzdio", + .succeeds = TRUE }, { .filename = NULL } }; @@ -1475,6 +1517,19 @@ test_module_index_read_compressed (void) expected[i].filename); g_assert_nonnull (file_path); +#ifdef HAVE_RPMIO + /* Support for various compression formats in RPMIO is optional. Probe + * the support first and set expected success/error accordingly. */ + if (!rpmio_can_read_compressed_file (file_path, expected[i].rpmio_mode)) + { + g_debug ("rpmio library does not support %s compression mode", + expected[i].rpmio_mode); + expected[i].succeeds = FALSE; + expected[i].error_domain = MODULEMD_YAML_ERROR; + expected[i].error_code = MMD_YAML_ERROR_UNPARSEABLE; + } +#endif + g_debug ("Processing %s, expecting %s", file_path, expected[i].succeeds ? "success" : "failure");