OpenVINO™ is an open source toolkit for optimizing and deploying AI inference
C++ aicomputer-visiondeep-learningdeploy-aidiffusion-modelsgenerative-aigood-first-issueinferencellm-inferencenatural-language-processingnlpopenvinooptimize-aiperformance-boostrecommendation-systemspeech-recognitionstable-diffusiontransformersyolo
[benchmark_app] Do not crash while collecting command line arguments (#38197)
Daksha174aaf436abe
diff --git a/.github/workflows/job_python_unit_tests.yml b/.github/workflows/job_python_unit_tests.ymlindex 5ff6e92818b..9686aee9f8d 100644--- a/.github/workflows/job_python_unit_tests.yml+++ b/.github/workflows/job_python_unit_tests.yml@@ -134,6 +134,10 @@ jobs:if: fromJSON(inputs.affected-components).OVC.testrun: python3 -m pytest -sv ${INSTALL_TEST_DIR}/ovc/unit_tests --junitxml=${INSTALL_TEST_DIR}/TEST-OpenVinoConversion.xml+ - name: Benchmark tool unit tests+ if: fromJSON(inputs.affected-components).tools.test+ run: python3 -m pytest -sv ${INSTALL_TEST_DIR}/benchmark_tool/unit_tests --junitxml=${INSTALL_TEST_DIR}/TEST-BenchmarkTool.xml+- name: OVC Python API Testsif: ${{ fromJSON(inputs.affected-components).OVC.test && (runner.arch != 'ARM64' && runner.os != 'macOS') }} # Ticket: 173019run: |diff --git a/tools/benchmark_tool/CMakeLists.txt b/tools/benchmark_tool/CMakeLists.txtindex 82891af3500..f24b0185fc7 100644--- a/tools/benchmark_tool/CMakeLists.txt+++ b/tools/benchmark_tool/CMakeLists.txt@@ -35,6 +35,17 @@ install(DIRECTORY ${OpenVINOBenchmarkTool_SOURCE_DIR}/openvino${OV_CPACK_COMP_BENCHMARK_APP_EXCLUDE_ALL}USE_SOURCE_PERMISSIONS)+#+# Tests+#++if(ENABLE_TESTS)+ install(DIRECTORY unit_tests+ DESTINATION tests/benchmark_tool+ COMPONENT tests+ EXCLUDE_FROM_ALL)+endif()+## Cpack#diff --git a/tools/benchmark_tool/openvino/tools/benchmark/utils/utils.py b/tools/benchmark_tool/openvino/tools/benchmark/utils/utils.pyindex 8565ba095cd..6b8688dda25 100644--- a/tools/benchmark_tool/openvino/tools/benchmark/utils/utils.py+++ b/tools/benchmark_tool/openvino/tools/benchmark/utils/utils.py@@ -470,15 +470,15 @@ def get_command_line_arguments(argv):arg_name = ''arg_value = ''for arg in argv[1:]:- if '=' in arg:+ if arg.startswith('-') and '=' in arg:if arg_name != '':parameters.append((arg_name, arg_value))- arg_name, arg_value = arg.split('=')+ arg_name, arg_value = arg.split('=', 1)parameters.append((arg_name, arg_value))arg_name = ''arg_value = ''else:- if arg[0] == '-':+ if arg.startswith('-'):if arg_name != '':parameters.append((arg_name, arg_value))arg_value = ''diff --git a/tools/benchmark_tool/unit_tests/test_get_command_line_arguments.py b/tools/benchmark_tool/unit_tests/test_get_command_line_arguments.pynew file mode 100644index 00000000000..ad7d8a5fbdb--- /dev/null+++ b/tools/benchmark_tool/unit_tests/test_get_command_line_arguments.py@@ -0,0 +1,39 @@+# Copyright (C) 2018-2026 Intel Corporation+# SPDX-License-Identifier: Apache-2.0++import unittest++from openvino.tools.benchmark.utils.utils import get_command_line_arguments+++class TestGetCommandLineArguments(unittest.TestCase):+ def test_separate_name_and_value(self):+ self.assertEqual(get_command_line_arguments(['benchmark_app', '-m', 'model.xml', '-niter', '10']),+ [('-m', 'model.xml'), ('-niter', '10')])++ def test_name_and_value_joined_by_equals(self):+ self.assertEqual(get_command_line_arguments(['benchmark_app', '-m=model.xml']),+ [('-m', 'model.xml')])++ def test_value_containing_equals_is_kept_whole(self):+ # only the first '=' separates the name from the value+ self.assertEqual(get_command_line_arguments(['benchmark_app', '-m=/data/exp=1/model.xml']),+ [('-m', '/data/exp=1/model.xml')])++ def test_separate_value_containing_equals_is_a_value(self):+ # a value that is not an option must not be split, even though it contains '='+ self.assertEqual(get_command_line_arguments(['benchmark_app', '-m', '/data/exp=1/model.xml', '-niter', '10']),+ [('-m', '/data/exp=1/model.xml'), ('-niter', '10')])++ def test_separate_config_value_containing_equals(self):+ self.assertEqual(get_command_line_arguments(['benchmark_app', '-load_config', 'CPU:{NUM_STREAMS=4}']),+ [('-load_config', 'CPU:{NUM_STREAMS=4}')])++ def test_empty_argument_is_not_fatal(self):+ # an unset shell variable expands to an empty argument+ self.assertEqual(get_command_line_arguments(['benchmark_app', '-m', 'model.xml', '-i', '']),+ [('-m', 'model.xml'), ('-i', '')])+++if __name__ == '__main__':+ unittest.main()