2019-10-31 13:43:05 +00:00
|
|
|
#!/usr/bin/env python3
|
2018-05-06 21:58:06 +00:00
|
|
|
# SPDX-License-Identifier: GPL-2.0+
|
2016-11-26 03:15:51 +00:00
|
|
|
|
|
|
|
# Copyright (c) 2016 Google, Inc
|
|
|
|
# Written by Simon Glass <sjg@chromium.org>
|
|
|
|
#
|
|
|
|
# Creates binary images from input files controlled by a description
|
|
|
|
#
|
|
|
|
|
|
|
|
"""See README for more information"""
|
|
|
|
|
|
|
|
import os
|
2019-07-08 19:18:36 +00:00
|
|
|
import site
|
2016-11-26 03:15:51 +00:00
|
|
|
import sys
|
|
|
|
import traceback
|
|
|
|
|
2021-12-06 11:44:12 +00:00
|
|
|
# Get the absolute path to this file at run-time
|
|
|
|
our_path = os.path.dirname(os.path.realpath(__file__))
|
|
|
|
our1_path = os.path.dirname(our_path)
|
|
|
|
our2_path = os.path.dirname(our1_path)
|
|
|
|
|
2021-12-06 11:44:13 +00:00
|
|
|
# Extract $(srctree) from Kbuild environment, or use relative paths below
|
|
|
|
srctree = os.environ.get('srctree', our2_path)
|
|
|
|
|
2021-12-06 11:44:12 +00:00
|
|
|
#
|
|
|
|
# Do not pollute source tree with cache files:
|
|
|
|
# https://stackoverflow.com/a/60024195/2511795
|
|
|
|
# https://bugs.python.org/issue33499
|
|
|
|
#
|
2021-12-06 11:44:13 +00:00
|
|
|
sys.pycache_prefix = os.path.relpath(our_path, srctree)
|
2021-12-06 11:44:12 +00:00
|
|
|
|
2019-07-08 20:25:29 +00:00
|
|
|
# Bring in the patman and dtoc libraries (but don't override the first path
|
|
|
|
# in PYTHONPATH)
|
2021-12-06 11:44:13 +00:00
|
|
|
sys.path.insert(2, our1_path)
|
2020-04-18 00:09:05 +00:00
|
|
|
|
2022-01-10 03:14:11 +00:00
|
|
|
from binman import bintool
|
2020-04-18 00:09:05 +00:00
|
|
|
from patman import test_util
|
2016-11-26 03:15:51 +00:00
|
|
|
|
2017-05-27 13:38:22 +00:00
|
|
|
# Bring in the libfdt module
|
2019-07-08 20:25:29 +00:00
|
|
|
sys.path.insert(2, 'scripts/dtc/pylibfdt')
|
2021-12-06 11:44:13 +00:00
|
|
|
sys.path.insert(2, os.path.join(srctree, 'scripts/dtc/pylibfdt'))
|
2022-01-27 14:03:13 +00:00
|
|
|
sys.path.insert(2, os.path.join(srctree, 'build-sandbox/scripts/dtc/pylibfdt'))
|
2021-12-06 11:44:13 +00:00
|
|
|
sys.path.insert(2, os.path.join(srctree, 'build-sandbox_spl/scripts/dtc/pylibfdt'))
|
2017-05-27 13:38:22 +00:00
|
|
|
|
2020-04-18 00:09:03 +00:00
|
|
|
from binman import cmdline
|
|
|
|
from binman import control
|
2020-04-18 00:09:04 +00:00
|
|
|
from patman import test_util
|
2016-11-26 03:15:51 +00:00
|
|
|
|
2019-07-08 19:18:50 +00:00
|
|
|
def RunTests(debug, verbosity, processes, test_preserve_dirs, args, toolpath):
|
2018-06-01 15:38:18 +00:00
|
|
|
"""Run the functional tests and any embedded doctests
|
|
|
|
|
|
|
|
Args:
|
|
|
|
debug: True to enable debugging, which shows a full stack trace on error
|
2019-07-08 19:18:48 +00:00
|
|
|
verbosity: Verbosity level to use
|
2019-07-08 19:18:49 +00:00
|
|
|
test_preserve_dirs: True to preserve the input directory used by tests
|
|
|
|
so that it can be examined afterwards (only useful for debugging
|
|
|
|
tests). If a single test is selected (in args[0]) it also preserves
|
|
|
|
the output directory for this test. Both directories are displayed
|
|
|
|
on the command line.
|
|
|
|
processes: Number of processes to use to run tests (None=same as #CPUs)
|
2018-06-01 15:38:18 +00:00
|
|
|
args: List of positional args provided to binman. This can hold a test
|
2019-07-08 20:25:29 +00:00
|
|
|
name to execute (as in 'binman test testSections', for example)
|
2019-07-08 19:18:50 +00:00
|
|
|
toolpath: List of paths to use for tools
|
2018-06-01 15:38:18 +00:00
|
|
|
"""
|
2022-01-10 03:13:57 +00:00
|
|
|
from binman import bintool_test
|
2020-04-18 00:09:03 +00:00
|
|
|
from binman import cbfs_util_test
|
|
|
|
from binman import elf_test
|
|
|
|
from binman import entry_test
|
|
|
|
from binman import fdt_test
|
2021-11-24 04:08:58 +00:00
|
|
|
from binman import fip_util_test
|
2020-04-18 00:09:03 +00:00
|
|
|
from binman import ftest
|
|
|
|
from binman import image_test
|
2016-11-26 03:15:51 +00:00
|
|
|
import doctest
|
|
|
|
|
2020-04-18 00:09:01 +00:00
|
|
|
test_name = args and args[0] or None
|
2017-11-13 04:52:21 +00:00
|
|
|
|
|
|
|
# Run the entry tests first ,since these need to be the first to import the
|
|
|
|
# 'entry' module.
|
2022-04-02 17:06:06 +00:00
|
|
|
result = test_util.run_test_suites(
|
|
|
|
'binman', debug, verbosity, test_preserve_dirs, processes, test_name,
|
2020-04-18 00:09:01 +00:00
|
|
|
toolpath,
|
2022-01-10 03:13:57 +00:00
|
|
|
[bintool_test.TestBintool, entry_test.TestEntry, ftest.TestFunctional,
|
|
|
|
fdt_test.TestFdt, elf_test.TestElf, image_test.TestImage,
|
|
|
|
cbfs_util_test.TestCbfs, fip_util_test.TestFip])
|
2019-05-14 21:53:38 +00:00
|
|
|
|
2022-04-02 17:06:06 +00:00
|
|
|
return (0 if result.wasSuccessful() else 1)
|
2016-11-26 03:15:51 +00:00
|
|
|
|
2020-07-10 00:39:29 +00:00
|
|
|
def RunTestCoverage(toolpath):
|
2016-11-26 03:15:51 +00:00
|
|
|
"""Run the tests and check that we get 100% coverage"""
|
2020-08-05 19:27:46 +00:00
|
|
|
glob_list = control.GetEntryModules(False)
|
2018-07-06 16:27:14 +00:00
|
|
|
all_set = set([os.path.splitext(os.path.basename(item))[0]
|
|
|
|
for item in glob_list if '_testing' not in item])
|
2020-07-10 00:39:29 +00:00
|
|
|
extra_args = ''
|
|
|
|
if toolpath:
|
|
|
|
for path in toolpath:
|
|
|
|
extra_args += ' --toolpath %s' % path
|
2022-01-29 21:14:14 +00:00
|
|
|
test_util.run_test_coverage('tools/binman/binman', None,
|
2020-04-18 00:08:58 +00:00
|
|
|
['*test*', '*main.py', 'tools/patman/*', 'tools/dtoc/*'],
|
2020-07-10 00:39:29 +00:00
|
|
|
args.build_dir, all_set, extra_args or None)
|
2016-11-26 03:15:51 +00:00
|
|
|
|
2019-07-08 20:25:29 +00:00
|
|
|
def RunBinman(args):
|
2016-11-26 03:15:51 +00:00
|
|
|
"""Main entry point to binman once arguments are parsed
|
|
|
|
|
|
|
|
Args:
|
2019-07-08 20:25:29 +00:00
|
|
|
args: Command line arguments Namespace object
|
2016-11-26 03:15:51 +00:00
|
|
|
"""
|
|
|
|
ret_code = 0
|
|
|
|
|
2019-07-08 20:25:29 +00:00
|
|
|
if not args.debug:
|
2016-11-26 03:15:51 +00:00
|
|
|
sys.tracebacklimit = 0
|
|
|
|
|
2020-07-10 00:39:30 +00:00
|
|
|
# Provide a default toolpath in the hope of finding a mkimage built from
|
|
|
|
# current source
|
|
|
|
if not args.toolpath:
|
|
|
|
args.toolpath = ['./tools', 'build-sandbox/tools']
|
|
|
|
|
2019-07-08 20:25:29 +00:00
|
|
|
if args.cmd == 'test':
|
|
|
|
if args.test_coverage:
|
2020-07-10 00:39:29 +00:00
|
|
|
RunTestCoverage(args.toolpath)
|
2019-07-08 20:25:29 +00:00
|
|
|
else:
|
|
|
|
ret_code = RunTests(args.debug, args.verbosity, args.processes,
|
|
|
|
args.test_preserve_dirs, args.tests,
|
|
|
|
args.toolpath)
|
2016-11-26 03:15:51 +00:00
|
|
|
|
2022-01-10 03:14:11 +00:00
|
|
|
elif args.cmd == 'bintool-docs':
|
|
|
|
control.write_bintool_docs(bintool.Bintool.get_tool_list())
|
|
|
|
|
2019-07-08 20:25:29 +00:00
|
|
|
elif args.cmd == 'entry-docs':
|
2020-08-05 19:27:46 +00:00
|
|
|
control.WriteEntryDocs(control.GetEntryModules())
|
2016-11-26 03:15:51 +00:00
|
|
|
|
|
|
|
else:
|
|
|
|
try:
|
2019-07-08 20:25:29 +00:00
|
|
|
ret_code = control.Binman(args)
|
2016-11-26 03:15:51 +00:00
|
|
|
except Exception as e:
|
2020-07-10 00:39:26 +00:00
|
|
|
print('binman: %s' % e, file=sys.stderr)
|
2019-07-08 20:25:29 +00:00
|
|
|
if args.debug:
|
2019-05-14 21:53:37 +00:00
|
|
|
print()
|
2016-11-26 03:15:51 +00:00
|
|
|
traceback.print_exc()
|
|
|
|
ret_code = 1
|
|
|
|
return ret_code
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
2019-07-08 20:25:29 +00:00
|
|
|
args = cmdline.ParseArgs(sys.argv[1:])
|
|
|
|
|
|
|
|
ret_code = RunBinman(args)
|
2016-11-26 03:15:51 +00:00
|
|
|
sys.exit(ret_code)
|