Skip to content

Commit

Permalink
Merge pull request flux-framework#5643 from garlick/issue#5642
Browse files Browse the repository at this point in the history
testsuite: fix fileref unit test failure on tmpfs
  • Loading branch information
mergify[bot] authored Dec 28, 2023
2 parents beeb4ef + d2b418b commit d54e364
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 d54e364

Please sign in to comment.