Add json file with tests ids to CC tests (#4425)
This commit is contained in:
parent
a26aad1cfa
commit
83ec2d321a
@ -14,23 +14,22 @@ python3 -m pytest --artifacts ./compiled --test_conf=<path to test config> \
|
||||
"""
|
||||
|
||||
import sys
|
||||
from inspect import getsourcefile
|
||||
from pathlib import Path
|
||||
|
||||
import pytest
|
||||
import yaml
|
||||
|
||||
from inspect import getsourcefile
|
||||
from pathlib import Path
|
||||
|
||||
from tests_utils import write_session_info, SESSION_INFO_FILE
|
||||
|
||||
# add ../lib to imports
|
||||
sys.path.insert(
|
||||
0, str((Path(getsourcefile(lambda: 0)) / ".." / ".." / "lib").resolve(strict=True))
|
||||
)
|
||||
sys.path.insert(0, str((Path(getsourcefile(lambda: 0)) / ".." / ".." / "lib").resolve(strict=True)))
|
||||
|
||||
from path_utils import expand_env_vars # pylint: disable=import-error
|
||||
|
||||
|
||||
def pytest_addoption(parser):
|
||||
""" Define extra options for pytest options
|
||||
"""
|
||||
"""Define extra options for pytest options."""
|
||||
parser.addoption(
|
||||
"--test_conf",
|
||||
type=Path,
|
||||
@ -67,8 +66,7 @@ def pytest_addoption(parser):
|
||||
|
||||
|
||||
def pytest_generate_tests(metafunc):
|
||||
""" Generate tests depending on command line options
|
||||
"""
|
||||
"""Generate tests depending on command line options."""
|
||||
params = []
|
||||
ids = []
|
||||
|
||||
@ -87,6 +85,25 @@ def pytest_generate_tests(metafunc):
|
||||
metafunc.parametrize("test_id, model", params, ids=ids)
|
||||
|
||||
|
||||
@pytest.fixture(scope="function")
|
||||
def test_info(request, pytestconfig):
|
||||
"""Fixture function for getting the additional attributes of the current test."""
|
||||
setattr(request.node._request, "test_info", {})
|
||||
if not hasattr(pytestconfig, "session_info"):
|
||||
setattr(pytestconfig, "session_info", [])
|
||||
|
||||
yield request.node._request.test_info
|
||||
|
||||
pytestconfig.session_info.append(request.node._request.test_info)
|
||||
|
||||
|
||||
@pytest.fixture(scope="session", autouse=True)
|
||||
def save_session_info(pytestconfig, artifacts):
|
||||
"""Fixture function for saving additional attributes to configuration file."""
|
||||
yield
|
||||
write_session_info(path=artifacts / SESSION_INFO_FILE, data=pytestconfig.session_info)
|
||||
|
||||
|
||||
@pytest.fixture(scope="session")
|
||||
def sea_runtool(request):
|
||||
"""Fixture function for command-line option."""
|
||||
|
@ -13,16 +13,19 @@ import sys
|
||||
from proc_utils import cmd_exec # pylint: disable=import-error
|
||||
|
||||
|
||||
def test_cc_collect(test_id, model, sea_runtool, benchmark_app, collector_dir, artifacts):
|
||||
def test_cc_collect(test_id, model, sea_runtool, benchmark_app, collector_dir, artifacts, test_info):
|
||||
""" Test conditional compilation statistics collection
|
||||
:param test_info: custom `test_info` field of built-in `request` pytest fixture.
|
||||
contain a dictionary to store test metadata.
|
||||
"""
|
||||
out = artifacts / test_id
|
||||
test_info["test_id"] = test_id
|
||||
# cleanup old data if any
|
||||
prev_results = glob.glob(f"{out}.pid*.csv")
|
||||
for path in prev_results:
|
||||
prev_result = glob.glob(f"{out}.pid*.csv")
|
||||
for path in prev_result:
|
||||
os.remove(path)
|
||||
# run use case
|
||||
returncode, output = cmd_exec(
|
||||
return_code, output = cmd_exec(
|
||||
[
|
||||
sys.executable,
|
||||
str(sea_runtool),
|
||||
@ -37,7 +40,8 @@ def test_cc_collect(test_id, model, sea_runtool, benchmark_app, collector_dir, a
|
||||
"-nireq=1",
|
||||
]
|
||||
)
|
||||
assert returncode == 0, f"Command exited with non-zero status {returncode}:\n {output}"
|
||||
assert (
|
||||
len(glob.glob(f"{out}.pid*.csv")) == 1
|
||||
), f'Multiple or none "{out}.pid*.csv" files'
|
||||
out_csv = glob.glob(f"{out}.pid*.csv")
|
||||
test_info["out_csv"] = out_csv
|
||||
|
||||
assert return_code == 0, f"Command exited with non-zero status {return_code}:\n {output}"
|
||||
assert (len(out_csv) == 1), f'Multiple or none "{out}.pid*.csv" files'
|
||||
|
25
tests/conditional_compilation/tests_utils.py
Normal file
25
tests/conditional_compilation/tests_utils.py
Normal file
@ -0,0 +1,25 @@
|
||||
#!/usr/bin/env python3
|
||||
# Copyright (C) 2021 Intel Corporation
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
""" Utility functions for work with json test configuration file.
|
||||
"""
|
||||
import json
|
||||
|
||||
from inspect import getsourcefile
|
||||
from pathlib import Path
|
||||
|
||||
|
||||
SESSION_INFO_FILE = "cc_tests.json"
|
||||
|
||||
|
||||
def read_session_info(path: Path = Path(getsourcefile(lambda: 0)).parent / SESSION_INFO_FILE):
|
||||
with open(path, 'r') as json_file:
|
||||
cc_tests_ids = json.load(json_file)
|
||||
return cc_tests_ids
|
||||
|
||||
|
||||
def write_session_info(path: Path = Path(getsourcefile(lambda: 0)).parent / SESSION_INFO_FILE,
|
||||
data: dict = None):
|
||||
with open(path, "w") as json_file:
|
||||
json.dump(data, json_file, indent=4)
|
Loading…
Reference in New Issue
Block a user