Simon Glass | c78ed66 | 2019-10-31 07:42:53 -0600 | [diff] [blame] | 1 | #!/usr/bin/env python3 |
Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 2 | # SPDX-License-Identifier: GPL-2.0+ |
Simon Glass | c05694f | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 3 | # |
| 4 | # Copyright (c) 2012 The Chromium OS Authors. |
| 5 | # |
Simon Glass | c05694f | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 6 | |
| 7 | """See README for more information""" |
| 8 | |
Simon Glass | c7643c1 | 2023-07-19 17:48:32 -0600 | [diff] [blame] | 9 | try: |
Simon Glass | c0cdbe4 | 2023-09-04 09:54:59 -0600 | [diff] [blame] | 10 | import importlib.resources |
Simon Glass | c7643c1 | 2023-07-19 17:48:32 -0600 | [diff] [blame] | 11 | except ImportError: |
| 12 | # for Python 3.6 |
| 13 | import importlib_resources |
Simon Glass | c05694f | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 14 | import os |
Simon Glass | c05694f | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 15 | import sys |
Simon Glass | c05694f | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 16 | |
| 17 | # Bring in the patman libraries |
Simon Glass | bb928de | 2023-07-19 17:48:29 -0600 | [diff] [blame] | 18 | # pylint: disable=C0413 |
Simon Glass | c05694f | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 19 | our_path = os.path.dirname(os.path.realpath(__file__)) |
Simon Glass | f0d9c10 | 2020-04-17 18:09:02 -0600 | [diff] [blame] | 20 | sys.path.insert(1, os.path.join(our_path, '..')) |
Simon Glass | c05694f | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 21 | |
| 22 | # Our modules |
Simon Glass | f0d9c10 | 2020-04-17 18:09:02 -0600 | [diff] [blame] | 23 | from buildman import bsettings |
Simon Glass | f0d9c10 | 2020-04-17 18:09:02 -0600 | [diff] [blame] | 24 | from buildman import cmdline |
| 25 | from buildman import control |
Simon Glass | 131444f | 2023-02-23 18:18:04 -0700 | [diff] [blame] | 26 | from u_boot_pylib import test_util |
Simon Glass | c7643c1 | 2023-07-19 17:48:32 -0600 | [diff] [blame] | 27 | from u_boot_pylib import tools |
Simon Glass | c05694f | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 28 | |
Simon Glass | bb928de | 2023-07-19 17:48:29 -0600 | [diff] [blame] | 29 | def run_tests(skip_net_tests, debug, verbose, args): |
Simon Glass | 1cd79c6 | 2023-07-19 17:48:09 -0600 | [diff] [blame] | 30 | """Run the buildman tests |
| 31 | |
| 32 | Args: |
| 33 | skip_net_tests (bool): True to skip tests which need the network |
Simon Glass | 7fd6615 | 2023-07-19 17:48:10 -0600 | [diff] [blame] | 34 | debug (bool): True to run in debugging mode (full traceback) |
Simon Glass | 1cd79c6 | 2023-07-19 17:48:09 -0600 | [diff] [blame] | 35 | verbosity (int): Verbosity level to use (0-4) |
| 36 | args (list of str): List of tests to run, empty to run all |
| 37 | """ |
Simon Glass | bb928de | 2023-07-19 17:48:29 -0600 | [diff] [blame] | 38 | # These imports are here since tests are not available when buildman is |
| 39 | # installed as a Python module |
| 40 | # pylint: disable=C0415 |
Simon Glass | e36fe01 | 2022-02-11 13:23:19 -0700 | [diff] [blame] | 41 | from buildman import func_test |
| 42 | from buildman import test |
Simon Glass | cc246fb | 2013-09-23 17:35:17 -0600 | [diff] [blame] | 43 | |
Simon Glass | a56ac99 | 2023-07-19 17:49:04 -0600 | [diff] [blame] | 44 | test_name = args.terms and args.terms[0] or None |
Simon Glass | 2bfc697 | 2017-11-12 21:52:14 -0700 | [diff] [blame] | 45 | if skip_net_tests: |
| 46 | test.use_network = False |
Simon Glass | c05694f | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 47 | |
Simon Glass | 6f484e4 | 2022-01-22 05:07:30 -0700 | [diff] [blame] | 48 | # Run the entry tests first ,since these need to be the first to import the |
| 49 | # 'entry' module. |
Alper Nebi Yasak | ca1c588 | 2022-04-02 20:06:06 +0300 | [diff] [blame] | 50 | result = test_util.run_test_suites( |
Simon Glass | c8b99b1 | 2023-07-19 17:49:31 -0600 | [diff] [blame] | 51 | 'buildman', debug, verbose, False, args.threads, test_name, [], |
Simon Glass | 6f484e4 | 2022-01-22 05:07:30 -0700 | [diff] [blame] | 52 | [test.TestBuild, func_test.TestFunctional, |
| 53 | 'buildman.toolchain', 'patman.gitutil']) |
Simon Glass | c05694f | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 54 | |
Alper Nebi Yasak | ca1c588 | 2022-04-02 20:06:06 +0300 | [diff] [blame] | 55 | return (0 if result.wasSuccessful() else 1) |
Simon Glass | c05694f | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 56 | |
Simon Glass | c8b99b1 | 2023-07-19 17:49:31 -0600 | [diff] [blame] | 57 | def run_test_coverage(): |
| 58 | """Run the tests and check that we get 100% coverage""" |
| 59 | test_util.run_test_coverage( |
| 60 | 'tools/buildman/buildman', None, |
| 61 | ['tools/patman/*.py', 'tools/u_boot_pylib/*', '*test_fdt.py', |
| 62 | 'tools/buildman/kconfiglib.py', 'tools/buildman/*test*.py', |
| 63 | 'tools/buildman/main.py'], |
| 64 | '/tmp/b', single_thread='-T1') |
| 65 | |
| 66 | |
Simon Glass | 62043e3 | 2023-02-23 18:18:09 -0700 | [diff] [blame] | 67 | def run_buildman(): |
Simon Glass | bb928de | 2023-07-19 17:48:29 -0600 | [diff] [blame] | 68 | """Run bulidman |
| 69 | |
| 70 | This is the main program. It collects arguments and runs either the tests or |
| 71 | the control module. |
| 72 | """ |
Simon Glass | a56ac99 | 2023-07-19 17:49:04 -0600 | [diff] [blame] | 73 | args = cmdline.parse_args() |
Simon Glass | c05694f | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 74 | |
Simon Glass | a56ac99 | 2023-07-19 17:49:04 -0600 | [diff] [blame] | 75 | if not args.debug: |
Simon Glass | 62043e3 | 2023-02-23 18:18:09 -0700 | [diff] [blame] | 76 | sys.tracebacklimit = 0 |
Simon Glass | 838ddf3 | 2022-01-22 05:07:29 -0700 | [diff] [blame] | 77 | |
Simon Glass | 62043e3 | 2023-02-23 18:18:09 -0700 | [diff] [blame] | 78 | # Run our meagre tests |
Simon Glass | a56ac99 | 2023-07-19 17:49:04 -0600 | [diff] [blame] | 79 | if cmdline.HAS_TESTS and args.test: |
| 80 | return run_tests(args.skip_net_tests, args.debug, args.verbose, args) |
Simon Glass | 62043e3 | 2023-02-23 18:18:09 -0700 | [diff] [blame] | 81 | |
Simon Glass | c8b99b1 | 2023-07-19 17:49:31 -0600 | [diff] [blame] | 82 | elif cmdline.HAS_TESTS and args.coverage: |
| 83 | run_test_coverage() |
| 84 | |
Simon Glass | a56ac99 | 2023-07-19 17:49:04 -0600 | [diff] [blame] | 85 | elif args.full_help: |
Simon Glass | c0cdbe4 | 2023-09-04 09:54:59 -0600 | [diff] [blame] | 86 | if hasattr(importlib.resources, 'files'): |
| 87 | dirpath = importlib.resources.files('buildman') |
| 88 | tools.print_full_help(str(dirpath.joinpath('README.rst'))) |
| 89 | else: |
| 90 | with importlib.resources.path('buildman', 'README.rst') as readme: |
| 91 | tools.print_full_help(str(readme)) |
| 92 | |
Simon Glass | c7643c1 | 2023-07-19 17:48:32 -0600 | [diff] [blame] | 93 | |
Simon Glass | 62043e3 | 2023-02-23 18:18:09 -0700 | [diff] [blame] | 94 | # Build selected commits for selected boards |
| 95 | else: |
Simon Glass | 06b83a5 | 2023-07-19 17:49:05 -0600 | [diff] [blame] | 96 | bsettings.setup(args.config_file) |
Simon Glass | a56ac99 | 2023-07-19 17:49:04 -0600 | [diff] [blame] | 97 | ret_code = control.do_buildman(args) |
Simon Glass | 44b0a7f | 2023-07-19 17:48:11 -0600 | [diff] [blame] | 98 | return ret_code |
Simon Glass | 62043e3 | 2023-02-23 18:18:09 -0700 | [diff] [blame] | 99 | |
Simon Glass | c05694f | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 100 | |
Simon Glass | 62043e3 | 2023-02-23 18:18:09 -0700 | [diff] [blame] | 101 | if __name__ == "__main__": |
Simon Glass | 44b0a7f | 2023-07-19 17:48:11 -0600 | [diff] [blame] | 102 | sys.exit(run_buildman()) |