only useful for testing in-tree builds.
work_in_output: Use the output directory as the work directory and
don't write to a separate output directory.
+ thread_exceptions: List of exceptions raised by thread jobs
Private members:
_base_board_dict: Last-summarised Dict of boards
no_subdirs=False, full_path=False, verbose_build=False,
mrproper=False, per_board_out_dir=False,
config_only=False, squash_config_y=False,
- warnings_as_errors=False, work_in_output=False):
+ warnings_as_errors=False, work_in_output=False,
+ test_thread_exceptions=False):
"""Create a new Builder object
Args:
warnings_as_errors: Treat all compiler warnings as errors
work_in_output: Use the output directory as the work directory and
don't write to a separate output directory.
+ test_thread_exceptions: Uses for tests only, True to make the
+ threads raise an exception instead of reporting their result.
+ This simulates a failure in the code somewhere
"""
self.toolchains = toolchains
self.base_dir = base_dir
self._re_migration_warning = re.compile(r'^={21} WARNING ={22}\n.*\n=+\n',
re.MULTILINE | re.DOTALL)
+ self.thread_exceptions = []
+ self.test_thread_exceptions = test_thread_exceptions
if self.num_threads:
self._single_builder = None
self.queue = queue.Queue()
self.out_queue = queue.Queue()
for i in range(self.num_threads):
- t = builderthread.BuilderThread(self, i, mrproper,
- per_board_out_dir)
+ t = builderthread.BuilderThread(
+ self, i, mrproper, per_board_out_dir,
+ test_exception=test_thread_exceptions)
t.setDaemon(True)
t.start()
self.threads.append(t)
Tuple containing:
- number of boards that failed to build
- number of boards that issued warnings
+ - list of thread exceptions raised
"""
self.commit_count = len(commits) if commits else 1
self.commits = commits
Print('\rStarting build...', newline=False)
self.SetupBuild(board_selected, commits)
self.ProcessResult(None)
-
+ self.thread_exceptions = []
# Create jobs to build all commits for each board
for brd in board_selected.values():
job = builderthread.BuilderJob()
rate = float(self.count) / duration.total_seconds()
msg += ', duration %s, rate %1.2f' % (duration, rate)
Print(msg)
+ if self.thread_exceptions:
+ Print('Failed: %d thread exceptions' % len(self.thread_exceptions),
+ colour=self.col.RED)
- return (self.fail, self.warned)
+ return (self.fail, self.warned, self.thread_exceptions)
test_exception: Used for testing; True to raise an exception instead of
reporting the build result
"""
+ def __init__(self, builder, thread_num, mrproper, per_board_out_dir,
+ test_exception=False):
"""Set up a new builder thread"""
threading.Thread.__init__(self)
self.builder = builder
self.thread_num = thread_num
self.mrproper = mrproper
self.per_board_out_dir = per_board_out_dir
+ self.test_exception = test_exception
def Make(self, commit, brd, stage, cwd, *args, **kwargs):
"""Run 'make' on a particular commit and board.
Args:
result: CommandResult object containing the results of the build
+
+ Raises:
+ ValueError if self.test_exception is true (for testing)
"""
+ if self.test_exception:
+ raise ValueError('test exception')
if self.thread_num != -1:
self.builder.out_queue.put(result)
else:
"""
while True:
job = self.builder.queue.get()
- self.RunJob(job)
+ try:
+ self.RunJob(job)
+ except Exception as e:
+ print('Thread exception:', e)
+ self.builder.thread_exceptions.append(e)
self.builder.queue.task_done()
return None
def DoBuildman(options, args, toolchains=None, make_func=None, boards=None,
- clean_dir=False):
+ clean_dir=False, test_thread_exceptions=False):
"""The main control code for buildman
Args:
boards. If this is None it will be created and scanned.
clean_dir: Used for tests only, indicates that the existing output_dir
should be removed before starting the build
+ test_thread_exceptions: Uses for tests only, True to make the threads
+ raise an exception instead of reporting their result. This simulates
+ a failure in the code somewhere
"""
global builder
config_only=options.config_only,
squash_config_y=not options.preserve_config_y,
warnings_as_errors=options.warnings_as_errors,
- work_in_output=options.work_in_output)
+ work_in_output=options.work_in_output,
+ test_thread_exceptions=test_thread_exceptions)
builder.force_config_on_failure = not options.quick
if make_func:
builder.do_make = make_func
if options.summary:
builder.ShowSummary(commits, board_selected)
else:
- fail, warned = builder.BuildBoards(commits, board_selected,
- options.keep_outputs, options.verbose)
- if fail:
+ fail, warned, excs = builder.BuildBoards(
+ commits, board_selected, options.keep_outputs, options.verbose)
+ if excs:
+ return 102
+ elif fail:
return 100
elif warned and not options.ignore_warnings:
return 101
from patman import command
from patman import gitutil
from patman import terminal
+from patman import test_util
from patman import tools
settings_data = '''
return command.RunPipe([[self._buildman_pathname] + list(args)],
capture=True, capture_stderr=True)
+ def _RunControl(self, *args, boards=None, clean_dir=False,
+ test_thread_exceptions=False):
"""Run buildman
Args:
boards:
clean_dir: Used for tests only, indicates that the existing output_dir
should be removed before starting the build
+ test_thread_exceptions: Uses for tests only, True to make the threads
+ raise an exception instead of reporting their result. This simulates
+ a failure in the code somewhere
Returns:
result code from buildman
options, args = cmdline.ParseArgs()
result = control.DoBuildman(options, args, toolchains=self._toolchains,
make_func=self._HandleMake, boards=boards or self._boards,
+ clean_dir=clean_dir,
+ test_thread_exceptions=test_thread_exceptions)
self._builder = control.builder
return result
with self.assertRaises(SystemExit) as e:
self._RunControl('-w', clean_dir=False)
self.assertIn("specify -o", str(e.exception))
+
+ def testThreadExceptions(self):
+ """Test that exceptions in threads are reported"""
+ with test_util.capture_sys_output() as (stdout, stderr):
+ self.assertEqual(102, self._RunControl('-o', self._output_dir,
+ test_thread_exceptions=True))
+ self.assertIn('Thread exception: test exception', stdout.getvalue())