* tests/ioctl_loop.c: New file. * tests/ioctl_loop-v.c: Likewise. * tests/ioctl_loop.test: New test. * tests/ioctl_loop-v.test: Likewise. * tests/.gitignore: Add ioctl_loop and ioctl_loop-v. * tests/Makefile.am (check_PROGRAMS): Likewise. (DECODER_TESTS): Add ioctl_loop.test and ioctl_loop-v.test. --- tests/.gitignore | 2 + tests/Makefile.am | 4 ++ tests/ioctl_loop-v.c | 2 + tests/ioctl_loop-v.test | 12 ++++ tests/ioctl_loop.c | 184 ++++++++++++++++++++++++++++++++++++++++++++++++ tests/ioctl_loop.test | 12 ++++ 6 files changed, 216 insertions(+) create mode 100644 tests/ioctl_loop-v.c create mode 100755 tests/ioctl_loop-v.test create mode 100644 tests/ioctl_loop.c create mode 100755 tests/ioctl_loop.test
diff --git a/tests/.gitignore b/tests/.gitignore index bab02a0..48a0e21 100644 --- a/tests/.gitignore +++ b/tests/.gitignore @@ -121,6 +121,8 @@ ioctl_dm ioctl_dm-v ioctl_evdev ioctl_evdev-v +ioctl_loop +ioctl_loop-v ioctl_mtd ioctl_rtc ioctl_rtc-v diff --git a/tests/Makefile.am b/tests/Makefile.am index 7a8b411..cd98900 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -180,6 +180,8 @@ check_PROGRAMS = \ ioctl_dm-v \ ioctl_evdev \ ioctl_evdev-v \ + ioctl_loop \ + ioctl_loop-v \ ioctl_mtd \ ioctl_rtc \ ioctl_rtc-v \ @@ -570,6 +572,8 @@ DECODER_TESTS = \ ioctl_dm-v.test \ ioctl_evdev.test \ ioctl_evdev-v.test \ + ioctl_loop.test \ + ioctl_loop-v.test \ ioctl_mtd.test \ ioctl_rtc.test \ ioctl_rtc-v.test \ diff --git a/tests/ioctl_loop-v.c b/tests/ioctl_loop-v.c new file mode 100644 index 0000000..22e7572 --- /dev/null +++ b/tests/ioctl_loop-v.c @@ -0,0 +1,2 @@ +#define VERBOSE 1 +#include "ioctl_loop.c" diff --git a/tests/ioctl_loop-v.test b/tests/ioctl_loop-v.test new file mode 100755 index 0000000..7faa859 --- /dev/null +++ b/tests/ioctl_loop-v.test @@ -0,0 +1,12 @@ +#!/bin/sh + +# Check verbose decoding LOOP_* ioctls. + +. "${srcdir=.}/init.sh" + +run_prog > /dev/null +run_strace -a22 -veioctl $args > "$EXP" +check_prog grep +grep -v '^ioctl([012],' < "$LOG" > "$OUT" +match_diff "$OUT" "$EXP" +rm -f "$EXP" "$OUT" diff --git a/tests/ioctl_loop.c b/tests/ioctl_loop.c new file mode 100644 index 0000000..323468a --- /dev/null +++ b/tests/ioctl_loop.c @@ -0,0 +1,184 @@ +/* + * This file is part of ioctl_loop strace test. + * + * Copyright (c) 2016 JingPiao Chen <chenjingp...@gmail.com> + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + + +#include "tests.h" +#include <stdio.h> +#include <string.h> +#include <inttypes.h> +#include <sys/ioctl.h> +#include <linux/loop.h> + +# ifndef VERBOSE +# define VERBOSE 0 +# endif + +static const unsigned int magic = 0xdeadbeef; +static const unsigned long lmagic = (unsigned long) 0xdeadbeefbadc0dedULL; + +static void +init_magic(void *addr, const unsigned int size) +{ + unsigned int *p = addr; + const unsigned int *end = addr + size - sizeof(int); + + for (; p <= end; ++p) + *(unsigned int *) p = magic; +} + +int +main(void) +{ + ioctl(-1, LOOP_SET_FD, magic); + printf("ioctl(-1, LOOP_SET_FD, %d) = -1 EBADF (%m)\n", magic); + + ioctl(-1, LOOP_CLR_FD, 0); + printf("ioctl(-1, LOOP_CLR_FD) = -1 EBADF (%m)\n"); + + struct loop_info *const info = tail_alloc(sizeof(*info)); + init_magic(info, sizeof(*info)); + info->lo_encrypt_type = LO_CRYPT_NONE; + info->lo_flags = LO_FLAGS_READ_ONLY; + memset(info->lo_name, 'A', sizeof(info->lo_name)); + memset(info->lo_encrypt_key, 'B', sizeof(info->lo_encrypt_key)); + ioctl(-1, LOOP_SET_STATUS, info); + printf("ioctl(-1, LOOP_SET_STATUS, {lo_number=%d", info->lo_number); +# if VERBOSE + printf(", lo_device=%#lx, lo_inode=%lu, lo_rdevice=%#lx", + (unsigned long) info->lo_device, + info->lo_inode, + (unsigned long) info->lo_rdevice); +# endif /* VERBOSE */ + + printf(", lo_offset=%#x", info->lo_offset); + +# if VERBOSE + printf(", lo_encrypt_type=LO_CRYPT_NONE, lo_encrypt_key_size=%d", + info->lo_encrypt_key_size); +#endif /* VERBOSE */ + + printf(", lo_flags=LO_FLAGS_READ_ONLY, lo_name=\"%.*s\"", + (int) sizeof(info->lo_name) - 1, info->lo_name); + +# if VERBOSE + printf(", lo_encrypt_key=\"%.*s\"", + (int) sizeof(info->lo_encrypt_key), + info->lo_encrypt_key); +#endif /* VERBOSE */ +# if VERBOSE + printf(", lo_init=[%#lx, %#lx]" + ", reserved=[%#x, %#x, %#x, %#x]}", + info->lo_init[0], info->lo_init[1], + info->reserved[0], info->reserved[1], + info->reserved[2], info->reserved[3]); +# else /* !VERBOSE */ + printf(", ...}"); +#endif /* VERBOSE */ + printf(") = -1 EBADF (%m)\n"); + + ioctl(-1, LOOP_GET_STATUS, info); + printf("ioctl(-1, LOOP_GET_STATUS, %#llx) = -1 EBADF (%m)\n", + (long long) info); + + struct loop_info64 *const info64 = tail_alloc(sizeof(*info64)); + init_magic(info64, sizeof(*info64)); + info64->lo_flags = LO_FLAGS_READ_ONLY; + info64->lo_encrypt_type = LO_CRYPT_NONE; + memset(info64->lo_file_name, 'C', sizeof(info64->lo_file_name)); + memset(info64->lo_crypt_name, 'D', sizeof(info64->lo_crypt_name)); + memset(info64->lo_encrypt_key, 'E', sizeof(info64->lo_encrypt_key)); + ioctl(-1, LOOP_SET_STATUS64, info64); + printf("ioctl(-1, LOOP_SET_STATUS64, "); +# if VERBOSE + printf("{lo_device=%" PRIu64 ", lo_inode=%" PRIu64 + ", lo_rdevice=%" PRIu64 ", lo_offset=%#" PRIx64 + ", lo_sizelimit=%" PRIu64 ", lo_number=%" PRIu32, + (uint64_t) info64->lo_device, + (uint64_t) info64->lo_inode, + (uint64_t) info64->lo_rdevice, + (uint64_t) info64->lo_offset, + (uint64_t) info64->lo_sizelimit, + (uint32_t) info64->lo_number); +#else /* !VERBOSE */ + printf("{lo_offset=%#" PRIx64 ", lo_number=%" PRIu32, + (uint64_t) info64->lo_offset, + (uint32_t) info64->lo_number); +#endif /* VERBOSE */ + +# if VERBOSE + printf(", lo_encrypt_type=LO_CRYPT_NONE, lo_encrypt_key_size=%" PRIu32, + info64->lo_encrypt_key_size); +# endif /* VERBOSE */ + + printf(", lo_flags=LO_FLAGS_READ_ONLY, lo_file_name=\"%.*s\"", + (int) sizeof(info64->lo_file_name) - 1, info64->lo_file_name); + +# if VERBOSE + printf(", lo_crypt_name=\"%.*s\", lo_encrypt_key=\"%.*s\"", + (int) sizeof(info64->lo_crypt_name) - 1, + info64->lo_crypt_name, + (int) sizeof(info64->lo_encrypt_key), + info64->lo_encrypt_key); +# endif /* VERBOSE */ + +# if VERBOSE + printf(", lo_init=[%#" PRIx64 ", %#" PRIx64 "]}", + (uint64_t) info64->lo_init[0], + (uint64_t) info64->lo_init[1]); +# else /* !VERBOSE */ + printf(", ...}"); +# endif /* VERBOSE */ + + printf(") = -1 EBADF (%m)\n"); + + ioctl(-1, LOOP_GET_STATUS64, info64); + printf("ioctl(-1, LOOP_GET_STATUS64, %#llx) = -1 EBADF (%m)\n", + (long long) info64); + + ioctl(-1, LOOP_CHANGE_FD, magic); + printf("ioctl(-1, LOOP_CHANGE_FD, %d) = -1 EBADF (%m)\n", magic); + + ioctl(-1, LOOP_SET_CAPACITY, 0); + printf("ioctl(-1, LOOP_SET_CAPACITY) = -1 EBADF (%m)\n"); + + ioctl(-1, LOOP_SET_DIRECT_IO, lmagic); + printf("ioctl(-1, LOOP_SET_DIRECT_IO, %lu) = -1 EBADF (%m)\n", lmagic); + + ioctl(-1, LOOP_CTL_ADD, magic); + printf("ioctl(-1, LOOP_CTL_ADD, %d) = -1 EBADF (%m)\n", magic); + + ioctl(-1, LOOP_CTL_REMOVE, magic); + printf("ioctl(-1, LOOP_CTL_REMOVE, %d) = -1 EBADF (%m)\n", magic); + + ioctl(-1, LOOP_CTL_GET_FREE, 0); + printf("ioctl(-1, LOOP_CTL_GET_FREE) = -1 EBADF (%m)\n"); + + puts("+++ exited with 0 +++"); + return 0; +} diff --git a/tests/ioctl_loop.test b/tests/ioctl_loop.test new file mode 100755 index 0000000..112cd63 --- /dev/null +++ b/tests/ioctl_loop.test @@ -0,0 +1,12 @@ +#!/bin/sh + +# Check decoding of LOOP_* ioctls. + +. "${srcdir=.}/init.sh" + +run_prog > /dev/null +run_strace -a22 -eioctl $args > "$EXP" +check_prog grep +grep -v '^ioctl([012],' < "$LOG" > "$OUT" +match_diff "$OUT" "$EXP" +rm -f "$EXP" "$OUT" -- 2.7.4 ------------------------------------------------------------------------------ Check out the vibrant tech community on one of the world's most engaging tech sites, SlashDot.org! http://sdm.link/slashdot _______________________________________________ Strace-devel mailing list Strace-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/strace-devel