1 // SPDX-License-Identifier: GPL-2.0
2 /* Copyright (c) 2020 Facebook */
8 #include <test_progs.h>
10 #define TDIR "/sys/kernel/debug"
12 static int read_iter(char *file
)
14 /* 1024 should be enough to get contiguous 4 "iter" letters at some point */
21 while ((len
= read(fd
, buf
, sizeof(buf
))) > 0)
22 if (strstr(buf
, "iter")) {
32 int err
, duration
= 0;
34 err
= unshare(CLONE_NEWNS
);
35 if (CHECK(err
, "unshare", "failed: %d\n", errno
))
38 err
= mount("", "/", "", MS_REC
| MS_PRIVATE
, NULL
);
39 if (CHECK(err
, "mount /", "failed: %d\n", errno
))
43 if (CHECK(err
, "umount " TDIR
, "failed: %d\n", errno
))
46 err
= mount("none", TDIR
, "tmpfs", 0, NULL
);
47 if (CHECK(err
, "mount", "mount root failed: %d\n", errno
))
50 err
= mkdir(TDIR
"/fs1", 0777);
51 if (CHECK(err
, "mkdir "TDIR
"/fs1", "failed: %d\n", errno
))
53 err
= mkdir(TDIR
"/fs2", 0777);
54 if (CHECK(err
, "mkdir "TDIR
"/fs2", "failed: %d\n", errno
))
57 err
= mount("bpf", TDIR
"/fs1", "bpf", 0, NULL
);
58 if (CHECK(err
, "mount bpffs "TDIR
"/fs1", "failed: %d\n", errno
))
60 err
= mount("bpf", TDIR
"/fs2", "bpf", 0, NULL
);
61 if (CHECK(err
, "mount bpffs " TDIR
"/fs2", "failed: %d\n", errno
))
64 err
= read_iter(TDIR
"/fs1/maps.debug");
65 if (CHECK(err
, "reading " TDIR
"/fs1/maps.debug", "failed\n"))
67 err
= read_iter(TDIR
"/fs2/progs.debug");
68 if (CHECK(err
, "reading " TDIR
"/fs2/progs.debug", "failed\n"))
79 void test_test_bpffs(void)
81 int err
, duration
= 0, status
= 0;
85 if (CHECK(pid
== -1, "clone", "clone failed %d", errno
))
89 err
= waitpid(pid
, &status
, 0);
90 if (CHECK(err
== -1 && errno
!= ECHILD
, "waitpid", "failed %d", errno
))
92 if (CHECK(WEXITSTATUS(status
), "bpffs test ", "failed %d", WEXITSTATUS(status
)))