Dmitry V. Levin | b8f0c92 | 2015-09-16 16:31:43 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2015 Dmitry V. Levin <ldv@altlinux.org> |
| 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 <stdio.h> |
| 30 | #include <signal.h> |
| 31 | #include <time.h> |
| 32 | #include <unistd.h> |
| 33 | #include <sys/syscall.h> |
| 34 | |
| 35 | #ifdef __NR_timer_create |
| 36 | |
| 37 | int |
| 38 | main(void) |
| 39 | { |
| 40 | int tid[4] = {}; |
| 41 | struct sigevent sev = { |
| 42 | .sigev_notify = SIGEV_NONE, |
| 43 | .sigev_signo = 0xfacefeed, |
| 44 | .sigev_value.sival_ptr = |
| 45 | (void *) (unsigned long) 0xdeadbeefbadc0ded |
| 46 | }; |
| 47 | |
| 48 | if (syscall(__NR_timer_create, CLOCK_REALTIME, &sev, &tid[0])) |
| 49 | return 77; |
| 50 | printf("timer_create(CLOCK_REALTIME, {sigev_value={int=%d, ptr=%p}" |
| 51 | ", sigev_signo=%u, sigev_notify=SIGEV_NONE}" |
| 52 | ", [%d]) = 0\n", |
| 53 | sev.sigev_value.sival_int, |
| 54 | sev.sigev_value.sival_ptr, |
| 55 | sev.sigev_signo, tid[0]); |
| 56 | |
| 57 | sev.sigev_notify = SIGEV_SIGNAL; |
| 58 | sev.sigev_signo = SIGALRM; |
| 59 | if (syscall(__NR_timer_create, CLOCK_MONOTONIC, &sev, &tid[1])) |
| 60 | return 77; |
| 61 | printf("timer_create(CLOCK_MONOTONIC, {sigev_value={int=%d, ptr=%p}" |
| 62 | ", sigev_signo=SIGALRM, sigev_notify=SIGEV_SIGNAL}" |
| 63 | ", [%d]) = 0\n", |
| 64 | sev.sigev_value.sival_int, |
| 65 | sev.sigev_value.sival_ptr, tid[1]); |
| 66 | |
| 67 | sev.sigev_notify = SIGEV_THREAD; |
| 68 | sev.sigev_notify_function = |
| 69 | (void *) (unsigned long) 0xdeadbeefbadc0ded; |
| 70 | sev.sigev_notify_attributes = |
| 71 | (void *) (unsigned long) 0xcafef00dfacefeed; |
| 72 | if (syscall(__NR_timer_create, CLOCK_REALTIME, &sev, &tid[2])) |
| 73 | return 77; |
| 74 | printf("timer_create(CLOCK_REALTIME, {sigev_value={int=%d, ptr=%p}" |
| 75 | ", sigev_signo=SIGALRM, sigev_notify=SIGEV_THREAD" |
| 76 | ", sigev_notify_function=%p, sigev_notify_attributes=%p}" |
| 77 | ", [%d]) = 0\n", |
| 78 | sev.sigev_value.sival_int, |
| 79 | sev.sigev_value.sival_ptr, |
| 80 | sev.sigev_notify_function, |
| 81 | sev.sigev_notify_attributes, |
| 82 | tid[2]); |
| 83 | |
| 84 | #ifndef sigev_notify_thread_id |
| 85 | # if defined HAVE_STRUCT_SIGEVENT__SIGEV_UN__PAD |
| 86 | # define sigev_notify_thread_id _sigev_un._pad[0] |
| 87 | # elif defined HAVE_STRUCT_SIGEVENT___PAD |
| 88 | # define sigev_notify_thread_id __pad[0] |
| 89 | # endif |
| 90 | #endif /* !sigev_notify_thread_id */ |
| 91 | |
| 92 | #ifdef sigev_notify_thread_id |
| 93 | # ifndef SIGEV_THREAD_ID |
| 94 | # define SIGEV_THREAD_ID 4 |
| 95 | # endif |
| 96 | sev.sigev_notify = SIGEV_THREAD_ID; |
| 97 | sev.sigev_notify_thread_id = getpid(); |
| 98 | if (syscall(__NR_timer_create, CLOCK_MONOTONIC, &sev, &tid[3])) |
| 99 | return 77; |
| 100 | printf("timer_create(CLOCK_MONOTONIC, {sigev_value={int=%d, ptr=%p}" |
| 101 | ", sigev_signo=SIGALRM, sigev_notify=SIGEV_THREAD_ID" |
| 102 | ", sigev_notify_thread_id=%d}" |
| 103 | ", [%d]) = 0\n", |
| 104 | sev.sigev_value.sival_int, |
| 105 | sev.sigev_value.sival_ptr, |
| 106 | sev.sigev_notify_thread_id, |
| 107 | tid[3]); |
| 108 | #endif /* sigev_notify_thread_id */ |
| 109 | |
| 110 | puts("+++ exited with 0 +++"); |
| 111 | return 0; |
| 112 | } |
| 113 | |
| 114 | #else |
| 115 | |
| 116 | int |
| 117 | main(void) |
| 118 | { |
| 119 | return 77; |
| 120 | } |
| 121 | |
| 122 | #endif |