blob: 8f7d5cd88eae85743a3f03538d7e7a393948b242 [file] [log] [blame]
Dmitry V. Levinb8f0c922015-09-16 16:31:43 +00001/*
Dmitry V. Levin595fc102016-02-07 23:28:18 +00002 * This file is part of timer_create strace test.
3 *
Dmitry V. Levin21bbc142016-01-06 09:49:32 +00004 * Copyright (c) 2015-2016 Dmitry V. Levin <ldv@altlinux.org>
Dmitry V. Levinb8f0c922015-09-16 16:31:43 +00005 * 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. Levin0c8853c2016-01-02 13:28:43 +000030#include "tests.h"
Dmitry V. Levinb8f0c922015-09-16 16:31:43 +000031#include <sys/syscall.h>
32
33#ifdef __NR_timer_create
34
Dmitry V. Levin21bbc142016-01-06 09:49:32 +000035# include <stdio.h>
36# include <signal.h>
37# include <time.h>
38# include <unistd.h>
Dmitry V. Levine714b872016-01-12 01:13:48 +000039# include "sigevent.h"
Dmitry V. Levin21bbc142016-01-06 09:49:32 +000040
Dmitry V. Levinb8f0c922015-09-16 16:31:43 +000041int
42main(void)
43{
Dmitry V. Levin595fc102016-02-07 23:28:18 +000044 syscall(__NR_timer_create, CLOCK_REALTIME, NULL, NULL);
45 printf("timer_create(CLOCK_REALTIME, NULL, NULL) = -1 EFAULT (%m)\n");
46
Dmitry V. Levinb8f0c922015-09-16 16:31:43 +000047 int tid[4] = {};
Dmitry V. Levine714b872016-01-12 01:13:48 +000048 struct_sigevent sev = {
Dmitry V. Levin595fc102016-02-07 23:28:18 +000049 .sigev_notify = 0xdefaced,
Dmitry V. Levinb8f0c922015-09-16 16:31:43 +000050 .sigev_signo = 0xfacefeed,
Dmitry V. Levine714b872016-01-12 01:13:48 +000051 .sigev_value.sival_ptr = (unsigned long) 0xdeadbeefbadc0ded
Dmitry V. Levinb8f0c922015-09-16 16:31:43 +000052 };
53
Dmitry V. Levin595fc102016-02-07 23:28:18 +000054 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. Levinb8f0c922015-09-16 16:31:43 +000063 if (syscall(__NR_timer_create, CLOCK_REALTIME, &sev, &tid[0]))
Dmitry V. Levin21bbc142016-01-06 09:49:32 +000064 perror_msg_and_skip("timer_create CLOCK_REALTIME");
Dmitry V. Levine714b872016-01-12 01:13:48 +000065 printf("timer_create(CLOCK_REALTIME, {sigev_value={int=%d, ptr=%#lx}"
Dmitry V. Levin595fc102016-02-07 23:28:18 +000066 ", sigev_signo=%u, sigev_notify=SIGEV_NONE}, [%d]) = 0\n",
Dmitry V. Levinb8f0c922015-09-16 16:31:43 +000067 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. Levin21bbc142016-01-06 09:49:32 +000074 perror_msg_and_skip("timer_create CLOCK_MONOTONIC");
Dmitry V. Levine714b872016-01-12 01:13:48 +000075 printf("timer_create(CLOCK_MONOTONIC, {sigev_value={int=%d, ptr=%#lx}"
Dmitry V. Levinb8f0c922015-09-16 16:31:43 +000076 ", 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. Levine714b872016-01-12 01:13:48 +000082 sev.sigev_un.sigev_thread.function = (unsigned long) 0xdeadbeefbadc0ded;
83 sev.sigev_un.sigev_thread.attribute = (unsigned long) 0xcafef00dfacefeed;
Dmitry V. Levinb8f0c922015-09-16 16:31:43 +000084 if (syscall(__NR_timer_create, CLOCK_REALTIME, &sev, &tid[2]))
Dmitry V. Levin21bbc142016-01-06 09:49:32 +000085 perror_msg_and_skip("timer_create CLOCK_REALTIME");
Dmitry V. Levine714b872016-01-12 01:13:48 +000086 printf("timer_create(CLOCK_REALTIME, {sigev_value={int=%d, ptr=%#lx}"
Dmitry V. Levinb8f0c922015-09-16 16:31:43 +000087 ", sigev_signo=SIGALRM, sigev_notify=SIGEV_THREAD"
Dmitry V. Levine714b872016-01-12 01:13:48 +000088 ", sigev_notify_function=%#lx, sigev_notify_attributes=%#lx}"
Dmitry V. Levinb8f0c922015-09-16 16:31:43 +000089 ", [%d]) = 0\n",
90 sev.sigev_value.sival_int,
91 sev.sigev_value.sival_ptr,
Dmitry V. Levine714b872016-01-12 01:13:48 +000092 sev.sigev_un.sigev_thread.function,
93 sev.sigev_un.sigev_thread.attribute,
Dmitry V. Levinb8f0c922015-09-16 16:31:43 +000094 tid[2]);
95
Dmitry V. Levine714b872016-01-12 01:13:48 +000096#ifndef SIGEV_THREAD_ID
97# define SIGEV_THREAD_ID 4
98#endif
Dmitry V. Levinb8f0c922015-09-16 16:31:43 +000099 sev.sigev_notify = SIGEV_THREAD_ID;
Dmitry V. Levine714b872016-01-12 01:13:48 +0000100 sev.sigev_un.tid = getpid();
Dmitry V. Levinb8f0c922015-09-16 16:31:43 +0000101 if (syscall(__NR_timer_create, CLOCK_MONOTONIC, &sev, &tid[3]))
Dmitry V. Levin21bbc142016-01-06 09:49:32 +0000102 perror_msg_and_skip("timer_create CLOCK_MONOTONIC");
Dmitry V. Levine714b872016-01-12 01:13:48 +0000103 printf("timer_create(CLOCK_MONOTONIC, {sigev_value={int=%d, ptr=%#lx}"
Dmitry V. Levinb8f0c922015-09-16 16:31:43 +0000104 ", 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. Levine714b872016-01-12 01:13:48 +0000109 sev.sigev_un.tid,
Dmitry V. Levinb8f0c922015-09-16 16:31:43 +0000110 tid[3]);
Dmitry V. Levinb8f0c922015-09-16 16:31:43 +0000111
112 puts("+++ exited with 0 +++");
113 return 0;
114}
115
116#else
117
Dmitry V. Levin21bbc142016-01-06 09:49:32 +0000118SKIP_MAIN_UNDEFINED("__NR_timer_create")
Dmitry V. Levinb8f0c922015-09-16 16:31:43 +0000119
120#endif