2 # SPDX-License-Identifier: GPL-2.0+
4 # Copyright (c) 2016 Google, Inc
5 # Written by Simon Glass <sjg@chromium.org>
7 # Creates binary images from input files controlled by a description
10 """See README for more information"""
12 from distutils.sysconfig import get_python_lib
19 # Bring in the patman and dtoc libraries (but don't override the first path
21 our_path = os.path.dirname(os.path.realpath(__file__))
22 sys.path.insert(2, os.path.join(our_path, '..'))
24 from patman import test_util
26 # Bring in the libfdt module
27 sys.path.insert(2, 'scripts/dtc/pylibfdt')
28 sys.path.insert(2, os.path.join(our_path, '../../scripts/dtc/pylibfdt'))
29 sys.path.insert(2, os.path.join(our_path,
30 '../../build-sandbox_spl/scripts/dtc/pylibfdt'))
32 # When running under python-coverage on Ubuntu 16.04, the dist-packages
33 # directories are dropped from the python path. Add them in so that we can find
34 # the elffile module. We could use site.getsitepackages() here but unfortunately
35 # that is not available in a virtualenv.
36 sys.path.append(get_python_lib())
38 from binman import cmdline
39 from binman import control
40 from patman import test_util
42 def RunTests(debug, verbosity, processes, test_preserve_dirs, args, toolpath):
43 """Run the functional tests and any embedded doctests
46 debug: True to enable debugging, which shows a full stack trace on error
47 verbosity: Verbosity level to use
48 test_preserve_dirs: True to preserve the input directory used by tests
49 so that it can be examined afterwards (only useful for debugging
50 tests). If a single test is selected (in args[0]) it also preserves
51 the output directory for this test. Both directories are displayed
53 processes: Number of processes to use to run tests (None=same as #CPUs)
54 args: List of positional args provided to binman. This can hold a test
55 name to execute (as in 'binman test testSections', for example)
56 toolpath: List of paths to use for tools
58 from binman import cbfs_util_test
59 from binman import elf_test
60 from binman import entry_test
61 from binman import fdt_test
62 from binman import fip_util_test
63 from binman import ftest
64 from binman import image_test
67 result = unittest.TestResult()
68 test_name = args and args[0] or None
70 # Run the entry tests first ,since these need to be the first to import the
72 test_util.RunTestSuites(
73 result, debug, verbosity, test_preserve_dirs, processes, test_name,
75 [entry_test.TestEntry, ftest.TestFunctional, fdt_test.TestFdt,
76 elf_test.TestElf, image_test.TestImage, cbfs_util_test.TestCbfs,
77 fip_util_test.TestFip])
79 return test_util.ReportResult('binman', test_name, result)
81 def RunTestCoverage(toolpath):
82 """Run the tests and check that we get 100% coverage"""
83 glob_list = control.GetEntryModules(False)
84 all_set = set([os.path.splitext(os.path.basename(item))[0]
85 for item in glob_list if '_testing' not in item])
89 extra_args += ' --toolpath %s' % path
90 test_util.RunTestCoverage('tools/binman/binman', None,
91 ['*test*', '*main.py', 'tools/patman/*', 'tools/dtoc/*'],
92 args.build_dir, all_set, extra_args or None)
95 """Main entry point to binman once arguments are parsed
98 args: Command line arguments Namespace object
103 sys.tracebacklimit = 0
105 # Provide a default toolpath in the hope of finding a mkimage built from
107 if not args.toolpath:
108 args.toolpath = ['./tools', 'build-sandbox/tools']
110 if args.cmd == 'test':
111 if args.test_coverage:
112 RunTestCoverage(args.toolpath)
114 ret_code = RunTests(args.debug, args.verbosity, args.processes,
115 args.test_preserve_dirs, args.tests,
118 elif args.cmd == 'entry-docs':
119 control.WriteEntryDocs(control.GetEntryModules())
123 ret_code = control.Binman(args)
124 except Exception as e:
125 print('binman: %s' % e, file=sys.stderr)
128 traceback.print_exc()
133 if __name__ == "__main__":
134 args = cmdline.ParseArgs(sys.argv[1:])
136 ret_code = RunBinman(args)