1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3 * Copyright (c) 2017 Petr Vorel <pvorel@suse.cz>
4 */
5
6 #ifndef MQ_TIMED_H
7 #define MQ_TIMED_H
8
9 #include "mq.h"
10 #include "time64_variants.h"
11 #include "tst_timer.h"
12
13 static struct time64_variants variants[] = {
14 { .clock_gettime = libc_clock_gettime, .mqt_send = libc_mq_timedsend, .mqt_receive = libc_mq_timedreceive, .ts_type = TST_LIBC_TIMESPEC, .desc = "vDSO or syscall with libc spec"},
15
16 #if (__NR_mq_timedsend != __LTP__NR_INVALID_SYSCALL)
17 { .clock_gettime = sys_clock_gettime, .mqt_send = sys_mq_timedsend, .mqt_receive = sys_mq_timedreceive, .ts_type = TST_KERN_OLD_TIMESPEC, .desc = "syscall with old kernel spec"},
18 #endif
19
20 #if (__NR_mq_timedsend_time64 != __LTP__NR_INVALID_SYSCALL)
21 { .clock_gettime = sys_clock_gettime64, .mqt_send = sys_mq_timedsend64, .mqt_receive = sys_mq_timedreceive64, .ts_type = TST_KERN_TIMESPEC, .desc = "syscall time64 with kernel spec"},
22 #endif
23 };
24
25 struct test_case {
26 int *fd;
27 unsigned int len;
28 unsigned int prio;
29 struct tst_ts *rq;
30 long tv_sec;
31 long tv_nsec;
32 int invalid_msg;
33 int send;
34 int signal;
35 int timeout;
36 int bad_msg_addr;
37 int bad_ts_addr;
38 int ret;
39 int err;
40 };
41
set_sig(struct tst_ts * ts,int (* gettime)(clockid_t clk_id,void * ts))42 static pid_t set_sig(struct tst_ts *ts,
43 int (*gettime)(clockid_t clk_id, void *ts))
44 {
45 gettime(CLOCK_REALTIME, tst_ts_get(ts));
46 *ts = tst_ts_add_us(*ts, 3000000);
47
48 return create_sig_proc(SIGINT, 40, 50000);
49 }
50
set_timeout(struct tst_ts * ts,int (* gettime)(clockid_t clk_id,void * ts))51 static void set_timeout(struct tst_ts *ts,
52 int (*gettime)(clockid_t clk_id, void *ts))
53 {
54 gettime(CLOCK_REALTIME, tst_ts_get(ts));
55 *ts = tst_ts_add_us(*ts, 10000);
56 }
57
kill_pid(pid_t pid)58 static void kill_pid(pid_t pid)
59 {
60 SAFE_KILL(pid, SIGTERM);
61 SAFE_WAIT(NULL);
62 }
63
64 #endif /* MQ_TIMED_H */
65