File: verify_deterministic_operation.sh

package info (click to toggle)
rdfind 1.4.1-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster, sid
  • size: 648 kB
  • sloc: cpp: 1,670; sh: 1,622; makefile: 32
file content (132 lines) | stat: -rwxr-xr-x 3,436 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
#!/bin/sh
# Ensures that the deterministic flag works as intended.
#


set -e
. "$(dirname "$0")/common_funcs.sh"


DISORDERED_MNT=$datadir/disordered_mnt
DISORDERED_ROOT=$datadir/disordered_root

#unmount disordered
unmount_disordered() {
  if [ -d $DISORDERED_MNT ]; then
    if ! fusermount -u $DISORDERED_MNT ; then
      dbgecho failed unmounting disordered
    fi	
  fi
}

DISORDERED_FLAGS_RANDOM="--shuffle-dirents=yes --sort-dirents=no --reverse-dirents=no"
DISORDERED_FLAGS_ASC="--shuffle-dirents=no --sort-dirents=yes --reverse-dirents=no"
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
  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
}
local_reset() {
  if which disorderfs >/dev/null ; then
    unmount_disordered
    reset_teststate
    mount_disordered
  else
    reset_teststate
  fi
  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 -a ! -e $DISORDERED_MNT/b ] ; then
    outcome=a
  elif  [ ! -e $DISORDERED_MNT/a -a -f $DISORDERED_MNT/b ] ; then
    outcome=b
  else
    dbgecho "bad result! test failed!"
    exit 1
  fi
}


if ! which disorderfs >/dev/null ; then
  dbgecho "could not execute tests for deterministic behaviour - please install disorderfs"
  exit 0
fi

trap "unmount_disordered;cleanup" INT QUIT EXIT

#verify that with deterministic disabled, results depend on ordering.
DISORDERED_FLAGS=$DISORDERED_FLAGS_ASC
run_outcome false
outcome_asc=$outcome

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
fi

dbgecho "tests for deterministic false passed ok (non-randomized)"

#verify that with deterministic ordering off, we may get different results
#depending on the output from the file system
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!
    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 determinstic enabled, we get the same results regardless of ordering
DISORDERED_FLAGS=$DISORDERED_FLAGS_ASC
run_outcome true
outcome_asc=$outcome

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
fi
dbgecho "tests for deterministic true passed ok"




dbgecho "all is good for the ranking tests!"