Dmitry V. Levin | b8f0c92 | 2015-09-16 16:31:43 +0000 | [diff] [blame] | 1 | /* |
Dmitry V. Levin | 595fc10 | 2016-02-07 23:28:18 +0000 | [diff] [blame^] | 2 | * This file is part of timer_create strace test. |
| 3 | * |
Dmitry V. Levin | 21bbc14 | 2016-01-06 09:49:32 +0000 | [diff] [blame] | 4 | * Copyright (c) 2015-2016 Dmitry V. Levin <ldv@altlinux.org> |
Dmitry V. Levin | b8f0c92 | 2015-09-16 16:31:43 +0000 | [diff] [blame] | 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 | |
Dmitry V. Levin | 0c8853c | 2016-01-02 13:28:43 +0000 | [diff] [blame] | 30 | #include "tests.h" |
Dmitry V. Levin | b8f0c92 | 2015-09-16 16:31:43 +0000 | [diff] [blame] | 31 | #include <sys/syscall.h> |
| 32 | |
| 33 | #ifdef __NR_timer_create |
| 34 | |
Dmitry V. Levin | 21bbc14 | 2016-01-06 09:49:32 +0000 | [diff] [blame] | 35 | # include <stdio.h> |
| 36 | # include <signal.h> |
| 37 | # include <time.h> |
| 38 | # include <unistd.h> |
Dmitry V. Levin | e714b87 | 2016-01-12 01:13:48 +0000 | [diff] [blame] | 39 | # include "sigevent.h" |
Dmitry V. Levin | 21bbc14 | 2016-01-06 09:49:32 +0000 | [diff] [blame] | 40 | |
Dmitry V. Levin | b8f0c92 | 2015-09-16 16:31:43 +0000 | [diff] [blame] | 41 | int |
| 42 | main(void) |
| 43 | { |
Dmitry V. Levin | 595fc10 | 2016-02-07 23:28:18 +0000 | [diff] [blame^] | 44 | syscall(__NR_timer_create, CLOCK_REALTIME, NULL, NULL); |
| 45 | printf("timer_create(CLOCK_REALTIME, NULL, NULL) = -1 EFAULT (%m)\n"); |
| 46 | |
Dmitry V. Levin | b8f0c92 | 2015-09-16 16:31:43 +0000 | [diff] [blame] | 47 | int tid[4] = {}; |
Dmitry V. Levin | e714b87 | 2016-01-12 01:13:48 +0000 | [diff] [blame] | 48 | struct_sigevent sev = { |
Dmitry V. Levin | 595fc10 | 2016-02-07 23:28:18 +0000 | [diff] [blame^] | 49 | .sigev_notify = 0xdefaced, |
Dmitry V. Levin | b8f0c92 | 2015-09-16 16:31:43 +0000 | [diff] [blame] | 50 | .sigev_signo = 0xfacefeed, |
Dmitry V. Levin | e714b87 | 2016-01-12 01:13:48 +0000 | [diff] [blame] | 51 | .sigev_value.sival_ptr = (unsigned long) 0xdeadbeefbadc0ded |
Dmitry V. Levin | b8f0c92 | 2015-09-16 16:31:43 +0000 | [diff] [blame] | 52 | }; |
| 53 | |
Dmitry V. Levin | 595fc10 | 2016-02-07 23:28:18 +0000 | [diff] [blame^] | 54 | syscall(__NR_timer_create, CLOCK_REALTIME, &sev, NULL); |
| 55 | printf("timer_create(CLOCK_REALTIME, {sigev_value={int=%d, ptr=%#lx}" |
| 56 | ", sigev_signo=%u, sigev_notify=%#x /* SIGEV_??? */}" |
| 57 | ", NULL) = -1 EINVAL (%m)\n", |
| 58 | sev.sigev_value.sival_int, |
| 59 | sev.sigev_value.sival_ptr, |
| 60 | sev.sigev_signo, sev.sigev_notify); |
| 61 | |
| 62 | sev.sigev_notify = SIGEV_NONE; |
Dmitry V. Levin | b8f0c92 | 2015-09-16 16:31:43 +0000 | [diff] [blame] | 63 | if (syscall(__NR_timer_create, CLOCK_REALTIME, &sev, &tid[0])) |
Dmitry V. Levin | 21bbc14 | 2016-01-06 09:49:32 +0000 | [diff] [blame] | 64 | perror_msg_and_skip("timer_create CLOCK_REALTIME"); |
Dmitry V. Levin | e714b87 | 2016-01-12 01:13:48 +0000 | [diff] [blame] | 65 | printf("timer_create(CLOCK_REALTIME, {sigev_value={int=%d, ptr=%#lx}" |
Dmitry V. Levin | 595fc10 | 2016-02-07 23:28:18 +0000 | [diff] [blame^] | 66 | ", sigev_signo=%u, sigev_notify=SIGEV_NONE}, [%d]) = 0\n", |
Dmitry V. Levin | b8f0c92 | 2015-09-16 16:31:43 +0000 | [diff] [blame] | 67 | sev.sigev_value.sival_int, |
| 68 | sev.sigev_value.sival_ptr, |
| 69 | sev.sigev_signo, tid[0]); |
| 70 | |
| 71 | sev.sigev_notify = SIGEV_SIGNAL; |
| 72 | sev.sigev_signo = SIGALRM; |
| 73 | if (syscall(__NR_timer_create, CLOCK_MONOTONIC, &sev, &tid[1])) |
Dmitry V. Levin | 21bbc14 | 2016-01-06 09:49:32 +0000 | [diff] [blame] | 74 | perror_msg_and_skip("timer_create CLOCK_MONOTONIC"); |
Dmitry V. Levin | e714b87 | 2016-01-12 01:13:48 +0000 | [diff] [blame] | 75 | printf("timer_create(CLOCK_MONOTONIC, {sigev_value={int=%d, ptr=%#lx}" |
Dmitry V. Levin | b8f0c92 | 2015-09-16 16:31:43 +0000 | [diff] [blame] | 76 | ", sigev_signo=SIGALRM, sigev_notify=SIGEV_SIGNAL}" |
| 77 | ", [%d]) = 0\n", |
| 78 | sev.sigev_value.sival_int, |
| 79 | sev.sigev_value.sival_ptr, tid[1]); |
| 80 | |
| 81 | sev.sigev_notify = SIGEV_THREAD; |
Dmitry V. Levin | e714b87 | 2016-01-12 01:13:48 +0000 | [diff] [blame] | 82 | sev.sigev_un.sigev_thread.function = (unsigned long) 0xdeadbeefbadc0ded; |
| 83 | sev.sigev_un.sigev_thread.attribute = (unsigned long) 0xcafef00dfacefeed; |
Dmitry V. Levin | b8f0c92 | 2015-09-16 16:31:43 +0000 | [diff] [blame] | 84 | if (syscall(__NR_timer_create, CLOCK_REALTIME, &sev, &tid[2])) |
Dmitry V. Levin | 21bbc14 | 2016-01-06 09:49:32 +0000 | [diff] [blame] | 85 | perror_msg_and_skip("timer_create CLOCK_REALTIME"); |
Dmitry V. Levin | e714b87 | 2016-01-12 01:13:48 +0000 | [diff] [blame] | 86 | printf("timer_create(CLOCK_REALTIME, {sigev_value={int=%d, ptr=%#lx}" |
Dmitry V. Levin | b8f0c92 | 2015-09-16 16:31:43 +0000 | [diff] [blame] | 87 | ", sigev_signo=SIGALRM, sigev_notify=SIGEV_THREAD" |
Dmitry V. Levin | e714b87 | 2016-01-12 01:13:48 +0000 | [diff] [blame] | 88 | ", sigev_notify_function=%#lx, sigev_notify_attributes=%#lx}" |
Dmitry V. Levin | b8f0c92 | 2015-09-16 16:31:43 +0000 | [diff] [blame] | 89 | ", [%d]) = 0\n", |
| 90 | sev.sigev_value.sival_int, |
| 91 | sev.sigev_value.sival_ptr, |
Dmitry V. Levin | e714b87 | 2016-01-12 01:13:48 +0000 | [diff] [blame] | 92 | sev.sigev_un.sigev_thread.function, |
| 93 | sev.sigev_un.sigev_thread.attribute, |
Dmitry V. Levin | b8f0c92 | 2015-09-16 16:31:43 +0000 | [diff] [blame] | 94 | tid[2]); |
| 95 | |
Dmitry V. Levin | e714b87 | 2016-01-12 01:13:48 +0000 | [diff] [blame] | 96 | #ifndef SIGEV_THREAD_ID |
| 97 | # define SIGEV_THREAD_ID 4 |
| 98 | #endif |
Dmitry V. Levin | b8f0c92 | 2015-09-16 16:31:43 +0000 | [diff] [blame] | 99 | sev.sigev_notify = SIGEV_THREAD_ID; |
Dmitry V. Levin | e714b87 | 2016-01-12 01:13:48 +0000 | [diff] [blame] | 100 | sev.sigev_un.tid = getpid(); |
Dmitry V. Levin | b8f0c92 | 2015-09-16 16:31:43 +0000 | [diff] [blame] | 101 | if (syscall(__NR_timer_create, CLOCK_MONOTONIC, &sev, &tid[3])) |
Dmitry V. Levin | 21bbc14 | 2016-01-06 09:49:32 +0000 | [diff] [blame] | 102 | perror_msg_and_skip("timer_create CLOCK_MONOTONIC"); |
Dmitry V. Levin | e714b87 | 2016-01-12 01:13:48 +0000 | [diff] [blame] | 103 | printf("timer_create(CLOCK_MONOTONIC, {sigev_value={int=%d, ptr=%#lx}" |
Dmitry V. Levin | b8f0c92 | 2015-09-16 16:31:43 +0000 | [diff] [blame] | 104 | ", sigev_signo=SIGALRM, sigev_notify=SIGEV_THREAD_ID" |
| 105 | ", sigev_notify_thread_id=%d}" |
| 106 | ", [%d]) = 0\n", |
| 107 | sev.sigev_value.sival_int, |
| 108 | sev.sigev_value.sival_ptr, |
Dmitry V. Levin | e714b87 | 2016-01-12 01:13:48 +0000 | [diff] [blame] | 109 | sev.sigev_un.tid, |
Dmitry V. Levin | b8f0c92 | 2015-09-16 16:31:43 +0000 | [diff] [blame] | 110 | tid[3]); |
Dmitry V. Levin | b8f0c92 | 2015-09-16 16:31:43 +0000 | [diff] [blame] | 111 | |
| 112 | puts("+++ exited with 0 +++"); |
| 113 | return 0; |
| 114 | } |
| 115 | |
| 116 | #else |
| 117 | |
Dmitry V. Levin | 21bbc14 | 2016-01-06 09:49:32 +0000 | [diff] [blame] | 118 | SKIP_MAIN_UNDEFINED("__NR_timer_create") |
Dmitry V. Levin | b8f0c92 | 2015-09-16 16:31:43 +0000 | [diff] [blame] | 119 | |
| 120 | #endif |