diff --git a/.github/workflows/windows-build-test.yml b/.github/workflows/windows-build-test.yml index 262cb4f1511f..dc23b9145474 100644 --- a/.github/workflows/windows-build-test.yml +++ b/.github/workflows/windows-build-test.yml @@ -2526,3 +2526,209 @@ jobs: + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +# This is a basic workflow to help you get started with Actions +# https://github.blog/changelog/2020-07-06-github-actions-manual-triggers-with-workflow_dispatch/ + + test8_pyifstest: + needs: [build_windows] #, build_wsl] + timeout-minutes: 30 + runs-on: windows-latest +# if: ${{ inputs.run-failing }} + steps: + + - uses: actions/checkout@v3 + + + - uses: actions/download-artifact@v3 + with: + name: dev_build_inno + +# - uses: actions/download-artifact@v3 +# with: +# name: build result + +# - name: get files +# run: Get-ChildItem -Recurse + + - name: get diskdrive + run: wmic diskdrive list + +# - name: Download +# uses: suisei-cn/actions-download-file@v1.3.0 +# #id: innoinstaller +# with: +# url: 'https://github.com/andrewc12/zfsfiledump/raw/main/testdrives.zip' +# target: ${{github.workspace}}/ +# +# +# - name: make disk +# run: | +# Expand-Archive -LiteralPath ${{github.workspace}}/testdrives.zip -DestinationPath D:\ +# +# - name: Download +# uses: suisei-cn/actions-download-file@v1.3.0 +# #id: innoinstaller +# with: +# url: 'https://github.com/andrewc12/zfsfiledump/raw/main/scriptname.txt' +# target: ${{github.workspace}}/ +# +# - name: make disk +# run: | +# diskpart /s scriptname.txt +# +# +# +# - name: get diskdrive +# run: wmic diskdrive list +# +# +# - name: get files +# run: Get-ChildItem -Recurse + + + - name: get zfsexename + id: zfsinstaller + run: | + $p = Get-ChildItem | Where-Object {$_.Name -like 'OpenZFSOnWindows-*.exe'} | Select-Object -first 1 + echo $p + $f = (Get-Item $p ).Name + echo $f + echo "filename=$f" | Out-File -FilePath $Env:GITHUB_OUTPUT -Encoding utf8 -Append + + # https://github.com/MicrosoftDocs/windows-powershell-docs/issues/266 + - name: Import root certificate + run: | + $plaintextpwd = 'password1234' + $pwd = ConvertTo-SecureString -String $plaintextpwd -Force -AsPlainText + Import-PfxCertificate -FilePath ${{github.workspace}}/contrib/windows/TestCert/test_sign_cert_pass.pfx -CertStoreLocation Cert:\LocalMachine\Root -Password $pwd + Import-PfxCertificate -FilePath ${{github.workspace}}/contrib/windows/TestCert/test_sign_cert_pass.pfx -CertStoreLocation Cert:\LocalMachine\TrustedPublisher -Password $pwd + + - name: debug - echo filename + run: echo ${{ steps.zfsinstaller.outputs.filename }} + +# - name: debug - list +# run: ls ${{github.workspace}}\ + + - name: debug - list + run: ls ${{github.workspace}}\${{ steps.zfsinstaller.outputs.filename }} + + #- name: install zfs + # run: ${{github.workspace}}\${{ steps.zfsinstaller.outputs.filename }} /NORESTART /ALLUSERS /VERYSILENT /LOG="${{github.workspace}}\InnoSetup-Install.log" + + - name: install zfs + run: 'Start-Process -FilePath "${{github.workspace}}\${{ steps.zfsinstaller.outputs.filename }}" -Wait -ArgumentList "/NORESTART /ALLUSERS /VERYSILENT /LOG=`"${{github.workspace}}\InnoSetup-Install.log`""' + + #- name: Wait for install to finish + # run: Start-Sleep -Seconds 30 + # uses: iFaxity/wait-on-action@v1 + # with: + # resource: 'C:\Program Files\OpenZFS On Windows\zpool.exe' + +# - name: debug - print log +# run: cat "${{github.workspace}}\InnoSetup-Install.log" +# +# - name: debug - list +# run: ls "C:\Program Files" +# +# - name: debug - list +# run: ls "C:\Program Files\OpenZFS On Windows" + + - name: debug - get status + run: '& "C:\Program Files\OpenZFS On Windows\zpool.exe" status' + + + + + + + + - name: Download ifstest + uses: suisei-cn/actions-download-file@v1.3.0 + id: winbtrs # Remember to give an ID if you need the output filename + with: + url: "https://github.com/andrewc12/ifstest/raw/main/ifs_test_kit.zip" + target: ${{github.workspace}}/ + + - name: extract + run: Expand-Archive -LiteralPath '${{ steps.winbtrs.outputs.filename }}' -DestinationPath ${{github.workspace}}\ifs_test_kit + + - name: debug - list + run: ls ${{github.workspace}}\ + + - name: debug - list + run: ls ${{github.workspace}}\ifs_test_kit + + + + + + - name: test + run: 'python.exe -u "${{github.workspace}}\contrib\windows\tests\ifstest.py" -path ${{github.workspace}}\' + + - name: Adding markdown + run: | + cat ${{github.workspace}}\ifstest.log | Out-File $env:GITHUB_STEP_SUMMARY + + - name: Upload a Build Artifact + uses: actions/upload-artifact@v3.1.0 + with: + name: build_output + path: ${{github.workspace}}/ifstest.log + + + + - name: Upload a Build Artifact + uses: actions/upload-artifact@v3.1.0 + with: + name: build_output + path: ${{github.workspace}}/TestResults.log + + + + + + + + + + + diff --git a/contrib/windows/tests/ifstest.py b/contrib/windows/tests/ifstest.py new file mode 100644 index 000000000000..d57417e69991 --- /dev/null +++ b/contrib/windows/tests/ifstest.py @@ -0,0 +1,266 @@ +import os +import argparse + +import subprocess + +# from pathlib import Path, PurePosixPath, PureWindowsPath, WindowsPath +from pathlib import PureWindowsPath + +# from pprint import pprint + +import time + + +# import json + +import logging + +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 + else: + raise argparse.ArgumentTypeError(f"readable_dir:{path} is not a valid" + "path") + + +def get_DeviceId(): + magic_number_process = subprocess.run( + ["wmic", "diskdrive", "get", "DeviceId"], + stdout=subprocess.PIPE, + stderr=subprocess.PIPE + ) + +# https://github.com/sir-ragna/dddddd +# get DeviceId + + a = magic_number_process.stdout.decode(encoding='UTF-8', errors='strict') + b = a.replace("\r\r\n", "\r\n") + + c = b.splitlines() + + d = [x.split() for x in c] + + e = [x[0] for x in d if len(x) > 0 and x[0] not in "DeviceID"] + + e.sort() + +# print(e) + +# print([x.encode(encoding='UTF-8') for x in e]) + +# import csv + +# with open('csv_file.csv', 'w', encoding='UTF8') as f: +# writer = csv.writer(f, dialect='excel', quoting=csv.QUOTE_ALL) +# +# for row in e: +# writer.writerow([row]) + + 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) + else: + print("The file does not exist") + + +def get_driveletters(): + magic_number_process = subprocess.run( + ["C:\\Program Files\\OpenZFS On Windows\\zfs.exe", "mount"], + stdout=subprocess.PIPE, + stderr=subprocess.PIPE + ) + +# b'test01 H:\\ \r\ntest02 I:\\ \r\n' + + a = magic_number_process.stdout.decode(encoding='UTF-8', errors='strict') + + c = a.splitlines() + + logging.debug("get_driveletters() {}".format(c)) + +# print("get_driveletters() debug",c) + + d = [x.split() for x in c] + + logging.debug("get_driveletters() {}".format(d)) + + return d + +# 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], + stdout=subprocess.PIPE, + stderr=subprocess.PIPE + ) + + return magic_number_process + + +def destroy_pool(name): + magic_number_process = subprocess.run( + ["C:\\Program Files\\OpenZFS On Windows\\zpool.exe", + "destroy", "-f", name], + stdout=subprocess.PIPE, + stderr=subprocess.PIPE + ) + + return magic_number_process + + +def zpool(*args): + magic_number_process = subprocess.run( + ["C:\\Program Files\\OpenZFS On Windows\\zpool.exe", *args], + stdout=subprocess.PIPE, + stderr=subprocess.PIPE + ) + + return magic_number_process + + +def zfs(*args): + magic_number_process = subprocess.run( + ["C:\\Program Files\\OpenZFS On Windows\\zfs.exe", *args], + stdout=subprocess.PIPE, + stderr=subprocess.PIPE + ) + + return magic_number_process + + +def run(args): + d = {"zfs": "C:\\Program Files\\OpenZFS On Windows\\zfs.exe", + "zpool": "C:\\Program Files\\OpenZFS On Windows\\zpool.exe"} + arglist = list(args) + try: + cmd = d[arglist[0]] + except Exception: + cmd = arglist[0] + result = subprocess.run( + [cmd, *arglist[1:]], + stdout=subprocess.PIPE, + stderr=subprocess.PIPE + ) + + return result + + +def tounc(name): + q = "\\\\?\\" + str(name) + return q + + +def runWithPrint(cmd): + print(" ".join(cmd)) + ret = run(cmd) + logging.debug(str("args={}".format(" ".join(ret.args)))) + logging.debug(str("returncode={}".format(ret.returncode))) + 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: + print("Name:", testName) + + get_driveletters() + + +def postTest(): + get_driveletters() + print("=" * 20) + + +def main(): + parsed_args = parse_arguments() + + print("Path:", parsed_args.path) + + p = PureWindowsPath(parsed_args.path) + + print("Path object:", p) + + print("Physical devices", get_DeviceId()) + + if p.is_absolute(): + + f1 = PureWindowsPath(p, "test01.dat") + allocate_file(f1, 1024*1024*1024) + + with open(str(p.joinpath("ifstest.log")), "w") as log_file: + + preTest() + ret = runWithPrint(["zpool", "create", "-f", "test01", tounc(f1)]) + time.sleep(10) + if ret.returncode != 0: + print("FAIL") + print("Drive letters after pool create:", get_driveletters()) + time.sleep(10) + postTest() + + for test in ['Test']: + preTest(str(test) + " tests:") + f = PureWindowsPath(get_driveletters()[0][1]) + ret = runWithPrint([str(p.joinpath("ifs_test_kit", "ifstest.exe")), '-g', 'Virus', str(f), '/n', '.\\' + str(test) + 'Results.log', '/N', '356789AB', '/T', '/p', '/m', '/E', '-R', '/j', '/r', 'c:', '-d', '\\Ntfs', '-a', '\\datacoh.exe', '/u', 'ifstest', '/U', '*rw53w52']) + + time.sleep(10) + if ret.returncode != 0: + print("FAIL") + postTest() + + print(ret.stdout.decode()) + + lines = ret.stdout.decode().splitlines() + outlines = [] + ignoreflag = True + for line in lines[13:]: + if "------------------" in line: + outlines.append("\n") + else: + outlines.append(line) + + + out = str(test) + "\n" + "\n".join(outlines) + + print(out) + log_file.write(out) + log_file.write("\n") + + preTest() +# runWithPrint(["zpool", "destroy", "-f", "test01"]) + time.sleep(10) + postTest() + +# delete_file(f1) + + +if __name__ == "__main__": + main()