blob: 3cf877e5e6889c3b67aff7eedad68196341d0214 [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 Glassc05694f2013-04-03 11:07:16 +000028
Simon Glassbb928de2023-07-19 17:48:29 -060029def run_tests(skip_net_tests, debug, verbose, args):
Simon Glass1cd79c62023-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 Glass7fd66152023-07-19 17:48:10 -060034 debug (bool): True to run in debugging mode (full traceback)
Simon Glass1cd79c62023-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 Glassbb928de2023-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 Glasse36fe012022-02-11 13:23:19 -070041 from buildman import func_test
42 from buildman import test
Simon Glasscc246fb2013-09-23 17:35:17 -060043
Simon Glassa56ac992023-07-19 17:49:04 -060044 test_name = args.terms and args.terms[0] or None
Simon Glass2bfc6972017-11-12 21:52:14 -070045 if skip_net_tests:
46 test.use_network = False
Simon Glassc05694f2013-04-03 11:07:16 +000047
Simon Glass6f484e42022-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 Yasakca1c5882022-04-02 20:06:06 +030050 result = test_util.run_test_suites(
Simon Glassc8b99b12023-07-19 17:49:31 -060051 'buildman', debug, verbose, False, args.threads, test_name, [],
Simon Glass6f484e42022-01-22 05:07:30 -070052 [test.TestBuild, func_test.TestFunctional,
53 'buildman.toolchain', 'patman.gitutil'])
Simon Glassc05694f2013-04-03 11:07:16 +000054
Alper Nebi Yasakca1c5882022-04-02 20:06:06 +030055 return (0 if result.wasSuccessful() else 1)
Simon Glassc05694f2013-04-03 11:07:16 +000056
Simon Glassc8b99b12023-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 Glass62043e32023-02-23 18:18:09 -070067def run_buildman():
Simon Glassbb928de2023-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 Glassa56ac992023-07-19 17:49:04 -060073 args = cmdline.parse_args()
Simon Glassc05694f2013-04-03 11:07:16 +000074
Simon Glassa56ac992023-07-19 17:49:04 -060075 if not args.debug:
Simon Glass62043e32023-02-23 18:18:09 -070076 sys.tracebacklimit = 0
Simon Glass838ddf32022-01-22 05:07:29 -070077
Simon Glass62043e32023-02-23 18:18:09 -070078 # Run our meagre tests
Simon Glassa56ac992023-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 Glass62043e32023-02-23 18:18:09 -070081
Simon Glassc8b99b12023-07-19 17:49:31 -060082 elif cmdline.HAS_TESTS and args.coverage:
83 run_test_coverage()
84
Simon Glassa56ac992023-07-19 17:49:04 -060085 elif args.full_help:
Simon Glassc0cdbe42023-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 Glassc7643c12023-07-19 17:48:32 -060093
Simon Glass62043e32023-02-23 18:18:09 -070094 # Build selected commits for selected boards
95 else:
Simon Glass06b83a52023-07-19 17:49:05 -060096 bsettings.setup(args.config_file)
Simon Glassa56ac992023-07-19 17:49:04 -060097 ret_code = control.do_buildman(args)
Simon Glass44b0a7f2023-07-19 17:48:11 -060098 return ret_code
Simon Glass62043e32023-02-23 18:18:09 -070099
Simon Glassc05694f2013-04-03 11:07:16 +0000100
Simon Glass62043e32023-02-23 18:18:09 -0700101if __name__ == "__main__":
Simon Glass44b0a7f2023-07-19 17:48:11 -0600102 sys.exit(run_buildman())