Home | History | Annotate | Download | only in tests-m32
      1 /*
      2  * Copyright (c) 2015-2016 Dmitry V. Levin <ldv (at) altlinux.org>
      3  * Copyright (c) 2015-2017 The strace developers.
      4  * 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 <asm/unistd.h>
     31 
     32 #ifdef __NR_fcntl64
     33 
     34 # define TEST_SYSCALL_NR __NR_fcntl64
     35 # define TEST_SYSCALL_STR "fcntl64"
     36 # include "struct_flock.c"
     37 
     38 # define TEST_FLOCK64_EINVAL(cmd) test_flock64_einval(cmd, #cmd)
     39 
     40 static void
     41 test_flock64_einval(const int cmd, const char *name)
     42 {
     43 	struct_kernel_flock64 fl = {
     44 		.l_type = F_RDLCK,
     45 		.l_start = 0xdefaced1facefeedULL,
     46 		.l_len = 0xdefaced2cafef00dULL
     47 	};
     48 	long rc = invoke_test_syscall(cmd, &fl);
     49 	printf("%s(0, %s, {l_type=F_RDLCK, l_whence=SEEK_SET"
     50 	       ", l_start=%jd, l_len=%jd}) = %s\n", TEST_SYSCALL_STR, name,
     51 	       (intmax_t) fl.l_start, (intmax_t) fl.l_len, sprintrc(rc));
     52 }
     53 
     54 static void
     55 test_flock64(void)
     56 {
     57 	TEST_FLOCK64_EINVAL(F_SETLK64);
     58 	TEST_FLOCK64_EINVAL(F_SETLKW64);
     59 # ifdef F_OFD_SETLK
     60 	TEST_FLOCK64_EINVAL(F_OFD_SETLK);
     61 	TEST_FLOCK64_EINVAL(F_OFD_SETLKW);
     62 # endif
     63 
     64 	struct_kernel_flock64 fl = {
     65 		.l_type = F_RDLCK,
     66 		.l_len = FILE_LEN
     67 	};
     68 	long rc = invoke_test_syscall(F_SETLK64, &fl);
     69 	printf("%s(0, F_SETLK64, {l_type=F_RDLCK, l_whence=SEEK_SET"
     70 	       ", l_start=0, l_len=%d}) = %s\n",
     71 	       TEST_SYSCALL_STR, FILE_LEN, sprintrc(rc));
     72 
     73 	if (rc)
     74 		return;
     75 
     76 	invoke_test_syscall(F_GETLK64, &fl);
     77 	printf("%s(0, F_GETLK64, {l_type=F_UNLCK, l_whence=SEEK_SET"
     78 	       ", l_start=0, l_len=%d, l_pid=0}) = 0\n",
     79 	       TEST_SYSCALL_STR, FILE_LEN);
     80 
     81 	invoke_test_syscall(F_SETLK64, &fl);
     82 	printf("%s(0, F_SETLK64, {l_type=F_UNLCK, l_whence=SEEK_SET"
     83 	       ", l_start=0, l_len=%d}) = 0\n",
     84 	       TEST_SYSCALL_STR, FILE_LEN);
     85 }
     86 
     87 int
     88 main(void)
     89 {
     90 	create_sample();
     91 	test_flock();
     92 	test_flock64();
     93 
     94 	puts("+++ exited with 0 +++");
     95 	return 0;
     96 }
     97 
     98 #else
     99 
    100 SKIP_MAIN_UNDEFINED("__NR_fcntl64")
    101 
    102 #endif
    103