1f08c3bdfSopenharmony_ci// SPDX-License-Identifier: GPL-2.0-or-later
2f08c3bdfSopenharmony_ci/*
3f08c3bdfSopenharmony_ci * Copyright (c) 2014 Fujitsu Ltd.
4f08c3bdfSopenharmony_ci * Author: Zeng Linggang <zenglg.jy@cn.fujitsu.com>
5f08c3bdfSopenharmony_ci */
6f08c3bdfSopenharmony_ci
7f08c3bdfSopenharmony_ci/*\
8f08c3bdfSopenharmony_ci * [Description]
9f08c3bdfSopenharmony_ci *
10f08c3bdfSopenharmony_ci *  Verify that pselect() fails with:
11f08c3bdfSopenharmony_ci *
12f08c3bdfSopenharmony_ci *  - EBADF if a file descriptor that was already closed
13f08c3bdfSopenharmony_ci *  - EINVAL if nfds was negative
14f08c3bdfSopenharmony_ci *  - EINVAL if the value contained within timeout was invalid
15f08c3bdfSopenharmony_ci */
16f08c3bdfSopenharmony_ci
17f08c3bdfSopenharmony_ci#include "tst_test.h"
18f08c3bdfSopenharmony_ci
19f08c3bdfSopenharmony_cistatic fd_set read_fds;
20f08c3bdfSopenharmony_cistatic struct timespec time_buf;
21f08c3bdfSopenharmony_ci
22f08c3bdfSopenharmony_cistatic struct tcase {
23f08c3bdfSopenharmony_ci	int nfds;
24f08c3bdfSopenharmony_ci	fd_set *readfds;
25f08c3bdfSopenharmony_ci	struct timespec *timeout;
26f08c3bdfSopenharmony_ci	int exp_errno;
27f08c3bdfSopenharmony_ci} tcases[] = {
28f08c3bdfSopenharmony_ci	{128, &read_fds, NULL, EBADF},
29f08c3bdfSopenharmony_ci	{-1, NULL, NULL, EINVAL},
30f08c3bdfSopenharmony_ci	{128, NULL, &time_buf, EINVAL},
31f08c3bdfSopenharmony_ci};
32f08c3bdfSopenharmony_ci
33f08c3bdfSopenharmony_cistatic void setup(void)
34f08c3bdfSopenharmony_ci{
35f08c3bdfSopenharmony_ci	int fd;
36f08c3bdfSopenharmony_ci
37f08c3bdfSopenharmony_ci	fd = SAFE_OPEN("test_file", O_RDWR | O_CREAT, 0777);
38f08c3bdfSopenharmony_ci
39f08c3bdfSopenharmony_ci	FD_ZERO(&read_fds);
40f08c3bdfSopenharmony_ci	FD_SET(fd, &read_fds);
41f08c3bdfSopenharmony_ci
42f08c3bdfSopenharmony_ci	SAFE_CLOSE(fd);
43f08c3bdfSopenharmony_ci
44f08c3bdfSopenharmony_ci	time_buf.tv_sec = -1;
45f08c3bdfSopenharmony_ci	time_buf.tv_nsec = 0;
46f08c3bdfSopenharmony_ci}
47f08c3bdfSopenharmony_ci
48f08c3bdfSopenharmony_cistatic void pselect_verify(unsigned int i)
49f08c3bdfSopenharmony_ci{
50f08c3bdfSopenharmony_ci	struct tcase *tc = &tcases[i];
51f08c3bdfSopenharmony_ci
52f08c3bdfSopenharmony_ci	TST_EXP_FAIL(pselect(tc->nfds, tc->readfds, NULL, NULL, tc->timeout, NULL),
53f08c3bdfSopenharmony_ci			tc->exp_errno, "pselect(%i, %p, %p)",
54f08c3bdfSopenharmony_ci			tc->nfds, tc->readfds, tc->timeout);
55f08c3bdfSopenharmony_ci}
56f08c3bdfSopenharmony_ci
57f08c3bdfSopenharmony_cistatic struct tst_test test = {
58f08c3bdfSopenharmony_ci	.tcnt = ARRAY_SIZE(tcases),
59f08c3bdfSopenharmony_ci	.test = pselect_verify,
60f08c3bdfSopenharmony_ci	.setup = setup,
61f08c3bdfSopenharmony_ci	.needs_tmpdir = 1,
62f08c3bdfSopenharmony_ci};
63