]>
git.ipfire.org Git - people/ms/u-boot.git/blob - tools/binman/binman.py
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"""
19 # Bring in the patman and dtoc libraries
20 our_path
= os
.path
.dirname(os
.path
.realpath(__file__
))
21 for dirname
in ['../patman', '../dtoc', '..']:
22 sys
.path
.insert(0, os
.path
.join(our_path
, dirname
))
24 # Bring in the libfdt module
25 sys
.path
.insert(0, 'scripts/dtc/pylibfdt')
27 # Also allow entry-type modules to be brought in from the etype directory.
28 sys
.path
.insert(0, 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]]
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
):
54 suite
= unittest
.TestLoader().loadTestsFromTestCase(module
)
58 for test
, err
in result
.errors
:
60 for test
, err
in result
.failures
:
61 print err
, result
.failures
62 if result
.errors
or result
.failures
:
63 print 'binman tests FAILED'
67 def RunTestCoverage():
68 """Run the tests and check that we get 100% coverage"""
69 # This uses the build output from sandbox_spl to get _libfdt.so
70 cmd
= ('PYTHONPATH=$PYTHONPATH:%s/sandbox_spl/tools coverage run '
71 '--include "tools/binman/*.py" --omit "*test*,*binman.py" '
72 'tools/binman/binman.py -t' % options
.build_dir
)
74 stdout
= command
.Output('coverage', 'report')
75 lines
= stdout
.splitlines()
77 test_set
= set([os
.path
.basename(line
.split()[0])
78 for line
in lines
if '/etype/' in line
])
79 glob_list
= glob
.glob(os
.path
.join(our_path
, 'etype/*.py'))
80 all_set
= set([os
.path
.basename(item
) for item
in glob_list
])
81 missing_list
= all_set
82 missing_list
.difference_update(test_set
)
83 missing_list
.remove('_testing.py')
84 coverage
= lines
[-1].split(' ')[-1]
87 print 'Missing tests for %s' % (', '.join(missing_list
))
89 if coverage
!= '100%':
91 print "Type 'coverage html' to get a report in htmlcov/index.html"
92 print 'Coverage error: %s, but should be 100%%' % coverage
95 raise ValueError('Test coverage failure')
97 def RunBinman(options
, args
):
98 """Main entry point to binman once arguments are parsed
101 options: Command-line options
102 args: Non-option arguments
106 # For testing: This enables full exception traces.
107 #options.debug = True
109 if not options
.debug
:
110 sys
.tracebacklimit
= 0
113 ret_code
= RunTests()
115 elif options
.test_coverage
:
118 elif options
.full_help
:
119 pager
= os
.getenv('PAGER')
122 fname
= os
.path
.join(os
.path
.dirname(os
.path
.realpath(sys
.argv
[0])),
124 command
.Run(pager
, fname
)
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
)