• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * This file is part of timer_xettime strace test.
3  *
4  * Copyright (c) 2015-2016 Dmitry V. Levin <ldv@altlinux.org>
5  * Copyright (c) 2015-2017 The strace developers.
6  * All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  * 1. Redistributions of source code must retain the above copyright
12  *    notice, this list of conditions and the following disclaimer.
13  * 2. Redistributions in binary form must reproduce the above copyright
14  *    notice, this list of conditions and the following disclaimer in the
15  *    documentation and/or other materials provided with the distribution.
16  * 3. The name of the author may not be used to endorse or promote products
17  *    derived from this software without specific prior written permission.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
20  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
21  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
22  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
23  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
24  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
28  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29  */
30 
31 #include "tests.h"
32 #include <asm/unistd.h>
33 
34 #if defined __NR_timer_create \
35  && defined __NR_timer_gettime \
36  && defined __NR_timer_settime
37 
38 # include <stdio.h>
39 # include <stdint.h>
40 # include <signal.h>
41 # include <time.h>
42 # include <unistd.h>
43 
44 int
main(void)45 main(void)
46 {
47 	syscall(__NR_timer_settime, 0xdefaced, TIMER_ABSTIME, NULL, NULL);
48 	printf("timer_settime(%d, TIMER_ABSTIME, NULL, NULL)"
49 	       " = -1 EINVAL (%m)\n", 0xdefaced);
50 
51 	long rc;
52 	int tid;
53 	struct sigevent sev = { .sigev_notify = SIGEV_NONE };
54 
55 	if (syscall(__NR_timer_create, CLOCK_MONOTONIC, &sev, &tid))
56 		perror_msg_and_skip("timer_create");
57 	printf("timer_create(CLOCK_MONOTONIC, {sigev_signo=0"
58 	       ", sigev_notify=SIGEV_NONE}, [%d]) = 0\n", tid);
59 
60 	TAIL_ALLOC_OBJECT_CONST_PTR(struct itimerspec, its_new);
61 	TAIL_ALLOC_OBJECT_CONST_PTR(struct itimerspec, its_old);
62 
63 	its_new->it_interval.tv_sec = 0xdeadbeefU;
64 	its_new->it_interval.tv_nsec = 0xfacefeedU;
65 	its_new->it_value.tv_sec = (time_t) 0xcafef00ddeadbeefLL;
66 	its_new->it_value.tv_nsec = (long) 0xbadc0dedfacefeedLL;
67 
68 	rc = syscall(__NR_timer_settime, tid, 0, its_new, its_old);
69 	printf("timer_settime(%d, 0"
70 	       ", {it_interval={tv_sec=%lld, tv_nsec=%llu}"
71 	       ", it_value={tv_sec=%lld, tv_nsec=%llu}}, %p) = %s\n",
72 	       tid, (long long) its_new->it_interval.tv_sec,
73 	       zero_extend_signed_to_ull(its_new->it_interval.tv_nsec),
74 	       (long long) its_new->it_value.tv_sec,
75 	       zero_extend_signed_to_ull(its_new->it_value.tv_nsec),
76 	       its_old, sprintrc(rc));
77 
78 	its_new->it_interval.tv_sec = 0xdeface1;
79 	its_new->it_interval.tv_nsec = 0xdeface2;
80 	its_new->it_value.tv_sec = 0xdeface3;
81 	its_new->it_value.tv_nsec = 0xdeface4;
82 	its_old->it_interval.tv_sec = 0xdeface5;
83 	its_old->it_interval.tv_nsec = 0xdeface6;
84 	its_old->it_value.tv_sec = 0xdeface7;
85 	its_old->it_value.tv_nsec = 0xdeface8;
86 
87 	if (syscall(__NR_timer_settime, tid, 0, its_new, its_old))
88 		perror_msg_and_skip("timer_settime");
89 	printf("timer_settime(%d, 0"
90 	       ", {it_interval={tv_sec=%lld, tv_nsec=%llu}"
91 	       ", it_value={tv_sec=%lld, tv_nsec=%llu}}"
92 	       ", {it_interval={tv_sec=%lld, tv_nsec=%llu}"
93 	       ", it_value={tv_sec=%lld, tv_nsec=%llu}}"
94 	       ") = 0\n",
95 	       tid,
96 	       (long long) its_new->it_interval.tv_sec,
97 	       zero_extend_signed_to_ull(its_new->it_interval.tv_nsec),
98 	       (long long) its_new->it_value.tv_sec,
99 	       zero_extend_signed_to_ull(its_new->it_value.tv_nsec),
100 	       (long long) its_old->it_interval.tv_sec,
101 	       zero_extend_signed_to_ull(its_old->it_interval.tv_nsec),
102 	       (long long) its_old->it_value.tv_sec,
103 	       zero_extend_signed_to_ull(its_old->it_value.tv_nsec));
104 
105 	if (syscall(__NR_timer_gettime, tid, its_old))
106 		perror_msg_and_skip("timer_gettime");
107 	printf("timer_gettime(%d"
108 	       ", {it_interval={tv_sec=%lld, tv_nsec=%llu}"
109 	       ", it_value={tv_sec=%lld, tv_nsec=%llu}}) = 0\n",
110 	       tid,
111 	       (long long) its_old->it_interval.tv_sec,
112 	       zero_extend_signed_to_ull(its_old->it_interval.tv_nsec),
113 	       (long long) its_old->it_value.tv_sec,
114 	       zero_extend_signed_to_ull(its_old->it_value.tv_nsec));
115 
116 	puts("+++ exited with 0 +++");
117 	return 0;
118 }
119 
120 #else
121 
122 SKIP_MAIN_UNDEFINED("__NR_timer_create && __NR_timer_gettime && __NR_timer_settime")
123 
124 #endif
125