Skip to content

Commit

Permalink
Enable Windows CI tests
Browse files Browse the repository at this point in the history
In order to run tests on Windows, Intel OpenCL runtime needs to be
installed to run the tests on a compute device. It is also required to
create a configuration file so that the tests are run on the CPU instead
of a GPU (since there are no GPU available in azure-pipelines)

Added update environment script in order to load the latest environment
variables set by `Zivid-SDK` after successful installation. `PATH`
environment variable must be updated befre running the tests.

Ignored sample testing for windows, because of the following error:
```
python: can't open file 'D:\a\samples\sample_print_version_info.py': [Errno 2] No such file or directory
```

Ignored `winreg` import error, this module is not available on Linux
  • Loading branch information
Trym Bremnes authored and trym-b committed Jul 14, 2020
1 parent 8e41840 commit 3f85f26
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 10 deletions.
42 changes: 42 additions & 0 deletions continuous-integration/windows/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,51 @@ def _install_zivid_sdk():
_run_process((str(zivid_installer), "/S"))


def _install_intel_opencl_runtime():
import requests # pylint: disable=import-outside-toplevel

with tempfile.TemporaryDirectory() as temp_dir:
intel_opencl_runtime_url = "https://www.dropbox.com/s/09bk2nx31hzrupf/opencl_runtime_18.1_x64_setup-20200625-090300.msi?raw=1"
print("Downloading {}".format(intel_opencl_runtime_url), flush=True)
opencl_runtime = Path(temp_dir) / "opencl_runtime.msi"
response = requests.get(intel_opencl_runtime_url)
opencl_runtime.write_bytes(response.content)
print("Installing {}".format(opencl_runtime), flush=True)
_run_process(("msiexec", "/i", str(opencl_runtime), "/passive"))


def _write_zivid_cpu_configuration_file():
content = """__version__: 4
Configuration:
ComputeDevice:
SelectionFilter: ""
Type: CPU
Vendor: Any
DriverConfig:
ToshibaTeli:
VersionCheck: yes
Logging:
Asynchronous: yes
CrashHandler: yes
Directory: ""
Enabled: yes
FlushOnExit: yes
HistorySize: 30
MaxFileSizeMB: 50
MaxTotalSizeMB: 1000
RotationCount: 2
WriteInterval: 0
"""
filepath = Path(r"C:\Users\VssAdministrator\AppData\Local\Zivid\API\Config.yml")
filepath.parent.mkdir(parents=True, exist_ok=True)
filepath.write_text(content)


def _main():
_install_pip_dependencies()
_install_intel_opencl_runtime()
_install_zivid_sdk()
_write_zivid_cpu_configuration_file()


if __name__ == "__main__":
Expand Down
39 changes: 29 additions & 10 deletions continuous-integration/windows/test.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import argparse
import sys
import subprocess
import winreg # pylint: disable=import-error
from os import environ
from pathlib import Path


Expand All @@ -10,10 +12,10 @@ def _options():
return parser.parse_args()


def _run_process(args):
def _run_process(args, env=None):
sys.stdout.flush()
try:
process = subprocess.Popen(args)
process = subprocess.Popen(args, env=env)
exit_code = process.wait()
if exit_code != 0:
raise RuntimeError("Wait failed with exit code {}".format(exit_code))
Expand All @@ -23,24 +25,41 @@ def _run_process(args):
sys.stdout.flush()


def _read_sys_env(environement_variable_name):
key = winreg.CreateKey(
winreg.HKEY_LOCAL_MACHINE,
r"System\CurrentControlSet\Control\Session Manager\Environment",
)
return winreg.QueryValueEx(key, environement_variable_name)[0]


def _test(root):
environment = environ.copy()
sys_path_key = "PATH"
sys_path_value = _read_sys_env(sys_path_key)
environment[sys_path_key] = sys_path_value
_run_process(
("python", "-m", "pytest", str(root), "-c", str(root / "pytest.ini"),),
env=environment,
)


def _install_pip_dependencies():
print("Installing python test requirements", flush=True)
_run_process(
(
"echo",
"TODO: ",
"python",
"-m",
"pytest",
str(root),
"-c",
str(root / "pytest.ini"),
"pip",
"install",
"--requirement",
"continuous-integration/python-requirements/test.txt",
)
)


def _main():
options = _options()

_install_pip_dependencies()
_test(options.root)


Expand Down
10 changes: 10 additions & 0 deletions test/test_samples.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,21 @@
import platform

import pytest


@pytest.mark.skipif(
platform.system() == "Windows",
reason=r"python: can't open file 'D:\a\samples\sample_capture_from_file.py': [Errno 2] No such file or directory",
)
def test_capture_from_file(sample_data_file):
pytest.helpers.run_sample(
name="capture_from_file", working_directory=sample_data_file.parent
)


@pytest.mark.skipif(
platform.system() == "Windows",
reason=r"python: can't open file 'D:\a\samples\sample_print_version_info.py': [Errno 2] No such file or directory",
)
def test_print_version_info():
pytest.helpers.run_sample(name="print_version_info")

0 comments on commit 3f85f26

Please sign in to comment.