Test timetest MVP (#2345)
This commit is contained in:
parent
5e4cd10568
commit
d48d2109dc
@ -21,6 +21,11 @@ cmake .. -DInferenceEngineDeveloperPackage_DIR=$(realpath ../../../build) && mak
|
||||
|
||||
2. Run test:
|
||||
``` bash
|
||||
./scripts/run_timetest.py ../../../bin/intel64/Release/timetest_infer -m model.xml -d CPU
|
||||
./scripts/run_timetest.py ../../bin/intel64/Release/timetest_infer -m model.xml -d CPU
|
||||
```
|
||||
|
||||
2. Run several configurations using `pytest`:
|
||||
``` bash
|
||||
export PYTHONPATH=./:$PYTHONPATH
|
||||
pytest ./test_runner/test_timetest.py --exe ../../bin/intel64/Release/timetest_infer
|
||||
```
|
||||
|
1
tests/time_tests/scripts/requirements.txt
Normal file
1
tests/time_tests/scripts/requirements.txt
Normal file
@ -0,0 +1 @@
|
||||
PyYAML==5.3.1
|
98
tests/time_tests/test_runner/conftest.py
Normal file
98
tests/time_tests/test_runner/conftest.py
Normal file
@ -0,0 +1,98 @@
|
||||
# Copyright (C) 2020 Intel Corporation
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
#
|
||||
"""
|
||||
Basic high-level plugin file for pytest.
|
||||
|
||||
See [Writing plugins](https://docs.pytest.org/en/latest/writing_plugins.html)
|
||||
for more information.
|
||||
|
||||
This plugin adds the following command-line options:
|
||||
|
||||
* `--test_conf` - Path to test configuration file. Used to parametrize tests.
|
||||
Format: YAML file.
|
||||
* `--exe` - Path to a timetest binary to execute.
|
||||
* `--niter` - Number of times to run executable.
|
||||
"""
|
||||
|
||||
# pylint:disable=import-error
|
||||
import pytest
|
||||
from pathlib import Path
|
||||
import yaml
|
||||
|
||||
from test_runner.utils import expand_env_vars
|
||||
|
||||
|
||||
# -------------------- CLI options --------------------
|
||||
|
||||
def pytest_addoption(parser):
|
||||
"""Specify command-line options for all plugins"""
|
||||
parser.addoption(
|
||||
"--test_conf",
|
||||
type=Path,
|
||||
help="Path to test config",
|
||||
default=Path(__file__).parent / "test_config.yml"
|
||||
)
|
||||
parser.addoption(
|
||||
"--exe",
|
||||
required=True,
|
||||
dest="executable",
|
||||
type=Path,
|
||||
help="Path to a timetest binary to execute",
|
||||
)
|
||||
parser.addoption(
|
||||
"--niter",
|
||||
type=int,
|
||||
help="Number of iterations to run executable and aggregate results",
|
||||
default=3
|
||||
)
|
||||
# TODO: add support of --mo, --omz etc. required for OMZ support
|
||||
|
||||
|
||||
@pytest.fixture(scope="session")
|
||||
def test_conf(request):
|
||||
"""Fixture function for command-line option."""
|
||||
return request.config.getoption('test_conf')
|
||||
|
||||
|
||||
@pytest.fixture(scope="session")
|
||||
def executable(request):
|
||||
"""Fixture function for command-line option."""
|
||||
return request.config.getoption('executable')
|
||||
|
||||
|
||||
@pytest.fixture(scope="session")
|
||||
def niter(request):
|
||||
"""Fixture function for command-line option."""
|
||||
return request.config.getoption('niter')
|
||||
|
||||
# -------------------- CLI options --------------------
|
||||
|
||||
|
||||
def pytest_generate_tests(metafunc):
|
||||
"""Pytest hook for test generation.
|
||||
|
||||
Generate parameterized tests from discovered modules and test config
|
||||
parameters.
|
||||
"""
|
||||
with open(metafunc.config.getoption('test_conf'), "r") as file:
|
||||
test_cases = expand_env_vars(yaml.safe_load(file))
|
||||
if test_cases:
|
||||
metafunc.parametrize("instance", test_cases)
|
||||
|
||||
|
||||
def pytest_make_parametrize_id(config, val, argname):
|
||||
"""Pytest hook for user-friendly test name representation"""
|
||||
|
||||
def get_dict_values(d):
|
||||
"""Unwrap dictionary to get all values of nested dictionaries"""
|
||||
if isinstance(d, dict):
|
||||
for v in d.values():
|
||||
yield from get_dict_values(v)
|
||||
else:
|
||||
yield d
|
||||
|
||||
keys = val.keys()
|
||||
values = list(get_dict_values(val))
|
||||
|
||||
return "-".join(["_".join([key, val]) for key, val in zip(keys, values)])
|
3
tests/time_tests/test_runner/requirements.txt
Normal file
3
tests/time_tests/test_runner/requirements.txt
Normal file
@ -0,0 +1,3 @@
|
||||
pytest==4.0.1
|
||||
attrs==19.1.0 # required for pytest==4.0.1 to resolve compatibility issues
|
||||
PyYAML==5.3.1
|
8
tests/time_tests/test_runner/test_config.yml
Normal file
8
tests/time_tests/test_runner/test_config.yml
Normal file
@ -0,0 +1,8 @@
|
||||
- device:
|
||||
name: CPU
|
||||
model:
|
||||
path: ${SHARE}/stress_tests/master_04d6f112132f92cab563ae7655747e0359687dc9/caffe/FP32/alexnet/alexnet.xml # TODO: add link to `test_data` repo model
|
||||
- device:
|
||||
name: GPU
|
||||
model:
|
||||
path: ${SHARE}/stress_tests/master_04d6f112132f92cab563ae7655747e0359687dc9/caffe/FP32/alexnet/alexnet.xml
|
@ -1 +1,42 @@
|
||||
#TODO: fill
|
||||
# Copyright (C) 2020 Intel Corporation
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
#
|
||||
"""Main entry-point to run timetests tests.
|
||||
|
||||
Default run:
|
||||
$ pytest test_timetest.py
|
||||
|
||||
Options[*]:
|
||||
--test_conf Path to test config
|
||||
--exe Path to timetest binary to execute
|
||||
--niter Number of times to run executable
|
||||
|
||||
[*] For more information see conftest.py
|
||||
"""
|
||||
|
||||
from pathlib import Path
|
||||
import logging
|
||||
|
||||
from scripts.run_timetest import run_timetest
|
||||
|
||||
|
||||
def test_timetest(instance, executable, niter):
|
||||
"""Parameterized test.
|
||||
|
||||
:param instance: test instance
|
||||
:param executable: timetest executable to run
|
||||
:param niter: number of times to run executable
|
||||
"""
|
||||
# Prepare model to get model_path
|
||||
model_path = instance["model"].get("path")
|
||||
assert model_path, "Model path is empty"
|
||||
|
||||
# Run executable
|
||||
exe_args = {
|
||||
"executable": Path(executable),
|
||||
"model": Path(model_path),
|
||||
"device": instance["device"]["name"],
|
||||
"niter": niter
|
||||
}
|
||||
retcode, aggr_stats = run_timetest(exe_args, log=logging)
|
||||
assert retcode == 0, "Run of executable failed"
|
||||
|
20
tests/time_tests/test_runner/utils.py
Normal file
20
tests/time_tests/test_runner/utils.py
Normal file
@ -0,0 +1,20 @@
|
||||
# Copyright (C) 2020 Intel Corporation
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
#
|
||||
"""Utility module."""
|
||||
|
||||
import os
|
||||
|
||||
|
||||
def expand_env_vars(obj):
|
||||
"""Expand environment variables in provided object."""
|
||||
|
||||
if isinstance(obj, list):
|
||||
for i, value in enumerate(obj):
|
||||
obj[i] = expand_env_vars(value)
|
||||
elif isinstance(obj, dict):
|
||||
for name, value in obj.items():
|
||||
obj[name] = expand_env_vars(value)
|
||||
else:
|
||||
obj = os.path.expandvars(obj)
|
||||
return obj
|
Loading…
Reference in New Issue
Block a user