From 820362fc601f68cc1bed7e76943e763e976d4284 Mon Sep 17 00:00:00 2001 From: BillyOu <12047406+billyou@user.noreply.gitee.com> Date: Sat, 23 Nov 2024 13:15:33 +0000 Subject: [PATCH 1/2] =?UTF-8?q?update=20fs/template/tests/stages/remount.s?= =?UTF-8?q?h.=20=E5=A2=9E=E5=8A=A0=E6=96=87=E4=BB=B6=E5=90=8D=E9=9A=8F?= =?UTF-8?q?=E6=9C=BA=E7=94=9F=E6=88=90=EF=BC=8C=E5=90=91python=E8=84=9A?= =?UTF-8?q?=E6=9C=AC=E4=BC=A0=E9=80=92=E6=96=87=E4=BB=B6=E5=90=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: BillyOu <12047406+billyou@user.noreply.gitee.com> --- fs/template/tests/stages/remount.sh | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/fs/template/tests/stages/remount.sh b/fs/template/tests/stages/remount.sh index cdf9c38..3097237 100755 --- a/fs/template/tests/stages/remount.sh +++ b/fs/template/tests/stages/remount.sh @@ -3,6 +3,7 @@ TEST_CASE="case 5 - remount" RES2=( 'file0 file1 file2' ) +filename="$((RANDOM)).txt" function check_umount () { _PARAM=$1 @@ -30,7 +31,7 @@ function create_and_except_remount () { } function create_and_except_bitmap () { - touch_and_check "${MNTPOINT}/hello" + touch_and_check "${MNTPOINT}/$filename" } function check_ls_remount () { @@ -67,7 +68,7 @@ function check_bm() { _PARAM=$1 _TEST_CASE=$2 ROOT_PARENT_PATH=$(cd $(dirname $ROOT_PATH); pwd) - python3 "$ROOT_PATH"/checkbm/checkbm.py -l "$ROOT_PARENT_PATH"/include/fs.layout -r "$ROOT_PARENT_PATH"/tests/checkbm/golden.json > /dev/null + python3 "$ROOT_PATH"/checkbm/checkbm.py -l "$ROOT_PARENT_PATH"/include/fs.layout -r "$ROOT_PARENT_PATH"/tests/checkbm/golden.json -n "$filename" > /dev/null RET=$? if (( RET == ERR_OK )); then return 0 -- Gitee From 620e7bb54f1d6a73b03be25cdbd85510e2c4907f Mon Sep 17 00:00:00 2001 From: BillyOu <12047406+billyou@user.noreply.gitee.com> Date: Sat, 23 Nov 2024 13:21:10 +0000 Subject: [PATCH 2/2] =?UTF-8?q?update=20fs/template/tests/checkbm/checkbm.?= =?UTF-8?q?py.=201=E3=80=81=E5=A2=9E=E5=8A=A0=E4=BA=86=E6=96=87=E4=BB=B6?= =?UTF-8?q?=E5=90=8D=E5=8F=82=E6=95=B0=202=E3=80=81=E7=BB=86=E5=8C=96?= =?UTF-8?q?=E4=BA=86=E6=95=B0=E6=8D=AE=E5=9D=97=E4=BD=8D=E5=9B=BE=E7=9A=84?= =?UTF-8?q?=E6=A3=80=E6=9F=A5=E8=BF=87=E7=A8=8B=EF=BC=8C=E9=99=A4=E7=BB=9F?= =?UTF-8?q?=E8=AE=A1=E5=B7=B2=E4=BD=BF=E7=94=A8=E6=95=B0=E6=8D=AE=E5=9D=97?= =?UTF-8?q?=E6=95=B0=E9=87=8F=E5=A4=96=EF=BC=8C=E4=BF=9D=E5=AD=98=E6=95=B0?= =?UTF-8?q?=E6=8D=AE=E5=9D=97=E5=81=8F=E7=A7=BB=E3=80=82=203=E3=80=81?= =?UTF-8?q?=E6=9B=B4=E6=94=B9=E4=BA=86check=5Fdata=EF=BC=8C=E6=A0=B9?= =?UTF-8?q?=E6=8D=AE=E4=B8=8A=E4=B8=80=E6=AD=A5=E4=BF=9D=E5=AD=98=E7=9A=84?= =?UTF-8?q?=E5=81=8F=E7=A7=BB=E6=A3=80=E6=9F=A5=E6=95=B0=E6=8D=AE=E5=9D=97?= =?UTF-8?q?=E5=86=85=E5=AE=B9=EF=BC=8C=E6=95=B0=E6=8D=AE=E5=9D=97=E4=B8=AD?= =?UTF-8?q?=E5=BA=94=E5=8C=85=E5=90=ABshell=E8=84=9A=E6=9C=AC=E5=88=9B?= =?UTF-8?q?=E5=BB=BA=E7=9A=84=E6=96=87=E4=BB=B6=E7=9A=84=E5=90=8D=E7=A7=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: BillyOu <12047406+billyou@user.noreply.gitee.com> --- fs/template/tests/checkbm/checkbm.py | 51 +++++++++++++++++++++------- 1 file changed, 38 insertions(+), 13 deletions(-) diff --git a/fs/template/tests/checkbm/checkbm.py b/fs/template/tests/checkbm/checkbm.py index 37c2b23..f76c1fc 100644 --- a/fs/template/tests/checkbm/checkbm.py +++ b/fs/template/tests/checkbm/checkbm.py @@ -1,5 +1,5 @@ import argparse -from distutils.log import error +# from distutils.log import error from io import TextIOWrapper import os import sys @@ -32,6 +32,7 @@ ddriver = home + "/ddriver" parser = argparse.ArgumentParser() parser.add_argument("-l", "--layout", help="absolute path of .layout file") parser.add_argument("-r", "--rules", help="absolute path of golden rule json file") +parser.add_argument("-n", "--name", help="file name or directory name to check") args = parser.parse_args() if args.layout == None: @@ -44,6 +45,12 @@ if args.rules == None: else: golden = args.rules +if args.name == None: + sys.stderr.write("未输入需检查的数据内容\n") + exit(-1) +else: + name = args.name + """ Does layout contain token """ def check_layout(layout: str, tokens: List[str]): layout_lower = layout.lower() @@ -201,7 +208,7 @@ with open(fslayout, "r") as f: print("\tinode_blks: %d" % inode_blks) -def check_map(f: TextIOWrapper, map_ofs: int, map_blks: int, golden_cnt: int): +def check_inodemap(f: TextIOWrapper, map_ofs: int, map_blks: int, golden_cnt: int): f.seek(map_ofs * block_size) bm = f.read(map_blks * block_size) valid_count = 0 @@ -210,33 +217,51 @@ def check_map(f: TextIOWrapper, map_ofs: int, map_blks: int, golden_cnt: int): valid_count += bin(val).count("1") return [ valid_count == golden_cnt, valid_count, golden_cnt] -def check_data(f: TextIOWrapper, ino_ofs: int, ino_blks: int): - res = True - f.seek((ino_ofs + ino_blks) * block_size) +def check_datamap(f: TextIOWrapper, map_ofs: int, map_blks: int, golden_cnt: int): + f.seek(map_ofs * block_size) + bm = f.read(map_blks * block_size) + position = [] + valid_count = 0 + for i in range(0, int(map_blks * block_size / 4)): + val = int.from_bytes(bm[i * 4 : i * 4 + 4], byteorder='little', signed=False) + bin_str = bin(val)[2:].zfill(32) + for b in range(len(bin_str)): + if bin_str[b] == '1': + valid_count += 1 + position.append(i*32 + (31 - b)) + return [ valid_count == golden_cnt, valid_count, golden_cnt, position] + +def check_data(f: TextIOWrapper, ino_ofs: int, ino_blks: int, position: list): + res = [False, False] + f.seek((ino_ofs + ino_blks + position[0]) * block_size) bm = f.read(1 * block_size) valid_count = 0 - if all(byte == 0 for byte in bm): - res = False - else: - res = True + if not all(byte == 0 for byte in bm): + res[0] = True + if name in bm.decode('utf-8'): + res[1] = True return res with open(ddriver, "rb") as f: if is_check_inode_map: - res1 = check_map(f, inode_map_ofs, inode_map_blks, valid_inode) + res1 = check_inodemap(f, inode_map_ofs, inode_map_blks, valid_inode) if not res1[0]: sys.stderr.write("Inode位图错误, 期望值: %d个有效位, 实际值: %d个有效位" % (res1[2], res1[1])) exit(INODE_MAP_ERR) if is_check_data_map: - res2 = check_map(f, data_map_ofs, data_map_blks, valid_data) + res2 = check_datamap(f, data_map_ofs, data_map_blks, valid_data) + print(res2[3]) if not res2[0]: sys.stderr.write("数据位图错误, 期望值: %d个有效位, 实际值: %d个有效位" % (res2[2], res2[1])) exit(DATA_MAP_ERR) if is_check_data: - res3 = check_data(f, inode_ofs, inode_blks) - if not res3: + res3 = check_data(f, inode_ofs, inode_blks, res2[3]) + if not res3[0]: sys.stderr.write("数据写回错误, 没有写回到指定的数据区中") exit(DATA_ERR) + if not res3[1]: + sys.stderr.write("数据写回错误, 找不到写入的数据内容") + exit(DATA_ERR) exit(ERR_OK) \ No newline at end of file -- Gitee