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')
25 sys.path.insert(0, os.path.join(our_path,
26 '../../build-sandbox_spl/scripts/dtc/pylibfdt'))
33 def RunTests(debug, args):
34 """Run the functional tests and any embedded doctests
37 debug: True to enable debugging, which shows a full stack trace on error
38 args: List of positional args provided to binman. This can hold a test
39 name to execute (as in 'binman -t testSections', for example)
49 result = unittest.TestResult()
51 suite = doctest.DocTestSuite(module)
54 sys.argv = [sys.argv[0]]
58 # Run the entry tests first ,since these need to be the first to import the
60 test_name = args and args[0] or None
61 for module in (entry_test.TestEntry, ftest.TestFunctional, fdt_test.TestFdt,
62 elf_test.TestElf, image_test.TestImage):
65 suite = unittest.TestLoader().loadTestsFromName(test_name, module)
66 except AttributeError:
69 suite = unittest.TestLoader().loadTestsFromTestCase(module)
73 for test, err in result.errors:
75 for test, err in result.failures:
76 print err, result.failures
77 if result.errors or result.failures:
78 print 'binman tests FAILED'
82 def GetEntryModules(include_testing=True):
83 """Get a set of entry class implementations
86 Set of paths to entry class filenames
88 glob_list = glob.glob(os.path.join(our_path, 'etype/*.py'))
89 return set([os.path.splitext(os.path.basename(item))[0]
91 if include_testing or '_testing' not in item])
93 def RunTestCoverage():
94 """Run the tests and check that we get 100% coverage"""
95 glob_list = GetEntryModules(False)
96 all_set = set([os.path.splitext(os.path.basename(item))[0]
97 for item in glob_list if '_testing' not in item])
98 test_util.RunTestCoverage('tools/binman/binman.py', None,
99 ['*test*', '*binman.py', 'tools/patman/*', 'tools/dtoc/*'],
100 options.build_dir, all_set)
102 def RunBinman(options, args):
103 """Main entry point to binman once arguments are parsed
106 options: Command-line options
107 args: Non-option arguments
111 # For testing: This enables full exception traces.
112 #options.debug = True
114 if not options.debug:
115 sys.tracebacklimit = 0
118 ret_code = RunTests(options.debug, args[1:])
120 elif options.test_coverage:
123 elif options.entry_docs:
124 control.WriteEntryDocs(GetEntryModules())
128 ret_code = control.Binman(options, args)
129 except Exception as e:
130 print 'binman: %s' % e
133 traceback.print_exc()
138 if __name__ == "__main__":
139 (options, args) = cmdline.ParseArgs(sys.argv)
140 ret_code = RunBinman(options, args)