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'))
22 sys.path.append(os.path.join(our_path, '../'))
24 # Bring in the libfdt module
25 sys.path.append('tools')
27 # Also allow entry-type modules to be brought in from the etype directory.
28 sys.path.append(os.path.join(our_path, 'etype'))
35 """Run the functional tests and any embedded doctests"""
42 result = unittest.TestResult()
44 suite = doctest.DocTestSuite(module)
47 sys.argv = [sys.argv[0]]
48 for module in (func_test.TestFunctional, fdt_test.TestFdt,
49 entry_test.TestEntry):
50 suite = unittest.TestLoader().loadTestsFromTestCase(module)
54 for test, err in result.errors:
56 for test, err in result.failures:
59 def RunTestCoverage():
60 """Run the tests and check that we get 100% coverage"""
61 # This uses the build output from sandbox_spl to get _libfdt.so
62 cmd = ('PYTHONPATH=%s/sandbox_spl/tools coverage run '
63 '--include "tools/binman/*.py" --omit "*test*,*binman.py" '
64 'tools/binman/binman.py -t' % options.build_dir)
66 stdout = command.Output('coverage', 'report')
67 coverage = stdout.splitlines()[-1].split(' ')[-1]
68 if coverage != '100%':
70 print "Type 'coverage html' to get a report in htmlcov/index.html"
71 raise ValueError('Coverage error: %s, but should be 100%%' % coverage)
74 def RunBinman(options, args):
75 """Main entry point to binman once arguments are parsed
78 options: Command-line options
79 args: Non-option arguments
83 # For testing: This enables full exception traces.
87 sys.tracebacklimit = 0
92 elif options.test_coverage:
95 elif options.full_help:
96 pager = os.getenv('PAGER')
99 fname = os.path.join(os.path.dirname(os.path.realpath(sys.argv[0])),
101 command.Run(pager, fname)
105 ret_code = control.Binman(options, args)
106 except Exception as e:
107 print 'binman: %s' % e
110 traceback.print_exc()
115 if __name__ == "__main__":
116 (options, args) = cmdline.ParseArgs(sys.argv)
117 ret_code = RunBinman(options, args)