diff --git a/contrib/windows/tests/btrfstests.py b/contrib/windows/tests/btrfstests.py index 871fa7ec1f6b..7012c4f6a6ae 100644 --- a/contrib/windows/tests/btrfstests.py +++ b/contrib/windows/tests/btrfstests.py @@ -18,10 +18,14 @@ print("Printed immediately.") + + def parse_arguments(): parser = argparse.ArgumentParser(description='Process command line arguments.') parser.add_argument('-path', type=dir_path, required=True) return parser.parse_args() + + def dir_path(path): if os.path.isdir(path): return path @@ -29,7 +33,6 @@ def dir_path(path): raise argparse.ArgumentTypeError(f"readable_dir:{path} is not a valid path") - def get_DeviceId(): magic_number_process = subprocess.run( ["wmic", "diskdrive", "get", "DeviceId"], @@ -64,11 +67,13 @@ def get_DeviceId(): return e + def allocate_file(name, size): with open(name, 'wb') as f: f.seek(size) f.write(b'0') + def delete_file(name): if os.path.exists(name): os.remove(name) @@ -83,7 +88,7 @@ def get_driveletters(): stderr=subprocess.PIPE ) - #b'test01 H:\\ \r\ntest02 I:\\ \r\n' +# b'test01 H:\\ \r\ntest02 I:\\ \r\n' a=magic_number_process.stdout.decode(encoding='UTF-8',errors='strict') @@ -92,7 +97,7 @@ def get_driveletters(): logging.debug("get_driveletters() {}".format(c)) - #print("get_driveletters() debug",c) +# print("get_driveletters() debug",c) d = [x.split() for x in c] @@ -103,7 +108,6 @@ def get_driveletters(): # run: '& "C:\Program Files\OpenZFS On Windows\zfs.exe" mount' - def create_pool(name, file): magic_number_process = subprocess.run( ["C:\\Program Files\\OpenZFS On Windows\\zpool.exe", "create", "-f", name, file], @@ -112,7 +116,6 @@ def create_pool(name, file): ) - def destroy_pool(name): magic_number_process = subprocess.run( ["C:\\Program Files\\OpenZFS On Windows\\zpool.exe", "destroy", "-f", name], @@ -120,6 +123,7 @@ def destroy_pool(name): stderr=subprocess.PIPE ) + def zpool(*args): magic_number_process = subprocess.run( ["C:\\Program Files\\OpenZFS On Windows\\zpool.exe", *args], @@ -156,15 +160,11 @@ def run(args): return result - def tounc(name): q = "\\\\?\\" + str(name) return q - - - def runWithPrint(cmd): print(" ".join(cmd)) ret = run(cmd) @@ -173,20 +173,22 @@ def runWithPrint(cmd): logging.debug(str("stdout={}".format(ret.stdout))) logging.debug(str("stderr={}".format(ret.stderr))) - return ret -def preTest(testName = None): + +def preTest(testName=None): print("=" * 20) if testName is not None: print("Name:", testName) get_driveletters() + def postTest(): get_driveletters() print("=" * 20) + def main(): parsed_args = parse_arguments() @@ -203,7 +205,6 @@ def main(): f1 = PureWindowsPath(p, "test01.dat") allocate_file(f1, 1024*1024*1024) - with open(str(p.joinpath("winbtrfs.log")), "w") as log_file: preTest() @@ -215,10 +216,8 @@ def main(): time.sleep(10) postTest() - - for test in ['create', 'supersede', 'overwrite', 'open_id', 'io', 'mmap', 'rename', 'rename_ex', 'delete', 'delete_ex', 'links', 'links_ex', 'oplock_i', 'oplock_ii', 'oplock_batch', 'oplock_filter', 'oplock_r', 'oplock_rw', 'oplock_rh', 'oplock_rwh', 'cs', 'reparse', 'streams', 'fileinfo', 'ea']: - preTest(str(test) +" tests:") + preTest(str(test) + " tests:") f = PureWindowsPath(get_driveletters()[0][1]) ret = runWithPrint([str(p.joinpath("winbtrfs", "test.exe")), str(test), str(f)]) time.sleep(10) @@ -235,36 +234,11 @@ def main(): log_file.write("\n") preTest() - #runWithPrint(["zpool", "destroy", "-f", "test01"]) +# runWithPrint(["zpool", "destroy", "-f", "test01"]) time.sleep(10) postTest() - - - - - #delete_file(f1) - - - - - - - - - - - - - - - - +# delete_file(f1) if __name__ == "__main__": main() - - - - - diff --git a/contrib/windows/tests/tests.py b/contrib/windows/tests/tests.py index ac1c79707493..4c915d744143 100644 --- a/contrib/windows/tests/tests.py +++ b/contrib/windows/tests/tests.py @@ -16,12 +16,15 @@ logging.basicConfig(level=logging.DEBUG) - print("Printed immediately.") + + def parse_arguments(): parser = argparse.ArgumentParser(description='Process command line arguments.') parser.add_argument('-path', type=dir_path, required=True) return parser.parse_args() + + def dir_path(path): if os.path.isdir(path): return path @@ -29,7 +32,6 @@ def dir_path(path): raise argparse.ArgumentTypeError(f"readable_dir:{path} is not a valid path") - def get_DeviceId(): magic_number_process = subprocess.run( ["wmic", "diskdrive", "get", "DeviceId"], @@ -64,11 +66,13 @@ def get_DeviceId(): return e + def allocate_file(name, size): with open(name, 'wb') as f: f.seek(size) f.write(b'0') + def delete_file(name): if os.path.exists(name): os.remove(name) @@ -103,7 +107,6 @@ def get_driveletters(): # run: '& "C:\Program Files\OpenZFS On Windows\zfs.exe" mount' - def create_pool(name, file): magic_number_process = subprocess.run( ["C:\\Program Files\\OpenZFS On Windows\\zpool.exe", "create", "-f", name, file], @@ -112,7 +115,6 @@ def create_pool(name, file): ) - def destroy_pool(name): magic_number_process = subprocess.run( ["C:\\Program Files\\OpenZFS On Windows\\zpool.exe", "destroy", "-f", name], @@ -120,6 +122,7 @@ def destroy_pool(name): stderr=subprocess.PIPE ) + def zpool(*args): magic_number_process = subprocess.run( ["C:\\Program Files\\OpenZFS On Windows\\zpool.exe", *args], @@ -153,15 +156,11 @@ def run(args): return result - def tounc(name): q = "\\\\?\\" + str(name) return q - - - def runWithPrint(cmd): print(" ".join(cmd)) ret = run(cmd) @@ -170,9 +169,9 @@ def runWithPrint(cmd): logging.debug(str("stdout={}".format(ret.stdout))) logging.debug(str("stderr={}".format(ret.stderr))) - return ret + def preTest(testName = None): print("=" * 20) if testName is not None: @@ -180,10 +179,12 @@ def preTest(testName = None): get_driveletters() + def postTest(): get_driveletters() print("=" * 20) + def main(): parsed_args = parse_arguments() @@ -204,12 +205,6 @@ def main(): f3 = PureWindowsPath(p, "test03.dat") allocate_file(f3, 1024*1024*1024) - - - - - - preTest() ret = runWithPrint(["zpool", "create", "-f", "test01", tounc(f1)]) time.sleep(10) @@ -220,10 +215,6 @@ def main(): time.sleep(10) postTest() - - - - preTest() ret = runWithPrint(["zpool", "create", "-f", "test02", tounc(f1), tounc(f2)]) if ret.returncode != 0: @@ -234,10 +225,6 @@ def main(): time.sleep(10) postTest() - - - - preTest() ret = runWithPrint(["zpool", "create", "-f", "test03", tounc(f1), tounc(f2), tounc(f3)]) if ret.returncode != 0: @@ -248,10 +235,6 @@ def main(): time.sleep(10) postTest() - - - - preTest() ret = runWithPrint(["zpool", "create", "-f", "test04", "mirror", tounc(f1), tounc(f2)]) if ret.returncode != 0: @@ -262,10 +245,6 @@ def main(): time.sleep(10) postTest() - - - - preTest() ret = runWithPrint(["zpool", "create", "-f", "test05", "mirror", tounc(f1), tounc(f2), tounc(f3)]) time.sleep(10) @@ -276,10 +255,6 @@ def main(): time.sleep(10) postTest() - - - - preTest() ret = runWithPrint(["zpool", "create", "-f", "test06", "raidz", tounc(f1), tounc(f2), tounc(f3)]) if ret.returncode != 0: @@ -290,10 +265,6 @@ def main(): time.sleep(10) postTest() - - - - preTest() ret = runWithPrint(["zpool", "create", "-f", "test07", "raidz1", tounc(f1), tounc(f2), tounc(f3)]) if ret.returncode != 0: @@ -304,23 +275,6 @@ def main(): time.sleep(10) postTest() - - - - - - - - - - - - - - - - - preTest("snapshot no hang:") ret = runWithPrint(["zpool", "create", "-f", "testsn01", tounc(f1)]) @@ -349,11 +303,6 @@ def main(): time.sleep(10) postTest() - - - - - # preTest("snapshot hang") # # ret = runWithPrint(["zpool", "create", "-f", "testsn02", tounc(f1)]) @@ -387,43 +336,6 @@ def main(): # time.sleep(10) # postTest() - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - preTest("regex for key file") random_bytearray = bytearray(os.urandom(32)) @@ -436,7 +348,6 @@ def main(): nx ="file://" + tounc(key01).replace("\\", "/") print(nx) - ret = runWithPrint(["zpool", "create", "-f", "-O", "encryption=aes-256-ccm", "-O", "keylocation=" + nx, "-O", "keyformat=raw", "tank", tounc(f1)]) if ret.returncode != 0: print("FAIL") @@ -452,36 +363,17 @@ def main(): print("FAIL") time.sleep(10) - - - - - - print("Drive letters before pool create:", get_driveletters()) ret = runWithPrint(["zpool", "import", "-f", "-l", "-O", "encryption=aes-256-ccm", "-O", "keylocation=" + nx, "-O", "keyformat=raw", tounc(f1)]) if ret.returncode != 0: print("FAIL") time.sleep(10) - print("Drive letters after pool create:", get_driveletters()) runWithPrint(["zpool", "destroy", "-f", "tank"]) time.sleep(10) postTest() - - - - - - - - - - - - preTest("run out of drive letters") for i in range(1, 26): @@ -501,27 +393,11 @@ def main(): runWithPrint(["zpool", "destroy", "-f", "tank" + str(i)]) time.sleep(10) - postTest() - - - - - - - delete_file(f1) delete_file(f2) delete_file(f3) - - - if __name__ == "__main__": main() - - - - -