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"""
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')
31 """Run the functional tests and any embedded doctests"""
40 result = unittest.TestResult()
42 suite = doctest.DocTestSuite(module)
45 sys.argv = [sys.argv[0]]
49 # Run the entry tests first ,since these need to be the first to import the
51 suite = unittest.TestLoader().loadTestsFromTestCase(entry_test.TestEntry)
53 for module in (ftest.TestFunctional, fdt_test.TestFdt, elf_test.TestElf,
54 image_test.TestImage):
55 suite = unittest.TestLoader().loadTestsFromTestCase(module)
59 for test, err in result.errors:
61 for test, err in result.failures:
62 print err, result.failures
63 if result.errors or result.failures:
64 print 'binman tests FAILED'
68 def RunTestCoverage():
69 """Run the tests and check that we get 100% coverage"""
70 # This uses the build output from sandbox_spl to get _libfdt.so
71 cmd = ('PYTHONPATH=$PYTHONPATH:%s/sandbox_spl/tools coverage run '
72 '--include "tools/binman/*.py" --omit "*test*,*binman.py" '
73 'tools/binman/binman.py -t' % options.build_dir)
75 stdout = command.Output('coverage', 'report')
76 lines = stdout.splitlines()
78 test_set= set([os.path.basename(line.split()[0])
79 for line in lines if '/etype/' in line])
80 glob_list = glob.glob(os.path.join(our_path, 'etype/*.py'))
81 all_set = set([os.path.basename(item) for item in glob_list])
82 missing_list = all_set
83 missing_list.difference_update(test_set)
84 missing_list.remove('_testing.py')
85 coverage = lines[-1].split(' ')[-1]
88 print 'Missing tests for %s' % (', '.join(missing_list))
90 if coverage != '100%':
92 print "Type 'coverage html' to get a report in htmlcov/index.html"
93 print 'Coverage error: %s, but should be 100%%' % coverage
96 raise ValueError('Test coverage failure')
98 def RunBinman(options, args):
99 """Main entry point to binman once arguments are parsed
102 options: Command-line options
103 args: Non-option arguments
107 # For testing: This enables full exception traces.
108 #options.debug = True
110 if not options.debug:
111 sys.tracebacklimit = 0
114 ret_code = RunTests(options.debug)
116 elif options.test_coverage:
119 elif options.full_help:
120 pager = os.getenv('PAGER')
123 fname = os.path.join(os.path.dirname(os.path.realpath(sys.argv[0])),
125 command.Run(pager, fname)
129 ret_code = control.Binman(options, args)
130 except Exception as e:
131 print 'binman: %s' % e
134 traceback.print_exc()
139 if __name__ == "__main__":
140 (options, args) = cmdline.ParseArgs(sys.argv)
141 ret_code = RunBinman(options, args)