diff options
Diffstat (limited to 'tests/shred')
-rwxr-xr-x | tests/shred/shred-exact.sh | 49 | ||||
-rwxr-xr-x | tests/shred/shred-passes.sh | 91 | ||||
-rwxr-xr-x | tests/shred/shred-remove.sh | 70 | ||||
-rwxr-xr-x | tests/shred/shred-size.sh | 34 |
4 files changed, 244 insertions, 0 deletions
diff --git a/tests/shred/shred-exact.sh b/tests/shred/shred-exact.sh new file mode 100755 index 0000000..17a8b05 --- /dev/null +++ b/tests/shred/shred-exact.sh @@ -0,0 +1,49 @@ +#!/bin/sh +# Test functionality of --exact + +# Copyright (C) 2000-2023 Free Software Foundation, Inc. + +# This 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 <https://www.gnu.org/licenses/>. + +. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src +print_ver_ shred + + +# make sure that neither --exact nor --zero gobbles a command line argument +for opt in --exact --zero; do + echo a > a || framework_failure_ + echo bb > b || framework_failure_ + echo ccc > c || framework_failure_ + + shred --remove $opt a b || fail=1 + test -f a && fail=1 + test -f b && fail=1 + + shred --remove $opt c || fail=1 + 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/shred/shred-passes.sh b/tests/shred/shred-passes.sh new file mode 100755 index 0000000..020cf68 --- /dev/null +++ b/tests/shred/shred-passes.sh @@ -0,0 +1,91 @@ +#!/bin/sh +# Verify the operations done by shred + +# Copyright (C) 2009-2023 Free Software Foundation, Inc. + +# This 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 <https://www.gnu.org/licenses/>. + +. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src +print_ver_ shred + + +# shred a single letter, which should result in +# 3 random passes and a single rename. +printf 1 > f || framework_failure_ +echo "\ +shred: f: pass 1/3 (random)... +shred: f: pass 2/3 (random)... +shred: f: pass 3/3 (random)... +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 + + +# shred data 20 times and verify the passes used. +# This would consume all random data between 5.93 and 8.24 inclusive. +dd bs=100K count=1 if=/dev/zero | tr '\0' 'U' > Us || framework_failure_ +printf 1 > f || framework_failure_ +echo "\ +shred: f: pass 1/20 (random)... +shred: f: pass 2/20 (ffffff)... +shred: f: pass 3/20 (924924)... +shred: f: pass 4/20 (888888)... +shred: f: pass 5/20 (db6db6)... +shred: f: pass 6/20 (777777)... +shred: f: pass 7/20 (492492)... +shred: f: pass 8/20 (bbbbbb)... +shred: f: pass 9/20 (555555)... +shred: f: pass 10/20 (aaaaaa)... +shred: f: pass 11/20 (random)... +shred: f: pass 12/20 (6db6db)... +shred: f: pass 13/20 (249249)... +shred: f: pass 14/20 (999999)... +shred: f: pass 15/20 (111111)... +shred: f: pass 16/20 (000000)... +shred: f: pass 17/20 (b6db6d)... +shred: f: pass 18/20 (eeeeee)... +shred: f: pass 19/20 (333333)... +shred: f: pass 20/20 (random)... +shred: f: removing +shred: f: renamed to 0 +shred: f: removed" > exp || framework_failure_ + +shred -v -u -n20 -s4096 --random-source=Us f 2>out || fail=1 +compare exp out || fail=1 + +# Trigger an issue in shred before v8.27 where single +# bytes in the pattern space were not initialized correctly +# for particular sizes, like 7,13,... +# This failed under both valgrind and ASAN. +for size in 1 2 6 7 8; do + touch shred.pattern.umr.size + shred -n4 -s$size shred.pattern.umr.size || fail=1 +done + +Exit $fail diff --git a/tests/shred/shred-remove.sh b/tests/shred/shred-remove.sh new file mode 100755 index 0000000..25d58db --- /dev/null +++ b/tests/shred/shred-remove.sh @@ -0,0 +1,70 @@ +#!/bin/sh +# Exercise shred --remove + +# Copyright (C) 1999-2023 Free Software Foundation, Inc. + +# This 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 <https://www.gnu.org/licenses/>. + +. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src +print_ver_ shred +skip_if_root_ + +# The length of the basename is what matters. +# 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. +returns_ 1 shred -u $file > /dev/null 2>&1 || fail=1 +rm -f $file || framework_failure_ + +# Ensure all --remove methods at least unlink the file +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_ +returns_ 1 shred -n0 --remove=none $file 2>/dev/null || fail=1 + +# Ensure rename passes complete. +# coreutils-8.28 did not do the decreasing length rename +# which may have leaked the length of the removed file name + # test level exhaustion +touch \ + 0 1 2 3 4 5 6 7 8 9 \ + a b c d e f g h i j k l m n o p q r s t u v w x y z \ + A B C D E F G H I J K L M N O P Q R S T U V W X Y Z _ || framework_failure_ +touch test 000 || framework_failure_ # test level increment +shred -vu test 2>out || fail=1 +cat <<\EOF >exp || framework_failure_ +shred: test: removing +shred: test: renamed to 0000 +shred: 0000: renamed to 001 +shred: 001: renamed to 00 +shred: test: removed +EOF +compare exp out || fail=1 + +# Ensure renames are only retried for EEXIST +mkdir rodir && cd rodir && touch $file && chmod a-w . || framework_failure_ +returns_ 1 timeout 10 shred -u $file || fail=1 + +Exit $fail diff --git a/tests/shred/shred-size.sh b/tests/shred/shred-size.sh new file mode 100755 index 0000000..8690582 --- /dev/null +++ b/tests/shred/shred-size.sh @@ -0,0 +1,34 @@ +#!/bin/sh +# Exercise shred --size + +# Copyright (C) 2014-2023 Free Software Foundation, Inc. + +# This 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 <https://www.gnu.org/licenses/>. + +. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src +print_ver_ shred + +# Negative size +echo "shred: invalid file size: '-2'" > exp || framework_failure_ +echo 1234 > f || framework_failure_ +shred -s-2 f 2>err && fail=1 +compare exp err || fail=1 + +# Octal/Hex +shred -s010 f || fail=1 +test $(stat --printf=%s f) = 8 || fail=1 +shred -s0x10 f || fail=1 +test $(stat --printf=%s f) = 16 || fail=1 + +Exit $fail |