3 # Copyright (c) 2016 Google, Inc
4 # Written by Simon Glass <sjg@chromium.org>
6 # SPDX-License-Identifier: GPL-2.0+
8 # Creates binary images from input files controlled by a description
11 """See README for more information"""
18 # Bring in the patman and dtoc libraries
19 our_path = os.path.dirname(os.path.realpath(__file__))
20 sys.path.append(os.path.join(our_path, '../patman'))
21 sys.path.append(os.path.join(our_path, '../dtoc'))
23 # Also allow entry-type modules to be brought in from the etype directory.
24 sys.path.append(os.path.join(our_path, 'etype'))
31 """Run the functional tests and any embedded doctests"""
38 result = unittest.TestResult()
40 suite = doctest.DocTestSuite(module)
43 sys.argv = [sys.argv[0]]
44 for module in (func_test.TestFunctional, fdt_test.TestFdt,
45 entry_test.TestEntry):
46 suite = unittest.TestLoader().loadTestsFromTestCase(module)
50 for test, err in result.errors:
52 for test, err in result.failures:
55 def RunTestCoverage():
56 """Run the tests and check that we get 100% coverage"""
57 # This uses the build output from sandbox_spl to get _libfdt.so
58 cmd = ('PYTHONPATH=%s/sandbox_spl/tools coverage run '
59 '--include "tools/binman/*.py" --omit "*test*,*binman.py" '
60 'tools/binman/binman.py -t' % options.build_dir)
62 stdout = command.Output('coverage', 'report')
63 coverage = stdout.splitlines()[-1].split(' ')[-1]
64 if coverage != '100%':
66 print "Type 'coverage html' to get a report in htmlcov/index.html"
67 raise ValueError('Coverage error: %s, but should be 100%%' % coverage)
70 def RunBinman(options, args):
71 """Main entry point to binman once arguments are parsed
74 options: Command-line options
75 args: Non-option arguments
79 # For testing: This enables full exception traces.
83 sys.tracebacklimit = 0
88 elif options.test_coverage:
91 elif options.full_help:
92 pager = os.getenv('PAGER')
95 fname = os.path.join(os.path.dirname(os.path.realpath(sys.argv[0])),
97 command.Run(pager, fname)
101 ret_code = control.Binman(options, args)
102 except Exception as e:
103 print 'binman: %s' % e
106 traceback.print_exc()
111 if __name__ == "__main__":
112 (options, args) = cmdline.ParseArgs(sys.argv)
113 ret_code = RunBinman(options, args)