blob: 380c978d5a9c787a2fa982dc677e88ed851c42fc [file] [log] [blame]
Dmitry V. Levinb8f0c922015-09-16 16:31:43 +00001/*
Dmitry V. Levin21bbc142016-01-06 09:49:32 +00002 * Copyright (c) 2015-2016 Dmitry V. Levin <ldv@altlinux.org>
Dmitry V. Levinb8f0c922015-09-16 16:31:43 +00003 * 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. Levin0c8853c2016-01-02 13:28:43 +000028#include "tests.h"
Dmitry V. Levinb8f0c922015-09-16 16:31:43 +000029#include <sys/syscall.h>
30
31#ifdef __NR_timer_create
32
Dmitry V. Levin21bbc142016-01-06 09:49:32 +000033# include <stdio.h>
34# include <signal.h>
35# include <time.h>
36# include <unistd.h>
Dmitry V. Levine714b872016-01-12 01:13:48 +000037# include "sigevent.h"
Dmitry V. Levin21bbc142016-01-06 09:49:32 +000038
Dmitry V. Levinb8f0c922015-09-16 16:31:43 +000039int
40main(void)
41{
42 int tid[4] = {};
Dmitry V. Levine714b872016-01-12 01:13:48 +000043 struct_sigevent sev = {
Dmitry V. Levinb8f0c922015-09-16 16:31:43 +000044 .sigev_notify = SIGEV_NONE,
45 .sigev_signo = 0xfacefeed,
Dmitry V. Levine714b872016-01-12 01:13:48 +000046 .sigev_value.sival_ptr = (unsigned long) 0xdeadbeefbadc0ded
Dmitry V. Levinb8f0c922015-09-16 16:31:43 +000047 };
48
49 if (syscall(__NR_timer_create, CLOCK_REALTIME, &sev, &tid[0]))
Dmitry V. Levin21bbc142016-01-06 09:49:32 +000050 perror_msg_and_skip("timer_create CLOCK_REALTIME");
Dmitry V. Levine714b872016-01-12 01:13:48 +000051 printf("timer_create(CLOCK_REALTIME, {sigev_value={int=%d, ptr=%#lx}"
Dmitry V. Levinb8f0c922015-09-16 16:31:43 +000052 ", 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. Levin21bbc142016-01-06 09:49:32 +000061 perror_msg_and_skip("timer_create CLOCK_MONOTONIC");
Dmitry V. Levine714b872016-01-12 01:13:48 +000062 printf("timer_create(CLOCK_MONOTONIC, {sigev_value={int=%d, ptr=%#lx}"
Dmitry V. Levinb8f0c922015-09-16 16:31:43 +000063 ", 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. Levine714b872016-01-12 01:13:48 +000069 sev.sigev_un.sigev_thread.function = (unsigned long) 0xdeadbeefbadc0ded;
70 sev.sigev_un.sigev_thread.attribute = (unsigned long) 0xcafef00dfacefeed;
Dmitry V. Levinb8f0c922015-09-16 16:31:43 +000071 if (syscall(__NR_timer_create, CLOCK_REALTIME, &sev, &tid[2]))
Dmitry V. Levin21bbc142016-01-06 09:49:32 +000072 perror_msg_and_skip("timer_create CLOCK_REALTIME");
Dmitry V. Levine714b872016-01-12 01:13:48 +000073 printf("timer_create(CLOCK_REALTIME, {sigev_value={int=%d, ptr=%#lx}"
Dmitry V. Levinb8f0c922015-09-16 16:31:43 +000074 ", sigev_signo=SIGALRM, sigev_notify=SIGEV_THREAD"
Dmitry V. Levine714b872016-01-12 01:13:48 +000075 ", sigev_notify_function=%#lx, sigev_notify_attributes=%#lx}"
Dmitry V. Levinb8f0c922015-09-16 16:31:43 +000076 ", [%d]) = 0\n",
77 sev.sigev_value.sival_int,
78 sev.sigev_value.sival_ptr,
Dmitry V. Levine714b872016-01-12 01:13:48 +000079 sev.sigev_un.sigev_thread.function,
80 sev.sigev_un.sigev_thread.attribute,
Dmitry V. Levinb8f0c922015-09-16 16:31:43 +000081 tid[2]);
82
Dmitry V. Levine714b872016-01-12 01:13:48 +000083#ifndef SIGEV_THREAD_ID
84# define SIGEV_THREAD_ID 4
85#endif
Dmitry V. Levinb8f0c922015-09-16 16:31:43 +000086 sev.sigev_notify = SIGEV_THREAD_ID;
Dmitry V. Levine714b872016-01-12 01:13:48 +000087 sev.sigev_un.tid = getpid();
Dmitry V. Levinb8f0c922015-09-16 16:31:43 +000088 if (syscall(__NR_timer_create, CLOCK_MONOTONIC, &sev, &tid[3]))
Dmitry V. Levin21bbc142016-01-06 09:49:32 +000089 perror_msg_and_skip("timer_create CLOCK_MONOTONIC");
Dmitry V. Levine714b872016-01-12 01:13:48 +000090 printf("timer_create(CLOCK_MONOTONIC, {sigev_value={int=%d, ptr=%#lx}"
Dmitry V. Levinb8f0c922015-09-16 16:31:43 +000091 ", 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. Levine714b872016-01-12 01:13:48 +000096 sev.sigev_un.tid,
Dmitry V. Levinb8f0c922015-09-16 16:31:43 +000097 tid[3]);
Dmitry V. Levinb8f0c922015-09-16 16:31:43 +000098
99 puts("+++ exited with 0 +++");
100 return 0;
101}
102
103#else
104
Dmitry V. Levin21bbc142016-01-06 09:49:32 +0000105SKIP_MAIN_UNDEFINED("__NR_timer_create")
Dmitry V. Levinb8f0c922015-09-16 16:31:43 +0000106
107#endif