From 924882a1f9db8aa309ff5bffb794f3b0d8fef890 Mon Sep 17 00:00:00 2001 From: LiaoU3 <58060146+LiaoU3@users.noreply.github.com> Date: Wed, 4 Sep 2024 09:29:51 +0800 Subject: [PATCH] [checkbox-ce-oem] Fix all checks in ceoem (Bugfix) (#1445) * Reduce length of the testplan name * fix the shell check issue fix the shell check issue * Fix flake8 * Fix black * Fix flake8 * fix add_subparsers param issue in python3.5 fix the required parameter not available in Python 3.5 * fix fstring error in Python 3.5 fix fstring error in Python 3.5 --------- Co-authored-by: stanley31huang --- .../bin/performance_mode_controller.py | 14 +++++++------- .../bin/rpmsg_load_firmware.py | 8 ++++++-- .../checkbox-provider-ce-oem/bin/spidev_test.py | 2 +- .../tests/test_cpufreq_governors.py | 5 ++++- ...t_v4l2_video_decoder_md5_checksum_comparison.py | 4 +++- .../tests/test_rpmsg_load_firmware.py | 2 +- .../tests/test_rpmsg_tests.py | 2 +- .../tests/test_tcp_multi_connections.py | 2 +- .../checkbox-provider-ce-oem/units/gadget/jobs.pxu | 2 +- .../checkbox-provider-ce-oem/units/optee/jobs.pxu | 2 +- .../test-plan-strict-confinement.pxu | 10 +++++----- 11 files changed, 31 insertions(+), 22 deletions(-) diff --git a/contrib/checkbox-ce-oem/checkbox-provider-ce-oem/bin/performance_mode_controller.py b/contrib/checkbox-ce-oem/checkbox-provider-ce-oem/bin/performance_mode_controller.py index 4c8b1e0f0..89ba880ae 100755 --- a/contrib/checkbox-ce-oem/checkbox-provider-ce-oem/bin/performance_mode_controller.py +++ b/contrib/checkbox-ce-oem/checkbox-provider-ce-oem/bin/performance_mode_controller.py @@ -39,7 +39,7 @@ def get_performance_ctx_function() -> Optional[Callable]: Environment Variables: ----------- - PERFORMANCE_PYTHON_MODULE_PATH + performance_module_path The full path of a python module that you are interested in even it's not in PYTHONPATH PERFORMANCE_FUNCTION_NAME @@ -63,10 +63,10 @@ def get_performance_ctx_function() -> Optional[Callable]: # in ce-oem provider. # It's the empty value by defaul, you have to define it as Checkbox's # configuraion. - PERFORMANCE_PYTHON_MODULE_PATH = os.environ.get( + performance_module_path = os.environ.get( "PERFORMANCE_PYTHON_MODULE_PATH", "" ) - if PERFORMANCE_PYTHON_MODULE_PATH == "": + if performance_module_path == "": raise FileNotFoundError( ( "Fail to get a performance python module" @@ -78,14 +78,14 @@ def get_performance_ctx_function() -> Optional[Callable]: # Get the name of context manager function which controls the performance # mode. Default name is performance_mode. You can assign the specific name # via environment variable - PERFORMANCE_FUNCTION_NAME = os.environ.get( + performance_function_name = os.environ.get( "PERFORMANCE_FUNCTION_NAME", "performance_mode" ) return get_function_from_a_module( - module_name=os.path.basename(PERFORMANCE_PYTHON_MODULE_PATH), - module_path=PERFORMANCE_PYTHON_MODULE_PATH, - function_name=PERFORMANCE_FUNCTION_NAME, + module_name=os.path.basename(performance_module_path), + module_path=performance_module_path, + function_name=performance_function_name, ) diff --git a/contrib/checkbox-ce-oem/checkbox-provider-ce-oem/bin/rpmsg_load_firmware.py b/contrib/checkbox-ce-oem/checkbox-provider-ce-oem/bin/rpmsg_load_firmware.py index af4f84504..203fa3930 100755 --- a/contrib/checkbox-ce-oem/checkbox-provider-ce-oem/bin/rpmsg_load_firmware.py +++ b/contrib/checkbox-ce-oem/checkbox-provider-ce-oem/bin/rpmsg_load_firmware.py @@ -220,7 +220,7 @@ def dump_firmware_test_mapping(args) -> None: def register_arguments(): parser = argparse.ArgumentParser(description="RPMSG reload firmware test") - subparsers = parser.add_subparsers(dest="mode", required=True) + subparsers = parser.add_subparsers(dest="mode") reload_test_parser = subparsers.add_parser("test-reload") reload_test_parser.add_argument( "--device", @@ -260,8 +260,12 @@ def register_arguments(): required=True, ) reload_res_test_parser.set_defaults(test_func=dump_firmware_test_mapping) + args = parser.parse_args() + if args.mode is None: + parser.print_help() + exit(1) - return parser.parse_args() + return args if __name__ == "__main__": diff --git a/contrib/checkbox-ce-oem/checkbox-provider-ce-oem/bin/spidev_test.py b/contrib/checkbox-ce-oem/checkbox-provider-ce-oem/bin/spidev_test.py index 61a3e5e5b..5704c0360 100755 --- a/contrib/checkbox-ce-oem/checkbox-provider-ce-oem/bin/spidev_test.py +++ b/contrib/checkbox-ce-oem/checkbox-provider-ce-oem/bin/spidev_test.py @@ -52,7 +52,7 @@ def test_spi_content_consistency(spi_path): # Construct the command to run the SPI test cmd = "spidev_test -D {} -p 'Canonical SPI Test' -v".format(spi_path) - print(f"Run command: {cmd}\n") + print("Run command: {}\n".format(cmd)) # Run the command and capture the output spi_ret = runcmd(cmd) diff --git a/contrib/checkbox-ce-oem/checkbox-provider-ce-oem/tests/test_cpufreq_governors.py b/contrib/checkbox-ce-oem/checkbox-provider-ce-oem/tests/test_cpufreq_governors.py index becacf099..76d5fcf2b 100644 --- a/contrib/checkbox-ce-oem/checkbox-provider-ce-oem/tests/test_cpufreq_governors.py +++ b/contrib/checkbox-ce-oem/checkbox-provider-ce-oem/tests/test_cpufreq_governors.py @@ -992,7 +992,10 @@ def test_debug_logging_disabled(self, mock_exit): def test_policy_resource_flag_enabled(self, mock_handler, mock_exit): with patch("sys.argv", ["program_name", "--policy-resource"]): main() - mock_handler.return_value.print_policies_list.assert_called_once_with() + # fmt: off + mock_handler.return_value.print_policies_list.\ + assert_called_once_with() + # fmt: on @patch("sys.exit") @patch("cpufreq_governors.CPUScalingHandler") diff --git a/contrib/checkbox-ce-oem/checkbox-provider-ce-oem/tests/test_gst_v4l2_video_decoder_md5_checksum_comparison.py b/contrib/checkbox-ce-oem/checkbox-provider-ce-oem/tests/test_gst_v4l2_video_decoder_md5_checksum_comparison.py index 2dab55d90..07440c36d 100644 --- a/contrib/checkbox-ce-oem/checkbox-provider-ce-oem/tests/test_gst_v4l2_video_decoder_md5_checksum_comparison.py +++ b/contrib/checkbox-ce-oem/checkbox-provider-ce-oem/tests/test_gst_v4l2_video_decoder_md5_checksum_comparison.py @@ -264,7 +264,9 @@ def test_validate_video_decoder_md5_checksum_golden_md5_checksum_not_found( (), { "golden_sample_path": "golden_sample.mp4", - "golden_sample_md5_checksum_path": "non_exist_golden_sample.md5", + "golden_sample_md5_checksum_path": ( + "non_exist_golden_sample.md5" + ), "decoder_plugin": "fake_decoder", "color_space": "NN", }, diff --git a/contrib/checkbox-ce-oem/checkbox-provider-ce-oem/tests/test_rpmsg_load_firmware.py b/contrib/checkbox-ce-oem/checkbox-provider-ce-oem/tests/test_rpmsg_load_firmware.py index 1d9527f75..2704457e7 100755 --- a/contrib/checkbox-ce-oem/checkbox-provider-ce-oem/tests/test_rpmsg_load_firmware.py +++ b/contrib/checkbox-ce-oem/checkbox-provider-ce-oem/tests/test_rpmsg_load_firmware.py @@ -7,7 +7,7 @@ from unittest.mock import patch, MagicMock, Mock sys.modules["systemd"] = MagicMock() - +# flake8: noqa: E402 import rpmsg_load_firmware diff --git a/contrib/checkbox-ce-oem/checkbox-provider-ce-oem/tests/test_rpmsg_tests.py b/contrib/checkbox-ce-oem/checkbox-provider-ce-oem/tests/test_rpmsg_tests.py index 45d97a5dc..8284a2eea 100755 --- a/contrib/checkbox-ce-oem/checkbox-provider-ce-oem/tests/test_rpmsg_tests.py +++ b/contrib/checkbox-ce-oem/checkbox-provider-ce-oem/tests/test_rpmsg_tests.py @@ -4,7 +4,7 @@ from unittest.mock import patch, MagicMock, Mock sys.modules["systemd"] = MagicMock() - +# flake8: noqa: E402 import rpmsg_tests diff --git a/contrib/checkbox-ce-oem/checkbox-provider-ce-oem/tests/test_tcp_multi_connections.py b/contrib/checkbox-ce-oem/checkbox-provider-ce-oem/tests/test_tcp_multi_connections.py index a8bb3152b..f4e8646de 100644 --- a/contrib/checkbox-ce-oem/checkbox-provider-ce-oem/tests/test_tcp_multi_connections.py +++ b/contrib/checkbox-ce-oem/checkbox-provider-ce-oem/tests/test_tcp_multi_connections.py @@ -4,7 +4,7 @@ from datetime import timedelta, datetime import tcp_multi_connections from tcp_multi_connections import StatusEnum -from unittest.mock import patch, Mock, MagicMock +from unittest.mock import patch, Mock class TestTcpMulitConnections(unittest.TestCase): diff --git a/contrib/checkbox-ce-oem/checkbox-provider-ce-oem/units/gadget/jobs.pxu b/contrib/checkbox-ce-oem/checkbox-provider-ce-oem/units/gadget/jobs.pxu index 715e06c0b..2cf5b332a 100644 --- a/contrib/checkbox-ce-oem/checkbox-provider-ce-oem/units/gadget/jobs.pxu +++ b/contrib/checkbox-ce-oem/checkbox-provider-ce-oem/units/gadget/jobs.pxu @@ -33,7 +33,7 @@ category_id: com.canonical.certification::gadget plugin: resource environ: GADGET_INTERFACE_FILE command: - gadget_interface_utils.py --file $GADGET_INTERFACE_FILE --action dump + gadget_interface_utils.py --file "$GADGET_INTERFACE_FILE" --action dump unit: template template-resource: snap_interface_resource diff --git a/contrib/checkbox-ce-oem/checkbox-provider-ce-oem/units/optee/jobs.pxu b/contrib/checkbox-ce-oem/checkbox-provider-ce-oem/units/optee/jobs.pxu index ede04a236..0eb0f8865 100644 --- a/contrib/checkbox-ce-oem/checkbox-provider-ce-oem/units/optee/jobs.pxu +++ b/contrib/checkbox-ce-oem/checkbox-provider-ce-oem/units/optee/jobs.pxu @@ -47,7 +47,7 @@ command: tool=$(look_up_xtest.py) ta_path="" if [[ "$tool" == "x-test.xtest" ]]; then - ta_path="$(find /var/snap -wholename */lib/optee_armtz)" + ta_path="$(find /var/snap -wholename '*/lib/optee_armtz')" else gadget=$(awk -F"." '{ print $1}' <<< "$tool") ta_path="/snap/$gadget/current/lib/optee_armtz/" diff --git a/contrib/checkbox-ce-oem/checkbox-provider-ce-oem/units/strict-confinement/test-plan-strict-confinement.pxu b/contrib/checkbox-ce-oem/checkbox-provider-ce-oem/units/strict-confinement/test-plan-strict-confinement.pxu index 490683ea5..3726e7142 100644 --- a/contrib/checkbox-ce-oem/checkbox-provider-ce-oem/units/strict-confinement/test-plan-strict-confinement.pxu +++ b/contrib/checkbox-ce-oem/checkbox-provider-ce-oem/units/strict-confinement/test-plan-strict-confinement.pxu @@ -1,6 +1,6 @@ id: strict-confinement-full unit: test plan -_name: Strict-confinement - Full manual + automated tests for Ubuntu Core in strict confinement environment +_name: Full manual + automated tests for Ubuntu Core in strict confinement _description: Combined manual and automated test plans for Ubuntu Core in strict confinement environment. include: @@ -12,7 +12,7 @@ nested_part: id: strict-confinement-manual unit: test plan -_name: Strict-confinement - Manual only QA tests for Ubuntu Core in strict confinement environment +_name: Manual only QA tests for Ubuntu Core in strict confinement _description: Ubuntu Core QA test plan for strict confinement environment. This test plan contains all of the tests that require manual @@ -25,7 +25,7 @@ exclude: id: strict-confinement-automated unit: test plan -_name: Strict-confinement - Automated only QA tests for Ubuntu Core in strict confinement environment +_name: Automated only QA tests for Ubuntu Core in strict confinement _description: Ubuntu Core QA test plan for the strict confinement environment. This test plan contains all of the automated tests used to validate @@ -40,7 +40,7 @@ exclude: id: after-suspend-strict-confinement-manual unit: test plan -_name: Strict-confinement - After suspend Manual only QA tests for Ubuntu Core in strict confinement environment +_name: After suspend Manual only QA tests for Ubuntu Core in strict confinement _description: Ubuntu Core QA test plan for strict confinement environment. This test plan contains all of the tests that require manual @@ -53,7 +53,7 @@ exclude: id: after-suspend-strict-confinement-automated unit: test plan -_name: Strict-confinement - After suspend Automated only QA tests for Ubuntu Core in strict confinement environment +_name: After suspend Automated only QA tests for Ubuntu Core in strict confinement _description: Ubuntu Core QA test plan for the strict confinement environment. This test plan contains all of the automated tests used to validate