From c186c3ce866bc22660feae400913aa0659bcd5bc Mon Sep 17 00:00:00 2001 From: Jimmy Brisson Date: Thu, 3 May 2018 09:16:26 -0500 Subject: [PATCH] Use mocked notifier for individual tests That way we separate the collection of notifications from everything else --- tools/build_api.py | 21 --------------------- tools/test_api.py | 14 ++++++++++---- 2 files changed, 10 insertions(+), 25 deletions(-) diff --git a/tools/build_api.py b/tools/build_api.py index d9f82742b8..13f5179528 100644 --- a/tools/build_api.py +++ b/tools/build_api.py @@ -599,7 +599,6 @@ def build_project(src_paths, build_path, target, toolchain_name, if report != None: end = time() cur_result["elapsed_time"] = end - start - cur_result["output"] = notify.get_output() + memap_table cur_result["result"] = "OK" cur_result["memory_usage"] = (memap_instance.mem_report if memap_instance is not None else None) @@ -622,12 +621,7 @@ def build_project(src_paths, build_path, target, toolchain_name, cur_result["elapsed_time"] = end - start - toolchain_output = notify.get_output() - if toolchain_output: - cur_result["output"] += toolchain_output - add_result_to_report(report, cur_result) - # Let Exception propagate raise @@ -754,7 +748,6 @@ def build_library(src_paths, build_path, target, toolchain_name, if report != None: end = time() cur_result["elapsed_time"] = end - start - cur_result["output"] = notify.get_output() cur_result["result"] = "OK" @@ -772,10 +765,6 @@ def build_library(src_paths, build_path, target, toolchain_name, cur_result["elapsed_time"] = end - start - toolchain_output = notify.get_output() - if toolchain_output: - cur_result["output"] += toolchain_output - add_result_to_report(report, cur_result) # Let Exception propagate @@ -926,7 +915,6 @@ def build_lib(lib_id, target, toolchain_name, clean=False, macros=None, if report != None and needed_update: end = time() cur_result["elapsed_time"] = end - start - cur_result["output"] = notify.get_output() cur_result["result"] = "OK" add_result_to_report(report, cur_result) @@ -938,10 +926,6 @@ def build_lib(lib_id, target, toolchain_name, clean=False, macros=None, cur_result["result"] = "FAIL" cur_result["elapsed_time"] = end - start - toolchain_output = notify.get_output() - if toolchain_output: - cur_result["output"] += toolchain_output - add_result_to_report(report, cur_result) # Let Exception propagate @@ -1085,7 +1069,6 @@ def build_mbed_libs(target, toolchain_name, clean=False, macros=None, if report != None: end = time() cur_result["elapsed_time"] = end - start - cur_result["output"] = notify.get_output() cur_result["result"] = "OK" add_result_to_report(report, cur_result) @@ -1098,10 +1081,6 @@ def build_mbed_libs(target, toolchain_name, clean=False, macros=None, cur_result["result"] = "FAIL" cur_result["elapsed_time"] = end - start - toolchain_output = notify.get_output() - if toolchain_output: - cur_result["output"] += toolchain_output - cur_result["output"] += str(exc) add_result_to_report(report, cur_result) diff --git a/tools/test_api.py b/tools/test_api.py index 50b2d334b1..db0ac59fba 100644 --- a/tools/test_api.py +++ b/tools/test_api.py @@ -32,7 +32,7 @@ import ctypes import functools from colorama import Fore, Back, Style from prettytable import PrettyTable -from copy import copy +from copy import copy, deepcopy from time import sleep, time try: @@ -75,6 +75,7 @@ from tools.utils import argparse_filestring_type from tools.utils import argparse_uppercase_type from tools.utils import argparse_lowercase_type from tools.utils import argparse_many +from tools.notifier.mock import MockNotifier import tools.host_tests.host_tests_plugins as host_tests_plugins @@ -2262,7 +2263,7 @@ def build_tests(tests, base_source_paths, build_path, target, toolchain_name, 'build_profile': build_profile, 'toolchain_paths': TOOLCHAIN_PATHS, 'stats_depth': stats_depth, - 'notify': notify + 'notify': MockNotifier() } results.append(p.apply_async(build_test_worker, args, kwargs)) @@ -2285,9 +2286,15 @@ def build_tests(tests, base_source_paths, build_path, target, toolchain_name, worker_result = r.get() results.remove(r) + # Push all deferred notifications out to the actual notifier + new_notify = deepcopy(notify) + for message in worker_result['kwargs']['notify'].messages: + new_notify.notify(message) + # Take report from the kwargs and merge it into existing report if report: report_entry = worker_result['kwargs']['report'][target_name][toolchain_name] + report_entry[worker_result['kwargs']['project_id'].upper()][0][0]['output'] = new_notify.get_output() for test_key in report_entry.keys(): report[target_name][toolchain_name][test_key] = report_entry[test_key] @@ -2298,6 +2305,7 @@ def build_tests(tests, base_source_paths, build_path, target, toolchain_name, result = False break + # Adding binary path to test build result if ('result' in worker_result and worker_result['result'] and @@ -2313,8 +2321,6 @@ def build_tests(tests, base_source_paths, build_path, target, toolchain_name, } test_key = worker_result['kwargs']['project_id'].upper() - if report: - print(report[target_name][toolchain_name][test_key][0][0]['output'].rstrip()) print('Image: %s\n' % bin_file) except: