Skip to content

Commit

Permalink
Activate OV environment from cond comp test_infer (#4244)
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrey Somsikov authored Feb 11, 2021
1 parent b7212b9 commit 8da7f22
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 7 deletions.
3 changes: 0 additions & 3 deletions tests/conditional_compilation/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,19 +38,16 @@ def pytest_addoption(parser):
)
parser.addoption(
"--sea_runtool",
required=True,
type=Path,
help="Path to sea_runtool.py"
)
parser.addoption(
"--benchmark_app",
required=True,
type=Path,
help="Path to the benchmark_app tool",
)
parser.addoption(
"--collector_dir",
required=True,
type=Path,
help="Path to a directory with a collector binary",
)
Expand Down
11 changes: 8 additions & 3 deletions tests/conditional_compilation/test_infer.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,19 @@

""" Test inference with conditional compiled binaries.
"""

import sys
from proc_utils import cmd_exec # pylint: disable=import-error
from install_pkg import get_openvino_environment # pylint: disable=import-error


def test_infer(model, benchmark_app):
def test_infer(test_id, model, artifacts):
""" Test inference with conditional compiled binaries
"""
install_prefix = artifacts / test_id / "install_pkg"
exe_suffix = ".exe" if sys.platform == "win32" else ""
benchmark_app = install_prefix / "bin" / f"benchmark_app{exe_suffix}"
returncode, _ = cmd_exec(
[str(benchmark_app), "-d=CPU", f"-m={model}", "-niter=1", "-nireq=1"]
[str(benchmark_app), "-d=CPU", f"-m={model}", "-niter=1", "-nireq=1"],
env=get_openvino_environment(install_prefix),
)
assert returncode == 0, f"Command exited with non-zero status {returncode}"
16 changes: 16 additions & 0 deletions tests/lib/install_pkg.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/usr/bin/env python3
# Copyright (C) 2021 Intel Corporation
# SPDX-License-Identifier: Apache-2.0

""" Common utilities for OpenVINO install package.
"""
import sys
from pathlib import Path
from proc_utils import get_env_from # pylint: disable=import-error


def get_openvino_environment(install_prefix: Path):
""" Get OpenVINO environment variables
"""
script = "setupvars.bat" if sys.platform == "win32" else "setupvars.sh"
return get_env_from(install_prefix / "bin" / script)
25 changes: 24 additions & 1 deletion tests/lib/proc_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,33 @@
""" Common utilities for working with processes.
"""

import errno
import os
import logging
import subprocess
import sys


def cmd_exec(args, log=None, verbose=True):
def get_env_from(script):
""" Get environment set by a shell script
"""
if not os.path.exists(str(script)):
raise FileNotFoundError(errno.ENOENT, os.strerror(errno.ENOENT), str(script))
env = {}
if sys.platform == "win32":
cmd = f'"{script}" && set'
else:
cmd = f'source "{script}" && env'
dump = subprocess.check_output(cmd, shell=True, universal_newlines=True).strip()
for line in dump.split("\n"):
# split by first '='
pair = [str(val).strip() for val in line.split("=", 1)]
if len(pair) > 1 and pair[0]: # ignore invalid entries
env[pair[0]] = pair[1]
return env


def cmd_exec(args, env=None, log=None, verbose=True):
""" Run cmd using subprocess with logging and other improvements
"""
if log is None:
Expand All @@ -22,6 +44,7 @@ def cmd_exec(args, log=None, verbose=True):

proc = subprocess.Popen(
args,
env=env,
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT,
encoding="utf-8",
Expand Down

0 comments on commit 8da7f22

Please sign in to comment.