• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2017 Petr Vorel <pvorel@suse.cz>
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License as
6  * published by the Free Software Foundation; either version 2 of
7  * the License, or (at your option) any later version.
8  *
9  * This program is distributed in the hope that it would be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program. If not, see <http://www.gnu.org/licenses/>.
16  */
17 
18 #ifndef MQ_TIMED_H
19 #define MQ_TIMED_H
20 
21 #include "mq.h"
22 
23 struct test_case {
24 	int *fd;
25 	unsigned int len;
26 	unsigned int prio;
27 	struct timespec *rq;
28 	int invalid_msg;
29 	int send;
30 	int signal;
31 	int timeout;
32 	int ret;
33 	int err;
34 };
35 
set_sig(struct timespec * ts)36 static pid_t set_sig(struct timespec *ts)
37 {
38 	clock_gettime(CLOCK_REALTIME, ts);
39 	ts->tv_sec += 3;
40 
41 	return create_sig_proc(SIGINT, 40, 200000);
42 }
43 
set_timeout(struct timespec * ts)44 static void set_timeout(struct timespec *ts)
45 {
46 	clock_gettime(CLOCK_REALTIME, ts);
47 	ts->tv_nsec += 50000000;
48 	ts->tv_sec += ts->tv_nsec / 1000000000;
49 	ts->tv_nsec %= 1000000000;
50 }
51 
send_msg(int fd,int len,int prio)52 static void send_msg(int fd, int len, int prio)
53 {
54 	if (mq_timedsend(fd, smsg, len, prio,
55 		&((struct timespec){0})) < 0)
56 		tst_brk(TBROK | TERRNO, "mq_timedsend failed");
57 }
58 
kill_pid(pid_t pid)59 static void kill_pid(pid_t pid)
60 {
61 	SAFE_KILL(pid, SIGTERM);
62 	SAFE_WAIT(NULL);
63 }
64 
65 #endif /* MQ_TIMED_H */
66