Skip to content

Commit 3eeab5a

Browse files
committed
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
1 parent e7f179e commit 3eeab5a

File tree

2 files changed

+61
-5
lines changed

2 files changed

+61
-5
lines changed

modulemd/meson.build

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -377,6 +377,7 @@ foreach name, sources : c_tests
377377
sources,
378378
dependencies : [
379379
modulemd_dep,
380+
rpm,
380381
],
381382
link_with : [
382383
test_utils_lib,

modulemd/tests/test-modulemd-moduleindex.c

Lines changed: 60 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,18 @@
1111
* For more information on free software, see <https://www.gnu.org/philosophy/free-sw.en.html>.
1212
*/
1313

14+
#include "config.h"
15+
1416
#include <glib.h>
1517
#include <glib/gstdio.h>
1618
#include <locale.h>
1719
#include <signal.h>
1820
#include <yaml.h>
1921

20-
#include "config.h"
22+
#ifdef HAVE_RPMIO
23+
#include <rpm/rpmio.h>
24+
#endif
25+
2126
#include "modulemd.h"
2227
#include "modulemd-defaults.h"
2328
#include "modulemd-obsoletes.h"
@@ -1377,6 +1382,10 @@ module_index_test_dump_empty_index (void)
13771382
struct expected_compressed_read_t
13781383
{
13791384
const gchar *filename;
1385+
#ifdef HAVE_RPMIO
1386+
/* Determines a compression type */
1387+
const gchar *rpmio_mode;
1388+
#endif
13801389

13811390
/* Whether this should succeed at reading */
13821391
gboolean succeeds;
@@ -1386,6 +1395,33 @@ struct expected_compressed_read_t
13861395
int error_code;
13871396
};
13881397

1398+
#ifdef HAVE_RPMIO
1399+
/* Probe whether rpmio library supports that type of compression.
1400+
* @file_path is a file name to open
1401+
* @compression_type is rpmio mode string specifying the desired compression
1402+
* format.
1403+
* It assumes that an uncompressed content of the file starts with "---\n"
1404+
* string and checks the first chararter is '-'. That's because rpmio library
1405+
* silenty returns original, undecompressed, content if it does not support
1406+
* the compression format. */
1407+
static gboolean
1408+
rpmio_can_read_compressed_file (const gchar *file_path,
1409+
const gchar *compression_type)
1410+
{
1411+
FD_t rpmfd;
1412+
ssize_t read;
1413+
unsigned char buffer;
1414+
1415+
rpmfd = Fopen ((const char *)file_path, (const char *)compression_type);
1416+
g_assert_nonnull (rpmfd);
1417+
read = Fread (&buffer, sizeof (buffer), 1, rpmfd);
1418+
Fclose (rpmfd);
1419+
g_assert_cmpint (read, ==, 1);
1420+
1421+
return (buffer == (unsigned char)'-');
1422+
}
1423+
#endif
1424+
13891425
static void
13901426
test_module_index_read_compressed (void)
13911427
{
@@ -1402,16 +1438,22 @@ test_module_index_read_compressed (void)
14021438
struct expected_compressed_read_t expected[] = {
14031439
{
14041440
.filename = "bzipped",
1441+
.rpmio_mode = "r.bzdio",
14051442
.succeeds = TRUE,
14061443
},
14071444
{
14081445
.filename = "bzipped.yaml.bz2",
1446+
.rpmio_mode = "r.bzdio",
14091447
.succeeds = TRUE,
14101448
},
1411-
{ .filename = "gzipped", .succeeds = TRUE },
1412-
{ .filename = "gzipped.yaml.gz", .succeeds = TRUE },
1413-
{ .filename = "xzipped", .succeeds = TRUE },
1414-
{ .filename = "xzipped.yaml.xz", .succeeds = TRUE },
1449+
{ .filename = "gzipped", .rpmio_mode = "r.gzdio", .succeeds = TRUE },
1450+
{ .filename = "gzipped.yaml.gz",
1451+
.rpmio_mode = "r.gzdio",
1452+
.succeeds = TRUE },
1453+
{ .filename = "xzipped", .rpmio_mode = "r.xzdio", .succeeds = TRUE },
1454+
{ .filename = "xzipped.yaml.xz",
1455+
.rpmio_mode = "r.xzdio",
1456+
.succeeds = TRUE },
14151457
{ .filename = NULL }
14161458
};
14171459

@@ -1475,6 +1517,19 @@ test_module_index_read_compressed (void)
14751517
expected[i].filename);
14761518
g_assert_nonnull (file_path);
14771519

1520+
#ifdef HAVE_RPMIO
1521+
/* Support for various compression formats in RPMIO is optional. Probe
1522+
* the support first and set expected success/error accordingly. */
1523+
if (!rpmio_can_read_compressed_file (file_path, expected[i].rpmio_mode))
1524+
{
1525+
g_debug ("rpmio library does not support %s compression mode",
1526+
expected[i].rpmio_mode);
1527+
expected[i].succeeds = FALSE;
1528+
expected[i].error_domain = MODULEMD_YAML_ERROR;
1529+
expected[i].error_code = MMD_YAML_ERROR_UNPARSEABLE;
1530+
}
1531+
#endif
1532+
14781533
g_debug ("Processing %s, expecting %s",
14791534
file_path,
14801535
expected[i].succeeds ? "success" : "failure");

0 commit comments

Comments
 (0)