On 10/10/2011 08:40 AM, Jim Meyering wrote: > Pádraig Brady wrote: >> On 10/08/2011 03:46 PM, Bruno Haible wrote: >>> On NetBSD 5.1/x86: 10 failures >>> >>> FAIL: split/l-chunk >> >> This one at least was due to missing /dev/zero >> which is not required by POSIX so the attached >> skips the tests requiring it. > > Thanks for the patch. > >> From 274a4bff32efb2fb483d19d9884e3f1be03cf849 Mon Sep 17 00:00:00 2001 >> From: =?UTF-8?q?P=C3=A1draig=20Brady?= <p...@draigbrady.com> >> Date: Sun, 9 Oct 2011 23:30:02 +0100 >> Subject: [PATCH] tests: don't assume the existence of /dev/zero >> >> /dev/zero is not defined by POSIX and is >> not available on NetBSD at least. >> > ... >> +# TODO: we might relax this requirement in some tests, if >> +# for example, truncate --alloc (posix_fallocate) is implemented. >> +require_dev_zero_() >> +{ >> + test -c /dev/zero || >> + skip_ "This test requires /dev/zero support." >> +} > > This TODO seems like good justification for adding the truncate option. > > However, just to be a little paranoid, it might be better > to ensure that we can actually read from it, too. > > What do you think about a syntax-check that requires a use of > require_dev_zero_ in each file under tests/ that uses /dev/zero? >
I've updated the patch to do both of the above suggestions. However it probably shouldn't be applied unless we're targetting systems without /dev/zero. cheers, Pádraig.
>From bed480f34465d2b06efa2e39fb0aacbb2e99d4cd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C3=A1draig=20Brady?= <p...@draigbrady.com> Date: Sun, 9 Oct 2011 23:30:02 +0100 Subject: [PATCH] tests: don't assume the existence of /dev/zero /dev/zero is not defined by POSIX and is not available on NetBSD at least. * tests/init.cfg (require_dev_zero_): Add this new function. * tests/cp/cp-a-selinux: Use require_dev_zero_. * tests/cp/cp-mv-enotsup-xattr: Likewise. * tests/cp/fiemap-2: Likewise. * tests/dd/nocache: Likewise. * tests/mkdir/writable-under-readonly: Likewise. * tests/rm/read-only: Likewise. * tests/split/l-chunk: Likewise. * tests/cp/sparse-fiemap: Likewise. Also use the more standard require_perl_. * cfg.mk (sc_require_dev_zero): A new syntax check to ensure require_dev_zero_ is used in tests mentioning /dev/zero. Reported by Bruno Haible. --- cfg.mk | 10 ++++++++++ tests/cp/cp-a-selinux | 1 + tests/cp/cp-mv-enotsup-xattr | 1 + tests/cp/fiemap-2 | 2 ++ tests/cp/sparse-fiemap | 3 ++- tests/dd/nocache | 1 + tests/init.cfg | 8 ++++++++ tests/mkdir/writable-under-readonly | 1 + tests/mv/vfat | 2 ++ tests/rm/read-only | 1 + tests/split/filter | 1 + tests/split/l-chunk | 1 + 12 files changed, 31 insertions(+), 1 deletions(-) diff --git a/cfg.mk b/cfg.mk index 05859dc..10f93f9 100644 --- a/cfg.mk +++ b/cfg.mk @@ -75,6 +75,16 @@ sc_prohibit_jm_in_m4: { echo '$(ME): do not use jm_ in m4 macro names' \ 1>&2; exit 1; } || : +# Ensure that each test referencing /dev/zero uses require_dev_zero_ +sc_require_dev_zero: + @if test -d tests && \ + grep require_dev_zero_ tests/init.cfg>/dev/null 2>&1; then \ + $$($(VC_LIST) tests | xargs grep -lF /dev/zero | \ + xargs grep -LF require_dev_zero_ | grep . >&2) && \ + { echo '$(ME): the above need to use require_dev_zero_ '>&2; \ + exit 1; } || :; \ + fi + # Ensure that each root-requiring test is run via the "check-root" rule. sc_root_tests: @if test -d tests \ diff --git a/tests/cp/cp-a-selinux b/tests/cp/cp-a-selinux index 0f9c149..fb12a2a 100755 --- a/tests/cp/cp-a-selinux +++ b/tests/cp/cp-a-selinux @@ -24,6 +24,7 @@ print_ver_ cp require_root_ require_selinux_ require_mkfs_PATH_ +require_dev_zero_ cwd=`pwd` cleanup_() { cd /; umount "$cwd/mnt"; } diff --git a/tests/cp/cp-mv-enotsup-xattr b/tests/cp/cp-mv-enotsup-xattr index 32798d2..72d2e66 100755 --- a/tests/cp/cp-mv-enotsup-xattr +++ b/tests/cp/cp-mv-enotsup-xattr @@ -36,6 +36,7 @@ make_fs() { fs="$where.bin" + require_dev_zero_ dd if=/dev/zero of="$fs" bs=8192 count=200 > /dev/null 2>&1 \ || skip=1 mkdir "$where" || skip=1 diff --git a/tests/cp/fiemap-2 b/tests/cp/fiemap-2 index 691ead2..8f0adf7 100755 --- a/tests/cp/fiemap-2 +++ b/tests/cp/fiemap-2 @@ -19,6 +19,8 @@ . "${srcdir=.}/init.sh"; path_prepend_ ../src print_ver_ cp +require_dev_zero_ + # Require a fiemap-enabled FS. touch fiemap_chk # check a file rather than current dir for best coverage fiemap_capable_ fiemap_chk \ diff --git a/tests/cp/sparse-fiemap b/tests/cp/sparse-fiemap index 831bf0b..02604c9 100755 --- a/tests/cp/sparse-fiemap +++ b/tests/cp/sparse-fiemap @@ -18,7 +18,8 @@ . "${srcdir=.}/init.sh"; path_prepend_ ../src print_ver_ cp -$PERL -e 1 || skip_ 'you lack perl' +require_perl_ +require_dev_zero_ # The test was seen to fail on ext3 so exclude that type # (or any file system where the type can't be determined) diff --git a/tests/dd/nocache b/tests/dd/nocache index 5dcd897..b34c3aa 100755 --- a/tests/dd/nocache +++ b/tests/dd/nocache @@ -18,6 +18,7 @@ . "${srcdir=.}/init.sh"; path_prepend_ ../src print_ver_ dd +require_dev_zero_ # This should not call posix_fadvise dd iflag=nocache oflag=nocache if=/dev/null of=/dev/null || fail=1 diff --git a/tests/init.cfg b/tests/init.cfg index f6eb651..48d1fd7 100644 --- a/tests/init.cfg +++ b/tests/init.cfg @@ -385,6 +385,14 @@ require_sparse_support_() fi } +# TODO: we might relax this requirement in some tests, if +# for example, truncate --alloc (posix_fallocate) is implemented. +require_dev_zero_() +{ + test -c /dev/zero && test -r /dev/zero || + skip_ "This test requires /dev/zero support." +} + mkfifo_or_skip_() { test $# = 1 || framework_failure_ diff --git a/tests/mkdir/writable-under-readonly b/tests/mkdir/writable-under-readonly index 3e42b1d..2a294ab 100755 --- a/tests/mkdir/writable-under-readonly +++ b/tests/mkdir/writable-under-readonly @@ -28,6 +28,7 @@ print_ver_ mkdir require_root_ require_mkfs_PATH_ +require_dev_zero_ # FIXME: for now, skip it unconditionally skip_ temporarily disabled diff --git a/tests/mv/vfat b/tests/mv/vfat index 6530767..4bcd754 100644 --- a/tests/mv/vfat +++ b/tests/mv/vfat @@ -29,6 +29,8 @@ The problem: Demonstrate the problem, as root: +require_dev_zero_ + cd /tmp \ && dd if=/dev/zero of=1 bs=8192 count=50 \ && mkdir mnt && mkfs -t vfat 1 \ diff --git a/tests/rm/read-only b/tests/rm/read-only index 489b1bf..f6d1c4e 100755 --- a/tests/rm/read-only +++ b/tests/rm/read-only @@ -20,6 +20,7 @@ print_ver_ rm require_root_ require_mkfs_PATH_ +require_dev_zero_ cwd=`pwd` cleanup_() { cd /; umount "$cwd/mnt"; } diff --git a/tests/split/filter b/tests/split/filter index afdd4d2..f914aa3 100755 --- a/tests/split/filter +++ b/tests/split/filter @@ -18,6 +18,7 @@ . "${srcdir=.}/init.sh"; path_prepend_ ../src print_ver_ split +require_dev_zero_ xz --version || skip_ "xz (better than gzip/bzip2) required" for total_n_lines in 5 3000 20000; do diff --git a/tests/split/l-chunk b/tests/split/l-chunk index e1c9ec7..870c211 100755 --- a/tests/split/l-chunk +++ b/tests/split/l-chunk @@ -18,6 +18,7 @@ . "${srcdir=.}/init.sh"; path_prepend_ ../src print_ver_ split +require_dev_zero_ # invalid number of chunks echo 'split: 1o: invalid number of chunks' > exp -- 1.7.6