blob: d9ad83621509bb9e864f46a997cbd4539d340e23 [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 Glassc05694f2013-04-03 11:07:16 +00009import os
Simon Glassc05694f2013-04-03 11:07:16 +000010import sys
Simon Glassc05694f2013-04-03 11:07:16 +000011
12# Bring in the patman libraries
Simon Glassbb928de2023-07-19 17:48:29 -060013# pylint: disable=C0413
Simon Glassc05694f2013-04-03 11:07:16 +000014our_path = os.path.dirname(os.path.realpath(__file__))
Simon Glassf0d9c102020-04-17 18:09:02 -060015sys.path.insert(1, os.path.join(our_path, '..'))
Simon Glassc05694f2013-04-03 11:07:16 +000016
17# Our modules
Simon Glassf0d9c102020-04-17 18:09:02 -060018from buildman import bsettings
Simon Glassf0d9c102020-04-17 18:09:02 -060019from buildman import cmdline
20from buildman import control
Simon Glass131444f2023-02-23 18:18:04 -070021from u_boot_pylib import test_util
Simon Glassc05694f2013-04-03 11:07:16 +000022
Simon Glassbb928de2023-07-19 17:48:29 -060023def run_tests(skip_net_tests, debug, verbose, args):
Simon Glass1cd79c62023-07-19 17:48:09 -060024 """Run the buildman tests
25
26 Args:
27 skip_net_tests (bool): True to skip tests which need the network
Simon Glass7fd66152023-07-19 17:48:10 -060028 debug (bool): True to run in debugging mode (full traceback)
Simon Glass1cd79c62023-07-19 17:48:09 -060029 verbosity (int): Verbosity level to use (0-4)
30 args (list of str): List of tests to run, empty to run all
31 """
Simon Glassbb928de2023-07-19 17:48:29 -060032 # These imports are here since tests are not available when buildman is
33 # installed as a Python module
34 # pylint: disable=C0415
Simon Glasse36fe012022-02-11 13:23:19 -070035 from buildman import func_test
36 from buildman import test
Simon Glasscc246fb2013-09-23 17:35:17 -060037
Simon Glass6f484e42022-01-22 05:07:30 -070038 test_name = args and args[0] or None
Simon Glass2bfc6972017-11-12 21:52:14 -070039 if skip_net_tests:
40 test.use_network = False
Simon Glassc05694f2013-04-03 11:07:16 +000041
Simon Glass6f484e42022-01-22 05:07:30 -070042 # Run the entry tests first ,since these need to be the first to import the
43 # 'entry' module.
Alper Nebi Yasakca1c5882022-04-02 20:06:06 +030044 result = test_util.run_test_suites(
Simon Glass7fd66152023-07-19 17:48:10 -060045 'buildman', debug, verbose, False, None, test_name, [],
Simon Glass6f484e42022-01-22 05:07:30 -070046 [test.TestBuild, func_test.TestFunctional,
47 'buildman.toolchain', 'patman.gitutil'])
Simon Glassc05694f2013-04-03 11:07:16 +000048
Alper Nebi Yasakca1c5882022-04-02 20:06:06 +030049 return (0 if result.wasSuccessful() else 1)
Simon Glassc05694f2013-04-03 11:07:16 +000050
Simon Glass62043e32023-02-23 18:18:09 -070051def run_buildman():
Simon Glassbb928de2023-07-19 17:48:29 -060052 """Run bulidman
53
54 This is the main program. It collects arguments and runs either the tests or
55 the control module.
56 """
Simon Glass62043e32023-02-23 18:18:09 -070057 options, args = cmdline.ParseArgs()
Simon Glassc05694f2013-04-03 11:07:16 +000058
Simon Glass62043e32023-02-23 18:18:09 -070059 if not options.debug:
60 sys.tracebacklimit = 0
Simon Glass838ddf32022-01-22 05:07:29 -070061
Simon Glass62043e32023-02-23 18:18:09 -070062 # Run our meagre tests
63 if cmdline.HAS_TESTS and options.test:
Simon Glassbb928de2023-07-19 17:48:29 -060064 return run_tests(options.skip_net_tests, options.debug, options.verbose,
65 args)
Simon Glass62043e32023-02-23 18:18:09 -070066
67 # Build selected commits for selected boards
68 else:
69 bsettings.Setup(options.config_file)
Simon Glassc1e1e1d2023-07-19 17:48:30 -060070 ret_code = control.do_buildman(options, args)
Simon Glass44b0a7f2023-07-19 17:48:11 -060071 return ret_code
Simon Glass62043e32023-02-23 18:18:09 -070072
Simon Glassc05694f2013-04-03 11:07:16 +000073
Simon Glass62043e32023-02-23 18:18:09 -070074if __name__ == "__main__":
Simon Glass44b0a7f2023-07-19 17:48:11 -060075 sys.exit(run_buildman())