1 /*
2 * This file is part of timer_create strace test.
3 *
4 * Copyright (c) 2015-2016 Dmitry V. Levin <ldv@altlinux.org>
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. The name of the author may not be used to endorse or promote products
16 * derived from this software without specific prior written permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
19 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
22 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
23 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 */
29
30 #include "tests.h"
31 #include <asm/unistd.h>
32
33 #ifdef __NR_timer_create
34
35 # include <stdio.h>
36 # include <signal.h>
37 # include <time.h>
38 # include <unistd.h>
39 # include "sigevent.h"
40
41 int
main(void)42 main(void)
43 {
44 syscall(__NR_timer_create, CLOCK_REALTIME, NULL, NULL);
45 printf("timer_create(CLOCK_REALTIME, NULL, NULL) = -1 %s (%m)\n",
46 errno2name());
47
48 int tid[4] = {};
49 struct_sigevent sev = {
50 .sigev_notify = 0xdefaced,
51 .sigev_signo = 0xfacefeed,
52 .sigev_value.sival_ptr = (unsigned long) 0xdeadbeefbadc0dedULL
53 };
54
55 syscall(__NR_timer_create, CLOCK_REALTIME, &sev, NULL);
56 printf("timer_create(CLOCK_REALTIME, {sigev_value={sival_int=%d, "
57 "sival_ptr=%#lx}, sigev_signo=%u, "
58 "sigev_notify=%#x /* SIGEV_??? */}, NULL) = -1 %s (%m)\n",
59 sev.sigev_value.sival_int,
60 sev.sigev_value.sival_ptr,
61 sev.sigev_signo, sev.sigev_notify,
62 errno2name());
63
64 sev.sigev_notify = SIGEV_NONE;
65 if (syscall(__NR_timer_create, CLOCK_REALTIME, &sev, &tid[0]))
66 perror_msg_and_skip("timer_create CLOCK_REALTIME");
67 printf("timer_create(CLOCK_REALTIME, {sigev_value={sival_int=%d, "
68 "sival_ptr=%#lx}, sigev_signo=%u, sigev_notify=SIGEV_NONE}, "
69 "[%d]) = 0\n",
70 sev.sigev_value.sival_int,
71 sev.sigev_value.sival_ptr,
72 sev.sigev_signo, tid[0]);
73
74 sev.sigev_notify = SIGEV_SIGNAL;
75 sev.sigev_signo = SIGALRM;
76 if (syscall(__NR_timer_create, CLOCK_MONOTONIC, &sev, &tid[1]))
77 perror_msg_and_skip("timer_create CLOCK_MONOTONIC");
78 printf("timer_create(CLOCK_MONOTONIC, {sigev_value={sival_int=%d, "
79 "sival_ptr=%#lx}, sigev_signo=SIGALRM, "
80 "sigev_notify=SIGEV_SIGNAL}, [%d]) = 0\n",
81 sev.sigev_value.sival_int,
82 sev.sigev_value.sival_ptr, tid[1]);
83
84 sev.sigev_notify = SIGEV_THREAD;
85 sev.sigev_un.sigev_thread.function =
86 (unsigned long) 0xdeadbeefbadc0dedULL;
87 sev.sigev_un.sigev_thread.attribute =
88 (unsigned long) 0xcafef00dfacefeedULL;
89 if (syscall(__NR_timer_create, CLOCK_REALTIME, &sev, &tid[2]))
90 perror_msg_and_skip("timer_create CLOCK_REALTIME");
91 printf("timer_create(CLOCK_REALTIME, {sigev_value={sival_int=%d, "
92 "sival_ptr=%#lx}, sigev_signo=SIGALRM, sigev_notify=SIGEV_THREAD"
93 ", sigev_notify_function=%#lx, sigev_notify_attributes=%#lx}"
94 ", [%d]) = 0\n",
95 sev.sigev_value.sival_int,
96 sev.sigev_value.sival_ptr,
97 sev.sigev_un.sigev_thread.function,
98 sev.sigev_un.sigev_thread.attribute,
99 tid[2]);
100
101 #ifndef SIGEV_THREAD_ID
102 # define SIGEV_THREAD_ID 4
103 #endif
104 sev.sigev_notify = SIGEV_THREAD_ID;
105 sev.sigev_un.tid = getpid();
106 if (syscall(__NR_timer_create, CLOCK_MONOTONIC, &sev, &tid[3]))
107 perror_msg_and_skip("timer_create CLOCK_MONOTONIC");
108 printf("timer_create(CLOCK_MONOTONIC, {sigev_value={sival_int=%d, "
109 "sival_ptr=%#lx}, sigev_signo=SIGALRM, "
110 "sigev_notify=SIGEV_THREAD_ID, sigev_notify_thread_id=%d}"
111 ", [%d]) = 0\n",
112 sev.sigev_value.sival_int,
113 sev.sigev_value.sival_ptr,
114 sev.sigev_un.tid,
115 tid[3]);
116
117 puts("+++ exited with 0 +++");
118 return 0;
119 }
120
121 #else
122
123 SKIP_MAIN_UNDEFINED("__NR_timer_create")
124
125 #endif
126