blob: 3cf877e5e6889c3b67aff7eedad68196341d0214 [file] [log] [blame]
Simon Glassc05aa032019-10-31 07:42:53 -06001#!/usr/bin/env python3
Tom Rini83d290c2018-05-06 17:58:06 -04002# SPDX-License-Identifier: GPL-2.0+
Simon Glassfc3fe1c2013-04-03 11:07:16 +00003#
4# Copyright (c) 2012 The Chromium OS Authors.
5#
Simon Glassfc3fe1c2013-04-03 11:07:16 +00006
7"""See README for more information"""
8
Simon Glass309f0f12023-07-19 17:48:32 -06009try:
Simon Glass305114e2023-09-04 09:54:59 -060010 import importlib.resources
Simon Glass309f0f12023-07-19 17:48:32 -060011except ImportError:
12 # for Python 3.6
13 import importlib_resources
Simon Glassfc3fe1c2013-04-03 11:07:16 +000014import os
Simon Glassfc3fe1c2013-04-03 11:07:16 +000015import sys
Simon Glassfc3fe1c2013-04-03 11:07:16 +000016
17# Bring in the patman libraries
Simon Glass2ce6f9f2023-07-19 17:48:29 -060018# pylint: disable=C0413
Simon Glassfc3fe1c2013-04-03 11:07:16 +000019our_path = os.path.dirname(os.path.realpath(__file__))
Simon Glass0ede00f2020-04-17 18:09:02 -060020sys.path.insert(1, os.path.join(our_path, '..'))
Simon Glassfc3fe1c2013-04-03 11:07:16 +000021
22# Our modules
Simon Glass0ede00f2020-04-17 18:09:02 -060023from buildman import bsettings
Simon Glass0ede00f2020-04-17 18:09:02 -060024from buildman import cmdline
25from buildman import control
Simon Glass4583c002023-02-23 18:18:04 -070026from u_boot_pylib import test_util
Simon Glass309f0f12023-07-19 17:48:32 -060027from u_boot_pylib import tools
Simon Glassfc3fe1c2013-04-03 11:07:16 +000028
Simon Glass2ce6f9f2023-07-19 17:48:29 -060029def run_tests(skip_net_tests, debug, verbose, args):
Simon Glass2ef22f82023-07-19 17:48:09 -060030 """Run the buildman tests
31
32 Args:
33 skip_net_tests (bool): True to skip tests which need the network
Simon Glasseadbfa62023-07-19 17:48:10 -060034 debug (bool): True to run in debugging mode (full traceback)
Simon Glass2ef22f82023-07-19 17:48:09 -060035 verbosity (int): Verbosity level to use (0-4)
36 args (list of str): List of tests to run, empty to run all
37 """
Simon Glass2ce6f9f2023-07-19 17:48:29 -060038 # These imports are here since tests are not available when buildman is
39 # installed as a Python module
40 # pylint: disable=C0415
Simon Glassac053352022-02-11 13:23:19 -070041 from buildman import func_test
42 from buildman import test
Simon Glass4281ad82013-09-23 17:35:17 -060043
Simon Glass529957c2023-07-19 17:49:04 -060044 test_name = args.terms and args.terms[0] or None
Simon Glasscb39a102017-11-12 21:52:14 -070045 if skip_net_tests:
46 test.use_network = False
Simon Glassfc3fe1c2013-04-03 11:07:16 +000047
Simon Glassd10dc402022-01-22 05:07:30 -070048 # Run the entry tests first ,since these need to be the first to import the
49 # 'entry' module.
Alper Nebi Yasakd8318fe2022-04-02 20:06:06 +030050 result = test_util.run_test_suites(
Simon Glass407a1412023-07-19 17:49:31 -060051 'buildman', debug, verbose, False, args.threads, test_name, [],
Simon Glassd10dc402022-01-22 05:07:30 -070052 [test.TestBuild, func_test.TestFunctional,
53 'buildman.toolchain', 'patman.gitutil'])
Simon Glassfc3fe1c2013-04-03 11:07:16 +000054
Alper Nebi Yasakd8318fe2022-04-02 20:06:06 +030055 return (0 if result.wasSuccessful() else 1)
Simon Glassfc3fe1c2013-04-03 11:07:16 +000056
Simon Glass407a1412023-07-19 17:49:31 -060057def 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 Glass793aa172023-02-23 18:18:09 -070067def run_buildman():
Simon Glass2ce6f9f2023-07-19 17:48:29 -060068 """Run bulidman
69
70 This is the main program. It collects arguments and runs either the tests or
71 the control module.
72 """
Simon Glass529957c2023-07-19 17:49:04 -060073 args = cmdline.parse_args()
Simon Glassfc3fe1c2013-04-03 11:07:16 +000074
Simon Glass529957c2023-07-19 17:49:04 -060075 if not args.debug:
Simon Glass793aa172023-02-23 18:18:09 -070076 sys.tracebacklimit = 0
Simon Glass433fa542022-01-22 05:07:29 -070077
Simon Glass793aa172023-02-23 18:18:09 -070078 # Run our meagre tests
Simon Glass529957c2023-07-19 17:49:04 -060079 if cmdline.HAS_TESTS and args.test:
80 return run_tests(args.skip_net_tests, args.debug, args.verbose, args)
Simon Glassfc3fe1c2013-04-03 11:07:16 +000081
Simon Glass407a1412023-07-19 17:49:31 -060082 elif cmdline.HAS_TESTS and args.coverage:
83 run_test_coverage()
84
Simon Glass529957c2023-07-19 17:49:04 -060085 elif args.full_help:
Simon Glass305114e2023-09-04 09:54:59 -060086 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 Glass309f0f12023-07-19 17:48:32 -060093
Simon Glass793aa172023-02-23 18:18:09 -070094 # Build selected commits for selected boards
95 else:
Simon Glass42d42cf2023-07-19 17:49:05 -060096 bsettings.setup(args.config_file)
Simon Glass529957c2023-07-19 17:49:04 -060097 ret_code = control.do_buildman(args)
Simon Glass8dae07a2023-07-19 17:48:11 -060098 return ret_code
Simon Glass793aa172023-02-23 18:18:09 -070099
100
101if __name__ == "__main__":
Simon Glass8dae07a2023-07-19 17:48:11 -0600102 sys.exit(run_buildman())