diff options
Diffstat (limited to 'util')
28 files changed, 298 insertions, 38 deletions
diff --git a/util/build_with_clang.py b/util/build_with_clang.py index cc4397cab1..ea3a244797 100755 --- a/util/build_with_clang.py +++ b/util/build_with_clang.py @@ -7,6 +7,7 @@ """Build firmware with clang instead of gcc.""" import argparse import concurrent +from concurrent.futures import ThreadPoolExecutor import logging import multiprocessing import os @@ -14,7 +15,7 @@ import shutil import subprocess import sys import typing -from concurrent.futures import ThreadPoolExecutor + # Add to this list as compilation errors are fixed for boards. BOARDS_THAT_COMPILE_SUCCESSFULLY_WITH_CLANG = [ @@ -105,6 +106,7 @@ BOARDS_THAT_COMPILE_SUCCESSFULLY_WITH_CLANG = [ "ambassador", "anahera", "atlas", + "aurash", "banshee", "berknip", "bloog", @@ -117,6 +119,7 @@ BOARDS_THAT_COMPILE_SUCCESSFULLY_WITH_CLANG = [ "casta", "chronicler", "collis", + "constitution", "copano", "coral", "corori", diff --git a/util/check_zephyr_project_config.py b/util/check_zephyr_project_config.py index a49e9855b9..d879a9f04e 100755 --- a/util/check_zephyr_project_config.py +++ b/util/check_zephyr_project_config.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python3 +#!/usr/bin/env vpython3 # Copyright 2023 The ChromiumOS Authors # Use of this source code is governed by a BSD-style license that can be @@ -14,6 +14,7 @@ import site import sys import tempfile + EC_BASE = pathlib.Path(__file__).parent.parent if "ZEPHYR_BASE" in os.environ: @@ -35,6 +36,7 @@ site.addsitedir(ZEPHYR_BASE / "scripts" / "kconfig") import kconfiglib import zephyr_module + # pylint:enable=import-error,wrong-import-position # Known configuration file extensions. diff --git a/util/check_zephyr_project_config.py.vpython3 b/util/check_zephyr_project_config.py.vpython3 new file mode 120000 index 0000000000..d586316989 --- /dev/null +++ b/util/check_zephyr_project_config.py.vpython3 @@ -0,0 +1 @@ +../../../third_party/zephyr/main/.vpython3
\ No newline at end of file diff --git a/util/check_zephyr_project_config_unittest.py b/util/check_zephyr_project_config_unittest.py index ad28d8e128..d881cc5a91 100755 --- a/util/check_zephyr_project_config_unittest.py +++ b/util/check_zephyr_project_config_unittest.py @@ -13,6 +13,7 @@ import unittest import check_zephyr_project_config import mock # pylint:disable=import-error + # pylint:disable=protected-access diff --git a/util/clangd_config.py b/util/clangd_config.py index 1e013b4159..e9b23e3a04 100755 --- a/util/clangd_config.py +++ b/util/clangd_config.py @@ -10,10 +10,10 @@ import argparse import glob import multiprocessing import os +from pathlib import Path import shutil import subprocess import sys -from pathlib import Path from typing import List, Optional diff --git a/util/config_allowed.txt b/util/config_allowed.txt index 3c792ae0fb..1b4bc1c107 100644 --- a/util/config_allowed.txt +++ b/util/config_allowed.txt @@ -491,7 +491,6 @@ CONFIG_I2C_CONTROLLER CONFIG_I2C_EXTRA_PACKET_SIZE CONFIG_I2C_HID_TOUCHPAD CONFIG_I2C_MULTI_PORT_CONTROLLER -CONFIG_I2C_NACK_RETRY_COUNT CONFIG_I2C_PERIPHERAL CONFIG_I2C_SCL_GATE_ADDR CONFIG_I2C_SCL_GATE_ADDR_FLAGS diff --git a/util/crash_analyzer.py b/util/crash_analyzer.py index 88592f800a..d564984500 100755 --- a/util/crash_analyzer.py +++ b/util/crash_analyzer.py @@ -10,6 +10,7 @@ import pathlib import re import sys + # TODO(b/253492108): Add regexp for missing architectures. # Regex tested here: https://regex101.com/r/K5S8cB/1 _REGEX_CORTEX_M0 = ( diff --git a/util/ec3po/console.py b/util/ec3po/console.py index 12b31baa60..cc822a7073 100755 --- a/util/ec3po/console.py +++ b/util/ec3po/console.py @@ -17,6 +17,7 @@ from __future__ import print_function import argparse import binascii import ctypes +from datetime import datetime import logging import os import pty @@ -25,10 +26,11 @@ import select import stat import sys import traceback -from datetime import datetime +from ec3po import interpreter +from ec3po import threadproc_shim import six -from ec3po import interpreter, threadproc_shim + PROMPT = b"> " CONSOLE_INPUT_LINE_SIZE = 80 # Taken from the CONFIG_* with the same name. diff --git a/util/ec3po/console_unittest.py b/util/ec3po/console_unittest.py index e2a3d588fd..dfa411f3c8 100755 --- a/util/ec3po/console_unittest.py +++ b/util/ec3po/console_unittest.py @@ -14,9 +14,12 @@ import logging import tempfile import unittest +from ec3po import console +from ec3po import interpreter +from ec3po import threadproc_shim import mock # pylint:disable=import-error import six -from ec3po import console, interpreter, threadproc_shim + ESC_STRING = six.int2byte(console.ControlKey.ESC) diff --git a/util/ec3po/interpreter.py b/util/ec3po/interpreter.py index 8d21af247a..16c047039b 100644 --- a/util/ec3po/interpreter.py +++ b/util/ec3po/interpreter.py @@ -25,6 +25,7 @@ import traceback import six + COMMAND_RETRIES = 3 # Number of attempts to retry a command. EC_MAX_READ = 1024 # Max bytes to read at a time from the EC. EC_SYN = b"\xec" # Byte indicating EC interrogation. diff --git a/util/ec3po/interpreter_unittest.py b/util/ec3po/interpreter_unittest.py index e8f19e2e46..a6bfd3baec 100755 --- a/util/ec3po/interpreter_unittest.py +++ b/util/ec3po/interpreter_unittest.py @@ -13,9 +13,10 @@ import logging import tempfile import unittest +from ec3po import interpreter +from ec3po import threadproc_shim import mock # pylint:disable=import-error import six -from ec3po import interpreter, threadproc_shim def GetBuiltins(func): diff --git a/util/ec3po/threadproc_shim.py b/util/ec3po/threadproc_shim.py index f76841dbf7..b468de1535 100644 --- a/util/ec3po/threadproc_shim.py +++ b/util/ec3po/threadproc_shim.py @@ -38,6 +38,7 @@ from threading import Thread as ThreadOrProcess from six.moves.queue import Queue + # True if this module has ec3po using subprocesses, False if using threads. USING_SUBPROCS = False diff --git a/util/ec_openocd.py b/util/ec_openocd.py index e0a15bd08b..4d114d4343 100755 --- a/util/ec_openocd.py +++ b/util/ec_openocd.py @@ -12,6 +12,7 @@ import subprocess import sys import time + """ Flashes and debugs the EC through openocd """ diff --git a/util/ectool.cc b/util/ectool.cc index c997e8e7c3..6a7768b130 100644 --- a/util/ectool.cc +++ b/util/ectool.cc @@ -3647,9 +3647,6 @@ static int print_fan(int idx) switch (rv) { case EC_FAN_SPEED_NOT_PRESENT: return -1; - case EC_FAN_SPEED_STALLED: - printf("Fan %d stalled!\n", idx); - break; default: printf("Fan %d RPM: %d\n", idx, rv); break; diff --git a/util/flash_jlink.py b/util/flash_jlink.py index dc462e354b..9f4a55e544 100755 --- a/util/flash_jlink.py +++ b/util/flash_jlink.py @@ -25,6 +25,7 @@ import sys import tempfile import time + DEFAULT_SEGGER_REMOTE_PORT = 19020 # Commands are documented here: https://wiki.segger.com/J-Link_Commander diff --git a/util/inject-keys.py b/util/inject-keys.py index 7ff72ea134..71eb7a3281 100755 --- a/util/inject-keys.py +++ b/util/inject-keys.py @@ -13,6 +13,7 @@ import string import subprocess import sys + KEYMATRIX = { "`": (3, 1), "1": (6, 1), diff --git a/util/kconfig_check.py b/util/kconfig_check.py index f3d127175c..1b67f0c846 100755 --- a/util/kconfig_check.py +++ b/util/kconfig_check.py @@ -27,6 +27,7 @@ import re import sys import traceback + # Try to use kconfiglib if available, but fall back to a simple recursive grep. # This is used by U-Boot in some situations so we keep it to avoid forking this # script. diff --git a/util/lcov_stencil.py b/util/lcov_stencil.py index 12d613c6a4..ba08f0ccaa 100755 --- a/util/lcov_stencil.py +++ b/util/lcov_stencil.py @@ -13,12 +13,13 @@ https://github.com/linux-test-project/lcov/blob/master/bin/geninfo """ import argparse +from collections import defaultdict import logging import re import sys -from collections import defaultdict from typing import Dict, Set + EXTRACT_LINE = re.compile(r"^(FN|DA|BRDA):(\d+),") EXTRACT_FN = re.compile(r"^(FN):(\d+),(\S+)") EXTRACT_FNDA = re.compile(r"^(FNDA):(\d+),(\S+)") diff --git a/util/presubmit_check.sh b/util/presubmit_check.sh index 5cec68ddd4..0fcd4a3319 100755 --- a/util/presubmit_check.sh +++ b/util/presubmit_check.sh @@ -19,26 +19,3 @@ if git diff --no-ext-diff "${upstream_branch}" HEAD | echo "error: CPRINTS strings should not include newline characters" >&2 exit 1 fi - -# Directories that need to be tested by separate unit tests. -unittest_dirs="util/ec3po/ extra/stack_analyzer/" - -for dir in $unittest_dirs; do - dir_files=$(echo "${PRESUBMIT_FILES}" | grep "${dir}") - if [[ -z "${dir_files}" ]]; then - continue - fi - - if [[ ! -e "${dir}/.tests-passed" ]]; then - echo "Unit tests have not passed. Please run \"${dir}run_tests.sh\"." - exit 1 - fi - - changed_files=$(find ${dir_files} -newer "${dir}/.tests-passed") - if [[ -n "${changed_files}" ]] && [[ -n "${dir_files}" ]]; then - echo "Files have changed since last time unit tests passed:" - echo "${changed_files}" | sed -e 's/^/ /' - echo "Please run \"${dir}run_tests.sh\"." - exit 1 - fi -done diff --git a/util/run_ects.py b/util/run_ects.py index a3bf4d295c..e9ab944938 100644 --- a/util/run_ects.py +++ b/util/run_ects.py @@ -11,6 +11,7 @@ import os import subprocess import sys + # List of tests to run. TESTS = ["meta", "gpio", "hook", "i2c", "interrupt", "mutex", "task", "timer"] diff --git a/util/run_tests.sh b/util/run_tests.sh index 56732ee13e..729faf517d 100755 --- a/util/run_tests.sh +++ b/util/run_tests.sh @@ -26,3 +26,7 @@ cd util # NOTE: this uses the Zephyr version of kconfiglib, runs separately from # test_kconfig_check.py pytest check_zephyr_project_config_unittest.py + +# Run the Zephyr check_compliance wrapper test. +# NOTE: this uses vpython so it does not run correctly through pytest. +./zephyr_check_compliance_unittest.py diff --git a/util/test_kconfig_check.py b/util/test_kconfig_check.py index 3e459006b1..e30df416fb 100644 --- a/util/test_kconfig_check.py +++ b/util/test_kconfig_check.py @@ -14,6 +14,7 @@ import unittest import kconfig_check + # Prefix that we strip from each Kconfig option, when considering whether it is # equivalent to a CONFIG option with the same name PREFIX = "PLATFORM_EC_" diff --git a/util/twister_launcher.py b/util/twister_launcher.py index 2d6fe9616a..9178b142d9 100755 --- a/util/twister_launcher.py +++ b/util/twister_launcher.py @@ -82,16 +82,16 @@ import argparse import json import os import pathlib +from pathlib import Path import re import shlex import shutil +from shutil import which import socket import subprocess import sys import tempfile import time -from pathlib import Path -from shutil import which def find_checkout() -> Path: diff --git a/util/twister_tags.py b/util/twister_tags.py index 68ac5846bd..851c526bac 100755 --- a/util/twister_tags.py +++ b/util/twister_tags.py @@ -24,6 +24,7 @@ import sys import yaml # pylint: disable=import-error + TAG_TO_DESCRIPTION = { "common": "Directly test shared code in the ec/common dir", "mkbp": "Testing the MKBP (Matrix Keyboard Protocol) stack", diff --git a/util/uart_stress_tester.py b/util/uart_stress_tester.py index 8abb71d144..2e96174930 100755 --- a/util/uart_stress_tester.py +++ b/util/uart_stress_tester.py @@ -17,7 +17,9 @@ Prerequisite: e.g. dut-control cr50_uart_timestamp:off """ -from __future__ import absolute_import, division, print_function +from __future__ import absolute_import +from __future__ import division +from __future__ import print_function import argparse import atexit @@ -30,6 +32,7 @@ import time import serial # pylint:disable=import-error + BAUDRATE = 115200 # Default baudrate setting for UART port CROS_USERNAME = "root" # Account name to login to ChromeOS CROS_PASSWORD = "test0000" # Password to login to ChromeOS diff --git a/util/update_release_branch.py b/util/update_release_branch.py index 939d572dc4..93527c312c 100755 --- a/util/update_release_branch.py +++ b/util/update_release_branch.py @@ -19,6 +19,7 @@ import subprocess import sys import textwrap + BUG_NONE_PATTERN = re.compile("none", flags=re.IGNORECASE) diff --git a/util/zephyr_check_compliance.py b/util/zephyr_check_compliance.py new file mode 100755 index 0000000000..24fea8594e --- /dev/null +++ b/util/zephyr_check_compliance.py @@ -0,0 +1,136 @@ +#!/usr/bin/env vpython3 + +# Copyright 2023 The ChromiumOS Authors +# Use of this source code is governed by a BSD-style license that can be +# found in the LICENSE file. + +"""Check a single commit using the Zephyr check_compliance.py script.""" + +# [VPYTHON:BEGIN] +# python_version: "3.8" +# wheel: < +# name: "infra/python/wheels/junitparser-py2_py3" +# version: "version:2.8.0" +# > +# wheel: < +# name: "infra/python/wheels/future-py2_py3" +# version: "version:0.18.2" +# > +# wheel: < +# name: "infra/python/wheels/python-magic-py2_py3" +# version: "version:0.4.24" +# > +# wheel: < +# name: "infra/python/wheels/pyyaml-py3" +# version: "version:5.3.1" +# > +# wheel: < +# name: "infra/python/wheels/yamllint-py3" +# version: "version:1.29.0" +# > +# wheel: < +# name: "infra/python/wheels/pathspec-py3" +# version: "version:0.9.0" +# > +# wheel: < +# name: "infra/python/wheels/lxml/${vpython_platform}" +# version: "version:4.6.3" +# > +# [VPYTHON:END] + +import argparse +import os +import pathlib +import site +import sys + + +EC_BASE = pathlib.Path(__file__).parent.parent + +if "ZEPHYR_BASE" in os.environ: + ZEPHYR_BASE = pathlib.Path(os.environ.get("ZEPHYR_BASE")) +else: + ZEPHYR_BASE = pathlib.Path( + EC_BASE.resolve().parent.parent / "third_party" / "zephyr" / "main" + ) + +site.addsitedir(ZEPHYR_BASE / "scripts" / "ci") +# pylint:disable=import-error,wrong-import-position +import check_compliance + + +# pylint:enable=import-error,wrong-import-position + + +# Fake ref used by "pre-upload.py --pre-submit" +PRE_SUBMIT_REF = "pre-submit" + + +def _parse_args(argv): + parser = argparse.ArgumentParser(description=__doc__) + + parser.add_argument( + "commit", + help="Git commit to be checked, hash or reference.", + ) + + return parser.parse_args(argv) + + +def _patch_get_files(): + """Patch compliance get_files() to exclude non zephyr files.""" + original_get_files = check_compliance.get_files + + def patched_get_files(**kwargs): + out = [] + for file in original_get_files(**kwargs): + if file.startswith("zephyr/"): + out.append(file) + return out + + check_compliance.get_files = patched_get_files + + +def _changed_files(commit_range): + check_compliance.COMMIT_RANGE = commit_range + check_compliance.GIT_TOP = EC_BASE + + files = check_compliance.get_files(filter="d") + if len(files) > 0: + return True + + return False + + +def main(argv): + """Main function""" + args = _parse_args(argv) + + if args.commit == PRE_SUBMIT_REF: + # Skip if there's no actual commit + return + + commit_range = f"{args.commit}~1..{args.commit}" + + _patch_get_files() + + if not _changed_files(commit_range): + # Exit early if nothing changed + return + + # TODO: also enable DevicetreeBindings + check_compliance.main( + [ + "--output=", + "--no-case-output", + "-m", + "YAMLLint", + "-c", + commit_range, + ] + ) + # Never returns, check_compliance.main() calls sys.exit() + + +if __name__ == "__main__": + main(sys.argv[1:]) diff --git a/util/zephyr_check_compliance_unittest.py b/util/zephyr_check_compliance_unittest.py new file mode 100755 index 0000000000..1d4be968d0 --- /dev/null +++ b/util/zephyr_check_compliance_unittest.py @@ -0,0 +1,119 @@ +#!/usr/bin/env vpython3 + +# Copyright 2023 The ChromiumOS Authors +# Use of this source code is governed by a BSD-style license that can be +# found in the LICENSE file. + +"""Unit tests for check_zephyr_project_config.py""" + +# [VPYTHON:BEGIN] +# python_version: "3.8" +# wheel: < +# name: "infra/python/wheels/mock-py3" +# version: "version:4.0.3" +# > +# wheel: < +# name: "infra/python/wheels/junitparser-py2_py3" +# version: "version:2.8.0" +# > +# wheel: < +# name: "infra/python/wheels/future-py2_py3" +# version: "version:0.18.2" +# > +# wheel: < +# name: "infra/python/wheels/python-magic-py2_py3" +# version: "version:0.4.24" +# > +# wheel: < +# name: "infra/python/wheels/pyyaml-py3" +# version: "version:5.3.1" +# > +# wheel: < +# name: "infra/python/wheels/yamllint-py3" +# version: "version:1.29.0" +# > +# wheel: < +# name: "infra/python/wheels/pathspec-py3" +# version: "version:0.9.0" +# > +# wheel: < +# name: "infra/python/wheels/lxml/${vpython_platform}" +# version: "version:4.6.3" +# > +# [VPYTHON:END] + +import unittest + +import mock # pylint:disable=import-error +import zephyr_check_compliance + + +# pylint:disable=protected-access,no-self-use + + +class TestZephyrCheckCompliance(unittest.TestCase): + """Tests for zephyr_check_compliance.""" + + @mock.patch("check_compliance.get_files") + def test_changed_files(self, get_files_mock): + """Test _changed_files.""" + get_files_mock.return_value = [ + "file1", + "file2", + ] + + zephyr_check_compliance._patch_get_files() + out = zephyr_check_compliance._changed_files("ref") + self.assertFalse(out) + + get_files_mock.return_value.append("zephyr/file3") + + zephyr_check_compliance._patch_get_files() + out = zephyr_check_compliance._changed_files("ref") + self.assertTrue(out) + + @mock.patch("zephyr_check_compliance._changed_files") + @mock.patch("check_compliance.main") + def test_main(self, main_mock, changed_files_mock): + """Tests the main function.""" + changed_files_mock.return_value = True + + zephyr_check_compliance.main(["ref"]) + + changed_files_mock.assert_called_with("ref~1..ref") + main_mock.assert_called_with( + [ + "--output=", + "--no-case-output", + "-m", + "YAMLLint", + "-c", + "ref~1..ref", + ] + ) + + @mock.patch("zephyr_check_compliance._changed_files") + @mock.patch("check_compliance.main") + def test_main_skip_presubmit(self, main_mock, changed_files_mock): + """Tests the main function.""" + changed_files_mock.return_value = False + + zephyr_check_compliance.main([zephyr_check_compliance.PRE_SUBMIT_REF]) + + self.assertEqual(changed_files_mock.call_count, 0) + self.assertEqual(main_mock.call_count, 0) + + @mock.patch("zephyr_check_compliance._changed_files") + @mock.patch("check_compliance.main") + def test_main_skip(self, main_mock, changed_files_mock): + """Tests the main function.""" + changed_files_mock.return_value = False + + zephyr_check_compliance.main(["ref"]) + + changed_files_mock.assert_called_with("ref~1..ref") + self.assertEqual(main_mock.call_count, 0) + + +if __name__ == "__main__": + unittest.main() |