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 def RunTests(debug, args):
32 """Run the functional tests and any embedded doctests
35 debug: True to enable debugging, which shows a full stack trace on error
36 args: List of positional args provided to binman. This can hold a test
37 name to execute (as in 'binman -t testSections', for example)
47 result = unittest.TestResult()
49 suite = doctest.DocTestSuite(module)
52 sys.argv = [sys.argv[0]]
56 # Run the entry tests first ,since these need to be the first to import the
58 test_name = args and args[0] or None
59 for module in (entry_test.TestEntry, ftest.TestFunctional, fdt_test.TestFdt,
60 elf_test.TestElf, image_test.TestImage):
63 suite = unittest.TestLoader().loadTestsFromName(test_name, module)
64 except AttributeError:
67 suite = unittest.TestLoader().loadTestsFromTestCase(module)
71 for test, err in result.errors:
73 for test, err in result.failures:
74 print err, result.failures
75 if result.errors or result.failures:
76 print 'binman tests FAILED'
80 def GetEntryModules(include_testing=True):
81 """Get a set of entry class implementations
84 Set of paths to entry class filenames
86 glob_list = glob.glob(os.path.join(our_path, 'etype/*.py'))
87 return set([os.path.splitext(os.path.basename(item))[0]
89 if include_testing or '_testing' not in item])
91 def RunTestCoverage():
92 """Run the tests and check that we get 100% coverage"""
93 glob_list = GetEntryModules(False)
94 all_set = set([os.path.splitext(os.path.basename(item))[0]
95 for item in glob_list if '_testing' not in item])
96 test_util.RunTestCoverage('tools/binman/binman.py', None,
97 ['*test*', '*binman.py', 'tools/patman/*', 'tools/dtoc/*'],
98 options.build_dir, all_set)
100 def RunBinman(options, args):
101 """Main entry point to binman once arguments are parsed
104 options: Command-line options
105 args: Non-option arguments
109 # For testing: This enables full exception traces.
110 #options.debug = True
112 if not options.debug:
113 sys.tracebacklimit = 0
116 ret_code = RunTests(options.debug, args[1:])
118 elif options.test_coverage:
121 elif options.entry_docs:
122 control.WriteEntryDocs(GetEntryModules())
126 ret_code = control.Binman(options, args)
127 except Exception as e:
128 print 'binman: %s' % e
131 traceback.print_exc()
136 if __name__ == "__main__":
137 (options, args) = cmdline.ParseArgs(sys.argv)
138 ret_code = RunBinman(options, args)