Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

testsuite: fix fileref unit test failure on tmpfs #5643

Merged
merged 1 commit into from
Dec 28, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading