]> granicus.if.org Git - strace/blob - tests/timer_create.c
f13b7b040f9ec87354c69d6aaf743ad3ee65207a
[strace] / tests / timer_create.c
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
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={int=%d, ptr=%#lx}"
57                ", sigev_signo=%u, sigev_notify=%#x /* SIGEV_??? */}"
58                ", 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={int=%d, ptr=%#lx}"
68                ", sigev_signo=%u, sigev_notify=SIGEV_NONE}, [%d]) = 0\n",
69                sev.sigev_value.sival_int,
70                sev.sigev_value.sival_ptr,
71                sev.sigev_signo, tid[0]);
72
73         sev.sigev_notify = SIGEV_SIGNAL;
74         sev.sigev_signo = SIGALRM;
75         if (syscall(__NR_timer_create, CLOCK_MONOTONIC, &sev, &tid[1]))
76                 perror_msg_and_skip("timer_create CLOCK_MONOTONIC");
77         printf("timer_create(CLOCK_MONOTONIC, {sigev_value={int=%d, ptr=%#lx}"
78                ", sigev_signo=SIGALRM, sigev_notify=SIGEV_SIGNAL}"
79                ", [%d]) = 0\n",
80                sev.sigev_value.sival_int,
81                sev.sigev_value.sival_ptr, tid[1]);
82
83         sev.sigev_notify = SIGEV_THREAD;
84         sev.sigev_un.sigev_thread.function =
85                 (unsigned long) 0xdeadbeefbadc0dedULL;
86         sev.sigev_un.sigev_thread.attribute =
87                 (unsigned long) 0xcafef00dfacefeedULL;
88         if (syscall(__NR_timer_create, CLOCK_REALTIME, &sev, &tid[2]))
89                 perror_msg_and_skip("timer_create CLOCK_REALTIME");
90         printf("timer_create(CLOCK_REALTIME, {sigev_value={int=%d, ptr=%#lx}"
91                ", sigev_signo=SIGALRM, sigev_notify=SIGEV_THREAD"
92                ", sigev_notify_function=%#lx, sigev_notify_attributes=%#lx}"
93                ", [%d]) = 0\n",
94                sev.sigev_value.sival_int,
95                sev.sigev_value.sival_ptr,
96                sev.sigev_un.sigev_thread.function,
97                sev.sigev_un.sigev_thread.attribute,
98                tid[2]);
99
100 #ifndef SIGEV_THREAD_ID
101 # define SIGEV_THREAD_ID 4
102 #endif
103         sev.sigev_notify = SIGEV_THREAD_ID;
104         sev.sigev_un.tid = getpid();
105         if (syscall(__NR_timer_create, CLOCK_MONOTONIC, &sev, &tid[3]))
106                 perror_msg_and_skip("timer_create CLOCK_MONOTONIC");
107         printf("timer_create(CLOCK_MONOTONIC, {sigev_value={int=%d, ptr=%#lx}"
108                ", sigev_signo=SIGALRM, sigev_notify=SIGEV_THREAD_ID"
109                ", sigev_notify_thread_id=%d}"
110                ", [%d]) = 0\n",
111                sev.sigev_value.sival_int,
112                sev.sigev_value.sival_ptr,
113                sev.sigev_un.tid,
114                tid[3]);
115
116         puts("+++ exited with 0 +++");
117         return 0;
118 }
119
120 #else
121
122 SKIP_MAIN_UNDEFINED("__NR_timer_create")
123
124 #endif