]> granicus.if.org Git - strace/blob - tests/readahead.c
strace: terminate itself if interrupted by a signal
[strace] / tests / readahead.c
1 /*
2  * Copyright (c) 2016 Eugene Syromyatnikov <evgsyr@gmail.com>
3  * Copyright (c) 2016-2017 The strace developers.
4  * All rights reserved.
5  *
6  * SPDX-License-Identifier: GPL-2.0-or-later
7  */
8
9 #include "tests.h"
10 #include <asm/unistd.h>
11
12 #ifdef HAVE_READAHEAD
13 /* Check for glibc readahead argument passing bugs. */
14 # ifdef __GLIBC__
15 /*
16  * glibc < 2.8 had an incorrect order of higher and lower parts of offset,
17  * see https://sourceware.org/bugzilla/show_bug.cgi?id=5208
18  */
19 #  if !(defined __GLIBC_MINOR__ && \
20         (__GLIBC__ << 16) + __GLIBC_MINOR__ >= (2 << 16) + 8)
21 #   undef HAVE_READAHEAD
22 #  endif /* glibc < 2.8 */
23 /*
24  * glibc < 2.25 had an incorrect implementation on mips n64,
25  * see https://sourceware.org/bugzilla/show_bug.cgi?id=21026
26  */
27 #  if defined LINUX_MIPSN64 && !(defined __GLIBC_MINOR__ && \
28         (__GLIBC__ << 16) + __GLIBC_MINOR__ >= (2 << 16) + 25)
29 #   undef HAVE_READAHEAD
30 #  endif /* LINUX_MIPSN64 && glibc < 2.25 */
31 # endif /* __GLIBC__ */
32 #endif /* HAVE_READAHEAD */
33
34 #ifdef HAVE_READAHEAD
35
36 # include <fcntl.h>
37 # include <stdio.h>
38
39 static const int fds[] = {
40         -0x80000000,
41         -100,
42         -1,
43         0,
44         1,
45         2,
46         0x7fffffff,
47 };
48
49 static const off64_t offsets[] = {
50         -0x8000000000000000LL,
51         -0x5060708090a0b0c0LL,
52         -1LL,
53          0,
54          1,
55          0xbadfaced,
56          0x7fffffffffffffffLL,
57 };
58
59 static const unsigned long counts[] = {
60         0UL,
61         0xdeadca75,
62         (unsigned long) 0xface1e55beeff00dULL,
63         (unsigned long) 0xffffffffffffffffULL,
64 };
65
66 int
67 main(void)
68 {
69         unsigned i;
70         unsigned j;
71         unsigned k;
72         ssize_t rc;
73
74         for (i = 0; i < ARRAY_SIZE(fds); i++)
75                 for (j = 0; j < ARRAY_SIZE(offsets); j++)
76                         for (k = 0; k < ARRAY_SIZE(counts); k++) {
77                                 rc = readahead(fds[i], offsets[j], counts[k]);
78
79                                 printf("readahead(%d, %lld, %lu) = %s\n",
80                                         fds[i], (long long) offsets[j],
81                                         counts[k], sprintrc(rc));
82                         }
83
84         puts("+++ exited with 0 +++");
85         return 0;
86 }
87
88 #else
89
90 SKIP_MAIN_UNDEFINED("HAVE_READAHEAD")
91
92 #endif