1#!/bin/sh 2# Verify the operations done by shred 3 4# Copyright (C) 2009-2023 Free Software Foundation, Inc. 5 6# This program is free software: you can redistribute it and/or modify 7# it under the terms of the GNU General Public License as published by 8# the Free Software Foundation, either version 3 of the License, or 9# (at your option) any later version. 10 11# This program is distributed in the hope that it will be useful, 12# but WITHOUT ANY WARRANTY; without even the implied warranty of 13# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14# GNU General Public License for more details. 15 16# You should have received a copy of the GNU General Public License 17# along with this program. If not, see <https://www.gnu.org/licenses/>. 18 19. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src 20print_ver_ shred 21 22 23# shred a single letter, which should result in 24# 3 random passes and a single rename. 25printf 1 > f || framework_failure_ 26echo "\ 27shred: f: pass 1/3 (random)... 28shred: f: pass 2/3 (random)... 29shred: f: pass 3/3 (random)... 30shred: f: removing 31shred: f: renamed to 0 32shred: f: removed" > exp || framework_failure_ 33 34shred -v -u f 2>out || fail=1 35compare exp out || fail=1 36 37 38# Likewise but for a zero length file 39# to bypass the data passes 40touch f || framework_failure_ 41echo "\ 42shred: f: removing 43shred: f: renamed to 0 44shred: f: removed" > exp || framework_failure_ 45 46shred -v -u f 2>out || fail=1 47compare exp out || fail=1 48 49 50# shred data 20 times and verify the passes used. 51# This would consume all random data between 5.93 and 8.24 inclusive. 52dd bs=100K count=1 if=/dev/zero | tr '\0' 'U' > Us || framework_failure_ 53printf 1 > f || framework_failure_ 54echo "\ 55shred: f: pass 1/20 (random)... 56shred: f: pass 2/20 (ffffff)... 57shred: f: pass 3/20 (924924)... 58shred: f: pass 4/20 (888888)... 59shred: f: pass 5/20 (db6db6)... 60shred: f: pass 6/20 (777777)... 61shred: f: pass 7/20 (492492)... 62shred: f: pass 8/20 (bbbbbb)... 63shred: f: pass 9/20 (555555)... 64shred: f: pass 10/20 (aaaaaa)... 65shred: f: pass 11/20 (random)... 66shred: f: pass 12/20 (6db6db)... 67shred: f: pass 13/20 (249249)... 68shred: f: pass 14/20 (999999)... 69shred: f: pass 15/20 (111111)... 70shred: f: pass 16/20 (000000)... 71shred: f: pass 17/20 (b6db6d)... 72shred: f: pass 18/20 (eeeeee)... 73shred: f: pass 19/20 (333333)... 74shred: f: pass 20/20 (random)... 75shred: f: removing 76shred: f: renamed to 0 77shred: f: removed" > exp || framework_failure_ 78 79shred -v -u -n20 -s4096 --random-source=Us f 2>out || fail=1 80compare exp out || fail=1 81 82# Trigger an issue in shred before v8.27 where single 83# bytes in the pattern space were not initialized correctly 84# for particular sizes, like 7,13,... 85# This failed under both valgrind and ASAN. 86for size in 1 2 6 7 8; do 87 touch shred.pattern.umr.size 88 shred -n4 -s$size shred.pattern.umr.size || fail=1 89done 90 91Exit $fail 92