1 /*
2 * Copyright (C) 2019 Cyril Hrubis <chrubis@suse.cz>
3 */
4
5 #ifndef SELECT_VAR__
6 #define SELECT_VAR__
7
8 #include "lapi/syscalls.h"
9
10 struct compat_sel_arg_struct {
11 long _n;
12 long _inp;
13 long _outp;
14 long _exp;
15 long _tvp;
16 };
17
do_select(int nfds,fd_set * readfds,fd_set * writefds,fd_set * exceptfds,struct timeval * timeout)18 static int do_select(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, struct timeval *timeout)
19 {
20 switch (tst_variant) {
21 case 0:
22 return select(nfds, readfds, writefds, exceptfds, timeout);
23 break;
24 case 1: {
25 #ifdef __LP64__
26 return tst_syscall(__NR_select, nfds, readfds, writefds, exceptfds, timeout);
27 #else
28 struct compat_sel_arg_struct arg = {
29 ._n = (long)nfds,
30 ._inp = (long)readfds,
31 ._outp = (long)writefds,
32 ._exp = (long)exceptfds,
33 ._tvp = (long)timeout,
34 };
35
36 return tst_syscall(__NR_select, &arg);
37 #endif /* __LP64__ */
38 }
39 case 2: {
40 int ret;
41 struct timespec ts = {
42 .tv_sec = timeout->tv_sec,
43 .tv_nsec = timeout->tv_usec * 1000,
44 };
45 ret = tst_syscall(__NR_pselect6, nfds, readfds, writefds, exceptfds, &ts, NULL);
46 timeout->tv_sec = ts.tv_sec;
47 timeout->tv_usec = ts.tv_nsec / 1000;
48 return ret;
49 }
50 case 3:
51 #ifdef __NR__newselect
52 return tst_syscall(__NR__newselect, nfds, readfds, writefds, exceptfds, timeout);
53 #else
54 tst_brk(TCONF, "__NR__newselect not implemented");
55 #endif
56 break;
57 }
58
59 return -1;
60 }
61
select_info(void)62 static void select_info(void)
63 {
64 switch (tst_variant) {
65 case 0:
66 tst_res(TINFO, "Testing libc select()");
67 break;
68 case 1:
69 tst_res(TINFO, "Testing SYS_select syscall");
70 break;
71 case 2:
72 tst_res(TINFO, "Testing SYS_pselect6 syscall");
73 break;
74 case 3:
75 tst_res(TINFO, "Testing SYS__newselect syscall");
76 break;
77 }
78 }
79
80 #define TEST_VARIANTS 4
81
82 #endif /* SELECT_VAR__ */
83