blob: 651b426e0c0b6099daf260befafdfbcb83b8bbb0 [file] [log] [blame]
Dmitry V. Levinb8f0c922015-09-16 16:31:43 +00001/*
Dmitry V. Levin21bbc142016-01-06 09:49:32 +00002 * Copyright (c) 2015-2016 Dmitry V. Levin <ldv@altlinux.org>
Dmitry V. Levinb8f0c922015-09-16 16:31:43 +00003 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. The name of the author may not be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
Dmitry V. Levin0c8853c2016-01-02 13:28:43 +000028#include "tests.h"
Dmitry V. Levinb8f0c922015-09-16 16:31:43 +000029#include <sys/syscall.h>
30
31#ifdef __NR_timer_create
32
Dmitry V. Levin21bbc142016-01-06 09:49:32 +000033# include <stdio.h>
34# include <signal.h>
35# include <time.h>
36# include <unistd.h>
37
Dmitry V. Levinb8f0c922015-09-16 16:31:43 +000038int
39main(void)
40{
41 int tid[4] = {};
42 struct sigevent sev = {
43 .sigev_notify = SIGEV_NONE,
44 .sigev_signo = 0xfacefeed,
45 .sigev_value.sival_ptr =
46 (void *) (unsigned long) 0xdeadbeefbadc0ded
47 };
48
49 if (syscall(__NR_timer_create, CLOCK_REALTIME, &sev, &tid[0]))
Dmitry V. Levin21bbc142016-01-06 09:49:32 +000050 perror_msg_and_skip("timer_create CLOCK_REALTIME");
Dmitry V. Levinb8f0c922015-09-16 16:31:43 +000051 printf("timer_create(CLOCK_REALTIME, {sigev_value={int=%d, ptr=%p}"
52 ", sigev_signo=%u, sigev_notify=SIGEV_NONE}"
53 ", [%d]) = 0\n",
54 sev.sigev_value.sival_int,
55 sev.sigev_value.sival_ptr,
56 sev.sigev_signo, tid[0]);
57
58 sev.sigev_notify = SIGEV_SIGNAL;
59 sev.sigev_signo = SIGALRM;
60 if (syscall(__NR_timer_create, CLOCK_MONOTONIC, &sev, &tid[1]))
Dmitry V. Levin21bbc142016-01-06 09:49:32 +000061 perror_msg_and_skip("timer_create CLOCK_MONOTONIC");
Dmitry V. Levinb8f0c922015-09-16 16:31:43 +000062 printf("timer_create(CLOCK_MONOTONIC, {sigev_value={int=%d, ptr=%p}"
63 ", sigev_signo=SIGALRM, sigev_notify=SIGEV_SIGNAL}"
64 ", [%d]) = 0\n",
65 sev.sigev_value.sival_int,
66 sev.sigev_value.sival_ptr, tid[1]);
67
68 sev.sigev_notify = SIGEV_THREAD;
69 sev.sigev_notify_function =
70 (void *) (unsigned long) 0xdeadbeefbadc0ded;
71 sev.sigev_notify_attributes =
72 (void *) (unsigned long) 0xcafef00dfacefeed;
73 if (syscall(__NR_timer_create, CLOCK_REALTIME, &sev, &tid[2]))
Dmitry V. Levin21bbc142016-01-06 09:49:32 +000074 perror_msg_and_skip("timer_create CLOCK_REALTIME");
Dmitry V. Levinb8f0c922015-09-16 16:31:43 +000075 printf("timer_create(CLOCK_REALTIME, {sigev_value={int=%d, ptr=%p}"
76 ", sigev_signo=SIGALRM, sigev_notify=SIGEV_THREAD"
77 ", sigev_notify_function=%p, sigev_notify_attributes=%p}"
78 ", [%d]) = 0\n",
79 sev.sigev_value.sival_int,
80 sev.sigev_value.sival_ptr,
81 sev.sigev_notify_function,
82 sev.sigev_notify_attributes,
83 tid[2]);
84
85#ifndef sigev_notify_thread_id
86# if defined HAVE_STRUCT_SIGEVENT__SIGEV_UN__PAD
87# define sigev_notify_thread_id _sigev_un._pad[0]
88# elif defined HAVE_STRUCT_SIGEVENT___PAD
89# define sigev_notify_thread_id __pad[0]
90# endif
91#endif /* !sigev_notify_thread_id */
92
93#ifdef sigev_notify_thread_id
94# ifndef SIGEV_THREAD_ID
95# define SIGEV_THREAD_ID 4
96# endif
97 sev.sigev_notify = SIGEV_THREAD_ID;
98 sev.sigev_notify_thread_id = getpid();
99 if (syscall(__NR_timer_create, CLOCK_MONOTONIC, &sev, &tid[3]))
Dmitry V. Levin21bbc142016-01-06 09:49:32 +0000100 perror_msg_and_skip("timer_create CLOCK_MONOTONIC");
Dmitry V. Levinb8f0c922015-09-16 16:31:43 +0000101 printf("timer_create(CLOCK_MONOTONIC, {sigev_value={int=%d, ptr=%p}"
102 ", sigev_signo=SIGALRM, sigev_notify=SIGEV_THREAD_ID"
103 ", sigev_notify_thread_id=%d}"
104 ", [%d]) = 0\n",
105 sev.sigev_value.sival_int,
106 sev.sigev_value.sival_ptr,
107 sev.sigev_notify_thread_id,
108 tid[3]);
109#endif /* sigev_notify_thread_id */
110
111 puts("+++ exited with 0 +++");
112 return 0;
113}
114
115#else
116
Dmitry V. Levin21bbc142016-01-06 09:49:32 +0000117SKIP_MAIN_UNDEFINED("__NR_timer_create")
Dmitry V. Levinb8f0c922015-09-16 16:31:43 +0000118
119#endif