From: Sheng Yong <[email protected]>
Signed-off-by: Sheng Yong <[email protected]>
---
tests/f_cp_bad_crc/README | 5 +++++
tests/f_cp_bad_crc/expect.in | 4 ++++
tests/f_cp_bad_crc/script | 38 ++++++++++++++++++++++++++++++++++++
3 files changed, 47 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..d21fdab7304a
--- /dev/null
+++ b/tests/f_cp_bad_crc/expect.in
@@ -0,0 +1,4 @@
+Info: Automatic fix mode enabled.
+ Invalid CP CRC: offset:_OFFS_, crc:0x12345, calc:_CRC_
+Info: Automatic fix mode enabled.
+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..b5181614f537
--- /dev/null
+++ b/tests/f_cp_bad_crc/script
@@ -0,0 +1,38 @@
+#!/bin/bash
+
+DESC="current cp with invalid crc"
+
+. $TOPDIR/tests/helpers
+
+cleanup
+make_f2fs > $LOG
+
+mkdir $TESTDIR/mntdir
+safe_mount $MNT_OPTS $META $TESTDIR/mntdir >> $LOG
+touch $TESTDIR/mntdir/testfile
+safe_umount $TESTDIR/mntdir >> $LOG
+rm -rf $TESTDIR/mntdir
+
+cp=`get_cp $META`
+offs=`get_mb_val "$cp" checksum_offset`
+crc=`get_mb_val "$cp" '\<checksum\>'`
+
+echo "crc:$crc offs:$offs" >> $LOG
+
+$INJECT --cp 0 --mb crc --val 0x12345 $META >> $LOG
+$FSCK $FSCK_OPTS -a $META > $OUT
+$FSCK $FSCK_OPTS -a $META >> $OUT
+
+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
--
2.43.0
_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel