From 431d63c13f955f8606eb46ad7344825dc2e3e7ca Mon Sep 17 00:00:00 2001 From: "Dmitry V. Levin" Date: Tue, 1 Dec 2015 00:32:40 +0000 Subject: [PATCH] tests: add ftruncate64.test and truncate64.test * tests/ftruncate64.c: New file. * tests/truncate64.c: Likewise. * tests/ftruncate64.test: New test. * tests/truncate64.test: Likewise. * tests/Makefile.am (check_PROGRAMS): Add ftruncate64 and truncate64. (ftruncate64_CFLAGS, truncate64_CFLAGS): Define. (TESTS): Add ftruncate64.test and truncate64.test. * tests/.gitignore: Add ftruncate64 and truncate64. --- tests/.gitignore | 2 ++ tests/Makefile.am | 6 ++++ tests/ftruncate64.c | 64 ++++++++++++++++++++++++++++++++++++++++ tests/ftruncate64.test | 13 +++++++++ tests/truncate64.c | 66 ++++++++++++++++++++++++++++++++++++++++++ tests/truncate64.test | 13 +++++++++ 6 files changed, 164 insertions(+) create mode 100644 tests/ftruncate64.c create mode 100755 tests/ftruncate64.test create mode 100644 tests/truncate64.c create mode 100755 tests/truncate64.test diff --git a/tests/.gitignore b/tests/.gitignore index 48aa3018..eb2aeeb9 100644 --- a/tests/.gitignore +++ b/tests/.gitignore @@ -12,6 +12,7 @@ fanotify_mark file_handle filter-unavailable ftruncate +ftruncate64 getdents getdents64 getrandom @@ -68,6 +69,7 @@ timerfd_xettime times times-fail truncate +truncate64 uid uid16 uid32 diff --git a/tests/Makefile.am b/tests/Makefile.am index 3e962c84..2ad8d400 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -25,6 +25,7 @@ check_PROGRAMS = \ file_handle \ filter-unavailable \ ftruncate \ + ftruncate64 \ getdents \ getdents64 \ getrandom \ @@ -81,6 +82,7 @@ check_PROGRAMS = \ times \ times-fail \ truncate \ + truncate64 \ uid \ uid16 \ uid32 \ @@ -100,12 +102,14 @@ check_PROGRAMS = \ clock_xettime_LDADD = -lrt filter_unavailable_LDADD = -lpthread +ftruncate64_CFLAGS = $(AM_CFLAGS) -D_FILE_OFFSET_BITS=64 mmap64_CFLAGS = $(AM_CFLAGS) -D_FILE_OFFSET_BITS=64 mq_LDADD = -lrt pc_LDADD = $(dl_LIBS) stat_CFLAGS = $(AM_CFLAGS) -D_FILE_OFFSET_BITS=64 statfs_CFLAGS = $(AM_CFLAGS) -D_FILE_OFFSET_BITS=64 times_LDADD = -lrt +truncate64_CFLAGS = $(AM_CFLAGS) -D_FILE_OFFSET_BITS=64 uio_CFLAGS = $(AM_CFLAGS) -D_FILE_OFFSET_BITS=64 stack_fcall_SOURCES = stack-fcall.c \ stack-fcall-0.c stack-fcall-1.c stack-fcall-2.c stack-fcall-3.c @@ -129,6 +133,7 @@ TESTS = \ file_handle.test \ filter-unavailable.test \ ftruncate.test \ + ftruncate64.test \ getdents.test \ getdents64.test \ getrandom.test \ @@ -183,6 +188,7 @@ TESTS = \ times.test \ times-fail.test \ truncate.test \ + truncate64.test \ umovestr.test \ umovestr2.test \ unix-yy.test \ diff --git a/tests/ftruncate64.c b/tests/ftruncate64.c new file mode 100644 index 00000000..7dfbf6b4 --- /dev/null +++ b/tests/ftruncate64.c @@ -0,0 +1,64 @@ +/* + * Copyright (c) 2015 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. + */ + +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#include + +#ifdef __NR_ftruncate64 + +#include +#include +#include + +int +main(void) +{ + const off_t len = 0xdefaceddeadbeef; + int rc = ftruncate(-1, len); + + if (rc != -1 || EBADF != errno) + return 77; + + printf("ftruncate64(-1, %Lu) = -1 EBADF (Bad file descriptor)\n", + (unsigned long long) len); + + puts("+++ exited with 0 +++"); + return 0; +} + +#else + +int +main(void) +{ + return 77; +} + +#endif diff --git a/tests/ftruncate64.test b/tests/ftruncate64.test new file mode 100755 index 00000000..43cd9add --- /dev/null +++ b/tests/ftruncate64.test @@ -0,0 +1,13 @@ +#!/bin/sh + +# Check ftruncate64 syscall decoding. + +. "${srcdir=.}/init.sh" + +run_prog > /dev/null +OUT="$LOG.out" +run_strace -a36 -eftruncate64 $args > "$OUT" +match_diff "$LOG" "$OUT" +rm -f "$OUT" + +exit 0 diff --git a/tests/truncate64.c b/tests/truncate64.c new file mode 100644 index 00000000..82565802 --- /dev/null +++ b/tests/truncate64.c @@ -0,0 +1,66 @@ +/* + * Copyright (c) 2015 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. + */ + +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#include + +#ifdef __NR_truncate64 + +#include +#include +#include + +int +main(void) +{ + static const char fname[] = "truncate64\nfilename"; + static const char qname[] = "truncate64\\nfilename"; + const off_t len = 0xdefaceddeadbeef; + int rc = truncate(fname, len); + + if (rc != -1 || ENOENT != errno) + return 77; + + printf("truncate64(\"%s\", %Lu) = -1 ENOENT (No such file or directory)\n", + qname, (unsigned long long) len); + + puts("+++ exited with 0 +++"); + return 0; +} + +#else + +int +main(void) +{ + return 77; +} + +#endif diff --git a/tests/truncate64.test b/tests/truncate64.test new file mode 100755 index 00000000..2113e069 --- /dev/null +++ b/tests/truncate64.test @@ -0,0 +1,13 @@ +#!/bin/sh + +# Check truncate64 syscall decoding. + +. "${srcdir=.}/init.sh" + +run_prog > /dev/null +OUT="$LOG.out" +run_strace -etruncate64 $args > "$OUT" +match_diff "$LOG" "$OUT" +rm -f "$OUT" + +exit 0 -- 2.40.0