Skip to content

Commit a8efadd

Browse files
lorenzo-stoakesakpm00
authored andcommitted
tools/testing/selftests: fix guard region test tmpfs assumption
The current implementation of the guard region tests assume that /tmp is mounted as tmpfs, that is shmem. This isn't always the case, and at least one instance of a spurious test failure has been reported as a result. This assumption is unsafe, rushed and silly - and easily remedied by simply using memfd, so do so. We also have to fixup the readonly_file test to explicitly only be applicable to file-backed cases. Link: https://lkml.kernel.org/r/[email protected] Fixes: 272f37d ("tools/selftests: expand all guard region tests to file-backed") Signed-off-by: Lorenzo Stoakes <[email protected]> Reported-by: Ryan Roberts <[email protected]> Closes: https://lore.kernel.org/linux-mm/[email protected]/ Reviewed-by: Ryan Roberts <[email protected]> Cc: <[email protected]> Signed-off-by: Andrew Morton <[email protected]>
1 parent fcaf3b2 commit a8efadd

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

tools/testing/selftests/mm/guard-regions.c

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -271,12 +271,16 @@ FIXTURE_SETUP(guard_regions)
271271
self->page_size = (unsigned long)sysconf(_SC_PAGESIZE);
272272
setup_sighandler();
273273

274-
if (variant->backing == ANON_BACKED)
274+
switch (variant->backing) {
275+
case ANON_BACKED:
275276
return;
276-
277-
self->fd = open_file(
278-
variant->backing == SHMEM_BACKED ? "/tmp/" : "",
279-
self->path);
277+
case LOCAL_FILE_BACKED:
278+
self->fd = open_file("", self->path);
279+
break;
280+
case SHMEM_BACKED:
281+
self->fd = memfd_create(self->path, 0);
282+
break;
283+
}
280284

281285
/* We truncate file to at least 100 pages, tests can modify as needed. */
282286
ASSERT_EQ(ftruncate(self->fd, 100 * self->page_size), 0);
@@ -1696,7 +1700,7 @@ TEST_F(guard_regions, readonly_file)
16961700
char *ptr;
16971701
int i;
16981702

1699-
if (variant->backing == ANON_BACKED)
1703+
if (variant->backing != LOCAL_FILE_BACKED)
17001704
SKIP(return, "Read-only test specific to file-backed");
17011705

17021706
/* Map shared so we can populate with pattern, populate it, unmap. */

0 commit comments

Comments
 (0)