1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3 * Copyright (c) International Business Machines Corp., 2001
4 * Copyright (c) 2008 Vijay Kumar B. <[email protected]>
5 * Copyright (c) Linux Test Project, 2008-2022
6 * Copyright (C) 2023 SUSE LLC Andrea Cervesato <[email protected]>
7 */
8
9 /*\
10 * [Description]
11 *
12 * Verify read operation for eventfd fail with:
13 *
14 * - EAGAIN when counter is zero on non blocking fd
15 * - EINVAL when buffer size is less than 8 bytes
16 */
17
18 #include <stdlib.h>
19 #include <sys/eventfd.h>
20 #include "tst_test.h"
21
22 #define EVENT_COUNT 10
23
run(void)24 static void run(void)
25 {
26 int fd;
27 uint64_t val;
28 uint32_t invalid;
29
30 fd = TST_EXP_FD(eventfd(EVENT_COUNT, EFD_NONBLOCK));
31
32 SAFE_READ(0, fd, &val, sizeof(val));
33 TST_EXP_EQ_LI(val, EVENT_COUNT);
34
35 TST_EXP_FAIL(read(fd, &val, sizeof(val)), EAGAIN);
36 TST_EXP_FAIL(read(fd, &invalid, sizeof(invalid)), EINVAL);
37
38 SAFE_CLOSE(fd);
39 }
40
41 static struct tst_test test = {
42 .test_all = run,
43 .needs_kconfigs = (const char *[]) {
44 "CONFIG_EVENTFD",
45 NULL
46 },
47 };
48