From 16a52b4b873e86cb081b0b344d12a22d3e572872 Mon Sep 17 00:00:00 2001 From: "Dmitry V. Levin" Date: Sat, 13 Feb 2016 22:31:30 +0000 Subject: [PATCH] Fix printing of negative offsets in splice syscall * io.c (SYS_FUNC(splice)): Use PRId64 instead of PRIu64 for printing offsets. * tests/splice.c: New file. * tests/splice.test: New test. * tests/.gitignore: Add splice. * tests/Makefile.am (check_PROGRAMS): Likewise. (TESTS): Add splice.test. --- io.c | 4 +-- tests/.gitignore | 1 + tests/Makefile.am | 2 ++ tests/splice.c | 66 +++++++++++++++++++++++++++++++++++++++++++++++ tests/splice.test | 11 ++++++++ 5 files changed, 82 insertions(+), 2 deletions(-) create mode 100644 tests/splice.c create mode 100755 tests/splice.test diff --git a/io.c b/io.c index b98bc8a1..2075d201 100644 --- a/io.c +++ b/io.c @@ -256,13 +256,13 @@ SYS_FUNC(splice) printfd(tcp, tcp->u_arg[0]); tprints(", "); /* loff_t *off_in */ - printnum_int64(tcp, tcp->u_arg[1], "%" PRIu64); + printnum_int64(tcp, tcp->u_arg[1], "%" PRId64); tprints(", "); /* int fd_out */ printfd(tcp, tcp->u_arg[2]); tprints(", "); /* loff_t *off_out */ - printnum_int64(tcp, tcp->u_arg[3], "%" PRIu64); + printnum_int64(tcp, tcp->u_arg[3], "%" PRId64); tprints(", "); /* size_t len */ tprintf("%lu, ", tcp->u_arg[4]); diff --git a/tests/.gitignore b/tests/.gitignore index ce52655a..73b83400 100644 --- a/tests/.gitignore +++ b/tests/.gitignore @@ -93,6 +93,7 @@ sigaltstack signalfd sigreturn sleep +splice stack-fcall stat stat64 diff --git a/tests/Makefile.am b/tests/Makefile.am index 4c7ae8f1..3907637a 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -140,6 +140,7 @@ check_PROGRAMS = \ sigaltstack \ signalfd \ sigreturn \ + splice \ stack-fcall \ sleep \ stat \ @@ -283,6 +284,7 @@ TESTS = \ sigaltstack.test \ signalfd.test \ sigreturn.test \ + splice.test \ stat.test \ stat64.test \ statfs.test \ diff --git a/tests/splice.c b/tests/splice.c new file mode 100644 index 00000000..ac24b2a7 --- /dev/null +++ b/tests/splice.c @@ -0,0 +1,66 @@ +/* + * This file is part of splice strace test. + * + * Copyright (c) 2016 Dmitry V. Levin + * 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 + +#if defined __NR_splice + +# include +# include +# include +# include + +int +main(void) +{ + const long int fd_in = (long int) 0xdeadbeefffffffff; + const long int fd_out = (long int) 0xdeadbeeffffffffe; + long long int *const off_in = tail_alloc(sizeof(*off_in)); + long long int *const off_out = tail_alloc(sizeof(*off_out)); + *off_in = 0xdeadbef1facefed1; + *off_out = 0xdeadbef2facefed2; + const size_t len = (size_t) 0xdeadbef3facefed3ULL; + const unsigned int flags = 15; + + assert(syscall(__NR_splice, fd_in, off_in, fd_out, off_out, + len, flags) == -1); + printf("splice(%d, [%lld], %d, [%lld], %zu, %s) = -1 %s (%m)\n", + (int) fd_in, *off_in, (int) fd_out, *off_out, len, + "SPLICE_F_MOVE|SPLICE_F_NONBLOCK|SPLICE_F_MORE|SPLICE_F_GIFT", + errno == ENOSYS ? "ENOSYS" : "EBADF"); + puts("+++ exited with 0 +++"); + return 0; +} + +#else + +SKIP_MAIN_UNDEFINED("__NR_splice") + +#endif diff --git a/tests/splice.test b/tests/splice.test new file mode 100755 index 00000000..e3bb0936 --- /dev/null +++ b/tests/splice.test @@ -0,0 +1,11 @@ +#!/bin/sh + +# Check splice syscall decoding. + +. "${srcdir=.}/init.sh" + +run_prog > /dev/null +OUT="$LOG.out" +run_strace -esplice $args > "$OUT" +match_diff "$LOG" "$OUT" +rm -f "$OUT" -- 2.40.0