diff options
| author | Zhihao Cheng <chengzhihao1@huawei.com> | 2024-11-11 17:08:27 +0800 | 
|---|---|---|
| committer | David Oberhollenzer <david.oberhollenzer@sigma-star.at> | 2024-11-11 10:32:46 +0100 | 
| commit | 389048a771e625a559b53b804a8e0739312cb12c (patch) | |
| tree | e9edcadf5504fe7160803aa359ef8e1645e5362d /tests | |
| parent | 60fd097fb0c436956e58d0a30535a04a35258225 (diff) | |
tests: ubifs_tools: mkfs_tests: Add fs content check test
Initialize UBIFS image from a given directory, then check whether the
fs content in mounted UBIFS is consistent with the original directory.
Both UBI volume and file are chosen as storage mediums to test.
Signed-off-by: Zhihao Cheng <chengzhihao1@huawei.com>
Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/ubifs_tools-tests/Makemodule.am | 3 | ||||
| -rwxr-xr-x | tests/ubifs_tools-tests/lib/common.sh.in | 8 | ||||
| -rwxr-xr-x | tests/ubifs_tools-tests/mkfs_tests/build_fs_from_dir.sh.in | 174 | 
3 files changed, 184 insertions, 1 deletions
| diff --git a/tests/ubifs_tools-tests/Makemodule.am b/tests/ubifs_tools-tests/Makemodule.am index 1d3d0f2..f4d8a07 100644 --- a/tests/ubifs_tools-tests/Makemodule.am +++ b/tests/ubifs_tools-tests/Makemodule.am @@ -6,7 +6,8 @@ test_SCRIPTS += \  	tests/ubifs_tools-tests/fsck_tests/cycle_corrupted_fsck_fault_inject.sh \  	tests/ubifs_tools-tests/fsck_tests/cycle_powercut_mount_fsck.sh \  	tests/ubifs_tools-tests/fsck_tests/random_corrupted_fsck.sh \ -	tests/ubifs_tools-tests/fsck_tests/fsck_bad_image.sh +	tests/ubifs_tools-tests/fsck_tests/fsck_bad_image.sh \ +	tests/ubifs_tools-tests/mkfs_tests/build_fs_from_dir.sh  test_DATA += \  	tests/ubifs_tools-tests/images/good.gz \ diff --git a/tests/ubifs_tools-tests/lib/common.sh.in b/tests/ubifs_tools-tests/lib/common.sh.in index a27fe10..8d1b3c0 100755 --- a/tests/ubifs_tools-tests/lib/common.sh.in +++ b/tests/ubifs_tools-tests/lib/common.sh.in @@ -8,8 +8,10 @@ UBI_NUM=0  DEV=/dev/ubi0_0  MNT=/mnt/test_file_system  TMP_FILE=/tmp/ubifs_test_file +TMP_MNT=/tmp/ubifs_tmp_mnt  LOG_FILE=/tmp/ubifs_log  KEY_FILE=/tmp/key +IMG_FILE=ubifs.img  nandsim_patt="NAND simulator"  mtdram_patt="mtdram test device" @@ -35,6 +37,8 @@ function cleanup_handler()  {  	local ret="$1" +	umount $TMP_MNT >/dev/null 2>&1 ||: +	rm -rf $TMP_MNT >/dev/null 2>&1 ||:  	if [ "$ret" == "0" ]; then  		umount $MNT >/dev/null 2>&1 ||:  		modprobe -r ubifs >/dev/null 2>&1 ||: @@ -45,6 +49,7 @@ function cleanup_handler()  		rm -f $TMP_FILE >/dev/null 2>&1 ||:  		rm -f $KEY_FILE >/dev/null 2>&1 ||:  		rm -f $LOG_FILE >/dev/null 2>&1 ||: +		rm -f $IMG_FILE >/dev/null 2>&1 ||:  		exit 0  	else  		exit 1 @@ -344,6 +349,9 @@ function cancel_io_err()  if ! [ -d $MNT ]; then  	mkdir -p $MNT  fi +if ! [ -d $TMP_MNT ]; then +	mkdir -p $TMP_MNT +fi  modprobe ubi || fatal "common.sh: cannot load ubi"  modprobe ubifs || fatal "common.sh: cannot load ubifs" diff --git a/tests/ubifs_tools-tests/mkfs_tests/build_fs_from_dir.sh.in b/tests/ubifs_tools-tests/mkfs_tests/build_fs_from_dir.sh.in new file mode 100755 index 0000000..0b22856 --- /dev/null +++ b/tests/ubifs_tools-tests/mkfs_tests/build_fs_from_dir.sh.in @@ -0,0 +1,174 @@ +#!/bin/sh +# Copyright (c), 2024, Huawei Technologies Co, Ltd. +# Author: Zhihao Cheng <chengzhihao1@huawei.com> +# +# Test Description: +# Initialize UBIFS image from a given directory, then check whether the +# fs content in mounted UBIFS is consistent with the original directory. +# Both UBI volume and file are chosen as storage mediums to test. +# Running time: 10min + +TESTBINDIR=@TESTBINDIR@ +source $TESTBINDIR/common.sh + +function run_test() +{ +	local simulator="$1"; +	local size="$2"; +	local peb_size="$3"; +	local page_size="$4"; +	local vid_offs=$page_size; +	local encryption=$5; +	local test_medium=$6; +	local space_fix=$7; +	local need_fsck=$8; +	local double_mkfs=$9; +	local leb_size=$(($(($peb_size*1024))-$page_size)); +	VIDHDR_SZ=64; + +	option="" +	if [[ "$space_fix" == "fix_space" ]]; then +		option="-F" +	fi +	echo "======================================================================" +	printf "%s" "$simulator: ${size}MiB PEB size ${peb_size}KiB" +	if [ "$simulator" = "mtdram" ]; then +		page_size=8 +		leb_size=$(($leb_size-$VIDHDR_SZ)) +	else +		leb_size=$(($leb_size-$page_size)) +	fi +	printf " %s" "page size ${page_size}Bytes" +	printf " $encryption $test_medium $space_fix $need_fsck $double_mkfs\n" + +	if [ "$simulator" = "nandsim" ]; then +		$TESTBINDIR/load_nandsim.sh "$size" "$peb_size" "$page_size" || echo "cannot load nandsim"; +		mtdnum="$(find_mtd_device "$nandsim_patt")" +	elif [ "$simulator" = "mtdram" ]; then +		load_mtdram "$size" "$peb_size" || echo "cannot load mtdram" +		mtdnum="$(find_mtd_device "$mtdram_patt")" +	else +		fatal "$simulator is not supported" +	fi + +	dmesg -c > /dev/null +	flash_eraseall /dev/mtd$mtdnum +	modprobe ubi mtd="$mtdnum,$vid_offs" || fatal "modprobe ubi fail" +	ubimkvol -N vol_test -m -n 0 /dev/ubi$UBI_NUM || fatal "mkvol fail" +	modprobe ubifs || fatal "modprobe ubifs fail" +	if [[ "$encryption" == "encrypted" ]]; then +		encryption_gen_key +		option="$option --cipher AES-256-XTS --key $KEY_FILE" +	fi + +	if [[ "$test_medium" == "volume" ]]; then +		mkfs.ubifs $option -m${page_size} -c 1024 -e $leb_size -f 4 -r $TMP_MNT $DEV +		if [[ $? != 0 ]]; then +			fatal "mkfs failed" +		fi +		if [[ "$double_mkfs" == "double_format" ]]; then +			mkfs.ubifs -y $option -m${page_size} -c 1024 -e $leb_size -f 4 -r $TMP_MNT $DEV +			if [[ $? != 0 ]]; then +				fatal "mkfs failed" +			fi +		fi +	else +		mkfs.ubifs $option -m${page_size} -c 1024 -e $leb_size -f 4 -r $TMP_MNT -o $IMG_FILE +		if [[ $? != 0 ]]; then +			fatal "mkfs failed" +		fi +		ubiupdatevol $DEV $IMG_FILE +		if [[ $? != 0 ]]; then +			fatal "ubiupdatevol failed" +		fi +	fi + +	if [[ "$need_fsck" == "do_fsck" ]]; then +		fsck.ubifs -a $DEV # 'fsck.ubifs $DEV' is fine too. +		res=$? +		if [[ $res != $FSCK_OK ]] +		then +			fatal "fsck expects result $FSCK_OK, but $res is returned" +		fi +	fi + +	enable_chkfs + +	mount_ubifs $DEV $MNT "noauthentication" "noatime" +	res=$? +	if [[ $res != 0 ]] +	then +		fatal "mount fail $res" +	fi + +	if [[ "$encryption" != "encrypted" ]]; then +		# Check filesystem information, skip encrypted image. +		# fscryptctl is not compatible with fscryptctl in mtd-utils. +		# See https://github.com/google/fscryptctl/issues/33 +		du -sh $MNT > /dev/null  # Make sure all files are accessible +		ret=$? +		if [[ $ret != 0 ]]; then +			fatal "Cannot access all files" +		fi + +		parse_dir "md5sum" +	fi + +	check_err_msg + +	umount $MNT +	res=$? +	if [[ $res != 0 ]] +	then +		fatal "unmount fail $res" +	fi + +	check_err_msg +	disable_chkfs + +	if [[ "$test_medium" != "volume" ]]; then +		rm -f $IMG_FILE +	fi +	modprobe -r ubifs +	modprobe -r ubi +	modprobe -r $simulator + +	echo "----------------------------------------------------------------------" +} + +check_fsstress +start_t=$(date +%s) +echo "Do mkfs+fsck+mount test in kinds of flashes" +mount -t tmpfs -osize=50m  none $TMP_MNT || fatal "cannot mount tmpfs" +echo 123 > $TMP_MNT/file +setfattr -n user.xyz -v 123abc $TMP_MNT/file +fsstress -d $TMP_MNT -l30 -n10 -p4 +# Record filesystem information +rm -f $TMP_FILE 2>/dev/null +read_dir $TMP_MNT "md5sum" + +# No authentication tests, which needs a specific key from certs directory corresponding to linux source code.. +# See https://patchwork.ozlabs.org/project/linux-mtd/cover/20190806104928.1224-1-s.hauer@pengutronix.de/ +for simulator in "mtdram" "nandsim"; do +	for encryption in "encrypted" "noencrypted"; do +		for test_medium in "volume" "file"; do +			for space_fix in "fix_space" "nofix_space"; do +				for need_fsck in "do_fsck" "no_fsck"; do +					for double_mkfs in "double_format" "format_once"; do +						run_test "$simulator" "64" "64" "2048" $encryption $test_medium $space_fix $need_fsck $double_mkfs +						run_test "$simulator" "128" "128" "2048" $encryption $test_medium $space_fix $need_fsck $double_mkfs +						run_test "$simulator" "512" "512" "2048" $encryption $test_medium $space_fix $need_fsck $double_mkfs +						run_test "$simulator" "1024" "512" "2048" $encryption $test_medium $space_fix $need_fsck $double_mkfs +					done +				done +			done +		done +	done +done + +umount $TMP_MNT +rm -f $TMP_FILE 2>/dev/null +end_t=$(date +%s) +time_cost=$(( end_t - start_t )) +echo "Success, cost $time_cost seconds" +exit 0 | 
