xref: /minix/minix/tests/fbdtest/test.sh (revision 7f5f010b)
1#!/bin/sh
2
3# This test set tests the some of the basic functionality of the Faulty Block
4# Device driver. It takes a writable device as input - a small (sub)partition
5# suffices for this purpose. All information on the given device WILL BE LOST,
6# so USE AT YOUR OWN RISK.
7#
8# Currently, a reasonable subset of supported read and write fault injection is
9# tested. Since injection of write faults was the original goal for this
10# driver, the test set for this part of FBD functionality is relatively large.
11#
12# Testing of read faults works as follows. First, a known pattern is written to
13# the actual device. Then FBD is loaded as an overlay over the device. A fault
14# injection rule is set on FBD, and the disk pattern is read back from the FBD
15# device (/dev/fbd). FBD is then unloaded. The test succeeds if the pattern
16# that was read back, matches a certain expected pattern.
17#
18# Testing of write faults works as follows. First, a known pattern is written
19# to the actual device. Then FBD is loaded as an overlay over the device. A
20# fault injection rule is set on FBD, and another pattern is written to the FBD
21# device (/dev/fbd). FBD is unloaded, and the resulting disk pattern is read
22# back from the actual device. This resulting pattern should match a certain
23# expected pattern.
24#
25# Since all raw block I/O requests go through the root file server, this test
26# set heavily depends on the behavior of that root file server. It has been
27# tested with MFS, and may not work with any other file server type. It assumes
28# that a 4K block size is used, and that the file server translates raw block
29# requests to aligned 4K-multiples. The test set also makes assumptions about
30# merging pages in write operations, flushing only upon a sync call, etcetera.
31# Unfortunately, this dependency on the root file server precludes the test set
32# from properly exercising all possible options of FBD.
33
34RWBLOCKS=./rwblocks
35
36devtopair() {
37  label=`awk "/^$(stat -f '%Hr' $1) / "'{print $2}' /proc/dmap`
38  if [ ! -z "$label" ]; then echo "label=$label,minor=`stat -f '%Lr' $1`"; fi
39}
40
41if [ ! -b "$1" ]; then
42  echo "usage: $0 device" >&2
43  exit 1
44fi
45
46PAIR=$(devtopair $1)
47if [ -z "$PAIR" ]; then
48  echo "driver not found for $1" >&2
49  exit 1
50fi
51
52if [ ! -x $RWBLOCKS ]; then
53  make || exit 1
54fi
55
56if [ "`stat -f '%k' /`" != "4096" ]; then
57  echo "The root file system is not using a 4K block size." >&2
58  exit 1
59fi
60
61read -p "This will overwrite the contents of $1. Are you sure? [y/N] " RESP
62case $RESP in
63  [yY]*)
64    ;;
65  *)
66    echo "Hmpf. Okay. Aborting test.."
67    exit 0
68esac
69
70DEV="$1"
71LAST=
72SUCCESS=0
73TOTAL=0
74
75read_test() {
76  OPT=
77  if [ "$1" = "-last" -o "$1" = "-notlast" ]; then
78    OPT=$1
79    shift
80  fi
81  PAT=$1
82  EXP=$2
83  shift 2
84  $RWBLOCKS $DEV $PAT
85  service up /service/fbd -dev /dev/fbd -args "$PAIR" || exit 1
86  fbdctl add $@ >/dev/null
87  #fbdctl list
88  RES="`$RWBLOCKS /dev/fbd`"
89  service down fbd
90  echo -n "$RES: "
91  if echo "$RES" | egrep "^$EXP\$" >/dev/null 2>&1; then
92    if [ "$OPT" = "-last" -a "$RES" != "$LAST" ]; then
93      echo FAILURE
94    elif [ "$OPT" = "-notlast" -a "$RES" = "$LAST" ]; then
95      echo FAILURE
96    else
97      echo SUCCESS
98      SUCCESS=`expr $SUCCESS + 1`
99      LAST="$RES"
100    fi
101  else
102    echo FAILURE
103  fi
104  TOTAL=`expr $TOTAL + 1`
105}
106
107write_test() {
108  OPT=
109  if [ "$1" = "-last" -o "$1" = "-notlast" ]; then
110    OPT=$1
111    shift
112  fi
113  PAT=$1
114  EXP=$2
115  WS=$3
116  shift 3
117  $RWBLOCKS $DEV UUUUUUUUUUUUUUUU
118  service up /service/fbd -dev /dev/fbd -args "$PAIR" || exit 1
119  fbdctl add $@ >/dev/null
120  #fbdctl list
121  $RWBLOCKS /dev/fbd $PAT $WS
122  service down fbd
123  RES="`$RWBLOCKS $DEV`"
124  echo -n "$RES: "
125  if echo "$RES" | egrep "^$EXP\$" >/dev/null 2>&1; then
126    if [ "$OPT" = "-last" -a "$RES" != "$LAST" ]; then
127      echo FAILURE
128    elif [ "$OPT" = "-notlast" -a "$RES" = "$LAST" ]; then
129      echo FAILURE
130    else
131      echo SUCCESS
132      SUCCESS=`expr $SUCCESS + 1`
133      LAST="$RES"
134    fi
135  else
136    echo FAILURE
137  fi
138  TOTAL=`expr $TOTAL + 1`
139}
140
141read_test AAAAAAAAAAAAAAAA A0AAAAAAAAAAAAAA -a 1000-2000 -r corrupt zero
142
143read_test       AAAAAAAAAAAAAAAA 'AA[a-z][a-z]AAAAAAAAAAAA' -a 2000-4000 -r corrupt persist
144read_test -last AAAAAAAAAAAAAAAA 'AA[a-z][a-z]AAAAAAAAAAAA' -a 2000-4000 -r corrupt persist
145
146read_test          AAAAAAAAAAAAAAAA 'AAAAA[a-z][a-z][a-z]AAAAAAAA' -a 5000-8000 -r corrupt random
147read_test -notlast AAAAAAAAAAAAAAAA 'AAAAA[a-z][a-z][a-z]AAAAAAAA' -a 5000-8000 -r corrupt random
148
149read_test AAAAAAAAAAAAAAAA 'A[a-z]AAAAAAAAAAAAAA' -a 1100-1200 -r corrupt zero
150
151read_test AAAAAAAAAAAAAAAA 'AA#AAAAAAAAAAAAA' -a 2000-3000 -r error EIO
152read_test AAAAAAAAABAAABAA 'AAAAAAAAAB###BAA' -a A800-C800 -r error EIO
153
154read_test ABBBAAAAAAAAAAAA 'ABBB#' -a 4000 -r error OK
155
156write_test AAAAAAAAAAAAAAAA A0AAAAAAAAAAAAAA   512 -a 1000-2000 -w corrupt zero
157write_test AAAAAAAAAAAAAAAA A0AAAAAAAAAAAAAA  4096 -a 1000-2000 -w corrupt zero
158write_test AAAAAAAAAAAAAAAA A0AAAAAAAAAAAAAA 16384 -a 1000-2000 -w corrupt zero
159
160write_test       AAAAAAAAAAAAAAAA 'AA[a-z][a-z]AAAAAAAAAAAA'   512 -a 2000-4000 -w corrupt persist
161write_test -last AAAAAAAAAAAAAAAA 'AA[a-z][a-z]AAAAAAAAAAAA'   512 -a 2000-4000 -w corrupt persist
162write_test -last AAAAAAAAAAAAAAAA 'AA[a-z][a-z]AAAAAAAAAAAA'  4096 -a 2000-4000 -w corrupt persist
163write_test -last AAAAAAAAAAAAAAAA 'AA[a-z][a-z]AAAAAAAAAAAA'  4096 -a 2000-4000 -w corrupt persist
164write_test -last AAAAAAAAAAAAAAAA 'AA[a-z][a-z]AAAAAAAAAAAA' 16384 -a 2000-4000 -w corrupt persist
165write_test -last AAAAAAAAAAAAAAAA 'AA[a-z][a-z]AAAAAAAAAAAA' 16384 -a 2000-4000 -w corrupt persist
166
167write_test          AAAAAAAAAAAAAAAA 'AAAAA[a-z][a-z][a-z]AAAAAAAA'   512 -a 5000-8000 -w corrupt random
168write_test -notlast AAAAAAAAAAAAAAAA 'AAAAA[a-z][a-z][a-z]AAAAAAAA'   512 -a 5000-8000 -w corrupt random
169write_test -notlast AAAAAAAAAAAAAAAA 'AAAAA[a-z][a-z][a-z]AAAAAAAA'  4096 -a 5000-8000 -w corrupt random
170write_test -notlast AAAAAAAAAAAAAAAA 'AAAAA[a-z][a-z][a-z]AAAAAAAA'  4096 -a 5000-8000 -w corrupt random
171write_test -notlast AAAAAAAAAAAAAAAA 'AAAAA[a-z][a-z][a-z]AAAAAAAA' 16384 -a 5000-8000 -w corrupt random
172write_test -notlast AAAAAAAAAAAAAAAA 'AAAAA[a-z][a-z][a-z]AAAAAAAA' 16384 -a 5000-8000 -w corrupt random
173
174write_test AAAAAAAAAAAAAAAA 'A[a-z]AAAAAAAAAAAAAA'   512 -a 1100-1200 -w corrupt zero
175write_test AAAAAAAAAAAAAAAA 'A[a-z]AAAAAAAAAAAAAA'  4096 -a 1100-1200 -w corrupt zero
176write_test AAAAAAAAAAAAAAAA 'A[a-z]AAAAAAAAAAAAAA' 16384 -a 1100-1200 -w corrupt zero
177
178write_test AAAAAAAAAAAAAAAA AAAUUUUUUUUUUUUU   512 -a 3000 -w error EIO
179write_test AAAAAAAAAAAAAAAA AAAUUUUUUUUUUUUU  4096 -a 3000 -w error EIO
180write_test AAAAAAAAAAAAAAAA AAAUUUUUUUUUUUUU 16384 -a 3000 -w error EIO
181
182write_test AAAAAAAAAAAAABAA AAAAAABAAAAAAUAA        4096 -a D000-E000 -w misdir 6000-7000 4096
183write_test AAAAAAAAAAAAABAA 'AAAAAA(AB|BA)AAAAAUAA' 4096 -a D000-E000 -w misdir 6000-8000 4096
184write_test AAAAAAAAAAAAABAA 'AAAAAA(AB|BA)AAAAAUAA' 4096 -a D000-E000 -w misdir 6000-8000 4096
185write_test AAAAAAAAAAAAABAA 'AAAAAA(AB|BA)AAAAAUAA' 4096 -a D000-E000 -w misdir 6000-8000 4096
186
187write_test AAAAAAAAABAAAAAA AAAAAAAAAUAAAAAA   512 -a 9000-A000 -w lost
188write_test AAAAAAAAABAAAAAA AAAAAAAAAUAAAAAA  4096 -a 9000-A000 -w lost
189write_test AAAAAAAAABAAAAAA AAAAAAAAUUUUAAAA 16384 -a 9000-A000 -w lost
190
191write_test AAAAAAAAAAABAAAA 'AAAAAAAAAAA[a-z]AAAA'   512 -a B000-C000 -w torn 512
192write_test AAAAAAAAAAABAAAA 'AAAAAAAAAAA[a-z]AAAA'  4096 -a B000-C000 -w torn 512
193write_test AAAAAAAAAAABAAAA 'AAAAAAAA[a-z]UUUAAAA' 16384 -a B000-C000 -w torn 512
194
195write_test AAAAAAAAAAABAAAA AAAAAAAAAAABAAAA   512 -a B000-C000 -w torn 4096
196write_test AAAAAAAAAAABAAAA AAAAAAAAAAABAAAA  4096 -a B000-C000 -w torn 4096
197write_test AAAAAAAAAAABAAAA AAAAAAAAAUUUAAAA 16384 -a B000-C000 -w torn 4096
198
199echo "$SUCCESS out of $TOTAL tests succeeded."
200