blob: a948f36d9c0e7f04c30718ae58c6649339465734 [file] [log] [blame]
Simon Glassc78ed662019-10-31 07:42:53 -06001#!/usr/bin/env python3
Tom Rini10e47792018-05-06 17:58:06 -04002# SPDX-License-Identifier: GPL-2.0+
Simon Glassc05694f2013-04-03 11:07:16 +00003#
4# Copyright (c) 2012 The Chromium OS Authors.
5#
Simon Glassc05694f2013-04-03 11:07:16 +00006
7"""See README for more information"""
8
Simon Glassc7643c12023-07-19 17:48:32 -06009try:
Simon Glassc0cdbe42023-09-04 09:54:59 -060010 import importlib.resources
Simon Glassc7643c12023-07-19 17:48:32 -060011except ImportError:
12 # for Python 3.6
13 import importlib_resources
Simon Glassc05694f2013-04-03 11:07:16 +000014import os
Simon Glassc05694f2013-04-03 11:07:16 +000015import sys
Simon Glassc05694f2013-04-03 11:07:16 +000016
17# Bring in the patman libraries
Simon Glassbb928de2023-07-19 17:48:29 -060018# pylint: disable=C0413
Simon Glassc05694f2013-04-03 11:07:16 +000019our_path = os.path.dirname(os.path.realpath(__file__))
Simon Glassf0d9c102020-04-17 18:09:02 -060020sys.path.insert(1, os.path.join(our_path, '..'))
Simon Glassc05694f2013-04-03 11:07:16 +000021
22# Our modules
Simon Glassf0d9c102020-04-17 18:09:02 -060023from buildman import bsettings
Simon Glassf0d9c102020-04-17 18:09:02 -060024from buildman import cmdline
25from buildman import control
Simon Glass131444f2023-02-23 18:18:04 -070026from u_boot_pylib import test_util
Simon Glassc7643c12023-07-19 17:48:32 -060027from u_boot_pylib import tools
Simon Glass3a41bf82024-11-08 08:23:43 -070028from u_boot_pylib import tout
Simon Glassc05694f2013-04-03 11:07:16 +000029
Simon Glassbb928de2023-07-19 17:48:29 -060030def run_tests(skip_net_tests, debug, verbose, args):
Simon Glass1cd79c62023-07-19 17:48:09 -060031 """Run the buildman tests
32
33 Args:
34 skip_net_tests (bool): True to skip tests which need the network
Simon Glass7fd66152023-07-19 17:48:10 -060035 debug (bool): True to run in debugging mode (full traceback)
Simon Glass1cd79c62023-07-19 17:48:09 -060036 verbosity (int): Verbosity level to use (0-4)
37 args (list of str): List of tests to run, empty to run all
38 """
Simon Glassbb928de2023-07-19 17:48:29 -060039 # These imports are here since tests are not available when buildman is
40 # installed as a Python module
41 # pylint: disable=C0415
Simon Glasse36fe012022-02-11 13:23:19 -070042 from buildman import func_test
43 from buildman import test
Simon Glasscc246fb2013-09-23 17:35:17 -060044
Simon Glassa56ac992023-07-19 17:49:04 -060045 test_name = args.terms and args.terms[0] or None
Simon Glass2bfc6972017-11-12 21:52:14 -070046 if skip_net_tests:
47 test.use_network = False
Simon Glassc05694f2013-04-03 11:07:16 +000048
Simon Glass6f484e42022-01-22 05:07:30 -070049 # Run the entry tests first ,since these need to be the first to import the
50 # 'entry' module.
Alper Nebi Yasakca1c5882022-04-02 20:06:06 +030051 result = test_util.run_test_suites(
Simon Glassc8b99b12023-07-19 17:49:31 -060052 'buildman', debug, verbose, False, args.threads, test_name, [],
Simon Glass6f484e42022-01-22 05:07:30 -070053 [test.TestBuild, func_test.TestFunctional,
54 'buildman.toolchain', 'patman.gitutil'])
Simon Glassc05694f2013-04-03 11:07:16 +000055
Alper Nebi Yasakca1c5882022-04-02 20:06:06 +030056 return (0 if result.wasSuccessful() else 1)
Simon Glassc05694f2013-04-03 11:07:16 +000057
Simon Glassc8b99b12023-07-19 17:49:31 -060058def run_test_coverage():
59 """Run the tests and check that we get 100% coverage"""
60 test_util.run_test_coverage(
61 'tools/buildman/buildman', None,
62 ['tools/patman/*.py', 'tools/u_boot_pylib/*', '*test_fdt.py',
63 'tools/buildman/kconfiglib.py', 'tools/buildman/*test*.py',
64 'tools/buildman/main.py'],
65 '/tmp/b', single_thread='-T1')
66
67
Simon Glass62043e32023-02-23 18:18:09 -070068def run_buildman():
Simon Glassbb928de2023-07-19 17:48:29 -060069 """Run bulidman
70
71 This is the main program. It collects arguments and runs either the tests or
72 the control module.
73 """
Simon Glassa56ac992023-07-19 17:49:04 -060074 args = cmdline.parse_args()
Simon Glassc05694f2013-04-03 11:07:16 +000075
Simon Glassa56ac992023-07-19 17:49:04 -060076 if not args.debug:
Simon Glass62043e32023-02-23 18:18:09 -070077 sys.tracebacklimit = 0
Simon Glass838ddf32022-01-22 05:07:29 -070078
Simon Glass62043e32023-02-23 18:18:09 -070079 # Run our meagre tests
Simon Glassa56ac992023-07-19 17:49:04 -060080 if cmdline.HAS_TESTS and args.test:
81 return run_tests(args.skip_net_tests, args.debug, args.verbose, args)
Simon Glass62043e32023-02-23 18:18:09 -070082
Simon Glassc8b99b12023-07-19 17:49:31 -060083 elif cmdline.HAS_TESTS and args.coverage:
84 run_test_coverage()
85
Simon Glassa56ac992023-07-19 17:49:04 -060086 elif args.full_help:
Simon Glassc0cdbe42023-09-04 09:54:59 -060087 if hasattr(importlib.resources, 'files'):
88 dirpath = importlib.resources.files('buildman')
89 tools.print_full_help(str(dirpath.joinpath('README.rst')))
90 else:
91 with importlib.resources.path('buildman', 'README.rst') as readme:
92 tools.print_full_help(str(readme))
93
Simon Glassc7643c12023-07-19 17:48:32 -060094
Simon Glass62043e32023-02-23 18:18:09 -070095 # Build selected commits for selected boards
96 else:
Simon Glass3a41bf82024-11-08 08:23:43 -070097 try:
98 tout.init(tout.INFO if args.verbose else tout.WARNING)
99 bsettings.setup(args.config_file)
100 ret_code = control.do_buildman(args)
101 finally:
102 tout.uninit()
Simon Glass44b0a7f2023-07-19 17:48:11 -0600103 return ret_code
Simon Glass62043e32023-02-23 18:18:09 -0700104
Simon Glassc05694f2013-04-03 11:07:16 +0000105
Simon Glass62043e32023-02-23 18:18:09 -0700106if __name__ == "__main__":
Simon Glass44b0a7f2023-07-19 17:48:11 -0600107 sys.exit(run_buildman())