Backup 1

Committer:
borlanic
Date:
Tue Apr 24 11:45:18 2018 +0000
Revision:
0:02dd72d1d465
BaBoRo_test2 - backup 1

Who changed what in which revision?

UserRevisionLine numberNew contents of line
borlanic 0:02dd72d1d465 1 """
borlanic 0:02dd72d1d465 2 mbed SDK
borlanic 0:02dd72d1d465 3 Copyright (c) 2011-2014 ARM Limited
borlanic 0:02dd72d1d465 4
borlanic 0:02dd72d1d465 5 Licensed under the Apache License, Version 2.0 (the "License");
borlanic 0:02dd72d1d465 6 you may not use this file except in compliance with the License.
borlanic 0:02dd72d1d465 7 You may obtain a copy of the License at
borlanic 0:02dd72d1d465 8
borlanic 0:02dd72d1d465 9 http://www.apache.org/licenses/LICENSE-2.0
borlanic 0:02dd72d1d465 10
borlanic 0:02dd72d1d465 11 Unless required by applicable law or agreed to in writing, software
borlanic 0:02dd72d1d465 12 distributed under the License is distributed on an "AS IS" BASIS,
borlanic 0:02dd72d1d465 13 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
borlanic 0:02dd72d1d465 14 See the License for the specific language governing permissions and
borlanic 0:02dd72d1d465 15 limitations under the License.
borlanic 0:02dd72d1d465 16
borlanic 0:02dd72d1d465 17 Author: Przemyslaw Wirkus <Przemyslaw.wirkus@arm.com>
borlanic 0:02dd72d1d465 18 """
borlanic 0:02dd72d1d465 19 from __future__ import print_function
borlanic 0:02dd72d1d465 20
borlanic 0:02dd72d1d465 21 import os
borlanic 0:02dd72d1d465 22 import re
borlanic 0:02dd72d1d465 23 import sys
borlanic 0:02dd72d1d465 24 import json
borlanic 0:02dd72d1d465 25 import uuid
borlanic 0:02dd72d1d465 26 import pprint
borlanic 0:02dd72d1d465 27 import random
borlanic 0:02dd72d1d465 28 import argparse
borlanic 0:02dd72d1d465 29 import datetime
borlanic 0:02dd72d1d465 30 import threading
borlanic 0:02dd72d1d465 31 import ctypes
borlanic 0:02dd72d1d465 32 import functools
borlanic 0:02dd72d1d465 33 from colorama import Fore, Back, Style
borlanic 0:02dd72d1d465 34 from prettytable import PrettyTable
borlanic 0:02dd72d1d465 35 from copy import copy
borlanic 0:02dd72d1d465 36
borlanic 0:02dd72d1d465 37 from time import sleep, time
borlanic 0:02dd72d1d465 38 try:
borlanic 0:02dd72d1d465 39 from Queue import Queue, Empty
borlanic 0:02dd72d1d465 40 except ImportError:
borlanic 0:02dd72d1d465 41 from queue import Queue, Empty
borlanic 0:02dd72d1d465 42 from os.path import join, exists, basename, relpath
borlanic 0:02dd72d1d465 43 from threading import Thread, Lock
borlanic 0:02dd72d1d465 44 from multiprocessing import Pool, cpu_count
borlanic 0:02dd72d1d465 45 from subprocess import Popen, PIPE
borlanic 0:02dd72d1d465 46
borlanic 0:02dd72d1d465 47 # Imports related to mbed build api
borlanic 0:02dd72d1d465 48 from tools.tests import TESTS
borlanic 0:02dd72d1d465 49 from tools.tests import TEST_MAP
borlanic 0:02dd72d1d465 50 from tools.paths import BUILD_DIR
borlanic 0:02dd72d1d465 51 from tools.paths import HOST_TESTS
borlanic 0:02dd72d1d465 52 from tools.utils import ToolException
borlanic 0:02dd72d1d465 53 from tools.utils import NotSupportedException
borlanic 0:02dd72d1d465 54 from tools.utils import construct_enum
borlanic 0:02dd72d1d465 55 from tools.memap import MemapParser
borlanic 0:02dd72d1d465 56 from tools.targets import TARGET_MAP, Target
borlanic 0:02dd72d1d465 57 import tools.test_configs as TestConfig
borlanic 0:02dd72d1d465 58 from tools.test_db import BaseDBAccess
borlanic 0:02dd72d1d465 59 from tools.build_api import build_project, build_mbed_libs, build_lib
borlanic 0:02dd72d1d465 60 from tools.build_api import get_target_supported_toolchains
borlanic 0:02dd72d1d465 61 from tools.build_api import write_build_report
borlanic 0:02dd72d1d465 62 from tools.build_api import prep_report
borlanic 0:02dd72d1d465 63 from tools.build_api import prep_properties
borlanic 0:02dd72d1d465 64 from tools.build_api import create_result
borlanic 0:02dd72d1d465 65 from tools.build_api import add_result_to_report
borlanic 0:02dd72d1d465 66 from tools.build_api import prepare_toolchain
borlanic 0:02dd72d1d465 67 from tools.build_api import scan_resources
borlanic 0:02dd72d1d465 68 from tools.build_api import get_config
borlanic 0:02dd72d1d465 69 from tools.libraries import LIBRARIES, LIBRARY_MAP
borlanic 0:02dd72d1d465 70 from tools.options import extract_profile
borlanic 0:02dd72d1d465 71 from tools.toolchains import TOOLCHAIN_PATHS
borlanic 0:02dd72d1d465 72 from tools.toolchains import TOOLCHAINS
borlanic 0:02dd72d1d465 73 from tools.test_exporters import ReportExporter, ResultExporterType
borlanic 0:02dd72d1d465 74 from tools.utils import argparse_filestring_type
borlanic 0:02dd72d1d465 75 from tools.utils import argparse_uppercase_type
borlanic 0:02dd72d1d465 76 from tools.utils import argparse_lowercase_type
borlanic 0:02dd72d1d465 77 from tools.utils import argparse_many
borlanic 0:02dd72d1d465 78
borlanic 0:02dd72d1d465 79 import tools.host_tests.host_tests_plugins as host_tests_plugins
borlanic 0:02dd72d1d465 80
borlanic 0:02dd72d1d465 81 try:
borlanic 0:02dd72d1d465 82 import mbed_lstools
borlanic 0:02dd72d1d465 83 from tools.compliance.ioper_runner import get_available_oper_test_scopes
borlanic 0:02dd72d1d465 84 except:
borlanic 0:02dd72d1d465 85 pass
borlanic 0:02dd72d1d465 86
borlanic 0:02dd72d1d465 87
borlanic 0:02dd72d1d465 88 class ProcessObserver(Thread):
borlanic 0:02dd72d1d465 89 def __init__(self, proc):
borlanic 0:02dd72d1d465 90 Thread.__init__(self)
borlanic 0:02dd72d1d465 91 self.proc = proc
borlanic 0:02dd72d1d465 92 self.queue = Queue()
borlanic 0:02dd72d1d465 93 self.daemon = True
borlanic 0:02dd72d1d465 94 self.active = True
borlanic 0:02dd72d1d465 95 self.start()
borlanic 0:02dd72d1d465 96
borlanic 0:02dd72d1d465 97 def run(self):
borlanic 0:02dd72d1d465 98 while self.active:
borlanic 0:02dd72d1d465 99 c = self.proc.stdout.read(1)
borlanic 0:02dd72d1d465 100 self.queue.put(c)
borlanic 0:02dd72d1d465 101
borlanic 0:02dd72d1d465 102 def stop(self):
borlanic 0:02dd72d1d465 103 self.active = False
borlanic 0:02dd72d1d465 104 try:
borlanic 0:02dd72d1d465 105 self.proc.terminate()
borlanic 0:02dd72d1d465 106 except Exception:
borlanic 0:02dd72d1d465 107 pass
borlanic 0:02dd72d1d465 108
borlanic 0:02dd72d1d465 109
borlanic 0:02dd72d1d465 110 class SingleTestExecutor(threading.Thread):
borlanic 0:02dd72d1d465 111 """ Example: Single test class in separate thread usage
borlanic 0:02dd72d1d465 112 """
borlanic 0:02dd72d1d465 113 def __init__(self, single_test):
borlanic 0:02dd72d1d465 114 self.single_test = single_test
borlanic 0:02dd72d1d465 115 threading.Thread.__init__(self)
borlanic 0:02dd72d1d465 116
borlanic 0:02dd72d1d465 117 def run(self):
borlanic 0:02dd72d1d465 118 start = time()
borlanic 0:02dd72d1d465 119 # Execute tests depending on options and filter applied
borlanic 0:02dd72d1d465 120 test_summary, shuffle_seed, test_summary_ext, test_suite_properties_ext = self.single_test.execute()
borlanic 0:02dd72d1d465 121 elapsed_time = time() - start
borlanic 0:02dd72d1d465 122
borlanic 0:02dd72d1d465 123 # Human readable summary
borlanic 0:02dd72d1d465 124 if not self.single_test.opts_suppress_summary:
borlanic 0:02dd72d1d465 125 # prints well-formed summary with results (SQL table like)
borlanic 0:02dd72d1d465 126 print(self.single_test.generate_test_summary(test_summary,
borlanic 0:02dd72d1d465 127 shuffle_seed))
borlanic 0:02dd72d1d465 128 if self.single_test.opts_test_x_toolchain_summary:
borlanic 0:02dd72d1d465 129 # prints well-formed summary with results (SQL table like)
borlanic 0:02dd72d1d465 130 # table shows text x toolchain test result matrix
borlanic 0:02dd72d1d465 131 print(self.single_test.generate_test_summary_by_target(
borlanic 0:02dd72d1d465 132 test_summary, shuffle_seed))
borlanic 0:02dd72d1d465 133 print("Completed in %.2f sec"% (elapsed_time))
borlanic 0:02dd72d1d465 134
borlanic 0:02dd72d1d465 135
borlanic 0:02dd72d1d465 136 class SingleTestRunner(object):
borlanic 0:02dd72d1d465 137 """ Object wrapper for single test run which may involve multiple MUTs
borlanic 0:02dd72d1d465 138 """
borlanic 0:02dd72d1d465 139 RE_DETECT_TESTCASE_RESULT = None
borlanic 0:02dd72d1d465 140
borlanic 0:02dd72d1d465 141 # Return codes for test script
borlanic 0:02dd72d1d465 142 TEST_RESULT_OK = "OK"
borlanic 0:02dd72d1d465 143 TEST_RESULT_FAIL = "FAIL"
borlanic 0:02dd72d1d465 144 TEST_RESULT_ERROR = "ERROR"
borlanic 0:02dd72d1d465 145 TEST_RESULT_UNDEF = "UNDEF"
borlanic 0:02dd72d1d465 146 TEST_RESULT_IOERR_COPY = "IOERR_COPY"
borlanic 0:02dd72d1d465 147 TEST_RESULT_IOERR_DISK = "IOERR_DISK"
borlanic 0:02dd72d1d465 148 TEST_RESULT_IOERR_SERIAL = "IOERR_SERIAL"
borlanic 0:02dd72d1d465 149 TEST_RESULT_TIMEOUT = "TIMEOUT"
borlanic 0:02dd72d1d465 150 TEST_RESULT_NO_IMAGE = "NO_IMAGE"
borlanic 0:02dd72d1d465 151 TEST_RESULT_MBED_ASSERT = "MBED_ASSERT"
borlanic 0:02dd72d1d465 152 TEST_RESULT_BUILD_FAILED = "BUILD_FAILED"
borlanic 0:02dd72d1d465 153 TEST_RESULT_NOT_SUPPORTED = "NOT_SUPPORTED"
borlanic 0:02dd72d1d465 154
borlanic 0:02dd72d1d465 155 GLOBAL_LOOPS_COUNT = 1 # How many times each test should be repeated
borlanic 0:02dd72d1d465 156 TEST_LOOPS_LIST = [] # We redefine no.of loops per test_id
borlanic 0:02dd72d1d465 157 TEST_LOOPS_DICT = {} # TEST_LOOPS_LIST in dict format: { test_id : test_loop_count}
borlanic 0:02dd72d1d465 158
borlanic 0:02dd72d1d465 159 muts = {} # MUTs descriptor (from external file)
borlanic 0:02dd72d1d465 160 test_spec = {} # Test specification (from external file)
borlanic 0:02dd72d1d465 161
borlanic 0:02dd72d1d465 162 # mbed test suite -> SingleTestRunner
borlanic 0:02dd72d1d465 163 TEST_RESULT_MAPPING = {"success" : TEST_RESULT_OK,
borlanic 0:02dd72d1d465 164 "failure" : TEST_RESULT_FAIL,
borlanic 0:02dd72d1d465 165 "error" : TEST_RESULT_ERROR,
borlanic 0:02dd72d1d465 166 "ioerr_copy" : TEST_RESULT_IOERR_COPY,
borlanic 0:02dd72d1d465 167 "ioerr_disk" : TEST_RESULT_IOERR_DISK,
borlanic 0:02dd72d1d465 168 "ioerr_serial" : TEST_RESULT_IOERR_SERIAL,
borlanic 0:02dd72d1d465 169 "timeout" : TEST_RESULT_TIMEOUT,
borlanic 0:02dd72d1d465 170 "no_image" : TEST_RESULT_NO_IMAGE,
borlanic 0:02dd72d1d465 171 "end" : TEST_RESULT_UNDEF,
borlanic 0:02dd72d1d465 172 "mbed_assert" : TEST_RESULT_MBED_ASSERT,
borlanic 0:02dd72d1d465 173 "build_failed" : TEST_RESULT_BUILD_FAILED,
borlanic 0:02dd72d1d465 174 "not_supproted" : TEST_RESULT_NOT_SUPPORTED
borlanic 0:02dd72d1d465 175 }
borlanic 0:02dd72d1d465 176
borlanic 0:02dd72d1d465 177 def __init__(self,
borlanic 0:02dd72d1d465 178 _global_loops_count=1,
borlanic 0:02dd72d1d465 179 _test_loops_list=None,
borlanic 0:02dd72d1d465 180 _muts={},
borlanic 0:02dd72d1d465 181 _clean=False,
borlanic 0:02dd72d1d465 182 _parser=None,
borlanic 0:02dd72d1d465 183 _opts=None,
borlanic 0:02dd72d1d465 184 _opts_db_url=None,
borlanic 0:02dd72d1d465 185 _opts_log_file_name=None,
borlanic 0:02dd72d1d465 186 _opts_report_html_file_name=None,
borlanic 0:02dd72d1d465 187 _opts_report_junit_file_name=None,
borlanic 0:02dd72d1d465 188 _opts_report_build_file_name=None,
borlanic 0:02dd72d1d465 189 _opts_report_text_file_name=None,
borlanic 0:02dd72d1d465 190 _opts_build_report={},
borlanic 0:02dd72d1d465 191 _opts_build_properties={},
borlanic 0:02dd72d1d465 192 _test_spec={},
borlanic 0:02dd72d1d465 193 _opts_goanna_for_mbed_sdk=None,
borlanic 0:02dd72d1d465 194 _opts_goanna_for_tests=None,
borlanic 0:02dd72d1d465 195 _opts_shuffle_test_order=False,
borlanic 0:02dd72d1d465 196 _opts_shuffle_test_seed=None,
borlanic 0:02dd72d1d465 197 _opts_test_by_names=None,
borlanic 0:02dd72d1d465 198 _opts_peripheral_by_names=None,
borlanic 0:02dd72d1d465 199 _opts_test_only_peripheral=False,
borlanic 0:02dd72d1d465 200 _opts_test_only_common=False,
borlanic 0:02dd72d1d465 201 _opts_verbose_skipped_tests=False,
borlanic 0:02dd72d1d465 202 _opts_verbose_test_result_only=False,
borlanic 0:02dd72d1d465 203 _opts_verbose=False,
borlanic 0:02dd72d1d465 204 _opts_firmware_global_name=None,
borlanic 0:02dd72d1d465 205 _opts_only_build_tests=False,
borlanic 0:02dd72d1d465 206 _opts_parallel_test_exec=False,
borlanic 0:02dd72d1d465 207 _opts_suppress_summary=False,
borlanic 0:02dd72d1d465 208 _opts_test_x_toolchain_summary=False,
borlanic 0:02dd72d1d465 209 _opts_copy_method=None,
borlanic 0:02dd72d1d465 210 _opts_mut_reset_type=None,
borlanic 0:02dd72d1d465 211 _opts_jobs=None,
borlanic 0:02dd72d1d465 212 _opts_waterfall_test=None,
borlanic 0:02dd72d1d465 213 _opts_consolidate_waterfall_test=None,
borlanic 0:02dd72d1d465 214 _opts_extend_test_timeout=None,
borlanic 0:02dd72d1d465 215 _opts_auto_detect=None,
borlanic 0:02dd72d1d465 216 _opts_include_non_automated=False):
borlanic 0:02dd72d1d465 217 """ Let's try hard to init this object
borlanic 0:02dd72d1d465 218 """
borlanic 0:02dd72d1d465 219 from colorama import init
borlanic 0:02dd72d1d465 220 init()
borlanic 0:02dd72d1d465 221
borlanic 0:02dd72d1d465 222 PATTERN = "\\{(" + "|".join(self.TEST_RESULT_MAPPING.keys()) + ")\\}"
borlanic 0:02dd72d1d465 223 self.RE_DETECT_TESTCASE_RESULT = re.compile(PATTERN)
borlanic 0:02dd72d1d465 224 # Settings related to test loops counters
borlanic 0:02dd72d1d465 225 try:
borlanic 0:02dd72d1d465 226 _global_loops_count = int(_global_loops_count)
borlanic 0:02dd72d1d465 227 except:
borlanic 0:02dd72d1d465 228 _global_loops_count = 1
borlanic 0:02dd72d1d465 229 if _global_loops_count < 1:
borlanic 0:02dd72d1d465 230 _global_loops_count = 1
borlanic 0:02dd72d1d465 231 self.GLOBAL_LOOPS_COUNT = _global_loops_count
borlanic 0:02dd72d1d465 232 self.TEST_LOOPS_LIST = _test_loops_list if _test_loops_list else []
borlanic 0:02dd72d1d465 233 self.TEST_LOOPS_DICT = self.test_loop_list_to_dict(_test_loops_list)
borlanic 0:02dd72d1d465 234
borlanic 0:02dd72d1d465 235 self.shuffle_random_seed = 0.0
borlanic 0:02dd72d1d465 236 self.SHUFFLE_SEED_ROUND = 10
borlanic 0:02dd72d1d465 237
borlanic 0:02dd72d1d465 238 # MUT list and test specification storage
borlanic 0:02dd72d1d465 239 self.muts = _muts
borlanic 0:02dd72d1d465 240 self.test_spec = _test_spec
borlanic 0:02dd72d1d465 241
borlanic 0:02dd72d1d465 242 # Settings passed e.g. from command line
borlanic 0:02dd72d1d465 243 self.opts_db_url = _opts_db_url
borlanic 0:02dd72d1d465 244 self.opts_log_file_name = _opts_log_file_name
borlanic 0:02dd72d1d465 245 self.opts_report_html_file_name = _opts_report_html_file_name
borlanic 0:02dd72d1d465 246 self.opts_report_junit_file_name = _opts_report_junit_file_name
borlanic 0:02dd72d1d465 247 self.opts_report_build_file_name = _opts_report_build_file_name
borlanic 0:02dd72d1d465 248 self.opts_report_text_file_name = _opts_report_text_file_name
borlanic 0:02dd72d1d465 249 self.opts_goanna_for_mbed_sdk = _opts_goanna_for_mbed_sdk
borlanic 0:02dd72d1d465 250 self.opts_goanna_for_tests = _opts_goanna_for_tests
borlanic 0:02dd72d1d465 251 self.opts_shuffle_test_order = _opts_shuffle_test_order
borlanic 0:02dd72d1d465 252 self.opts_shuffle_test_seed = _opts_shuffle_test_seed
borlanic 0:02dd72d1d465 253 self.opts_test_by_names = _opts_test_by_names
borlanic 0:02dd72d1d465 254 self.opts_peripheral_by_names = _opts_peripheral_by_names
borlanic 0:02dd72d1d465 255 self.opts_test_only_peripheral = _opts_test_only_peripheral
borlanic 0:02dd72d1d465 256 self.opts_test_only_common = _opts_test_only_common
borlanic 0:02dd72d1d465 257 self.opts_verbose_skipped_tests = _opts_verbose_skipped_tests
borlanic 0:02dd72d1d465 258 self.opts_verbose_test_result_only = _opts_verbose_test_result_only
borlanic 0:02dd72d1d465 259 self.opts_verbose = _opts_verbose
borlanic 0:02dd72d1d465 260 self.opts_firmware_global_name = _opts_firmware_global_name
borlanic 0:02dd72d1d465 261 self.opts_only_build_tests = _opts_only_build_tests
borlanic 0:02dd72d1d465 262 self.opts_parallel_test_exec = _opts_parallel_test_exec
borlanic 0:02dd72d1d465 263 self.opts_suppress_summary = _opts_suppress_summary
borlanic 0:02dd72d1d465 264 self.opts_test_x_toolchain_summary = _opts_test_x_toolchain_summary
borlanic 0:02dd72d1d465 265 self.opts_copy_method = _opts_copy_method
borlanic 0:02dd72d1d465 266 self.opts_mut_reset_type = _opts_mut_reset_type
borlanic 0:02dd72d1d465 267 self.opts_jobs = _opts_jobs if _opts_jobs is not None else 1
borlanic 0:02dd72d1d465 268 self.opts_waterfall_test = _opts_waterfall_test
borlanic 0:02dd72d1d465 269 self.opts_consolidate_waterfall_test = _opts_consolidate_waterfall_test
borlanic 0:02dd72d1d465 270 self.opts_extend_test_timeout = _opts_extend_test_timeout
borlanic 0:02dd72d1d465 271 self.opts_clean = _clean
borlanic 0:02dd72d1d465 272 self.opts_parser = _parser
borlanic 0:02dd72d1d465 273 self.opts = _opts
borlanic 0:02dd72d1d465 274 self.opts_auto_detect = _opts_auto_detect
borlanic 0:02dd72d1d465 275 self.opts_include_non_automated = _opts_include_non_automated
borlanic 0:02dd72d1d465 276
borlanic 0:02dd72d1d465 277 self.build_report = _opts_build_report
borlanic 0:02dd72d1d465 278 self.build_properties = _opts_build_properties
borlanic 0:02dd72d1d465 279
borlanic 0:02dd72d1d465 280 # File / screen logger initialization
borlanic 0:02dd72d1d465 281 self.logger = CLITestLogger(file_name=self.opts_log_file_name) # Default test logger
borlanic 0:02dd72d1d465 282
borlanic 0:02dd72d1d465 283 # Database related initializations
borlanic 0:02dd72d1d465 284 self.db_logger = factory_db_logger(self.opts_db_url)
borlanic 0:02dd72d1d465 285 self.db_logger_build_id = None # Build ID (database index of build_id table)
borlanic 0:02dd72d1d465 286 # Let's connect to database to set up credentials and confirm database is ready
borlanic 0:02dd72d1d465 287 if self.db_logger:
borlanic 0:02dd72d1d465 288 self.db_logger.connect_url(self.opts_db_url) # Save db access info inside db_logger object
borlanic 0:02dd72d1d465 289 if self.db_logger.is_connected():
borlanic 0:02dd72d1d465 290 # Get hostname and uname so we can use it as build description
borlanic 0:02dd72d1d465 291 # when creating new build_id in external database
borlanic 0:02dd72d1d465 292 (_hostname, _uname) = self.db_logger.get_hostname()
borlanic 0:02dd72d1d465 293 _host_location = os.path.dirname(os.path.abspath(__file__))
borlanic 0:02dd72d1d465 294 build_id_type = None if self.opts_only_build_tests is None else self.db_logger.BUILD_ID_TYPE_BUILD_ONLY
borlanic 0:02dd72d1d465 295 self.db_logger_build_id = self.db_logger.get_next_build_id(_hostname, desc=_uname, location=_host_location, type=build_id_type)
borlanic 0:02dd72d1d465 296 self.db_logger.disconnect()
borlanic 0:02dd72d1d465 297
borlanic 0:02dd72d1d465 298 def dump_options(self):
borlanic 0:02dd72d1d465 299 """ Function returns data structure with common settings passed to SingelTestRunner
borlanic 0:02dd72d1d465 300 It can be used for example to fill _extra fields in database storing test suite single run data
borlanic 0:02dd72d1d465 301 Example:
borlanic 0:02dd72d1d465 302 data = self.dump_options()
borlanic 0:02dd72d1d465 303 or
borlanic 0:02dd72d1d465 304 data_str = json.dumps(self.dump_options())
borlanic 0:02dd72d1d465 305 """
borlanic 0:02dd72d1d465 306 result = {"db_url" : str(self.opts_db_url),
borlanic 0:02dd72d1d465 307 "log_file_name" : str(self.opts_log_file_name),
borlanic 0:02dd72d1d465 308 "shuffle_test_order" : str(self.opts_shuffle_test_order),
borlanic 0:02dd72d1d465 309 "shuffle_test_seed" : str(self.opts_shuffle_test_seed),
borlanic 0:02dd72d1d465 310 "test_by_names" : str(self.opts_test_by_names),
borlanic 0:02dd72d1d465 311 "peripheral_by_names" : str(self.opts_peripheral_by_names),
borlanic 0:02dd72d1d465 312 "test_only_peripheral" : str(self.opts_test_only_peripheral),
borlanic 0:02dd72d1d465 313 "test_only_common" : str(self.opts_test_only_common),
borlanic 0:02dd72d1d465 314 "verbose" : str(self.opts_verbose),
borlanic 0:02dd72d1d465 315 "firmware_global_name" : str(self.opts_firmware_global_name),
borlanic 0:02dd72d1d465 316 "only_build_tests" : str(self.opts_only_build_tests),
borlanic 0:02dd72d1d465 317 "copy_method" : str(self.opts_copy_method),
borlanic 0:02dd72d1d465 318 "mut_reset_type" : str(self.opts_mut_reset_type),
borlanic 0:02dd72d1d465 319 "jobs" : str(self.opts_jobs),
borlanic 0:02dd72d1d465 320 "extend_test_timeout" : str(self.opts_extend_test_timeout),
borlanic 0:02dd72d1d465 321 "_dummy" : ''
borlanic 0:02dd72d1d465 322 }
borlanic 0:02dd72d1d465 323 return result
borlanic 0:02dd72d1d465 324
borlanic 0:02dd72d1d465 325 def shuffle_random_func(self):
borlanic 0:02dd72d1d465 326 return self.shuffle_random_seed
borlanic 0:02dd72d1d465 327
borlanic 0:02dd72d1d465 328 def is_shuffle_seed_float(self):
borlanic 0:02dd72d1d465 329 """ return true if function parameter can be converted to float
borlanic 0:02dd72d1d465 330 """
borlanic 0:02dd72d1d465 331 result = True
borlanic 0:02dd72d1d465 332 try:
borlanic 0:02dd72d1d465 333 float(self.shuffle_random_seed)
borlanic 0:02dd72d1d465 334 except ValueError:
borlanic 0:02dd72d1d465 335 result = False
borlanic 0:02dd72d1d465 336 return result
borlanic 0:02dd72d1d465 337
borlanic 0:02dd72d1d465 338 # This will store target / toolchain specific properties
borlanic 0:02dd72d1d465 339 test_suite_properties_ext = {} # target : toolchain
borlanic 0:02dd72d1d465 340 # Here we store test results
borlanic 0:02dd72d1d465 341 test_summary = []
borlanic 0:02dd72d1d465 342 # Here we store test results in extended data structure
borlanic 0:02dd72d1d465 343 test_summary_ext = {}
borlanic 0:02dd72d1d465 344 execute_thread_slice_lock = Lock()
borlanic 0:02dd72d1d465 345
borlanic 0:02dd72d1d465 346 def execute_thread_slice(self, q, target, toolchains, clean, test_ids, build_report, build_properties):
borlanic 0:02dd72d1d465 347 for toolchain in toolchains:
borlanic 0:02dd72d1d465 348 tt_id = "%s::%s" % (toolchain, target)
borlanic 0:02dd72d1d465 349
borlanic 0:02dd72d1d465 350 T = TARGET_MAP[target]
borlanic 0:02dd72d1d465 351
borlanic 0:02dd72d1d465 352 # print target, toolchain
borlanic 0:02dd72d1d465 353 # Test suite properties returned to external tools like CI
borlanic 0:02dd72d1d465 354 test_suite_properties = {
borlanic 0:02dd72d1d465 355 'jobs': self.opts_jobs,
borlanic 0:02dd72d1d465 356 'clean': clean,
borlanic 0:02dd72d1d465 357 'target': target,
borlanic 0:02dd72d1d465 358 'vendor': T.extra_labels[0],
borlanic 0:02dd72d1d465 359 'test_ids': ', '.join(test_ids),
borlanic 0:02dd72d1d465 360 'toolchain': toolchain,
borlanic 0:02dd72d1d465 361 'shuffle_random_seed': self.shuffle_random_seed
borlanic 0:02dd72d1d465 362 }
borlanic 0:02dd72d1d465 363
borlanic 0:02dd72d1d465 364
borlanic 0:02dd72d1d465 365 # print '=== %s::%s ===' % (target, toolchain)
borlanic 0:02dd72d1d465 366 # Let's build our test
borlanic 0:02dd72d1d465 367 if target not in TARGET_MAP:
borlanic 0:02dd72d1d465 368 print(self.logger.log_line(
borlanic 0:02dd72d1d465 369 self.logger.LogType.NOTIF,
borlanic 0:02dd72d1d465 370 'Skipped tests for %s target. Target platform not found' %
borlanic 0:02dd72d1d465 371 (target)))
borlanic 0:02dd72d1d465 372 continue
borlanic 0:02dd72d1d465 373
borlanic 0:02dd72d1d465 374 clean_mbed_libs_options = (self.opts_goanna_for_mbed_sdk or
borlanic 0:02dd72d1d465 375 self.opts_clean or clean)
borlanic 0:02dd72d1d465 376
borlanic 0:02dd72d1d465 377 profile = extract_profile(self.opts_parser, self.opts, toolchain)
borlanic 0:02dd72d1d465 378 stats_depth = self.opts.stats_depth or 2
borlanic 0:02dd72d1d465 379
borlanic 0:02dd72d1d465 380 try:
borlanic 0:02dd72d1d465 381 build_mbed_libs_result = build_mbed_libs(
borlanic 0:02dd72d1d465 382 T, toolchain,
borlanic 0:02dd72d1d465 383 clean=clean_mbed_libs_options,
borlanic 0:02dd72d1d465 384 verbose=self.opts_verbose,
borlanic 0:02dd72d1d465 385 jobs=self.opts_jobs,
borlanic 0:02dd72d1d465 386 report=build_report,
borlanic 0:02dd72d1d465 387 properties=build_properties,
borlanic 0:02dd72d1d465 388 build_profile=profile)
borlanic 0:02dd72d1d465 389
borlanic 0:02dd72d1d465 390 if not build_mbed_libs_result:
borlanic 0:02dd72d1d465 391 print(self.logger.log_line(
borlanic 0:02dd72d1d465 392 self.logger.LogType.NOTIF,
borlanic 0:02dd72d1d465 393 'Skipped tests for %s target. Toolchain %s is not '
borlanic 0:02dd72d1d465 394 'supported for this target'% (T.name, toolchain)))
borlanic 0:02dd72d1d465 395 continue
borlanic 0:02dd72d1d465 396
borlanic 0:02dd72d1d465 397 except ToolException:
borlanic 0:02dd72d1d465 398 print(self.logger.log_line(
borlanic 0:02dd72d1d465 399 self.logger.LogType.ERROR,
borlanic 0:02dd72d1d465 400 'There were errors while building MBED libs for %s using %s'
borlanic 0:02dd72d1d465 401 % (target, toolchain)))
borlanic 0:02dd72d1d465 402 continue
borlanic 0:02dd72d1d465 403
borlanic 0:02dd72d1d465 404 build_dir = join(BUILD_DIR, "test", target, toolchain)
borlanic 0:02dd72d1d465 405
borlanic 0:02dd72d1d465 406 test_suite_properties['build_mbed_libs_result'] = build_mbed_libs_result
borlanic 0:02dd72d1d465 407 test_suite_properties['build_dir'] = build_dir
borlanic 0:02dd72d1d465 408 test_suite_properties['skipped'] = []
borlanic 0:02dd72d1d465 409
borlanic 0:02dd72d1d465 410 # Enumerate through all tests and shuffle test order if requested
borlanic 0:02dd72d1d465 411 test_map_keys = sorted(TEST_MAP.keys())
borlanic 0:02dd72d1d465 412
borlanic 0:02dd72d1d465 413 if self.opts_shuffle_test_order:
borlanic 0:02dd72d1d465 414 random.shuffle(test_map_keys, self.shuffle_random_func)
borlanic 0:02dd72d1d465 415 # Update database with shuffle seed f applicable
borlanic 0:02dd72d1d465 416 if self.db_logger:
borlanic 0:02dd72d1d465 417 self.db_logger.reconnect();
borlanic 0:02dd72d1d465 418 if self.db_logger.is_connected():
borlanic 0:02dd72d1d465 419 self.db_logger.update_build_id_info(
borlanic 0:02dd72d1d465 420 self.db_logger_build_id,
borlanic 0:02dd72d1d465 421 _shuffle_seed=self.shuffle_random_func())
borlanic 0:02dd72d1d465 422 self.db_logger.disconnect();
borlanic 0:02dd72d1d465 423
borlanic 0:02dd72d1d465 424 if self.db_logger:
borlanic 0:02dd72d1d465 425 self.db_logger.reconnect();
borlanic 0:02dd72d1d465 426 if self.db_logger.is_connected():
borlanic 0:02dd72d1d465 427 # Update MUTs and Test Specification in database
borlanic 0:02dd72d1d465 428 self.db_logger.update_build_id_info(
borlanic 0:02dd72d1d465 429 self.db_logger_build_id,
borlanic 0:02dd72d1d465 430 _muts=self.muts, _test_spec=self.test_spec)
borlanic 0:02dd72d1d465 431 # Update Extra information in database (some options passed to test suite)
borlanic 0:02dd72d1d465 432 self.db_logger.update_build_id_info(
borlanic 0:02dd72d1d465 433 self.db_logger_build_id,
borlanic 0:02dd72d1d465 434 _extra=json.dumps(self.dump_options()))
borlanic 0:02dd72d1d465 435 self.db_logger.disconnect();
borlanic 0:02dd72d1d465 436
borlanic 0:02dd72d1d465 437 valid_test_map_keys = self.get_valid_tests(test_map_keys, target, toolchain, test_ids, self.opts_include_non_automated)
borlanic 0:02dd72d1d465 438 skipped_test_map_keys = self.get_skipped_tests(test_map_keys, valid_test_map_keys)
borlanic 0:02dd72d1d465 439
borlanic 0:02dd72d1d465 440 for skipped_test_id in skipped_test_map_keys:
borlanic 0:02dd72d1d465 441 test_suite_properties['skipped'].append(skipped_test_id)
borlanic 0:02dd72d1d465 442
borlanic 0:02dd72d1d465 443
borlanic 0:02dd72d1d465 444 # First pass through all tests and determine which libraries need to be built
borlanic 0:02dd72d1d465 445 libraries = []
borlanic 0:02dd72d1d465 446 for test_id in valid_test_map_keys:
borlanic 0:02dd72d1d465 447 test = TEST_MAP[test_id]
borlanic 0:02dd72d1d465 448
borlanic 0:02dd72d1d465 449 # Detect which lib should be added to test
borlanic 0:02dd72d1d465 450 # Some libs have to compiled like RTOS or ETH
borlanic 0:02dd72d1d465 451 for lib in LIBRARIES:
borlanic 0:02dd72d1d465 452 if lib['build_dir'] in test.dependencies and lib['id'] not in libraries:
borlanic 0:02dd72d1d465 453 libraries.append(lib['id'])
borlanic 0:02dd72d1d465 454
borlanic 0:02dd72d1d465 455
borlanic 0:02dd72d1d465 456 clean_project_options = True if self.opts_goanna_for_tests or clean or self.opts_clean else None
borlanic 0:02dd72d1d465 457
borlanic 0:02dd72d1d465 458 # Build all required libraries
borlanic 0:02dd72d1d465 459 for lib_id in libraries:
borlanic 0:02dd72d1d465 460 try:
borlanic 0:02dd72d1d465 461 build_lib(lib_id,
borlanic 0:02dd72d1d465 462 T,
borlanic 0:02dd72d1d465 463 toolchain,
borlanic 0:02dd72d1d465 464 verbose=self.opts_verbose,
borlanic 0:02dd72d1d465 465 clean=clean_mbed_libs_options,
borlanic 0:02dd72d1d465 466 jobs=self.opts_jobs,
borlanic 0:02dd72d1d465 467 report=build_report,
borlanic 0:02dd72d1d465 468 properties=build_properties,
borlanic 0:02dd72d1d465 469 build_profile=profile)
borlanic 0:02dd72d1d465 470
borlanic 0:02dd72d1d465 471 except ToolException:
borlanic 0:02dd72d1d465 472 print(self.logger.log_line(
borlanic 0:02dd72d1d465 473 self.logger.LogType.ERROR,
borlanic 0:02dd72d1d465 474 'There were errors while building library %s' % lib_id))
borlanic 0:02dd72d1d465 475 continue
borlanic 0:02dd72d1d465 476
borlanic 0:02dd72d1d465 477
borlanic 0:02dd72d1d465 478 for test_id in valid_test_map_keys:
borlanic 0:02dd72d1d465 479 test = TEST_MAP[test_id]
borlanic 0:02dd72d1d465 480
borlanic 0:02dd72d1d465 481 test_suite_properties['test.libs.%s.%s.%s'% (target, toolchain, test_id)] = ', '.join(libraries)
borlanic 0:02dd72d1d465 482
borlanic 0:02dd72d1d465 483 # TODO: move this 2 below loops to separate function
borlanic 0:02dd72d1d465 484 INC_DIRS = []
borlanic 0:02dd72d1d465 485 for lib_id in libraries:
borlanic 0:02dd72d1d465 486 if 'inc_dirs_ext' in LIBRARY_MAP[lib_id] and LIBRARY_MAP[lib_id]['inc_dirs_ext']:
borlanic 0:02dd72d1d465 487 INC_DIRS.extend(LIBRARY_MAP[lib_id]['inc_dirs_ext'])
borlanic 0:02dd72d1d465 488
borlanic 0:02dd72d1d465 489 MACROS = []
borlanic 0:02dd72d1d465 490 for lib_id in libraries:
borlanic 0:02dd72d1d465 491 if 'macros' in LIBRARY_MAP[lib_id] and LIBRARY_MAP[lib_id]['macros']:
borlanic 0:02dd72d1d465 492 MACROS.extend(LIBRARY_MAP[lib_id]['macros'])
borlanic 0:02dd72d1d465 493 MACROS.append('TEST_SUITE_TARGET_NAME="%s"'% target)
borlanic 0:02dd72d1d465 494 MACROS.append('TEST_SUITE_TEST_ID="%s"'% test_id)
borlanic 0:02dd72d1d465 495 test_uuid = uuid.uuid4()
borlanic 0:02dd72d1d465 496 MACROS.append('TEST_SUITE_UUID="%s"'% str(test_uuid))
borlanic 0:02dd72d1d465 497
borlanic 0:02dd72d1d465 498 # Prepare extended test results data structure (it can be used to generate detailed test report)
borlanic 0:02dd72d1d465 499 if target not in self.test_summary_ext:
borlanic 0:02dd72d1d465 500 self.test_summary_ext[target] = {} # test_summary_ext : toolchain
borlanic 0:02dd72d1d465 501 if toolchain not in self.test_summary_ext[target]:
borlanic 0:02dd72d1d465 502 self.test_summary_ext[target][toolchain] = {} # test_summary_ext : toolchain : target
borlanic 0:02dd72d1d465 503
borlanic 0:02dd72d1d465 504 tt_test_id = "%s::%s::%s" % (toolchain, target, test_id) # For logging only
borlanic 0:02dd72d1d465 505
borlanic 0:02dd72d1d465 506 project_name = self.opts_firmware_global_name if self.opts_firmware_global_name else None
borlanic 0:02dd72d1d465 507 try:
borlanic 0:02dd72d1d465 508 path = build_project(test.source_dir, join(build_dir, test_id), T,
borlanic 0:02dd72d1d465 509 toolchain, test.dependencies, clean=clean_project_options,
borlanic 0:02dd72d1d465 510 verbose=self.opts_verbose, name=project_name, macros=MACROS,
borlanic 0:02dd72d1d465 511 inc_dirs=INC_DIRS, jobs=self.opts_jobs, report=build_report,
borlanic 0:02dd72d1d465 512 properties=build_properties, project_id=test_id,
borlanic 0:02dd72d1d465 513 project_description=test.get_description(),
borlanic 0:02dd72d1d465 514 build_profile=profile, stats_depth=stats_depth)
borlanic 0:02dd72d1d465 515
borlanic 0:02dd72d1d465 516 except Exception as e:
borlanic 0:02dd72d1d465 517 project_name_str = project_name if project_name is not None else test_id
borlanic 0:02dd72d1d465 518
borlanic 0:02dd72d1d465 519
borlanic 0:02dd72d1d465 520 test_result = self.TEST_RESULT_FAIL
borlanic 0:02dd72d1d465 521
borlanic 0:02dd72d1d465 522 if isinstance(e, ToolException):
borlanic 0:02dd72d1d465 523 print(self.logger.log_line(
borlanic 0:02dd72d1d465 524 self.logger.LogType.ERROR,
borlanic 0:02dd72d1d465 525 'There were errors while building project %s' %
borlanic 0:02dd72d1d465 526 project_name_str))
borlanic 0:02dd72d1d465 527 test_result = self.TEST_RESULT_BUILD_FAILED
borlanic 0:02dd72d1d465 528 elif isinstance(e, NotSupportedException):
borlanic 0:02dd72d1d465 529 print(elf.logger.log_line(
borlanic 0:02dd72d1d465 530 self.logger.LogType.INFO,
borlanic 0:02dd72d1d465 531 'Project %s is not supported' % project_name_str))
borlanic 0:02dd72d1d465 532 test_result = self.TEST_RESULT_NOT_SUPPORTED
borlanic 0:02dd72d1d465 533
borlanic 0:02dd72d1d465 534
borlanic 0:02dd72d1d465 535 # Append test results to global test summary
borlanic 0:02dd72d1d465 536 self.test_summary.append(
borlanic 0:02dd72d1d465 537 (test_result, target, toolchain, test_id,
borlanic 0:02dd72d1d465 538 test.get_description(), 0, 0, '-')
borlanic 0:02dd72d1d465 539 )
borlanic 0:02dd72d1d465 540
borlanic 0:02dd72d1d465 541 # Add detailed test result to test summary structure
borlanic 0:02dd72d1d465 542 if test_id not in self.test_summary_ext[target][toolchain]:
borlanic 0:02dd72d1d465 543 self.test_summary_ext[target][toolchain][test_id] = []
borlanic 0:02dd72d1d465 544
borlanic 0:02dd72d1d465 545 self.test_summary_ext[target][toolchain][test_id].append({ 0: {
borlanic 0:02dd72d1d465 546 'result' : test_result,
borlanic 0:02dd72d1d465 547 'output' : '',
borlanic 0:02dd72d1d465 548 'target_name' : target,
borlanic 0:02dd72d1d465 549 'target_name_unique': target,
borlanic 0:02dd72d1d465 550 'toolchain_name' : toolchain,
borlanic 0:02dd72d1d465 551 'id' : test_id,
borlanic 0:02dd72d1d465 552 'description' : test.get_description(),
borlanic 0:02dd72d1d465 553 'elapsed_time' : 0,
borlanic 0:02dd72d1d465 554 'duration' : 0,
borlanic 0:02dd72d1d465 555 'copy_method' : None
borlanic 0:02dd72d1d465 556 }})
borlanic 0:02dd72d1d465 557 continue
borlanic 0:02dd72d1d465 558
borlanic 0:02dd72d1d465 559 if self.opts_only_build_tests:
borlanic 0:02dd72d1d465 560 # With this option we are skipping testing phase
borlanic 0:02dd72d1d465 561 continue
borlanic 0:02dd72d1d465 562
borlanic 0:02dd72d1d465 563 # Test duration can be increased by global value
borlanic 0:02dd72d1d465 564 test_duration = test.duration
borlanic 0:02dd72d1d465 565 if self.opts_extend_test_timeout is not None:
borlanic 0:02dd72d1d465 566 test_duration += self.opts_extend_test_timeout
borlanic 0:02dd72d1d465 567
borlanic 0:02dd72d1d465 568 # For an automated test the duration act as a timeout after
borlanic 0:02dd72d1d465 569 # which the test gets interrupted
borlanic 0:02dd72d1d465 570 test_spec = self.shape_test_request(target, path, test_id, test_duration)
borlanic 0:02dd72d1d465 571 test_loops = self.get_test_loop_count(test_id)
borlanic 0:02dd72d1d465 572
borlanic 0:02dd72d1d465 573 test_suite_properties['test.duration.%s.%s.%s'% (target, toolchain, test_id)] = test_duration
borlanic 0:02dd72d1d465 574 test_suite_properties['test.loops.%s.%s.%s'% (target, toolchain, test_id)] = test_loops
borlanic 0:02dd72d1d465 575 test_suite_properties['test.path.%s.%s.%s'% (target, toolchain, test_id)] = path
borlanic 0:02dd72d1d465 576
borlanic 0:02dd72d1d465 577 # read MUTs, test specification and perform tests
borlanic 0:02dd72d1d465 578 handle_results = self.handle(test_spec, target, toolchain, test_loops=test_loops)
borlanic 0:02dd72d1d465 579
borlanic 0:02dd72d1d465 580 if handle_results is None:
borlanic 0:02dd72d1d465 581 continue
borlanic 0:02dd72d1d465 582
borlanic 0:02dd72d1d465 583 for handle_result in handle_results:
borlanic 0:02dd72d1d465 584 if handle_result:
borlanic 0:02dd72d1d465 585 single_test_result, detailed_test_results = handle_result
borlanic 0:02dd72d1d465 586 else:
borlanic 0:02dd72d1d465 587 continue
borlanic 0:02dd72d1d465 588
borlanic 0:02dd72d1d465 589 # Append test results to global test summary
borlanic 0:02dd72d1d465 590 if single_test_result is not None:
borlanic 0:02dd72d1d465 591 self.test_summary.append(single_test_result)
borlanic 0:02dd72d1d465 592
borlanic 0:02dd72d1d465 593 # Add detailed test result to test summary structure
borlanic 0:02dd72d1d465 594 if target not in self.test_summary_ext[target][toolchain]:
borlanic 0:02dd72d1d465 595 if test_id not in self.test_summary_ext[target][toolchain]:
borlanic 0:02dd72d1d465 596 self.test_summary_ext[target][toolchain][test_id] = []
borlanic 0:02dd72d1d465 597
borlanic 0:02dd72d1d465 598 append_test_result = detailed_test_results
borlanic 0:02dd72d1d465 599
borlanic 0:02dd72d1d465 600 # If waterfall and consolidate-waterfall options are enabled,
borlanic 0:02dd72d1d465 601 # only include the last test result in the report.
borlanic 0:02dd72d1d465 602 if self.opts_waterfall_test and self.opts_consolidate_waterfall_test:
borlanic 0:02dd72d1d465 603 append_test_result = {0: detailed_test_results[len(detailed_test_results) - 1]}
borlanic 0:02dd72d1d465 604
borlanic 0:02dd72d1d465 605 self.test_summary_ext[target][toolchain][test_id].append(append_test_result)
borlanic 0:02dd72d1d465 606
borlanic 0:02dd72d1d465 607 test_suite_properties['skipped'] = ', '.join(test_suite_properties['skipped'])
borlanic 0:02dd72d1d465 608 self.test_suite_properties_ext[target][toolchain] = test_suite_properties
borlanic 0:02dd72d1d465 609
borlanic 0:02dd72d1d465 610 q.put(target + '_'.join(toolchains))
borlanic 0:02dd72d1d465 611 return
borlanic 0:02dd72d1d465 612
borlanic 0:02dd72d1d465 613 def execute(self):
borlanic 0:02dd72d1d465 614 clean = self.test_spec.get('clean', False)
borlanic 0:02dd72d1d465 615 test_ids = self.test_spec.get('test_ids', [])
borlanic 0:02dd72d1d465 616 q = Queue()
borlanic 0:02dd72d1d465 617
borlanic 0:02dd72d1d465 618 # Generate seed for shuffle if seed is not provided in
borlanic 0:02dd72d1d465 619 self.shuffle_random_seed = round(random.random(), self.SHUFFLE_SEED_ROUND)
borlanic 0:02dd72d1d465 620 if self.opts_shuffle_test_seed is not None and self.is_shuffle_seed_float():
borlanic 0:02dd72d1d465 621 self.shuffle_random_seed = round(float(self.opts_shuffle_test_seed), self.SHUFFLE_SEED_ROUND)
borlanic 0:02dd72d1d465 622
borlanic 0:02dd72d1d465 623
borlanic 0:02dd72d1d465 624 if self.opts_parallel_test_exec:
borlanic 0:02dd72d1d465 625 ###################################################################
borlanic 0:02dd72d1d465 626 # Experimental, parallel test execution per singletest instance.
borlanic 0:02dd72d1d465 627 ###################################################################
borlanic 0:02dd72d1d465 628 execute_threads = [] # Threads used to build mbed SDL, libs, test cases and execute tests
borlanic 0:02dd72d1d465 629 # Note: We are building here in parallel for each target separately!
borlanic 0:02dd72d1d465 630 # So we are not building the same thing multiple times and compilers
borlanic 0:02dd72d1d465 631 # in separate threads do not collide.
borlanic 0:02dd72d1d465 632 # Inside execute_thread_slice() function function handle() will be called to
borlanic 0:02dd72d1d465 633 # get information about available MUTs (per target).
borlanic 0:02dd72d1d465 634 for target, toolchains in self.test_spec['targets'].items():
borlanic 0:02dd72d1d465 635 self.test_suite_properties_ext[target] = {}
borlanic 0:02dd72d1d465 636 t = threading.Thread(target=self.execute_thread_slice, args = (q, target, toolchains, clean, test_ids, self.build_report, self.build_properties))
borlanic 0:02dd72d1d465 637 t.daemon = True
borlanic 0:02dd72d1d465 638 t.start()
borlanic 0:02dd72d1d465 639 execute_threads.append(t)
borlanic 0:02dd72d1d465 640
borlanic 0:02dd72d1d465 641 for t in execute_threads:
borlanic 0:02dd72d1d465 642 q.get() # t.join() would block some threads because we should not wait in any order for thread end
borlanic 0:02dd72d1d465 643 else:
borlanic 0:02dd72d1d465 644 # Serialized (not parallel) test execution
borlanic 0:02dd72d1d465 645 for target, toolchains in self.test_spec['targets'].items():
borlanic 0:02dd72d1d465 646 if target not in self.test_suite_properties_ext:
borlanic 0:02dd72d1d465 647 self.test_suite_properties_ext[target] = {}
borlanic 0:02dd72d1d465 648
borlanic 0:02dd72d1d465 649 self.execute_thread_slice(q, target, toolchains, clean, test_ids, self.build_report, self.build_properties)
borlanic 0:02dd72d1d465 650 q.get()
borlanic 0:02dd72d1d465 651
borlanic 0:02dd72d1d465 652 if self.db_logger:
borlanic 0:02dd72d1d465 653 self.db_logger.reconnect();
borlanic 0:02dd72d1d465 654 if self.db_logger.is_connected():
borlanic 0:02dd72d1d465 655 self.db_logger.update_build_id_info(self.db_logger_build_id, _status_fk=self.db_logger.BUILD_ID_STATUS_COMPLETED)
borlanic 0:02dd72d1d465 656 self.db_logger.disconnect();
borlanic 0:02dd72d1d465 657
borlanic 0:02dd72d1d465 658 return self.test_summary, self.shuffle_random_seed, self.test_summary_ext, self.test_suite_properties_ext, self.build_report, self.build_properties
borlanic 0:02dd72d1d465 659
borlanic 0:02dd72d1d465 660 def get_valid_tests(self, test_map_keys, target, toolchain, test_ids, include_non_automated):
borlanic 0:02dd72d1d465 661 valid_test_map_keys = []
borlanic 0:02dd72d1d465 662
borlanic 0:02dd72d1d465 663 for test_id in test_map_keys:
borlanic 0:02dd72d1d465 664 test = TEST_MAP[test_id]
borlanic 0:02dd72d1d465 665 if self.opts_test_by_names and test_id not in self.opts_test_by_names:
borlanic 0:02dd72d1d465 666 continue
borlanic 0:02dd72d1d465 667
borlanic 0:02dd72d1d465 668 if test_ids and test_id not in test_ids:
borlanic 0:02dd72d1d465 669 continue
borlanic 0:02dd72d1d465 670
borlanic 0:02dd72d1d465 671 if self.opts_test_only_peripheral and not test.peripherals:
borlanic 0:02dd72d1d465 672 if self.opts_verbose_skipped_tests:
borlanic 0:02dd72d1d465 673 print(self.logger.log_line(
borlanic 0:02dd72d1d465 674 self.logger.LogType.INFO,
borlanic 0:02dd72d1d465 675 'Common test skipped for target %s' % target))
borlanic 0:02dd72d1d465 676 continue
borlanic 0:02dd72d1d465 677
borlanic 0:02dd72d1d465 678 if (self.opts_peripheral_by_names and test.peripherals and
borlanic 0:02dd72d1d465 679 not any((i in self.opts_peripheral_by_names)
borlanic 0:02dd72d1d465 680 for i in test.peripherals)):
borlanic 0:02dd72d1d465 681 # We will skip tests not forced with -p option
borlanic 0:02dd72d1d465 682 if self.opts_verbose_skipped_tests:
borlanic 0:02dd72d1d465 683 print(self.logger.log_line(
borlanic 0:02dd72d1d465 684 self.logger.LogType.INFO,
borlanic 0:02dd72d1d465 685 'Common test skipped for target %s' % target))
borlanic 0:02dd72d1d465 686 continue
borlanic 0:02dd72d1d465 687
borlanic 0:02dd72d1d465 688 if self.opts_test_only_common and test.peripherals:
borlanic 0:02dd72d1d465 689 if self.opts_verbose_skipped_tests:
borlanic 0:02dd72d1d465 690 print(self.logger.log_line(
borlanic 0:02dd72d1d465 691 self.logger.LogType.INFO,
borlanic 0:02dd72d1d465 692 'Peripheral test skipped for target %s' % target))
borlanic 0:02dd72d1d465 693 continue
borlanic 0:02dd72d1d465 694
borlanic 0:02dd72d1d465 695 if not include_non_automated and not test.automated:
borlanic 0:02dd72d1d465 696 if self.opts_verbose_skipped_tests:
borlanic 0:02dd72d1d465 697 print(self.logger.log_line(
borlanic 0:02dd72d1d465 698 self.logger.LogType.INFO,
borlanic 0:02dd72d1d465 699 'Non automated test skipped for target %s' % target))
borlanic 0:02dd72d1d465 700 continue
borlanic 0:02dd72d1d465 701
borlanic 0:02dd72d1d465 702 if test.is_supported(target, toolchain):
borlanic 0:02dd72d1d465 703 if test.peripherals is None and self.opts_only_build_tests:
borlanic 0:02dd72d1d465 704 # When users are using 'build only flag' and test do not have
borlanic 0:02dd72d1d465 705 # specified peripherals we can allow test building by default
borlanic 0:02dd72d1d465 706 pass
borlanic 0:02dd72d1d465 707 elif self.opts_peripheral_by_names and test_id not in self.opts_peripheral_by_names:
borlanic 0:02dd72d1d465 708 # If we force peripheral with option -p we expect test
borlanic 0:02dd72d1d465 709 # to pass even if peripheral is not in MUTs file.
borlanic 0:02dd72d1d465 710 pass
borlanic 0:02dd72d1d465 711 elif not self.is_peripherals_available(target, test.peripherals):
borlanic 0:02dd72d1d465 712 if self.opts_verbose_skipped_tests:
borlanic 0:02dd72d1d465 713 if test.peripherals:
borlanic 0:02dd72d1d465 714 print(self.logger.log_line(
borlanic 0:02dd72d1d465 715 self.logger.LogType.INFO,
borlanic 0:02dd72d1d465 716 'Peripheral %s test skipped for target %s' %
borlanic 0:02dd72d1d465 717 (",".join(test.peripherals), target)))
borlanic 0:02dd72d1d465 718 else:
borlanic 0:02dd72d1d465 719 print(self.logger.log_line(
borlanic 0:02dd72d1d465 720 self.logger.LogType.INFO,
borlanic 0:02dd72d1d465 721 'Test %s skipped for target %s' %
borlanic 0:02dd72d1d465 722 (test_id, target)))
borlanic 0:02dd72d1d465 723 continue
borlanic 0:02dd72d1d465 724
borlanic 0:02dd72d1d465 725 # The test has made it through all the filters, so add it to the valid tests list
borlanic 0:02dd72d1d465 726 valid_test_map_keys.append(test_id)
borlanic 0:02dd72d1d465 727
borlanic 0:02dd72d1d465 728 return valid_test_map_keys
borlanic 0:02dd72d1d465 729
borlanic 0:02dd72d1d465 730 def get_skipped_tests(self, all_test_map_keys, valid_test_map_keys):
borlanic 0:02dd72d1d465 731 # NOTE: This will not preserve order
borlanic 0:02dd72d1d465 732 return list(set(all_test_map_keys) - set(valid_test_map_keys))
borlanic 0:02dd72d1d465 733
borlanic 0:02dd72d1d465 734 def generate_test_summary_by_target(self, test_summary, shuffle_seed=None):
borlanic 0:02dd72d1d465 735 """ Prints well-formed summary with results (SQL table like)
borlanic 0:02dd72d1d465 736 table shows text x toolchain test result matrix
borlanic 0:02dd72d1d465 737 """
borlanic 0:02dd72d1d465 738 RESULT_INDEX = 0
borlanic 0:02dd72d1d465 739 TARGET_INDEX = 1
borlanic 0:02dd72d1d465 740 TOOLCHAIN_INDEX = 2
borlanic 0:02dd72d1d465 741 TEST_INDEX = 3
borlanic 0:02dd72d1d465 742 DESC_INDEX = 4
borlanic 0:02dd72d1d465 743
borlanic 0:02dd72d1d465 744 unique_targets = get_unique_value_from_summary(test_summary, TARGET_INDEX)
borlanic 0:02dd72d1d465 745 unique_tests = get_unique_value_from_summary(test_summary, TEST_INDEX)
borlanic 0:02dd72d1d465 746 unique_test_desc = get_unique_value_from_summary_ext(test_summary, TEST_INDEX, DESC_INDEX)
borlanic 0:02dd72d1d465 747 unique_toolchains = get_unique_value_from_summary(test_summary, TOOLCHAIN_INDEX)
borlanic 0:02dd72d1d465 748
borlanic 0:02dd72d1d465 749 result = "Test summary:\n"
borlanic 0:02dd72d1d465 750 for target in unique_targets:
borlanic 0:02dd72d1d465 751 result_dict = {} # test : { toolchain : result }
borlanic 0:02dd72d1d465 752 unique_target_toolchains = []
borlanic 0:02dd72d1d465 753 for test in test_summary:
borlanic 0:02dd72d1d465 754 if test[TARGET_INDEX] == target:
borlanic 0:02dd72d1d465 755 if test[TOOLCHAIN_INDEX] not in unique_target_toolchains:
borlanic 0:02dd72d1d465 756 unique_target_toolchains.append(test[TOOLCHAIN_INDEX])
borlanic 0:02dd72d1d465 757 if test[TEST_INDEX] not in result_dict:
borlanic 0:02dd72d1d465 758 result_dict[test[TEST_INDEX]] = {}
borlanic 0:02dd72d1d465 759 result_dict[test[TEST_INDEX]][test[TOOLCHAIN_INDEX]] = test[RESULT_INDEX]
borlanic 0:02dd72d1d465 760
borlanic 0:02dd72d1d465 761 pt_cols = ["Target", "Test ID", "Test Description"] + unique_target_toolchains
borlanic 0:02dd72d1d465 762 pt = PrettyTable(pt_cols)
borlanic 0:02dd72d1d465 763 for col in pt_cols:
borlanic 0:02dd72d1d465 764 pt.align[col] = "l"
borlanic 0:02dd72d1d465 765 pt.padding_width = 1 # One space between column edges and contents (default)
borlanic 0:02dd72d1d465 766
borlanic 0:02dd72d1d465 767 for test in unique_tests:
borlanic 0:02dd72d1d465 768 if test in result_dict:
borlanic 0:02dd72d1d465 769 test_results = result_dict[test]
borlanic 0:02dd72d1d465 770 if test in unique_test_desc:
borlanic 0:02dd72d1d465 771 row = [target, test, unique_test_desc[test]]
borlanic 0:02dd72d1d465 772 for toolchain in unique_toolchains:
borlanic 0:02dd72d1d465 773 if toolchain in test_results:
borlanic 0:02dd72d1d465 774 row.append(test_results[toolchain])
borlanic 0:02dd72d1d465 775 pt.add_row(row)
borlanic 0:02dd72d1d465 776 result += pt.get_string()
borlanic 0:02dd72d1d465 777 shuffle_seed_text = "Shuffle Seed: %.*f"% (self.SHUFFLE_SEED_ROUND,
borlanic 0:02dd72d1d465 778 shuffle_seed if shuffle_seed else self.shuffle_random_seed)
borlanic 0:02dd72d1d465 779 result += "\n%s"% (shuffle_seed_text if self.opts_shuffle_test_order else '')
borlanic 0:02dd72d1d465 780 return result
borlanic 0:02dd72d1d465 781
borlanic 0:02dd72d1d465 782 def generate_test_summary(self, test_summary, shuffle_seed=None):
borlanic 0:02dd72d1d465 783 """ Prints well-formed summary with results (SQL table like)
borlanic 0:02dd72d1d465 784 table shows target x test results matrix across
borlanic 0:02dd72d1d465 785 """
borlanic 0:02dd72d1d465 786 success_code = 0 # Success code that can be leter returned to
borlanic 0:02dd72d1d465 787 result = "Test summary:\n"
borlanic 0:02dd72d1d465 788 # Pretty table package is used to print results
borlanic 0:02dd72d1d465 789 pt = PrettyTable(["Result", "Target", "Toolchain", "Test ID", "Test Description",
borlanic 0:02dd72d1d465 790 "Elapsed Time (sec)", "Timeout (sec)", "Loops"])
borlanic 0:02dd72d1d465 791 pt.align["Result"] = "l" # Left align
borlanic 0:02dd72d1d465 792 pt.align["Target"] = "l" # Left align
borlanic 0:02dd72d1d465 793 pt.align["Toolchain"] = "l" # Left align
borlanic 0:02dd72d1d465 794 pt.align["Test ID"] = "l" # Left align
borlanic 0:02dd72d1d465 795 pt.align["Test Description"] = "l" # Left align
borlanic 0:02dd72d1d465 796 pt.padding_width = 1 # One space between column edges and contents (default)
borlanic 0:02dd72d1d465 797
borlanic 0:02dd72d1d465 798 result_dict = {self.TEST_RESULT_OK : 0,
borlanic 0:02dd72d1d465 799 self.TEST_RESULT_FAIL : 0,
borlanic 0:02dd72d1d465 800 self.TEST_RESULT_ERROR : 0,
borlanic 0:02dd72d1d465 801 self.TEST_RESULT_UNDEF : 0,
borlanic 0:02dd72d1d465 802 self.TEST_RESULT_IOERR_COPY : 0,
borlanic 0:02dd72d1d465 803 self.TEST_RESULT_IOERR_DISK : 0,
borlanic 0:02dd72d1d465 804 self.TEST_RESULT_IOERR_SERIAL : 0,
borlanic 0:02dd72d1d465 805 self.TEST_RESULT_NO_IMAGE : 0,
borlanic 0:02dd72d1d465 806 self.TEST_RESULT_TIMEOUT : 0,
borlanic 0:02dd72d1d465 807 self.TEST_RESULT_MBED_ASSERT : 0,
borlanic 0:02dd72d1d465 808 self.TEST_RESULT_BUILD_FAILED : 0,
borlanic 0:02dd72d1d465 809 self.TEST_RESULT_NOT_SUPPORTED : 0
borlanic 0:02dd72d1d465 810 }
borlanic 0:02dd72d1d465 811
borlanic 0:02dd72d1d465 812 for test in test_summary:
borlanic 0:02dd72d1d465 813 if test[0] in result_dict:
borlanic 0:02dd72d1d465 814 result_dict[test[0]] += 1
borlanic 0:02dd72d1d465 815 pt.add_row(test)
borlanic 0:02dd72d1d465 816 result += pt.get_string()
borlanic 0:02dd72d1d465 817 result += "\n"
borlanic 0:02dd72d1d465 818
borlanic 0:02dd72d1d465 819 # Print result count
borlanic 0:02dd72d1d465 820 result += "Result: " + ' / '.join(['%s %s' % (value, key) for (key, value) in {k: v for k, v in result_dict.items() if v != 0}.items()])
borlanic 0:02dd72d1d465 821 shuffle_seed_text = "Shuffle Seed: %.*f\n"% (self.SHUFFLE_SEED_ROUND,
borlanic 0:02dd72d1d465 822 shuffle_seed if shuffle_seed else self.shuffle_random_seed)
borlanic 0:02dd72d1d465 823 result += "\n%s"% (shuffle_seed_text if self.opts_shuffle_test_order else '')
borlanic 0:02dd72d1d465 824 return result
borlanic 0:02dd72d1d465 825
borlanic 0:02dd72d1d465 826 def test_loop_list_to_dict(self, test_loops_str):
borlanic 0:02dd72d1d465 827 """ Transforms test_id=X,test_id=X,test_id=X into dictionary {test_id : test_id_loops_count}
borlanic 0:02dd72d1d465 828 """
borlanic 0:02dd72d1d465 829 result = {}
borlanic 0:02dd72d1d465 830 if test_loops_str:
borlanic 0:02dd72d1d465 831 test_loops = test_loops_str
borlanic 0:02dd72d1d465 832 for test_loop in test_loops:
borlanic 0:02dd72d1d465 833 test_loop_count = test_loop.split('=')
borlanic 0:02dd72d1d465 834 if len(test_loop_count) == 2:
borlanic 0:02dd72d1d465 835 _test_id, _test_loops = test_loop_count
borlanic 0:02dd72d1d465 836 try:
borlanic 0:02dd72d1d465 837 _test_loops = int(_test_loops)
borlanic 0:02dd72d1d465 838 except:
borlanic 0:02dd72d1d465 839 continue
borlanic 0:02dd72d1d465 840 result[_test_id] = _test_loops
borlanic 0:02dd72d1d465 841 return result
borlanic 0:02dd72d1d465 842
borlanic 0:02dd72d1d465 843 def get_test_loop_count(self, test_id):
borlanic 0:02dd72d1d465 844 """ This function returns no. of loops per test (deducted by test_id_.
borlanic 0:02dd72d1d465 845 If test is not in list of redefined loop counts it will use default value.
borlanic 0:02dd72d1d465 846 """
borlanic 0:02dd72d1d465 847 result = self.GLOBAL_LOOPS_COUNT
borlanic 0:02dd72d1d465 848 if test_id in self.TEST_LOOPS_DICT:
borlanic 0:02dd72d1d465 849 result = self.TEST_LOOPS_DICT[test_id]
borlanic 0:02dd72d1d465 850 return result
borlanic 0:02dd72d1d465 851
borlanic 0:02dd72d1d465 852 def delete_file(self, file_path):
borlanic 0:02dd72d1d465 853 """ Remove file from the system
borlanic 0:02dd72d1d465 854 """
borlanic 0:02dd72d1d465 855 result = True
borlanic 0:02dd72d1d465 856 resutl_msg = ""
borlanic 0:02dd72d1d465 857 try:
borlanic 0:02dd72d1d465 858 os.remove(file_path)
borlanic 0:02dd72d1d465 859 except Exception as e:
borlanic 0:02dd72d1d465 860 resutl_msg = e
borlanic 0:02dd72d1d465 861 result = False
borlanic 0:02dd72d1d465 862 return result, resutl_msg
borlanic 0:02dd72d1d465 863
borlanic 0:02dd72d1d465 864 def handle_mut(self, mut, data, target_name, toolchain_name, test_loops=1):
borlanic 0:02dd72d1d465 865 """ Test is being invoked for given MUT.
borlanic 0:02dd72d1d465 866 """
borlanic 0:02dd72d1d465 867 # Get test information, image and test timeout
borlanic 0:02dd72d1d465 868 test_id = data['test_id']
borlanic 0:02dd72d1d465 869 test = TEST_MAP[test_id]
borlanic 0:02dd72d1d465 870 test_description = TEST_MAP[test_id].get_description()
borlanic 0:02dd72d1d465 871 image = data["image"]
borlanic 0:02dd72d1d465 872 duration = data.get("duration", 10)
borlanic 0:02dd72d1d465 873
borlanic 0:02dd72d1d465 874 if mut is None:
borlanic 0:02dd72d1d465 875 print("Error: No Mbed available: MUT[%s]" % data['mcu'])
borlanic 0:02dd72d1d465 876 return None
borlanic 0:02dd72d1d465 877
borlanic 0:02dd72d1d465 878 mcu = mut['mcu']
borlanic 0:02dd72d1d465 879 copy_method = mut.get('copy_method') # Available board configuration selection e.g. core selection etc.
borlanic 0:02dd72d1d465 880
borlanic 0:02dd72d1d465 881 if self.db_logger:
borlanic 0:02dd72d1d465 882 self.db_logger.reconnect()
borlanic 0:02dd72d1d465 883
borlanic 0:02dd72d1d465 884 selected_copy_method = self.opts_copy_method if copy_method is None else copy_method
borlanic 0:02dd72d1d465 885
borlanic 0:02dd72d1d465 886 # Tests can be looped so test results must be stored for the same test
borlanic 0:02dd72d1d465 887 test_all_result = []
borlanic 0:02dd72d1d465 888 # Test results for one test ran few times
borlanic 0:02dd72d1d465 889 detailed_test_results = {} # { Loop_number: { results ... } }
borlanic 0:02dd72d1d465 890
borlanic 0:02dd72d1d465 891 for test_index in range(test_loops):
borlanic 0:02dd72d1d465 892
borlanic 0:02dd72d1d465 893 # If mbedls is available and we are auto detecting MUT info,
borlanic 0:02dd72d1d465 894 # update MUT info (mounting may changed)
borlanic 0:02dd72d1d465 895 if get_module_avail('mbed_lstools') and self.opts_auto_detect:
borlanic 0:02dd72d1d465 896 platform_name_filter = [mcu]
borlanic 0:02dd72d1d465 897 muts_list = {}
borlanic 0:02dd72d1d465 898 found = False
borlanic 0:02dd72d1d465 899
borlanic 0:02dd72d1d465 900 for i in range(0, 60):
borlanic 0:02dd72d1d465 901 print('Looking for %s with MBEDLS' % mcu)
borlanic 0:02dd72d1d465 902 muts_list = get_autodetected_MUTS_list(platform_name_filter=platform_name_filter)
borlanic 0:02dd72d1d465 903
borlanic 0:02dd72d1d465 904 if 1 not in muts_list:
borlanic 0:02dd72d1d465 905 sleep(3)
borlanic 0:02dd72d1d465 906 else:
borlanic 0:02dd72d1d465 907 found = True
borlanic 0:02dd72d1d465 908 break
borlanic 0:02dd72d1d465 909
borlanic 0:02dd72d1d465 910 if not found:
borlanic 0:02dd72d1d465 911 print("Error: mbed not found with MBEDLS: %s" % data['mcu'])
borlanic 0:02dd72d1d465 912 return None
borlanic 0:02dd72d1d465 913 else:
borlanic 0:02dd72d1d465 914 mut = muts_list[1]
borlanic 0:02dd72d1d465 915
borlanic 0:02dd72d1d465 916 disk = mut.get('disk')
borlanic 0:02dd72d1d465 917 port = mut.get('port')
borlanic 0:02dd72d1d465 918
borlanic 0:02dd72d1d465 919 if disk is None or port is None:
borlanic 0:02dd72d1d465 920 return None
borlanic 0:02dd72d1d465 921
borlanic 0:02dd72d1d465 922 target_by_mcu = TARGET_MAP[mut['mcu']]
borlanic 0:02dd72d1d465 923 target_name_unique = mut['mcu_unique'] if 'mcu_unique' in mut else mut['mcu']
borlanic 0:02dd72d1d465 924 # Some extra stuff can be declared in MUTs structure
borlanic 0:02dd72d1d465 925 reset_type = mut.get('reset_type') # reboot.txt, reset.txt, shutdown.txt
borlanic 0:02dd72d1d465 926 reset_tout = mut.get('reset_tout') # COPY_IMAGE -> RESET_PROC -> SLEEP(RESET_TOUT)
borlanic 0:02dd72d1d465 927
borlanic 0:02dd72d1d465 928 # When the build and test system were separate, this was relative to a
borlanic 0:02dd72d1d465 929 # base network folder base path: join(NETWORK_BASE_PATH, )
borlanic 0:02dd72d1d465 930 image_path = image
borlanic 0:02dd72d1d465 931
borlanic 0:02dd72d1d465 932 # Host test execution
borlanic 0:02dd72d1d465 933 start_host_exec_time = time()
borlanic 0:02dd72d1d465 934
borlanic 0:02dd72d1d465 935 single_test_result = self.TEST_RESULT_UNDEF # single test run result
borlanic 0:02dd72d1d465 936 _copy_method = selected_copy_method
borlanic 0:02dd72d1d465 937
borlanic 0:02dd72d1d465 938 if not exists(image_path):
borlanic 0:02dd72d1d465 939 single_test_result = self.TEST_RESULT_NO_IMAGE
borlanic 0:02dd72d1d465 940 elapsed_time = 0
borlanic 0:02dd72d1d465 941 single_test_output = self.logger.log_line(self.logger.LogType.ERROR, 'Image file does not exist: %s'% image_path)
borlanic 0:02dd72d1d465 942 print(single_test_output)
borlanic 0:02dd72d1d465 943 else:
borlanic 0:02dd72d1d465 944 # Host test execution
borlanic 0:02dd72d1d465 945 start_host_exec_time = time()
borlanic 0:02dd72d1d465 946
borlanic 0:02dd72d1d465 947 host_test_verbose = self.opts_verbose_test_result_only or self.opts_verbose
borlanic 0:02dd72d1d465 948 host_test_reset = self.opts_mut_reset_type if reset_type is None else reset_type
borlanic 0:02dd72d1d465 949 host_test_result = self.run_host_test(test.host_test,
borlanic 0:02dd72d1d465 950 image_path, disk, port, duration,
borlanic 0:02dd72d1d465 951 micro=target_name,
borlanic 0:02dd72d1d465 952 verbose=host_test_verbose,
borlanic 0:02dd72d1d465 953 reset=host_test_reset,
borlanic 0:02dd72d1d465 954 reset_tout=reset_tout,
borlanic 0:02dd72d1d465 955 copy_method=selected_copy_method,
borlanic 0:02dd72d1d465 956 program_cycle_s=target_by_mcu.program_cycle_s)
borlanic 0:02dd72d1d465 957 single_test_result, single_test_output, single_testduration, single_timeout = host_test_result
borlanic 0:02dd72d1d465 958
borlanic 0:02dd72d1d465 959 # Store test result
borlanic 0:02dd72d1d465 960 test_all_result.append(single_test_result)
borlanic 0:02dd72d1d465 961 total_elapsed_time = time() - start_host_exec_time # Test time with copy (flashing) / reset
borlanic 0:02dd72d1d465 962 elapsed_time = single_testduration # TIme of single test case execution after reset
borlanic 0:02dd72d1d465 963
borlanic 0:02dd72d1d465 964 detailed_test_results[test_index] = {
borlanic 0:02dd72d1d465 965 'result' : single_test_result,
borlanic 0:02dd72d1d465 966 'output' : single_test_output,
borlanic 0:02dd72d1d465 967 'target_name' : target_name,
borlanic 0:02dd72d1d465 968 'target_name_unique' : target_name_unique,
borlanic 0:02dd72d1d465 969 'toolchain_name' : toolchain_name,
borlanic 0:02dd72d1d465 970 'id' : test_id,
borlanic 0:02dd72d1d465 971 'description' : test_description,
borlanic 0:02dd72d1d465 972 'elapsed_time' : round(elapsed_time, 2),
borlanic 0:02dd72d1d465 973 'duration' : single_timeout,
borlanic 0:02dd72d1d465 974 'copy_method' : _copy_method,
borlanic 0:02dd72d1d465 975 }
borlanic 0:02dd72d1d465 976
borlanic 0:02dd72d1d465 977 print(self.print_test_result(
borlanic 0:02dd72d1d465 978 single_test_result, target_name_unique, toolchain_name, test_id,
borlanic 0:02dd72d1d465 979 test_description, elapsed_time, single_timeout))
borlanic 0:02dd72d1d465 980
borlanic 0:02dd72d1d465 981 # Update database entries for ongoing test
borlanic 0:02dd72d1d465 982 if self.db_logger and self.db_logger.is_connected():
borlanic 0:02dd72d1d465 983 test_type = 'SingleTest'
borlanic 0:02dd72d1d465 984 self.db_logger.insert_test_entry(self.db_logger_build_id,
borlanic 0:02dd72d1d465 985 target_name,
borlanic 0:02dd72d1d465 986 toolchain_name,
borlanic 0:02dd72d1d465 987 test_type,
borlanic 0:02dd72d1d465 988 test_id,
borlanic 0:02dd72d1d465 989 single_test_result,
borlanic 0:02dd72d1d465 990 single_test_output,
borlanic 0:02dd72d1d465 991 elapsed_time,
borlanic 0:02dd72d1d465 992 single_timeout,
borlanic 0:02dd72d1d465 993 test_index)
borlanic 0:02dd72d1d465 994
borlanic 0:02dd72d1d465 995 # If we perform waterfall test we test until we get OK and we stop testing
borlanic 0:02dd72d1d465 996 if self.opts_waterfall_test and single_test_result == self.TEST_RESULT_OK:
borlanic 0:02dd72d1d465 997 break
borlanic 0:02dd72d1d465 998
borlanic 0:02dd72d1d465 999 if self.db_logger:
borlanic 0:02dd72d1d465 1000 self.db_logger.disconnect()
borlanic 0:02dd72d1d465 1001
borlanic 0:02dd72d1d465 1002 return (self.shape_global_test_loop_result(test_all_result, self.opts_waterfall_test and self.opts_consolidate_waterfall_test),
borlanic 0:02dd72d1d465 1003 target_name_unique,
borlanic 0:02dd72d1d465 1004 toolchain_name,
borlanic 0:02dd72d1d465 1005 test_id,
borlanic 0:02dd72d1d465 1006 test_description,
borlanic 0:02dd72d1d465 1007 round(elapsed_time, 2),
borlanic 0:02dd72d1d465 1008 single_timeout,
borlanic 0:02dd72d1d465 1009 self.shape_test_loop_ok_result_count(test_all_result)), detailed_test_results
borlanic 0:02dd72d1d465 1010
borlanic 0:02dd72d1d465 1011 def handle(self, test_spec, target_name, toolchain_name, test_loops=1):
borlanic 0:02dd72d1d465 1012 """ Function determines MUT's mbed disk/port and copies binary to
borlanic 0:02dd72d1d465 1013 target.
borlanic 0:02dd72d1d465 1014 """
borlanic 0:02dd72d1d465 1015 handle_results = []
borlanic 0:02dd72d1d465 1016 data = json.loads(test_spec)
borlanic 0:02dd72d1d465 1017
borlanic 0:02dd72d1d465 1018 # Find a suitable MUT:
borlanic 0:02dd72d1d465 1019 mut = None
borlanic 0:02dd72d1d465 1020 for id, m in self.muts.items():
borlanic 0:02dd72d1d465 1021 if m['mcu'] == data['mcu']:
borlanic 0:02dd72d1d465 1022 mut = m
borlanic 0:02dd72d1d465 1023 handle_result = self.handle_mut(mut, data, target_name, toolchain_name, test_loops=test_loops)
borlanic 0:02dd72d1d465 1024 handle_results.append(handle_result)
borlanic 0:02dd72d1d465 1025
borlanic 0:02dd72d1d465 1026 return handle_results
borlanic 0:02dd72d1d465 1027
borlanic 0:02dd72d1d465 1028 def print_test_result(self, test_result, target_name, toolchain_name,
borlanic 0:02dd72d1d465 1029 test_id, test_description, elapsed_time, duration):
borlanic 0:02dd72d1d465 1030 """ Use specific convention to print test result and related data
borlanic 0:02dd72d1d465 1031 """
borlanic 0:02dd72d1d465 1032 tokens = []
borlanic 0:02dd72d1d465 1033 tokens.append("TargetTest")
borlanic 0:02dd72d1d465 1034 tokens.append(target_name)
borlanic 0:02dd72d1d465 1035 tokens.append(toolchain_name)
borlanic 0:02dd72d1d465 1036 tokens.append(test_id)
borlanic 0:02dd72d1d465 1037 tokens.append(test_description)
borlanic 0:02dd72d1d465 1038 separator = "::"
borlanic 0:02dd72d1d465 1039 time_info = " in %.2f of %d sec" % (round(elapsed_time, 2), duration)
borlanic 0:02dd72d1d465 1040 result = separator.join(tokens) + " [" + test_result +"]" + time_info
borlanic 0:02dd72d1d465 1041 return Fore.MAGENTA + result + Fore.RESET
borlanic 0:02dd72d1d465 1042
borlanic 0:02dd72d1d465 1043 def shape_test_loop_ok_result_count(self, test_all_result):
borlanic 0:02dd72d1d465 1044 """ Reformats list of results to simple string
borlanic 0:02dd72d1d465 1045 """
borlanic 0:02dd72d1d465 1046 test_loop_count = len(test_all_result)
borlanic 0:02dd72d1d465 1047 test_loop_ok_result = test_all_result.count(self.TEST_RESULT_OK)
borlanic 0:02dd72d1d465 1048 return "%d/%d"% (test_loop_ok_result, test_loop_count)
borlanic 0:02dd72d1d465 1049
borlanic 0:02dd72d1d465 1050 def shape_global_test_loop_result(self, test_all_result, waterfall_and_consolidate):
borlanic 0:02dd72d1d465 1051 """ Reformats list of results to simple string
borlanic 0:02dd72d1d465 1052 """
borlanic 0:02dd72d1d465 1053 result = self.TEST_RESULT_FAIL
borlanic 0:02dd72d1d465 1054
borlanic 0:02dd72d1d465 1055 if all(test_all_result[0] == res for res in test_all_result):
borlanic 0:02dd72d1d465 1056 result = test_all_result[0]
borlanic 0:02dd72d1d465 1057 elif waterfall_and_consolidate and any(res == self.TEST_RESULT_OK for res in test_all_result):
borlanic 0:02dd72d1d465 1058 result = self.TEST_RESULT_OK
borlanic 0:02dd72d1d465 1059
borlanic 0:02dd72d1d465 1060 return result
borlanic 0:02dd72d1d465 1061
borlanic 0:02dd72d1d465 1062 def run_host_test(self, name, image_path, disk, port, duration,
borlanic 0:02dd72d1d465 1063 micro=None, reset=None, reset_tout=None,
borlanic 0:02dd72d1d465 1064 verbose=False, copy_method=None, program_cycle_s=None):
borlanic 0:02dd72d1d465 1065 """ Function creates new process with host test configured with particular test case.
borlanic 0:02dd72d1d465 1066 Function also is pooling for serial port activity from process to catch all data
borlanic 0:02dd72d1d465 1067 printed by test runner and host test during test execution
borlanic 0:02dd72d1d465 1068 """
borlanic 0:02dd72d1d465 1069
borlanic 0:02dd72d1d465 1070 def get_char_from_queue(obs):
borlanic 0:02dd72d1d465 1071 """ Get character from queue safe way
borlanic 0:02dd72d1d465 1072 """
borlanic 0:02dd72d1d465 1073 try:
borlanic 0:02dd72d1d465 1074 c = obs.queue.get(block=True, timeout=0.5)
borlanic 0:02dd72d1d465 1075 except Empty:
borlanic 0:02dd72d1d465 1076 c = None
borlanic 0:02dd72d1d465 1077 return c
borlanic 0:02dd72d1d465 1078
borlanic 0:02dd72d1d465 1079 def filter_queue_char(c):
borlanic 0:02dd72d1d465 1080 """ Filters out non ASCII characters from serial port
borlanic 0:02dd72d1d465 1081 """
borlanic 0:02dd72d1d465 1082 if ord(c) not in range(128):
borlanic 0:02dd72d1d465 1083 c = ' '
borlanic 0:02dd72d1d465 1084 return c
borlanic 0:02dd72d1d465 1085
borlanic 0:02dd72d1d465 1086 def get_test_result(output):
borlanic 0:02dd72d1d465 1087 """ Parse test 'output' data
borlanic 0:02dd72d1d465 1088 """
borlanic 0:02dd72d1d465 1089 result = self.TEST_RESULT_TIMEOUT
borlanic 0:02dd72d1d465 1090 for line in "".join(output).splitlines():
borlanic 0:02dd72d1d465 1091 search_result = self.RE_DETECT_TESTCASE_RESULT.search(line)
borlanic 0:02dd72d1d465 1092 if search_result and len(search_result.groups()):
borlanic 0:02dd72d1d465 1093 result = self.TEST_RESULT_MAPPING[search_result.groups(0)[0]]
borlanic 0:02dd72d1d465 1094 break
borlanic 0:02dd72d1d465 1095 return result
borlanic 0:02dd72d1d465 1096
borlanic 0:02dd72d1d465 1097 def get_auto_property_value(property_name, line):
borlanic 0:02dd72d1d465 1098 """ Scans auto detection line from MUT and returns scanned parameter 'property_name'
borlanic 0:02dd72d1d465 1099 Returns string
borlanic 0:02dd72d1d465 1100 """
borlanic 0:02dd72d1d465 1101 result = None
borlanic 0:02dd72d1d465 1102 if re.search("HOST: Property '%s'"% property_name, line) is not None:
borlanic 0:02dd72d1d465 1103 property = re.search("HOST: Property '%s' = '([\w\d _]+)'"% property_name, line)
borlanic 0:02dd72d1d465 1104 if property is not None and len(property.groups()) == 1:
borlanic 0:02dd72d1d465 1105 result = property.groups()[0]
borlanic 0:02dd72d1d465 1106 return result
borlanic 0:02dd72d1d465 1107
borlanic 0:02dd72d1d465 1108 cmd = ["python",
borlanic 0:02dd72d1d465 1109 '%s.py'% name,
borlanic 0:02dd72d1d465 1110 '-d', disk,
borlanic 0:02dd72d1d465 1111 '-f', '"%s"'% image_path,
borlanic 0:02dd72d1d465 1112 '-p', port,
borlanic 0:02dd72d1d465 1113 '-t', str(duration),
borlanic 0:02dd72d1d465 1114 '-C', str(program_cycle_s)]
borlanic 0:02dd72d1d465 1115
borlanic 0:02dd72d1d465 1116 if get_module_avail('mbed_lstools') and self.opts_auto_detect:
borlanic 0:02dd72d1d465 1117 cmd += ['--auto']
borlanic 0:02dd72d1d465 1118
borlanic 0:02dd72d1d465 1119 # Add extra parameters to host_test
borlanic 0:02dd72d1d465 1120 if copy_method is not None:
borlanic 0:02dd72d1d465 1121 cmd += ["-c", copy_method]
borlanic 0:02dd72d1d465 1122 if micro is not None:
borlanic 0:02dd72d1d465 1123 cmd += ["-m", micro]
borlanic 0:02dd72d1d465 1124 if reset is not None:
borlanic 0:02dd72d1d465 1125 cmd += ["-r", reset]
borlanic 0:02dd72d1d465 1126 if reset_tout is not None:
borlanic 0:02dd72d1d465 1127 cmd += ["-R", str(reset_tout)]
borlanic 0:02dd72d1d465 1128
borlanic 0:02dd72d1d465 1129 if verbose:
borlanic 0:02dd72d1d465 1130 print(Fore.MAGENTA + "Executing '" + " ".join(cmd) + "'" + Fore.RESET)
borlanic 0:02dd72d1d465 1131 print("Test::Output::Start")
borlanic 0:02dd72d1d465 1132
borlanic 0:02dd72d1d465 1133 proc = Popen(cmd, stdout=PIPE, cwd=HOST_TESTS)
borlanic 0:02dd72d1d465 1134 obs = ProcessObserver(proc)
borlanic 0:02dd72d1d465 1135 update_once_flag = {} # Stores flags checking if some auto-parameter was already set
borlanic 0:02dd72d1d465 1136 line = ''
borlanic 0:02dd72d1d465 1137 output = []
borlanic 0:02dd72d1d465 1138 start_time = time()
borlanic 0:02dd72d1d465 1139 while (time() - start_time) < (2 * duration):
borlanic 0:02dd72d1d465 1140 c = get_char_from_queue(obs)
borlanic 0:02dd72d1d465 1141 if c:
borlanic 0:02dd72d1d465 1142 if verbose:
borlanic 0:02dd72d1d465 1143 sys.stdout.write(c)
borlanic 0:02dd72d1d465 1144 c = filter_queue_char(c)
borlanic 0:02dd72d1d465 1145 output.append(c)
borlanic 0:02dd72d1d465 1146 # Give the mbed under test a way to communicate the end of the test
borlanic 0:02dd72d1d465 1147 if c in ['\n', '\r']:
borlanic 0:02dd72d1d465 1148
borlanic 0:02dd72d1d465 1149 # Checking for auto-detection information from the test about MUT reset moment
borlanic 0:02dd72d1d465 1150 if 'reset_target' not in update_once_flag and "HOST: Reset target..." in line:
borlanic 0:02dd72d1d465 1151 # We will update this marker only once to prevent multiple time resets
borlanic 0:02dd72d1d465 1152 update_once_flag['reset_target'] = True
borlanic 0:02dd72d1d465 1153 start_time = time()
borlanic 0:02dd72d1d465 1154
borlanic 0:02dd72d1d465 1155 # Checking for auto-detection information from the test about timeout
borlanic 0:02dd72d1d465 1156 auto_timeout_val = get_auto_property_value('timeout', line)
borlanic 0:02dd72d1d465 1157 if 'timeout' not in update_once_flag and auto_timeout_val is not None:
borlanic 0:02dd72d1d465 1158 # We will update this marker only once to prevent multiple time resets
borlanic 0:02dd72d1d465 1159 update_once_flag['timeout'] = True
borlanic 0:02dd72d1d465 1160 duration = int(auto_timeout_val)
borlanic 0:02dd72d1d465 1161
borlanic 0:02dd72d1d465 1162 # Detect mbed assert:
borlanic 0:02dd72d1d465 1163 if 'mbed assertation failed: ' in line:
borlanic 0:02dd72d1d465 1164 output.append('{{mbed_assert}}')
borlanic 0:02dd72d1d465 1165 break
borlanic 0:02dd72d1d465 1166
borlanic 0:02dd72d1d465 1167 # Check for test end
borlanic 0:02dd72d1d465 1168 if '{end}' in line:
borlanic 0:02dd72d1d465 1169 break
borlanic 0:02dd72d1d465 1170 line = ''
borlanic 0:02dd72d1d465 1171 else:
borlanic 0:02dd72d1d465 1172 line += c
borlanic 0:02dd72d1d465 1173 end_time = time()
borlanic 0:02dd72d1d465 1174 testcase_duration = end_time - start_time # Test case duration from reset to {end}
borlanic 0:02dd72d1d465 1175
borlanic 0:02dd72d1d465 1176 c = get_char_from_queue(obs)
borlanic 0:02dd72d1d465 1177
borlanic 0:02dd72d1d465 1178 if c:
borlanic 0:02dd72d1d465 1179 if verbose:
borlanic 0:02dd72d1d465 1180 sys.stdout.write(c)
borlanic 0:02dd72d1d465 1181 c = filter_queue_char(c)
borlanic 0:02dd72d1d465 1182 output.append(c)
borlanic 0:02dd72d1d465 1183
borlanic 0:02dd72d1d465 1184 if verbose:
borlanic 0:02dd72d1d465 1185 print("Test::Output::Finish")
borlanic 0:02dd72d1d465 1186 # Stop test process
borlanic 0:02dd72d1d465 1187 obs.stop()
borlanic 0:02dd72d1d465 1188
borlanic 0:02dd72d1d465 1189 result = get_test_result(output)
borlanic 0:02dd72d1d465 1190 return (result, "".join(output), testcase_duration, duration)
borlanic 0:02dd72d1d465 1191
borlanic 0:02dd72d1d465 1192 def is_peripherals_available(self, target_mcu_name, peripherals=None):
borlanic 0:02dd72d1d465 1193 """ Checks if specified target should run specific peripheral test case defined in MUTs file
borlanic 0:02dd72d1d465 1194 """
borlanic 0:02dd72d1d465 1195 if peripherals is not None:
borlanic 0:02dd72d1d465 1196 peripherals = set(peripherals)
borlanic 0:02dd72d1d465 1197 for id, mut in self.muts.items():
borlanic 0:02dd72d1d465 1198 # Target MCU name check
borlanic 0:02dd72d1d465 1199 if mut["mcu"] != target_mcu_name:
borlanic 0:02dd72d1d465 1200 continue
borlanic 0:02dd72d1d465 1201 # Peripherals check
borlanic 0:02dd72d1d465 1202 if peripherals is not None:
borlanic 0:02dd72d1d465 1203 if 'peripherals' not in mut:
borlanic 0:02dd72d1d465 1204 continue
borlanic 0:02dd72d1d465 1205 if not peripherals.issubset(set(mut['peripherals'])):
borlanic 0:02dd72d1d465 1206 continue
borlanic 0:02dd72d1d465 1207 return True
borlanic 0:02dd72d1d465 1208 return False
borlanic 0:02dd72d1d465 1209
borlanic 0:02dd72d1d465 1210 def shape_test_request(self, mcu, image_path, test_id, duration=10):
borlanic 0:02dd72d1d465 1211 """ Function prepares JSON structure describing test specification
borlanic 0:02dd72d1d465 1212 """
borlanic 0:02dd72d1d465 1213 test_spec = {
borlanic 0:02dd72d1d465 1214 "mcu": mcu,
borlanic 0:02dd72d1d465 1215 "image": image_path,
borlanic 0:02dd72d1d465 1216 "duration": duration,
borlanic 0:02dd72d1d465 1217 "test_id": test_id,
borlanic 0:02dd72d1d465 1218 }
borlanic 0:02dd72d1d465 1219 return json.dumps(test_spec)
borlanic 0:02dd72d1d465 1220
borlanic 0:02dd72d1d465 1221
borlanic 0:02dd72d1d465 1222 def get_unique_value_from_summary(test_summary, index):
borlanic 0:02dd72d1d465 1223 """ Gets list of unique target names
borlanic 0:02dd72d1d465 1224 """
borlanic 0:02dd72d1d465 1225 result = []
borlanic 0:02dd72d1d465 1226 for test in test_summary:
borlanic 0:02dd72d1d465 1227 target_name = test[index]
borlanic 0:02dd72d1d465 1228 if target_name not in result:
borlanic 0:02dd72d1d465 1229 result.append(target_name)
borlanic 0:02dd72d1d465 1230 return sorted(result)
borlanic 0:02dd72d1d465 1231
borlanic 0:02dd72d1d465 1232
borlanic 0:02dd72d1d465 1233 def get_unique_value_from_summary_ext(test_summary, index_key, index_val):
borlanic 0:02dd72d1d465 1234 """ Gets list of unique target names and return dictionary
borlanic 0:02dd72d1d465 1235 """
borlanic 0:02dd72d1d465 1236 result = {}
borlanic 0:02dd72d1d465 1237 for test in test_summary:
borlanic 0:02dd72d1d465 1238 key = test[index_key]
borlanic 0:02dd72d1d465 1239 val = test[index_val]
borlanic 0:02dd72d1d465 1240 if key not in result:
borlanic 0:02dd72d1d465 1241 result[key] = val
borlanic 0:02dd72d1d465 1242 return result
borlanic 0:02dd72d1d465 1243
borlanic 0:02dd72d1d465 1244
borlanic 0:02dd72d1d465 1245 def show_json_file_format_error(json_spec_filename, line, column):
borlanic 0:02dd72d1d465 1246 """ Prints JSON broken content
borlanic 0:02dd72d1d465 1247 """
borlanic 0:02dd72d1d465 1248 with open(json_spec_filename) as data_file:
borlanic 0:02dd72d1d465 1249 line_no = 1
borlanic 0:02dd72d1d465 1250 for json_line in data_file:
borlanic 0:02dd72d1d465 1251 if line_no + 5 >= line: # Print last few lines before error
borlanic 0:02dd72d1d465 1252 print('Line %d:\t'%line_no + json_line)
borlanic 0:02dd72d1d465 1253 if line_no == line:
borlanic 0:02dd72d1d465 1254 print('%s\t%s^' (' ' * len('Line %d:' % line_no),
borlanic 0:02dd72d1d465 1255 '-' * (column - 1)))
borlanic 0:02dd72d1d465 1256 break
borlanic 0:02dd72d1d465 1257 line_no += 1
borlanic 0:02dd72d1d465 1258
borlanic 0:02dd72d1d465 1259
borlanic 0:02dd72d1d465 1260 def json_format_error_defect_pos(json_error_msg):
borlanic 0:02dd72d1d465 1261 """ Gets first error line and column in JSON file format.
borlanic 0:02dd72d1d465 1262 Parsed from exception thrown by json.loads() string
borlanic 0:02dd72d1d465 1263 """
borlanic 0:02dd72d1d465 1264 result = None
borlanic 0:02dd72d1d465 1265 line, column = 0, 0
borlanic 0:02dd72d1d465 1266 # Line value search
borlanic 0:02dd72d1d465 1267 line_search = re.search('line [0-9]+', json_error_msg)
borlanic 0:02dd72d1d465 1268 if line_search is not None:
borlanic 0:02dd72d1d465 1269 ls = line_search.group().split(' ')
borlanic 0:02dd72d1d465 1270 if len(ls) == 2:
borlanic 0:02dd72d1d465 1271 line = int(ls[1])
borlanic 0:02dd72d1d465 1272 # Column position search
borlanic 0:02dd72d1d465 1273 column_search = re.search('column [0-9]+', json_error_msg)
borlanic 0:02dd72d1d465 1274 if column_search is not None:
borlanic 0:02dd72d1d465 1275 cs = column_search.group().split(' ')
borlanic 0:02dd72d1d465 1276 if len(cs) == 2:
borlanic 0:02dd72d1d465 1277 column = int(cs[1])
borlanic 0:02dd72d1d465 1278 result = [line, column]
borlanic 0:02dd72d1d465 1279 return result
borlanic 0:02dd72d1d465 1280
borlanic 0:02dd72d1d465 1281
borlanic 0:02dd72d1d465 1282 def get_json_data_from_file(json_spec_filename, verbose=False):
borlanic 0:02dd72d1d465 1283 """ Loads from file JSON formatted string to data structure
borlanic 0:02dd72d1d465 1284 """
borlanic 0:02dd72d1d465 1285 result = None
borlanic 0:02dd72d1d465 1286 try:
borlanic 0:02dd72d1d465 1287 with open(json_spec_filename) as data_file:
borlanic 0:02dd72d1d465 1288 try:
borlanic 0:02dd72d1d465 1289 result = json.load(data_file)
borlanic 0:02dd72d1d465 1290 except ValueError as json_error_msg:
borlanic 0:02dd72d1d465 1291 result = None
borlanic 0:02dd72d1d465 1292 print('JSON file %s parsing failed. Reason: %s' %
borlanic 0:02dd72d1d465 1293 (json_spec_filename, json_error_msg))
borlanic 0:02dd72d1d465 1294 # We can print where error occurred inside JSON file if we can parse exception msg
borlanic 0:02dd72d1d465 1295 json_format_defect_pos = json_format_error_defect_pos(str(json_error_msg))
borlanic 0:02dd72d1d465 1296 if json_format_defect_pos is not None:
borlanic 0:02dd72d1d465 1297 line = json_format_defect_pos[0]
borlanic 0:02dd72d1d465 1298 column = json_format_defect_pos[1]
borlanic 0:02dd72d1d465 1299 print()
borlanic 0:02dd72d1d465 1300 show_json_file_format_error(json_spec_filename, line, column)
borlanic 0:02dd72d1d465 1301
borlanic 0:02dd72d1d465 1302 except IOError as fileopen_error_msg:
borlanic 0:02dd72d1d465 1303 print('JSON file %s not opened. Reason: %s\n'%
borlanic 0:02dd72d1d465 1304 (json_spec_filename, fileopen_error_msg))
borlanic 0:02dd72d1d465 1305 if verbose and result:
borlanic 0:02dd72d1d465 1306 pp = pprint.PrettyPrinter(indent=4)
borlanic 0:02dd72d1d465 1307 pp.pprint(result)
borlanic 0:02dd72d1d465 1308 return result
borlanic 0:02dd72d1d465 1309
borlanic 0:02dd72d1d465 1310
borlanic 0:02dd72d1d465 1311 def print_muts_configuration_from_json(json_data, join_delim=", ", platform_filter=None):
borlanic 0:02dd72d1d465 1312 """ Prints MUTs configuration passed to test script for verboseness
borlanic 0:02dd72d1d465 1313 """
borlanic 0:02dd72d1d465 1314 muts_info_cols = []
borlanic 0:02dd72d1d465 1315 # We need to check all unique properties for each defined MUT
borlanic 0:02dd72d1d465 1316 for k in json_data:
borlanic 0:02dd72d1d465 1317 mut_info = json_data[k]
borlanic 0:02dd72d1d465 1318 for mut_property in mut_info:
borlanic 0:02dd72d1d465 1319 if mut_property not in muts_info_cols:
borlanic 0:02dd72d1d465 1320 muts_info_cols.append(mut_property)
borlanic 0:02dd72d1d465 1321
borlanic 0:02dd72d1d465 1322 # Prepare pretty table object to display all MUTs
borlanic 0:02dd72d1d465 1323 pt_cols = ["index"] + muts_info_cols
borlanic 0:02dd72d1d465 1324 pt = PrettyTable(pt_cols)
borlanic 0:02dd72d1d465 1325 for col in pt_cols:
borlanic 0:02dd72d1d465 1326 pt.align[col] = "l"
borlanic 0:02dd72d1d465 1327
borlanic 0:02dd72d1d465 1328 # Add rows to pretty print object
borlanic 0:02dd72d1d465 1329 for k in json_data:
borlanic 0:02dd72d1d465 1330 row = [k]
borlanic 0:02dd72d1d465 1331 mut_info = json_data[k]
borlanic 0:02dd72d1d465 1332
borlanic 0:02dd72d1d465 1333 add_row = True
borlanic 0:02dd72d1d465 1334 if platform_filter and 'mcu' in mut_info:
borlanic 0:02dd72d1d465 1335 add_row = re.search(platform_filter, mut_info['mcu']) is not None
borlanic 0:02dd72d1d465 1336 if add_row:
borlanic 0:02dd72d1d465 1337 for col in muts_info_cols:
borlanic 0:02dd72d1d465 1338 cell_val = mut_info[col] if col in mut_info else None
borlanic 0:02dd72d1d465 1339 if isinstance(cell_val, list):
borlanic 0:02dd72d1d465 1340 cell_val = join_delim.join(cell_val)
borlanic 0:02dd72d1d465 1341 row.append(cell_val)
borlanic 0:02dd72d1d465 1342 pt.add_row(row)
borlanic 0:02dd72d1d465 1343 return pt.get_string()
borlanic 0:02dd72d1d465 1344
borlanic 0:02dd72d1d465 1345
borlanic 0:02dd72d1d465 1346 def print_test_configuration_from_json(json_data, join_delim=", "):
borlanic 0:02dd72d1d465 1347 """ Prints test specification configuration passed to test script for verboseness
borlanic 0:02dd72d1d465 1348 """
borlanic 0:02dd72d1d465 1349 toolchains_info_cols = []
borlanic 0:02dd72d1d465 1350 # We need to check all toolchains for each device
borlanic 0:02dd72d1d465 1351 for k in json_data:
borlanic 0:02dd72d1d465 1352 # k should be 'targets'
borlanic 0:02dd72d1d465 1353 targets = json_data[k]
borlanic 0:02dd72d1d465 1354 for target in targets:
borlanic 0:02dd72d1d465 1355 toolchains = targets[target]
borlanic 0:02dd72d1d465 1356 for toolchain in toolchains:
borlanic 0:02dd72d1d465 1357 if toolchain not in toolchains_info_cols:
borlanic 0:02dd72d1d465 1358 toolchains_info_cols.append(toolchain)
borlanic 0:02dd72d1d465 1359
borlanic 0:02dd72d1d465 1360 # Prepare pretty table object to display test specification
borlanic 0:02dd72d1d465 1361 pt_cols = ["mcu"] + sorted(toolchains_info_cols)
borlanic 0:02dd72d1d465 1362 pt = PrettyTable(pt_cols)
borlanic 0:02dd72d1d465 1363 for col in pt_cols:
borlanic 0:02dd72d1d465 1364 pt.align[col] = "l"
borlanic 0:02dd72d1d465 1365
borlanic 0:02dd72d1d465 1366 # { target : [conflicted toolchains] }
borlanic 0:02dd72d1d465 1367 toolchain_conflicts = {}
borlanic 0:02dd72d1d465 1368 toolchain_path_conflicts = []
borlanic 0:02dd72d1d465 1369 for k in json_data:
borlanic 0:02dd72d1d465 1370 # k should be 'targets'
borlanic 0:02dd72d1d465 1371 targets = json_data[k]
borlanic 0:02dd72d1d465 1372 for target in targets:
borlanic 0:02dd72d1d465 1373 target_supported_toolchains = get_target_supported_toolchains(target)
borlanic 0:02dd72d1d465 1374 if not target_supported_toolchains:
borlanic 0:02dd72d1d465 1375 target_supported_toolchains = []
borlanic 0:02dd72d1d465 1376 target_name = target if target in TARGET_MAP else "%s*"% target
borlanic 0:02dd72d1d465 1377 row = [target_name]
borlanic 0:02dd72d1d465 1378 toolchains = targets[target]
borlanic 0:02dd72d1d465 1379
borlanic 0:02dd72d1d465 1380 for toolchain in sorted(toolchains_info_cols):
borlanic 0:02dd72d1d465 1381 # Check for conflicts: target vs toolchain
borlanic 0:02dd72d1d465 1382 conflict = False
borlanic 0:02dd72d1d465 1383 conflict_path = False
borlanic 0:02dd72d1d465 1384 if toolchain in toolchains:
borlanic 0:02dd72d1d465 1385 if toolchain not in target_supported_toolchains:
borlanic 0:02dd72d1d465 1386 conflict = True
borlanic 0:02dd72d1d465 1387 if target not in toolchain_conflicts:
borlanic 0:02dd72d1d465 1388 toolchain_conflicts[target] = []
borlanic 0:02dd72d1d465 1389 toolchain_conflicts[target].append(toolchain)
borlanic 0:02dd72d1d465 1390 # Add marker inside table about target usage / conflict
borlanic 0:02dd72d1d465 1391 cell_val = 'Yes' if toolchain in toolchains else '-'
borlanic 0:02dd72d1d465 1392 if conflict:
borlanic 0:02dd72d1d465 1393 cell_val += '*'
borlanic 0:02dd72d1d465 1394 # Check for conflicts: toolchain vs toolchain path
borlanic 0:02dd72d1d465 1395 if toolchain in TOOLCHAIN_PATHS:
borlanic 0:02dd72d1d465 1396 toolchain_path = TOOLCHAIN_PATHS[toolchain]
borlanic 0:02dd72d1d465 1397 if not os.path.isdir(toolchain_path):
borlanic 0:02dd72d1d465 1398 conflict_path = True
borlanic 0:02dd72d1d465 1399 if toolchain not in toolchain_path_conflicts:
borlanic 0:02dd72d1d465 1400 toolchain_path_conflicts.append(toolchain)
borlanic 0:02dd72d1d465 1401 if conflict_path:
borlanic 0:02dd72d1d465 1402 cell_val += '#'
borlanic 0:02dd72d1d465 1403 row.append(cell_val)
borlanic 0:02dd72d1d465 1404 pt.add_row(row)
borlanic 0:02dd72d1d465 1405
borlanic 0:02dd72d1d465 1406 # generate result string
borlanic 0:02dd72d1d465 1407 result = pt.get_string() # Test specification table
borlanic 0:02dd72d1d465 1408 if toolchain_conflicts or toolchain_path_conflicts:
borlanic 0:02dd72d1d465 1409 result += "\n"
borlanic 0:02dd72d1d465 1410 result += "Toolchain conflicts:\n"
borlanic 0:02dd72d1d465 1411 for target in toolchain_conflicts:
borlanic 0:02dd72d1d465 1412 if target not in TARGET_MAP:
borlanic 0:02dd72d1d465 1413 result += "\t* Target %s unknown\n"% (target)
borlanic 0:02dd72d1d465 1414 conflict_target_list = join_delim.join(toolchain_conflicts[target])
borlanic 0:02dd72d1d465 1415 sufix = 's' if len(toolchain_conflicts[target]) > 1 else ''
borlanic 0:02dd72d1d465 1416 result += "\t* Target %s does not support %s toolchain%s\n"% (target, conflict_target_list, sufix)
borlanic 0:02dd72d1d465 1417
borlanic 0:02dd72d1d465 1418 for toolchain in toolchain_path_conflicts:
borlanic 0:02dd72d1d465 1419 # Let's check toolchain configuration
borlanic 0:02dd72d1d465 1420 if toolchain in TOOLCHAIN_PATHS:
borlanic 0:02dd72d1d465 1421 toolchain_path = TOOLCHAIN_PATHS[toolchain]
borlanic 0:02dd72d1d465 1422 if not os.path.isdir(toolchain_path):
borlanic 0:02dd72d1d465 1423 result += "\t# Toolchain %s path not found: %s\n"% (toolchain, toolchain_path)
borlanic 0:02dd72d1d465 1424 return result
borlanic 0:02dd72d1d465 1425
borlanic 0:02dd72d1d465 1426
borlanic 0:02dd72d1d465 1427 def get_avail_tests_summary_table(cols=None, result_summary=True, join_delim=',',platform_filter=None):
borlanic 0:02dd72d1d465 1428 """ Generates table summary with all test cases and additional test cases
borlanic 0:02dd72d1d465 1429 information using pretty print functionality. Allows test suite user to
borlanic 0:02dd72d1d465 1430 see test cases
borlanic 0:02dd72d1d465 1431 """
borlanic 0:02dd72d1d465 1432 # get all unique test ID prefixes
borlanic 0:02dd72d1d465 1433 unique_test_id = []
borlanic 0:02dd72d1d465 1434 for test in TESTS:
borlanic 0:02dd72d1d465 1435 split = test['id'].split('_')[:-1]
borlanic 0:02dd72d1d465 1436 test_id_prefix = '_'.join(split)
borlanic 0:02dd72d1d465 1437 if test_id_prefix not in unique_test_id:
borlanic 0:02dd72d1d465 1438 unique_test_id.append(test_id_prefix)
borlanic 0:02dd72d1d465 1439 unique_test_id.sort()
borlanic 0:02dd72d1d465 1440 counter_dict_test_id_types = dict((t, 0) for t in unique_test_id)
borlanic 0:02dd72d1d465 1441 counter_dict_test_id_types_all = dict((t, 0) for t in unique_test_id)
borlanic 0:02dd72d1d465 1442
borlanic 0:02dd72d1d465 1443 test_properties = ['id',
borlanic 0:02dd72d1d465 1444 'automated',
borlanic 0:02dd72d1d465 1445 'description',
borlanic 0:02dd72d1d465 1446 'peripherals',
borlanic 0:02dd72d1d465 1447 'host_test',
borlanic 0:02dd72d1d465 1448 'duration'] if cols is None else cols
borlanic 0:02dd72d1d465 1449
borlanic 0:02dd72d1d465 1450 # All tests status table print
borlanic 0:02dd72d1d465 1451 pt = PrettyTable(test_properties)
borlanic 0:02dd72d1d465 1452 for col in test_properties:
borlanic 0:02dd72d1d465 1453 pt.align[col] = "l"
borlanic 0:02dd72d1d465 1454 pt.align['duration'] = "r"
borlanic 0:02dd72d1d465 1455
borlanic 0:02dd72d1d465 1456 counter_all = 0
borlanic 0:02dd72d1d465 1457 counter_automated = 0
borlanic 0:02dd72d1d465 1458 pt.padding_width = 1 # One space between column edges and contents (default)
borlanic 0:02dd72d1d465 1459
borlanic 0:02dd72d1d465 1460 for test_id in sorted(TEST_MAP.keys()):
borlanic 0:02dd72d1d465 1461 if platform_filter is not None:
borlanic 0:02dd72d1d465 1462 # FIlter out platforms using regex
borlanic 0:02dd72d1d465 1463 if re.search(platform_filter, test_id) is None:
borlanic 0:02dd72d1d465 1464 continue
borlanic 0:02dd72d1d465 1465 row = []
borlanic 0:02dd72d1d465 1466 test = TEST_MAP[test_id]
borlanic 0:02dd72d1d465 1467 split = test_id.split('_')[:-1]
borlanic 0:02dd72d1d465 1468 test_id_prefix = '_'.join(split)
borlanic 0:02dd72d1d465 1469
borlanic 0:02dd72d1d465 1470 for col in test_properties:
borlanic 0:02dd72d1d465 1471 col_value = test[col]
borlanic 0:02dd72d1d465 1472 if isinstance(test[col], list):
borlanic 0:02dd72d1d465 1473 col_value = join_delim.join(test[col])
borlanic 0:02dd72d1d465 1474 elif test[col] == None:
borlanic 0:02dd72d1d465 1475 col_value = "-"
borlanic 0:02dd72d1d465 1476
borlanic 0:02dd72d1d465 1477 row.append(col_value)
borlanic 0:02dd72d1d465 1478 if test['automated'] == True:
borlanic 0:02dd72d1d465 1479 counter_dict_test_id_types[test_id_prefix] += 1
borlanic 0:02dd72d1d465 1480 counter_automated += 1
borlanic 0:02dd72d1d465 1481 pt.add_row(row)
borlanic 0:02dd72d1d465 1482 # Update counters
borlanic 0:02dd72d1d465 1483 counter_all += 1
borlanic 0:02dd72d1d465 1484 counter_dict_test_id_types_all[test_id_prefix] += 1
borlanic 0:02dd72d1d465 1485 result = pt.get_string()
borlanic 0:02dd72d1d465 1486 result += "\n\n"
borlanic 0:02dd72d1d465 1487
borlanic 0:02dd72d1d465 1488 if result_summary and not platform_filter:
borlanic 0:02dd72d1d465 1489 # Automation result summary
borlanic 0:02dd72d1d465 1490 test_id_cols = ['automated', 'all', 'percent [%]', 'progress']
borlanic 0:02dd72d1d465 1491 pt = PrettyTable(test_id_cols)
borlanic 0:02dd72d1d465 1492 pt.align['automated'] = "r"
borlanic 0:02dd72d1d465 1493 pt.align['all'] = "r"
borlanic 0:02dd72d1d465 1494 pt.align['percent [%]'] = "r"
borlanic 0:02dd72d1d465 1495
borlanic 0:02dd72d1d465 1496 percent_progress = round(100.0 * counter_automated / float(counter_all), 1)
borlanic 0:02dd72d1d465 1497 str_progress = progress_bar(percent_progress, 75)
borlanic 0:02dd72d1d465 1498 pt.add_row([counter_automated, counter_all, percent_progress, str_progress])
borlanic 0:02dd72d1d465 1499 result += "Automation coverage:\n"
borlanic 0:02dd72d1d465 1500 result += pt.get_string()
borlanic 0:02dd72d1d465 1501 result += "\n\n"
borlanic 0:02dd72d1d465 1502
borlanic 0:02dd72d1d465 1503 # Test automation coverage table print
borlanic 0:02dd72d1d465 1504 test_id_cols = ['id', 'automated', 'all', 'percent [%]', 'progress']
borlanic 0:02dd72d1d465 1505 pt = PrettyTable(test_id_cols)
borlanic 0:02dd72d1d465 1506 pt.align['id'] = "l"
borlanic 0:02dd72d1d465 1507 pt.align['automated'] = "r"
borlanic 0:02dd72d1d465 1508 pt.align['all'] = "r"
borlanic 0:02dd72d1d465 1509 pt.align['percent [%]'] = "r"
borlanic 0:02dd72d1d465 1510 for unique_id in unique_test_id:
borlanic 0:02dd72d1d465 1511 # print "\t\t%s: %d / %d" % (unique_id, counter_dict_test_id_types[unique_id], counter_dict_test_id_types_all[unique_id])
borlanic 0:02dd72d1d465 1512 percent_progress = round(100.0 * counter_dict_test_id_types[unique_id] / float(counter_dict_test_id_types_all[unique_id]), 1)
borlanic 0:02dd72d1d465 1513 str_progress = progress_bar(percent_progress, 75)
borlanic 0:02dd72d1d465 1514 row = [unique_id,
borlanic 0:02dd72d1d465 1515 counter_dict_test_id_types[unique_id],
borlanic 0:02dd72d1d465 1516 counter_dict_test_id_types_all[unique_id],
borlanic 0:02dd72d1d465 1517 percent_progress,
borlanic 0:02dd72d1d465 1518 "[" + str_progress + "]"]
borlanic 0:02dd72d1d465 1519 pt.add_row(row)
borlanic 0:02dd72d1d465 1520 result += "Test automation coverage:\n"
borlanic 0:02dd72d1d465 1521 result += pt.get_string()
borlanic 0:02dd72d1d465 1522 result += "\n\n"
borlanic 0:02dd72d1d465 1523 return result
borlanic 0:02dd72d1d465 1524
borlanic 0:02dd72d1d465 1525
borlanic 0:02dd72d1d465 1526 def progress_bar(percent_progress, saturation=0):
borlanic 0:02dd72d1d465 1527 """ This function creates progress bar with optional simple saturation mark
borlanic 0:02dd72d1d465 1528 """
borlanic 0:02dd72d1d465 1529 step = int(percent_progress / 2) # Scale by to (scale: 1 - 50)
borlanic 0:02dd72d1d465 1530 str_progress = '#' * step + '.' * int(50 - step)
borlanic 0:02dd72d1d465 1531 c = '!' if str_progress[38] == '.' else '|'
borlanic 0:02dd72d1d465 1532 if saturation > 0:
borlanic 0:02dd72d1d465 1533 saturation = saturation / 2
borlanic 0:02dd72d1d465 1534 str_progress = str_progress[:saturation] + c + str_progress[saturation:]
borlanic 0:02dd72d1d465 1535 return str_progress
borlanic 0:02dd72d1d465 1536
borlanic 0:02dd72d1d465 1537
borlanic 0:02dd72d1d465 1538 def singletest_in_cli_mode(single_test):
borlanic 0:02dd72d1d465 1539 """ Runs SingleTestRunner object in CLI (Command line interface) mode
borlanic 0:02dd72d1d465 1540
borlanic 0:02dd72d1d465 1541 @return returns success code (0 == success) for building and running tests
borlanic 0:02dd72d1d465 1542 """
borlanic 0:02dd72d1d465 1543 start = time()
borlanic 0:02dd72d1d465 1544 # Execute tests depending on options and filter applied
borlanic 0:02dd72d1d465 1545 test_summary, shuffle_seed, test_summary_ext, test_suite_properties_ext, build_report, build_properties = single_test.execute()
borlanic 0:02dd72d1d465 1546 elapsed_time = time() - start
borlanic 0:02dd72d1d465 1547
borlanic 0:02dd72d1d465 1548 # Human readable summary
borlanic 0:02dd72d1d465 1549 if not single_test.opts_suppress_summary:
borlanic 0:02dd72d1d465 1550 # prints well-formed summary with results (SQL table like)
borlanic 0:02dd72d1d465 1551 print(single_test.generate_test_summary(test_summary, shuffle_seed))
borlanic 0:02dd72d1d465 1552 if single_test.opts_test_x_toolchain_summary:
borlanic 0:02dd72d1d465 1553 # prints well-formed summary with results (SQL table like)
borlanic 0:02dd72d1d465 1554 # table shows text x toolchain test result matrix
borlanic 0:02dd72d1d465 1555 print(single_test.generate_test_summary_by_target(test_summary,
borlanic 0:02dd72d1d465 1556 shuffle_seed))
borlanic 0:02dd72d1d465 1557
borlanic 0:02dd72d1d465 1558 print("Completed in %.2f sec" % elapsed_time)
borlanic 0:02dd72d1d465 1559 print
borlanic 0:02dd72d1d465 1560 # Write summary of the builds
borlanic 0:02dd72d1d465 1561
borlanic 0:02dd72d1d465 1562 print_report_exporter = ReportExporter(ResultExporterType.PRINT, package="build")
borlanic 0:02dd72d1d465 1563 status = print_report_exporter.report(build_report)
borlanic 0:02dd72d1d465 1564
borlanic 0:02dd72d1d465 1565 # Store extra reports in files
borlanic 0:02dd72d1d465 1566 if single_test.opts_report_html_file_name:
borlanic 0:02dd72d1d465 1567 # Export results in form of HTML report to separate file
borlanic 0:02dd72d1d465 1568 report_exporter = ReportExporter(ResultExporterType.HTML)
borlanic 0:02dd72d1d465 1569 report_exporter.report_to_file(test_summary_ext, single_test.opts_report_html_file_name, test_suite_properties=test_suite_properties_ext)
borlanic 0:02dd72d1d465 1570 if single_test.opts_report_junit_file_name:
borlanic 0:02dd72d1d465 1571 # Export results in form of JUnit XML report to separate file
borlanic 0:02dd72d1d465 1572 report_exporter = ReportExporter(ResultExporterType.JUNIT)
borlanic 0:02dd72d1d465 1573 report_exporter.report_to_file(test_summary_ext, single_test.opts_report_junit_file_name, test_suite_properties=test_suite_properties_ext)
borlanic 0:02dd72d1d465 1574 if single_test.opts_report_text_file_name:
borlanic 0:02dd72d1d465 1575 # Export results in form of a text file
borlanic 0:02dd72d1d465 1576 report_exporter = ReportExporter(ResultExporterType.TEXT)
borlanic 0:02dd72d1d465 1577 report_exporter.report_to_file(test_summary_ext, single_test.opts_report_text_file_name, test_suite_properties=test_suite_properties_ext)
borlanic 0:02dd72d1d465 1578 if single_test.opts_report_build_file_name:
borlanic 0:02dd72d1d465 1579 # Export build results as html report to sparate file
borlanic 0:02dd72d1d465 1580 report_exporter = ReportExporter(ResultExporterType.JUNIT, package="build")
borlanic 0:02dd72d1d465 1581 report_exporter.report_to_file(build_report, single_test.opts_report_build_file_name, test_suite_properties=build_properties)
borlanic 0:02dd72d1d465 1582
borlanic 0:02dd72d1d465 1583 # Returns True if no build failures of the test projects or their dependencies
borlanic 0:02dd72d1d465 1584 return status
borlanic 0:02dd72d1d465 1585
borlanic 0:02dd72d1d465 1586 class TestLogger():
borlanic 0:02dd72d1d465 1587 """ Super-class for logging and printing ongoing events for test suite pass
borlanic 0:02dd72d1d465 1588 """
borlanic 0:02dd72d1d465 1589 def __init__(self, store_log=True):
borlanic 0:02dd72d1d465 1590 """ We can control if logger actually stores log in memory
borlanic 0:02dd72d1d465 1591 or just handled all log entries immediately
borlanic 0:02dd72d1d465 1592 """
borlanic 0:02dd72d1d465 1593 self.log = []
borlanic 0:02dd72d1d465 1594 self.log_to_file = False
borlanic 0:02dd72d1d465 1595 self.log_file_name = None
borlanic 0:02dd72d1d465 1596 self.store_log = store_log
borlanic 0:02dd72d1d465 1597
borlanic 0:02dd72d1d465 1598 self.LogType = construct_enum(INFO='Info',
borlanic 0:02dd72d1d465 1599 WARN='Warning',
borlanic 0:02dd72d1d465 1600 NOTIF='Notification',
borlanic 0:02dd72d1d465 1601 ERROR='Error',
borlanic 0:02dd72d1d465 1602 EXCEPT='Exception')
borlanic 0:02dd72d1d465 1603
borlanic 0:02dd72d1d465 1604 self.LogToFileAttr = construct_enum(CREATE=1, # Create or overwrite existing log file
borlanic 0:02dd72d1d465 1605 APPEND=2) # Append to existing log file
borlanic 0:02dd72d1d465 1606
borlanic 0:02dd72d1d465 1607 def log_line(self, LogType, log_line, timestamp=True, line_delim='\n'):
borlanic 0:02dd72d1d465 1608 """ Log one line of text
borlanic 0:02dd72d1d465 1609 """
borlanic 0:02dd72d1d465 1610 log_timestamp = time()
borlanic 0:02dd72d1d465 1611 log_entry = {'log_type' : LogType,
borlanic 0:02dd72d1d465 1612 'log_timestamp' : log_timestamp,
borlanic 0:02dd72d1d465 1613 'log_line' : log_line,
borlanic 0:02dd72d1d465 1614 '_future' : None
borlanic 0:02dd72d1d465 1615 }
borlanic 0:02dd72d1d465 1616 # Store log in memory
borlanic 0:02dd72d1d465 1617 if self.store_log:
borlanic 0:02dd72d1d465 1618 self.log.append(log_entry)
borlanic 0:02dd72d1d465 1619 return log_entry
borlanic 0:02dd72d1d465 1620
borlanic 0:02dd72d1d465 1621
borlanic 0:02dd72d1d465 1622 class CLITestLogger(TestLogger):
borlanic 0:02dd72d1d465 1623 """ Logger used with CLI (Command line interface) test suite. Logs on screen and to file if needed
borlanic 0:02dd72d1d465 1624 """
borlanic 0:02dd72d1d465 1625 def __init__(self, store_log=True, file_name=None):
borlanic 0:02dd72d1d465 1626 TestLogger.__init__(self)
borlanic 0:02dd72d1d465 1627 self.log_file_name = file_name
borlanic 0:02dd72d1d465 1628 #self.TIMESTAMP_FORMAT = '%y-%m-%d %H:%M:%S' # Full date and time
borlanic 0:02dd72d1d465 1629 self.TIMESTAMP_FORMAT = '%H:%M:%S' # Time only
borlanic 0:02dd72d1d465 1630
borlanic 0:02dd72d1d465 1631 def log_print(self, log_entry, timestamp=True):
borlanic 0:02dd72d1d465 1632 """ Prints on screen formatted log entry
borlanic 0:02dd72d1d465 1633 """
borlanic 0:02dd72d1d465 1634 ts = log_entry['log_timestamp']
borlanic 0:02dd72d1d465 1635 timestamp_str = datetime.datetime.fromtimestamp(ts).strftime("[%s] "% self.TIMESTAMP_FORMAT) if timestamp else ''
borlanic 0:02dd72d1d465 1636 log_line_str = "%(log_type)s: %(log_line)s"% (log_entry)
borlanic 0:02dd72d1d465 1637 return timestamp_str + log_line_str
borlanic 0:02dd72d1d465 1638
borlanic 0:02dd72d1d465 1639 def log_line(self, LogType, log_line, timestamp=True, line_delim='\n'):
borlanic 0:02dd72d1d465 1640 """ Logs line, if log file output was specified log line will be appended
borlanic 0:02dd72d1d465 1641 at the end of log file
borlanic 0:02dd72d1d465 1642 """
borlanic 0:02dd72d1d465 1643 log_entry = TestLogger.log_line(self, LogType, log_line)
borlanic 0:02dd72d1d465 1644 log_line_str = self.log_print(log_entry, timestamp)
borlanic 0:02dd72d1d465 1645 if self.log_file_name is not None:
borlanic 0:02dd72d1d465 1646 try:
borlanic 0:02dd72d1d465 1647 with open(self.log_file_name, 'a') as f:
borlanic 0:02dd72d1d465 1648 f.write(log_line_str + line_delim)
borlanic 0:02dd72d1d465 1649 except IOError:
borlanic 0:02dd72d1d465 1650 pass
borlanic 0:02dd72d1d465 1651 return log_line_str
borlanic 0:02dd72d1d465 1652
borlanic 0:02dd72d1d465 1653
borlanic 0:02dd72d1d465 1654 def factory_db_logger(db_url):
borlanic 0:02dd72d1d465 1655 """ Factory database driver depending on database type supplied in database connection string db_url
borlanic 0:02dd72d1d465 1656 """
borlanic 0:02dd72d1d465 1657 if db_url is not None:
borlanic 0:02dd72d1d465 1658 from tools.test_mysql import MySQLDBAccess
borlanic 0:02dd72d1d465 1659 connection_info = BaseDBAccess().parse_db_connection_string(db_url)
borlanic 0:02dd72d1d465 1660 if connection_info is not None:
borlanic 0:02dd72d1d465 1661 (db_type, username, password, host, db_name) = BaseDBAccess().parse_db_connection_string(db_url)
borlanic 0:02dd72d1d465 1662 if db_type == 'mysql':
borlanic 0:02dd72d1d465 1663 return MySQLDBAccess()
borlanic 0:02dd72d1d465 1664 return None
borlanic 0:02dd72d1d465 1665
borlanic 0:02dd72d1d465 1666
borlanic 0:02dd72d1d465 1667 def detect_database_verbose(db_url):
borlanic 0:02dd72d1d465 1668 """ uses verbose mode (prints) database detection sequence to check it database connection string is valid
borlanic 0:02dd72d1d465 1669 """
borlanic 0:02dd72d1d465 1670 result = BaseDBAccess().parse_db_connection_string(db_url)
borlanic 0:02dd72d1d465 1671 if result is not None:
borlanic 0:02dd72d1d465 1672 # Parsing passed
borlanic 0:02dd72d1d465 1673 (db_type, username, password, host, db_name) = result
borlanic 0:02dd72d1d465 1674 #print "DB type '%s', user name '%s', password '%s', host '%s', db name '%s'"% result
borlanic 0:02dd72d1d465 1675 # Let's try to connect
borlanic 0:02dd72d1d465 1676 db_ = factory_db_logger(db_url)
borlanic 0:02dd72d1d465 1677 if db_ is not None:
borlanic 0:02dd72d1d465 1678 print("Connecting to database '%s'..." % db_url)
borlanic 0:02dd72d1d465 1679 db_.connect(host, username, password, db_name)
borlanic 0:02dd72d1d465 1680 if db_.is_connected():
borlanic 0:02dd72d1d465 1681 print("ok")
borlanic 0:02dd72d1d465 1682 print("Detecting database...")
borlanic 0:02dd72d1d465 1683 print(db_.detect_database(verbose=True))
borlanic 0:02dd72d1d465 1684 print("Disconnecting...")
borlanic 0:02dd72d1d465 1685 db_.disconnect()
borlanic 0:02dd72d1d465 1686 print("done")
borlanic 0:02dd72d1d465 1687 else:
borlanic 0:02dd72d1d465 1688 print("Database type '%s' unknown" % db_type)
borlanic 0:02dd72d1d465 1689 else:
borlanic 0:02dd72d1d465 1690 print("Parse error: '%s' - DB Url error" % db_url)
borlanic 0:02dd72d1d465 1691
borlanic 0:02dd72d1d465 1692
borlanic 0:02dd72d1d465 1693 def get_module_avail(module_name):
borlanic 0:02dd72d1d465 1694 """ This function returns True if module_name is already imported module
borlanic 0:02dd72d1d465 1695 """
borlanic 0:02dd72d1d465 1696 return module_name in sys.modules.keys()
borlanic 0:02dd72d1d465 1697
borlanic 0:02dd72d1d465 1698 def get_autodetected_MUTS_list(platform_name_filter=None):
borlanic 0:02dd72d1d465 1699 oldError = None
borlanic 0:02dd72d1d465 1700 if os.name == 'nt':
borlanic 0:02dd72d1d465 1701 # Disable Windows error box temporarily
borlanic 0:02dd72d1d465 1702 oldError = ctypes.windll.kernel32.SetErrorMode(1) #note that SEM_FAILCRITICALERRORS = 1
borlanic 0:02dd72d1d465 1703
borlanic 0:02dd72d1d465 1704 mbeds = mbed_lstools.create()
borlanic 0:02dd72d1d465 1705 detect_muts_list = mbeds.list_mbeds()
borlanic 0:02dd72d1d465 1706
borlanic 0:02dd72d1d465 1707 if os.name == 'nt':
borlanic 0:02dd72d1d465 1708 ctypes.windll.kernel32.SetErrorMode(oldError)
borlanic 0:02dd72d1d465 1709
borlanic 0:02dd72d1d465 1710 return get_autodetected_MUTS(detect_muts_list, platform_name_filter=platform_name_filter)
borlanic 0:02dd72d1d465 1711
borlanic 0:02dd72d1d465 1712 def get_autodetected_MUTS(mbeds_list, platform_name_filter=None):
borlanic 0:02dd72d1d465 1713 """ Function detects all connected to host mbed-enabled devices and generates artificial MUTS file.
borlanic 0:02dd72d1d465 1714 If function fails to auto-detect devices it will return empty dictionary.
borlanic 0:02dd72d1d465 1715
borlanic 0:02dd72d1d465 1716 if get_module_avail('mbed_lstools'):
borlanic 0:02dd72d1d465 1717 mbeds = mbed_lstools.create()
borlanic 0:02dd72d1d465 1718 mbeds_list = mbeds.list_mbeds()
borlanic 0:02dd72d1d465 1719
borlanic 0:02dd72d1d465 1720 @param mbeds_list list of mbeds captured from mbed_lstools
borlanic 0:02dd72d1d465 1721 @param platform_name You can filter 'platform_name' with list of filtered targets from 'platform_name_filter'
borlanic 0:02dd72d1d465 1722 """
borlanic 0:02dd72d1d465 1723 result = {} # Should be in muts_all.json format
borlanic 0:02dd72d1d465 1724 # Align mbeds_list from mbed_lstools to MUT file format (JSON dictionary with muts)
borlanic 0:02dd72d1d465 1725 # mbeds_list = [{'platform_name': 'NUCLEO_F302R8', 'mount_point': 'E:', 'target_id': '07050200623B61125D5EF72A', 'serial_port': u'COM34'}]
borlanic 0:02dd72d1d465 1726 index = 1
borlanic 0:02dd72d1d465 1727 for mut in mbeds_list:
borlanic 0:02dd72d1d465 1728 # Filter the MUTS if a filter is specified
borlanic 0:02dd72d1d465 1729
borlanic 0:02dd72d1d465 1730 if platform_name_filter and not mut['platform_name'] in platform_name_filter:
borlanic 0:02dd72d1d465 1731 continue
borlanic 0:02dd72d1d465 1732
borlanic 0:02dd72d1d465 1733 # For mcu_unique - we are assigning 'platform_name_unique' value from mbedls output (if its existing)
borlanic 0:02dd72d1d465 1734 # if not we are creating our own unique value (last few chars from platform's target_id).
borlanic 0:02dd72d1d465 1735 m = {'mcu': mut['platform_name'],
borlanic 0:02dd72d1d465 1736 'mcu_unique' : mut['platform_name_unique'] if 'platform_name_unique' in mut else "%s[%s]" % (mut['platform_name'], mut['target_id'][-4:]),
borlanic 0:02dd72d1d465 1737 'port': mut['serial_port'],
borlanic 0:02dd72d1d465 1738 'disk': mut['mount_point'],
borlanic 0:02dd72d1d465 1739 'peripherals': [] # No peripheral detection
borlanic 0:02dd72d1d465 1740 }
borlanic 0:02dd72d1d465 1741 if index not in result:
borlanic 0:02dd72d1d465 1742 result[index] = {}
borlanic 0:02dd72d1d465 1743 result[index] = m
borlanic 0:02dd72d1d465 1744 index += 1
borlanic 0:02dd72d1d465 1745 return result
borlanic 0:02dd72d1d465 1746
borlanic 0:02dd72d1d465 1747
borlanic 0:02dd72d1d465 1748 def get_autodetected_TEST_SPEC(mbeds_list,
borlanic 0:02dd72d1d465 1749 use_default_toolchain=True,
borlanic 0:02dd72d1d465 1750 use_supported_toolchains=False,
borlanic 0:02dd72d1d465 1751 toolchain_filter=None,
borlanic 0:02dd72d1d465 1752 platform_name_filter=None):
borlanic 0:02dd72d1d465 1753 """ Function detects all connected to host mbed-enabled devices and generates artificial test_spec file.
borlanic 0:02dd72d1d465 1754 If function fails to auto-detect devices it will return empty 'targets' test_spec description.
borlanic 0:02dd72d1d465 1755
borlanic 0:02dd72d1d465 1756 use_default_toolchain - if True add default toolchain to test_spec
borlanic 0:02dd72d1d465 1757 use_supported_toolchains - if True add all supported toolchains to test_spec
borlanic 0:02dd72d1d465 1758 toolchain_filter - if [...list of toolchains...] add from all toolchains only those in filter to test_spec
borlanic 0:02dd72d1d465 1759 """
borlanic 0:02dd72d1d465 1760 result = {'targets': {} }
borlanic 0:02dd72d1d465 1761
borlanic 0:02dd72d1d465 1762 for mut in mbeds_list:
borlanic 0:02dd72d1d465 1763 mcu = mut['mcu']
borlanic 0:02dd72d1d465 1764 if platform_name_filter is None or (platform_name_filter and mut['mcu'] in platform_name_filter):
borlanic 0:02dd72d1d465 1765 if mcu in TARGET_MAP:
borlanic 0:02dd72d1d465 1766 default_toolchain = TARGET_MAP[mcu].default_toolchain
borlanic 0:02dd72d1d465 1767 supported_toolchains = TARGET_MAP[mcu].supported_toolchains
borlanic 0:02dd72d1d465 1768
borlanic 0:02dd72d1d465 1769 # Decide which toolchains should be added to test specification toolchain pool for each target
borlanic 0:02dd72d1d465 1770 toolchains = []
borlanic 0:02dd72d1d465 1771 if use_default_toolchain:
borlanic 0:02dd72d1d465 1772 toolchains.append(default_toolchain)
borlanic 0:02dd72d1d465 1773 if use_supported_toolchains:
borlanic 0:02dd72d1d465 1774 toolchains += supported_toolchains
borlanic 0:02dd72d1d465 1775 if toolchain_filter is not None:
borlanic 0:02dd72d1d465 1776 all_toolchains = supported_toolchains + [default_toolchain]
borlanic 0:02dd72d1d465 1777 for toolchain in toolchain_filter:
borlanic 0:02dd72d1d465 1778 if toolchain in all_toolchains:
borlanic 0:02dd72d1d465 1779 toolchains.append(toolchain)
borlanic 0:02dd72d1d465 1780
borlanic 0:02dd72d1d465 1781 result['targets'][mcu] = list(set(toolchains))
borlanic 0:02dd72d1d465 1782 return result
borlanic 0:02dd72d1d465 1783
borlanic 0:02dd72d1d465 1784
borlanic 0:02dd72d1d465 1785 def get_default_test_options_parser():
borlanic 0:02dd72d1d465 1786 """ Get common test script options used by CLI, web services etc.
borlanic 0:02dd72d1d465 1787 """
borlanic 0:02dd72d1d465 1788 parser = argparse.ArgumentParser()
borlanic 0:02dd72d1d465 1789 parser.add_argument('-i', '--tests',
borlanic 0:02dd72d1d465 1790 dest='test_spec_filename',
borlanic 0:02dd72d1d465 1791 metavar="FILE",
borlanic 0:02dd72d1d465 1792 type=argparse_filestring_type,
borlanic 0:02dd72d1d465 1793 help='Points to file with test specification')
borlanic 0:02dd72d1d465 1794
borlanic 0:02dd72d1d465 1795 parser.add_argument('-M', '--MUTS',
borlanic 0:02dd72d1d465 1796 dest='muts_spec_filename',
borlanic 0:02dd72d1d465 1797 metavar="FILE",
borlanic 0:02dd72d1d465 1798 type=argparse_filestring_type,
borlanic 0:02dd72d1d465 1799 help='Points to file with MUTs specification (overwrites settings.py and private_settings.py)')
borlanic 0:02dd72d1d465 1800
borlanic 0:02dd72d1d465 1801 parser.add_argument("-j", "--jobs",
borlanic 0:02dd72d1d465 1802 dest='jobs',
borlanic 0:02dd72d1d465 1803 metavar="NUMBER",
borlanic 0:02dd72d1d465 1804 type=int,
borlanic 0:02dd72d1d465 1805 help="Define number of compilation jobs. Default value is 1")
borlanic 0:02dd72d1d465 1806
borlanic 0:02dd72d1d465 1807 if get_module_avail('mbed_lstools'):
borlanic 0:02dd72d1d465 1808 # Additional features available when mbed_lstools is installed on host and imported
borlanic 0:02dd72d1d465 1809 # mbed_lstools allow users to detect connected to host mbed-enabled devices
borlanic 0:02dd72d1d465 1810 parser.add_argument('--auto',
borlanic 0:02dd72d1d465 1811 dest='auto_detect',
borlanic 0:02dd72d1d465 1812 action="store_true",
borlanic 0:02dd72d1d465 1813 help='Use mbed-ls module to detect all connected mbed devices')
borlanic 0:02dd72d1d465 1814
borlanic 0:02dd72d1d465 1815 toolchain_list = list(TOOLCHAINS) + ["DEFAULT", "ALL"]
borlanic 0:02dd72d1d465 1816 parser.add_argument('--tc',
borlanic 0:02dd72d1d465 1817 dest='toolchains_filter',
borlanic 0:02dd72d1d465 1818 type=argparse_many(argparse_uppercase_type(toolchain_list, "toolchains")),
borlanic 0:02dd72d1d465 1819 help="Toolchain filter for --auto argument. Use toolchains names separated by comma, 'default' or 'all' to select toolchains")
borlanic 0:02dd72d1d465 1820
borlanic 0:02dd72d1d465 1821 test_scopes = ','.join(["'%s'" % n for n in get_available_oper_test_scopes()])
borlanic 0:02dd72d1d465 1822 parser.add_argument('--oper',
borlanic 0:02dd72d1d465 1823 dest='operability_checks',
borlanic 0:02dd72d1d465 1824 type=argparse_lowercase_type(get_available_oper_test_scopes(), "scopes"),
borlanic 0:02dd72d1d465 1825 help='Perform interoperability tests between host and connected mbed devices. Available test scopes are: %s' % test_scopes)
borlanic 0:02dd72d1d465 1826
borlanic 0:02dd72d1d465 1827 parser.add_argument('--clean',
borlanic 0:02dd72d1d465 1828 dest='clean',
borlanic 0:02dd72d1d465 1829 action="store_true",
borlanic 0:02dd72d1d465 1830 help='Clean the build directory')
borlanic 0:02dd72d1d465 1831
borlanic 0:02dd72d1d465 1832 parser.add_argument('-P', '--only-peripherals',
borlanic 0:02dd72d1d465 1833 dest='test_only_peripheral',
borlanic 0:02dd72d1d465 1834 default=False,
borlanic 0:02dd72d1d465 1835 action="store_true",
borlanic 0:02dd72d1d465 1836 help='Test only peripheral declared for MUT and skip common tests')
borlanic 0:02dd72d1d465 1837
borlanic 0:02dd72d1d465 1838 parser.add_argument("--profile", dest="profile", action="append",
borlanic 0:02dd72d1d465 1839 type=argparse_filestring_type,
borlanic 0:02dd72d1d465 1840 default=[])
borlanic 0:02dd72d1d465 1841
borlanic 0:02dd72d1d465 1842 parser.add_argument('-C', '--only-commons',
borlanic 0:02dd72d1d465 1843 dest='test_only_common',
borlanic 0:02dd72d1d465 1844 default=False,
borlanic 0:02dd72d1d465 1845 action="store_true",
borlanic 0:02dd72d1d465 1846 help='Test only board internals. Skip perpherials tests and perform common tests')
borlanic 0:02dd72d1d465 1847
borlanic 0:02dd72d1d465 1848 parser.add_argument('-n', '--test-by-names',
borlanic 0:02dd72d1d465 1849 dest='test_by_names',
borlanic 0:02dd72d1d465 1850 type=argparse_many(str),
borlanic 0:02dd72d1d465 1851 help='Runs only test enumerated it this switch. Use comma to separate test case names')
borlanic 0:02dd72d1d465 1852
borlanic 0:02dd72d1d465 1853 parser.add_argument('-p', '--peripheral-by-names',
borlanic 0:02dd72d1d465 1854 dest='peripheral_by_names',
borlanic 0:02dd72d1d465 1855 type=argparse_many(str),
borlanic 0:02dd72d1d465 1856 help='Forces discovery of particular peripherals. Use comma to separate peripheral names')
borlanic 0:02dd72d1d465 1857
borlanic 0:02dd72d1d465 1858 copy_methods = host_tests_plugins.get_plugin_caps('CopyMethod')
borlanic 0:02dd72d1d465 1859 copy_methods_str = "Plugin support: " + ', '.join(copy_methods)
borlanic 0:02dd72d1d465 1860
borlanic 0:02dd72d1d465 1861 parser.add_argument('-c', '--copy-method',
borlanic 0:02dd72d1d465 1862 dest='copy_method',
borlanic 0:02dd72d1d465 1863 type=argparse_uppercase_type(copy_methods, "flash method"),
borlanic 0:02dd72d1d465 1864 help="Select binary copy (flash) method. Default is Python's shutil.copy() method. %s"% copy_methods_str)
borlanic 0:02dd72d1d465 1865
borlanic 0:02dd72d1d465 1866 reset_methods = host_tests_plugins.get_plugin_caps('ResetMethod')
borlanic 0:02dd72d1d465 1867 reset_methods_str = "Plugin support: " + ', '.join(reset_methods)
borlanic 0:02dd72d1d465 1868
borlanic 0:02dd72d1d465 1869 parser.add_argument('-r', '--reset-type',
borlanic 0:02dd72d1d465 1870 dest='mut_reset_type',
borlanic 0:02dd72d1d465 1871 default=None,
borlanic 0:02dd72d1d465 1872 type=argparse_uppercase_type(reset_methods, "reset method"),
borlanic 0:02dd72d1d465 1873 help='Extra reset method used to reset MUT by host test script. %s'% reset_methods_str)
borlanic 0:02dd72d1d465 1874
borlanic 0:02dd72d1d465 1875 parser.add_argument('-g', '--goanna-for-tests',
borlanic 0:02dd72d1d465 1876 dest='goanna_for_tests',
borlanic 0:02dd72d1d465 1877 action="store_true",
borlanic 0:02dd72d1d465 1878 help='Run Goanna static analyse tool for tests. (Project will be rebuilded)')
borlanic 0:02dd72d1d465 1879
borlanic 0:02dd72d1d465 1880 parser.add_argument('-G', '--goanna-for-sdk',
borlanic 0:02dd72d1d465 1881 dest='goanna_for_mbed_sdk',
borlanic 0:02dd72d1d465 1882 action="store_true",
borlanic 0:02dd72d1d465 1883 help='Run Goanna static analyse tool for mbed SDK (Project will be rebuilded)')
borlanic 0:02dd72d1d465 1884
borlanic 0:02dd72d1d465 1885 parser.add_argument('-s', '--suppress-summary',
borlanic 0:02dd72d1d465 1886 dest='suppress_summary',
borlanic 0:02dd72d1d465 1887 default=False,
borlanic 0:02dd72d1d465 1888 action="store_true",
borlanic 0:02dd72d1d465 1889 help='Suppresses display of wellformatted table with test results')
borlanic 0:02dd72d1d465 1890
borlanic 0:02dd72d1d465 1891 parser.add_argument('-t', '--test-summary',
borlanic 0:02dd72d1d465 1892 dest='test_x_toolchain_summary',
borlanic 0:02dd72d1d465 1893 default=False,
borlanic 0:02dd72d1d465 1894 action="store_true",
borlanic 0:02dd72d1d465 1895 help='Displays wellformatted table with test x toolchain test result per target')
borlanic 0:02dd72d1d465 1896
borlanic 0:02dd72d1d465 1897 parser.add_argument('-A', '--test-automation-report',
borlanic 0:02dd72d1d465 1898 dest='test_automation_report',
borlanic 0:02dd72d1d465 1899 default=False,
borlanic 0:02dd72d1d465 1900 action="store_true",
borlanic 0:02dd72d1d465 1901 help='Prints information about all tests and exits')
borlanic 0:02dd72d1d465 1902
borlanic 0:02dd72d1d465 1903 parser.add_argument('-R', '--test-case-report',
borlanic 0:02dd72d1d465 1904 dest='test_case_report',
borlanic 0:02dd72d1d465 1905 default=False,
borlanic 0:02dd72d1d465 1906 action="store_true",
borlanic 0:02dd72d1d465 1907 help='Prints information about all test cases and exits')
borlanic 0:02dd72d1d465 1908
borlanic 0:02dd72d1d465 1909 parser.add_argument("-S", "--supported-toolchains",
borlanic 0:02dd72d1d465 1910 action="store_true",
borlanic 0:02dd72d1d465 1911 dest="supported_toolchains",
borlanic 0:02dd72d1d465 1912 default=False,
borlanic 0:02dd72d1d465 1913 help="Displays supported matrix of MCUs and toolchains")
borlanic 0:02dd72d1d465 1914
borlanic 0:02dd72d1d465 1915 parser.add_argument("-O", "--only-build",
borlanic 0:02dd72d1d465 1916 action="store_true",
borlanic 0:02dd72d1d465 1917 dest="only_build_tests",
borlanic 0:02dd72d1d465 1918 default=False,
borlanic 0:02dd72d1d465 1919 help="Only build tests, skips actual test procedures (flashing etc.)")
borlanic 0:02dd72d1d465 1920
borlanic 0:02dd72d1d465 1921 parser.add_argument('--parallel',
borlanic 0:02dd72d1d465 1922 dest='parallel_test_exec',
borlanic 0:02dd72d1d465 1923 default=False,
borlanic 0:02dd72d1d465 1924 action="store_true",
borlanic 0:02dd72d1d465 1925 help='Experimental, you execute test runners for connected to your host MUTs in parallel (speeds up test result collection)')
borlanic 0:02dd72d1d465 1926
borlanic 0:02dd72d1d465 1927 parser.add_argument('--config',
borlanic 0:02dd72d1d465 1928 dest='verbose_test_configuration_only',
borlanic 0:02dd72d1d465 1929 default=False,
borlanic 0:02dd72d1d465 1930 action="store_true",
borlanic 0:02dd72d1d465 1931 help='Displays full test specification and MUTs configration and exits')
borlanic 0:02dd72d1d465 1932
borlanic 0:02dd72d1d465 1933 parser.add_argument('--loops',
borlanic 0:02dd72d1d465 1934 dest='test_loops_list',
borlanic 0:02dd72d1d465 1935 type=argparse_many(str),
borlanic 0:02dd72d1d465 1936 help='Set no. of loops per test. Format: TEST_1=1,TEST_2=2,TEST_3=3')
borlanic 0:02dd72d1d465 1937
borlanic 0:02dd72d1d465 1938 parser.add_argument('--global-loops',
borlanic 0:02dd72d1d465 1939 dest='test_global_loops_value',
borlanic 0:02dd72d1d465 1940 type=int,
borlanic 0:02dd72d1d465 1941 help='Set global number of test loops per test. Default value is set 1')
borlanic 0:02dd72d1d465 1942
borlanic 0:02dd72d1d465 1943 parser.add_argument('--consolidate-waterfall',
borlanic 0:02dd72d1d465 1944 dest='consolidate_waterfall_test',
borlanic 0:02dd72d1d465 1945 default=False,
borlanic 0:02dd72d1d465 1946 action="store_true",
borlanic 0:02dd72d1d465 1947 help='Used with --waterfall argument. Adds only one test to report reflecting outcome of waterfall test.')
borlanic 0:02dd72d1d465 1948
borlanic 0:02dd72d1d465 1949 parser.add_argument('-W', '--waterfall',
borlanic 0:02dd72d1d465 1950 dest='waterfall_test',
borlanic 0:02dd72d1d465 1951 default=False,
borlanic 0:02dd72d1d465 1952 action="store_true",
borlanic 0:02dd72d1d465 1953 help='Used with --loops or --global-loops arguments. Tests until OK result occurs and assumes test passed')
borlanic 0:02dd72d1d465 1954
borlanic 0:02dd72d1d465 1955 parser.add_argument('-N', '--firmware-name',
borlanic 0:02dd72d1d465 1956 dest='firmware_global_name',
borlanic 0:02dd72d1d465 1957 help='Set global name for all produced projects. Note, proper file extension will be added by buid scripts')
borlanic 0:02dd72d1d465 1958
borlanic 0:02dd72d1d465 1959 parser.add_argument('-u', '--shuffle',
borlanic 0:02dd72d1d465 1960 dest='shuffle_test_order',
borlanic 0:02dd72d1d465 1961 default=False,
borlanic 0:02dd72d1d465 1962 action="store_true",
borlanic 0:02dd72d1d465 1963 help='Shuffles test execution order')
borlanic 0:02dd72d1d465 1964
borlanic 0:02dd72d1d465 1965 parser.add_argument('--shuffle-seed',
borlanic 0:02dd72d1d465 1966 dest='shuffle_test_seed',
borlanic 0:02dd72d1d465 1967 default=None,
borlanic 0:02dd72d1d465 1968 help='Shuffle seed (If you want to reproduce your shuffle order please use seed provided in test summary)')
borlanic 0:02dd72d1d465 1969
borlanic 0:02dd72d1d465 1970 parser.add_argument('-f', '--filter',
borlanic 0:02dd72d1d465 1971 dest='general_filter_regex',
borlanic 0:02dd72d1d465 1972 type=argparse_many(str),
borlanic 0:02dd72d1d465 1973 default=None,
borlanic 0:02dd72d1d465 1974 help='For some commands you can use filter to filter out results')
borlanic 0:02dd72d1d465 1975
borlanic 0:02dd72d1d465 1976 parser.add_argument('--inc-timeout',
borlanic 0:02dd72d1d465 1977 dest='extend_test_timeout',
borlanic 0:02dd72d1d465 1978 metavar="NUMBER",
borlanic 0:02dd72d1d465 1979 type=int,
borlanic 0:02dd72d1d465 1980 help='You can increase global timeout for each test by specifying additional test timeout in seconds')
borlanic 0:02dd72d1d465 1981
borlanic 0:02dd72d1d465 1982 parser.add_argument('--db',
borlanic 0:02dd72d1d465 1983 dest='db_url',
borlanic 0:02dd72d1d465 1984 help='This specifies what database test suite uses to store its state. To pass DB connection info use database connection string. Example: \'mysql://username:password@127.0.0.1/db_name\'')
borlanic 0:02dd72d1d465 1985
borlanic 0:02dd72d1d465 1986 parser.add_argument('-l', '--log',
borlanic 0:02dd72d1d465 1987 dest='log_file_name',
borlanic 0:02dd72d1d465 1988 help='Log events to external file (note not all console entries may be visible in log file)')
borlanic 0:02dd72d1d465 1989
borlanic 0:02dd72d1d465 1990 parser.add_argument('--report-html',
borlanic 0:02dd72d1d465 1991 dest='report_html_file_name',
borlanic 0:02dd72d1d465 1992 help='You can log test suite results in form of HTML report')
borlanic 0:02dd72d1d465 1993
borlanic 0:02dd72d1d465 1994 parser.add_argument('--report-junit',
borlanic 0:02dd72d1d465 1995 dest='report_junit_file_name',
borlanic 0:02dd72d1d465 1996 help='You can log test suite results in form of JUnit compliant XML report')
borlanic 0:02dd72d1d465 1997
borlanic 0:02dd72d1d465 1998 parser.add_argument("--report-build",
borlanic 0:02dd72d1d465 1999 dest="report_build_file_name",
borlanic 0:02dd72d1d465 2000 help="Output the build results to a junit xml file")
borlanic 0:02dd72d1d465 2001
borlanic 0:02dd72d1d465 2002 parser.add_argument("--report-text",
borlanic 0:02dd72d1d465 2003 dest="report_text_file_name",
borlanic 0:02dd72d1d465 2004 help="Output the build results to a text file")
borlanic 0:02dd72d1d465 2005
borlanic 0:02dd72d1d465 2006 parser.add_argument('--verbose-skipped',
borlanic 0:02dd72d1d465 2007 dest='verbose_skipped_tests',
borlanic 0:02dd72d1d465 2008 default=False,
borlanic 0:02dd72d1d465 2009 action="store_true",
borlanic 0:02dd72d1d465 2010 help='Prints some extra information about skipped tests')
borlanic 0:02dd72d1d465 2011
borlanic 0:02dd72d1d465 2012 parser.add_argument('-V', '--verbose-test-result',
borlanic 0:02dd72d1d465 2013 dest='verbose_test_result_only',
borlanic 0:02dd72d1d465 2014 default=False,
borlanic 0:02dd72d1d465 2015 action="store_true",
borlanic 0:02dd72d1d465 2016 help='Prints test serial output')
borlanic 0:02dd72d1d465 2017
borlanic 0:02dd72d1d465 2018 parser.add_argument('-v', '--verbose',
borlanic 0:02dd72d1d465 2019 dest='verbose',
borlanic 0:02dd72d1d465 2020 default=False,
borlanic 0:02dd72d1d465 2021 action="store_true",
borlanic 0:02dd72d1d465 2022 help='Verbose mode (prints some extra information)')
borlanic 0:02dd72d1d465 2023
borlanic 0:02dd72d1d465 2024 parser.add_argument('--version',
borlanic 0:02dd72d1d465 2025 dest='version',
borlanic 0:02dd72d1d465 2026 default=False,
borlanic 0:02dd72d1d465 2027 action="store_true",
borlanic 0:02dd72d1d465 2028 help='Prints script version and exits')
borlanic 0:02dd72d1d465 2029
borlanic 0:02dd72d1d465 2030 parser.add_argument('--stats-depth',
borlanic 0:02dd72d1d465 2031 dest='stats_depth',
borlanic 0:02dd72d1d465 2032 default=2,
borlanic 0:02dd72d1d465 2033 type=int,
borlanic 0:02dd72d1d465 2034 help="Depth level for static memory report")
borlanic 0:02dd72d1d465 2035 return parser
borlanic 0:02dd72d1d465 2036
borlanic 0:02dd72d1d465 2037 def test_path_to_name(path, base):
borlanic 0:02dd72d1d465 2038 """Change all slashes in a path into hyphens
borlanic 0:02dd72d1d465 2039 This creates a unique cross-platform test name based on the path
borlanic 0:02dd72d1d465 2040 This can eventually be overriden by a to-be-determined meta-data mechanism"""
borlanic 0:02dd72d1d465 2041 name_parts = []
borlanic 0:02dd72d1d465 2042 head, tail = os.path.split(relpath(path,base))
borlanic 0:02dd72d1d465 2043 while (tail and tail != "."):
borlanic 0:02dd72d1d465 2044 name_parts.insert(0, tail)
borlanic 0:02dd72d1d465 2045 head, tail = os.path.split(head)
borlanic 0:02dd72d1d465 2046
borlanic 0:02dd72d1d465 2047 return "-".join(name_parts).lower()
borlanic 0:02dd72d1d465 2048
borlanic 0:02dd72d1d465 2049 def get_test_config(config_name, target_name):
borlanic 0:02dd72d1d465 2050 """Finds the path to a test configuration file
borlanic 0:02dd72d1d465 2051 config_name: path to a custom configuration file OR mbed OS interface "ethernet, wifi_odin, etc"
borlanic 0:02dd72d1d465 2052 target_name: name of target to determing if mbed OS interface given is valid
borlanic 0:02dd72d1d465 2053 returns path to config, will return None if no valid config is found
borlanic 0:02dd72d1d465 2054 """
borlanic 0:02dd72d1d465 2055 # If they passed in a full path
borlanic 0:02dd72d1d465 2056 if exists(config_name):
borlanic 0:02dd72d1d465 2057 # This is a module config
borlanic 0:02dd72d1d465 2058 return config_name
borlanic 0:02dd72d1d465 2059 # Otherwise find the path to configuration file based on mbed OS interface
borlanic 0:02dd72d1d465 2060 return TestConfig.get_config_path(config_name, target_name)
borlanic 0:02dd72d1d465 2061
borlanic 0:02dd72d1d465 2062 def find_tests(base_dir, target_name, toolchain_name, app_config=None):
borlanic 0:02dd72d1d465 2063 """ Finds all tests in a directory recursively
borlanic 0:02dd72d1d465 2064 base_dir: path to the directory to scan for tests (ex. 'path/to/project')
borlanic 0:02dd72d1d465 2065 target_name: name of the target to use for scanning (ex. 'K64F')
borlanic 0:02dd72d1d465 2066 toolchain_name: name of the toolchain to use for scanning (ex. 'GCC_ARM')
borlanic 0:02dd72d1d465 2067 options: Compile options to pass to the toolchain (ex. ['debug-info'])
borlanic 0:02dd72d1d465 2068 app_config - location of a chosen mbed_app.json file
borlanic 0:02dd72d1d465 2069
borlanic 0:02dd72d1d465 2070 returns a dictionary where keys are the test name, and the values are
borlanic 0:02dd72d1d465 2071 lists of paths needed to biuld the test.
borlanic 0:02dd72d1d465 2072 """
borlanic 0:02dd72d1d465 2073
borlanic 0:02dd72d1d465 2074 # Temporary structure: tests referenced by (name, base, group, case) tuple
borlanic 0:02dd72d1d465 2075 tests = {}
borlanic 0:02dd72d1d465 2076 # List of common folders: (predicate function, path) tuple
borlanic 0:02dd72d1d465 2077 commons = []
borlanic 0:02dd72d1d465 2078
borlanic 0:02dd72d1d465 2079 # Prepare the toolchain
borlanic 0:02dd72d1d465 2080 toolchain = prepare_toolchain([base_dir], None, target_name, toolchain_name,
borlanic 0:02dd72d1d465 2081 silent=True, app_config=app_config)
borlanic 0:02dd72d1d465 2082
borlanic 0:02dd72d1d465 2083 # Scan the directory for paths to probe for 'TESTS' folders
borlanic 0:02dd72d1d465 2084 base_resources = scan_resources([base_dir], toolchain)
borlanic 0:02dd72d1d465 2085
borlanic 0:02dd72d1d465 2086 dirs = base_resources.inc_dirs
borlanic 0:02dd72d1d465 2087 for directory in dirs:
borlanic 0:02dd72d1d465 2088 subdirs = os.listdir(directory)
borlanic 0:02dd72d1d465 2089
borlanic 0:02dd72d1d465 2090 # If the directory contains a subdirectory called 'TESTS', scan it for test cases
borlanic 0:02dd72d1d465 2091 if 'TESTS' in subdirs:
borlanic 0:02dd72d1d465 2092 walk_base_dir = join(directory, 'TESTS')
borlanic 0:02dd72d1d465 2093 test_resources = toolchain.scan_resources(walk_base_dir, base_path=base_dir)
borlanic 0:02dd72d1d465 2094
borlanic 0:02dd72d1d465 2095 # Loop through all subdirectories
borlanic 0:02dd72d1d465 2096 for d in test_resources.inc_dirs:
borlanic 0:02dd72d1d465 2097
borlanic 0:02dd72d1d465 2098 # If the test case folder is not called 'host_tests' or 'COMMON' and it is
borlanic 0:02dd72d1d465 2099 # located two folders down from the main 'TESTS' folder (ex. TESTS/testgroup/testcase)
borlanic 0:02dd72d1d465 2100 # then add it to the tests
borlanic 0:02dd72d1d465 2101 relative_path = relpath(d, walk_base_dir)
borlanic 0:02dd72d1d465 2102 relative_path_parts = os.path.normpath(relative_path).split(os.sep)
borlanic 0:02dd72d1d465 2103 if len(relative_path_parts) == 2:
borlanic 0:02dd72d1d465 2104 test_group_directory_path, test_case_directory = os.path.split(d)
borlanic 0:02dd72d1d465 2105 test_group_directory = os.path.basename(test_group_directory_path)
borlanic 0:02dd72d1d465 2106
borlanic 0:02dd72d1d465 2107 # Check to make sure discoverd folder is not in a host test directory or common directory
borlanic 0:02dd72d1d465 2108 special_dirs = ['host_tests', 'COMMON']
borlanic 0:02dd72d1d465 2109 if test_group_directory not in special_dirs and test_case_directory not in special_dirs:
borlanic 0:02dd72d1d465 2110 test_name = test_path_to_name(d, base_dir)
borlanic 0:02dd72d1d465 2111 tests[(test_name, walk_base_dir, test_group_directory, test_case_directory)] = [d]
borlanic 0:02dd72d1d465 2112
borlanic 0:02dd72d1d465 2113 # Also find any COMMON paths, we'll add these later once we find all the base tests
borlanic 0:02dd72d1d465 2114 if 'COMMON' in relative_path_parts:
borlanic 0:02dd72d1d465 2115 if relative_path_parts[0] != 'COMMON':
borlanic 0:02dd72d1d465 2116 def predicate(base_pred, group_pred, (name, base, group, case)):
borlanic 0:02dd72d1d465 2117 return base == base_pred and group == group_pred
borlanic 0:02dd72d1d465 2118 commons.append((functools.partial(predicate, walk_base_dir, relative_path_parts[0]), d))
borlanic 0:02dd72d1d465 2119 else:
borlanic 0:02dd72d1d465 2120 def predicate(base_pred, (name, base, group, case)):
borlanic 0:02dd72d1d465 2121 return base == base_pred
borlanic 0:02dd72d1d465 2122 commons.append((functools.partial(predicate, walk_base_dir), d))
borlanic 0:02dd72d1d465 2123
borlanic 0:02dd72d1d465 2124 # Apply common directories
borlanic 0:02dd72d1d465 2125 for pred, path in commons:
borlanic 0:02dd72d1d465 2126 for test_identity, test_paths in tests.iteritems():
borlanic 0:02dd72d1d465 2127 if pred(test_identity):
borlanic 0:02dd72d1d465 2128 test_paths.append(path)
borlanic 0:02dd72d1d465 2129
borlanic 0:02dd72d1d465 2130 # Drop identity besides name
borlanic 0:02dd72d1d465 2131 return {name: paths for (name, _, _, _), paths in tests.iteritems()}
borlanic 0:02dd72d1d465 2132
borlanic 0:02dd72d1d465 2133 def print_tests(tests, format="list", sort=True):
borlanic 0:02dd72d1d465 2134 """Given a dictionary of tests (as returned from "find_tests"), print them
borlanic 0:02dd72d1d465 2135 in the specified format"""
borlanic 0:02dd72d1d465 2136 if format == "list":
borlanic 0:02dd72d1d465 2137 for test_name in sorted(tests.keys()):
borlanic 0:02dd72d1d465 2138 test_path = tests[test_name][0]
borlanic 0:02dd72d1d465 2139 print("Test Case:")
borlanic 0:02dd72d1d465 2140 print(" Name: %s" % test_name)
borlanic 0:02dd72d1d465 2141 print(" Path: %s" % test_path)
borlanic 0:02dd72d1d465 2142 elif format == "json":
borlanic 0:02dd72d1d465 2143 print(json.dumps({test_name: test_path[0] for test_name, test_paths
borlanic 0:02dd72d1d465 2144 in tests}, indent=2))
borlanic 0:02dd72d1d465 2145 else:
borlanic 0:02dd72d1d465 2146 print("Unknown format '%s'" % format)
borlanic 0:02dd72d1d465 2147 sys.exit(1)
borlanic 0:02dd72d1d465 2148
borlanic 0:02dd72d1d465 2149 def norm_relative_path(path, start):
borlanic 0:02dd72d1d465 2150 """This function will create a normalized, relative path. It mimics the
borlanic 0:02dd72d1d465 2151 python os.path.relpath function, but also normalizes a Windows-syle path
borlanic 0:02dd72d1d465 2152 that use backslashes to a Unix style path that uses forward slashes."""
borlanic 0:02dd72d1d465 2153 path = os.path.normpath(path)
borlanic 0:02dd72d1d465 2154 path = os.path.relpath(path, start)
borlanic 0:02dd72d1d465 2155 path = path.replace("\\", "/")
borlanic 0:02dd72d1d465 2156 return path
borlanic 0:02dd72d1d465 2157
borlanic 0:02dd72d1d465 2158
borlanic 0:02dd72d1d465 2159 def build_test_worker(*args, **kwargs):
borlanic 0:02dd72d1d465 2160 """This is a worker function for the parallel building of tests. The `args`
borlanic 0:02dd72d1d465 2161 and `kwargs` are passed directly to `build_project`. It returns a dictionary
borlanic 0:02dd72d1d465 2162 with the following structure:
borlanic 0:02dd72d1d465 2163
borlanic 0:02dd72d1d465 2164 {
borlanic 0:02dd72d1d465 2165 'result': `True` if no exceptions were thrown, `False` otherwise
borlanic 0:02dd72d1d465 2166 'reason': Instance of exception that was thrown on failure
borlanic 0:02dd72d1d465 2167 'bin_file': Path to the created binary if `build_project` was
borlanic 0:02dd72d1d465 2168 successful. Not present otherwise
borlanic 0:02dd72d1d465 2169 'kwargs': The keyword arguments that were passed to `build_project`.
borlanic 0:02dd72d1d465 2170 This includes arguments that were modified (ex. report)
borlanic 0:02dd72d1d465 2171 }
borlanic 0:02dd72d1d465 2172 """
borlanic 0:02dd72d1d465 2173 bin_file = None
borlanic 0:02dd72d1d465 2174 ret = {
borlanic 0:02dd72d1d465 2175 'result': False,
borlanic 0:02dd72d1d465 2176 'args': args,
borlanic 0:02dd72d1d465 2177 'kwargs': kwargs
borlanic 0:02dd72d1d465 2178 }
borlanic 0:02dd72d1d465 2179
borlanic 0:02dd72d1d465 2180 # Use parent TOOLCHAIN_PATHS variable
borlanic 0:02dd72d1d465 2181 for key, value in kwargs['toolchain_paths'].items():
borlanic 0:02dd72d1d465 2182 TOOLCHAIN_PATHS[key] = value
borlanic 0:02dd72d1d465 2183
borlanic 0:02dd72d1d465 2184 del kwargs['toolchain_paths']
borlanic 0:02dd72d1d465 2185
borlanic 0:02dd72d1d465 2186 try:
borlanic 0:02dd72d1d465 2187 bin_file = build_project(*args, **kwargs)
borlanic 0:02dd72d1d465 2188 ret['result'] = True
borlanic 0:02dd72d1d465 2189 ret['bin_file'] = bin_file
borlanic 0:02dd72d1d465 2190 ret['kwargs'] = kwargs
borlanic 0:02dd72d1d465 2191
borlanic 0:02dd72d1d465 2192 except NotSupportedException as e:
borlanic 0:02dd72d1d465 2193 ret['reason'] = e
borlanic 0:02dd72d1d465 2194 except ToolException as e:
borlanic 0:02dd72d1d465 2195 ret['reason'] = e
borlanic 0:02dd72d1d465 2196 except KeyboardInterrupt as e:
borlanic 0:02dd72d1d465 2197 ret['reason'] = e
borlanic 0:02dd72d1d465 2198 except:
borlanic 0:02dd72d1d465 2199 # Print unhandled exceptions here
borlanic 0:02dd72d1d465 2200 import traceback
borlanic 0:02dd72d1d465 2201 traceback.print_exc(file=sys.stdout)
borlanic 0:02dd72d1d465 2202
borlanic 0:02dd72d1d465 2203 return ret
borlanic 0:02dd72d1d465 2204
borlanic 0:02dd72d1d465 2205
borlanic 0:02dd72d1d465 2206 def build_tests(tests, base_source_paths, build_path, target, toolchain_name,
borlanic 0:02dd72d1d465 2207 clean=False, notify=None, verbose=False, jobs=1, macros=None,
borlanic 0:02dd72d1d465 2208 silent=False, report=None, properties=None,
borlanic 0:02dd72d1d465 2209 continue_on_build_fail=False, app_config=None,
borlanic 0:02dd72d1d465 2210 build_profile=None, stats_depth=None):
borlanic 0:02dd72d1d465 2211 """Given the data structure from 'find_tests' and the typical build parameters,
borlanic 0:02dd72d1d465 2212 build all the tests
borlanic 0:02dd72d1d465 2213
borlanic 0:02dd72d1d465 2214 Returns a tuple of the build result (True or False) followed by the test
borlanic 0:02dd72d1d465 2215 build data structure"""
borlanic 0:02dd72d1d465 2216
borlanic 0:02dd72d1d465 2217 execution_directory = "."
borlanic 0:02dd72d1d465 2218 base_path = norm_relative_path(build_path, execution_directory)
borlanic 0:02dd72d1d465 2219
borlanic 0:02dd72d1d465 2220 target_name = target.name if isinstance(target, Target) else target
borlanic 0:02dd72d1d465 2221 cfg, _, _ = get_config(base_source_paths, target_name, toolchain_name)
borlanic 0:02dd72d1d465 2222
borlanic 0:02dd72d1d465 2223 baud_rate = 9600
borlanic 0:02dd72d1d465 2224 if 'platform.stdio-baud-rate' in cfg:
borlanic 0:02dd72d1d465 2225 baud_rate = cfg['platform.stdio-baud-rate'].value
borlanic 0:02dd72d1d465 2226
borlanic 0:02dd72d1d465 2227 test_build = {
borlanic 0:02dd72d1d465 2228 "platform": target_name,
borlanic 0:02dd72d1d465 2229 "toolchain": toolchain_name,
borlanic 0:02dd72d1d465 2230 "base_path": base_path,
borlanic 0:02dd72d1d465 2231 "baud_rate": baud_rate,
borlanic 0:02dd72d1d465 2232 "binary_type": "bootable",
borlanic 0:02dd72d1d465 2233 "tests": {}
borlanic 0:02dd72d1d465 2234 }
borlanic 0:02dd72d1d465 2235
borlanic 0:02dd72d1d465 2236 result = True
borlanic 0:02dd72d1d465 2237
borlanic 0:02dd72d1d465 2238 jobs_count = int(jobs if jobs else cpu_count())
borlanic 0:02dd72d1d465 2239 p = Pool(processes=jobs_count)
borlanic 0:02dd72d1d465 2240 results = []
borlanic 0:02dd72d1d465 2241 for test_name, test_paths in tests.items():
borlanic 0:02dd72d1d465 2242 if not isinstance(test_paths, list):
borlanic 0:02dd72d1d465 2243 test_paths = [test_paths]
borlanic 0:02dd72d1d465 2244
borlanic 0:02dd72d1d465 2245 test_build_path = os.path.join(build_path, test_paths[0])
borlanic 0:02dd72d1d465 2246 src_paths = base_source_paths + test_paths
borlanic 0:02dd72d1d465 2247 bin_file = None
borlanic 0:02dd72d1d465 2248 test_case_folder_name = os.path.basename(test_paths[0])
borlanic 0:02dd72d1d465 2249
borlanic 0:02dd72d1d465 2250 args = (src_paths, test_build_path, target, toolchain_name)
borlanic 0:02dd72d1d465 2251 kwargs = {
borlanic 0:02dd72d1d465 2252 'jobs': 1,
borlanic 0:02dd72d1d465 2253 'clean': clean,
borlanic 0:02dd72d1d465 2254 'macros': macros,
borlanic 0:02dd72d1d465 2255 'name': test_case_folder_name,
borlanic 0:02dd72d1d465 2256 'project_id': test_name,
borlanic 0:02dd72d1d465 2257 'report': report,
borlanic 0:02dd72d1d465 2258 'properties': properties,
borlanic 0:02dd72d1d465 2259 'verbose': verbose,
borlanic 0:02dd72d1d465 2260 'app_config': app_config,
borlanic 0:02dd72d1d465 2261 'build_profile': build_profile,
borlanic 0:02dd72d1d465 2262 'silent': True,
borlanic 0:02dd72d1d465 2263 'toolchain_paths': TOOLCHAIN_PATHS,
borlanic 0:02dd72d1d465 2264 'stats_depth': stats_depth
borlanic 0:02dd72d1d465 2265 }
borlanic 0:02dd72d1d465 2266
borlanic 0:02dd72d1d465 2267 results.append(p.apply_async(build_test_worker, args, kwargs))
borlanic 0:02dd72d1d465 2268
borlanic 0:02dd72d1d465 2269 p.close()
borlanic 0:02dd72d1d465 2270 result = True
borlanic 0:02dd72d1d465 2271 itr = 0
borlanic 0:02dd72d1d465 2272 while len(results):
borlanic 0:02dd72d1d465 2273 itr += 1
borlanic 0:02dd72d1d465 2274 if itr > 360000:
borlanic 0:02dd72d1d465 2275 p.terminate()
borlanic 0:02dd72d1d465 2276 p.join()
borlanic 0:02dd72d1d465 2277 raise ToolException("Compile did not finish in 10 minutes")
borlanic 0:02dd72d1d465 2278 else:
borlanic 0:02dd72d1d465 2279 sleep(0.01)
borlanic 0:02dd72d1d465 2280 pending = 0
borlanic 0:02dd72d1d465 2281 for r in results:
borlanic 0:02dd72d1d465 2282 if r.ready() is True:
borlanic 0:02dd72d1d465 2283 try:
borlanic 0:02dd72d1d465 2284 worker_result = r.get()
borlanic 0:02dd72d1d465 2285 results.remove(r)
borlanic 0:02dd72d1d465 2286
borlanic 0:02dd72d1d465 2287 # Take report from the kwargs and merge it into existing report
borlanic 0:02dd72d1d465 2288 if report:
borlanic 0:02dd72d1d465 2289 report_entry = worker_result['kwargs']['report'][target_name][toolchain_name]
borlanic 0:02dd72d1d465 2290 for test_key in report_entry.keys():
borlanic 0:02dd72d1d465 2291 report[target_name][toolchain_name][test_key] = report_entry[test_key]
borlanic 0:02dd72d1d465 2292
borlanic 0:02dd72d1d465 2293 # Set the overall result to a failure if a build failure occurred
borlanic 0:02dd72d1d465 2294 if ('reason' in worker_result and
borlanic 0:02dd72d1d465 2295 not worker_result['reason'] and
borlanic 0:02dd72d1d465 2296 not isinstance(worker_result['reason'], NotSupportedException)):
borlanic 0:02dd72d1d465 2297 result = False
borlanic 0:02dd72d1d465 2298 break
borlanic 0:02dd72d1d465 2299
borlanic 0:02dd72d1d465 2300 # Adding binary path to test build result
borlanic 0:02dd72d1d465 2301 if ('result' in worker_result and
borlanic 0:02dd72d1d465 2302 worker_result['result'] and
borlanic 0:02dd72d1d465 2303 'bin_file' in worker_result):
borlanic 0:02dd72d1d465 2304 bin_file = norm_relative_path(worker_result['bin_file'], execution_directory)
borlanic 0:02dd72d1d465 2305
borlanic 0:02dd72d1d465 2306 test_build['tests'][worker_result['kwargs']['project_id']] = {
borlanic 0:02dd72d1d465 2307 "binaries": [
borlanic 0:02dd72d1d465 2308 {
borlanic 0:02dd72d1d465 2309 "path": bin_file
borlanic 0:02dd72d1d465 2310 }
borlanic 0:02dd72d1d465 2311 ]
borlanic 0:02dd72d1d465 2312 }
borlanic 0:02dd72d1d465 2313
borlanic 0:02dd72d1d465 2314 test_key = worker_result['kwargs']['project_id'].upper()
borlanic 0:02dd72d1d465 2315 if report:
borlanic 0:02dd72d1d465 2316 print(report[target_name][toolchain_name][test_key][0][0]['output'].rstrip())
borlanic 0:02dd72d1d465 2317 print('Image: %s\n' % bin_file)
borlanic 0:02dd72d1d465 2318
borlanic 0:02dd72d1d465 2319 except:
borlanic 0:02dd72d1d465 2320 if p._taskqueue.queue:
borlanic 0:02dd72d1d465 2321 p._taskqueue.queue.clear()
borlanic 0:02dd72d1d465 2322 sleep(0.5)
borlanic 0:02dd72d1d465 2323 p.terminate()
borlanic 0:02dd72d1d465 2324 p.join()
borlanic 0:02dd72d1d465 2325 raise
borlanic 0:02dd72d1d465 2326 else:
borlanic 0:02dd72d1d465 2327 pending += 1
borlanic 0:02dd72d1d465 2328 if pending >= jobs_count:
borlanic 0:02dd72d1d465 2329 break
borlanic 0:02dd72d1d465 2330
borlanic 0:02dd72d1d465 2331 # Break as soon as possible if there is a failure and we are not
borlanic 0:02dd72d1d465 2332 # continuing on build failures
borlanic 0:02dd72d1d465 2333 if not result and not continue_on_build_fail:
borlanic 0:02dd72d1d465 2334 if p._taskqueue.queue:
borlanic 0:02dd72d1d465 2335 p._taskqueue.queue.clear()
borlanic 0:02dd72d1d465 2336 sleep(0.5)
borlanic 0:02dd72d1d465 2337 p.terminate()
borlanic 0:02dd72d1d465 2338 break
borlanic 0:02dd72d1d465 2339
borlanic 0:02dd72d1d465 2340 p.join()
borlanic 0:02dd72d1d465 2341
borlanic 0:02dd72d1d465 2342 test_builds = {}
borlanic 0:02dd72d1d465 2343 test_builds["%s-%s" % (target_name, toolchain_name)] = test_build
borlanic 0:02dd72d1d465 2344
borlanic 0:02dd72d1d465 2345 return result, test_builds
borlanic 0:02dd72d1d465 2346
borlanic 0:02dd72d1d465 2347
borlanic 0:02dd72d1d465 2348 def test_spec_from_test_builds(test_builds):
borlanic 0:02dd72d1d465 2349 return {
borlanic 0:02dd72d1d465 2350 "builds": test_builds
borlanic 0:02dd72d1d465 2351 }