blob: 5677c1edba4cc841323c1788a51b78cb499cd997 [file] [log] [blame]
Eugene Syromyatnikov0c766332016-09-02 18:28:24 +03001/*
2 * Copyright (c) 2016 Eugene Syromiatnikov <evgsyr@gmail.com>
3 * 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
28#include "tests.h"
29#include <asm/unistd.h>
30
31#ifdef HAVE_READAHEAD
32# ifdef __GLIBC__
33/*
34 * Check for glibc readahead off64_t argument passing bug,
35 * see https://sourceware.org/bugzilla/show_bug.cgi?id=5208
36 */
37# if !(defined __GLIBC_MINOR__ && \
38 (__GLIBC__ << 16) + __GLIBC_MINOR__ >= (2 << 16) + 8)
39# undef HAVE_READAHEAD
40# endif
41# endif /* __GLIBC__ */
42#endif /* HAVE_READAHEAD */
43
44#ifdef HAVE_READAHEAD
45
46# include <fcntl.h>
47# include <stdio.h>
48
49static const int fds[] = {
50 -0x80000000,
51 -100,
52 -1,
53 0,
54 1,
55 2,
56 0x7fffffff,
57};
58
59static const off64_t offsets[] = {
60 -0x8000000000000000LL,
61 -0x5060708090a0b0c0LL,
62 -1LL,
63 0,
64 1,
65 0xbadfaced,
66 0x7fffffffffffffffLL,
67};
68
69static const unsigned long counts[] = {
70 0UL,
71 0xdeadca75,
72 (unsigned long) 0xface1e55beeff00dULL,
73 (unsigned long) 0xffffffffffffffffULL,
74};
75
76int
77main(void)
78{
79 unsigned i;
80 unsigned j;
81 unsigned k;
82 ssize_t rc;
83
84 for (i = 0; i < ARRAY_SIZE(fds); i++)
85 for (j = 0; j < ARRAY_SIZE(offsets); j++)
86 for (k = 0; k < ARRAY_SIZE(counts); k++) {
87 rc = readahead(fds[i], offsets[j], counts[k]);
88
89 printf("readahead(%d, %lld, %lu) = %s\n",
90 fds[i], (long long) offsets[j],
91 counts[k], sprintrc(rc));
92 }
93
94 puts("+++ exited with 0 +++");
95 return 0;
96}
97
98#else
99
100SKIP_MAIN_UNDEFINED("HAVE_READAHEAD")
101
102#endif