From: Sheng Yong <shengyo...@xiaomi.com>

Signed-off-by: Sheng Yong <shengyo...@xiaomi.com>
---
 tests/i_meta/README    |   5 +
 tests/i_meta/expect.in |  60 ++++++++++++
 tests/i_meta/script    | 212 +++++++++++++++++++++++++++++++++++++++++
 3 files changed, 277 insertions(+)
 create mode 100644 tests/i_meta/README
 create mode 100644 tests/i_meta/expect.in
 create mode 100644 tests/i_meta/script

diff --git a/tests/i_meta/README b/tests/i_meta/README
new file mode 100644
index 000000000000..2ad5bd5d90c5
--- /dev/null
+++ b/tests/i_meta/README
@@ -0,0 +1,5 @@
+1. create f2fs image
+2. inject members in META area
+3. verify injected fields with dump.f2fs
+4. restore injected fields
+5. fsck checks f2fs image
diff --git a/tests/i_meta/expect.in b/tests/i_meta/expect.in
new file mode 100644
index 000000000000..f9a306eaa918
--- /dev/null
+++ b/tests/i_meta/expect.in
@@ -0,0 +1,60 @@
+original feature:_ORIG_FEATURE_
+inject feature:feature [0x12345:74565]
+restore feature:_ORIG_FEATURE_
+original devs.path:devs[i].path [_ORIG_PATH_]
+inject devs.path:devs[i].path [_INJECT_PATH_]
+restore devs.path:devs[i].path [_ORIG_PATH_]
+original checkpoint_ver:
+checkpoint_ver [_ORIG_CPVER_HEX_:_ORIG_CPVER_DEC_]
+original ckpt_flags:
+ckpt_flags [_ORIG_FLAGS_HEX_:_ORIG_FLAGS_DEC_]
+original cur_node_segno[1]:
+cur_node_segno[1] [_ORIG_CUR_NODE_SEGNO_HEX_:_ORIG_CUR_NODE_SEGNO_DEC_]
+original cur_node_blkoff[1]:
+cur_node_blkoff[1] [_ORIG_CUR_NODE_BLKOFF_HEX_:_ORIG_CUR_NODE_BLKOFF_DEC_]
+original cur_data_segno[2]:
+cur_data_segno[2] [_ORIG_CUR_DATA_SEGNO_HEX_:_ORIG_CUR_DATA_SEGNO_DEC_]
+original cur_data_blkoff[2]:
+cur_data_blkoff[2] [_ORIG_CUR_DATA_BLKOFF_HEX_:_ORIG_CUR_DATA_BLKOFF_DEC_]
+original elapsed_time:
+elapsed_time [_ORIG_ELAPSED_TIME_HEX_:_ORIG_ELAPSED_TIME_DEC_]
+inject checkpoint_ver:
+checkpoint_ver [0xffffffffffffff0:1152921504606846960]
+inject ckpt_flags:
+ckpt_flags [0x12345:74565]
+inject cur_node_segno[1]:
+cur_node_segno[1] [0x1:1]
+inject cur_node_blkoff[1]:
+cur_node_blkoff[1] [0x2:2]
+inject cur_data_segno[2]:
+cur_data_segno[2] [0x3:3]
+inject cur_data_blkoff[2]:
+cur_data_blkoff[2] [0x4:4]
+inject elapsed_time:
+elapsed_time [0xffff0000:4294901760]
+restore checkpoint_ver:
+checkpoint_ver [_ORIG_CPVER_HEX_:_ORIG_CPVER_DEC_]
+restore ckpt_flags:
+ckpt_flags [_ORIG_FLAGS_HEX_:_ORIG_FLAGS_DEC_]
+restore cur_node_segno[1]:
+cur_node_segno[1] [_ORIG_CUR_NODE_SEGNO_HEX_:_ORIG_CUR_NODE_SEGNO_DEC_]
+restore cur_node_blkoff[1]:
+cur_node_blkoff[1] [_ORIG_CUR_NODE_BLKOFF_HEX_:_ORIG_CUR_NODE_BLKOFF_DEC_]
+restore cur_data_segno[2]:
+cur_data_segno[2] [_ORIG_CUR_DATA_SEGNO_HEX_:_ORIG_CUR_DATA_SEGNO_DEC_]
+restore cur_data_blkoff[2]:
+cur_data_blkoff[2] [_ORIG_CUR_DATA_BLKOFF_HEX_:_ORIG_CUR_DATA_BLKOFF_DEC_]
+restore elapsed_time:
+elapsed_time [_ORIG_ELAPSED_TIME_HEX_:_ORIG_ELAPSED_TIME_DEC_]
+original nat entry:
+nid:_INO_ ino:_INO_ ver:0 offset:0
+inject nat entry:
+nid:_INO_ ino:_INO_ ver:18 offset:0
+restore nat entry:
+nid:_INO_ ino:_INO_ ver:0 offset:0
+original sit entry:
+segno:_SEGNO_ vblocks:512 seg_type:1 mtime:0
+inject sit entry:
+segno:_SEGNO_ vblocks:512 seg_type:1 mtime:74565
+restore sit entry:
+segno:_SEGNO_ vblocks:512 seg_type:1 mtime:0
diff --git a/tests/i_meta/script b/tests/i_meta/script
new file mode 100644
index 000000000000..c1484bf470f5
--- /dev/null
+++ b/tests/i_meta/script
@@ -0,0 +1,212 @@
+#!/bin/bash
+
+DESC="verify injecting fields in META area"
+
+. $TOPDIR/tests/helpers
+
+cleanup
+make_f2fs > $LOG
+
+mkdir $TESTDIR/mntdir
+safe_mount $MNT_OPTS $META $TESTDIR/mntdir >> $LOG
+dd if=/dev/zero of=$TESTDIR/mntdir/testfile bs=4K count=513 status=none
+ino=`stat -c "%i" $TESTDIR/mntdir/testfile`
+safe_umount $TESTDIR/mntdir >> $LOG
+rm -rf $TESTDIR/mntdir
+
+node=`$DUMP $DUMP_OPTS -i $ino $META`
+echo "$node" >> $LOG
+blkaddr=`get_mb_val "$node" 'i_addr\[0x100\]'`
+segno=`get_segno $blkaddr`
+echo "ino:$ino blkaddr:$blkaddr segno:$segno" >> $LOG
+
+## inject super block
+# member "magic", "s_stop_reason" and "s_errors" are verified by
+# f_sb_bad_magic and f_sb_errors
+
+orig_sb=`get_sb $META`
+orig_feats_val=`get_mb_val "$orig_sb" feature`
+orig_path_str=`get_mb_val "$orig_sb" 'devs\[i\]\.path'`
+
+# inject and restore feature
+orig_feats=`echo "$orig_sb" | grep "^feature" | trim_extra_space`
+echo "original feature:$orig_feats" > $OUT
+$INJECT --sb 0 --mb feature --val 0x12345 $META >> $LOG
+cur_sb=`get_sb $META`
+cur_feats=`echo "$cur_sb" | grep "^feature" | trim_extra_space`
+echo "inject feature:$cur_feats" >> $OUT
+$INJECT --sb 0 --mb feature --val $orig_feats_val $META >> $LOG
+cur_sb=`get_sb $META`
+cur_feats=`echo "$cur_sb" | grep "^feature" | trim_extra_space`
+echo "restore feature:$cur_feats" >> $OUT
+
+# inject and restore the first devs.path
+orig_path=`echo "$orig_sb" | grep '^devs\[i\]\.path' | awk "NR==1" | 
trim_extra_space`
+if [ x"$orig_path" = x"" ]; then
+       echo "original devs.path:devs[i].path []" >> $OUT
+       echo "inject devs.path:devs[i].path []" >> $OUT
+       echo "restore devs.path:devs[i].path []" >> $OUT
+else
+       echo "original devs.path:$orig_path" >> $OUT
+       new_meta_path=$TESTDIR/new_meta
+       rm -f $new_meta_path
+       ln -s $META $new_meta_path
+       $INJECT --sb 0 --mb devs.path --idx 0 --str $new_meta_path $META >> $LOG
+       cur_sb=`get_sb $new_meta_path`
+       cur_path=`echo "$cur_sb" | grep '^devs\[i\]\.path' | awk "NR==1" | 
trim_extra_space`
+       echo "inject devs.path:$cur_path" >> $OUT
+       $INJECT --sb 0 --mb devs.path --idx 0 --str $orig_path_str 
$new_meta_path >> $LOG
+       cur_sb=`get_sb $META`
+       cur_path=`echo "$cur_sb" | grep '^devs\[i\]\.path' | awk "NR==1" | 
trim_extra_space`
+       echo "restore devs.path:$cur_path" >> $OUT
+fi
+
+## inject checkpoint
+# member "next_blkaddr" and "crc" are verified by f_loop_fsync_dnodes and
+# f_cp_bad_crc
+
+# inject and restore cp members
+orig_cp=`get_cp $META`
+echo "original checkpoint_ver:" >> $OUT
+get_mb "$orig_cp" checkpoint_ver >> $OUT
+orig_cpver_val=`get_mb_val "$orig_cp" checkpoint_ver`
+echo "original ckpt_flags:" >> $OUT
+get_mb "$orig_cp" ckpt_flags >> $OUT
+orig_flags_val=`get_mb_val "$orig_cp" ckpt_flags`
+echo "original cur_node_segno[1]:" >> $OUT
+get_mb "$orig_cp" 'cur_node_segno\[1\]' >> $OUT
+orig_cur_node_segno_val=`get_mb_val "$orig_cp" 'cur_node_segno\[1\]'`
+echo "original cur_node_blkoff[1]:" >> $OUT
+get_mb "$orig_cp" 'cur_node_blkoff\[1\]' >> $OUT
+orig_cur_node_blkoff_val=`get_mb_val "$orig_cp" 'cur_node_blkoff\[1\]'`
+echo "original cur_data_segno[2]:" >> $OUT
+get_mb "$orig_cp" 'cur_data_segno\[2\]' >> $OUT
+orig_cur_data_segno_val=`get_mb_val "$orig_cp" 'cur_data_segno\[2\]'`
+echo "original cur_data_blkoff[2]:" >> $OUT
+get_mb "$orig_cp" 'cur_data_blkoff\[2\]' >> $OUT
+orig_cur_data_blkoff_val=`get_mb_val "$orig_cp" 'cur_data_blkoff\[2\]'`
+echo "original elapsed_time:" >> $OUT
+get_mb "$orig_cp" 'elapsed_time' >> $OUT
+orig_elapsed_time_val=`get_mb_val "$orig_cp" elapsed_time`
+$INJECT --cp 0 --mb checkpoint_ver --val 0xffffffffffffff0 $META >> $LOG
+$INJECT --cp 0 --mb ckpt_flags --val 0x12345 $META >> $LOG
+$INJECT --cp 0 --mb cur_node_segno --idx 1 --val 1 $META >> $LOG
+$INJECT --cp 0 --mb cur_node_blkoff --idx 1 --val 2 $META >> $LOG
+$INJECT --cp 0 --mb cur_data_segno --idx 2 --val 3 $META >> $LOG
+$INJECT --cp 0 --mb cur_data_blkoff --idx 2 --val 4 $META >> $LOG
+$INJECT --cp 0 --mb elapsed_time --val 0xffff0000 $META >> $LOG
+cur_cp=`get_cp $META`
+echo "inject checkpoint_ver:" >> $OUT
+get_mb "$cur_cp" checkpoint_ver >> $OUT
+echo "inject ckpt_flags:" >> $OUT
+get_mb "$cur_cp" ckpt_flags >> $OUT
+echo "inject cur_node_segno[1]:" >> $OUT
+get_mb "$cur_cp" 'cur_node_segno\[1\]' >> $OUT
+echo "inject cur_node_blkoff[1]:" >> $OUT
+get_mb "$cur_cp" 'cur_node_blkoff\[1\]' >> $OUT
+echo "inject cur_data_segno[2]:" >> $OUT
+get_mb "$cur_cp" 'cur_data_segno\[2\]' >> $OUT
+echo "inject cur_data_blkoff[2]:" >> $OUT
+get_mb "$cur_cp" 'cur_data_blkoff\[2\]' >> $OUT
+echo "inject elapsed_time:" >> $OUT
+get_mb "$cur_cp" 'elapsed_time' >> $OUT
+$INJECT --cp 0 --mb checkpoint_ver --val $orig_cpver_val $META >> $LOG
+$INJECT --cp 0 --mb ckpt_flags --val $orig_flags_val $META >> $LOG
+$INJECT --cp 0 --mb cur_node_segno --idx 1 --val $orig_cur_node_segno_val 
$META >> $LOG
+$INJECT --cp 0 --mb cur_node_blkoff --idx 1 --val $orig_cur_node_blkoff_val 
$META >> $LOG
+$INJECT --cp 0 --mb cur_data_segno --idx 2 --val $orig_cur_data_segno_val 
$META >> $LOG
+$INJECT --cp 0 --mb cur_data_blkoff --idx 2 --val $orig_cur_data_blkoff_val 
$META >> $LOG
+$INJECT --cp 0 --mb elapsed_time --val $orig_elapsed_time_val $META >> $LOG
+cur_cp=`get_cp $META`
+echo "restore checkpoint_ver:" >> $OUT
+get_mb "$cur_cp" checkpoint_ver >> $OUT
+echo "restore ckpt_flags:" >> $OUT
+get_mb "$cur_cp" ckpt_flags >> $OUT
+echo "restore cur_node_segno[1]:" >> $OUT
+get_mb "$cur_cp" 'cur_node_segno\[1\]' >> $OUT
+echo "restore cur_node_blkoff[1]:" >> $OUT
+get_mb "$cur_cp" 'cur_node_blkoff\[1\]' >> $OUT
+echo "restore cur_data_segno[2]:" >> $OUT
+get_mb "$cur_cp" 'cur_data_segno\[2\]' >> $OUT
+echo "restore cur_data_blkoff[2]:" >> $OUT
+get_mb "$cur_cp" 'cur_data_blkoff\[2\]' >> $OUT
+echo "restore elapsed_time:" >> $OUT
+get_mb "$cur_cp" 'elapsed_time' >> $OUT
+
+## inject nat entry
+# member "ino" and "block_addr" are verified by f_nat_bad_ino and
+# f_nat_bad_blkaddr
+
+# inject and restore version
+rm -f dump_nat
+$DUMP $DUMP_OPTS -n $ino~$((ino + 1)) $META >> $LOG
+echo "original nat entry:" >> $OUT
+cat dump_nat | trim_extra_space >> $OUT
+orig_ver=0 # orig_ver must be 0 in this testcase
+$INJECT --nat 0 --nid $ino --mb version --val 0x12 $META >> $LOG
+$DUMP $DUMP_OPTS -n $ino~$((ino + 1)) $META >> $LOG
+echo "inject nat entry:" >> $OUT
+cat dump_nat | trim_extra_space >> $OUT
+$INJECT --nat 0 --nid $ino --mb version --val $orig_ver $META >> $LOG
+$DUMP $DUMP_OPTS -n $ino~$((ino + 1)) $META >> $LOG
+echo "restore nat entry:" >> $OUT
+cat dump_nat | trim_extra_space >> $OUT
+
+## inject sit entry
+# member "type", "valid_map" and "vblocks" are verified by f_sit_bad_type,
+# f_sit_bad_valid_blocks and f_sit_bad_vblocks
+
+# inject and restore mtime
+rm -f dump_sit
+$DUMP $DUMP_OPTS -s $segno~$((segno + 1)) $META >> $LOG
+echo "original sit entry:" >> $OUT
+orig_sit=`grep "segno:" dump_sit | trim_extra_space`
+echo "$orig_sit" >> $OUT
+orig_mtime=`echo $orig_sit | sed 's/.* mtime:\([0-9]\{,1\}\) .*/\1/'`
+$INJECT --sit 0 --blk $blkaddr --mb mtime --val 0x12345 $META >> $LOG
+$DUMP $DUMP_OPTS -s $segno~$((segno + 1)) $META >> $LOG
+echo "inject sit entry:" >> $OUT
+grep "segno:" dump_sit | trim_extra_space >> $OUT
+$INJECT --sit 0 --blk $blkaddr --mb mtime --val $orig_mtime $META >> $LOG
+$DUMP $DUMP_OPTS -s $segno~$((segno + 1)) $META >> $LOG
+echo "restore sit entry:" >> $OUT
+grep "segno:" dump_sit | trim_extra_space >> $OUT
+
+## run fsck to check if there are any errors
+$FSCK $FSCK_OPTS -f $META >> $LOG
+if [ $? -ne 0 ]; then
+       echo "fsck fail" >> $OUT
+fi
+
+sed "s/_ORIG_FEATURE_/$orig_feats/g" $TESTDIR/expect.in > $TESTDIR/expect
+# escape '\' in path
+new_meta_path_str=`echo $new_meta_path | sed 's/\\//\\\\\//g'`
+orig_path_str=`echo $orig_path_str | sed 's/\\//\\\\\//g'`
+sed -i "s/_ORIG_PATH_/$orig_path_str/g" $TESTDIR/expect
+sed -i "s/_INJECT_PATH_/$new_meta_path_str/g" $TESTDIR/expect
+dec=$((orig_cpver_val)); hex=`printf "0x%x" $dec`
+sed -i "s/_ORIG_CPVER_HEX_/$hex/g" $TESTDIR/expect
+sed -i "s/_ORIG_CPVER_DEC_/$dec/g" $TESTDIR/expect
+dec=$((orig_flags_val)); hex=`printf "0x%x" $dec`
+sed -i "s/_ORIG_FLAGS_HEX_/$hex/g" $TESTDIR/expect
+sed -i "s/_ORIG_FLAGS_DEC_/$dec/g" $TESTDIR/expect
+dec=$((orig_cur_node_segno_val)); hex=`printf "0x%x" $dec`
+sed -i "s/_ORIG_CUR_NODE_SEGNO_HEX_/$hex/g" $TESTDIR/expect
+sed -i "s/_ORIG_CUR_NODE_SEGNO_DEC_/$dec/g" $TESTDIR/expect
+dec=$((orig_cur_node_blkoff_val)); hex=`printf "0x%x" $dec`
+sed -i "s/_ORIG_CUR_NODE_BLKOFF_HEX_/$hex/g" $TESTDIR/expect
+sed -i "s/_ORIG_CUR_NODE_BLKOFF_DEC_/$dec/g" $TESTDIR/expect
+dec=$((orig_cur_data_segno_val)); hex=`printf "0x%x" $dec`
+sed -i "s/_ORIG_CUR_DATA_SEGNO_HEX_/$hex/g" $TESTDIR/expect
+sed -i "s/_ORIG_CUR_DATA_SEGNO_DEC_/$dec/g" $TESTDIR/expect
+dec=$((orig_cur_data_blkoff_val)); hex=`printf "0x%x" $dec`
+sed -i "s/_ORIG_CUR_DATA_BLKOFF_HEX_/$hex/g" $TESTDIR/expect
+sed -i "s/_ORIG_CUR_DATA_BLKOFF_DEC_/$dec/g" $TESTDIR/expect
+dec=$((orig_elapsed_time_val)); hex=`printf "0x%x" $dec`
+sed -i "s/_ORIG_ELAPSED_TIME_HEX_/$hex/g" $TESTDIR/expect
+sed -i "s/_ORIG_ELAPSED_TIME_DEC_/$dec/g" $TESTDIR/expect
+sed -i "s/_INO_/$ino/g" $TESTDIR/expect
+sed -i "s/_SEGNO_/$segno/g" $TESTDIR/expect
+
+check_result
+rm -f $new_meta_path dump_nat dump_sit
-- 
2.43.0



_______________________________________________
Linux-f2fs-devel mailing list
Linux-f2fs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel

Reply via email to