diff options
author | Igor Pashev <pashev.igor@gmail.com> | 2015-07-04 17:13:50 +0300 |
---|---|---|
committer | Igor Pashev <pashev.igor@gmail.com> | 2015-07-04 17:13:50 +0300 |
commit | 71cd8e3a743046573744123777061b64881bf372 (patch) | |
tree | 82522befe647f4fff186a5630cad0cad33f8ef53 /tests | |
parent | c18578632fd3c9e513e613a86ba2b7c4ebee6c45 (diff) | |
download | coreutils-upstream.tar.gz |
Imported Upstream version 8.24upstream/8.24upstream
Diffstat (limited to 'tests')
550 files changed, 3231 insertions, 1627 deletions
diff --git a/tests/Coreutils.pm b/tests/Coreutils.pm index cfa41a96..bd2088f6 100644 --- a/tests/Coreutils.pm +++ b/tests/Coreutils.pm @@ -1,7 +1,7 @@ package Coreutils; # This is a testing framework. -# Copyright (C) 1998-2014 Free Software Foundation, Inc. +# Copyright (C) 1998-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -91,7 +91,7 @@ defined $ENV{DJDIR} # If the EXIT-keyed one is omitted, then expect the exit status to be zero. # FIXME: Make sure that no junkfile is also listed as a -# non-junkfile (i.e. with undef for contents) +# non-junkfile (i.e., with undef for contents) sub _shell_quote ($) { @@ -576,7 +576,7 @@ sub run_tests ($$$$$) } # For each test in @$TESTS, generate two additional tests, -# one using stdin, the other using a pipe. I.e., given this one +# one using stdin, the other using a pipe. I.e., given this one # ['idem-0', {IN=>''}, {OUT=>''}], # generate these: # ['idem-0.r', '<', {IN=>''}, {OUT=>''}], diff --git a/tests/CuSkip.pm b/tests/CuSkip.pm index d0cfdb54..a25688a6 100644 --- a/tests/CuSkip.pm +++ b/tests/CuSkip.pm @@ -1,7 +1,7 @@ package CuSkip; # Skip a test: emit diag to log and to stderr, and exit 77 -# Copyright (C) 2011-2014 Free Software Foundation, Inc. +# Copyright (C) 2011-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/CuTmpdir.pm b/tests/CuTmpdir.pm index 7e73f65e..fd65556f 100644 --- a/tests/CuTmpdir.pm +++ b/tests/CuTmpdir.pm @@ -1,7 +1,7 @@ package CuTmpdir; # create, then chdir into a temporary sub-directory -# Copyright (C) 2007-2014 Free Software Foundation, Inc. +# Copyright (C) 2007-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/chgrp/basic.sh b/tests/chgrp/basic.sh index 153b36c3..39a8d3c8 100755 --- a/tests/chgrp/basic.sh +++ b/tests/chgrp/basic.sh @@ -1,7 +1,7 @@ #!/bin/sh # make sure chgrp is reasonable -# Copyright (C) 2000-2014 Free Software Foundation, Inc. +# Copyright (C) 2000-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/chgrp/default-no-deref.sh b/tests/chgrp/default-no-deref.sh index c8c1da24..a0080e7b 100755 --- a/tests/chgrp/default-no-deref.sh +++ b/tests/chgrp/default-no-deref.sh @@ -1,7 +1,7 @@ #!/bin/sh # Ensure that chgrp -R does not dereference symlinks. -# Copyright (C) 2006-2014 Free Software Foundation, Inc. +# Copyright (C) 2006-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/chgrp/deref.sh b/tests/chgrp/deref.sh index 97eadfd0..22548ea3 100755 --- a/tests/chgrp/deref.sh +++ b/tests/chgrp/deref.sh @@ -1,7 +1,7 @@ #!/bin/sh # see if chgrp can change the group of a symlink -# Copyright (C) 2000-2014 Free Software Foundation, Inc. +# Copyright (C) 2000-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/chgrp/no-x.sh b/tests/chgrp/no-x.sh index 27248af4..b532c97e 100755 --- a/tests/chgrp/no-x.sh +++ b/tests/chgrp/no-x.sh @@ -2,7 +2,7 @@ # Make sure chgrp gives the right diagnostic for a readable, # but inaccessible directory. -# Copyright (C) 2003-2014 Free Software Foundation, Inc. +# Copyright (C) 2003-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/chgrp/posix-H.sh b/tests/chgrp/posix-H.sh index 093d5181..205d0732 100755 --- a/tests/chgrp/posix-H.sh +++ b/tests/chgrp/posix-H.sh @@ -1,7 +1,7 @@ #!/bin/sh # Test POSIX-mandated -H option. -# Copyright (C) 2003-2014 Free Software Foundation, Inc. +# Copyright (C) 2003-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/chgrp/recurse.sh b/tests/chgrp/recurse.sh index cd973838..05b987a0 100755 --- a/tests/chgrp/recurse.sh +++ b/tests/chgrp/recurse.sh @@ -1,7 +1,7 @@ #!/bin/sh # ad-hoc tests of chgrp with -R and -H or -L and symlinks -# Copyright (C) 2000-2014 Free Software Foundation, Inc. +# Copyright (C) 2000-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/chmod/c-option.sh b/tests/chmod/c-option.sh index 03e1db9a..bba557af 100755 --- a/tests/chmod/c-option.sh +++ b/tests/chmod/c-option.sh @@ -1,7 +1,7 @@ #!/bin/sh # Verify that chmod's --changes (-c) option works. -# Copyright (C) 2000-2014 Free Software Foundation, Inc. +# Copyright (C) 2000-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/chmod/equal-x.sh b/tests/chmod/equal-x.sh index 75a2fa1a..98f6bc49 100755 --- a/tests/chmod/equal-x.sh +++ b/tests/chmod/equal-x.sh @@ -1,7 +1,7 @@ #!/bin/sh # Test "chmod =x" and the like. -# Copyright (C) 1999-2014 Free Software Foundation, Inc. +# Copyright (C) 1999-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/chmod/equals.sh b/tests/chmod/equals.sh index 4daba4be..b7f4362e 100755 --- a/tests/chmod/equals.sh +++ b/tests/chmod/equals.sh @@ -3,7 +3,7 @@ # Before fileutils-4.1.2, some of them didn't. # Also, before coreutils-5.3.1, =[ugo] sometimes didn't work. -# Copyright (C) 2001-2014 Free Software Foundation, Inc. +# Copyright (C) 2001-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/chmod/inaccessible.sh b/tests/chmod/inaccessible.sh index 2ef2a61f..e57cf92a 100755 --- a/tests/chmod/inaccessible.sh +++ b/tests/chmod/inaccessible.sh @@ -1,7 +1,7 @@ #!/bin/sh # Test for the bug fixed on 2006-09-20. -# Copyright (C) 2006-2014 Free Software Foundation, Inc. +# Copyright (C) 2006-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/chmod/no-x.sh b/tests/chmod/no-x.sh index 64e81ed8..d43c4a25 100755 --- a/tests/chmod/no-x.sh +++ b/tests/chmod/no-x.sh @@ -2,7 +2,7 @@ # Make sure chmod gives the right diagnostic for a readable, # but inaccessible directory. -# Copyright (C) 2003-2014 Free Software Foundation, Inc. +# Copyright (C) 2003-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/chmod/octal.sh b/tests/chmod/octal.sh index 895c8348..23d0542f 100755 --- a/tests/chmod/octal.sh +++ b/tests/chmod/octal.sh @@ -1,7 +1,7 @@ #!/bin/sh # ensure that chmod diagnoses a certain type of invalid mode string -# Copyright (C) 2005-2014 Free Software Foundation, Inc. +# Copyright (C) 2005-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -22,8 +22,8 @@ print_ver_ chmod # Before coreutils-5.92, this would mistakenly succeed, # and act like 'chmod 0 .'. -chmod 0-followed-by-anything . 2> /dev/null && fail=1 -chmod 7-followed-by-anything . 2> /dev/null && fail=1 -chmod 8 . 2> /dev/null && fail=1 +for mode in '0-anything' '7-anything' '8'; do + returns_ 1 chmod "$mode" . 2>/dev/null || fail=1 +done Exit $fail diff --git a/tests/chmod/setgid.sh b/tests/chmod/setgid.sh index 0c0722de..1e82e882 100755 --- a/tests/chmod/setgid.sh +++ b/tests/chmod/setgid.sh @@ -3,7 +3,7 @@ # on directories with the setgid bit set. Also, check that the GNU octal # notations work. -# Copyright (C) 2001-2014 Free Software Foundation, Inc. +# Copyright (C) 2001-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/chmod/silent.sh b/tests/chmod/silent.sh index 5d5dcb58..d0d2b158 100755 --- a/tests/chmod/silent.sh +++ b/tests/chmod/silent.sh @@ -1,7 +1,7 @@ #!/bin/sh # ensure that chgrp, chmod, chown -f don't print some diagnostics -# Copyright (C) 2008-2014 Free Software Foundation, Inc. +# Copyright (C) 2008-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/chmod/thru-dangling.sh b/tests/chmod/thru-dangling.sh index 4a137e81..5cd0ad96 100755 --- a/tests/chmod/thru-dangling.sh +++ b/tests/chmod/thru-dangling.sh @@ -1,7 +1,7 @@ #!/bin/sh # Test for proper error and exit code of chmod on a dangling symlink. -# Copyright (C) 2007-2014 Free Software Foundation, Inc. +# Copyright (C) 2007-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/chmod/umask-x.sh b/tests/chmod/umask-x.sh index 9e0e0012..f31452a3 100755 --- a/tests/chmod/umask-x.sh +++ b/tests/chmod/umask-x.sh @@ -1,7 +1,7 @@ #!/bin/sh # Test that chmod -x file reports an error if the result is executable. -# Copyright (C) 2005-2014 Free Software Foundation, Inc. +# Copyright (C) 2005-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -21,6 +21,6 @@ print_ver_ chmod touch file chmod 755 file -(umask 77 && chmod -x file) 2>/dev/null && fail=1 +(umask 77 && returns_ 1 chmod -x file) 2>/dev/null || fail=1 Exit $fail diff --git a/tests/chmod/usage.sh b/tests/chmod/usage.sh index 7e27e7ce..ac6d635a 100755 --- a/tests/chmod/usage.sh +++ b/tests/chmod/usage.sh @@ -1,7 +1,7 @@ #!/bin/sh # Verify that chmod works correctly with odd option combinations. -# Copyright (C) 2004-2014 Free Software Foundation, Inc. +# Copyright (C) 2004-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -67,7 +67,7 @@ for case in $cases; do case $files in '') touch -- $all_files || framework_failure_ - chmod $args 2>/dev/null && fail=1 + returns_ 1 chmod $args 2>/dev/null || fail=1 ;; ?*) touch -- $files || framework_failure_ @@ -77,7 +77,7 @@ for case in $cases; do # chmod has a bug if it succeeds even though $file is absent. rm -f -- $all_files && touch -- $files && rm -- $file \ || framework_failure_ - chmod $args 2>/dev/null && fail=1 + returns_ 1 chmod $args 2>/dev/null || fail=1 done ;; esac diff --git a/tests/chown/basic.sh b/tests/chown/basic.sh index d4b2b9b0..e57b9c89 100755 --- a/tests/chown/basic.sh +++ b/tests/chown/basic.sh @@ -1,7 +1,7 @@ #!/bin/sh # make sure chown --from=... works -# Copyright (C) 2001-2014 Free Software Foundation, Inc. +# Copyright (C) 2001-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -34,7 +34,7 @@ printf "ownership of 'f' retained as $(id -nu)\n" > exp compare exp out || fail=1 # Ensure diagnostics work for non existent files. -chown -v 0 nf > out && fail=1 +returns_ 1 chown -v 0 nf > out || fail=1 printf "failed to change ownership of 'nf' to 0\n" > exp compare exp out || fail=1 diff --git a/tests/chown/deref.sh b/tests/chown/deref.sh index e576a9f9..30b4ed9e 100755 --- a/tests/chown/deref.sh +++ b/tests/chown/deref.sh @@ -2,7 +2,7 @@ # For coreutils-5.2.1 and earlier, chown --dereference would skip # symlinks having owner/group matching the specified owner/group. -# Copyright (C) 2004-2014 Free Software Foundation, Inc. +# Copyright (C) 2004-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/chown/preserve-root.sh b/tests/chown/preserve-root.sh index 176c7c4f..cbef76a8 100755 --- a/tests/chown/preserve-root.sh +++ b/tests/chown/preserve-root.sh @@ -1,7 +1,7 @@ #!/bin/sh # Verify that --preserve-root works. -# Copyright (C) 2006-2014 Free Software Foundation, Inc. +# Copyright (C) 2006-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/chown/separator.sh b/tests/chown/separator.sh index f5ecb5bb..642b0023 100755 --- a/tests/chown/separator.sh +++ b/tests/chown/separator.sh @@ -1,7 +1,7 @@ #!/bin/sh # Make sure "chown USER:GROUP FILE" works, and similar tests with separators. -# Copyright (C) 2004-2014 Free Software Foundation, Inc. +# Copyright (C) 2004-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -59,7 +59,7 @@ for u in $id_u "$id_un" ''; do esac for sep in $seps; do case $u$sep$g in - [0-9]*$sep) chown "$u$sep$g" . 2> /dev/null && fail=1 ;; + [0-9]*$sep) returns_ 1 chown "$u$sep$g" . 2>/dev/null || fail=1 ;; *) chown "$u$sep$g" . || fail=1 ;; esac done diff --git a/tests/cp/abuse.sh b/tests/cp/abuse.sh index 80eb1d62..cf7b45ab 100755 --- a/tests/cp/abuse.sh +++ b/tests/cp/abuse.sh @@ -1,7 +1,7 @@ #!/bin/sh # ensure that cp does not write through a just-copied symlink -# Copyright (C) 2007-2014 Free Software Foundation, Inc. +# Copyright (C) 2007-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/cp/acl.sh b/tests/cp/acl.sh index 36a5d298..e397ff06 100755 --- a/tests/cp/acl.sh +++ b/tests/cp/acl.sh @@ -2,7 +2,7 @@ # copy files/directories across file system boundaries # and make sure acls are preserved appropriately -# Copyright (C) 2005-2014 Free Software Foundation, Inc. +# Copyright (C) 2005-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/cp/attr-existing.sh b/tests/cp/attr-existing.sh index 7e48fbbc..74b26d73 100755 --- a/tests/cp/attr-existing.sh +++ b/tests/cp/attr-existing.sh @@ -1,7 +1,7 @@ #!/bin/sh # Make sure cp --attributes-only doesn't truncate existing data -# Copyright 2012-2014 Free Software Foundation, Inc. +# Copyright 2012-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/cp/backup-1.sh b/tests/cp/backup-1.sh index 033f8a93..39f48170 100755 --- a/tests/cp/backup-1.sh +++ b/tests/cp/backup-1.sh @@ -1,7 +1,7 @@ #!/bin/sh # Test cp backup. -# Copyright (C) 1997-2014 Free Software Foundation, Inc. +# Copyright (C) 1997-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/cp/backup-dir.sh b/tests/cp/backup-dir.sh index 2b11fd18..e6ead6cf 100755 --- a/tests/cp/backup-dir.sh +++ b/tests/cp/backup-dir.sh @@ -1,7 +1,7 @@ #!/bin/sh # Ensure that cp -b doesn't back up directories. -# Copyright (C) 2006-2014 Free Software Foundation, Inc. +# Copyright (C) 2006-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/cp/backup-is-src.sh b/tests/cp/backup-is-src.sh index ae2502e5..5b9da8dc 100755 --- a/tests/cp/backup-is-src.sh +++ b/tests/cp/backup-is-src.sh @@ -1,7 +1,7 @@ #!/bin/sh # Test cp backup to source file. -# Copyright (C) 1998-2014 Free Software Foundation, Inc. +# Copyright (C) 1998-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/cp/capability.sh b/tests/cp/capability.sh index fb3bc1c8..843b520e 100755 --- a/tests/cp/capability.sh +++ b/tests/cp/capability.sh @@ -1,7 +1,7 @@ #!/bin/sh # Ensure cp --preserves copies capabilities -# Copyright (C) 2010-2014 Free Software Foundation, Inc. +# Copyright (C) 2010-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/cp/cp-HL.sh b/tests/cp/cp-HL.sh index bdc31ed5..08a72b13 100755 --- a/tests/cp/cp-HL.sh +++ b/tests/cp/cp-HL.sh @@ -1,7 +1,7 @@ #!/bin/sh # test cp's -H and -L options -# Copyright (C) 2000-2014 Free Software Foundation, Inc. +# Copyright (C) 2000-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -33,7 +33,7 @@ test -d dest-dir/src-dir || fail=1 cat dest-dir/slink > /dev/null 2>&1 || fail=1 # Expect this to fail since *this* slink is a dangling symlink. -cat dest-dir/src-dir/slink > /dev/null 2>&1 && fail=1 +returns_ 1 cat dest-dir/src-dir/slink >/dev/null 2>&1 || fail=1 # FIXME: test -L, too. diff --git a/tests/cp/cp-a-selinux.sh b/tests/cp/cp-a-selinux.sh index 58887d27..d000ee8f 100755 --- a/tests/cp/cp-a-selinux.sh +++ b/tests/cp/cp-a-selinux.sh @@ -4,7 +4,7 @@ # Check also locally if --preserve=context, -a and --preserve=all # does work -# Copyright (C) 2007-2014 Free Software Foundation, Inc. +# Copyright (C) 2007-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -49,14 +49,16 @@ rm -f f # in the destination, so SELinux contexts should be updated too. chmod o+rw restore/existing_dir mkdir -p backup/existing_dir/ || framework_failure_ -ls -Zd backup/existing_dir | grep $ctx && framework_failure_ +ls -Zd backup/existing_dir > ed_ctx || fail=1 +grep $ctx ed_ctx && framework_failure_ touch backup/existing_dir/file || framework_failure_ chcon $ctx backup/existing_dir/file || framework_failure_ # Set the dir context to ensure it is reset mkdir -p --context="$ctx" restore/existing_dir || framework_failure_ # Copy and ensure existing directories updated cp -a backup/. restore/ -ls -Zd restore/existing_dir | grep $ctx && +ls -Zd restore/existing_dir > ed_ctx || fail=1 +grep $ctx ed_ctx && { ls -lZd restore/existing_dir; fail=1; } # Check restorecon (-Z) functionality for file and directory @@ -64,7 +66,7 @@ get_selinux_type() { ls -Zd "$1" | sed -n 's/.*:\(.*_t\):.*/\1/p'; } # Also make a dir with our known context mkdir c_d || framework_failure_ chcon $ctx c_d || framework_failure_ -# Get the type of this known context for file and dir +# Get the type of this known context for file and dir for tracing old_type_f=$(get_selinux_type c) old_type_d=$(get_selinux_type c_d) # Setup copies for manipulation with restorecon @@ -80,7 +82,7 @@ if restorecon Z1 Z1_d 2>/dev/null; then cpZ_type_f=$(get_selinux_type Z2) test "$cpZ_type_f" = "$new_type_f" || fail=1 - # Ensuze -Z overrides -a and that dirs are handled too + # Ensure -Z overrides -a and that dirs are handled too cp -aZ c Z3 || fail=1 cp -aZ c_d Z3_d || fail=1 cpaZ_type_f=$(get_selinux_type Z3) @@ -175,6 +177,7 @@ for no_g_cmd in '' 'rm -f g'; do # restorecon equivalent. Note even though the context # returned from matchpathcon() will not match $ctx # the resulting ENOTSUP warning will be suppressed. + # With absolute path $no_g_cmd cp -Z ../f $(realpath g) || fail=1 @@ -186,7 +189,7 @@ for no_g_cmd in '' 'rm -f g'; do cp -Z -a ../f g || fail=1 # -Z doesn't take an arg $no_g_cmd - cp -Z "$ctx" ../f g && fail=1 + returns_ 1 cp -Z "$ctx" ../f g || fail=1 # Explicit context $no_g_cmd @@ -197,9 +200,9 @@ for no_g_cmd in '' 'rm -f g'; do cp -a --context="$ctx" ../f g || fail=1 done -# Mutually exlusive options -cp -Z --preserve=context ../f g && fail=1 -cp --preserve=context -Z ../f g && fail=1 -cp --preserve=context --context="$ctx" ../f g && fail=1 +# Mutually exclusive options +returns_ 1 cp -Z --preserve=context ../f g || fail=1 +returns_ 1 cp --preserve=context -Z ../f g || fail=1 +returns_ 1 cp --preserve=context --context="$ctx" ../f g || fail=1 Exit $fail diff --git a/tests/cp/cp-deref.sh b/tests/cp/cp-deref.sh index 63a1c22d..7de56e44 100755 --- a/tests/cp/cp-deref.sh +++ b/tests/cp/cp-deref.sh @@ -2,7 +2,7 @@ # cp -RL dir1 dir2' must handle the case in which each of dir1 and dir2 # contain a symlink pointing to some third directory. -# Copyright (C) 2006-2014 Free Software Foundation, Inc. +# Copyright (C) 2006-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/cp/cp-i.sh b/tests/cp/cp-i.sh index 9f2905e6..e7414130 100755 --- a/tests/cp/cp-i.sh +++ b/tests/cp/cp-i.sh @@ -1,7 +1,7 @@ #!/bin/sh # Test whether cp -i prompts in the right place. -# Copyright (C) 2006-2014 Free Software Foundation, Inc. +# Copyright (C) 2006-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -60,6 +60,6 @@ echo n | cp -vnf c d 2>/dev/null > out7 || fail=1 compare out7 out_empty || fail=1 # options --backup and --no-clobber are mutually exclusive -cp -bn c d 2>/dev/null && fail=1 +returns_ 1 cp -bn c d 2>/dev/null || fail=1 Exit $fail diff --git a/tests/cp/cp-mv-backup.sh b/tests/cp/cp-mv-backup.sh index e313b72c..15695f19 100755 --- a/tests/cp/cp-mv-backup.sh +++ b/tests/cp/cp-mv-backup.sh @@ -1,7 +1,7 @@ #!/bin/sh # Test basic --backup functionality for both cp and mv. -# Copyright (C) 1999-2014 Free Software Foundation, Inc. +# Copyright (C) 1999-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/cp/cp-mv-enotsup-xattr.sh b/tests/cp/cp-mv-enotsup-xattr.sh index f46977b6..13f477d6 100755 --- a/tests/cp/cp-mv-enotsup-xattr.sh +++ b/tests/cp/cp-mv-enotsup-xattr.sh @@ -3,7 +3,7 @@ # as expected on file system without their support and do show correct # diagnostics when required -# Copyright (C) 2009-2014 Free Software Foundation, Inc. +# Copyright (C) 2009-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/cp/cp-parents.sh b/tests/cp/cp-parents.sh index e326d6bd..f0454f71 100755 --- a/tests/cp/cp-parents.sh +++ b/tests/cp/cp-parents.sh @@ -2,7 +2,7 @@ # cp -R --parents dir-specified-with-trailing-slash/ other-dir # would get a failed assertion. -# Copyright (C) 2000-2014 Free Software Foundation, Inc. +# Copyright (C) 2000-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -42,7 +42,7 @@ test -d d/a/b/c || fail=1 # With 6.7 and earlier, cp --parents f/g d would mistakenly create a # directory d/f, even though f is a regular file. -cp --parents f/g d 2>/dev/null && fail=1 +returns_ 1 cp --parents f/g d 2>/dev/null || fail=1 test -d d/f && fail=1 # Check that re_protect works. diff --git a/tests/cp/deref-slink.sh b/tests/cp/deref-slink.sh index b81997be..8e094ff2 100755 --- a/tests/cp/deref-slink.sh +++ b/tests/cp/deref-slink.sh @@ -2,7 +2,7 @@ # Demonstrate bug when using -d with an existing destination file # that is a symlink. -# Copyright (C) 2000-2014 Free Software Foundation, Inc. +# Copyright (C) 2000-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/cp/dir-rm-dest.sh b/tests/cp/dir-rm-dest.sh index 2723631d..e9e79937 100755 --- a/tests/cp/dir-rm-dest.sh +++ b/tests/cp/dir-rm-dest.sh @@ -1,7 +1,7 @@ #!/bin/sh # verify that cp's --remove-destination option works with -R -# Copyright (C) 2000-2014 Free Software Foundation, Inc. +# Copyright (C) 2000-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/cp/dir-slash.sh b/tests/cp/dir-slash.sh index 42bf0696..0042de94 100755 --- a/tests/cp/dir-slash.sh +++ b/tests/cp/dir-slash.sh @@ -2,7 +2,7 @@ # Make sure that cp -R DIR1 DIR2 does the right thing # when DIR1 is written with a trailing slash. -# Copyright (C) 2000-2014 Free Software Foundation, Inc. +# Copyright (C) 2000-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/cp/dir-vs-file.sh b/tests/cp/dir-vs-file.sh index 5398656e..8ac159c0 100755 --- a/tests/cp/dir-vs-file.sh +++ b/tests/cp/dir-vs-file.sh @@ -1,7 +1,7 @@ #!/bin/sh # A directory may not replace an existing file. -# Copyright (C) 2001-2014 Free Software Foundation, Inc. +# Copyright (C) 2001-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -24,7 +24,7 @@ touch file || framework_failure_ # In 4.0.35, this cp invocation silently succeeded. -cp -R dir file 2>/dev/null && fail=1 +returns_ 1 cp -R dir file 2>/dev/null || fail=1 # Make sure file is not replaced with a directory. # In 4.0.35, it was. diff --git a/tests/cp/duplicate-sources.sh b/tests/cp/duplicate-sources.sh new file mode 100755 index 00000000..3b9e0cc1 --- /dev/null +++ b/tests/cp/duplicate-sources.sh @@ -0,0 +1,44 @@ +#!/bin/sh +# Ensure cp warns about but otherwise ignores source +# items specified multiple times. + +# Copyright (C) 2014-2015 Free Software Foundation, Inc. + +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. + +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. + +. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src +print_ver_ cp + +mkdir a || framework_failure_ +touch f || framework_failure_ + +# verify multiple files and dir sources only warned about +mkdir dest || framework_failure_ +cp -a a a f f dest 2>err || fail=1 +rm -Rf dest || framework_failure_ + +# verify multiple dirs and files with different names copied +mkdir dest || framework_failure_ +ln -s a al || framework_failure_ +ln -s f fl || framework_failure_ +cp -aH a al f fl dest 2>>err || fail=1 + +cat <<EOF >exp +cp: warning: source directory 'a' specified more than once +cp: warning: source file 'f' specified more than once +EOF + +compare exp err || fail=1 + +Exit $fail diff --git a/tests/cp/existing-perm-dir.sh b/tests/cp/existing-perm-dir.sh index 46f1be0d..b56041b1 100755 --- a/tests/cp/existing-perm-dir.sh +++ b/tests/cp/existing-perm-dir.sh @@ -1,7 +1,7 @@ #!/bin/sh # Make sure cp -p doesn't "restore" permissions it shouldn't (Bug#9170). -# Copyright 2011-2014 Free Software Foundation, Inc. +# Copyright 2011-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/cp/existing-perm-race.sh b/tests/cp/existing-perm-race.sh index c12cbb85..f48369cd 100755 --- a/tests/cp/existing-perm-race.sh +++ b/tests/cp/existing-perm-race.sh @@ -1,7 +1,7 @@ #!/bin/sh # Make sure cp -p isn't too generous with existing file permissions. -# Copyright (C) 2006-2014 Free Software Foundation, Inc. +# Copyright (C) 2006-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -37,10 +37,12 @@ chgrp $g1 fifo && chgrp $g2 fifo-copy && chmod g+r fifo-copy || framework-failure +# Terminate any background cp process +cleanup_() { kill $pid 2>/dev/null && wait $pid; } + # Copy a fifo's contents. That way, we can examine the # destination permissions before they're finalized. -cp -p --copy-contents fifo fifo-copy & -cp_pid=$! +cp -p --copy-contents fifo fifo-copy & pid=$! ( # Now 'cp' is reading the fifo. Wait for the destination file to @@ -77,7 +79,7 @@ case $mode in *) fail=1;; esac -wait $cp_pid || fail=1 +wait $pid || fail=1 # Check that the final mode and group are right. ls -l -n fifo-copy >ls.out && diff --git a/tests/cp/fail-perm.sh b/tests/cp/fail-perm.sh index 83518417..6a9cc880 100755 --- a/tests/cp/fail-perm.sh +++ b/tests/cp/fail-perm.sh @@ -1,6 +1,6 @@ #!/bin/sh -# Copyright (C) 2000-2014 Free Software Foundation, Inc. +# Copyright (C) 2000-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -27,7 +27,7 @@ chmod u=rx,go=,-st D || framework_failure_ # This is expected to exit non-zero, because it can't read D/a. -cp -pR D DD > /dev/null 2>&1 && fail=1 +returns_ 1 cp -pR D DD > /dev/null 2>&1 || fail=1 # Permissions on DD must be 'dr-x------' diff --git a/tests/cp/fiemap-2.sh b/tests/cp/fiemap-2.sh index 79e2c1c4..054be5f8 100755 --- a/tests/cp/fiemap-2.sh +++ b/tests/cp/fiemap-2.sh @@ -1,7 +1,7 @@ #!/bin/sh # Exercise a few more corners of the fiemap-copying code. -# Copyright (C) 2011-2014 Free Software Foundation, Inc. +# Copyright (C) 2011-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/cp/fiemap-FMR.sh b/tests/cp/fiemap-FMR.sh index 7c9e3198..96cc3bd2 100755 --- a/tests/cp/fiemap-FMR.sh +++ b/tests/cp/fiemap-FMR.sh @@ -1,7 +1,7 @@ #!/bin/sh # Trigger a free-memory read bug in cp from coreutils-[8.11..8.19] -# Copyright (C) 2012-2014 Free Software Foundation, Inc. +# Copyright (C) 2012-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/cp/fiemap-empty.sh b/tests/cp/fiemap-empty.sh index 34aec424..b3b2cd72 100755 --- a/tests/cp/fiemap-empty.sh +++ b/tests/cp/fiemap-empty.sh @@ -1,7 +1,7 @@ #!/bin/sh # Test cp reads unwritten extents efficiently -# Copyright (C) 2011-2014 Free Software Foundation, Inc. +# Copyright (C) 2011-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -22,6 +22,7 @@ print_ver_ cp # FIXME: enable any part of this test that is still relevant, # or, if none are relevant (now that cp does not handle unwritten # extents), just remove the test altogether. +# Note also if checking allocations may need to sync first on BTRFS at least skip_ 'disabled for now' touch fiemap_chk diff --git a/tests/cp/fiemap-perf.sh b/tests/cp/fiemap-perf.sh index 10bb7324..5517ad0c 100755 --- a/tests/cp/fiemap-perf.sh +++ b/tests/cp/fiemap-perf.sh @@ -1,7 +1,7 @@ #!/bin/sh # ensure that a sparse file is copied efficiently, by default -# Copyright (C) 2011-2014 Free Software Foundation, Inc. +# Copyright (C) 2011-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -35,7 +35,7 @@ timeout 10 truncate -s1T f || # Disable this test on old BTRFS (e.g. Fedora 14) # which reports (unwritten) extents for holes. -filefrag f || skip_ 'the 'filefrag' utility is missing' +filefrag f || skip_ "the 'filefrag' utility is missing" filefrag f | grep -F ': 0 extents found' > /dev/null || skip_ 'this file system reports extents for holes' diff --git a/tests/cp/file-perm-race.sh b/tests/cp/file-perm-race.sh index 5a01675c..8197962d 100755 --- a/tests/cp/file-perm-race.sh +++ b/tests/cp/file-perm-race.sh @@ -1,7 +1,7 @@ #!/bin/sh # Make sure cp -p isn't too generous with file permissions. -# Copyright (C) 2006-2014 Free Software Foundation, Inc. +# Copyright (C) 2006-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -25,10 +25,12 @@ require_local_dir_ umask 022 mkfifo_or_skip_ fifo +# Terminate any background cp process +cleanup_() { kill $pid 2>/dev/null && wait $pid; } + # Copy a fifo's contents. That way, we can examine the # destination permissions before they're finalized. -cp -p --copy-contents fifo fifo-copy & -cp_pid=$! +cp -p --copy-contents fifo fifo-copy & pid=$! ( # Now 'cp' is reading the fifo. Wait for the destination file to @@ -51,6 +53,6 @@ case $(cat ls.out) in *) fail=1;; esac -wait $cp_pid || fail=1 +wait $pid || fail=1 Exit $fail diff --git a/tests/cp/into-self.sh b/tests/cp/into-self.sh index 124be241..6799d659 100755 --- a/tests/cp/into-self.sh +++ b/tests/cp/into-self.sh @@ -1,7 +1,7 @@ #!/bin/sh # Confirm that copying a directory into itself gets a proper diagnostic. -# Copyright (C) 2001-2014 Free Software Foundation, Inc. +# Copyright (C) 2001-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/cp/link-deref.sh b/tests/cp/link-deref.sh index 1b666589..b0efb6f8 100755 --- a/tests/cp/link-deref.sh +++ b/tests/cp/link-deref.sh @@ -1,7 +1,7 @@ #!/bin/sh # Exercise cp --link's behavior regarding the dereferencing of symbolic links. -# Copyright (C) 2013-2014 Free Software Foundation, Inc. +# Copyright (C) 2013-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -19,7 +19,8 @@ . "${srcdir=.}/tests/init.sh"; path_prepend_ ./src print_ver_ cp -if grep '^#define HAVE_LINKAT 1' "$CONFIG_HEADER" > /dev/null \ +if { grep '^#define HAVE_LINKAT 1' "$CONFIG_HEADER" > /dev/null \ + && grep '#undef LINKAT_SYMLINK_NOTSUP' "$CONFIG_HEADER" > /dev/null; } \ || grep '^#define LINK_FOLLOWS_SYMLINKS 0' "$CONFIG_HEADER" > /dev/null; then # With this config cp will attempt to linkat() to hardlink a symlink. # So now double check the current file system supports this operation. diff --git a/tests/cp/link-heap.sh b/tests/cp/link-heap.sh index 594ade89..901a92fc 100755 --- a/tests/cp/link-heap.sh +++ b/tests/cp/link-heap.sh @@ -1,7 +1,7 @@ #!/bin/sh # ensure that cp --preserve=link --link doesn't waste heap -# Copyright (C) 2008-2014 Free Software Foundation, Inc. +# Copyright (C) 2008-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/cp/link-no-deref.sh b/tests/cp/link-no-deref.sh index 13fd0ef5..582ea5a3 100755 --- a/tests/cp/link-no-deref.sh +++ b/tests/cp/link-no-deref.sh @@ -1,7 +1,7 @@ #!/bin/sh # Ensure that cp --link --no-dereference works properly -# Copyright (C) 2006-2014 Free Software Foundation, Inc. +# Copyright (C) 2006-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/cp/link-preserve.sh b/tests/cp/link-preserve.sh index c2cfd4ae..00ebe15c 100755 --- a/tests/cp/link-preserve.sh +++ b/tests/cp/link-preserve.sh @@ -2,7 +2,7 @@ # ensure that 'cp -d' preserves hard-links between command line arguments # ensure that --preserve=links works with -RH and -RL -# Copyright (C) 2001-2014 Free Software Foundation, Inc. +# Copyright (C) 2001-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/cp/link-symlink.sh b/tests/cp/link-symlink.sh index 9aab0b85..6bdc9f59 100755 --- a/tests/cp/link-symlink.sh +++ b/tests/cp/link-symlink.sh @@ -1,7 +1,7 @@ #!/bin/sh # Ensure that cp -a --link maintains timestamps if possible -# Copyright (C) 2011-2014 Free Software Foundation, Inc. +# Copyright (C) 2011-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/cp/link.sh b/tests/cp/link.sh index 034a6275..b7917016 100755 --- a/tests/cp/link.sh +++ b/tests/cp/link.sh @@ -2,7 +2,7 @@ # Make sure cp --link -f works when the target exists. # This failed for 4.0z (due to a bug introduced in that test release). -# Copyright (C) 2000-2014 Free Software Foundation, Inc. +# Copyright (C) 2000-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/cp/nfs-removal-race.sh b/tests/cp/nfs-removal-race.sh index 6969e8bd..fdac03f7 100755 --- a/tests/cp/nfs-removal-race.sh +++ b/tests/cp/nfs-removal-race.sh @@ -13,7 +13,7 @@ # This test is skipped on systems that lack LD_PRELOAD support; that's fine. # Similarly, on a system that lacks <dlfcn.h> or __xstat, skipping it is fine. -# Copyright (C) 2012-2014 Free Software Foundation, Inc. +# Copyright (C) 2012-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -35,6 +35,7 @@ require_gcc_shared_ # Replace each stat call with a call to this wrapper. cat > k.c <<'EOF' || framework_failure_ #define _GNU_SOURCE +#include <stdio.h> #include <sys/types.h> #include <dlfcn.h> @@ -49,6 +50,7 @@ int __xstat (int ver, const char *path, struct stat *st) { static int (*real_stat)(int ver, const char *path, struct stat *st) = NULL; + fclose(fopen("preloaded", "w")); if (!real_stat) real_stat = dlsym (RTLD_NEXT, "__xstat"); /* When asked to stat nonexistent "d", @@ -65,7 +67,9 @@ touch d2 || framework_failure_ echo xyz > src || framework_failure_ # Finally, run the test: -LD_PRELOAD=./k.so cp src d || fail=1 +LD_PRELOAD=$LD_PRELOAD:./k.so cp src d || fail=1 + +test -f preloaded || skip_ 'LD_PRELOAD was ineffective?' compare src d || fail=1 Exit $fail diff --git a/tests/cp/no-ctx.sh b/tests/cp/no-ctx.sh index 8b1328a4..852b8e64 100755 --- a/tests/cp/no-ctx.sh +++ b/tests/cp/no-ctx.sh @@ -4,7 +4,7 @@ # This test is skipped on systems that lack LD_PRELOAD support; that's fine. # Similarly, on a system that lacks lgetfilecon altogether, skipping it is fine. -# Copyright (C) 2014 Free Software Foundation, Inc. +# Copyright (C) 2014-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -50,14 +50,15 @@ gcc_shared_ k.c k.so \ touch file_src # New file with SELinux context optionally included -LD_PRELOAD=./k.so cp -a file_src file_dst || fail=1 +LD_PRELOAD=$LD_PRELOAD:./k.so cp -a file_src file_dst || fail=1 # Existing file with SELinux context optionally included -LD_PRELOAD=./k.so cp -a file_src file_dst || fail=1 +LD_PRELOAD=$LD_PRELOAD:./k.so cp -a file_src file_dst || fail=1 # ENODATA should give an immediate error when required to preserve ctx # This is debatable, and maybe we should not fail when no context available? -LD_PRELOAD=./k.so cp --preserve=context file_src file_dst && fail=1 +( export LD_PRELOAD=$LD_PRELOAD:./k.so + returns_ 1 cp --preserve=context file_src file_dst ) || fail=1 test -e preloaded || skip_ 'LD_PRELOAD interception failed' diff --git a/tests/cp/no-deref-link1.sh b/tests/cp/no-deref-link1.sh index 50a94d37..7206b24b 100755 --- a/tests/cp/no-deref-link1.sh +++ b/tests/cp/no-deref-link1.sh @@ -1,7 +1,7 @@ #!/bin/sh # cp from 3.16 fails this test -# Copyright (C) 1997-2014 Free Software Foundation, Inc. +# Copyright (C) 1997-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/cp/no-deref-link2.sh b/tests/cp/no-deref-link2.sh index cf07bf9e..87ab74c3 100755 --- a/tests/cp/no-deref-link2.sh +++ b/tests/cp/no-deref-link2.sh @@ -1,7 +1,7 @@ #!/bin/sh # cp from 3.16 fails this test -# Copyright (C) 1997-2014 Free Software Foundation, Inc. +# Copyright (C) 1997-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/cp/no-deref-link3.sh b/tests/cp/no-deref-link3.sh index a8416855..ea69e217 100755 --- a/tests/cp/no-deref-link3.sh +++ b/tests/cp/no-deref-link3.sh @@ -1,7 +1,7 @@ #!/bin/sh # cp from 3.16 fails this test -# Copyright (C) 1997-2014 Free Software Foundation, Inc. +# Copyright (C) 1997-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/cp/parent-perm-race.sh b/tests/cp/parent-perm-race.sh index b7ea9143..c370f9e0 100755 --- a/tests/cp/parent-perm-race.sh +++ b/tests/cp/parent-perm-race.sh @@ -1,7 +1,7 @@ #!/bin/sh # Make sure cp -pR --parents isn't too generous with parent permissions. -# Copyright (C) 2006-2014 Free Software Foundation, Inc. +# Copyright (C) 2006-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -26,6 +26,8 @@ umask 002 mkdir mode ownership d || framework_failure_ chmod g+s d 2>/dev/null # The cp test is valid either way. +# Terminate any background cp process +cleanup_() { kill $pid 2>/dev/null && wait $pid; } for attr in mode ownership do @@ -33,8 +35,7 @@ do # Copy a fifo's contents. That way, we can examine d/$attr's # state while cp is running. - cp --preserve=$attr -R --copy-contents --parents $attr d & - cp_pid=$! + cp --preserve=$attr -R --copy-contents --parents $attr d & pid=$! ( # Now 'cp' is reading the fifo. @@ -58,7 +59,7 @@ do fail=1;; esac - wait $cp_pid || fail=1 + wait $pid || fail=1 done Exit $fail diff --git a/tests/cp/parent-perm.sh b/tests/cp/parent-perm.sh index 0a9c41e0..3b557b6d 100755 --- a/tests/cp/parent-perm.sh +++ b/tests/cp/parent-perm.sh @@ -1,7 +1,7 @@ #!/bin/sh # Ensure that cp --parents works properly with a preexisting dest. directory -# Copyright (C) 2008-2014 Free Software Foundation, Inc. +# Copyright (C) 2008-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/cp/perm.sh b/tests/cp/perm.sh index 8311cd21..a8b87977 100755 --- a/tests/cp/perm.sh +++ b/tests/cp/perm.sh @@ -1,7 +1,7 @@ #!/bin/sh # Make sure the permission-preserving code in copy.c (mv, cp, install) works. -# Copyright (C) 2000-2014 Free Software Foundation, Inc. +# Copyright (C) 2000-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/cp/preserve-2.sh b/tests/cp/preserve-2.sh index ac2fcf6a..9918e119 100755 --- a/tests/cp/preserve-2.sh +++ b/tests/cp/preserve-2.sh @@ -1,7 +1,7 @@ #!/bin/sh # ensure that cp's --preserve=X,Y option is parsed properly -# Copyright (C) 2002-2014 Free Software Foundation, Inc. +# Copyright (C) 2002-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/cp/preserve-gid.sh b/tests/cp/preserve-gid.sh index f141ac14..89b88575 100755 --- a/tests/cp/preserve-gid.sh +++ b/tests/cp/preserve-gid.sh @@ -1,7 +1,7 @@ #!/bin/sh # Verify that cp -p preserves GID when it is possible. -# Copyright (C) 2007-2014 Free Software Foundation, Inc. +# Copyright (C) 2007-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -117,7 +117,8 @@ t1() { u=$1; shift g=$1; shift t0 "$f" "$u" "$g" \ - chroot --user=+$nameless_uid:+$nameless_gid1 \ + chroot --skip-chdir \ + --user=+$nameless_uid:+$nameless_gid1 \ --groups="+$nameless_gid1,+$nameless_gid2" \ / env PATH="$tmp_path" "$@" } diff --git a/tests/cp/preserve-link.sh b/tests/cp/preserve-link.sh index b7e4aa28..b0eb7de7 100755 --- a/tests/cp/preserve-link.sh +++ b/tests/cp/preserve-link.sh @@ -1,7 +1,7 @@ #!/bin/sh # Exercise the fix for http://debbugs.gnu.org/8419 -# Copyright (C) 2011-2014 Free Software Foundation, Inc. +# Copyright (C) 2011-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/cp/preserve-mode.sh b/tests/cp/preserve-mode.sh index 3b36defc..c86c5503 100755 --- a/tests/cp/preserve-mode.sh +++ b/tests/cp/preserve-mode.sh @@ -1,7 +1,7 @@ #!/bin/sh # ensure that cp's --no-preserve=mode works correctly -# Copyright (C) 2002-2014 Free Software Foundation, Inc. +# Copyright (C) 2002-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/cp/preserve-slink-time.sh b/tests/cp/preserve-slink-time.sh index c6c3548f..68114fa8 100755 --- a/tests/cp/preserve-slink-time.sh +++ b/tests/cp/preserve-slink-time.sh @@ -1,7 +1,7 @@ #!/bin/sh # Verify that cp -Pp preserves times even on symlinks. -# Copyright (C) 2009-2014 Free Software Foundation, Inc. +# Copyright (C) 2009-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/cp/proc-short-read.sh b/tests/cp/proc-short-read.sh index bd665620..5dbf8fd5 100755 --- a/tests/cp/proc-short-read.sh +++ b/tests/cp/proc-short-read.sh @@ -1,7 +1,7 @@ #!/bin/sh # exercise cp's short-read failure when operating on >4KB files in /proc -# Copyright (C) 2009-2014 Free Software Foundation, Inc. +# Copyright (C) 2009-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/cp/proc-zero-len.sh b/tests/cp/proc-zero-len.sh index 3fcd5aab..33006b14 100755 --- a/tests/cp/proc-zero-len.sh +++ b/tests/cp/proc-zero-len.sh @@ -1,7 +1,7 @@ #!/bin/sh # Ensure that cp copies contents of non-empty "regular" file with st_size==0 -# Copyright (C) 2007-2014 Free Software Foundation, Inc. +# Copyright (C) 2007-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -31,7 +31,7 @@ cat $f > out || fail=1 # number of the file changed during the cp run. cp $f exp 2>err \ || { fail=1; - grep 'replaced while being copied' \ + grep 'replaced while being copied' err \ && skip_ "File $f is being replaced while being copied"; } # Don't simply compare contents; they might differ, diff --git a/tests/cp/r-vs-symlink.sh b/tests/cp/r-vs-symlink.sh index 9398c9b4..bc2ef360 100755 --- a/tests/cp/r-vs-symlink.sh +++ b/tests/cp/r-vs-symlink.sh @@ -1,7 +1,7 @@ #!/bin/sh # cp -r should not create symlinks. Fixed in fileutils-4.1.5. -# Copyright (C) 2001-2014 Free Software Foundation, Inc. +# Copyright (C) 2001-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/cp/reflink-auto.sh b/tests/cp/reflink-auto.sh index a16fdc66..b0464a2e 100755 --- a/tests/cp/reflink-auto.sh +++ b/tests/cp/reflink-auto.sh @@ -1,7 +1,7 @@ #!/bin/sh # Test cp --reflink=auto -# Copyright (C) 2009-2014 Free Software Foundation, Inc. +# Copyright (C) 2009-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -27,7 +27,7 @@ rm -f "$a_other" || framework_failure_ echo non_zero_size > "$a_other" || framework_failure_ # we shouldn't be able to reflink() files on separate partitions -cp --reflink "$a_other" b && fail=1 +returns_ 1 cp --reflink "$a_other" b || fail=1 # --reflink=auto should fall back to a normal copy cp --reflink=auto "$a_other" b || fail=1 diff --git a/tests/cp/reflink-perm.sh b/tests/cp/reflink-perm.sh index 52f5e257..7160f46d 100755 --- a/tests/cp/reflink-perm.sh +++ b/tests/cp/reflink-perm.sh @@ -1,7 +1,7 @@ #!/bin/sh # Test cp --reflink copies permissions -# Copyright (C) 2009-2014 Free Software Foundation, Inc. +# Copyright (C) 2009-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/cp/same-file.sh b/tests/cp/same-file.sh index f62a9a72..47c6507c 100755 --- a/tests/cp/same-file.sh +++ b/tests/cp/same-file.sh @@ -2,7 +2,7 @@ # Test some of cp's options and how cp handles situations in # which a naive implementation might overwrite the source file. -# Copyright (C) 1998-2014 Free Software Foundation, Inc. +# Copyright (C) 1998-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -36,7 +36,7 @@ ln dangling-slink hard-link > /dev/null 2>&1 \ rm -f no-such dangling-slink hard-link test $hard_link_to_symlink_does_the_deref = yes \ - && remove_these_sed='/^0 -[bf]*l .*sl1 ->/d' \ + && remove_these_sed='/^0 -[bf]*l .*sl1 ->/d; /hlsl/d' \ || remove_these_sed='/^ELIDE NO TEST OUTPUT/d' exec 3>&1 1> actual @@ -44,7 +44,8 @@ exec 3>&1 1> actual # FIXME: This should be bigger: like more than 8k contents=XYZ -for args in 'foo symlink' 'symlink foo' 'foo foo' 'sl1 sl2' 'foo hardlink'; do +for args in 'foo symlink' 'symlink foo' 'foo foo' 'sl1 sl2' \ + 'foo hardlink' 'hlsl sl2'; do for options in '' -d -f -df --rem -b -bd -bf -bdf \ -l -dl -fl -dfl -bl -bdl -bfl -bdfl; do case $args$options in @@ -76,6 +77,8 @@ for args in 'foo symlink' 'symlink foo' 'foo foo' 'sl1 sl2' 'foo hardlink'; do continue ;; 'yes:sl1 sl2:-bfl') continue ;; + yes:hlsl*) + continue ;; esac rm -rf dir @@ -86,6 +89,7 @@ for args in 'foo symlink' 'symlink foo' 'foo foo' 'sl1 sl2' 'foo hardlink'; do case "$args" in *hardlink*) ln foo hardlink ;; esac case "$args" in *sl1*) ln -s foo sl1;; esac case "$args" in *sl2*) ln -s foo sl2;; esac + case "$args" in *hlsl*) ln sl2 hlsl;; esac ( ( # echo 1>&2 cp $options $args @@ -211,6 +215,24 @@ cat <<\EOF | sed "$remove_these_sed" > expected 0 -bfl (foo hardlink) 0 -bdfl (foo hardlink) +1 [cp: 'hlsl' and 'sl2' are the same file] (foo hlsl -> foo sl2 -> foo) +0 -d (foo hlsl -> foo sl2 -> foo) +1 -f [cp: 'hlsl' and 'sl2' are the same file] (foo hlsl -> foo sl2 -> foo) +0 -df (foo hlsl -> foo sl2 -> foo) +0 --rem (foo hlsl -> foo sl2) +0 -b (foo hlsl -> foo sl2 sl2.~1~ -> foo) +0 -bd (foo hlsl -> foo sl2 -> foo sl2.~1~ -> foo) +0 -bf (foo hlsl -> foo sl2 sl2.~1~ -> foo) +0 -bdf (foo hlsl -> foo sl2 -> foo sl2.~1~ -> foo) +1 -l [cp: cannot create hard link 'sl2' to 'hlsl'] (foo hlsl -> foo sl2 -> foo) +0 -dl (foo hlsl -> foo sl2 -> foo) +0 -fl (foo hlsl -> foo sl2) +0 -dfl (foo hlsl -> foo sl2 -> foo) +0 -bl (foo hlsl -> foo sl2 sl2.~1~ -> foo) +0 -bdl (foo hlsl -> foo sl2 -> foo) +0 -bfl (foo hlsl -> foo sl2 sl2.~1~ -> foo) +0 -bdfl (foo hlsl -> foo sl2 -> foo) + EOF exec 1>&3 3>&- diff --git a/tests/cp/slink-2-slink.sh b/tests/cp/slink-2-slink.sh index 19a28621..65cce9e6 100755 --- a/tests/cp/slink-2-slink.sh +++ b/tests/cp/slink-2-slink.sh @@ -2,7 +2,7 @@ # 'test cp --update A B' where A and B are both symlinks that point # to the same file -# Copyright (C) 2000-2014 Free Software Foundation, Inc. +# Copyright (C) 2000-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/cp/sparse-fiemap.sh b/tests/cp/sparse-fiemap.sh index 7aa24715..ac6ea3c7 100755 --- a/tests/cp/sparse-fiemap.sh +++ b/tests/cp/sparse-fiemap.sh @@ -1,7 +1,7 @@ #!/bin/sh # Test cp --sparse=always through fiemap copy -# Copyright (C) 2010-2014 Free Software Foundation, Inc. +# Copyright (C) 2010-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/cp/sparse-to-pipe.sh b/tests/cp/sparse-to-pipe.sh index b800e069..2c3dcefb 100755 --- a/tests/cp/sparse-to-pipe.sh +++ b/tests/cp/sparse-to-pipe.sh @@ -1,7 +1,7 @@ #!/bin/sh # copy a sparse file to a pipe, to exercise some seldom-used parts of copy.c -# Copyright (C) 2011-2014 Free Software Foundation, Inc. +# Copyright (C) 2011-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -21,14 +21,17 @@ print_ver_ cp require_sparse_support_ +# Terminate any background cp process +cleanup_() { kill $pid 2>/dev/null && wait $pid; } + mkfifo_or_skip_ pipe -timeout 10 cat pipe > copy & +timeout 10 cat pipe > copy & pid=$! truncate -s1M sparse || framework_failure_ cp sparse pipe || fail=1 # Ensure that the cat has completed before comparing. -wait +wait $pid cmp sparse copy || fail=1 diff --git a/tests/cp/sparse.sh b/tests/cp/sparse.sh index d6cc4c4b..958de830 100755 --- a/tests/cp/sparse.sh +++ b/tests/cp/sparse.sh @@ -1,7 +1,7 @@ #!/bin/sh # Test cp --sparse=always -# Copyright (C) 2006-2014 Free Software Foundation, Inc. +# Copyright (C) 2006-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -34,7 +34,40 @@ cp --sparse=always sparse copy || fail=1 test $(stat --printf %b copy) -le $(stat --printf %b sparse) || fail=1 # Ensure that --sparse={always,never} with --reflink fail. -cp --sparse=always --reflink sparse copy && fail=1 -cp --sparse=never --reflink sparse copy && fail=1 +returns_ 1 cp --sparse=always --reflink sparse copy || fail=1 +returns_ 1 cp --sparse=never --reflink sparse copy || fail=1 + + +# Ensure we handle sparse/non-sparse transitions correctly +maxn=128 # how many $hole_size chunks per file +hole_size=$(stat -c %o copy) +dd if=/dev/zero bs=$hole_size count=$maxn of=zeros || framework_failure_ +tr '\0' 'U' < zeros > nonzero || framework_failure_ + +for pattern in 1 0; do + test "$pattern" = 1 && pattern="$(printf '%s\n%s' nonzero zeros)" + test "$pattern" = 0 && pattern="$(printf '%s\n%s' zeros nonzero)" + + for n in 1 2 4 11 32 $maxn; do + parts=$(expr $maxn / $n) + + rm -f sparse.in + + # Generate non sparse file for copying with alternating + # hole/data patterns of size n * $hole_size + for i in $(yes "$pattern" | head -n$parts); do + dd iflag=fullblock if=$i of=sparse.in conv=notrunc oflag=append \ + bs=$hole_size count=$n status=none || framework_failure_ + done + + cp --sparse=always sparse.in sparse.out || fail=1 # non sparse input + cp --sparse=always sparse.out sparse.out2 || fail=1 # sparse input + + cmp sparse.in sparse.out || fail=1 + cmp sparse.in sparse.out2 || fail=1 + + ls -lsh sparse.* + done +done Exit $fail diff --git a/tests/cp/special-bits.sh b/tests/cp/special-bits.sh index a55eea21..ec17ccec 100755 --- a/tests/cp/special-bits.sh +++ b/tests/cp/special-bits.sh @@ -2,7 +2,7 @@ # make sure 'cp -p' preserves special bits # This works only when run as root. -# Copyright (C) 2000-2014 Free Software Foundation, Inc. +# Copyright (C) 2000-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -42,7 +42,8 @@ set _ $(ls -l b); shift; p1=$1 set _ $(ls -l b2); shift; p2=$1 test $p1 = $p2 || fail=1 -chroot --user=$NON_ROOT_USERNAME / env PATH="$PATH" cp -p c c2 || fail=1 +chroot --skip-chdir --user=$NON_ROOT_USERNAME / env PATH="$PATH" cp -p c c2 \ + || fail=1 set _ $(ls -l c); shift; p1=$1 set _ $(ls -l c2); shift; p2=$1 test $p1 = $p2 && fail=1 diff --git a/tests/cp/special-f.sh b/tests/cp/special-f.sh index ee01bb33..2217c675 100755 --- a/tests/cp/special-f.sh +++ b/tests/cp/special-f.sh @@ -2,7 +2,7 @@ # Ensure that "cp -Rf fifo E" unlinks E and retries. # Up until coreutils-6.10.171, it would not. -# Copyright (C) 2008-2014 Free Software Foundation, Inc. +# Copyright (C) 2008-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/cp/src-base-dot.sh b/tests/cp/src-base-dot.sh index 599f4cdc..75aa62e0 100755 --- a/tests/cp/src-base-dot.sh +++ b/tests/cp/src-base-dot.sh @@ -1,7 +1,7 @@ #!/bin/sh # Ensure that "mkdir x y; cd y; cp -ab ../x/. ." is a successful, silent, no-op. -# Copyright (C) 2006-2014 Free Software Foundation, Inc. +# Copyright (C) 2006-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/cp/symlink-slash.sh b/tests/cp/symlink-slash.sh index 1ae846b6..ee70b77e 100755 --- a/tests/cp/symlink-slash.sh +++ b/tests/cp/symlink-slash.sh @@ -2,7 +2,7 @@ # Make sure that cp -dR dereferences a symlink arg if its name is # written with a trailing slash. -# Copyright (C) 2000-2014 Free Software Foundation, Inc. +# Copyright (C) 2000-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/cp/thru-dangling.sh b/tests/cp/thru-dangling.sh index f4a609d5..bd8e7084 100755 --- a/tests/cp/thru-dangling.sh +++ b/tests/cp/thru-dangling.sh @@ -1,7 +1,7 @@ #!/bin/sh # Ensure that cp works as documented, when the destination is a dangling symlink -# Copyright (C) 2007-2014 Free Software Foundation, Inc. +# Copyright (C) 2007-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/d_type-check b/tests/d_type-check index 33c1fd6d..ff1eb60b 100644 --- a/tests/d_type-check +++ b/tests/d_type-check @@ -5,7 +5,7 @@ import sys fail = 1 try: - import ctypes + import ctypes.util (DT_UNKNOWN, DT_DIR,) = (0, 4,) @@ -19,8 +19,7 @@ try: direntp = ctypes.POINTER(dirent) - # FIXME: find a way to avoid hard-coding libc's so-name. - libc = ctypes.cdll.LoadLibrary("libc.so.6") + libc = ctypes.CDLL(ctypes.util.find_library('c'), use_errno=True) libc.readdir.restype = direntp dirp = libc.opendir(".") diff --git a/tests/dd/ascii.sh b/tests/dd/ascii.sh index 7dc39cc9..be6494a0 100755 --- a/tests/dd/ascii.sh +++ b/tests/dd/ascii.sh @@ -1,7 +1,7 @@ #!/bin/sh # test conv=ascii -# Copyright (C) 2014 Free Software Foundation, Inc. +# Copyright (C) 2014-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -21,45 +21,46 @@ print_ver_ dd { # Two lines, EBCDIC " A A" and " A ", followed by all the bytes in order. - printf '\100\301\100\301\100\301\100\100' && - printf $(printf '\\%03o' $(seq 0 255)); + env printf '\100\301\100\301\100\301\100\100' && + env printf $(env printf '\\%03o' $(seq 0 255)); } >in || framework_failure_ { # The converted lines, with trailing spaces removed. - printf ' A A\n A\n' && - printf '\000\001\002\003\n\234\011\206\177\n' && - printf '\227\215\216\013\n\014\015\016\017\n' && - printf '\020\021\022\023\n\235\205\010\207\n' && - printf '\030\031\222\217\n\034\035\036\037\n' && - printf '\200\201\202\203\n\204\012\027\033\n' && - printf '\210\211\212\213\n\214\005\006\007\n' && - printf '\220\221\026\223\n\224\225\226\004\n' && - printf '\230\231\232\233\n\024\025\236\032\n' && - printf '\040\240\241\242\n\243\244\245\246\n' && - printf '\247\250\325\056\n\074\050\053\174\n' && - printf '\046\251\252\253\n\254\255\256\257\n' && - printf '\260\261\041\044\n\052\051\073\176\n' && - printf '\055\057\262\263\n\264\265\266\267\n' && - printf '\270\271\313\054\n\045\137\076\077\n' && - printf '\272\273\274\275\n\276\277\300\301\n' && - printf '\302\140\072\043\n\100\047\075\042\n' && - printf '\303\141\142\143\n\144\145\146\147\n' && - printf '\150\151\304\305\n\306\307\310\311\n' && - printf '\312\152\153\154\n\155\156\157\160\n' && - printf '\161\162\136\314\n\315\316\317\320\n' && - printf '\321\345\163\164\n\165\166\167\170\n' && - printf '\171\172\322\323\n\324\133\326\327\n' && - printf '\330\331\332\333\n\334\335\336\337\n' && - printf '\340\341\342\343\n\344\135\346\347\n' && - printf '\173\101\102\103\n\104\105\106\107\n' && - printf '\110\111\350\351\n\352\353\354\355\n' && - printf '\175\112\113\114\n\115\116\117\120\n' && - printf '\121\122\356\357\n\360\361\362\363\n' && - printf '\134\237\123\124\n\125\126\127\130\n' && - printf '\131\132\364\365\n\366\367\370\371\n' && - printf '\060\061\062\063\n\064\065\066\067\n' && - printf '\070\071\372\373\n\374\375\376\377\n'; +env printf \ +' A A\n A\n'\ +'\000\001\002\003\n\234\011\206\177\n'\ +'\227\215\216\013\n\014\015\016\017\n'\ +'\020\021\022\023\n\235\205\010\207\n'\ +'\030\031\222\217\n\034\035\036\037\n'\ +'\200\201\202\203\n\204\012\027\033\n'\ +'\210\211\212\213\n\214\005\006\007\n'\ +'\220\221\026\223\n\224\225\226\004\n'\ +'\230\231\232\233\n\024\025\236\032\n'\ +'\040\240\241\242\n\243\244\245\246\n'\ +'\247\250\325\056\n\074\050\053\174\n'\ +'\046\251\252\253\n\254\255\256\257\n'\ +'\260\261\041\044\n\052\051\073\176\n'\ +'\055\057\262\263\n\264\265\266\267\n'\ +'\270\271\313\054\n\045\137\076\077\n'\ +'\272\273\274\275\n\276\277\300\301\n'\ +'\302\140\072\043\n\100\047\075\042\n'\ +'\303\141\142\143\n\144\145\146\147\n'\ +'\150\151\304\305\n\306\307\310\311\n'\ +'\312\152\153\154\n\155\156\157\160\n'\ +'\161\162\136\314\n\315\316\317\320\n'\ +'\321\345\163\164\n\165\166\167\170\n'\ +'\171\172\322\323\n\324\133\326\327\n'\ +'\330\331\332\333\n\334\335\336\337\n'\ +'\340\341\342\343\n\344\135\346\347\n'\ +'\173\101\102\103\n\104\105\106\107\n'\ +'\110\111\350\351\n\352\353\354\355\n'\ +'\175\112\113\114\n\115\116\117\120\n'\ +'\121\122\356\357\n\360\361\362\363\n'\ +'\134\237\123\124\n\125\126\127\130\n'\ +'\131\132\364\365\n\366\367\370\371\n'\ +'\060\061\062\063\n\064\065\066\067\n'\ +'\070\071\372\373\n\374\375\376\377\n'; } >exp || framework_failure_ dd if=in of=out conv=ascii cbs=4 || fail=1 diff --git a/tests/dd/bytes.sh b/tests/dd/bytes.sh index 1b72cc4c..68e98f7a 100755 --- a/tests/dd/bytes.sh +++ b/tests/dd/bytes.sh @@ -1,6 +1,6 @@ #!/bin/sh -# Copyright (C) 2012-2014 Free Software Foundation, Inc. +# Copyright (C) 2012-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/dd/direct.sh b/tests/dd/direct.sh index f6065cae..6b741472 100755 --- a/tests/dd/direct.sh +++ b/tests/dd/direct.sh @@ -1,7 +1,7 @@ #!/bin/sh # ensure that dd's oflag=direct works -# Copyright (C) 2009-2014 Free Software Foundation, Inc. +# Copyright (C) 2009-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/dd/misc.sh b/tests/dd/misc.sh index f877fddf..bc5fb37e 100755 --- a/tests/dd/misc.sh +++ b/tests/dd/misc.sh @@ -2,7 +2,7 @@ # Ensure dd treats '--' properly. # Also test some flag values. -# Copyright (C) 1999-2014 Free Software Foundation, Inc. +# Copyright (C) 1999-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -35,9 +35,12 @@ dd status=none if=$tmp_in of=/dev/null 2> err || fail=1 compare /dev/null err || fail=1 dd status=none if=$tmp_in skip=2 of=/dev/null 2> err || fail=1 compare /dev/null err || fail=1 -# check status=none is cumulative with status=noxfer -dd status=none status=noxfer if=$tmp_in of=/dev/null 2> err || fail=1 +# check later status=none overrides earlier status=noxfer +dd status=noxfer status=none if=$tmp_in of=/dev/null 2> err || fail=1 compare /dev/null err || fail=1 +# check later status=noxfer overrides earlier status=none +dd status=none status=noxfer if=$tmp_in of=/dev/null 2> err || fail=1 +compare /dev/null err && fail=1 dd if=$tmp_in of=$tmp_out 2> /dev/null || fail=1 compare $tmp_in $tmp_out || fail=1 @@ -58,12 +61,12 @@ case $(cat /dev/stdin <$tmp_in 2>/dev/null) in esac if dd iflag=nofollow if=$tmp_in count=0 2> /dev/null; then - dd iflag=nofollow if=$tmp_sym count=0 2> /dev/null && fail=1 + returns_ 1 dd iflag=nofollow if=$tmp_sym count=0 2> /dev/null || fail=1 fi if dd iflag=directory if=. count=0 2> /dev/null; then dd iflag=directory count=0 <. 2> /dev/null || fail=1 - dd iflag=directory count=0 <$tmp_in 2> /dev/null && fail=1 + returns_ 1 dd iflag=directory count=0 <$tmp_in 2> /dev/null || fail=1 fi old_ls=$(ls -u --full-time $tmp_in) @@ -84,8 +87,8 @@ EOF fi if dd oflag=nolinks if=$tmp_in of=$tmp_out 2> /dev/null; then - dd iflag=nolinks if=$tmp_in > /dev/null 2>&1 && fail=1 - dd iflag=nolinks < $tmp_in > /dev/null 2>&1 && fail=1 + returns_ 1 dd iflag=nolinks if=$tmp_in > /dev/null 2>&1 || fail=1 + returns_ 1 dd iflag=nolinks < $tmp_in > /dev/null 2>&1 || fail=1 dd oflag=nolinks < $tmp_in > $tmp_out 2>&1 || fail=1 fi diff --git a/tests/dd/no-allocate.sh b/tests/dd/no-allocate.sh index 62170b9b..99e0542a 100755 --- a/tests/dd/no-allocate.sh +++ b/tests/dd/no-allocate.sh @@ -1,7 +1,7 @@ #!/bin/sh # make sure that dd doesn't allocate memory unnecessarily -# Copyright (C) 2013-2014 Free Software Foundation, Inc. +# Copyright (C) 2013-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/dd/nocache.sh b/tests/dd/nocache.sh index 4756663d..e7fdf4e5 100755 --- a/tests/dd/nocache.sh +++ b/tests/dd/nocache.sh @@ -1,7 +1,7 @@ #!/bin/sh # Ensure dd handles the 'nocache' flag -# Copyright (C) 2011-2014 Free Software Foundation, Inc. +# Copyright (C) 2011-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -23,10 +23,10 @@ print_ver_ dd dd iflag=nocache oflag=nocache if=/dev/null of=/dev/null || fail=1 # We should get an error for trying to process a pipe -dd count=0 | dd iflag=nocache count=0 && fail=1 +dd count=0 | returns_ 1 dd iflag=nocache count=0 || fail=1 # O_DIRECT is orthogonal to drop cache so mutually exclusive -dd iflag=nocache,direct if=/dev/null && fail=1 +returns_ 1 dd iflag=nocache,direct if=/dev/null || fail=1 # The rest ensure that the documented uses cases # proceed without error diff --git a/tests/dd/not-rewound.sh b/tests/dd/not-rewound.sh index 4b38c216..beaf6403 100755 --- a/tests/dd/not-rewound.sh +++ b/tests/dd/not-rewound.sh @@ -2,7 +2,7 @@ # Make sure dd does the right thing when the input file descriptor # is not rewound. -# Copyright (C) 2000-2014 Free Software Foundation, Inc. +# Copyright (C) 2000-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/dd/reblock.sh b/tests/dd/reblock.sh index ccae9459..cd9d9420 100755 --- a/tests/dd/reblock.sh +++ b/tests/dd/reblock.sh @@ -1,7 +1,7 @@ #!/bin/sh # test dd reblocking vs. bs= -# Copyright (C) 2008-2014 Free Software Foundation, Inc. +# Copyright (C) 2008-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/dd/skip-seek-past-dev.sh b/tests/dd/skip-seek-past-dev.sh index 5eb7ab5a..216898c4 100755 --- a/tests/dd/skip-seek-past-dev.sh +++ b/tests/dd/skip-seek-past-dev.sh @@ -1,7 +1,7 @@ #!/bin/sh # test diagnostics are printed immediately when seeking beyond device. -# Copyright (C) 2008-2014 Free Software Foundation, Inc. +# Copyright (C) 2008-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/dd/skip-seek-past-file.sh b/tests/dd/skip-seek-past-file.sh index 8ed1d3f6..2e15a84d 100755 --- a/tests/dd/skip-seek-past-file.sh +++ b/tests/dd/skip-seek-past-file.sh @@ -1,7 +1,7 @@ #!/bin/sh # test diagnostics are printed when seeking too far in seekable files. -# Copyright (C) 2008-2014 Free Software Foundation, Inc. +# Copyright (C) 2008-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/dd/skip-seek.pl b/tests/dd/skip-seek.pl index e2a7d022..6bacf67d 100755 --- a/tests/dd/skip-seek.pl +++ b/tests/dd/skip-seek.pl @@ -1,7 +1,7 @@ #!/usr/bin/perl # Test dd's skip and seek options. -# Copyright (C) 2000-2014 Free Software Foundation, Inc. +# Copyright (C) 2000-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/dd/skip-seek2.sh b/tests/dd/skip-seek2.sh index aa6d65dd..62d08f07 100755 --- a/tests/dd/skip-seek2.sh +++ b/tests/dd/skip-seek2.sh @@ -2,7 +2,7 @@ # show how to skip an amount that is smaller than the nominal block size. # There's a more realistic example in the documentation. -# Copyright (C) 2000-2014 Free Software Foundation, Inc. +# Copyright (C) 2000-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/dd/sparse.sh b/tests/dd/sparse.sh index a7e90d2b..626b4059 100755 --- a/tests/dd/sparse.sh +++ b/tests/dd/sparse.sh @@ -1,6 +1,6 @@ #!/bin/sh -# Copyright (C) 2012-2014 Free Software Foundation, Inc. +# Copyright (C) 2012-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -17,6 +17,7 @@ . "${srcdir=.}/tests/init.sh"; path_prepend_ ./src print_ver_ dd +is_local_dir_ . || very_expensive_ require_sparse_support_ # Ensure basic sparse generation works @@ -50,6 +51,9 @@ dd if=/dev/zero of=file.in bs=1M count=1 seek=1 conv=notrunc || fail=1 kb_alloc() { du -k "$1"|cut -f1; } +# sync out data for async allocators like NFS/BTRFS +# sync file.in || fail=1 + # If our just-created input file appears to be too small, # skip the remaining tests. On at least Solaris 10 with NFS, # file.in is reported to occupy <= 1KiB for about 50 seconds @@ -58,7 +62,10 @@ if test $(kb_alloc file.in) -gt 3000; then # Ensure NUL blocks smaller than the block size are not made sparse. # Here, with a 2MiB block size, dd's conv=sparse must *not* introduce a hole. - dd if=file.in of=file.out bs=2M conv=sparse + dd if=file.in of=file.out bs=2M conv=sparse || fail=1 + + # Intermittently BTRFS returns 0 allocation for file.out unless synced + sync file.out || framework_failure_ test 2500 -lt $(kb_alloc file.out) || fail=1 # Note we recreate a sparse file first to avoid diff --git a/tests/dd/stats.sh b/tests/dd/stats.sh new file mode 100755 index 00000000..a82c66d2 --- /dev/null +++ b/tests/dd/stats.sh @@ -0,0 +1,73 @@ +#!/bin/sh +# Check stats output for SIG{INFO,USR1} and status=progress + +# Copyright (C) 2014-2015 Free Software Foundation, Inc. + +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. + +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. + +. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src +print_ver_ dd + +env kill -l | grep '^INFO$' && SIGINFO='INFO' || SIGINFO='USR1' + +# This to avoid races in the USR1 case +# as the dd process will terminate by default until +# it has its handler enabled. +trap '' $SIGINFO + +mkfifo_or_skip_ fifo + +# Terminate any background processes +cleanup_() +{ + kill $pid 2>/dev/null + kill $pid2 2>/dev/null + wait +} + +for open in '' '1'; do + # Run dd with the fullblock iflag to avoid short reads + # which can be triggered by reception of signals + dd iflag=fullblock if=/dev/zero of=fifo count=50 bs=5000000 2>err & pid=$! + + # Note if we sleep here we give dd a chance to exec and block on open. + # Otherwise we're probably testing SIG_IGN in the forked shell or early dd. + test "$open" && sleep .1 + + # dd will block on open until fifo is opened for reading. + # Timeout in case dd goes away erroneously which we check for below. + timeout 20 sh -c 'wc -c < fifo > nwritten' & pid2=$! + + # Send lots of signals immediately to ensure dd not killed due + # to race setting handler, or blocking on open of fifo. + # Many signals also check that short reads are handled. + until ! kill -s $SIGINFO $pid 2>/dev/null; do + sleep .01 + done + + wait + + # Ensure all data processed and at least last status written + grep '250000000 bytes .* copied' err || { cat err; fail=1; } +done + +progress_output() +{ + { sleep "$1"; echo 1; } | dd bs=1 status=progress of=/dev/null 2>err + # Progress output should be for "byte ... copied", while final is "bytes ..." + grep 'byte .* copied' err +} +retry_delay_ progress_output 1 4 || { cat err; fail=1; } + +Exit $fail diff --git a/tests/dd/stderr.sh b/tests/dd/stderr.sh index d0a304a7..82ab08f1 100755 --- a/tests/dd/stderr.sh +++ b/tests/dd/stderr.sh @@ -1,7 +1,7 @@ #!/bin/sh # Ensure dd recognizes failure to write to stderr. -# Copyright (C) 2009-2014 Free Software Foundation, Inc. +# Copyright (C) 2009-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -32,12 +32,12 @@ dd --help >/dev/null 2>&- || fail=1 # This exposes a failure present in 6.11 through 7.5. if "$p/src/test" -w /dev/stderr 2>/dev/null && "$p/src/test" ! -w /dev/stderr 2>&-; then - : | dd 2>&- && fail=1 + : | returns_ 1 dd 2>&- || fail=1 fi # Likewise for /dev/full, if /dev/full works. if test -w /dev/full && test -c /dev/full; then - : | dd 2>/dev/full && fail=1 + : | returns_ 1 dd 2>/dev/full || fail=1 fi Exit $fail diff --git a/tests/dd/unblock-sync.sh b/tests/dd/unblock-sync.sh index 72fd2ab0..751cefdf 100755 --- a/tests/dd/unblock-sync.sh +++ b/tests/dd/unblock-sync.sh @@ -1,7 +1,7 @@ #!/bin/sh # Ensure that dd conv=unblock,sync works. -# Copyright (C) 2003-2014 Free Software Foundation, Inc. +# Copyright (C) 2003-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/dd/unblock.pl b/tests/dd/unblock.pl index 586b7b4d..1e6a47d1 100755 --- a/tests/dd/unblock.pl +++ b/tests/dd/unblock.pl @@ -1,7 +1,7 @@ #!/usr/bin/perl # Exercise dd's conv=unblock mode -# Copyright (C) 2009-2014 Free Software Foundation, Inc. +# Copyright (C) 2009-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/df/df-P.sh b/tests/df/df-P.sh index aff6e1b5..f40da30a 100755 --- a/tests/df/df-P.sh +++ b/tests/df/df-P.sh @@ -1,7 +1,7 @@ #!/bin/sh # Ensure that df -P is not affected by BLOCK_SIZE settings -# Copyright (C) 2007-2014 Free Software Foundation, Inc. +# Copyright (C) 2007-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/df/df-output.sh b/tests/df/df-output.sh index b2715885..d81f0ee4 100755 --- a/tests/df/df-output.sh +++ b/tests/df/df-output.sh @@ -1,7 +1,7 @@ #!/bin/sh # Exercise df's --output option. -# Copyright (C) 2012-2014 Free Software Foundation, Inc. +# Copyright (C) 2012-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -93,7 +93,7 @@ EOF df -B1K --output=size '.' >out || fail=1 sed -e '1 { - s/ // + s/ *// q }' out > out2 compare exp out2 || fail=1 diff --git a/tests/df/df-symlink.sh b/tests/df/df-symlink.sh index 6d96bd2a..b5930978 100755 --- a/tests/df/df-symlink.sh +++ b/tests/df/df-symlink.sh @@ -1,7 +1,7 @@ #!/bin/sh # Ensure that df dereferences symlinks to disk nodes -# Copyright (C) 2013-2014 Free Software Foundation, Inc. +# Copyright (C) 2013-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -31,7 +31,7 @@ compare exp out || fail=1 # Ensure we output the same values for device nodes and '.' # This was not the case in coreutil-8.22 on systems # where the device in the mount list was a symlink itself. -# I.E. '.' => /dev/mapper/fedora-home -> /dev/dm-2 +# I.e., '.' => /dev/mapper/fedora-home -> /dev/dm-2 df --out=source,target '.' > out || fail=1 compare exp out || fail=1 diff --git a/tests/df/header.sh b/tests/df/header.sh index 664ef800..d315a33f 100755 --- a/tests/df/header.sh +++ b/tests/df/header.sh @@ -1,7 +1,7 @@ #!/bin/sh # Ensure that "df ." outputs a header. -# Copyright (C) 2006-2014 Free Software Foundation, Inc. +# Copyright (C) 2006-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/df/no-mtab-status.sh b/tests/df/no-mtab-status.sh index 9ea2036d..c35da6b8 100755 --- a/tests/df/no-mtab-status.sh +++ b/tests/df/no-mtab-status.sh @@ -2,7 +2,7 @@ # Test df's behaviour when the mount list cannot be read. # This test is skipped on systems that lack LD_PRELOAD support; that's fine. -# Copyright (C) 2012-2014 Free Software Foundation, Inc. +# Copyright (C) 2012-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -21,7 +21,8 @@ print_ver_ df require_gcc_shared_ -df || skip_ "df fails" +# Protect against inaccessible remote mounts etc. +timeout 10 df || skip_ "df fails" grep '^#define HAVE_MNTENT_H 1' $CONFIG_HEADER > /dev/null \ || skip_ "no mntent.h available to confirm the interface" @@ -30,10 +31,43 @@ grep '^#define HAVE_GETMNTENT 1' $CONFIG_HEADER > /dev/null \ || skip_ "getmntent is not used on this system" # Simulate "mtab" failure. -cat > k.c <<'EOF' || framework_failure_ +cat > k.c <<EOF || framework_failure_ +#define _GNU_SOURCE #include <stdio.h> #include <errno.h> #include <mntent.h> +#include <string.h> +#include <dlfcn.h> + +#define STREQ(a, b) (strcmp (a, b) == 0) + +FILE* fopen(const char *path, const char *mode) +{ + static FILE* (*fopen_func)(char const *, char const *); + + /* get reference to original (libc provided) fopen */ + if (!fopen_func) + { + fopen_func = (FILE*(*)(char const *, char const *)) + dlsym(RTLD_NEXT, "fopen"); + if (!fopen_func) + { + fprintf (stderr, "Failed to find fopen()\n"); + errno = ESRCH; + return NULL; + } + } + + /* Returning ENOENT here will get read_file_system_list() + to fall back to using getmntent() below. */ + if (STREQ (path, "/proc/self/mountinfo")) + { + errno = ENOENT; + return NULL; + } + else + return fopen_func(path, mode); +} struct mntent *getmntent (FILE *fp) { @@ -54,34 +88,38 @@ EOF gcc_shared_ k.c k.so \ || framework_failure_ 'failed to build shared library' +cleanup_() { unset LD_PRELOAD; } + +export LD_PRELOAD=$LD_PRELOAD:./k.so + # Test if LD_PRELOAD works: -LD_PRELOAD=./k.so df +df 2>/dev/null test -f x || skip_ "internal test failure: maybe LD_PRELOAD doesn't work?" # These tests are supposed to succeed: -LD_PRELOAD=./k.so df '.' || fail=1 -LD_PRELOAD=./k.so df -i '.' || fail=1 -LD_PRELOAD=./k.so df -T '.' || fail=1 -LD_PRELOAD=./k.so df -Ti '.' || fail=1 -LD_PRELOAD=./k.so df --total '.' || fail=1 +df '.' || fail=1 +df -i '.' || fail=1 +df -T '.' || fail=1 +df -Ti '.' || fail=1 +df --total '.' || fail=1 # These tests are supposed to fail: -LD_PRELOAD=./k.so df && fail=1 -LD_PRELOAD=./k.so df -i && fail=1 -LD_PRELOAD=./k.so df -T && fail=1 -LD_PRELOAD=./k.so df -Ti && fail=1 -LD_PRELOAD=./k.so df --total && fail=1 +returns_ 1 df || fail=1 +returns_ 1 df -i || fail=1 +returns_ 1 df -T || fail=1 +returns_ 1 df -Ti || fail=1 +returns_ 1 df --total || fail=1 -LD_PRELOAD=./k.so df -a && fail=1 -LD_PRELOAD=./k.so df -a '.' && fail=1 +returns_ 1 df -a || fail=1 +returns_ 1 df -a '.' || fail=1 -LD_PRELOAD=./k.so df -l && fail=1 -LD_PRELOAD=./k.so df -l '.' && fail=1 +returns_ 1 df -l || fail=1 +returns_ 1 df -l '.' || fail=1 -LD_PRELOAD=./k.so df -t hello && fail=1 -LD_PRELOAD=./k.so df -t hello '.' && fail=1 +returns_ 1 df -t hello || fail=1 +returns_ 1 df -t hello '.' || fail=1 -LD_PRELOAD=./k.so df -x hello && fail=1 -LD_PRELOAD=./k.so df -x hello '.' && fail=1 +returns_ 1 df -x hello || fail=1 +returns_ 1 df -x hello '.' || fail=1 Exit $fail diff --git a/tests/df/over-mount-device.sh b/tests/df/over-mount-device.sh index a85ce8db..82eab4bd 100755 --- a/tests/df/over-mount-device.sh +++ b/tests/df/over-mount-device.sh @@ -1,7 +1,7 @@ #!/bin/sh # Ensure that df /dev/loop0 errors out if overmounted by another device -# Copyright (C) 2014 Free Software Foundation, Inc. +# Copyright (C) 2014-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/df/problematic-chars.sh b/tests/df/problematic-chars.sh index bdabf0c0..eb938f6b 100755 --- a/tests/df/problematic-chars.sh +++ b/tests/df/problematic-chars.sh @@ -1,7 +1,7 @@ #!/bin/sh # Ensure that df outputs one line per entry -# Copyright (C) 2012-2014 Free Software Foundation, Inc. +# Copyright (C) 2012-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/df/skip-duplicates.sh b/tests/df/skip-duplicates.sh index 52b9014a..40696047 100755 --- a/tests/df/skip-duplicates.sh +++ b/tests/df/skip-duplicates.sh @@ -2,7 +2,7 @@ # Test df's behavior when the mount list contains duplicate entries. # This test is skipped on systems that lack LD_PRELOAD support; that's fine. -# Copyright (C) 2012-2014 Free Software Foundation, Inc. +# Copyright (C) 2012-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -23,10 +23,15 @@ require_gcc_shared_ # We use --local here so as to not activate # potentially very many remote mounts. -df --local || skip_ "df fails" +df --local || skip_ 'df fails' export CU_NONROOT_FS=$(df --local --output=target 2>&1 | grep /. | head -n1) -test -z "$CU_NONROOT_FS" && unique_entries=1 || unique_entries=2 +export CU_REMOTE_FS=$(df --local --output=target 2>&1 | grep /. | + tail -n+2 | head -n1) + +unique_entries=1 +test -z "$CU_NONROOT_FS" || unique_entries=$(expr $unique_entries + 1) +test -z "$CU_REMOTE_FS" || unique_entries=$(expr $unique_entries + 2) grep '^#define HAVE_MNTENT_H 1' $CONFIG_HEADER > /dev/null \ || skip_ "no mntent.h available to confirm the interface" @@ -35,17 +40,51 @@ grep '^#define HAVE_GETMNTENT 1' $CONFIG_HEADER > /dev/null \ || skip_ "getmntent is not used on this system" # Simulate an mtab file to test various cases. -cat > k.c <<'EOF' || framework_failure_ +cat > k.c <<EOF || framework_failure_ +#define _GNU_SOURCE #include <stdio.h> #include <stdlib.h> -#include <string.h> +#include <errno.h> #include <mntent.h> +#include <string.h> +#include <dlfcn.h> + +#define STREQ(a, b) (strcmp (a, b) == 0) + +FILE* fopen(const char *path, const char *mode) +{ + static FILE* (*fopen_func)(char const *, char const *); + + /* get reference to original (libc provided) fopen */ + if (!fopen_func) + { + fopen_func = (FILE*(*)(char const *, char const *)) + dlsym(RTLD_NEXT, "fopen"); + if (!fopen_func) + { + fprintf (stderr, "Failed to find fopen()\n"); + errno = ESRCH; + return NULL; + } + } + + /* Returning ENOENT here will get read_file_system_list() + to fall back to using getmntent() below. */ + if (STREQ (path, "/proc/self/mountinfo")) + { + errno = ENOENT; + return NULL; + } + else + return fopen_func(path, mode); +} #define STREQ(a, b) (strcmp (a, b) == 0) struct mntent *getmntent (FILE *fp) { static char *nonroot_fs; + static char *remote_fs; static int done; /* Prove that LD_PRELOAD works. */ @@ -56,13 +95,16 @@ struct mntent *getmntent (FILE *fp) } static struct mntent mntents[] = { - {.mnt_fsname="/short", .mnt_dir="/invalid/mount/dir"}, - {.mnt_fsname="fsname", .mnt_dir="/",}, - {.mnt_fsname="/fsname", .mnt_dir="/."}, - {.mnt_fsname="/fsname", .mnt_dir="/"}, - {.mnt_fsname="virtfs", .mnt_dir="/NONROOT", .mnt_type="fstype1"}, - {.mnt_fsname="virtfs2", .mnt_dir="/NONROOT", .mnt_type="fstype2"}, - {.mnt_fsname="netns", .mnt_dir="net:[1234567]"}, + {.mnt_fsname="/short", .mnt_dir="/invalid/mount/dir", .mnt_opts=""}, + {.mnt_fsname="fsname", .mnt_dir="/", .mnt_opts=""}, + {.mnt_fsname="/fsname", .mnt_dir="/.", .mnt_opts=""}, + {.mnt_fsname="/fsname", .mnt_dir="/", .mnt_opts=""}, + {.mnt_fsname="virtfs", .mnt_dir="/NONROOT", .mnt_type="t1", .mnt_opts=""}, + {.mnt_fsname="virtfs2", .mnt_dir="/NONROOT", .mnt_type="t2", .mnt_opts=""}, + {.mnt_fsname="netns", .mnt_dir="net:[1234567]", .mnt_opts=""}, + {.mnt_fsname="rem:ote1",.mnt_dir="/REMOTE", .mnt_opts=""}, + {.mnt_fsname="rem:ote1",.mnt_dir="/REMOTE", .mnt_opts=""}, + {.mnt_fsname="rem:ote2",.mnt_dir="/REMOTE", .mnt_opts=""}, }; if (done == 1) @@ -70,17 +112,28 @@ struct mntent *getmntent (FILE *fp) nonroot_fs = getenv ("CU_NONROOT_FS"); if (!nonroot_fs || !*nonroot_fs) nonroot_fs = "/"; /* merge into / entries. */ + + remote_fs = getenv ("CU_REMOTE_FS"); } if (done == 1 && !getenv ("CU_TEST_DUPE_INVALID")) done++; /* skip the first entry. */ - while (done++ <= 7) + while (done++ <= 10) { if (!mntents[done-2].mnt_type) mntents[done-2].mnt_type = "-"; + if (!mntents[done-2].mnt_opts) + mntents[done-2].mnt_opts = "-"; if (STREQ (mntents[done-2].mnt_dir, "/NONROOT")) mntents[done-2].mnt_dir = nonroot_fs; + if (STREQ (mntents[done-2].mnt_dir, "/REMOTE")) + { + if (!remote_fs || !*remote_fs) + continue; + else + mntents[done-2].mnt_dir = remote_fs; + } return &mntents[done-2]; } @@ -93,17 +146,23 @@ gcc_shared_ k.c k.so \ || framework_failure_ 'failed to build shared library' # Test if LD_PRELOAD works: -LD_PRELOAD=./k.so df +LD_PRELOAD=$LD_PRELOAD:./k.so df test -f x || skip_ "internal test failure: maybe LD_PRELOAD doesn't work?" # The fake mtab file should only contain entries # having the same device number; thus the output should # consist of a header and unique entries. -LD_PRELOAD=./k.so df -T >out || fail=1 +LD_PRELOAD=$LD_PRELOAD:./k.so df -T >out || fail=1 test $(wc -l <out) -eq $(expr 1 + $unique_entries) || { fail=1; cat out; } +# With --total we should suppress the duplicate but separate remote file system +LD_PRELOAD=$LD_PRELOAD:./k.so df --total >out || fail=1 +test "$CU_REMOTE_FS" && elide_remote=1 || elide_remote=0 +test $(wc -l <out) -eq $(expr 2 + $unique_entries - $elide_remote) || + { fail=1; cat out; } + # Ensure we don't fail when unable to stat (currently) unavailable entries -LD_PRELOAD=./k.so CU_TEST_DUPE_INVALID=1 df -T >out || fail=1 +LD_PRELOAD=$LD_PRELOAD:./k.so CU_TEST_DUPE_INVALID=1 df -T >out || fail=1 test $(wc -l <out) -eq $(expr 1 + $unique_entries) || { fail=1; cat out; } # df should also prefer "/fsname" over "fsname" @@ -114,11 +173,12 @@ if test "$unique_entries" = 2; then fi # df should use the last seen devname (mnt_fsname) and devtype (mnt_type) -test $(grep -c 'virtfs2.*fstype2' <out) -eq 1 || { fail=1; cat out; } +test $(grep -c 'virtfs2.*t2' <out) -eq 1 || { fail=1; cat out; } # Ensure that filtering duplicates does not affect -a processing. -LD_PRELOAD=./k.so df -a >out || fail=1 -test $(wc -l <out) -eq 6 || { fail=1; cat out; } +LD_PRELOAD=$LD_PRELOAD:./k.so df -a >out || fail=1 +total_fs=6; test "$CU_REMOTE_FS" && total_fs=$(expr $total_fs + 3) +test $(wc -l <out) -eq $total_fs || { fail=1; cat out; } # Ensure placeholder "-" values used for the eclipsed "virtfs" test $(grep -c 'virtfs *-' <out) -eq 1 || { fail=1; cat out; } diff --git a/tests/df/skip-rootfs.sh b/tests/df/skip-rootfs.sh index 94f32c6b..43ba70b4 100755 --- a/tests/df/skip-rootfs.sh +++ b/tests/df/skip-rootfs.sh @@ -1,7 +1,7 @@ #!/bin/sh # Test df's behavior for skipping the pseudo "rootfs" file system. -# Copyright (C) 2012-2014 Free Software Foundation, Inc. +# Copyright (C) 2012-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -19,11 +19,14 @@ . "${srcdir=.}/tests/init.sh"; path_prepend_ ./src print_ver_ df -df || skip_ "df fails" +# Protect against inaccessible remote mounts etc. +timeout 10 df || skip_ "df fails" # Verify that rootfs is in mtab (and shown when the -a option is specified). +# Note this is the case when /proc/self/mountinfo is parsed +# rather than /proc/mounts. I.e., when libmount is being used. df -a >out || fail=1 -grep '^rootfs' out || skip_ "no rootfs in mtab" +grep '^rootfs' out || skip_ 'no rootfs in mtab' # Ensure that rootfs is suppressed when no options is specified. df >out || fail=1 @@ -32,7 +35,7 @@ grep '^rootfs' out && { fail=1; cat out; } # Ensure that rootfs is yet skipped when explicitly specifying "-t rootfs". # As df emits "no file systems processed" in this case, it would be a failure # if df exited with status Zero. -df -t rootfs >out && fail=1 +returns_ 1 df -t rootfs >out || fail=1 grep '^rootfs' out && { fail=1; cat out; } # Ensure that the rootfs is shown when explicitly both specifying "-t rootfs" diff --git a/tests/df/total-unprocessed.sh b/tests/df/total-unprocessed.sh index 9b17c8aa..9779471d 100755 --- a/tests/df/total-unprocessed.sh +++ b/tests/df/total-unprocessed.sh @@ -2,7 +2,7 @@ # Ensure that df exits non-Zero and writes an error message when # --total is used but no file system has been processed. -# Copyright (C) 2012-2014 Free Software Foundation, Inc. +# Copyright (C) 2012-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/df/total-verify.sh b/tests/df/total-verify.sh index 63cbe8f7..ba50b03c 100755 --- a/tests/df/total-verify.sh +++ b/tests/df/total-verify.sh @@ -1,7 +1,7 @@ #!/bin/sh # Ensure "df --total" computes accurate totals -# Copyright (C) 2008-2014 Free Software Foundation, Inc. +# Copyright (C) 2008-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -20,7 +20,8 @@ print_ver_ df require_perl_ -df || skip_ "df fails" +# Protect against inaccessible remote mounts etc. +timeout 10 df || skip_ "df fails" cat <<\EOF > check-df || framework_failure_ my ($total, $used, $avail) = (0, 0, 0); diff --git a/tests/df/unreadable.sh b/tests/df/unreadable.sh index 4ad23373..9e3da0ed 100755 --- a/tests/df/unreadable.sh +++ b/tests/df/unreadable.sh @@ -1,7 +1,7 @@ #!/bin/sh # ensure that df can handle an unreadable argument -# Copyright (C) 2009-2014 Free Software Foundation, Inc. +# Copyright (C) 2009-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/du/2g.sh b/tests/du/2g.sh index f766d4d9..12c2eede 100755 --- a/tests/du/2g.sh +++ b/tests/du/2g.sh @@ -3,7 +3,7 @@ # Before coreutils-5.93, on systems with a signed, 32-bit stat.st_blocks # one of du's computations would overflow. -# Copyright (C) 2005-2014 Free Software Foundation, Inc. +# Copyright (C) 2005-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -24,7 +24,6 @@ print_ver_ du # Creating a 2GB file counts as 'very expensive'. very_expensive_ - # Get number of free kilobytes on current partition, so we can # skip this test if there is insufficient free space. free_kb=$(df -k --output=avail . | tail -n1) @@ -42,16 +41,22 @@ test $min_kb -lt $free_kb || } big=big -rm -f $big -test -t 1 || printf 'creating a 2GB file...\n' -for i in $(seq 100); do - # Note: 2147483648 == 2^31. Print floor(2^31/100) per iteration. - printf %21474836s x >> $big || fail=1 - # On the final iteration, append the remaining 48 bytes. - test $i = 100 && { printf %48s x >> $big || fail=1; } - test -t 1 && printf 'creating a 2GB file: %d%% complete\r' $i -done -echo + +if ! fallocate -l2G $big; then + rm -f $big + { + is_local_dir_ . || skip 'Not writing 2GB data to remote' + for i in $(seq 100); do + # Note: 2147483648 == 2^31. Print floor(2^31/100) per iteration. + printf %21474836s x || fail=1 + done + # After the final iteration, append the remaining 48 bytes. + printf %48s x || fail=1 + } > $big || fail=1 +fi + +# The allocation may be done asynchronously (BTRFS for example) +sync $big || framework_failure_ du -k $big > out1 || fail=1 rm -f $big diff --git a/tests/du/8gb.sh b/tests/du/8gb.sh index 399fe7e5..696dd9f0 100755 --- a/tests/du/8gb.sh +++ b/tests/du/8gb.sh @@ -2,7 +2,7 @@ # Ensure that du does not rely on narrow types like size_t for # file sizes or sums. -# Copyright (C) 2003-2014 Free Software Foundation, Inc. +# Copyright (C) 2003-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/du/basic.sh b/tests/du/basic.sh index 75bc9be1..b14a1b41 100755 --- a/tests/du/basic.sh +++ b/tests/du/basic.sh @@ -1,7 +1,7 @@ #!/bin/sh # Compare actual numbers from du, assuming block size matches mine. -# Copyright (C) 2003-2014 Free Software Foundation, Inc. +# Copyright (C) 2003-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/du/bigtime.sh b/tests/du/bigtime.sh index eebdeb04..ad484f81 100755 --- a/tests/du/bigtime.sh +++ b/tests/du/bigtime.sh @@ -1,7 +1,7 @@ #!/bin/sh # Exercise du on a file with a big time stamp. -# Copyright (C) 2010-2014 Free Software Foundation, Inc. +# Copyright (C) 2010-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/du/bind-mount-dir-cycle-v2.sh b/tests/du/bind-mount-dir-cycle-v2.sh new file mode 100755 index 00000000..f897098e --- /dev/null +++ b/tests/du/bind-mount-dir-cycle-v2.sh @@ -0,0 +1,38 @@ +#!/bin/sh +# Check that du can handle sub-bind-mounts cycles as well. + +# Copyright (C) 2014-2015 Free Software Foundation, Inc. + +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. + +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. + +. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src +print_ver_ du +require_root_ + +cleanup_() { umount a/b/c; } + +mkdir -p a/b/c || framework_failure_ +mount --bind a a/b/c \ + || skip_ 'This test requires mount with a working --bind option.' + +echo a/b/c > exp || framework_failure_ +echo a/b >> exp || framework_failure_ + +du a/b > out 2> err || fail=1 +sed 's/^[0-9][0-9]* //' out > k && mv k out + +compare /dev/null err || fail=1 +compare exp out || fail=1 + +Exit $fail diff --git a/tests/du/bind-mount-dir-cycle.sh b/tests/du/bind-mount-dir-cycle.sh index ac6bf2e2..88ae057a 100755 --- a/tests/du/bind-mount-dir-cycle.sh +++ b/tests/du/bind-mount-dir-cycle.sh @@ -1,7 +1,7 @@ #!/bin/sh # Exercise du's new ability to handle bind-mount-induced dir cycles. -# Copyright (C) 2012-2014 Free Software Foundation, Inc. +# Copyright (C) 2012-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/du/deref-args.sh b/tests/du/deref-args.sh index 50e525a1..d35fe5bb 100755 --- a/tests/du/deref-args.sh +++ b/tests/du/deref-args.sh @@ -2,7 +2,7 @@ # Ensure that --dereference-args (-D) gives reasonable names. # This test would fail for coreutils-5.0.91. -# Copyright (C) 2003-2014 Free Software Foundation, Inc. +# Copyright (C) 2003-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/du/deref.sh b/tests/du/deref.sh index 543b7395..6c2a4724 100755 --- a/tests/du/deref.sh +++ b/tests/du/deref.sh @@ -4,7 +4,7 @@ # Also, up to coreutils-8.5, du -L sometimes incorrectly # counted the space of the followed symlinks. -# Copyright (C) 2002-2014 Free Software Foundation, Inc. +# Copyright (C) 2002-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -34,7 +34,7 @@ ln -s nowhere dangle || framework_failure_ du -sD slink b > /dev/null 2>&1 || fail=1 # This used to fail to report the dangling symlink. -du -L dangle > /dev/null 2>&1 && fail=1 +returns_ 1 du -L dangle > /dev/null 2>&1 || fail=1 # du -L used to mess up, either by counting the symlink's disk space itself # (-L should follow symlinks, not count their space) diff --git a/tests/du/exclude.sh b/tests/du/exclude.sh index 26ba598e..c738a7a0 100755 --- a/tests/du/exclude.sh +++ b/tests/du/exclude.sh @@ -1,7 +1,7 @@ #!/bin/sh # make sure du's --exclude option works -# Copyright (C) 2003-2014 Free Software Foundation, Inc. +# Copyright (C) 2003-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/du/fd-leak.sh b/tests/du/fd-leak.sh index ba8518e1..51eff9b4 100755 --- a/tests/du/fd-leak.sh +++ b/tests/du/fd-leak.sh @@ -1,7 +1,7 @@ #!/bin/sh # check for file descriptor leak -# Copyright (C) 2003-2014 Free Software Foundation, Inc. +# Copyright (C) 2003-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/du/files0-from-dir.sh b/tests/du/files0-from-dir.sh index 67088434..2f55c4ed 100755 --- a/tests/du/files0-from-dir.sh +++ b/tests/du/files0-from-dir.sh @@ -1,7 +1,7 @@ #!/bin/sh # ensure that du and wc handle --files0-from=DIR -# Copyright (C) 2011-2014 Free Software Foundation, Inc. +# Copyright (C) 2011-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/du/files0-from.pl b/tests/du/files0-from.pl index 13c03c0c..3854059f 100755 --- a/tests/du/files0-from.pl +++ b/tests/du/files0-from.pl @@ -2,7 +2,7 @@ # Exercise du's --files0-from option. # FIXME: keep this file in sync with tests/misc/wc-files0-from. -# Copyright (C) 2004-2014 Free Software Foundation, Inc. +# Copyright (C) 2004-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/du/hard-link.sh b/tests/du/hard-link.sh index 1d431e4c..66287aed 100755 --- a/tests/du/hard-link.sh +++ b/tests/du/hard-link.sh @@ -3,7 +3,7 @@ # Likewise for excluded directories. # Ensure that hard links _are_ listed twice when using --count-links. -# Copyright (C) 2003-2014 Free Software Foundation, Inc. +# Copyright (C) 2003-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/du/inacc-dest.sh b/tests/du/inacc-dest.sh index 578237c3..749ad246 100755 --- a/tests/du/inacc-dest.sh +++ b/tests/du/inacc-dest.sh @@ -2,7 +2,7 @@ # Prior to coreutils-6.5, an inaccessible destination dir (chmod a-x) # would cause du to exit prematurely on systems with native openat support. -# Copyright (C) 2006-2014 Free Software Foundation, Inc. +# Copyright (C) 2006-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/du/inacc-dir.sh b/tests/du/inacc-dir.sh index 4c053909..048fe774 100755 --- a/tests/du/inacc-dir.sh +++ b/tests/du/inacc-dir.sh @@ -1,6 +1,6 @@ #!/bin/sh # Ensure that du counts the size of an inaccessible directory. -# Copyright (C) 2007-2014 Free Software Foundation, Inc. +# Copyright (C) 2007-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/du/inaccessible-cwd.sh b/tests/du/inaccessible-cwd.sh index 663e0401..e5a6549f 100755 --- a/tests/du/inaccessible-cwd.sh +++ b/tests/du/inaccessible-cwd.sh @@ -2,7 +2,7 @@ # Ensure that even when run from an inaccessible directory, du can still # operate on accessible directories elsewhere. -# Copyright (C) 2003-2014 Free Software Foundation, Inc. +# Copyright (C) 2003-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/du/inodes.sh b/tests/du/inodes.sh index 6d2c28bb..384eaf69 100755 --- a/tests/du/inodes.sh +++ b/tests/du/inodes.sh @@ -1,7 +1,7 @@ #!/bin/sh # exercise du's --inodes option -# Copyright (C) 2010-2014 Free Software Foundation, Inc. +# Copyright (C) 2010-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/du/long-from-unreadable.sh b/tests/du/long-from-unreadable.sh index e343bb56..4081eca2 100755 --- a/tests/du/long-from-unreadable.sh +++ b/tests/du/long-from-unreadable.sh @@ -1,7 +1,7 @@ #!/bin/sh # Show fts fails on old-fashioned systems. -# Copyright (C) 2006-2014 Free Software Foundation, Inc. +# Copyright (C) 2006-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/du/long-sloop.sh b/tests/du/long-sloop.sh index 5168ac00..9c325b6d 100755 --- a/tests/du/long-sloop.sh +++ b/tests/du/long-sloop.sh @@ -3,7 +3,7 @@ # Show that du fails with ELOOP (Too many levels of symbolic links) # when it encounters that condition. -# Copyright (C) 2006-2014 Free Software Foundation, Inc. +# Copyright (C) 2006-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/du/max-depth.sh b/tests/du/max-depth.sh index 4d201095..25ad4689 100755 --- a/tests/du/max-depth.sh +++ b/tests/du/max-depth.sh @@ -1,7 +1,7 @@ #!/bin/sh # exercise du's --max-depth=N option -# Copyright (C) 2010-2014 Free Software Foundation, Inc. +# Copyright (C) 2010-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/du/move-dir-while-traversing.sh b/tests/du/move-dir-while-traversing.sh index 046dad90..67bb3458 100755 --- a/tests/du/move-dir-while-traversing.sh +++ b/tests/du/move-dir-while-traversing.sh @@ -1,7 +1,7 @@ #!/bin/sh # Trigger a failed assertion in coreutils-8.9 and earlier. -# Copyright (C) 2011-2014 Free Software Foundation, Inc. +# Copyright (C) 2011-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -71,14 +71,17 @@ for i in $(seq 50); do mkdir -p $t/3/a/b/c/$i/$long || framework_failure_ done +# Terminate any background cp process +cleanup_() { kill $pid 2>/dev/null && wait $pid; } + # Prohibit suspension, which could otherwise cause a timeout-induced FP failure. trap '' TSTP -timeout 6 ./inotify-watch-for-dir-access.py $t/3/a/b > start-msg & +timeout 6 ./inotify-watch-for-dir-access.py $t/3/a/b > start-msg & pid=$! # Wait for the watcher to start... nonempty() { test -s start-msg || { sleep $1; return 1; }; } -retry_delay_ nonempty .1 5 +retry_delay_ nonempty .1 5 || fail=1 # The above watches for an IN_OPEN event on $t/3/a/b, # and when it triggers, moves the parent, $t/3/a, up one level diff --git a/tests/du/no-deref.sh b/tests/du/no-deref.sh index 0708bd35..1388f5d0 100755 --- a/tests/du/no-deref.sh +++ b/tests/du/no-deref.sh @@ -1,7 +1,7 @@ #!/bin/sh # Ensure that by default, du doesn't dereference command-line symlinks. -# Copyright (C) 2003-2014 Free Software Foundation, Inc. +# Copyright (C) 2003-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/du/no-x.sh b/tests/du/no-x.sh index 625eb96a..c035e3f2 100755 --- a/tests/du/no-x.sh +++ b/tests/du/no-x.sh @@ -2,7 +2,7 @@ # Make sure du gives the right diagnostic for a readable, # but inaccessible directory. -# Copyright (C) 2003-2014 Free Software Foundation, Inc. +# Copyright (C) 2003-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/du/one-file-system.sh b/tests/du/one-file-system.sh index db18d9b7..ab42286b 100755 --- a/tests/du/one-file-system.sh +++ b/tests/du/one-file-system.sh @@ -1,7 +1,7 @@ #!/bin/sh # Test for bugs in du's --one-file-system (-x) option. -# Copyright (C) 2006-2014 Free Software Foundation, Inc. +# Copyright (C) 2006-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/du/restore-wd.sh b/tests/du/restore-wd.sh index 605399e4..aa05557b 100755 --- a/tests/du/restore-wd.sh +++ b/tests/du/restore-wd.sh @@ -2,7 +2,7 @@ # due to a bug in glibc's ftw.c, in some cases, nftw w/FTW_CHDIR # would not restore the working directory. -# Copyright (C) 2003-2014 Free Software Foundation, Inc. +# Copyright (C) 2003-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/du/slash.sh b/tests/du/slash.sh index 3073cb1b..87e280b7 100755 --- a/tests/du/slash.sh +++ b/tests/du/slash.sh @@ -1,7 +1,7 @@ #!/bin/sh # 'du /' would omit the '/' on the last line. -# Copyright (C) 2003-2014 Free Software Foundation, Inc. +# Copyright (C) 2003-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/du/threshold.sh b/tests/du/threshold.sh index 1985a6be..a4e488ae 100755 --- a/tests/du/threshold.sh +++ b/tests/du/threshold.sh @@ -1,7 +1,7 @@ #!/bin/sh # Exercise du's --threshold option. -# Copyright (C) 2013-2014 Free Software Foundation, Inc. +# Copyright (C) 2013-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -102,9 +102,11 @@ du --threshold= a > out 2>&1 && fail=1 compare exp out || fail=1 # Exercise a bad argument: no argument. -du --threshold > out 2>&1 && fail=1 +du --threshold > out.tmp 2>&1 && fail=1 +sed 's/argument.*/argument/; s/option.*requires/option requires/' \ + < out.tmp > out || framework_failure_ cat <<EOF > exp -du: option '--threshold' requires an argument +du: option requires an argument Try 'du --help' for more information. EOF compare exp out || fail=1 diff --git a/tests/du/trailing-slash.sh b/tests/du/trailing-slash.sh index d6a935ad..42eb9116 100755 --- a/tests/du/trailing-slash.sh +++ b/tests/du/trailing-slash.sh @@ -2,7 +2,7 @@ # Ensure that du works properly for an argument that refers to a # symbolic link, and that is specified with a trailing slash. -# Copyright (C) 2002-2014 Free Software Foundation, Inc. +# Copyright (C) 2002-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/du/two-args.sh b/tests/du/two-args.sh index b5ec3024..999774f3 100755 --- a/tests/du/two-args.sh +++ b/tests/du/two-args.sh @@ -2,7 +2,7 @@ # Make sure 'du d/1 d/2' works. # That command failed with du from fileutils-4.0q. -# Copyright (C) 2000-2014 Free Software Foundation, Inc. +# Copyright (C) 2000-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/envvar-check b/tests/envvar-check index b6d94b4c..28d95f30 100644 --- a/tests/envvar-check +++ b/tests/envvar-check @@ -1,7 +1,7 @@ # -*- sh -*- # Check environment variables for sane values while testing. -# Copyright (C) 2000-2014 Free Software Foundation, Inc. +# Copyright (C) 2000-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -28,12 +28,14 @@ vars=' _STDBUF_E _STDBUF_I _STDBUF_O + BASH_ENV BLOCKSIZE BLOCK_SIZE CDPATH COLUMNS DF_BLOCK_SIZE DU_BLOCK_SIZE + ENV LANGUAGE LS_BLOCK_SIZE LS_COLORS diff --git a/tests/factor/create-test.sh b/tests/factor/create-test.sh index b9519725..8d79373b 100755 --- a/tests/factor/create-test.sh +++ b/tests/factor/create-test.sh @@ -1,7 +1,7 @@ #!/bin/sh # Create the factor test scripts. -# Copyright (C) 2012-2014 Free Software Foundation, Inc. +# Copyright (C) 2012-2015 Free Software Foundation, Inc. test_name=$1 template=$2 diff --git a/tests/factor/run.sh b/tests/factor/run.sh index d7bae642..2cf2b47e 100755 --- a/tests/factor/run.sh +++ b/tests/factor/run.sh @@ -10,7 +10,7 @@ # # See: tests/factor/create-test.sh -# Copyright (C) 2012-2014 Free Software Foundation, Inc. +# Copyright (C) 2012-2015 Free Software Foundation, Inc. . "${srcdir=.}/tests/init.sh"; path_prepend_ ./src diff --git a/tests/fmt/base.pl b/tests/fmt/base.pl index c6b97878..695d91bd 100755 --- a/tests/fmt/base.pl +++ b/tests/fmt/base.pl @@ -1,7 +1,7 @@ #!/usr/bin/perl # Basic tests for "fmt". -# Copyright (C) 2001-2014 Free Software Foundation, Inc. +# Copyright (C) 2001-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -19,6 +19,7 @@ use strict; (my $program_name = $0) =~ s|.*/||; +my $normalize_strerror = "s/': .*/'/"; my @Tests = ( @@ -26,9 +27,11 @@ my @Tests = {IN=> "ça\nçb\n"}, {OUT=>"ça b\n"}], ['wide-1', '-w 32768', - {ERR => "fmt: invalid width: '32768'\n"}, {EXIT => 1}], + {ERR => "fmt: invalid width: '32768'\n"}, {EXIT => 1}, + {ERR_SUBST => $normalize_strerror}], ['wide-2', '-w 2147483647', - {ERR => "fmt: invalid width: '2147483647'\n"}, {EXIT => 1}], + {ERR => "fmt: invalid width: '2147483647'\n"}, {EXIT => 1}, + {ERR_SUBST => $normalize_strerror}], ['bad-suffix', '-72x', {IN=> ''}, {ERR => "fmt: invalid width: '72x'\n"}, {EXIT => 1}], ['no-file', 'no-such-file', diff --git a/tests/fmt/goal-option.sh b/tests/fmt/goal-option.sh index d2d60c83..322f239e 100755 --- a/tests/fmt/goal-option.sh +++ b/tests/fmt/goal-option.sh @@ -1,7 +1,7 @@ #!/bin/sh # Exercise the fmt -g option. -# Copyright (C) 2012-2014 Free Software Foundation, Inc. +# Copyright (C) 2012-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/fmt/long-line.sh b/tests/fmt/long-line.sh index 33a85016..6f529c0a 100755 --- a/tests/fmt/long-line.sh +++ b/tests/fmt/long-line.sh @@ -1,7 +1,7 @@ #!/bin/sh # make sure fmt -s works even on long lines -# Copyright (C) 2002-2014 Free Software Foundation, Inc. +# Copyright (C) 2002-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/id/context.sh b/tests/id/context.sh index 4629c1a0..b1aefe73 100755 --- a/tests/id/context.sh +++ b/tests/id/context.sh @@ -1,6 +1,6 @@ #!/bin/sh # Ensure that "id" outputs SELinux context only without specified user -# Copyright (C) 2008-2014 Free Software Foundation, Inc. +# Copyright (C) 2008-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -26,7 +26,10 @@ id | grep context= >/dev/null || fail=1 # Check with specified user, no context string should be present. # But if the current user is nameless, skip this part. -id -nu > /dev/null \ - && id $(id -nu) | grep context= >/dev/null && fail=1 +name=$(id -nu) || { test $? -ne 1 && fail=1; } +if test "$name"; then + id "$name" > id_name || fail=1 + grep context= id_name >/dev/null && fail=1 +fi Exit $fail diff --git a/tests/id/gnu-zero-uids.sh b/tests/id/gnu-zero-uids.sh index 89ca3097..c2ee6cfb 100755 --- a/tests/id/gnu-zero-uids.sh +++ b/tests/id/gnu-zero-uids.sh @@ -1,7 +1,7 @@ #!/bin/sh # On GNU, 'id' must fail for processes with zero UIDs. -# Copyright (C) 2011-2014 Free Software Foundation, Inc. +# Copyright (C) 2011-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -24,6 +24,6 @@ require_gnu_ sush - true || skip_ "the 'sush' command does not work" # Run 'id' with zero UIDs. It should exit with a non-zero status. -sush - id > out && fail=1 +returns_ 1 sush - id > out || fail=1 Exit $fail diff --git a/tests/id/no-context.sh b/tests/id/no-context.sh index 7b699278..ff4f44d1 100755 --- a/tests/id/no-context.sh +++ b/tests/id/no-context.sh @@ -1,7 +1,7 @@ #!/bin/sh # With POSIXLY_CORRECT, id must not print context=... -# Copyright (C) 2009-2014 Free Software Foundation, Inc. +# Copyright (C) 2009-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/id/setgid.sh b/tests/id/setgid.sh index 6d9d74f4..2ea249a0 100755 --- a/tests/id/setgid.sh +++ b/tests/id/setgid.sh @@ -1,7 +1,7 @@ #!/bin/sh # Verify that id [-G] prints the right group when run set-GID. -# Copyright (C) 2012-2014 Free Software Foundation, Inc. +# Copyright (C) 2012-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -27,14 +27,14 @@ echo $gp1 > exp || framework_failure_ # With coreutils-8.16 and earlier, id -G would print both: # $gp1 $NON_ROOT_GID -chroot --user=$NON_ROOT_USERNAME:+$gp1 --groups='' / env PATH="$PATH" \ - id -G > out || fail=1 +chroot --skip-chdir --user=$NON_ROOT_USERNAME:+$gp1 --groups='' / \ + env PATH="$PATH" id -G > out || fail=1 compare exp out || fail=1 # With coreutils-8.22 and earlier, id would erroneously print # groups=$NON_ROOT_GID -chroot --user=$NON_ROOT_USERNAME:+$gp1 --groups='' / env PATH="$PATH" \ - id > out || fail=1 +chroot --skip-chdir --user=$NON_ROOT_USERNAME:+$gp1 --groups='' / \ + env PATH="$PATH" id > out || fail=1 grep -F "groups=$gp1" out || { cat out; fail=1; } Exit $fail diff --git a/tests/id/smack.sh b/tests/id/smack.sh index 227db3e8..10350cc2 100755 --- a/tests/id/smack.sh +++ b/tests/id/smack.sh @@ -1,7 +1,7 @@ #!/bin/sh # SMACK test for the id-command. # Derived from tests/id/context.sh and tests/id/no-context.sh. -# Copyright (C) 2014 Free Software Foundation, Inc. +# Copyright (C) 2014-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/id/uid.sh b/tests/id/uid.sh index 919ffbe2..e7a83858 100755 --- a/tests/id/uid.sh +++ b/tests/id/uid.sh @@ -1,6 +1,6 @@ #!/bin/sh # Ensure that "id" works with numeric user ids -# Copyright (C) 2013-2014 Free Software Foundation, Inc. +# Copyright (C) 2013-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -22,7 +22,7 @@ uid=$(id -u) || fail=1 user=$(id -nu) || fail=1 # Ensure the empty user spec is discarded -id '' && fail=1 +returns_ 1 id '' || fail=1 for mode in '' '-G' '-g'; do id $mode $user > user_out || fail=1 # lookup name for comparison diff --git a/tests/id/zero.sh b/tests/id/zero.sh index c826ff43..7bee3a64 100755 --- a/tests/id/zero.sh +++ b/tests/id/zero.sh @@ -1,7 +1,7 @@ #!/bin/sh # Exercise "id --zero". -# Copyright (C) 2013-2014 Free Software Foundation, Inc. +# Copyright (C) 2013-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -51,8 +51,10 @@ while read u ; do printf '\n%s: ' "id -${o}${n}[z] $u" >> out || framework_failure_ # There may be no name corresponding to an id, so don't check # exit status when in name lookup mode - id -${o}${n} $u >> exp || { test -z "$n" && fail=1; } - id -${o}${n}z $u > tmp || { test -z "$n" && fail=1; } + id -${o}${n} $u >> exp || + { test $? -ne 1 || test -z "$n" && fail=1; } + id -${o}${n}z $u > tmp || + { test $? -ne 1 || test -z "$n" && fail=1; } head -c-1 < tmp >> out || framework_failure_ done done diff --git a/tests/init.sh b/tests/init.sh index fbd293d6..d3662061 100755 --- a/tests/init.sh +++ b/tests/init.sh @@ -1,6 +1,6 @@ # source this file; set up for tests -# Copyright (C) 2009-2014 Free Software Foundation, Inc. +# Copyright (C) 2009-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -93,6 +93,27 @@ skip_ () { warn_ "$ME_: skipped test: $@"; Exit 77; } fatal_ () { warn_ "$ME_: hard error: $@"; Exit 99; } framework_failure_ () { warn_ "$ME_: set-up failure: $@"; Exit 99; } +# This is used to simplify checking of the return value +# which is useful when ensuring a command fails as desired. +# I.e., just doing `command ... &&fail=1` will not catch +# a segfault in command for example. With this helper you +# instead check an explicit exit code like +# returns_ 1 command ... || fail +returns_ () { + # Disable tracing so it doesn't interfere with stderr of the wrapped command + { set +x; } 2>/dev/null + + local exp_exit="$1" + shift + "$@" + test $? -eq $exp_exit && ret_=0 || ret_=1 + + if test "$VERBOSE" = yes && test "$gl_set_x_corrupts_stderr_" = false; then + set -x + fi + { return $ret_; } 2>/dev/null +} + # Sanitize this shell to POSIX mode, if possible. DUALCASE=1; export DUALCASE if test -n "${ZSH_VERSION+set}" && (emulate sh) >/dev/null 2>&1; then @@ -129,6 +150,7 @@ fi # ? - not ok gl_shell_test_script_=' test $(echo y) = y || exit 1 +f_local_() { local v=1; }; f_local_ || exit 1 score_=10 if test "$VERBOSE" = yes; then test -n "$( (exec 3>&1; set -x; P=1 true 2>&3) 2> /dev/null)" && score_=9 diff --git a/tests/install/basic-1.sh b/tests/install/basic-1.sh index 0c0d1de8..db3b3c31 100755 --- a/tests/install/basic-1.sh +++ b/tests/install/basic-1.sh @@ -1,7 +1,7 @@ #! /bin/sh # Basic tests for "install". -# Copyright (C) 1998-2014 Free Software Foundation, Inc. +# Copyright (C) 1998-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -80,8 +80,8 @@ iwd=$(pwd) mkdir sub || fail=1 (cd sub && chmod 0 . && - ginstall -d "$iwd/xx/yy" rel/sub1 rel/sub2 2> /dev/null -) && fail=1 + returns_ 1 ginstall -d "$iwd/xx/yy" rel/sub1 rel/sub2 2> /dev/null +) || fail=1 chmod 755 sub # Ensure that the first argument-dir has been created. diff --git a/tests/install/create-leading.sh b/tests/install/create-leading.sh index 0bff21db..c9cb1dc2 100755 --- a/tests/install/create-leading.sh +++ b/tests/install/create-leading.sh @@ -1,7 +1,7 @@ #! /bin/sh # Test -D option. -# Copyright (C) 2000-2014 Free Software Foundation, Inc. +# Copyright (C) 2000-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/install/d-slashdot.sh b/tests/install/d-slashdot.sh index 044b8bf5..eeb62ae9 100755 --- a/tests/install/d-slashdot.sh +++ b/tests/install/d-slashdot.sh @@ -1,7 +1,7 @@ #!/bin/sh # Ensure that ginstall -d works with arguments specified with a trailing "/.". -# Copyright (C) 2005-2014 Free Software Foundation, Inc. +# Copyright (C) 2005-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/install/install-C-root.sh b/tests/install/install-C-root.sh index 473725af..cadc8e22 100755 --- a/tests/install/install-C-root.sh +++ b/tests/install/install-C-root.sh @@ -1,7 +1,7 @@ #!/bin/sh # Ensure "install -C" compares owner and group. -# Copyright (C) 2008-2014 Free Software Foundation, Inc. +# Copyright (C) 2008-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/install/install-C-selinux.sh b/tests/install/install-C-selinux.sh index 722e5b01..06e6c025 100755 --- a/tests/install/install-C-selinux.sh +++ b/tests/install/install-C-selinux.sh @@ -1,7 +1,7 @@ #!/bin/sh # Ensure "install -C" compares SELinux context. -# Copyright (C) 2008-2014 Free Software Foundation, Inc. +# Copyright (C) 2008-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/install/install-C.sh b/tests/install/install-C.sh index 9ee1685a..630005c8 100755 --- a/tests/install/install-C.sh +++ b/tests/install/install-C.sh @@ -1,7 +1,7 @@ #!/bin/sh # Ensure "install -C" works. (basic tests) -# Copyright (C) 2008-2014 Free Software Foundation, Inc. +# Copyright (C) 2008-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -107,9 +107,9 @@ ginstall -Cv -m$mode2 a b > out || fail=1 compare out out_empty || fail=1 # options -C and --preserve-timestamps are mutually exclusive -ginstall -C --preserve-timestamps a b && fail=1 +returns_ 1 ginstall -C --preserve-timestamps a b || fail=1 # options -C and --strip are mutually exclusive -ginstall -C --strip --strip-program=echo a b && fail=1 +returns_ 1 ginstall -C --strip --strip-program=echo a b || fail=1 Exit $fail diff --git a/tests/install/strip-program.sh b/tests/install/strip-program.sh index 874329ae..103f5494 100755 --- a/tests/install/strip-program.sh +++ b/tests/install/strip-program.sh @@ -1,7 +1,7 @@ #!/bin/sh # Ensure "install -s --strip-program=PROGRAM" uses the program to strip -# Copyright (C) 2008-2014 Free Software Foundation, Inc. +# Copyright (C) 2008-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -22,7 +22,7 @@ print_ver_ ginstall working_umask_or_skip_ cat <<EOF > b || framework_failure_ -#!$PREFERABLY_POSIX_SHELL +#!$SHELL sed s/b/B/ \$1 > \$1.t && mv \$1.t \$1 EOF chmod a+x b || framework_failure_ @@ -34,7 +34,7 @@ ginstall src dest -s --strip-program=./b || fail=1 compare exp dest || fail=1 # Check that install cleans up properly if strip fails. -ginstall src dest2 -s --strip-program=./FOO && fail=1 +returns_ 1 ginstall src dest2 -s --strip-program=./FOO || fail=1 test -e dest2 && fail=1 Exit $fail diff --git a/tests/install/trap.sh b/tests/install/trap.sh index 235cd1d1..0851ba62 100755 --- a/tests/install/trap.sh +++ b/tests/install/trap.sh @@ -2,7 +2,7 @@ # Ensure that 'install -s' doesn't infloop when its parent # process traps CHLD signal. -# Copyright (C) 2004-2014 Free Software Foundation, Inc. +# Copyright (C) 2004-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/ln/backup-1.sh b/tests/ln/backup-1.sh index 15aff2d0..08551c51 100755 --- a/tests/ln/backup-1.sh +++ b/tests/ln/backup-1.sh @@ -2,7 +2,7 @@ # Try to create a symlink with backup where the destination file exists # and the backup file name is a hard link to the destination file. -# Copyright (C) 1999-2014 Free Software Foundation, Inc. +# Copyright (C) 1999-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/ln/hard-backup.sh b/tests/ln/hard-backup.sh index 5f867bc9..317b2f3a 100755 --- a/tests/ln/hard-backup.sh +++ b/tests/ln/hard-backup.sh @@ -1,7 +1,7 @@ #!/bin/sh # Ensure that 'ln --backup F F' gives a proper diagnostic. -# Copyright (C) 2006-2014 Free Software Foundation, Inc. +# Copyright (C) 2006-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/ln/hard-to-sym.sh b/tests/ln/hard-to-sym.sh index 995d3cf6..edcee660 100755 --- a/tests/ln/hard-to-sym.sh +++ b/tests/ln/hard-to-sym.sh @@ -1,7 +1,7 @@ #!/bin/sh # Tests for ln -L/-P. -# Copyright (C) 2009-2014 Free Software Foundation, Inc. +# Copyright (C) 2009-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -29,24 +29,30 @@ ln -s -L -P symlink2 symlink3 || fail=1 # =================================================== # ensure that -L follows symlinks, and overrides -P -ln -P -L symlink3 hard-to-a || fail=1 -ls=$(ls -lG hard-to-a)x -case "$ls" in - *'hard-to-ax') ;; - *'hard-to-a -> '*x) fail=1 ;; - *) framework_failure_ ;; -esac +if ln -P -L symlink3 hard-to-a; then + ls=$(ls -lG hard-to-a)x + case "$ls" in + *'hard-to-ax') ;; + *'hard-to-a -> '*x) fail=1 ;; + *) framework_failure_ ;; + esac +else + fail=1 +fi # =================================================== # ensure that -P links (or at least duplicates) symlinks, and overrides -L -ln -L -P symlink3 hard-to-3 || fail=1 -ls=$(ls -lG hard-to-3)x -case "$ls" in - *'hard-to-3 -> symlink2x') ;; - *'hard-to-3x') fail=1 ;; - *'hard-to-3 -> '*x) fail=1 ;; - *) framework_failure_ ;; -esac +if ln -L -P symlink3 hard-to-3; then + ls=$(ls -lG hard-to-3)x + case "$ls" in + *'hard-to-3 -> symlink2x') ;; + *'hard-to-3x') fail=1 ;; + *'hard-to-3 -> '*x) fail=1 ;; + *) framework_failure_ ;; + esac +else + fail=1 +fi # =================================================== # Create a hard link to a dangling symlink. diff --git a/tests/ln/misc.sh b/tests/ln/misc.sh index 0615d6c5..68756309 100755 --- a/tests/ln/misc.sh +++ b/tests/ln/misc.sh @@ -1,7 +1,7 @@ #!/bin/sh # Miscellaneous tests for "ln". -# Copyright (C) 1998-2014 Free Software Foundation, Inc. +# Copyright (C) 1998-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -52,20 +52,20 @@ rm -rf $d $f touch $f || framework_failure_ rm -rf $d || framework_failure_ mkdir $d $d/$f || framework_failure_ -ln $f $d/ 2> /dev/null && fail=1 -ln -s $f $d/ 2> /dev/null && fail=1 +returns_ 1 ln $f $d/ 2> /dev/null || fail=1 +returns_ 1 ln -s $f $d/ 2> /dev/null || fail=1 rm -rf $d $f # Make sure we get a failure with existing dest without -f option touch $t || framework_failure_ # FIXME: don't ignore the error message but rather test # it to make sure it's the right one. -ln -s $t $t 2> /dev/null && fail=1 +returns_ 1 ln -s $t $t 2> /dev/null || fail=1 rm $t # Make sure -sf fails when src and dest are the same touch $t || framework_failure_ -ln -sf $t $t 2> /dev/null && fail=1 +returns_ 1 ln -sf $t $t 2> /dev/null || fail=1 rm $t # Create a symlink with source file and no explicit directory diff --git a/tests/ln/relative.sh b/tests/ln/relative.sh index 5cf280a5..bb71e268 100755 --- a/tests/ln/relative.sh +++ b/tests/ln/relative.sh @@ -1,7 +1,7 @@ #!/bin/sh # Test "ln --relative". -# Copyright (C) 2012-2014 Free Software Foundation, Inc. +# Copyright (C) 2012-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/ln/sf-1.sh b/tests/ln/sf-1.sh index 17e67a9f..2895e14c 100755 --- a/tests/ln/sf-1.sh +++ b/tests/ln/sf-1.sh @@ -1,7 +1,7 @@ #!/bin/sh # Test "ln -sf". -# Copyright (C) 1997-2014 Free Software Foundation, Inc. +# Copyright (C) 1997-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/ln/slash-decorated-nonexistent-dest.sh b/tests/ln/slash-decorated-nonexistent-dest.sh index 6e537a9b..7a0696f2 100755 --- a/tests/ln/slash-decorated-nonexistent-dest.sh +++ b/tests/ln/slash-decorated-nonexistent-dest.sh @@ -1,7 +1,7 @@ #!/bin/sh # ensure that touch f; ln -T f no-such-file/ does not mistakenly succeed -# Copyright (C) 2009-2014 Free Software Foundation, Inc. +# Copyright (C) 2009-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -23,7 +23,7 @@ touch f || framework_failure_ # Before coreutils-7.6, this would succeed on Solaris 10 -ln -T f no-such-file/ && fail=1 +returns_ 1 ln -T f no-such-file/ || fail=1 test -e no-such-file && fail=1 Exit $fail diff --git a/tests/ln/target-1.sh b/tests/ln/target-1.sh index 2ddad3fc..cdd0c2e2 100755 --- a/tests/ln/target-1.sh +++ b/tests/ln/target-1.sh @@ -1,7 +1,7 @@ #!/bin/sh # Test "ln --target-dir" with one file. -# Copyright (C) 2002-2014 Free Software Foundation, Inc. +# Copyright (C) 2002-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/local.mk b/tests/local.mk index e0f1f84e..7df04dac 100644 --- a/tests/local.mk +++ b/tests/local.mk @@ -1,6 +1,6 @@ ## Process this file with automake to produce Makefile.in -*-Makefile-*-. -## Copyright (C) 2007-2014 Free Software Foundation, Inc. +## Copyright (C) 2007-2015 Free Software Foundation, Inc. ## This program is free software: you can redistribute it and/or modify ## it under the terms of the GNU General Public License as published by @@ -79,7 +79,7 @@ TESTS_ENVIRONMENT = \ MAKE=$(MAKE) \ PACKAGE_VERSION=$(PACKAGE_VERSION) \ PERL='$(PERL)' \ - PREFERABLY_POSIX_SHELL='$(PREFERABLY_POSIX_SHELL)' \ + SHELL='$(PREFERABLY_POSIX_SHELL)' \ ; test -d /usr/xpg4/bin && PATH='/usr/xpg4/bin$(PATH_SEPARATOR)'"$$PATH"; \ PATH='$(abs_top_builddir)/src$(PATH_SEPARATOR)'"$$PATH" \ ; 9>&2 @@ -117,6 +117,7 @@ all_root_tests = \ tests/df/problematic-chars.sh \ tests/df/over-mount-device.sh \ tests/du/bind-mount-dir-cycle.sh \ + tests/du/bind-mount-dir-cycle-v2.sh \ tests/id/setgid.sh \ tests/install/install-C-root.sh \ tests/ls/capability.sh \ @@ -127,6 +128,7 @@ all_root_tests = \ tests/misc/truncate-owned-by-other.sh \ tests/mkdir/writable-under-readonly.sh \ tests/mkdir/smack-root.sh \ + tests/mv/hardlink-case.sh \ tests/mv/sticky-to-xpart.sh \ tests/rm/fail-2eperm.sh \ tests/rm/no-give-up.sh \ @@ -159,6 +161,7 @@ check-root: all_tests = \ tests/misc/help-version.sh \ tests/tail-2/inotify-race.sh \ + tests/tail-2/inotify-race2.sh \ tests/misc/invalid-opt.pl \ tests/rm/ext3-perf.sh \ tests/rm/cycle.sh \ @@ -169,7 +172,10 @@ all_tests = \ tests/tail-2/inotify-hash-abuse2.sh \ tests/tail-2/F-vs-missing.sh \ tests/tail-2/F-vs-rename.sh \ + tests/tail-2/F-headers.sh \ + tests/tail-2/descriptor-vs-rename.sh \ tests/tail-2/inotify-rotate.sh \ + tests/tail-2/inotify-rotate-resources.sh \ tests/chmod/no-x.sh \ tests/chgrp/basic.sh \ tests/rm/dangling-symlink.sh \ @@ -193,7 +199,6 @@ all_tests = \ tests/rm/i-1.sh \ tests/rm/i-never.sh \ tests/rm/i-no-r.sh \ - tests/tail-2/infloop-1.sh \ tests/rm/ignorable.sh \ tests/rm/inaccessible.sh \ tests/rm/interactive-always.sh \ @@ -231,6 +236,7 @@ all_tests = \ tests/misc/test.pl \ tests/misc/seq.pl \ tests/misc/seq-long-double.sh \ + tests/misc/seq-precision.sh \ tests/misc/head.pl \ tests/misc/head-elide-tail.pl \ tests/tail-2/tail-n0f.sh \ @@ -256,8 +262,10 @@ all_tests = \ tests/misc/wc-files0-from.pl \ tests/misc/wc-files0.sh \ tests/misc/wc-parallel.sh \ + tests/misc/wc-proc.sh \ tests/misc/cat-proc.sh \ tests/misc/cat-buf.sh \ + tests/misc/cat-self.sh \ tests/misc/base64.pl \ tests/misc/basename.pl \ tests/misc/close-stdout.sh \ @@ -274,6 +282,7 @@ all_tests = \ tests/misc/expand.pl \ tests/misc/expr.pl \ tests/misc/factor.pl \ + tests/misc/factor-parallel.sh \ tests/misc/false-status.sh \ tests/misc/fold.pl \ tests/misc/groups-dash.sh \ @@ -294,6 +303,7 @@ all_tests = \ tests/misc/nproc-positive.sh \ tests/misc/numfmt.pl \ tests/misc/od-N.sh \ + tests/misc/od-j.sh \ tests/misc/od-multiple-t.sh \ tests/misc/od-x8.sh \ tests/misc/paste.pl \ @@ -315,9 +325,9 @@ all_tests = \ tests/misc/sha384sum.pl \ tests/misc/sha512sum.pl \ tests/misc/shred-exact.sh \ - tests/misc/shred-negative.sh \ tests/misc/shred-passes.sh \ tests/misc/shred-remove.sh \ + tests/misc/shred-size.sh \ tests/misc/shuf.sh \ tests/misc/shuf-reservoir.sh \ tests/misc/sort.pl \ @@ -353,6 +363,7 @@ all_tests = \ tests/split/line-bytes.sh \ tests/split/l-chunk.sh \ tests/split/r-chunk.sh \ + tests/split/record-sep.sh \ tests/split/numeric.sh \ tests/split/guard-input.sh \ tests/misc/stat-birthtime.sh \ @@ -369,12 +380,12 @@ all_tests = \ tests/misc/stty-row-col.sh \ tests/misc/sum.pl \ tests/misc/sum-sysv.sh \ + tests/misc/sync.sh \ tests/misc/tac.pl \ tests/misc/tac-continue.sh \ tests/misc/tac-2-nonseekable.sh \ tests/misc/tail.pl \ tests/misc/tee.sh \ - tests/misc/tee-dash.sh \ tests/misc/test-diag.pl \ tests/misc/timeout.sh \ tests/misc/timeout-blocked.pl \ @@ -395,9 +406,12 @@ all_tests = \ tests/misc/uniq.pl \ tests/misc/uniq-perf.sh \ tests/misc/xattr.sh \ + tests/misc/yes.sh \ tests/tail-2/wait.sh \ tests/tail-2/retry.sh \ - tests/tail-2/symlink.sh \ + tests/tail-2/symlink.sh \ + tests/tail-2/tail-c.sh \ + tests/tail-2/truncate.sh \ tests/chmod/c-option.sh \ tests/chmod/equal-x.sh \ tests/chmod/equals.sh \ @@ -426,6 +440,7 @@ all_tests = \ tests/cp/dir-rm-dest.sh \ tests/cp/dir-slash.sh \ tests/cp/dir-vs-file.sh \ + tests/cp/duplicate-sources.sh \ tests/cp/existing-perm-dir.sh \ tests/cp/existing-perm-race.sh \ tests/cp/fail-perm.sh \ @@ -476,7 +491,7 @@ all_tests = \ tests/dd/ascii.sh \ tests/dd/direct.sh \ tests/dd/misc.sh \ - tests/dd/no-allocate.sh \ + tests/dd/no-allocate.sh \ tests/dd/nocache.sh \ tests/dd/not-rewound.sh \ tests/dd/reblock.sh \ @@ -488,6 +503,7 @@ all_tests = \ tests/dd/stderr.sh \ tests/dd/unblock.pl \ tests/dd/unblock-sync.sh \ + tests/dd/stats.sh \ tests/df/total-verify.sh \ tests/du/2g.sh \ tests/du/8gb.sh \ @@ -549,6 +565,7 @@ all_tests = \ tests/ls/file-type.sh \ tests/ls/follow-slink.sh \ tests/ls/getxattr-speedup.sh \ + tests/ls/hex-option.sh \ tests/ls/infloop.sh \ tests/ls/inode.sh \ tests/ls/m-option.sh \ @@ -599,7 +616,6 @@ all_tests = \ tests/mv/hard-3.sh \ tests/mv/hard-4.sh \ tests/mv/hard-link-1.sh \ - tests/mv/hard-verbose.sh \ tests/mv/i-1.pl \ tests/mv/i-2.sh \ tests/mv/i-3.sh \ diff --git a/tests/ls/abmon-align.sh b/tests/ls/abmon-align.sh index 7630889e..088be160 100755 --- a/tests/ls/abmon-align.sh +++ b/tests/ls/abmon-align.sh @@ -1,7 +1,7 @@ #!/bin/sh # Ensure ls output is aligned when using abbreviated months from the locale -# Copyright (C) 2009-2014 Free Software Foundation, Inc. +# Copyright (C) 2009-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/ls/block-size.sh b/tests/ls/block-size.sh index c4861629..9208b40d 100755 --- a/tests/ls/block-size.sh +++ b/tests/ls/block-size.sh @@ -1,7 +1,7 @@ #!/bin/sh # Exercise ls --block-size and related options. -# Copyright (C) 2011-2014 Free Software Foundation, Inc. +# Copyright (C) 2011-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/ls/capability.sh b/tests/ls/capability.sh index 54ba296c..bd32be26 100755 --- a/tests/ls/capability.sh +++ b/tests/ls/capability.sh @@ -1,7 +1,7 @@ #!/bin/sh # Ensure "ls --color" properly colorizes file with capability. -# Copyright (C) 2008-2014 Free Software Foundation, Inc. +# Copyright (C) 2008-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/ls/color-clear-to-eol.sh b/tests/ls/color-clear-to-eol.sh index a9cc6e91..54878184 100755 --- a/tests/ls/color-clear-to-eol.sh +++ b/tests/ls/color-clear-to-eol.sh @@ -1,7 +1,7 @@ #!/bin/sh # ensure that ls --color works well when a colored name is wrapped -# Copyright (C) 2009-2014 Free Software Foundation, Inc. +# Copyright (C) 2009-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/ls/color-dtype-dir.sh b/tests/ls/color-dtype-dir.sh index 559a1884..2c891727 100755 --- a/tests/ls/color-dtype-dir.sh +++ b/tests/ls/color-dtype-dir.sh @@ -4,7 +4,7 @@ # directories the same as the first one -- but only on a file system # with dirent.d_type support. -# Copyright (C) 2006-2014 Free Software Foundation, Inc. +# Copyright (C) 2006-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/ls/color-norm.sh b/tests/ls/color-norm.sh index 23c01871..8d86f19a 100755 --- a/tests/ls/color-norm.sh +++ b/tests/ls/color-norm.sh @@ -1,9 +1,9 @@ #!/bin/sh # Ensure "ls --color" properly colors "normal" text and files. -# I.E. that it uses NORMAL to style non file name output and +# I.e., that it uses NORMAL to style non file name output and # file names with no associated color (unless FILE is also set). -# Copyright (C) 2010-2014 Free Software Foundation, Inc. +# Copyright (C) 2010-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/ls/color-term.sh b/tests/ls/color-term.sh index 8eb3783a..97b0aa36 100755 --- a/tests/ls/color-term.sh +++ b/tests/ls/color-term.sh @@ -1,7 +1,7 @@ #!/bin/sh # Ensure "ls --color" doesn't output colors for TERM=dumb -# Copyright (C) 2014 Free Software Foundation, Inc. +# Copyright (C) 2014-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/ls/dangle.sh b/tests/ls/dangle.sh index 628f760b..d27f03fe 100755 --- a/tests/ls/dangle.sh +++ b/tests/ls/dangle.sh @@ -1,7 +1,7 @@ #!/bin/sh # Make sure ls properly handles dangling symlinks vs. ls's -L, -H, options. -# Copyright (C) 2003-2014 Free Software Foundation, Inc. +# Copyright (C) 2003-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -19,6 +19,9 @@ . "${srcdir=.}/tests/init.sh"; path_prepend_ ./src print_ver_ ls +LS_MINOR_PROBLEM=1 +LS_FAILURE=2 + ln -s no-such-file dangle || framework_failure_ mkdir -p dir/sub || framework_failure_ ln -s dir slink-to-dir || framework_failure_ @@ -27,11 +30,10 @@ ln -s no-such d/dangle || framework_failure_ printf '? dangle\n' > subdir_Li_exp || framework_failure_ printf 'total 0\n? dangle\n' > subdir_Ls_exp || framework_failure_ - # This must exit nonzero. -ls -L dangle > /dev/null 2>&1 && fail=1 +returns_ $LS_FAILURE ls -L dangle > /dev/null 2>&1 || fail=1 # So must this. -ls -H dangle > /dev/null 2>&1 && fail=1 +returns_ $LS_FAILURE ls -H dangle > /dev/null 2>&1 || fail=1 # This must exit successfully. ls dangle >> out || fail=1 @@ -51,12 +53,12 @@ compare exp out || fail=1 # Ensure that ls -Li prints "?" as the inode of a dangling symlink. rm -f out -ls -Li d > out 2>/dev/null && fail=1 +returns_ $LS_MINOR_PROBLEM ls -Li d > out 2>/dev/null || fail=1 compare subdir_Li_exp out || fail=1 # Ensure that ls -Ls prints "?" as the allocation of a dangling symlink. rm -f out -ls -Ls d > out 2>/dev/null && fail=1 +returns_ $LS_MINOR_PROBLEM ls -Ls d > out 2>/dev/null || fail=1 compare subdir_Ls_exp out || fail=1 Exit $fail diff --git a/tests/ls/dired.sh b/tests/ls/dired.sh index e87590e7..6a501ad1 100755 --- a/tests/ls/dired.sh +++ b/tests/ls/dired.sh @@ -1,7 +1,7 @@ #!/bin/sh # make sure --dired option works -# Copyright (C) 2001-2014 Free Software Foundation, Inc. +# Copyright (C) 2001-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/ls/file-type.sh b/tests/ls/file-type.sh index 0afa4d4e..e594c999 100755 --- a/tests/ls/file-type.sh +++ b/tests/ls/file-type.sh @@ -1,7 +1,7 @@ #!/bin/sh # contrast ls -F, ls -p, and ls --indicator-style=file-type -# Copyright (C) 2002-2014 Free Software Foundation, Inc. +# Copyright (C) 2002-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/ls/follow-slink.sh b/tests/ls/follow-slink.sh index 3357439a..edf6a481 100755 --- a/tests/ls/follow-slink.sh +++ b/tests/ls/follow-slink.sh @@ -1,7 +1,7 @@ #!/bin/sh # make sure ls -L always follows symlinks -# Copyright (C) 2000-2014 Free Software Foundation, Inc. +# Copyright (C) 2000-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -19,6 +19,8 @@ . "${srcdir=.}/tests/init.sh"; path_prepend_ ./src print_ver_ ls +LS_FAILURE=2 + # Isolate output files from directory being listed mkdir dir dir/sub dir1 || framework_failure_ cd dir || framework_failure_ @@ -32,7 +34,7 @@ ls -F link > /dev/null || framework_failure_ # When explicitly listing a broken link, the command must fail. -ls -L link 2> /dev/null && fail=1 +returns_ $LS_FAILURE ls -L link 2> /dev/null || fail=1 # When encountering a broken link implicitly, Solaris 9 and OpenBSD 3.4 # list the link, provided no further information about the link needed diff --git a/tests/ls/getxattr-speedup.sh b/tests/ls/getxattr-speedup.sh index 0144571e..be43c50e 100755 --- a/tests/ls/getxattr-speedup.sh +++ b/tests/ls/getxattr-speedup.sh @@ -4,7 +4,7 @@ # This test is skipped on systems that lack LD_PRELOAD support; that's fine. # Similarly, on a system that lacks getxattr altogether, skipping it is fine. -# Copyright (C) 2012-2014 Free Software Foundation, Inc. +# Copyright (C) 2012-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -55,7 +55,7 @@ gcc_shared_ k.c k.so \ seq 20 | xargs touch || framework_failure_ # Finally, run the test: -LD_PRELOAD=./k.so ls --color=always -l . || fail=1 +LD_PRELOAD=$LD_PRELOAD:./k.so ls --color=always -l . || fail=1 test -f x || skip_ "internal test failure: maybe LD_PRELOAD doesn't work?" diff --git a/tests/misc/tee-dash.sh b/tests/ls/hex-option.sh index 761a4780..3f915ee7 100755 --- a/tests/misc/tee-dash.sh +++ b/tests/ls/hex-option.sh @@ -1,7 +1,7 @@ #!/bin/sh -# test for "tee -". +# accept hex/oct numbers to -w and -T -# Copyright (C) 2005-2014 Free Software Foundation, Inc. +# Copyright (C) 2014-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -17,8 +17,8 @@ # along with this program. If not, see <http://www.gnu.org/licenses/>. . "${srcdir=.}/tests/init.sh"; path_prepend_ ./src -print_ver_ tee +print_ver_ ls -tee - </dev/null || fail=1 +ls -x -T0x10 -w010 || fail=1 Exit $fail diff --git a/tests/ls/infloop.sh b/tests/ls/infloop.sh index 48d356a0..34dbfb2c 100755 --- a/tests/ls/infloop.sh +++ b/tests/ls/infloop.sh @@ -2,7 +2,7 @@ # show that the following no longer makes ls infloop # mkdir loop; cd loop; ln -s ../loop sub; ls -RL # Also ensure ls exits with status = 2 in that case. -# Copyright (C) 2001-2014 Free Software Foundation, Inc. +# Copyright (C) 2001-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/ls/inode.sh b/tests/ls/inode.sh index e09efa60..ea5494e9 100755 --- a/tests/ls/inode.sh +++ b/tests/ls/inode.sh @@ -1,7 +1,7 @@ #!/bin/sh # Make sure that ls -i works properly on symlinks. -# Copyright (C) 2003-2014 Free Software Foundation, Inc. +# Copyright (C) 2003-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/ls/m-option.sh b/tests/ls/m-option.sh index 2255b6eb..ca8e01b5 100755 --- a/tests/ls/m-option.sh +++ b/tests/ls/m-option.sh @@ -1,7 +1,7 @@ #!/bin/sh # exercise the -m option -# Copyright (C) 2003-2014 Free Software Foundation, Inc. +# Copyright (C) 2003-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/ls/multihardlink.sh b/tests/ls/multihardlink.sh index 4407ba61..25ed08f3 100755 --- a/tests/ls/multihardlink.sh +++ b/tests/ls/multihardlink.sh @@ -1,7 +1,7 @@ #!/bin/sh # Ensure "ls --color" properly colorizes hard linked files. -# Copyright (C) 2008-2014 Free Software Foundation, Inc. +# Copyright (C) 2008-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/ls/nameless-uid.sh b/tests/ls/nameless-uid.sh index db6c56ea..cd3a4094 100755 --- a/tests/ls/nameless-uid.sh +++ b/tests/ls/nameless-uid.sh @@ -1,7 +1,7 @@ #!/bin/sh # Ensure that ls -l works on files with nameless uid and/or gid -# Copyright (C) 2006-2014 Free Software Foundation, Inc. +# Copyright (C) 2006-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/ls/no-arg.sh b/tests/ls/no-arg.sh index e356a296..793080f1 100755 --- a/tests/ls/no-arg.sh +++ b/tests/ls/no-arg.sh @@ -1,7 +1,7 @@ #!/bin/sh # make sure ls and 'ls -R' do the right thing when invoked with no arguments. -# Copyright (C) 2001-2014 Free Software Foundation, Inc. +# Copyright (C) 2001-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/ls/no-cap.sh b/tests/ls/no-cap.sh index a75180c2..ecbfb31c 100755 --- a/tests/ls/no-cap.sh +++ b/tests/ls/no-cap.sh @@ -1,7 +1,7 @@ #!/bin/sh # ensure that an empty "ca=" attribute disables ls's capability-checking -# Copyright (C) 2008-2014 Free Software Foundation, Inc. +# Copyright (C) 2008-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -20,13 +20,14 @@ print_ver_ ls require_strace_ capget +LS_COLORS=ca=1; export LS_COLORS strace -e capget ls --color=always > /dev/null 2> out || fail=1 $EGREP 'capget\(' out || skip_ "your ls doesn't call capget" rm -f out -eval "$(TERM=xterm dircolors -b | sed 's/ca=[^:]*:/ca=:/')" -strace -e capget ls --color=always > /dev/null 2> out || fail=1 +LS_COLORS=ca=:; export LS_COLORS +strace -e capget ls --color=always > /dev/null 2> out || fail=1 $EGREP 'capget\(' out && fail=1 Exit $fail diff --git a/tests/ls/proc-selinux-segfault.sh b/tests/ls/proc-selinux-segfault.sh index 1b7a39be..333e040d 100755 --- a/tests/ls/proc-selinux-segfault.sh +++ b/tests/ls/proc-selinux-segfault.sh @@ -1,7 +1,7 @@ #!/bin/sh # ls -l /proc/sys would segfault when built against libselinux1 2.0.15-2+b1 -# Copyright (C) 2008-2014 Free Software Foundation, Inc. +# Copyright (C) 2008-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/ls/readdir-mountpoint-inode.sh b/tests/ls/readdir-mountpoint-inode.sh index 83ebe68c..e566dc24 100755 --- a/tests/ls/readdir-mountpoint-inode.sh +++ b/tests/ls/readdir-mountpoint-inode.sh @@ -1,7 +1,7 @@ #!/bin/sh # ensure that ls -i works also for mount points -# Copyright (C) 2009-2014 Free Software Foundation, Inc. +# Copyright (C) 2009-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/ls/recursive.sh b/tests/ls/recursive.sh index be2d849b..05a384c7 100755 --- a/tests/ls/recursive.sh +++ b/tests/ls/recursive.sh @@ -2,7 +2,7 @@ # 4.1.1 and 4.1.2 had a bug whereby some recursive listings # didn't include a blank line between per-directory groups of files. -# Copyright (C) 2001-2014 Free Software Foundation, Inc. +# Copyright (C) 2001-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/ls/root-rel-symlink-color.sh b/tests/ls/root-rel-symlink-color.sh index 2318a479..0b977fcb 100755 --- a/tests/ls/root-rel-symlink-color.sh +++ b/tests/ls/root-rel-symlink-color.sh @@ -1,7 +1,7 @@ #!/bin/sh # Exercise the 8.17 ls bug with coloring relative-named symlinks in "/". -# Copyright (C) 2012-2014 Free Software Foundation, Inc. +# Copyright (C) 2012-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/ls/rt-1.sh b/tests/ls/rt-1.sh index 99c62afe..44e02476 100755 --- a/tests/ls/rt-1.sh +++ b/tests/ls/rt-1.sh @@ -1,7 +1,7 @@ #!/bin/sh # Make sure name is used as secondary key when sorting on mtime or ctime. -# Copyright (C) 1998-2014 Free Software Foundation, Inc. +# Copyright (C) 1998-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/ls/slink-acl.sh b/tests/ls/slink-acl.sh index 8ba3be15..05b98cec 100755 --- a/tests/ls/slink-acl.sh +++ b/tests/ls/slink-acl.sh @@ -1,7 +1,7 @@ #!/bin/sh # verify that ls -lL works when applied to a symlink to an ACL'd file -# Copyright (C) 2011-2014 Free Software Foundation, Inc. +# Copyright (C) 2011-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/ls/stat-dtype.sh b/tests/ls/stat-dtype.sh index 01da0c8a..1d6f5ec3 100755 --- a/tests/ls/stat-dtype.sh +++ b/tests/ls/stat-dtype.sh @@ -3,7 +3,7 @@ # Also check for the dtype-related (and fs-type dependent) bug # in coreutils-6.0 that made ls -CF columns misaligned. -# Copyright (C) 2006-2014 Free Software Foundation, Inc. +# Copyright (C) 2006-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/ls/stat-failed.sh b/tests/ls/stat-failed.sh index 9de018f3..002b71cf 100755 --- a/tests/ls/stat-failed.sh +++ b/tests/ls/stat-failed.sh @@ -2,7 +2,7 @@ # Verify that ls works properly when it fails to stat a file that is # not mentioned on the command line. -# Copyright (C) 2006-2014 Free Software Foundation, Inc. +# Copyright (C) 2006-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -21,6 +21,8 @@ print_ver_ ls skip_if_root_ +LS_MINOR_PROBLEM=1 + mkdir d || framework_failure_ ln -s / d/s || framework_failure_ chmod 600 d || framework_failure_ @@ -38,7 +40,7 @@ sed 's/^l/?/' out | compare exp - || fail=1 # Ensure that the offsets in --dired output are accurate. rm -f out exp -ls --dired -l d > out && fail=1 +returns_ $LS_MINOR_PROBLEM ls --dired -l d > out || fail=1 cat <<\EOF > exp || fail=1 total 0 diff --git a/tests/ls/stat-free-color.sh b/tests/ls/stat-free-color.sh index 72a09bb6..fb2ee8b5 100755 --- a/tests/ls/stat-free-color.sh +++ b/tests/ls/stat-free-color.sh @@ -1,7 +1,7 @@ #!/bin/sh # Show that --color need not use stat, as long as we have d_type support. -# Copyright (C) 2011-2014 Free Software Foundation, Inc. +# Copyright (C) 2011-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/ls/stat-free-symlinks.sh b/tests/ls/stat-free-symlinks.sh index 0bc4c6aa..a9322e03 100755 --- a/tests/ls/stat-free-symlinks.sh +++ b/tests/ls/stat-free-symlinks.sh @@ -1,7 +1,7 @@ #!/bin/sh # ensure that ls does not stat a symlink in an unusual case -# Copyright (C) 2007-2014 Free Software Foundation, Inc. +# Copyright (C) 2007-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/ls/stat-vs-dirent.sh b/tests/ls/stat-vs-dirent.sh index 57c718a9..9903d27b 100755 --- a/tests/ls/stat-vs-dirent.sh +++ b/tests/ls/stat-vs-dirent.sh @@ -1,7 +1,7 @@ #!/bin/sh # Ensure that d_ino (from ls -di) and st_ino (from stat --format=%i) match. -# Copyright (C) 2006-2014 Free Software Foundation, Inc. +# Copyright (C) 2006-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/ls/symlink-slash.sh b/tests/ls/symlink-slash.sh index da5da28f..4f521b9e 100755 --- a/tests/ls/symlink-slash.sh +++ b/tests/ls/symlink-slash.sh @@ -1,7 +1,7 @@ #!/bin/sh # Do dereference a symlink arg if its name is written with a trailing slash. -# Copyright (C) 1999-2014 Free Software Foundation, Inc. +# Copyright (C) 1999-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/ls/time-style-diag.sh b/tests/ls/time-style-diag.sh index d292c982..1d6d8616 100755 --- a/tests/ls/time-style-diag.sh +++ b/tests/ls/time-style-diag.sh @@ -1,7 +1,7 @@ #!/bin/sh # Ensure that an invalid --time-style=ARG is diagnosed the way we want. -# Copyright (C) 2011-2014 Free Software Foundation, Inc. +# Copyright (C) 2011-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/ls/x-option.sh b/tests/ls/x-option.sh index f009cdc2..1ec23d5b 100755 --- a/tests/ls/x-option.sh +++ b/tests/ls/x-option.sh @@ -1,7 +1,7 @@ #!/bin/sh # Exercise the -x option. -# Copyright (C) 2007-2014 Free Software Foundation, Inc. +# Copyright (C) 2007-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/misc/arch.sh b/tests/misc/arch.sh index 95369067..d5ae5822 100755 --- a/tests/misc/arch.sh +++ b/tests/misc/arch.sh @@ -1,7 +1,7 @@ #!/bin/sh # Ensure that arch output is equal to uname -m -# Copyright (C) 2007-2014 Free Software Foundation, Inc. +# Copyright (C) 2007-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/misc/base64.pl b/tests/misc/base64.pl index 54e2cc21..fd75c624 100755 --- a/tests/misc/base64.pl +++ b/tests/misc/base64.pl @@ -1,7 +1,7 @@ #!/usr/bin/perl # Exercise base64. -# Copyright (C) 2006-2014 Free Software Foundation, Inc. +# Copyright (C) 2006-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/misc/basename.pl b/tests/misc/basename.pl index 3aace6f8..7b0ea7dd 100755 --- a/tests/misc/basename.pl +++ b/tests/misc/basename.pl @@ -1,6 +1,6 @@ #!/usr/bin/perl # Test basename. -# Copyright (C) 2006-2014 Free Software Foundation, Inc. +# Copyright (C) 2006-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -71,7 +71,7 @@ my @Tests = ); # Append a newline to end of each expected 'OUT' string. -# Skip -z tests, i.e. those whose 'OUT' string has a trailing '\0'. +# Skip -z tests, i.e., those whose 'OUT' string has a trailing '\0'. my $t; foreach $t (@Tests) { diff --git a/tests/misc/cat-buf.sh b/tests/misc/cat-buf.sh index 592b5a1d..31382481 100755 --- a/tests/misc/cat-buf.sh +++ b/tests/misc/cat-buf.sh @@ -1,7 +1,7 @@ #!/bin/sh # Ensure that cat outputs processed data immediately. -# Copyright (C) 2009-2014 Free Software Foundation, Inc. +# Copyright (C) 2009-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -26,6 +26,8 @@ print_ver_ cat # write separately. mkfifo_or_skip_ fifo +# Terminate any background cp process +cleanup_() { kill $pid 2>/dev/null && wait $pid; } echo 1 > exp @@ -33,9 +35,9 @@ cat_buf_1() { local delay="$1" - dd count=1 if=fifo > out & + dd count=1 if=fifo > out & pid=$! (echo 1; sleep $delay; echo 2) | cat -v > fifo - wait # for dd to complete + wait $pid compare exp out } diff --git a/tests/misc/cat-proc.sh b/tests/misc/cat-proc.sh index 7b826ef3..32e71e10 100755 --- a/tests/misc/cat-proc.sh +++ b/tests/misc/cat-proc.sh @@ -2,7 +2,7 @@ # Ensure that cat -E produces same output as cat, module '$'s, # even when applied to a file in /proc. -# Copyright (C) 2006-2014 Free Software Foundation, Inc. +# Copyright (C) 2006-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/misc/cat-self.sh b/tests/misc/cat-self.sh new file mode 100755 index 00000000..57777e53 --- /dev/null +++ b/tests/misc/cat-self.sh @@ -0,0 +1,33 @@ +#!/bin/sh +# Check that cat operates correctly when the input is the same as the output. + +# Copyright 2014-2015 Free Software Foundation, Inc. + +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. + +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. + +. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src +print_ver_ cat + +echo x >out || framework_failure_ +echo x >out1 || framework_failure_ +returns_ 1 cat out >>out || fail=1 +compare out out1 || fail=1 + +# This example is taken from the POSIX spec for 'cat'. +echo x >doc || framework_failure_ +echo y >doc.end || framework_failure_ +cat doc doc.end >doc || fail=1 +compare doc doc.end || fail=1 + +Exit $fail diff --git a/tests/misc/chcon-fail.sh b/tests/misc/chcon-fail.sh index 77b91d3b..5265fa01 100755 --- a/tests/misc/chcon-fail.sh +++ b/tests/misc/chcon-fail.sh @@ -2,7 +2,7 @@ # Ensure that chcon fails when it should. # These tests don't use any actual SE Linux syscalls. -# Copyright (C) 2007-2014 Free Software Foundation, Inc. +# Copyright (C) 2007-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -22,16 +22,16 @@ print_ver_ chcon # neither context nor file -chcon 2> /dev/null && fail=1 +returns_ 1 chcon 2> /dev/null || fail=1 # No file -chcon CON 2> /dev/null && fail=1 +returns_ 1 chcon CON 2> /dev/null || fail=1 # No file touch f -chcon --reference=f 2> /dev/null && fail=1 +returns_ 1 chcon --reference=f 2> /dev/null || fail=1 # No file -chcon -u anyone 2> /dev/null && fail=1 +returns_ 1 chcon -u anyone 2> /dev/null || fail=1 Exit $fail diff --git a/tests/misc/chcon.sh b/tests/misc/chcon.sh index ec573967..e3f61e8b 100755 --- a/tests/misc/chcon.sh +++ b/tests/misc/chcon.sh @@ -1,7 +1,7 @@ #!/bin/sh # exercise chcon -# Copyright (C) 2007-2014 Free Software Foundation, Inc. +# Copyright (C) 2007-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -44,7 +44,7 @@ stat --printf='g|%C\n' g >> out || fail=1 # Change the individual parts of the context, one by one. u2=user_u r2=object_r -t2=file_t +t2=unlabeled_t for i in --user=$u2 --role=$r2 --type=$t2 --range=$range; do chcon $i f || fail=1 stat --printf="f|$i|"'%C\n' f >> out || fail=1 @@ -63,8 +63,8 @@ f|--user=$u2|$u2:$r1:$t1:$range f|--role=$r2|$u2:$r2:$t1:$range f|--type=$t2|$u2:$r2:$t2:$range f|--range=$range|$u2:$r2:$t2:$range -f|-uroot|root:object_r:file_t:$range -f|-robject_r|root:object_r:file_t:$range +f|-uroot|root:object_r:$t2:$range +f|-robject_r|root:object_r:$t2:$range f|-ttmp_t|root:object_r:tmp_t:$range EOF diff --git a/tests/misc/chroot-credentials.sh b/tests/misc/chroot-credentials.sh index b06e8b7f..8b677100 100755 --- a/tests/misc/chroot-credentials.sh +++ b/tests/misc/chroot-credentials.sh @@ -1,7 +1,7 @@ #!/bin/sh # Verify that the credentials are changed correctly. -# Copyright (C) 2009-2014 Free Software Foundation, Inc. +# Copyright (C) 2009-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -22,6 +22,8 @@ print_ver_ chroot require_root_ +EXIT_CANCELED=125 + grep '^#define HAVE_SETGROUPS 1' "$CONFIG_HEADER" >/dev/null \ && HAVE_SETGROUPS=1 @@ -36,7 +38,8 @@ chroot --userspec=$NON_ROOT_UID: / true || fail=1 # verify that invalid groups are diagnosed for g in ' ' ',' '0trail'; do - test "$(chroot --groups="$g" / id -G)" && fail=1 + returns_ $EXIT_CANCELED chroot --groups="$g" / id -G >invalid || fail=1 + compare /dev/null invalid || fail=1 done # Verify that root credentials are kept. @@ -111,7 +114,7 @@ if ! id -u +12342; then test "$(chroot --userspec=+12342:+5678 / id -G)" = '5678' || fail=1 # Ensure we fail when we don't know what groups to set for an unknown ID - chroot --userspec=+12342 / true && fail=1 + returns_ $EXIT_CANCELED chroot --userspec=+12342 / true || fail=1 fi Exit $fail diff --git a/tests/misc/chroot-fail.sh b/tests/misc/chroot-fail.sh index a84826fd..14499edd 100755 --- a/tests/misc/chroot-fail.sh +++ b/tests/misc/chroot-fail.sh @@ -1,7 +1,7 @@ #!/bin/sh # Verify that internal failure in chroot gives exact status. -# Copyright (C) 2009-2014 Free Software Foundation, Inc. +# Copyright (C) 2009-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -29,20 +29,42 @@ test $? = 125 || fail=1 chroot --- / true # unknown option test $? = 125 || fail=1 -# Note chroot("/") succeeds for non-root users on some systems, but not all, -# however we avoid the chroot() with "/" to have common behvavior. -chroot / sh -c 'exit 2' # exit status propagation -test $? = 2 || fail=1 -chroot / . # invalid command -test $? = 126 || fail=1 -chroot / no_such # no such command -test $? = 127 || fail=1 - -# Ensure we don't chdir("/") when not changing root -# to allow only changing user ids for a command. -for dir in '/' '/.' '/../'; do - curdir=$(chroot "$dir" env pwd) || fail=1 - test "$curdir" = '/' && fail=1 -done +# chroot("/") succeeds for non-root users on some systems, but not all. +if chroot / true ; then + can_chroot_root=1 + chroot / sh -c 'exit 2' # exit status propagation + test $? = 2 || fail=1 + chroot / . # invalid command + test $? = 126 || fail=1 + chroot / no_such # no such command + test $? = 127 || fail=1 +else + test $? = 125 || fail=1 + can_chroot_root=0 +fi + +# Ensure that --skip-chdir fails with a non-"/" argument. +cat <<\EOF > exp || framework_failure_ +chroot: option --skip-chdir only permitted if NEWROOT is old '/' +Try 'chroot --help' for more information. +EOF +chroot --skip-chdir . env pwd >out 2>err && fail=1 +compare /dev/null out || fail=1 +compare exp err || fail=1 + +# Ensure we chdir("/") appropriately when NEWROOT is old "/". +if test $can_chroot_root = 1; then + ln -s / isroot || framework_failure_ + for dir in '/' '/.' '/../' isroot; do + # Verify that chroot(1) succeeds and performs chdir("/") + # (chroot(1) of coreutils-8.23 failed to run the latter). + curdir=$(chroot "$dir" env pwd) || fail=1 + test "$curdir" = '/' || fail=1 + + # Test the "--skip-chdir" option. + curdir=$(chroot --skip-chdir "$dir" env pwd) || fail=1 + test "$curdir" = '/' && fail=1 + done +fi Exit $fail diff --git a/tests/misc/close-stdout.sh b/tests/misc/close-stdout.sh index 4da696c4..6714ec0f 100755 --- a/tests/misc/close-stdout.sh +++ b/tests/misc/close-stdout.sh @@ -2,7 +2,7 @@ # Ensure that several programs work fine, even with stdout initially closed. # This is effectively a test of closeout.c's close_stdout function. -# Copyright (C) 2004-2014 Free Software Foundation, Inc. +# Copyright (C) 2004-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -44,21 +44,21 @@ sleep 0 >&- || fail=1 # This test is ineffective unless /dev/stdout also works. if "$p/src/test" -w /dev/stdout >/dev/null && "$p/src/test" ! -w /dev/stdout >&-; then - "$p/src/printf" 'foo' >&- 2>/dev/null && fail=1 - cp --verbose a b >&- 2>/dev/null && fail=1 + returns_ 1 "$p/src/printf" 'foo' >&- 2>/dev/null || fail=1 + returns_ 1 cp --verbose a b >&- 2>/dev/null || fail=1 rm -Rf tmpfile-?????? || fail=1 - mktemp tmpfile-XXXXXX >&- 2>/dev/null && fail=1 - mktemp tmpfile-XXXXXX -q >&- 2>/dev/null && fail=1 + returns_ 1 mktemp tmpfile-XXXXXX >&- 2>/dev/null || fail=1 + returns_ 1 mktemp tmpfile-XXXXXX -q >&- 2>/dev/null || fail=1 case $(echo tmpfile-??????) in 'tmpfile-??????') ;; *) fail=1 ;; esac fi # Likewise for /dev/full, if /dev/full works. if test -w /dev/full && test -c /dev/full; then - "$p/src/printf" 'foo' >/dev/full 2>/dev/null && fail=1 - cp --verbose a b >/dev/full 2>/dev/null && fail=1 + returns_ 1 "$p/src/printf" 'foo' >/dev/full 2>/dev/null || fail=1 + returns_ 1 cp --verbose a b >/dev/full 2>/dev/null || fail=1 rm -Rf tmpdir-?????? || fail=1 - mktemp -d tmpdir-XXXXXX >/dev/full 2>/dev/null && fail=1 - mktemp -d -q tmpdir-XXXXXX >/dev/full 2>/dev/null && fail=1 + returns_ 1 mktemp -d tmpdir-XXXXXX >/dev/full 2>/dev/null || fail=1 + returns_ 1 mktemp -d -q tmpdir-XXXXXX >/dev/full 2>/dev/null || fail=1 case $(echo tmpfile-??????) in 'tmpfile-??????') ;; *) fail=1 ;; esac fi diff --git a/tests/misc/comm.pl b/tests/misc/comm.pl index c96939b1..76be936f 100755 --- a/tests/misc/comm.pl +++ b/tests/misc/comm.pl @@ -2,7 +2,7 @@ # -*- perl -*- # Test comm -# Copyright (C) 2008-2014 Free Software Foundation, Inc. +# Copyright (C) 2008-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/misc/coreutils.sh b/tests/misc/coreutils.sh index a22bc9f6..c568ac02 100755 --- a/tests/misc/coreutils.sh +++ b/tests/misc/coreutils.sh @@ -1,7 +1,7 @@ #!/bin/sh # Verify behavior of separate coreutils multicall binary -# Copyright (C) 2014 Free Software Foundation, Inc. +# Copyright (C) 2014-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/misc/csplit-1000.sh b/tests/misc/csplit-1000.sh index 6757a464..9baac2fa 100755 --- a/tests/misc/csplit-1000.sh +++ b/tests/misc/csplit-1000.sh @@ -1,7 +1,7 @@ #!/bin/sh # cause a 1-byte heap buffer overrun -# Copyright (C) 2010-2014 Free Software Foundation, Inc. +# Copyright (C) 2010-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/misc/csplit-heap.sh b/tests/misc/csplit-heap.sh index 03fc9a36..9e51cb15 100755 --- a/tests/misc/csplit-heap.sh +++ b/tests/misc/csplit-heap.sh @@ -1,7 +1,7 @@ #!/bin/sh # ensure that csplit uses a bounded amount of memory -# Copyright (C) 2010-2014 Free Software Foundation, Inc. +# Copyright (C) 2010-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/misc/csplit-suppress-matched.pl b/tests/misc/csplit-suppress-matched.pl index cea64e4f..d4ca3cd0 100755 --- a/tests/misc/csplit-suppress-matched.pl +++ b/tests/misc/csplit-suppress-matched.pl @@ -1,6 +1,6 @@ #!/usr/bin/perl -# Copyright (C) 2013-2014 Free Software Foundation, Inc. +# Copyright (C) 2013-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/misc/csplit.sh b/tests/misc/csplit.sh index da09c1f0..1ccf1218 100755 --- a/tests/misc/csplit.sh +++ b/tests/misc/csplit.sh @@ -1,7 +1,7 @@ #!/bin/sh # various csplit tests -# Copyright (C) 2001-2014 Free Software Foundation, Inc. +# Copyright (C) 2001-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/misc/cut-huge-range.sh b/tests/misc/cut-huge-range.sh index e2c4108c..035d8d08 100755 --- a/tests/misc/cut-huge-range.sh +++ b/tests/misc/cut-huge-range.sh @@ -1,7 +1,7 @@ #!/bin/sh # Ensure that cut does not allocate mem for large ranges -# Copyright (C) 2012-2014 Free Software Foundation, Inc. +# Copyright (C) 2012-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -56,8 +56,8 @@ CUT_MAX=$(echo $SIZE_MAX | sed "$subtract_one") (ulimit -v 20000; : | cut -b1-$CUT_MAX >> err 2>&1) || fail=1 # Explicitly disallow values above CUT_MAX -(ulimit -v 20000; : | cut -b$SIZE_MAX 2>/dev/null) && fail=1 -(ulimit -v 20000; : | cut -b$SIZE_OFLOW 2>/dev/null) && fail=1 +(ulimit -v 20000; : | returns_ 1 cut -b$SIZE_MAX 2>/dev/null) || fail=1 +(ulimit -v 20000; : | returns_ 1 cut -b$SIZE_OFLOW 2>/dev/null) || fail=1 compare /dev/null err || fail=1 diff --git a/tests/misc/cut.pl b/tests/misc/cut.pl index 04188621..23e9ce36 100755 --- a/tests/misc/cut.pl +++ b/tests/misc/cut.pl @@ -1,7 +1,7 @@ #!/usr/bin/perl # Test "cut". -# Copyright (C) 2006-2014 Free Software Foundation, Inc. +# Copyright (C) 2006-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/misc/date-next-dow.pl b/tests/misc/date-next-dow.pl index a1c21127..feb076be 100755 --- a/tests/misc/date-next-dow.pl +++ b/tests/misc/date-next-dow.pl @@ -1,7 +1,7 @@ #!/usr/bin/perl # Test "date". -# Copyright (C) 2005-2014 Free Software Foundation, Inc. +# Copyright (C) 2005-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/misc/date-sec.sh b/tests/misc/date-sec.sh index 9c001fdc..d3d5e6c5 100755 --- a/tests/misc/date-sec.sh +++ b/tests/misc/date-sec.sh @@ -3,7 +3,7 @@ # date --date="21:04 +0100" +%S' always prints '00'. # Before coreutils-5.2.1, it would print the seconds from the current time. -# Copyright (C) 2004-2014 Free Software Foundation, Inc. +# Copyright (C) 2004-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/misc/date.pl b/tests/misc/date.pl index 40be4cab..6a7c6f88 100755 --- a/tests/misc/date.pl +++ b/tests/misc/date.pl @@ -1,7 +1,7 @@ #!/usr/bin/perl # Test "date". -# Copyright (C) 2005-2014 Free Software Foundation, Inc. +# Copyright (C) 2005-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/misc/dircolors.pl b/tests/misc/dircolors.pl index a70a8c5d..b9f8a1d2 100755 --- a/tests/misc/dircolors.pl +++ b/tests/misc/dircolors.pl @@ -1,7 +1,7 @@ #!/usr/bin/perl # Simple dircolors tests. -# Copyright (C) 1998-2014 Free Software Foundation, Inc. +# Copyright (C) 1998-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/misc/dirname.pl b/tests/misc/dirname.pl index 34c905d4..98416694 100755 --- a/tests/misc/dirname.pl +++ b/tests/misc/dirname.pl @@ -1,7 +1,7 @@ #!/usr/bin/perl # Test "dirname". -# Copyright (C) 2006-2014 Free Software Foundation, Inc. +# Copyright (C) 2006-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/misc/env-null.sh b/tests/misc/env-null.sh index 9b9c95e7..de9e016d 100755 --- a/tests/misc/env-null.sh +++ b/tests/misc/env-null.sh @@ -1,7 +1,7 @@ #!/bin/sh # Verify behavior of env -0 and printenv -0. -# Copyright (C) 2009-2014 Free Software Foundation, Inc. +# Copyright (C) 2009-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/misc/env.sh b/tests/misc/env.sh index d06a1fb0..d7c5a099 100755 --- a/tests/misc/env.sh +++ b/tests/misc/env.sh @@ -1,7 +1,7 @@ #!/bin/sh # Verify behavior of env. -# Copyright (C) 2009-2014 Free Software Foundation, Inc. +# Copyright (C) 2009-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -102,7 +102,7 @@ cat <<EOF > unlikely_name/also_unlikely || framework_failure_ echo pass EOF chmod +x unlikely_name/also_unlikely || framework_failure_ -env also_unlikely && fail=1 +returns_ 127 env also_unlikely || fail=1 test x$(PATH=$PATH:unlikely_name env also_unlikely) = xpass || fail=1 test x$(env PATH="$PATH":unlikely_name also_unlikely) = xpass || fail=1 diff --git a/tests/misc/expand.pl b/tests/misc/expand.pl index 939e22b8..283b8579 100755 --- a/tests/misc/expand.pl +++ b/tests/misc/expand.pl @@ -1,7 +1,7 @@ #!/usr/bin/perl # Exercise expand. -# Copyright (C) 2004-2014 Free Software Foundation, Inc. +# Copyright (C) 2004-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/misc/expr.pl b/tests/misc/expr.pl index c084b118..0fa7111e 100755 --- a/tests/misc/expr.pl +++ b/tests/misc/expr.pl @@ -1,7 +1,7 @@ #!/usr/bin/perl # Basic tests for "expr". -# Copyright (C) 2001-2014 Free Software Foundation, Inc. +# Copyright (C) 2001-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/misc/factor-parallel.sh b/tests/misc/factor-parallel.sh new file mode 100755 index 00000000..8cec630e --- /dev/null +++ b/tests/misc/factor-parallel.sh @@ -0,0 +1,34 @@ +#!/bin/sh +# Test for complete lines on output + +# Copyright (C) 2015 Free Software Foundation, Inc. + +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. + +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. + +. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src +print_ver_ factor + + +odd() { LC_ALL=C sed '/[24680]$/d'; } +primes() { LC_ALL=C sed 's/.*: //; / /d'; } + +# Before v8.24 the number reported here would vary +# Note -u not supplied to split, increased batching of quickly processed items. +# As processing cost increases it becomes advantageous to use -u to keep +# the factor processes supplied with data. +nprimes=$(seq 1e6 | odd | split -nr/4 --filter='factor' | primes | wc -l) + +test "$nprimes" = '78498' || fail=1 + +Exit $fail diff --git a/tests/misc/factor.pl b/tests/misc/factor.pl index 294b814f..b48eb3c0 100755 --- a/tests/misc/factor.pl +++ b/tests/misc/factor.pl @@ -1,7 +1,7 @@ #!/usr/bin/perl # Basic tests for "factor". -# Copyright (C) 1998-2014 Free Software Foundation, Inc. +# Copyright (C) 1998-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/misc/false-status.sh b/tests/misc/false-status.sh index 77bea451..03fe98c2 100755 --- a/tests/misc/false-status.sh +++ b/tests/misc/false-status.sh @@ -2,7 +2,7 @@ # ensure that false exits nonzero even with --help or --version # and ensure that true exits nonzero when it can't write --help or --version -# Copyright (C) 2003-2014 Free Software Foundation, Inc. +# Copyright (C) 2003-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -20,12 +20,12 @@ . "${srcdir=.}/tests/init.sh"; path_prepend_ ./src print_ver_ false true -env false --version > /dev/null && fail=1 -env false --help > /dev/null && fail=1 +returns_ 1 env false --version > /dev/null || fail=1 +returns_ 1 env false --help > /dev/null || fail=1 if test -w /dev/full && test -c /dev/full; then - env true --version > /dev/full && fail=1 - env true --help > /dev/full && fail=1 + returns_ 1 env true --version > /dev/full || fail=1 + returns_ 1 env true --help > /dev/full || fail=1 fi Exit $fail diff --git a/tests/misc/fold.pl b/tests/misc/fold.pl index 69b0c5b5..be13cc14 100755 --- a/tests/misc/fold.pl +++ b/tests/misc/fold.pl @@ -1,7 +1,7 @@ #!/usr/bin/perl # Exercise fold. -# Copyright (C) 2003-2014 Free Software Foundation, Inc. +# Copyright (C) 2003-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/misc/groups-dash.sh b/tests/misc/groups-dash.sh index 0aed2229..8f7ec759 100755 --- a/tests/misc/groups-dash.sh +++ b/tests/misc/groups-dash.sh @@ -1,7 +1,7 @@ #!/bin/sh # ensure groups handles -- sanely -# Copyright (C) 2007-2014 Free Software Foundation, Inc. +# Copyright (C) 2007-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/misc/groups-version.sh b/tests/misc/groups-version.sh index a867701c..44394435 100755 --- a/tests/misc/groups-version.sh +++ b/tests/misc/groups-version.sh @@ -1,7 +1,7 @@ #!/bin/sh # ensure groups --version output is similar to id --version -# Copyright (C) 2007-2014 Free Software Foundation, Inc. +# Copyright (C) 2007-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/misc/head-c.sh b/tests/misc/head-c.sh index d6433d0d..a553a55b 100755 --- a/tests/misc/head-c.sh +++ b/tests/misc/head-c.sh @@ -1,7 +1,7 @@ #!/bin/sh # exercise head -c -# Copyright (C) 2001-2014 Free Software Foundation, Inc. +# Copyright (C) 2001-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -42,4 +42,16 @@ esac # based on the value passed to -c (ulimit -v 20000; head --bytes=-$SSIZE_MAX < /dev/null) || fail=1 +# Make sure it works on funny files in /proc and /sys. + +for file in /proc/version /sys/kernel/profiling; do + if test -r $file; then + cp -f $file copy && + head -c -1 copy > exp1 || framework_failure_ + + head -c -1 $file > out1 || fail=1 + compare exp1 out1 || fail=1 + fi +done + Exit $fail diff --git a/tests/misc/head-elide-tail.pl b/tests/misc/head-elide-tail.pl index 3c178d69..bae87174 100755 --- a/tests/misc/head-elide-tail.pl +++ b/tests/misc/head-elide-tail.pl @@ -1,7 +1,7 @@ #!/usr/bin/perl # Exercise head's --bytes=-N option. -# Copyright (C) 2003-2014 Free Software Foundation, Inc. +# Copyright (C) 2003-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/misc/head-pos.sh b/tests/misc/head-pos.sh index 1cf9e04b..c195f320 100755 --- a/tests/misc/head-pos.sh +++ b/tests/misc/head-pos.sh @@ -2,7 +2,7 @@ # When reading a specified number of lines, ensure that the output # file pointer is positioned just after those lines. -# Copyright (C) 2002-2014 Free Software Foundation, Inc. +# Copyright (C) 2002-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/misc/head-write-error.sh b/tests/misc/head-write-error.sh index 22ecf993..53582278 100755 --- a/tests/misc/head-write-error.sh +++ b/tests/misc/head-write-error.sh @@ -2,7 +2,7 @@ # Ensure we diagnose and not continue writing to # the output if we get a write error. -# Copyright (C) 2014 Free Software Foundation, Inc. +# Copyright (C) 2014-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/misc/head.pl b/tests/misc/head.pl index 159d4efc..b8bbd676 100755 --- a/tests/misc/head.pl +++ b/tests/misc/head.pl @@ -1,7 +1,7 @@ #!/usr/bin/perl # test head -# Copyright (C) 2008-2014 Free Software Foundation, Inc. +# Copyright (C) 2008-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/misc/help-version.sh b/tests/misc/help-version.sh index 0598557f..78150374 100755 --- a/tests/misc/help-version.sh +++ b/tests/misc/help-version.sh @@ -2,7 +2,7 @@ # Make sure all of these programs work properly # when invoked with --help or --version. -# Copyright (C) 2000-2014 Free Software Foundation, Inc. +# Copyright (C) 2000-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -17,14 +17,11 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. -# Ensure that $SHELL is set to *some* value and exported. -# This is required for dircolors, which would fail e.g., when -# invoked via debuild (which removes SHELL from the environment). -test "x$SHELL" = x && SHELL=/bin/sh -export SHELL - . "${srcdir=.}/tests/init.sh"; path_prepend_ ./src +# Terminate any background processes +cleanup_() { kill $pid 2>/dev/null && wait $pid; } + expected_failure_status_chroot=125 expected_failure_status_env=125 expected_failure_status_nice=125 @@ -216,8 +213,8 @@ id_setup () { args=-u; } # Use env to avoid invoking built-in sleep of Solaris 11's /bin/sh. kill_setup () { - env sleep 31.5 & - args=$! + env sleep 10m & pid=$! + args=$pid } link_setup () { args="$tmp_in link-target"; } diff --git a/tests/misc/invalid-opt.pl b/tests/misc/invalid-opt.pl index bcf6ee71..a319bb14 100755 --- a/tests/misc/invalid-opt.pl +++ b/tests/misc/invalid-opt.pl @@ -1,7 +1,7 @@ #!/usr/bin/perl # exercise the 'invalid option' handling code in each program -# Copyright (C) 2008-2014 Free Software Foundation, Inc. +# Copyright (C) 2008-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/misc/join.pl b/tests/misc/join.pl index cf3f4bd4..08f29656 100755 --- a/tests/misc/join.pl +++ b/tests/misc/join.pl @@ -1,7 +1,7 @@ #!/usr/bin/perl # Test join. -# Copyright (C) 2008-2014 Free Software Foundation, Inc. +# Copyright (C) 2008-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/misc/ls-misc.pl b/tests/misc/ls-misc.pl index a47e70b7..f88c7a8e 100755 --- a/tests/misc/ls-misc.pl +++ b/tests/misc/ls-misc.pl @@ -1,6 +1,6 @@ #!/usr/bin/perl -# Copyright (C) 1998-2014 Free Software Foundation, Inc. +# Copyright (C) 1998-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -266,7 +266,7 @@ my @Tests = # The patch associated with sl-dangle[678] introduced a regression # that was fixed after coreutils-8.19. This edge case triggers when # listing a dir containing dangling symlinks, but with orphans uncolored. - # I.E. the same as the previous test, but listing the directory + # I.e., the same as the previous test, but listing the directory # rather than the symlink directly. ['sl-dangle9', '--color=always d', {OUT => "$e\e[1;36ms$e\n"}, diff --git a/tests/misc/ls-time.sh b/tests/misc/ls-time.sh index 3ce4a91c..676d1850 100755 --- a/tests/misc/ls-time.sh +++ b/tests/misc/ls-time.sh @@ -1,7 +1,7 @@ #!/bin/sh # Test some of ls's sorting options. -# Copyright (C) 1998-2014 Free Software Foundation, Inc. +# Copyright (C) 1998-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/misc/md5sum-bsd.sh b/tests/misc/md5sum-bsd.sh index f73e0622..c5069f35 100755 --- a/tests/misc/md5sum-bsd.sh +++ b/tests/misc/md5sum-bsd.sh @@ -2,7 +2,7 @@ # 'md5sum' tests for generation and checking of # BSD traditional and alternate formats (md5 [-r]) -# Copyright (C) 2011-2014 Free Software Foundation, Inc. +# Copyright (C) 2011-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -25,7 +25,7 @@ print_ver_ md5sum # Ensure we can --check BSD alternate format. # Note we start this list with a name # that's unambiguous in BSD format. -# I.E. one not starting with ' ' or '*' +# I.e., one not starting with ' ' or '*' for i in 'a' ' b' '*c' 'dd' ' '; do echo "$i" > "$i" md5sum "$i" >> check.md5sum @@ -40,20 +40,20 @@ md5sum --strict -c check.md5 || fail=1 # then it'll be detected as standard format and error. # This unlikely caveat was thought better than mandating # an option to avoid the ambiguity. -tail -n+2 check.md5 | md5sum --strict -c && fail=1 +tail -n+2 check.md5 | returns_ 1 md5sum --strict -c || fail=1 ## BSD traditional format tests (--tag option) ## # Ensure --tag and --check are mutually exclusive -md5sum --tag --check /dev/null && fail=1 +returns_ 1 md5sum --tag --check /dev/null || fail=1 # Ensure --tag and --text are mutually exclusive # We don't support --text with BSD tradition format, # as that would complicate the output format, # while providing little benefit over --text processing # available with the default md5sum output format. -md5sum --tag --text /dev/null && fail=1 +returns_ 1 md5sum --tag --text /dev/null || fail=1 # Ensure we can --check BSD traditional format we produce rm check.md5 diff --git a/tests/misc/md5sum-newline.pl b/tests/misc/md5sum-newline.pl index b418d5b4..4d2c21e4 100755 --- a/tests/misc/md5sum-newline.pl +++ b/tests/misc/md5sum-newline.pl @@ -1,7 +1,7 @@ #!/usr/bin/perl # Newline tests for "md5sum". -# Copyright (C) 1999-2014 Free Software Foundation, Inc. +# Copyright (C) 1999-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/misc/md5sum-parallel.sh b/tests/misc/md5sum-parallel.sh index 92f66296..2a526bdf 100755 --- a/tests/misc/md5sum-parallel.sh +++ b/tests/misc/md5sum-parallel.sh @@ -2,7 +2,7 @@ # Ensure that md5sum prints each checksum atomically # so that concurrent md5sums don't intersperse their output -# Copyright (C) 2009-2014 Free Software Foundation, Inc. +# Copyright (C) 2009-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -20,13 +20,17 @@ . "${srcdir=.}/tests/init.sh"; path_prepend_ ./src print_ver_ md5sum +xargs -P2 </dev/null >/dev/null 2>&1 \ + || skip_ 'xargs -P is required' + (mkdir tmp && cd tmp && seq 500 | xargs touch) # This will output at least 16KiB per process # and start 3 processes, with 2 running concurrently, # which triggers often on Fedora 11 at least. -(find tmp tmp tmp -type f | xargs -n500 -P2 md5sum) | +(find tmp tmp tmp -type f | xargs -n500 -P2 md5sum 2>err) | sed -n '/[0-9a-f]\{32\} /!p' | grep . > /dev/null && fail=1 +compare /dev/null err || fail=1 Exit $fail diff --git a/tests/misc/md5sum.pl b/tests/misc/md5sum.pl index 0aa0056f..b3ff4b4f 100755 --- a/tests/misc/md5sum.pl +++ b/tests/misc/md5sum.pl @@ -1,7 +1,7 @@ #!/usr/bin/perl # Basic tests for "md5sum". -# Copyright (C) 1998-2014 Free Software Foundation, Inc. +# Copyright (C) 1998-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/misc/mknod.sh b/tests/misc/mknod.sh index fb907f16..8ca35648 100755 --- a/tests/misc/mknod.sh +++ b/tests/misc/mknod.sh @@ -1,7 +1,7 @@ #!/bin/sh # Ensure that mknod, mkfifo, mkdir -m MODE work with a restrictive umask -# Copyright (C) 2004-2014 Free Software Foundation, Inc. +# Copyright (C) 2004-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/misc/mktemp.pl b/tests/misc/mktemp.pl index 13ee03f5..ca6a8516 100755 --- a/tests/misc/mktemp.pl +++ b/tests/misc/mktemp.pl @@ -1,7 +1,7 @@ #!/usr/bin/perl # Test "mktemp". -# Copyright (C) 2007-2014 Free Software Foundation, Inc. +# Copyright (C) 2007-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/misc/nice-fail.sh b/tests/misc/nice-fail.sh index 3bf823ab..2e957000 100755 --- a/tests/misc/nice-fail.sh +++ b/tests/misc/nice-fail.sh @@ -1,7 +1,7 @@ #!/bin/sh # Verify that internal failure in nice gives exact status. -# Copyright (C) 2009-2014 Free Software Foundation, Inc. +# Copyright (C) 2009-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/misc/nice.sh b/tests/misc/nice.sh index 26a01ca9..59316ec5 100755 --- a/tests/misc/nice.sh +++ b/tests/misc/nice.sh @@ -1,7 +1,7 @@ #! /bin/sh # Test "nice". -# Copyright (C) 2002-2014 Free Software Foundation, Inc. +# Copyright (C) 2002-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -73,7 +73,7 @@ done if test x$(nice -n -1 nice 2> /dev/null) = x0 ; then # unprivileged user - warn about failure to change nice -n -1 true 2> err || fail=1 - test -s err || fail=1 + compare /dev/null err && fail=1 mv err exp || framework_failure_ nice --1 true 2> err || fail=1 compare exp err || fail=1 diff --git a/tests/misc/nl.sh b/tests/misc/nl.sh index 676c75d7..310d45fe 100755 --- a/tests/misc/nl.sh +++ b/tests/misc/nl.sh @@ -1,7 +1,7 @@ #!/bin/sh # exercise nl functionality -# Copyright (C) 2002-2014 Free Software Foundation, Inc. +# Copyright (C) 2002-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/misc/nohup.sh b/tests/misc/nohup.sh index b3f4274c..b0621f4d 100755 --- a/tests/misc/nohup.sh +++ b/tests/misc/nohup.sh @@ -1,7 +1,7 @@ #!/bin/sh # test nohup -# Copyright (C) 2003-2014 Free Software Foundation, Inc. +# Copyright (C) 2003-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/misc/nproc-avail.sh b/tests/misc/nproc-avail.sh index 1a7e7219..a045c580 100755 --- a/tests/misc/nproc-avail.sh +++ b/tests/misc/nproc-avail.sh @@ -1,7 +1,7 @@ #!/bin/sh # Ensure that "nproc" is less than or equal to "nproc --all". -# Copyright (C) 2009-2014 Free Software Foundation, Inc. +# Copyright (C) 2009-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/misc/nproc-positive.sh b/tests/misc/nproc-positive.sh index c8fe9bae..fb825fac 100755 --- a/tests/misc/nproc-positive.sh +++ b/tests/misc/nproc-positive.sh @@ -1,7 +1,7 @@ #!/bin/sh # Ensure that nproc prints a number > 0 -# Copyright (C) 2009-2014 Free Software Foundation, Inc. +# Copyright (C) 2009-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -35,7 +35,7 @@ for i in 0 ' 1' 1000; do done for i in -1 N; do - nproc --ignore=$i && fail=1 + returns_ 1 nproc --ignore=$i || fail=1 done procs=$(OMP_NUM_THREADS=42 nproc --ignore=40) diff --git a/tests/misc/numfmt.pl b/tests/misc/numfmt.pl index dfb4b2e0..0e4dc79c 100755 --- a/tests/misc/numfmt.pl +++ b/tests/misc/numfmt.pl @@ -1,7 +1,7 @@ #!/usr/bin/perl # Basic tests for "numfmt". -# Copyright (C) 2012-2014 Free Software Foundation, Inc. +# Copyright (C) 2012-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -21,6 +21,8 @@ use strict; (my $program_name = $0) =~ s|.*/||; my $prog = 'numfmt'; +my $limits = getlimits (); + # TODO: add localization tests with "grouping" # Turn off localization of executable's output. @ENV{qw(LANGUAGE LANG LC_ALL)} = ('C') x 3; @@ -92,10 +94,16 @@ my @Tests = ['unit-6', '--from-unit=54W --from=iec --to=iec 4M', {ERR => "$prog: invalid unit size: '54W'\n"}, {EXIT => '1'}], - # Not fully documented.. "--{from,to}-unit" can accept IEC suffixes - ['unit-7', '--from-unit=2K --to=iec 30', {OUT=>"60K"}], - ['unit-8', '--from-unit=1234567890123456789012345 --to=iec 30', - {ERR => "$prog: invalid unit size: '1234567890123456789012345'\n"}, + ['unit-7', '--from-unit=K 30', {OUT=>"30000"}], + ['unit-7.1', '--from-unit=Ki 30', {OUT=>"30720"}], + ['unit-7.2', '--from-unit=i 0', + {ERR => "$prog: invalid unit size: 'i'\n"}, + {EXIT => '1'}], + ['unit-7.3', '--from-unit=1i 0', + {ERR => "$prog: invalid unit size: '1i'\n"}, + {EXIT => '1'}], + ['unit-8', '--from-unit='.$limits->{UINTMAX_OFLOW}.' --to=iec 30', + {ERR => "$prog: invalid unit size: '$limits->{UINTMAX_OFLOW}'\n"}, {EXIT => '1'}], ['unit-9', '--from-unit=0 1', {ERR => "$prog: invalid unit size: '0'\n"}, @@ -188,21 +196,16 @@ my @Tests = ['delim-3', '--delimiter=" " --from=auto "40M Foo"',{OUT=>'40000000 Foo'}], ['delim-4', '--delimiter=: --from=auto 40M:60M', {OUT=>'40000000:60M'}], ['delim-5', '-d: --field=2 --from=auto :40M:60M', {OUT=>':40000000:60M'}], - ['delim-6', '--delimiter=: --field 3 --from=auto 40M:60M', - {EXIT=>2}, - {ERR=>"$prog: input line is too short, no numbers found " . - "to convert in field 3\n"}], + ['delim-6', '-d: --field 3 --from=auto 40M:60M', {OUT=>"40M:60M"}], #Fields ['field-1', '--field A', {ERR => "$prog: invalid field value 'A'\n"}, {EXIT => '1'}], - ['field-1.1', '--field -5', - {ERR => "$prog: invalid field value '-5'\n"}, - {EXIT => '1'}], ['field-2', '--field 2 --from=auto "Hello 40M World 90G"', {OUT=>'Hello 40000000 World 90G'}], ['field-3', '--field 3 --from=auto "Hello 40M World 90G"', + {OUT=>"Hello 40M "}, {ERR=>"$prog: invalid number: 'World'\n"}, {EXIT => 2},], # Last field - no text after number @@ -217,10 +220,32 @@ my @Tests = {OUT=>"Hello:40000000:World:90G"}], # not enough fields - ['field-8', '--field 3 --to=si "Hello World"', - {EXIT=>2}, - {ERR=>"$prog: input line is too short, no numbers found " . - "to convert in field 3\n"}], + ['field-8', '--field 3 --to=si "Hello World"', {OUT=>"Hello World"}], + + # Multiple fields + ['field-range-1', '--field 2,4 --to=si "1000 2000 3000 4000 5000"', + {OUT=>"1000 2.0K 3000 4.0K 5000"}], + + ['field-range-2', '--field 2-4 --to=si "1000 2000 3000 4000 5000"', + {OUT=>"1000 2.0K 3.0K 4.0K 5000"}], + + ['field-range-3', '--field 1,2,3-5 --to=si "1000 2000 3000 4000 5000"', + {OUT=>"1.0K 2.0K 3.0K 4.0K 5.0K"}], + + ['field-range-4', '--field 1-5 --to=si "1000 2000 3000 4000 5000"', + {OUT=>"1.0K 2.0K 3.0K 4.0K 5.0K"}], + + ['field-range-5', '--field 1-3,5 --to=si "1000 2000 3000 4000 5000"', + {OUT=>"1.0K 2.0K 3.0K 4000 5.0K"}], + + ['field-range-6', '--field 3- --to=si "1000 2000 3000 4000 5000"', + {OUT=>"1000 2000 3.0K 4.0K 5.0K"}], + + ['field-range-7', '--field -3 --to=si "1000 2000 3000 4000 5000"', + {OUT=>"1.0K 2.0K 3.0K 4000 5000"}], + + ['all-fields-1', '--field=- --to=si "1000 2000 3000 4000 5000"', + {OUT=>"1.0K 2.0K 3.0K 4.0K 5.0K"}], # Auto-consume white-space, setup auto-padding ['whitespace-1', '--to=si --field 2 "A 500 B"', {OUT=>"A 500 B"}], @@ -336,15 +361,6 @@ my @Tests = {ERR=>"$prog: invalid number: ''\n"}, {EXIT=> 2}], - # INTEGRAL_OVERFLOW - ['strtod-3', '--from=si "1234567890123456789012345678901234567890'. - '1234567890123456789012345678901234567890"', - {ERR=>"$prog: value too large to be converted: '" . - "1234567890123456789012345678901234567890" . - "1234567890123456789012345678901234567890'\n", - }, - {EXIT=> 2}], - # FRACTION_NO_DIGITS_FOUND ['strtod-5', '--from=si 12.', {ERR=>"$prog: invalid number: '12.'\n"}, @@ -358,15 +374,6 @@ my @Tests = {ERR=>"$prog: invalid number: '12. 2'\n"}, {EXIT=>2}], - # FRACTION_OVERFLOW - ['strtod-7', '--from=si "12.1234567890123456789012345678901234567890'. - '1234567890123456789012345678901234567890"', - {ERR=>"$prog: value too large to be converted: '" . - "12.1234567890123456789012345678901234567890" . - "1234567890123456789012345678901234567890'\n", - }, - {EXIT=> 2}], - # INVALID_SUFFIX ['strtod-9', '--from=si 12.2Q', {ERR=>"$prog: invalid suffix in input: '12.2Q'\n"}, @@ -502,128 +509,35 @@ my @Tests = {OUT=>"5.8594\n-5.8594"}], - # Large Values - ['large-1','1000000000000000', {OUT=>"1000000000000000"}], - # 18 digits is OK - ['large-2','1000000000000000000', {OUT=>"1000000000000000000"}], - # 19 digits is too much (without output scaling) - ['large-3','10000000000000000000', - {ERR => "$prog: value too large to be printed: '1e+19' " . - "(consider using --to)\n"}, - {EXIT=>2}], - - # Test input: - # Up to 27 digits is OK. - ['large-3.1', '--to=si 1', {OUT=> "1"}], - ['large-3.2', '--to=si 10', {OUT=> "10"}], - ['large-3.3', '--to=si 100', {OUT=> "100"}], - ['large-3.4', '--to=si 1000', {OUT=>"1.0K"}], - ['large-3.5', '--to=si 10000', {OUT=> "10K"}], - ['large-3.6', '--to=si 100000', {OUT=>"100K"}], - ['large-3.7', '--to=si 1000000', {OUT=>"1.0M"}], - ['large-3.8', '--to=si 10000000', {OUT=> "10M"}], - ['large-3.9', '--to=si 100000000', {OUT=>"100M"}], - ['large-3.10','--to=si 1000000000', {OUT=>"1.0G"}], - ['large-3.11','--to=si 10000000000', {OUT=> "10G"}], - ['large-3.12','--to=si 100000000000', {OUT=>"100G"}], - ['large-3.13','--to=si 1000000000000', {OUT=>"1.0T"}], - ['large-3.14','--to=si 10000000000000', {OUT=> "10T"}], - ['large-3.15','--to=si 100000000000000', {OUT=>"100T"}], - ['large-3.16','--to=si 1000000000000000', {OUT=>"1.0P"}], - ['large-3.17','--to=si 10000000000000000', {OUT=> "10P"}], - ['large-3.18','--to=si 100000000000000000', {OUT=>"100P"}], - ['large-3.19','--to=si 1000000000000000000', {OUT=>"1.0E"}], - ['large-3.20','--to=si 10000000000000000000', {OUT=> "10E"}], - ['large-3.21','--to=si 210000000000000000000', {OUT=>"210E"}], - ['large-3.22','--to=si 3210000000000000000000', {OUT=>"3.3Z"}], - ['large-3.23','--to=si 43210000000000000000000', {OUT=> "44Z"}], - ['large-3.24','--to=si 543210000000000000000000', {OUT=>"544Z"}], - ['large-3.25','--to=si 6543210000000000000000000', {OUT=>"6.6Y"}], - ['large-3.26','--to=si 76543210000000000000000000', {OUT=> "77Y"}], - ['large-3.27','--to=si 876543210000000000000000000', {OUT=>"877Y"}], - - # More than 27 digits is not OK - ['large-3.28','--to=si 9876543210000000000000000000', - {ERR => "$prog: value too large to be converted: " . - "'9876543210000000000000000000'\n"}, - {EXIT => 2}], - - # Test Output - ['large-4.1', '--from=si 9.7M', {OUT=>"9700000"}], - ['large-4.2', '--from=si 10M', {OUT =>"10000000"}], - ['large-4.3', '--from=si 200M', {OUT =>"200000000"}], - ['large-4.4', '--from=si 3G', {OUT =>"3000000000"}], - ['large-4.5', '--from=si 40G', {OUT =>"40000000000"}], - ['large-4.6', '--from=si 500G', {OUT =>"500000000000"}], - ['large-4.7', '--from=si 6T', {OUT =>"6000000000000"}], - ['large-4.8', '--from=si 70T', {OUT =>"70000000000000"}], - ['large-4.9', '--from=si 800T', {OUT =>"800000000000000"}], - ['large-4.10','--from=si 9P', {OUT =>"9000000000000000"}], - ['large-4.11','--from=si 10P', {OUT =>"10000000000000000"}], - ['large-4.12','--from=si 200P', {OUT =>"200000000000000000"}], - ['large-4.13','--from=si 3E', {OUT =>"3000000000000000000"}], - - # More than 18 digits of output without scaling - no good. - ['large-4.14','--from=si 40E', - {ERR => "$prog: value too large to be printed: '4e+19' " . - "(consider using --to)\n"}, - {EXIT => 2}], - ['large-4.15','--from=si 500E', - {ERR => "$prog: value too large to be printed: '5e+20' " . - "(consider using --to)\n"}, - {EXIT => 2}], - ['large-4.16','--from=si 6Z', - {ERR => "$prog: value too large to be printed: '6e+21' " . - "(consider using --to)\n"}, - {EXIT => 2}], - ['large-4.17','--from=si 70Z', - {ERR => "$prog: value too large to be printed: '7e+22' " . - "(consider using --to)\n"}, + # Leading zeros weren't handled appropriately before 8.24 + ['leading-1','0000000000000000000000000001', {OUT=>"1"}], + ['leading-2','.1', {OUT=>"0.1"}], + ['leading-3','bad.1', + {ERR => "$prog: invalid number: 'bad.1'\n"}, {EXIT => 2}], - ['large-4.18','--from=si 800Z', - {ERR => "$prog: value too large to be printed: '8e+23' " . - "(consider using --to)\n"}, + ['leading-4','..1', + {ERR => "$prog: invalid suffix in input: '..1'\n"}, {EXIT => 2}], - ['large-4.19','--from=si 9Y', - {ERR => "$prog: value too large to be printed: '9e+24' " . - "(consider using --to)\n"}, - {EXIT => 2}], - ['large-4.20','--from=si 10Y', - {ERR => "$prog: value too large to be printed: '1e+25' " . - "(consider using --to)\n"}, - {EXIT => 2}], - ['large-4.21','--from=si 200Y', - {ERR => "$prog: value too large to be printed: '2e+26' " . - "(consider using --to)\n"}, - {EXIT => 2}], - - ['large-5.1','--to=si 1000000000000000000', {OUT=>"1.0E"}], - ['large-5','--from=si --to=si 2E', {OUT=>"2.0E"}], - ['large-6','--from=si --to=si 3.4Z', {OUT=>"3.4Z"}], - ['large-7','--from=si --to=si 80Y', {OUT=>"80Y"}], - ['large-8','--from=si --to=si 9000Z', {OUT=>"9.0Y"}], - - ['large-10','--from=si --to=si 999Y', {OUT=>"999Y"}], - ['large-11','--from=si --to=iec 999Y', {OUT=>"827Y"}], - ['large-12','--from=si --round=down --to=iec 999Y', {OUT=>"826Y"}], - - # units can also affect the output - ['large-13','--from=si --from-unit=1000000 9P', - {ERR => "$prog: value too large to be printed: '9e+21' " . - "(consider using --to)\n"}, + ['leading-5','1.', + {ERR => "$prog: invalid number: '1.'\n"}, {EXIT => 2}], - ['large-13.1','--from=si --from-unit=1000000 --to=si 9P', {OUT=>"9.0Z"}], - # Numbers>999Y are never acceptable, regardless of scaling - ['large-14','--from=si --to=si 999Y', {OUT=>"999Y"}], - ['large-14.1','--from=si --to=si 1000Y', - {ERR => "$prog: value too large to be printed: '1e+27' " . - "(cannot handle values > 999Y)\n"}, - {EXIT => 2}], - ['large-14.2','--from=si --to=si --from-unit=10000 1Y', - {ERR => "$prog: value too large to be printed: '1e+28' " . - "(cannot handle values > 999Y)\n"}, - {EXIT => 2}], + # precision override + ['precision-1','--format=%.4f 9991239123 --to=si', {OUT=>"9.9913G"}], + ['precision-2','--format=%.1f 9991239123 --to=si', {OUT=>"10.0G"}], + ['precision-3','--format=%.1f 1', {OUT=>"1.0"}], + ['precision-4','--format=%.1f 1.12', {OUT=>"1.2"}], + ['precision-5','--format=%.1f 9991239123 --to-unit=G', {OUT=>"10.0"}], + ['precision-6','--format="% .1f" 9991239123 --to-unit=G', {OUT=>"10.0"}], + ['precision-7','--format=%.-1f 1.1', + {ERR => "$prog: invalid precision in format '%.-1f'\n"}, + {EXIT => 1}], + ['precision-8','--format=%.+1f 1.1', + {ERR => "$prog: invalid precision in format '%.+1f'\n"}, + {EXIT => 1}], + ['precision-9','--format="%. 1f" 1.1', + {ERR => "$prog: invalid precision in format '%. 1f'\n"}, + {EXIT => 1}], # debug warnings ['debug-1', '--debug 4096', {OUT=>"4096"}, @@ -632,14 +546,6 @@ my @Tests = ['debug-1.1', '--debug --padding 10 4096', {OUT=>" 4096"}], ['debug-2', '--debug --grouping --from=si 4.0K', {OUT=>"4000"}, {ERR=>"$prog: grouping has no effect in this locale\n"}], - ['debug-4', '--to=si --debug 12345678901234567890', - {OUT=>"13E"}, - {ERR=>"$prog: large input value '12345678901234567890':" . - " possible precision loss\n"}], - ['debug-5', '--to=si --from=si --debug 1.12345678901234567890Y', - {OUT=>"1.2Y"}, - {ERR=>"$prog: large input value '1.12345678901234567890Y':" . - " possible precision loss\n"}], # dev-debug messages - the actual messages don't matter # just ensure the program works, and for code coverage testing. @@ -673,14 +579,12 @@ my @Tests = ['devdebug-11', '---debug --format "%\'-10f" 10000',{OUT=>"10000 "}, {ERR=>""}, {ERR_SUBST=>"s/.*//msg"}], - ['devdebug-12', '---debug --field 2 A',{OUT=>""}, - {ERR=>""}, {EXIT=>2}, - {ERR_SUBST=>"s/.*//msg"}], # Invalid parameters ['help-1', '--foobar', - {ERR=>"$prog: unrecognized option '--foobar'\n" . + {ERR=>"$prog: unrecognized option\n" . "Try '$prog --help' for more information.\n"}, + {ERR_SUBST=>"s/option.*/option/; s/unknown/unrecognized/"}, {EXIT=>1}], ## Format string - check error detection @@ -695,17 +599,17 @@ my @Tests = {EXIT=>1}], ['fmt-err-4', '--format "%d"', {ERR=>"$prog: invalid format '%d', " . - "directive must be %[0]['][-][N]f\n"}, + "directive must be %[0]['][-][N][.][N]f\n"}, {EXIT=>1}], ['fmt-err-5', '--format "% -43 f"', {ERR=>"$prog: invalid format '% -43 f', " . - "directive must be %[0]['][-][N]f\n"}, + "directive must be %[0]['][-][N][.][N]f\n"}, {EXIT=>1}], ['fmt-err-6', '--format "%f %f"', {ERR=>"$prog: format '%f %f' has too many % directives\n"}, {EXIT=>1}], - ['fmt-err-7', '--format "%123456789012345678901234567890f"', - {ERR=>"$prog: invalid format '%123456789012345678901234567890f'". + ['fmt-err-7', '--format "%'.$limits->{LONG_OFLOW}.'f"', + {ERR=>"$prog: invalid format '%$limits->{LONG_OFLOW}f'". " (width overflow)\n"}, {EXIT=>1}], ['fmt-err-9', '--format "%f" --grouping', @@ -781,11 +685,6 @@ my @Tests = {ERR => "$prog: invalid number: 'World'\n"}, {OUT => "Hello 40M World 90G\n"}, {EXIT => 2}], - ['ign-err-6', '--invalid=fail --field 3 --to=si "Hello World"', - {ERR => "$prog: input line is too short, no numbers found " . - "to convert in field 3\n"}, - {OUT => "Hello World\n"}, - {EXIT => 2}], ['ign-err-7', '--invalid=fail --from=si "foo"', {ERR => "$prog: invalid number: 'foo'\n"}, {OUT => "foo\n"}, @@ -800,16 +699,6 @@ my @Tests = "'12M' (e.g Ki/Mi/Gi)\n"}, {OUT => "12M\n"}, {EXIT=>2}], - ['ign-err-10','--invalid=fail 10000000000000000000', - {ERR => "$prog: value too large to be printed: '1e+19' " . - "(consider using --to)\n"}, - {OUT => "10000000000000000000\n"}, - {EXIT=>2}], - ['ign-err-11','--invalid=fail --to=si 9876543210000000000000000000', - {ERR => "$prog: value too large to be converted: " . - "'9876543210000000000000000000'\n"}, - {OUT => "9876543210000000000000000000\n"}, - {EXIT => 2}], ## Ignore Errors with multiple conversions ['ign-err-m1', '--invalid=ignore --to=si 1000 2000 bad 3000', @@ -849,15 +738,184 @@ my @Tests = {OUT => "A 1000 x\nB Foo y\nC 2.8G z\n"}, {ERR => "$prog: invalid number: 'Foo'\n"}, {EXIT => 2}], - # one of the lines is too short - ['ign-err-m3.2', '--invalid=fail --field 2 --from=si --to=iec', - {IN_PIPE => "A 1K x\nB\nC 3G z\n"}, - {OUT => "A 1000 x\nB\nC 2.8G z\n"}, - {ERR => "$prog: input line is too short, no numbers found " . - "to convert in field 2\n"}, - {EXIT => 2}], ); +my @Limit_Tests = + ( + # Large Values + ['large-1','1000000000000000', {OUT=>"1000000000000000"}], + # 18 digits is OK + ['large-2','1000000000000000000', {OUT=>"1000000000000000000"}], + # 19 digits is too much (without output scaling) + ['large-3','10000000000000000000', + {ERR => "$prog: value too large to be printed: '1e+19' " . + "(consider using --to)\n"}, + {EXIT=>2}], + ['large-4','1000000000000000000.0', + {ERR => "$prog: value/precision too large to be printed: " . + "'1e+18/1' (consider using --to)\n"}, + {EXIT=>2}], + + + # Test input: + # Up to 27 digits is OK. + ['large-3.1', '--to=si 1', {OUT=> "1"}], + ['large-3.2', '--to=si 10', {OUT=> "10"}], + ['large-3.3', '--to=si 100', {OUT=> "100"}], + ['large-3.4', '--to=si 1000', {OUT=>"1.0K"}], + ['large-3.5', '--to=si 10000', {OUT=> "10K"}], + ['large-3.6', '--to=si 100000', {OUT=>"100K"}], + ['large-3.7', '--to=si 1000000', {OUT=>"1.0M"}], + ['large-3.8', '--to=si 10000000', {OUT=> "10M"}], + ['large-3.9', '--to=si 100000000', {OUT=>"100M"}], + ['large-3.10','--to=si 1000000000', {OUT=>"1.0G"}], + ['large-3.11','--to=si 10000000000', {OUT=> "10G"}], + ['large-3.12','--to=si 100000000000', {OUT=>"100G"}], + ['large-3.13','--to=si 1000000000000', {OUT=>"1.0T"}], + ['large-3.14','--to=si 10000000000000', {OUT=> "10T"}], + ['large-3.15','--to=si 100000000000000', {OUT=>"100T"}], + ['large-3.16','--to=si 1000000000000000', {OUT=>"1.0P"}], + ['large-3.17','--to=si 10000000000000000', {OUT=> "10P"}], + ['large-3.18','--to=si 100000000000000000', {OUT=>"100P"}], + ['large-3.19','--to=si 1000000000000000000', {OUT=>"1.0E"}], + ['large-3.20','--to=si 10000000000000000000', {OUT=> "10E"}], + ['large-3.21','--to=si 210000000000000000000', {OUT=>"210E"}], + ['large-3.22','--to=si 3210000000000000000000', {OUT=>"3.3Z"}], + ['large-3.23','--to=si 43210000000000000000000', {OUT=> "44Z"}], + ['large-3.24','--to=si 543210000000000000000000', {OUT=>"544Z"}], + ['large-3.25','--to=si 6543210000000000000000000', {OUT=>"6.6Y"}], + ['large-3.26','--to=si 76543210000000000000000000', {OUT=> "77Y"}], + ['large-3.27','--to=si 876543210000000000000000000', {OUT=>"877Y"}], + + # More than 27 digits is not OK + ['large-3.28','--to=si 9876543210000000000000000000', + {ERR => "$prog: value too large to be converted: " . + "'9876543210000000000000000000'\n"}, + {EXIT => 2}], + + # Test Output + ['large-4.1', '--from=si 9.7M', {OUT=>"9700000"}], + ['large-4.2', '--from=si 10M', {OUT =>"10000000"}], + ['large-4.3', '--from=si 200M', {OUT =>"200000000"}], + ['large-4.4', '--from=si 3G', {OUT =>"3000000000"}], + ['large-4.5', '--from=si 40G', {OUT =>"40000000000"}], + ['large-4.6', '--from=si 500G', {OUT =>"500000000000"}], + ['large-4.7', '--from=si 6T', {OUT =>"6000000000000"}], + ['large-4.8', '--from=si 70T', {OUT =>"70000000000000"}], + ['large-4.9', '--from=si 800T', {OUT =>"800000000000000"}], + ['large-4.10','--from=si 9P', {OUT =>"9000000000000000"}], + ['large-4.11','--from=si 10P', {OUT =>"10000000000000000"}], + ['large-4.12','--from=si 200P', {OUT =>"200000000000000000"}], + ['large-4.13','--from=si 3E', {OUT =>"3000000000000000000"}], + + # More than 18 digits of output without scaling - no good. + ['large-4.14','--from=si 40E', + {ERR => "$prog: value too large to be printed: '4e+19' " . + "(consider using --to)\n"}, + {EXIT => 2}], + ['large-4.15','--from=si 500E', + {ERR => "$prog: value too large to be printed: '5e+20' " . + "(consider using --to)\n"}, + {EXIT => 2}], + ['large-4.16','--from=si 6Z', + {ERR => "$prog: value too large to be printed: '6e+21' " . + "(consider using --to)\n"}, + {EXIT => 2}], + ['large-4.17','--from=si 70Z', + {ERR => "$prog: value too large to be printed: '7e+22' " . + "(consider using --to)\n"}, + {EXIT => 2}], + ['large-4.18','--from=si 800Z', + {ERR => "$prog: value too large to be printed: '8e+23' " . + "(consider using --to)\n"}, + {EXIT => 2}], + ['large-4.19','--from=si 9Y', + {ERR => "$prog: value too large to be printed: '9e+24' " . + "(consider using --to)\n"}, + {EXIT => 2}], + ['large-4.20','--from=si 10Y', + {ERR => "$prog: value too large to be printed: '1e+25' " . + "(consider using --to)\n"}, + {EXIT => 2}], + ['large-4.21','--from=si 200Y', + {ERR => "$prog: value too large to be printed: '2e+26' " . + "(consider using --to)\n"}, + {EXIT => 2}], + + ['large-5.1','--to=si 1000000000000000000', {OUT=>"1.0E"}], + ['large-5','--from=si --to=si 2E', {OUT=>"2.0E"}], + ['large-6','--from=si --to=si 3.4Z', {OUT=>"3.4Z"}], + ['large-7','--from=si --to=si 80Y', {OUT=>"80Y"}], + ['large-8','--from=si --to=si 9000Z', {OUT=>"9.0Y"}], + + ['large-10','--from=si --to=si 999Y', {OUT=>"999Y"}], + ['large-11','--from=si --to=iec 999Y', {OUT=>"827Y"}], + ['large-12','--from=si --round=down --to=iec 999Y', {OUT=>"826Y"}], + + # units can also affect the output + ['large-13','--from=si --from-unit=1000000 9P', + {ERR => "$prog: value too large to be printed: '9e+21' " . + "(consider using --to)\n"}, + {EXIT => 2}], + ['large-13.1','--from=si --from-unit=1000000 --to=si 9P', {OUT=>"9.0Z"}], + + # Numbers>999Y are never acceptable, regardless of scaling + ['large-14','--from=si --to=si 999Y', {OUT=>"999Y"}], + ['large-14.1','--from=si --to=si 1000Y', + {ERR => "$prog: value too large to be printed: '1e+27' " . + "(cannot handle values > 999Y)\n"}, + {EXIT => 2}], + ['large-14.2','--from=si --to=si --from-unit=10000 1Y', + {ERR => "$prog: value too large to be printed: '1e+28' " . + "(cannot handle values > 999Y)\n"}, + {EXIT => 2}], + + # intmax_t overflow when rounding caused this to fail before 8.24 + ['large-15',$limits->{INTMAX_OFLOW}, {OUT=>$limits->{INTMAX_OFLOW}}], + ['large-16','9.300000000000000000', {OUT=>'9.300000000000000000'}], + + # INTEGRAL_OVERFLOW + ['strtod-3', '--from=si "1234567890123456789012345678901234567890'. + '1234567890123456789012345678901234567890"', + {ERR=>"$prog: value too large to be converted: '" . + "1234567890123456789012345678901234567890" . + "1234567890123456789012345678901234567890'\n", + }, + {EXIT=> 2}], + + # FRACTION_OVERFLOW + ['strtod-7', '--from=si "12.1234567890123456789012345678901234567890'. + '1234567890123456789012345678901234567890"', + {ERR=>"$prog: value too large to be converted: '" . + "12.1234567890123456789012345678901234567890" . + "1234567890123456789012345678901234567890'\n", + }, + {EXIT=> 2}], + + ['debug-4', '--to=si --debug 12345678901234567890', + {OUT=>"13E"}, + {ERR=>"$prog: large input value '12345678901234567890':" . + " possible precision loss\n"}], + ['debug-5', '--to=si --from=si --debug 1.12345678901234567890Y', + {OUT=>"1.2Y"}, + {ERR=>"$prog: large input value '1.12345678901234567890Y':" . + " possible precision loss\n"}], + + ['ign-err-10','--invalid=fail 10000000000000000000', + {ERR => "$prog: value too large to be printed: '1e+19' " . + "(consider using --to)\n"}, + {OUT => "10000000000000000000\n"}, + {EXIT=>2}], + ['ign-err-11','--invalid=fail --to=si 9876543210000000000000000000', + {ERR => "$prog: value too large to be converted: " . + "'9876543210000000000000000000'\n"}, + {OUT => "9876543210000000000000000000\n"}, + {EXIT => 2}], + ); +# Restrict these tests to systems with LDBL_DIG == 18 +(system "$prog ---debug 1 2>&1|grep 'MAX_UNSCALED_DIGITS: 18' > /dev/null") == 0 + and push @Tests, @Limit_Tests; + my @Locale_Tests = ( # Locale that supports grouping, but without '--grouping' parameter diff --git a/tests/misc/od-N.sh b/tests/misc/od-N.sh index 247ea546..ec417d27 100755 --- a/tests/misc/od-N.sh +++ b/tests/misc/od-N.sh @@ -1,7 +1,7 @@ #!/bin/sh # Verify that 'od -N N' reads no more than N bytes of input. -# Copyright (C) 2001-2014 Free Software Foundation, Inc. +# Copyright (C) 2001-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/misc/od-endian.sh b/tests/misc/od-endian.sh index a01ae0a8..c3acca70 100755 --- a/tests/misc/od-endian.sh +++ b/tests/misc/od-endian.sh @@ -1,7 +1,7 @@ #!/bin/sh # verify that od --endian works properly -# Copyright (C) 2014 Free Software Foundation, Inc. +# Copyright (C) 2014-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/misc/od-float.sh b/tests/misc/od-float.sh index 8a8e29b2..bbfa5704 100755 --- a/tests/misc/od-float.sh +++ b/tests/misc/od-float.sh @@ -1,7 +1,7 @@ #!/bin/sh # Test od on floating-point values. -# Copyright (C) 2010-2014 Free Software Foundation, Inc. +# Copyright (C) 2010-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -29,7 +29,7 @@ export LC_ALL=C # on x86: sometimes there was no space between the columns. set x $(echo aaaabaaa | tr ab '\376\377' | od -t fF) || - framework_failure_ + fail=1 case "$*" in *0-*) fail=1;; esac @@ -38,7 +38,7 @@ case $3,$4 in esac set x $(echo aaaaaaaabaaaaaaa | tr ab '\376\377' | od -t fD) || - framework_failure_ + fail=1 case "$*" in *0-*) fail=1;; esac @@ -47,7 +47,7 @@ case $3,$4 in esac set x $(echo aaaaaaaaaaaaaaaabaaaaaaaaaaaaaaa | tr ab '\376\377' | od -t fL) || - framework_failure_ + fail=1 case "$*" in *0-*) fail=1;; esac @@ -55,4 +55,18 @@ case $3,$4 in -1.023442870282055988e+4855,-1.023442870282055988e+4855) fail=1;; esac +# Ensure od doesn't crash as it did on glibc <= 2.5: +# https://sourceware.org/bugzilla/show_bug.cgi?id=4586 +set x $(printf 00000000ff000000 | tr 0f '\000\377' | od -t fL) || fail=1 +# With coreutils <= 8.7 we used to print "nan" for the above invalid value. +# However since v8.7-22-ga71c22f we deferred to the system printf routines +# through the use of the ftoastr module. So the following check would only +# be valid on x86_64 if we again handle the conversion internally or +# if this glibc bug is resolved: +# https://sourceware.org/bugzilla/show_bug.cgi?id=17661 +#case "$*" in +#*nan*) ;; +#*) fail=1;; +#esac + Exit $fail diff --git a/tests/misc/od-j.sh b/tests/misc/od-j.sh new file mode 100755 index 00000000..293aad5f --- /dev/null +++ b/tests/misc/od-j.sh @@ -0,0 +1,39 @@ +#!/bin/sh +# Verify that 'od -j N' skips N bytes of input. + +# Copyright 2014-2015 Free Software Foundation, Inc. + +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. + +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. + +. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src +print_ver_ od + +for file in ${srcdir=.}/tests/init.sh /proc/version /sys/kernel/profiling; do + test -r $file || continue + + cp -f $file copy && + bytes=$(wc -c < copy) || framework_failure_ + + od -An $file > exp || fail=1 + od -An -j $bytes $file $file > out || fail=1 + compare exp out || fail=1 + + od -An -j 4096 copy copy > exp1 2> experr1; expstatus=$? + od -An -j 4096 $file $file > out1 2> err1; status=$? + test $status -eq $expstatus || fail=1 + compare exp1 out1 || fail=1 + compare experr1 err1 || fail=1 +done + +Exit $fail diff --git a/tests/misc/od-multiple-t.sh b/tests/misc/od-multiple-t.sh index 451fa2f5..07fc1a1f 100755 --- a/tests/misc/od-multiple-t.sh +++ b/tests/misc/od-multiple-t.sh @@ -2,7 +2,7 @@ # verify that multiple -t specifiers to od align well # This would fail before coreutils-6.13. -# Copyright (C) 2008-2014 Free Software Foundation, Inc. +# Copyright (C) 2008-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/misc/od-x8.sh b/tests/misc/od-x8.sh index 6e72dee7..c10f07fb 100755 --- a/tests/misc/od-x8.sh +++ b/tests/misc/od-x8.sh @@ -2,7 +2,7 @@ # verify that od -t x8 works properly # This would fail before coreutils-4.5.2. -# Copyright (C) 2002-2014 Free Software Foundation, Inc. +# Copyright (C) 2002-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/misc/od.pl b/tests/misc/od.pl index edddf4e3..601fbbcb 100755 --- a/tests/misc/od.pl +++ b/tests/misc/od.pl @@ -1,7 +1,7 @@ #!/usr/bin/perl # Exercise od -# Copyright (C) 2006-2014 Free Software Foundation, Inc. +# Copyright (C) 2006-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/misc/paste.pl b/tests/misc/paste.pl index 04f8ec07..8d957f46 100755 --- a/tests/misc/paste.pl +++ b/tests/misc/paste.pl @@ -1,7 +1,7 @@ #!/usr/bin/perl # Test paste. -# Copyright (C) 2003-2014 Free Software Foundation, Inc. +# Copyright (C) 2003-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/misc/pathchk1.sh b/tests/misc/pathchk1.sh index 616e763f..6c8a5088 100755 --- a/tests/misc/pathchk1.sh +++ b/tests/misc/pathchk1.sh @@ -1,7 +1,7 @@ #!/bin/sh # pathchk tests -# Copyright (C) 2002-2014 Free Software Foundation, Inc. +# Copyright (C) 2002-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -25,14 +25,14 @@ touch file || framework_failure_ # This should exit nonzero. Before 2.0.13, it gave a diagnostic, # but exited successfully. -pathchk file/x > /dev/null 2>&1 && fail=1 +returns_ 1 pathchk file/x > /dev/null 2>&1 || fail=1 # This should exit nonzero. Through 5.3.0 it exited with status zero. -pathchk -p '' > /dev/null 2>&1 && fail=1 +returns_ 1 pathchk -p '' > /dev/null 2>&1 || fail=1 # This tests the new -P option. -pathchk -P '' > /dev/null 2>&1 && fail=1 -pathchk -P -- - > /dev/null 2>&1 && fail=1 -pathchk -p -P x/- > /dev/null 2>&1 && fail=1 +returns_ 1 pathchk -P '' > /dev/null 2>&1 || fail=1 +returns_ 1 pathchk -P -- - > /dev/null 2>&1 || fail=1 +returns_ 1 pathchk -p -P x/- > /dev/null 2>&1 || fail=1 Exit $fail diff --git a/tests/misc/printenv.sh b/tests/misc/printenv.sh index 054b02c2..862b48ba 100755 --- a/tests/misc/printenv.sh +++ b/tests/misc/printenv.sh @@ -1,7 +1,7 @@ #!/bin/sh # Verify behavior of printenv. -# Copyright (C) 2009-2014 Free Software Foundation, Inc. +# Copyright (C) 2009-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -23,8 +23,12 @@ print_ver_ printenv # printenv as a builtin, so we must invoke it via "env". # But beware of $_, set by many shells to the last command run. # Also, filter out LD_PRELOAD, which is set when running under valgrind. -env | grep -Ev '^(_|LD_PRELOAD=)' > exp || framework_failure_ -env -- printenv | grep -Ev '^(_|LD_PRELOAD=)' > out || fail=1 +# Note the apparently redundant "env env": this is to ensure to get +# env's output the same way as that of printenv and works around a bug +# on aarch64 at least where libc's execvp reverses the order of the +# output. +env -- env | grep -Ev '^(_|LD_PRELOAD)=' > exp || framework_failure_ +env -- printenv | grep -Ev '^(_|LD_PRELOAD)=' > out || fail=1 compare exp out || fail=1 # POSIX is clear that environ may, but need not be, sorted. diff --git a/tests/misc/printf-cov.pl b/tests/misc/printf-cov.pl index 3d797284..4be97971 100755 --- a/tests/misc/printf-cov.pl +++ b/tests/misc/printf-cov.pl @@ -1,7 +1,7 @@ #!/usr/bin/perl # improve printf.c test coverage -# Copyright (C) 2008-2014 Free Software Foundation, Inc. +# Copyright (C) 2008-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/misc/printf-hex.sh b/tests/misc/printf-hex.sh index 27503fae..04044560 100755 --- a/tests/misc/printf-hex.sh +++ b/tests/misc/printf-hex.sh @@ -1,7 +1,7 @@ #!/bin/sh # make sure that only two hex. digits are consumed in a \xHHH sequence -# Copyright (C) 2002-2014 Free Software Foundation, Inc. +# Copyright (C) 2002-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/misc/printf-surprise.sh b/tests/misc/printf-surprise.sh index 6083806d..20e6b098 100755 --- a/tests/misc/printf-surprise.sh +++ b/tests/misc/printf-surprise.sh @@ -1,7 +1,7 @@ #!/bin/sh # Detect printf(3) failure even when it doesn't set stream error indicator -# Copyright (C) 2007-2014 Free Software Foundation, Inc. +# Copyright (C) 2007-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -53,7 +53,10 @@ mkfifo_or_skip_ fifo # http://bugs.debian.org/481543#77 export MALLOC_PERTURB_=0 -head -c 10 fifo > out & +# Terminate any background process +cleanup_() { kill $pid 2>/dev/null && wait $pid; } + +head -c 10 fifo > out & pid=$! # Choosing the virtual memory limit, 11000 is enough, but 10000 is too # little and provokes a "memory exhausted" diagnostic on FreeBSD 9.0-p3. @@ -63,7 +66,7 @@ exit=$? # Map this longer, and rarer, diagnostic to the common one. # printf: cannot perform formatted output: Cannot allocate memory" \ sed 's/cannot perform .*/write error/' err-msg > k && mv k err-msg -err_msg=$(cat err-msg|tr '\n' :) +err_msg=$(tr '\n' : < err-msg) # By some bug, on Solaris 11 (5.11 snv_86), err_msg ends up # containing '1> fifo:printf: write error:'. Recognize that, too. diff --git a/tests/misc/printf.sh b/tests/misc/printf.sh index b2292252..87ca489f 100755 --- a/tests/misc/printf.sh +++ b/tests/misc/printf.sh @@ -1,7 +1,7 @@ #!/bin/sh # basic tests for printf -# Copyright (C) 2002-2014 Free Software Foundation, Inc. +# Copyright (C) 2002-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -25,7 +25,9 @@ getlimits_ # Verify the 3 methods of specifying "Escape": -test $($prog "\x1b\n\33\n\e\n" | uniq -u) && fail=1 +printf '%s\n' . . . | tr . '\033' > exp +$prog '\x1b\n\33\n\e\n' > out || fail=1 +compare exp out || fail=1 # This would fail (by printing the '--') for printf in sh-utils # and in coreutils 4.5.1. @@ -68,17 +70,17 @@ $prog '8 %b %b %b %b\n' '\1y' '\01y' '\001y' '\0001y'|tr '\1' = >> out $prog '9 %*dx\n' -2 0 >>out || fail=1 $prog '10 %.*dx\n' $INT_UFLOW 0 >>out || fail=1 -$prog '%.*dx\n' $INT_OFLOW 0 >>out 2> /dev/null && fail=1 +returns_ 1 $prog '%.*dx\n' $INT_OFLOW 0 >>out 2> /dev/null || fail=1 $prog '11 %*c\n' 2 x >>out || fail=1 -$prog '%#d\n' 0 >>out 2> /dev/null && fail=1 +returns_ 1 $prog '%#d\n' 0 >>out 2> /dev/null || fail=1 -$prog '%0s\n' 0 >>out 2> /dev/null && fail=1 +returns_ 1 $prog '%0s\n' 0 >>out 2> /dev/null || fail=1 -$prog '%.9c\n' 0 >>out 2> /dev/null && fail=1 +returns_ 1 $prog '%.9c\n' 0 >>out 2> /dev/null || fail=1 -$prog '%'\''s\n' 0 >>out 2> /dev/null && fail=1 +returns_ 1 $prog '%'\''s\n' 0 >>out 2> /dev/null || fail=1 cat <<\EOF > exp 1 x y diff --git a/tests/misc/ptx-overrun.sh b/tests/misc/ptx-overrun.sh index be9fb524..301e8dc6 100755 --- a/tests/misc/ptx-overrun.sh +++ b/tests/misc/ptx-overrun.sh @@ -1,6 +1,6 @@ #!/bin/sh -# Copyright (C) 2008-2014 Free Software Foundation, Inc. +# Copyright (C) 2008-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/misc/ptx.pl b/tests/misc/ptx.pl index 8a91d616..83583238 100755 --- a/tests/misc/ptx.pl +++ b/tests/misc/ptx.pl @@ -1,6 +1,6 @@ #!/usr/bin/perl -# Copyright (C) 2008-2014 Free Software Foundation, Inc. +# Copyright (C) 2008-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/misc/pwd-long.sh b/tests/misc/pwd-long.sh index 1ba0c1a9..3ced777a 100755 --- a/tests/misc/pwd-long.sh +++ b/tests/misc/pwd-long.sh @@ -2,7 +2,7 @@ # -*- perl -*- # Ensure that pwd works even when run from a very deep directory. -# Copyright (C) 2006-2014 Free Software Foundation, Inc. +# Copyright (C) 2006-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -56,7 +56,6 @@ sub normalize_to_cwd_relative ($$$) } # Set up a safe, well-known environment -delete @ENV{qw(BASH_ENV CDPATH ENV)}; $ENV{IFS} = ''; # Taint checking requires a sanitized $PATH. This script performs no $PATH diff --git a/tests/misc/pwd-option.sh b/tests/misc/pwd-option.sh index 0eba9429..fb2ad15b 100755 --- a/tests/misc/pwd-option.sh +++ b/tests/misc/pwd-option.sh @@ -1,7 +1,7 @@ #!/bin/sh # Ensure that pwd options work. -# Copyright (C) 2009-2014 Free Software Foundation, Inc. +# Copyright (C) 2009-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/misc/readlink-fp-loop.sh b/tests/misc/readlink-fp-loop.sh index 4ae2dc52..1c4428b9 100755 --- a/tests/misc/readlink-fp-loop.sh +++ b/tests/misc/readlink-fp-loop.sh @@ -1,7 +1,7 @@ #!/bin/sh # readlink from 6.9 would fail with a false-positive symlink loop error -# Copyright (C) 2007-2014 Free Software Foundation, Inc. +# Copyright (C) 2007-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/misc/readlink-root.sh b/tests/misc/readlink-root.sh index f33574cb..44693bdf 100755 --- a/tests/misc/readlink-root.sh +++ b/tests/misc/readlink-root.sh @@ -1,7 +1,7 @@ #!/bin/sh # tests for canonicalize-existing mode (readlink -e) on /. -# Copyright (C) 2012-2014 Free Software Foundation, Inc. +# Copyright (C) 2012-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/misc/realpath.sh b/tests/misc/realpath.sh index 257b9f24..ed4be396 100755 --- a/tests/misc/realpath.sh +++ b/tests/misc/realpath.sh @@ -1,7 +1,7 @@ #!/bin/sh # Validate realpath operation -# Copyright (C) 2011-2014 Free Software Foundation, Inc. +# Copyright (C) 2011-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -42,17 +42,17 @@ ln -s /// three || framework_failure_ # Basic operation realpath -Pqz . >/dev/null || fail=1 # Operand is required -realpath >/dev/null && fail=1 -realpath --relative-base . --relative-to . && fail=1 -realpath --relative-base . && fail=1 +returns_ 1 realpath >/dev/null || fail=1 +returns_ 1 realpath --relative-base . --relative-to . || fail=1 +returns_ 1 realpath --relative-base . || fail=1 # -e --relative-* require directories -realpath -e --relative-to=dir1/f --relative-base=. . && fail=1 +returns_ 1 realpath -e --relative-to=dir1/f --relative-base=. . || fail=1 realpath -e --relative-to=dir1/ --relative-base=. . || fail=1 # Note NUL params are unconditionally rejected by canonicalize_filename_mode -realpath -m '' && fail=1 -realpath --relative-base= --relative-to=. . && fail=1 +returns_ 1 realpath -m '' || fail=1 +returns_ 1 realpath --relative-base= --relative-to=. . || fail=1 # symlink resolution this=$(realpath .) diff --git a/tests/misc/runcon-no-reorder.sh b/tests/misc/runcon-no-reorder.sh index ca8ad5b3..274d2d7d 100755 --- a/tests/misc/runcon-no-reorder.sh +++ b/tests/misc/runcon-no-reorder.sh @@ -1,7 +1,7 @@ #!/bin/sh # Ensure that runcon does not reorder its arguments. -# Copyright (C) 2007-2014 Free Software Foundation, Inc. +# Copyright (C) 2007-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/misc/selinux.sh b/tests/misc/selinux.sh index 2a8ad89f..1f906dde 100755 --- a/tests/misc/selinux.sh +++ b/tests/misc/selinux.sh @@ -1,7 +1,7 @@ #!/bin/sh # Test SELinux-related options. -# Copyright (C) 2007-2014 Free Software Foundation, Inc. +# Copyright (C) 2007-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -47,7 +47,7 @@ c=$(ls -l f|cut -c11); test "$c" = . || fail=1 # Copy with an invalid context and ensure it fails # Note this may succeed when root and selinux is in permissive mode if test "$(getenforce)" = Enforcing; then - cp --context='invalid-selinux-context' f f.cp && fail=1 + returns_ 1 cp --context='invalid-selinux-context' f f.cp || fail=1 fi # Copy each to a new directory and ensure that context is preserved. diff --git a/tests/misc/seq-long-double.sh b/tests/misc/seq-long-double.sh index 78ed50f5..dbc59386 100755 --- a/tests/misc/seq-long-double.sh +++ b/tests/misc/seq-long-double.sh @@ -3,7 +3,7 @@ # Ensure that seq prints exactly two numbers for a 2-number integral # range at the limit of floating point precision. -# Copyright (C) 2008-2014 Free Software Foundation, Inc. +# Copyright (C) 2008-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/misc/seq-precision.sh b/tests/misc/seq-precision.sh new file mode 100755 index 00000000..b8382ca1 --- /dev/null +++ b/tests/misc/seq-precision.sh @@ -0,0 +1,79 @@ +#!/bin/sh +# Test for output with appropriate precision + +# Copyright (C) 2015 Free Software Foundation, Inc. + +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. + +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. + +. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src +print_ver_ seq + +# Integer only. Before v8.24 these would switch output format + +seq 999999 inf | head -n2 > out || fail=1 +printf "%s\n" 999999 1000000 > exp || framework_failure_ +compare exp out || fail=1 + +# Excercise buffer handling in non floating point output +for i in $(seq 100); do + n1="$(printf '%*s' $i '' | tr ' ' 9)" + n2="1$(echo $n1 | tr 9 0)" + + seq $n1 $n2 > out || fail=1 + printf "%s\n" "$n1" "$n2" > exp || framework_failure_ + compare exp out || fail=1 +done + +seq 0xF423F 0xF4240 > out || fail=1 +printf "%s\n" 999999 1000000 > exp || framework_failure_ +compare exp out || fail=1 + +# Ensure consistent precision for inf +seq 1 .1 inf | head -n2 > out || fail=1 +printf "%s\n" 1.0 1.1 > exp || framework_failure_ +compare exp out || fail=1 + +# Ensure standard output methods with inf start +seq inf inf | head -n2 | uniq > out || fail=1 +test "$(wc -l < out)" = 1 || fail=1 + +# Ensure auto precision for hex float +seq 1 0x1p-1 2 > out || fail=1 +printf "%s\n" 1 1.5 2 > exp || framework_failure_ +compare exp out || fail=1 + +# Ensure consistent precision for hex +seq 1 .1 0x2 | head -n2 > out || fail=1 +printf "%s\n" 1.0 1.1 > exp || framework_failure_ +compare exp out || fail=1 + +# Ensure consistent handling of precision/width for exponents + +seq 1.1e1 12 > out || fail=1 +printf "%s\n" 11 12 > exp || framework_failure_ +compare exp out || fail=1 + +seq 11 1.2e1 > out || fail=1 +printf "%s\n" 11 12 > exp || framework_failure_ +compare exp out || fail=1 + +seq -w 1.1e4 | head -n1 > out || fail=1 +printf "%s\n" 00001 > exp || framework_failure_ +compare exp out || fail=1 + +seq -w 1.10000e5 1.10000e5 > out || fail=1 +printf "%s\n" 110000 > exp || framework_failure_ +compare exp out || fail=1 + +Exit $fail diff --git a/tests/misc/seq.pl b/tests/misc/seq.pl index 92484363..d24acad1 100755 --- a/tests/misc/seq.pl +++ b/tests/misc/seq.pl @@ -1,7 +1,7 @@ #!/usr/bin/perl # Test "seq". -# Copyright (C) 1999-2014 Free Software Foundation, Inc. +# Copyright (C) 1999-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/misc/sha1sum-vec.pl b/tests/misc/sha1sum-vec.pl index 14005a76..fdf20459 100755 --- a/tests/misc/sha1sum-vec.pl +++ b/tests/misc/sha1sum-vec.pl @@ -1,7 +1,7 @@ #!/usr/bin/perl # Sample vectors for "sha1sum". -# Copyright (C) 2000-2014 Free Software Foundation, Inc. +# Copyright (C) 2000-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/misc/sha1sum.pl b/tests/misc/sha1sum.pl index fdb243a0..de923b63 100755 --- a/tests/misc/sha1sum.pl +++ b/tests/misc/sha1sum.pl @@ -1,7 +1,7 @@ #!/usr/bin/perl # Test "sha1sum". -# Copyright (C) 2000-2014 Free Software Foundation, Inc. +# Copyright (C) 2000-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/misc/sha224sum.pl b/tests/misc/sha224sum.pl index 384738b8..71464a6c 100755 --- a/tests/misc/sha224sum.pl +++ b/tests/misc/sha224sum.pl @@ -1,7 +1,7 @@ #!/usr/bin/perl # Test "sha224sum". -# Copyright (C) 2005-2014 Free Software Foundation, Inc. +# Copyright (C) 2005-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/misc/sha256sum.pl b/tests/misc/sha256sum.pl index e5f29392..ae724f50 100755 --- a/tests/misc/sha256sum.pl +++ b/tests/misc/sha256sum.pl @@ -1,7 +1,7 @@ #!/usr/bin/perl # Test "sha256sum". -# Copyright (C) 2005-2014 Free Software Foundation, Inc. +# Copyright (C) 2005-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/misc/sha384sum.pl b/tests/misc/sha384sum.pl index eafbf5b4..6cf8797c 100755 --- a/tests/misc/sha384sum.pl +++ b/tests/misc/sha384sum.pl @@ -1,7 +1,7 @@ #!/usr/bin/perl # Test "sha384sum". -# Copyright (C) 2005-2014 Free Software Foundation, Inc. +# Copyright (C) 2005-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/misc/sha512sum.pl b/tests/misc/sha512sum.pl index c4a1cd4a..157a1158 100755 --- a/tests/misc/sha512sum.pl +++ b/tests/misc/sha512sum.pl @@ -1,7 +1,7 @@ #!/usr/bin/perl # Test "sha512sum". -# Copyright (C) 2005-2014 Free Software Foundation, Inc. +# Copyright (C) 2005-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/misc/shred-exact.sh b/tests/misc/shred-exact.sh index 5434229c..679e2675 100755 --- a/tests/misc/shred-exact.sh +++ b/tests/misc/shred-exact.sh @@ -1,7 +1,7 @@ #!/bin/sh # Test functionality of --exact -# Copyright (C) 2000-2014 Free Software Foundation, Inc. +# Copyright (C) 2000-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -37,7 +37,7 @@ done # make sure direct I/O is handled appropriately at end of file # Create a 1MiB file as we'll probably not be using blocks larger than that -# (i.e. we want to test failed writes not at the start). +# (i.e., we want to test failed writes not at the start). truncate -s1MiB file.slop || framework_failure_ truncate -s+1 file.slop || framework_failure_ shred --exact -n2 file.slop || fail=1 diff --git a/tests/misc/shred-passes.sh b/tests/misc/shred-passes.sh index 268af950..0fa63be2 100755 --- a/tests/misc/shred-passes.sh +++ b/tests/misc/shred-passes.sh @@ -1,7 +1,7 @@ #!/bin/sh # Verify the operations done by shred -# Copyright (C) 2009-2014 Free Software Foundation, Inc. +# Copyright (C) 2009-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/misc/shred-remove.sh b/tests/misc/shred-remove.sh index 9765e352..cb27c1ca 100755 --- a/tests/misc/shred-remove.sh +++ b/tests/misc/shred-remove.sh @@ -1,7 +1,7 @@ #!/bin/sh # Exercise shred --remove -# Copyright (C) 1999-2014 Free Software Foundation, Inc. +# Copyright (C) 1999-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -30,7 +30,7 @@ chmod u-w $file || framework_failure_ # This would take so long that it appears to infloop # when using version from fileutils-4.0k. # When the command completes, expect it to fail. -shred -u $file > /dev/null 2>&1 && fail=1 +returns_ 1 shred -u $file > /dev/null 2>&1 || fail=1 rm -f $file || framework_failure_ # Ensure all --remove methods at least unlink the file @@ -42,6 +42,6 @@ done # Ensure incorrect params are diagnosed touch $file || framework_failure_ -shred -n0 --remove=none $file 2>/dev/null && fail=1 +returns_ 1 shred -n0 --remove=none $file 2>/dev/null || fail=1 Exit $fail diff --git a/tests/misc/shred-negative.sh b/tests/misc/shred-size.sh index 86cbf3e0..c6ac2d07 100755 --- a/tests/misc/shred-negative.sh +++ b/tests/misc/shred-size.sh @@ -1,7 +1,7 @@ #!/bin/sh -# Exercise shred -s-3 FILE +# Exercise shred --size -# Copyright (C) 2014 Free Software Foundation, Inc. +# Copyright (C) 2014-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -19,10 +19,16 @@ . "${srcdir=.}/tests/init.sh"; path_prepend_ ./src print_ver_ shred -echo 'shred: -2: invalid file size' > exp || framework_failure_ +# Negative size +echo "shred: invalid file size: '-2'" > exp || framework_failure_ echo 1234 > f || framework_failure_ - shred -s-2 f 2>err && fail=1 compare exp err || fail=1 +# Octal/Hex +shred -s010 f || fail=1 +test $(stat --printf=%s f) = 8 || fail=1 +shred -s0x10 f || fail=1 +test $(stat --printf=%s f) = 16 || fail=1 + Exit $fail diff --git a/tests/misc/shuf-reservoir.sh b/tests/misc/shuf-reservoir.sh index aa9edbea..3eea5e70 100755 --- a/tests/misc/shuf-reservoir.sh +++ b/tests/misc/shuf-reservoir.sh @@ -4,7 +4,7 @@ # These tests do not check valid randomness, # they just check memory allocation related code. -# Copyright (C) 2013-2014 Free Software Foundation, Inc. +# Copyright (C) 2013-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/misc/shuf.sh b/tests/misc/shuf.sh index d7251d1d..c7db14f6 100755 --- a/tests/misc/shuf.sh +++ b/tests/misc/shuf.sh @@ -1,7 +1,7 @@ #!/bin/sh # Ensure that shuf randomizes its input. -# Copyright (C) 2006-2014 Free Software Foundation, Inc. +# Copyright (C) 2006-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -47,6 +47,11 @@ test "$t" = 'a b c d e' || { fail=1; echo "not a permutation" 1>&2; } shuf -er test $? -eq 1 || fail=1 +# coreutils-8.22 and 8.23 dump core +# with a single redundant operand with --input-range +shuf -i0-0 1 +test $? -eq 1 || fail=1 + # Before coreutils-6.3, this would infloop. # "seq 1860" produces 8193 (8K + 1) bytes of output. seq 1860 | shuf > /dev/null || fail=1 @@ -66,7 +71,7 @@ touch unreadable || framework_failure_ chmod 0 unreadable || framework_failure_ if ! test -r unreadable; then shuf -n0 unreadable || fail=1 - shuf -n1 unreadable && fail=1 + { shuf -n1 unreadable || test $? -ne 1; } && fail=1 fi # Multiple -n is accepted, should use the smallest value @@ -77,25 +82,25 @@ test "$c" -eq 3 || { fail=1; echo "Multiple -n failed">&2 ; } # Test error conditions # -i and -e must not be used together -: | shuf -i0-9 -e A B && +: | { shuf -i0-9 -e A B || test $? -ne 1; } && { fail=1; echo "shuf did not detect erroneous -e and -i usage.">&2 ; } # Test invalid value for -n -: | shuf -nA && +: | { shuf -nA || test $? -ne 1; } && { fail=1; echo "shuf did not detect erroneous -n usage.">&2 ; } # Test multiple -i -shuf -i0-9 -n10 -i8-90 && +{ shuf -i0-9 -n10 -i8-90 || test $? -ne 1; } && { fail=1; echo "shuf did not detect multiple -i usage.">&2 ; } # Test invalid range for ARG in '1' 'A' '1-' '1-A'; do - shuf -i$ARG && + { shuf -i$ARG || test $? -ne 1; } && { fail=1; echo "shuf did not detect erroneous -i$ARG usage.">&2 ; } done # multiple -o are forbidden -shuf -i0-9 -o A -o B && +{ shuf -i0-9 -o A -o B || test $? -ne 1; } && { fail=1; echo "shuf did not detect erroneous multiple -o usage.">&2 ; } # multiple random-sources are forbidden -shuf -i0-9 --random-source A --random-source B && +{ shuf -i0-9 --random-source A --random-source B || test $? -ne 1; } && { fail=1; echo "shuf did not detect multiple --random-source usage.">&2 ; } # Test --repeat option @@ -120,7 +125,7 @@ test "$c" = "0 1 2 3 4 5 6 7 8 9" || # check --repeat with non-zero low value shuf --rep -i222-233 -n2000 > exp || framework_failure_ -c=$(cat exp | sort -nu | paste -s -d ' ') || framework_failure_ +c=$(sort -nu exp | paste -s -d ' ') || framework_failure_ test "$c" = "222 223 224 225 226 227 228 229 230 231 232 233" || { fail=1; echo "--repeat produced bad output with non-zero low">&2 ; } diff --git a/tests/misc/sort-NaN-infloop.sh b/tests/misc/sort-NaN-infloop.sh index 9c6e021a..15fa4e52 100755 --- a/tests/misc/sort-NaN-infloop.sh +++ b/tests/misc/sort-NaN-infloop.sh @@ -1,7 +1,7 @@ #!/bin/sh # exercise the NaN-infloop bug in coreutils-8.13 -# Copyright (C) 2011-2014 Free Software Foundation, Inc. +# Copyright (C) 2011-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/misc/sort-benchmark-random.sh b/tests/misc/sort-benchmark-random.sh index c074301f..d13073e2 100755 --- a/tests/misc/sort-benchmark-random.sh +++ b/tests/misc/sort-benchmark-random.sh @@ -1,7 +1,7 @@ #!/bin/sh # Benchmark sort on randomly generated data. -# Copyright (C) 2010-2014 Free Software Foundation, Inc. +# Copyright (C) 2010-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/misc/sort-compress-hang.sh b/tests/misc/sort-compress-hang.sh index cc1e6d36..dc101fea 100755 --- a/tests/misc/sort-compress-hang.sh +++ b/tests/misc/sort-compress-hang.sh @@ -1,7 +1,7 @@ #!/bin/sh # Test for sort --compress hang -# Copyright (C) 2010-2014 Free Software Foundation, Inc. +# Copyright (C) 2010-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -20,8 +20,8 @@ print_ver_ sort very_expensive_ -cat <<\EOF >compress || framework_failure_ -#!/bin/sh +cat <<EOF >compress || framework_failure_ +#!$SHELL tr 41 14 || exit touch ok EOF diff --git a/tests/misc/sort-compress-proc.sh b/tests/misc/sort-compress-proc.sh index d06eb56f..05017a54 100755 --- a/tests/misc/sort-compress-proc.sh +++ b/tests/misc/sort-compress-proc.sh @@ -1,7 +1,7 @@ #!/bin/sh # Test use of compression subprocesses by sort -# Copyright (C) 2010-2014 Free Software Foundation, Inc. +# Copyright (C) 2010-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -20,6 +20,11 @@ print_ver_ sort expensive_ +# Terminate any background processes +cleanup_() { kill $pid 2>/dev/null && wait $pid; } + +SORT_FAILURE=2 + seq -w 2000 > exp || fail=1 tac exp > in || fail=1 insize=$(stat -c %s - <in) || fail=1 @@ -27,8 +32,9 @@ insize=$(stat -c %s - <in) || fail=1 # This compressor's behavior is adjustable via environment variables. export PRE_COMPRESS= export POST_COMPRESS= -cat <<\EOF >compress || framework_failure_ -#!/bin/sh + +printf '%s\n' '#!'"$SHELL" >compress || framework_failure_ +cat <<\EOF >>compress || framework_failure_ eval "$PRE_COMPRESS" tr 41 14 || exit eval "$POST_COMPRESS" @@ -52,7 +58,8 @@ do exec >/dev/null 2>&1 <&1 || exit expr $size "<" '"$insize"' / 2 || { sleep 1; exit 1; } } - ' sort --compress-program=./compress -S 1k --batch-size=2 in > out && fail=1 + ' sort --compress-program=./compress -S 1k --batch-size=2 in > out + test $? -eq $SORT_FAILURE || fail=1 done # "Pre-exec child" test @@ -60,7 +67,7 @@ done # Ignore a random child process created before 'sort' was exec'ed. # This bug was also present in coreutils 8.7. # -( (sleep 1; exec false) & +( (sleep 1; exec false) & pid=$! PRE_COMPRESS='test -f ok || sleep 2' POST_COMPRESS='touch ok' exec sort --compress-program=./compress -S 1k in >out diff --git a/tests/misc/sort-compress.sh b/tests/misc/sort-compress.sh index 8f215b8b..584110e1 100755 --- a/tests/misc/sort-compress.sh +++ b/tests/misc/sort-compress.sh @@ -1,7 +1,7 @@ #!/bin/sh # Test use of compression by sort -# Copyright (C) 2007-2014 Free Software Foundation, Inc. +# Copyright (C) 2007-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -27,8 +27,8 @@ sort -S 1k in > out || fail=1 compare exp out || fail=1 # Create our own gzip program that will be used as the default -cat <<\EOF > gzip || fail=1 -#!/bin/sh +cat <<EOF > gzip || fail=1 +#!$SHELL tr 41 14 touch ok EOF diff --git a/tests/misc/sort-continue.sh b/tests/misc/sort-continue.sh index 1c4030d9..0860287a 100755 --- a/tests/misc/sort-continue.sh +++ b/tests/misc/sort-continue.sh @@ -1,7 +1,7 @@ #!/bin/sh # Tests for file descriptor exhaustion. -# Copyright (C) 2009-2014 Free Software Foundation, Inc. +# Copyright (C) 2009-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/misc/sort-debug-keys.sh b/tests/misc/sort-debug-keys.sh index ff1e19b6..776fb67c 100755 --- a/tests/misc/sort-debug-keys.sh +++ b/tests/misc/sort-debug-keys.sh @@ -1,7 +1,7 @@ #!/bin/sh # Test annotation of sort keys -# Copyright (C) 2010-2014 Free Software Foundation, Inc. +# Copyright (C) 2010-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/misc/sort-debug-warn.sh b/tests/misc/sort-debug-warn.sh index fd16829b..19015664 100755 --- a/tests/misc/sort-debug-warn.sh +++ b/tests/misc/sort-debug-warn.sh @@ -1,7 +1,7 @@ #!/bin/sh # Test warnings for sort options -# Copyright (C) 2010-2014 Free Software Foundation, Inc. +# Copyright (C) 2010-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/misc/sort-discrim.sh b/tests/misc/sort-discrim.sh index e3cd1907..9b7ad997 100755 --- a/tests/misc/sort-discrim.sh +++ b/tests/misc/sort-discrim.sh @@ -1,7 +1,7 @@ #!/bin/sh # Test discriminator-based sorting. -# Copyright (C) 2012-2014 Free Software Foundation, Inc. +# Copyright (C) 2012-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/misc/sort-exit-early.sh b/tests/misc/sort-exit-early.sh index 2a70253e..c675503c 100755 --- a/tests/misc/sort-exit-early.sh +++ b/tests/misc/sort-exit-early.sh @@ -1,7 +1,7 @@ #!/bin/sh # Test 'sort' exits early on inaccessible inputs or output -# Copyright (C) 2012-2014 Free Software Foundation, Inc. +# Copyright (C) 2012-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -20,18 +20,18 @@ print_ver_ sort skip_if_root_ +SORT_FAILURE=2 + # Check output is writable before starting to sort touch input chmod a-w input -timeout 10 sort -o input && fail=1 -test $? = 124 && fail=1 +returns_ $SORT_FAILURE timeout 10 sort -o input || fail=1 # Check all inputs are readable before starting to sort # Also ensure the output isn't created in this case touch output chmod a-r output -timeout 10 sort -o typo - output && fail=1 -test $? = 124 && fail=1 +returns_ $SORT_FAILURE timeout 10 sort -o typo - output || fail=1 test -e typo && fail=1 Exit $fail diff --git a/tests/misc/sort-files0-from.pl b/tests/misc/sort-files0-from.pl index 77c1b1aa..63c5bb3e 100755 --- a/tests/misc/sort-files0-from.pl +++ b/tests/misc/sort-files0-from.pl @@ -2,7 +2,7 @@ # Exercise sort's --files0-from option. # FIXME: keep this file in sync with tests/du/files0-from. -# Copyright (C) 2006-2014 Free Software Foundation, Inc. +# Copyright (C) 2006-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/misc/sort-float.sh b/tests/misc/sort-float.sh index 7a4e8292..1c760baf 100755 --- a/tests/misc/sort-float.sh +++ b/tests/misc/sort-float.sh @@ -1,7 +1,7 @@ #!/bin/sh # Ensure sort -g sorts floating point limits correctly -# Copyright (C) 2010-2014 Free Software Foundation, Inc. +# Copyright (C) 2010-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/misc/sort-merge-fdlimit.sh b/tests/misc/sort-merge-fdlimit.sh index 0df7aa66..ce1a6c48 100755 --- a/tests/misc/sort-merge-fdlimit.sh +++ b/tests/misc/sort-merge-fdlimit.sh @@ -2,7 +2,7 @@ # Test whether sort avoids opening more file descriptors than it is # allowed when merging files. -# Copyright (C) 2009-2014 Free Software Foundation, Inc. +# Copyright (C) 2009-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/misc/sort-merge.pl b/tests/misc/sort-merge.pl index 06e3c15f..c60e2626 100755 --- a/tests/misc/sort-merge.pl +++ b/tests/misc/sort-merge.pl @@ -1,7 +1,7 @@ #!/usr/bin/perl # Test "sort -m". -# Copyright (C) 2002-2014 Free Software Foundation, Inc. +# Copyright (C) 2002-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/misc/sort-month.sh b/tests/misc/sort-month.sh index 40c814da..ab49cc28 100755 --- a/tests/misc/sort-month.sh +++ b/tests/misc/sort-month.sh @@ -1,7 +1,7 @@ #!/bin/sh # Test sorting of abbreviated months from the locale -# Copyright (C) 2010-2014 Free Software Foundation, Inc. +# Copyright (C) 2010-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/misc/sort-rand.sh b/tests/misc/sort-rand.sh index 2397fb4b..3fc5fef2 100755 --- a/tests/misc/sort-rand.sh +++ b/tests/misc/sort-rand.sh @@ -1,7 +1,7 @@ #!/bin/sh # Ensure that sort --sort-random doesn't sort. -# Copyright (C) 2005-2014 Free Software Foundation, Inc. +# Copyright (C) 2005-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/misc/sort-spinlock-abuse.sh b/tests/misc/sort-spinlock-abuse.sh index 49ed920f..e81abf80 100755 --- a/tests/misc/sort-spinlock-abuse.sh +++ b/tests/misc/sort-spinlock-abuse.sh @@ -2,7 +2,7 @@ # trigger a bug that would make parallel sort use 100% of one or more # CPU while blocked on output. -# Copyright (C) 2010-2014 Free Software Foundation, Inc. +# Copyright (C) 2010-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -29,13 +29,16 @@ very_expensive_ grep '^#define HAVE_PTHREAD_T 1' "$CONFIG_HEADER" > /dev/null || skip_ 'requires pthreads' +# Terminate any background processes +cleanup_() { kill $pid 2>/dev/null && wait $pid; } + seq 100000 > in || framework_failure_ mkfifo_or_skip_ fifo # Arrange for sort to require 8.0+ seconds of wall-clock time, # while actually using far less than 1 second of CPU time. (for i in $(seq 80); do read line; echo $i; sleep .1; done - cat > /dev/null) < fifo & + cat > /dev/null) < fifo & pid=$! # However, under heavy load, it can easily take more than # one second of CPU time, so set a permissive limit: diff --git a/tests/misc/sort-stale-thread-mem.sh b/tests/misc/sort-stale-thread-mem.sh index 78defd23..dd4789eb 100755 --- a/tests/misc/sort-stale-thread-mem.sh +++ b/tests/misc/sort-stale-thread-mem.sh @@ -1,7 +1,7 @@ #!/bin/sh # Trigger a bug that would cause 'sort' to reference stale thread stack memory. -# Copyright (C) 2010-2014 Free Software Foundation, Inc. +# Copyright (C) 2010-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/misc/sort-u-FMR.sh b/tests/misc/sort-u-FMR.sh index 3019cbe8..0720ed43 100755 --- a/tests/misc/sort-u-FMR.sh +++ b/tests/misc/sort-u-FMR.sh @@ -1,7 +1,7 @@ #!/bin/sh # Before 8.19, this would trigger a free-memory read. -# Copyright (C) 2012-2014 Free Software Foundation, Inc. +# Copyright (C) 2012-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/misc/sort-unique-segv.sh b/tests/misc/sort-unique-segv.sh index 148dc243..bd0dc575 100755 --- a/tests/misc/sort-unique-segv.sh +++ b/tests/misc/sort-unique-segv.sh @@ -1,7 +1,7 @@ #!/bin/sh # parallel sort with --unique (-u) would segfault -# Copyright (C) 2010-2014 Free Software Foundation, Inc. +# Copyright (C) 2010-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/misc/sort-unique.sh b/tests/misc/sort-unique.sh index d7a7629c..eaaef681 100755 --- a/tests/misc/sort-unique.sh +++ b/tests/misc/sort-unique.sh @@ -1,7 +1,7 @@ #!/bin/sh # Test 'sort -u'. -# Copyright (C) 2010-2014 Free Software Foundation, Inc. +# Copyright (C) 2010-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/misc/sort-version.sh b/tests/misc/sort-version.sh index d8db1e1c..383f100f 100755 --- a/tests/misc/sort-version.sh +++ b/tests/misc/sort-version.sh @@ -1,7 +1,7 @@ #!/bin/sh # exercise sort's --sort=version option -# Copyright (C) 2008-2014 Free Software Foundation, Inc. +# Copyright (C) 2008-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/misc/sort.pl b/tests/misc/sort.pl index db732094..f6a222c2 100755 --- a/tests/misc/sort.pl +++ b/tests/misc/sort.pl @@ -1,6 +1,6 @@ #!/usr/bin/perl -# Copyright (C) 2008-2014 Free Software Foundation, Inc. +# Copyright (C) 2008-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -271,11 +271,11 @@ my @Tests = ["18e", '-nb -k1.1,1.2', {IN=>" 901\n100\n"}, {OUT=>"100\n 901\n"}], # When ignoring leading blanks for end position, ensure blanks from -# next field are not included in the sort. I.E. order should not change here. +# next field are not included in the sort. I.e., order should not change here. ["18f", '-k1,1b', {IN=>"a y\na z\n"}, {OUT=>"a y\na z\n"}], # When ignoring leading blanks for start position, ensure blanks from -# next field are not included in the sort. I.E. order should not change here. +# next field are not included in the sort. I.e., order should not change here. # This was noticed as an issue on fedora 8 (only in multibyte locales). ["18g", '-k1b,1', {IN=>"a y\na z\n"}, {OUT=>"a y\na z\n"}, {ENV => "LC_ALL=$mb_locale"}], @@ -317,6 +317,10 @@ my @Tests = ["22a", '-k 2,2fd -k 1,1r', {IN=>"3 b\n4 B\n"}, {OUT=>"4 B\n3 b\n"}], ["22b", '-k 2,2d -k 1,1r', {IN=>"3 b\n4 b\n"}, {OUT=>"4 b\n3 b\n"}], +# This fails in Fedora 20, per Göran Uddeborg in: http://bugs.gnu.org/18540 +["23", '-s -k1,1 -t/', {IN=>"a b/x\na-b-c/x\n"}, {OUT=>"a b/x\na-b-c/x\n"}, + {ENV => "LC_ALL=$mb_locale"}], + ["no-file1", 'no-file', {EXIT=>2}, {ERR=>$no_file}], # This test failed until 1.22f. Sort didn't give an error. # From Will Edgington. diff --git a/tests/misc/stat-birthtime.sh b/tests/misc/stat-birthtime.sh index f06ddea8..d7877c59 100755 --- a/tests/misc/stat-birthtime.sh +++ b/tests/misc/stat-birthtime.sh @@ -1,7 +1,7 @@ #!/bin/sh # ensure that stat attempts birthtime access -# Copyright (C) 2010-2014 Free Software Foundation, Inc. +# Copyright (C) 2010-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/misc/stat-fmt.sh b/tests/misc/stat-fmt.sh index 3982f23b..2a3e9d2a 100755 --- a/tests/misc/stat-fmt.sh +++ b/tests/misc/stat-fmt.sh @@ -1,7 +1,7 @@ #!/bin/sh # ensure that stat properly handles a format string ending with % -# Copyright (C) 2003-2014 Free Software Foundation, Inc. +# Copyright (C) 2003-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/misc/stat-hyphen.sh b/tests/misc/stat-hyphen.sh index 9f090a0f..a2e0a3fb 100755 --- a/tests/misc/stat-hyphen.sh +++ b/tests/misc/stat-hyphen.sh @@ -1,7 +1,7 @@ #!/bin/sh # demonstrate that stat - works and stat -f - does not. -# Copyright (C) 2009-2014 Free Software Foundation, Inc. +# Copyright (C) 2009-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -23,7 +23,7 @@ printf -- '-\n' > exp || framework_failure_ touch f || framework_failure_ stat --format=%n - < f > out || fail=1 -stat -f - < f && fail=1 +returns_ 1 stat -f - < f || fail=1 compare exp out || fail=1 diff --git a/tests/misc/stat-mount.sh b/tests/misc/stat-mount.sh index ab1ff479..34193875 100755 --- a/tests/misc/stat-mount.sh +++ b/tests/misc/stat-mount.sh @@ -1,7 +1,7 @@ #!/bin/sh # Test stat -c%m -# Copyright (C) 2010-2014 Free Software Foundation, Inc. +# Copyright (C) 2010-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/misc/stat-nanoseconds.sh b/tests/misc/stat-nanoseconds.sh index 30c47c02..f08ac983 100755 --- a/tests/misc/stat-nanoseconds.sh +++ b/tests/misc/stat-nanoseconds.sh @@ -1,7 +1,7 @@ #!/bin/sh # Exercise format strings involving %:X, %:Y, etc. -# Copyright (C) 2010-2014 Free Software Foundation, Inc. +# Copyright (C) 2010-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/misc/stat-printf.pl b/tests/misc/stat-printf.pl index 5021130d..967eef7d 100755 --- a/tests/misc/stat-printf.pl +++ b/tests/misc/stat-printf.pl @@ -1,7 +1,7 @@ #!/usr/bin/perl # Test "stat --printf". -# Copyright (C) 2005-2014 Free Software Foundation, Inc. +# Copyright (C) 2005-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/misc/stat-slash.sh b/tests/misc/stat-slash.sh index 465de2ed..fecb7b69 100755 --- a/tests/misc/stat-slash.sh +++ b/tests/misc/stat-slash.sh @@ -1,7 +1,7 @@ #!/bin/sh # demonstrate that stat handles trailing slashes correctly -# Copyright (C) 2009-2014 Free Software Foundation, Inc. +# Copyright (C) 2009-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -33,7 +33,7 @@ EOF # This failed on Solaris 9 for coreutils 8.0. stat --format=%n link1 > out || fail=1 -stat --format=%n link1/ >> out && fail=1 +returns_ 1 stat --format=%n link1/ >> out || fail=1 stat --format=%F link2 >> out || fail=1 stat -L --format=%F link2 >> out || fail=1 diff --git a/tests/misc/stdbuf.sh b/tests/misc/stdbuf.sh index e0ca3530..428d4a2f 100755 --- a/tests/misc/stdbuf.sh +++ b/tests/misc/stdbuf.sh @@ -1,7 +1,7 @@ #!/bin/sh # Exercise stdbuf functionality -# Copyright (C) 2009-2014 Free Software Foundation, Inc. +# Copyright (C) 2009-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -58,15 +58,18 @@ test $? = 126 || fail=1 stdbuf -o1 no_such # no such command test $? = 127 || fail=1 +# Terminate any background processes +cleanup_() { kill $pid 2>/dev/null && wait $pid; } + # Ensure line buffering stdout takes effect stdbuf_linebuffer() { local delay="$1" printf '1\n' > exp - dd count=1 if=fifo > out 2> err & + dd count=1 if=fifo > out 2> err & pid=$! (printf '1\n'; sleep $delay; printf '2\n') | stdbuf -oL uniq > fifo - wait # for dd to complete + wait $pid compare exp out } @@ -78,16 +81,16 @@ stdbuf_unbuffer() # Ensure un buffering stdout takes effect printf '1\n' > exp - dd count=1 if=fifo > out 2> err & + dd count=1 if=fifo > out 2> err & pid=$! (printf '1\n'; sleep $delay; printf '2\n') | stdbuf -o0 uniq > fifo - wait # for dd to complete + wait $pid compare exp out } retry_delay_ stdbuf_unbuffer .1 6 || fail=1 # Ensure un buffering stdin takes effect -# The following works for me, but is racy. I.E. we're depending +# The following works for me, but is racy. I.e., we're depending # on dd to run and close the fifo before the second write by uniq. # If we add a sleep, then we're just testing -oL # printf '3\n' > exp diff --git a/tests/misc/stty-invalid.sh b/tests/misc/stty-invalid.sh index 36bc8aa0..881146f6 100755 --- a/tests/misc/stty-invalid.sh +++ b/tests/misc/stty-invalid.sh @@ -1,7 +1,7 @@ #!/bin/sh # Ensure that stty diagnoses invalid inputs, rather than silently misbehaving. -# Copyright (C) 2007-2014 Free Software Foundation, Inc. +# Copyright (C) 2007-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -34,8 +34,10 @@ stty $saved_state || fail=1 # For each of the following, with coreutils-6.9 and earlier, # stty would fail to diagnose the error on at least Solaris 10. hex_2_64=10000000000000000 -stty $(echo $saved_state |sed 's/^[^:]*:/'$hex_2_64:/) 2>/dev/null && fail=1 -stty $(echo $saved_state |sed 's/:[0-9a-f]*$/:'$hex_2_64/) 2>/dev/null && fail=1 +returns_ 1 stty $(echo $saved_state |sed 's/^[^:]*:/'$hex_2_64:/) \ + 2>/dev/null || fail=1 +returns_ 1 stty $(echo $saved_state |sed 's/:[0-9a-f]*$/:'$hex_2_64/) \ + 2>/dev/null || fail=1 # Just in case either of the above mistakenly succeeds (and changes # the state of our tty), try to restore the initial state. diff --git a/tests/misc/stty-pairs.sh b/tests/misc/stty-pairs.sh index 1a7c26cf..129c22f0 100755 --- a/tests/misc/stty-pairs.sh +++ b/tests/misc/stty-pairs.sh @@ -1,7 +1,7 @@ #!/bin/sh # Make sure stty can parse most of its options - in pairs [expensive]. -# Copyright (C) 1998-2014 Free Software Foundation, Inc. +# Copyright (C) 1998-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/misc/stty-row-col.sh b/tests/misc/stty-row-col.sh index 729d6f91..0616812e 100755 --- a/tests/misc/stty-row-col.sh +++ b/tests/misc/stty-row-col.sh @@ -1,7 +1,7 @@ #! /bin/sh # Test "stty" with rows and columns. -# Copyright (C) 1998-2014 Free Software Foundation, Inc. +# Copyright (C) 1998-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -47,6 +47,8 @@ tests=' 7 rows_1 1_1 8 columns_80 1_80 9 rows_30 30_80 +10 rows_0x1E 30_80 +11 rows_036 30_80 NA LAST NA ' set $tests diff --git a/tests/misc/stty.sh b/tests/misc/stty.sh index ab1c78de..5e39b72e 100755 --- a/tests/misc/stty.sh +++ b/tests/misc/stty.sh @@ -1,7 +1,7 @@ #! /bin/sh # Make sure stty can parse most of its options. -# Copyright (C) 1998-2014 Free Software Foundation, Inc. +# Copyright (C) 1998-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -34,9 +34,9 @@ stty $(cat $saved_state) || fail=1 stty erase - || fail=1 # These would improperly ignore invalid options through coreutils 5.2.1. -stty -F 2>/dev/null && fail=1 -stty -raw -F no/such/file 2>/dev/null && fail=1 -stty -raw -a 2>/dev/null && fail=1 +returns_ 1 stty -F 2>/dev/null || fail=1 +returns_ 1 stty -raw -F no/such/file 2>/dev/null || fail=1 +returns_ 1 stty -raw -a 2>/dev/null || fail=1 # Build a list of all boolean options stty accepts on this system. # Don't depend on terminal width. Put each option on its own line, @@ -57,6 +57,10 @@ for opt in $options; do cstopb|crtscts|cdtrdsr|icanon) continue;; esac + # This is listed as supported on FreeBSD + # but the ioctl returns ENOTTY. + test $opt = extproc && continue + stty $opt || fail=1 # Likewise, 'stty -cread' would fail, so skip that, too. diff --git a/tests/misc/sum-sysv.sh b/tests/misc/sum-sysv.sh index 7624685f..8b732eef 100755 --- a/tests/misc/sum-sysv.sh +++ b/tests/misc/sum-sysv.sh @@ -1,7 +1,7 @@ #!/bin/sh # make sure 'sum -s' works for input whose sum of bytes is larger than 2^32 -# Copyright (C) 2001-2014 Free Software Foundation, Inc. +# Copyright (C) 2001-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/misc/sum.pl b/tests/misc/sum.pl index 696eda4b..7b9412ef 100755 --- a/tests/misc/sum.pl +++ b/tests/misc/sum.pl @@ -1,7 +1,7 @@ #!/usr/bin/perl # Test "sum". -# Copyright (C) 2000-2014 Free Software Foundation, Inc. +# Copyright (C) 2000-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/misc/sync.sh b/tests/misc/sync.sh new file mode 100755 index 00000000..c6e09beb --- /dev/null +++ b/tests/misc/sync.sh @@ -0,0 +1,52 @@ +#!/bin/sh +# Test various sync(1) operations + +# Copyright (C) 2015 Free Software Foundation, Inc. + +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. + +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. + +. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src +print_ver_ sync + +touch file + +# fdatasync+syncfs is nonsensical +returns_ 1 sync --data --file-system || fail=1 + +# fdatasync needs an operand +returns_ 1 sync -d || fail=1 + +# Test syncing of file (fsync) (little side effects) +sync file || fail=1 + +# Ensure multiple args are processed and diagnosed +returns_ 1 sync file nofile || fail=1 + +# Ensure inaccessible dirs give an appropriate error +mkdir norw || framework_failure_ +chmod 0 norw || framework_failure_ +if ! test -r norw; then + sync norw 2>err + printf "sync: error opening 'norw': Permission denied\n" >exp + compare exp err || fail=1 +fi + +if test "$fail" != '1'; then + # Ensure a fifo doesn't block + mkfifo_or_skip_ fifo + timeout 10 sync fifo + test $? = 124 && fail=1 +fi + +Exit $fail diff --git a/tests/misc/tac-2-nonseekable.sh b/tests/misc/tac-2-nonseekable.sh index c27694c1..60f3dd4d 100755 --- a/tests/misc/tac-2-nonseekable.sh +++ b/tests/misc/tac-2-nonseekable.sh @@ -1,7 +1,7 @@ #!/bin/sh -# ensure that tac works with two or more non-seekable inputs +# ensure that tac works with non-seekable or quasi-seekable inputs -# Copyright (C) 2011-2014 Free Software Foundation, Inc. +# Copyright (C) 2011-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -24,4 +24,16 @@ echo x > exp || fail=1 compare exp out || fail=1 compare /dev/null err || fail=1 +# Make sure it works on funny files in /proc and /sys. + +for file in /proc/version /sys/kernel/profiling; do + if test -r $file; then + cp -f $file copy && + tac copy > exp1 || framework_failure_ + + tac $file > out1 || fail=1 + compare exp1 out1 || fail=1 + fi +done + Exit $fail diff --git a/tests/misc/tac-continue.sh b/tests/misc/tac-continue.sh index d4280650..1389072b 100755 --- a/tests/misc/tac-continue.sh +++ b/tests/misc/tac-continue.sh @@ -3,7 +3,7 @@ # when it encounters an error with say the first one. # With coreutils-5.2.1 and earlier, this test would fail. -# Copyright (C) 2004-2014 Free Software Foundation, Inc. +# Copyright (C) 2004-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -33,9 +33,15 @@ if ! test -d "$FULL_PARTITION_TMPDIR"; then fi fp_tmp="$FULL_PARTITION_TMPDIR/tac-cont-$$" -cleanup_() { rm -f "$fp_tmp"; } - -# Make sure we can create an empty file there (i.e. no shortage of inodes). +cleanup_() +{ + # Terminate any background process + # and remove tmp dir + rm -f "$fp_tmp" + kill $pid 2>/dev/null && wait $pid +} + +# Make sure we can create an empty file there (i.e., no shortage of inodes). if ! touch $fp_tmp; then echo "$0: $fp_tmp: cannot create empty file" 1>&2 Exit 1 @@ -54,7 +60,7 @@ seq 5 > in # Give tac a fifo command line argument. # This makes it try to create a temporary file in $TMPDIR. mkfifo_or_skip_ fifo -seq 1000 > fifo & +seq 1000 > fifo & pid=$! TMPDIR=$FULL_PARTITION_TMPDIR tac fifo in >out 2>err && fail=1 cat <<\EOF > exp || fail=1 diff --git a/tests/misc/tac.pl b/tests/misc/tac.pl index 0f21affd..38196d23 100755 --- a/tests/misc/tac.pl +++ b/tests/misc/tac.pl @@ -1,6 +1,6 @@ #!/usr/bin/perl -# Copyright (C) 2008-2014 Free Software Foundation, Inc. +# Copyright (C) 2008-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/misc/tail.pl b/tests/misc/tail.pl index 6798eb05..7f113aaf 100755 --- a/tests/misc/tail.pl +++ b/tests/misc/tail.pl @@ -1,7 +1,7 @@ #!/usr/bin/perl # Test tail. -# Copyright (C) 2008-2014 Free Software Foundation, Inc. +# Copyright (C) 2008-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -19,7 +19,7 @@ use strict; my $prog = 'tail'; -my $normalize_filename = {ERR_SUBST => 's/^$prog: .*?:/$prog: -:/'}; +my $normalize_strerror = "s/': .*/'/"; # Turn off localization of executable's output. @ENV{qw(LANGUAGE LANG LC_ALL)} = ('C') x 3; @@ -59,7 +59,7 @@ my @tv = ( "$prog: cannot open '+cl' for reading: No such file or directory\n"], ['err-2', '-cl', '', '', 1, - "$prog: l: invalid number of bytes\n"], + "$prog: invalid number of bytes: 'l'\n", $normalize_strerror], ['err-3', '+2cz', '', '', 1, "$prog: cannot open '+2cz' for reading: No such file or directory\n"], @@ -72,9 +72,10 @@ my @tv = ( # the diagnostic: 'tail: 99999999999999999999: invalid number of bytes' # on all systems... probably, for now, maybe. ['err-5', '-c99999999999999999999', '', '', 1, - "$prog: 99999999999999999999: invalid number of bytes\n"], + "$prog: invalid number of bytes: '99999999999999999999'\n", + $normalize_strerror], ['err-6', '-c --', '', '', 1, - "$prog: -: invalid number of bytes\n", $normalize_filename], + "$prog: invalid number of bytes: '-'\n", $normalize_strerror], # Same as -n 10 ['minus-1', '-', '', '', 0], @@ -106,10 +107,10 @@ my @Tests; foreach my $t (@tv) { - my ($test_name, $flags, $in, $exp, $ret, $err_msg) = @$t; + my ($test_name, $flags, $in, $exp, $ret, $err_msg, $err_sub) = @$t; my $e = [$test_name, $flags, {IN=>$in}, {OUT=>$exp}]; $ret - and push @$e, {EXIT=>$ret}, {ERR=>$err_msg}; + and push @$e, {EXIT=>$ret}, {ERR=>$err_msg}, {ERR_SUBST=>$err_sub}; $test_name =~ /^(obs-plus-|minus-)/ and push @$e, {ENV=>'_POSIX2_VERSION=199209'}; diff --git a/tests/misc/tee.sh b/tests/misc/tee.sh index f0072bfd..f457a0b7 100755 --- a/tests/misc/tee.sh +++ b/tests/misc/tee.sh @@ -1,7 +1,7 @@ #!/bin/sh # test for basic tee functionality. -# Copyright (C) 2005-2014 Free Software Foundation, Inc. +# Copyright (C) 2005-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -20,15 +20,90 @@ print_ver_ tee echo line >sample || framework_failure_ -nums=$(seq 9) || framework_failure_ - -for n in 0 $nums; do - files=$(seq $n) - rm -f $files - tee $files <sample >out || fail=1 - for f in out $files; do - compare sample $f || fail=1 - done + +# POSIX says: "Processing of at least 13 file operands shall be supported." +for n in 0 1 2 12 13; do + files=$(seq $n) + rm -f $files + tee $files <sample >out || fail=1 + for f in out $files; do + compare sample $f || fail=1 + done done +# Ensure tee treats '-' as the name of a file, as mandated by POSIX. +# Between v5.3.0 and v8.23, a '-' argument caused tee to send another +# copy of input to standard output. +tee - <sample >out 2>err || fail=1 +compare sample ./- || fail=1 +compare sample out || fail=1 +compare /dev/null err || fail + +# Ensure tee exits early if no more writable outputs +if test -w /dev/full && test -c /dev/full; then + yes | returns_ 1 timeout 10 tee /dev/full 2>err >/dev/full || fail=1 + # Ensure an error for each of the 2 outputs + # (and no redundant errors for stdout). + test $(wc -l < err) = 2 || { cat err; fail=1; } + + + # Ensure we continue with outputs that are OK + seq 10000 > multi_read || framework_failure_ + + returns_ 1 tee /dev/full out2 2>err >out1 <multi_read || fail=1 + cmp multi_read out1 || fail=1 + cmp multi_read out2 || fail=1 + # Ensure an error for failing output + test $(wc -l < err) = 1 || { cat err; fail=1; } + + returns_ 1 tee out1 out2 2>err >/dev/full <multi_read || fail=1 + cmp multi_read out1 || fail=1 + cmp multi_read out2 || fail=1 + # Ensure an error for failing output + test $(wc -l < err) = 1 || { cat err; fail=1; } +fi + + +# Ensure tee honors --output-error modes +mkfifo_or_skip_ fifo +read_fifo() { timeout 10 dd count=1 if=fifo of=/dev/null status=none & } + +# Determine platform sigpipe exit status +read_fifo +yes >fifo +pipe_status=$? + +# Default operation is to continue on output errors but exit silently on SIGPIPE +read_fifo +yes | returns_ $pipe_status timeout 10 tee ./e/noent 2>err >fifo || fail=1 +test $(wc -l < err) = 1 || { cat err; fail=1; } + +# With -p, SIGPIPE is suppressed, exit 0 for EPIPE when all outputs finished +read_fifo +yes | timeout 10 tee -p 2>err >fifo || fail=1 +test $(wc -l < err) = 0 || { cat err; fail=1; } + +# With --output-error=warn, exit 1 for EPIPE when all outputs finished +read_fifo +yes | returns_ 1 timeout 10 tee --output-error=warn 2>err >fifo || fail=1 +test $(wc -l < err) = 1 || { cat err; fail=1; } + +# With --output-error=exit, exit 1 immediately for EPIPE +read_fifo +yes | returns_ 1 timeout 10 tee --output-error=exit /dev/null 2>err >fifo \ + || fail=1 +test $(wc -l < err) = 1 || { cat err; fail=1; } + +# With --output-error=exit, exit 1 immediately on output error +read_fifo +yes | returns_ 1 timeout 10 tee --output-error=exit ./e/noent 2>err >fifo \ + || fail=1 +test $(wc -l < err) = 1 || { cat err; fail=1; } + +# With --output-error=exit-nopipe, exit 0 for EPIPE +read_fifo +yes | timeout 10 tee --output-error=exit-nopipe 2>err >fifo || fail=1 +test $(wc -l < err) = 0 || { cat err; fail=1; } + +wait Exit $fail diff --git a/tests/misc/test-diag.pl b/tests/misc/test-diag.pl index 14d0f4d5..f498d1a8 100755 --- a/tests/misc/test-diag.pl +++ b/tests/misc/test-diag.pl @@ -1,7 +1,7 @@ #!/usr/bin/perl # Test the diagnostics of "test". -# Copyright (C) 2006-2014 Free Software Foundation, Inc. +# Copyright (C) 2006-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/misc/test.pl b/tests/misc/test.pl index b27adb48..f4c1ed1a 100755 --- a/tests/misc/test.pl +++ b/tests/misc/test.pl @@ -1,6 +1,6 @@ #!/usr/bin/perl -# Copyright (C) 2008-2014 Free Software Foundation, Inc. +# Copyright (C) 2008-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/misc/timeout-blocked.pl b/tests/misc/timeout-blocked.pl index b5f31c96..77bf6667 100755 --- a/tests/misc/timeout-blocked.pl +++ b/tests/misc/timeout-blocked.pl @@ -1,7 +1,7 @@ #!/usr/bin/perl # Test that timeout handles blocked SIGALRM from its parent. -# Copyright (C) 2013-2014 Free Software Foundation, Inc. +# Copyright (C) 2013-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/misc/timeout-group.sh b/tests/misc/timeout-group.sh index 23c1b065..d47f0dc8 100755 --- a/tests/misc/timeout-group.sh +++ b/tests/misc/timeout-group.sh @@ -1,7 +1,7 @@ #!/bin/sh # test program group handling -# Copyright (C) 2011-2014 Free Software Foundation, Inc. +# Copyright (C) 2011-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -30,8 +30,8 @@ print_ver_ timeout setsid true || skip_ "setsid required to control groups" -cat > timeout.cmd <<\EOF -#!/bin/sh +printf '%s\n' '#!'"$SHELL" > timeout.cmd || framework_failure_ +cat >> timeout.cmd <<\EOF trap 'touch int.received; exit' INT touch timeout.running count=$1 @@ -42,8 +42,8 @@ done EOF chmod a+x timeout.cmd -cat > group.sh <<\EOF -#!/bin/sh +cat > group.sh <<EOF +#!$SHELL trap '' INT timeout --foreground 25 ./timeout.cmd 20& wait @@ -57,15 +57,17 @@ check_timeout_cmd_running() { sleep $delay; return 1; } } +# Terminate any background processes +cleanup_() { kill $pid 2>/dev/null && wait $pid; } # Start above script in its own group. # We could use timeout for this, but that assumes an implementation. -setsid ./group.sh & +setsid ./group.sh & pid=$! # Wait 6.3s for timeout.cmd to start retry_delay_ check_timeout_cmd_running .1 6 || fail=1 # Simulate a Ctrl-C to the group to test timely exit # Note dash doesn't support signalling groups (a leading -) -env kill -INT -- -$! +env kill -INT -- -$pid wait test -e int.received || fail=1 @@ -82,8 +84,7 @@ start=$(date +%s) # Note the first timeout must send a signal that # the second is handling for it to be propagated to the command. # SIGINT, SIGTERM, SIGALRM etc. are implicit. -timeout -sALRM 30 timeout -sINT 25 ./timeout.cmd 20& -pid=$! +timeout -sALRM 30 timeout -sINT 25 ./timeout.cmd 20 & pid=$! # Wait 6.3s for timeout.cmd to start retry_delay_ check_timeout_cmd_running .1 6 || fail=1 kill -ALRM $pid # trigger the alarm of the first timeout command diff --git a/tests/misc/timeout-parameters.sh b/tests/misc/timeout-parameters.sh index fca30f0b..0bdb38ac 100755 --- a/tests/misc/timeout-parameters.sh +++ b/tests/misc/timeout-parameters.sh @@ -1,7 +1,7 @@ #!/bin/sh # Validate timeout parameter combinations -# Copyright (C) 2008-2014 Free Software Foundation, Inc. +# Copyright (C) 2008-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/misc/timeout.sh b/tests/misc/timeout.sh index 8eaeef95..3cebd330 100755 --- a/tests/misc/timeout.sh +++ b/tests/misc/timeout.sh @@ -1,7 +1,7 @@ #!/bin/sh # Validate timeout basic operation -# Copyright (C) 2008-2014 Free Software Foundation, Inc. +# Copyright (C) 2008-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/misc/tr-case-class.sh b/tests/misc/tr-case-class.sh index 952aae45..07c37607 100755 --- a/tests/misc/tr-case-class.sh +++ b/tests/misc/tr-case-class.sh @@ -1,7 +1,7 @@ #!/bin/sh # Test case conversion classes -# Copyright (C) 2010-2014 Free Software Foundation, Inc. +# Copyright (C) 2010-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -29,11 +29,11 @@ tr '[:lower:][:lower:]' '[:upper:]0-9' > out || fail=1 compare exp out || fail=1 # Validate the alignment of case classes -tr 'A-Z[:lower:]' 'a-y[:upper:]' < /dev/null && fail=1 -tr '[:upper:][:lower:]' 'a-y[:upper:]' < /dev/null && fail=1 -tr 'A-Y[:lower:]' 'a-z[:upper:]' < /dev/null && fail=1 -tr 'A-Z[:lower:]' '[:lower:][:upper:]' < /dev/null && fail=1 -tr 'A-Z[:lower:]' '[:lower:]A-Z' < /dev/null && fail=1 +returns_ 1 tr 'A-Z[:lower:]' 'a-y[:upper:]' </dev/null || fail=1 +returns_ 1 tr '[:upper:][:lower:]' 'a-y[:upper:]' </dev/null || fail=1 +returns_ 1 tr 'A-Y[:lower:]' 'a-z[:upper:]' </dev/null || fail=1 +returns_ 1 tr 'A-Z[:lower:]' '[:lower:][:upper:]' </dev/null || fail=1 +returns_ 1 tr 'A-Z[:lower:]' '[:lower:]A-Z' </dev/null || fail=1 tr '[:upper:][:lower:]' 'a-z[:upper:]' < /dev/null || fail=1 tr '[:upper:][:lower:]' '[:upper:]a-z' < /dev/null || fail=1 diff --git a/tests/misc/tr.pl b/tests/misc/tr.pl index e7018e79..738df3cb 100755 --- a/tests/misc/tr.pl +++ b/tests/misc/tr.pl @@ -1,6 +1,6 @@ #!/usr/bin/perl -# Copyright (C) 2008-2014 Free Software Foundation, Inc. +# Copyright (C) 2008-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/misc/truncate-dangling-symlink.sh b/tests/misc/truncate-dangling-symlink.sh index c5bbc3b6..fe0edfbe 100755 --- a/tests/misc/truncate-dangling-symlink.sh +++ b/tests/misc/truncate-dangling-symlink.sh @@ -1,7 +1,7 @@ #!/bin/sh # Make sure truncate can create a file through a dangling symlink. -# Copyright (C) 2008-2014 Free Software Foundation, Inc. +# Copyright (C) 2008-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/misc/truncate-dir-fail.sh b/tests/misc/truncate-dir-fail.sh index 8ff09179..7787381e 100755 --- a/tests/misc/truncate-dir-fail.sh +++ b/tests/misc/truncate-dir-fail.sh @@ -1,7 +1,7 @@ #!/bin/sh # Make sure truncate fails for a directory. -# Copyright (C) 2008-2014 Free Software Foundation, Inc. +# Copyright (C) 2008-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -20,6 +20,6 @@ print_ver_ truncate # truncate on dir not allowed -truncate -s+0 . && fail=1 +returns_ 1 truncate -s+0 . || fail=1 Exit $fail diff --git a/tests/misc/truncate-fail-diag.sh b/tests/misc/truncate-fail-diag.sh index 9f242d34..e092d3f2 100755 --- a/tests/misc/truncate-fail-diag.sh +++ b/tests/misc/truncate-fail-diag.sh @@ -5,7 +5,7 @@ # open ("missing/", O_CREAT & (O_WRONLY | O_RDWR), ...) -> EISDIR # open ("missing/file", O_CREAT & (O_WRONLY | O_RDWR), ...) -> ENOENT -# Copyright (C) 2008-2014 Free Software Foundation, Inc. +# Copyright (C) 2008-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/misc/truncate-fifo.sh b/tests/misc/truncate-fifo.sh index c2c0bbfc..db2e5647 100755 --- a/tests/misc/truncate-fifo.sh +++ b/tests/misc/truncate-fifo.sh @@ -1,7 +1,7 @@ #!/bin/sh # Make sure truncate works on fifos without hanging -# Copyright (C) 2008-2014 Free Software Foundation, Inc. +# Copyright (C) 2008-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/misc/truncate-no-create-missing.sh b/tests/misc/truncate-no-create-missing.sh index 1cf55330..fbac330e 100755 --- a/tests/misc/truncate-no-create-missing.sh +++ b/tests/misc/truncate-no-create-missing.sh @@ -1,7 +1,7 @@ #!/bin/sh # Ensure that truncate -c no-such-file doesn't fail. -# Copyright (C) 2008-2014 Free Software Foundation, Inc. +# Copyright (C) 2008-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/misc/truncate-overflow.sh b/tests/misc/truncate-overflow.sh index 72ed626b..c690c406 100755 --- a/tests/misc/truncate-overflow.sh +++ b/tests/misc/truncate-overflow.sh @@ -1,7 +1,7 @@ #!/bin/sh # Validate truncate integer overflow -# Copyright (C) 2008-2014 Free Software Foundation, Inc. +# Copyright (C) 2008-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -27,13 +27,13 @@ truncate -s-1 create-zero-len-file || fail=1 echo > non-empty-file # signed overflow -truncate -s$OFF_T_OFLOW file && fail=1 +returns_ 1 truncate -s$OFF_T_OFLOW file || fail=1 # += signed overflow -truncate -s+$OFF_T_MAX non-empty-file && fail=1 +returns_ 1 truncate -s+$OFF_T_MAX non-empty-file || fail=1 # *= signed overflow IO_BLOCK_OFLOW=$(expr $OFF_T_MAX / $(stat -f -c%s .) + 1) -truncate --io-blocks --size=$IO_BLOCK_OFLOW file && fail=1 +returns_ 1 truncate --io-blocks --size=$IO_BLOCK_OFLOW file || fail=1 Exit $fail diff --git a/tests/misc/truncate-owned-by-other.sh b/tests/misc/truncate-owned-by-other.sh index e70badb6..b224864f 100755 --- a/tests/misc/truncate-owned-by-other.sh +++ b/tests/misc/truncate-owned-by-other.sh @@ -1,7 +1,7 @@ #!/bin/sh # Demonstrate that "truncate -s0 writable-but-owned-by-other" works. -# Copyright (C) 2008-2014 Free Software Foundation, Inc. +# Copyright (C) 2008-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -29,7 +29,7 @@ chmod g+w root-owned # Ensure that the current directory is searchable by $NON_ROOT_USERNAME. chmod g+x . -chroot --user=$NON_ROOT_USERNAME / env PATH="$PATH" \ +chroot --skip-chdir --user=$NON_ROOT_USERNAME / env PATH="$PATH" \ truncate -s0 root-owned || fail=1 Exit $fail diff --git a/tests/misc/truncate-parameters.sh b/tests/misc/truncate-parameters.sh index d9e6d64d..d3cf5940 100755 --- a/tests/misc/truncate-parameters.sh +++ b/tests/misc/truncate-parameters.sh @@ -1,7 +1,7 @@ #!/bin/sh # Validate truncate parameter combinations -# Copyright (C) 2008-2014 Free Software Foundation, Inc. +# Copyright (C) 2008-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -21,22 +21,22 @@ print_ver_ truncate # must specify at least 1 file -truncate --size=0 && fail=1 +returns_ 1 truncate --size=0 || fail=1 # must specify size. don't default to 0 -truncate file && fail=1 +returns_ 1 truncate file || fail=1 # mixture of absolute size & reference not allowed -truncate --size=0 --reference=file file && fail=1 +returns_ 1 truncate --size=0 --reference=file file || fail=1 # blocks without size is not valid -truncate --io-blocks --reference=file file && fail=1 +returns_ 1 truncate --io-blocks --reference=file file || fail=1 # must specify valid numbers -truncate --size="invalid" file && fail=1 +returns_ 1 truncate --size="invalid" file || fail=1 # spaces not significant around size -truncate --size="> -1" file && fail=1 +returns_ 1 truncate --size="> -1" file || fail=1 truncate --size=" >1" file || fail=1 #file now 1 truncate --size=" +1" file || fail=1 #file now 2 test $(stat --format %s file) = 2 || fail=1 diff --git a/tests/misc/truncate-relative.sh b/tests/misc/truncate-relative.sh index 3daa073e..97be8cb7 100755 --- a/tests/misc/truncate-relative.sh +++ b/tests/misc/truncate-relative.sh @@ -1,7 +1,7 @@ #!/bin/sh # Validate truncate relative sizes -# Copyright (C) 2008-2014 Free Software Foundation, Inc. +# Copyright (C) 2008-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -21,15 +21,15 @@ print_ver_ truncate # mixture of relative modifiers not allowed -truncate --size="+>0" file && fail=1 +returns_ 1 truncate --size="+>0" file || fail=1 # mixture of relative modifiers not allowed -truncate --size=">+0" file && fail=1 +returns_ 1 truncate --size=">+0" file || fail=1 # division by zero -truncate --size="/0" file && fail=1 +returns_ 1 truncate --size="/0" file || fail=1 # division by zero -truncate --size="%0" file && fail=1 +returns_ 1 truncate --size="%0" file || fail=1 Exit $fail diff --git a/tests/misc/tsort.pl b/tests/misc/tsort.pl index e59af328..4d04866a 100755 --- a/tests/misc/tsort.pl +++ b/tests/misc/tsort.pl @@ -1,7 +1,7 @@ #!/usr/bin/perl # Test "tsort". -# Copyright (C) 1999-2014 Free Software Foundation, Inc. +# Copyright (C) 1999-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/misc/tty-eof.pl b/tests/misc/tty-eof.pl index b4d36de6..c49efc24 100755 --- a/tests/misc/tty-eof.pl +++ b/tests/misc/tty-eof.pl @@ -4,7 +4,7 @@ # Do the same for all programs that can read stdin, # require no arguments and that write to standard output. -# Copyright (C) 2003-2014 Free Software Foundation, Inc. +# Copyright (C) 2003-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/misc/unexpand.pl b/tests/misc/unexpand.pl index 8c5b693b..548bc91c 100755 --- a/tests/misc/unexpand.pl +++ b/tests/misc/unexpand.pl @@ -1,7 +1,7 @@ #!/usr/bin/perl # Test "unexpand". -# Copyright (C) 2000-2014 Free Software Foundation, Inc. +# Copyright (C) 2000-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/misc/uniq-perf.sh b/tests/misc/uniq-perf.sh index 31c40e53..b8bac973 100755 --- a/tests/misc/uniq-perf.sh +++ b/tests/misc/uniq-perf.sh @@ -1,7 +1,7 @@ #!/bin/sh # before coreutils-8.10, seq 100000|uniq -f 10000000000 would run for days -# Copyright (C) 2011-2014 Free Software Foundation, Inc. +# Copyright (C) 2011-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -20,6 +20,6 @@ print_ver_ uniq seq 100 > in || fail=1 -timeout 1 uniq -f 10000000000 in || fail=1 +timeout 10 uniq -f 10000000000 in || fail=1 Exit $fail diff --git a/tests/misc/uniq.pl b/tests/misc/uniq.pl index d07f15f1..5eae7010 100755 --- a/tests/misc/uniq.pl +++ b/tests/misc/uniq.pl @@ -1,7 +1,7 @@ #!/usr/bin/perl # Test uniq. -# Copyright (C) 2008-2014 Free Software Foundation, Inc. +# Copyright (C) 2008-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/misc/wc-files0-from.pl b/tests/misc/wc-files0-from.pl index 4ff10019..cae3fc22 100755 --- a/tests/misc/wc-files0-from.pl +++ b/tests/misc/wc-files0-from.pl @@ -2,7 +2,7 @@ # Exercise wc's --files0-from option. # FIXME: keep this file in sync with tests/du/files0-from. -# Copyright (C) 2006-2014 Free Software Foundation, Inc. +# Copyright (C) 2006-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/misc/wc-files0.sh b/tests/misc/wc-files0.sh index 37fd1ab0..c52b8b0d 100755 --- a/tests/misc/wc-files0.sh +++ b/tests/misc/wc-files0.sh @@ -1,7 +1,7 @@ #!/bin/sh # Show that wc's new --files0-from option works. -# Copyright (C) 2006-2014 Free Software Foundation, Inc. +# Copyright (C) 2006-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/misc/wc-parallel.sh b/tests/misc/wc-parallel.sh index 01005820..19497e04 100755 --- a/tests/misc/wc-parallel.sh +++ b/tests/misc/wc-parallel.sh @@ -2,7 +2,7 @@ # Ensure that wc prints counts atomically # so that concurrent processes don't intersperse their output -# Copyright (C) 2009-2014 Free Software Foundation, Inc. +# Copyright (C) 2009-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -20,13 +20,17 @@ . "${srcdir=.}/tests/init.sh"; path_prepend_ ./src print_ver_ wc +xargs -P2 </dev/null >/dev/null 2>&1 \ + || skip_ 'xargs -P is required' + (mkdir tmp && cd tmp && seq 2000 | xargs touch) # This will output at least 16KiB per process # and start 3 processes, with 2 running concurrently, # which triggers often on Fedora 11 at least. -(find tmp tmp tmp -type f | xargs -n2000 -P2 wc) | +(find tmp tmp tmp -type f | xargs -n2000 -P2 wc 2>err) | sed -n '/0 0 0 /!p' | grep . > /dev/null && fail=1 +compare /dev/null err || fail=1 Exit $fail diff --git a/tests/mv/hard-verbose.sh b/tests/misc/wc-proc.sh index 45491ab0..5b83aa41 100755 --- a/tests/mv/hard-verbose.sh +++ b/tests/misc/wc-proc.sh @@ -1,7 +1,7 @@ #!/bin/sh -# ensure that mv's --verbose options works even in this unusual case +# Test wc on /proc and /sys files. -# Copyright (C) 2006-2014 Free Software Foundation, Inc. +# Copyright 2014-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -17,17 +17,16 @@ # along with this program. If not, see <http://www.gnu.org/licenses/>. . "${srcdir=.}/tests/init.sh"; path_prepend_ ./src -print_ver_ mv +print_ver_ wc -touch x || framework_failure_ -ln x y || framework_failure_ +for file in /proc/version /sys/kernel/profiling; do + if test -r $file; then + cp -f $file copy && + wc -c < copy > exp1 || framework_failure_ - -mv --verbose x y > out || fail=1 -cat <<\EOF > exp || fail=1 -removed 'x' -EOF - -compare exp out || fail=1 + wc -c < $file > out1 || fail=1 + compare exp1 out1 || fail=1 + fi +done Exit $fail diff --git a/tests/misc/wc.pl b/tests/misc/wc.pl index 076ce049..3b8a6a23 100755 --- a/tests/misc/wc.pl +++ b/tests/misc/wc.pl @@ -1,7 +1,7 @@ #!/usr/bin/perl # Basic tests for "wc". -# Copyright (C) 1997-2014 Free Software Foundation, Inc. +# Copyright (C) 1997-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/misc/xattr.sh b/tests/misc/xattr.sh index f208090f..56a40574 100755 --- a/tests/misc/xattr.sh +++ b/tests/misc/xattr.sh @@ -3,7 +3,7 @@ # attributes and install does not preserve extended attributes. # cp -a should preserve xattr, error diagnostics should not be displayed -# Copyright (C) 2009-2014 Free Software Foundation, Inc. +# Copyright (C) 2009-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/misc/xstrtol.pl b/tests/misc/xstrtol.pl index fed8d7d6..2140c1f8 100755 --- a/tests/misc/xstrtol.pl +++ b/tests/misc/xstrtol.pl @@ -1,7 +1,7 @@ #!/usr/bin/perl # exercise xstrtol's diagnostics via pr -# Copyright (C) 2007-2014 Free Software Foundation, Inc. +# Copyright (C) 2007-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/misc/yes.sh b/tests/misc/yes.sh new file mode 100755 index 00000000..79f8b87c --- /dev/null +++ b/tests/misc/yes.sh @@ -0,0 +1,42 @@ +#!/bin/sh +# Validate yes buffer handling + +# Copyright (C) 2015 Free Software Foundation, Inc. + +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. + +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. + +. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src +print_ver_ yes + +# Check various single item sizes, with the most important +# size being BUFSIZ used for the local buffer to yes(1). +# Note a \n is added, so actual sizes required internally +# are 1 more than the size used here. +for size in 1 1999 4095 4096 8191 8192 16383 16384; do + printf "%${size}s\n" '' > out.1 + yes "$(printf %${size}s '')" | head -n2 | uniq > out.2 + compare out.1 out.2 || fail=1 +done + +# Check the many small items case, +# both fitting and overflowing the internal buffer +if env true $(seq 4000); then + for i in 100 4000; do + seq $i | paste -s -d ' ' | sed p > out.1 + yes $(seq $i) | head -n2 > out.2 + compare out.1 out.2 || fail=1 + done +fi + +Exit $fail diff --git a/tests/mkdir/p-1.sh b/tests/mkdir/p-1.sh index e08fd33d..5ed74dce 100755 --- a/tests/mkdir/p-1.sh +++ b/tests/mkdir/p-1.sh @@ -1,7 +1,7 @@ #!/bin/sh # Test "mkdir -p". -# Copyright (C) 1997-2014 Free Software Foundation, Inc. +# Copyright (C) 1997-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/mkdir/p-2.sh b/tests/mkdir/p-2.sh index 874a56af..c13a91fd 100755 --- a/tests/mkdir/p-2.sh +++ b/tests/mkdir/p-2.sh @@ -1,7 +1,7 @@ #!/bin/sh # Just like p-1, but with an absolute path. -# Copyright (C) 1997-2014 Free Software Foundation, Inc. +# Copyright (C) 1997-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/mkdir/p-3.sh b/tests/mkdir/p-3.sh index 6d55adee..199e7e1d 100755 --- a/tests/mkdir/p-3.sh +++ b/tests/mkdir/p-3.sh @@ -3,7 +3,7 @@ # causes immediate failure. Also, ensure that we don't create # subsequent, relative command-line arguments in the wrong place. -# Copyright (C) 2005-2014 Free Software Foundation, Inc. +# Copyright (C) 2005-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -27,7 +27,8 @@ mkdir no-acce2s || framework_failure_ mkdir -p no-acce3s/d || framework_failure_ p=$(pwd) -(cd no-access && chmod 0 . && mkdir -p "$p/a/b" u/v) 2> /dev/null && fail=1 +(cd no-access && chmod 0 . && mkdir -p "$p/a/b" u/v) 2> /dev/null +test $? -eq 1 || fail=1 test -d "$p/a/b" || fail=1 # Same as above, but with a following *absolute* name, it should succeed diff --git a/tests/mkdir/p-acl.sh b/tests/mkdir/p-acl.sh index dd4473a9..a4a29727 100755 --- a/tests/mkdir/p-acl.sh +++ b/tests/mkdir/p-acl.sh @@ -1,7 +1,7 @@ #!/bin/sh # Test "mkdir -p" with default ACLs. -# Copyright (C) 1997-2014 Free Software Foundation, Inc. +# Copyright (C) 1997-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/mkdir/p-slashdot.sh b/tests/mkdir/p-slashdot.sh index bbca9ad7..e318547e 100755 --- a/tests/mkdir/p-slashdot.sh +++ b/tests/mkdir/p-slashdot.sh @@ -1,7 +1,7 @@ #!/bin/sh # Ensure that mkdir -p works with arguments specified with a trailing "/.". -# Copyright (C) 2005-2014 Free Software Foundation, Inc. +# Copyright (C) 2005-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/mkdir/p-thru-slink.sh b/tests/mkdir/p-thru-slink.sh index a884a386..ffa4450b 100755 --- a/tests/mkdir/p-thru-slink.sh +++ b/tests/mkdir/p-thru-slink.sh @@ -1,7 +1,7 @@ #!/bin/sh # Ensure that mkdir -p foo/bar works when foo is a symbolic link to a directory -# Copyright (C) 2005-2014 Free Software Foundation, Inc. +# Copyright (C) 2005-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/mkdir/p-v.sh b/tests/mkdir/p-v.sh index a6a51cbc..963038f4 100755 --- a/tests/mkdir/p-v.sh +++ b/tests/mkdir/p-v.sh @@ -1,7 +1,7 @@ #!/bin/sh # Test mkdir -pv. -# Copyright (C) 2006-2014 Free Software Foundation, Inc. +# Copyright (C) 2006-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/mkdir/parents.sh b/tests/mkdir/parents.sh index 786f08f9..ebdb5271 100755 --- a/tests/mkdir/parents.sh +++ b/tests/mkdir/parents.sh @@ -1,7 +1,7 @@ #!/bin/sh # make sure mkdir's -p options works properly -# Copyright (C) 2000-2014 Free Software Foundation, Inc. +# Copyright (C) 2000-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -26,7 +26,7 @@ mkdir -m 700 e-dir || framework_failure_ # Make sure 'mkdir -p existing-dir' succeeds # and that 'mkdir existing-dir' fails. mkdir -p e-dir || fail=1 -mkdir e-dir > /dev/null 2>&1 && fail=1 +returns_ 1 mkdir e-dir > /dev/null 2>&1 || fail=1 # Create an existing directory. umask 077 diff --git a/tests/mkdir/perm.sh b/tests/mkdir/perm.sh index bf0f6a8e..ff0a57dc 100755 --- a/tests/mkdir/perm.sh +++ b/tests/mkdir/perm.sh @@ -2,7 +2,7 @@ # Verify that mkdir's '-m MODE' option works properly # with various umask settings. -# Copyright (C) 2000-2014 Free Software Foundation, Inc. +# Copyright (C) 2000-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -59,7 +59,7 @@ for p in empty -p; do # If we're not using -p, then create the parent manually, # and adjust expectations accordingly. - test x$p = x && \ + test x$p = x && { mkdir -m =,u=rwx parent || fail=1 parent_perms=drwx------ diff --git a/tests/mkdir/restorecon.sh b/tests/mkdir/restorecon.sh index 14a8b899..7d6a671b 100755 --- a/tests/mkdir/restorecon.sh +++ b/tests/mkdir/restorecon.sh @@ -1,7 +1,7 @@ #!/bin/sh # test mkdir, mknod, mkfifo -Z -# Copyright (C) 2013-2014 Free Software Foundation, Inc. +# Copyright (C) 2013-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -17,7 +17,7 @@ # along with this program. If not, see <http://www.gnu.org/licenses/>. . "${srcdir=.}/tests/init.sh"; path_prepend_ ./src -print_ver_ mkdir +print_ver_ mkdir mknod mkfifo require_selinux_ @@ -38,6 +38,7 @@ if restorecon restored 2>/dev/null; then mkdir -Z single || fail=1 # Run these as separate processes in case global context # set for an arg, impacts on another arg + # TODO: Have the defaultcon() vary over these directories for dir in single_p single_p/existing multi/ple; do mkdir -Zp "$dir" || fail=1 done diff --git a/tests/mkdir/selinux.sh b/tests/mkdir/selinux.sh index 983ceb57..4d3cbce7 100755 --- a/tests/mkdir/selinux.sh +++ b/tests/mkdir/selinux.sh @@ -1,7 +1,7 @@ #!/bin/sh # ensure that an invalid context doesn't cause a segfault -# Copyright (C) 2008-2014 Free Software Foundation, Inc. +# Copyright (C) 2008-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/mkdir/smack-no-root.sh b/tests/mkdir/smack-no-root.sh index 527940b3..fac16ede 100755 --- a/tests/mkdir/smack-no-root.sh +++ b/tests/mkdir/smack-no-root.sh @@ -3,7 +3,7 @@ # Derived from tests/mkdir/selinux.sh. # Ensure that an unsettable SMACK label doesn't cause a segfault. -# Copyright (C) 2014 Free Software Foundation, Inc. +# Copyright (C) 2014-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/mkdir/smack-root.sh b/tests/mkdir/smack-root.sh index 8d7ec9b7..772eb60a 100755 --- a/tests/mkdir/smack-root.sh +++ b/tests/mkdir/smack-root.sh @@ -3,7 +3,7 @@ # Derived from tests/mkdir/selinux.sh. # Ensure that SMACK label gets set. -# Copyright (C) 2014 Free Software Foundation, Inc. +# Copyright (C) 2014-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/mkdir/special-1.sh b/tests/mkdir/special-1.sh index 8c65a757..a6ba642f 100755 --- a/tests/mkdir/special-1.sh +++ b/tests/mkdir/special-1.sh @@ -1,7 +1,7 @@ #!/bin/sh # verify that mkdir honors special bits in MODE -# Copyright (C) 2000-2014 Free Software Foundation, Inc. +# Copyright (C) 2000-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -36,7 +36,7 @@ rmdir $tmp || fail=1 tmp2=$tmp/sub # This should fail. -mkdir -m$set_mode_string $tmp2 2> /dev/null && fail=1 +returns_ 1 mkdir -m$set_mode_string $tmp2 2> /dev/null || fail=1 # Now test the --parents option. mkdir --parents -m$set_mode_string $tmp2 || fail=1 diff --git a/tests/mkdir/t-slash.sh b/tests/mkdir/t-slash.sh index d9e8d3eb..e16db501 100755 --- a/tests/mkdir/t-slash.sh +++ b/tests/mkdir/t-slash.sh @@ -2,7 +2,7 @@ # Ensure that mkdir works with arguments specified with and without # a trailing slash. -# Copyright (C) 2000-2014 Free Software Foundation, Inc. +# Copyright (C) 2000-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/mkdir/writable-under-readonly.sh b/tests/mkdir/writable-under-readonly.sh index e7c4a9ca..c2f81c5a 100755 --- a/tests/mkdir/writable-under-readonly.sh +++ b/tests/mkdir/writable-under-readonly.sh @@ -1,7 +1,7 @@ #!/bin/sh # FIXME: convert this to a root-only test. -# Copyright (C) 2005-2014 Free Software Foundation, Inc. +# Copyright (C) 2005-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/mv/acl.sh b/tests/mv/acl.sh index f681f5d0..b09125c5 100755 --- a/tests/mv/acl.sh +++ b/tests/mv/acl.sh @@ -2,7 +2,7 @@ # move files/directories across file system boundaries # and make sure acls are preserved -# Copyright (C) 2005-2014 Free Software Foundation, Inc. +# Copyright (C) 2005-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/mv/atomic.sh b/tests/mv/atomic.sh index a026bd5b..6d8c5a92 100755 --- a/tests/mv/atomic.sh +++ b/tests/mv/atomic.sh @@ -1,7 +1,7 @@ #!/bin/sh # ensure that mv doesn't first unlink its destination in one particular case -# Copyright (C) 2006-2014 Free Software Foundation, Inc. +# Copyright (C) 2006-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/mv/atomic2.sh b/tests/mv/atomic2.sh index 92a8e436..6787dd34 100755 --- a/tests/mv/atomic2.sh +++ b/tests/mv/atomic2.sh @@ -1,7 +1,7 @@ #!/bin/sh # ensure that mv doesn't first unlink a multi-hard-linked destination -# Copyright (C) 2008-2014 Free Software Foundation, Inc. +# Copyright (C) 2008-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/mv/backup-dir.sh b/tests/mv/backup-dir.sh index 682173d4..f547a63e 100755 --- a/tests/mv/backup-dir.sh +++ b/tests/mv/backup-dir.sh @@ -1,7 +1,7 @@ #!/bin/sh # Ensure "mv --verbose --backup" works the same for dirs and non-dirs. -# Copyright (C) 2006-2014 Free Software Foundation, Inc. +# Copyright (C) 2006-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/mv/backup-is-src.sh b/tests/mv/backup-is-src.sh index 4208d91e..acfe5684 100755 --- a/tests/mv/backup-is-src.sh +++ b/tests/mv/backup-is-src.sh @@ -1,7 +1,7 @@ #!/bin/sh # Force mv to use the copying code. -# Copyright (C) 1998-2014 Free Software Foundation, Inc. +# Copyright (C) 1998-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/mv/childproof.sh b/tests/mv/childproof.sh index c212b83d..cc879ff1 100755 --- a/tests/mv/childproof.sh +++ b/tests/mv/childproof.sh @@ -3,7 +3,7 @@ # With fileutils-4.1 and earlier, this test would fail for cp and mv. # With coreutils-6.9 and earlier, this test would fail for ln. -# Copyright (C) 2001-2014 Free Software Foundation, Inc. +# Copyright (C) 2001-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -28,7 +28,7 @@ echo a > a/f || framework_failure_ echo b > b/f || framework_failure_ -cp a/f b/f c 2> /dev/null && fail=1 +returns_ 1 cp a/f b/f c 2> /dev/null || fail=1 test -f a/f || fail=1 test -f b/f || fail=1 test -f c/f || fail=1 @@ -43,7 +43,7 @@ test -f c/f || fail=1 test -f c/f.~1~ || fail=1 rm -f c/f* -mv a/f b/f c 2> /dev/null && fail=1 +returns_ 1 mv a/f b/f c 2> /dev/null || fail=1 test -f a/f && fail=1 test -f b/f || fail=1 test -f c/f || fail=1 @@ -62,7 +62,7 @@ test -f c/f || fail=1 test -f c/g || fail=1 touch a/f b/f b/g -mv a/f b/f b/g c 2> /dev/null && fail=1 +returns_ 1 mv a/f b/f b/g c 2> /dev/null || fail=1 test -f a/f && fail=1 # a/f should have been moved test -f b/f || fail=1 # b/f should remain test -f b/g && fail=1 # b/g should have been moved @@ -74,7 +74,7 @@ test -f c/g || fail=1 rm -f a/f b/f c/f echo a > a/f || fail=1 echo b > b/f || fail=1 -ln -f a/f b/f c 2> /dev/null && fail=1 +returns_ 1 ln -f a/f b/f c 2> /dev/null || fail=1 # a/f and c/f must be linked test $(stat --format %i a/f) = $(stat --format %i c/f) || fail=1 # b/f and c/f must not be linked diff --git a/tests/mv/diag.sh b/tests/mv/diag.sh index b38fb18c..62bc2da5 100755 --- a/tests/mv/diag.sh +++ b/tests/mv/diag.sh @@ -1,7 +1,7 @@ #!/bin/sh # make sure we get proper diagnostics: e.g., with --target-dir=d but no args -# Copyright (C) 2000-2014 Free Software Foundation, Inc. +# Copyright (C) 2000-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/mv/dir-file.sh b/tests/mv/dir-file.sh index bb32f356..7b798ed6 100755 --- a/tests/mv/dir-file.sh +++ b/tests/mv/dir-file.sh @@ -1,7 +1,7 @@ #!/bin/sh # mv must fail when src and dest are mismatched directory/non-directory. -# Copyright (C) 2000-2014 Free Software Foundation, Inc. +# Copyright (C) 2000-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -24,7 +24,7 @@ mkdir -p dir/file || framework_failure_ # These should both fail, but until fileutils-4.0q only the second one did. -mv dir file > /dev/null 2>&1 && fail=1 -mv file dir > /dev/null 2>&1 && fail=1 +returns_ 1 mv dir file > /dev/null 2>&1 || fail=1 +returns_ 1 mv file dir > /dev/null 2>&1 || fail=1 Exit $fail diff --git a/tests/mv/dir2dir.sh b/tests/mv/dir2dir.sh index 7a8f7fd3..6f9c3ce7 100755 --- a/tests/mv/dir2dir.sh +++ b/tests/mv/dir2dir.sh @@ -2,7 +2,7 @@ # Ensure that mv prints the right diagnostic for a dir->dir move # where the destination directory is not empty. -# Copyright (C) 2006-2014 Free Software Foundation, Inc. +# Copyright (C) 2006-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/mv/dup-source.sh b/tests/mv/dup-source.sh index d3b56c5e..c160c0de 100755 --- a/tests/mv/dup-source.sh +++ b/tests/mv/dup-source.sh @@ -4,7 +4,7 @@ # made this fail: cp a a d/ # Ensure that mv fails with a similar command. -# Copyright (C) 2001-2014 Free Software Foundation, Inc. +# Copyright (C) 2001-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/mv/force.sh b/tests/mv/force.sh index 05adabc5..cd4e7948 100755 --- a/tests/mv/force.sh +++ b/tests/mv/force.sh @@ -1,7 +1,7 @@ #!/bin/sh # move a file onto itself -# Copyright (C) 1999-2014 Free Software Foundation, Inc. +# Copyright (C) 1999-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -25,18 +25,19 @@ ff2=mvforce2 echo force-contents > $ff || framework_failure_ ln $ff $ff2 || framework_failure_ -# This mv command should exit nonzero. -mv $ff $ff > out 2>&1 && fail=1 +# mv should fail for the same name, or separate hardlinks as in +# both cases rename() will do nothing and return success. +# One could unlink(src) in the hardlink case, but that would +# introduce races with overlapping mv instances removing both hardlinks. -cat > exp <<EOF -mv: '$ff' and '$ff' are the same file -EOF +for dest in $ff $ff2; do + # This mv command should exit nonzero. + mv $ff $dest > out 2>&1 && fail=1 -compare exp out || fail=1 -test $(cat $ff) = force-contents || fail=1 + printf "mv: '$ff' and '$dest' are the same file\n" > exp + compare exp out || fail=1 -# This should succeed, even though the source and destination -# device and inodes are the same. -mv $ff $ff2 || fail=1 + test $(cat $ff) = force-contents || fail=1 +done Exit $fail diff --git a/tests/mv/hard-2.sh b/tests/mv/hard-2.sh index 0b2880a2..1276c9eb 100755 --- a/tests/mv/hard-2.sh +++ b/tests/mv/hard-2.sh @@ -2,7 +2,7 @@ # Ensure that moving hard-linked arguments onto existing destinations works. # Likewise when using cp --preserve=link. -# Copyright (C) 2003-2014 Free Software Foundation, Inc. +# Copyright (C) 2003-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/mv/hard-3.sh b/tests/mv/hard-3.sh index a3acd1a6..380aa4ca 100755 --- a/tests/mv/hard-3.sh +++ b/tests/mv/hard-3.sh @@ -2,7 +2,7 @@ # Ensure that using 'cp --preserve=link' to copy hard-linked arguments # onto existing destinations works, even when one of the link operations fails. -# Copyright (C) 2003-2014 Free Software Foundation, Inc. +# Copyright (C) 2003-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/mv/hard-4.sh b/tests/mv/hard-4.sh index d518e3bc..c751c33d 100755 --- a/tests/mv/hard-4.sh +++ b/tests/mv/hard-4.sh @@ -1,7 +1,7 @@ #!/bin/sh -# ensure that mv removes a in this case: touch a; ln a b; mv a b +# ensure that mv maintains a in this case: touch a; ln a b; mv a b -# Copyright (C) 2003-2014 Free Software Foundation, Inc. +# Copyright (C) 2003-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -21,15 +21,18 @@ print_ver_ mv touch a || framework_failure_ ln a b || framework_failure_ +# Between coreutils-5.0 and coreutils-8.24, 'a' would be removed. +# Before coreutils-5.0.1 the issue would not have been diagnosed. +# We don't emulate the rename(a,b) with unlink(a) as that would +# introduce races with overlapping mv instances removing both links. +mv a b 2>err && fail=1 +printf "mv: 'a' and 'b' are the same file\n" > exp +compare exp err || fail=1 -mv a b || fail=1 - -# In coreutils-5.0 and earlier, a would not be removed. -test -r a && fail=1 +test -r a || fail=1 test -r b || fail=1 -# Make sure it works also with --backup. -ln b a +# Make sure it works with --backup. mv --backup=simple a b || fail=1 test -r a && fail=1 test -r b || fail=1 diff --git a/tests/mv/hard-link-1.sh b/tests/mv/hard-link-1.sh index fdf355a3..392ca2ef 100755 --- a/tests/mv/hard-link-1.sh +++ b/tests/mv/hard-link-1.sh @@ -2,7 +2,7 @@ # move a directory containing hard-linked files and # make sure the links are preserved -# Copyright (C) 1998-2014 Free Software Foundation, Inc. +# Copyright (C) 1998-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/mv/hardlink-case.sh b/tests/mv/hardlink-case.sh new file mode 100755 index 00000000..3e51c38a --- /dev/null +++ b/tests/mv/hardlink-case.sh @@ -0,0 +1,37 @@ +#!/bin/sh +# Ensure multi-hardlinked files are not lost on case insensitive file systems + +# Copyright (C) 2014-2015 Free Software Foundation, Inc. + +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. + +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. + +. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src +print_ver_ mv +require_root_ + +cwd=$(pwd) +cleanup_() { cd /; umount "$cwd/mnt"; } + +truncate -s100M hfs.img || framework_failure_ +mkfs -t hfsplus hfs.img || skip_ 'failed to create hfs file system' +mkdir mnt || framework_failure_ +mount hfs.img mnt || skip_ 'failed to mount hfs file system' + +cd mnt +touch foo +ln foo whatever +returns_ 1 mv foo Foo || fail=1 +test -r foo || fail=1 + +Exit $fail diff --git a/tests/mv/i-1.pl b/tests/mv/i-1.pl index 84902ee2..714783c8 100755 --- a/tests/mv/i-1.pl +++ b/tests/mv/i-1.pl @@ -1,7 +1,7 @@ #!/usr/bin/perl # Make sure a 'n' reply to 'mv -i...' aborts the move operation. -# Copyright (C) 2001-2014 Free Software Foundation, Inc. +# Copyright (C) 2001-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/mv/i-2.sh b/tests/mv/i-2.sh index 4202b5c5..39cdafb2 100755 --- a/tests/mv/i-2.sh +++ b/tests/mv/i-2.sh @@ -2,7 +2,7 @@ # Test both cp and mv for their behavior with -if and -fi # The standards (POSIX and SuS) dictate annoyingly inconsistent behavior. -# Copyright (C) 2000-2014 Free Software Foundation, Inc. +# Copyright (C) 2000-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/mv/i-3.sh b/tests/mv/i-3.sh index 8c58d5d3..5dba1fe4 100755 --- a/tests/mv/i-3.sh +++ b/tests/mv/i-3.sh @@ -2,7 +2,7 @@ # Make sure that 'mv file unwritable-file' prompts the user # and that 'mv -f file unwritable-file' doesn't. -# Copyright (C) 2001-2014 Free Software Foundation, Inc. +# Copyright (C) 2001-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -23,7 +23,7 @@ require_controlling_input_terminal_ skip_if_root_ trap '' TTIN # Ignore SIGTTIN -test "$(uname -s)" = FreeBSD && skip_ "known spurious failure on FreeBSD" +uname -s | grep 'BSD$' && skip_ 'known spurious failure on *BSD' touch f g h i || framework_failure_ chmod 0 g i || framework_failure_ @@ -39,6 +39,9 @@ tty=$(readlink -f /dev/stdin) test -r "$tty" 2>&1 \ || skip_ '/dev/stdin is not readable' +# Terminate any background processes +cleanup_() { kill $pid 2>/dev/null && wait $pid; } + mv f g < $tty > out 2>&1 & pid=$! # Test for the expected prompt; sleep upon non-match. @@ -54,7 +57,7 @@ check_overwrite_prompt() # Wait for up to 12.7 seconds for the expected prompt. retry_delay_ check_overwrite_prompt .1 7 || { fail=1; cat out; } -kill $pid +cleanup_ mv -f h i > out 2>&1 || fail=1 test -f i || fail=1 diff --git a/tests/mv/i-4.sh b/tests/mv/i-4.sh index b366bc46..ff3513a8 100755 --- a/tests/mv/i-4.sh +++ b/tests/mv/i-4.sh @@ -1,7 +1,7 @@ #!/bin/sh # make sure 'mv -i a b' does its job with a positive response -# Copyright (C) 2001-2014 Free Software Foundation, Inc. +# Copyright (C) 2001-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -23,6 +23,7 @@ for i in a b; do echo $i > $i || framework_failure_ done echo y > y || framework_failure_ +echo n > n || framework_failure_ mv -i a b < y >/dev/null 2>&1 || fail=1 @@ -32,18 +33,15 @@ case "$(cat b)" in *) fail=1 ;; esac -# Ensure that mv -i a b works properly with 'n' and 'y' -# responses, even when a and b are hard links to the same file. -# This 'n' test would fail (no prompt) for coreutils-5.0.1 through 5.3.0. -echo n > n +# Ensure that mv -i a b works properly with 'n' and 'y' responses, +# when a and b are hard links to the same file. rm -f a b echo a > a ln a b -mv -i a b < n >/dev/null 2>&1 || fail=1 +mv -i a b < y 2>err && fail=1 test -r a || fail=1 test -r b || fail=1 -mv -i a b < y >/dev/null 2>&1 || fail=1 -test -r a && fail=1 -test -r b || fail=1 +printf "mv: 'a' and 'b' are the same file\n" > exp +compare exp err || fail=1 Exit $fail diff --git a/tests/mv/i-5.sh b/tests/mv/i-5.sh index c69f1784..85931122 100755 --- a/tests/mv/i-5.sh +++ b/tests/mv/i-5.sh @@ -1,7 +1,7 @@ #!/bin/sh # Make sure 'mv -i dir file' prompts before failing. -# Copyright (C) 2006-2014 Free Software Foundation, Inc. +# Copyright (C) 2006-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/mv/i-link-no.sh b/tests/mv/i-link-no.sh index 67a8ff9c..59bee0b1 100755 --- a/tests/mv/i-link-no.sh +++ b/tests/mv/i-link-no.sh @@ -1,7 +1,7 @@ #!/bin/sh # Show that mv doesn't preserve links to files the user has declined to move. -# Copyright (C) 2002-2014 Free Software Foundation, Inc. +# Copyright (C) 2002-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/mv/into-self-2.sh b/tests/mv/into-self-2.sh index 4109d9e6..645ed41a 100755 --- a/tests/mv/into-self-2.sh +++ b/tests/mv/into-self-2.sh @@ -3,7 +3,7 @@ # Consider the case where SRC and DEST are on different # partitions and DEST is a symlink to SRC. -# Copyright (C) 1998-2014 Free Software Foundation, Inc. +# Copyright (C) 1998-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/mv/into-self-3.sh b/tests/mv/into-self-3.sh index 52069b88..e7a1ee76 100755 --- a/tests/mv/into-self-3.sh +++ b/tests/mv/into-self-3.sh @@ -1,7 +1,7 @@ #!/bin/sh # move a directory into itself, with a twist -# Copyright (C) 1998-2014 Free Software Foundation, Inc. +# Copyright (C) 1998-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/mv/into-self-4.sh b/tests/mv/into-self-4.sh index ac78f90b..2ae0468f 100755 --- a/tests/mv/into-self-4.sh +++ b/tests/mv/into-self-4.sh @@ -2,7 +2,7 @@ # confirm that 'mv symlink symlink' doesn't remove symlink # Based on an example from David Luyer. -# Copyright (C) 2001-2014 Free Software Foundation, Inc. +# Copyright (C) 2001-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -25,7 +25,7 @@ ln -s file s || framework_failure_ # This must fail. -mv s s 2> /dev/null && fail=1 +returns_ 1 mv s s 2> /dev/null || fail=1 # But the symlink, s, must not be removed. # Before 4.0.36, 's' would have been removed. diff --git a/tests/mv/into-self.sh b/tests/mv/into-self.sh index 76aefa26..0a08154b 100755 --- a/tests/mv/into-self.sh +++ b/tests/mv/into-self.sh @@ -1,7 +1,7 @@ #! /bin/sh # Demonstrate how mv fails when it tries to move a directory into itself. -# Copyright (C) 1998-2014 Free Software Foundation, Inc. +# Copyright (C) 1998-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/mv/leak-fd.sh b/tests/mv/leak-fd.sh index 6b81f5cb..b36da8d3 100755 --- a/tests/mv/leak-fd.sh +++ b/tests/mv/leak-fd.sh @@ -2,7 +2,7 @@ # Exercise mv's file-descriptor-leak bug, reported against coreutils-5.2.1 # and fixed (properly) on 2004-10-21. -# Copyright (C) 2004-2014 Free Software Foundation, Inc. +# Copyright (C) 2004-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/mv/mv-n.sh b/tests/mv/mv-n.sh index 30ba35bb..8c3fedb8 100755 --- a/tests/mv/mv-n.sh +++ b/tests/mv/mv-n.sh @@ -1,7 +1,7 @@ #!/bin/sh # Test whether mv -n works as documented (not overwrite target). -# Copyright (C) 2006-2014 Free Software Foundation, Inc. +# Copyright (C) 2006-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -52,6 +52,6 @@ compare out5 out_empty || fail=1 # options --backup and --no-clobber are mutually exclusive touch a || framework_failure_ -mv -bn a b 2>/dev/null && fail=1 +returns_ 1 mv -bn a b 2>/dev/null || fail=1 Exit $fail diff --git a/tests/mv/mv-special-1.sh b/tests/mv/mv-special-1.sh index 34449150..0c649f03 100755 --- a/tests/mv/mv-special-1.sh +++ b/tests/mv/mv-special-1.sh @@ -1,7 +1,7 @@ #! /bin/sh # Test "mv" with special files. -# Copyright (C) 1998-2014 Free Software Foundation, Inc. +# Copyright (C) 1998-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/mv/no-target-dir.sh b/tests/mv/no-target-dir.sh index ac65ff7f..d7bca59b 100755 --- a/tests/mv/no-target-dir.sh +++ b/tests/mv/no-target-dir.sh @@ -2,7 +2,7 @@ # ensure that --no-target-directory (-T) works when the destination is # an empty directory. -# Copyright (C) 2006-2014 Free Software Foundation, Inc. +# Copyright (C) 2006-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -20,6 +20,8 @@ . "${srcdir=.}/tests/init.sh"; path_prepend_ ./src print_ver_ mv +LS_FAILURE=2 + mkdir -p d/sub empty src d2/sub e2 || framework_failure_ touch f || framework_failure_ @@ -35,15 +37,15 @@ mv a b || mv -fT d empty || fail=1 # Ensure that the source, d, is gone. -ls -d d > /dev/null 2>&1 && fail=1 +returns_ $LS_FAILURE ls -d d > /dev/null 2>&1 || fail=1 # Ensure that the dest dir now has a subdirectory. test -d empty/sub || fail=1 # rename must fail, since the dest is non-empty. -mv -fT src d2 2> /dev/null && fail=1 +returns_ 1 mv -fT src d2 2> /dev/null || fail=1 # rename must fail, since the src is not a directory. -mv -fT f e2 2> /dev/null && fail=1 +returns_ 1 mv -fT f e2 2> /dev/null || fail=1 Exit $fail diff --git a/tests/mv/part-fail.sh b/tests/mv/part-fail.sh index 71ee30c0..164a6393 100755 --- a/tests/mv/part-fail.sh +++ b/tests/mv/part-fail.sh @@ -4,7 +4,7 @@ # This is a bit fragile since it relies on the string used # for EPERM: 'permission denied'. -# Copyright (C) 2002-2014 Free Software Foundation, Inc. +# Copyright (C) 2002-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/mv/part-hardlink.sh b/tests/mv/part-hardlink.sh index 8eacaabc..c4a5830f 100755 --- a/tests/mv/part-hardlink.sh +++ b/tests/mv/part-hardlink.sh @@ -4,7 +4,7 @@ # For additional constraints, see the comment in copy.c. # Before coreutils-5.2.1, this test would fail. -# Copyright (C) 2004-2014 Free Software Foundation, Inc. +# Copyright (C) 2004-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/mv/part-rename.sh b/tests/mv/part-rename.sh index ba68f6e6..b84f6886 100755 --- a/tests/mv/part-rename.sh +++ b/tests/mv/part-rename.sh @@ -1,7 +1,7 @@ #!/bin/sh # Test various cases for moving directories across file systems -# Copyright (C) 2000-2014 Free Software Foundation, Inc. +# Copyright (C) 2000-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -31,13 +31,13 @@ mv foo/ "$other_partition_tmpdir/bar" || fail=1 # Moving a non directory from source shouldn't replace empty dir in dest touch bar || framework_failure_ -mv bar "$other_partition_tmpdir/" && fail=1 +returns_ 1 mv bar "$other_partition_tmpdir/" || fail=1 # Moving a directory from source shouldn't replace non directory in dest mkdir bar2 touch "$other_partition_tmpdir/bar2" -mv bar2 "$other_partition_tmpdir/" && fail=1 +returns_ 1 mv bar2 "$other_partition_tmpdir/" || fail=1 # As per POSIX moving directory from source should replace empty dir in dest @@ -51,7 +51,7 @@ test -e "$other_partition_tmpdir/bar3/file" || fail=1 # As per POSIX moving directory from source shouldn't update dir in dest mkdir bar3 touch bar3/file2 -mv bar3 "$other_partition_tmpdir/" && fail=1 +returns_ 1 mv bar3 "$other_partition_tmpdir/" || fail=1 test -e "$other_partition_tmpdir/bar3/file2" && fail=1 Exit $fail diff --git a/tests/mv/part-symlink.sh b/tests/mv/part-symlink.sh index 9604d873..16856259 100755 --- a/tests/mv/part-symlink.sh +++ b/tests/mv/part-symlink.sh @@ -2,7 +2,7 @@ # make sure cp and mv can handle many combinations of local and # other-partition regular/symlink'd files. -# Copyright (C) 2000-2014 Free Software Foundation, Inc. +# Copyright (C) 2000-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/mv/partition-perm.sh b/tests/mv/partition-perm.sh index 713988f7..18c1a77f 100755 --- a/tests/mv/partition-perm.sh +++ b/tests/mv/partition-perm.sh @@ -1,7 +1,7 @@ #!/bin/sh # Make sure permissions are preserved when moving from one partition to another. -# Copyright (C) 1999-2014 Free Software Foundation, Inc. +# Copyright (C) 1999-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/mv/perm-1.sh b/tests/mv/perm-1.sh index 2826c61f..3632d8d4 100755 --- a/tests/mv/perm-1.sh +++ b/tests/mv/perm-1.sh @@ -2,7 +2,7 @@ # ensure that mv gives one diagnostic, not two, when failing # due to lack of permissions -# Copyright (C) 2002-2014 Free Software Foundation, Inc. +# Copyright (C) 2002-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/mv/sticky-to-xpart.sh b/tests/mv/sticky-to-xpart.sh index e0c99e94..602562cc 100755 --- a/tests/mv/sticky-to-xpart.sh +++ b/tests/mv/sticky-to-xpart.sh @@ -4,7 +4,7 @@ # mv: cannot remove 'x': Operation not permitted # Affects coreutils-6.0-6.9. -# Copyright (C) 2007-2014 Free Software Foundation, Inc. +# Copyright (C) 2007-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -42,7 +42,8 @@ chmod go+x . || framework_failure_ # Ensure that $NON_ROOT_USERNAME can access the required version of mv. version=$( - chroot --user=$NON_ROOT_USERNAME / env PATH="$PATH" mv --version | + chroot --skip-chdir --user=$NON_ROOT_USERNAME / env PATH="$PATH" \ + mv --version | sed -n '1s/.* //p' ) case $version in @@ -50,7 +51,7 @@ case $version in *) skip_ "cannot access just-built mv as user $NON_ROOT_USERNAME";; esac -chroot --user=$NON_ROOT_USERNAME / env PATH="$PATH" \ +chroot --skip-chdir --user=$NON_ROOT_USERNAME / env PATH="$PATH" \ mv t/root-owned "$other_partition_tmpdir" 2> out-t && fail=1 # On some systems, we get 'Not owner'. Convert it. diff --git a/tests/mv/symlink-onto-hardlink-to-self.sh b/tests/mv/symlink-onto-hardlink-to-self.sh index f3e8ff98..295844c0 100755 --- a/tests/mv/symlink-onto-hardlink-to-self.sh +++ b/tests/mv/symlink-onto-hardlink-to-self.sh @@ -1,10 +1,10 @@ #!/bin/sh -# Demonstrate that when moving a symlink onto a hardlink-to-that-symlink, the -# source symlink is removed. Depending on your kernel (e.g., Linux, Solaris, +# Demonstrate that when moving a symlink onto a hardlink-to-that-symlink, +# an error is presented. Depending on your kernel (e.g., Linux, Solaris, # but not NetBSD), prior to coreutils-8.16, the mv would successfully perform # a no-op. I.e., surprisingly, mv s1 s2 would succeed, yet fail to remove s1. -# Copyright (C) 2012-2014 Free Software Foundation, Inc. +# Copyright (C) 2012-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -26,27 +26,34 @@ print_ver_ mv touch f || framework_failure_ ln -s f s2 || framework_failure_ -for opt in '' --backup; do +# Attempt to create a hard link to that symlink. +# On some systems, it's not possible: they create a hard link to the referent. +ln s2 s1 || framework_failure_ - # Attempt to create a hard link to that symlink. - # On some systems, it's not possible: they create a hard link to the referent. - ln s2 s1 || framework_failure_ +# If s1 is not a symlink, skip this test. +test -h s1 \ + || skip_ your kernel or file system cannot create a hard link to a symlink - # If s1 is not a symlink, skip this test. - test -h s1 \ - || skip_ your kernel or file system cannot create a hard link to a symlink +for opt in '' --backup; do - mv $opt s1 s2 > out 2>&1 || fail=1 - compare /dev/null out || fail=1 + if test "$opt" = --backup; then + mv $opt s1 s2 > out 2>&1 || fail=1 + compare /dev/null out || fail=1 - # Ensure that s1 is gone. - test -e s1 && fail=1 + # Ensure that s1 is gone. + test -e s1 && fail=1 - if test "$opt" = --backup; then # With --backup, ensure that the backup file was created. ref=$(readlink s2~) || fail=1 test "$ref" = f || fail=1 else + echo "mv: 's1' and 's2' are the same file" > exp + mv $opt s1 s2 2>err && fail=1 + compare exp err || fail=1 + + # Ensure that s1 is still present. + test -e s1 || fail=1 + # Without --backup, ensure there is no backup file. test -e s2~ && fail=1 fi diff --git a/tests/mv/symlink-onto-hardlink.sh b/tests/mv/symlink-onto-hardlink.sh index 5b4dead0..9bd370b1 100755 --- a/tests/mv/symlink-onto-hardlink.sh +++ b/tests/mv/symlink-onto-hardlink.sh @@ -1,7 +1,7 @@ #!/bin/sh # Ensure that mv works with a few symlink-onto-hard-link cases. -# Copyright (C) 2012-2014 Free Software Foundation, Inc. +# Copyright (C) 2012-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/mv/to-symlink.sh b/tests/mv/to-symlink.sh index 70ca6179..8b8091a9 100755 --- a/tests/mv/to-symlink.sh +++ b/tests/mv/to-symlink.sh @@ -2,7 +2,7 @@ # Make sure that the copying code used in an inter-partition # move unlinks a destination symlink before opening it. -# Copyright (C) 1999-2014 Free Software Foundation, Inc. +# Copyright (C) 1999-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/mv/trailing-slash.sh b/tests/mv/trailing-slash.sh index e3225025..47335d3c 100755 --- a/tests/mv/trailing-slash.sh +++ b/tests/mv/trailing-slash.sh @@ -4,7 +4,7 @@ # Also, ensure that "mv dir non-exist-dir/" works. # Also, ensure that "cp dir non-exist-dir/" works. -# Copyright (C) 2004-2014 Free Software Foundation, Inc. +# Copyright (C) 2004-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -48,14 +48,14 @@ done # underlying rename syscall handles the trailing slash. # It does fail, as desired, on recent Linux and Solaris systems. #touch a a2 -#mv a a2/ && fail=1 +#returns_ 1 mv a a2/ || fail=1 # Test for a cp-specific diagnostic introduced after coreutils-8.7: printf '%s\n' \ "cp: cannot create regular file 'no-such/': Not a directory" \ > expected-err touch b -cp b no-such/ 2> err && fail=1 +cp b no-such/ 2> err # Map "No such file..." diagnostic to the expected "Not a directory" sed 's/No such file or directory/Not a directory/' err > k && mv k err diff --git a/tests/mv/update.sh b/tests/mv/update.sh index 4c0553a5..2ada7dd1 100755 --- a/tests/mv/update.sh +++ b/tests/mv/update.sh @@ -1,7 +1,7 @@ #!/bin/sh # make sure --update works as advertised -# Copyright (C) 2001-2014 Free Software Foundation, Inc. +# Copyright (C) 2001-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/other-fs-tmpdir b/tests/other-fs-tmpdir index e82058ad..22d8ccad 100644 --- a/tests/other-fs-tmpdir +++ b/tests/other-fs-tmpdir @@ -4,7 +4,7 @@ # of the current directory. If one is found, create a temporary directory # inside it. -# Copyright (C) 1998-2014 Free Software Foundation, Inc. +# Copyright (C) 1998-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/pr/pr-tests.pl b/tests/pr/pr-tests.pl index 10947ac9..575943f4 100755 --- a/tests/pr/pr-tests.pl +++ b/tests/pr/pr-tests.pl @@ -1,7 +1,7 @@ #!/usr/bin/perl # Test pr. -# Copyright (C) 2008-2014 Free Software Foundation, Inc. +# Copyright (C) 2008-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -22,6 +22,7 @@ use strict; @ENV{qw(LANGUAGE LANG LC_ALL)} = ('C') x 3; my $prog = 'pr'; +my $normalize_strerror = "s/': .*/'/"; my @tv = ( @@ -385,9 +386,9 @@ my @tv = ( ['col-long', '-W3 -t -1 --columns=2', "a\nb\nc\n", "a c\nb\n", 0], # Make sure these fail. ['col-0', '-0', '', '', 1, - "$prog: invalid number of columns: '0'\n"], + "$prog: invalid number of columns: '0'\n", $normalize_strerror], ['col-inval', '-'.'9'x100, '', '', 1, - "$prog: invalid number of columns: '". ('9'x100) ."'\n"], + "$prog: invalid number of columns: '". ('9'x100) ."'\n", $normalize_strerror], # Before coreutils-5.3.1, --pages=1:-1 would be treated like # --pages=1:18446744073709551615. @@ -427,7 +428,7 @@ my $common_option_prefix = '--date-format="-- Date/Time --" -h x'; my @Tests; foreach my $t (@tv) { - my ($test_name, $flags, $in, $exp, $ret, $err_msg) = @$t; + my ($test_name, $flags, $in, $exp, $ret, $err_msg, $err_sub) = @$t; my $new_ent = [$test_name, $common_option_prefix, $flags]; if (!ref $in) { @@ -454,7 +455,7 @@ foreach my $t (@tv) } } $ret - and push @$new_ent, {EXIT=>$ret}, {ERR=>$err_msg}; + and push @$new_ent, {EXIT=>$ret}, {ERR=>$err_msg}, {ERR_SUBST=>$err_sub}; push @Tests, $new_ent; } diff --git a/tests/readlink/can-e.sh b/tests/readlink/can-e.sh index a6415b94..05f297b7 100755 --- a/tests/readlink/can-e.sh +++ b/tests/readlink/can-e.sh @@ -1,7 +1,7 @@ #!/bin/sh # tests for canonicalize-existing mode (readlink -e). -# Copyright (C) 2004-2014 Free Software Foundation, Inc. +# Copyright (C) 2004-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -38,7 +38,7 @@ cd "$pwd/$tmp/removed" || framework_failure_ # Skip this test if the system doesn't let you remove the working directory. if rmdir ../removed 2>/dev/null; then - v=$(readlink -e .) && fail=1 + v=$(returns_ 1 readlink -e .) || fail=1 test -z "$v" || fail=1 fi @@ -49,7 +49,7 @@ for p in "" "$pwd/$tmp/"; do v=$(readlink -e "${p}regfile") || fail=1 test "$v" = "$my_pwd/$tmp/regfile" || fail=1 - v=$(readlink -e "${p}./regfile/") && fail=1 + v=$(returns_ 1 readlink -e "${p}./regfile/") || fail=1 test -z "$v" || fail=1 v=$(readlink -e "${p}subdir") || fail=1 @@ -58,19 +58,19 @@ for p in "" "$pwd/$tmp/"; do v=$(readlink -e "${p}./subdir/") || fail=1 test "$v" = "$my_pwd/$tmp/subdir" || fail=1 - v=$(readlink -e "${p}missing") && fail=1 + v=$(returns_ 1 readlink -e "${p}missing") || fail=1 test -z "$v" || fail=1 - v=$(readlink -e "${p}./missing/") && fail=1 + v=$(returns_ 1 readlink -e "${p}./missing/") || fail=1 test -z "$v" || fail=1 v=$(readlink -e "${p}link1") || fail=1 test "$v" = "$my_pwd/$tmp/regfile" || fail=1 - v=$(readlink -e "${p}./link1/") && fail=1 + v=$(returns_ 1 readlink -e "${p}./link1/") || fail=1 test -z "$v" || fail=1 - v=$(readlink -e "${p}link1/more") && fail=1 + v=$(returns_ 1 readlink -e "${p}link1/more") || fail=1 test -z "$v" || fail=1 v=$(readlink -e "${p}link2") || fail=1 @@ -79,25 +79,25 @@ for p in "" "$pwd/$tmp/"; do v=$(readlink -e "${p}./link2/") || fail=1 test "$v" = "$my_pwd/$tmp/subdir" || fail=1 - v=$(readlink -e "${p}link2/more") && fail=1 + v=$(returns_ 1 readlink -e "${p}link2/more") || fail=1 test -z "$v" || fail=1 - v=$(readlink -e "${p}link3") && fail=1 + v=$(returns_ 1 readlink -e "${p}link3") || fail=1 test -z "$v" || fail=1 - v=$(readlink -e "${p}./link3/") && fail=1 + v=$(returns_ 1 readlink -e "${p}./link3/") || fail=1 test -z "$v" || fail=1 - v=$(readlink -e "${p}link3/more") && fail=1 + v=$(returns_ 1 readlink -e "${p}link3/more") || fail=1 test -z "$v" || fail=1 - v=$(readlink -e "${p}link4") && fail=1 + v=$(returns_ 1 readlink -e "${p}link4") || fail=1 test -z "$v" || fail=1 - v=$(readlink -e "${p}./link4/") && fail=1 + v=$(returns_ 1 readlink -e "${p}./link4/") || fail=1 test -z "$v" || fail=1 - v=$(readlink -e "${p}link4/more") && fail=1 + v=$(returns_ 1 readlink -e "${p}link4/more") || fail=1 test -z "$v" || fail=1 done diff --git a/tests/readlink/can-f.sh b/tests/readlink/can-f.sh index 2a980fa8..4b25fc63 100755 --- a/tests/readlink/can-f.sh +++ b/tests/readlink/can-f.sh @@ -1,7 +1,7 @@ #!/bin/sh # tests for canonicalize mode (readlink -f). -# Copyright (C) 2004-2014 Free Software Foundation, Inc. +# Copyright (C) 2004-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -39,7 +39,7 @@ cd "$pwd/$tmp/removed" || framework_failure_ # Skip this test if the system doesn't let you remove the working directory. if rmdir ../removed 2>/dev/null; then - v=$(readlink -e .) && fail=1 + v=$(returns_ 1 readlink -e .) || fail=1 test -z "$v" || fail=1 fi @@ -50,13 +50,13 @@ for p in "" "$pwd/$tmp/"; do v=$(readlink -f "${p}regfile") || fail=1 test "$v" = "$my_pwd/$tmp/regfile" || fail=1 - v=$(readlink -f "${p}./regfile/") && fail=1 + v=$(returns_ 1 readlink -f "${p}./regfile/") || fail=1 test -z "$v" || fail=1 - v=$(readlink -f "${p}regfile/more") && fail=1 + v=$(returns_ 1 readlink -f "${p}regfile/more") || fail=1 test -z "$v" || fail=1 - v=$(readlink -f "${p}./regfile/more/") && fail=1 + v=$(returns_ 1 readlink -f "${p}./regfile/more/") || fail=1 test -z "$v" || fail=1 v=$(readlink -f "${p}subdir") || fail=1 @@ -77,22 +77,22 @@ for p in "" "$pwd/$tmp/"; do v=$(readlink -f "${p}./missing/") || fail=1 test "$v" = "$my_pwd/$tmp/missing" || fail=1 - v=$(readlink -f "${p}missing/more") && fail=1 + v=$(returns_ 1 readlink -f "${p}missing/more") || fail=1 test -z "$v" || fail=1 - v=$(readlink -f "${p}./missing/more/") && fail=1 + v=$(returns_ 1 readlink -f "${p}./missing/more/") || fail=1 test -z "$v" || fail=1 v=$(readlink -f "${p}link1") || fail=1 test "$v" = "$my_pwd/$tmp/regfile" || fail=1 - v=$(readlink -f "${p}./link1/") && fail=1 + v=$(returns_ 1 readlink -f "${p}./link1/") || fail=1 test -z "$v" || fail=1 - v=$(readlink -f "${p}link1/more") && fail=1 + v=$(returns_ 1 readlink -f "${p}link1/more") || fail=1 test -z "$v" || fail=1 - v=$(readlink -f "${p}./link1/more/") && fail=1 + v=$(returns_ 1 readlink -f "${p}./link1/more/") || fail=1 test -z "$v" || fail=1 v=$(readlink -f "${p}link2") || fail=1 @@ -107,10 +107,10 @@ for p in "" "$pwd/$tmp/"; do v=$(readlink -f "${p}./link2/more/") || fail=1 test "$v" = "$my_pwd/$tmp/subdir/more" || fail=1 - v=$(readlink -f "${p}link2/more/more2") && fail=1 + v=$(returns_ 1 readlink -f "${p}link2/more/more2") || fail=1 test -z "$v" || fail=1 - v=$(readlink -f "${p}./link2/more/more2/") && fail=1 + v=$(returns_ 1 readlink -f "${p}./link2/more/more2/") || fail=1 test -z "$v" || fail=1 v=$(readlink -f "${p}link3") || fail=1 @@ -119,10 +119,10 @@ for p in "" "$pwd/$tmp/"; do v=$(readlink -f "${p}./link3/") || fail=1 test "$v" = "$my_pwd/$tmp/missing" || fail=1 - v=$(readlink -f "${p}link3/more") && fail=1 + v=$(returns_ 1 readlink -f "${p}link3/more") || fail=1 test -z "$v" || fail=1 - v=$(readlink -f "${p}./link3/more/") && fail=1 + v=$(returns_ 1 readlink -f "${p}./link3/more/") || fail=1 test -z "$v" || fail=1 v=$(readlink -f "${p}link4") || fail=1 @@ -131,22 +131,22 @@ for p in "" "$pwd/$tmp/"; do v=$(readlink -f "${p}./link4/") || fail=1 test "$v" = "$my_pwd/$tmp/subdir/missing" || fail=1 - v=$(readlink -f "${p}link4/more") && fail=1 + v=$(returns_ 1 readlink -f "${p}link4/more") || fail=1 test -z "$v" || fail=1 - v=$(readlink -f "${p}./link4/more") && fail=1 + v=$(returns_ 1 readlink -f "${p}./link4/more") || fail=1 test -z "$v" || fail=1 - v=$(readlink -f "${p}link5") && fail=1 + v=$(returns_ 1 readlink -f "${p}link5") || fail=1 test -z "$v" || fail=1 - v=$(readlink -f "${p}./link5/") && fail=1 + v=$(returns_ 1 readlink -f "${p}./link5/") || fail=1 test -z "$v" || fail=1 - v=$(readlink -f "${p}link5/more") && fail=1 + v=$(returns_ 1 readlink -f "${p}link5/more") || fail=1 test -z "$v" || fail=1 - v=$(readlink -f "${p}./link5/more") && fail=1 + v=$(returns_ 1 readlink -f "${p}./link5/more") || fail=1 test -z "$v" || fail=1 done diff --git a/tests/readlink/can-m.sh b/tests/readlink/can-m.sh index 768c552b..2eb13565 100755 --- a/tests/readlink/can-m.sh +++ b/tests/readlink/can-m.sh @@ -1,7 +1,7 @@ #!/bin/sh # tests for canonicalize-missing mode (readlink -m). -# Copyright (C) 2004-2014 Free Software Foundation, Inc. +# Copyright (C) 2004-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -38,7 +38,7 @@ cd "$pwd/$tmp/removed" || framework_failure_ # Skip this test if the system doesn't let you remove the working directory. if rmdir ../removed 2>/dev/null; then - v=$(readlink -e .) && fail=1 + v=$(returns_ 1 readlink -e .) || fail=1 test -z "$v" || fail=1 fi diff --git a/tests/readlink/multi.sh b/tests/readlink/multi.sh index e4878ecc..c7c2ef71 100755 --- a/tests/readlink/multi.sh +++ b/tests/readlink/multi.sh @@ -1,7 +1,7 @@ #!/bin/sh # test multiple argument handling. -# Copyright (C) 2012-2014 Free Software Foundation, Inc. +# Copyright (C) 2012-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -23,8 +23,8 @@ touch regfile || framework_failure_ ln -s regfile link1 || framework_failure_ readlink link1 link1 || fail=1 -readlink link1 link2 && fail=1 -readlink link1 link2 link1 && fail=1 +returns_ 1 readlink link1 link2 || fail=1 +returns_ 1 readlink link1 link2 link1 || fail=1 readlink -m link1 link2 || fail=1 printf '/1\0/1\0' > exp || framework_failure_ diff --git a/tests/readlink/rl-1.sh b/tests/readlink/rl-1.sh index ede0a915..5b429ede 100755 --- a/tests/readlink/rl-1.sh +++ b/tests/readlink/rl-1.sh @@ -1,7 +1,7 @@ #!/bin/sh # test for readlink mode. -# Copyright (C) 2004-2014 Free Software Foundation, Inc. +# Copyright (C) 2004-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -31,13 +31,13 @@ test "$v" = regfile || fail=1 v=$(readlink link2) || fail=1 test "$v" = missing || fail=1 -v=$(readlink subdir) && fail=1 +v=$(returns_ 1 readlink subdir) || fail=1 test -z "$v" || fail=1 -v=$(readlink regfile) && fail=1 +v=$(returns_ 1 readlink regfile) || fail=1 test -z "$v" || fail=1 -v=$(readlink missing) && fail=1 +v=$(returns_ 1 readlink missing) || fail=1 test -z "$v" || fail=1 Exit $fail diff --git a/tests/rm/cycle.sh b/tests/rm/cycle.sh index 589ee73a..259efd28 100755 --- a/tests/rm/cycle.sh +++ b/tests/rm/cycle.sh @@ -1,7 +1,7 @@ #!/bin/sh # rm (coreutils-4.5.4) could be tricked into mistakenly reporting a cycle. -# Copyright (C) 2003-2014 Free Software Foundation, Inc. +# Copyright (C) 2003-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/rm/d-1.sh b/tests/rm/d-1.sh index dd7cfd0f..43b753eb 100755 --- a/tests/rm/d-1.sh +++ b/tests/rm/d-1.sh @@ -1,7 +1,7 @@ #!/bin/sh # Test "rm --dir --verbose". -# Copyright (C) 2012-2014 Free Software Foundation, Inc. +# Copyright (C) 2012-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/rm/d-2.sh b/tests/rm/d-2.sh index 87fb100c..98e39990 100755 --- a/tests/rm/d-2.sh +++ b/tests/rm/d-2.sh @@ -2,7 +2,7 @@ # Ensure that 'rm -d dir' (i.e., without --recursive) gives a reasonable # diagnostic when failing. -# Copyright (C) 2012-2014 Free Software Foundation, Inc. +# Copyright (C) 2012-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/rm/d-3.sh b/tests/rm/d-3.sh index 646ecd06..af39da38 100755 --- a/tests/rm/d-3.sh +++ b/tests/rm/d-3.sh @@ -2,7 +2,7 @@ # Ensure that 'rm -d -i dir' (i.e., without --recursive) gives a prompt and # then deletes the directory if it is empty -# Copyright (C) 2012-2014 Free Software Foundation, Inc. +# Copyright (C) 2012-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/rm/dangling-symlink.sh b/tests/rm/dangling-symlink.sh index 1e5cdfa9..d2e08a8a 100755 --- a/tests/rm/dangling-symlink.sh +++ b/tests/rm/dangling-symlink.sh @@ -4,7 +4,7 @@ # But for fileutils-4.1.9, it would do the former and # for fileutils-4.1.10 the latter. -# Copyright (C) 2002-2014 Free Software Foundation, Inc. +# Copyright (C) 2002-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -25,9 +25,10 @@ print_ver_ rm ln -s no-file dangle ln -s / symlink +# Terminate any background processes +cleanup_() { kill $pid 2>/dev/null && wait $pid; } -rm ---presume-input-tty dangle symlink & -pid=$! +rm ---presume-input-tty dangle symlink & pid=$! # The buggy rm (fileutils-4.1.9) would hang here, waiting for input. # Wait up to 3.1s for rm to remove the files @@ -40,6 +41,6 @@ check_files_removed() { } retry_delay_ check_files_removed .1 5 || fail=1 -kill $pid > /dev/null 2>&1 +cleanup_ Exit $fail diff --git a/tests/rm/deep-1.sh b/tests/rm/deep-1.sh index 1f1b307c..82b3fe2e 100755 --- a/tests/rm/deep-1.sh +++ b/tests/rm/deep-1.sh @@ -1,7 +1,7 @@ #!/bin/sh # Test "rm" with a deep hierarchy. -# Copyright (C) 1997-2014 Free Software Foundation, Inc. +# Copyright (C) 1997-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/rm/deep-2.sh b/tests/rm/deep-2.sh index c3ea0856..7a7f6114 100755 --- a/tests/rm/deep-2.sh +++ b/tests/rm/deep-2.sh @@ -1,7 +1,7 @@ #!/bin/sh # Ensure rm -r DIR does not prompt for very long full relative names in DIR. -# Copyright (C) 2008-2014 Free Software Foundation, Inc. +# Copyright (C) 2008-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/rm/dir-no-w.sh b/tests/rm/dir-no-w.sh index de9035e9..1cecedb4 100755 --- a/tests/rm/dir-no-w.sh +++ b/tests/rm/dir-no-w.sh @@ -2,7 +2,7 @@ # rm (without -r) must give a diagnostic for any directory. # It must not prompt, even if that directory is unwritable. -# Copyright (C) 2003-2014 Free Software Foundation, Inc. +# Copyright (C) 2003-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/rm/dir-nonrecur.sh b/tests/rm/dir-nonrecur.sh index 45956da7..d2dcbb74 100755 --- a/tests/rm/dir-nonrecur.sh +++ b/tests/rm/dir-nonrecur.sh @@ -2,7 +2,7 @@ # Ensure that 'rm dir' (i.e., without --recursive) gives a reasonable # diagnostic when failing. -# Copyright (C) 2005-2014 Free Software Foundation, Inc. +# Copyright (C) 2005-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/rm/dot-rel.sh b/tests/rm/dot-rel.sh index 4e1a8ce0..ac34b0e3 100755 --- a/tests/rm/dot-rel.sh +++ b/tests/rm/dot-rel.sh @@ -2,7 +2,7 @@ # Use rm -r to remove two non-empty dot-relative directories. # This would have failed between 2004-10-18 and 2004-10-21. -# Copyright (C) 2004-2014 Free Software Foundation, Inc. +# Copyright (C) 2004-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/rm/empty-inacc.sh b/tests/rm/empty-inacc.sh index e3771530..791937c7 100755 --- a/tests/rm/empty-inacc.sh +++ b/tests/rm/empty-inacc.sh @@ -1,7 +1,7 @@ #!/bin/sh # Ensure that rm -rf removes an empty-and-inaccessible directory. -# Copyright (C) 2006-2014 Free Software Foundation, Inc. +# Copyright (C) 2006-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/rm/empty-name.pl b/tests/rm/empty-name.pl index b6ee6ad5..a050081f 100755 --- a/tests/rm/empty-name.pl +++ b/tests/rm/empty-name.pl @@ -1,7 +1,7 @@ #!/usr/bin/perl # Make sure that rm -r '' fails. -# Copyright (C) 1998-2014 Free Software Foundation, Inc. +# Copyright (C) 1998-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/rm/ext3-perf.sh b/tests/rm/ext3-perf.sh index ef4fee46..baa8d5dc 100755 --- a/tests/rm/ext3-perf.sh +++ b/tests/rm/ext3-perf.sh @@ -1,7 +1,7 @@ #!/bin/sh # ensure that "rm -rf DIR-with-many-entries" is not O(N^2) -# Copyright (C) 2008-2014 Free Software Foundation, Inc. +# Copyright (C) 2008-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/rm/f-1.sh b/tests/rm/f-1.sh index 0fc95c4f..c068c778 100755 --- a/tests/rm/f-1.sh +++ b/tests/rm/f-1.sh @@ -1,7 +1,7 @@ #!/bin/sh # Test "rm -f" with a nonexistent file. -# Copyright (C) 1997-2014 Free Software Foundation, Inc. +# Copyright (C) 1997-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/rm/fail-2eperm.sh b/tests/rm/fail-2eperm.sh index 6e8ce9ba..0bbd028d 100755 --- a/tests/rm/fail-2eperm.sh +++ b/tests/rm/fail-2eperm.sh @@ -2,7 +2,7 @@ # Like fail-eperm, but the failure must be for a file encountered # while trying to remove the containing directory with the sticky bit set. -# Copyright (C) 2003-2014 Free Software Foundation, Inc. +# Copyright (C) 2003-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -32,14 +32,16 @@ touch a/b || framework_failure_ # Try to ensure that $NON_ROOT_USERNAME can access # the required version of rm. rm_version=$( - chroot --user=$NON_ROOT_USERNAME / env PATH="$PATH" rm --version | + chroot --skip-chdir --user=$NON_ROOT_USERNAME / env PATH="$PATH" \ + rm --version | sed -n '1s/.* //p' ) case $rm_version in $PACKAGE_VERSION) ;; *) skip_ "cannot access just-built rm as user $NON_ROOT_USERNAME";; esac -chroot --user=$NON_ROOT_USERNAME / env PATH="$PATH" rm -rf a 2> out-t && fail=1 +chroot --skip-chdir --user=$NON_ROOT_USERNAME / \ + env PATH="$PATH" rm -rf a 2> out-t && fail=1 # On some systems, we get 'Not owner'. Convert it. # On other systems (HPUX), we get 'Permission denied'. Convert it, too. diff --git a/tests/rm/fail-eacces.sh b/tests/rm/fail-eacces.sh index dd31ea4c..64242a50 100755 --- a/tests/rm/fail-eacces.sh +++ b/tests/rm/fail-eacces.sh @@ -4,7 +4,7 @@ # With the symlink, rm from coreutils-6.9 would fail with a misleading # ELOOP diagnostic. -# Copyright (C) 2006-2014 Free Software Foundation, Inc. +# Copyright (C) 2006-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/rm/fail-eperm.xpl b/tests/rm/fail-eperm.xpl index b167d0ba..7a5b9ce1 100755 --- a/tests/rm/fail-eperm.xpl +++ b/tests/rm/fail-eperm.xpl @@ -2,7 +2,7 @@ # Ensure that rm gives the expected diagnostic when failing to remove a file # owned by some other user in a directory with the sticky bit set. -# Copyright (C) 2002-2014 Free Software Foundation, Inc. +# Copyright (C) 2002-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -32,7 +32,6 @@ my $verbose = $ENV{VERBOSE} && $ENV{VERBOSE} eq 'yes'; $ENV{LC_ALL} = 'C'; # Set up a safe, well-known environment -delete @ENV{qw(BASH_ENV CDPATH ENV)}; $ENV{IFS} = ''; # Taint checking requires a sanitized $PATH. This script performs no $PATH diff --git a/tests/rm/hash.sh b/tests/rm/hash.sh index 6bc82bdc..7b0d452f 100755 --- a/tests/rm/hash.sh +++ b/tests/rm/hash.sh @@ -3,7 +3,7 @@ # Before then, rm would fail occasionally, sometimes via # a failed assertion, others with a seg fault. -# Copyright (C) 2000-2014 Free Software Foundation, Inc. +# Copyright (C) 2000-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/rm/i-1.sh b/tests/rm/i-1.sh index 6a4ca64b..1aeec0ca 100755 --- a/tests/rm/i-1.sh +++ b/tests/rm/i-1.sh @@ -1,7 +1,7 @@ #!/bin/sh # Test "rm -i". -# Copyright (C) 1997-2014 Free Software Foundation, Inc. +# Copyright (C) 1997-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/rm/i-never.sh b/tests/rm/i-never.sh index 6302174a..751473e4 100755 --- a/tests/rm/i-never.sh +++ b/tests/rm/i-never.sh @@ -2,7 +2,7 @@ # Ensure that rm --interactive=never works does not prompt, even for # an unwritable file. -# Copyright (C) 2007-2014 Free Software Foundation, Inc. +# Copyright (C) 2007-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/rm/i-no-r.sh b/tests/rm/i-no-r.sh index 8a535faf..22819ab6 100755 --- a/tests/rm/i-no-r.sh +++ b/tests/rm/i-no-r.sh @@ -3,7 +3,7 @@ # recurse into directory DIR. rm -i (without -r) must fail in that case. # Fixed in coreutils-4.5.2. -# Copyright (C) 2002-2014 Free Software Foundation, Inc. +# Copyright (C) 2002-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -26,7 +26,7 @@ echo y > y || framework_failure_ # This must fail. -rm -i dir < y > /dev/null 2>&1 && fail=1 +returns_ 1 rm -i dir < y > /dev/null 2>&1 || fail=1 # The directory must remain. test -d dir || fail=1 diff --git a/tests/rm/ignorable.sh b/tests/rm/ignorable.sh index 8d656eea..e4ddcc2d 100755 --- a/tests/rm/ignorable.sh +++ b/tests/rm/ignorable.sh @@ -1,7 +1,7 @@ #!/bin/sh # Ensure that rm -f existing-non-dir/anything exits successfully -# Copyright (C) 2006-2014 Free Software Foundation, Inc. +# Copyright (C) 2006-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/rm/inaccessible.sh b/tests/rm/inaccessible.sh index e3c48dfe..42cda786 100755 --- a/tests/rm/inaccessible.sh +++ b/tests/rm/inaccessible.sh @@ -2,7 +2,7 @@ # Ensure that rm works even when run from a directory # for which the user has no access at all. -# Copyright (C) 2004-2014 Free Software Foundation, Inc. +# Copyright (C) 2004-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/rm/interactive-always.sh b/tests/rm/interactive-always.sh index 627d923e..ef72002a 100755 --- a/tests/rm/interactive-always.sh +++ b/tests/rm/interactive-always.sh @@ -1,7 +1,7 @@ #!/bin/sh # Test the --interactive[=WHEN] changes added to coreutils 6.0 -# Copyright (C) 2006-2014 Free Software Foundation, Inc. +# Copyright (C) 2006-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/rm/interactive-once.sh b/tests/rm/interactive-once.sh index db10bba6..398826e6 100755 --- a/tests/rm/interactive-once.sh +++ b/tests/rm/interactive-once.sh @@ -1,7 +1,7 @@ #!/bin/sh # Test the -I option added to coreutils 6.0 -# Copyright (C) 2006-2014 Free Software Foundation, Inc. +# Copyright (C) 2006-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/rm/ir-1.sh b/tests/rm/ir-1.sh index 86a5595f..002ea454 100755 --- a/tests/rm/ir-1.sh +++ b/tests/rm/ir-1.sh @@ -1,7 +1,7 @@ #!/bin/sh # Test "rm -ir". -# Copyright (C) 1997-2014 Free Software Foundation, Inc. +# Copyright (C) 1997-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/rm/isatty.sh b/tests/rm/isatty.sh index 0ff8d1fa..4eea4432 100755 --- a/tests/rm/isatty.sh +++ b/tests/rm/isatty.sh @@ -1,7 +1,7 @@ #!/bin/sh # Make sure 'chown 0 f; rm f' prompts before removing f. -# Copyright (C) 2001-2014 Free Software Foundation, Inc. +# Copyright (C) 2001-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -25,10 +25,12 @@ skip_if_root_ ls /dev/stdin >/dev/null 2>&1 \ || skip_ 'there is no /dev/stdin file' +# Terminate any background processes +cleanup_() { kill $pid 2>/dev/null && wait $pid; } + touch f chmod 0 f -rm ---presume-input-tty f > out 2>&1 & -pid=$! +rm ---presume-input-tty f > out 2>&1 & pid=$! # Wait a second, to give a buggy rm (as in fileutils-4.0.40) # enough time to remove the file. @@ -37,7 +39,7 @@ sleep 1 # The file must still exist. test -f f || fail=1 -kill $pid > /dev/null 2>&1 +cleanup_ # Note the trailing 'x' -- so I don't have to have a trailing # blank in this file :-) diff --git a/tests/rm/many-dir-entries-vs-OOM.sh b/tests/rm/many-dir-entries-vs-OOM.sh index c45453d7..e9c95d5d 100755 --- a/tests/rm/many-dir-entries-vs-OOM.sh +++ b/tests/rm/many-dir-entries-vs-OOM.sh @@ -2,7 +2,7 @@ # In coreutils-8.12, rm,du,chmod, etc. would use too much memory # when processing a directory with many entries (as in > 100,000). -# Copyright (C) 2011-2014 Free Software Foundation, Inc. +# Copyright (C) 2011-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/rm/no-give-up.sh b/tests/rm/no-give-up.sh index 41070c9d..a5134d76 100755 --- a/tests/rm/no-give-up.sh +++ b/tests/rm/no-give-up.sh @@ -2,7 +2,7 @@ # With rm from coreutils-5.2.1 and earlier, 'rm -r' would mistakenly # give up too early under some conditions. -# Copyright (C) 2004-2014 Free Software Foundation, Inc. +# Copyright (C) 2004-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -30,8 +30,8 @@ chmod go=x . || framework_failure_ # This must fail, since '.' is not writable by $NON_ROOT_USERNAME. -chroot --user=$NON_ROOT_USERNAME / env PATH="$PATH" \ - rm -rf d 2>/dev/null && fail=1 +returns_ 1 chroot --skip-chdir --user=$NON_ROOT_USERNAME / env PATH="$PATH" \ + rm -rf d 2>/dev/null || fail=1 # d must remain. test -d d || fail=1 diff --git a/tests/rm/one-file-system.sh b/tests/rm/one-file-system.sh index 09a0464b..11492092 100755 --- a/tests/rm/one-file-system.sh +++ b/tests/rm/one-file-system.sh @@ -1,7 +1,7 @@ #!/bin/sh # Demonstrate rm's new --one-file-system option. -# Copyright (C) 2006-2014 Free Software Foundation, Inc. +# Copyright (C) 2006-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/rm/one-file-system2.sh b/tests/rm/one-file-system2.sh index e4e8a417..1a27dfd1 100755 --- a/tests/rm/one-file-system2.sh +++ b/tests/rm/one-file-system2.sh @@ -1,7 +1,7 @@ #!/bin/sh # Verify --one-file-system does delete within a file system -# Copyright (C) 2009-2014 Free Software Foundation, Inc. +# Copyright (C) 2009-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/rm/r-1.sh b/tests/rm/r-1.sh index 6e1d6089..21564c6a 100755 --- a/tests/rm/r-1.sh +++ b/tests/rm/r-1.sh @@ -1,7 +1,7 @@ #!/bin/sh # Test "rm -r --verbose". -# Copyright (C) 1997-2014 Free Software Foundation, Inc. +# Copyright (C) 1997-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/rm/r-2.sh b/tests/rm/r-2.sh index a8049bd2..a99bdbf4 100755 --- a/tests/rm/r-2.sh +++ b/tests/rm/r-2.sh @@ -1,7 +1,7 @@ #!/bin/sh # Test "rm -r --verbose". -# Copyright (C) 1997-2014 Free Software Foundation, Inc. +# Copyright (C) 1997-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/rm/r-3.sh b/tests/rm/r-3.sh index 82c35bed..a8bea100 100755 --- a/tests/rm/r-3.sh +++ b/tests/rm/r-3.sh @@ -1,7 +1,7 @@ #!/bin/sh # Create and remove a directory with more than 254 files. -# Copyright (C) 1997-2014 Free Software Foundation, Inc. +# Copyright (C) 1997-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/rm/r-4.sh b/tests/rm/r-4.sh index 095f1516..91a8b58a 100755 --- a/tests/rm/r-4.sh +++ b/tests/rm/r-4.sh @@ -1,7 +1,7 @@ #!/bin/sh # Try to remove '.' and '..' recursively. -# Copyright (C) 2006-2014 Free Software Foundation, Inc. +# Copyright (C) 2006-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -43,8 +43,8 @@ rmtest 'd/..' || fail=1 rmtest 'd/../' || fail=1 -# This test is too dangerous -- if there's a bug you're wiped out! -# rm -fr / 2>/dev/null && fail=1 +# This test is handled more carefully in r-root.sh +# returns_ 1 rm -fr / 2>/dev/null || fail=1 test -f d/a || fail=1 diff --git a/tests/rm/r-root.sh b/tests/rm/r-root.sh index e17b85bd..c06332ae 100755 --- a/tests/rm/r-root.sh +++ b/tests/rm/r-root.sh @@ -1,7 +1,7 @@ #!/bin/sh # Try to remove '/' recursively. -# Copyright (C) 2013-2014 Free Software Foundation, Inc. +# Copyright (C) 2013-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -89,7 +89,7 @@ exercise_rm_r_root () fi timeout --signal=KILL 2 \ - env LD_PRELOAD=./k.so $skip_exit \ + env LD_PRELOAD=$LD_PRELOAD:./k.so $skip_exit \ rm -rv --one-file-system "$@" > out 2> err return $? @@ -143,8 +143,7 @@ for opts in \ 'rootlink2/' \ 'rootlink3/' ; do - exercise_rm_r_root $opts \ - && fail=1 + returns_ 1 exercise_rm_r_root $opts || fail=1 # For some of the synonyms, the error diagnostic slightly differs from that # of the basic "/" case (see gnulib's fts_open' and ROOT_DEV_INO_WARN): @@ -178,8 +177,7 @@ done # by setting the following variable. CU_TEST_SKIP_EXIT=1 -exercise_rm_r_root --preserve-root file1 '/' file2 \ - && fail=1 +returns_ 1 exercise_rm_r_root --preserve-root file1 '/' file2 || fail=1 unset CU_TEST_SKIP_EXIT @@ -219,8 +217,7 @@ for file in \ test -d "$file" || continue # if e.g. /etc does not exist. - exercise_rm_r_root --preserve-root "$file" \ - && fail=1 + returns_ 1 exercise_rm_r_root --preserve-root "$file" || fail=1 grep "^rm: refusing to remove '\.' or '\.\.' directory: skipping" err \ || fail=1 @@ -244,11 +241,10 @@ exercise_rm_r_root --interactive=never --no-preserve-root '/' \ || fail=1 # The 'err' file should not contain the above error diagnostic. -grep "^rm: it is dangerous to operate recursively on '/'" err \ - && fail=1 +grep "^rm: it is dangerous to operate recursively on '/'" err && fail=1 # Instead, rm(1) should have called the intercepted unlinkat() function, -# i.e. the evidence file "x" should exist. +# i.e., the evidence file "x" should exist. test -f x || fail=1 test $fail = 1 && { cat out; cat err; } diff --git a/tests/rm/read-only.sh b/tests/rm/read-only.sh index 377305cd..4375f1bc 100755 --- a/tests/rm/read-only.sh +++ b/tests/rm/read-only.sh @@ -1,7 +1,7 @@ #!/bin/sh # Ensure that rm -f nonexistent-file-on-read-only-fs succeeds. -# Copyright (C) 2009-2014 Free Software Foundation, Inc. +# Copyright (C) 2009-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -47,6 +47,6 @@ compare /dev/null out || fail=1 # However, trying to remove an existing file must fail. rm -f mnt/f > out 2>&1 && fail=1 # with a diagnostic. -test -s out || fail=1 +compare /dev/null out && fail=1 Exit $fail diff --git a/tests/rm/readdir-bug.sh b/tests/rm/readdir-bug.sh index d54a71c1..0ff02714 100755 --- a/tests/rm/readdir-bug.sh +++ b/tests/rm/readdir-bug.sh @@ -2,7 +2,7 @@ # Exercise the Darwin/MacOS bug worked around on 2006-09-29, # whereby rm would fail to remove all entries in a directory. -# Copyright (C) 2006-2014 Free Software Foundation, Inc. +# Copyright (C) 2006-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/rm/rm1.sh b/tests/rm/rm1.sh index 575a78dd..dcdfecf4 100755 --- a/tests/rm/rm1.sh +++ b/tests/rm/rm1.sh @@ -1,7 +1,7 @@ #!/bin/sh # exercise another small part of remove.c -# Copyright (C) 2002-2014 Free Software Foundation, Inc. +# Copyright (C) 2002-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/rm/rm2.sh b/tests/rm/rm2.sh index 93ca66e2..2bc558ef 100755 --- a/tests/rm/rm2.sh +++ b/tests/rm/rm2.sh @@ -1,7 +1,7 @@ #!/bin/sh # exercise another small part of remove.c -# Copyright (C) 2002-2014 Free Software Foundation, Inc. +# Copyright (C) 2002-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/rm/rm3.sh b/tests/rm/rm3.sh index dda27a60..df426b7e 100755 --- a/tests/rm/rm3.sh +++ b/tests/rm/rm3.sh @@ -1,7 +1,7 @@ #!/bin/sh # exercise another small part of remove.c -# Copyright (C) 2002-2014 Free Software Foundation, Inc. +# Copyright (C) 2002-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/rm/rm4.sh b/tests/rm/rm4.sh index 60eb4a78..e0f141fd 100755 --- a/tests/rm/rm4.sh +++ b/tests/rm/rm4.sh @@ -1,7 +1,7 @@ #!/bin/sh # ensure that 'rm dir' fails without --recursive -# Copyright (C) 2002-2014 Free Software Foundation, Inc. +# Copyright (C) 2002-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -24,7 +24,7 @@ mkdir dir || framework_failure_ # This should fail. -rm dir > /dev/null 2>&1 && fail=1 +returns_ 1 rm dir > /dev/null 2>&1 || fail=1 test -d dir || fail=1 diff --git a/tests/rm/rm5.sh b/tests/rm/rm5.sh index 6ccd6c6b..7e017a68 100755 --- a/tests/rm/rm5.sh +++ b/tests/rm/rm5.sh @@ -1,7 +1,7 @@ #!/bin/sh # a basic test of rm -ri -# Copyright (C) 2002-2014 Free Software Foundation, Inc. +# Copyright (C) 2002-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/rm/sunos-1.sh b/tests/rm/sunos-1.sh index cc8a02b7..db4221f0 100755 --- a/tests/rm/sunos-1.sh +++ b/tests/rm/sunos-1.sh @@ -1,7 +1,7 @@ #!/bin/sh # Make sure that rm -r '' fails. -# Copyright (C) 1997-2014 Free Software Foundation, Inc. +# Copyright (C) 1997-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -24,6 +24,6 @@ . "${srcdir=.}/tests/init.sh"; path_prepend_ ./src print_ver_ rm -rm -r '' > /dev/null 2>&1 && fail=1 +returns_ 1 rm -r '' > /dev/null 2>&1 || fail=1 Exit $fail diff --git a/tests/rm/unread2.sh b/tests/rm/unread2.sh index 977d557d..3e532497 100755 --- a/tests/rm/unread2.sh +++ b/tests/rm/unread2.sh @@ -1,7 +1,7 @@ #!/bin/sh # exercise one small part of remove.c -# Copyright (C) 2002-2014 Free Software Foundation, Inc. +# Copyright (C) 2002-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/rm/unread3.sh b/tests/rm/unread3.sh index a8df825c..3d9d74cb 100755 --- a/tests/rm/unread3.sh +++ b/tests/rm/unread3.sh @@ -1,7 +1,7 @@ #!/bin/sh # Ensure that rm works even from an unreadable working directory. -# Copyright (C) 2004-2014 Free Software Foundation, Inc. +# Copyright (C) 2004-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/rm/unreadable.pl b/tests/rm/unreadable.pl index 7f0cd3d6..4abf301d 100755 --- a/tests/rm/unreadable.pl +++ b/tests/rm/unreadable.pl @@ -1,7 +1,7 @@ #!/usr/bin/perl # Test "rm" and unreadable directories. -# Copyright (C) 1998-2014 Free Software Foundation, Inc. +# Copyright (C) 1998-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/rm/v-slash.sh b/tests/rm/v-slash.sh index 69730a19..5cabb0bc 100755 --- a/tests/rm/v-slash.sh +++ b/tests/rm/v-slash.sh @@ -1,7 +1,7 @@ #!/bin/sh # avoid extra slashes in --verbose output -# Copyright (C) 2007-2014 Free Software Foundation, Inc. +# Copyright (C) 2007-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/rmdir/fail-perm.sh b/tests/rmdir/fail-perm.sh index 1072feef..985cb23b 100755 --- a/tests/rmdir/fail-perm.sh +++ b/tests/rmdir/fail-perm.sh @@ -2,7 +2,7 @@ # For unwritable directory 'd', 'rmdir -p d d/e/f' would emit # diagnostics but would not fail. Fixed in 5.1.2. -# Copyright (C) 2004-2014 Free Software Foundation, Inc. +# Copyright (C) 2004-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -27,6 +27,6 @@ chmod a-w d || framework_failure_ # This rmdir command outputs two diagnostics. # Before coreutils-5.1.2, it would mistakenly exit successfully. # As of coreutils-5.1.2, it fails, as required. -rmdir -p d d/e/f 2> /dev/null && fail=1 +returns_ 1 rmdir -p d d/e/f 2> /dev/null || fail=1 Exit $fail diff --git a/tests/rmdir/ignore.sh b/tests/rmdir/ignore.sh index 487dd9fd..6cf5c225 100755 --- a/tests/rmdir/ignore.sh +++ b/tests/rmdir/ignore.sh @@ -1,7 +1,7 @@ #!/bin/sh # make sure rmdir's --ignore-fail-on-non-empty option works -# Copyright (C) 1999-2014 Free Software Foundation, Inc. +# Copyright (C) 1999-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/rmdir/t-slash.sh b/tests/rmdir/t-slash.sh index 8d010412..4bf9c915 100755 --- a/tests/rmdir/t-slash.sh +++ b/tests/rmdir/t-slash.sh @@ -1,7 +1,7 @@ #!/bin/sh # make sure rmdir -p works on a directory specified with a trailing slash -# Copyright (C) 2002-2014 Free Software Foundation, Inc. +# Copyright (C) 2002-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/sample-test b/tests/sample-test index a6dcc21b..2ddf3b8f 100644 --- a/tests/sample-test +++ b/tests/sample-test @@ -1,7 +1,7 @@ #!/bin/sh # FIXME -# Copyright (C) 2014 Free Software Foundation, Inc. +# Copyright (C) 2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/split/additional-suffix.sh b/tests/split/additional-suffix.sh index 7a4d2d7b..79a3f972 100755 --- a/tests/split/additional-suffix.sh +++ b/tests/split/additional-suffix.sh @@ -1,7 +1,7 @@ #!/bin/sh # show that 'split --additional-suffix=SUFFIX' works. -# Copyright (C) 2012-2014 Free Software Foundation, Inc. +# Copyright (C) 2012-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -39,6 +39,6 @@ compare exp-2 xab.txt || fail=1 compare exp-3 xac.txt || fail=1 # Additional suffix must not contain slash -split --lines=2 --additional-suffix=a/b in 2>/dev/null > out && fail=1 +returns_ 1 split --lines=2 --additional-suffix=a/b in 2>/dev/null >out || fail=1 Exit $fail diff --git a/tests/split/b-chunk.sh b/tests/split/b-chunk.sh index 86f95a05..d10fbb9d 100755 --- a/tests/split/b-chunk.sh +++ b/tests/split/b-chunk.sh @@ -1,7 +1,7 @@ #!/bin/sh # test splitting into 3 chunks -# Copyright (C) 2010-2014 Free Software Foundation, Inc. +# Copyright (C) 2010-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -29,22 +29,33 @@ rm -f x?? split -e -n 10 /dev/null || fail=1 stat x?? 2>/dev/null && fail=1 -printf '1\n2\n3\n4\n5\n' > in || framework_failure_ - -split -n 3 in > out || fail=1 -split -n 1/3 in > b1 || fail=1 -split -n 2/3 in > b2 || fail=1 -split -n 3/3 in > b3 || fail=1 -printf '1\n2' > exp-1 -printf '\n3\n' > exp-2 -printf '4\n5\n' > exp-3 - -compare exp-1 xaa || fail=1 -compare exp-2 xab || fail=1 -compare exp-3 xac || fail=1 -compare exp-1 b1 || fail=1 -compare exp-2 b2 || fail=1 -compare exp-3 b3 || fail=1 -test -f xad && fail=1 +printf '1\n2\n3\n4\n5\n' > input || framework_failure_ + +for file in input /proc/version /sys/kernel/profiling; do + test -f $file || continue + + split -n 3 $file > out || fail=1 + split -n 1/3 $file > b1 || fail=1 + split -n 2/3 $file > b2 || fail=1 + split -n 3/3 $file > b3 || fail=1 + + case $file in + input) + printf '1\n2' > exp-1 + printf '\n3\n' > exp-2 + printf '4\n5\n' > exp-3 + + compare exp-1 xaa || fail=1 + compare exp-2 xab || fail=1 + compare exp-3 xac || fail=1 + ;; + esac + + compare xaa b1 || fail=1 + compare xab b2 || fail=1 + compare xac b3 || fail=1 + cat xaa xab xac | compare - $file || fail=1 + test -f xad && fail=1 +done Exit $fail diff --git a/tests/split/fail.sh b/tests/split/fail.sh index 33694129..e8f7bc3c 100755 --- a/tests/split/fail.sh +++ b/tests/split/fail.sh @@ -1,7 +1,7 @@ #!/bin/sh # split must fail when given length/count of zero. -# Copyright (C) 2003-2014 Free Software Foundation, Inc. +# Copyright (C) 2003-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -24,13 +24,13 @@ touch in || framework_failure_ split -a 0 in 2> /dev/null || fail=1 -split -b 0 in 2> /dev/null && fail=1 -split -C 0 in 2> /dev/null && fail=1 -split -l 0 in 2> /dev/null && fail=1 -split -n 0 in 2> /dev/null && fail=1 -split -n 1/0 in 2> /dev/null && fail=1 -split -n 0/1 in 2> /dev/null && fail=1 -split -n 2/1 in 2> /dev/null && fail=1 +returns_ 1 split -b 0 in 2> /dev/null || fail=1 +returns_ 1 split -C 0 in 2> /dev/null || fail=1 +returns_ 1 split -l 0 in 2> /dev/null || fail=1 +returns_ 1 split -n 0 in 2> /dev/null || fail=1 +returns_ 1 split -n 1/0 in 2> /dev/null || fail=1 +returns_ 1 split -n 0/1 in 2> /dev/null || fail=1 +returns_ 1 split -n 2/1 in 2> /dev/null || fail=1 # Make sure -C doesn't create empty files. rm -f x?? || fail=1 @@ -42,21 +42,21 @@ test -f xac && fail=1 split -1 in 2> /dev/null || fail=1 # Then make sure that -0 evokes a failure. -split -0 in 2> /dev/null && fail=1 +returns_ 1 split -0 in 2> /dev/null || fail=1 split --lines=$UINTMAX_MAX in || fail=1 split --bytes=$OFF_T_MAX in || fail=1 -split --line-bytes=$OFF_T_OFLOW 2> /dev/null in && fail=1 -split --line-bytes=$SIZE_OFLOW 2> /dev/null in && fail=1 +returns_ 1 split --line-bytes=$OFF_T_OFLOW 2> /dev/null in || fail=1 +returns_ 1 split --line-bytes=$SIZE_OFLOW 2> /dev/null in || fail=1 if truncate -s$SIZE_OFLOW large; then # Ensure we can split chunks of a large file on 32 bit hosts split --number=$SIZE_OFLOW/$SIZE_OFLOW large >/dev/null || fail=1 fi split --number=r/$UINTMAX_MAX/$UINTMAX_MAX </dev/null >/dev/null || fail=1 -split --number=r/$UINTMAX_OFLOW </dev/null 2>/dev/null && fail=1 +returns_ 1 split --number=r/$UINTMAX_OFLOW </dev/null 2>/dev/null || fail=1 # Make sure that a huge obsolete option evokes the right failure. -split -99999999999999999991 2> out && fail=1 +split -99999999999999999991 2> out # On losing systems (x86 Solaris 5.9 c89), we get a message like this: # split: line count option -9999999999... is too large @@ -75,7 +75,7 @@ compare exp out || fail=1 # (the current directory in this case) if ! cat . >/dev/null; then # can't read() directories - split . && fail=1 + returns_ 1 split . || fail=1 fi Exit $fail diff --git a/tests/split/filter.sh b/tests/split/filter.sh index fed8c7a4..55610e41 100755 --- a/tests/split/filter.sh +++ b/tests/split/filter.sh @@ -1,7 +1,7 @@ #!/bin/sh # Exercise split's new --filter option. -# Copyright (C) 2011-2014 Free Software Foundation, Inc. +# Copyright (C) 2011-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -44,7 +44,7 @@ split -e -n 10 --filter='xz > $FILE.xz' /dev/null || fail=1 stat x?? 2>/dev/null && fail=1 # Ensure this invalid combination is flagged -split -n 1/2 --filter='true' /dev/null 2>/dev/null && fail=1 +returns_ 1 split -n 1/2 --filter='true' /dev/null 2>&1 || fail=1 # Ensure SIGPIPEs sent by the children don't propagate back # where they would result in a non zero exit from split. diff --git a/tests/split/guard-input.sh b/tests/split/guard-input.sh index 56b3158b..1213ab04 100755 --- a/tests/split/guard-input.sh +++ b/tests/split/guard-input.sh @@ -1,7 +1,7 @@ #!/bin/sh # ensure split doesn't overwrite input with output. -# Copyright (C) 2012-2014 Free Software Foundation, Inc. +# Copyright (C) 2012-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -23,10 +23,10 @@ seq 10 | tee exp-1 > xaa ln -s xaa in2 ln xaa in3 -split -C 6 xaa && fail=1 -split -C 6 in2 && fail=1 -split -C 6 in3 && fail=1 -split -C 6 - < xaa && fail=1 +returns_ 1 split -C 6 xaa || fail=1 +returns_ 1 split -C 6 in2 || fail=1 +returns_ 1 split -C 6 in3 || fail=1 +returns_ 1 split -C 6 - < xaa || fail=1 compare exp-1 xaa || fail=1 diff --git a/tests/split/l-chunk.sh b/tests/split/l-chunk.sh index 792c5569..c97b3b56 100755 --- a/tests/split/l-chunk.sh +++ b/tests/split/l-chunk.sh @@ -1,7 +1,7 @@ #!/bin/sh # test splitting into newline delineated chunks (-n l/...) -# Copyright (C) 2010-2014 Free Software Foundation, Inc. +# Copyright (C) 2010-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -20,7 +20,7 @@ print_ver_ split # invalid number of chunks -echo 'split: 1o: invalid number of chunks' > exp +echo "split: invalid number of chunks: '1o'" > exp split -n l/1o 2>err && fail=1 compare exp err || fail=1 @@ -53,8 +53,9 @@ lines=\ printf "%s" "$lines" | tr '~' '\n' > in || framework_failure_ -echo 'split: 16: invalid chunk number' > exp -split -n l/16/15 in 2>err && fail=1 +echo "split: invalid chunk number: '16'" > exp +split -n l/16/15 in 2>err.t && fail=1 +sed "s/': .*/'/" < err.t > err || framework_failure_ compare exp err || fail=1 printf '%s' "\ diff --git a/tests/split/line-bytes.sh b/tests/split/line-bytes.sh index 5f6f505b..6e2f1376 100755 --- a/tests/split/line-bytes.sh +++ b/tests/split/line-bytes.sh @@ -1,7 +1,7 @@ #!/bin/sh # test -C, --lines-bytes -# Copyright (C) 2013-2014 Free Software Foundation, Inc. +# Copyright (C) 2013-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/split/lines.sh b/tests/split/lines.sh index 09dc8c77..5363eb4d 100755 --- a/tests/split/lines.sh +++ b/tests/split/lines.sh @@ -1,7 +1,7 @@ #!/bin/sh # show that 'split --lines=2' works. -# Copyright (C) 2002-2014 Free Software Foundation, Inc. +# Copyright (C) 2002-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/split/numeric.sh b/tests/split/numeric.sh index 6467cb7f..9c4e1c55 100755 --- a/tests/split/numeric.sh +++ b/tests/split/numeric.sh @@ -1,7 +1,7 @@ #!/bin/sh # Show that split --numeric-suffixes[=from] works. -# Copyright (C) 2012-2014 Free Software Foundation, Inc. +# Copyright (C) 2012-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -56,10 +56,10 @@ compare exp-3 x03 || fail=1 # Check that split failed when suffix length is not large enough for # the numerical suffix start value -split -a 3 --numeric-suffixes=1000 in 2> /dev/null && fail=1 +returns_ 1 split -a 3 --numeric-suffixes=1000 in 2>/dev/null || fail=1 # check invalid --numeric-suffixes start values are flagged -split --numeric-suffixes=-1 in 2> /dev/null && fail=1 -split --numeric-suffixes=one in 2> /dev/null && fail=1 +returns_ 1 split --numeric-suffixes=-1 in 2> /dev/null || fail=1 +returns_ 1 split --numeric-suffixes=one in 2> /dev/null || fail=1 Exit $fail diff --git a/tests/split/r-chunk.sh b/tests/split/r-chunk.sh index 8a5f221e..b03defb4 100755 --- a/tests/split/r-chunk.sh +++ b/tests/split/r-chunk.sh @@ -1,7 +1,7 @@ #!/bin/sh # test splitting into round-robin chunks -# Copyright (C) 2010-2014 Free Software Foundation, Inc. +# Copyright (C) 2010-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/split/record-sep.sh b/tests/split/record-sep.sh new file mode 100755 index 00000000..69eb27fa --- /dev/null +++ b/tests/split/record-sep.sh @@ -0,0 +1,78 @@ +#!/bin/sh +# test split with custom record separators + +# Copyright (C) 2015 Free Software Foundation, Inc. + +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. + +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. + +. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src +print_ver_ split + +NL=' +' + +for sep in "$NL" '\0' ':'; do + + test "$sep" = "$NL" && tr='\n' || tr="$sep" + + for mode in '--lines=2' '--line-bytes=4' '--number=l/3' '--number=r/3'; do + + # Generate in default mode for comparison + printf '1\n2\n3\n4\n5\n' > in || framework_failure_ + split $mode in || fail=1 + tr '\n' "$tr" < xaa > exp1 + tr '\n' "$tr" < xab > exp2 + tr '\n' "$tr" < xac > exp3 + + rm -f x?? + + # Generate output with specified --separator + printf '1\n2\n3\n4\n5\n' | tr '\n' "$tr" > in || framework_failure_ + split $mode -t "$sep" in || fail=1 + + compare exp1 xaa || fail=1 + compare exp2 xab || fail=1 + compare exp3 xac || fail=1 + test -f xad && fail=1 + done + +done + + +# +# Test usage edge cases +# + +# Should fail: '-t' requires an argument +returns_ 1 split -t </dev/null || + { warn_ "-t without argument did not trigger an error" ; fail=1 ; } + +# should fail: multi-character separator +returns_ 1 split -txx </dev/null || + { warn_ "-txx did not trigger an error" ; fail=1 ; } + +# should fail: different separators used +returns_ 1 split -ta -tb </dev/null || + { warn_ "-ta -tb did not trigger an error" ; fail=1 ; } + +# should fail: different separators used, including default +returns_ 1 split -t"$NL" -tb </dev/null || + { warn_ "-t\$NL -tb did not trigger an error" ; fail=1 ; } + +# should not fail: same separator used multiple times +split -t: -t: </dev/null || + { warn_ "-t: -t: triggered an error" ; fail=1 ; } + + +Exit $fail diff --git a/tests/split/suffix-auto-length.sh b/tests/split/suffix-auto-length.sh index 40d95af9..6ef221a1 100755 --- a/tests/split/suffix-auto-length.sh +++ b/tests/split/suffix-auto-length.sh @@ -1,7 +1,7 @@ #!/bin/sh -# Test the suffix auto widening functionality +# Test the suffix auto width functionality -# Copyright (C) 2012-2014 Free Software Foundation, Inc. +# Copyright (C) 2012-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -20,14 +20,14 @@ print_ver_ split -# ensure this feature is off when start number specified -truncate -s12 file.in -split file.in -b1 --numeric=89 && fail=1 +# ensure auto widening is off when start number specified +truncate -s12 file.in || framework_failure_ +returns_ 1 split file.in -b1 --numeric=89 || fail=1 test "$(ls -1 x* | wc -l)" = 11 || fail=1 rm -f x* -# ensure this feature works when no start num specified -truncate -s91 file.in +# ensure auto widening works when no start num specified +truncate -s91 file.in || framework_failure_ for prefix in 'x' 'xx' ''; do for add_suffix in '.txt' ''; do split file.in "$prefix" -b1 --numeric --additional-suffix="$add_suffix" \ @@ -39,4 +39,15 @@ for prefix in 'x' 'xx' ''; do done done +# ensure auto width with --number and start num < number of files +# That's the single run use case which is valid to adjust suffix len +truncate -s100 file.in || framework_failure_ +split --numeric-suffixes=1 --number=r/100 file.in || fail=1 +rm -f x* + +# ensure no auto width with --number and start num >= number of files +# That's the multi run use case which is invalid to adjust suffix len +# as that would result in an incorrect order for the total output file set +returns_ 1 split --numeric-suffixes=100 --number=r/100 file.in || fail=1 + Exit $fail diff --git a/tests/split/suffix-length.sh b/tests/split/suffix-length.sh index af5e95ee..0be3e9bc 100755 --- a/tests/split/suffix-length.sh +++ b/tests/split/suffix-length.sh @@ -1,7 +1,7 @@ #!/bin/sh # Show that split -a works. -# Copyright (C) 2002-2014 Free Software Foundation, Inc. +# Copyright (C) 2002-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -70,7 +70,7 @@ split -a2 -C1000 < /dev/null || fail=1 # Ensure that -a fails early with a -n that is too large rm -f x* -split -a2 -n1000 < /dev/null && fail=1 +returns_ 1 split -a2 -n1000 < /dev/null || fail=1 test -f xaa && fail=1 Exit $fail diff --git a/tests/tail-2/F-headers.sh b/tests/tail-2/F-headers.sh new file mode 100755 index 00000000..31d0fa6b --- /dev/null +++ b/tests/tail-2/F-headers.sh @@ -0,0 +1,59 @@ +#!/bin/sh +# Ensure tail -F distinguishes output with the correct headers +# Between coreutils 7.5 and 8.23 inclusive, 'tail -F ...' would +# not output headers for or created/renamed files in certain cases. + +# Copyright (C) 2015 Free Software Foundation, Inc. + +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. + +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. + +. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src +print_ver_ tail + +check_tail_output() +{ + local delay="$1" + grep "$tail_re" out || + { sleep $delay; return 1; } +} + +# Terminate any background tail process +cleanup_() { kill $pid 2>/dev/null && wait $pid; } + +# Speedup the non inotify case +fastpoll='-s.1 --max-unchanged-stats=1' + +for mode in '' '---disable-inotify'; do + rm -f a b out + + tail $mode -F $fastpoll a b > out 2>&1 & pid=$! + + # Wait up to 12.7s for tail to start. + tail_re="cannot open 'b'" retry_delay_ check_tail_output .1 7 || + { cat out; fail=1; } + + echo x > a + # Wait up to 12.7s for a's header to appear in the output: + tail_re='==> a <==' retry_delay_ check_tail_output .1 7 || + { echo "$0: a: unexpected delay?"; cat out; fail=1; } + + echo y > b + # Wait up to 12.7s for b's header to appear in the output: + tail_re='==> b <==' retry_delay_ check_tail_output .1 7 || + { echo "$0: b: unexpected delay?"; cat out; fail=1; } + + cleanup_ +done + +Exit $fail diff --git a/tests/tail-2/F-vs-missing.sh b/tests/tail-2/F-vs-missing.sh index d47b3022..54fe30a8 100755 --- a/tests/tail-2/F-vs-missing.sh +++ b/tests/tail-2/F-vs-missing.sh @@ -3,7 +3,7 @@ # Before coreutils-8.6, tail -F missing/file would not # notice any subsequent availability of the missing/file. -# Copyright (C) 2010-2014 Free Software Foundation, Inc. +# Copyright (C) 2010-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -21,10 +21,6 @@ . "${srcdir=.}/tests/init.sh"; path_prepend_ ./src print_ver_ tail -debug='---disable-inotify' -debug= -tail $debug -F -s.1 missing/file > out 2>&1 & pid=$! - check_tail_output() { local delay="$1" @@ -32,33 +28,32 @@ check_tail_output() { sleep $delay; return 1; } } -# Wait up to 6.3s for tail to start with diagnostic: -# tail: cannot open 'missing/file' for reading: No such file or directory -tail_re='cannot open' retry_delay_ check_tail_output .1 7 || fail=1 +# Terminate any background tail process +cleanup_() { kill $pid 2>/dev/null && wait $pid; } -mkdir missing || fail=1 -(cd missing && echo x > file) +# Speedup the non inotify case +fastpoll='-s.1 --max-unchanged-stats=1' -# Wait up to 6.3s for this to appear in the output: -# "tail: '...' has appeared; following end of new file" -tail_re='has appeared' retry_delay_ check_tail_output .1 7 || - { echo "$0: file: unexpected delay?"; cat out; fail=1; } +for mode in '' '---disable-inotify'; do + rm -rf out missing -kill -HUP $pid + tail $mode -F $fastpoll missing/file > out 2>&1 & pid=$! -cleanup() -{ - local delay="$1" - rm -rf missing || - { sleep $delay; return 1; } -} + # Wait up to 12.7s for tail to start with diagnostic: + # tail: cannot open 'missing/file' for reading: No such file or directory + tail_re='cannot open' retry_delay_ check_tail_output .1 7 || + { cat out; fail=1; } + + mkdir missing || framework_failure_ + (cd missing && echo x > file) || framework_failure_ + + # Wait up to 12.7s for this to appear in the output: + # "tail: '...' has appeared; following new file" + tail_re='has appeared' retry_delay_ check_tail_output .1 7 || + { echo "$0: file: unexpected delay?"; cat out; fail=1; } + + cleanup_ +done -# Try repeatedly to remove the temporary directory. -# This is normally unnecessary, because the containing directory will -# be removed by code from init.sh. However, when this particular test -# is run on an NFS-mounted volume, sometimes init.sh's cleanup code -# fails because the directory is not yet really empty, perhaps because -# the tail process (reading missing/file) is not yet killed. -retry_delay_ cleanup .1 6 Exit $fail diff --git a/tests/tail-2/F-vs-rename.sh b/tests/tail-2/F-vs-rename.sh index 3e31ec8c..06733fb4 100755 --- a/tests/tail-2/F-vs-rename.sh +++ b/tests/tail-2/F-vs-rename.sh @@ -1,9 +1,9 @@ #!/bin/sh -# demonstrate that tail -F works when renaming the tailed files -# Before coreutils-8.3, tail -F a b would stop tracking additions to b -# after "mv a b". +# Demonstrate that tail -F works when renaming the tailed files. +# Between coreutils 7.5 and 8.2 inclusive, 'tail -F a b' would +# stop tracking additions to b after 'mv a b'. -# Copyright (C) 2009-2014 Free Software Foundation, Inc. +# Copyright (C) 2009-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -21,55 +21,63 @@ . "${srcdir=.}/tests/init.sh"; path_prepend_ ./src print_ver_ tail -touch a b || framework_failure_ - -debug='---disable-inotify' -debug= -tail $debug -F -s.1 a b > out 2>&1 & pid=$! - check_tail_output() { local delay="$1" - grep "$tail_re" out > /dev/null || - { sleep $delay; return 1; } -} - -# Wait up to 6.3s for tail to start -echo x > a -tail_re='^x$' retry_delay_ check_tail_output .1 7 || fail=1 - -mv a b || fail=1 - -# Wait 6.3s for this diagnostic: -# tail: 'a' has become inaccessible: No such file or directory -tail_re='inaccessible' retry_delay_ check_tail_output .1 7 || fail=1 - -echo x > a -# Wait up to 6.3s for this to appear in the output: -# "tail: '...' has appeared; following end of new file" -tail_re='has appeared' retry_delay_ check_tail_output .1 7 || - { echo "$0: a: unexpected delay?"; cat out; fail=1; } - -echo y >> b -# Wait up to 6.3s for "y" to appear in the output: -tail_f_vs_rename_2() { - local delay="$1" - tr '\n' @ < out | grep '@@==> b <==@y@$' > /dev/null || - { sleep $delay; return 1; } -} -retry_delay_ tail_f_vs_rename_2 .1 7 || - { echo "$0: b: unexpected delay?"; cat out; fail=1; } - -echo z >> a -# Wait up to 6.3s for "z" to appear in the output: -tail_f_vs_rename_3() { - local delay="$1" - tr '\n' @ < out | grep '@@==> a <==@z@$' > /dev/null || + grep "$tail_re" out || { sleep $delay; return 1; } } -retry_delay_ tail_f_vs_rename_3 .1 7 || - { echo "$0: a: unexpected delay?"; cat out; fail=1; } -kill -HUP $pid +# Terminate any background tail process +cleanup_() { kill $pid 2>/dev/null && wait $pid; } + +# Speedup the non inotify case +fastpoll='-s.1 --max-unchanged-stats=1' + +for mode in '' '---disable-inotify'; do + rm -f a b out + touch a b || framework_failure_ + + tail $mode -F $fastpoll a b > out 2>&1 & pid=$! + + # Wait up to 12.7s for tail to start. + echo x > a + tail_re='^x$' retry_delay_ check_tail_output .1 7 || { cat out; fail=1; } + + mv a b || framework_failure_ + + # Wait 12.7s for this diagnostic: + # tail: 'a' has become inaccessible: No such file or directory + tail_re='inaccessible' retry_delay_ check_tail_output .1 7 || + { cat out; fail=1; } + + echo x > a + # Wait up to 12.7s for this to appear in the output: + # "tail: '...' has appeared; following new file" + tail_re='has appeared' retry_delay_ check_tail_output .1 7 || + { echo "$0: a: unexpected delay?"; cat out; fail=1; } + + echo y >> b + # Wait up to 12.7s for "y" to appear in the output: + tail_f_vs_rename_2() { + local delay="$1" + tr '\n' @ < out | grep '@@==> b <==@y@$' > /dev/null || + { sleep $delay; return 1; } + } + retry_delay_ tail_f_vs_rename_2 .1 7 || + { echo "$0: b: unexpected delay?"; cat out; fail=1; } + + echo z >> a + # Wait up to 12.7s for "z" to appear in the output: + tail_f_vs_rename_3() { + local delay="$1" + tr '\n' @ < out | grep '@@==> a <==@z@$' > /dev/null || + { sleep $delay; return 1; } + } + retry_delay_ tail_f_vs_rename_3 .1 7 || + { echo "$0: a: unexpected delay?"; cat out; fail=1; } + + cleanup_ +done Exit $fail diff --git a/tests/tail-2/append-only.sh b/tests/tail-2/append-only.sh index 7414da3e..2ea5df1f 100755 --- a/tests/tail-2/append-only.sh +++ b/tests/tail-2/append-only.sh @@ -2,7 +2,7 @@ # Ensure that tail -f works on an append-only file # Requires root access to do chattr +a, as well as an ext[23] or xfs file system -# Copyright (C) 2006-2014 Free Software Foundation, Inc. +# Copyright (C) 2006-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -21,6 +21,9 @@ print_ver_ tail require_root_ +# Terminate any background tail process +cleanup_() { kill $pid 2>/dev/null && wait $pid; } + chattr_a_works=1 touch f chattr +a f 2>/dev/null || chattr_a_works=0 @@ -32,10 +35,10 @@ if test $chattr_a_works = 0; then fi -for inotify in ---disable-inotify ''; do - sleep 1 & - pid=$! - tail --pid=$pid -f $inotify f || fail=1 +for mode in '' '---disable-inotify'; do + sleep 1 & pid=$! + tail --pid=$pid -f $mode f || fail=1 + cleanup_ done chattr -a f 2>/dev/null diff --git a/tests/tail-2/assert-2.sh b/tests/tail-2/assert-2.sh index 930e422a..67804fea 100755 --- a/tests/tail-2/assert-2.sh +++ b/tests/tail-2/assert-2.sh @@ -1,9 +1,9 @@ #!/bin/sh -# This variant of 'assert' would get a UMR reliably in 2.0.9. +# This variant of 'assert' would get a Uninit Mem Read reliably in 2.0.9. # Due to a race condition in the test, the 'assert' script would get # the UMR on Solaris only some of the time, and not at all on Linux/GNU. -# Copyright (C) 2000-2014 Free Software Foundation, Inc. +# Copyright (C) 2000-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -21,29 +21,37 @@ . "${srcdir=.}/tests/init.sh"; path_prepend_ ./src print_ver_ tail -# Not "expensive" per se, but sleeping for so long is annoying. -very_expensive_ +check_tail_output() +{ + local delay="$1" + grep "$tail_re" out || + { sleep $delay; return 1; } +} -ok='ok ok ok' +# Terminate any background tail process +cleanup_() { kill $pid 2>/dev/null && wait $pid; } -touch a -tail --follow=name a foo > err 2>&1 & -tail_pid=$! -# Arrange for the tail process to die after 12 seconds. -(sleep 12; kill $tail_pid) & -echo $ok > f -echo sleeping for 7 seconds... -sleep 7 -mv f foo +# Speedup the non inotify case +fastpoll='-s.1 --max-unchanged-stats=1' -# echo waiting.... -wait +for mode in '' '---disable-inotify'; do + rm -f a foo out + touch a || framework_failure_ -case "$(cat err)" in - *$ok) ;; - *) fail=1;; -esac + tail $mode --follow=name $fastpoll a foo > out 2>&1 & pid=$! -test $fail = 1 && cat err + # Wait up to 12.7s for tail to start. + echo x > a || framework_failure_ + tail_re='^x$' retry_delay_ check_tail_output .1 7 || + { cat out; fail=1; break; } + + # Wait up to 12.7s for tail to notice new foo file + ok='ok ok ok' + echo "$ok" > foo || framework_failure_ + tail_re="^$ok$" retry_delay_ check_tail_output .1 7 || + { echo "$0: foo: unexpected delay?"; cat out; fail=1; break; } + + cleanup_ +done Exit $fail diff --git a/tests/tail-2/assert.sh b/tests/tail-2/assert.sh index 35a10da2..43bd1e14 100755 --- a/tests/tail-2/assert.sh +++ b/tests/tail-2/assert.sh @@ -1,7 +1,7 @@ #!/bin/sh # Test for assertion failure in "test". -# Copyright (C) 1999-2014 Free Software Foundation, Inc. +# Copyright (C) 1999-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -26,36 +26,43 @@ . "${srcdir=.}/tests/init.sh"; path_prepend_ ./src print_ver_ tail -# Not "expensive" per se, but sleeping for so long is annoying. -very_expensive_ +check_tail_output() +{ + local delay="$1" + grep "$tail_re" out || + { sleep $delay; return 1; } +} -ok='ok ok ok' +# Terminate any background tail process +cleanup_() { kill $pid 2>/dev/null && wait $pid; } -touch a foo -tail --follow=name a foo > err 2>&1 & -tail_pid=$! -# Arrange for the tail process to die after 12 seconds. -(sleep 12; kill $tail_pid) & +# Speedup the non inotify case +fastpoll='-s.1 --max-unchanged-stats=1' -echo sleeping for 7 seconds... +for mode in '' '---disable-inotify'; do + rm -f a foo out + touch a foo || framework_failure_ -# Give the backgrounded 'tail' a chance to start before removing foo. -# Otherwise, without --retry, tail wouldn't try to open 'foo' again. -sleep 1 + tail $mode --follow=name $fastpoll a foo > out 2>&1 & pid=$! -rm -f foo -sleep 6 -echo $ok > f -mv f foo + # Wait up to 12.7s for tail to start. + echo x > a || framework_failure_ + tail_re='^x$' retry_delay_ check_tail_output .1 7 || + { cat out; fail=1; break; } -# echo waiting.... -wait + # Wait 12.7s for this diagnostic: + # tail: foo: No such file or directory + rm foo || framework_failure_ + tail_re='No such file' retry_delay_ check_tail_output .1 7 || + { cat out; fail=1; break; } -case "$(cat err)" in - *$ok) ;; - *) fail=1;; -esac + # Wait up to 12.7s for tail to notice new foo file + ok='ok ok ok' + echo "$ok" > foo || framework_failure_ + tail_re="^$ok$" retry_delay_ check_tail_output .1 7 || + { echo "$0: foo: unexpected delay?"; cat out; fail=1; break; } -test $fail = 1 && cat err + cleanup_ +done Exit $fail diff --git a/tests/tail-2/big-4gb.sh b/tests/tail-2/big-4gb.sh index cfd867b7..ac07a022 100755 --- a/tests/tail-2/big-4gb.sh +++ b/tests/tail-2/big-4gb.sh @@ -2,7 +2,7 @@ # Demonstrate a bug in 'tail -cN' when operating on files of size 4G and larger # Fixed in coreutils-4.5.2. -# Copyright (C) 2002-2014 Free Software Foundation, Inc. +# Copyright (C) 2002-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/tail-2/descriptor-vs-rename.sh b/tests/tail-2/descriptor-vs-rename.sh new file mode 100755 index 00000000..083d7144 --- /dev/null +++ b/tests/tail-2/descriptor-vs-rename.sh @@ -0,0 +1,56 @@ +#!/bin/sh +# Demonstrate that tail -f works when renaming the tailed files. +# Between coreutils 7.5 and 8.23 inclusive, 'tail -f a' would +# stop tracking additions to b after 'mv a b'. + +# Copyright (C) 2015 Free Software Foundation, Inc. + +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. + +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. + +. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src +print_ver_ tail + +check_tail_output() +{ + local delay="$1" + grep "$tail_re" out || + { sleep $delay; return 1; } +} + +# Terminate any background tail process +cleanup_() { kill $pid 2>/dev/null && wait $pid; } + +# Speedup the non inotify case +fastpoll='-s.1 --max-unchanged-stats=1' + +for mode in '' '---disable-inotify'; do + rm -f a out + touch a || framework_failure_ + + tail $mode $fastpoll -f a > out 2>&1 & pid=$! + + # Wait up to 12.7s for tail to start. + echo x > a + tail_re='^x$' retry_delay_ check_tail_output .1 7 || { cat out; fail=1; } + + mv a b || framework_failure_ + + echo y >> b + # Wait up to 12.7s for "y" to appear in the output: + tail_re='^y$' retry_delay_ check_tail_output .1 7 || { cat out; fail=1; } + + cleanup_ +done + +Exit $fail diff --git a/tests/tail-2/flush-initial.sh b/tests/tail-2/flush-initial.sh index fd14eae9..a25bbeb1 100755 --- a/tests/tail-2/flush-initial.sh +++ b/tests/tail-2/flush-initial.sh @@ -1,7 +1,7 @@ #!/bin/sh # inotify-based tail -f didn't flush its initial output before blocking -# Copyright (C) 2009-2014 Free Software Foundation, Inc. +# Copyright (C) 2009-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -19,13 +19,18 @@ . "${srcdir=.}/tests/init.sh"; path_prepend_ ./src print_ver_ tail -echo line > in || fail=1 +# Speedup the non inotify case +fastpoll='-s.1 --max-unchanged-stats=1' + +# Terminate any background tail process +cleanup_() { kill $pid 2>/dev/null && wait $pid; } + +echo line > in || framework_failure_ # Output should be buffered since we're writing to file # so we're depending on the flush to write out -tail -f in > out & -tail_pid=$! +tail $fastpoll -f in > out & pid=$! -# Wait for 1.5s for the file to be flushed. +# Wait for 3.1s for the file to be flushed. tail_flush() { local delay="$1" @@ -35,6 +40,6 @@ tail_flush() } retry_delay_ tail_flush .1 5 || fail=1 -kill $tail_pid +cleanup_ Exit $fail diff --git a/tests/tail-2/follow-name.sh b/tests/tail-2/follow-name.sh index f70baec3..be68479e 100755 --- a/tests/tail-2/follow-name.sh +++ b/tests/tail-2/follow-name.sh @@ -1,7 +1,7 @@ #!/bin/sh # ensure that --follow=name does not imply --retry -# Copyright (C) 2011-2014 Free Software Foundation, Inc. +# Copyright (C) 2011-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/tail-2/follow-stdin.sh b/tests/tail-2/follow-stdin.sh index 1769ee2c..f50dd726 100755 --- a/tests/tail-2/follow-stdin.sh +++ b/tests/tail-2/follow-stdin.sh @@ -1,7 +1,7 @@ #!/bin/sh # tail -f - would fail with the initial inotify implementation -# Copyright (C) 2009-2014 Free Software Foundation, Inc. +# Copyright (C) 2009-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/tail-2/inotify-hash-abuse.sh b/tests/tail-2/inotify-hash-abuse.sh index 6492049d..6333699c 100755 --- a/tests/tail-2/inotify-hash-abuse.sh +++ b/tests/tail-2/inotify-hash-abuse.sh @@ -1,7 +1,7 @@ #!/bin/sh # Exercise an abort-inducing flaw in inotify-enabled tail -F. -# Copyright (C) 2009-2014 Free Software Foundation, Inc. +# Copyright (C) 2009-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -23,10 +23,6 @@ print_ver_ tail n=9 seq $n | xargs touch || framework_failure_ -debug='---disable-inotify' -debug= -tail $debug -s.1 -qF $(seq $n) > out 2>&1 & pid=$! - check_tail_output() { local delay="$1" @@ -34,30 +30,42 @@ check_tail_output() { sleep $delay; return 1; } } -# Wait up to 6.3s for tail to start -echo x > $n -tail_re='^x$' retry_delay_ check_tail_output .1 7 || fail=1 +# Terminate any background tail process +cleanup_() { kill $pid 2>/dev/null && wait $pid; } -mv 1 f || fail=1 +# Speedup the non inotify case +fastpoll='-s.1 --max-unchanged-stats=1' -# Wait 6.3s for this diagnostic: -# tail: '1' has become inaccessible: No such file or directory -tail_re='inaccessible' retry_delay_ check_tail_output .1 7 || fail=1 +for mode in '' '---disable-inotify'; do + rm -f out -# Trigger the bug. Before the fix, this would provoke the abort. -echo a > 1 || fail=1 + tail $mode $fastpoll -qF $(seq $n) > out 2>&1 & pid=$! -# Wait up to 2s for the buggy tail to die, -# or for the "tail: '1' has appeared; following end of new file" output -for i in $(seq 10); do - kill -0 $pid || break - grep 'has appeared;' out > /dev/null && break - sleep .2 -done + # Wait up to 12.7s for tail to start + echo x > $n + tail_re='^x$' retry_delay_ check_tail_output .1 7 || + { cat out; fail=1; } + + mv 1 f || framework_failure_ + + # Wait 12.7s for this diagnostic: + # tail: '1' has become inaccessible: No such file or directory + tail_re='inaccessible' retry_delay_ check_tail_output .1 7 || + { cat out; fail=1; } -# Kill the working tail, or fail if it has already aborted -kill $pid || fail=1 + # Trigger the bug. Before the fix, this would provoke the abort. + echo a > 1 || framework_failure_ + + # Wait up to 6.3s for the "tail: '1' has appeared; ..." message + # (or for the buggy tail to die) + tail_re='has appeared' retry_delay_ check_tail_output .1 6 || + { cat out; fail=1; } + + # Double check that tail hasn't aborted + kill -0 $pid || fail=1 + + cleanup_ +done -cat out Exit $fail diff --git a/tests/tail-2/inotify-hash-abuse2.sh b/tests/tail-2/inotify-hash-abuse2.sh index 6018448f..d641c241 100755 --- a/tests/tail-2/inotify-hash-abuse2.sh +++ b/tests/tail-2/inotify-hash-abuse2.sh @@ -2,7 +2,7 @@ # Exercise an abort-inducing flaw in inotify-enabled tail -F. # Like inotify-hash-abuse, but without a hard-coded "9". -# Copyright (C) 2009-2014 Free Software Foundation, Inc. +# Copyright (C) 2009-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -20,20 +20,27 @@ . "${srcdir=.}/tests/init.sh"; path_prepend_ ./src print_ver_ tail -touch f || framework_failure_ +# Terminate any background tail process +cleanup_() { kill $pid 2>/dev/null && wait $pid; } -debug='---disable-inotify -s .001' -debug= -tail $debug -F f & pid=$! -cleanup_() { kill $pid; } +# Speedup the non inotify case +fastpoll='-s.1 --max-unchanged-stats=1' -for i in $(seq 200); do - kill -0 $pid || break; - mv f g - touch f -done +for mode in '' '---disable-inotify'; do + touch f || framework_failure_ + + tail $mode $fastpoll -F f & pid=$! + + for i in $(seq 200); do + kill -0 $pid || break; + mv f g + touch f + done -# Kill the working tail, or fail if it has already aborted -kill $pid || fail=1 + # Ensure tail hasn't aborted + kill -0 $pid || fail=1 + + cleanup_ +done Exit $fail diff --git a/tests/tail-2/inotify-race.sh b/tests/tail-2/inotify-race.sh index c25f354a..4ce05083 100755 --- a/tests/tail-2/inotify-race.sh +++ b/tests/tail-2/inotify-race.sh @@ -5,7 +5,7 @@ # indefinitely if no *other* data is appended, but it would be printed as # soon as any additional appended data is detected. -# Copyright (C) 2009-2014 Free Software Foundation, Inc. +# Copyright (C) 2009-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -23,10 +23,11 @@ . "${srcdir=.}/tests/init.sh"; path_prepend_ ./src print_ver_ tail -# Don't run this test by default because sometimes it's skipped as noted below. -# Also gdb has a bug in Debian's gdb-6.8-3 at least that causes it to not -# cleanup and exit correctly when it receives a SIGTERM, thus hanging the test. -very_expensive_ +# Terminate any background gdb/tail process +cleanup_() { + kill $pid 2>/dev/null && wait $pid + kill $sleep 2>/dev/null && wait $sleep +} touch file || framework_failure_ touch tail.out || framework_failure_ @@ -37,37 +38,61 @@ case $(cat gdb.out) in *) skip_ "can't run gdb";; esac -break_src="$abs_top_builddir/src/tail.c" +# Break on a line rather than a symbol, to cater for inline functions +break_src="$abs_top_srcdir/src/tail.c" break_line=$(grep -n ^tail_forever_inotify "$break_src") || framework_failure_ break_line=$(echo "$break_line" | cut -d: -f1) || framework_failure_ + +# Note we get tail to monitor a background sleep process +# rather than using timeout(1), as timeout sends SIGCONT +# signals to its monitored process, and gdb (7.9 at least) +# has _intermittent_ issues with this. +# Sending SIGCONT resulted in either delayed child termination, +# or no child termination resulting in a hung test. +# See https://sourceware.org/bugzilla/show_bug.cgi?id=18364 + +env sleep 10 & sleep=$! + # See if gdb works and # tail_forever_inotify is compiled and run -timeout 10s gdb -nx --batch-silent \ +gdb -nx --batch-silent \ --eval-command="break $break_line" \ - --eval-command='run -f file' \ + --eval-command="run --pid=$sleep -f file" \ --eval-command='quit' \ - tail < /dev/null > gdb.out 2>&1 || skip_ 'breakpoint not hit' + tail < /dev/null > gdb.out 2>&1 + +kill $sleep || skip_ 'breakpoint not hit' +wait $sleep # FIXME: The above is seen to _intermittently_ fail with: # warning: .dynamic section for "/lib/libc.so.6" is not at the expected address # warning: difference appears to be caused by prelink, adjusting expectations compare /dev/null gdb.out || skip_ "can't set breakpoints in tail" +env sleep 10 & sleep=$! + # Run "tail -f file", stopping to append a line just before # inotify initialization, and then continue. Before the fix, # that just-appended line would never be output. -timeout 10s gdb -nx --batch-silent \ +gdb -nx --batch-silent \ --eval-command="break $break_line" \ - --eval-command='run -f file >> tail.out' \ + --eval-command="run --pid=$sleep -f file >> tail.out" \ --eval-command='shell echo never-seen-with-tail-7.5 >> file' \ --eval-command='continue' \ --eval-command='quit' \ - tail < /dev/null > /dev/null 2>&1 & -pid=$! + tail < /dev/null > /dev/null 2>&1 & pid=$! + +tail --pid=$pid -f tail.out | (read REPLY; kill $pid) + +# gdb has a bug in Debian's gdb-6.8-3 at least that causes it to not +# cleanup and exit correctly when it receives a SIGTERM, but +# killing sleep, should cause the tail process and thus gdb to exit. +kill $sleep +wait $sleep -tail --pid=$pid -f tail.out | (read; kill $pid) +wait $pid -test -s tail.out || fail=1 +compare /dev/null tail.out && fail=1 Exit $fail diff --git a/tests/tail-2/inotify-race2.sh b/tests/tail-2/inotify-race2.sh new file mode 100755 index 00000000..1e01d505 --- /dev/null +++ b/tests/tail-2/inotify-race2.sh @@ -0,0 +1,103 @@ +#!/bin/sh +# Ensure that tail does not ignore a tailed-forever file that has been +# replaced between tail's initial read-to-EOF, and when the inotify watches +# are established in tail_forever_inotify. That new file would be ignored +# indefinitely. + +# Copyright (C) 2015 Free Software Foundation, Inc. + +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. + +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. + +. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src +print_ver_ tail + +# Terminate any background gdb/tail process +cleanup_() { + kill $pid 2>/dev/null && wait $pid + kill $sleep 2>/dev/null && wait $sleep +} + +touch file || framework_failure_ +touch tail.out || framework_failure_ + +( timeout 10s gdb --version ) > gdb.out 2>&1 +case $(cat gdb.out) in + *'GNU gdb'*) ;; + *) skip_ "can't run gdb";; +esac + +# Break on a line rather than a symbol, to cater for inline functions +break_src="$abs_top_srcdir/src/tail.c" +break_line=$(grep -n ^tail_forever_inotify "$break_src") || framework_failure_ +break_line=$(echo "$break_line" | cut -d: -f1) || framework_failure_ + + +# Note we get tail to monitor a background sleep process +# rather than using timeout(1), as timeout sends SIGCONT +# signals to its monitored process, and gdb (7.9 at least) +# has _intermittent_ issues with this. +# Sending SIGCONT resulted in either delayed child termination, +# or no child termination resulting in a hung test. +# See https://sourceware.org/bugzilla/show_bug.cgi?id=18364 + +env sleep 10 & sleep=$! + +# See if gdb works and +# tail_forever_inotify is compiled and run +gdb -nx --batch-silent \ + --eval-command="break $break_line" \ + --eval-command="run --pid=$sleep -f file" \ + --eval-command='quit' \ + tail < /dev/null > gdb.out 2>&1 + +kill $sleep || skip_ 'breakpoint not hit' +wait $sleep + +# FIXME: The above is seen to _intermittently_ fail with: +# warning: .dynamic section for "/lib/libc.so.6" is not at the expected address +# warning: difference appears to be caused by prelink, adjusting expectations +compare /dev/null gdb.out || skip_ "can't set breakpoints in tail" + +env sleep 10 & sleep=$! + +echo never-seen-with-tail-8.23 > file.new || framework_failure_ + +# Run "tail -F file", stopping to replace with a new file before +# inotify initialization, and then continue. Before the fix, +# changes to the new file would effectively be ignored. +gdb -nx --batch-silent \ + --eval-command="break $break_line" \ + --eval-command="run --pid=$sleep -F file 2>tail.err >>tail.out" \ + --eval-command='shell mv file.new file' \ + --eval-command='continue' \ + --eval-command='quit' \ + tail < /dev/null > /dev/null 2>&1 & pid=$! + +# Note even updating the watched 'file' wouldn't have output +# anything between coreutils 7.5 and 8.23 inclusive as +# The old file descriptor (still held open by tail) was being fstat(). + +tail --pid=$pid -f tail.out | (read REPLY; kill $pid) + +# gdb has a bug in Debian's gdb-6.8-3 at least that causes it to not +# cleanup and exit correctly when it receives a SIGTERM, but +# killing sleep, should cause the tail process and thus gdb to exit. +kill $sleep +wait $sleep + +wait $pid + +compare /dev/null tail.out && { cat tail.err; fail=1; } + +Exit $fail diff --git a/tests/tail-2/inotify-rotate-resources.sh b/tests/tail-2/inotify-rotate-resources.sh new file mode 100755 index 00000000..fe5d9127 --- /dev/null +++ b/tests/tail-2/inotify-rotate-resources.sh @@ -0,0 +1,108 @@ +#!/bin/sh +# ensure that tail -F doesn't leak inotify resources + +# Copyright (C) 2015 Free Software Foundation, Inc. + +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. + +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. + +. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src +print_ver_ tail + +grep '^#define HAVE_INOTIFY 1' "$CONFIG_HEADER" >/dev/null \ + || skip_ 'inotify required' + +require_strace_ 'inotify_add_watch,inotify_rm_watch' + +# Quickly skip on remote file systems +is_local_dir_ . || skip_ 'inotify not used on remote file system' + +check_tail_output() +{ + local delay="$1" + grep "$tail_re" out > /dev/null || + { sleep $delay; return 1; } +} + +# Wait up to 25.5 seconds for grep REGEXP 'out' to succeed. +grep_timeout() { tail_re="$1" retry_delay_ check_tail_output .1 8; } + +check_strace() +{ + local delay="$1" + grep "$strace_re" strace.out > /dev/null || + { sleep $delay; return 1; } +} + +cleanup_fail() +{ + cat out + warn_ $1 + fail=1 +} + +# Terminate any background tail process +cleanup_() { kill $pid 2>/dev/null && wait $pid; } + +fastpoll='-s.1 --max-unchanged-stats=1' + +touch k || framework_failure_ + +# Note the timeout guard isn't strictly necessary here, +# however without it strace will ignore SIGTERM. +# strace does always honor SIGTERM with the -I2 option, +# though that's not available on RHEL6 for example. +timeout 180 strace -e inotify_add_watch,inotify_rm_watch -o strace.out \ + tail -F $fastpoll k >> out 2>&1 & pid=$! + +reverted_to_polling_=0 +for i in $(seq 2); do + echo $i + + echo 'tailed' > k; + + # Wait for watch on (new) file + strace_re='inotify_add_watch.*MODIFY' retry_delay_ check_strace .1 8 || + no_watch_=1 + + # Assume this is not because we're leaking + # (resources may already be depleted) + # The explicit check for inotify_rm_watch should confirm that. + grep -F 'reverting to polling' out >/dev/null && skip_ 'inotify unused' + + # Otherwise failure is unknown + test "$no_watch_" && { cat out; framework_failure_ 'no inotify_add_watch'; } + + mv k k.tmp + # wait for tail to detect the rename + grep_timeout 'inaccessible' || + { cleanup_fail 'failed to detect rename'; break; } + + # Note we strace here rather than consuming all available watches + # to be more efficient, but more importantly avoid depleting resources. + # Note also available resources can currently be tuned with: + # sudo sysctl -w fs.inotify.max_user_watches=$smallish_number + # However that impacts all processes for the current user, and also + # may not be supported in future, instead being auto scaled to RAM + # like the Linux epoll resources were. + if test "$i" -gt 1; then + strace_re='inotify_rm_watch' retry_delay_ check_strace .1 8 || + { cleanup_fail 'failed to find inotify_rm_watch syscall'; break; } + fi + + >out && >strace.out || framework_failure_ 'failed to reset output files' +done + +cleanup_ + +Exit $fail diff --git a/tests/tail-2/inotify-rotate.sh b/tests/tail-2/inotify-rotate.sh index 1c942cc3..638a3bbb 100755 --- a/tests/tail-2/inotify-rotate.sh +++ b/tests/tail-2/inotify-rotate.sh @@ -1,7 +1,7 @@ #!/bin/sh # ensure that tail -F handles rotation -# Copyright (C) 2009-2014 Free Software Foundation, Inc. +# Copyright (C) 2009-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -16,55 +16,62 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. -if test "$VERBOSE" = yes; then - set -x - tail --version -fi - . "${srcdir=.}/tests/init.sh"; path_prepend_ ./src -expensive_ +print_ver_ tail + +grep '^#define HAVE_INOTIFY 1' "$CONFIG_HEADER" >/dev/null \ + || expensive_ + +check_tail_output() +{ + local delay="$1" + grep "$tail_re" out > /dev/null || + { sleep $delay; return 1; } +} + +# Wait up to 25.5 seconds for grep REGEXP 'out' to succeed. +grep_timeout() { tail_re="$1" retry_delay_ check_tail_output .1 8; } -# Wait several seconds for grep REGEXP FILE to succeed. -# Usage: grep_timeout REGEXP FILE -grep_timeout() +# Terminate any background tail process +cleanup_() { kill $pid 2>/dev/null && wait $pid; } + +cleanup_fail() { - local j - for j in $(seq 150); do - grep $1 $2 > /dev/null && return 0 - sleep 0.1 - done - return 1 + cat out + warn_ $1 + cleanup_ + fail=1 } -# For details, see -# http://lists.gnu.org/archive/html/bug-coreutils/2009-11/msg00213.html +# Speedup the non inotify case +fastpoll='-s.1 --max-unchanged-stats=1' # Perform at least this many iterations, because on multi-core systems # the offending sequence of events can be surprisingly uncommon. +# See: http://lists.gnu.org/archive/html/bug-coreutils/2009-11/msg00213.html for i in $(seq 50); do echo $i - rm -rf k x out + rm -f k x out + # Normally less than a second is required here, but with heavy load # and a lot of disk activity, even 20 seconds is insufficient, which # leads to this timeout killing tail before the "ok" is written below. >k && >x || framework_failure_ failed to initialize files - timeout 40 tail -F k > out 2>&1 & - pid=$! - sleep .1 - echo b > k; - # wait for b to appear in out - grep_timeout b out || fail_ failed to find b in out - while :; do grep b out > /dev/null && break; done + timeout 60 tail $fastpoll -F k > out 2>&1 & pid=$! + + echo 'tailed' > k; + # wait for 'tailed' to appear in out + grep_timeout 'tailed' || { cleanup_fail 'failed to find "tailed"'; break; } + mv x k # wait for tail to detect the rename - grep_timeout tail: out || { cat out; fail_ failed to detect rename; } + grep_timeout 'tail:' || { cleanup_fail 'failed to detect rename'; break; } + echo ok >> k - found=0 - # wait up to 10 seconds for "ok" to appear in out - grep_timeout ok out && found=1 - kill $pid - test $found = 0 && { cat out; fail_ failed to detect echoed '"ok"'; } + # wait for "ok" to appear in 'out' + grep_timeout 'ok' || { cleanup_fail 'failed to detect echoed ok'; break; } + + cleanup_ done -wait Exit $fail diff --git a/tests/tail-2/pid.sh b/tests/tail-2/pid.sh index ef440818..b410478e 100755 --- a/tests/tail-2/pid.sh +++ b/tests/tail-2/pid.sh @@ -1,7 +1,7 @@ #!/bin/sh # Test the --pid option of tail. -# Copyright (C) 2003-2014 Free Software Foundation, Inc. +# Copyright (C) 2003-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -22,29 +22,29 @@ getlimits_ touch empty here || framework_failure_ +# Terminate any background tail process +cleanup_() { kill $pid 2>/dev/null && wait $pid; } -for inotify in ---disable-inotify ''; do +for mode in '' '---disable-inotify'; do # Use tail itself to create a background process to monitor, # which will auto exit when "here" is removed. - tail -f $inotify here & - bg_pid=$! + tail -f $mode here & pid=$! # Ensure that tail --pid=PID does not exit when PID is alive. - timeout 1 tail -f -s.1 --pid=$bg_pid $inotify here + timeout 1 tail -f -s.1 --pid=$pid $mode here test $? = 124 || fail=1 - # Cleanup background process - kill $bg_pid + cleanup_ # Ensure that tail --pid=PID exits with success status when PID is dead. # Use an unlikely-to-be-live PID - timeout 10 tail -f -s.1 --pid=$PID_T_MAX $inotify empty + timeout 10 tail -f -s.1 --pid=$PID_T_MAX $mode empty ret=$? test $ret = 124 && skip_ "pid $PID_T_MAX present or tail too slow" test $ret = 0 || fail=1 # Ensure tail doesn't wait for data when PID is dead - timeout 10 tail -f -s10 --pid=$PID_T_MAX $inotify empty + timeout 10 tail -f -s10 --pid=$PID_T_MAX $mode empty test $? = 124 && fail=1 done diff --git a/tests/tail-2/pipe-f.sh b/tests/tail-2/pipe-f.sh index eaa928fb..22850c49 100755 --- a/tests/tail-2/pipe-f.sh +++ b/tests/tail-2/pipe-f.sh @@ -1,7 +1,7 @@ #!/bin/sh # ensure that :|tail -f doesn't hang, per POSIX -# Copyright (C) 2009-2014 Free Software Foundation, Inc. +# Copyright (C) 2009-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/tail-2/pipe-f2.sh b/tests/tail-2/pipe-f2.sh index 13ccd0b3..71a081c3 100755 --- a/tests/tail-2/pipe-f2.sh +++ b/tests/tail-2/pipe-f2.sh @@ -1,7 +1,7 @@ #!/bin/sh # Ensure that "tail -f fifo" tails indefinitely. -# Copyright (C) 2009-2014 Free Software Foundation, Inc. +# Copyright (C) 2009-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -24,7 +24,13 @@ mkfifo_or_skip_ fifo echo 1 > fifo & echo 1 > exp || framework_failure_ -timeout 10 tail -f fifo > out & pid=$! +# Terminate any background tail process +cleanup_() { kill $pid 2>/dev/null && wait $pid; } + +# Speedup the non inotify case +fastpoll='-s.1 --max-unchanged-stats=1' + +timeout 10 tail $fastpoll -f fifo > out & pid=$! check_tail_output() { @@ -32,12 +38,14 @@ check_tail_output() test -s out || { sleep $n_sec; return 1; } } -# Wait 6.3s for tail to write something. +# Wait 12.7s for tail to write something. retry_delay_ check_tail_output .1 7 || fail=1 compare exp out || fail=1 -# Kill the still-running tail, or fail if it's gone. -kill $pid || fail=1 +# Ensure tail is still running +kill -0 $pid || fail=1 + +cleanup_ Exit $fail diff --git a/tests/tail-2/proc-ksyms.sh b/tests/tail-2/proc-ksyms.sh index 3f799649..cd007744 100755 --- a/tests/tail-2/proc-ksyms.sh +++ b/tests/tail-2/proc-ksyms.sh @@ -1,7 +1,7 @@ #!/bin/sh # Prior to textutils-2.0.17, 'tail /proc/ksyms' would segfault on Linux. -# Copyright (C) 2001-2014 Free Software Foundation, Inc. +# Copyright (C) 2001-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/tail-2/retry.sh b/tests/tail-2/retry.sh index dbe66a4e..a1497d90 100755 --- a/tests/tail-2/retry.sh +++ b/tests/tail-2/retry.sh @@ -1,7 +1,7 @@ #!/bin/sh # Exercise tail's behavior regarding missing files with/without --retry. -# Copyright (C) 2013-2014 Free Software Foundation, Inc. +# Copyright (C) 2013-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -19,6 +19,13 @@ . "${srcdir=.}/tests/init.sh"; path_prepend_ ./src print_ver_ tail +# Function to count number of lines from tail +# while ignoring transient errors due to resource limits +countlines_ () +{ + grep -Ev 'inotify (resources exhausted|cannot be used)' out | wc -l +} + # Function to check the expected line count in 'out'. # Called via retry_delay_(). Sleep some time - see retry_delay_() - if the # line count is still smaller than expected. @@ -26,34 +33,41 @@ wait4lines_ () { local delay=$1 local elc=$2 # Expected line count. - [ "$( wc -l < out )" -ge "$elc" ] || { sleep $delay; return 1; } + [ "$(countlines_)" -ge "$elc" ] || { sleep $delay; return 1; } } +# Terminate any background tail process +cleanup_() { kill $pid 2>/dev/null && wait $pid; } + +# Speedup the non inotify case +fastpoll='-s.1 --max-unchanged-stats=1' + # === Test: # Retry without --follow results in a warning. touch file tail --retry file > out 2>&1 || fail=1 -[ $( wc -l < out ) = 1 ] || fail=1 -grep -F 'tail: warning: --retry ignored' out || fail=1 +[ "$(countlines_)" = 1 ] || { cat out; fail=1; } +grep -F 'tail: warning: --retry ignored' out || { cat out; fail=1; } # === Test: # The same with a missing file: expect error message and exit 1. tail --retry missing > out 2>&1 && fail=1 -[ $( wc -l < out ) = 2 ] || fail=1 -grep -F 'tail: warning: --retry ignored' out || fail=1 +[ "$(countlines_)" = 2 ] || { cat out; fail=1; } +grep -F 'tail: warning: --retry ignored' out || { cat out; fail=1; } # === Test: # Ensure that "tail --retry --follow=name" waits for the file to appear. # Clear 'out' so that we can check its contents without races >out || framework_failure_ -timeout 10 tail -s.1 --follow=name --retry missing >out 2>&1 & pid=$! -retry_delay_ wait4lines_ .1 6 1 || fail=1 # Wait for "cannot open" error. -echo "X" > missing || fail=1 -retry_delay_ wait4lines_ .1 6 3 || fail=1 # Wait for the expected output. -kill $pid -wait $pid +timeout 10 tail $fastpoll --follow=name --retry missing >out 2>&1 & pid=$! +# Wait for "cannot open" error. +retry_delay_ wait4lines_ .1 6 1 || { cat out; fail=1; } +echo "X" > missing || framework_failure_ +# Wait for the expected output. +retry_delay_ wait4lines_ .1 6 3 || { cat out; fail=1; } +cleanup_ # Expect 3 lines in the output file. -[ $( wc -l < out ) = 3 ] || { fail=1; cat out; } +[ "$(countlines_)" = 3 ] || { fail=1; cat out; } grep -F 'cannot open' out || { fail=1; cat out; } grep -F 'has appeared' out || { fail=1; cat out; } grep '^X$' out || { fail=1; cat out; } @@ -62,14 +76,15 @@ rm -f missing out || framework_failure_ # === Test: # Ensure that "tail --retry --follow=descriptor" waits for the file to appear. # tail-8.21 failed at this (since the implementation of the inotify support). -timeout 10 tail -s.1 --follow=descriptor --retry missing >out 2>&1 & pid=$! -retry_delay_ wait4lines_ .1 6 2 || fail=1 # Wait for "cannot open" error. -echo "X" > missing || fail=1 -retry_delay_ wait4lines_ .1 6 4 || fail=1 # Wait for the expected output. -kill $pid -wait $pid +timeout 10 tail $fastpoll --follow=descriptor --retry missing >out 2>&1 & pid=$! +# Wait for "cannot open" error. +retry_delay_ wait4lines_ .1 6 2 || { cat out; fail=1; } +echo "X" > missing || framework_failure_ +# Wait for the expected output. +retry_delay_ wait4lines_ .1 6 4 || { cat out; fail=1; } +cleanup_ # Expect 4 lines in the output file. -[ $( wc -l < out ) = 4 ] || { fail=1; cat out; } +[ "$(countlines_)" = 4 ] || { fail=1; cat out; } grep -F 'retry only effective for the initial open' out \ || { fail=1; cat out; } grep -F 'cannot open' out || { fail=1; cat out; } @@ -80,13 +95,15 @@ rm -f missing out || framework_failure_ # === Test: # Ensure that tail --follow=descriptor --retry exits when the file appears # untailable. Expect exit status 1. -timeout 10 tail -s.1 --follow=descriptor --retry missing >out 2>&1 & pid=$! -retry_delay_ wait4lines_ .1 6 2 || fail=1 # Wait for "cannot open" error. -mkdir missing || fail=1 # Create untailable 'missing'. -retry_delay_ wait4lines_ .1 6 4 || fail=1 # Wait for the expected output. +timeout 10 tail $fastpoll --follow=descriptor --retry missing >out 2>&1 & pid=$! +# Wait for "cannot open" error. +retry_delay_ wait4lines_ .1 6 2 || { cat out; fail=1; } +mkdir missing || framework_failure_ # Create untailable +# Wait for the expected output. +retry_delay_ wait4lines_ .1 6 4 || { cat out; fail=1; } wait $pid rc=$? -[ $( wc -l < out ) = 4 ] || { fail=1; cat out; } +[ "$(countlines_)" = 4 ] || { fail=1; cat out; } grep -F 'retry only effective for the initial open' out \ || { fail=1; cat out; } grep -F 'cannot open' out || { fail=1; cat out; } @@ -100,14 +117,14 @@ rm -fd missing out || framework_failure_ # file to appear. Expect 2 lines in the output file ("cannot open" + # "no files remaining") and exit status 1. tail --follow=descriptor missing >out 2>&1 && fail=1 -[ $( wc -l < out ) = 2 ] || { fail=1; cat out; } +[ "$(countlines_)" = 2 ] || { fail=1; cat out; } grep -F 'cannot open' out || { fail=1; cat out; } grep -F 'no files remaining' out || { fail=1; cat out; } # === Test: # Likewise for --follow=name (without --retry). tail --follow=name missing >out 2>&1 && fail=1 -[ $( wc -l < out ) = 2 ] || { fail=1; cat out; } +[ "$(countlines_)" = 2 ] || { fail=1; cat out; } grep -F 'cannot open' out || { fail=1; cat out; } grep -F 'no files remaining' out || { fail=1; cat out; } diff --git a/tests/tail-2/start-middle.sh b/tests/tail-2/start-middle.sh index dbf9bae8..9c709aee 100755 --- a/tests/tail-2/start-middle.sh +++ b/tests/tail-2/start-middle.sh @@ -2,7 +2,7 @@ # Verify that tail works even when it's reading from a file # that is not at its beginning. Based on a report from John Roll. -# Copyright (C) 2001-2014 Free Software Foundation, Inc. +# Copyright (C) 2001-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/tail-2/symlink.sh b/tests/tail-2/symlink.sh index b21f9e15..b5dcbbd6 100755 --- a/tests/tail-2/symlink.sh +++ b/tests/tail-2/symlink.sh @@ -1,7 +1,7 @@ #!/bin/sh # Ensure tail tracks symlinks properly. -# Copyright (C) 2013-2014 Free Software Foundation, Inc. +# Copyright (C) 2013-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -19,6 +19,13 @@ . "${srcdir=.}/tests/init.sh"; path_prepend_ ./src print_ver_ tail +# Function to count number of lines from tail +# while ignoring transient errors due to resource limits +countlines_ () +{ + grep -Ev 'inotify (resources exhausted|cannot be used)' out | wc -l +} + # Function to check the expected line count in 'out'. # Called via retry_delay_(). Sleep some time - see retry_delay_() - if the # line count is still smaller than expected. @@ -26,43 +33,52 @@ wait4lines_ () { local delay=$1 local elc=$2 # Expected line count. - [ "$( wc -l < out )" -ge "$elc" ] || { sleep $delay; return 1; } + [ "$(countlines_)" -ge "$elc" ] || { sleep $delay; return 1; } } +# Terminate any background tail process +cleanup_() { kill $pid 2>/dev/null && wait $pid; } + +# speedup non inotify case +fastpoll='-s.1 --max-unchanged-stats=1' + # Ensure changing targets of cli specified symlinks are handled. # Prior to v8.22, inotify would fail to recognize changes in the targets. # Clear 'out' so that we can check its contents without races. >out || framework_failure_ ln -nsf target symlink || framework_failure_ -timeout 10 tail -s.1 -F symlink >out 2>&1 & pid=$! -retry_delay_ wait4lines_ .1 6 1 || fail=1 # Wait for "cannot open..." -echo "X" > target || fail=1 -retry_delay_ wait4lines_ .1 6 3 || fail=1 # Wait for the expected output. -kill $pid -wait $pid +timeout 10 tail $fastpoll -F symlink >out 2>&1 & pid=$! +# Wait for "cannot open..." +retry_delay_ wait4lines_ .1 6 1 || { cat out; fail=1; } +echo "X" > target || framework_failure_ +# Wait for the expected output. +retry_delay_ wait4lines_ .1 6 3 || { cat out; fail=1; } +cleanup_ # Expect 3 lines in the output file. -[ $( wc -l < out ) = 3 ] || { fail=1; cat out; } +[ "$(countlines_)" = 3 ] || { fail=1; cat out; } grep -F 'cannot open' out || { fail=1; cat out; } grep -F 'has appeared' out || { fail=1; cat out; } grep '^X$' out || { fail=1; cat out; } rm -f target out || framework_failure_ # Ensure we correctly handle the source symlink itself changing. -# I.E. that we don't operate solely on the targets. +# I.e., that we don't operate solely on the targets. # Clear 'out' so that we can check its contents without races. >out || framework_failure_ echo "X1" > target1 || framework_failure_ ln -nsf target1 symlink || framework_failure_ -timeout 10 tail -s.1 -F symlink >out 2>&1 & pid=$! -retry_delay_ wait4lines_ .1 6 1 || fail=1 # Wait for the expected output. +timeout 10 tail $fastpoll -F symlink >out 2>&1 & pid=$! +# Wait for the expected output. +retry_delay_ wait4lines_ .1 6 1 || { cat out; fail=1; } ln -nsf target2 symlink || framework_failure_ -retry_delay_ wait4lines_ .1 6 2 || fail=1 # Wait for "become inaccess..." -echo "X2" > target2 || fail=1 -retry_delay_ wait4lines_ .1 6 4 || fail=1 # Wait for the expected output. -kill $pid -wait $pid +# Wait for "become inaccess..." +retry_delay_ wait4lines_ .1 6 2 || { cat out; fail=1; } +echo "X2" > target2 || framework_failure_ +# Wait for the expected output. +retry_delay_ wait4lines_ .1 6 4 || { cat out; fail=1; } +cleanup_ # Expect 4 lines in the output file. -[ $( wc -l < out ) = 4 ] || { fail=1; cat out; } +[ "$(countlines_)" = 4 ] || { fail=1; cat out; } grep -F 'become inacce' out || { fail=1; cat out; } grep -F 'has appeared' out || { fail=1; cat out; } grep '^X1$' out || { fail=1; cat out; } @@ -70,7 +86,7 @@ grep '^X2$' out || { fail=1; cat out; } rm -f target1 target2 out || framework_failure_ # Note other symlink edge cases are currently just diagnosed -# rather than being handled. I.E. if you specify a missing item, +# rather than being handled. I.e., if you specify a missing item, # or existing file that later change to a symlink, if inotify # is in use, you'll get a diagnostic saying that link will # no longer be tailed. diff --git a/tests/tail-2/infloop-1.sh b/tests/tail-2/tail-c.sh index 37d081f3..04ff782b 100755 --- a/tests/tail-2/infloop-1.sh +++ b/tests/tail-2/tail-c.sh @@ -1,7 +1,7 @@ #!/bin/sh -# This test would fail with tail from pre-1.22i textutils. +# exercise tail -c -# Copyright (C) 1999-2014 Free Software Foundation, Inc. +# Copyright 2014-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -19,28 +19,16 @@ . "${srcdir=.}/tests/init.sh"; path_prepend_ ./src print_ver_ tail -yes > t & -yes_pid=$! -while :; do - test -s t \ - && break - sleep .1 -done -tail -n 1 t & -tail_pid=$! -kill $yes_pid - -# This test is racy, and can fail under unusual circumstances. -# On a very busy system, tail will fail to notice that $yes_pid is gone. -# Then the following kill will succeed and cause this test to fail. - -# Wait for up to 3 seconds for tail to detect the death of $yes_pid. -for i in $(seq 30); do - kill -0 $tail_pid || break - echo sleep 0.1s - sleep .1 -done +# Make sure it works on funny files in /proc and /sys. -kill $tail_pid && fail=1 || : +for file in /proc/version /sys/kernel/profiling; do + if test -r $file; then + cp -f $file copy && + tail -c -1 copy > exp1 || framework_failure_ + + tail -c -1 $file > out1 || fail=1 + compare exp1 out1 || fail=1 + fi +done Exit $fail diff --git a/tests/tail-2/tail-n0f.sh b/tests/tail-2/tail-n0f.sh index 1d020ac9..ba9f4071 100755 --- a/tests/tail-2/tail-n0f.sh +++ b/tests/tail-2/tail-n0f.sh @@ -2,7 +2,7 @@ # Make sure that 'tail -n0 -f' and 'tail -c0 -f' sleep # rather than doing what amounted to a busy-wait. -# Copyright (C) 2003-2014 Free Software Foundation, Inc. +# Copyright (C) 2003-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -35,11 +35,13 @@ chmod 0 unreadable || framework_failure_ tail -c0 unreadable || fail=1 tail -n0 unreadable || fail=1 -for inotify in ---disable-inotify ''; do +# Terminate any background tail process +cleanup_() { kill $pid 2>/dev/null && wait $pid; } + +for mode in '' '---disable-inotify'; do for file in empty nonempty; do for c_or_n in c n; do - tail --sleep=4 -${c_or_n} 0 -f $inotify $file & - pid=$! + tail --sleep=4 -${c_or_n} 0 -f $mode $file & pid=$! tail_sleeping() { local delay="$1"; sleep $delay @@ -52,7 +54,7 @@ for inotify in ---disable-inotify ''; do # Wait up to 1.5s for tail to sleep retry_delay_ tail_sleeping .1 4 || { echo $0: process in unexpected state: $state >&2; fail=1; } - kill $pid + cleanup_ done done done diff --git a/tests/tail-2/truncate.sh b/tests/tail-2/truncate.sh new file mode 100755 index 00000000..82720fda --- /dev/null +++ b/tests/tail-2/truncate.sh @@ -0,0 +1,56 @@ +#!/bin/sh +# Ensure all logs are output upon file truncation + +# Copyright (C) 2015 Free Software Foundation, Inc. + +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. + +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. + +. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src +print_ver_ tail + +check_tail_output() +{ + local delay="$1" + grep "$tail_re" out > /dev/null || + { sleep $delay; return 1; } +} + +# Terminate any background tail process +cleanup_() { kill $pid 2>/dev/null && wait $pid; } + +# Speedup the non inotify case +fastpoll='-s.1 --max-unchanged-stats=1' + +for follow in '-f' '-F'; do + for mode in '' '---disable-inotify'; do + rm -f out + seq 10 > f || framework_failure_ + + tail $follow $mode $fastpoll f > out 2>&1 & pid=$! + + # Wait up to 12.7s for tail to start + tail_re='^10$' retry_delay_ check_tail_output .1 7 || + { cat out; fail=1; } + + seq 11 15 > f || framework_failure_ + + # Wait up to 12.7s for new data + tail_re='^15$' retry_delay_ check_tail_output .1 7 || + { cat out; fail=1; } + + cleanup_ + done +done + +Exit $fail diff --git a/tests/tail-2/wait.sh b/tests/tail-2/wait.sh index 3dec55c0..2e58e821 100755 --- a/tests/tail-2/wait.sh +++ b/tests/tail-2/wait.sh @@ -2,7 +2,7 @@ # Make sure that 'tail -f' returns immediately if a file doesn't exist # while 'tail -F' waits for it to appear. -# Copyright (C) 2003-2014 Free Software Foundation, Inc. +# Copyright (C) 2003-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -20,47 +20,60 @@ . "${srcdir=.}/tests/init.sh"; path_prepend_ ./src print_ver_ tail +grep '^#define HAVE_INOTIFY 1' "$CONFIG_HEADER" >/dev/null \ + && HAVE_INOTIFY=1 + +inotify_failed_re='inotify (resources exhausted|cannot be used)' + touch here || framework_failure_ { touch unreadable && chmod a-r unreadable; } || framework_failure_ +# Terminate any background tail process +cleanup_() { kill $pid 2>/dev/null && wait $pid; } + +# speedup non inotify case +fastpoll='-s.1 --max-unchanged-stats=1' -for inotify in ---disable-inotify ''; do - timeout 10 tail -s0.1 -f $inotify not_here +for mode in '' '---disable-inotify'; do + timeout 10 tail $fastpoll -f $mode not_here test $? = 124 && fail=1 if test ! -r unreadable; then # can't test this when root - timeout 10 tail -s0.1 -f $inotify unreadable + timeout 10 tail $fastpoll -f $mode unreadable test $? = 124 && fail=1 fi - timeout 1 tail -s0.1 -f $inotify here 2>tail.err + timeout .1 tail $fastpoll -f $mode here 2>tail.err test $? = 124 || fail=1 # 'tail -F' must wait in any case. - timeout 1 tail -s0.1 -F $inotify here 2>>tail.err + timeout .1 tail $fastpoll -F $mode here 2>>tail.err test $? = 124 || fail=1 if test ! -r unreadable; then # can't test this when root - timeout 1 tail -s0.1 -F $inotify unreadable + timeout .1 tail $fastpoll -F $mode unreadable test $? = 124 || fail=1 fi - timeout 1 tail -s0.1 -F $inotify not_here + timeout .1 tail $fastpoll -F $mode not_here test $? = 124 || fail=1 - grep -Ev 'inotify (resources exhausted|cannot be used)' tail.err > x + grep -Ev "$inotify_failed_re" tail.err > x mv x tail.err compare /dev/null tail.err || fail=1 >tail.err +done +if test "$HAVE_INOTIFY"; then + # Ensure -F never follows a descriptor after rename + # either with tiny or significant delays between operations tail_F() { local delay="$1" touch k || framework_failure_ - tail -s.1 --max-unchanged-stats=2 -F $inotify k > tail.out & - pid=$! + tail $fastpoll -F $mode k >tail.out 2>tail.err & pid=$! sleep $delay mv k l sleep $delay @@ -69,12 +82,15 @@ for inotify in ---disable-inotify ''; do sleep $delay echo NO >> l sleep $delay - kill $pid + cleanup_ rm -f k l - test ! -s tail.out + test -s tail.out \ + && ! grep -E "$inotify_failed_re" tail.err >/dev/null } - retry_delay_ tail_F .1 4 || fail=1 -done + + retry_delay_ tail_F 0 1 && { cat tail.out; fail=1; } + retry_delay_ tail_F .2 1 && { cat tail.out; fail=1; } +fi Exit $fail diff --git a/tests/touch/60-seconds.sh b/tests/touch/60-seconds.sh index f0d5b89e..c8b798ea 100755 --- a/tests/touch/60-seconds.sh +++ b/tests/touch/60-seconds.sh @@ -1,7 +1,7 @@ #!/bin/sh # touch -t would mistakenly reject a time specifying "60" seconds -# Copyright (C) 2009-2014 Free Software Foundation, Inc. +# Copyright (C) 2009-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/touch/dangling-symlink.sh b/tests/touch/dangling-symlink.sh index 9adfd4bd..52845006 100755 --- a/tests/touch/dangling-symlink.sh +++ b/tests/touch/dangling-symlink.sh @@ -2,7 +2,7 @@ # Make sure touch can create a file through a dangling symlink. # This was broken in the 4.0[e-i] test releases. -# Copyright (C) 1999-2014 Free Software Foundation, Inc. +# Copyright (C) 1999-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/touch/empty-file.sh b/tests/touch/empty-file.sh index e6d1b334..17432aba 100755 --- a/tests/touch/empty-file.sh +++ b/tests/touch/empty-file.sh @@ -1,7 +1,7 @@ #!/bin/sh # Make sure touch can set the mtime on an empty file. -# Copyright (C) 1998-2014 Free Software Foundation, Inc. +# Copyright (C) 1998-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/touch/fail-diag.sh b/tests/touch/fail-diag.sh index 191ec30c..86215c68 100755 --- a/tests/touch/fail-diag.sh +++ b/tests/touch/fail-diag.sh @@ -1,7 +1,7 @@ #!/bin/sh # make sure touch gives reasonable diagnostics -# Copyright (C) 2001-2014 Free Software Foundation, Inc. +# Copyright (C) 2001-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/touch/fifo.sh b/tests/touch/fifo.sh index 71ae7791..f8c6d885 100755 --- a/tests/touch/fifo.sh +++ b/tests/touch/fifo.sh @@ -1,7 +1,7 @@ #!/bin/sh # Make sure touch works on fifos without hanging. -# Copyright (C) 2000-2014 Free Software Foundation, Inc. +# Copyright (C) 2000-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/touch/no-create-missing.sh b/tests/touch/no-create-missing.sh index 7ce63b1b..7ad1a3a9 100755 --- a/tests/touch/no-create-missing.sh +++ b/tests/touch/no-create-missing.sh @@ -1,7 +1,7 @@ #!/bin/sh # Ensure that touch -c no-such-file no longer fails (it did in 4.1.8). -# Copyright (C) 2002-2014 Free Software Foundation, Inc. +# Copyright (C) 2002-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/touch/no-dereference.sh b/tests/touch/no-dereference.sh index 0f4fdca9..fc0c7237 100755 --- a/tests/touch/no-dereference.sh +++ b/tests/touch/no-dereference.sh @@ -1,7 +1,7 @@ #!/bin/sh # Ensure that touch -h works. -# Copyright (C) 2009-2014 Free Software Foundation, Inc. +# Copyright (C) 2009-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -26,8 +26,8 @@ ln -s file link || framework_failure_ # These first tests should work on every platform. # -h does not create files, but it warns. Use -c to silence warning. -touch -h no-file 2> err && fail=1 -test -s err || fail=1 +returns_ 1 touch -h no-file 2> err || fail=1 +compare /dev/null err && fail=1 touch -h -c no-file 2> err || fail=1 compare /dev/null err || fail=1 @@ -75,7 +75,7 @@ touch -h - > file || fail=1 # If stdout is open, it is not a symlink. if env test -w /dev/stdout >/dev/null && env test ! -w /dev/stdout >&-; then - touch -h - >&- && fail=1 + returns_ 1 touch -h - >&- || fail=1 touch -h -c - >&- || fail=1 fi diff --git a/tests/touch/no-rights.sh b/tests/touch/no-rights.sh index 085c8307..baf39d40 100755 --- a/tests/touch/no-rights.sh +++ b/tests/touch/no-rights.sh @@ -2,7 +2,7 @@ # Make sure touch can update the times on a file that is neither # readable nor writable. -# Copyright (C) 1999-2014 Free Software Foundation, Inc. +# Copyright (C) 1999-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/touch/not-owner.sh b/tests/touch/not-owner.sh index c822f0b5..987b85d2 100755 --- a/tests/touch/not-owner.sh +++ b/tests/touch/not-owner.sh @@ -2,7 +2,7 @@ # Make sure that touch gives reasonable diagnostics when applied # to an unwritable directory owned by some other user. -# Copyright (C) 2003-2014 Free Software Foundation, Inc. +# Copyright (C) 2003-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/touch/now-owned-by-other.sh b/tests/touch/now-owned-by-other.sh index d01097ed..67789e79 100755 --- a/tests/touch/now-owned-by-other.sh +++ b/tests/touch/now-owned-by-other.sh @@ -1,7 +1,7 @@ #!/bin/sh # Demonstrate that "touch -d now writable-but-owned-by-other" works. -# Copyright (C) 2008-2014 Free Software Foundation, Inc. +# Copyright (C) 2008-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -28,7 +28,7 @@ chmod g+w root-owned # Ensure that the current directory is searchable by $NON_ROOT_USERNAME. chmod g+x . -chroot --user=$NON_ROOT_USERNAME / env PATH="$PATH" \ +chroot --skip-chdir --user=$NON_ROOT_USERNAME / env PATH="$PATH" \ touch -d now root-owned || fail=1 Exit $fail diff --git a/tests/touch/obsolescent.sh b/tests/touch/obsolescent.sh index 7dd1418b..3c4dc734 100755 --- a/tests/touch/obsolescent.sh +++ b/tests/touch/obsolescent.sh @@ -1,7 +1,7 @@ #!/bin/sh # Test touch with obsolescent 8- or 10-digit time stamps. -# Copyright (C) 2000-2014 Free Software Foundation, Inc. +# Copyright (C) 2000-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/touch/read-only.sh b/tests/touch/read-only.sh index d2397385..9cce6478 100755 --- a/tests/touch/read-only.sh +++ b/tests/touch/read-only.sh @@ -1,7 +1,7 @@ #!/bin/sh # ensure that touch can operate on read-only files -# Copyright (C) 2005-2014 Free Software Foundation, Inc. +# Copyright (C) 2005-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/touch/relative.sh b/tests/touch/relative.sh index 396c2f11..acfb03bf 100755 --- a/tests/touch/relative.sh +++ b/tests/touch/relative.sh @@ -2,7 +2,7 @@ # Demonstrate using a combination of --reference and --date to # set the time of a file back by an arbitrary amount. -# Copyright (C) 2004-2014 Free Software Foundation, Inc. +# Copyright (C) 2004-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/touch/trailing-slash.sh b/tests/touch/trailing-slash.sh index 7e6eb908..2d57007b 100755 --- a/tests/touch/trailing-slash.sh +++ b/tests/touch/trailing-slash.sh @@ -1,7 +1,7 @@ #!/bin/sh # Ensure that touch honors trailing slash. -# Copyright (C) 2009-2014 Free Software Foundation, Inc. +# Copyright (C) 2009-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -29,22 +29,22 @@ ln -s dir link2 || framework_failure_ # Trailing slash can only appear on directory or symlink-to-directory. # Up through coreutils 8.0, Solaris 9 failed these tests. -touch no-file/ && fail=1 -touch file/ && fail=1 -touch dangling/ && fail=1 -touch loop/ && fail=1 -touch link1/ && fail=1 +returns_ 1 touch no-file/ || fail=1 +returns_ 1 touch file/ || fail=1 +returns_ 1 touch dangling/ || fail=1 +returns_ 1 touch loop/ || fail=1 +returns_ 1 touch link1/ || fail=1 touch dir/ || fail=1 # -c silences ENOENT, but not ENOTDIR or ELOOP touch -c no-file/ || fail=1 -touch -c file/ && fail=1 +returns_ 1 touch -c file/ || fail=1 touch -c dangling/ || fail=1 -touch -c loop/ && fail=1 -touch -c link1/ && fail=1 +returns_ 1 touch -c loop/ || fail=1 +returns_ 1 touch -c link1/ || fail=1 touch -c dir/ || fail=1 -test -f no-file && fail=1 -test -f nowhere && fail=1 +returns_ 1 test -f no-file || fail=1 +returns_ 1 test -f nowhere || fail=1 # Trailing slash dereferences a symlink, even with -h. # mtime is sufficient to show pass (besides, lstat changes atime of |