Skip to content

Commit

Permalink
testsuite: fix fileref unit test failure on tmpfs
Browse files Browse the repository at this point in the history
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
  • Loading branch information
garlick committed Dec 28, 2023
1 parent beeb4ef commit d2b418b
Showing 1 changed file with 27 additions and 5 deletions.
32 changes: 27 additions & 5 deletions src/common/libutil/test/fileref.c
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand Down Expand Up @@ -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);
Expand All @@ -493,9 +516,8 @@ void test_vec (void)
testvec[i].exp_blobs,
testvec[i].hashtype);
json_decref (o);
rmfile ("testfile");

end_skip;
rmfile ("testfile");
}
}

Expand Down

0 comments on commit d2b418b

Please sign in to comment.