From 9e79f997e44ef43baaf7ffbb96f2ba67ece67fdb Mon Sep 17 00:00:00 2001 From: Victor Kuznetsov Date: Wed, 13 Oct 2021 14:25:44 +0300 Subject: [PATCH] [Memory tests] Add timeout to proc_exec (#7942) * add timeout to proc_exec * add framework field for db * upd db fields name --- tests/memory_tests/scripts/run_memorytest.py | 2 +- tests/memory_tests/test_runner/conftest.py | 15 ++++++++------- tests/memory_tests/test_runner/test_memorytest.py | 4 ++-- tests/utils/proc_utils.py | 4 ++-- 4 files changed, 13 insertions(+), 12 deletions(-) diff --git a/tests/memory_tests/scripts/run_memorytest.py b/tests/memory_tests/scripts/run_memorytest.py index c4ce69b43b2..fc585b37241 100644 --- a/tests/memory_tests/scripts/run_memorytest.py +++ b/tests/memory_tests/scripts/run_memorytest.py @@ -75,7 +75,7 @@ def run_memorytest(args: dict, log=None): stats = {} for run_iter in range(args["niter"]): tmp_stats_path = tempfile.NamedTemporaryFile().name - retcode, msg = cmd_exec(cmd_common + ["-s", str(tmp_stats_path)], log=log) + retcode, msg = cmd_exec(cmd_common + ["-s", str(tmp_stats_path)], timeout=60, log=log) if retcode != 0: log.error("Run of executable '{}' failed with return code '{}'. Error: {}\n" "Statistics aggregation is skipped.".format(args["executable"], retcode, msg)) diff --git a/tests/memory_tests/test_runner/conftest.py b/tests/memory_tests/test_runner/conftest.py index 2dc9f419f9c..78774372039 100644 --- a/tests/memory_tests/test_runner/conftest.py +++ b/tests/memory_tests/test_runner/conftest.py @@ -214,9 +214,9 @@ def omz_models_conversion(instance, request): logging.error(f"Please specify precision for the model " f"{model_name} from the list: {model_info['precisions']}") - model_out_path = Path(omz_models_out_dir / model_info["subdirectory"]) / model_precision / ( - model_name + ".xml") - model_full_path = omz_irs_out_dir / model_info["subdirectory"] / model_precision / (model_name + ".xml") + sub_model_path = str(Path(model_info["subdirectory"]) / model_precision / (model_name + ".xml")) + model_out_path = omz_models_out_dir / sub_model_path + model_irs_out_path = omz_irs_out_dir / sub_model_path # prepare models and convert models to IRs cmd = [f'{sys.executable}', f'{downloader_path}', '--name', f'{model_name}', @@ -233,9 +233,11 @@ def omz_models_conversion(instance, request): return_code, _ = cmd_exec(cmd, log=logging) assert return_code == 0, "Converting OMZ models has failed!" - instance["instance"]["model"]["framework"] = model_info["framework"] - instance["instance"]["model"]["path"] = model_out_path - instance["instance"]["model"]["full_path"] = model_full_path + instance["orig_instance"]["model"]["framework"] = model_info["framework"] + instance["orig_instance"]["model"]["path"] = sub_model_path + + instance["instance"]["model"]["cache_path"] = model_out_path + instance["instance"]["model"]["irs_out_path"] = model_irs_out_path @pytest.fixture(scope="function") @@ -340,7 +342,6 @@ def prepare_db_info(request, instance, executable, niter, manifest_metadata): "model": { "type": "object", "properties": { - "path": {"type": "string"}, "name": {"type": "string"}, "precision": {"type": "string"}, "framework": {"type": "string"} diff --git a/tests/memory_tests/test_runner/test_memorytest.py b/tests/memory_tests/test_runner/test_memorytest.py index c5e18067b75..c2f8bea635b 100644 --- a/tests/memory_tests/test_runner/test_memorytest.py +++ b/tests/memory_tests/test_runner/test_memorytest.py @@ -42,8 +42,8 @@ def test(instance, executable, niter, temp_dir, omz_models_conversion, validate_ """ # Prepare model to get model_path model_path = '' - cache_model_path = instance["instance"]["model"].get("path") - irs_model_path = instance["instance"]["model"].get("full_path") + cache_model_path = instance["instance"]["model"].get("cache_path") + irs_model_path = instance["instance"]["model"].get("irs_out_path") if os.path.isfile(irs_model_path): model_path = irs_model_path diff --git a/tests/utils/proc_utils.py b/tests/utils/proc_utils.py index 4b5be22e443..a06ac91abd2 100644 --- a/tests/utils/proc_utils.py +++ b/tests/utils/proc_utils.py @@ -10,7 +10,7 @@ import logging import subprocess -def cmd_exec(args, env=None, log=None, verbose=True, shell=False): +def cmd_exec(args, timeout=None, env=None, log=None, verbose=True, shell=False): """ Run cmd using subprocess with logging and other improvements """ if log is None: @@ -37,7 +37,7 @@ def cmd_exec(args, env=None, log=None, verbose=True, shell=False): if line or proc.poll() is None: continue break - outs = proc.communicate()[0] + outs = proc.communicate(timeout=timeout)[0] if outs: log_out(outs.strip("\n"))