blob: d06f9c21a9e6a4285cb18c69f61fb025fe0b5d92 [file] [log] [blame]
Elliott Hughesd35df492017-02-15 15:19:05 -08001/*
2 * Copyright (c) 2015-2016 Dmitry V. Levin <ldv@altlinux.org>
Elliott Hughes39bac052017-05-25 16:56:11 -07003 * Copyright (c) 2015-2017 The strace developers.
Elliott Hughesd35df492017-02-15 15:19:05 -08004 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * 3. The name of the author may not be used to endorse or promote products
15 * derived from this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29#include "tests.h"
30#include <assert.h>
31#include <stdio.h>
32#include <stdint.h>
33#include <signal.h>
34#include <time.h>
35#include <sys/time.h>
36
37int
38main(void)
39{
40#if defined __x86_64__ && defined __ILP32__
41 /*
42 * x32 is broken from the beginning:
43 * https://lkml.org/lkml/2015/11/30/790
44 */
45 error_msg_and_skip("x32 is broken");
46#else
47 const sigset_t set = {};
48 const struct sigaction act = { .sa_handler = SIG_IGN };
49 const struct itimerval itv = { .it_value.tv_usec = 111111 };
50 struct timespec req = { .tv_nsec = 222222222 }, rem;
51
52 assert(sigaction(SIGALRM, &act, NULL) == 0);
53 assert(sigprocmask(SIG_SETMASK, &set, NULL) == 0);
54 if (setitimer(ITIMER_REAL, &itv, NULL))
55 perror_msg_and_skip("setitimer");
56 if (nanosleep(&req, &rem))
57 perror_msg_and_fail("nanosleep");
58
Elliott Hughes39bac052017-05-25 16:56:11 -070059 printf("nanosleep\\(\\{tv_sec=%lld, tv_nsec=%llu\\}"
60 ", \\{tv_sec=%lld, tv_nsec=%llu\\}\\)"
Elliott Hughesd35df492017-02-15 15:19:05 -080061 " = \\? ERESTART_RESTARTBLOCK \\(Interrupted by signal\\)\n",
Elliott Hughes39bac052017-05-25 16:56:11 -070062 (long long) req.tv_sec, zero_extend_signed_to_ull(req.tv_nsec),
63 (long long) rem.tv_sec, zero_extend_signed_to_ull(rem.tv_nsec));
Elliott Hughesd35df492017-02-15 15:19:05 -080064 puts("--- SIGALRM \\{si_signo=SIGALRM, si_code=SI_KERNEL\\} ---");
65#ifdef __arm__
66/* old kernels used to overwrite ARM_r0 with -EINTR */
67# define ALTERNATIVE_NANOSLEEP_REQ "0xfffffffc|"
68#else
69# define ALTERNATIVE_NANOSLEEP_REQ ""
70#endif
Elliott Hughes39bac052017-05-25 16:56:11 -070071 printf("(nanosleep\\((%s\\{tv_sec=%lld, tv_nsec=%llu\\})"
72 ", %p|restart_syscall\\(<\\.\\.\\."
Elliott Hughesd35df492017-02-15 15:19:05 -080073 " resuming interrupted nanosleep \\.\\.\\.>)\\) = 0\n",
74 ALTERNATIVE_NANOSLEEP_REQ,
Elliott Hughes39bac052017-05-25 16:56:11 -070075 (long long) req.tv_sec, zero_extend_signed_to_ull(req.tv_nsec),
76 &rem);
Elliott Hughesd35df492017-02-15 15:19:05 -080077
78 puts("\\+\\+\\+ exited with 0 \\+\\+\\+");
79 return 0;
80#endif
81}