blob: 963d43a3761a6953a5116d7e6a1afd4919199550 [file] [log] [blame]
Jörg Krausecd6d46e2017-03-06 21:07:11 +01001#!/usr/bin/env python2
Simon Glass2574ef62016-11-25 20:15:51 -07002
3# Copyright (c) 2016 Google, Inc
4# Written by Simon Glass <sjg@chromium.org>
5#
6# SPDX-License-Identifier: GPL-2.0+
7#
8# Creates binary images from input files controlled by a description
9#
10
11"""See README for more information"""
12
13import os
14import sys
15import traceback
16import unittest
17
18# Bring in the patman and dtoc libraries
19our_path = os.path.dirname(os.path.realpath(__file__))
Simon Glassdde3e712017-06-20 21:28:49 -060020for dirname in ['../patman', '../dtoc', '..']:
21 sys.path.insert(0, os.path.join(our_path, dirname))
Simon Glass2574ef62016-11-25 20:15:51 -070022
Simon Glass55901ff2017-05-27 07:38:22 -060023# Bring in the libfdt module
Masahiro Yamada47ae5392017-10-17 13:42:43 +090024sys.path.insert(0, 'scripts/dtc/pylibfdt')
Simon Glass55901ff2017-05-27 07:38:22 -060025
Simon Glass2574ef62016-11-25 20:15:51 -070026# Also allow entry-type modules to be brought in from the etype directory.
Simon Glassdde3e712017-06-20 21:28:49 -060027sys.path.insert(0, os.path.join(our_path, 'etype'))
Simon Glass2574ef62016-11-25 20:15:51 -070028
29import cmdline
30import command
31import control
32
33def RunTests():
34 """Run the functional tests and any embedded doctests"""
35 import entry_test
36 import fdt_test
Simon Glass076e63b2017-11-12 21:52:08 -070037 import ftest
Simon Glass2574ef62016-11-25 20:15:51 -070038 import test
39 import doctest
40
41 result = unittest.TestResult()
42 for module in []:
43 suite = doctest.DocTestSuite(module)
44 suite.run(result)
45
46 sys.argv = [sys.argv[0]]
Simon Glass076e63b2017-11-12 21:52:08 -070047 for module in (ftest.TestFunctional, fdt_test.TestFdt,
Simon Glass2574ef62016-11-25 20:15:51 -070048 entry_test.TestEntry):
49 suite = unittest.TestLoader().loadTestsFromTestCase(module)
50 suite.run(result)
51
52 print result
53 for test, err in result.errors:
54 print test.id(), err
55 for test, err in result.failures:
56 print err
57
58def RunTestCoverage():
59 """Run the tests and check that we get 100% coverage"""
60 # This uses the build output from sandbox_spl to get _libfdt.so
Simon Glassc303b9a2017-11-12 21:52:19 -070061 cmd = ('PYTHONPATH=$PYTHONPATH:%s/sandbox_spl/tools coverage run '
Simon Glass2574ef62016-11-25 20:15:51 -070062 '--include "tools/binman/*.py" --omit "*test*,*binman.py" '
63 'tools/binman/binman.py -t' % options.build_dir)
64 os.system(cmd)
65 stdout = command.Output('coverage', 'report')
66 coverage = stdout.splitlines()[-1].split(' ')[-1]
67 if coverage != '100%':
68 print stdout
69 print "Type 'coverage html' to get a report in htmlcov/index.html"
70 raise ValueError('Coverage error: %s, but should be 100%%' % coverage)
71
72
73def RunBinman(options, args):
74 """Main entry point to binman once arguments are parsed
75
76 Args:
77 options: Command-line options
78 args: Non-option arguments
79 """
80 ret_code = 0
81
82 # For testing: This enables full exception traces.
83 #options.debug = True
84
85 if not options.debug:
86 sys.tracebacklimit = 0
87
88 if options.test:
89 RunTests()
90
91 elif options.test_coverage:
92 RunTestCoverage()
93
94 elif options.full_help:
95 pager = os.getenv('PAGER')
96 if not pager:
97 pager = 'more'
98 fname = os.path.join(os.path.dirname(os.path.realpath(sys.argv[0])),
99 'README')
100 command.Run(pager, fname)
101
102 else:
103 try:
104 ret_code = control.Binman(options, args)
105 except Exception as e:
106 print 'binman: %s' % e
107 if options.debug:
108 print
109 traceback.print_exc()
110 ret_code = 1
111 return ret_code
112
113
114if __name__ == "__main__":
115 (options, args) = cmdline.ParseArgs(sys.argv)
116 ret_code = RunBinman(options, args)
117 sys.exit(ret_code)