diff options
Diffstat (limited to 'tests')
533 files changed, 3635 insertions, 886 deletions
diff --git a/tests/Coreutils.pm b/tests/Coreutils.pm index 71b15165..cfa41a96 100644 --- a/tests/Coreutils.pm +++ b/tests/Coreutils.pm @@ -1,7 +1,7 @@ package Coreutils; # This is a testing framework. -# Copyright (C) 1998-2013 Free Software Foundation, Inc. +# Copyright (C) 1998-2014 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/CuSkip.pm b/tests/CuSkip.pm index b296fcbc..d0cfdb54 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2011-2014 Free Software Foundation, Inc. # This program is free software: 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 024b1bc9..7e73f65e 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2007-2014 Free Software Foundation, Inc. # This program is free software: 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 4e0d1811..153b36c3 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2000-2014 Free Software Foundation, Inc. # This program is free software: 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 03849e50..c8c1da24 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2006-2014 Free Software Foundation, Inc. # This program is free software: 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 b7f6e8f9..97eadfd0 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2000-2014 Free Software Foundation, Inc. # This program is free software: 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 2f3239f3..27248af4 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2003-2014 Free Software Foundation, Inc. # This program is free software: 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 95676691..093d5181 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2003-2014 Free Software Foundation, Inc. # This program is free software: 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 6ad7a10c..cd973838 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2000-2014 Free Software Foundation, Inc. # This program is free software: 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 23fffeab..03e1db9a 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2000-2014 Free Software Foundation, Inc. # This 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,10 +31,21 @@ chmod u=rwx $file || fail=1 chmod -c g=rwx $file > out || fail=1 chmod -c g=rwx $file > empty || fail=1 -test -s empty && fail=1 +compare /dev/null empty || fail=1 case "$(cat out)" in "mode of 'f' changed from 0744 "?rwxr--r--?" to 0774 "?rwxrwxr--?) ;; *) cat out; fail=1 ;; esac +# From V5.1.0 to 8.22 this would stat the wrong file and +# give an erroneous ENOENT diagnostic +mkdir -p a/b || framework_failure_ +# chmod g+s might fail as detailed in setgid.sh +# but we don't care about those edge cases here +chmod g+s a/b +# This should never warn, but it did when special +# bits are set on b (the common case under test) +chmod -c -R g+w a 2>err +compare /dev/null err || fail=1 + Exit $fail diff --git a/tests/chmod/equal-x.sh b/tests/chmod/equal-x.sh index de7ff547..75a2fa1a 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-2013 Free Software Foundation, Inc. +# Copyright (C) 1999-2014 Free Software Foundation, Inc. # This program is free software: 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 f0dc9e67..4daba4be 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2001-2014 Free Software Foundation, Inc. # This program is free software: 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 0863a6e3..2ef2a61f 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2006-2014 Free Software Foundation, Inc. # This program is free software: 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 76c8fa40..64e81ed8 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2003-2014 Free Software Foundation, Inc. # This program is free software: 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 eaf39208..895c8348 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2005-2014 Free Software Foundation, Inc. # This program is free software: 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/setgid.sh b/tests/chmod/setgid.sh index fac37e84..0c0722de 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2001-2014 Free Software Foundation, Inc. # This program is free software: 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 30529ac1..5d5dcb58 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2008-2014 Free Software Foundation, Inc. # This program is free software: 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 e6053d0f..4a137e81 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2007-2014 Free Software Foundation, Inc. # This program is free software: 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 33166e41..9e0e0012 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2005-2014 Free Software Foundation, Inc. # This program is free software: 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/usage.sh b/tests/chmod/usage.sh index 2187e35c..7e27e7ce 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2004-2014 Free Software Foundation, Inc. # This program is free software: 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/basic.sh b/tests/chown/basic.sh index e80a065c..d4b2b9b0 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2001-2014 Free Software Foundation, Inc. # This program is free software: 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/deref.sh b/tests/chown/deref.sh index 2372f98f..e576a9f9 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2004-2014 Free Software Foundation, Inc. # This program is free software: 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 76594180..176c7c4f 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2006-2014 Free Software Foundation, Inc. # This program is free software: 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 2a05fb2d..f5ecb5bb 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2004-2014 Free Software Foundation, Inc. # This 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,6 +31,12 @@ test -n "$id_g" || framework_failure_ id_gn=$(id -gn) || framework_failure_ test -n "$id_gn" || framework_failure_ +# Systems with both local and external groups with conflicting IDs, +# were seen to fail this test erroneously with EPERM errors. +test $(getent group | grep "^$id_gn:" | wc -l) = 1 || + skip_ "group '$id_gn' not biunique: " \ + "$(getent group | grep "^$id_gn:" | tr '\n' ',')" + # FreeBSD 6.x's getgrnam fails to look up a group name containing # a space. On such a system, skip this test if the group name contains # a byte not in the portable filename character set. diff --git a/tests/cp/abuse.sh b/tests/cp/abuse.sh index 1a092dee..80eb1d62 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2007-2014 Free Software Foundation, Inc. # This program is free software: 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 d7c4f2ff..36a5d298 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2005-2014 Free Software Foundation, Inc. # This 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,7 @@ test "$acl1" = "$acl2" || fail=1 echo > a/file || framework_failure_ # add some data test -s a/file || framework_failure_ cp -p --attributes-only a/file b/ || fail=1 -test -s b/file && fail=1 +compare /dev/null b/file || fail=1 acl2=$(cd b && getfacl file) || framework_failure_ test "$acl1" = "$acl2" || fail=1 diff --git a/tests/cp/attr-existing.sh b/tests/cp/attr-existing.sh index 81334a2c..7e48fbbc 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-2013 Free Software Foundation, Inc. +# Copyright 2012-2014 Free Software Foundation, Inc. # This program is free software: 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 1244de62..033f8a93 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-2013 Free Software Foundation, Inc. +# Copyright (C) 1997-2014 Free Software Foundation, Inc. # This program is free software: 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 9dc18acd..2b11fd18 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2006-2014 Free Software Foundation, Inc. # This program is free software: 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 5b6f3138..ae2502e5 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-2013 Free Software Foundation, Inc. +# Copyright (C) 1998-2014 Free Software Foundation, Inc. # This program is free software: 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 61a60cd0..fb3bc1c8 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2010-2014 Free Software Foundation, Inc. # This program is free software: 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 93052dd6..bdc31ed5 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2000-2014 Free Software Foundation, Inc. # This program is free software: 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-a-selinux.sh b/tests/cp/cp-a-selinux.sh index e7bdcf1d..58887d27 100755 --- a/tests/cp/cp-a-selinux.sh +++ b/tests/cp/cp-a-selinux.sh @@ -1,10 +1,10 @@ #!/bin/sh -# Ensure that cp -a and cp --preserve=context work properly. +# Ensure that cp -Z, -a and cp --preserve=context work properly. # In particular, test on a writable NFS partition. # Check also locally if --preserve=context, -a and --preserve=all # does work -# Copyright (C) 2007-2013 Free Software Foundation, Inc. +# Copyright (C) 2007-2014 Free Software Foundation, Inc. # This 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,9 +37,66 @@ cp -a c d 2>err || framework_failure_ cp --preserve=context c e || framework_failure_ cp --preserve=all c f || framework_failure_ ls -Z d | grep $ctx || fail=1 -test -s err && fail=1 #there must be no stderr output for -a +# there must be no stderr output for -a +compare /dev/null err || fail=1 ls -Z e | grep $ctx || fail=1 ls -Z f | grep $ctx || fail=1 +rm -f f + +# Check handling of existing dirs which requires specific handling +# due to recursion, and was handled incorrectly in coreutils-8.22 +# Note standard permissions are updated for existing directories +# 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_ +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 -lZd restore/existing_dir; fail=1; } + +# Check restorecon (-Z) functionality for file and directory +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 +old_type_f=$(get_selinux_type c) +old_type_d=$(get_selinux_type c_d) +# Setup copies for manipulation with restorecon +# and get the adjusted type for comparison +cp -a c Z1 || fail=1 +cp -a c_d Z1_d || fail=1 +if restorecon Z1 Z1_d 2>/dev/null; then + new_type_f=$(get_selinux_type Z1) + new_type_d=$(get_selinux_type Z1_d) + + # Ensure -Z sets the type like restorecon does + cp -Z c Z2 || fail=1 + 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 + cp -aZ c Z3 || fail=1 + cp -aZ c_d Z3_d || fail=1 + cpaZ_type_f=$(get_selinux_type Z3) + cpaZ_type_d=$(get_selinux_type Z3_d) + test "$cpaZ_type_f" = "$new_type_f" || fail=1 + test "$cpaZ_type_d" = "$new_type_d" || fail=1 + + # Ensure -Z sets the type for existing files + mkdir -p existing/c_d || framework_failure_ + touch existing/c || framework_failure_ + cp -aZ c c_d existing || fail=1 + cpaZ_type_f=$(get_selinux_type existing/c) + cpaZ_type_d=$(get_selinux_type existing/c_d) + test "$cpaZ_type_f" = "$new_type_f" || fail=1 + test "$cpaZ_type_d" = "$new_type_d" || fail=1 +fi skip=0 # Create a file system, then mount it with the context=... option. @@ -54,27 +111,30 @@ test $skip = 1 \ cd mnt || framework_failure_ -echo > f || framework_failure_ - +# Create files with hopefully different contexts +echo > ../f || framework_failure_ echo > g || framework_failure_ +test "$(stat -c%C ../f)" = "$(stat -c%C g)" && + skip_ "files on separate file systems have the same security context" + # /bin/cp from coreutils-6.7-3.fc7 would fail this test by letting cp # succeed (giving no diagnostics), yet leaving the destination file empty. -cp -a f g 2>err || fail=1 +cp -a ../f g 2>err || fail=1 test -s g || fail=1 # The destination file must not be empty. -test -s err && fail=1 # There must be no stderr output. +compare /dev/null err || fail=1 # ===================================================== # Here, we expect cp to succeed and not warn with "Operation not supported" rm -f g echo > g -cp --preserve=all f g 2>err || fail=1 +cp --preserve=all ../f g 2>err || fail=1 test -s g || fail=1 grep "Operation not supported" err && fail=1 # ===================================================== # The same as above except destination does not exist rm -f g -cp --preserve=all f g 2>err || fail=1 +cp --preserve=all ../f g 2>err || fail=1 test -s g || fail=1 grep "Operation not supported" err && fail=1 @@ -94,21 +154,52 @@ echo > g # ===================================================== # Here, we expect cp to fail, because it cannot set the SELinux # security context through NFS or a mount with fixed context. -cp --preserve=context f g 2> out && fail=1 +cp --preserve=context ../f g 2> out && fail=1 # Here, we *do* expect the destination to be empty. -test -s g && fail=1 -sed "s/ .g' to .*//" out > k +compare /dev/null g || fail=1 +sed "s/ .g'.*//" out > k mv k out compare exp out || fail=1 rm -f g echo > g # Check if -a option doesn't silence --preserve=context option diagnostics -cp -a --preserve=context f g 2> out2 && fail=1 +cp -a --preserve=context ../f g 2> out2 && fail=1 # Here, we *do* expect the destination to be empty. -test -s g && fail=1 -sed "s/ .g' to .*//" out2 > k +compare /dev/null g || fail=1 +sed "s/ .g'.*//" out2 > k mv k out2 compare exp out2 || fail=1 +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 + # With relative path + $no_g_cmd + cp -Z ../f g || fail=1 + # -Z overrides -a + $no_g_cmd + cp -Z -a ../f g || fail=1 + # -Z doesn't take an arg + $no_g_cmd + cp -Z "$ctx" ../f g && fail=1 + + # Explicit context + $no_g_cmd + # Explicitly defaulting to the global $ctx should work + cp --context="$ctx" ../f g || fail=1 + # --context overrides -a + $no_g_cmd + 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 + Exit $fail diff --git a/tests/cp/cp-deref.sh b/tests/cp/cp-deref.sh index 3194fda9..63a1c22d 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2006-2014 Free Software Foundation, Inc. # This program is free software: 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 74e9b12f..9f2905e6 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2006-2014 Free Software Foundation, Inc. # This program is free software: 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-backup.sh b/tests/cp/cp-mv-backup.sh index 6ebd644c..e313b72c 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-2013 Free Software Foundation, Inc. +# Copyright (C) 1999-2014 Free Software Foundation, Inc. # This program is free software: 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 e091b44b..f46977b6 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2009-2014 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -69,19 +69,19 @@ grep -F "$xattr_pair" out_a >/dev/null \ # This should pass without diagnostics cp -a xattr/a noxattr/ 2>err || fail=1 test -s noxattr/a || fail=1 # destination file must not be empty -test -s err && fail=1 # there must be no stderr output +compare /dev/null err || fail=1 rm -f err noxattr/a # This should pass without diagnostics (new file) cp --preserve=all xattr/a noxattr/ 2>err || fail=1 test -s noxattr/a || fail=1 # destination file must not be empty -test -s err && fail=1 # there must be no stderr output +compare /dev/null err || fail=1 # This should pass without diagnostics (existing file) cp --preserve=all xattr/a noxattr/ 2>err || fail=1 test -s noxattr/a || fail=1 # destination file must not be empty -test -s err && fail=1 # there must be no stderr output +compare /dev/null err || fail=1 rm -f err noxattr/a @@ -104,6 +104,26 @@ rm -f err noxattr/a # This should pass without diagnostics mv xattr/a noxattr/ 2>err || fail=1 test -s noxattr/a || fail=1 # destination file must not be empty -test -s err && fail=1 # there must be no stderr output +compare /dev/null err || fail=1 + +# This should pass and copy xattrs of the symlink +# since the xattrs used here are not in the 'user.' namespace. +# Up to and including coreutils-8.22 xattrs of symlinks +# were not copied across file systems. +ln -s 'foo' xattr/symlink || framework_failure_ +# Note 'user.' namespace is only supported on regular files/dirs +# so use the 'trusted.' namespace here +txattr='trusted.overlay.whiteout' +if setfattr -hn "$txattr" -v y xattr/symlink; then + # Note only root can read the 'trusted.' namespace + if getfattr -h -m- -d xattr/symlink | grep -F "$txattr"; then + mv xattr/symlink noxattr/ || fail=1 + getfattr -h -m- -d noxattr/symlink | grep -F "$txattr" || fail=1 + else + echo "failed to get '$txattr' xattr. skipping symlink check" >&2 + fi +else + echo "failed to set '$txattr' xattr. skipping symlink check" >&2 +fi Exit $fail diff --git a/tests/cp/cp-parents.sh b/tests/cp/cp-parents.sh index cebf672a..e326d6bd 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2000-2014 Free Software Foundation, Inc. # This program is free software: 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/deref-slink.sh b/tests/cp/deref-slink.sh index aa3c2507..b81997be 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2000-2014 Free Software Foundation, Inc. # This program is free software: 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 83a1b4c9..2723631d 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2000-2014 Free Software Foundation, Inc. # This program is free software: 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 5bbaa813..42bf0696 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2000-2014 Free Software Foundation, Inc. # This program is free software: 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 3c5f70c5..5398656e 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2001-2014 Free Software Foundation, Inc. # This program is free software: 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-dir.sh b/tests/cp/existing-perm-dir.sh index 4c167b98..46f1be0d 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-2013 Free Software Foundation, Inc. +# Copyright 2011-2014 Free Software Foundation, Inc. # This program is free software: 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 d1b87776..c12cbb85 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2006-2014 Free Software Foundation, Inc. # This program is free software: 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/fail-perm.sh b/tests/cp/fail-perm.sh index 8665449a..83518417 100755 --- a/tests/cp/fail-perm.sh +++ b/tests/cp/fail-perm.sh @@ -1,6 +1,6 @@ #!/bin/sh -# Copyright (C) 2000-2013 Free Software Foundation, Inc. +# Copyright (C) 2000-2014 Free Software Foundation, Inc. # This program is free software: 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-2.sh b/tests/cp/fiemap-2.sh index 3f8eb006..79e2c1c4 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2011-2014 Free Software Foundation, Inc. # This program is free software: 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 ad4dfed5..7c9e3198 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2012-2014 Free Software Foundation, Inc. # This program is free software: 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 29439d7c..34aec424 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2011-2014 Free Software Foundation, Inc. # This program is free software: 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-perf.sh b/tests/cp/fiemap-perf.sh index d3747990..10bb7324 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2011-2014 Free Software Foundation, Inc. # This program is free software: 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/file-perm-race.sh b/tests/cp/file-perm-race.sh index 7157c923..5a01675c 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2006-2014 Free Software Foundation, Inc. # This program is free software: 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/into-self.sh b/tests/cp/into-self.sh index 347b8589..124be241 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2001-2014 Free Software Foundation, Inc. # This program is free software: 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 new file mode 100755 index 00000000..1b666589 --- /dev/null +++ b/tests/cp/link-deref.sh @@ -0,0 +1,125 @@ +#!/bin/sh +# Exercise cp --link's behavior regarding the dereferencing of symbolic links. + +# Copyright (C) 2013-2014 Free Software Foundation, Inc. + +# This 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 + +if grep '^#define HAVE_LINKAT 1' "$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. + ln -s testtarget test_sl || framework_failure_ + ln -P test_sl test_hl_sl || framework_failure_ + ino_sl="$(stat -c '%i' test_sl)" || framework_failure_ + ino_hl="$(stat -c '%i' test_hl_sl)" || framework_failure_ + test "$ino_sl" = "$ino_hl" && can_hardlink_to_symlink=1 +fi + +mkdir dir || framework_failure_ +> file || framework_failure_ +ln -s dir dirlink || framework_failure_ +ln -s file filelink || framework_failure_ +ln -s nowhere danglink || framework_failure_ + +# printf format of the output line. +outformat='%s|result=%s|inode=%s|type=%s|error=%s\n' + +for src in dirlink filelink danglink; do + # Get symlink's target. + tgt=$(readlink $src) || framework_failure_ + # Get inodes and file type of the symlink (src) and its target (tgt). + # Note: this will fail for 'danglink'; catch it. + ino_src="$(stat -c '%i' $src)" || framework_failure_ + typ_src="$(stat -c '%F' $src)" || framework_failure_ + ino_tgt="$(stat -c '%i' $tgt 2>/dev/null)" || ino_tgt= + typ_tgt="$(stat -c '%F' $tgt 2>/dev/null)" || typ_tgt= + + for o in '' -L -H -P; do + + # Skip the -P case where we don't or can't hardlink symlinks + ! test "$can_hardlink_to_symlink" && test "$o" = '-P' && continue + + for r in '' -R; do + + command="cp --link $o $r $src dst" + $command 2> err + result=$? + + # Get inode and file type of the destination (which may fail, too). + ino_dst="$(stat -c '%i' dst 2>/dev/null)" || ini_dst= + typ_dst="$(stat -c '%F' dst 2>/dev/null)" || typ_dst= + + # Print the actual result in a certain format. + printf "$outformat" \ + "$command" \ + "$result" \ + "$ino_dst" \ + "$typ_dst" \ + "$(cat err)" \ + > out + + # What was expected? + if [ "$o" = "-P" ]; then + # cp --link should not dereference if -P is given. + exp_result=0 + exp_inode=$ino_src + exp_ftype=$typ_src + exp_error= + elif [ "$src" = 'danglink' ]; then + # Dereferencing should fail for the 'danglink'. + exp_result=1 + exp_inode= + exp_ftype= + exp_error="cp: cannot stat 'danglink': No such file or directory" + elif [ "$src" = 'dirlink' ] && [ "$r" != '-R' ]; then + # Dereferencing should fail for the 'dirlink' without -R. + exp_result=1 + exp_inode= + exp_ftype= + exp_error="cp: omitting directory 'dirlink'" + elif [ "$src" = 'dirlink' ]; then + # cp --link -R 'dirlink' should create a new directory. + exp_result=0 + exp_inode=$ino_dst + exp_ftype=$typ_dst + exp_error= + else + # cp --link 'filelink' should create a hard link to the target. + exp_result=0 + exp_inode=$ino_tgt + exp_ftype=$typ_tgt + exp_error= + fi + + # Print the expected result in a certain format. + printf "$outformat" \ + "$command" \ + "$exp_result" \ + "$exp_inode" \ + "$exp_ftype" \ + "$exp_error" \ + > exp + + compare exp out || { ls -lid $src $tgt dst; fail=1; } + + rm -rf dst err exp out || framework_failure_ + done + done +done + +Exit $fail diff --git a/tests/cp/link-heap.sh b/tests/cp/link-heap.sh index 62d7de00..594ade89 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2008-2014 Free Software Foundation, Inc. # This 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 @@ . "${srcdir=.}/tests/init.sh"; path_prepend_ ./src print_ver_ cp expensive_ -require_ulimit_ +require_ulimit_v_ a=$(printf %031d 0) b=$(printf %031d 1) diff --git a/tests/cp/link-no-deref.sh b/tests/cp/link-no-deref.sh index 755d8922..13fd0ef5 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2006-2014 Free Software Foundation, Inc. # This program is free software: 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 52df843c..c2cfd4ae 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2001-2014 Free Software Foundation, Inc. # This program is free software: 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 b328b717..9aab0b85 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2011-2014 Free Software Foundation, Inc. # This program is free software: 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 50e42bd8..034a6275 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2000-2014 Free Software Foundation, Inc. # This program is free software: 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 b606784e..6969e8bd 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2012-2014 Free Software Foundation, Inc. # This 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,6 +30,7 @@ . "${srcdir=.}/tests/init.sh"; path_prepend_ ./src print_ver_ cp +require_gcc_shared_ # Replace each stat call with a call to this wrapper. cat > k.c <<'EOF' || framework_failure_ @@ -57,8 +58,8 @@ __xstat (int ver, const char *path, struct stat *st) EOF # Then compile/link it: -$CC -shared -fPIC -O2 k.c -o k.so -ldl \ - || framework_failure_ 'failed to compile with -shared -fPIC' +gcc_shared_ k.c k.so \ + || framework_failure_ 'failed to build shared library' touch d2 || framework_failure_ echo xyz > src || framework_failure_ diff --git a/tests/cp/no-ctx.sh b/tests/cp/no-ctx.sh new file mode 100755 index 00000000..8b1328a4 --- /dev/null +++ b/tests/cp/no-ctx.sh @@ -0,0 +1,64 @@ +#!/bin/sh +# Ensure we handle file systems returning no SELinux context, +# which triggered a segmentation fault in coreutils-8.22. +# 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. + +# This 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 +require_gcc_shared_ +require_selinux_ + +# Replace each getfilecon and lgetfilecon call with a call to these stubs. +cat > k.c <<'EOF' || framework_failure_ +#include <stdio.h> +#include <selinux/selinux.h> +#include <errno.h> + +int getfilecon (const char *path, char **con) +{ + /* Leave a marker so we can identify if the function was intercepted. */ + fclose(fopen("preloaded", "w")); + + errno=ENODATA; + return -1; +} + +int lgetfilecon (const char *path, char **con) +{ return getfilecon (path, con); } +EOF + +# Then compile/link it: +gcc_shared_ k.c k.so \ + || skip_ 'failed to build SELinux shared library' + +touch file_src + +# New file with SELinux context optionally included +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 + +# 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 + +test -e preloaded || skip_ 'LD_PRELOAD interception failed' + +Exit $fail diff --git a/tests/cp/no-deref-link1.sh b/tests/cp/no-deref-link1.sh index b950622f..50a94d37 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-2013 Free Software Foundation, Inc. +# Copyright (C) 1997-2014 Free Software Foundation, Inc. # This program is free software: 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 dd8af5c6..cf07bf9e 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-2013 Free Software Foundation, Inc. +# Copyright (C) 1997-2014 Free Software Foundation, Inc. # This program is free software: 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 c8dadee9..a8416855 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-2013 Free Software Foundation, Inc. +# Copyright (C) 1997-2014 Free Software Foundation, Inc. # This program is free software: 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 e46d1483..b7ea9143 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2006-2014 Free Software Foundation, Inc. # This program is free software: 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.sh b/tests/cp/parent-perm.sh index 46869e27..0a9c41e0 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2008-2014 Free Software Foundation, Inc. # This program is free software: 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 620bd55f..8311cd21 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2000-2014 Free Software Foundation, Inc. # This program is free software: 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 68369d37..ac2fcf6a 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2002-2014 Free Software Foundation, Inc. # This program is free software: 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 0a0bacdd..f141ac14 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2007-2014 Free Software Foundation, Inc. # This 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,8 +117,9 @@ t1() { u=$1; shift g=$1; shift t0 "$f" "$u" "$g" \ - setuidgid -g "$nameless_gid1,$nameless_gid2" \ - "$nameless_uid" env PATH="$tmp_path" "$@" + chroot --user=+$nameless_uid:+$nameless_gid1 \ + --groups="+$nameless_gid1,+$nameless_gid2" \ + / env PATH="$tmp_path" "$@" } t1 a0 "$nameless_uid" "$nameless_gid1" cp diff --git a/tests/cp/preserve-link.sh b/tests/cp/preserve-link.sh index 9497598b..b7e4aa28 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2011-2014 Free Software Foundation, Inc. # This program is free software: 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 188a20e5..3b36defc 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2002-2014 Free Software Foundation, Inc. # This program is free software: 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 4c12679b..c6c3548f 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2009-2014 Free Software Foundation, Inc. # This program is free software: 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 f596aced..bd665620 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2009-2014 Free Software Foundation, Inc. # This program is free software: 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 5416c7db..3fcd5aab 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2007-2014 Free Software Foundation, Inc. # This 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,20 @@ test -r $f || f=empty cat $f > out || fail=1 # With coreutils-6.9, this would create a zero-length "exp" file. -cp $f exp || fail=1 +# Skip this test on architectures like aarch64 where the inode +# number of the file changed during the cp run. +cp $f exp 2>err \ + || { fail=1; + grep 'replaced while being copied' \ + && skip_ "File $f is being replaced while being copied"; } # Don't simply compare contents; they might differ, # e.g., if CPU freq changes between cat and cp invocations. # Instead, simply compare whether they're both nonempty. -test -s out && { rm -f out; echo nonempty > out; } -test -s exp && { rm -f exp; echo nonempty > exp; } +test -s out \ + && { rm -f out; echo nonempty > out; } +test -s exp \ + && { rm -f exp; echo nonempty > exp; } compare exp out || fail=1 diff --git a/tests/cp/r-vs-symlink.sh b/tests/cp/r-vs-symlink.sh index dfe01f31..9398c9b4 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2001-2014 Free Software Foundation, Inc. # This program is free software: 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 03560506..a16fdc66 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2009-2014 Free Software Foundation, Inc. # This program is free software: 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-perm.sh b/tests/cp/reflink-perm.sh index 3f22630e..52f5e257 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2009-2014 Free Software Foundation, Inc. # This 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_ cp -: > time_check -: > file +> time_check +> file ts='2009-08-28 19:00' touch -d "$ts" file || framework_failure_ test time_check -nt file || skip_ "The system clock is wrong" @@ -38,8 +38,8 @@ test copy -nt file && fail=1 # Ensure that --attributes-only overrides --reflink completely echo > file2 # file with data cp --reflink=auto --preserve --attributes-only file2 empty_copy || fail=1 -test -s empty_copy && fail=1 +compare /dev/null empty_copy || fail=1 cp --reflink=always --preserve --attributes-only file2 empty_copy || fail=1 -test -s empty_copy && fail=1 +compare /dev/null empty_copy || fail=1 Exit $fail diff --git a/tests/cp/same-file.sh b/tests/cp/same-file.sh index 003a62ba..f62a9a72 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-2013 Free Software Foundation, Inc. +# Copyright (C) 1998-2014 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -189,9 +189,9 @@ cat <<\EOF | sed "$remove_these_sed" > expected 0 -bf (foo sl1 -> foo sl2 sl2.~1~ -> foo) 0 -bdf (foo sl1 -> foo sl2 -> foo sl2.~1~ -> foo) 1 -l [cp: cannot create hard link 'sl2' to 'sl1'] (foo sl1 -> foo sl2 -> foo) -0 -fl (foo sl1 -> foo sl2 -> foo) -0 -bl (foo sl1 -> foo sl2 -> foo sl2.~1~ -> foo) -0 -bfl (foo sl1 -> foo sl2 -> foo sl2.~1~ -> foo) +0 -fl (foo sl1 -> foo sl2) +0 -bl (foo sl1 -> foo sl2 sl2.~1~ -> foo) +0 -bfl (foo sl1 -> foo sl2 sl2.~1~ -> foo) 1 [cp: 'foo' and 'hardlink' are the same file] (foo hardlink) 1 -d [cp: 'foo' and 'hardlink' are the same file] (foo hardlink) diff --git a/tests/cp/slink-2-slink.sh b/tests/cp/slink-2-slink.sh index cf469160..19a28621 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2000-2014 Free Software Foundation, Inc. # This program is free software: 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 47ddf294..7aa24715 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2010-2014 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -64,7 +64,8 @@ fi f() { sed 's/ [a-z,][a-z,]*$//' $@ \ - | $AWK '/^ *[0-9]/ {printf "%d %d ", $2, (NF<5 ? $NF : $5) } END {print ""}' + | $AWK '/^ *[0-9]/ {printf "%d %d ", $2, (NF>=6 ? $6 : (NF<5 ? $NF : $5)) } + END {print ""}' } for i in $(seq 1 2 21); do diff --git a/tests/cp/sparse-to-pipe.sh b/tests/cp/sparse-to-pipe.sh index f8c1d1e8..b800e069 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2011-2014 Free Software Foundation, Inc. # This program is free software: 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.sh b/tests/cp/sparse.sh index ed288ad8..d6cc4c4b 100755 --- a/tests/cp/sparse.sh +++ b/tests/cp/sparse.sh @@ -1,7 +1,7 @@ #!/bin/sh # Test cp --sparse=always -# Copyright (C) 2006-2013 Free Software Foundation, Inc. +# Copyright (C) 2006-2014 Free Software Foundation, Inc. # This program is free software: 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/special-bits.sh b/tests/cp/special-bits.sh index c8fb3dc1..a55eea21 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2000-2014 Free Software Foundation, Inc. # This 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 @@ set _ $(ls -l b); shift; p1=$1 set _ $(ls -l b2); shift; p2=$1 test $p1 = $p2 || fail=1 -setuidgid $NON_ROOT_USERNAME env PATH="$PATH" cp -p c c2 || fail=1 +chroot --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 c416e126..ee01bb33 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2008-2014 Free Software Foundation, Inc. # This program is free software: 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 3dbfa052..599f4cdc 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2006-2014 Free Software Foundation, Inc. # This program is free software: 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 85acb69c..1ae846b6 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2000-2014 Free Software Foundation, Inc. # This program is free software: 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 383bf41f..f4a609d5 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2007-2014 Free Software Foundation, Inc. # This program is free software: 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/ascii.sh b/tests/dd/ascii.sh new file mode 100755 index 00000000..7dc39cc9 --- /dev/null +++ b/tests/dd/ascii.sh @@ -0,0 +1,73 @@ +#!/bin/sh +# test conv=ascii + +# Copyright (C) 2014 Free Software Foundation, Inc. + +# This 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 + +{ + # 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)); +} >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'; +} >exp || framework_failure_ + +dd if=in of=out conv=ascii cbs=4 || fail=1 + +compare exp out \ + || { od -v -to1 exp > exp2 || framework_failure_; + od -v -to1 out > out2 || framework_failure_; + compare exp2 out2; + fail=1; } + +Exit $fail diff --git a/tests/dd/bytes.sh b/tests/dd/bytes.sh index a2734536..1b72cc4c 100755 --- a/tests/dd/bytes.sh +++ b/tests/dd/bytes.sh @@ -1,6 +1,6 @@ #!/bin/sh -# Copyright (C) 2012-2013 Free Software Foundation, Inc. +# Copyright (C) 2012-2014 Free Software Foundation, Inc. # This program is free software: 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 8870911d..f6065cae 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2009-2014 Free Software Foundation, Inc. # This program is free software: 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 b9ad31ab..f877fddf 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-2013 Free Software Foundation, Inc. +# Copyright (C) 1999-2014 Free Software Foundation, Inc. # This 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,10 +32,12 @@ ln -s $tmp_in $tmp_sym || framework_failure_ # check status=none suppresses all output to stderr dd status=none if=$tmp_in of=/dev/null 2> err || fail=1 -test -s 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 -test -s 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 diff --git a/tests/dd/no-allocate.sh b/tests/dd/no-allocate.sh new file mode 100755 index 00000000..62170b9b --- /dev/null +++ b/tests/dd/no-allocate.sh @@ -0,0 +1,70 @@ +#!/bin/sh +# make sure that dd doesn't allocate memory unnecessarily + +# Copyright (C) 2013-2014 Free Software Foundation, Inc. + +# This 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 +require_ulimit_v_ + +# count and skip are zero, we don't need to allocate memory +(ulimit -v 20000; dd bs=30M count=0) || fail=1 +(ulimit -v 20000; dd ibs=30M count=0) || fail=1 +(ulimit -v 20000; dd obs=30M count=0) || fail=1 + +check_dd_seek_alloc() { + local file="$1" + local buf="$2" + test "$file" = 'in' && { dd_file=if; dd_op=skip; } + test "$file" = 'out' && { dd_file=of; dd_op=seek; } + test "$buf" = 'in' && { dd_buf=ibs; } + test "$buf" = 'out' && { dd_buf=obs; } + test "$buf" = 'both' && { dd_buf=bs; } + + # Provide input to the "tape" + timeout 10 dd count=1 if=/dev/zero of=tape& + + # Allocate buffer and read from the "tape" + (ulimit -v 20000; timeout 10 dd $dd_buf=30M $dd_op=1 count=0 $dd_file=tape) + local ret=$? + + # Be defensive in case the tape reader is blocked for some reason + test $ret = 124 && framework_failure_ + + # This should happen without delay, + # and is used to ensure we've not multiple writers to the "tape" + wait + + # We want the "tape" reader to fail iff allocating + # a large buffer corresponding to the file being read + case "$file$buf" in + inout|outin) test $ret = 0;; + *) test $ret != 0;; + esac +} + +# Use a fifo for which seek fails, but read does not. +# For non seekable output we need to allocate a buffer +# when simulating seeking with a read. +if mkfifo tape; then + for file in 'in' 'out'; do + for buf in 'both' 'in' 'out'; do + check_dd_seek_alloc "$file" "$buf" || fail=1 + done + done +fi + +Exit $fail diff --git a/tests/dd/nocache.sh b/tests/dd/nocache.sh index 73774053..4756663d 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2011-2014 Free Software Foundation, Inc. # This program is free software: 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/not-rewound.sh b/tests/dd/not-rewound.sh index c869eb83..4b38c216 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2000-2014 Free Software Foundation, Inc. # This program is free software: 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 bba29f87..ccae9459 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2008-2014 Free Software Foundation, Inc. # This program is free software: 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 87f6469e..5eb7ab5a 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2008-2014 Free Software Foundation, Inc. # This 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 @@ get_device_size() { # Get path to device the current dir is on. # Note df can only get fs size, not device size. -device=$(df -P . | tail -n1 | cut -d' ' -f1) || framework_failure_ +device=$(df --output=source . | tail -n1) || framework_failure_ dev_size=$(get_device_size "$device") || skip_ "failed to determine size of $device" diff --git a/tests/dd/skip-seek-past-file.sh b/tests/dd/skip-seek-past-file.sh index d379b753..8ed1d3f6 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2008-2014 Free Software Foundation, Inc. # This program is free software: 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 bb574bde..e2a7d022 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2000-2014 Free Software Foundation, Inc. # This program is free software: 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 a85db9a9..aa6d65dd 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2000-2014 Free Software Foundation, Inc. # This program is free software: 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 d9de985a..a7e90d2b 100755 --- a/tests/dd/sparse.sh +++ b/tests/dd/sparse.sh @@ -1,6 +1,6 @@ #!/bin/sh -# Copyright (C) 2012-2013 Free Software Foundation, Inc. +# Copyright (C) 2012-2014 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -61,8 +61,15 @@ if test $(kb_alloc file.in) -gt 3000; then dd if=file.in of=file.out bs=2M conv=sparse test 2500 -lt $(kb_alloc file.out) || fail=1 + # Note we recreate a sparse file first to avoid + # speculative preallocation seen in XFS, where a write() that + # extends a file can preallocate some extra space that + # a subsequent seek will not convert to a hole. + rm -f file.out + truncate --size=3M file.out + # Ensure that this 1MiB string of NULs *is* converted to a hole. - dd if=file.in of=file.out bs=1M conv=sparse + dd if=file.in of=file.out bs=1M conv=sparse,notrunc test $(kb_alloc file.out) -lt 2500 || fail=1 fi diff --git a/tests/dd/stderr.sh b/tests/dd/stderr.sh index a1b0b894..d0a304a7 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2009-2014 Free Software Foundation, Inc. # This program is free software: 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-sync.sh b/tests/dd/unblock-sync.sh index 239e2f2b..72fd2ab0 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2003-2014 Free Software Foundation, Inc. # This program is free software: 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 6dc7efc0..586b7b4d 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2009-2014 Free Software Foundation, Inc. # This program is free software: 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 635b4cb2..aff6e1b5 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2007-2014 Free Software Foundation, Inc. # This program is free software: 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 a10f2706..b2715885 100644..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-2013 Free Software Foundation, Inc. +# Copyright (C) 2012-2014 Free Software Foundation, Inc. # This 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,11 +67,11 @@ compare exp out || fail=1 # that --o (without argument) is identical to the full list. cat <<\EOF > exp || framework_failure_ -Filesystem Type Inodes IUsed IFree IUse% Size Used Avail Use% Mounted on +Filesystem Type Inodes IUsed IFree IUse% Size Used Avail Use% File Mounted on EOF df -h --o=source,fstype,itotal,iused,iavail,ipcent \ - --o=size,used,avail,pcent,target '.' >out || fail=1 + --o=size,used,avail,pcent,file,target '.' >out || fail=1 sed -e '1 { s/ [ ]*/ /g q @@ -127,4 +127,14 @@ compare exp out2 || fail=1 df --help > out || fail=1 grep ' --output' out >/dev/null || { fail=1; cat out; } +# Ensure that the FILE field contains the argument. +cat <<\EOF > exp || framework_failure_ +. +exp +EOF + +df --output=file '.' exp >out || fail=1 +sed '1d' out > out2 +compare exp out2 || fail=1 + Exit $fail diff --git a/tests/df/df-symlink.sh b/tests/df/df-symlink.sh new file mode 100755 index 00000000..6d96bd2a --- /dev/null +++ b/tests/df/df-symlink.sh @@ -0,0 +1,38 @@ +#!/bin/sh +# Ensure that df dereferences symlinks to disk nodes + +# Copyright (C) 2013-2014 Free Software Foundation, Inc. + +# This 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_ df + +disk=$(df --out=source '.' | tail -n1) || + skip_ "cannot determine '.' file system" + +ln -s "$disk" symlink || framework_failure_ + +df --out=source,target "$disk" > exp || skip_ "cannot get info for $disk" +df --out=source,target symlink > out || fail=1 +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 +df --out=source,target '.' > out || fail=1 +compare exp out || fail=1 + +Exit $fail diff --git a/tests/df/header.sh b/tests/df/header.sh index 3e61ba71..664ef800 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2006-2014 Free Software Foundation, Inc. # This program is free software: 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 896a9fe5..9ea2036d 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2012-2014 Free Software Foundation, Inc. # This 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,9 +19,16 @@ . "${srcdir=.}/tests/init.sh"; path_prepend_ ./src print_ver_ df +require_gcc_shared_ df || skip_ "df fails" +grep '^#define HAVE_MNTENT_H 1' $CONFIG_HEADER > /dev/null \ + || skip_ "no mntent.h available to confirm the interface" + +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_ #include <stdio.h> @@ -44,8 +51,8 @@ struct mntent *getmntent (FILE *fp) EOF # Then compile/link it: -$CC -shared -fPIC -ldl -O2 k.c -o k.so \ - || skip_ "getmntent hack does not work on this platform" +gcc_shared_ k.c k.so \ + || framework_failure_ 'failed to build shared library' # Test if LD_PRELOAD works: LD_PRELOAD=./k.so df diff --git a/tests/df/over-mount-device.sh b/tests/df/over-mount-device.sh new file mode 100755 index 00000000..a85ce8db --- /dev/null +++ b/tests/df/over-mount-device.sh @@ -0,0 +1,57 @@ +#!/bin/sh +# Ensure that df /dev/loop0 errors out if overmounted by another device + +# Copyright (C) 2014 Free Software Foundation, Inc. + +# This 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_ df +require_root_ + +cwd=$(pwd) +cleanup_() { cd /; umount "$cwd/mnt"; umount "$cwd/mnt"; } + +skip=0 + +# Create 2 file systems +for i in 1 2; do + dd if=/dev/zero of=blob$i bs=8192 count=200 > /dev/null 2>&1 \ + || skip=1 + mkfs -t ext2 -F blob$i \ + || skip_ "failed to create ext2 file system" +done + +# Mount both at the same place (eclipsing the first) +mkdir mnt || skip=1 +mount -oloop blob1 mnt || skip=1 +eclipsed_dev=$(df --o=source mnt | tail -n1) || skip=1 +mount -oloop blob2 mnt || skip=1 + +test $skip = 1 \ + && skip_ "insufficient mount/ext2 support" + +df . || skip_ "failed to lookup the device for the current dir" + +echo "df: cannot access '$eclipsed_dev': over-mounted by another device" > exp + +# We should get an error for the eclipsed device and continue +df $eclipsed_dev . > out 2> err && fail=1 + +# header and single entry in output +test $(wc -l < out) = 2 || fail=1 + +compare exp err || fail=1 + +Exit $fail diff --git a/tests/df/problematic-chars.sh b/tests/df/problematic-chars.sh index 86953213..bdabf0c0 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2012-2014 Free Software Foundation, Inc. # This program is free software: 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 ad5249b5..52b9014a 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2012-2014 Free Software Foundation, Inc. # This 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,65 +19,108 @@ . "${srcdir=.}/tests/init.sh"; path_prepend_ ./src print_ver_ df +require_gcc_shared_ -df || skip_ "df fails" +# We use --local here so as to not activate +# potentially very many remote mounts. +df --local || skip_ "df fails" -# Simulate an mtab file with two entries of the same device number. +export CU_NONROOT_FS=$(df --local --output=target 2>&1 | grep /. | head -n1) +test -z "$CU_NONROOT_FS" && unique_entries=1 || unique_entries=2 + +grep '^#define HAVE_MNTENT_H 1' $CONFIG_HEADER > /dev/null \ + || skip_ "no mntent.h available to confirm the interface" + +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_ #include <stdio.h> +#include <stdlib.h> +#include <string.h> #include <mntent.h> +#define STREQ(a, b) (strcmp (a, b) == 0) + struct mntent *getmntent (FILE *fp) { + static char *nonroot_fs; + static int done; + /* Prove that LD_PRELOAD works. */ - static int done = 0; if (!done) { fclose (fopen ("x", "w")); ++done; } - static struct mntent mntent; + 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]"}, + }; + + if (done == 1) + { + nonroot_fs = getenv ("CU_NONROOT_FS"); + if (!nonroot_fs || !*nonroot_fs) + nonroot_fs = "/"; /* merge into / entries. */ + } + + if (done == 1 && !getenv ("CU_TEST_DUPE_INVALID")) + done++; /* skip the first entry. */ - while (done++ < 4) + while (done++ <= 7) { - /* File system - Mounted on - fsname / - /fsname /root - /fsname / - */ - mntent.mnt_fsname = (done == 2) ? "fsname" : "/fsname"; - mntent.mnt_dir = (done == 3) ? "/root" : "/"; - mntent.mnt_type = "-"; - - return &mntent; + if (!mntents[done-2].mnt_type) + mntents[done-2].mnt_type = "-"; + if (STREQ (mntents[done-2].mnt_dir, "/NONROOT")) + mntents[done-2].mnt_dir = nonroot_fs; + return &mntents[done-2]; } + return NULL; } EOF # Then compile/link it: -gcc --std=gnu99 -shared -fPIC -ldl -O2 k.c -o k.so \ - || skip_ "getmntent hack does not work on this platform" +gcc_shared_ k.c k.so \ + || framework_failure_ 'failed to build shared library' # Test if LD_PRELOAD works: 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 2 entries, both +# The fake mtab file should only contain entries # having the same device number; thus the output should -# consist of a header and one entry. -LD_PRELOAD=./k.so df >out || fail=1 -test $(wc -l <out) -eq 2 || { fail=1; cat out; } +# consist of a header and unique entries. +LD_PRELOAD=./k.so df -T >out || fail=1 +test $(wc -l <out) -eq $(expr 1 + $unique_entries) || { 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 +test $(wc -l <out) -eq $(expr 1 + $unique_entries) || { fail=1; cat out; } # df should also prefer "/fsname" over "fsname" -test $(grep -c '/fsname' <out) -eq 1 || { fail=1; cat out; } -# ... and "/fsname" with '/' as Mounted on over '/root' -test $(grep -c '/root' <out) -eq 0 || { fail=1; cat out; } +if test "$unique_entries" = 2; then + test $(grep -c '/fsname' <out) -eq 1 || { fail=1; cat out; } + # ... and "/fsname" with '/' as Mounted on over '/.' + test $(grep -cF '/.' <out) -eq 0 || { fail=1; cat out; } +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; } # Ensure that filtering duplicates does not affect -a processing. LD_PRELOAD=./k.so df -a >out || fail=1 -test $(wc -l <out) -eq 4 || { fail=1; cat out; } +test $(wc -l <out) -eq 6 || { fail=1; cat out; } +# Ensure placeholder "-" values used for the eclipsed "virtfs" +test $(grep -c 'virtfs *-' <out) -eq 1 || { fail=1; cat out; } # Ensure that filtering duplicates does not affect # argument processing (now without the fake getmntent()). diff --git a/tests/df/skip-rootfs.sh b/tests/df/skip-rootfs.sh index 9c5d0a9f..94f32c6b 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2012-2014 Free Software Foundation, Inc. # This program is free software: 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-unprocessed.sh b/tests/df/total-unprocessed.sh index f6885d5e..9b17c8aa 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2012-2014 Free Software Foundation, Inc. # This 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,11 +25,13 @@ cat <<\EOF > exp || framework_failure_ df: no file systems processed EOF -# The following simply finds no match for the combination -# of the options --local and FS-type nfs together with the -# argument ".". It must exit non-Zero nonetheless. -df --local -t nfs --total '.' 2>out && fail=1 -compare exp out || fail=1 +# Check we exit with non-Zero. +# Note we don't check when the file system can't be determined +# as -t filtering is not applied in that case. +if test "$(df --output=fstype . | tail -n1)" != '-'; then + df -t _non_existent_fstype_ --total . 2>out && fail=1 + compare exp out || fail=1 +fi cat <<\EOF > exp || framework_failure_ df: '_does_not_exist_': No such file or directory diff --git a/tests/df/total-verify.sh b/tests/df/total-verify.sh index a045ccf9..63cbe8f7 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2008-2014 Free Software Foundation, Inc. # This program is free software: 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/unreadable.sh b/tests/df/unreadable.sh index 5ab2972b..4ad23373 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2009-2014 Free Software Foundation, Inc. # This program is free software: 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 17ca13e1..f766d4d9 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2005-2014 Free Software Foundation, Inc. # This 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,10 +27,7 @@ very_expensive_ # Get number of free kilobytes on current partition, so we can # skip this test if there is insufficient free space. - -# This technique relies on the fact that the 'Available' kilobyte -# count is the number just before the one with a trailing '%'. -free_kb=$(df -kP .|tail -1|sed 's/ [0-9][0-9]*%.*//;s/ *$//;s/.* //') +free_kb=$(df -k --output=avail . | tail -n1) case "$free_kb" in [0-9]*) ;; *) skip_ "invalid size from df: $free_kb";; diff --git a/tests/du/8gb.sh b/tests/du/8gb.sh index 8c172397..399fe7e5 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2003-2014 Free Software Foundation, Inc. # This program is free software: 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 a97e08cc..75bc9be1 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2003-2014 Free Software Foundation, Inc. # This program is free software: 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 64e68610..eebdeb04 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2010-2014 Free Software Foundation, Inc. # This program is free software: 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.sh b/tests/du/bind-mount-dir-cycle.sh index c70b41fb..ac6bf2e2 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2012-2014 Free Software Foundation, Inc. # This 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,12 +27,11 @@ mount --bind a a/b \ || skip_ "This test requires mount with a working --bind option." echo a > exp || framework_failure_ -echo "du: mount point 'a/b' already traversed" > exp-err || framework_failure_ -du a > out 2> err && fail=1 +du a > out 2> err || fail=1 sed 's/^[0-9][0-9]* //' out > k && mv k out -compare exp-err err || fail=1 +compare /dev/null err || fail=1 compare exp out || fail=1 Exit $fail diff --git a/tests/du/deref-args.sh b/tests/du/deref-args.sh index c1c5a4d4..50e525a1 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2003-2014 Free Software Foundation, Inc. # This program is free software: 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 7ac9aedb..543b7395 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2002-2014 Free Software Foundation, Inc. # This program is free software: 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/exclude.sh b/tests/du/exclude.sh index c9e0ef56..26ba598e 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2003-2014 Free Software Foundation, Inc. # This program is free software: 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 e278e70e..ba8518e1 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2003-2014 Free Software Foundation, Inc. # This program is free software: 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 d305fad0..67088434 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2011-2014 Free Software Foundation, Inc. # This program is free software: 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 7bb82ab9..13c03c0c 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2004-2014 Free Software Foundation, Inc. # This program is free software: 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 052cb4e3..1d431e4c 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2003-2014 Free Software Foundation, Inc. # This program is free software: 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 88e18945..578237c3 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2006-2014 Free Software Foundation, Inc. # This program is free software: 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 911c04fc..4c053909 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2007-2014 Free Software Foundation, Inc. # This program is free software: 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 cd00444b..663e0401 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2003-2014 Free Software Foundation, Inc. # This program is free software: 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 new file mode 100755 index 00000000..6d2c28bb --- /dev/null +++ b/tests/du/inodes.sh @@ -0,0 +1,140 @@ +#!/bin/sh +# exercise du's --inodes option + +# Copyright (C) 2010-2014 Free Software Foundation, Inc. + +# This 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 + +# An empty directory uses only 1 inode. +mkdir d || framework_failure_ +printf '1\td\n' > exp || framework_failure_ + +du --inodes d > out 2>err || fail=1 +compare exp out || fail=1 +compare /dev/null err || fail=1 + +# Add a regular file: 2 inodes used. +touch d/f || framework_failure_ +printf '2\td\n' > exp || framework_failure_ + +du --inodes d > out 2>err || fail=1 +compare exp out || fail=1 +compare /dev/null err || fail=1 + +# Add a hardlink to the file: still only 2 inodes used. +ln -v d/f d/h || framework_failure_ +du --inodes d > out 2>err || fail=1 +compare exp out || fail=1 +compare /dev/null err || fail=1 + +# Now count also hardlinks (-l,--count-links): 3 inodes. +printf '3\td\n' > exp || framework_failure_ +du --inodes -l d > out 2>err || fail=1 +compare exp out || fail=1 +compare /dev/null err || fail=1 + +# Create a directory and summarize: 3 inodes. +mkdir d/d || framework_failure_ +du --inodes -s d > out 2>err || fail=1 +compare exp out || fail=1 +compare /dev/null err || fail=1 + +# Count inodes separated: 1-2. +printf '1\td/d\n2\td\n' > exp || framework_failure_ +du --inodes -S d > out 2>err || fail=1 +compare exp out || fail=1 +compare /dev/null err || fail=1 + +# Count inodes cumulative (default): 1-3. +printf '1\td/d\n3\td\n' > exp || framework_failure_ +du --inodes d > out 2>err || fail=1 +compare exp out || fail=1 +compare /dev/null err || fail=1 + +# Count all items: 1-1-3. +# Sort output because the directory entry order is not defined. +# Also replace the hardlink with the original file name because +# the system may either return 'd/f' or 'd/h' first, and du(1) +# will ignore the other one. +printf '1\td/d\n1\td/f\n3\td\n' | sort > exp || framework_failure_ +du --inodes -a d > out.tmp 2>err || fail=1 +sed 's/h$/f/' out.tmp | sort >out || framework_failure_ +compare exp out || fail=1 +compare /dev/null err || fail=1 + +# Count all items and hardlinks again: 1-1-1-4 +# Sort output because the directory entry order is not defined. +printf '1\td/d\n1\td/h\n1\td/f\n4\td\n' | sort > exp || framework_failure_ +du --inodes -al d > out.tmp 2>err || fail=1 +sort <out.tmp >out || framework_failure_ +compare exp out || fail=1 +compare /dev/null err || fail=1 + +# Run with total (-c) line: 1-3-3 +printf '1\td/d\n3\td\n3\ttotal\n' > exp || framework_failure_ +du --inodes -c d > out 2>err || fail=1 +compare exp out || fail=1 +compare /dev/null err || fail=1 + +# Create another file in the subdirectory: 2-4 +touch d/d/f || framework_failure_ +printf '2\td/d\n4\td\n' > exp || framework_failure_ +du --inodes d > out 2>err || fail=1 +compare exp out || fail=1 +compare /dev/null err || fail=1 + +# Ensure human output (-h, --si) works. +rm -rf d || framework_failure_ +mkdir d || framework_failure_ +seq --format="d/file%g" 1023 | xargs touch || framework_failure_ +printf '1.0K\td\n' > exp || framework_failure_ +du --inodes -h d > out 2>err || fail=1 +compare exp out || fail=1 +compare /dev/null err || fail=1 + +printf '1.1k\td\n' > exp || framework_failure_ +du --inodes --si d > out 2>err || fail=1 +compare exp out || fail=1 +compare /dev/null err || fail=1 + +# Verify --inodes ignores -B. +printf '1024\td\n' > exp || framework_failure_ +du --inodes -B10 d > out 2>err || fail=1 +compare exp out || fail=1 +compare /dev/null err || fail=1 + +# Verify --inodes works with --threshold. +printf '1024\td\n' > exp || framework_failure_ +du --inodes --threshold=1000 d > out 2>err || fail=1 +compare exp out || fail=1 +compare /dev/null err || fail=1 + +du --inodes --threshold=-1000 d > out 2>err || fail=1 +compare /dev/null out || fail=1 +compare /dev/null err || fail=1 + +# Verify --inodes raises a warning for --apparent-size and -b. +du --inodes -b d > out 2>err || fail=1 +grep ' ineffective ' err >/dev/null || { fail=1; cat out err; } + +du --inodes --apparent-size d > out 2>err || fail=1 +grep ' ineffective ' err >/dev/null || { fail=1; cat out err; } + +# Ensure that --inodes is mentioned in the usage. +du --help > out || fail=1 +grep ' --inodes ' out >/dev/null || { fail=1; cat out; } +Exit $fail diff --git a/tests/du/long-from-unreadable.sh b/tests/du/long-from-unreadable.sh index 18bf384d..e343bb56 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2006-2014 Free Software Foundation, Inc. # This 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,6 +31,11 @@ . "${srcdir=.}/tests/init.sh"; path_prepend_ ./src print_ver_ du +# ecryptfs for example uses some of the file name space +# for encrypting filenames, so we must check dynamically. +name_max=$(stat -f -c %l .) +test "$name_max" -ge '200' || skip_ "NAME_MAX=$name_max is not sufficient" + proc_file=/proc/self/fd if test ! -d $proc_file; then skip_ 'This test would fail, since your system lacks /proc support.' diff --git a/tests/du/long-sloop.sh b/tests/du/long-sloop.sh index faeabbf2..5168ac00 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2006-2014 Free Software Foundation, Inc. # This program is free software: 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 36167ff0..4d201095 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2010-2014 Free Software Foundation, Inc. # This program is free software: 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 ab670984..046dad90 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2011-2014 Free Software Foundation, Inc. # This program is free software: 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-deref.sh b/tests/du/no-deref.sh index 65e5e4ad..0708bd35 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2003-2014 Free Software Foundation, Inc. # This program is free software: 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 492bfa08..625eb96a 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2003-2014 Free Software Foundation, Inc. # This program is free software: 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 f53b8853..db18d9b7 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2006-2014 Free Software Foundation, Inc. # This program is free software: 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 5300554e..605399e4 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2003-2014 Free Software Foundation, Inc. # This program is free software: 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 f0222784..3073cb1b 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2003-2014 Free Software Foundation, Inc. # This program is free software: 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 ee5217db..1985a6be 100644..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 Free Software Foundation, Inc. +# Copyright (C) 2013-2014 Free Software Foundation, Inc. # This program is free software: 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/trailing-slash.sh b/tests/du/trailing-slash.sh index 9fc51237..d6a935ad 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2002-2014 Free Software Foundation, Inc. # This program is free software: 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 f3dea761..b5ec3024 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2000-2014 Free Software Foundation, Inc. # This program is free software: 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 3846caea..b6d94b4c 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2000-2014 Free Software Foundation, Inc. # This 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,6 +43,7 @@ vars=' SIMPLE_BACKUP_SUFFIX TABSIZE TERM + COLORTERM TIME_STYLE TMPDIR VERSION_CONTROL diff --git a/tests/factor/create-test.sh b/tests/factor/create-test.sh index c81a8283..b9519725 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2012-2014 Free Software Foundation, Inc. test_name=$1 template=$2 diff --git a/tests/factor/run.sh b/tests/factor/run.sh index dfe11648..d7bae642 100644..100755 --- a/tests/factor/run.sh +++ b/tests/factor/run.sh @@ -10,7 +10,7 @@ # # See: tests/factor/create-test.sh -# Copyright (C) 2012-2013 Free Software Foundation, Inc. +# Copyright (C) 2012-2014 Free Software Foundation, Inc. . "${srcdir=.}/tests/init.sh"; path_prepend_ ./src diff --git a/tests/fmt/base.pl b/tests/fmt/base.pl index d74c1643..c6b97878 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2001-2014 Free Software Foundation, Inc. # This program is free software: 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/goal-option.sh b/tests/fmt/goal-option.sh index 6f7b0e6c..d2d60c83 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2012-2014 Free Software Foundation, Inc. # This program is free software: 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 60f4a17e..33a85016 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2002-2014 Free Software Foundation, Inc. # This program is free software: 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/id-context.sh b/tests/id/context.sh index dc023033..4629c1a0 100755 --- a/tests/misc/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-2013 Free Software Foundation, Inc. +# Copyright (C) 2008-2014 Free Software Foundation, Inc. # This program is free software: 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/gnu-zero-uids.sh b/tests/id/gnu-zero-uids.sh index 1b8739e1..89ca3097 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2011-2014 Free Software Foundation, Inc. # This program is free software: 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/no-context.sh b/tests/id/no-context.sh index 7038beb2..7b699278 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2009-2014 Free Software Foundation, Inc. # This program is free software: 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 new file mode 100755 index 00000000..6d9d74f4 --- /dev/null +++ b/tests/id/setgid.sh @@ -0,0 +1,40 @@ +#!/bin/sh +# Verify that id [-G] prints the right group when run set-GID. + +# Copyright (C) 2012-2014 Free Software Foundation, Inc. + +# This 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_ id +require_root_ + +# Construct a different group number +gp1=$(expr $NON_ROOT_GID + 1) + +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 +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 +grep -F "groups=$gp1" out || { cat out; fail=1; } + +Exit $fail diff --git a/tests/id/smack.sh b/tests/id/smack.sh new file mode 100755 index 00000000..227db3e8 --- /dev/null +++ b/tests/id/smack.sh @@ -0,0 +1,37 @@ +#!/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. + +# This 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_ id + +require_smack_ + +# Check the string "context=" presence without specified user. +id > out || fail=1 +grep 'context=' out || { cat out; fail=1; } + +# Check context=" is absent without specified user in conforming mode. +POSIXLY_CORRECT=1 id > out || fail=1 +grep 'context=' out && fail=1 + +# Check the string "context=" absence with specified user. +# But if the current user is nameless, skip this part. +id -nu > /dev/null && id $(id -nu) > out +grep 'context=' out && fail=1 + +Exit $fail diff --git a/tests/id/uid.sh b/tests/id/uid.sh new file mode 100755 index 00000000..919ffbe2 --- /dev/null +++ b/tests/id/uid.sh @@ -0,0 +1,37 @@ +#!/bin/sh +# Ensure that "id" works with numeric user ids +# Copyright (C) 2013-2014 Free Software Foundation, Inc. + +# This 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_ id + +uid=$(id -u) || fail=1 +user=$(id -nu) || fail=1 + +# Ensure the empty user spec is discarded +id '' && fail=1 + +for mode in '' '-G' '-g'; do + id $mode $user > user_out || fail=1 # lookup name for comparison + + id $mode $uid > uid_out || fail=1 # lookup name "$uid" before id "$uid" + compare user_out uid_out || fail=1 + + id $mode +$uid > uid_out || fail=1 # lookup only id "$uid" + compare user_out uid_out || fail=1 +done + +Exit $fail diff --git a/tests/id/zero.sh b/tests/id/zero.sh new file mode 100755 index 00000000..c826ff43 --- /dev/null +++ b/tests/id/zero.sh @@ -0,0 +1,64 @@ +#!/bin/sh +# Exercise "id --zero". + +# Copyright (C) 2013-2014 Free Software Foundation, Inc. + +# This 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_ id + +u="$( id -nu )" +id || fail=1 +id "$u" || fail=1 + +# id(1) should refuse --zero in default format. +echo 'id: option --zero not permitted in default format' > err-exp \ + || framework_failure_ +id --zero > out 2>err && fail=1 +compare /dev/null out || fail=1 +compare err-exp err || fail=1 + +# Create a nice list of users. +# Add $USER to ensure we have at least one explicit entry. +users="$u" +# Add a few typical users to test single group and multiple groups. +for u in root man postfix sshd nobody ; do + id $u >/dev/null 2>&1 && users="$users $u" +done +# Add $users and '' (implicit $USER) to list to process. +printf '%s\n' $users '' >> users || framework_failure_ + +# Exercise "id -z" with various options. +printf '\n' > exp || framework_failure_ +> out || framework_failure_ + +while read u ; do + for o in g gr G Gr u ur ; do + for n in '' n ; do + printf '%s: ' "id -${o}${n}[z] $u" >> exp || framework_failure_ + 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; } + head -c-1 < tmp >> out || framework_failure_ + done + done +done < users +printf '\n' >> out || framework_failure_ +tr '\0' ' ' < out > out2 || framework_failure_ +compare exp out2 || fail=1 + +Exit $fail diff --git a/tests/init.sh b/tests/init.sh index bd2048e2..fbd293d6 100644..100755 --- a/tests/init.sh +++ b/tests/init.sh @@ -1,6 +1,6 @@ # source this file; set up for tests -# Copyright (C) 2009-2013 Free Software Foundation, Inc. +# Copyright (C) 2009-2014 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -201,6 +201,8 @@ else *x*) opts_=-x ;; *) opts_= ;; esac + re_shell=$re_shell_ + export re_shell exec "$re_shell_" $opts_ "$0" --no-reexec "$@" echo "$ME_: exec failed" 1>&2 exit 127 diff --git a/tests/install/basic-1.sh b/tests/install/basic-1.sh index 2e231645..0c0d1de8 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-2013 Free Software Foundation, Inc. +# Copyright (C) 1998-2014 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -46,13 +46,17 @@ is not readable, so skipping the remaining tests in this file." cp "$just_built_dd" . || fail=1 cp $dd $dd2 || fail=1 -strip $dd2 \ - || warn_ "WARNING!!! Your strip command doesn't seem to work, +strip=-s +if ! strip $dd2; then + ! test -e $abs_top_builddir/src/coreutils \ + && warn_ "WARNING!!! Your strip command doesn't seem to work, so skipping the test of install's --strip option." + strip= +fi # This test would fail with 3.16s when using versions of strip that # don't work on read-only files (the one from binutils works fine). -ginstall -s -c -m 555 $dd $dir || fail=1 +ginstall $strip -c -m 555 $dd $dir || fail=1 # Make sure the source file is still around. test -f $dd || fail=1 @@ -112,4 +116,31 @@ ginstall: creating directory 'sub3/a/b/c' 'file' -> 'sub3/a/b/c/file' EOF +# Test -D together with -t (available since coreutils >= 8.23). +# Let ginstall create a completely new destination hierarchy. +ginstall -t sub4/a/b/c -Dv file >out 2>&1 || fail=1 +compare - out <<\EOF || fail=1 +ginstall: creating directory 'sub4' +ginstall: creating directory 'sub4/a' +ginstall: creating directory 'sub4/a/b' +ginstall: creating directory 'sub4/a/b/c' +'file' -> 'sub4/a/b/c/file' +EOF + +# Ensure that -D with an already existing file as -t's option argument fails. +touch sub4/file_exists || framework_failure_ +ginstall -t sub4/file_exists -Dv file >out 2>&1 && fail=1 +compare - out <<\EOF || fail=1 +ginstall: target 'sub4/file_exists' is not a directory +EOF + +# Ensure that -D with an already existing directory for -t's option argument +# succeeds. +mkdir sub4/dir_exists || framework_failure_ +touch sub4/dir_exists || framework_failure_ +ginstall -t sub4/dir_exists -Dv file >out 2>&1 || fail=1 +compare - out <<\EOF || fail=1 +'file' -> 'sub4/dir_exists/file' +EOF + Exit $fail diff --git a/tests/install/create-leading.sh b/tests/install/create-leading.sh index 54a81b77..0bff21db 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2000-2014 Free Software Foundation, Inc. # This program is free software: 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 d6751891..044b8bf5 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2005-2014 Free Software Foundation, Inc. # This 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_ install +print_ver_ ginstall ginstall -d d1/. || fail=1 diff --git a/tests/install/install-C-root.sh b/tests/install/install-C-root.sh index d8a8d846..473725af 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2008-2014 Free Software Foundation, Inc. # This 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,7 @@ print_ver_ ginstall require_root_ skip_if_setgid_ +skip_if_nondefault_group_ u1=1 u2=2 diff --git a/tests/install/install-C-selinux.sh b/tests/install/install-C-selinux.sh index 8513d50b..722e5b01 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2008-2014 Free Software Foundation, Inc. # This 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 @@ . "${srcdir=.}/tests/init.sh"; path_prepend_ ./src print_ver_ ginstall require_selinux_ - +skip_if_nondefault_group_ echo test > a || framework_failure_ chcon -u system_u a || skip_ "chcon doesn't work" diff --git a/tests/install/install-C.sh b/tests/install/install-C.sh index 7d3582c4..9ee1685a 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2008-2014 Free Software Foundation, Inc. # This 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,31 @@ . "${srcdir=.}/tests/init.sh"; path_prepend_ ./src print_ver_ ginstall skip_if_setgid_ +skip_if_nondefault_group_ + +# Note if a group is not specified, install(1) will assume that a file +# would be installed with the current user's group ID, and thus if the +# file is the same except that it does have a different group due to +# its parent directory being g+s for example, then the copy will be +# done again redundantly in a futile attempt to reset the group ID to +# that of the current user. +# +# install -d -g wheel -m 2775 test # Create setgid dir +# touch test/a # Create source +# install -Cv -m664 test/a test/i1 # install source with mode +# install -Cv -m664 test/i1 test/i2 # install dest +# install -Cv -m664 test/i1 test/i2 # again to see redundant install +# +# Similarly if an existing file exists that is the same and has the +# current users group ID, but when an actual install of the file would +# reset to a different group ID due to the directory being g+s for example, +# then the install will not be done when it should. +# +# install -Cv -m664 -g "$(id -nrg)" test/i1 test/i2 # set i2 to uesr's gid +# install -Cv -m664 test/i1 test/i2 # this should install but doesn't +# +# Therefore we skip the test in the presence of setgid dirs +# An additional complication on HFS is that it... mode1=0644 mode2=0755 @@ -29,7 +54,7 @@ echo test > a || framework_failure_ echo "'a' -> 'b'" > out_installed_first || framework_failure_ echo "removed 'b' 'a' -> 'b'" > out_installed_second || framework_failure_ -: > out_empty || framework_failure_ +> out_empty || framework_failure_ # destination file does not exist ginstall -Cv -m$mode1 a b > out || fail=1 diff --git a/tests/install/strip-program.sh b/tests/install/strip-program.sh index 8950d50c..874329ae 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2008-2014 Free Software Foundation, Inc. # This 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,4 +33,8 @@ echo aBc > exp || fail=1 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 +test -e dest2 && fail=1 + Exit $fail diff --git a/tests/install/trap.sh b/tests/install/trap.sh index 87887b2e..235cd1d1 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2004-2014 Free Software Foundation, Inc. # This 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 @@ print_ver_ ginstall # Use a subshell and an exec to work around a bug in FreeBSD 5.0 /bin/sh. ( # ash doesn't support "trap '' CHLD"; it knows only signal numbers. - sig=$("$abs_top_builddir/src/kill" -l CHLD 2>/dev/null) && trap '' $sig + sig=$(env kill -l CHLD 2>/dev/null) && trap '' $sig # Before 2004-04-21, install would infloop, in the 'while (wait...' loop: exec ginstall -s "$abs_top_builddir/src/ginstall$EXEEXT" . diff --git a/tests/ln/backup-1.sh b/tests/ln/backup-1.sh index d712b2f8..15aff2d0 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-2013 Free Software Foundation, Inc. +# Copyright (C) 1999-2014 Free Software Foundation, Inc. # This program is free software: 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 18ed0311..5f867bc9 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2006-2014 Free Software Foundation, Inc. # This program is free software: 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 26de099a..995d3cf6 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2009-2014 Free Software Foundation, Inc. # This program is free software: 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/misc.sh b/tests/ln/misc.sh index 5db1bacf..0615d6c5 100755 --- a/tests/ln/misc.sh +++ b/tests/ln/misc.sh @@ -1,7 +1,7 @@ #!/bin/sh # Miscellaneous tests for "ln". -# Copyright (C) 1998-2013 Free Software Foundation, Inc. +# Copyright (C) 1998-2014 Free Software Foundation, Inc. # This program is free software: 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/relative.sh b/tests/ln/relative.sh index 0418b8a0..5cf280a5 100755 --- a/tests/ln/relative.sh +++ b/tests/ln/relative.sh @@ -1,7 +1,7 @@ #!/bin/sh # Test "ln --relative". -# Copyright (C) 2012-2013 Free Software Foundation, Inc. +# Copyright (C) 2012-2014 Free Software Foundation, Inc. # This 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,4 +29,25 @@ test $(readlink usr/bin/foo) = '../lib/foo/foo' || fail=1 ln -sr usr/bin/foo usr/lib/foo/link-to-foo test $(readlink usr/lib/foo/link-to-foo) = 'foo' || fail=1 +# Correctly update an existing link, which was broken in <= 8.21 +ln -s dir1/dir2/f existing_link +ln -srf here existing_link +test $(readlink existing_link) = 'here' || fail=1 + +# Demonstrate resolved symlinks used to generate relative links +# so here, 'web/latest' will not be linked to the intermediate 'latest' link. +# You'd probably want to use realpath(1) in conjunction +# with ln(1) without --relative to give greater control. +ln -s release1 alpha +ln -s release2 beta +ln -s beta latest +mkdir web +ln -sr latest web/latest +test $(readlink web/latest) = '../release2' || fail=1 + +# Expect this to fail with exit status 1, or to succeed quietly (freebsd). +# Prior to coreutils-8.23, it would segfault. +ln -sr '' F +case $? in [01]) ;; *) fail=1;; esac + Exit $fail diff --git a/tests/ln/sf-1.sh b/tests/ln/sf-1.sh index cb864af4..17e67a9f 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-2013 Free Software Foundation, Inc. +# Copyright (C) 1997-2014 Free Software Foundation, Inc. # This 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,27 @@ print_ver_ ln echo foo > a || framework_failure_ -ln -s . b || framework_failure_ +# Check that a target directory of '.' is supported +# and that indirectly specifying the same target and link name +# through that is detected. +ln -s . b || framework_failure_ ln -sf a b > err 2>&1 && fail=1 case $(cat err) in *'are the same file') ;; *) fail=1 ;; esac +# Ensure we replace symlinks that don't or can't link to an existing target. +# coreutils-8.22 would fail to replace {ENOTDIR,ELOOP,ENAMETOOLONG}_link below. +name_max_plus1=$(expr $(stat -f -c %l .) + 1) +test $name_max_plus1 -gt 1 || skip_ 'Error determining NAME_MAX' +long_name=$(printf '%0*d' $name_max_plus1 0) +for f in '' f; do + ln -s$f missing ENOENT_link || fail=1 + ln -s$f a/b ENOTDIR_link || fail=1 + ln -s$f ELOOP_link ELOOP_link || fail=1 + ln -s$f "$long_name" ENAMETOOLONG_link || fail=1 +done + Exit $fail diff --git a/tests/ln/slash-decorated-nonexistent-dest.sh b/tests/ln/slash-decorated-nonexistent-dest.sh index baf5f77f..6e537a9b 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2009-2014 Free Software Foundation, Inc. # This program is free software: 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/target-1.sh b/tests/ln/target-1.sh index 3e59cbc9..2ddad3fc 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2002-2014 Free Software Foundation, Inc. # This program is free software: 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 9be19702..e0f1f84e 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-2013 Free Software Foundation, Inc. +## Copyright (C) 2007-2014 Free Software Foundation, Inc. ## This program is free software: you can redistribute it and/or modify ## it under the terms of the GNU General Public License as published by @@ -65,7 +65,7 @@ TESTS_ENVIRONMENT = \ abs_top_builddir='$(abs_top_builddir)' \ abs_top_srcdir='$(abs_top_srcdir)' \ abs_srcdir='$(abs_srcdir)' \ - built_programs='$(built_programs)' \ + built_programs='$(built_programs) $(single_binary_progs)' \ host_os=$(host_os) \ host_triplet='$(host_triplet)' \ srcdir='$(srcdir)' \ @@ -77,7 +77,6 @@ TESTS_ENVIRONMENT = \ EGREP='$(EGREP)' \ EXEEXT='$(EXEEXT)' \ MAKE=$(MAKE) \ - PACKAGE_BUGREPORT='$(PACKAGE_BUGREPORT)' \ PACKAGE_VERSION=$(PACKAGE_VERSION) \ PERL='$(PERL)' \ PREFERABLY_POSIX_SHELL='$(PREFERABLY_POSIX_SHELL)' \ @@ -116,16 +115,18 @@ all_root_tests = \ tests/cp/sparse-fiemap.sh \ tests/dd/skip-seek-past-dev.sh \ tests/df/problematic-chars.sh \ + tests/df/over-mount-device.sh \ tests/du/bind-mount-dir-cycle.sh \ + tests/id/setgid.sh \ tests/install/install-C-root.sh \ tests/ls/capability.sh \ tests/ls/nameless-uid.sh \ tests/misc/chcon.sh \ tests/misc/chroot-credentials.sh \ - tests/misc/id-setgid.sh \ tests/misc/selinux.sh \ tests/misc/truncate-owned-by-other.sh \ tests/mkdir/writable-under-readonly.sh \ + tests/mkdir/smack-root.sh \ tests/mv/sticky-to-xpart.sh \ tests/rm/fail-2eperm.sh \ tests/rm/no-give-up.sh \ @@ -162,6 +163,7 @@ all_tests = \ tests/rm/ext3-perf.sh \ tests/rm/cycle.sh \ tests/cp/link-heap.sh \ + tests/cp/no-ctx.sh \ tests/misc/tty-eof.pl \ tests/tail-2/inotify-hash-abuse.sh \ tests/tail-2/inotify-hash-abuse2.sh \ @@ -202,6 +204,7 @@ all_tests = \ tests/rm/r-2.sh \ tests/rm/r-3.sh \ tests/rm/r-4.sh \ + tests/rm/r-root.sh \ tests/rm/readdir-bug.sh \ tests/rm/rm1.sh \ tests/touch/empty-file.sh \ @@ -238,6 +241,7 @@ all_tests = \ tests/misc/xstrtol.pl \ tests/tail-2/pid.sh \ tests/misc/od.pl \ + tests/misc/od-endian.sh \ tests/misc/od-float.sh \ tests/misc/mktemp.pl \ tests/misc/arch.sh \ @@ -245,8 +249,9 @@ all_tests = \ tests/pr/pr-tests.pl \ tests/misc/pwd-option.sh \ tests/misc/chcon-fail.sh \ + tests/misc/coreutils.sh \ tests/misc/cut.pl \ - tests/misc/cut-huge-to-eol-range.sh \ + tests/misc/cut-huge-range.sh \ tests/misc/wc.pl \ tests/misc/wc-files0-from.pl \ tests/misc/wc-files0.sh \ @@ -261,6 +266,7 @@ all_tests = \ tests/misc/csplit.sh \ tests/misc/csplit-1000.sh \ tests/misc/csplit-heap.sh \ + tests/misc/csplit-suppress-matched.pl \ tests/misc/date-sec.sh \ tests/misc/dircolors.pl \ tests/misc/dirname.pl \ @@ -274,9 +280,7 @@ all_tests = \ tests/misc/groups-version.sh \ tests/misc/head-c.sh \ tests/misc/head-pos.sh \ - tests/misc/id-context.sh \ - tests/misc/id-groups.sh \ - tests/misc/id-setgid.sh \ + tests/misc/head-write-error.sh \ tests/misc/md5sum.pl \ tests/misc/md5sum-bsd.sh \ tests/misc/md5sum-newline.pl \ @@ -311,9 +315,11 @@ 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/shuf.sh \ + tests/misc/shuf-reservoir.sh \ tests/misc/sort.pl \ tests/misc/sort-benchmark-random.sh \ tests/misc/sort-compress.sh \ @@ -344,6 +350,7 @@ all_tests = \ tests/split/b-chunk.sh \ tests/split/fail.sh \ tests/split/lines.sh \ + tests/split/line-bytes.sh \ tests/split/l-chunk.sh \ tests/split/r-chunk.sh \ tests/split/numeric.sh \ @@ -389,6 +396,8 @@ all_tests = \ tests/misc/uniq-perf.sh \ tests/misc/xattr.sh \ tests/tail-2/wait.sh \ + tests/tail-2/retry.sh \ + tests/tail-2/symlink.sh \ tests/chmod/c-option.sh \ tests/chmod/equal-x.sh \ tests/chmod/equals.sh \ @@ -427,6 +436,7 @@ all_tests = \ tests/cp/file-perm-race.sh \ tests/cp/into-self.sh \ tests/cp/link.sh \ + tests/cp/link-deref.sh \ tests/cp/link-no-deref.sh \ tests/cp/link-preserve.sh \ tests/cp/link-symlink.sh \ @@ -457,13 +467,16 @@ all_tests = \ tests/df/header.sh \ tests/df/df-P.sh \ tests/df/df-output.sh \ + tests/df/df-symlink.sh \ tests/df/unreadable.sh \ tests/df/total-unprocessed.sh \ tests/df/no-mtab-status.sh \ tests/df/skip-duplicates.sh \ tests/df/skip-rootfs.sh \ + tests/dd/ascii.sh \ tests/dd/direct.sh \ tests/dd/misc.sh \ + tests/dd/no-allocate.sh \ tests/dd/nocache.sh \ tests/dd/not-rewound.sh \ tests/dd/reblock.sh \ @@ -490,6 +503,7 @@ all_tests = \ tests/du/inacc-dest.sh \ tests/du/inacc-dir.sh \ tests/du/inaccessible-cwd.sh \ + tests/du/inodes.sh \ tests/du/long-from-unreadable.sh \ tests/du/long-sloop.sh \ tests/du/max-depth.sh \ @@ -504,6 +518,11 @@ all_tests = \ tests/du/two-args.sh \ tests/id/gnu-zero-uids.sh \ tests/id/no-context.sh \ + tests/id/context.sh \ + tests/id/uid.sh \ + tests/id/setgid.sh \ + tests/id/zero.sh \ + tests/id/smack.sh \ tests/install/basic-1.sh \ tests/install/create-leading.sh \ tests/install/d-slashdot.sh \ @@ -524,6 +543,7 @@ all_tests = \ tests/ls/color-clear-to-eol.sh \ tests/ls/color-dtype-dir.sh \ tests/ls/color-norm.sh \ + tests/ls/color-term.sh \ tests/ls/dangle.sh \ tests/ls/dired.sh \ tests/ls/file-type.sh \ @@ -552,14 +572,18 @@ all_tests = \ tests/mkdir/p-1.sh \ tests/mkdir/p-2.sh \ tests/mkdir/p-3.sh \ + tests/mkdir/p-acl.sh \ tests/mkdir/p-slashdot.sh \ tests/mkdir/p-thru-slink.sh \ tests/mkdir/p-v.sh \ tests/mkdir/parents.sh \ tests/mkdir/perm.sh \ tests/mkdir/selinux.sh \ + tests/mkdir/restorecon.sh \ tests/mkdir/special-1.sh \ tests/mkdir/t-slash.sh \ + tests/mkdir/smack-no-root.sh \ + tests/mkdir/smack-root.sh \ tests/mv/acl.sh \ tests/mv/atomic.sh \ tests/mv/atomic2.sh \ @@ -650,7 +674,7 @@ $(factor_tests): $(tf)/run.sh $(tf)/create-test.sh $(AM_V_at)$(SHELL) $(srcdir)/$(tf)/create-test.sh $@ \ $(srcdir)/$(tf)/run.sh > $@-t $(AM_V_at)chmod a+x $@-t - $(AM_V_at)mv $@-t $@ + $(AM_V_at)mv -f $@-t $@ CLEANFILES += $(factor_tests) diff --git a/tests/ls/abmon-align.sh b/tests/ls/abmon-align.sh index 4c7dc296..7630889e 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2009-2014 Free Software Foundation, Inc. # This program is free software: 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 2ae5a0c5..c4861629 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2011-2014 Free Software Foundation, Inc. # This 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,18 +30,18 @@ for size in 1024 4096 262144; do done touch -d '2001-01-01 00:00' file* || fail=1 -size_etc='s/[^ ]* *[^ ]* *[^ ]* *[^ ]* *//' +size_etc='s/[^ ]* *[^ ]* *//' -ls -l * | sed "$size_etc" >../out || fail=1 -POSIXLY_CORRECT=1 ls -l * | sed "$size_etc" >>../out || fail=1 -POSIXLY_CORRECT=1 ls -k -l * | sed "$size_etc" >>../out || fail=1 +ls -og * | sed "$size_etc" >../out || fail=1 +POSIXLY_CORRECT=1 ls -og * | sed "$size_etc" >>../out || fail=1 +POSIXLY_CORRECT=1 ls -k -og * | sed "$size_etc" >>../out || fail=1 for var in BLOCKSIZE BLOCK_SIZE LS_BLOCK_SIZE; do for blocksize in 1 512 1K 1KiB; do (eval $var=$blocksize && export $var && - ls -l * && - ls -l -k * && - ls -l -k --block-size=$blocksize * + ls -og * && + ls -og -k * && + ls -og -k --block-size=$blocksize * ) | sed "$size_etc" >>../out || fail=1 done done diff --git a/tests/ls/capability.sh b/tests/ls/capability.sh index 6b41a39f..54ba296c 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2008-2014 Free Software Foundation, Inc. # This program is free software: 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 3d393f47..a9cc6e91 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2009-2014 Free Software Foundation, Inc. # This program is free software: 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 fc96e21f..559a1884 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2006-2014 Free Software Foundation, Inc. # This 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 o+w other-writable || framework_failure_ chmod o+t sticky || framework_failure_ -ls --color=always > out || fail=1 +TERM=xterm ls --color=always > out || fail=1 cat -A out > o1 || fail=1 mv o1 out || fail=1 diff --git a/tests/ls/color-norm.sh b/tests/ls/color-norm.sh index 9910903b..23c01871 100755 --- a/tests/ls/color-norm.sh +++ b/tests/ls/color-norm.sh @@ -3,7 +3,7 @@ # 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2010-2014 Free Software Foundation, Inc. # This program is free software: 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 new file mode 100755 index 00000000..8eb3783a --- /dev/null +++ b/tests/ls/color-term.sh @@ -0,0 +1,48 @@ +#!/bin/sh +# Ensure "ls --color" doesn't output colors for TERM=dumb + +# Copyright (C) 2014 Free Software Foundation, Inc. + +# This 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_ ls + +# Output time as something constant +export TIME_STYLE="+norm" + +touch exe || framework_failure_ +chmod u+x exe || framework_failure_ + +# output colors +LS_COLORS='' COLORTERM='nonempty' TERM='' ls --color=always exe >> out || fail=1 +LS_COLORS='' COLORTERM='' TERM='xterm' ls --color=always exe >> out || fail=1 + +# Don't output colors +LS_COLORS='' COLORTERM='' TERM='dumb' ls --color=always exe >> out || fail=1 +LS_COLORS='' COLORTERM='' TERM='' ls --color=always exe >> out || fail=1 + +cat -A out > out.display || framework_failure_ +mv out.display out || framework_failure_ + +cat <<\EOF > exp || framework_failure_ +^[[0m^[[01;32mexe^[[0m$ +^[[0m^[[01;32mexe^[[0m$ +exe$ +exe$ +EOF + +compare exp out || fail=1 + +Exit $fail diff --git a/tests/ls/dangle.sh b/tests/ls/dangle.sh index e22519d9..628f760b 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2003-2014 Free Software Foundation, Inc. # This program is free software: 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/dired.sh b/tests/ls/dired.sh index 82110034..e87590e7 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2001-2014 Free Software Foundation, Inc. # This program is free software: 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 62a7dcf7..0afa4d4e 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2002-2014 Free Software Foundation, Inc. # This program is free software: 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 e099b602..3357439a 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2000-2014 Free Software Foundation, Inc. # This program is free software: 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/getxattr-speedup.sh b/tests/ls/getxattr-speedup.sh index 224362f0..0144571e 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2012-2014 Free Software Foundation, Inc. # This 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,7 @@ . "${srcdir=.}/tests/init.sh"; path_prepend_ ./src print_ver_ ls +require_gcc_shared_ # Replace each getxattr and lgetxattr call with a call to these stubs. # Count those and write the total number of calls to the file "x" @@ -47,8 +48,8 @@ ssize_t lgetxattr(const char *path, const char *name, void *value, size_t size) EOF # Then compile/link it: -$CC -shared -fPIC -O2 k.c -o k.so \ - || framework_failure_ 'failed to compile with -shared -fPIC' +gcc_shared_ k.c k.so \ + || framework_failure_ 'failed to build shared library' # Create a few files: seq 20 | xargs touch || framework_failure_ diff --git a/tests/ls/infloop.sh b/tests/ls/infloop.sh index a441ec2c..48d356a0 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2001-2014 Free Software Foundation, Inc. # This program is free software: 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 8d4bc79d..e09efa60 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2003-2014 Free Software Foundation, Inc. # This program is free software: 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 a66df9a9..2255b6eb 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2003-2014 Free Software Foundation, Inc. # This program is free software: 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 a7344444..4407ba61 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2008-2014 Free Software Foundation, Inc. # This program is free software: 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 a7b9417c..db6c56ea 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2006-2014 Free Software Foundation, Inc. # This program is free software: 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 a89780e0..e356a296 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2001-2014 Free Software Foundation, Inc. # This program is free software: 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 283f4f42..a75180c2 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2008-2014 Free Software Foundation, Inc. # This program is free software: 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/proc-selinux-segfault.sh b/tests/ls/proc-selinux-segfault.sh index 65790911..1b7a39be 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2008-2014 Free Software Foundation, Inc. # This program is free software: 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 07839713..83ebe68c 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2009-2014 Free Software Foundation, Inc. # This 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,9 +21,9 @@ print_ver_ ls # We use --local here so as to not activate # potentially very many remote mounts. -mount_points=$(df --local -P 2>&1 | sed -n 's,.*[0-9]% \(/.\),\1,p') -test -z "$mount_points" && - skip_ "this test requires a non-root mount point" +df --local --out=target | sed -n '/^\/./p' > mount_points +test -s mount_points || + skip_ "this test requires a non-root mount point" # Given e.g., /dev/shm, produce the list of GNU ls options that # let us list just that entry using readdir data from its parent: @@ -48,23 +48,23 @@ ls_ignore_options() inode_via_readdir() { mount_point=$1 - base=$(basename $mount_point) - case $base in + base=$(basename "$mount_point") + case "$base" in .*) skip_ 'mount point component starts with "."' ;; *[*?]*) skip_ 'mount point component contains "?" or "*"' ;; esac opts=$(ls_ignore_options "$base") - parent_dir=$(dirname $mount_point) - eval "ls -i $opts $parent_dir" | sed 's/ .*//' + parent_dir=$(dirname "$mount_point") + eval "ls -i $opts '$parent_dir'" | sed 's/ .*//' } -for dir in $mount_points; do - readdir_inode=$(inode_via_readdir $dir) +while read dir; do + readdir_inode=$(inode_via_readdir "$dir") test $? = 77 && continue - stat_inode=$(timeout 1 stat --format=%i $dir) + stat_inode=$(timeout 1 stat --format=%i "$dir") # If stat fails or says the inode is 0, skip $dir. case $stat_inode in 0|'') continue;; esac test "$readdir_inode" = "$stat_inode" || fail=1 -done +done < mount_points Exit $fail diff --git a/tests/ls/recursive.sh b/tests/ls/recursive.sh index 94a414a2..be2d849b 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2001-2014 Free Software Foundation, Inc. # This program is free software: 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 d90148da..2318a479 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2012-2014 Free Software Foundation, Inc. # This program is free software: 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 50ad1fd2..99c62afe 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-2013 Free Software Foundation, Inc. +# Copyright (C) 1998-2014 Free Software Foundation, Inc. # This program is free software: 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 e02478a4..8ba3be15 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2011-2014 Free Software Foundation, Inc. # This program is free software: 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 8bfc69d1..01da0c8a 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2006-2014 Free Software Foundation, Inc. # This program is free software: 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 cdd7a4e9..9de018f3 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2006-2014 Free Software Foundation, Inc. # This program is free software: 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-color.sh b/tests/ls/stat-free-color.sh index 3aacf961..72a09bb6 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2011-2014 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -18,12 +18,16 @@ . "${srcdir=.}/tests/init.sh"; path_prepend_ ./src print_ver_ ls -require_strace_ stat + +# Note this list of _file name_ stat functions must be +# as cross platform as possible and so doesn't include +# fstatat64 as that's not available on aarch64 for example. +stats='stat,lstat,stat64,lstat64,newfstatat' + +require_strace_ $stats require_dirent_d_type_ -for i in 1 2 3; do - ln -s nowhere dangle-$i || framework_failure_ -done +ln -s nowhere dangle || framework_failure_ # Disable enough features via LS_COLORS so that ls --color # can do its job without calling stat (other than the obligatory @@ -53,17 +57,18 @@ eval $(dircolors -b color-without-stat) # To avoid counting those, first get a baseline count by running # ls with only the --help option. Then, compare that with the # invocation under test. -strace -o log-help -e stat,lstat,stat64,lstat64 ls --help >/dev/null || fail=1 +strace -o log-help -e $stats ls --help >/dev/null || fail=1 n_lines_help=$(wc -l < log-help) -strace -o log -e stat,lstat,stat64,lstat64 ls --color=always . || fail=1 +strace -o log -e $stats ls --color=always . || fail=1 n_lines=$(wc -l < log) n_stat=$(expr $n_lines - $n_lines_help) -# Expect one or two stat calls. +# Expect one stat call. case $n_stat in - 1) ;; + 0) skip_ 'No stat calls recognized on this platform' ;; + 1) ;; # Corresponding to stat(".") *) fail=1; head -n30 log* ;; esac diff --git a/tests/ls/stat-free-symlinks.sh b/tests/ls/stat-free-symlinks.sh index 33cd16a8..0bc4c6aa 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2007-2014 Free Software Foundation, Inc. # This program is free software: 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 b54f5503..57c718a9 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2006-2014 Free Software Foundation, Inc. # This 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 @@ while :; do d_ino=$(sed -n '1s/^ *\([0-9][0-9]*\) .*/\1/p;q' tmp) # Extract the name of the corresponding directory entry. - file=$(sed -n '1s/^ *[0-9][0-9]* *//p;q' tmp) + file=$(sed -n '1s/^ *[0-9][0-9]* //p;q' tmp) # Get its inode number (stat.st_ino) via stat(1)'s call to lstat. st_ino=$(stat --format=%i "$t/$file") diff --git a/tests/ls/symlink-slash.sh b/tests/ls/symlink-slash.sh index 5e64a52b..da5da28f 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-2013 Free Software Foundation, Inc. +# Copyright (C) 1999-2014 Free Software Foundation, Inc. # This program is free software: 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 e9d32989..d292c982 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2011-2014 Free Software Foundation, Inc. # This program is free software: 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 f1bc69d9..f009cdc2 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2007-2014 Free Software Foundation, Inc. # This program is free software: 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 db2b784f..95369067 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2007-2014 Free Software Foundation, Inc. # This program is free software: 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 5d1d2621..54e2cc21 100755 --- a/tests/misc/base64.pl +++ b/tests/misc/base64.pl @@ -1,7 +1,7 @@ #!/usr/bin/perl # Exercise base64. -# Copyright (C) 2006-2013 Free Software Foundation, Inc. +# Copyright (C) 2006-2014 Free Software Foundation, Inc. # This program is free software: 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 b84412bb..3aace6f8 100755 --- a/tests/misc/basename.pl +++ b/tests/misc/basename.pl @@ -1,6 +1,6 @@ #!/usr/bin/perl # Test basename. -# Copyright (C) 2006-2013 Free Software Foundation, Inc. +# Copyright (C) 2006-2014 Free Software Foundation, Inc. # This program is free software: 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-buf.sh b/tests/misc/cat-buf.sh index 17fd936f..592b5a1d 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2009-2014 Free Software Foundation, Inc. # This program is free software: 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-proc.sh b/tests/misc/cat-proc.sh index 77f548e4..7b826ef3 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2006-2014 Free Software Foundation, Inc. # This program is free software: 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/chcon-fail.sh b/tests/misc/chcon-fail.sh index c9b651b7..77b91d3b 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2007-2014 Free Software Foundation, Inc. # This program is free software: 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/chcon.sh b/tests/misc/chcon.sh index aace5389..ec573967 100755 --- a/tests/misc/chcon.sh +++ b/tests/misc/chcon.sh @@ -1,7 +1,7 @@ #!/bin/sh # exercise chcon -# Copyright (C) 2007-2013 Free Software Foundation, Inc. +# Copyright (C) 2007-2014 Free Software Foundation, Inc. # This program is free software: 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/chroot-credentials.sh b/tests/misc/chroot-credentials.sh index 8eb658d9..b06e8b7f 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2009-2014 Free Software Foundation, Inc. # This 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,31 +22,96 @@ print_ver_ chroot require_root_ +grep '^#define HAVE_SETGROUPS 1' "$CONFIG_HEADER" >/dev/null \ + && HAVE_SETGROUPS=1 + +root=$(id -nu 0) || skip_ "Couldn't look up root username" + +# verify numeric IDs looked up similarly to names +NON_ROOT_UID=$(id -u $NON_ROOT_USERNAME) +NON_ROOT_GROUP=$NON_ROOT_GID # Used where we want name lookups to occur + +# "uid:" is supported (unlike chown etc.) since we treat it like "uid" +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 +done # Verify that root credentials are kept. -test $(chroot / whoami) = root || fail=1 +test $(chroot / whoami) = "$root" || fail=1 test "$(groups)" = "$(chroot / groups)" || fail=1 # Verify that credentials are changed correctly. whoami_after_chroot=$( chroot --userspec=$NON_ROOT_USERNAME:$NON_ROOT_GROUP / whoami ) -test "$whoami_after_chroot" != root || fail=1 +test "$whoami_after_chroot" != "$root" || fail=1 + +# Verify that when specifying only a group we don't change the +# list of supplemental groups +test "$(chroot --userspec=:$NON_ROOT_GROUP / id -G)" = \ + "$NON_ROOT_GID $(id -G)" || fail=1 + +if ! test "$HAVE_SETGROUPS"; then + Exit $fail +fi + # Verify that there are no additional groups. id_G_after_chroot=$( chroot --userspec=$NON_ROOT_USERNAME:$NON_ROOT_GROUP \ --groups=$NON_ROOT_GROUP / id -G ) -test "$id_G_after_chroot" = $NON_ROOT_GROUP || fail=1 +test "$id_G_after_chroot" = $NON_ROOT_GID || fail=1 + +# Verify that when specifying only the user name we get all their groups +test "$(chroot --userspec=$NON_ROOT_USERNAME / id -G)" = \ + "$(id -G $NON_ROOT_USERNAME)" || fail=1 -# Verify that when specifying only the user name we get the current -# primary group ID. -test "$(chroot --userspec=$NON_ROOT_USERNAME / id -g)" = "$(id -g)" \ - || fail=1 +# Ditto with trailing : on the user name. +test "$(chroot --userspec=$NON_ROOT_USERNAME: / id -G)" = \ + "$(id -G $NON_ROOT_USERNAME)" || fail=1 + +# Verify that when specifying only the user and clearing supplemental groups +# that we only get the primary group +test "$(chroot --userspec=$NON_ROOT_USERNAME --groups='' / id -G)" = \ + $NON_ROOT_GID || fail=1 + +# Verify that when specifying only the UID we get all their groups +test "$(chroot --userspec=$NON_ROOT_UID / id -G)" = \ + "$(id -G $NON_ROOT_USERNAME)" || fail=1 + +# Verify that when specifying only the user and clearing supplemental groups +# that we only get the primary group. Note this variant with prepended '+' +# results in no lookups in the name database which could be useful depending +# on your chroot setup. +test "$(chroot --userspec=+$NON_ROOT_UID:+$NON_ROOT_GID --groups='' / id -G)" =\ + $NON_ROOT_GID || fail=1 # Verify that when specifying only a group we get the current user ID test "$(chroot --userspec=:$NON_ROOT_GROUP / id -u)" = "$(id -u)" \ - || fail=1 + || fail=1 + +# verify that arbitrary numeric IDs are supported +test "$(chroot --userspec=1234:+5678 --groups=' +8765,4321' / id -G)" \ + || fail=1 + +# demonstrate that extraneous commas are supported +test "$(chroot --userspec=1234:+5678 --groups=',8765,,4321,' / id -G)" \ + || fail=1 + +# demonstrate that --groups is not cumulative +test "$(chroot --groups='invalid ignored' --groups='' / id -G)" \ + || fail=1 + +if ! id -u +12342; then + # Ensure supplemental groups cleared from some arbitrary unknown ID + 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 +fi Exit $fail diff --git a/tests/misc/chroot-fail.sh b/tests/misc/chroot-fail.sh index 86095f3c..a84826fd 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2009-2014 Free Software Foundation, Inc. # This 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,7 @@ . "${srcdir=.}/tests/init.sh"; path_prepend_ ./src print_ver_ chroot +require_built_ chroot # These tests verify exact status of internal failure; since none of # them actually run a command, we don't need root privileges @@ -28,16 +29,20 @@ test $? = 125 || fail=1 chroot --- / true # unknown option test $? = 125 || fail=1 -# chroot("/") succeeds for non-root users on some systems, but not all. -if chroot / true ; then - 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 -fi +# 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 Exit $fail diff --git a/tests/misc/close-stdout.sh b/tests/misc/close-stdout.sh index 8ea08487..4da696c4 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2004-2014 Free Software Foundation, Inc. # This program is free software: 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/comm.pl b/tests/misc/comm.pl index 62711bda..c96939b1 100755 --- a/tests/misc/comm.pl +++ b/tests/misc/comm.pl @@ -2,7 +2,7 @@ # -*- perl -*- # Test comm -# Copyright (C) 2008-2013 Free Software Foundation, Inc. +# Copyright (C) 2008-2014 Free Software Foundation, Inc. # This program is free software: 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 new file mode 100755 index 00000000..a22bc9f6 --- /dev/null +++ b/tests/misc/coreutils.sh @@ -0,0 +1,36 @@ +#!/bin/sh +# Verify behavior of separate coreutils multicall binary + +# Copyright (C) 2014 Free Software Foundation, Inc. + +# This 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_ coreutils + +test -s "$abs_top_builddir/src/coreutils.h" \ + || skip_ "multicall binary is disabled" + +# Yes outputs all its params so is good to verify argv manipulations +echo 'y' > exp +coreutils --coreutils-prog=yes | head -n10 | uniq > out +compare exp out || fail=1 + +# Ensure if incorrect program passed, we diagnose +echo "coreutils: unknown program 'blah'" > exp +coreutils --coreutils-prog='blah' --help 2>err && fail=1 +compare exp err || fail=1 + +Exit $fail diff --git a/tests/misc/csplit-1000.sh b/tests/misc/csplit-1000.sh index 26cb8a8c..6757a464 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2010-2014 Free Software Foundation, Inc. # This program is free software: 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 82945a78..03fc9a36 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2010-2014 Free Software Foundation, Inc. # This 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 @@ . "${srcdir=.}/tests/init.sh"; path_prepend_ ./src print_ver_ csplit -require_ulimit_ +require_ulimit_v_ ( ulimit -v 20000 diff --git a/tests/misc/csplit-suppress-matched.pl b/tests/misc/csplit-suppress-matched.pl new file mode 100755 index 00000000..cea64e4f --- /dev/null +++ b/tests/misc/csplit-suppress-matched.pl @@ -0,0 +1,213 @@ +#!/usr/bin/perl + +# Copyright (C) 2013-2014 Free Software Foundation, Inc. + +# This 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/>. + +use strict; +use Data::Dumper; + +my $limits = getlimits (); + +my $prog = 'csplit'; + +# Turn off localization of executable's output. +@ENV{qw(LANGUAGE LANG LC_ALL)} = ('C') x 3; + +# Input from 'seq 6' +my $IN_SEQ_6 =<<EOF; +1 +2 +3 +4 +5 +6 +EOF + +# Input from a possible run of 'uniq --group' +# (groups separated by empty lines) +my $IN_UNIQ =<<EOF; +a +a +YY + +XX +b +b +YY + +XX +c +YY + +XX +d +d +d +EOF + +# Standard Coreotils::run_tests() structure, except the addition of +# "OUTPUTS" array, containing the expected content of the output files. +# See code below for conversion into PRE/CMP/POST checks. +my @csplit_tests = +( + # without --suppress-matched, + # the newline (matched line) appears in the output files + ["re-base", "-q - '/^\$/' '{*}'", {IN_PIPE => $IN_UNIQ}, + {OUTPUTS => [ "a\na\nYY\n", "\nXX\nb\nb\nYY\n","\nXX\nc\nYY\n", + "\nXX\nd\nd\nd\n" ] }], + + # the newline (matched line) does not appears in the output files + ["re-1", " --suppress-matched -q - '/^\$/' '{*}'", {IN_PIPE => $IN_UNIQ}, + {OUTPUTS => ["a\na\nYY\n", "XX\nb\nb\nYY\n", "XX\nc\nYY\n", + "XX\nd\nd\nd\n"]}], + + # the 'XX' (matched line + offset 1) does not appears in the output files. + # the newline appears in the files (before each split, at the end of the file) + ["re-2", "--suppress-matched -q - '/^\$/1' '{*}'", {IN_PIPE => $IN_UNIQ}, + {OUTPUTS => ["a\na\nYY\n\n","b\nb\nYY\n\n","c\nYY\n\n","d\nd\nd\n"]}], + + # the 'YY' (matched line + offset of -1) does not appears in the output files + # the newline appears in the files (as the first line of the new split) + ["re-3", " --suppress-matched -q - '/^\$/-1' '{*}'", {IN_PIPE => $IN_UNIQ}, + {OUTPUTS => ["a\na\n", "\nXX\nb\nb\n", "\nXX\nc\n", "\nXX\nd\nd\nd\n"]}], + + # Test two consecutive matched lines + # without suppress-matched, the second file should contain a single newline. + ["re-4.1", "-q - '/^\$/' '{*}'", {IN_PIPE => "a\n\n\nb\n"}, + {OUTPUTS => [ "a\n", "\n", "\nb\n" ]}], + # suppress-matched will cause the second file to be empty. + ["re-4.2", "--suppress-match -q - '/^\$/' '{*}'", {IN_PIPE => "a\n\n\nb\n"}, + {OUTPUTS => [ "a\n", "", "b\n" ]}], + # suppress-matched + elide-empty should output just two files. + ["re-4.3", "--suppress-match -zq - '/^\$/' '{*}'", {IN_PIPE => "a\n\n\nb\n"}, + {OUTPUTS => [ "a\n", "b\n" ]}], + + + # Test a matched-line as the last line + # default: last file with newline should be created. + ["re-5.1", "-q - '/^\$/' '{*}'", {IN_PIPE => "a\n\nb\n\n"}, + {OUTPUTS => [ "a\n", "\nb\n", "\n" ]}], + # suppress-matched - last empty files should be created. + ["re-5.2", "--suppress-match -q - '/^\$/' '{*}'", {IN_PIPE => "a\n\nb\n\n"}, + {OUTPUTS => [ "a\n", "b\n", "" ]}], + # suppress-matched + elide-empty: just two files should be created. + ["re-5.3", "--suppress-match -zq - '/^\$/' '{*}'", {IN_PIPE => "a\n\nb\n\n"}, + {OUTPUTS => [ "a\n", "b\n" ]}], + + # without suppress-matched, + # the matched lines (2/4/6) appears in the output files + ["int-base", '-q - 2 4 6', {IN_PIPE => $IN_SEQ_6}, + {OUTPUTS => [ "1\n", "2\n3\n", "4\n5\n", "6\n" ]}], + # suppress matched - the matching lines (2/4/6) should not appear. + ["int-1", '--suppress-matched -q - 2 4 6', {IN_PIPE => $IN_SEQ_6}, + {OUTPUTS => [ "1\n", "3\n", "5\n", "" ]}], + # suppress matched + elide-empty + ["int-2", '--suppress-matched -zq - 2 4 6', {IN_PIPE => $IN_SEQ_6}, + {OUTPUTS => [ "1\n", "3\n", "5\n" ]}], +); + + + +=pod +The following loop translate the above @Tests to a Cureutils::run_tests() +compatible structure. It converts "OUTPUTS" key into "CMP" + "POST" keys: +1. Each element in the OUTPUTS key is expected to be an output file + from csplit (named xx00, xx01, xx02...) + create a "CMP" key for each one, with the output and the filename. +2. Add a "POST" key, ensuring no extra files have been created. + (e.g. if there are 4 expected outputs, xx00 to xx03, + ensure xx04 doesn't exist). +3. Add a "PRE" key, deleting all existing 'xx*' files. + +Example: + +Before conversion: + my @csplit_tests = + ( + ["1", '-z -q - 2 4 6', + {IN_PIPE => "1\n2\n3\n4\n5\n6\n"}, + {OUTPUTS => [ "1\n", "2\n3\n", "4\n5\n", "6\n" ], + ] + ) + +After conversion: + + my @csplit_tests = + ( + ["1", '-z -q - 2 4 6', + {IN_PIPE => "1\n2\n3\n4\n5\n6\n"}, + {PRE => sub { unlink glob './xx??' ; }}, + {CMP => ["1\n", {'xx00'=> undef}]}, + {CMP => ["2\n3\n", {'xx01'=> undef}]}, + {CMP => ["4\n5\n", {'xx02'=> undef}]}, + {CMP => ["6\n", {'xx03'=> undef}]}, + {POST => sub { die "extra file" if -e 'xx04'}}, + ], + ); +=cut +my @Tests; +foreach my $t (@csplit_tests) + { + my ($test_name, $cmdline, @others) = @$t; + my $new_ent = [$test_name, $cmdline]; + + my $out_file_num = 0 ; + + foreach my $e (@others) + { + die "Internal error: expecting a hash (e.g. IN_PIPE/OUTPUTS/ERR)" . + "in test '$test_name', got $e" + unless ref $e && (ref $e eq 'HASH'); + + my ($key, $value) = each %$e; + if ($key eq 'OUTPUTS') + { + # Convert each expected OUTPUT to a 'CMP' key. + foreach my $output (@$value) + { + my $filename = sprintf("xx%02d",$out_file_num++); + my $cmp = {CMP => [ $output, { $filename => undef}]}; + push @$new_ent, $cmp; + } + + # Add a 'POST' check + # Ensure no extra files have been created. + my $filename = sprintf("xx%02d",$out_file_num++); + my $post = { POST => sub { die "Test failed: an extraneous file " . + "'$filename' has been created\n" + if -e $filename; } } ; + push @$new_ent, $post; + + # before running each test, cleanup the 'xx00' files + # from previous runs. + my $pre = { PRE => sub { unlink glob "./xx??"; } }; + push @$new_ent, $pre; + } + else + { + # pass other entities as-is (e.g. OUT, ERR, OUT_SUBST, EXIT) + # run_tests() will know how to handle them. + push @$new_ent, $e; + } + } + + push @Tests, $new_ent; + } + +my $save_temps = $ENV{DEBUG}; +my $verbose = $ENV{VERBOSE}; + +my $fail = run_tests ($prog, $prog, \@Tests, $save_temps, $verbose); +exit $fail; diff --git a/tests/misc/csplit.sh b/tests/misc/csplit.sh index 24c21aaf..da09c1f0 100755 --- a/tests/misc/csplit.sh +++ b/tests/misc/csplit.sh @@ -1,7 +1,7 @@ #!/bin/sh # various csplit tests -# Copyright (C) 2001-2013 Free Software Foundation, Inc. +# Copyright (C) 2001-2014 Free Software Foundation, Inc. # This program is free software: 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 new file mode 100755 index 00000000..e2c4108c --- /dev/null +++ b/tests/misc/cut-huge-range.sh @@ -0,0 +1,64 @@ +#!/bin/sh +# Ensure that cut does not allocate mem for large ranges + +# Copyright (C) 2012-2014 Free Software Foundation, Inc. + +# This 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_ cut +require_ulimit_v_ +getlimits_ + +# sed script to subtract one from the input. +# Each input line should consist of a positive decimal number. +# Each output line's number is one less than the input's. +# There's no limit (other than line length) on the number's magnitude. +subtract_one=' + s/$/@/ + : again + s/0@/@9/ + s/1@/0/ + s/2@/1/ + s/3@/2/ + s/4@/3/ + s/5@/4/ + s/6@/5/ + s/7@/6/ + s/8@/7/ + s/9@/8/ + t again +' + +# Ensure we can cut up to our sentinel value. +# This is currently SIZE_MAX, but could be raised to UINTMAX_MAX +# if we didn't allocate memory for each line as a unit. +# Don't use expr to subtract one, since SIZE_MAX may exceed its maximum value. +CUT_MAX=$(echo $SIZE_MAX | sed "$subtract_one") + +# From coreutils-8.10 through 8.20, this would make cut try to allocate +# a 256MiB bit vector. With a 20MB limit on VM, the following would fail. +(ulimit -v 20000; : | cut -b$CUT_MAX- > err 2>&1) || fail=1 + +# Up to and including coreutils-8.21, cut would allocate possibly needed +# memory upfront. Subsequently extra memory is no longer needed. +(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 + +compare /dev/null err || fail=1 + +Exit $fail diff --git a/tests/misc/cut.pl b/tests/misc/cut.pl index 41e9e209..04188621 100755 --- a/tests/misc/cut.pl +++ b/tests/misc/cut.pl @@ -1,7 +1,7 @@ #!/usr/bin/perl # Test "cut". -# Copyright (C) 2006-2013 Free Software Foundation, Inc. +# Copyright (C) 2006-2014 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -144,15 +144,17 @@ my @Tests = ['newline-12', '-s', '-d:', '-f1', {IN=>"a:1\nb:"}, {OUT=>"a\nb\n"}], ['newline-13', '-d:', '-f1-', {IN=>"a1:\n:"}, {OUT=>"a1:\n:\n"}], # newline processing for fields when -d == '\n' - ['newline-14', "-d'\n'", '-f1', {IN=>"a:1\nb:"}, {OUT=>"a:1\nb:\n"}], + ['newline-14', "-d'\n'", '-f1', {IN=>"a:1\nb:"}, {OUT=>"a:1\n"}], ['newline-15', '-s', "-d'\n'", '-f1', {IN=>"a:1\nb:"}, {OUT=>"a:1\n"}], - ['newline-16', '-s', "-d'\n'", '-f2', {IN=>"\nb"}, {OUT=>""}], + ['newline-16', '-s', "-d'\n'", '-f2', {IN=>"\nb"}, {OUT=>"b\n"}], ['newline-17', '-s', "-d'\n'", '-f1', {IN=>"\nb"}, {OUT=>"\n"}], - ['newline-18', "-d'\n'", '-f2', {IN=>"\nb"}, {OUT=>"\nb\n"}], - ['newline-19', "-d'\n'", '-f1', {IN=>"\nb"}, {OUT=>"\nb\n"}], + ['newline-18', "-d'\n'", '-f2', {IN=>"\nb"}, {OUT=>"b\n"}], + ['newline-19', "-d'\n'", '-f1', {IN=>"\nb"}, {OUT=>"\n"}], ['newline-20', '-s', "-d'\n'", '-f1-', {IN=>"\n"}, {OUT=>"\n"}], - ['newline-21', '-s', "-d'\n'", '-f1-', {IN=>"\nb"}, {OUT=>"\n"}], + ['newline-21', '-s', "-d'\n'", '-f1-', {IN=>"\nb"}, {OUT=>"\nb\n"}], ['newline-22', "-d'\n'", '-f1-', {IN=>"\nb"}, {OUT=>"\nb\n"}], + ['newline-23', "-d'\n'", '-f1-', '--ou=:', {IN=>"a\nb\n"}, {OUT=>"a:b\n"}], + ['newline-24', "-d'\n'", '-f1,2', '--ou=:', {IN=>"a\nb\n"}, {OUT=>"a:b\n"}], # New functionality: ['out-delim1', '-c1-3,5-', '--output-d=:', {IN=>"abcdefg\n"}, @@ -210,6 +212,8 @@ my @Tests = {IN=>"123456\n"}, {OUT=>"23456\n"}], ['EOL-subsumed-3', '--complement -b3,4-4,5,2-', {IN=>"123456\n"}, {OUT=>"1\n"}], + ['EOL-subsumed-4', '--output-d=: -b1-2,2-3,3-', + {IN=>"1234\n"}, {OUT=>"1234\n"}], ); if ($mb_locale ne 'C') diff --git a/tests/misc/date-next-dow.pl b/tests/misc/date-next-dow.pl index 3c79e22a..a1c21127 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2005-2014 Free Software Foundation, Inc. # This program is free software: 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 67048c13..9c001fdc 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2004-2014 Free Software Foundation, Inc. # This program is free software: 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 d0b3517c..40be4cab 100755 --- a/tests/misc/date.pl +++ b/tests/misc/date.pl @@ -1,7 +1,7 @@ #!/usr/bin/perl # Test "date". -# Copyright (C) 2005-2013 Free Software Foundation, Inc. +# Copyright (C) 2005-2014 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -287,6 +287,13 @@ my @Tests = {ERR => "date: invalid date '\\260'\n"}, {EXIT => 1}, ], + + # From coreutils-5.3.0 to 8.22 inclusive + # this would either infinite loop or crash + ['invalid-TZ-crash', "-d 'TZ=\"\"\"'", + {ERR => "date: invalid date 'TZ=\"\"\"'\n"}, + {EXIT => 1}, + ], ); # Repeat the cross-dst test, using Jan 1, 2005 and every interval from 1..364. diff --git a/tests/misc/dircolors.pl b/tests/misc/dircolors.pl index 061e372f..a70a8c5d 100755 --- a/tests/misc/dircolors.pl +++ b/tests/misc/dircolors.pl @@ -1,7 +1,7 @@ #!/usr/bin/perl # Simple dircolors tests. -# Copyright (C) 1998-2013 Free Software Foundation, Inc. +# Copyright (C) 1998-2014 Free Software Foundation, Inc. # This program is free software: 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 43182a8c..34c905d4 100755 --- a/tests/misc/dirname.pl +++ b/tests/misc/dirname.pl @@ -1,7 +1,7 @@ #!/usr/bin/perl # Test "dirname". -# Copyright (C) 2006-2013 Free Software Foundation, Inc. +# Copyright (C) 2006-2014 Free Software Foundation, Inc. # This program is free software: 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 3cbbcbd5..9b9c95e7 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2009-2014 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -40,7 +40,7 @@ compare out1 out2 || fail=1 # env -0 does not work if a command is specified. env -0 echo hi > out test $? = 125 || fail=1 -test -s out && fail=1 +compare /dev/null out || fail=1 # Test env -0 on a one-variable environment. printf 'a=b\nc=\0' > exp || framework_failure_ @@ -53,7 +53,7 @@ env "$(printf 'a=b\nc=')" printenv -0 a > out || fail=1 compare exp out || fail=1 env -u a printenv -0 a > out test $? = 1 || fail=1 -test -s out && fail=1 +compare /dev/null out || fail=1 env -u b "$(printf 'a=b\nc=')" printenv -0 b a > out test $? = 1 || fail=1 compare exp out || fail=1 diff --git a/tests/misc/env.sh b/tests/misc/env.sh index 7c9e8fdc..d06a1fb0 100755 --- a/tests/misc/env.sh +++ b/tests/misc/env.sh @@ -1,7 +1,7 @@ #!/bin/sh # Verify behavior of env. -# Copyright (C) 2009-2013 Free Software Foundation, Inc. +# Copyright (C) 2009-2014 Free Software Foundation, Inc. # This 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,16 +20,24 @@ . "${srcdir=.}/tests/init.sh"; path_prepend_ ./src print_ver_ env +# A simple shebang program to call "echo" from symlinks like "./-u" or "./--". +echo "#!$abs_top_builddir/src/echo simple_echo" > simple_echo \ + || framework_failure_ +chmod a+x simple_echo || framework_failure_ + +# Verify we can run the shebang which is not the case if +# there are spaces in $abs_top_builddir. +./simple_echo || skip_ "Error running simple_echo script" # Verify clearing the environment a=1 export a env - > out || fail=1 -test -s out && fail=1 +compare /dev/null out || fail=1 env -i > out || fail=1 -test -s out && fail=1 +compare /dev/null out || fail=1 env -u a -i -u a -- > out || fail=1 -test -s out && fail=1 +compare /dev/null out || fail=1 env -i -- a=b > out || fail=1 echo a=b > exp || framework_failure_ compare exp out || fail=1 @@ -62,7 +70,7 @@ fi ENV_TEST1=a export ENV_TEST1 -: >out || framework_failure_ +>out || framework_failure_ env ENV_TEST2= > all || fail=1 grep '^ENV_TEST' all | LC_ALL=C sort >> out || framework_failure_ env -u ENV_TEST1 ENV_TEST3=c > all || fail=1 @@ -105,9 +113,10 @@ export PATH # Use -- to end options (but not variable assignments). # On some systems, execve("-i") invokes a shebang script ./-i on PATH as # '/bin/sh -i', rather than '/bin/sh -- -i', which doesn't do what we want. -# Avoid the issue by using an executable rather than a script. +# Avoid the issue by using a shebang to 'echo' passing a second parameter +# before the '-i'. See the definition of simple_echo before. # Test -u, rather than -i, to minimize PATH problems. -ln -s "$abs_top_builddir/src/echo" ./-u || framework_failure_ +ln -s "simple_echo" ./-u || framework_failure_ case $(env -u echo echo good) in good) ;; *) fail=1 ;; @@ -117,16 +126,16 @@ case $(env -u echo -- echo good) in *) fail=1 ;; esac case $(env -- -u pass) in - pass) ;; + *pass) ;; *) fail=1 ;; esac # After options have ended, the first argument not containing = is a program. env a=b -- true test $? = 127 || fail=1 -ln -s "$abs_top_builddir/src/echo" ./-- || framework_failure_ +ln -s "simple_echo" ./-- || framework_failure_ case $(env a=b -- true || echo fail) in - true) ;; + *true) ;; *) fail=1 ;; esac diff --git a/tests/misc/expand.pl b/tests/misc/expand.pl index 30be9f91..939e22b8 100755 --- a/tests/misc/expand.pl +++ b/tests/misc/expand.pl @@ -1,7 +1,7 @@ #!/usr/bin/perl # Exercise expand. -# Copyright (C) 2004-2013 Free Software Foundation, Inc. +# Copyright (C) 2004-2014 Free Software Foundation, Inc. # This program is free software: 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 9b957a5c..c084b118 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2001-2014 Free Software Foundation, Inc. # This program is free software: 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.pl b/tests/misc/factor.pl index 042a8469..294b814f 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-2013 Free Software Foundation, Inc. +# Copyright (C) 1998-2014 Free Software Foundation, Inc. # This program is free software: 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 33afc0f3..77bea451 100755 --- a/tests/misc/false-status.sh +++ b/tests/misc/false-status.sh @@ -1,7 +1,8 @@ #!/bin/sh # 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2003-2014 Free Software Foundation, Inc. # This 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,9 +18,14 @@ # along with this program. If not, see <http://www.gnu.org/licenses/>. . "${srcdir=.}/tests/init.sh"; path_prepend_ ./src -print_ver_ false +print_ver_ false true -false --version > /dev/null && fail=1 -false --help > /dev/null && fail=1 +env false --version > /dev/null && fail=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 +fi Exit $fail diff --git a/tests/misc/fold.pl b/tests/misc/fold.pl index 1d197bb4..69b0c5b5 100755 --- a/tests/misc/fold.pl +++ b/tests/misc/fold.pl @@ -1,7 +1,7 @@ #!/usr/bin/perl # Exercise fold. -# Copyright (C) 2003-2013 Free Software Foundation, Inc. +# Copyright (C) 2003-2014 Free Software Foundation, Inc. # This program is free software: 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 598c3164..0aed2229 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2007-2014 Free Software Foundation, Inc. # This program is free software: 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 5f87b325..a867701c 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2007-2014 Free Software Foundation, Inc. # This program is free software: 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 6807c4d5..d6433d0d 100755 --- a/tests/misc/head-c.sh +++ b/tests/misc/head-c.sh @@ -1,7 +1,7 @@ #!/bin/sh -# exercise the fix of 2001-08-18, based on test case from Ian Bruce +# exercise head -c -# Copyright (C) 2001-2013 Free Software Foundation, Inc. +# Copyright (C) 2001-2014 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -18,13 +18,28 @@ . "${srcdir=.}/tests/init.sh"; path_prepend_ ./src print_ver_ head +require_ulimit_v_ +getlimits_ +# exercise the fix of 2001-08-18, based on test case from Ian Bruce echo abc > in || framework_failure_ - (head -c1; head -c1) < in > out || fail=1 case "$(cat out)" in ab) ;; *) fail=1 ;; esac +# Test for a bug in coreutils 5.0.1 through 8.22. +printf 'abc\ndef\n' > in1 || framework_failure_ +(dd bs=1 skip=1 count=0 status=none && head -c-4) < in1 > out1 || fail=1 +case "$(cat out1)" in + bc) ;; + *) fail=1 ;; +esac + +# Only allocate memory as needed. +# Coreutils <= 8.21 would allocate memory up front +# based on the value passed to -c +(ulimit -v 20000; head --bytes=-$SSIZE_MAX < /dev/null) || fail=1 + Exit $fail diff --git a/tests/misc/head-elide-tail.pl b/tests/misc/head-elide-tail.pl index 71e00c6c..3c178d69 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2003-2014 Free Software Foundation, Inc. # This 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,8 @@ my @Tests = ['elide-l2', "--lines=-1", {IN=>"a"}, {OUT=>''}], ['elide-l3', "--lines=-1", {IN=>"a\nb"}, {OUT=>"a\n"}], ['elide-l4', "--lines=-1", {IN=>"a\nb\n"}, {OUT=>"a\n"}], + ['elide-l5', "--lines=-0", {IN=>"a\nb\n"}, {OUT=>"a\nb\n"}], + ['elide-l6', "--lines=-0", {IN=>"a\nb"}, {OUT=>"a\nb"}], ); if ($ENV{RUN_EXPENSIVE_TESTS}) @@ -80,9 +82,10 @@ if ($ENV{RUN_EXPENSIVE_TESTS}) } $s =~ s/(.)/$1\n/g; - for my $file_size (0..20) + $s .= 'u'; # test without trailing '\n' + for my $file_size (0..21) { - for my $n_elide (0..20) + for my $n_elide (0..21) { my $input = substr $s, 0, 2 * $file_size; my $out_len = $n_elide < $file_size ? $file_size - $n_elide : 0; diff --git a/tests/misc/head-pos.sh b/tests/misc/head-pos.sh index cb08d72e..1cf9e04b 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2002-2014 Free Software Foundation, Inc. # This program is free software: 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 new file mode 100755 index 00000000..22ecf993 --- /dev/null +++ b/tests/misc/head-write-error.sh @@ -0,0 +1,52 @@ +#!/bin/sh +# Ensure we diagnose and not continue writing to +# the output if we get a write error. + +# Copyright (C) 2014 Free Software Foundation, Inc. + +# This 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_ head + +if ! test -w /dev/full || ! test -c /dev/full; then + skip_ '/dev/full is required' +fi + +# We can't use /dev/zero as that's bypassed in the --lines case +# due to lseek() indicating it has a size of zero. +yes | head -c10M > bigseek || framework_failure_ + +# This is the single output diagnostic expected, +# (without the possibly varying :strerror(ENOSPC) suffix). +printf '%s\n' "head: error writing 'standard output'" > exp + +# Memory is bounded in these cases +for item in lines bytes; do + for N in 0 1; do + # pipe case + yes | timeout 10s head --$item=-$N > /dev/full 2> errt && fail=1 + test $? = 124 && fail=1 + sed 's/\(head:.*\):.*/\1/' errt > err + compare exp err || fail=1 + + # seekable case + timeout 10s head --$item=-$N bigseek > /dev/full 2> errt && fail=1 + test $? = 124 && fail=1 + sed 's/\(head:.*\):.*/\1/' errt > err + compare exp err || fail=1 + done +done + +Exit $fail diff --git a/tests/misc/head.pl b/tests/misc/head.pl index d92a0a5c..159d4efc 100755 --- a/tests/misc/head.pl +++ b/tests/misc/head.pl @@ -1,7 +1,7 @@ #!/usr/bin/perl # test head -# Copyright (C) 2008-2013 Free Software Foundation, Inc. +# Copyright (C) 2008-2014 Free Software Foundation, Inc. # This program is free software: 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 00f30cd0..0598557f 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2000-2014 Free Software Foundation, Inc. # This 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,47 +70,38 @@ done test "x$v" = "x$VERSION" \ || fail_ "--version-\$VERSION mismatch" -for lang in C fr da; do - for i in $built_programs; do - - # Skip 'test'; it doesn't accept --help or --version. - test $i = test && continue; - - # false fails even when invoked with --help or --version. - if test $i = false; then - env LC_MESSAGES=$lang $i --help >/dev/null && fail=1 - env LC_MESSAGES=$lang $i --version >/dev/null && fail=1 - continue - fi +for i in $built_programs; do - # The just-built install executable is always named 'ginstall'. - test $i = install && i=ginstall - - # Make sure they exit successfully, under normal conditions. - env $i --help > h-$i || fail=1 - env $i --version >/dev/null || fail=1 - - # Make sure they mention the bug-reporting address in --help output. - grep "$PACKAGE_BUGREPORT" h-$i > /dev/null || fail=1 - rm -f h-$i - - # Make sure they fail upon 'disk full' error. - if test -w /dev/full && test -c /dev/full; then - env $i --help >/dev/full 2>/dev/null && fail=1 - env $i --version >/dev/full 2>/dev/null && fail=1 - status=$? - test $i = [ && prog=lbracket || prog=$(echo $i|sed "s/$EXEEXT$//") - eval "expected=\$expected_failure_status_$prog" - test x$expected = x && expected=1 - if test $status = $expected; then - : # ok - else - fail=1 - echo "*** $i: bad exit status '$status' (expected $expected)," 1>&2 - echo " with --help or --version output redirected to /dev/full" 1>&2 - fi + # Skip 'test'; it doesn't accept --help or --version. + test $i = test && continue + + # false fails even when invoked with --help or --version. + # true and false are tested with these options separately. + test $i = false || test $i = true && continue + + # The just-built install executable is always named 'ginstall'. + test $i = install && i=ginstall + + # Make sure they exit successfully, under normal conditions. + env $i --help >/dev/null || fail=1 + env $i --version >/dev/null || fail=1 + + # Make sure they fail upon 'disk full' error. + if test -w /dev/full && test -c /dev/full; then + env $i --help >/dev/full 2>/dev/null && fail=1 + env $i --version >/dev/full 2>/dev/null && fail=1 + status=$? + test $i = [ && prog=lbracket || prog=$(echo $i|sed "s/$EXEEXT$//") + eval "expected=\$expected_failure_status_$prog" + test x$expected = x && expected=1 + if test $status = $expected; then + : # ok + else + fail=1 + echo "*** $i: bad exit status '$status' (expected $expected)," 1>&2 + echo " with --help or --version output redirected to /dev/full" 1>&2 fi - done + fi done bigZ_in=bigZ-in.Z @@ -248,7 +239,7 @@ parted_setup () { args="-s $tmp_in mklabel gpt" # something more than --help or --version. for i in $built_programs; do # Skip these. - case $i in chroot|stty|tty|false|chcon|runcon) continue;; esac + case $i in chroot|stty|tty|false|chcon|runcon|coreutils) continue;; esac rm -rf $tmp_in $tmp_in2 $tmp_dir $tmp_out $bigZ_in $zin $zin2 echo z |gzip > $zin diff --git a/tests/misc/invalid-opt.pl b/tests/misc/invalid-opt.pl index 1d7701f0..bcf6ee71 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2008-2014 Free Software Foundation, Inc. # This program is free software: 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 9b93794d..cf3f4bd4 100755 --- a/tests/misc/join.pl +++ b/tests/misc/join.pl @@ -1,7 +1,7 @@ #!/usr/bin/perl # Test join. -# Copyright (C) 2008-2013 Free Software Foundation, Inc. +# Copyright (C) 2008-2014 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -275,6 +275,26 @@ my @tv = ( [ "ID1 Name\n1 A\n", ""], "ID1 Name\n1 A\n", 0], +# Zero-terminated lines +['z1', '-z', + ["a\0c\0e\0", "a\0b\0c\0"], "a\0c\0", 0], + +# not zero-terminated, but related to the code change: +# the old readlinebuffer() auto-added '\n' to the last line. +# the new readlinebuffer_delim() does not. +# Ensure it doesn't matter. +['z2', '', + ["a\nc\ne\n", "a\nb\nc"], "a\nc\n", 0], +['z3', '', + ["a\nc\ne", "a\nb\nc"], "a\nc\n", 0], +# missing last NUL at the end of the last line (=end of file) +['z4', '-z', + ["a\0c\0e", "a\0b\0c"], "a\0c\0", 0], +# edge-case: the embedded newlines should treated as +# part of the nul-terminated line +['z5', '-z -a1 -a2', + ["a\n1\0c 3\0","b\n8\0c 9\0"], "a\n1\0b\n8\0c 3 9\0"], + ); # Convert the above old-style test vectors to the newer diff --git a/tests/misc/ls-misc.pl b/tests/misc/ls-misc.pl index 5bf7b9eb..a47e70b7 100755 --- a/tests/misc/ls-misc.pl +++ b/tests/misc/ls-misc.pl @@ -1,6 +1,6 @@ #!/usr/bin/perl -# Copyright (C) 1998-2013 Free Software Foundation, Inc. +# Copyright (C) 1998-2014 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -303,9 +303,12 @@ my @Tests = . "\e[37;44msticky$e\n" }, + {PRE => sub { + push_ls_colors('ow=34;42:tw=30;42:sg=30;43:su=37;41:st=37;44'); }}, {POST => sub { unlink qw(setuid setgid); - foreach my $dir (qw(owr owt sticky)) {rmdir $dir} }}, + foreach my $dir (qw(owr owt sticky)) {rmdir $dir} + restore_ls_colors; }}, ], # For 5.97 and earlier, --file-type acted like --indicator-style=slash. diff --git a/tests/misc/ls-time.sh b/tests/misc/ls-time.sh index 80e400f4..3ce4a91c 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-2013 Free Software Foundation, Inc. +# Copyright (C) 1998-2014 Free Software Foundation, Inc. # This program is free software: 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 6b70f21a..f73e0622 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2011-2014 Free Software Foundation, Inc. # This 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 @@ nl=' tab=' ' rm check.md5 for i in 'a\b' 'a\' "a${nl}b" "a${tab}b"; do - :> "$i" + > "$i" md5sum --tag "$i" >> check.md5 done md5sum --strict -c check.md5 || fail=1 diff --git a/tests/misc/md5sum-newline.pl b/tests/misc/md5sum-newline.pl index ad1b6acb..b418d5b4 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-2013 Free Software Foundation, Inc. +# Copyright (C) 1999-2014 Free Software Foundation, Inc. # This program is free software: 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 648bfa5b..92f66296 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2009-2014 Free Software Foundation, Inc. # This program is free software: 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.pl b/tests/misc/md5sum.pl index 5192d55f..0aa0056f 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-2013 Free Software Foundation, Inc. +# Copyright (C) 1998-2014 Free Software Foundation, Inc. # This 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,9 @@ my @Tests = {OUT=>"d174ab98d277d9f5a5611c2c9f419d9f f\n"}], ['7', {IN=> {f=> '1234567890' x 8}}, {OUT=>"57edf4a22be3c955ac49da2e2107b67a f\n"}], - ['backslash', {IN=> {".\\foo"=> ''}}, + ['backslash-1', {IN=> {".\nfoo"=> ''}}, + {OUT=>"\\$degenerate .\\nfoo\n"}], + ['backslash-2', {IN=> {".\\foo"=> ''}}, {OUT=>"\\$degenerate .\\\\foo\n"}], ['check-1', '--check', {AUX=> {f=> ''}}, {IN=> {'f.md5' => "$degenerate f\n"}}, diff --git a/tests/misc/mknod.sh b/tests/misc/mknod.sh index 30f363f6..fb907f16 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2004-2014 Free Software Foundation, Inc. # This program is free software: 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 b15b6694..13ee03f5 100755 --- a/tests/misc/mktemp.pl +++ b/tests/misc/mktemp.pl @@ -1,7 +1,7 @@ #!/usr/bin/perl # Test "mktemp". -# Copyright (C) 2007-2013 Free Software Foundation, Inc. +# Copyright (C) 2007-2014 Free Software Foundation, Inc. # This 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,14 +55,12 @@ my @Tests = ( # test-name, [option, option, ...] {OUT=>"expected-output"} # - ['too-many', 'a b', + ['too-many', '-q a b', {ERR=>"$prog: too many templates\n" . "Try '$prog --help' for more information.\n"}, {EXIT => 1} ], - ['too-many-q', '-q a b', {EXIT => 1} ], - ['too-few-x', 'foo.XX', {EXIT => 1}, + ['too-few-x', '-q foo.XX', {EXIT => 1}, {ERR=>"$prog: too few X's in template 'foo.XX'\n"}], - ['too-few-xq', '-q foo.XX', {EXIT => 1} ], ['1f', 'bar.XXXX', {OUT => "bar.ZZZZ\n"}, {OUT_SUBST => 's,\.....$,.ZZZZ,'}, @@ -148,11 +146,9 @@ my @Tests = ['suffix6f', 'aXXXX/b', {EXIT=>1}, {ERR=>"$prog: invalid suffix '/b', contains directory separator\n"}], - ['suffix6f-q', '-q aXXXX/b', {EXIT=>1}], ['suffix7f', '--suffix= aXXXXb', {EXIT=>1}, {ERR=>"$prog: with --suffix, template 'aXXXXb' must end in X\n"}], - ['suffix7f-q', '-q --suffix= aXXXXb', {EXIT=>1}], ['suffix7d', '-d --suffix=aXXXXb ""', {EXIT=>1}, {ERR=>"$prog: with --suffix, template '' must end in X\n"}], diff --git a/tests/misc/nice-fail.sh b/tests/misc/nice-fail.sh index 3e054354..3bf823ab 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2009-2014 Free Software Foundation, Inc. # This program is free software: 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 acee0f44..26a01ca9 100755 --- a/tests/misc/nice.sh +++ b/tests/misc/nice.sh @@ -1,7 +1,7 @@ #! /bin/sh # Test "nice". -# Copyright (C) 2002-2013 Free Software Foundation, Inc. +# Copyright (C) 2002-2014 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -81,12 +81,12 @@ if test x$(nice -n -1 nice 2> /dev/null) = x0 ; then if test -w /dev/full && test -c /dev/full; then nice -n -1 nice > out 2> /dev/full test $? = 125 || fail=1 - test -s out && fail=1 + compare /dev/null out || fail=1 fi else # superuser - change succeeds nice -n -1 nice 2> err || fail=1 - test -s err && fail=1 + compare /dev/null err || fail=1 test x$(nice -n -1 nice) = x-1 || fail=1 test x$(nice --1 nice) = x-1 || fail=1 fi diff --git a/tests/misc/nl.sh b/tests/misc/nl.sh index dfa7b237..676c75d7 100755 --- a/tests/misc/nl.sh +++ b/tests/misc/nl.sh @@ -1,7 +1,7 @@ #!/bin/sh # exercise nl functionality -# Copyright (C) 2002-2013 Free Software Foundation, Inc. +# Copyright (C) 2002-2014 Free Software Foundation, Inc. # This program is free software: 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 91d9e6a2..b3f4274c 100755 --- a/tests/misc/nohup.sh +++ b/tests/misc/nohup.sh @@ -1,7 +1,7 @@ #!/bin/sh # test nohup -# Copyright (C) 2003-2013 Free Software Foundation, Inc. +# Copyright (C) 2003-2014 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -63,12 +63,17 @@ rm -f nohup.out err # to stderr must be fatal. Requires stdout to be terminal. if test -w /dev/full && test -c /dev/full; then ( + # POSIX shells immediately exit the subshell on exec error. + # So check we can write to /dev/tty before the exec, which + # isn't possible if we've no controlling tty for example. + test -c /dev/tty && >/dev/tty || exit 0 + exec >/dev/tty test -t 1 || exit 0 nohup echo hi 2> /dev/full test $? = 125 || fail=1 test -f nohup.out || fail=1 - test -s nohup.out && fail=1 + compare /dev/null nohup.out || fail=1 rm -f nohup.out exit $fail ) || fail=1 @@ -81,7 +86,7 @@ if test -t 1; then # It must exist. test -f nohup.out || fail=1 # It must be empty. - test -s nohup.out && fail=1 + compare /dev/null nohup.out || fail=1 fi cat <<\EOF > exp || fail=1 @@ -101,7 +106,7 @@ if test -t 1; then # It must exist. test -f nohup.out || fail=1 # It must be empty. - test -s nohup.out && fail=1 + compare /dev/null nohup.out || fail=1 fi cat <<\EOF > exp || fail=1 diff --git a/tests/misc/nproc-avail.sh b/tests/misc/nproc-avail.sh index 8b0e8dcb..1a7e7219 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2009-2014 Free Software Foundation, Inc. # This program is free software: 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 d82dc930..c8fe9bae 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2009-2014 Free Software Foundation, Inc. # This program is free software: 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/numfmt.pl b/tests/misc/numfmt.pl index 61917fb8..dfb4b2e0 100644..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 Free Software Foundation, Inc. +# Copyright (C) 2012-2014 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -260,7 +260,7 @@ my @Tests = # so these are 40 of "M", not 40,000,000. ['mix-1', '--suffix=M --from=si 40M', {OUT=>"40M"}], - # These are fourty-million Ms . + # These are forty-million Ms . ['mix-2', '--suffix=M --from=si 40MM', {OUT=>"40000000M"}], ['mix-3', '--suffix=M --from=auto 40MM', {OUT=>"40000000M"}], @@ -695,11 +695,11 @@ my @Tests = {EXIT=>1}], ['fmt-err-4', '--format "%d"', {ERR=>"$prog: invalid format '%d', " . - "directive must be %['][-][N]f\n"}, + "directive must be %[0]['][-][N]f\n"}, {EXIT=>1}], ['fmt-err-5', '--format "% -43 f"', {ERR=>"$prog: invalid format '% -43 f', " . - "directive must be %['][-][N]f\n"}, + "directive must be %[0]['][-][N]f\n"}, {EXIT=>1}], ['fmt-err-6', '--format "%f %f"', {ERR=>"$prog: format '%f %f' has too many % directives\n"}, @@ -708,9 +708,6 @@ my @Tests = {ERR=>"$prog: invalid format '%123456789012345678901234567890f'". " (width overflow)\n"}, {EXIT=>1}], - ['fmt-err-8', '--format "%f" --padding 20', - {ERR=>"$prog: --padding cannot be combined with --format\n"}, - {EXIT=>1}], ['fmt-err-9', '--format "%f" --grouping', {ERR=>"$prog: --grouping cannot be combined with --format\n"}, {EXIT=>1}], @@ -748,6 +745,17 @@ my @Tests = ['fmt-15', '--format "--%100000f--" --to=si 4200', {OUT=>"--" . " " x 99996 . "4.2K--" }], + # --format padding overrides --padding + ['fmt-16', '--format="%6f" --padding=66 1234',{OUT=>" 1234"}], + + # zero padding + ['fmt-17', '--format="%06f" 1234',{OUT=>"001234"}], + # also support spaces (which are ignored as spacing is handled separately) + ['fmt-18', '--format="%0 6f" 1234',{OUT=>"001234"}], + # handle generic padding in combination + ['fmt-22', '--format="%06f" --padding=7 1234',{OUT=>" 001234"}], + ['fmt-23', '--format="%06f" --padding=-7 1234',{OUT=>"001234 "}], + ## Check all errors again, this time with --invalid=fail ## Input will be printed without conversion, @@ -881,13 +889,20 @@ my @Locale_Tests = ['lcl-fmt-4', '--format "--%-10f--" --to=si 5000000', {OUT=>"--5,0M --"}, {ENV=>"LC_ALL=$locale"}], + # handle zero/grouping in combination + ['lcl-fmt-5', '--format="%\'06f" 1234',{OUT=>"01 234"}, + {ENV=>"LC_ALL=$locale"}], + ['lcl-fmt-6', '--format="%0\'6f" 1234',{OUT=>"01 234"}, + {ENV=>"LC_ALL=$locale"}], + ['lcl-fmt-7', '--format="%0\'\'6f" 1234',{OUT=>"01 234"}, + {ENV=>"LC_ALL=$locale"}], ); if ($locale ne 'C') { # Reset locale to 'C' if LOCALE_FR_UTF8 doesn't output as expected # as determined by the separate printf program. - open(LOC_NUM, "LC_ALL=$locale printf \"%'d\" 1234|") + open(LOC_NUM, "env LC_ALL=$locale printf \"%'d\" 1234|") or die "Can't fork command: $!"; my $loc_num = <LOC_NUM>; close(LOC_NUM) || die "Failed to read grouped number from printf"; diff --git a/tests/misc/od-N.sh b/tests/misc/od-N.sh index 8a741fb1..247ea546 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2001-2014 Free Software Foundation, Inc. # This program is free software: 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 new file mode 100755 index 00000000..a01ae0a8 --- /dev/null +++ b/tests/misc/od-endian.sh @@ -0,0 +1,49 @@ +#!/bin/sh +# verify that od --endian works properly + +# Copyright (C) 2014 Free Software Foundation, Inc. + +# This 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 + +in='0123456789abcdef' + +NL=' +' + +# rev(1) is not generally available, so here's a simplistic +# implementation sufficient for our purposes. +rev() { + while read line; do + printf '%s' "$line" | sed "s/./&\\$NL/g" | tac | paste -s -d '' + done +} + +in_swapped() { printf '%s' "$in" | sed "s/.\{$1\}/&\\$NL/g" | rev |tr -d '\n'; } + +for e in little big; do + test $e = little && eo=big || eo=little + for s in 1 2 4 8 16; do + for t in x f; do + od -t $t$s --endian=$e /dev/null > /dev/null 2>&1 || continue + printf '%s' "$in" | od -An -t $t$s --endian=$e > out1 + in_swapped "$s" | od -An -t $t$s --endian=$eo > out2 + compare out1 out2 || fail=1 + done + done +done + +Exit $fail diff --git a/tests/misc/od-float.sh b/tests/misc/od-float.sh index 306c3abe..8a8e29b2 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2010-2014 Free Software Foundation, Inc. # This program is free software: 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-multiple-t.sh b/tests/misc/od-multiple-t.sh index 2b8de711..451fa2f5 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2008-2014 Free Software Foundation, Inc. # This program is free software: 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 f55e1b70..6e72dee7 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2002-2014 Free Software Foundation, Inc. # This program is free software: 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 0649b1c6..edddf4e3 100755 --- a/tests/misc/od.pl +++ b/tests/misc/od.pl @@ -1,7 +1,7 @@ #!/usr/bin/perl # Exercise od -# Copyright (C) 2006-2013 Free Software Foundation, Inc. +# Copyright (C) 2006-2014 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -57,6 +57,13 @@ my @Tests = # even if the kernel reports that the file has stat.st_size = 0. ['j-proc', "-An -c -j $proc_file_byte_count $proc_file", {IN=>{f2=>'e'}}, {OUT=>" e\n"}], + + # Ensure that a large width does not cause trouble. + # From coreutils-7.0 through coreutils-8.21, these would print + # approximately 128KiB of padding. + ['wide-a', '-a -w65537 -An', {IN=>{g=>'x'}}, {OUT=>" x\n"}], + ['wide-c', '-c -w65537 -An', {IN=>{g=>'x'}}, {OUT=>" x\n"}], + ['wide-x', '-tx1 -w65537 -An', {IN=>{g=>'B'}}, {OUT=>" 42\n"}], ); my $save_temps = $ENV{DEBUG}; diff --git a/tests/misc/paste.pl b/tests/misc/paste.pl index 783a5d42..04f8ec07 100755 --- a/tests/misc/paste.pl +++ b/tests/misc/paste.pl @@ -1,7 +1,7 @@ #!/usr/bin/perl # Test paste. -# Copyright (C) 2003-2013 Free Software Foundation, Inc. +# Copyright (C) 2003-2014 Free Software Foundation, Inc. # This program is free software: 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 eed71d5f..616e763f 100755 --- a/tests/misc/pathchk1.sh +++ b/tests/misc/pathchk1.sh @@ -1,7 +1,7 @@ #!/bin/sh # pathchk tests -# Copyright (C) 2002-2013 Free Software Foundation, Inc. +# Copyright (C) 2002-2014 Free Software Foundation, Inc. # This program is free software: 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/printenv.sh b/tests/misc/printenv.sh index e7dbbeef..054b02c2 100755 --- a/tests/misc/printenv.sh +++ b/tests/misc/printenv.sh @@ -1,7 +1,7 @@ #!/bin/sh # Verify behavior of printenv. -# Copyright (C) 2009-2013 Free Software Foundation, Inc. +# Copyright (C) 2009-2014 Free Software Foundation, Inc. # This 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 @@ fi # Printing a single variable's value. env -- printenv ENV_TEST > out test $? = 1 || fail=1 -test -s out && fail=1 +compare /dev/null out || fail=1 echo a > exp || framework_failure_ ENV_TEST=a env -- printenv ENV_TEST > out || fail=1 compare exp out || fail=1 @@ -76,6 +76,6 @@ compare exp out || fail=1 # Bug present through coreutils 8.0. env a=b=c printenv a=b > out test $? = 1 || fail=1 -test -s out && fail=1 +compare /dev/null out || fail=1 Exit $fail diff --git a/tests/misc/printf-cov.pl b/tests/misc/printf-cov.pl index 44250aab..3d797284 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2008-2014 Free Software Foundation, Inc. # This program is free software: 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 d59899cb..27503fae 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2002-2014 Free Software Foundation, Inc. # This program is free software: 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 0db6f7b1..6083806d 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2007-2014 Free Software Foundation, Inc. # This 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,7 @@ prog=printf . "${srcdir=.}/tests/init.sh"; path_prepend_ ./src print_ver_ printf - -require_ulimit_ +require_ulimit_v_ # Up to coreutils-6.9, "printf %.Nf 0" would encounter an ENOMEM internal diff --git a/tests/misc/printf.sh b/tests/misc/printf.sh index d2ff3edb..b2292252 100755 --- a/tests/misc/printf.sh +++ b/tests/misc/printf.sh @@ -1,7 +1,7 @@ #!/bin/sh # basic tests for printf -# Copyright (C) 2002-2013 Free Software Foundation, Inc. +# Copyright (C) 2002-2014 Free Software Foundation, Inc. # This program is free software: 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-overrun.sh b/tests/misc/ptx-overrun.sh index a89a1b2c..be9fb524 100755 --- a/tests/misc/ptx-overrun.sh +++ b/tests/misc/ptx-overrun.sh @@ -1,7 +1,6 @@ #!/bin/sh -# Trigger a heap-clobbering bug in ptx from coreutils-6.10 and earlier. -# Copyright (C) 2008-2013 Free Software Foundation, Inc. +# Copyright (C) 2008-2014 Free Software Foundation, Inc. # This 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,12 +18,12 @@ . "${srcdir=.}/tests/init.sh"; path_prepend_ ./src print_ver_ ptx +# Trigger a heap-clobbering bug in ptx from coreutils-6.10 and earlier. # Using a long file name makes an abort more likely. # Even with no file name, valgrind detects the buffer overrun. f=01234567890123456789012345678901234567890123456789 touch $f empty || framework_failure_ - # Specifying a regular expression ending in a lone backslash # would cause ptx to write beyond the end of a malloc'd buffer. ptx -F '\' $f < /dev/null > out || fail=1 @@ -32,4 +31,14 @@ ptx -S 'foo\' $f < /dev/null >> out || fail=1 ptx -W 'bar\\\' $f < /dev/null >> out || fail=1 compare out empty || fail=1 + +# Trigger an invalid heap reference noticed by gcc -fsanitize=address +# from coreutils-8.22 and earlier. As well as an invalid memory reference, +# the issue can be seen in the output, with non deterministice whitespace +# trimming when multiple files are specified. +printf '%s\n' 'This is a ptx whitespace Trimming test' > ws.in +ptx ws.in ws.in | sort | uniq -u > out +compare /dev/null out || fail=1 + + Exit $fail diff --git a/tests/misc/ptx.pl b/tests/misc/ptx.pl index b36eeb98..8a91d616 100755 --- a/tests/misc/ptx.pl +++ b/tests/misc/ptx.pl @@ -1,6 +1,6 @@ #!/usr/bin/perl -# Copyright (C) 2008-2013 Free Software Foundation, Inc. +# Copyright (C) 2008-2014 Free Software Foundation, Inc. # This 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,6 +33,13 @@ my @Tests = # with coreutils-6.12 and earlier, this would act like "ptx F1 F1" ["2files", '-g1 -w1', {IN=>{F1=>"a"}}, {IN=>{F2=>"b"}}, {OUT=>" a\n b\n"}], + +# with coreutils-8.22 and earlier, the --format long option would +# fall through into the --help case. +["format-r", '--format=roff', {IN=>"foo\n"}, + {OUT=>".xx \"\" \"\" \"foo\" \"\"\n"}], +["format-t", '--format=tex', {IN=>"foo\n"}, + {OUT=>"\\xx {}{}{foo}{}{}\n"}], ); @Tests = triple_test \@Tests; diff --git a/tests/misc/pwd-long.sh b/tests/misc/pwd-long.sh index 3b3f83d4..1ba0c1a9 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2006-2014 Free Software Foundation, Inc. # This program is free software: 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-option.sh b/tests/misc/pwd-option.sh index 9733e108..0eba9429 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2009-2014 Free Software Foundation, Inc. # This 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,7 @@ print_ver_ pwd mkdir -p a/b || framework_failure_ ln -s a/b c || framework_failure_ -base=$(env -- pwd) +base=$(env -- pwd -P) # Remove any logical paths from $PWD. cd "$base" || framework_failure_ diff --git a/tests/misc/readlink-fp-loop.sh b/tests/misc/readlink-fp-loop.sh index 6c7f70ac..4ae2dc52 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2007-2014 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -18,7 +18,7 @@ . "${srcdir=.}/tests/init.sh"; path_prepend_ ./src print_ver_ readlink -cwd=$("$abs_top_builddir/src/pwd") +cwd=$(env pwd -P) # To trigger this bug, we have to construct a name/situation during # the resolution of which the code dereferences the same symlink (S) diff --git a/tests/misc/readlink-root.sh b/tests/misc/readlink-root.sh index ddd49092..f33574cb 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2012-2014 Free Software Foundation, Inc. # This program is free software: 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 7a8bf497..257b9f24 100755 --- a/tests/misc/realpath.sh +++ b/tests/misc/realpath.sh @@ -1,7 +1,7 @@ #!/bin/sh # Validate realpath operation -# Copyright (C) 2011-2013 Free Software Foundation, Inc. +# Copyright (C) 2011-2014 Free Software Foundation, Inc. # This program is free software: 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/runcon-no-reorder.sh b/tests/misc/runcon-no-reorder.sh index 27656c7d..ca8ad5b3 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2007-2014 Free Software Foundation, Inc. # This 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 @@ echo "$diag" > exp || framework_failure_ # On such a system it fails with the above diagnostic, which is fine. # Before the no-reorder change, it would have failed with a diagnostic # about -j being an invalid option. -runcon $(id -Z) true -j 2> out && : > exp +runcon $(id -Z) true -j 2> out && > exp # When run on a system with no /selinux/context (i.e., in a chroot), # it chcon fails with this: "runcon: invalid context: \ diff --git a/tests/misc/selinux.sh b/tests/misc/selinux.sh index b30bcbcf..2a8ad89f 100755 --- a/tests/misc/selinux.sh +++ b/tests/misc/selinux.sh @@ -1,7 +1,7 @@ #!/bin/sh # Test SELinux-related options. -# Copyright (C) 2007-2013 Free Software Foundation, Inc. +# Copyright (C) 2007-2014 Free Software Foundation, Inc. # This 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,6 +44,12 @@ done # ensure that ls -l output includes the ".". 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 +fi + # Copy each to a new directory and ensure that context is preserved. cp -r --preserve=all d f p s1 || fail=1 for i in d f p; do diff --git a/tests/misc/seq-long-double.sh b/tests/misc/seq-long-double.sh index 45e2f05f..78ed50f5 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2008-2014 Free Software Foundation, Inc. # This program is free software: 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.pl b/tests/misc/seq.pl index b3496d62..92484363 100755 --- a/tests/misc/seq.pl +++ b/tests/misc/seq.pl @@ -1,7 +1,7 @@ #!/usr/bin/perl # Test "seq". -# Copyright (C) 1999-2013 Free Software Foundation, Inc. +# Copyright (C) 1999-2014 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -143,6 +143,9 @@ my @Tests = ['not-fast-1', qw(1 3 1), {OUT => [qw(1)]}], ['not-fast-2', qw(1 1 4.2), {OUT => [qw(1 2 3 4)]}], ['not-fast-3', qw(1 1 0)], + # In 8.20..8.22 a start or end of -0 was broken + ['not-fast-4', qw(-0 10), {OUT => [qw(-0 1 2 3 4 5 6 7 8 9 10)]}], + ['not-fast-5', qw(1 -0)], # Ensure the correct parameters are passed to the fast path ['fast-1', qw(4), {OUT => [qw(1 2 3 4)]}], diff --git a/tests/misc/sha1sum-vec.pl b/tests/misc/sha1sum-vec.pl index 6df91d64..14005a76 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2000-2014 Free Software Foundation, Inc. # This program is free software: 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 327c4dd8..fdb243a0 100755 --- a/tests/misc/sha1sum.pl +++ b/tests/misc/sha1sum.pl @@ -1,7 +1,7 @@ #!/usr/bin/perl # Test "sha1sum". -# Copyright (C) 2000-2013 Free Software Foundation, Inc. +# Copyright (C) 2000-2014 Free Software Foundation, Inc. # This 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,9 @@ my @Tests = {OUT=>"50abf5706a150990a08b2c5ea40fa0e585554732 f\n"}], ['million-a', {IN=> {f=> 'a' x 1000000}}, {OUT=>"34aa973cd4c4daa4f61eeb2bdbad27316534016f f\n"}], - ['bs-sha', {IN=> {".\\foo"=> ''}}, + ['bs-sha-1', {IN=> {".\nfoo"=> ''}}, + {OUT=>"\\$sha_degenerate .\\nfoo\n"}], + ['bs-sha-2', {IN=> {".\\foo"=> ''}}, {OUT=>"\\$sha_degenerate .\\\\foo\n"}], # The sha1sum and md5sum drivers share a lot of code. # Ensure that sha1sum does *not* share the part that makes diff --git a/tests/misc/sha224sum.pl b/tests/misc/sha224sum.pl index ef881280..384738b8 100755 --- a/tests/misc/sha224sum.pl +++ b/tests/misc/sha224sum.pl @@ -1,7 +1,7 @@ #!/usr/bin/perl # Test "sha224sum". -# Copyright (C) 2005-2013 Free Software Foundation, Inc. +# Copyright (C) 2005-2014 Free Software Foundation, Inc. # This program is free software: 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 2ad38e6e..e5f29392 100755 --- a/tests/misc/sha256sum.pl +++ b/tests/misc/sha256sum.pl @@ -1,7 +1,7 @@ #!/usr/bin/perl # Test "sha256sum". -# Copyright (C) 2005-2013 Free Software Foundation, Inc. +# Copyright (C) 2005-2014 Free Software Foundation, Inc. # This program is free software: 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 22e95e15..eafbf5b4 100755 --- a/tests/misc/sha384sum.pl +++ b/tests/misc/sha384sum.pl @@ -1,7 +1,7 @@ #!/usr/bin/perl # Test "sha384sum". -# Copyright (C) 2005-2013 Free Software Foundation, Inc. +# Copyright (C) 2005-2014 Free Software Foundation, Inc. # This program is free software: 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 5e121339..c4a1cd4a 100755 --- a/tests/misc/sha512sum.pl +++ b/tests/misc/sha512sum.pl @@ -1,7 +1,7 @@ #!/usr/bin/perl # Test "sha512sum". -# Copyright (C) 2005-2013 Free Software Foundation, Inc. +# Copyright (C) 2005-2014 Free Software Foundation, Inc. # This program is free software: 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 0cdc91fc..5434229c 100755 --- a/tests/misc/shred-exact.sh +++ b/tests/misc/shred-exact.sh @@ -1,7 +1,7 @@ #!/bin/sh -# make sure that neither --exact nor --zero gobbles a command line argument +# Test functionality of --exact -# Copyright (C) 2000-2013 Free Software Foundation, Inc. +# Copyright (C) 2000-2014 Free Software Foundation, Inc. # This 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,7 @@ print_ver_ shred +# make sure that neither --exact nor --zero gobbles a command line argument for opt in --exact --zero; do echo a > a || fail=1 echo bb > b || fail=1 @@ -33,4 +34,16 @@ for opt in --exact --zero; do test -f c && fail=1 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). +truncate -s1MiB file.slop || framework_failure_ +truncate -s+1 file.slop || framework_failure_ +shred --exact -n2 file.slop || fail=1 + +# make sure direct I/O is handled appropriately at start of file +truncate -s1 file.slop || framework_failure_ +shred --exact -n2 file.slop || fail=1 + Exit $fail diff --git a/tests/misc/id-groups.sh b/tests/misc/shred-negative.sh index ff3dc59f..86cbf3e0 100755 --- a/tests/misc/id-groups.sh +++ b/tests/misc/shred-negative.sh @@ -1,6 +1,7 @@ #!/bin/sh -# Ensure that "id" outputs groups for a user -# Copyright (C) 2009-2013 Free Software Foundation, Inc. +# Exercise shred -s-3 FILE + +# Copyright (C) 2014 Free Software Foundation, Inc. # This 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,8 +17,12 @@ # along with this program. If not, see <http://www.gnu.org/licenses/>. . "${srcdir=.}/tests/init.sh"; path_prepend_ ./src -print_ver_ id +print_ver_ shred + +echo 'shred: -2: invalid file size' > exp || framework_failure_ +echo 1234 > f || framework_failure_ -id -G $(id -nu) || fail=1 +shred -s-2 f 2>err && fail=1 +compare exp err || fail=1 Exit $fail diff --git a/tests/misc/shred-passes.sh b/tests/misc/shred-passes.sh index cfdd68e9..268af950 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2009-2014 Free Software Foundation, Inc. # This 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,9 +20,9 @@ print_ver_ shred -# shred a single letter, zero length file which should result in +# shred a single letter, which should result in # 3 random passes and a single rename. -touch f || framework_failure_ +printf 1 > f || framework_failure_ echo "\ shred: f: pass 1/3 (random)... shred: f: pass 2/3 (random)... @@ -31,9 +31,21 @@ shred: f: removing shred: f: renamed to 0 shred: f: removed" > exp || framework_failure_ +shred -v -u f 2>out || fail=1 + +compare exp out || fail=1 + +# Likewise but for a zero length file +# to bypass the data passes +touch f || framework_failure_ +echo "\ +shred: f: removing +shred: f: renamed to 0 +shred: f: removed" > exp || framework_failure_ shred -v -u f 2>out || fail=1 compare exp out || fail=1 + Exit $fail diff --git a/tests/misc/shred-remove.sh b/tests/misc/shred-remove.sh index 891dc2d2..9765e352 100755 --- a/tests/misc/shred-remove.sh +++ b/tests/misc/shred-remove.sh @@ -1,7 +1,7 @@ #!/bin/sh -# Exercise a bug that was fixed in shred-4.0l +# Exercise shred --remove -# Copyright (C) 1999-2013 Free Software Foundation, Inc. +# Copyright (C) 1999-2014 Free Software Foundation, Inc. # This 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,16 +21,27 @@ print_ver_ shred skip_if_root_ # The length of the basename is what matters. -# In this case, shred would try to rename the file 256^10 times +# In this case, shred-4.0l would try to rename the file 256^10 times # before terminating. file=0123456789 touch $file || framework_failure_ 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 || : +shred -u $file > /dev/null 2>&1 && fail=1 +rm -f $file || framework_failure_ + +# Ensure all --remove methods at least unlink the file +for mode in '' '=unlink' '=wipe' '=wipesync'; do + touch $file || framework_failure_ + shred -n0 --remove"$mode" $file || fail=1 + test -e $file && fail=1 +done + +# Ensure incorrect params are diagnosed +touch $file || framework_failure_ +shred -n0 --remove=none $file 2>/dev/null && fail=1 Exit $fail diff --git a/tests/misc/shuf-reservoir.sh b/tests/misc/shuf-reservoir.sh new file mode 100755 index 00000000..aa9edbea --- /dev/null +++ b/tests/misc/shuf-reservoir.sh @@ -0,0 +1,73 @@ +#!/bin/sh +# Exercise shuf's reservoir-sampling code +# NOTE: +# These tests do not check valid randomness, +# they just check memory allocation related code. + +# Copyright (C) 2013-2014 Free Software Foundation, Inc. + +# This 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_ shuf +expensive_ +require_valgrind_ + +# Only exit with error for leaks when in development mode +# in which case we enable code to suppress inconsequential leaks. +grep '^#define lint 1' "$CONFIG_HEADER" && leaklevel=full || leaklevel=summary + +# Run "shuf" with specific number of input lines and output lines +# Check the output for expected number of lines. +run_shuf_n() +{ + INPUT_LINES="$1" + OUTPUT_LINES="$2" + + # Critical memory-related bugs will cause a segfault here + # (with varying numbers of input/output lines) + seq "$INPUT_LINES" | valgrind --leak-check=$leaklevel --error-exitcode=1 \ + shuf -n "$OUTPUT_LINES" -o "out_${INPUT_LINES}_${OUTPUT_LINES}" || return 1 + + EXPECTED_LINES="$OUTPUT_LINES" + test "$INPUT_LINES" -lt "$OUTPUT_LINES" && EXPECTED_LINES="$INPUT_LINES" + + # There is no sure way to verify shuffled output (as it is random). + # Ensure we have the correct number of all numeric lines non duplicated lines. + GOOD_LINES=$(grep '^[0-9][0-9]*$' "out_${INPUT_LINES}_${OUTPUT_LINES}" | + sort -un | wc -l) || framework_failure_ + LINES=$(wc -l < "out_${INPUT_LINES}_${OUTPUT_LINES}") || framework_failure_ + + test "$EXPECTED_LINES" -eq "$GOOD_LINES" || return 1 + test "$EXPECTED_LINES" -eq "$LINES" || return 1 + + return 0 +} + +# Test multiple combinations of input lines and output lines. +# (e.g. small number of input lines and large number of output lines, +# and vice-versa. Also, each reservoir allocation uses a 1024-lines batch, +# so test 1023/1024/1025 and related values). +TEST_LINES="0 1 5 1023 1024 1025 3071 3072 3073" + +for IN_N in $TEST_LINES; do + for OUT_N in $TEST_LINES; do + run_shuf_n "$IN_N" "$OUT_N" || { + fail=1 + echo "shuf-reservoir-sampling failed with IN_N=$IN_N OUT_N=$OUT_N" >&2; + } + done +done + +Exit $fail diff --git a/tests/misc/shuf.sh b/tests/misc/shuf.sh index 9c9526d4..d7251d1d 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2006-2014 Free Software Foundation, Inc. # This 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,6 +43,10 @@ compare in out1 || { fail=1; echo "not a permutation" 1>&2; } t=$(shuf -e a b c d e | sort | fmt) test "$t" = 'a b c d e' || { fail=1; echo "not a permutation" 1>&2; } +# coreutils-8.22 dumps core. +shuf -er +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 @@ -57,4 +61,104 @@ cmp out exp || { fail=1; echo "missing NUL terminator?" 1>&2; } timeout 10 shuf -i1-$SIZE_MAX -n2 >/dev/null || { fail=1; echo "couldn't get a small subset" >&2; } +# Ensure shuf -n0 doesn't read any input or open specified files +touch unreadable || framework_failure_ +chmod 0 unreadable || framework_failure_ +if ! test -r unreadable; then + shuf -n0 unreadable || fail=1 + shuf -n1 unreadable && fail=1 +fi + +# Multiple -n is accepted, should use the smallest value +shuf -n10 -i0-9 -n3 -n20 > exp || framework_failure_ +c=$(wc -l < exp) || framework_failure_ +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 && + { fail=1; echo "shuf did not detect erroneous -e and -i usage.">&2 ; } +# Test invalid value for -n +: | shuf -nA && + { fail=1; echo "shuf did not detect erroneous -n usage.">&2 ; } +# Test multiple -i +shuf -i0-9 -n10 -i8-90 && + { 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 && + { fail=1; echo "shuf did not detect erroneous -i$ARG usage.">&2 ; } +done + +# multiple -o are forbidden +shuf -i0-9 -o A -o B && + { 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 && + { fail=1; echo "shuf did not detect multiple --random-source usage.">&2 ; } + +# Test --repeat option + +# --repeat without count should return an indefinite number of lines +shuf --rep -i 0-10 | head -n 1000 > exp || framework_failure_ +c=$(wc -l < exp) || framework_failure_ +test "$c" -eq 1000 \ + || { fail=1; echo "--repeat does not repeat indefinitely">&2 ; } + +# --repeat can output more values than the input range +shuf --rep -i0-9 -n1000 > exp || framework_failure_ +c=$(wc -l < exp) || framework_failure_ +test "$c" -eq 1000 || { fail=1; echo "--repeat with --count failed">&2 ; } + +# Check output values (this is not bullet-proof, but drawing 1000 values +# between 0 and 9 should produce all values, unless there's a bug in shuf +# or a very poor random source, or extremely bad luck) +c=$(sort -nu exp | paste -s -d ' ') || framework_failure_ +test "$c" = "0 1 2 3 4 5 6 7 8 9" || + { fail=1; echo "--repeat produced bad output">&2 ; } + +# 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_ +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 ; } + +# --repeat,-i,count=0 should not fail and produce no output +shuf --rep -i0-9 -n0 > exp || framework_failure_ +# file size should be zero (no output from shuf) +test \! -s exp || + { fail=1; echo "--repeat,-i0-9,-n0 produced bad output">&2 ; } + +# --repeat with -e, without count, should repeat indefinitely +shuf --rep -e A B C D | head -n 1000 > exp || framework_failure_ +c=$(wc -l < exp) || framework_failure_ +test "$c" -eq 1000 || + { fail=1; echo "--repeat,-e does not repeat indefinitely">&2 ; } + +# --repeat with STDIN, without count, should repeat indefinitely +printf "A\nB\nC\nD\nE\n" | shuf --rep | head -n 1000 > exp || framework_failure_ +c=$(wc -l < exp) || framework_failure_ +test "$c" -eq 1000 || + { fail=1; echo "--repeat,STDIN does not repeat indefinitely">&2 ; } + +# --repeat with STDIN,count - can return move values than input lines +printf "A\nB\nC\nD\nE\n" | shuf --rep -n2000 > exp || framework_failure_ +c=$(wc -l < exp) || framework_failure_ +test "$c" -eq 2000 || + { fail=1; echo "--repeat,STDIN,count failed">&2 ; } + +# Check output values (this is not bullet-proof, but drawing 2000 values +# between A and E should produce all values, unless there's a bug in shuf +# or a very poor random source, or extremely bad luck) +c=$(sort -u exp | paste -s -d ' ') || framework_failure_ +test "$c" = "A B C D E" || + { fail=1; echo "--repeat,STDIN,count produced bad output">&2 ; } + +# --repeat,stdin,count=0 should not fail and produce no output +printf "A\nB\nC\nD\nE\n" | shuf --rep -n0 > exp || framework_failure_ +# file size should be zero (no output from shuf) +test \! -s exp || + { fail=1; echo "--repeat,STDIN,-n0 produced bad output">&2 ; } + Exit $fail diff --git a/tests/misc/sort-NaN-infloop.sh b/tests/misc/sort-NaN-infloop.sh index 2ec13ee0..9c6e021a 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2011-2014 Free Software Foundation, Inc. # This program is free software: 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 04f2af99..c074301f 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2010-2014 Free Software Foundation, Inc. # This program is free software: 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 1b1f3a9c..cc1e6d36 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2010-2014 Free Software Foundation, Inc. # This program is free software: 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-proc.sh b/tests/misc/sort-compress-proc.sh index 3888fdb6..d06eb56f 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2010-2014 Free Software Foundation, Inc. # This program is free software: 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.sh b/tests/misc/sort-compress.sh index c7587c43..8f215b8b 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2007-2014 Free Software Foundation, Inc. # This 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 @@ chmod +x gzip # Use a subshell and an exec to work around a bug in FreeBSD 5.0 /bin/sh. ( # ash doesn't support "trap '' CHLD"; it knows only signal numbers. - sig=$("$abs_top_builddir/src/kill" -l CHLD 2>/dev/null) && trap '' $sig + sig=$(env kill -l CHLD 2>/dev/null) && trap '' $sig # This should force the use of child processes for "compression" PATH=.:$PATH exec sort -S 1k --compress-program=gzip in > /dev/null diff --git a/tests/misc/sort-continue.sh b/tests/misc/sort-continue.sh index bd569d0d..1c4030d9 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2009-2014 Free Software Foundation, Inc. # This program is free software: 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 9d4f8295..ff1e19b6 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2010-2014 Free Software Foundation, Inc. # This program is free software: 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 c9f1b9f3..fd16829b 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2010-2014 Free Software Foundation, Inc. # This program is free software: 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 0dac3a9d..e3cd1907 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2012-2014 Free Software Foundation, Inc. # This program is free software: 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 83a55f51..2a70253e 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2012-2014 Free Software Foundation, Inc. # This program is free software: 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-files0-from.pl b/tests/misc/sort-files0-from.pl index d843b646..77c1b1aa 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2006-2014 Free Software Foundation, Inc. # This program is free software: 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 dd3c079c..7a4e8292 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2010-2014 Free Software Foundation, Inc. # This program is free software: 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 bcd023ae..0df7aa66 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2009-2014 Free Software Foundation, Inc. # This 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,6 @@ . "${srcdir=.}/tests/init.sh"; path_prepend_ ./src print_ver_ sort -require_ulimit_ mkdir in err || framework_failure_ diff --git a/tests/misc/sort-merge.pl b/tests/misc/sort-merge.pl index 5b940f25..06e3c15f 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2002-2014 Free Software Foundation, Inc. # This program is free software: 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 99008367..40c814da 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2010-2014 Free Software Foundation, Inc. # This program is free software: 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 4313eb2f..2397fb4b 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2005-2014 Free Software Foundation, Inc. # This program is free software: 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 768fc1f4..49ed920f 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2010-2014 Free Software Foundation, Inc. # This program is free software: 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-stale-thread-mem.sh b/tests/misc/sort-stale-thread-mem.sh index 78fa2cda..78defd23 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2010-2014 Free Software Foundation, Inc. # This program is free software: 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 c13e9823..3019cbe8 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2012-2014 Free Software Foundation, Inc. # This program is free software: 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 58893158..148dc243 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2010-2014 Free Software Foundation, Inc. # This program is free software: 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 f34df96e..d7a7629c 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2010-2014 Free Software Foundation, Inc. # This program is free software: 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 d9686fbe..d8db1e1c 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2008-2014 Free Software Foundation, Inc. # This program is free software: 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 59c30e56..db732094 100755 --- a/tests/misc/sort.pl +++ b/tests/misc/sort.pl @@ -1,6 +1,6 @@ #!/usr/bin/perl -# Copyright (C) 2008-2013 Free Software Foundation, Inc. +# Copyright (C) 2008-2014 Free Software Foundation, Inc. # This program is free software: 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-birthtime.sh b/tests/misc/stat-birthtime.sh index b30c972b..f06ddea8 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2010-2014 Free Software Foundation, Inc. # This program is free software: 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 547f5b8f..3982f23b 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2003-2014 Free Software Foundation, Inc. # This program is free software: 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 a817b285..9f090a0f 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2009-2014 Free Software Foundation, Inc. # This program is free software: 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-mount.sh b/tests/misc/stat-mount.sh index f94c77cb..ab1ff479 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2010-2014 Free Software Foundation, Inc. # This 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,8 +19,10 @@ . "${srcdir=.}/tests/init.sh"; path_prepend_ ./src print_ver_ stat -df_mnt=$(df -P . | sed -n '2s/.* \([^ ]*$\)/\1/p') stat_mnt=$(stat -c%m .) || fail=1 -test "$stat_mnt" || fail=1 +case "$stat_mnt" in + /*) ;; + *) fail=1;; +esac Exit $fail diff --git a/tests/misc/stat-nanoseconds.sh b/tests/misc/stat-nanoseconds.sh index 9c891b76..30c47c02 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2010-2014 Free Software Foundation, Inc. # This program is free software: 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 fb31043f..5021130d 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2005-2014 Free Software Foundation, Inc. # This program is free software: 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 47aa7907..465de2ed 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2009-2014 Free Software Foundation, Inc. # This program is free software: 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/stdbuf.sh b/tests/misc/stdbuf.sh index 12347ecc..e0ca3530 100755 --- a/tests/misc/stdbuf.sh +++ b/tests/misc/stdbuf.sh @@ -1,7 +1,7 @@ #!/bin/sh # Exercise stdbuf functionality -# Copyright (C) 2009-2013 Free Software Foundation, Inc. +# Copyright (C) 2009-2014 Free Software Foundation, Inc. # This 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,6 +50,8 @@ stdbuf -o$SIZE_OFLOW true # size too large test $? = 125 || fail=1 stdbuf -iL true # line buffering stdin disallowed test $? = 125 || fail=1 +stdbuf true # a buffering mode must be specified +test $? = 125 || fail=1 stdbuf -i0 -o0 -e0 true || fail=1 #check all files stdbuf -o1 . # invalid command test $? = 126 || fail=1 diff --git a/tests/misc/stty-invalid.sh b/tests/misc/stty-invalid.sh index c6400fcf..36bc8aa0 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2007-2014 Free Software Foundation, Inc. # This program is free software: 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-pairs.sh b/tests/misc/stty-pairs.sh index be5b6f84..1a7c26cf 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-2013 Free Software Foundation, Inc. +# Copyright (C) 1998-2014 Free Software Foundation, Inc. # This program is free software: 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 586674ad..729d6f91 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-2013 Free Software Foundation, Inc. +# Copyright (C) 1998-2014 Free Software Foundation, Inc. # This program is free software: 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.sh b/tests/misc/stty.sh index 2f9b9a3b..ab1c78de 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-2013 Free Software Foundation, Inc. +# Copyright (C) 1998-2014 Free Software Foundation, Inc. # This 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,7 +52,10 @@ for opt in $options; do # other serial control settings give the same error. So skip them. # Also on ppc*|sparc* glibc platforms 'icanon' gives the same error. # See: http://debbugs.gnu.org/7228#14 - case $opt in parenb|parodd|cstopb|crtscts|cdtrdsr|icanon) continue;; esac + case $opt in + parenb|parodd|cmspar) continue;; + cstopb|crtscts|cdtrdsr|icanon) continue;; + esac stty $opt || fail=1 diff --git a/tests/misc/sum-sysv.sh b/tests/misc/sum-sysv.sh index a1e8cee9..7624685f 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2001-2014 Free Software Foundation, Inc. # This program is free software: 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 3cabcc53..696eda4b 100755 --- a/tests/misc/sum.pl +++ b/tests/misc/sum.pl @@ -1,7 +1,7 @@ #!/usr/bin/perl # Test "sum". -# Copyright (C) 2000-2013 Free Software Foundation, Inc. +# Copyright (C) 2000-2014 Free Software Foundation, Inc. # This program is free software: 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/tac-2-nonseekable.sh b/tests/misc/tac-2-nonseekable.sh index ef434807..c27694c1 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 -# Copyright (C) 2011-2013 Free Software Foundation, Inc. +# Copyright (C) 2011-2014 Free Software Foundation, Inc. # This program is free software: 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/tac-continue.sh b/tests/misc/tac-continue.sh index 95f37d7b..d4280650 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2004-2014 Free Software Foundation, Inc. # This program is free software: 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/tac.pl b/tests/misc/tac.pl index b064b9d2..0f21affd 100755 --- a/tests/misc/tac.pl +++ b/tests/misc/tac.pl @@ -1,6 +1,6 @@ #!/usr/bin/perl -# Copyright (C) 2008-2013 Free Software Foundation, Inc. +# Copyright (C) 2008-2014 Free Software Foundation, Inc. # This program is free software: 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 bc6e6d4a..6798eb05 100755 --- a/tests/misc/tail.pl +++ b/tests/misc/tail.pl @@ -1,7 +1,7 @@ #!/usr/bin/perl # Test tail. -# Copyright (C) 2008-2013 Free Software Foundation, Inc. +# Copyright (C) 2008-2014 Free Software Foundation, Inc. # This program is free software: 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/tee-dash.sh b/tests/misc/tee-dash.sh index 9e511beb..761a4780 100755 --- a/tests/misc/tee-dash.sh +++ b/tests/misc/tee-dash.sh @@ -1,7 +1,7 @@ #!/bin/sh # test for "tee -". -# Copyright (C) 2005-2013 Free Software Foundation, Inc. +# Copyright (C) 2005-2014 Free Software Foundation, Inc. # This program is free software: 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/tee.sh b/tests/misc/tee.sh index bbaf99b7..f0072bfd 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2005-2014 Free Software Foundation, Inc. # This program is free software: 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-diag.pl b/tests/misc/test-diag.pl index 81ab60d8..14d0f4d5 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2006-2014 Free Software Foundation, Inc. # This program is free software: 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 ee9150d7..b27adb48 100755 --- a/tests/misc/test.pl +++ b/tests/misc/test.pl @@ -1,6 +1,6 @@ #!/usr/bin/perl -# Copyright (C) 2008-2013 Free Software Foundation, Inc. +# Copyright (C) 2008-2014 Free Software Foundation, Inc. # This program is free software: 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 6f16ba4c..b5f31c96 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 Free Software Foundation, Inc. +# Copyright (C) 2013-2014 Free Software Foundation, Inc. # This program is free software: 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 35a6be0b..23c1b065 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2011-2014 Free Software Foundation, Inc. # This program is free software: 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-parameters.sh b/tests/misc/timeout-parameters.sh index 06cdfb39..fca30f0b 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2008-2014 Free Software Foundation, Inc. # This program is free software: 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 6b5a6f10..8eaeef95 100755 --- a/tests/misc/timeout.sh +++ b/tests/misc/timeout.sh @@ -1,7 +1,7 @@ #!/bin/sh # Validate timeout basic operation -# Copyright (C) 2008-2013 Free Software Foundation, Inc. +# Copyright (C) 2008-2014 Free Software Foundation, Inc. # This 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,7 +51,7 @@ test $? = 124 && fail=1 # Use a subshell and an exec to work around a bug in FreeBSD 5.0 /bin/sh. ( # ash doesn't support "trap '' CHLD"; it knows only signal numbers. - sig=$("$abs_top_builddir/src/kill" -l CHLD 2>/dev/null) && trap '' $sig + sig=$(env kill -l CHLD 2>/dev/null) && trap '' $sig exec timeout 10 true ) || fail=1 diff --git a/tests/misc/tr-case-class.sh b/tests/misc/tr-case-class.sh index 1294f965..952aae45 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2010-2014 Free Software Foundation, Inc. # This program is free software: 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.pl b/tests/misc/tr.pl index 89693f91..e7018e79 100755 --- a/tests/misc/tr.pl +++ b/tests/misc/tr.pl @@ -1,6 +1,6 @@ #!/usr/bin/perl -# Copyright (C) 2008-2013 Free Software Foundation, Inc. +# Copyright (C) 2008-2014 Free Software Foundation, Inc. # This program is free software: 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 5386ce2d..c5bbc3b6 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2008-2014 Free Software Foundation, Inc. # This program is free software: 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 8bd67b6e..8ff09179 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2008-2014 Free Software Foundation, Inc. # This program is free software: 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-fail-diag.sh b/tests/misc/truncate-fail-diag.sh index 8e5f07ba..9f242d34 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2008-2014 Free Software Foundation, Inc. # This program is free software: 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 58e5c14e..c2c0bbfc 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2008-2014 Free Software Foundation, Inc. # This program is free software: 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 6fa1f0c6..1cf55330 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2008-2014 Free Software Foundation, Inc. # This program is free software: 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 dd0fc730..72ed626b 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2008-2014 Free Software Foundation, Inc. # This program is free software: 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-owned-by-other.sh b/tests/misc/truncate-owned-by-other.sh index e7f7157c..e70badb6 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2008-2014 Free Software Foundation, Inc. # This 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,16 +21,15 @@ print_ver_ truncate require_root_ -group_num=$(id -g $NON_ROOT_USERNAME) - # Create a file owned by root, and writable by $NON_ROOT_USERNAME. echo > root-owned || framework_failure_ -chgrp +$group_num . root-owned || framework_failure_ +chgrp +$NON_ROOT_GID . root-owned || framework_failure_ chmod g+w root-owned # Ensure that the current directory is searchable by $NON_ROOT_USERNAME. chmod g+x . -setuidgid $NON_ROOT_USERNAME env PATH="$PATH" truncate -s0 root-owned || fail=1 +chroot --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 21713d99..d9e6d64d 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2008-2014 Free Software Foundation, Inc. # This program is free software: 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-relative.sh b/tests/misc/truncate-relative.sh index fbbd4f97..3daa073e 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2008-2014 Free Software Foundation, Inc. # This program is free software: 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/tsort.pl b/tests/misc/tsort.pl index 5e598c74..e59af328 100755 --- a/tests/misc/tsort.pl +++ b/tests/misc/tsort.pl @@ -1,7 +1,7 @@ #!/usr/bin/perl # Test "tsort". -# Copyright (C) 1999-2013 Free Software Foundation, Inc. +# Copyright (C) 1999-2014 Free Software Foundation, Inc. # This program is free software: 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 755ffac0..b4d36de6 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2003-2014 Free Software Foundation, Inc. # This program is free software: 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 a1ce5c52..8c5b693b 100755 --- a/tests/misc/unexpand.pl +++ b/tests/misc/unexpand.pl @@ -1,7 +1,7 @@ #!/usr/bin/perl # Test "unexpand". -# Copyright (C) 2000-2013 Free Software Foundation, Inc. +# Copyright (C) 2000-2014 Free Software Foundation, Inc. # This program is free software: 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 35dff8e5..31c40e53 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2011-2014 Free Software Foundation, Inc. # This program is free software: 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.pl b/tests/misc/uniq.pl index 140a49b4..d07f15f1 100755 --- a/tests/misc/uniq.pl +++ b/tests/misc/uniq.pl @@ -1,7 +1,7 @@ #!/usr/bin/perl # Test uniq. -# Copyright (C) 2008-2013 Free Software Foundation, Inc. +# Copyright (C) 2008-2014 Free Software Foundation, Inc. # This 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,23 +80,8 @@ sub add_z_variants($) return @new; } -# I've only ever triggered the problem in a non-C locale. -my $locale = $ENV{LOCALE_FR}; -! defined $locale || $locale eq 'none' - and CuSkip::skip "$prog: skipping this test -- no appropriate locale\n"; - -# See if isblank returns true for nbsp. -my $x = qx!env printf '\xa0'| LC_ALL=$locale tr '[:blank:]' x!; -# If so, expect just one line of output in the schar test. -# Otherwise, expect two. -my $in = " y z\n\xa0 y z\n"; -my $schar_exp = $x eq 'x' ? " y z\n" : $in; - my @Tests = ( - # Test for a subtle, system-and-locale-dependent bug in uniq. - ['schar', '-f1', {IN => $in}, {OUT => $schar_exp}, - {ENV => "LC_ALL=$locale"}], ['1', '', {IN=>''}, {OUT=>''}], ['2', '', {IN=>"a\na\n"}, {OUT=>"a\n"}], ['3', '', {IN=>"a\na"}, {OUT=>"a\n"}], @@ -199,8 +184,76 @@ my @Tests = # Check that --zero-terminated is synonymous with -z. ['123', '--zero-terminated', {IN=>"a\na\nb"}, {OUT=>"a\na\nb\0"}], ['124', '--zero-terminated', {IN=>"a\0a\0b"}, {OUT=>"a\0b\0"}], + # Check ignore-case + ['125', '', {IN=>"A\na\n"}, {OUT=>"A\na\n"}], + ['126', '-i', {IN=>"A\na\n"}, {OUT=>"A\n"}], + ['127', '--ignore-case', {IN=>"A\na\n"}, {OUT=>"A\n"}], + # Check grouping + ['128', '--group=prepend', {IN=>"a\na\nb\n"}, {OUT=>"\na\na\n\nb\n"}], + ['129', '--group=append', {IN=>"a\na\nb\n"}, {OUT=>"a\na\n\nb\n\n"}], + ['130', '--group=separate',{IN=>"a\na\nb\n"}, {OUT=>"a\na\n\nb\n"}], + # no explicit grouping = separate + ['131', '--group', {IN=>"a\na\nb\n"}, {OUT=>"a\na\n\nb\n"}], + ['132', '--group=both', {IN=>"a\na\nb\n"}, {OUT=>"\na\na\n\nb\n\n"}], + # Grouping in the special case of a single group + ['133', '--group=prepend', {IN=>"a\na\n"}, {OUT=>"\na\na\n"}], + ['134', '--group=append', {IN=>"a\na\n"}, {OUT=>"a\na\n\n"}], + ['135', '--group=separate',{IN=>"a\na\n"}, {OUT=>"a\na\n"}], + ['136', '--group', {IN=>"a\na\n"}, {OUT=>"a\na\n"}], + # Grouping with empty input - should never print anything + ['137', '--group=prepend', {IN=>""}, {OUT=>""}], + ['138', '--group=append', {IN=>""}, {OUT=>""}], + ['139', '--group=separate', {IN=>""}, {OUT=>""}], + ['140', '--group=both', {IN=>""}, {OUT=>""}], + # Grouping with other options - must fail + ['141', '--group -c', {IN=>""}, {OUT=>""}, {EXIT=>1}, + {ERR=>"$prog: --group is mutually exclusive with -c/-d/-D/-u\n" . + "Try 'uniq --help' for more information.\n"}], + ['142', '--group -d', {IN=>""}, {OUT=>""}, {EXIT=>1}, + {ERR=>"$prog: --group is mutually exclusive with -c/-d/-D/-u\n" . + "Try 'uniq --help' for more information.\n"}], + ['143', '--group -u', {IN=>""}, {OUT=>""}, {EXIT=>1}, + {ERR=>"$prog: --group is mutually exclusive with -c/-d/-D/-u\n" . + "Try 'uniq --help' for more information.\n"}], + ['144', '--group -D', {IN=>""}, {OUT=>""}, {EXIT=>1}, + {ERR=>"$prog: --group is mutually exclusive with -c/-d/-D/-u\n" . + "Try 'uniq --help' for more information.\n"}], + # Grouping with badoption + ['145', '--group=badoption',{IN=>""}, {OUT=>""}, {EXIT=>1}, + {ERR=>"$prog: invalid argument 'badoption' for '--group'\n" . + "Valid arguments are:\n" . + " - 'prepend'\n" . + " - 'append'\n" . + " - 'separate'\n" . + " - 'both'\n" . + "Try '$prog --help' for more information.\n"}], ); +# Locale related tests + +my $locale = $ENV{LOCALE_FR}; +if ( defined $locale && $locale ne 'none' ) + { + # I've only ever triggered the problem in a non-C locale. + + # See if isblank returns true for nbsp. + my $x = qx!env printf '\xa0'| LC_ALL=$locale tr '[:blank:]' x!; + # If so, expect just one line of output in the schar test. + # Otherwise, expect two. + my $in = " y z\n\xa0 y z\n"; + my $schar_exp = $x eq 'x' ? " y z\n" : $in; + + my @Locale_Tests = + ( + # Test for a subtle, system-and-locale-dependent bug in uniq. + ['schar', '-f1', {IN => $in}, {OUT => $schar_exp}, + {ENV => "LC_ALL=$locale"}] + ); + + push @Tests, @Locale_Tests; + } + + # Set _POSIX2_VERSION=199209 in the environment of each obs-plus* test. foreach my $t (@Tests) { diff --git a/tests/misc/wc-files0-from.pl b/tests/misc/wc-files0-from.pl index a14bf97f..4ff10019 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2006-2014 Free Software Foundation, Inc. # This program is free software: 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 06be054d..37fd1ab0 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2006-2014 Free Software Foundation, Inc. # This program is free software: 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 bf6b7b29..01005820 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2009-2014 Free Software Foundation, Inc. # This program is free software: 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.pl b/tests/misc/wc.pl index ed2feafd..076ce049 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-2013 Free Software Foundation, Inc. +# Copyright (C) 1997-2014 Free Software Foundation, Inc. # This program is free software: 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 6eccc10d..f208090f 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2009-2014 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -66,7 +66,7 @@ getfattr -d c >out_c || skip_ "failed to get xattr of file" grep -F "$xattr_pair" out_c || fail=1 # cp's -a option must produce no diagnostics. -cp -a a d 2>err && test -s err && fail=1 +cp -a a d 2>err && { compare /dev/null err || fail=1; } getfattr -d d >out_d || skip_ "failed to get xattr of file" grep -F "$xattr_pair" out_d || fail=1 diff --git a/tests/misc/xstrtol.pl b/tests/misc/xstrtol.pl index b2f38b61..fed8d7d6 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2007-2014 Free Software Foundation, Inc. # This program is free software: 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-1.sh b/tests/mkdir/p-1.sh index 76c4517f..e08fd33d 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-2013 Free Software Foundation, Inc. +# Copyright (C) 1997-2014 Free Software Foundation, Inc. # This program is free software: 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 14a0a453..874a56af 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-2013 Free Software Foundation, Inc. +# Copyright (C) 1997-2014 Free Software Foundation, Inc. # This program is free software: 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 8cc7f3cf..6d55adee 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2005-2014 Free Software Foundation, Inc. # This program is free software: 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-to-eol-range.sh b/tests/mkdir/p-acl.sh index 42cecfd7..dd4473a9 100755 --- a/tests/misc/cut-huge-to-eol-range.sh +++ b/tests/mkdir/p-acl.sh @@ -1,7 +1,7 @@ #!/bin/sh -# Ensure that cut does not allocate mem for a range like -b9999999999999- +# Test "mkdir -p" with default ACLs. -# Copyright (C) 2012-2013 Free Software Foundation, Inc. +# Copyright (C) 1997-2014 Free Software Foundation, Inc. # This 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,19 @@ # along with this program. If not, see <http://www.gnu.org/licenses/>. . "${srcdir=.}/tests/init.sh"; path_prepend_ ./src -print_ver_ cut -require_ulimit_ -getlimits_ +print_ver_ mkdir -# From coreutils-8.10 through 8.20, this would make cut try to allocate -# a 256MiB bit vector. With a 20MB limit on VM, the following would fail. -(ulimit -v 20000; : | cut -b$INT_MAX- > err 2>&1) || fail=1 +require_setfacl_ -compare /dev/null err || fail=1 +mkdir d || framework_failure_ +setfacl -d -m group::rwx d || framework_failure_ +umask 077 + +mkdir --parents d/e || fail=1 +ls_l=$(ls -ld d/e) || fail=1 +case $ls_l in + d???rw[sx]*) ;; + *) fail=1 ;; +esac Exit $fail diff --git a/tests/mkdir/p-slashdot.sh b/tests/mkdir/p-slashdot.sh index cfeead3a..bbca9ad7 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2005-2014 Free Software Foundation, Inc. # This program is free software: 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 510ba39b..a884a386 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2005-2014 Free Software Foundation, Inc. # This program is free software: 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 665b1a35..a6a51cbc 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2006-2014 Free Software Foundation, Inc. # This program is free software: 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 ef6830e7..786f08f9 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2000-2014 Free Software Foundation, Inc. # This program is free software: 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/perm.sh b/tests/mkdir/perm.sh index 671f0049..bf0f6a8e 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2000-2014 Free Software Foundation, Inc. # This program is free software: 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/restorecon.sh b/tests/mkdir/restorecon.sh new file mode 100755 index 00000000..14a8b899 --- /dev/null +++ b/tests/mkdir/restorecon.sh @@ -0,0 +1,72 @@ +#!/bin/sh +# test mkdir, mknod, mkfifo -Z + +# Copyright (C) 2013-2014 Free Software Foundation, Inc. + +# This 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_ mkdir +require_selinux_ + + +get_selinux_type() { ls -Zd "$1" | sed -n 's/.*:\(.*_t\):.*/\1/p'; } + +mkdir subdir || framework_failure_ +chcon 'root:object_r:tmp_t:s0' subdir || framework_failure_ +cd subdir + +# --- mkdir -Z --- +# Since in a tmp_t dir, dirs can be created as user_tmp_t ... +mkdir standard || framework_failure_ +mkdir restored || framework_failure_ +if restorecon restored 2>/dev/null; then + # ... but when restored can be set to user_home_t + # So ensure the type for these mkdir -Z cases matches + # the directory type as set by restorecon. + mkdir -Z single || fail=1 + # Run these as separate processes in case global context + # set for an arg, impacts on another arg + for dir in single_p single_p/existing multi/ple; do + mkdir -Zp "$dir" || fail=1 + done + restored_type=$(get_selinux_type 'restored') + test "$(get_selinux_type 'single')" = "$restored_type" || fail=1 + test "$(get_selinux_type 'single_p')" = "$restored_type" || fail=1 + test "$(get_selinux_type 'single_p/existing')" = "$restored_type" || fail=1 + test "$(get_selinux_type 'multi')" = "$restored_type" || fail=1 + test "$(get_selinux_type 'multi/ple')" = "$restored_type" || fail=1 +fi +if test "$fail" = '1'; then + ls -UZd standard restored + ls -UZd single single_p single_p/existing multi multi/ple +fi + +# --- mknod -Z and mkfifo -Z --- +# Assume if selinux present that we can create fifos +for cmd_w_arg in 'mknod' 'mkfifo'; do + # In OpenBSD's /bin/sh, mknod is a shell built-in. + # Running via "env" ensures we run our program and not the built-in. + basename="$cmd_w_arg" + test "$basename" = 'mknod' && nt='p' || nt='' + env -- $cmd_w_arg $basename $nt || fail=1 + env -- $cmd_w_arg ${basename}_restore $nt || fail=1 + if restorecon ${basename}_restore 2>/dev/null; then + env -- $cmd_w_arg -Z ${basename}_Z $nt || fail=1 + restored_type=$(get_selinux_type "${basename}_restore") + test "$(get_selinux_type ${basename}_Z)" = "$restored_type" || fail=1 + fi +done + +Exit $fail diff --git a/tests/mkdir/selinux.sh b/tests/mkdir/selinux.sh index e68f77b8..983ceb57 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2008-2014 Free Software Foundation, Inc. # This 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,7 @@ msg="failed to set default file creation context to '$c':" for cmd_w_arg in 'mkdir dir' 'mknod b p' 'mkfifo f'; do # In OpenBSD's /bin/sh, mknod is a shell built-in. # Running via "env" ensures we run our program and not the built-in. - env -- $cmd_w_arg -Z $c 2> out && fail=1 + env -- $cmd_w_arg --context=$c 2> out && fail=1 set $cmd_w_arg; cmd=$1 echo "$cmd: $msg" > exp || fail=1 diff --git a/tests/mkdir/smack-no-root.sh b/tests/mkdir/smack-no-root.sh new file mode 100755 index 00000000..527940b3 --- /dev/null +++ b/tests/mkdir/smack-no-root.sh @@ -0,0 +1,39 @@ +#!/bin/sh +# SMACK test for the mkdir,mknod, mkfifo commands. +# Derived from tests/mkdir/selinux.sh. +# Ensure that an unsettable SMACK label doesn't cause a segfault. + +# Copyright (C) 2014 Free Software Foundation, Inc. + +# This 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_ mkdir mkfifo mknod + +require_smack_ + +c=arbitrary-smack-label +msg="failed to set default file creation context to '$c':" + +for cmd in 'mkdir dir' 'mknod b p' 'mkfifo f'; do + $cmd --context="$c" 2> out && fail=1 + set $cmd + echo "$1: $msg" > exp || fail=1 + + sed -e 's/ Operation not permitted$//' out > k || fail=1 + mv k out || fail=1 + compare exp out || fail=1 +done + +Exit $fail diff --git a/tests/misc/id-setgid.sh b/tests/mkdir/smack-root.sh index f29eec07..8d7ec9b7 100755 --- a/tests/misc/id-setgid.sh +++ b/tests/mkdir/smack-root.sh @@ -1,7 +1,9 @@ #!/bin/sh -# Verify that id -G prints the right group when run set-GID. +# SMACK test for the mkdir,mknod, mkfifo commands. +# Derived from tests/mkdir/selinux.sh. +# Ensure that SMACK label gets set. -# Copyright (C) 2012-2013 Free Software Foundation, Inc. +# Copyright (C) 2014 Free Software Foundation, Inc. # This 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,18 +19,18 @@ # along with this program. If not, see <http://www.gnu.org/licenses/>. . "${srcdir=.}/tests/init.sh"; path_prepend_ ./src -print_ver_ id -require_root_ - -g=$(id -u $NON_ROOT_USERNAME) || framework_failure_ +print_ver_ mkdir mkfifo mknod -# Construct a different group number. -gp1=$(expr $g + 1) +require_smack_ +require_root_ -echo $gp1 > exp || framework_failure_ +c=arbitrary-smack-label -setuidgid -g $gp1 $NON_ROOT_USERNAME env PATH="$PATH" id -G > out || fail=1 -compare exp out || fail=1 -# With coreutils-8.16 and earlier, id -G would print both: $gp1 $g +for cmd in 'mkdir dir' 'mknod b p' 'mkfifo f'; do + $cmd --context="$c" || { fail=1; continue; } + set $cmd + ls -dZ $2 > out || fail=1 + test "$(cut -f1 -d' ' out)" = "$c" || { cat out; fail=1; } +done Exit $fail diff --git a/tests/mkdir/special-1.sh b/tests/mkdir/special-1.sh index 5557e39d..8c65a757 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2000-2014 Free Software Foundation, Inc. # This program is free software: 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/t-slash.sh b/tests/mkdir/t-slash.sh index 15c7d3cc..d9e8d3eb 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2000-2014 Free Software Foundation, Inc. # This program is free software: 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 ab467238..e7c4a9ca 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2005-2014 Free Software Foundation, Inc. # This program is free software: 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 97f5b048..f681f5d0 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2005-2014 Free Software Foundation, Inc. # This program is free software: 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 0c5393ec..a026bd5b 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2006-2014 Free Software Foundation, Inc. # This program is free software: 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 a98a6518..92a8e436 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2008-2014 Free Software Foundation, Inc. # This program is free software: 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 f76f3386..682173d4 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2006-2014 Free Software Foundation, Inc. # This program is free software: 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 a0d7a917..4208d91e 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-2013 Free Software Foundation, Inc. +# Copyright (C) 1998-2014 Free Software Foundation, Inc. # This program is free software: 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 4f14aa2e..c212b83d 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2001-2014 Free Software Foundation, Inc. # This program is free software: 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/diag.sh b/tests/mv/diag.sh index ecac8529..b38fb18c 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2000-2014 Free Software Foundation, Inc. # This program is free software: 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 6f655752..bb32f356 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2000-2014 Free Software Foundation, Inc. # This program is free software: 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/dir2dir.sh b/tests/mv/dir2dir.sh index 17c5b33e..7a8f7fd3 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2006-2014 Free Software Foundation, Inc. # This program is free software: 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 76efbb98..d3b56c5e 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2001-2014 Free Software Foundation, Inc. # This program is free software: 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 4b435dd8..05adabc5 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-2013 Free Software Foundation, Inc. +# Copyright (C) 1999-2014 Free Software Foundation, Inc. # This program is free software: 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-2.sh b/tests/mv/hard-2.sh index 4fa1d78f..0b2880a2 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2003-2014 Free Software Foundation, Inc. # This program is free software: 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 c40a7081..a3acd1a6 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2003-2014 Free Software Foundation, Inc. # This program is free software: 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 f74b1ec7..d518e3bc 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 -# Copyright (C) 2003-2013 Free Software Foundation, Inc. +# Copyright (C) 2003-2014 Free Software Foundation, Inc. # This program is free software: 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-link-1.sh b/tests/mv/hard-link-1.sh index 9468e91f..fdf355a3 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-2013 Free Software Foundation, Inc. +# Copyright (C) 1998-2014 Free Software Foundation, Inc. # This program is free software: 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-verbose.sh b/tests/mv/hard-verbose.sh index 6672ae7c..45491ab0 100755 --- a/tests/mv/hard-verbose.sh +++ b/tests/mv/hard-verbose.sh @@ -1,7 +1,7 @@ #!/bin/sh # ensure that mv's --verbose options works even in this unusual case -# Copyright (C) 2006-2013 Free Software Foundation, Inc. +# Copyright (C) 2006-2014 Free Software Foundation, Inc. # This program is free software: 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-1.pl b/tests/mv/i-1.pl index dfa6c515..84902ee2 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2001-2014 Free Software Foundation, Inc. # This program is free software: 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 adf87263..4202b5c5 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2000-2014 Free Software Foundation, Inc. # This 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 @@ cp -if e f < y > out 2>&1 || fail=1 # Make sure out contains the prompt. case "$(cat out)" in - "cp: try to overwrite 'f', overriding mode 0000 (---------)?"*) ;; + "cp: replace 'f', overriding mode 0000 (---------)?"*) ;; *) fail=1 ;; esac diff --git a/tests/mv/i-3.sh b/tests/mv/i-3.sh index 9f66edc6..8c58d5d3 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2001-2014 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -46,13 +46,13 @@ check_overwrite_prompt() { local delay="$1" case "$(cat out)" in - "mv: try to overwrite 'g', overriding mode 0000"*) ;; + "mv: replace 'g', overriding mode 0000"*) ;; *) sleep $delay; return 1;; esac } # Wait for up to 12.7 seconds for the expected prompt. -retry_delay_ check_overwrite_prompt .1 7 || fail=1 +retry_delay_ check_overwrite_prompt .1 7 || { fail=1; cat out; } kill $pid diff --git a/tests/mv/i-4.sh b/tests/mv/i-4.sh index 6d54ef7b..b366bc46 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2001-2014 Free Software Foundation, Inc. # This program is free software: 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-5.sh b/tests/mv/i-5.sh index cb57ca4b..c69f1784 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2006-2014 Free Software Foundation, Inc. # This program is free software: 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 38305b74..67a8ff9c 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2002-2014 Free Software Foundation, Inc. # This program is free software: 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 4200bbb6..4109d9e6 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-2013 Free Software Foundation, Inc. +# Copyright (C) 1998-2014 Free Software Foundation, Inc. # This program is free software: 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 6f224831..52069b88 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-2013 Free Software Foundation, Inc. +# Copyright (C) 1998-2014 Free Software Foundation, Inc. # This program is free software: 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 7aa5111f..ac78f90b 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2001-2014 Free Software Foundation, Inc. # This program is free software: 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.sh b/tests/mv/into-self.sh index 38b0809f..76aefa26 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-2013 Free Software Foundation, Inc. +# Copyright (C) 1998-2014 Free Software Foundation, Inc. # This program is free software: 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 8d83d6a0..6b81f5cb 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2004-2014 Free Software Foundation, Inc. # This program is free software: 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 d829c63b..30ba35bb 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2006-2014 Free Software Foundation, Inc. # This program is free software: 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-special-1.sh b/tests/mv/mv-special-1.sh index b2a0a19c..34449150 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-2013 Free Software Foundation, Inc. +# Copyright (C) 1998-2014 Free Software Foundation, Inc. # This program is free software: 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 55a63109..ac65ff7f 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2006-2014 Free Software Foundation, Inc. # This program is free software: 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-fail.sh b/tests/mv/part-fail.sh index 08ffadcd..71ee30c0 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2002-2014 Free Software Foundation, Inc. # This program is free software: 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 cb8e8d22..8eacaabc 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2004-2014 Free Software Foundation, Inc. # This program is free software: 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 aa2265b1..ba68f6e6 100755 --- a/tests/mv/part-rename.sh +++ b/tests/mv/part-rename.sh @@ -1,9 +1,7 @@ #!/bin/sh -# Moving a directory specified with a trailing slash from one partition to -# another, and giving it a different name at the destination would cause mv -# to get a failed assertion. +# Test various cases for moving directories across file systems -# Copyright (C) 2000-2013 Free Software Foundation, Inc. +# Copyright (C) 2000-2014 Free Software Foundation, Inc. # This 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,9 +21,37 @@ print_ver_ mv cleanup_() { rm -rf "$other_partition_tmpdir"; } . "$abs_srcdir/tests/other-fs-tmpdir" + +# Moving a directory specified with a trailing slash from one partition to +# another, and giving it a different name at the destination would cause mv +# to get a failed assertion. mkdir foo || framework_failure_ +mv foo/ "$other_partition_tmpdir/bar" || fail=1 -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 + + +# 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 + + +# As per POSIX moving directory from source should replace empty dir in dest +mkdir bar3 +touch bar3/file +mkdir "$other_partition_tmpdir/bar3" +mv bar3 "$other_partition_tmpdir/" || fail=1 +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 +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 8eb73f2e..9604d873 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2000-2014 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -88,7 +88,8 @@ for copy in cp mv; do # Normalize the program name in the error output, # remove any site-dependent part of other-partition file name, # and put brackets around the output. - test -s .err && { + test -s .err \ + && { echo ' [' | tr -d '\n' sed 's/^[^:][^:]*\(..\):/\1:/;s,'"$other_partition_tmpdir/,," .err | tr -d '\n' diff --git a/tests/mv/partition-perm.sh b/tests/mv/partition-perm.sh index 7fbd2b23..713988f7 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-2013 Free Software Foundation, Inc. +# Copyright (C) 1999-2014 Free Software Foundation, Inc. # This 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,11 +21,11 @@ print_ver_ mv cleanup_() { rm -rf "$other_partition_tmpdir"; } . "$abs_srcdir/tests/other-fs-tmpdir" -: > file -chmod a=rwx file +> file || framework_failure_ +chmod a=rwx file || framework_failure_ umask 077 -mv file "$other_partition_tmpdir" +mv file "$other_partition_tmpdir" || framework_failure_ test -f file && fail=1 test -f "$other_partition_tmpdir/file" || fail=1 diff --git a/tests/mv/perm-1.sh b/tests/mv/perm-1.sh index 88fbbdd9..2826c61f 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2002-2014 Free Software Foundation, Inc. # This program is free software: 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 b9afc685..e0c99e94 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2007-2014 Free Software Foundation, Inc. # This 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 @@ chmod go+x . || framework_failure_ # Ensure that $NON_ROOT_USERNAME can access the required version of mv. version=$( - setuidgid $NON_ROOT_USERNAME env PATH="$PATH" mv --version | + chroot --user=$NON_ROOT_USERNAME / env PATH="$PATH" mv --version | sed -n '1s/.* //p' ) case $version in @@ -50,7 +50,7 @@ case $version in *) skip_ "cannot access just-built mv as user $NON_ROOT_USERNAME";; esac -setuidgid $NON_ROOT_USERNAME env PATH="$PATH" \ +chroot --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 1e2bf817..f3e8ff98 100755 --- a/tests/mv/symlink-onto-hardlink-to-self.sh +++ b/tests/mv/symlink-onto-hardlink-to-self.sh @@ -4,7 +4,7 @@ # 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2012-2014 Free Software Foundation, Inc. # This program is free software: 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/symlink-onto-hardlink.sh b/tests/mv/symlink-onto-hardlink.sh index 0e62de7f..5b4dead0 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2012-2014 Free Software Foundation, Inc. # This program is free software: 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 cce4b768..70ca6179 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-2013 Free Software Foundation, Inc. +# Copyright (C) 1999-2014 Free Software Foundation, Inc. # This program is free software: 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 98a99133..e3225025 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2004-2014 Free Software Foundation, Inc. # This program is free software: 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/update.sh b/tests/mv/update.sh index 0bc770d8..4c0553a5 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2001-2014 Free Software Foundation, Inc. # This 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 @@ for interactive in '' -i; do # With coreutils-6.9 and earlier, using --update with -i would # mistakenly elicit a prompt. $cp_or_mv $interactive --update old new < /dev/null > out 2>&1 || fail=1 - test -s out && fail=1 + compare /dev/null out || fail=1 case "$(cat new)" in new) ;; *) fail=1 ;; esac case "$(cat old)" in old) ;; *) fail=1 ;; esac done diff --git a/tests/other-fs-tmpdir b/tests/other-fs-tmpdir index c141b9e6..e82058ad 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-2013 Free Software Foundation, Inc. +# Copyright (C) 1998-2014 Free Software Foundation, Inc. # This program is free software: 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 9efd019e..10947ac9 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2008-2014 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/readlink/can-e.sh b/tests/readlink/can-e.sh index 114e8640..a6415b94 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2004-2014 Free Software Foundation, Inc. # This 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_ readlink pwd=$(pwd) -my_pwd=$("$abs_top_builddir/src/pwd") +my_pwd=$(env pwd -P) tmp=d mkdir $tmp || framework_failure_ diff --git a/tests/readlink/can-f.sh b/tests/readlink/can-f.sh index 2a1021a7..2a980fa8 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2004-2014 Free Software Foundation, Inc. # This 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_ readlink pwd=$(pwd) -my_pwd=$("$abs_top_builddir/src/pwd") +my_pwd=$(env pwd -P) tmp=d mkdir $tmp || framework_failure_ diff --git a/tests/readlink/can-m.sh b/tests/readlink/can-m.sh index ae498bdd..768c552b 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2004-2014 Free Software Foundation, Inc. # This 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_ readlink pwd=$(pwd) -my_pwd=$("$abs_top_builddir/src/pwd") +my_pwd=$(env pwd -P) tmp=d mkdir $tmp || framework_failure_ diff --git a/tests/readlink/multi.sh b/tests/readlink/multi.sh index 3b915443..e4878ecc 100755 --- a/tests/readlink/multi.sh +++ b/tests/readlink/multi.sh @@ -1,7 +1,7 @@ #!/bin/sh # test multiple argument handling. -# Copyright (C) 2012-2013 Free Software Foundation, Inc. +# Copyright (C) 2012-2014 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -40,7 +40,7 @@ compare exp out || fail=1 # Note the edge case that the last xargs run may not have a delimiter rm out || framework_failure_ printf '/1\0/1\0/1' > exp || framework_failure_ -printf '/1 /1 /1' | xargs -n2 readlink -n -m --zero >> out || fail=1 +printf '/1 /1 /1 ' | xargs -n2 readlink -n -m --zero >> out || fail=1 compare exp out || fail=1 Exit $fail diff --git a/tests/readlink/rl-1.sh b/tests/readlink/rl-1.sh index 97d5ab3f..ede0a915 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2004-2014 Free Software Foundation, Inc. # This program is free software: 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/cycle.sh b/tests/rm/cycle.sh index 881d84b2..589ee73a 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2003-2014 Free Software Foundation, Inc. # This program is free software: 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 cfe38ad5..dd7cfd0f 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2012-2014 Free Software Foundation, Inc. # This program is free software: 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 3b8ca664..87fb100c 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2012-2014 Free Software Foundation, Inc. # This program is free software: 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 b3bd0b10..646ecd06 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2012-2014 Free Software Foundation, Inc. # This program is free software: 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 62c66915..1e5cdfa9 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2002-2014 Free Software Foundation, Inc. # This program is free software: 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-1.sh b/tests/rm/deep-1.sh index 5f4b63ef..1f1b307c 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-2013 Free Software Foundation, Inc. +# Copyright (C) 1997-2014 Free Software Foundation, Inc. # This program is free software: 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 a03cd965..c3ea0856 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2008-2014 Free Software Foundation, Inc. # This 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,6 +25,11 @@ require_perl_ # the offending euidaccess_stat call. skip_if_root_ +# ecryptfs for example uses some of the file name space +# for encrypting filenames, so we must check dynamically. +name_max=$(stat -f -c %l .) +test "$name_max" -ge '200' || skip_ "NAME_MAX=$name_max is not sufficient" + mkdir x || framework_failure_ cd x || framework_failure_ @@ -41,7 +46,7 @@ echo n > no || framework_failure_ rm ---presume-input-tty -r x < no > out || fail=1 # expect empty output -test -s out && fail=1 +compare /dev/null out || fail=1 # the directory must have been removed test -d x && fail=1 diff --git a/tests/rm/dir-no-w.sh b/tests/rm/dir-no-w.sh index da52155c..de9035e9 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2003-2014 Free Software Foundation, Inc. # This program is free software: 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 fa3168e8..45956da7 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2005-2014 Free Software Foundation, Inc. # This program is free software: 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 69956c57..4e1a8ce0 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2004-2014 Free Software Foundation, Inc. # This program is free software: 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 78d14155..e3771530 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2006-2014 Free Software Foundation, Inc. # This program is free software: 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 4c94ebc0..b6ee6ad5 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-2013 Free Software Foundation, Inc. +# Copyright (C) 1998-2014 Free Software Foundation, Inc. # This program is free software: 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 e24c8098..ef4fee46 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2008-2014 Free Software Foundation, Inc. # This program is free software: 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 7837580f..0fc95c4f 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-2013 Free Software Foundation, Inc. +# Copyright (C) 1997-2014 Free Software Foundation, Inc. # This program is free software: 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 0f1a4fa5..6e8ce9ba 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2003-2014 Free Software Foundation, Inc. # This 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,14 @@ touch a/b || framework_failure_ # Try to ensure that $NON_ROOT_USERNAME can access # the required version of rm. rm_version=$( - setuidgid $NON_ROOT_USERNAME env PATH="$PATH" rm --version | + chroot --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 -setuidgid $NON_ROOT_USERNAME env PATH="$PATH" rm -rf a 2> out-t && fail=1 +chroot --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 2167a047..dd31ea4c 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2006-2014 Free Software Foundation, Inc. # This program is free software: 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 fb46445e..b167d0ba 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2002-2014 Free Software Foundation, Inc. # This program is free software: 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/hash.sh b/tests/rm/hash.sh index e10879b8..6bc82bdc 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2000-2014 Free Software Foundation, Inc. # This program is free software: 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 32aba21d..6a4ca64b 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-2013 Free Software Foundation, Inc. +# Copyright (C) 1997-2014 Free Software Foundation, Inc. # This program is free software: 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 fc4e9412..6302174a 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2007-2014 Free Software Foundation, Inc. # This program is free software: 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 4304f051..8a535faf 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2002-2014 Free Software Foundation, Inc. # This program is free software: 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/ignorable.sh b/tests/rm/ignorable.sh index 645982c5..8d656eea 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2006-2014 Free Software Foundation, Inc. # This program is free software: 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 9408a18b..e3c48dfe 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2004-2014 Free Software Foundation, Inc. # This program is free software: 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 1dfb5a69..627d923e 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2006-2014 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -72,13 +72,13 @@ no WHEN WHEN=never . WHEN=once -rm: remove all arguments recursively? . +rm: remove 2 arguments recursively? . WHEN=always @remove_empty 'file4-1'? @remove_empty 'file4-2'? . -f overrides --interactive . --interactive overrides -f -rm: remove all arguments recursively? . +rm: remove 1 argument recursively? . EOF compare expout out || fail=1 diff --git a/tests/rm/interactive-once.sh b/tests/rm/interactive-once.sh index d138b752..db10bba6 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2006-2014 Free Software Foundation, Inc. # This 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,19 +30,36 @@ rm -f out err || framework_failure_ # The prompt has a trailing space, and no newline, so an extra # 'echo .' is inserted after each rm to make it obvious what was asked. -echo 'one file, no recursion' > err || fail=1 +echo 'one file, no recursion' > err || framework_failure_ rm -I file1-* < in-n >> out 2>> err || fail=1 echo . >> err || fail=1 test -f file1-1 && fail=1 -echo 'three files, no recursion' >> err || fail=1 +echo 'one file, read only, answer no' >> err || framework_failure_ +if ls /dev/stdin >/dev/null 2>&1; then + touch file1-1 || framework_failure_ + chmod a-w file1-1 || framework_failure_ + if ! test -w file1-1; then + # root won't get prompted + write_prot_msg1="rm: remove write-protected regular empty file 'file1-1'? " + fi + rm ---presume-input-tty -I file1-* < in-n >> out 2>> err || fail=1 + echo . >> err || fail=1 + if test "$write_prot_msg1"; then + test -f file1-1 || fail=1 + fi +else + echo '.' >> err || framework_failure_ +fi + +echo 'three files, no recursion' >> err || framework_failure_ rm -I file2-* < in-n >> out 2>> err || fail=1 echo . >> err || fail=1 test -f file2-1 && fail=1 test -f file2-2 && fail=1 test -f file2-3 && fail=1 -echo 'four files, no recursion, answer no' >> err || fail=1 +echo 'four files, no recursion, answer no' >> err || framework_failure_ rm -I file3-* < in-n >> out 2>> err || fail=1 echo . >> err || fail=1 test -f file3-1 || fail=1 @@ -50,7 +67,7 @@ test -f file3-2 || fail=1 test -f file3-3 || fail=1 test -f file3-4 || fail=1 -echo 'four files, no recursion, answer yes' >> err || fail=1 +echo 'four files, no recursion, answer yes' >> err || framework_failure_ rm -I file3-* < in-y >> out 2>> err || fail=1 echo . >> err || fail=1 test -f file3-1 && fail=1 @@ -58,23 +75,45 @@ test -f file3-2 && fail=1 test -f file3-3 && fail=1 test -f file3-4 && fail=1 -echo 'one file, recursion, answer no' >> err || fail=1 +echo 'four files, no recursion, 1 read only, answer yes no' >> err \ + || framework_failure_ +if ls /dev/stdin >/dev/null 2>&1; then + touch file3-1 file3-2 file3-3 file3-4 || framework_failure_ + echo non_empty > file3-4 || framework_failure_ # to shorten diagnostic + chmod a-w file3-4 || framework_failure_ + if ! test -w file3-4; then + # root won't get prompted + write_prot_msg2="rm: remove write-protected regular file 'file3-4'? " + fi + cat in-y in-n | rm ---presume-input-tty -I file3-* >> out 2>> err || fail=1 + echo . >> err || fail=1 + test -f file3-1 && fail=1 + test -f file3-2 && fail=1 + test -f file3-3 && fail=1 + if test "$write_prot_msg2"; then + test -f file3-4 || fail=1 + fi +else + echo 'rm: remove 4 arguments? .' >> err || framework_failure_ +fi + +echo 'one file, recursion, answer no' >> err || framework_failure_ rm -I -R dir1-* < in-n >> out 2>> err || fail=1 echo . >> err || fail=1 test -d dir1-1 || fail=1 -echo 'one file, recursion, answer yes' >> err || fail=1 +echo 'one file, recursion, answer yes' >> err || framework_failure_ rm -I -R dir1-* < in-y >> out 2>> err || fail=1 echo . >> err || fail=1 test -d dir1-1 && fail=1 -echo 'multiple files, recursion, answer no' >> err || fail=1 +echo 'multiple files, recursion, answer no' >> err || framework_failure_ rm -I -R dir2-* < in-n >> out 2>> err || fail=1 echo . >> err || fail=1 test -d dir2-1 || fail=1 test -d dir2-2 || fail=1 -echo 'multiple files, recursion, answer yes' >> err || fail=1 +echo 'multiple files, recursion, answer yes' >> err || framework_failure_ rm -I -R dir2-* < in-y >> out 2>> err || fail=1 echo . >> err || fail=1 test -d dir2-1 && fail=1 @@ -82,23 +121,27 @@ test -d dir2-2 && fail=1 cat <<\EOF > expout || fail=1 EOF -cat <<\EOF > experr || fail=1 +cat <<EOF > experr || fail=1 one file, no recursion . +one file, read only, answer no +$write_prot_msg1. three files, no recursion . four files, no recursion, answer no -rm: remove all arguments? . +rm: remove 4 arguments? . four files, no recursion, answer yes -rm: remove all arguments? . +rm: remove 4 arguments? . +four files, no recursion, 1 read only, answer yes no +rm: remove 4 arguments? $write_prot_msg2. one file, recursion, answer no -rm: remove all arguments recursively? . +rm: remove 1 argument recursively? . one file, recursion, answer yes -rm: remove all arguments recursively? . +rm: remove 1 argument recursively? . multiple files, recursion, answer no -rm: remove all arguments recursively? . +rm: remove 2 arguments recursively? . multiple files, recursion, answer yes -rm: remove all arguments recursively? . +rm: remove 2 arguments recursively? . EOF compare expout out || fail=1 diff --git a/tests/rm/ir-1.sh b/tests/rm/ir-1.sh index f2068fd6..86a5595f 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-2013 Free Software Foundation, Inc. +# Copyright (C) 1997-2014 Free Software Foundation, Inc. # This program is free software: 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 b0d7a06a..0ff8d1fa 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2001-2014 Free Software Foundation, Inc. # This program is free software: 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/many-dir-entries-vs-OOM.sh b/tests/rm/many-dir-entries-vs-OOM.sh index c867a46e..c45453d7 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2011-2014 Free Software Foundation, Inc. # This 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 @@ . "${srcdir=.}/tests/init.sh"; path_prepend_ ./src print_ver_ rm du chmod +require_ulimit_v_ expensive_ diff --git a/tests/rm/no-give-up.sh b/tests/rm/no-give-up.sh index 915970d1..41070c9d 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2004-2014 Free Software Foundation, Inc. # This 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,8 @@ chmod go=x . || framework_failure_ # This must fail, since '.' is not writable by $NON_ROOT_USERNAME. -setuidgid $NON_ROOT_USERNAME env PATH="$PATH" rm -rf d 2>/dev/null && fail=1 +chroot --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 54a81892..09a0464b 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2006-2014 Free Software Foundation, Inc. # This program is free software: 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 94bf442e..e4e8a417 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2009-2014 Free Software Foundation, Inc. # This program is free software: 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 362e6adb..6e1d6089 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-2013 Free Software Foundation, Inc. +# Copyright (C) 1997-2014 Free Software Foundation, Inc. # This program is free software: 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 34c9f282..a8049bd2 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-2013 Free Software Foundation, Inc. +# Copyright (C) 1997-2014 Free Software Foundation, Inc. # This program is free software: 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 91e80516..82c35bed 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-2013 Free Software Foundation, Inc. +# Copyright (C) 1997-2014 Free Software Foundation, Inc. # This program is free software: 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 94702a6d..095f1516 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2006-2014 Free Software Foundation, Inc. # This 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,11 +22,26 @@ print_ver_ rm mkdir d || framework_failure_ touch d/a || framework_failure_ -rm -fr d/. 2>/dev/null && fail=1 -rm -fr d/./ 2>/dev/null && fail=1 -rm -fr d/.//// 2>/dev/null && fail=1 -rm -fr d/.. 2>/dev/null && fail=1 -rm -fr d/../ 2>/dev/null && fail=1 +# Expected error diagnostic as grep pattern. +exp="^rm: refusing to remove '\.' or '\.\.' directory: skipping '.*'\$" + +rmtest() +{ + # Try removing - expecting failure. + rm -fr "$1" 2> err && fail=1 + + # Ensure the expected error diagnostic is output. + grep "$exp" err || { cat err; fail=1; } + + return $fail +} + +rmtest 'd/.' || fail=1 +rmtest 'd/./' || fail=1 +rmtest 'd/.////' || fail=1 +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 diff --git a/tests/rm/r-root.sh b/tests/rm/r-root.sh new file mode 100755 index 00000000..e17b85bd --- /dev/null +++ b/tests/rm/r-root.sh @@ -0,0 +1,256 @@ +#!/bin/sh +# Try to remove '/' recursively. + +# Copyright (C) 2013-2014 Free Software Foundation, Inc. + +# This 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_ rm + +# POSIX mandates rm(1) to skip '/' arguments. This test verifies this mandated +# behavior as well as the --preserve-root and --no-preserve-root options. +# Especially the latter case is a live fire exercise as rm(1) is supposed to +# enter the unlinkat() system call. Therefore, limit the risk as much +# as possible -- if there's a bug this test would wipe the system out! + +# Faint-hearted: skip this test for the 'root' user. +skip_if_root_ + +# Pull the teeth from rm(1) by intercepting the unlinkat() system call via the +# LD_PRELOAD environment variable. This requires shared libraries to work. +require_gcc_shared_ + +# This isn't terribly expensive, but it must not be run under heavy load. +# The reason is the conservative 'timeout' setting below to limit possible +# damage in the worst case which yields a race under heavy load. +# Marking this test as "expensive" therefore is a compromise, i.e., adding +# this test to the list ensures it still gets _some_ (albeit minimal) +# coverage while not causing false-positive failures in day to day runs. +expensive_ + +cat > k.c <<'EOF' || framework_failure_ +#include <stdio.h> +#include <stdlib.h> +#include <unistd.h> + +int unlinkat (int dirfd, const char *pathname, int flags) +{ + /* Prove that LD_PRELOAD works: create the evidence file "x". */ + fclose (fopen ("x", "w")); + + /* Immediately terminate, unless indicated otherwise. */ + if (! getenv("CU_TEST_SKIP_EXIT")) + _exit (0); + + /* Pretend success. */ + return 0; +} +EOF + +# Then compile/link it: +gcc_shared_ k.c k.so \ + || framework_failure_ 'failed to build shared library' + +#------------------------------------------------------------------------------- +# exercise_rm_r_root: shell function to test "rm -r '/'" +# The caller must provide the FILE to remove as well as any options +# which should be passed to 'rm'. +# Paranoia mode on: +# For the worst case where both rm(1) would fail to refuse to process the "/" +# argument (in the cases without the --no-preserve-root option), and +# intercepting the unlinkat(1) system call would fail (which actually already +# has been proven to work above), and the current non root user has +# write access to "/", limit the damage to the current file system via +# the --one-file-system option. +# Furthermore, run rm(1) via timeout(1) that kills that process after +# a maximum of 2 seconds. +exercise_rm_r_root () +{ + # Remove the evidence file "x"; verify that. + rm -f x || framework_failure_ + test -f x && framework_failure_ + + local skip_exit= + if [ "$CU_TEST_SKIP_EXIT" = 1 ]; then + # Pass on this variable into 'rm's environment. + skip_exit='CU_TEST_SKIP_EXIT=1' + fi + + timeout --signal=KILL 2 \ + env LD_PRELOAD=./k.so $skip_exit \ + rm -rv --one-file-system "$@" > out 2> err + + return $? +} + +# Verify that "rm -r dir" basically works. +mkdir dir || framework_failure_ +rm -r dir || framework_failure_ +test -d dir && framework_failure_ + +# Now verify that intercepting unlinkat() works: +# rm(1) must succeed as before, but this time both the evidence file "x" +# and the test file / directory must still exist afterward. +mkdir dir || framework_failure_ +> file || framework_failure_ + +skip= +for file in dir file ; do + exercise_rm_r_root "$file" || skip=1 + test -e "$file" || skip=1 + test -f x || skip=1 + + test $skip = 1 \ + && { cat out; cat err; \ + skip_ "internal test failure: maybe LD_PRELOAD doesn't work?"; } +done + +# "rm -r /" without --no-preserve-root should output the following +# diagnostic error message. +cat <<EOD > exp || framework_failure_ +rm: it is dangerous to operate recursively on '/' +rm: use --no-preserve-root to override this failsafe +EOD + +#------------------------------------------------------------------------------- +# Exercise "rm -r /" without and with the --preserve-root option. +# Exercise various synonyms of "/" including symlinks to it. +# Expect a non-Zero exit status. +# Prepare a few symlinks to "/". +ln -s / rootlink || framework_failure_ +ln -s rootlink rootlink2 || framework_failure_ +ln -sr / rootlink3 || framework_failure_ + +for opts in \ + '/' \ + '--preserve-root /' \ + '//' \ + '///' \ + '////' \ + 'rootlink/' \ + 'rootlink2/' \ + 'rootlink3/' ; do + + 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): + # rm: it is dangerous to operate recursively on 'FILE' (same as '/') + # Strip that part off for the following comparison. + sed "s/\(rm: it is dangerous to operate recursively on\).*$/\1 '\/'/" err \ + > err2 || framework_failure_ + + # Expect nothing in 'out' and the above error diagnostic in 'err2'. + # As rm(1) should have skipped the "/" argument, it does not call unlinkat(). + # Therefore, the evidence file "x" should not exist. + compare /dev/null out || fail=1 + compare exp err2 || fail=1 + test -f x && fail=1 + + # Do nothing more if this test failed. + test $fail = 1 && { cat out; cat err; Exit $fail; } +done + +#------------------------------------------------------------------------------- +# Exercise "rm -r file1 / file2". +# Expect a non-Zero exit status representing failure to remove "/", +# yet 'file1' and 'file2' should be removed. +> file1 || framework_failure_ +> file2 || framework_failure_ + +# Now that we know that 'rm' won't call the unlinkat() system function for "/", +# we could probably execute it without the LD_PRELOAD'ed safety net. +# Nevertheless, it's still better to use it for this test. +# Tell the unlinkat() replacement function to not _exit(0) immediately +# by setting the following variable. +CU_TEST_SKIP_EXIT=1 + +exercise_rm_r_root --preserve-root file1 '/' file2 \ + && fail=1 + +unset CU_TEST_SKIP_EXIT + +cat <<EOD > out_removed +removed 'file1' +removed 'file2' +EOD + +# The above error diagnostic should appear in 'err'. +# Both 'file1' and 'file2' should be removed. Simply verify that in the +# "out" file, as the replacement unlinkat() dummy did not remove them. +# Expect the evidence file "x" to exist. +compare out_removed out || fail=1 +compare exp err || fail=1 +test -f x || fail=1 + +# Do nothing more if this test failed. +test $fail = 1 && { cat out; cat err; Exit $fail; } + +#------------------------------------------------------------------------------- +# Exercise various synonyms of "/" having a trailing "." or ".." in the name. +# This triggers another check in the code first and therefore leads to a +# different diagnostic. However, we want to test anyway to protect against +# future reordering of the checks in the code. +# Expect that other error diagnostic in 'err' and nothing in 'out'. +# Expect a non-Zero exit status. The evidence file "x" should not exist. +for file in \ + '//.' \ + '/./' \ + '/.//' \ + '/../' \ + '/.././' \ + '/etc/..' \ + 'rootlink/..' \ + 'rootlink2/.' \ + 'rootlink3/./' ; do + + test -d "$file" || continue # if e.g. /etc does not exist. + + exercise_rm_r_root --preserve-root "$file" \ + && fail=1 + + grep "^rm: refusing to remove '\.' or '\.\.' directory: skipping" err \ + || fail=1 + + compare /dev/null out || fail=1 + test -f x && fail=1 + + # Do nothing more if this test failed. + test $fail = 1 && { cat out; cat err; Exit $fail; } +done + +#------------------------------------------------------------------------------- +# Until now, it was all just fun. +# Now exercise the --no-preserve-root option with which rm(1) should enter +# the intercepted unlinkat() system call. +# As the interception code terminates the process immediately via _exit(0), +# the exit status should be 0. +# Use the option --interactive=never to bypass the following prompt: +# "rm: descend into write-protected directory '/'?" +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 + +# Instead, rm(1) should have called the intercepted unlinkat() function, +# i.e. the evidence file "x" should exist. +test -f x || fail=1 + +test $fail = 1 && { cat out; cat err; } + +Exit $fail diff --git a/tests/rm/read-only.sh b/tests/rm/read-only.sh index dbb3f540..377305cd 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2009-2014 Free Software Foundation, Inc. # This 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 $skip = 1 \ # Applying rm -f to a nonexistent file on a read-only file system must succeed. rm -f mnt/no-such > out 2>&1 || fail=1 # It must produce no diagnostic. -test -s out && fail=1 +compare /dev/null out || fail=1 # However, trying to remove an existing file must fail. rm -f mnt/f > out 2>&1 && fail=1 diff --git a/tests/rm/readdir-bug.sh b/tests/rm/readdir-bug.sh index 58d864f9..d54a71c1 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2006-2014 Free Software Foundation, Inc. # This program is free software: 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 6c6b865e..575a78dd 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2002-2014 Free Software Foundation, Inc. # This program is free software: 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 df1990ff..93ca66e2 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2002-2014 Free Software Foundation, Inc. # This program is free software: 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 4b5e6b32..dda27a60 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2002-2014 Free Software Foundation, Inc. # This program is free software: 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 eff2b583..60eb4a78 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2002-2014 Free Software Foundation, Inc. # This program is free software: 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/rm5.sh b/tests/rm/rm5.sh index 3112026f..6ccd6c6b 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2002-2014 Free Software Foundation, Inc. # This program is free software: 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 7336540f..cc8a02b7 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-2013 Free Software Foundation, Inc. +# Copyright (C) 1997-2014 Free Software Foundation, Inc. # This program is free software: 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/unread2.sh b/tests/rm/unread2.sh index 139f9f00..977d557d 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2002-2014 Free Software Foundation, Inc. # This program is free software: 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 b094ae76..a8df825c 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2004-2014 Free Software Foundation, Inc. # This program is free software: 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 614dcfe9..7f0cd3d6 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-2013 Free Software Foundation, Inc. +# Copyright (C) 1998-2014 Free Software Foundation, Inc. # This program is free software: 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 b04e2187..69730a19 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2007-2014 Free Software Foundation, Inc. # This program is free software: 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 dea42c7d..1072feef 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2004-2014 Free Software Foundation, Inc. # This program is free software: 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/ignore.sh b/tests/rmdir/ignore.sh index 2eb14cc6..487dd9fd 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-2013 Free Software Foundation, Inc. +# Copyright (C) 1999-2014 Free Software Foundation, Inc. # This program is free software: 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 01e1b518..8d010412 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2002-2014 Free Software Foundation, Inc. # This program is free software: 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 0bf49487..a6dcc21b 100644 --- a/tests/sample-test +++ b/tests/sample-test @@ -1,7 +1,7 @@ #!/bin/sh # FIXME -# Copyright (C) 2013 Free Software Foundation, Inc. +# Copyright (C) 2014 Free Software Foundation, Inc. # This program is free software: 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 73fcdc49..7a4d2d7b 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2012-2014 Free Software Foundation, Inc. # This program is free software: 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/b-chunk.sh b/tests/split/b-chunk.sh index e80699fd..86f95a05 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2010-2014 Free Software Foundation, Inc. # This 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 @@ print_ver_ split # in which case no data is extracted, or empty files are written split -n 10 /dev/null || fail=1 test "$(stat -c %s x* | uniq -c | sed 's/^ *//; s/ /x/')" = "10x0" || fail=1 -rm x?? +rm -f x?? # Ensure --elide-empty-files is honored split -e -n 10 /dev/null || fail=1 diff --git a/tests/split/fail.sh b/tests/split/fail.sh index 6272e9b5..33694129 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2003-2014 Free Software Foundation, Inc. # This program is free software: 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/filter.sh b/tests/split/filter.sh index 3520b7af..fed8c7a4 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2011-2014 Free Software Foundation, Inc. # This program is free software: 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/guard-input.sh b/tests/split/guard-input.sh index 357ed543..56b3158b 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2012-2014 Free Software Foundation, Inc. # This program is free software: 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/l-chunk.sh b/tests/split/l-chunk.sh index 63968d15..792c5569 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2010-2014 Free Software Foundation, Inc. # This 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 @@ DEBUGGING= test "$DEBUGGING" && test "$VERBOSE" && set +x for ELIDE_EMPTY in '' '-e'; do for IO_BLKSIZE in 1 2 5 10 80 100; do - : > out + > out test "$DEBUGGING" && printf "\n---io-blk-size=$IO_BLKSIZE $ELIDE_EMPTY\n" for N in 6 8 12 15 22; do rm -f x* @@ -119,15 +119,15 @@ test "$DEBUGGING" && test "$VERBOSE" && set -x # Check extraction of particular chunks -: > out +> out printf '1\n12345\n' > exp split -n l/13/15 in > out compare exp out || fail=1 -: > out +> out printf '' > exp split -n l/14/15 in > out compare exp out || fail=1 -: > out +> out printf '1\n12345\n1\n' > exp split -n l/15/15 in > out compare exp out || fail=1 diff --git a/tests/split/line-bytes.sh b/tests/split/line-bytes.sh new file mode 100755 index 00000000..5f6f505b --- /dev/null +++ b/tests/split/line-bytes.sh @@ -0,0 +1,86 @@ +#!/bin/sh +# test -C, --lines-bytes + +# Copyright (C) 2013-2014 Free Software Foundation, Inc. + +# This 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 +require_ulimit_v_ + + +# Ensure memory is not allocated up front +(ulimit -v 20000; split -C 'G' /dev/null) || fail=1 + + +# Ensure correct operation with various split and buffer size combinations + +lines=\ +1~2222~3~4 + +printf '%s' "$lines" | tr '~' '\n' > in || framework_failure_ + +cat <<\EOF > splits_exp +1 1 1 1 1 1 1 1 1 1 +2 2 2 1 2 1 +2 3 2 2 1 +2 4 3 1 +2 5 3 +2 5 3 +7 3 +7 3 +9 1 +9 1 +10 +EOF + +seq 0 9 | tr -d '\n' > no_eol_in + +cat <<\EOF > no_eol_splits_exp +1 1 1 1 1 1 1 1 1 1 +2 2 2 2 2 +3 3 3 1 +4 4 2 +5 5 +6 4 +7 3 +8 2 +9 1 +10 +10 +EOF + +for b in $(seq 10); do + > splits + > no_eol_splits + for s in $(seq 11); do + rm x?? + split ---io=$b -C$s in || fail=1 + cat x* > out || framework_failure_ + compare in out || fail=1 + stat -c %s x* | paste -s -d ' ' >> splits + + rm x?? + split ---io=$b -C$s no_eol_in || fail=1 + cat x* > out || framework_failure_ + cat xaa + compare no_eol_in out || fail=1 + stat -c %s x* | paste -s -d ' ' >> no_eol_splits + done + compare splits_exp splits || fail=1 + compare no_eol_splits_exp no_eol_splits || fail=1 +done + +Exit $fail diff --git a/tests/split/lines.sh b/tests/split/lines.sh index d78bc202..09dc8c77 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2002-2014 Free Software Foundation, Inc. # This program is free software: 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 1fd9b6f5..6467cb7f 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2012-2014 Free Software Foundation, Inc. # This program is free software: 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/r-chunk.sh b/tests/split/r-chunk.sh index f4c4fd22..8a5f221e 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2010-2014 Free Software Foundation, Inc. # This 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,8 +19,6 @@ . "${srcdir=.}/tests/init.sh"; path_prepend_ ./src print_ver_ split -require_ulimit_ - # N can be greater than the file size # in which case no data is extracted, or empty files are written split -n r/10 /dev/null || fail=1 @@ -34,7 +32,7 @@ stat x?? 2>/dev/null && fail=1 printf '1\n2\n3\n4\n5\n' > in || framework_failure_ split -n r/3 in > out || fail=1 -test -s out && fail=1 +compare /dev/null out || fail=1 split -n r/1/3 in > r1 || fail=1 split -n r/2/3 in > r2 || fail=1 diff --git a/tests/split/suffix-auto-length.sh b/tests/split/suffix-auto-length.sh index 4beab031..40d95af9 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 -# Copyright (C) 2012-2013 Free Software Foundation, Inc. +# Copyright (C) 2012-2014 Free Software Foundation, Inc. # This program is free software: 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/suffix-length.sh b/tests/split/suffix-length.sh index 466d8a7c..af5e95ee 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2002-2014 Free Software Foundation, Inc. # This program is free software: 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/F-vs-missing.sh b/tests/tail-2/F-vs-missing.sh index 0f744042..d47b3022 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2010-2014 Free Software Foundation, Inc. # This program is free software: 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/F-vs-rename.sh b/tests/tail-2/F-vs-rename.sh index 4f3ad5eb..3e31ec8c 100755 --- a/tests/tail-2/F-vs-rename.sh +++ b/tests/tail-2/F-vs-rename.sh @@ -3,7 +3,7 @@ # Before coreutils-8.3, tail -F a b would stop tracking additions to b # after "mv a b". -# Copyright (C) 2009-2013 Free Software Foundation, Inc. +# Copyright (C) 2009-2014 Free Software Foundation, Inc. # This program is free software: 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/append-only.sh b/tests/tail-2/append-only.sh index 93d0b323..7414da3e 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2006-2014 Free Software Foundation, Inc. # This program is free software: 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/assert-2.sh b/tests/tail-2/assert-2.sh index 13cb3e02..930e422a 100755 --- a/tests/tail-2/assert-2.sh +++ b/tests/tail-2/assert-2.sh @@ -3,7 +3,7 @@ # 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2000-2014 Free Software Foundation, Inc. # This program is free software: 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/assert.sh b/tests/tail-2/assert.sh index ee7cec8c..35a10da2 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-2013 Free Software Foundation, Inc. +# Copyright (C) 1999-2014 Free Software Foundation, Inc. # This program is free software: 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/big-4gb.sh b/tests/tail-2/big-4gb.sh index 4e7463c6..cfd867b7 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2002-2014 Free Software Foundation, Inc. # This program is free software: 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/flush-initial.sh b/tests/tail-2/flush-initial.sh index c9f7f4e7..fd14eae9 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2009-2014 Free Software Foundation, Inc. # This program is free software: 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-name.sh b/tests/tail-2/follow-name.sh index ba480fee..f70baec3 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2011-2014 Free Software Foundation, Inc. # This program is free software: 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 b2ccba35..1769ee2c 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2009-2014 Free Software Foundation, Inc. # This 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 @@ timeout 1 tail -f < in > out 2> err test $? = 124 || fail=1 # Ensure there was no error output. -test -s err && fail=1 +compare /dev/null err || fail=1 # Ensure there was compare exp out || fail=1 diff --git a/tests/tail-2/infloop-1.sh b/tests/tail-2/infloop-1.sh index a4afb675..37d081f3 100755 --- a/tests/tail-2/infloop-1.sh +++ b/tests/tail-2/infloop-1.sh @@ -1,7 +1,7 @@ #!/bin/sh # This test would fail with tail from pre-1.22i textutils. -# Copyright (C) 1999-2013 Free Software Foundation, Inc. +# Copyright (C) 1999-2014 Free Software Foundation, Inc. # This 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,8 @@ print_ver_ tail yes > t & yes_pid=$! while :; do - test -s t && break + test -s t \ + && break sleep .1 done tail -n 1 t & diff --git a/tests/tail-2/inotify-hash-abuse.sh b/tests/tail-2/inotify-hash-abuse.sh index b9c7f108..6492049d 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2009-2014 Free Software Foundation, Inc. # This program is free software: 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-abuse2.sh b/tests/tail-2/inotify-hash-abuse2.sh index 7dbefdd3..6018448f 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2009-2014 Free Software Foundation, Inc. # This program is free software: 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-race.sh b/tests/tail-2/inotify-race.sh index cc0f61b3..c25f354a 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2009-2014 Free Software Foundation, Inc. # This 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,26 +37,30 @@ case $(cat gdb.out) in *) skip_ "can't run gdb";; esac +break_src="$abs_top_builddir/src/tail.c" +break_line=$(grep -n ^tail_forever_inotify "$break_src") || framework_failure_ +break_line=$(echo "$break_line" | cut -d: -f1) || framework_failure_ + # See if gdb works and -# tail_forever_inotify is compiled and not inlined +# tail_forever_inotify is compiled and run timeout 10s gdb -nx --batch-silent \ - --eval-command='break tail_forever_inotify' \ + --eval-command="break $break_line" \ --eval-command='run -f file' \ --eval-command='quit' \ - tail < /dev/null > gdb.out 2>&1 + tail < /dev/null > gdb.out 2>&1 || skip_ 'breakpoint not hit' # 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 -test -s gdb.out && { cat gdb.out; skip_ "can't set breakpoints in tail"; } +compare /dev/null gdb.out || skip_ "can't set breakpoints in tail" # 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 \ - --eval-command='break tail_forever_inotify' \ + --eval-command="break $break_line" \ --eval-command='run -f file >> tail.out' \ - --eval-command="shell echo never-seen-with-tail-7.5 >> file" \ + --eval-command='shell echo never-seen-with-tail-7.5 >> file' \ --eval-command='continue' \ --eval-command='quit' \ tail < /dev/null > /dev/null 2>&1 & diff --git a/tests/tail-2/inotify-rotate.sh b/tests/tail-2/inotify-rotate.sh index 4a16202d..1c942cc3 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2009-2014 Free Software Foundation, Inc. # This 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 @@ for i in $(seq 50); do # 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 + >k && >x || framework_failure_ failed to initialize files timeout 40 tail -F k > out 2>&1 & pid=$! sleep .1 diff --git a/tests/tail-2/pid.sh b/tests/tail-2/pid.sh index 19e6a18b..ef440818 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2003-2014 Free Software Foundation, Inc. # This program is free software: 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-f.sh b/tests/tail-2/pipe-f.sh index e0cf3c6d..eaa928fb 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2009-2014 Free Software Foundation, Inc. # This program is free software: 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 63091e39..13ccd0b3 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2009-2014 Free Software Foundation, Inc. # This program is free software: 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/proc-ksyms.sh b/tests/tail-2/proc-ksyms.sh index 243bb9b9..3f799649 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2001-2014 Free Software Foundation, Inc. # This program is free software: 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 new file mode 100755 index 00000000..dbe66a4e --- /dev/null +++ b/tests/tail-2/retry.sh @@ -0,0 +1,114 @@ +#!/bin/sh +# Exercise tail's behavior regarding missing files with/without --retry. + +# Copyright (C) 2013-2014 Free Software Foundation, Inc. + +# This 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 + +# 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. +wait4lines_ () +{ + local delay=$1 + local elc=$2 # Expected line count. + [ "$( wc -l < out )" -ge "$elc" ] || { sleep $delay; return 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 + +# === 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 + +# === 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 +# Expect 3 lines in the output file. +[ $( wc -l < out ) = 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 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 +# Expect 4 lines in the output file. +[ $( wc -l < out ) = 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; } +grep -F 'has appeared' out || { fail=1; cat out; } +grep '^X$' out || { fail=1; cat out; } +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. +wait $pid +rc=$? +[ $( wc -l < out ) = 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; } +grep -F 'replaced with an untailable file' out || { fail=1; cat out; } +grep -F 'no files remaining' out || { fail=1; cat out; } +[ $rc = 1 ] || { fail=1; cat out; } +rm -fd missing out || framework_failure_ + +# === Test: +# Ensure that --follow=descriptor (without --retry) does *not wait* for the +# 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; } +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; } +grep -F 'cannot open' out || { fail=1; cat out; } +grep -F 'no files remaining' out || { fail=1; cat out; } + +Exit $fail diff --git a/tests/tail-2/start-middle.sh b/tests/tail-2/start-middle.sh index 67d5b1a9..dbf9bae8 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2001-2014 Free Software Foundation, Inc. # This program is free software: 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 new file mode 100755 index 00000000..b21f9e15 --- /dev/null +++ b/tests/tail-2/symlink.sh @@ -0,0 +1,78 @@ +#!/bin/sh +# Ensure tail tracks symlinks properly. + +# Copyright (C) 2013-2014 Free Software Foundation, Inc. + +# This 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 + +# 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. +wait4lines_ () +{ + local delay=$1 + local elc=$2 # Expected line count. + [ "$( wc -l < out )" -ge "$elc" ] || { sleep $delay; return 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 +# Expect 3 lines in the output file. +[ $( wc -l < out ) = 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. +# 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. +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 +# Expect 4 lines in the output file. +[ $( wc -l < out ) = 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; } +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, +# 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. + +Exit $fail diff --git a/tests/tail-2/tail-n0f.sh b/tests/tail-2/tail-n0f.sh index a8d37597..1d020ac9 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2003-2014 Free Software Foundation, Inc. # This 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,6 +29,11 @@ require_proc_pid_status_ touch empty || framework_failure_ echo anything > nonempty || framework_failure_ +# First verify that -[nc]0 without -f, exit without reading +touch unreadable || framework_failure_ +chmod 0 unreadable || framework_failure_ +tail -c0 unreadable || fail=1 +tail -n0 unreadable || fail=1 for inotify in ---disable-inotify ''; do for file in empty nonempty; do diff --git a/tests/tail-2/wait.sh b/tests/tail-2/wait.sh index 529b9459..3dec55c0 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2003-2014 Free Software Foundation, Inc. # This 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,8 @@ for inotify in ---disable-inotify ''; do grep -Ev 'inotify (resources exhausted|cannot be used)' tail.err > x mv x tail.err - test -s tail.err && fail=1 - :>tail.err + compare /dev/null tail.err || fail=1 + >tail.err tail_F() { diff --git a/tests/touch/60-seconds.sh b/tests/touch/60-seconds.sh index 3f90fbb2..f0d5b89e 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2009-2014 Free Software Foundation, Inc. # This program is free software: 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 0d63edba..9adfd4bd 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-2013 Free Software Foundation, Inc. +# Copyright (C) 1999-2014 Free Software Foundation, Inc. # This program is free software: 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 6a654839..e6d1b334 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-2013 Free Software Foundation, Inc. +# Copyright (C) 1998-2014 Free Software Foundation, Inc. # This program is free software: 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 0be1b6e5..191ec30c 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2001-2014 Free Software Foundation, Inc. # This program is free software: 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 a67637f5..71ae7791 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2000-2014 Free Software Foundation, Inc. # This program is free software: 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 fe60282c..7ce63b1b 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2002-2014 Free Software Foundation, Inc. # This 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,11 @@ touch -c no-file > /dev/null 2>&1 || fail=1 touch -cm no-file > /dev/null 2>&1 || fail=1 touch -ca no-file > /dev/null 2>&1 || fail=1 -test="$abs_top_builddir/src/test" - # If >&- works, test "touch -c -" etc. # >&- apparently does not work in HP-UX 11.23. # This test is ineffective unless /dev/stdout also works. -if "$test" -w /dev/stdout >/dev/null && - "$test" ! -w /dev/stdout >&-; then +if env test -w /dev/stdout >/dev/null && + env test ! -w /dev/stdout >&-; then touch -c - >&- 2> /dev/null || fail=1 touch -cm - >&- 2> /dev/null || fail=1 touch -ca - >&- 2> /dev/null || fail=1 diff --git a/tests/touch/no-dereference.sh b/tests/touch/no-dereference.sh index c7697782..0f4fdca9 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2009-2014 Free Software Foundation, Inc. # This 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 @@ ln -s file link || framework_failure_ touch -h no-file 2> err && fail=1 test -s err || fail=1 touch -h -c no-file 2> err || fail=1 -test -s err && fail=1 +compare /dev/null err || fail=1 # -h works on regular files touch -h file || fail=1 @@ -49,7 +49,7 @@ grep '^#define HAVE_LUTIMES 1' "$CONFIG_HEADER" > /dev/null || touch -h dangling 2> err case $? in 0) test -f nowhere && fail=1 - test -s err && fail=1;; + compare /dev/null err || fail=1;; 1) grep 'Function not implemented' err \ && skip_ 'this system lacks the utimensat function' fail=1;; @@ -69,14 +69,12 @@ esac # Test interactions with -. touch -h - > file || fail=1 -test="$abs_top_builddir/src/test" - # If >&- works, test "touch -ch -" etc. # >&- apparently does not work in HP-UX 11.23. # This test is ineffective unless /dev/stdout also works. # If stdout is open, it is not a symlink. -if "$test" -w /dev/stdout >/dev/null && - "$test" ! -w /dev/stdout >&-; then +if env test -w /dev/stdout >/dev/null && + env test ! -w /dev/stdout >&-; then 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 135810cb..085c8307 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-2013 Free Software Foundation, Inc. +# Copyright (C) 1999-2014 Free Software Foundation, Inc. # This program is free software: 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 a111ef3a..c822f0b5 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2003-2014 Free Software Foundation, Inc. # This program is free software: 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 4c88fc94..d01097ed 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2008-2014 Free Software Foundation, Inc. # This 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,16 +20,15 @@ print_ver_ touch require_root_ -group_num=$(id -g $NON_ROOT_USERNAME) - # Create a file owned by root, and writable by $NON_ROOT_USERNAME. echo > root-owned || framework_failure_ -chgrp +$group_num . root-owned || framework_failure_ +chgrp +$NON_ROOT_GID . root-owned || framework_failure_ chmod g+w root-owned # Ensure that the current directory is searchable by $NON_ROOT_USERNAME. chmod g+x . -setuidgid $NON_ROOT_USERNAME env PATH="$PATH" touch -d now root-owned || fail=1 +chroot --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 3f1d9b0f..7dd1418b 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2000-2014 Free Software Foundation, Inc. # This program is free software: 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 e9f2bd9f..d2397385 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2005-2014 Free Software Foundation, Inc. # This 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_ touch skip_if_root_ -: > read-only || framework_failure_ +> read-only || framework_failure_ chmod 444 read-only || framework_failure_ diff --git a/tests/touch/relative.sh b/tests/touch/relative.sh index eeb56853..396c2f11 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2004-2014 Free Software Foundation, Inc. # This program is free software: 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 4dbd2776..7e6eb908 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-2013 Free Software Foundation, Inc. +# Copyright (C) 2009-2014 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by |