selftests: cachestat: catch failing fsync test on tmpfs
authorAndre Przywara <andre.przywara@arm.com>
Mon, 21 Aug 2023 16:05:34 +0000 (17:05 +0100)
committerAndrew Morton <akpm@linux-foundation.org>
Thu, 24 Aug 2023 21:59:47 +0000 (14:59 -0700)
commitf84f62e69963d7742acec4340ec1c4c7ef22b887
tree037fbdb5b9e4ba0227f5dfba4b3a0888c562da89
parent5e56982dd0759d8b345fe1468297dd4f630db5d7
selftests: cachestat: catch failing fsync test on tmpfs

The cachestat kselftest runs a test on a normal file, which is created
temporarily in the current directory.  Among the tests it runs there is a
call to fsync(), which is expected to clean all dirty pages used by the
file.

However the tmpfs filesystem implements fsync() as noop_fsync(), so the
call will not even attempt to clean anything when this test file happens
to live on a tmpfs instance.  This happens in an initramfs, or when the
current directory is in /dev/shm or sometimes /tmp.

To avoid this test failing wrongly, use statfs() to check which filesystem
the test file lives on.  If that is "tmpfs", we skip the fsync() test.

Since the fsync test is only one part of the "normal file" test, we now
execute this twice, skipping the fsync part on the first call.  This way
only the second test, including the fsync part, would be skipped.

Link: https://lkml.kernel.org/r/20230821160534.3414911-3-andre.przywara@arm.com
Signed-off-by: Andre Przywara <andre.przywara@arm.com>
Cc: Johannes Weiner <hannes@cmpxchg.org>
Cc: Nhat Pham <nphamcs@gmail.com>
Cc: Shuah Khan <shuah@kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
tools/testing/selftests/cachestat/test_cachestat.c