From d2b418b532bb25f4a37a8c586f06da1e7db72c34 Mon Sep 17 00:00:00 2001 From: Jim Garlick Date: Thu, 28 Dec 2023 09:22:13 -0800 Subject: [PATCH] testsuite: fix fileref unit test failure on tmpfs Problem: the fileref unit test fails on tmpfs in debian 11, kernel 6.1.0-rpi7-rpi-2712. Although tmpfs supports sparse files, in some cases the test's efforts to create sparse test files are unsuccessful. Skip tests when the test file must be sparse and is not. Fixes #5642 --- src/common/libutil/test/fileref.c | 32 ++++++++++++++++++++++++++----- 1 file changed, 27 insertions(+), 5 deletions(-) diff --git a/src/common/libutil/test/fileref.c b/src/common/libutil/test/fileref.c index e60268318d47..ee4656109480 100644 --- a/src/common/libutil/test/fileref.c +++ b/src/common/libutil/test/fileref.c @@ -109,6 +109,28 @@ bool test_sparse (void) return result; } +bool is_sparse (const char *name) +{ + bool result = false; +#ifdef SEEK_HOLE + int fd; + struct stat sb; + off_t offset; + + fd = open (mkpath (name), O_RDONLY); + if (fd < 0) + return false; + if (fstat (fd, &sb) < 0 || !S_ISREG (sb.st_mode)) + goto error; + offset = lseek (fd, 0, SEEK_HOLE); + if (offset < sb.st_size) + result = true; +error: + close (fd); +#endif /* SEEK_HOLE */ + return result; +} + /* Create test file 'name' under test directory. * Each character in 'spec' represents one block filled with that character, * except for "-" which tries to create a hole (if supported by file system). @@ -478,10 +500,11 @@ void test_vec (void) json_t *o; bool rc; - skip (strchr (testvec[i].spec, '-') && !have_sparse, - 1, "test directory does not support sparse files"); - mkfile ("testfile", 4096, testvec[i].spec); + skip ((strchr (testvec[i].spec, '-') + && (!have_sparse || !is_sparse ("testfile"))), + 1, "sparse %s test file could not be created", testvec[i].spec); + o = xfileref_create_vec (mkpath ("testfile"), testvec[i].hashtype, testvec[i].chunksize); @@ -493,9 +516,8 @@ void test_vec (void) testvec[i].exp_blobs, testvec[i].hashtype); json_decref (o); - rmfile ("testfile"); - end_skip; + rmfile ("testfile"); } }