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"""
|
|
|
|
|
2019-07-08 19:18:36 +00:00
|
|
|
from distutils.sysconfig import get_python_lib
|
2016-11-26 03:15:51 +00:00
|
|
|
import os
|
2019-07-08 19:18:36 +00:00
|
|
|
import site
|
2016-11-26 03:15:51 +00:00
|
|
|
import sys
|
|
|
|
import traceback
|
|
|
|
import unittest
|
|
|
|
|
2019-07-08 20:25:29 +00:00
|
|
|
# Bring in the patman and dtoc libraries (but don't override the first path
|
|
|
|
# in PYTHONPATH)
|
2016-11-26 03:15:51 +00:00
|
|
|
our_path = os.path.dirname(os.path.realpath(__file__))
|
2020-04-18 00:09:05 +00:00
|
|
|
sys.path.insert(2, os.path.join(our_path, '..'))
|
|
|
|
|
|
|
|
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')
|
2020-07-10 00:39:28 +00:00
|
|
|
sys.path.insert(2, os.path.join(our_path, '../../scripts/dtc/pylibfdt'))
|
2019-07-08 20:25:29 +00:00
|
|
|
sys.path.insert(2, os.path.join(our_path,
|
2018-10-02 03:12:40 +00:00
|
|
|
'../../build-sandbox_spl/scripts/dtc/pylibfdt'))
|
2017-05-27 13:38:22 +00:00
|
|
|
|
2019-07-08 19:18:36 +00:00
|
|
|
# When running under python-coverage on Ubuntu 16.04, the dist-packages
|
|
|
|
# directories are dropped from the python path. Add them in so that we can find
|
|
|
|
# the elffile module. We could use site.getsitepackages() here but unfortunately
|
|
|
|
# that is not available in a virtualenv.
|
|
|
|
sys.path.append(get_python_lib())
|
|
|
|
|
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
|
|
|
"""
|
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
|
|
|
|
from binman import ftest
|
|
|
|
from binman import image_test
|
2016-11-26 03:15:51 +00:00
|
|
|
import doctest
|
|
|
|
|
|
|
|
result = unittest.TestResult()
|
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.
|
2020-04-18 00:09:01 +00:00
|
|
|
test_util.RunTestSuites(
|
|
|
|
result, debug, verbosity, test_preserve_dirs, processes, test_name,
|
|
|
|
toolpath,
|
|
|
|
[entry_test.TestEntry, ftest.TestFunctional, fdt_test.TestFdt,
|
|
|
|
elf_test.TestElf, image_test.TestImage, cbfs_util_test.TestCbfs])
|
2019-05-14 21:53:38 +00:00
|
|
|
|
2020-04-18 00:09:01 +00:00
|
|
|
return test_util.ReportResult('binman', test_name, result)
|
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
|
2020-04-18 00:08:58 +00:00
|
|
|
test_util.RunTestCoverage('tools/binman/binman', None,
|
|
|
|
['*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
|
|
|
|
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)
|