From 3752a77cf1544a8469678263ace9198314815f22 Mon Sep 17 00:00:00 2001 From: Paul Dreik Date: Mon, 3 Feb 2025 06:31:27 +0100 Subject: [PATCH] auto format shell scripts --- bootstrap.sh | 8 +- cppcheck/run_cppcheck.sh | 7 +- do_clang_format.sh | 14 +- do_quality_checks.sh | 487 ++++++++++---------- do_shellcheck.sh | 6 +- do_yamllint.sh | 14 +- testcases/checksum_buffersize.sh | 50 +- testcases/checksum_buffersize_speedtest.sh | 48 +- testcases/checksum_options.sh | 50 +- testcases/checksum_speedtest.sh | 20 +- testcases/common_funcs.sh | 61 ++- testcases/hardlink_fails.sh | 49 +- testcases/largefilesupport.sh | 12 +- testcases/md5collisions.sh | 7 +- testcases/sha1collisions.sh | 7 +- testcases/symlinking_action.sh | 145 +++--- testcases/verify_deterministic_operation.sh | 111 +++-- testcases/verify_dryrun_option.sh | 157 +++---- testcases/verify_filesize_option.sh | 72 ++- testcases/verify_maxfilesize_option.sh | 32 +- testcases/verify_ranking.sh | 84 ++-- 21 files changed, 697 insertions(+), 744 deletions(-) diff --git a/bootstrap.sh b/bootstrap.sh index 626b20f..950d34e 100755 --- a/bootstrap.sh +++ b/bootstrap.sh @@ -11,10 +11,10 @@ set -e me="$(basename "$0")" for prog in aclocal autoheader automake autoconf make; do - if ! which $prog >/dev/null 2>&1 ; then - echo "$me: please install $prog" - exit 1 - fi + if ! which $prog >/dev/null 2>&1; then + echo "$me: please install $prog" + exit 1 + fi done aclocal --warnings=all diff --git a/cppcheck/run_cppcheck.sh b/cppcheck/run_cppcheck.sh index bfe265b..a5a57fc 100755 --- a/cppcheck/run_cppcheck.sh +++ b/cppcheck/run_cppcheck.sh @@ -18,13 +18,10 @@ cppcheck $args --xml ./*.cc ./*.hh 2>"$outdir/cppcheck.xml" cppcheck-htmlreport --source-dir=. --title=rdfind --file="$outdir/cppcheck.xml" --report-dir="$outdir" - #is anything serious found? if grep --quiet -v -E '^(style|information|performance):' "$outdir/cppcheck.out"; then - echo "$me: cppcheck found serious issues. see $outdir/cppcheck.out" - exit 1 + echo "$me: cppcheck found serious issues. see $outdir/cppcheck.out" + exit 1 fi echo "$me: cppcheck passed without serious issues." - - diff --git a/do_clang_format.sh b/do_clang_format.sh index b677aa2..36d8d09 100755 --- a/do_clang_format.sh +++ b/do_clang_format.sh @@ -8,14 +8,14 @@ # See LICENSE for further details. #find clang format (usually named clang-format-3.x or clang-format, who knows) -CLANGFORMAT="$(find /usr/local/bin /usr/bin -executable -name "clang-format*" |grep -v -- -diff |sort -g |tail -n1)" +CLANGFORMAT="$(find /usr/local/bin /usr/bin -executable -name "clang-format*" | grep -v -- -diff | sort -g | tail -n1)" -if [ ! -x "$CLANGFORMAT" ] ; then - echo "failed finding clangformat" - exit 1 +if [ ! -x "$CLANGFORMAT" ]; then + echo "failed finding clangformat" + exit 1 else - echo "found clang format: $CLANGFORMAT" + echo "found clang format: $CLANGFORMAT" fi -find . -maxdepth 1 -type f \( -name "*.h" -o -name "*.cpp" -o -name "*.cc" -o -name "*.hh" \) -print0 | \ - xargs -0 -n1 "$CLANGFORMAT" -i +find . -maxdepth 1 -type f \( -name "*.h" -o -name "*.cpp" -o -name "*.cc" -o -name "*.hh" \) -print0 \ + | xargs -0 -n1 "$CLANGFORMAT" -i diff --git a/do_quality_checks.sh b/do_quality_checks.sh index b754ab6..55f125a 100755 --- a/do_quality_checks.sh +++ b/do_quality_checks.sh @@ -42,10 +42,10 @@ ASSERT= ############################################################################### start_from_scratch() { - cd "$rootdir" - if [ -e Makefile ] ; then - make distclean >/dev/null 2>&1 - fi + cd "$rootdir" + if [ -e Makefile ]; then + make distclean >/dev/null 2>&1 + fi } ############################################################################### @@ -53,297 +53,296 @@ start_from_scratch() { #argument 2 is the c++ standard #argument 3 (optional) is appended to CXXFLAGS compile_and_test_standard() { - start_from_scratch - # shellcheck disable=SC3037 - /bin/echo -n "$me: using $(basename "$1") with standard $2" - if [ -n "$3" ] ; then - echo " (with additional CXXFLAGS $3)" - else - echo "" - fi + start_from_scratch + # shellcheck disable=SC3037 + /bin/echo -n "$me: using $(basename "$1") with standard $2" + if [ -n "$3" ]; then + echo " (with additional CXXFLAGS $3)" + else + echo "" + fi - if ! ./bootstrap.sh >bootstrap.log 2>&1; then - echo "$me: failed bootstrap - see bootstrap.log" - exit 1 - fi - if ! ./configure $ASSERT --enable-warnings CXX="$1" CXXFLAGS="-std=$2 $3" >configure.log 2>&1 ; then - echo "$me: failed configure - see configure.log" - exit 1 - fi - #make sure it compiles - if [ ! -x /usr/bin/time ] ; then - echo "$me: please install /usr/bin/time (apt install time)" - exit 1 - fi - if ! /usr/bin/time --format=%e --output=time.log make >make.log 2>&1; then - echo "$me: failed make" - exit 1 - fi - if [ -n "$MEASURE_COMPILE_TIME" ] ; then - echo "$me: compile with $(basename "$1") '$2' took $(cat time.log) seconds" - fi - #check for warnings - if grep -q "warning" make.log; then - # store as an artifact instead of erroring out - name="$(cat ./*.log |sha256sum |head -c 12)" - cp make.log "make_${name}.log" - echo "$me: found compile warning - see make.log, also stored as make_${name}.log" - fi - #run the tests - if ! make check >makecheck.log 2>&1 ; then - echo "$me: failed make check - see makecheck.log" - exit 1 - fi + if ! ./bootstrap.sh >bootstrap.log 2>&1; then + echo "$me: failed bootstrap - see bootstrap.log" + exit 1 + fi + if ! ./configure $ASSERT --enable-warnings CXX="$1" CXXFLAGS="-std=$2 $3" >configure.log 2>&1; then + echo "$me: failed configure - see configure.log" + exit 1 + fi + #make sure it compiles + if [ ! -x /usr/bin/time ]; then + echo "$me: please install /usr/bin/time (apt install time)" + exit 1 + fi + if ! /usr/bin/time --format=%e --output=time.log make >make.log 2>&1; then + echo "$me: failed make" + exit 1 + fi + if [ -n "$MEASURE_COMPILE_TIME" ]; then + echo "$me: compile with $(basename "$1") '$2' took $(cat time.log) seconds" + fi + #check for warnings + if grep -q "warning" make.log; then + # store as an artifact instead of erroring out + name="$(cat ./*.log | sha256sum | head -c 12)" + cp make.log "make_${name}.log" + echo "$me: found compile warning - see make.log, also stored as make_${name}.log" + fi + #run the tests + if ! make check >makecheck.log 2>&1; then + echo "$me: failed make check - see makecheck.log" + exit 1 + fi } ############################################################################### #argument 1 is the compiler compile_and_test() { - #this is the test program to compile, so we know the compiler and standard lib - #works. clang 4 with c++2a does not. - echo "#include ">x.cpp - #does the compiler understand c++17? That is mandatory. - if ! $1 -c x.cpp -std=c++17 >/dev/null 2>&1 ; then - echo "$me: this compiler '$1' does not understand c++17" - return 0 - fi + #this is the test program to compile, so we know the compiler and standard lib + #works. clang 4 with c++2a does not. + echo "#include " >x.cpp + #does the compiler understand c++17? That is mandatory. + if ! $1 -c x.cpp -std=c++17 >/dev/null 2>&1; then + echo "$me: this compiler '$1' does not understand c++17" + return 0 + fi - #loop over all standard flags>=17 and try those which work. - #use the code words. - for std in 1z 2a 2b ; do - if ! $1 -c x.cpp -std=c++$std >/dev/null 2>&1 ; then - echo "$me: compiler does not understand c++$std, skipping this combination." - else - # debug build - ASSERT=--enable-assert - compile_and_test_standard "$1" "c++$std" "-Og" + #loop over all standard flags>=17 and try those which work. + #use the code words. + for std in 1z 2a 2b; do + if ! $1 -c x.cpp -std=c++$std >/dev/null 2>&1; then + echo "$me: compiler does not understand c++$std, skipping this combination." + else + # debug build + ASSERT=--enable-assert + compile_and_test_standard "$1" "c++$std" "-Og" - # release build - ASSERT=--disable-assert - #compile_and_test_standard $1 c++$std "-O2" - compile_and_test_standard "$1" "c++$std" "-O3" - #compile_and_test_standard $1 c++$std "-Os" - fi - done + # release build + ASSERT=--disable-assert + #compile_and_test_standard $1 c++$std "-O2" + compile_and_test_standard "$1" "c++$std" "-O3" + #compile_and_test_standard $1 c++$std "-Os" + fi + done - rm x.cpp + rm x.cpp } ############################################################################### # finds the latest clang on the form clang++- and if none found, checks for # clang++. first found is assigned to variable latestclang get_latest_clang() { - for ver in $(seq 30 -1 10); do - candidate="clang++-$ver" - if which "$candidate" >/dev/null 2>&1; then - latestclang="$candidate" - return - fi - done - if which clang++ >/dev/null 2>&1; then - latestclang=clang++ + for ver in $(seq 30 -1 10); do + candidate="clang++-$ver" + if which "$candidate" >/dev/null 2>&1; then + latestclang="$candidate" return - fi - latestclang= + fi + done + if which clang++ >/dev/null 2>&1; then + latestclang=clang++ + return + fi + latestclang= } ############################################################################### run_with_sanitizer() { - echo "$me: running with sanitizer (options $1)" - get_latest_clang - if [ -z "$latestclang" ] ; then - echo "$me: could not find any clang compiler (on the form clang++-ver)" - return 0 - fi + echo "$me: running with sanitizer (options $1)" + get_latest_clang + if [ -z "$latestclang" ]; then + echo "$me: could not find any clang compiler (on the form clang++-ver)" + return 0 + fi - start_from_scratch - ./bootstrap.sh >bootstrap.log - ./configure "$ASSERT" "CXX=$latestclang" CXXFLAGS="-std=c++17 $1" >configure.log - make > make.log 2>&1 - export UBSAN_OPTIONS="halt_on_error=true exitcode=1" - export ASAN_OPTIONS="halt_on_error=true exitcode=1" - make check >make-check.log 2>&1 - unset UBSAN_OPTIONS - unset ASAN_OPTIONS + start_from_scratch + ./bootstrap.sh >bootstrap.log + ./configure "$ASSERT" "CXX=$latestclang" CXXFLAGS="-std=c++17 $1" >configure.log + make >make.log 2>&1 + export UBSAN_OPTIONS="halt_on_error=true exitcode=1" + export ASAN_OPTIONS="halt_on_error=true exitcode=1" + make check >make-check.log 2>&1 + unset UBSAN_OPTIONS + unset ASAN_OPTIONS } ############################################################################### #This tries to mimic how the debian package is built run_with_debian_buildflags() { - echo "$me: running with buildflags from debian dpkg-buildflags" - if ! which dpkg-buildflags >/dev/null ; then - echo "$me: dpkg-buildflags not found - skipping" - return 0 - fi - start_from_scratch - ./bootstrap.sh >bootstrap.log - eval "$(DEB_BUILD_MAINT_OPTIONS="hardening=+all qa=+all,-canary reproducible=+all" dpkg-buildflags --export=sh)" - ./configure >configure.log - make > make.log 2>&1 - #check for warnings - if grep -q "warning" make.log; then - # store as an artifact instead of erroring out - name="$(cat ./*.log |sha256sum |head -c 12)" - cp make.log "make_${name}.log" - echo "$me: found compile warnings - see make.log, also stored as make_${name}.log" + echo "$me: running with buildflags from debian dpkg-buildflags" + if ! which dpkg-buildflags >/dev/null; then + echo "$me: dpkg-buildflags not found - skipping" + return 0 + fi + start_from_scratch + ./bootstrap.sh >bootstrap.log + eval "$(DEB_BUILD_MAINT_OPTIONS="hardening=+all qa=+all,-canary reproducible=+all" dpkg-buildflags --export=sh)" + ./configure >configure.log + make >make.log 2>&1 + #check for warnings + if grep -q "warning" make.log; then + # store as an artifact instead of erroring out + name="$(cat ./*.log | sha256sum | head -c 12)" + cp make.log "make_${name}.log" + echo "$me: found compile warnings - see make.log, also stored as make_${name}.log" - fi - make check >make-check.log 2>&1 + fi + make check >make-check.log 2>&1 - #restore the build environment - for flag in $(dpkg-buildflags |cut -f1 -d=) ; do - unset "$flag" - done + #restore the build environment + for flag in $(dpkg-buildflags | cut -f1 -d=); do + unset "$flag" + done } ############################################################################### run_with_libcpp() { - # use the latest clang and see if it works - echo "#include + # use the latest clang and see if it works + echo "#include int main() { std::cout<<\"libc++ works!\"<x.cpp - get_latest_clang - if [ -n "$latestclang" ] ; then - if ! "$latestclang" -std=c++17 -stdlib=libc++ -lc++abi x.cpp >/dev/null 2>&1 || [ ! -x ./a.out ] || ! ./a.out ; then - echo "$me: debug: $latestclang could not compile with libc++ - perhaps uninstalled." - return - fi - compile_and_test_standard "$latestclang" c++17 "-stdlib=libc++ -D_LIBCPP_DEBUG=1" + get_latest_clang + if [ -n "$latestclang" ]; then + if ! "$latestclang" -std=c++17 -stdlib=libc++ -lc++abi x.cpp >/dev/null 2>&1 || [ ! -x ./a.out ] || ! ./a.out; then + echo "$me: debug: $latestclang could not compile with libc++ - perhaps uninstalled." return - fi - # we will get here if no clang could be found. that is not an error, - # having clang and libc++ installed is optional - echo "$me: no working clang with libc++ found, skipping." + fi + compile_and_test_standard "$latestclang" c++17 "-stdlib=libc++ -D_LIBCPP_DEBUG=1" + return + fi + # we will get here if no clang could be found. that is not an error, + # having clang and libc++ installed is optional + echo "$me: no working clang with libc++ found, skipping." } ############################################################################### verify_packaging() { - #make sure the packaging works as intended. - echo "$me: trying to make a tar ball for release and building it..." - log="$(pwd)/packagetest.log" - ./bootstrap.sh >"$log" - ./configure >>"$log" + #make sure the packaging works as intended. + echo "$me: trying to make a tar ball for release and building it..." + log="$(pwd)/packagetest.log" + ./bootstrap.sh >"$log" + ./configure >>"$log" - touch dummy - make dist >>"$log" - TARGZ=$(find "$(pwd)" -newer dummy -name "rdfind*gz" -type f |head -n1) - rm dummy - temp="$(mktemp -d)" - cp "$TARGZ" "$temp" - cd "$temp" - tar xzf "$(basename "$TARGZ")" >>"$log" - cd "$(basename "$TARGZ" .tar.gz)" - { - ./configure --prefix="$temp" - make - make check - make install - "$temp/bin/rdfind" --version - } >>"$log" - #coming here means all went fine, go back to the source dir. - cd "$(dirname "$TARGZ")" - rm -rf "$temp" + touch dummy + make dist >>"$log" + TARGZ=$(find "$(pwd)" -newer dummy -name "rdfind*gz" -type f | head -n1) + rm dummy + temp="$(mktemp -d)" + cp "$TARGZ" "$temp" + cd "$temp" + tar xzf "$(basename "$TARGZ")" >>"$log" + cd "$(basename "$TARGZ" .tar.gz)" + { + ./configure --prefix="$temp" + make + make check + make install + "$temp/bin/rdfind" --version + } >>"$log" + #coming here means all went fine, go back to the source dir. + cd "$(dirname "$TARGZ")" + rm -rf "$temp" } ############################################################################### verify_self_contained_headers() { - # shellcheck disable=SC3037 - /bin/echo -n "$me: verify that all header files are self contained..." - if [ ! -e configure ]; then - ./bootstrap.sh >bootstrap.log 2>&1 - fi - if [ ! -e config.h ]; then - ./configure >configure.log 2>&1 - fi - for header in *.hh ; do - cp "$header" tmp.cc - if ! g++ -std=c++17 -I. -c tmp.cc -o /dev/null >header.log 2>&1 ; then - echo "$me: found a header which is not self contained: $header." - echo "$me: see header.log for details" - exit 1 - fi - rm tmp.cc - done - echo "OK!" + # shellcheck disable=SC3037 + /bin/echo -n "$me: verify that all header files are self contained..." + if [ ! -e configure ]; then + ./bootstrap.sh >bootstrap.log 2>&1 + fi + if [ ! -e config.h ]; then + ./configure >configure.log 2>&1 + fi + for header in *.hh; do + cp "$header" tmp.cc + if ! g++ -std=c++17 -I. -c tmp.cc -o /dev/null >header.log 2>&1; then + echo "$me: found a header which is not self contained: $header." + echo "$me: see header.log for details" + exit 1 + fi + rm tmp.cc + done + echo "OK!" } ############################################################################### build_32bit() { - #compiling to 32 bit, on amd64. - #apt install libc6-i386 gcc-multilib g++-multilib - # - if [ "$(uname -m)" != x86_64 ] ; then - echo "$me: not on x64, won't cross compile with -m32" - return; - fi - echo "$me: trying to compile in 32 bit mode with -m32..." - configureflags="--build=i686-pc-linux-gnu CFLAGS=-m32 CXXFLAGS=-m32 LDFLAGS=-m32" - here="$(pwd)" - nettleinstall=$here/nettle32bit - if [ -d "$nettleinstall" ] ; then - echo "$me: local nettle already seems to be installed" - else - mkdir "$nettleinstall" - cd "$nettleinstall" - nettleversion=3.10.1 - echo "$me: downloading nettle from gnu.org..." - wget --quiet https://ftp.gnu.org/gnu/nettle/nettle-$nettleversion.tar.gz - echo "b0fcdd7fc0cdea6e80dcf1dd85ba794af0d5b4a57e26397eee3bc193272d9132 nettle-$nettleversion.tar.gz" >checksum - sha256sum --strict --quiet -c checksum - tar xzf nettle-$nettleversion.tar.gz - cd nettle-$nettleversion - echo "$me: trying to configure nettle" - # shellcheck disable=SC2086 - ./configure $configureflags --prefix="$nettleinstall" >"$here/nettle.configure.log" 2>&1 - make install >"$here/nettle.install.log" 2>&1 - echo "$me: local nettle install went ok" - cd "$here" - fi - ./bootstrap.sh >bootstrap.log 2>&1 - echo "$me: attempting configure with 32 bit flags... (see configure.log if it fails)" - ./configure --build=i686-pc-linux-gnu CFLAGS=-m32 CXXFLAGS="-m32 -I$nettleinstall/include" LDFLAGS="-m32 -L$nettleinstall/lib" >configure.log 2>&1 - echo "$me: building with 32 bit flags... (check make.log if it fails)" - make >make.log 2>&1 - echo "$me: make check with 32 bit flags... (check make-check.log if it fails)" - LD_LIBRARY_PATH=$nettleinstall/lib make check >make-check.log 2>&1 - echo "$me: 32 bit tests went fine!" + #compiling to 32 bit, on amd64. + #apt install libc6-i386 gcc-multilib g++-multilib + # + if [ "$(uname -m)" != x86_64 ]; then + echo "$me: not on x64, won't cross compile with -m32" + return + fi + echo "$me: trying to compile in 32 bit mode with -m32..." + configureflags="--build=i686-pc-linux-gnu CFLAGS=-m32 CXXFLAGS=-m32 LDFLAGS=-m32" + here="$(pwd)" + nettleinstall=$here/nettle32bit + if [ -d "$nettleinstall" ]; then + echo "$me: local nettle already seems to be installed" + else + mkdir "$nettleinstall" + cd "$nettleinstall" + nettleversion=3.10.1 + echo "$me: downloading nettle from gnu.org..." + wget --quiet https://ftp.gnu.org/gnu/nettle/nettle-$nettleversion.tar.gz + echo "b0fcdd7fc0cdea6e80dcf1dd85ba794af0d5b4a57e26397eee3bc193272d9132 nettle-$nettleversion.tar.gz" >checksum + sha256sum --strict --quiet -c checksum + tar xzf nettle-$nettleversion.tar.gz + cd nettle-$nettleversion + echo "$me: trying to configure nettle" + # shellcheck disable=SC2086 + ./configure $configureflags --prefix="$nettleinstall" >"$here/nettle.configure.log" 2>&1 + make install >"$here/nettle.install.log" 2>&1 + echo "$me: local nettle install went ok" + cd "$here" + fi + ./bootstrap.sh >bootstrap.log 2>&1 + echo "$me: attempting configure with 32 bit flags... (see configure.log if it fails)" + ./configure --build=i686-pc-linux-gnu CFLAGS=-m32 CXXFLAGS="-m32 -I$nettleinstall/include" LDFLAGS="-m32 -L$nettleinstall/lib" >configure.log 2>&1 + echo "$me: building with 32 bit flags... (check make.log if it fails)" + make >make.log 2>&1 + echo "$me: make check with 32 bit flags... (check make-check.log if it fails)" + LD_LIBRARY_PATH=$nettleinstall/lib make check >make-check.log 2>&1 + echo "$me: 32 bit tests went fine!" } ############################################################################### - #this is pretty quick so start with it. verify_self_contained_headers #keep track of which compilers have already been tested -echo "">inodes_for_tested_compilers.txt +echo "" >inodes_for_tested_compilers.txt #try all variants of g++ -if which g++ >/dev/null ; then - for COMPILER in "$(which g++)"*; do - if echo "$COMPILER" | grep libc; then - continue - fi - inode=$(stat --dereference --format=%i "$COMPILER") - if [ -f inodes_for_tested_compilers.txt ] && grep -q "^$inode\$" inodes_for_tested_compilers.txt >/dev/null; then - echo "$me: skipping this compiler $COMPILER - already tested" - else - #echo trying gcc $GCC:$($GCC --version|head -n1) - echo "$inode" >>inodes_for_tested_compilers.txt - compile_and_test "$COMPILER" - fi - done +if which g++ >/dev/null; then + for COMPILER in "$(which g++)"*; do + if echo "$COMPILER" | grep libc; then + continue + fi + inode=$(stat --dereference --format=%i "$COMPILER") + if [ -f inodes_for_tested_compilers.txt ] && grep -q "^$inode\$" inodes_for_tested_compilers.txt >/dev/null; then + echo "$me: skipping this compiler $COMPILER - already tested" + else + #echo trying gcc $GCC:$($GCC --version|head -n1) + echo "$inode" >>inodes_for_tested_compilers.txt + compile_and_test "$COMPILER" + fi + done fi #try all variants of clang get_latest_clang -if which "$latestclang" >/dev/null ; then - for COMPILER in "$(dirname "$(which "$latestclang")")"/clang++*; do - if echo "$COMPILER" | grep libc; then - continue - fi - inode=$(stat --dereference --format=%i "$COMPILER") - if [ -f inodes_for_tested_compilers.txt ] && grep -q "^$inode\$" inodes_for_tested_compilers.txt >/dev/null; then - echo "$me: skipping this compiler $COMPILER - already tested" - else - #echo trying gcc $GCC:$($GCC --version|head -n1) - echo "$inode" >>inodes_for_tested_compilers.txt - compile_and_test "$COMPILER" - fi - done +if which "$latestclang" >/dev/null; then + for COMPILER in "$(dirname "$(which "$latestclang")")"/clang++*; do + if echo "$COMPILER" | grep libc; then + continue + fi + inode=$(stat --dereference --format=%i "$COMPILER") + if [ -f inodes_for_tested_compilers.txt ] && grep -q "^$inode\$" inodes_for_tested_compilers.txt >/dev/null; then + echo "$me: skipping this compiler $COMPILER - already tested" + else + #echo trying gcc $GCC:$($GCC --version|head -n1) + echo "$inode" >>inodes_for_tested_compilers.txt + compile_and_test "$COMPILER" + fi + done fi rm inodes_for_tested_compilers.txt @@ -370,10 +369,10 @@ run_with_libcpp #test build with running through valgrind if which valgrind >/dev/null; then - echo "$me: running unit tests through valgrind" - ASSERT="--disable-assert" - compile_and_test_standard g++ c++17 "-O3" - VALGRIND=valgrind make check >make-check.log + echo "$me: running unit tests through valgrind" + ASSERT="--disable-assert" + compile_and_test_standard g++ c++17 "-O3" + VALGRIND=valgrind make check >make-check.log fi #make sure it is possible to build a tar ball, diff --git a/do_shellcheck.sh b/do_shellcheck.sh index 3fe577b..b32d0c0 100755 --- a/do_shellcheck.sh +++ b/do_shellcheck.sh @@ -4,14 +4,12 @@ set -e me=$(basename "$0") - echo "$me: run shellcheck on shellscripts" ( - git ls-files | grep -v "^testcases" | grep -E ".sh$" | xargs shellcheck + git ls-files | grep -v "^testcases" | grep -E ".sh$" | xargs shellcheck ) echo "$me: run shellcheck on testcases" ( - cd testcases && git ls-files | grep -E ".sh$" | xargs shellcheck -x + cd testcases && git ls-files | grep -E ".sh$" | xargs shellcheck -x ) - diff --git a/do_yamllint.sh b/do_yamllint.sh index 48fea76..2df3e58 100755 --- a/do_yamllint.sh +++ b/do_yamllint.sh @@ -4,15 +4,15 @@ set -e YMLLINT="" if which yamllint >/dev/null 2>/dev/null; then - YMLLINT="yamllint" + YMLLINT="yamllint" elif [ -f .venv/bin/yamllint ]; then - YMLLINT=".venv/bin/yamllint" + YMLLINT=".venv/bin/yamllint" else - echo "could not find yamllint please install" - echo "for debian based systems: apt -y install libxml2-utils" - echo "for redhat based systems: dnf install yamllint" - echo "local install: python3 -m venv .venv && .venv/bin/python3 -m pip install yamllint" - exit 3 + echo "could not find yamllint please install" + echo "for debian based systems: apt -y install libxml2-utils" + echo "for redhat based systems: dnf install yamllint" + echo "local install: python3 -m venv .venv && .venv/bin/python3 -m pip install yamllint" + exit 3 fi # run this when all issues are fixed diff --git a/testcases/checksum_buffersize.sh b/testcases/checksum_buffersize.sh index 695c5db..de0649a 100755 --- a/testcases/checksum_buffersize.sh +++ b/testcases/checksum_buffersize.sh @@ -10,12 +10,12 @@ TEST_DIR=buffersizes_test mkdir -p "$TEST_DIR" make_test_files() { - dbgecho "creating test files in $TEST_DIR" - head -c 1000000 /dev/zero >"$TEST_DIR/a" - cp "$TEST_DIR/a" "$TEST_DIR/b" - cp "$TEST_DIR/a" "$TEST_DIR/c" - cp "$TEST_DIR/a" "$TEST_DIR/d" - cp "$TEST_DIR/a" "$TEST_DIR/e" + dbgecho "creating test files in $TEST_DIR" + head -c 1000000 /dev/zero >"$TEST_DIR/a" + cp "$TEST_DIR/a" "$TEST_DIR/b" + cp "$TEST_DIR/a" "$TEST_DIR/c" + cp "$TEST_DIR/a" "$TEST_DIR/d" + cp "$TEST_DIR/a" "$TEST_DIR/e" } dbgecho "check so all buffersizes behave the same" @@ -23,23 +23,23 @@ dbgecho "check so all buffersizes behave the same" # disables only run once shellscheck # shellcheck disable=SC2043 for checksumtype in sha256; do - i=1 - while :; do - if [ $i -gt 128 ]; then - break - fi - i="$((i*2))" - make_test_files - dbgecho "testing buffersize $((i*1024))" - dbgecho "testing $checksumtype" - # Fix this properly by making rdfind to array and use "${rdfind[@]}" - # this requires bash not sh - # shellcheck disable=SC2086 - $rdfind -buffersize $((i*1024)) -checksum "$checksumtype" -deleteduplicates true "$TEST_DIR" >/dev/null - [ -e "$TEST_DIR/a" ] - [ ! -e "$TEST_DIR/b" ] - [ ! -e "$TEST_DIR/c" ] - [ ! -e "$TEST_DIR/d" ] - [ ! -e "$TEST_DIR/e" ] - done + i=1 + while :; do + if [ $i -gt 128 ]; then + break + fi + i="$((i * 2))" + make_test_files + dbgecho "testing buffersize $((i * 1024))" + dbgecho "testing $checksumtype" + # Fix this properly by making rdfind to array and use "${rdfind[@]}" + # this requires bash not sh + # shellcheck disable=SC2086 + $rdfind -buffersize $((i * 1024)) -checksum "$checksumtype" -deleteduplicates true "$TEST_DIR" >/dev/null + [ -e "$TEST_DIR/a" ] + [ ! -e "$TEST_DIR/b" ] + [ ! -e "$TEST_DIR/c" ] + [ ! -e "$TEST_DIR/d" ] + [ ! -e "$TEST_DIR/e" ] + done done diff --git a/testcases/checksum_buffersize_speedtest.sh b/testcases/checksum_buffersize_speedtest.sh index 1b6e95d..c6d94c5 100755 --- a/testcases/checksum_buffersize_speedtest.sh +++ b/testcases/checksum_buffersize_speedtest.sh @@ -11,15 +11,18 @@ TEST_DIR=buffersizes_speedtest mkdir -p "$TEST_DIR" make_test_files() { - dbgecho "creating test files in $TEST_DIR/bigfiles" - mkdir -p "$TEST_DIR/bigfiles" - head -c $((1024*1024*500)) /dev/zero >"$TEST_DIR/bigfiles/a" - for f in b c d e; do - cp "$TEST_DIR/bigfiles/a" "$TEST_DIR/bigfiles/$f" - done - dbgecho "creating test files in $TEST_DIR/smallfiles" - mkdir -p "$TEST_DIR/smallfiles" - (cd "$TEST_DIR/smallfiles"; head -c100000000 /dev/zero |split --bytes 1000) + dbgecho "creating test files in $TEST_DIR/bigfiles" + mkdir -p "$TEST_DIR/bigfiles" + head -c $((1024 * 1024 * 500)) /dev/zero >"$TEST_DIR/bigfiles/a" + for f in b c d e; do + cp "$TEST_DIR/bigfiles/a" "$TEST_DIR/bigfiles/$f" + done + dbgecho "creating test files in $TEST_DIR/smallfiles" + mkdir -p "$TEST_DIR/smallfiles" + ( + cd "$TEST_DIR/smallfiles" + head -c100000000 /dev/zero | split --bytes 1000 + ) } dbgecho "run speed test for all shecksums and buffersizes" @@ -28,21 +31,20 @@ make_test_files cat /dev/null >"$TEST_DIR/results.tsv" for filesize in big small; do -for checksumtype in sha1 xxh128; do + for checksumtype in sha1 xxh128; do i=1 while :; do - if [ $i -gt 4096 ]; then - break - fi - # Fix this properly by making rdfind to array and use "${rdfind[@]}" - # this requires bash not sh - # shellcheck disable=SC2086 - dbgecho "testing $checksumtype $i kB buffersize" - # shellcheck disable=SC2086 - /usr/bin/time --append --output=$TEST_DIR/results.tsv -f "$filesize\t$i\t$checksumtype\t%e\t%M\t%C" $rdfind -buffersize $((i*1024)) -checksum "$checksumtype" -dryrun true -deleteduplicates true "$TEST_DIR/${filesize}files" >/dev/null 2>&1 - i="$((i*2))" -done -done + if [ $i -gt 4096 ]; then + break + fi + # Fix this properly by making rdfind to array and use "${rdfind[@]}" + # this requires bash not sh + # shellcheck disable=SC2086 + dbgecho "testing $checksumtype $i kB buffersize" + # shellcheck disable=SC2086 + /usr/bin/time --append --output=$TEST_DIR/results.tsv -f "$filesize\t$i\t$checksumtype\t%e\t%M\t%C" $rdfind -buffersize $((i * 1024)) -checksum "$checksumtype" -dryrun true -deleteduplicates true "$TEST_DIR/${filesize}files" >/dev/null 2>&1 + i="$((i * 2))" + done + done done cat "$TEST_DIR/results.tsv" - diff --git a/testcases/checksum_options.sh b/testcases/checksum_options.sh index dfbc56f..b72f2c6 100755 --- a/testcases/checksum_options.sh +++ b/testcases/checksum_options.sh @@ -5,33 +5,41 @@ set -e . "$(dirname "$0")/common_funcs.sh" for checksumtype in $allchecksumtypes; do - reset_teststate - dbgecho "trying checksum $checksumtype with small files" - echo checksumtest >a - echo checksumtest >b - $rdfind -checksum "$checksumtype" -deleteduplicates true a b - [ -e a ] - [ ! -e b ] + reset_teststate + dbgecho "trying checksum $checksumtype with small files" + echo checksumtest >a + echo checksumtest >b + $rdfind -checksum "$checksumtype" -deleteduplicates true a b + [ -e a ] + [ ! -e b ] done for checksumtype in $allchecksumtypes; do - reset_teststate - dbgecho "trying checksum $checksumtype with large files" - head -c 1000000 /dev/zero >a - head -c 1000000 /dev/zero >b - $rdfind -checksum "$checksumtype" -deleteduplicates true a b - [ -e a ] - [ ! -e b ] + reset_teststate + dbgecho "trying checksum $checksumtype with large files" + head -c 1000000 /dev/zero >a + head -c 1000000 /dev/zero >b + $rdfind -checksum "$checksumtype" -deleteduplicates true a b + [ -e a ] + [ ! -e b ] done for checksumtype in $allchecksumtypes; do - reset_teststate - dbgecho "trying checksum $checksumtype with large files that differ only in the middle" - ( head -c 1000000 /dev/zero; echo =====a=====; head -c 1000000 /dev/zero) >a - ( head -c 1000000 /dev/zero; echo =====b=====; head -c 1000000 /dev/zero) >b - $rdfind -checksum "$checksumtype" -deleteduplicates true a b - [ -e a ] - [ -e b ] + reset_teststate + dbgecho "trying checksum $checksumtype with large files that differ only in the middle" + ( + head -c 1000000 /dev/zero + echo =====a===== + head -c 1000000 /dev/zero + ) >a + ( + head -c 1000000 /dev/zero + echo =====b===== + head -c 1000000 /dev/zero + ) >b + $rdfind -checksum "$checksumtype" -deleteduplicates true a b + [ -e a ] + [ -e b ] done dbgecho "all is good in this test!" diff --git a/testcases/checksum_speedtest.sh b/testcases/checksum_speedtest.sh index 6f221c7..5884e5b 100755 --- a/testcases/checksum_speedtest.sh +++ b/testcases/checksum_speedtest.sh @@ -2,27 +2,25 @@ # Performance test for checksumming. Not meant # to be run for regular testing. - set -e . "$(dirname "$0")/common_funcs.sh" reset_teststate -if [ ! -d speedtest ] ; then - mkdir -p speedtest +if [ ! -d speedtest ]; then + mkdir -p speedtest fi -if [ ! -e speedtest/largefile1 ] ; then - head -c1000000000 /dev/zero >speedtest/largefile1 - cp -al speedtest/largefile1 speedtest/largefile2 - #warm up the cache - md5sum speedtest/largefile1 speedtest/largefile2 +if [ ! -e speedtest/largefile1 ]; then + head -c1000000000 /dev/zero >speedtest/largefile1 + cp -al speedtest/largefile1 speedtest/largefile2 + #warm up the cache + md5sum speedtest/largefile1 speedtest/largefile2 fi - for checksumtype in $allchecksumtypes; do - dbgecho "trying checksum $checksumtype" - time $rdfind -removeidentinode false -checksum "$checksumtype" speedtest/largefile1 speedtest/largefile2 > rdfind.out + dbgecho "trying checksum $checksumtype" + time $rdfind -removeidentinode false -checksum "$checksumtype" speedtest/largefile1 speedtest/largefile2 >rdfind.out done dbgecho "all is good in this test!" diff --git a/testcases/common_funcs.sh b/testcases/common_funcs.sh index eeccd46..a4787c4 100755 --- a/testcases/common_funcs.sh +++ b/testcases/common_funcs.sh @@ -1,33 +1,31 @@ #!/bin/sh # common functionality for the unit tests - - #bail out on the first error set -e me="$(basename "$0")" if [ "$WITH_XXHASH" = "1" ]; then - export allchecksumtypes="md5 sha1 sha256 sha512 xxh128" + export allchecksumtypes="md5 sha1 sha256 sha512 xxh128" else - export allchecksumtypes="md5 sha1 sha256 sha512" + export allchecksumtypes="md5 sha1 sha256 sha512" fi # shellcheck disable=SC3037 /bin/echo -n "$me: checking for rdfind ..." rdfind=$PWD/rdfind if [ ! -x "$rdfind" ]; then - echo "could not find $rdfind" - exit 1 + echo "could not find $rdfind" + exit 1 fi echo " OK." printf "checking for valgrind ..." -if [ -z "$VALGRIND" ] ; then - echo "not used." +if [ -z "$VALGRIND" ]; then + echo "not used." else - echo "active! here is the command: $VALGRIND" + echo "active! here is the command: $VALGRIND" fi rdfind="$VALGRIND $rdfind" @@ -37,10 +35,9 @@ testscriptsdir="$(dirname "$(readlink -f "$0")")" export testscriptsdir dbgecho() { - echo "$0 debug: " "$@" + echo "$0 debug: " "$@" } - printf "checking for mktemp ..." which mktemp >/dev/null echo " OK." @@ -50,34 +47,30 @@ echo " OK." datadir=$(mktemp -d -t rdfindtestcases.d.XXXXXXXXXXXX) dbgecho "temp dir is $datadir" - - - -cleanup () { - cd / - rm -rf "$datadir" +cleanup() { + cd / + rm -rf "$datadir" } -if [ -z "$KEEPTEMPDIR" ] ; then - trap cleanup INT QUIT EXIT +if [ -z "$KEEPTEMPDIR" ]; then + trap cleanup INT QUIT EXIT fi [ -d "$datadir" ] cd "$datadir" reset_teststate() { - cd / - rm -rf "$datadir" - mkdir -p "$datadir" - cd "$datadir" + cd / + rm -rf "$datadir" + mkdir -p "$datadir" + cd "$datadir" } - verify() { - if ! "$@" ; then - echo "failed asserting $*" - exit 1 - fi + if ! "$@"; then + echo "failed asserting $*" + exit 1 + fi } # where to mount disorderfs for the determinism tests @@ -87,11 +80,11 @@ DISORDERED_ROOT="$datadir/disordered_root" # do we have a working disorder fs? hasdisorderfs=false if which disorderfs fusermount >/dev/null 2>&1; then - mkdir -p "$DISORDERED_MNT" "$DISORDERED_ROOT" - if disorderfs "$DISORDERED_ROOT" "$DISORDERED_MNT" >/dev/null 2>&1 ; then - # "Sälj inte skinnet förrän björnen är skjuten - Don't count your chickens until they're hatched" - fusermount -z -u "$DISORDERED_MNT" - hasdisorderfs=true - fi + mkdir -p "$DISORDERED_MNT" "$DISORDERED_ROOT" + if disorderfs "$DISORDERED_ROOT" "$DISORDERED_MNT" >/dev/null 2>&1; then + # "Sälj inte skinnet förrän björnen är skjuten - Don't count your chickens until they're hatched" + fusermount -z -u "$DISORDERED_MNT" + hasdisorderfs=true + fi fi export hasdisorderfs diff --git a/testcases/hardlink_fails.sh b/testcases/hardlink_fails.sh index 9fde52a..1e3d68e 100755 --- a/testcases/hardlink_fails.sh +++ b/testcases/hardlink_fails.sh @@ -3,7 +3,6 @@ # # See https://github.com/pauldreik/rdfind/issues/5 - set -e . "$(dirname "$0")/common_funcs.sh" @@ -12,21 +11,21 @@ reset_teststate #make identical files. files="a subdir/b c some/deeply/nested/subdir/d" nfiles=4 -for n in $files ; do - mkdir -p "$(dirname "$datadir/$n")" - echo "hello hardlink" > "$datadir/$n" +for n in $files; do + mkdir -p "$(dirname "$datadir/$n")" + echo "hello hardlink" >"$datadir/$n" done #eliminate them. $rdfind -makehardlinks true "$datadir/" #make sure one is a hard link to the other. -for n in $files ; do - nhardlinks=$(stat -c %h "$datadir/$n") - if [ "$nhardlinks" -ne "$nfiles" ] ; then - dbgecho "expected $nfiles hardlinks, got $nhardlinks" - exit 1 - fi +for n in $files; do + nhardlinks=$(stat -c %h "$datadir/$n") + if [ "$nhardlinks" -ne "$nfiles" ]; then + dbgecho "expected $nfiles hardlinks, got $nhardlinks" + exit 1 + fi done dbgecho passed the happy path @@ -34,29 +33,29 @@ dbgecho passed the happy path reset_teststate mkdir -p "$datadir/readonly.d/" -echo xxx > "$datadir/readonly.d/a" -echo xxx > "$datadir/readonly.d/b" +echo xxx >"$datadir/readonly.d/a" +echo xxx >"$datadir/readonly.d/b" chmod 500 "$datadir/readonly.d/" if [ "$(id -u)" -eq 0 ]; then - # if running as root, directory rights are not respected. drop the capability - # for doing that (requires capsh from package libcap2-bin) - MAYBEDROP="capsh --drop=CAP_DAC_OVERRIDE -- -c" + # if running as root, directory rights are not respected. drop the capability + # for doing that (requires capsh from package libcap2-bin) + MAYBEDROP="capsh --drop=CAP_DAC_OVERRIDE -- -c" else - MAYBEDROP="/bin/sh -c" + MAYBEDROP="/bin/sh -c" fi -$MAYBEDROP "$rdfind -makehardlinks true $datadir/readonly.d/" 2>&1 |tee rdfind.out -if ! grep -iq "failed" rdfind.out ; then - dbgecho "expected failure when trying to make hardlink on readonly directory" - exit 1 +$MAYBEDROP "$rdfind -makehardlinks true $datadir/readonly.d/" 2>&1 | tee rdfind.out +if ! grep -iq "failed" rdfind.out; then + dbgecho "expected failure when trying to make hardlink on readonly directory" + exit 1 fi #make sure that our own copy is still there -for f in a b ; do - if [ ! -e "$datadir/readonly.d/$f" ] ; then - dbgecho "file $f is missing, rdfind should not have removed it!" - exit 1 - fi +for f in a b; do + if [ ! -e "$datadir/readonly.d/$f" ]; then + dbgecho "file $f is missing, rdfind should not have removed it!" + exit 1 + fi done # make sure it can be cleaned up diff --git a/testcases/largefilesupport.sh b/testcases/largefilesupport.sh index c648c20..c487197 100755 --- a/testcases/largefilesupport.sh +++ b/testcases/largefilesupport.sh @@ -7,8 +7,8 @@ set -e reset_teststate #create a large file, sparse. -filesizem1=2147483647 #size, in bytes. This is no problem. -filesize=$((filesizem1+1)) #size, in bytes. This is a problematic value. +filesizem1=2147483647 #size, in bytes. This is no problem. +filesize=$((filesizem1 + 1)) #size, in bytes. This is a problematic value. #below, dd is used and the file is later appended to, to avoid problems #on Hurd which currently (20130619) can not take $filesize as argument to @@ -16,8 +16,8 @@ filesize=$((filesizem1+1)) #size, in bytes. This is a problematic value. #make two files, which differ at the first byte to make #rdfind return fast after comparing the initial part. -echo "a">sparse-file1 -echo "b">sparse-file2 +echo "a" >sparse-file1 +echo "b" >sparse-file2 dd if=/dev/null of=sparse-file1 bs=1 seek=$filesizem1 count=1 dd if=/dev/null of=sparse-file2 bs=1 seek=$filesizem1 count=1 head -c1 /dev/zero >>sparse-file1 @@ -29,11 +29,11 @@ sync #To prevent rdfind from reading its result file or rdfind.out mkdir subdir mv sparse-file* subdir -$rdfind subdir 2>&1 |tee rdfind.out +$rdfind subdir 2>&1 | tee rdfind.out dbgecho "rdfind ran ok." #make sure rdfind.out contains the right size -grep -q "^Total size is $((filesize*2)) bytes" rdfind.out +grep -q "^Total size is $((filesize * 2)) bytes" rdfind.out #make sure none could be reduced grep -q "^It seems like you have 0 files that are not unique$" rdfind.out diff --git a/testcases/md5collisions.sh b/testcases/md5collisions.sh index 83cda84..4030ecf 100755 --- a/testcases/md5collisions.sh +++ b/testcases/md5collisions.sh @@ -1,26 +1,23 @@ #!/bin/sh #This just tests basic operation - set -e . "$(dirname "$0")/common_funcs.sh" reset_teststate - #check md5 collision files mkdir md5coll cp "$testscriptsdir/md5collisions/"*.ps md5coll sync #make sure nothing happens when using sha -$rdfind -checksum sha1 -deleteduplicates true md5coll 2>&1 |tee rdfind.out +$rdfind -checksum sha1 -deleteduplicates true md5coll 2>&1 | tee rdfind.out grep -q "^Deleted 0 files.$" rdfind.out dbgecho "using sha1 did not delete any files, as expected" -$rdfind -checksum md5 -deleteduplicates true md5coll 2>&1 |tee rdfind.out +$rdfind -checksum md5 -deleteduplicates true md5coll 2>&1 | tee rdfind.out grep -q "^Deleted 1 files.$" rdfind.out dbgecho "using md5 did delete files, as expected" - dbgecho "all is good in this test!" diff --git a/testcases/sha1collisions.sh b/testcases/sha1collisions.sh index fa7aa9a..3c1b817 100755 --- a/testcases/sha1collisions.sh +++ b/testcases/sha1collisions.sh @@ -1,24 +1,21 @@ #!/bin/sh # Test for sha1 vs sha256 - set -e . "$(dirname "$0")/common_funcs.sh" - reset_teststate #unpack collisions example from https://shattered.it/static/shattered.pdf base64 --decode <"$testscriptsdir/sha1collisions/coll.tar.bz2.b64" | tar xvfj - #make sure nothing happens when using sha256 -$rdfind -checksum sha256 -deleteduplicates true . 2>&1 |tee rdfind.out +$rdfind -checksum sha256 -deleteduplicates true . 2>&1 | tee rdfind.out grep -q "^Deleted 0 files.$" rdfind.out dbgecho "using sha256 did not delete any files, as expected" -$rdfind -checksum sha1 -deleteduplicates true . 2>&1 |tee rdfind.out +$rdfind -checksum sha1 -deleteduplicates true . 2>&1 | tee rdfind.out grep -q "^Deleted 1 files.$" rdfind.out dbgecho "using sha1 did delete the files, as expected" - dbgecho "all is good in this test!" diff --git a/testcases/symlinking_action.sh b/testcases/symlinking_action.sh index 05103b7..6f0ad0e 100755 --- a/testcases/symlinking_action.sh +++ b/testcases/symlinking_action.sh @@ -2,7 +2,6 @@ # Investigate what happen when symlinking fails. # - set -e . "$(dirname "$0")/common_funcs.sh" @@ -10,9 +9,9 @@ reset_teststate #make identical files. files="first subdir/b c some/deeply/nested/subdir/d" -for n in $files ; do - mkdir -p "$(dirname "$datadir/$n")" - echo "hello symlink" > "$datadir/$n" +for n in $files; do + mkdir -p "$(dirname "$datadir/$n")" + echo "hello symlink" >"$datadir/$n" done #eliminate them. @@ -21,25 +20,25 @@ $rdfind -makesymlinks true "$datadir/first" "$datadir/" #make sure the first one is untouched (it has the highest rank), and the rest are symlinks. export LANG= -for n in $files ; do - if [ "$n" = "first" ]; then - inodeforfirst=$(stat -c %i "$datadir/first") - if [ x"$(stat -c %F "$datadir/first")" != x"regular file" ] ; then - dbgecho "expected first to be a regular file" - exit 1 - fi - else - if [ x"$(stat -c %F "$datadir/$n")" != x"symbolic link" ] ; then - dbgecho "expected file $n to be a symbolic link" - exit 1 - fi - inodeforn=$(stat --dereference -c %i "$datadir/$n") - if [ "$inodeforfirst" != "$inodeforn" ] ; then - dbgecho "$n does not refer to first - inode mismatch $inodeforfirst vs $inodeforn" - exit 1 - fi - - fi +for n in $files; do + if [ "$n" = "first" ]; then + inodeforfirst=$(stat -c %i "$datadir/first") + if [ x"$(stat -c %F "$datadir/first")" != x"regular file" ]; then + dbgecho "expected first to be a regular file" + exit 1 + fi + else + if [ x"$(stat -c %F "$datadir/$n")" != x"symbolic link" ]; then + dbgecho "expected file $n to be a symbolic link" + exit 1 + fi + inodeforn=$(stat --dereference -c %i "$datadir/$n") + if [ "$inodeforfirst" != "$inodeforn" ]; then + dbgecho "$n does not refer to first - inode mismatch $inodeforfirst vs $inodeforn" + exit 1 + fi + + fi done dbgecho passed the happy path @@ -47,29 +46,29 @@ dbgecho passed the happy path reset_teststate mkdir -p "$datadir/readonly.d/" -echo xxx > "$datadir/readonly.d/a" -echo xxx > "$datadir/readonly.d/b" +echo xxx >"$datadir/readonly.d/a" +echo xxx >"$datadir/readonly.d/b" chmod 500 "$datadir/readonly.d/" if [ "$(id -u)" -eq 0 ]; then - # if running as root, directory rights are not respected. drop the capability - # for doing that (requires capsh from package libcap2-bin) - MAYBEDROP="capsh --drop=CAP_DAC_OVERRIDE -- -c" + # if running as root, directory rights are not respected. drop the capability + # for doing that (requires capsh from package libcap2-bin) + MAYBEDROP="capsh --drop=CAP_DAC_OVERRIDE -- -c" else - MAYBEDROP="/bin/sh -c" + MAYBEDROP="/bin/sh -c" fi -$MAYBEDROP "$rdfind -makesymlinks true $datadir/readonly.d/" 2>&1 |tee rdfind.out -if ! grep -iq "failed" rdfind.out ; then - dbgecho "expected failure when trying to make symlink on readonly directory" - exit 1 +$MAYBEDROP "$rdfind -makesymlinks true $datadir/readonly.d/" 2>&1 | tee rdfind.out +if ! grep -iq "failed" rdfind.out; then + dbgecho "expected failure when trying to make symlink on readonly directory" + exit 1 fi # make sure that our own copy is still there -for f in a b ; do - if [ ! -e "$datadir/readonly.d/$f" ] ; then - dbgecho "file $f is missing, rdfind should not have removed it!" - exit 1 - fi +for f in a b; do + if [ ! -e "$datadir/readonly.d/$f" ]; then + dbgecho "file $f is missing, rdfind should not have removed it!" + exit 1 + fi done # make sure it can be cleaned up @@ -77,46 +76,44 @@ chmod 700 "$datadir/readonly.d/" dbgecho "passed the test with trying to write to a readonly directory" - - #This test tries to provoke errors in relative paths, path simplification # etc. # argument 1 is path to file 1. argument 2 is path to file 2. pathsimplification() { - reset_teststate - mkdir -p "$(dirname "$1")" && echo "simplification test" >"$1" - mkdir -p "$(dirname "$2")" && echo "simplification test" >"$2" - - #dbgecho "state before (args $1 $2)" - #tree - - $rdfind -makesymlinks true "$1" "$2" 2>&1 |tee rdfind.out - # $2 should be a symlink to $1 - if [ x"$(stat -c %F "$1")" != x"regular file" ] ; then - dbgecho "expected file $1 to be a regular file" - exit 1 - fi - if [ x"$(stat -c %F "$2")" != x"symbolic link" ] ; then - dbgecho "expected file $1 to be a symbolic link" - exit 1 - fi - inodefor1=$(stat -c %i "$1") - inodefor2=$(stat --dereference -c %i "$2") - if [ "$inodefor1" != "$inodefor2" ] ; then - dbgecho "inode mismatch $inodefor1 vs $inodefor2" - exit 1 - fi - #switching directory should still give the correct answer - cd "$(dirname "$2")" - inodefor2="$(stat --dereference -c %i "$(basename "$2")")" - if [ "$inodefor1" != "$inodefor2" ] ; then - dbgecho "inode mismatch $inodefor1 vs $inodefor2" - exit 1 - fi - #dbgecho "state after $1 $2" - #sync - #tree - echo ----------------------------------------------------------- + reset_teststate + mkdir -p "$(dirname "$1")" && echo "simplification test" >"$1" + mkdir -p "$(dirname "$2")" && echo "simplification test" >"$2" + + #dbgecho "state before (args $1 $2)" + #tree + + $rdfind -makesymlinks true "$1" "$2" 2>&1 | tee rdfind.out + # $2 should be a symlink to $1 + if [ x"$(stat -c %F "$1")" != x"regular file" ]; then + dbgecho "expected file $1 to be a regular file" + exit 1 + fi + if [ x"$(stat -c %F "$2")" != x"symbolic link" ]; then + dbgecho "expected file $1 to be a symbolic link" + exit 1 + fi + inodefor1=$(stat -c %i "$1") + inodefor2=$(stat --dereference -c %i "$2") + if [ "$inodefor1" != "$inodefor2" ]; then + dbgecho "inode mismatch $inodefor1 vs $inodefor2" + exit 1 + fi + #switching directory should still give the correct answer + cd "$(dirname "$2")" + inodefor2="$(stat --dereference -c %i "$(basename "$2")")" + if [ "$inodefor1" != "$inodefor2" ]; then + dbgecho "inode mismatch $inodefor1 vs $inodefor2" + exit 1 + fi + #dbgecho "state after $1 $2" + #sync + #tree + echo ----------------------------------------------------------- } pathsimplification a b diff --git a/testcases/verify_deterministic_operation.sh b/testcases/verify_deterministic_operation.sh index e8c1a4c..a894912 100755 --- a/testcases/verify_deterministic_operation.sh +++ b/testcases/verify_deterministic_operation.sh @@ -2,25 +2,24 @@ # Ensures that the deterministic flag works as intended. # - set -e . "$(dirname "$0")/common_funcs.sh" -if $hasdisorderfs ; then - echo "$me: found a working disorderfs setup. unit test will be properly executed" +if $hasdisorderfs; then + echo "$me: found a working disorderfs setup. unit test will be properly executed" else - echo "$me: please install disorderfs to execute this test properly!" - echo "$me: falsely exiting with success now" - exit 0 + echo "$me: please install disorderfs to execute this test properly!" + echo "$me: falsely exiting with success now" + exit 0 fi #unmount disordered unmount_disordered() { - if [ -d "$DISORDERED_MNT" ]; then - if ! fusermount --quiet -u "$DISORDERED_MNT" ; then - dbgecho "failed unmounting disordered" - fi - fi + if [ -d "$DISORDERED_MNT" ]; then + if ! fusermount --quiet -u "$DISORDERED_MNT"; then + dbgecho "failed unmounting disordered" + fi + fi } DISORDERED_FLAGS_RANDOM="--shuffle-dirents=yes --sort-dirents=no --reverse-dirents=no" @@ -28,41 +27,41 @@ DISORDERED_FLAGS_ASC="--shuffle-dirents=no --sort-dirents=yes --reverse-dirents= DISORDERED_FLAGS_DESC="--shuffle-dirents=no --sort-dirents=yes --reverse-dirents=yes" DISORDERED_FLAGS=$DISORDERED_FLAGS_RANDOM mount_disordered() { - mkdir -p "$DISORDERED_MNT" - mkdir -p "$DISORDERED_ROOT" - # shellcheck disable=SC2086 - disorderfs $DISORDERED_FLAGS "$DISORDERED_ROOT" "$DISORDERED_MNT" >/dev/null + mkdir -p "$DISORDERED_MNT" + mkdir -p "$DISORDERED_ROOT" + # shellcheck disable=SC2086 + disorderfs $DISORDERED_FLAGS "$DISORDERED_ROOT" "$DISORDERED_MNT" >/dev/null } #create cr8() { - while [ $# -gt 0 ] ; do - mkdir -p "$(dirname "$1")" - # make sure the file is longer than what fits in the byte buffer - head -c1000 /dev/zero >"$1" - shift - done + while [ $# -gt 0 ]; do + mkdir -p "$(dirname "$1")" + # make sure the file is longer than what fits in the byte buffer + head -c1000 /dev/zero >"$1" + shift + done } local_reset() { - unmount_disordered - reset_teststate - mount_disordered - cr8 "$@" + unmount_disordered + reset_teststate + mount_disordered + cr8 "$@" } #sets global variable outcome to which file was preserved, a or b. #$1 - value of -deterministic flag (true or false) run_outcome() { - local_reset "$DISORDERED_MNT/a" "$DISORDERED_MNT/b" - $rdfind -deterministic "$1" -deleteduplicates true "$DISORDERED_MNT" >rdfind.out - if [ -f "$DISORDERED_MNT/a" ] && [ ! -e "$DISORDERED_MNT/b" ] ; then - outcome=a - elif [ ! -e "$DISORDERED_MNT/a" ] && [ -f "$DISORDERED_MNT/b" ] ; then - outcome=b - else - dbgecho "bad result! test failed!" - exit 1 - fi + local_reset "$DISORDERED_MNT/a" "$DISORDERED_MNT/b" + $rdfind -deterministic "$1" -deleteduplicates true "$DISORDERED_MNT" >rdfind.out + if [ -f "$DISORDERED_MNT/a" ] && [ ! -e "$DISORDERED_MNT/b" ]; then + outcome=a + elif [ ! -e "$DISORDERED_MNT/a" ] && [ -f "$DISORDERED_MNT/b" ]; then + outcome=b + else + dbgecho "bad result! test failed!" + exit 1 + fi } trap "unmount_disordered;cleanup" INT QUIT EXIT @@ -76,9 +75,9 @@ DISORDERED_FLAGS=$DISORDERED_FLAGS_DESC run_outcome false outcome_desc=$outcome -if [ $outcome_desc = $outcome_asc ] ; then - dbgecho "fail! \"-deterministic false\" should have given the same outcome regardless of ordering" - exit 1 +if [ $outcome_desc = $outcome_asc ]; then + dbgecho "fail! \"-deterministic false\" should have given the same outcome regardless of ordering" + exit 1 fi dbgecho "tests for deterministic false passed ok (non-randomized)" @@ -88,24 +87,23 @@ dbgecho "tests for deterministic false passed ok (non-randomized)" DISORDERED_FLAGS=$DISORDERED_FLAGS_RANDOM run_outcome false last_outcome="$outcome" -for i in $(seq 128) ; do - run_outcome false - if [ "$last_outcome" != "$outcome" ] ; then - #proved that both outcomes can happen. good! - dbgecho "got a different outcome after $i random tries" - break - else - if [ "$i" -eq 64 ] ; then - dbgecho "reached max number of iterations without getting different results". - exit 1 - fi - fi - last_outcome=$outcome +for i in $(seq 128); do + run_outcome false + if [ "$last_outcome" != "$outcome" ]; then + #proved that both outcomes can happen. good! + dbgecho "got a different outcome after $i random tries" + break + else + if [ "$i" -eq 64 ]; then + dbgecho "reached max number of iterations without getting different results". + exit 1 + fi + fi + last_outcome=$outcome done dbgecho "tests for \"-deterministic false\" passed ok on randomized filesystem order" - #verify that with deterministic enabled, we get the same results regardless of ordering DISORDERED_FLAGS=$DISORDERED_FLAGS_ASC run_outcome true @@ -115,13 +113,10 @@ DISORDERED_FLAGS=$DISORDERED_FLAGS_DESC run_outcome true outcome_desc=$outcome -if [ $outcome_desc != $outcome_asc ] ; then - dbgecho "fail! \"-deterministic true\" should have given the same outcome regardless of ordering" - exit 1 +if [ $outcome_desc != $outcome_asc ]; then + dbgecho "fail! \"-deterministic true\" should have given the same outcome regardless of ordering" + exit 1 fi dbgecho "tests for deterministic true passed ok" - - - dbgecho "all is good for the ranking tests!" diff --git a/testcases/verify_dryrun_option.sh b/testcases/verify_dryrun_option.sh index 73712d3..4b2d7e2 100755 --- a/testcases/verify_dryrun_option.sh +++ b/testcases/verify_dryrun_option.sh @@ -2,99 +2,94 @@ # Ensures that dryrun does not modify anything # - set -e . "$(dirname "$0")/common_funcs.sh" local_reset() { - reset_teststate - echo "dryrun" >a - echo "dryrun" >b + reset_teststate + echo "dryrun" >a + echo "dryrun" >b } -for dryrunopt in -dryrun -n ; do - local_reset - $rdfind $dryrunopt true -deleteduplicates true a b >rdfind.out - [ -f a ] - [ -f b ] - dbgecho "files still there, good" - - local_reset - $rdfind $dryrunopt false -deleteduplicates true a b >rdfind.out - [ -f a ] - [ ! -e b ] - dbgecho "b was removed, good" - - - local_reset - $rdfind $dryrunopt true -makesymlinks true a b >rdfind.out - [ -f a ] - [ -f b ] - [ "$(stat -c %i a)" != "$(stat --dereference -c %i b)" ] - dbgecho "files still there, good" - $rdfind $dryrunopt false -makesymlinks true a b >rdfind.out - [ -f a ] - [ -L b ] - [ "$(stat -c %i a)" = "$(stat --dereference -c %i b)" ] - dbgecho "b was replaced with a symlink, good" - +for dryrunopt in -dryrun -n; do + local_reset + $rdfind $dryrunopt true -deleteduplicates true a b >rdfind.out + [ -f a ] + [ -f b ] + dbgecho "files still there, good" + local_reset + $rdfind $dryrunopt false -deleteduplicates true a b >rdfind.out + [ -f a ] + [ ! -e b ] + dbgecho "b was removed, good" - local_reset - $rdfind $dryrunopt true -makehardlinks true a b >rdfind.out - [ -f a ] - [ -f b ] - [ "$(stat -c %i a)" != "$(stat -c %i b)" ] - [ "$(stat -c %h a)" -eq 1 ] - dbgecho "files still there, good" - $rdfind $dryrunopt false -makehardlinks true a b >rdfind.out - [ -f a ] - [ -f b ] - [ "$(stat -c %i a)" = "$(stat -c %i b)" ] - [ "$(stat -c %h a)" -eq 2 ] - [ "$(stat -c %h b)" -eq 2 ] - dbgecho "b was replaced with a hard link, good" + local_reset + $rdfind $dryrunopt true -makesymlinks true a b >rdfind.out + [ -f a ] + [ -f b ] + [ "$(stat -c %i a)" != "$(stat --dereference -c %i b)" ] + dbgecho "files still there, good" + $rdfind $dryrunopt false -makesymlinks true a b >rdfind.out + [ -f a ] + [ -L b ] + [ "$(stat -c %i a)" = "$(stat --dereference -c %i b)" ] + dbgecho "b was replaced with a symlink, good" + local_reset + $rdfind $dryrunopt true -makehardlinks true a b >rdfind.out + [ -f a ] + [ -f b ] + [ "$(stat -c %i a)" != "$(stat -c %i b)" ] + [ "$(stat -c %h a)" -eq 1 ] + dbgecho "files still there, good" + $rdfind $dryrunopt false -makehardlinks true a b >rdfind.out + [ -f a ] + [ -f b ] + [ "$(stat -c %i a)" = "$(stat -c %i b)" ] + [ "$(stat -c %h a)" -eq 2 ] + [ "$(stat -c %h b)" -eq 2 ] + dbgecho "b was replaced with a hard link, good" - #make sure users who forget the boolean argument after - #dryrun get something comprehensible. see https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=754663 - local_reset - if $rdfind $dryrunopt a b >rdfind.out 2>&1 ; then - dbgecho "this should have failed, but did not!" - exit 1 - fi - dbgecho "rdfind exited with error status after \"rdfind $dryrunopt a b\", good." - if ! grep -iq "^expected true or false after $dryrunopt" rdfind.out ; then - dbgecho "got unexpected response after \"rdfind $dryrunopt a b\":" - tail rdfind.out - exit 1 - fi + #make sure users who forget the boolean argument after + #dryrun get something comprehensible. see https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=754663 + local_reset + if $rdfind $dryrunopt a b >rdfind.out 2>&1; then + dbgecho "this should have failed, but did not!" + exit 1 + fi + dbgecho "rdfind exited with error status after \"rdfind $dryrunopt a b\", good." + if ! grep -iq "^expected true or false after $dryrunopt" rdfind.out; then + dbgecho "got unexpected response after \"rdfind $dryrunopt a b\":" + tail rdfind.out + exit 1 + fi - #dryrun on it's own: "rdfind -dryrun" - local_reset - if $rdfind $dryrunopt >rdfind.out 2>&1 ; then - dbgecho "this should have failed, but did not!" - exit 1 - fi - dbgecho "rdfind exited with error status after \"rdfind $dryrunopt\", good." - if grep -iq "^did not understand option 1:" rdfind.out ; then - dbgecho "got the old non-helpful answer:" - tail rdfind.out - exit 1 - fi + #dryrun on it's own: "rdfind -dryrun" + local_reset + if $rdfind $dryrunopt >rdfind.out 2>&1; then + dbgecho "this should have failed, but did not!" + exit 1 + fi + dbgecho "rdfind exited with error status after \"rdfind $dryrunopt\", good." + if grep -iq "^did not understand option 1:" rdfind.out; then + dbgecho "got the old non-helpful answer:" + tail rdfind.out + exit 1 + fi - #dryrun with single argument: "rdfind -dryrun ." - local_reset - if $rdfind $dryrunopt a >rdfind.out 2>&1 ; then - dbgecho "this should have failed, but did not!" - exit 1 - fi - dbgecho "rdfind exited with error status after \"rdfind $dryrunopt\", good." - if grep -iq "^did not understand option 1:" rdfind.out ; then - dbgecho "got the old non-helpful answer:" - tail rdfind.out - exit 1 - fi + #dryrun with single argument: "rdfind -dryrun ." + local_reset + if $rdfind $dryrunopt a >rdfind.out 2>&1; then + dbgecho "this should have failed, but did not!" + exit 1 + fi + dbgecho "rdfind exited with error status after \"rdfind $dryrunopt\", good." + if grep -iq "^did not understand option 1:" rdfind.out; then + dbgecho "got the old non-helpful answer:" + tail rdfind.out + exit 1 + fi done dbgecho "all is good for the dryrun tests!" diff --git a/testcases/verify_filesize_option.sh b/testcases/verify_filesize_option.sh index 6743c62..e2b9c42 100755 --- a/testcases/verify_filesize_option.sh +++ b/testcases/verify_filesize_option.sh @@ -2,19 +2,17 @@ # Ensures the exclusion of empty files work as intended. # - set -e . "$(dirname "$0")/common_funcs.sh" #make pairs of files, with specific sizes makefiles() { - for i in $(seq 0 4) ; do - head -c"$i" /dev/zero >"a$i" - head -c"$i" /dev/zero >"b$i" - done + for i in $(seq 0 4); do + head -c"$i" /dev/zero >"a$i" + head -c"$i" /dev/zero >"b$i" + done } - reset_teststate makefiles @@ -22,9 +20,9 @@ makefiles $rdfind -ignoreempty true -deleteduplicates true a* b* verify [ -e "a0" ] verify [ -e "b0" ] -for i in $(seq 1 4) ; do - verify [ -e "a$i" ] - verify [ ! -e "b$i" ] +for i in $(seq 1 4); do + verify [ -e "a$i" ] + verify [ ! -e "b$i" ] done dbgecho "passed ignoreempty true test case" @@ -35,60 +33,48 @@ makefiles $rdfind -ignoreempty false -deleteduplicates true a* b* verify [ -e a0 ] verify [ ! -e b0 ] -for i in $(seq 1 4) ; do - verify [ -e "a$i" ] - verify [ ! -e "b$i" ] +for i in $(seq 1 4); do + verify [ -e "a$i" ] + verify [ ! -e "b$i" ] done dbgecho "passed ignoreempty false test case" - - reset_teststate makefiles $rdfind -minsize 0 -deleteduplicates true a* b* verify [ -e a0 ] verify [ ! -e b0 ] -for i in $(seq 1 4) ; do - verify [ -e "a$i" ] - verify [ ! -e "b$i" ] +for i in $(seq 1 4); do + verify [ -e "a$i" ] + verify [ ! -e "b$i" ] done dbgecho "passed -minsize 0 test case" - reset_teststate makefiles $rdfind -minsize 1 -deleteduplicates true a* b* verify [ -e a0 ] verify [ -e b0 ] -for i in $(seq 1 4) ; do - verify [ -e "a$i" ] - verify [ ! -e "b$i" ] +for i in $(seq 1 4); do + verify [ -e "a$i" ] + verify [ ! -e "b$i" ] done dbgecho "passed -minsize 1 test case" - - - -for cutoff in $(seq 0 4) ; do - reset_teststate - makefiles - $rdfind -minsize "$cutoff" -deleteduplicates true a* b* - for i in $(seq 0 4) ; do - verify [ -e "a$i" ] - if [ "$i" -lt "$cutoff" ] ; then - verify [ -e "b$i" ] - else - verify [ ! -e "b$i" ] - fi - done - dbgecho "passed -minsize $cutoff test case" +for cutoff in $(seq 0 4); do + reset_teststate + makefiles + $rdfind -minsize "$cutoff" -deleteduplicates true a* b* + for i in $(seq 0 4); do + verify [ -e "a$i" ] + if [ "$i" -lt "$cutoff" ]; then + verify [ -e "b$i" ] + else + verify [ ! -e "b$i" ] + fi + done + dbgecho "passed -minsize $cutoff test case" done - - - - - - dbgecho "all is good for the min filesize test!" diff --git a/testcases/verify_maxfilesize_option.sh b/testcases/verify_maxfilesize_option.sh index 033161d..6850fce 100755 --- a/testcases/verify_maxfilesize_option.sh +++ b/testcases/verify_maxfilesize_option.sh @@ -2,40 +2,35 @@ # Ensures the exclusion of empty files work as intended. # - set -e . "$(dirname "$0")/common_funcs.sh" - - makefiles() { - #make pairs of files, with specific sizes - for i in $(seq 0 4) ; do - head -c"$i" /dev/zero >"a$i" - head -c"$i" /dev/zero >"b$i" - done + #make pairs of files, with specific sizes + for i in $(seq 0 4); do + head -c"$i" /dev/zero >"a$i" + head -c"$i" /dev/zero >"b$i" + done } - #negative value should be reported as misusage reset_teststate makefiles -if $rdfind -deleteduplicates true -maxsize -1 a* b* ; then - dbgecho "negative value should have been detected" - exit 1 +if $rdfind -deleteduplicates true -maxsize -1 a* b*; then + dbgecho "negative value should have been detected" + exit 1 fi dbgecho "passed negative value test" #conflict between min and max should be reported as misusage reset_teststate makefiles -if $rdfind -deleteduplicates true -minsize 123 -maxsize 123 a* b* ; then - dbgecho "conflicting values should have been detected" - exit 1 +if $rdfind -deleteduplicates true -minsize 123 -maxsize 123 a* b*; then + dbgecho "conflicting values should have been detected" + exit 1 fi dbgecho "passed conflicting value test" - reset_teststate makefiles #try eliminate them, but they are correctly ignored. @@ -43,11 +38,10 @@ $rdfind -deleteduplicates true -minsize 2 -maxsize 3 a* b* verify [ -e a2 ] verify [ ! -e b2 ] for i in $(seq 0 1) $(seq 3 4); do - verify [ -e "a$i" ] - verify [ -e "b$i" ] + verify [ -e "a$i" ] + verify [ -e "b$i" ] done dbgecho "passed specific size test" - dbgecho "all is good for the max filesize test!" diff --git a/testcases/verify_ranking.sh b/testcases/verify_ranking.sh index daf78c7..8ed1027 100755 --- a/testcases/verify_ranking.sh +++ b/testcases/verify_ranking.sh @@ -3,54 +3,52 @@ # Ensures that ranking works as intended. # - set -e . "$(dirname "$0")/common_funcs.sh" #unmount disordered unmount_disordered() { - if ! $hasdisorderfs ; then - return - fi - if [ -d "$DISORDERED_MNT" ]; then - if ! fusermount --quiet -z -u "$DISORDERED_MNT" ; then - dbgecho failed unmounting disordered - fi - fi + if ! $hasdisorderfs; then + return + fi + if [ -d "$DISORDERED_MNT" ]; then + if ! fusermount --quiet -z -u "$DISORDERED_MNT"; then + dbgecho failed unmounting disordered + fi + fi } mount_disordered() { - mkdir -p "$DISORDERED_MNT" "$DISORDERED_ROOT" - if ! $hasdisorderfs; then - return - fi - disorderfs --sort-dirents=yes --reverse-dirents=no "$DISORDERED_ROOT" "$DISORDERED_MNT" >/dev/null + mkdir -p "$DISORDERED_MNT" "$DISORDERED_ROOT" + if ! $hasdisorderfs; then + return + fi + disorderfs --sort-dirents=yes --reverse-dirents=no "$DISORDERED_ROOT" "$DISORDERED_MNT" >/dev/null } #create cr8() { - while [ $# -gt 0 ] ; do - mkdir -p "$(dirname "$1")" - # make sure the file is longer than what fits in the byte buffer - head -c1000 /dev/zero >"$1" - shift - done + while [ $# -gt 0 ]; do + mkdir -p "$(dirname "$1")" + # make sure the file is longer than what fits in the byte buffer + head -c1000 /dev/zero >"$1" + shift + done } local_reset() { - unmount_disordered - reset_teststate - mount_disordered - cr8 "$@" + unmount_disordered + reset_teststate + mount_disordered + cr8 "$@" } - #enforce the rules form RANKING in the man page. -if $hasdisorderfs ; then - echo "$me: found a working disorderfs setup. unit test will be properly executed" +if $hasdisorderfs; then + echo "$me: found a working disorderfs setup. unit test will be properly executed" else - echo "$me: no working disorderfs setup, unit test will be partially executed" + echo "$me: no working disorderfs setup, unit test will be partially executed" fi trap "unmount_disordered;cleanup" INT QUIT EXIT @@ -86,7 +84,7 @@ $rdfind -deleteduplicates true sd0 >rdfind.out [ ! -e sd0/sd1/sd2/a ] local_reset sd0/a sd0/sd1/b0 sd0/sd1/b1 sd0/sd1/sd2/c -$rdfind -deleteduplicates true sd0>rdfind.out +$rdfind -deleteduplicates true sd0 >rdfind.out [ -f sd0/a ] [ ! -e sd0/sd1/sd2/a ] @@ -95,21 +93,21 @@ dbgecho "tests for rule 2 passed ok" #Rule 3: If A was found earlier than B, A is higher ranked. #We will have to test this using a tool from the reproducible builds project. #apt install disorderfs, and make sure you are member of the fuse group. -if $hasdisorderfs ; then - - local_reset "$DISORDERED_MNT/a" "$DISORDERED_MNT/b" - $rdfind -deleteduplicates true "$DISORDERED_MNT" >rdfind.out - [ -f "$DISORDERED_MNT/a" ] - [ ! -e "$DISORDERED_MNT/b" ] - dbgecho "tests for rule 3 passed ok" - - local_reset "$DISORDERED_MNT/b" "$DISORDERED_MNT/a" - $rdfind -deleteduplicates true "$DISORDERED_MNT" >rdfind.out - [ -f "$DISORDERED_MNT/a" ] - [ ! -e "$DISORDERED_MNT/b" ] - dbgecho "tests for rule 3 passed ok" +if $hasdisorderfs; then + + local_reset "$DISORDERED_MNT/a" "$DISORDERED_MNT/b" + $rdfind -deleteduplicates true "$DISORDERED_MNT" >rdfind.out + [ -f "$DISORDERED_MNT/a" ] + [ ! -e "$DISORDERED_MNT/b" ] + dbgecho "tests for rule 3 passed ok" + + local_reset "$DISORDERED_MNT/b" "$DISORDERED_MNT/a" + $rdfind -deleteduplicates true "$DISORDERED_MNT" >rdfind.out + [ -f "$DISORDERED_MNT/a" ] + [ ! -e "$DISORDERED_MNT/b" ] + dbgecho "tests for rule 3 passed ok" else - dbgecho "could not execute tests for rule 3 - please install disorderfs" + dbgecho "could not execute tests for rule 3 - please install disorderfs" fi dbgecho "all is good for the ranking tests!"