Skip to content

Commit

Permalink
Activate OV environment from cond comp test_infer
Browse files Browse the repository at this point in the history
  • Loading branch information
Somsikov, Andrey committed Feb 9, 2021
1 parent 2c4c3a7 commit 81fb4db
Show file tree
Hide file tree
Showing 3 changed files with 24 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
10 changes: 7 additions & 3 deletions tests/conditional_compilation/test_infer.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,17 @@
""" Test inference with conditional compiled binaries.
"""

from proc_utils import cmd_exec # pylint: disable=import-error
from proc_utils import cmd_exec, get_env_from # 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'
benchmark_app = str(install_prefix / 'bin' / 'benchmark_app')
env = get_env_from(install_prefix / 'bin' / 'setupvars.sh')
returncode, _ = cmd_exec(
[str(benchmark_app), "-d=CPU", f"-m={model}", "-niter=1", "-nireq=1"]
[str(benchmark_app), "-d=CPU", f"-m={str(model)}", "-niter=1", "-nireq=1"],
env=env,
)
assert returncode == 0, f"Command exited with non-zero status {returncode}"
18 changes: 17 additions & 1 deletion tests/lib/proc_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,22 @@
import subprocess


def cmd_exec(args, log=None, verbose=True):
def get_env_from(activate_script):
""" Get environment set by an activate_script
"""
env = {}
dump = subprocess.check_output(
f'source "{activate_script}" && env', 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] and pair[1] is not None: # exclude 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 +37,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 81fb4db

Please sign in to comment.