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 for dirname in ['../patman', '../dtoc', '..']:
21 sys.path.insert(0, os.path.join(our_path, dirname))
23 # Bring in the libfdt module
24 sys.path.insert(0, 'scripts/dtc/pylibfdt')
26 # Also allow entry-type modules to be brought in from the etype directory.
27 sys.path.insert(0, os.path.join(our_path, 'etype'))
34 """Run the functional tests and any embedded doctests"""
41 result = unittest.TestResult()
43 suite = doctest.DocTestSuite(module)
46 sys.argv = [sys.argv[0]]
48 # Run the entry tests first ,since these need to be the first to import the
50 suite = unittest.TestLoader().loadTestsFromTestCase(entry_test.TestEntry)
52 for module in (ftest.TestFunctional, fdt_test.TestFdt):
53 suite = unittest.TestLoader().loadTestsFromTestCase(module)
57 for test, err in result.errors:
59 for test, err in result.failures:
62 def RunTestCoverage():
63 """Run the tests and check that we get 100% coverage"""
64 # This uses the build output from sandbox_spl to get _libfdt.so
65 cmd = ('PYTHONPATH=$PYTHONPATH:%s/sandbox_spl/tools coverage run '
66 '--include "tools/binman/*.py" --omit "*test*,*binman.py" '
67 'tools/binman/binman.py -t' % options.build_dir)
69 stdout = command.Output('coverage', 'report')
70 coverage = stdout.splitlines()[-1].split(' ')[-1]
71 if coverage != '100%':
73 print "Type 'coverage html' to get a report in htmlcov/index.html"
74 raise ValueError('Coverage error: %s, but should be 100%%' % coverage)
77 def RunBinman(options, args):
78 """Main entry point to binman once arguments are parsed
81 options: Command-line options
82 args: Non-option arguments
86 # For testing: This enables full exception traces.
90 sys.tracebacklimit = 0
95 elif options.test_coverage:
98 elif options.full_help:
99 pager = os.getenv('PAGER')
102 fname = os.path.join(os.path.dirname(os.path.realpath(sys.argv[0])),
104 command.Run(pager, fname)
108 ret_code = control.Binman(options, args)
109 except Exception as e:
110 print 'binman: %s' % e
113 traceback.print_exc()
118 if __name__ == "__main__":
119 (options, args) = cmdline.ParseArgs(sys.argv)
120 ret_code = RunBinman(options, args)