Skip to content

Commit 5e56982

Browse files
Andre-ARMakpm00
authored andcommitted
selftests: cachestat: test for cachestat availability
Patch series "selftests: cachestat: fix run on older kernels", v2. I ran all kernel selftests on some test machine, and stumbled upon cachestat failing (among others). These patches fix the run on older kernels and when the current directory is on a tmpfs instance. This patch (of 2): As cachestat is a new syscall, it won't be available on older kernels, for instance those running on a development machine. At the moment the test reports all tests as "not ok" in this case. Test for the cachestat syscall availability first, before doing further tests, and bail out early with a TAP SKIP comment. This also uses the opportunity to add the proper TAP headers, and add one check for proper error handling (illegal file descriptor). Link: https://lkml.kernel.org/r/20230821160534.3414911-1-andre.przywara@arm.com Link: https://lkml.kernel.org/r/20230821160534.3414911-2-andre.przywara@arm.com Signed-off-by: Andre Przywara <andre.przywara@arm.com> Acked-by: Nhat Pham <nphamcs@gmail.com> Cc: Johannes Weiner <hannes@cmpxchg.org> Cc: Shuah Khan <shuah@kernel.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
1 parent cfeb6ae commit 5e56982

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

tools/testing/selftests/cachestat/test_cachestat.c

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515

1616
#include "../kselftest.h"
1717

18+
#define NR_TESTS 8
19+
1820
static const char * const dev_files[] = {
1921
"/dev/zero", "/dev/null", "/dev/urandom",
2022
"/proc/version", "/proc"
@@ -236,7 +238,23 @@ bool test_cachestat_shmem(void)
236238

237239
int main(void)
238240
{
239-
int ret = 0;
241+
int ret;
242+
243+
ksft_print_header();
244+
245+
ret = syscall(__NR_cachestat, -1, NULL, NULL, 0);
246+
if (ret == -1 && errno == ENOSYS)
247+
ksft_exit_skip("cachestat syscall not available\n");
248+
249+
ksft_set_plan(NR_TESTS);
250+
251+
if (ret == -1 && errno == EBADF) {
252+
ksft_test_result_pass("bad file descriptor recognized\n");
253+
ret = 0;
254+
} else {
255+
ksft_test_result_fail("bad file descriptor ignored\n");
256+
ret = 1;
257+
}
240258

241259
for (int i = 0; i < 5; i++) {
242260
const char *dev_filename = dev_files[i];

0 commit comments

Comments
 (0)