Skip to content

Commit 2b37d84

Browse files
rantalametan-ucw
authored andcommitted
syscalls/fanotify11.c: check fanotify kernel support
Add setup() with SAFE_FANOTIFY_INIT() call, so that the test is skipped if kernel is configured without fanotify support. Also move and tweak the tst_res() message, so that when running without FAN_REPORT_TID support, it's more clear which testcase was skipped. Signed-off-by: Tommi Rantala <[email protected]> Acked-by: Cyril Hrubis <[email protected]>
1 parent 2e74d99 commit 2b37d84

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

testcases/kernel/syscalls/fanotify/fanotify11.c

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,10 @@ void test01(unsigned int i)
6161
int fd_notify;
6262
int tgid = getpid();
6363

64+
tst_res(TINFO, "Test #%u: %s FAN_REPORT_TID: tgid=%d, tid=%d, event.pid=%d",
65+
i, (tcases[i] & FAN_REPORT_TID) ? "with" : "without",
66+
tgid, tid, event.pid);
67+
6468
fd_notify = fanotify_init(tcases[i], 0);
6569
if (fd_notify < 0) {
6670
if (errno == EINVAL && (tcases[i] & FAN_REPORT_TID)) {
@@ -80,9 +84,7 @@ void test01(unsigned int i)
8084
SAFE_PTHREAD_CREATE(&p_id, NULL, thread_create_file, NULL);
8185

8286
SAFE_READ(0, fd_notify, &event, sizeof(struct fanotify_event_metadata));
83-
tst_res(TINFO, "%s FAN_REPORT_TID: tgid=%d, tid=%d, event.pid=%d",
84-
(tcases[i] & FAN_REPORT_TID) ? "with" : "without",
85-
tgid, tid, event.pid);
87+
8688
if ((tcases[i] & FAN_REPORT_TID) && event.pid == tid)
8789
tst_res(TPASS, "event.pid == tid");
8890
else if (!(tcases[i] & FAN_REPORT_TID) && event.pid == tgid)
@@ -96,8 +98,16 @@ void test01(unsigned int i)
9698
SAFE_PTHREAD_JOIN(p_id, NULL);
9799
}
98100

101+
static void setup(void)
102+
{
103+
int fd;
104+
105+
fd = SAFE_FANOTIFY_INIT(FAN_CLASS_NOTIF, O_RDONLY);
106+
SAFE_CLOSE(fd);
107+
}
99108

100109
static struct tst_test test = {
110+
.setup = setup,
101111
.test = test01,
102112
.tcnt = ARRAY_SIZE(tcases),
103113
.needs_tmpdir = 1,

0 commit comments

Comments
 (0)