Home | History | Annotate | Download | only in tests-mx32
      1 /*
      2  * Copyright (c) 2016 Eugene Syromyatnikov <evgsyr (at) 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 /* Check for glibc readahead argument passing bugs. */
     33 # ifdef __GLIBC__
     34 /*
     35  * glibc < 2.8 had an incorrect order of higher and lower parts of offset,
     36  * see https://sourceware.org/bugzilla/show_bug.cgi?id=5208
     37  */
     38 #  if !(defined __GLIBC_MINOR__ && \
     39         (__GLIBC__ << 16) + __GLIBC_MINOR__ >= (2 << 16) + 8)
     40 #   undef HAVE_READAHEAD
     41 #  endif /* glibc < 2.8 */
     42 /*
     43  * glibc < 2.25 had an incorrect implementation on mips n64,
     44  * see https://sourceware.org/bugzilla/show_bug.cgi?id=21026
     45  */
     46 #  if defined LINUX_MIPSN64 && !(defined __GLIBC_MINOR__ && \
     47         (__GLIBC__ << 16) + __GLIBC_MINOR__ >= (2 << 16) + 25)
     48 #   undef HAVE_READAHEAD
     49 #  endif /* LINUX_MIPSN64 && glibc < 2.25 */
     50 # endif /* __GLIBC__ */
     51 #endif /* HAVE_READAHEAD */
     52 
     53 #ifdef HAVE_READAHEAD
     54 
     55 # include <fcntl.h>
     56 # include <stdio.h>
     57 
     58 static const int fds[] = {
     59 	-0x80000000,
     60 	-100,
     61 	-1,
     62 	0,
     63 	1,
     64 	2,
     65 	0x7fffffff,
     66 };
     67 
     68 static const off64_t offsets[] = {
     69 	-0x8000000000000000LL,
     70 	-0x5060708090a0b0c0LL,
     71 	-1LL,
     72 	 0,
     73 	 1,
     74 	 0xbadfaced,
     75 	 0x7fffffffffffffffLL,
     76 };
     77 
     78 static const unsigned long counts[] = {
     79 	0UL,
     80 	0xdeadca75,
     81 	(unsigned long) 0xface1e55beeff00dULL,
     82 	(unsigned long) 0xffffffffffffffffULL,
     83 };
     84 
     85 int
     86 main(void)
     87 {
     88 	unsigned i;
     89 	unsigned j;
     90 	unsigned k;
     91 	ssize_t rc;
     92 
     93 	for (i = 0; i < ARRAY_SIZE(fds); i++)
     94 		for (j = 0; j < ARRAY_SIZE(offsets); j++)
     95 			for (k = 0; k < ARRAY_SIZE(counts); k++) {
     96 				rc = readahead(fds[i], offsets[j], counts[k]);
     97 
     98 				printf("readahead(%d, %lld, %lu) = %s\n",
     99 					fds[i], (long long) offsets[j],
    100 					counts[k], sprintrc(rc));
    101 			}
    102 
    103 	puts("+++ exited with 0 +++");
    104 	return 0;
    105 }
    106 
    107 #else
    108 
    109 SKIP_MAIN_UNDEFINED("HAVE_READAHEAD")
    110 
    111 #endif
    112