From 7b2c449356d361018ee9c16ecca81b7636ae7df1 Mon Sep 17 00:00:00 2001 From: stanley31huang Date: Mon, 29 Apr 2024 18:02:08 +0800 Subject: [PATCH 01/15] Add remote processore firmware loading test add a test to load ELF firmware for remote processor via rpmsg --- .../bin/rpmsg_load_firmware.py | 271 ++++++++++++++++++ .../tests/test_rpmsg_load_firmware.py | 242 ++++++++++++++++ .../units/rpmsg/category.pxu | 2 +- .../units/rpmsg/jobs.pxu | 32 +++ .../units/rpmsg/test-plan.pxu | 9 +- 5 files changed, 552 insertions(+), 4 deletions(-) create mode 100755 contrib/checkbox-ce-oem/checkbox-provider-ce-oem/bin/rpmsg_load_firmware.py create mode 100755 contrib/checkbox-ce-oem/checkbox-provider-ce-oem/tests/test_rpmsg_load_firmware.py 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 new file mode 100755 index 000000000..1283350c3 --- /dev/null +++ b/contrib/checkbox-ce-oem/checkbox-provider-ce-oem/bin/rpmsg_load_firmware.py @@ -0,0 +1,271 @@ +#!/usr/bin/env python3 + +import sys +import re +import argparse +import datetime +import logging +import select +from collections import OrderedDict +from systemd import journal +from pathlib import Path + + +class RpmsgLoadFirmwareTest: + + properties = ["firmware_path", "firmware_file", "rpmsg_state"] + + def __init__(self, remoteproc_dev: str): + self._firmware_path = Path( + "/sys/module/firmware_class/parameters/path" + ) + self._firmware_file = Path( + "/sys/class/remoteproc/{}/firmware".format(remoteproc_dev) + ) + self._rpmsg_state = Path( + "/sys/class/remoteproc/{}/state".format(remoteproc_dev) + ) + self._search_patterns = {} + self.expected_events = [] + + def __enter__(self): + self._setup() + return self + + def __exit__(self, type, value, traceback): + self._teardown() + + def _setup(self): + self._previous_config = OrderedDict() + for key in self.properties: + self._previous_config.update({key: getattr(self, key)}) + + def _teardown(self): + self.rpmsg_state = "stop" + for key in self.properties: + if getattr(self, key) != self._previous_config[key]: + setattr(self, key, self._previous_config[key]) + + @property + def firmware_path(self) -> str: + return self._firmware_path.read_text() + + @firmware_path.setter + def firmware_path(self, value: str) -> None: + self._firmware_path.write_text(value) + + @property + def firmware_file(self) -> str: + return self._firmware_file.read_text() + + @firmware_file.setter + def firmware_file(self, value: str) -> None: + self._firmware_file.write_text(value) + + @property + def rpmsg_state(self) -> str: + return self._rpmsg_state.read_text() + + @rpmsg_state.setter + def rpmsg_state(self, value: str) -> None: + self._rpmsg_state.write_text(value) + + @property + def search_pattern(self) -> dict: + return self._search_patterns + + @search_pattern.setter + def search_pattern(self, patterns: dict) -> None: + self._search_patterns.update(patterns) + + def _init_logger(self): + self.log_reader = journal.Reader() + self.log_reader.this_boot() + self.log_reader.seek_tail() + self.log_reader.get_previous() + + self._poller = select.poll() + self._poller.register(self.log_reader, self.log_reader.get_events()) + + def lookup_reload_logs(self, entry: dict): + keep_looking = True + for key, pattern in self._search_patterns.items(): + if re.search(pattern, entry.get("MESSAGE")): + self.expected_events.append((key, entry.get("MESSAGE"))) + if key == "ready": + keep_looking = False + break + + return keep_looking + + def _monitor_journal_logs(self, lookup_func): + start_time = datetime.datetime.now() + logging.info("# start time: %s", start_time) + + while self._poller.poll(1000): + if self.log_reader.process() == journal.APPEND: + for entry in self.log_reader: + logging.debug(entry["MESSAGE"]) + if entry["MESSAGE"] == "": + continue + if lookup_func(entry) is False: + return self.expected_events + + cur_time = datetime.datetime.now() + if (cur_time - start_time).total_seconds() > 60: + return self.expected_events + + +def verify_load_firmware_logs(match_records: list, search_stages: list): + logging.info("Validate RPMSG related log from journal logs") + logging.debug(match_records) + actuall_stage = [] + for record in match_records: + if record[1]: + actuall_stage.append(record[0]) + logging.info("%s stage: %s", record[0], record[1]) + + return set(actuall_stage) == set(search_stages) + + +def load_firmware_test(args): + remote_proc_dev = args.device + target_path = args.path + target_file = args.file + + proc_pattern = "remoteproc remoteproc[0-9]+" + search_patterns = { + "start": r"{}: powering up imx-rproc".format(proc_pattern), + "boot_image": (r"{}: Booting fw image (?P\w*.elf), \w*").format( + proc_pattern + ), + # Please keep latest record in ready stage + # This function will return if latest record been captured. + "ready": (r"{}: remote processor imx-rproc is now up").format( + proc_pattern + ), + } + logging.info("# Start load M4 firmware test") + with RpmsgLoadFirmwareTest(remote_proc_dev) as rpmsg_handler: + rpmsg_handler.search_pattern = search_patterns + rpmsg_handler._init_logger() + if rpmsg_handler.rpmsg_state == "online": + logging.info("Stop the Remote processor") + rpmsg_handler.rpmsg_state = "stop" + logging.info( + "Configure the firmware file to %s and firmware path to %s", + target_file, + target_path, + ) + rpmsg_handler.firmware_path = target_path + rpmsg_handler.firmware_file = target_file + logging.info("Start the Remote processor") + rpmsg_handler.rpmsg_state = "start" + rpmsg_handler._monitor_journal_logs(rpmsg_handler.lookup_reload_logs) + + if verify_load_firmware_logs( + rpmsg_handler.expected_events, + rpmsg_handler._search_patterns.keys(), + ): + logging.info("# Reload M4 firmware successful") + else: + raise SystemExit("# Reload M4 firmware failed") + + # AI: will adding a feature to do testing after load M-core firmware + # extra_testing = None + # if extra_testing is not None: + # module_c = __import__(os.path.splitext(__file__)[0]) + # getattr(module_c, extra_testing)() + + +def dump_firmware_test_mapping(args): + firmware_mapping = args.mapping + firmware_path = args.path + pattern = r"(\w*):([\w\.-]*)" + output_format = "device: {}\nfirmware: {}\npath: {}\n" + + re_result = re.findall(pattern, firmware_mapping) + if not re_result or firmware_path.strip() == "": + print( + output_format.format( + firmware_mapping, firmware_mapping, firmware_path + ) + ) + return + + for data in re_result: + print(output_format.format(data[0], data[1], firmware_path)) + + +def register_arguments(): + parser = argparse.ArgumentParser(description="RPMSG reload firmware test") + + subparsers = parser.add_subparsers(dest="mode", required=True) + reload_test_parser = subparsers.add_parser("test-reload") + reload_test_parser.add_argument( + "--device", + help="The RPMSG device", + type=str, + required=True, + ) + reload_test_parser.add_argument( + "--path", + help="The directory to store M-core ELF firmware", + type=str, + required=True, + ) + reload_test_parser.add_argument( + "--file", help="M-core ELF firmware file", required=True, type=str + ) + # AI: will adding a feature to do testing after load M-core firmware + # reload_test_parser.add_argument( + # "--extra-test", + # help="RPMSG functional tests", + # choices=["pingpong", "rpmsg-tty"], + # default=None, + # ) + reload_test_parser.set_defaults(test_func=load_firmware_test) + + reload_res_test_parser = subparsers.add_parser("resource-reload") + reload_res_test_parser.add_argument( + "--mapping", + help="The mapping with RPMSG node and M-Core firmware", + type=str, + required=True, + ) + reload_res_test_parser.add_argument( + "--path", + help="The directory to store M-core ELF firmware", + type=str, + required=True, + ) + reload_res_test_parser.set_defaults(test_func=dump_firmware_test_mapping) + + return parser.parse_args() + + +if __name__ == "__main__": + + root_logger = logging.getLogger() + root_logger.setLevel(logging.INFO) + logger_format = "%(asctime)s %(levelname)-8s %(message)s" + date_format = "%Y-%m-%d %H:%M:%S" + + # Log DEBUG and INFO to stdout, others to stderr + stdout_handler = logging.StreamHandler(sys.stdout) + stdout_handler.setFormatter(logging.Formatter(logger_format, date_format)) + + stderr_handler = logging.StreamHandler(sys.stderr) + stderr_handler.setFormatter(logging.Formatter(logger_format, date_format)) + + stdout_handler.setLevel(logging.DEBUG) + stderr_handler.setLevel(logging.WARNING) + + # Add a filter to the stdout handler to limit log records to + # INFO level and below + stdout_handler.addFilter(lambda record: record.levelno <= logging.INFO) + + root_logger.addHandler(stderr_handler) + root_logger.addHandler(stdout_handler) + args = register_arguments() + args.test_func(args) 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 new file mode 100755 index 000000000..1d9527f75 --- /dev/null +++ b/contrib/checkbox-ce-oem/checkbox-provider-ce-oem/tests/test_rpmsg_load_firmware.py @@ -0,0 +1,242 @@ +import unittest +import sys +import argparse +from pathlib import Path +from io import StringIO +from contextlib import redirect_stdout +from unittest.mock import patch, MagicMock, Mock + +sys.modules["systemd"] = MagicMock() + +import rpmsg_load_firmware + + +class RpmsgLoardFirmwareTests(unittest.TestCase): + """ + Unit tests for RPMSG load firmware test scripts + """ + + def setUp(self) -> None: + test_dev = "remoteproc0" + self._rpmsg_load_fw_test = rpmsg_load_firmware.RpmsgLoadFirmwareTest( + test_dev + ) + self._default_search_pattern = { + "start": r"remoteproc remoteproc[0-9]+: powering up imx-rproc", + "boot_image": ( + r"remoteproc remoteproc[0-9]+: " + r"Booting fw image (?P\w*.elf), \w*" + ), + "ready": ( + r"remoteproc remoteproc[0-9]+: " + r"remote processor imx-rproc is now up" + ), + } + + def test_validate_rpmsg_object(self): + + self.assertEqual( + self._rpmsg_load_fw_test._firmware_path, + Path("/sys/module/firmware_class/parameters/path"), + ) + self.assertEqual( + self._rpmsg_load_fw_test._firmware_file, + Path("/sys/class/remoteproc/remoteproc0/firmware"), + ) + self.assertEqual( + self._rpmsg_load_fw_test._rpmsg_state, + Path("/sys/class/remoteproc/remoteproc0/state"), + ) + self.assertDictEqual( + self._rpmsg_load_fw_test._search_patterns, + {}, + ) + self.assertListEqual(self._rpmsg_load_fw_test.expected_events, []) + + @patch("pathlib.Path.read_text") + def test_get_firmware_path(self, mock_read): + + expected_result = "test-response" + mock_read.return_value = expected_result + self.assertEqual( + self._rpmsg_load_fw_test.firmware_path, expected_result + ) + + @patch("pathlib.Path.write_text") + def test_set_firmware_path(self, mock_write): + expected_result = "test-response" + self._rpmsg_load_fw_test.firmware_path = expected_result + mock_write.assert_called_once_with(expected_result) + + @patch("pathlib.Path.read_text") + def test_get_firmware_file(self, mock_read): + + expected_result = "test-response" + mock_read.return_value = expected_result + self.assertEqual( + self._rpmsg_load_fw_test.firmware_file, expected_result + ) + + @patch("pathlib.Path.write_text") + def test_set_firmware_file(self, mock_write): + expected_result = "test-response" + self._rpmsg_load_fw_test.firmware_file = expected_result + mock_write.assert_called_once_with(expected_result) + + @patch("pathlib.Path.read_text") + def test_get_rpmsg_state(self, mock_read): + + expected_result = "test-response" + mock_read.return_value = expected_result + self.assertEqual(self._rpmsg_load_fw_test.rpmsg_state, expected_result) + + @patch("pathlib.Path.write_text") + def test_set_rpmsg_state(self, mock_write): + expected_result = "test-response" + self._rpmsg_load_fw_test.rpmsg_state = expected_result + mock_write.assert_called_once_with(expected_result) + + def test_get_search_pattern(self): + self.assertDictEqual( + self._rpmsg_load_fw_test.search_pattern, + {}, + ) + + def test_set_search_pattern(self): + expected_result = { + "start": "fake", + "boot_image": "fake", + "ready": "fake", + } + + self._rpmsg_load_fw_test.search_pattern = expected_result + self.assertDictEqual( + self._rpmsg_load_fw_test.search_pattern, + expected_result, + ) + + def test_init_logger(self): + pass + + def test_lookup_reload_logs_not_last_one(self): + self._rpmsg_load_fw_test.search_pattern = self._default_search_pattern + entry = { + "MESSAGE": ( + "Apr 25 07:12:53 ubuntu kernel: remoteproc " + "remoteproc0: powering up imx-rproc" + ) + } + self.assertTrue(self._rpmsg_load_fw_test.lookup_reload_logs(entry)) + self.assertEqual( + self._rpmsg_load_fw_test.expected_events, + [("start", entry["MESSAGE"])], + ) + + def test_lookup_reload_logs_last_one(self): + self._rpmsg_load_fw_test.search_pattern = self._default_search_pattern + entry = { + "MESSAGE": ( + "Apr 25 07:12:53 ubuntu kernel: remoteproc " + "remoteproc0: remote processor imx-rproc is now up" + ) + } + self.assertFalse(self._rpmsg_load_fw_test.lookup_reload_logs(entry)) + self.assertEqual( + self._rpmsg_load_fw_test.expected_events, + [("ready", entry["MESSAGE"])], + ) + + def test_verify_load_firmware_logs_successful(self): + match_records = [("stage1", "message1"), ("stage2", "message2")] + search_stages = ["stage1", "stage2"] + + self.assertTrue( + rpmsg_load_firmware.verify_load_firmware_logs( + match_records, search_stages + ) + ) + + def test_verify_load_firmware_logs_not_match(self): + match_records = [("stage1", "message1")] + search_stages = ["stage1", "stage2"] + + self.assertFalse( + rpmsg_load_firmware.verify_load_firmware_logs( + match_records, search_stages + ) + ) + + +class RpmsgMainFunctionTest(unittest.TestCase): + def test_reload_test_parser(self): + sys.argv = [ + "rpmsg_load_firmware.py", + "test-reload", + "--device", + "remoteproc0", + "--path", + "/home", + "--file", + "test-fw.elf", + ] + args = rpmsg_load_firmware.register_arguments() + + self.assertEqual( + args.test_func, rpmsg_load_firmware.load_firmware_test + ) + self.assertEqual(args.device, "remoteproc0") + self.assertEqual(args.path, "/home") + self.assertEqual(args.file, "test-fw.elf") + + def test_resource_parser(self): + sys.argv = [ + "rpmsg_load_firmware.py", + "resource-reload", + "--mapping", + "remoteproc0:test-fw.elf", + "--path", + "/home", + ] + args = rpmsg_load_firmware.register_arguments() + + self.assertEqual( + args.test_func, rpmsg_load_firmware.dump_firmware_test_mapping + ) + self.assertEqual(args.path, "/home") + self.assertEqual(args.mapping, "remoteproc0:test-fw.elf") + + def test_dump_firmware_test_mapping_successful(self): + mock_args = Mock( + return_value=argparse.Namespace( + mapping="remoteproc0:test-fw.elf remoteproc1:test-fw.elf", + path="/home/ubuntu", + ) + ) + with redirect_stdout(StringIO()) as stdout: + rpmsg_load_firmware.dump_firmware_test_mapping(mock_args()) + self.assertEqual( + stdout.getvalue().strip("\n"), + ( + "device: remoteproc0\nfirmware: test-fw.elf\n" + "path: /home/ubuntu\n\n" + "device: remoteproc1\nfirmware: test-fw.elf\n" + "path: /home/ubuntu" + ), + ) + + def test_dump_firmware_test_mapping_format_invalid(self): + mock_args = Mock( + return_value=argparse.Namespace( + mapping="remoteproest-fw.elf", + path="/home/ubuntu", + ) + ) + args = mock_args() + with redirect_stdout(StringIO()) as stdout: + rpmsg_load_firmware.dump_firmware_test_mapping(args) + self.assertEqual( + stdout.getvalue().strip("\n"), + ("device: {}\nfirmware: {}\npath: {}").format( + args.mapping, args.mapping, args.path + ), + ) diff --git a/contrib/checkbox-ce-oem/checkbox-provider-ce-oem/units/rpmsg/category.pxu b/contrib/checkbox-ce-oem/checkbox-provider-ce-oem/units/rpmsg/category.pxu index 0474a6350..566fd6002 100644 --- a/contrib/checkbox-ce-oem/checkbox-provider-ce-oem/units/rpmsg/category.pxu +++ b/contrib/checkbox-ce-oem/checkbox-provider-ce-oem/units/rpmsg/category.pxu @@ -1,3 +1,3 @@ unit: category id: rpmsg -_name: M-series core RPMSG test \ No newline at end of file +_name: Remote Processor Messaging (rpmsg) Framework test \ No newline at end of file diff --git a/contrib/checkbox-ce-oem/checkbox-provider-ce-oem/units/rpmsg/jobs.pxu b/contrib/checkbox-ce-oem/checkbox-provider-ce-oem/units/rpmsg/jobs.pxu index 4154e50ac..924c8b80d 100644 --- a/contrib/checkbox-ce-oem/checkbox-provider-ce-oem/units/rpmsg/jobs.pxu +++ b/contrib/checkbox-ce-oem/checkbox-provider-ce-oem/units/rpmsg/jobs.pxu @@ -32,3 +32,35 @@ user: root plugin: shell command: rpmsg_tests.py --type serial-tty + +unit: job +category_id: rpmsg +id: ce-oem-rpmsg/rp-firmware-mapping +plugin: resource +_summary: List Remote Processor firmwares and RPMSG node mapping +_description: + List firmware and RPMSG node mapping for reload Remote Processor firmware test + RPMSG_RP_FIRMWARE_MAPPING="remoteproc0:test-1.elf remoteproc0:test-2.elf" + RPMSG_RP_FIRMWARE_PATH="/home/user1" +estimated_duration: 2s +flags: preserve-locale +environ: RPMSG_RP_FIRMWARE_MAPPING RPMSG_RP_FIRMWARE_PATH +command: + rpmsg_load_firmware.py resource-reload --path "$RPMSG_RP_FIRMWARE_PATH" --mapping "$RPMSG_RP_FIRMWARE_MAPPING" + +unit: template +template-resource: ce-oem-rpmsg/rp-firmware-mapping +template-id: ce-oem-rpmsg/reload-rp-firmware-test +template-unit: job +_template-summary: Reload Remote Processor firmware via RPMSG +_summary: Reload Remote Processor firmware to {firmware} via RPMSG {device} +id: ce-oem-rpmsg/reload-rp-firmware-test-{firmware}-{device} +category_id: rpmsg +estimated_duration: 60 +requires: manifest.has_rpmsg == 'True' +imports: from com.canonical.plainbox import manifest +flags: also-after-suspend +user: root +plugin: shell +command: + rpmsg_load_firmware.py test-reload --device {device} --file {firmware} --path {path} \ No newline at end of file diff --git a/contrib/checkbox-ce-oem/checkbox-provider-ce-oem/units/rpmsg/test-plan.pxu b/contrib/checkbox-ce-oem/checkbox-provider-ce-oem/units/rpmsg/test-plan.pxu index f3c4782d9..2d1b754d4 100644 --- a/contrib/checkbox-ce-oem/checkbox-provider-ce-oem/units/rpmsg/test-plan.pxu +++ b/contrib/checkbox-ce-oem/checkbox-provider-ce-oem/units/rpmsg/test-plan.pxu @@ -1,6 +1,6 @@ id: ce-oem-rpmsg unit: test plan -_name: M-series core RPMSG test +_name: Remote Processor RPMSG test _description: Check RPMSG framework between A core and M core. include: nested_part: @@ -9,15 +9,18 @@ nested_part: id: ce-oem-rpmsg-manual unit: test plan -_name: M-series core RPMSG manual tests +_name: Remote Processor core RPMSG manual tests _description: Manual RPMSG framework tests include: id: ce-oem-rpmsg-automated unit: test plan -_name: M-series core RPMSG auto tests +_name: Remote Processor RPMSG auto tests _description: Automated RPMSG framework tests +bootstrap_include: + ce-oem-rpmsg/rp-firmware-mapping include: ce-oem-rpmsg/detect-device ce-oem-rpmsg/serial-tty ce-oem-rpmsg/pingpong + ce-oem-rpmsg/reload-rp-firmware-test From 18db579e28e43763cda85aac7c93aafd571b5f56 Mon Sep 17 00:00:00 2001 From: stanley31huang Date: Tue, 30 Apr 2024 16:05:55 +0800 Subject: [PATCH 02/15] Update contrib/checkbox-ce-oem/checkbox-provider-ce-oem/bin/rpmsg_load_firmware.py Co-authored-by: LiaoU3 <58060146+LiaoU3@users.noreply.github.com> --- .../checkbox-provider-ce-oem/bin/rpmsg_load_firmware.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 1283350c3..511eae083 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 @@ -99,7 +99,7 @@ def lookup_reload_logs(self, entry: dict): return keep_looking def _monitor_journal_logs(self, lookup_func): - start_time = datetime.datetime.now() + start_time = time.time() logging.info("# start time: %s", start_time) while self._poller.poll(1000): From 55c209f5b56940a335382aef7d84c9d2daa18efd Mon Sep 17 00:00:00 2001 From: stanley31huang Date: Tue, 30 Apr 2024 16:06:06 +0800 Subject: [PATCH 03/15] Update contrib/checkbox-ce-oem/checkbox-provider-ce-oem/bin/rpmsg_load_firmware.py Co-authored-by: LiaoU3 <58060146+LiaoU3@users.noreply.github.com> --- .../checkbox-provider-ce-oem/bin/rpmsg_load_firmware.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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 511eae083..8747f6f04 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 @@ -111,8 +111,8 @@ def _monitor_journal_logs(self, lookup_func): if lookup_func(entry) is False: return self.expected_events - cur_time = datetime.datetime.now() - if (cur_time - start_time).total_seconds() > 60: + cur_time = time.time() + if (cur_time - start_time) > 60: return self.expected_events From 6c37d72002b667480fb0bbcc1fa6b3ece066c78b Mon Sep 17 00:00:00 2001 From: stanley31huang Date: Tue, 30 Apr 2024 16:06:12 +0800 Subject: [PATCH 04/15] Update contrib/checkbox-ce-oem/checkbox-provider-ce-oem/bin/rpmsg_load_firmware.py Co-authored-by: LiaoU3 <58060146+LiaoU3@users.noreply.github.com> --- .../checkbox-provider-ce-oem/bin/rpmsg_load_firmware.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 8747f6f04..80d40cb3c 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 @@ -3,7 +3,7 @@ import sys import re import argparse -import datetime +import time import logging import select from collections import OrderedDict From 1e244cfcd2ed5a55a2228c01d083037bb67d1128 Mon Sep 17 00:00:00 2001 From: stanley31huang Date: Tue, 30 Apr 2024 16:06:35 +0800 Subject: [PATCH 05/15] Update contrib/checkbox-ce-oem/checkbox-provider-ce-oem/bin/rpmsg_load_firmware.py Co-authored-by: LiaoU3 <58060146+LiaoU3@users.noreply.github.com> --- .../bin/rpmsg_load_firmware.py | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) 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 80d40cb3c..d39a8fc94 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 @@ -103,13 +103,14 @@ def _monitor_journal_logs(self, lookup_func): logging.info("# start time: %s", start_time) while self._poller.poll(1000): - if self.log_reader.process() == journal.APPEND: - for entry in self.log_reader: - logging.debug(entry["MESSAGE"]) - if entry["MESSAGE"] == "": - continue - if lookup_func(entry) is False: - return self.expected_events + if self.log_reader.process() != journal.APPEND: + continue + for entry in self.log_reader: + logging.debug(entry["MESSAGE"]) + if entry["MESSAGE"] == "": + continue + if lookup_func(entry) is False: + return self.expected_events cur_time = time.time() if (cur_time - start_time) > 60: From 3fb48b64f634dbee377846c1a395427059e6ad65 Mon Sep 17 00:00:00 2001 From: stanley31huang Date: Thu, 2 May 2024 10:05:37 +0800 Subject: [PATCH 06/15] Update contrib/checkbox-ce-oem/checkbox-provider-ce-oem/units/rpmsg/jobs.pxu Co-authored-by: Pei Yao-Chang --- .../checkbox-provider-ce-oem/units/rpmsg/jobs.pxu | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contrib/checkbox-ce-oem/checkbox-provider-ce-oem/units/rpmsg/jobs.pxu b/contrib/checkbox-ce-oem/checkbox-provider-ce-oem/units/rpmsg/jobs.pxu index 924c8b80d..e0f71d32a 100644 --- a/contrib/checkbox-ce-oem/checkbox-provider-ce-oem/units/rpmsg/jobs.pxu +++ b/contrib/checkbox-ce-oem/checkbox-provider-ce-oem/units/rpmsg/jobs.pxu @@ -63,4 +63,4 @@ flags: also-after-suspend user: root plugin: shell command: - rpmsg_load_firmware.py test-reload --device {device} --file {firmware} --path {path} \ No newline at end of file + rpmsg_load_firmware.py test-reload --device {device} --file {firmware} --path {path} From 4b8e0e99adbaae42e6e78de5825e244c3afaae93 Mon Sep 17 00:00:00 2001 From: stanley31huang Date: Thu, 2 May 2024 10:05:47 +0800 Subject: [PATCH 07/15] Update contrib/checkbox-ce-oem/checkbox-provider-ce-oem/units/rpmsg/category.pxu Co-authored-by: Pei Yao-Chang --- .../checkbox-provider-ce-oem/units/rpmsg/category.pxu | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contrib/checkbox-ce-oem/checkbox-provider-ce-oem/units/rpmsg/category.pxu b/contrib/checkbox-ce-oem/checkbox-provider-ce-oem/units/rpmsg/category.pxu index 566fd6002..8677e2814 100644 --- a/contrib/checkbox-ce-oem/checkbox-provider-ce-oem/units/rpmsg/category.pxu +++ b/contrib/checkbox-ce-oem/checkbox-provider-ce-oem/units/rpmsg/category.pxu @@ -1,3 +1,3 @@ unit: category id: rpmsg -_name: Remote Processor Messaging (rpmsg) Framework test \ No newline at end of file +_name: Remote Processor Messaging (rpmsg) Framework test From bca89ab5533c71f0ff69abb27163166c5b0bd177 Mon Sep 17 00:00:00 2001 From: stanley31huang Date: Thu, 2 May 2024 10:06:03 +0800 Subject: [PATCH 08/15] Update contrib/checkbox-ce-oem/checkbox-provider-ce-oem/bin/rpmsg_load_firmware.py Co-authored-by: Pei Yao-Chang --- .../bin/rpmsg_load_firmware.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) 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 d39a8fc94..702d8a63d 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 @@ -1,4 +1,21 @@ #!/usr/bin/env python3 +# This file is part of Checkbox. +# +# Copyright 2024 Canonical Ltd. +# Written by: +# Stanley Huang +# +# Checkbox is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License version 3, +# as published by the Free Software Foundation. +# +# Checkbox is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with Checkbox. If not, see . import sys import re From c8525d09afb84d5c0122a5a90283499d2a32663a Mon Sep 17 00:00:00 2001 From: stanley31huang Date: Thu, 2 May 2024 10:06:12 +0800 Subject: [PATCH 09/15] Update contrib/checkbox-ce-oem/checkbox-provider-ce-oem/bin/rpmsg_load_firmware.py Co-authored-by: Pei Yao-Chang --- .../checkbox-provider-ce-oem/bin/rpmsg_load_firmware.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 702d8a63d..5b2103b88 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 @@ -95,7 +95,7 @@ def search_pattern(self) -> dict: def search_pattern(self, patterns: dict) -> None: self._search_patterns.update(patterns) - def _init_logger(self): + def _init_logger(self) -> None: self.log_reader = journal.Reader() self.log_reader.this_boot() self.log_reader.seek_tail() From 86cc5daf7d92c72ab2536d6f2e6bc05b72b59dcb Mon Sep 17 00:00:00 2001 From: stanley31huang Date: Thu, 2 May 2024 10:06:19 +0800 Subject: [PATCH 10/15] Update contrib/checkbox-ce-oem/checkbox-provider-ce-oem/bin/rpmsg_load_firmware.py Co-authored-by: Pei Yao-Chang --- .../checkbox-provider-ce-oem/bin/rpmsg_load_firmware.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 5b2103b88..7e9190e34 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 @@ -134,7 +134,7 @@ def _monitor_journal_logs(self, lookup_func): return self.expected_events -def verify_load_firmware_logs(match_records: list, search_stages: list): +def verify_load_firmware_logs(match_records: list, search_stages: list) -> bool: logging.info("Validate RPMSG related log from journal logs") logging.debug(match_records) actuall_stage = [] From ffb3429f2ab16715ce5ce6f69b16fb32c22bee0f Mon Sep 17 00:00:00 2001 From: stanley31huang Date: Thu, 2 May 2024 10:06:28 +0800 Subject: [PATCH 11/15] Update contrib/checkbox-ce-oem/checkbox-provider-ce-oem/bin/rpmsg_load_firmware.py Co-authored-by: Pei Yao-Chang --- .../checkbox-provider-ce-oem/bin/rpmsg_load_firmware.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 7e9190e34..aa9460576 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 @@ -196,7 +196,7 @@ def load_firmware_test(args): # getattr(module_c, extra_testing)() -def dump_firmware_test_mapping(args): +def dump_firmware_test_mapping(args) -> None: firmware_mapping = args.mapping firmware_path = args.path pattern = r"(\w*):([\w\.-]*)" From 91b97f079988d9dd0d3cf00df2f63a4a27679da0 Mon Sep 17 00:00:00 2001 From: stanley31huang Date: Thu, 2 May 2024 10:06:49 +0800 Subject: [PATCH 12/15] Update contrib/checkbox-ce-oem/checkbox-provider-ce-oem/bin/rpmsg_load_firmware.py Co-authored-by: Pei Yao-Chang --- .../checkbox-provider-ce-oem/bin/rpmsg_load_firmware.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 aa9460576..5b29797f5 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 @@ -146,7 +146,7 @@ def verify_load_firmware_logs(match_records: list, search_stages: list) -> bool: return set(actuall_stage) == set(search_stages) -def load_firmware_test(args): +def load_firmware_test(args) -> None: remote_proc_dev = args.device target_path = args.path target_file = args.file From 8ec3007172aec3dda617e78ae095b801347d3645 Mon Sep 17 00:00:00 2001 From: stanley31huang Date: Thu, 2 May 2024 10:06:57 +0800 Subject: [PATCH 13/15] Update contrib/checkbox-ce-oem/checkbox-provider-ce-oem/bin/rpmsg_load_firmware.py Co-authored-by: Pei Yao-Chang --- .../checkbox-provider-ce-oem/bin/rpmsg_load_firmware.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 5b29797f5..45362cc70 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 @@ -115,7 +115,7 @@ def lookup_reload_logs(self, entry: dict): return keep_looking - def _monitor_journal_logs(self, lookup_func): + def _monitor_journal_logs(self, lookup_func) -> list: start_time = time.time() logging.info("# start time: %s", start_time) From 97bdeaafafa9fdc51bf7e17c3397142d2d23f88e Mon Sep 17 00:00:00 2001 From: stanley31huang Date: Thu, 2 May 2024 10:07:04 +0800 Subject: [PATCH 14/15] Update contrib/checkbox-ce-oem/checkbox-provider-ce-oem/bin/rpmsg_load_firmware.py Co-authored-by: Pei Yao-Chang --- .../checkbox-provider-ce-oem/bin/rpmsg_load_firmware.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 45362cc70..e23ea6b51 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 @@ -104,7 +104,7 @@ def _init_logger(self) -> None: self._poller = select.poll() self._poller.register(self.log_reader, self.log_reader.get_events()) - def lookup_reload_logs(self, entry: dict): + def lookup_reload_logs(self, entry: dict) -> bool: keep_looking = True for key, pattern in self._search_patterns.items(): if re.search(pattern, entry.get("MESSAGE")): From 9072e1f6b2ff5d04a08a6579385c834167459dce Mon Sep 17 00:00:00 2001 From: stanley31huang Date: Thu, 2 May 2024 10:51:15 +0800 Subject: [PATCH 15/15] Fix black format issue fix black format issue --- .../checkbox-provider-ce-oem/bin/rpmsg_load_firmware.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) 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 e23ea6b51..af4f84504 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 @@ -134,7 +134,9 @@ def _monitor_journal_logs(self, lookup_func) -> list: return self.expected_events -def verify_load_firmware_logs(match_records: list, search_stages: list) -> bool: +def verify_load_firmware_logs( + match_records: list, search_stages: list +) -> bool: logging.info("Validate RPMSG related log from journal logs") logging.debug(match_records) actuall_stage = []