xref: /aosp_15_r20/external/e2fsprogs/tests/f_mmp/script (revision 6a54128f25917bfc36a8a6e9d722c04a0b4641b6)
1*6a54128fSAndroid Build Coastguard WorkerFSCK_OPT=-yf
2*6a54128fSAndroid Build Coastguard Worker
3*6a54128fSAndroid Build Coastguard Workerecho "make the test image ..." > $test_name.log
4*6a54128fSAndroid Build Coastguard Worker$MKE2FS -q -F -o Linux -b 4096 -O mmp -E mmp_update_interval=1 $TMPFILE 100 >> $test_name.log 2>&1
5*6a54128fSAndroid Build Coastguard Workerstatus=$?
6*6a54128fSAndroid Build Coastguard Workerif [ "$status" != 0 ] ; then
7*6a54128fSAndroid Build Coastguard Worker	echo "mke2fs -O mmp failed" > $test_name.failed
8*6a54128fSAndroid Build Coastguard Worker	echo "$test_name: $test_description: failed"
9*6a54128fSAndroid Build Coastguard Worker	return $status
10*6a54128fSAndroid Build Coastguard Workerfi
11*6a54128fSAndroid Build Coastguard Worker
12*6a54128fSAndroid Build Coastguard Workerkill_debugfs() {
13*6a54128fSAndroid Build Coastguard Worker	trap 0
14*6a54128fSAndroid Build Coastguard Worker	PID=$(ps -o pid,command | grep -v grep |
15*6a54128fSAndroid Build Coastguard Worker		grep "debugfs -w $TMPFILE" | awk "{ print \$1 }")
16*6a54128fSAndroid Build Coastguard Worker	[ "x$PID" != "x" ] && kill -9 $PID
17*6a54128fSAndroid Build Coastguard Worker}
18*6a54128fSAndroid Build Coastguard Worker
19*6a54128fSAndroid Build Coastguard Worker# this will cause debugfs to create the $test_name.mark file once it has
20*6a54128fSAndroid Build Coastguard Worker# passed the MMP startup, then continue reading input until it is killed
21*6a54128fSAndroid Build Coastguard WorkerMARKFILE=$test_name.new
22*6a54128fSAndroid Build Coastguard Workerrm -f $MARKFILE
23*6a54128fSAndroid Build Coastguard Workertrap kill_debugfs EXIT
24*6a54128fSAndroid Build Coastguard Workerecho "set mmp sequence to EXT2_MMP_SEQ_FSCK..." >> $test_name.log
25*6a54128fSAndroid Build Coastguard Worker( { echo dump_mmp; echo "dump_inode <2> $MARKFILE"; cat /dev/zero; } |
26*6a54128fSAndroid Build Coastguard Worker	$DEBUGFS -w $TMPFILE >> $test_name.log 2>&1 & ) > /dev/null 2>&1 &
27*6a54128fSAndroid Build Coastguard Workerecho "wait until debugfs has started ..." >> $test_name.log
28*6a54128fSAndroid Build Coastguard Workerwhile [ ! -e $MARKFILE ]; do
29*6a54128fSAndroid Build Coastguard Worker	sleep 1
30*6a54128fSAndroid Build Coastguard Workerdone
31*6a54128fSAndroid Build Coastguard Workerrm -f $MARKFILE
32*6a54128fSAndroid Build Coastguard Workerecho "kill debugfs abruptly (simulates e2fsck failure) ..." >> $test_name.log
33*6a54128fSAndroid Build Coastguard Workerkill_debugfs
34*6a54128fSAndroid Build Coastguard Worker
35*6a54128fSAndroid Build Coastguard Worker$E2MMPSTATUS $TMPFILE > $test_name.log 2>&1
36*6a54128fSAndroid Build Coastguard Workerstatus=$?
37*6a54128fSAndroid Build Coastguard Workerif [ "$status" != 1 ] ; then
38*6a54128fSAndroid Build Coastguard Worker	echo "$E2MMPSTATUS with EXT2_MMP_SEQ_FSCK passed!" > $test_name.failed
39*6a54128fSAndroid Build Coastguard Worker	echo "$test_name: $test_description: failed"
40*6a54128fSAndroid Build Coastguard Worker	return 1
41*6a54128fSAndroid Build Coastguard Workerfi
42*6a54128fSAndroid Build Coastguard Worker
43*6a54128fSAndroid Build Coastguard Workerecho "e2fsck (should fail mmp_seq = EXT2_MMP_SEQ_FSCK) ..." >> $test_name.log
44*6a54128fSAndroid Build Coastguard Worker$FSCK $FSCK_OPT $TMPFILE >> $test_name.log 2>&1
45*6a54128fSAndroid Build Coastguard Workerstatus=$?
46*6a54128fSAndroid Build Coastguard Workerif [ "$status" = 0 ] ; then
47*6a54128fSAndroid Build Coastguard Worker	echo "e2fsck with MMP as EXT2_MMP_SEQ_FSCK ran!" > $test_name.failed
48*6a54128fSAndroid Build Coastguard Worker	echo "$test_name: $test_description: failed"
49*6a54128fSAndroid Build Coastguard Worker	return 1
50*6a54128fSAndroid Build Coastguard Workerfi
51*6a54128fSAndroid Build Coastguard Worker
52*6a54128fSAndroid Build Coastguard Workerecho "clear mmp_seq with tune2fs ..." >> $test_name.log
53*6a54128fSAndroid Build Coastguard Worker$TUNE2FS -f -E clear_mmp $TMPFILE >> $test_name.log 2>&1
54*6a54128fSAndroid Build Coastguard Workerstatus=$?
55*6a54128fSAndroid Build Coastguard Workerif [ "$status" != 0 ] ; then
56*6a54128fSAndroid Build Coastguard Worker	echo "tune2fs clearing EXT2_MMP_SEQ_FSCK failed" > $test_name.failed
57*6a54128fSAndroid Build Coastguard Worker	echo "$test_name: $test_description: failed"
58*6a54128fSAndroid Build Coastguard Worker	return 1
59*6a54128fSAndroid Build Coastguard Workerfi
60*6a54128fSAndroid Build Coastguard Worker
61*6a54128fSAndroid Build Coastguard Workerecho "run e2fsck again (should pass with clean mmp_seq) ..." >> $test_name.log
62*6a54128fSAndroid Build Coastguard Worker$FSCK $FSCK_OPT $TMPFILE >> $test_name.log 2>&1
63*6a54128fSAndroid Build Coastguard Workerstatus=$?
64*6a54128fSAndroid Build Coastguard Workerif [ "$status" != 0 ] ; then
65*6a54128fSAndroid Build Coastguard Worker	echo "e2fsck after clearing EXT2_MMP_SEQ_FSCK failed"> $test_name.failed
66*6a54128fSAndroid Build Coastguard Worker	echo "$test_name: $test_description: failed"
67*6a54128fSAndroid Build Coastguard Worker	return $status
68*6a54128fSAndroid Build Coastguard Workerfi
69*6a54128fSAndroid Build Coastguard Worker
70*6a54128fSAndroid Build Coastguard Workerecho "$test_name: $test_description: ok"
71*6a54128fSAndroid Build Coastguard Workerrm -f $TMPFILE
72