Dmitry V. Levin | b8f0c92 | 2015-09-16 16:31:43 +0000 | [diff] [blame] | 1 | /* |
Dmitry V. Levin | 21bbc14 | 2016-01-06 09:49:32 +0000 | [diff] [blame] | 2 | * Copyright (c) 2015-2016 Dmitry V. Levin <ldv@altlinux.org> |
Dmitry V. Levin | b8f0c92 | 2015-09-16 16:31:43 +0000 | [diff] [blame] | 3 | * 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. Levin | 0c8853c | 2016-01-02 13:28:43 +0000 | [diff] [blame] | 28 | #include "tests.h" |
Dmitry V. Levin | b8f0c92 | 2015-09-16 16:31:43 +0000 | [diff] [blame] | 29 | #include <sys/syscall.h> |
| 30 | |
| 31 | #ifdef __NR_timer_create |
| 32 | |
Dmitry V. Levin | 21bbc14 | 2016-01-06 09:49:32 +0000 | [diff] [blame] | 33 | # include <stdio.h> |
| 34 | # include <signal.h> |
| 35 | # include <time.h> |
| 36 | # include <unistd.h> |
Dmitry V. Levin | e714b87 | 2016-01-12 01:13:48 +0000 | [diff] [blame^] | 37 | # include "sigevent.h" |
Dmitry V. Levin | 21bbc14 | 2016-01-06 09:49:32 +0000 | [diff] [blame] | 38 | |
Dmitry V. Levin | b8f0c92 | 2015-09-16 16:31:43 +0000 | [diff] [blame] | 39 | int |
| 40 | main(void) |
| 41 | { |
| 42 | int tid[4] = {}; |
Dmitry V. Levin | e714b87 | 2016-01-12 01:13:48 +0000 | [diff] [blame^] | 43 | struct_sigevent sev = { |
Dmitry V. Levin | b8f0c92 | 2015-09-16 16:31:43 +0000 | [diff] [blame] | 44 | .sigev_notify = SIGEV_NONE, |
| 45 | .sigev_signo = 0xfacefeed, |
Dmitry V. Levin | e714b87 | 2016-01-12 01:13:48 +0000 | [diff] [blame^] | 46 | .sigev_value.sival_ptr = (unsigned long) 0xdeadbeefbadc0ded |
Dmitry V. Levin | b8f0c92 | 2015-09-16 16:31:43 +0000 | [diff] [blame] | 47 | }; |
| 48 | |
| 49 | if (syscall(__NR_timer_create, CLOCK_REALTIME, &sev, &tid[0])) |
Dmitry V. Levin | 21bbc14 | 2016-01-06 09:49:32 +0000 | [diff] [blame] | 50 | perror_msg_and_skip("timer_create CLOCK_REALTIME"); |
Dmitry V. Levin | e714b87 | 2016-01-12 01:13:48 +0000 | [diff] [blame^] | 51 | printf("timer_create(CLOCK_REALTIME, {sigev_value={int=%d, ptr=%#lx}" |
Dmitry V. Levin | b8f0c92 | 2015-09-16 16:31:43 +0000 | [diff] [blame] | 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. Levin | 21bbc14 | 2016-01-06 09:49:32 +0000 | [diff] [blame] | 61 | perror_msg_and_skip("timer_create CLOCK_MONOTONIC"); |
Dmitry V. Levin | e714b87 | 2016-01-12 01:13:48 +0000 | [diff] [blame^] | 62 | printf("timer_create(CLOCK_MONOTONIC, {sigev_value={int=%d, ptr=%#lx}" |
Dmitry V. Levin | b8f0c92 | 2015-09-16 16:31:43 +0000 | [diff] [blame] | 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; |
Dmitry V. Levin | e714b87 | 2016-01-12 01:13:48 +0000 | [diff] [blame^] | 69 | sev.sigev_un.sigev_thread.function = (unsigned long) 0xdeadbeefbadc0ded; |
| 70 | sev.sigev_un.sigev_thread.attribute = (unsigned long) 0xcafef00dfacefeed; |
Dmitry V. Levin | b8f0c92 | 2015-09-16 16:31:43 +0000 | [diff] [blame] | 71 | if (syscall(__NR_timer_create, CLOCK_REALTIME, &sev, &tid[2])) |
Dmitry V. Levin | 21bbc14 | 2016-01-06 09:49:32 +0000 | [diff] [blame] | 72 | perror_msg_and_skip("timer_create CLOCK_REALTIME"); |
Dmitry V. Levin | e714b87 | 2016-01-12 01:13:48 +0000 | [diff] [blame^] | 73 | printf("timer_create(CLOCK_REALTIME, {sigev_value={int=%d, ptr=%#lx}" |
Dmitry V. Levin | b8f0c92 | 2015-09-16 16:31:43 +0000 | [diff] [blame] | 74 | ", sigev_signo=SIGALRM, sigev_notify=SIGEV_THREAD" |
Dmitry V. Levin | e714b87 | 2016-01-12 01:13:48 +0000 | [diff] [blame^] | 75 | ", sigev_notify_function=%#lx, sigev_notify_attributes=%#lx}" |
Dmitry V. Levin | b8f0c92 | 2015-09-16 16:31:43 +0000 | [diff] [blame] | 76 | ", [%d]) = 0\n", |
| 77 | sev.sigev_value.sival_int, |
| 78 | sev.sigev_value.sival_ptr, |
Dmitry V. Levin | e714b87 | 2016-01-12 01:13:48 +0000 | [diff] [blame^] | 79 | sev.sigev_un.sigev_thread.function, |
| 80 | sev.sigev_un.sigev_thread.attribute, |
Dmitry V. Levin | b8f0c92 | 2015-09-16 16:31:43 +0000 | [diff] [blame] | 81 | tid[2]); |
| 82 | |
Dmitry V. Levin | e714b87 | 2016-01-12 01:13:48 +0000 | [diff] [blame^] | 83 | #ifndef SIGEV_THREAD_ID |
| 84 | # define SIGEV_THREAD_ID 4 |
| 85 | #endif |
Dmitry V. Levin | b8f0c92 | 2015-09-16 16:31:43 +0000 | [diff] [blame] | 86 | sev.sigev_notify = SIGEV_THREAD_ID; |
Dmitry V. Levin | e714b87 | 2016-01-12 01:13:48 +0000 | [diff] [blame^] | 87 | sev.sigev_un.tid = getpid(); |
Dmitry V. Levin | b8f0c92 | 2015-09-16 16:31:43 +0000 | [diff] [blame] | 88 | if (syscall(__NR_timer_create, CLOCK_MONOTONIC, &sev, &tid[3])) |
Dmitry V. Levin | 21bbc14 | 2016-01-06 09:49:32 +0000 | [diff] [blame] | 89 | perror_msg_and_skip("timer_create CLOCK_MONOTONIC"); |
Dmitry V. Levin | e714b87 | 2016-01-12 01:13:48 +0000 | [diff] [blame^] | 90 | printf("timer_create(CLOCK_MONOTONIC, {sigev_value={int=%d, ptr=%#lx}" |
Dmitry V. Levin | b8f0c92 | 2015-09-16 16:31:43 +0000 | [diff] [blame] | 91 | ", sigev_signo=SIGALRM, sigev_notify=SIGEV_THREAD_ID" |
| 92 | ", sigev_notify_thread_id=%d}" |
| 93 | ", [%d]) = 0\n", |
| 94 | sev.sigev_value.sival_int, |
| 95 | sev.sigev_value.sival_ptr, |
Dmitry V. Levin | e714b87 | 2016-01-12 01:13:48 +0000 | [diff] [blame^] | 96 | sev.sigev_un.tid, |
Dmitry V. Levin | b8f0c92 | 2015-09-16 16:31:43 +0000 | [diff] [blame] | 97 | tid[3]); |
Dmitry V. Levin | b8f0c92 | 2015-09-16 16:31:43 +0000 | [diff] [blame] | 98 | |
| 99 | puts("+++ exited with 0 +++"); |
| 100 | return 0; |
| 101 | } |
| 102 | |
| 103 | #else |
| 104 | |
Dmitry V. Levin | 21bbc14 | 2016-01-06 09:49:32 +0000 | [diff] [blame] | 105 | SKIP_MAIN_UNDEFINED("__NR_timer_create") |
Dmitry V. Levin | b8f0c92 | 2015-09-16 16:31:43 +0000 | [diff] [blame] | 106 | |
| 107 | #endif |