Signed-off-by: Sheng Yong <shengy...@oppo.com> --- tests/f_cp_bad_crc/README | 5 ++++ tests/f_cp_bad_crc/expect.in | 22 +++++++++++++++++ tests/f_cp_bad_crc/script | 46 ++++++++++++++++++++++++++++++++++++ 3 files changed, 73 insertions(+) create mode 100644 tests/f_cp_bad_crc/README create mode 100644 tests/f_cp_bad_crc/expect.in create mode 100644 tests/f_cp_bad_crc/script
diff --git a/tests/f_cp_bad_crc/README b/tests/f_cp_bad_crc/README new file mode 100644 index 000000000000..250ece3f8b5a --- /dev/null +++ b/tests/f_cp_bad_crc/README @@ -0,0 +1,5 @@ +1. create f2fs image +2. create a new file +3. inject crc in current cp with value 0x12345 +4. fsck fixes bad cp by copying backup cp +5. compare cp1 version with cp2 version, both cp should have the same version diff --git a/tests/f_cp_bad_crc/expect.in b/tests/f_cp_bad_crc/expect.in new file mode 100644 index 000000000000..f21fecd2ae17 --- /dev/null +++ b/tests/f_cp_bad_crc/expect.in @@ -0,0 +1,22 @@ +Info: Automatic fix mode enabled. + Invalid CP CRC: offset:_OFFS_, crc:0x12345, calc:_CRC_ +Info: checkpoint state = x : nat_bits crc fsck compacted_summary unmount + +[FSCK] Unreachable nat entries [Ok..] [x] +[FSCK] SIT valid block bitmap checking [Ok..] +[FSCK] Hard link checking for regular file [Ok..] [x] +[FSCK] valid_block_count matching with CP [Ok..] [x] +[FSCK] valid_node_count matching with CP (de lookup) [Ok..] [x] +[FSCK] valid_node_count matching with CP (nat lookup) [Ok..] [x] +[FSCK] valid_inode_count matched with CP [Ok..] [x] +[FSCK] free segment_count matched with CP [Ok..] [x] +[FSCK] next block offset is free [Ok..] +[FSCK] fixing SIT types +[FSCK] other corrupted bugs [Ok..] +Info: Duplicate valid checkpoint to mirror position x -> x +Info: Write valid nat_bits in checkpoint +Info: write_checkpoint() cur_cp:x + +Info: Automatic fix mode enabled. +Info: checkpoint state = x : nat_bits unmount +Info: No error was reported diff --git a/tests/f_cp_bad_crc/script b/tests/f_cp_bad_crc/script new file mode 100644 index 000000000000..5ef689c33ebe --- /dev/null +++ b/tests/f_cp_bad_crc/script @@ -0,0 +1,46 @@ +#!/bin/bash + +DESC="current cp with invalid crc" + +. $TOPDIR/tests/helpers + +cleanup pre > $LOG 2>&1 +make_f2fs >> $LOG 2>&1 + +mkdir $TESTDIR/mntdir +safe_mount $MNT_OPTS $META $TESTDIR/mntdir >> $LOG 2>&1 +if [ $? -ne 0 ]; then + echo "cannot mount f2fs image" + exit +fi +touch $TESTDIR/mntdir/testfile +safe_umount $TESTDIR/mntdir >> $LOG 2>&1 +if [ $? -ne 0 ]; then + echo "cannot umount f2fs image" + exit +fi +rm -rf $TESTDIR/mntdir + +offs=`get_cp checksum_offset` +crc=`get_cp crc` + +echo "crc:$crc offs:$offs" >> $LOG + +$INJECT --cp 0 --mb crc --val 0x12345 $META >> $LOG 2>&1 +$FSCK $FSCK_OPTS -a $META > $OUT 2>&1 +$FSCK $FSCK_OPTS -a $META >> $OUT 2>&1 + +cp1_ver=`$INJECT --cp 1 --mb checkpoint_ver --val 0 --dry-run $META | grep "inject checkpoint_ver of cp" | awk '{print $(NF-2)}'` +cp2_ver=`$INJECT --cp 2 --mb checkpoint_ver --val 0 --dry-run $META | grep "inject checkpoint_ver of cp" | awk '{print $(NF-2)}'` +if [ $(($cp1_ver)) -ne $(($cp2_ver)) ]; then + echo "cp1_ver: $cp1_ver" >> $OUT + echo "cp2_ver: $cp2_ver" >> $OUT +fi +cat $OUT >> $LOG + +CRC=`printf "0x%x" $crc` +sed "s/_CRC_/$CRC/g" $TESTDIR/expect.in > $TESTDIR/expect +sed -i "s/_OFFS_/$offs/g" $TESTDIR/expect + +check_result +cleanup post >> $LOG 2>&1 -- 2.40.1 _______________________________________________ Linux-f2fs-devel mailing list Linux-f2fs-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel