2015-04-22 22:23:19 +00:00
|
|
|
#!/usr/bin/env python2
|
2014-06-04 15:11:54 +00:00
|
|
|
|
2014-02-24 10:49:22 +00:00
|
|
|
"""
|
|
|
|
mbed SDK
|
2014-07-25 16:37:16 +00:00
|
|
|
Copyright (c) 2011-2014 ARM Limited
|
2014-02-24 10:49:22 +00:00
|
|
|
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
you may not use this file except in compliance with the License.
|
|
|
|
You may obtain a copy of the License at
|
|
|
|
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
See the License for the specific language governing permissions and
|
|
|
|
limitations under the License.
|
|
|
|
|
2014-08-19 15:24:33 +00:00
|
|
|
Author: Przemyslaw Wirkus <Przemyslaw.Wirkus@arm.com>
|
2014-08-18 14:33:24 +00:00
|
|
|
"""
|
2014-02-24 10:49:22 +00:00
|
|
|
|
2014-08-18 14:33:24 +00:00
|
|
|
"""
|
|
|
|
File format example: test_spec.json:
|
2014-03-12 10:59:19 +00:00
|
|
|
{
|
|
|
|
"targets": {
|
|
|
|
"KL46Z": ["ARM", "GCC_ARM"],
|
2016-02-11 05:27:33 +00:00
|
|
|
"LPC1768": ["ARM", "GCC_ARM", "GCC_CR", "IAR"],
|
2014-03-12 10:59:19 +00:00
|
|
|
"LPC11U24": ["uARM"],
|
|
|
|
"NRF51822": ["ARM"]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-08-18 14:33:24 +00:00
|
|
|
File format example: muts_all.json:
|
2014-03-12 10:59:19 +00:00
|
|
|
{
|
|
|
|
"1" : {"mcu": "LPC1768",
|
2014-08-05 08:32:44 +00:00
|
|
|
"port":"COM4",
|
|
|
|
"disk":"J:\\",
|
|
|
|
"peripherals": ["TMP102", "digital_loop", "port_loop", "analog_loop", "SD"]
|
2014-03-12 10:59:19 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
"2" : {"mcu": "KL25Z",
|
2014-08-05 08:32:44 +00:00
|
|
|
"port":"COM7",
|
|
|
|
"disk":"G:\\",
|
|
|
|
"peripherals": ["digital_loop", "port_loop", "analog_loop"]
|
2014-02-24 10:49:22 +00:00
|
|
|
}
|
2014-03-12 10:59:19 +00:00
|
|
|
}
|
2014-02-24 10:49:22 +00:00
|
|
|
"""
|
|
|
|
|
2014-08-18 14:33:24 +00:00
|
|
|
|
2014-10-08 14:15:11 +00:00
|
|
|
# Be sure that the tools directory is in the search path
|
2014-02-24 10:49:22 +00:00
|
|
|
import sys
|
2014-08-04 13:29:20 +00:00
|
|
|
from os.path import join, abspath, dirname
|
2014-03-13 11:32:55 +00:00
|
|
|
|
2014-02-24 10:49:22 +00:00
|
|
|
ROOT = abspath(join(dirname(__file__), ".."))
|
|
|
|
sys.path.insert(0, ROOT)
|
2014-06-09 15:10:47 +00:00
|
|
|
|
2014-10-08 14:15:11 +00:00
|
|
|
|
|
|
|
# Check: Extra modules which are required by core test suite
|
2016-06-09 20:34:53 +00:00
|
|
|
from tools.utils import check_required_modules
|
2014-10-16 13:34:11 +00:00
|
|
|
check_required_modules(['prettytable', 'serial'])
|
2014-10-08 14:15:11 +00:00
|
|
|
|
2014-08-04 13:29:20 +00:00
|
|
|
# Imports related to mbed build api
|
2016-06-09 20:34:53 +00:00
|
|
|
from tools.build_api import mcu_toolchain_matrix
|
2014-06-03 16:35:53 +00:00
|
|
|
|
2014-08-04 13:29:20 +00:00
|
|
|
# Imports from TEST API
|
2016-06-09 20:34:53 +00:00
|
|
|
from tools.test_api import SingleTestRunner
|
|
|
|
from tools.test_api import singletest_in_cli_mode
|
|
|
|
from tools.test_api import detect_database_verbose
|
|
|
|
from tools.test_api import get_json_data_from_file
|
|
|
|
from tools.test_api import get_avail_tests_summary_table
|
|
|
|
from tools.test_api import get_default_test_options_parser
|
|
|
|
from tools.test_api import print_muts_configuration_from_json
|
|
|
|
from tools.test_api import print_test_configuration_from_json
|
|
|
|
from tools.test_api import get_autodetected_MUTS_list
|
|
|
|
from tools.test_api import get_autodetected_TEST_SPEC
|
|
|
|
from tools.test_api import get_module_avail
|
|
|
|
from tools.test_exporters import ReportExporter, ResultExporterType
|
2015-05-26 14:59:07 +00:00
|
|
|
|
|
|
|
|
2015-02-10 21:18:17 +00:00
|
|
|
# Importing extra modules which can be not installed but if available they can extend test suite functionality
|
|
|
|
try:
|
|
|
|
import mbed_lstools
|
2016-06-09 20:34:53 +00:00
|
|
|
from tools.compliance.ioper_runner import IOperTestRunner
|
|
|
|
from tools.compliance.ioper_runner import get_available_oper_test_scopes
|
2015-02-10 21:18:17 +00:00
|
|
|
except:
|
|
|
|
pass
|
2014-07-30 17:11:19 +00:00
|
|
|
|
|
|
|
def get_version():
|
2014-08-12 12:24:04 +00:00
|
|
|
""" Returns test script version
|
|
|
|
"""
|
2014-08-04 15:16:47 +00:00
|
|
|
single_test_version_major = 1
|
2015-05-03 01:34:31 +00:00
|
|
|
single_test_version_minor = 5
|
2014-08-04 15:16:47 +00:00
|
|
|
return (single_test_version_major, single_test_version_minor)
|
2014-07-30 17:11:19 +00:00
|
|
|
|
2014-02-24 10:49:22 +00:00
|
|
|
|
|
|
|
if __name__ == '__main__':
|
2014-02-27 12:59:57 +00:00
|
|
|
# Command line options
|
2014-08-04 14:57:59 +00:00
|
|
|
parser = get_default_test_options_parser()
|
2014-02-27 12:59:57 +00:00
|
|
|
|
2014-02-27 16:47:53 +00:00
|
|
|
parser.description = """This script allows you to run mbed defined test cases for particular MCU(s) and corresponding toolchain(s)."""
|
2014-04-09 12:00:45 +00:00
|
|
|
parser.epilog = """Example: singletest.py -i test_spec.json -M muts_all.json"""
|
2014-02-27 16:47:53 +00:00
|
|
|
|
2016-06-24 22:15:01 +00:00
|
|
|
opts = parser.parse_args()
|
2014-02-24 10:49:22 +00:00
|
|
|
|
2014-08-07 10:48:21 +00:00
|
|
|
# Print scrip version
|
|
|
|
if opts.version:
|
|
|
|
print parser.description
|
|
|
|
print parser.epilog
|
|
|
|
print "Version %d.%d"% get_version()
|
|
|
|
exit(0)
|
|
|
|
|
2014-11-21 13:55:53 +00:00
|
|
|
if opts.db_url and opts.verbose_test_configuration_only:
|
|
|
|
detect_database_verbose(opts.db_url)
|
|
|
|
exit(0)
|
2014-10-20 09:51:02 +00:00
|
|
|
|
2014-04-07 10:59:33 +00:00
|
|
|
# Print summary / information about automation test status
|
|
|
|
if opts.test_automation_report:
|
2014-10-20 09:51:02 +00:00
|
|
|
print get_avail_tests_summary_table(platform_filter=opts.general_filter_regex)
|
2014-08-18 14:33:24 +00:00
|
|
|
exit(0)
|
|
|
|
|
2014-07-02 11:02:36 +00:00
|
|
|
# Print summary / information about automation test status
|
|
|
|
if opts.test_case_report:
|
2014-10-20 09:51:02 +00:00
|
|
|
test_case_report_cols = ['id',
|
|
|
|
'automated',
|
|
|
|
'description',
|
|
|
|
'peripherals',
|
|
|
|
'host_test',
|
|
|
|
'duration',
|
|
|
|
'source_dir']
|
|
|
|
print get_avail_tests_summary_table(cols=test_case_report_cols,
|
|
|
|
result_summary=False,
|
|
|
|
join_delim='\n',
|
|
|
|
platform_filter=opts.general_filter_regex)
|
2014-04-07 10:59:33 +00:00
|
|
|
exit(0)
|
|
|
|
|
2014-06-09 15:10:47 +00:00
|
|
|
# Only prints matrix of supported toolchains
|
|
|
|
if opts.supported_toolchains:
|
2014-07-29 13:48:48 +00:00
|
|
|
print mcu_toolchain_matrix(platform_filter=opts.general_filter_regex)
|
2014-06-09 15:10:47 +00:00
|
|
|
exit(0)
|
|
|
|
|
2015-02-10 21:18:17 +00:00
|
|
|
test_spec = None
|
|
|
|
MUTs = None
|
|
|
|
|
Bugfix for IOTSFW-345:
Adde missing check for optional auto_detect parameter in CLI options.
Test procedure:
* Check with mbed-ls installed:
$ singletest.py --auto -j 8
MBEDLS: Detecting connected mbed-enabled devices...
MBEDLS: Detected K64F, port: COM61, mounted: E:
Building library CMSIS (K64F, ARM)
Copy: startup_MK64F12.o
Copy: sys.o
Copy: cmsis_nvic.o
Copy: system_MK64F12.o
* Uninstall mbed-ls iools:
$ pip uninstall mbed-ls
Uninstalling mbed-ls:
c:\python27\lib\site-packages\mbed_ls-0.1.4-py2.7.egg
c:\python27\scripts\mbedls-script.py
c:\python27\scripts\mbedls.exe
c:\python27\scripts\mbedls.exe.manifest
Proceed (y/n)? y
Successfully uninstalled mbed-ls
$ mbedls
'mbedls' is not recognized as an internal or external command,
operable program or batch file.
$ python
Python 2.7.8 (default, Jun 30 2014, 16:03:49) [MSC v.1500 32 bit (Intel)] win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import mbed_lstools
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named mbed_lstools
* Check singletest.py work flow without mbed-ls:
$ singletest.py -i test_spec.json -M muts_all.json
Building library CMSIS (K64F, ARM)
Building library MBED (K64F, ARM)
Building project DETECT (K64F, ARM)
TargetTest::K64F::ARM::DTCT_1::Simple detect test [OK] in 0.50 of 10 sec
Building project DEV_NULL (K64F, ARM)
TargetTest::K64F::ARM::EXAMPLE_1::/dev/null [OK] in 3.49 of 20 sec
Building project HELLO (K64F, ARM)
TargetTest::K64F::ARM::MBED_10::Hello World [OK] in 0.38 of 5 sec
Building project TICKER (K64F, ARM)
TargetTest::K64F::ARM::MBED_11::Ticker Int [OK] in 11.35 of 15 sec
2015-02-19 11:16:41 +00:00
|
|
|
if hasattr(opts, 'auto_detect') and opts.auto_detect:
|
|
|
|
# If auto_detect attribute is present, we assume other auto-detection
|
|
|
|
# parameters like 'toolchains_filter' are also set.
|
2015-02-10 21:50:56 +00:00
|
|
|
print "MBEDLS: Detecting connected mbed-enabled devices... "
|
2015-02-10 21:18:17 +00:00
|
|
|
|
2015-09-23 15:54:41 +00:00
|
|
|
MUTs = get_autodetected_MUTS_list()
|
|
|
|
|
|
|
|
for mut in MUTs.values():
|
|
|
|
print "MBEDLS: Detected %s, port: %s, mounted: %s"% (mut['mcu_unique'] if 'mcu_unique' in mut else mut['mcu'],
|
|
|
|
mut['port'],
|
|
|
|
mut['disk'])
|
2015-02-10 21:18:17 +00:00
|
|
|
|
2015-02-10 21:50:56 +00:00
|
|
|
# Set up parameters for test specification filter function (we need to set toolchains per target here)
|
2016-06-24 22:15:01 +00:00
|
|
|
use_default_toolchain = 'default' in opts.toolchains_filter if opts.toolchains_filter is not None else True
|
|
|
|
use_supported_toolchains = 'all' in opts.toolchains_filter if opts.toolchains_filter is not None else False
|
2015-02-10 21:18:17 +00:00
|
|
|
toolchain_filter = opts.toolchains_filter
|
2016-06-24 22:15:01 +00:00
|
|
|
platform_name_filter = opts.general_filter_regex if opts.general_filter_regex is not None else opts.general_filter_regex
|
2015-02-10 21:50:56 +00:00
|
|
|
# Test specification with information about each target and associated toolchain
|
2015-09-23 15:54:41 +00:00
|
|
|
test_spec = get_autodetected_TEST_SPEC(MUTs.values(),
|
2015-02-10 21:18:17 +00:00
|
|
|
use_default_toolchain=use_default_toolchain,
|
|
|
|
use_supported_toolchains=use_supported_toolchains,
|
Added to option --auto handler for -f <mcu> filter switch. Now using -f switch
will filter target platforms to test. Use comma to pass more MCU names to
filter.
```
$ singletest.py --auto -j 8 -O --config
MBEDLS: Detecting connected mbed-enabled devices...
MBEDLS: Detected NUCLEO_L053R8, port: COM35, mounted: E:
MBEDLS: Detected KL25Z, port: COM89, mounted: F:
MUTs configuration in auto-detected:
+-------+-------------+---------------+------+-------+
| index | peripherals | mcu | disk | port |
+-------+-------------+---------------+------+-------+
| 1 | | NUCLEO_L053R8 | E: | COM35 |
| 2 | | KL25Z | F: | COM89 |
+-------+-------------+---------------+------+-------+
Test specification in auto-detected:
+---------------+-----+------+
| mcu | ARM | uARM |
+---------------+-----+------+
| KL25Z | Yes | - |
| NUCLEO_L053R8 | - | Yes |
+---------------+-----+------+
```
Building original configuration (no filter):
```
$ singletest.py --auto -j 8 -O
MBEDLS: Detecting connected mbed-enabled devices...
MBEDLS: Detected NUCLEO_L053R8, port: COM35, mounted: E:
MBEDLS: Detected KL25Z, port: COM89, mounted: F:
Building library CMSIS (KL25Z, ARM)
Building library MBED (KL25Z, ARM)
Building project DETECT (KL25Z, ARM)
.
.
.
Building library CMSIS (NUCLEO_L053R8, uARM)
Building library MBED (NUCLEO_L053R8, uARM)
Building project DETECT (NUCLEO_L053R8, uARM)
.
.
.
Completed in 3.68 sec
```
```
$ singletest.py --auto -j 8 -O -f KL25Z --config
MBEDLS: Detecting connected mbed-enabled devices...
MBEDLS: Detected NUCLEO_L053R8, port: COM35, mounted: E:
MBEDLS: Detected KL25Z, port: COM89, mounted: F:
MUTs configuration in auto-detected:
+-------+-------------+-------+------+-------+
| index | peripherals | mcu | disk | port |
+-------+-------------+-------+------+-------+
| 2 | | KL25Z | F: | COM89 |
+-------+-------------+-------+------+-------+
Test specification in auto-detected:
+-------+-----+
| mcu | ARM |
+-------+-----+
| KL25Z | Yes |
+-------+-----+
```
Building original configuration (with applied filter):
```
$ singletest.py --auto -j 8 -O -f KL25Z
MBEDLS: Detecting connected mbed-enabled devices...
MBEDLS: Detected NUCLEO_L053R8, port: COM35, mounted: E:
MBEDLS: Detected KL25Z, port: COM89, mounted: F:
Building library CMSIS (KL25Z, ARM)
Building library MBED (KL25Z, ARM)
Building project DETECT (KL25Z, ARM)
.
.
.
Completed in 1.33 sec
```
2015-03-13 15:30:33 +00:00
|
|
|
toolchain_filter=toolchain_filter,
|
|
|
|
platform_name_filter=platform_name_filter)
|
2015-02-10 21:18:17 +00:00
|
|
|
else:
|
|
|
|
# Open file with test specification
|
|
|
|
# test_spec_filename tells script which targets and their toolchain(s)
|
|
|
|
# should be covered by the test scenario
|
2015-09-28 12:09:54 +00:00
|
|
|
opts.auto_detect = False
|
2015-02-10 21:18:17 +00:00
|
|
|
test_spec = get_json_data_from_file(opts.test_spec_filename) if opts.test_spec_filename else None
|
|
|
|
if test_spec is None:
|
|
|
|
if not opts.test_spec_filename:
|
|
|
|
parser.print_help()
|
|
|
|
exit(-1)
|
|
|
|
|
|
|
|
# Get extra MUTs if applicable
|
|
|
|
MUTs = get_json_data_from_file(opts.muts_spec_filename) if opts.muts_spec_filename else None
|
|
|
|
|
|
|
|
if MUTs is None:
|
|
|
|
if not opts.muts_spec_filename:
|
|
|
|
parser.print_help()
|
|
|
|
exit(-1)
|
2014-02-27 16:47:53 +00:00
|
|
|
|
2014-11-12 18:01:44 +00:00
|
|
|
if opts.verbose_test_configuration_only:
|
2015-05-26 14:59:07 +00:00
|
|
|
print "MUTs configuration in %s:" % ('auto-detected' if opts.auto_detect else opts.muts_spec_filename)
|
2014-11-12 18:01:44 +00:00
|
|
|
if MUTs:
|
2015-01-30 08:38:15 +00:00
|
|
|
print print_muts_configuration_from_json(MUTs, platform_filter=opts.general_filter_regex)
|
2014-07-09 13:51:54 +00:00
|
|
|
print
|
2015-05-26 14:59:07 +00:00
|
|
|
print "Test specification in %s:" % ('auto-detected' if opts.auto_detect else opts.test_spec_filename)
|
2014-11-12 18:01:44 +00:00
|
|
|
if test_spec:
|
|
|
|
print print_test_configuration_from_json(test_spec)
|
2014-07-09 13:51:54 +00:00
|
|
|
exit(0)
|
|
|
|
|
2015-07-22 21:40:42 +00:00
|
|
|
if get_module_avail('mbed_lstools'):
|
|
|
|
if opts.operability_checks:
|
|
|
|
# Check if test scope is valid and run tests
|
|
|
|
test_scope = get_available_oper_test_scopes()
|
|
|
|
if opts.operability_checks in test_scope:
|
|
|
|
tests = IOperTestRunner(scope=opts.operability_checks)
|
|
|
|
test_results = tests.run()
|
|
|
|
|
|
|
|
# Export results in form of JUnit XML report to separate file
|
|
|
|
if opts.report_junit_file_name:
|
|
|
|
report_exporter = ReportExporter(ResultExporterType.JUNIT_OPER)
|
|
|
|
report_exporter.report_to_file(test_results, opts.report_junit_file_name)
|
|
|
|
else:
|
|
|
|
print "Unknown interoperability test scope name: '%s'" % (opts.operability_checks)
|
|
|
|
print "Available test scopes: %s" % (','.join(["'%s'" % n for n in test_scope]))
|
|
|
|
|
|
|
|
exit(0)
|
2015-05-26 14:59:07 +00:00
|
|
|
|
2014-07-09 13:51:54 +00:00
|
|
|
# Verbose test specification and MUTs configuration
|
|
|
|
if MUTs and opts.verbose:
|
|
|
|
print print_muts_configuration_from_json(MUTs)
|
|
|
|
if test_spec and opts.verbose:
|
|
|
|
print print_test_configuration_from_json(test_spec)
|
|
|
|
|
2014-07-28 16:20:58 +00:00
|
|
|
if opts.only_build_tests:
|
|
|
|
# We are skipping testing phase, and suppress summary
|
|
|
|
opts.suppress_summary = True
|
|
|
|
|
|
|
|
single_test = SingleTestRunner(_global_loops_count=opts.test_global_loops_value,
|
|
|
|
_test_loops_list=opts.test_loops_list,
|
|
|
|
_muts=MUTs,
|
2014-09-18 10:17:57 +00:00
|
|
|
_clean=opts.clean,
|
2014-11-21 13:55:53 +00:00
|
|
|
_opts_db_url=opts.db_url,
|
2014-08-12 15:15:33 +00:00
|
|
|
_opts_log_file_name=opts.log_file_name,
|
2014-09-25 16:21:03 +00:00
|
|
|
_opts_report_html_file_name=opts.report_html_file_name,
|
2014-10-09 10:51:37 +00:00
|
|
|
_opts_report_junit_file_name=opts.report_junit_file_name,
|
2015-04-14 18:45:56 +00:00
|
|
|
_opts_report_build_file_name=opts.report_build_file_name,
|
2016-06-21 21:20:19 +00:00
|
|
|
_opts_report_text_file_name=opts.report_text_file_name,
|
2014-07-28 16:20:58 +00:00
|
|
|
_test_spec=test_spec,
|
2014-07-28 16:46:21 +00:00
|
|
|
_opts_goanna_for_mbed_sdk=opts.goanna_for_mbed_sdk,
|
|
|
|
_opts_goanna_for_tests=opts.goanna_for_tests,
|
|
|
|
_opts_shuffle_test_order=opts.shuffle_test_order,
|
|
|
|
_opts_shuffle_test_seed=opts.shuffle_test_seed,
|
|
|
|
_opts_test_by_names=opts.test_by_names,
|
2015-03-04 09:48:39 +00:00
|
|
|
_opts_peripheral_by_names=opts.peripheral_by_names,
|
2014-07-28 16:46:21 +00:00
|
|
|
_opts_test_only_peripheral=opts.test_only_peripheral,
|
|
|
|
_opts_test_only_common=opts.test_only_common,
|
|
|
|
_opts_verbose_skipped_tests=opts.verbose_skipped_tests,
|
2014-08-04 13:29:20 +00:00
|
|
|
_opts_verbose_test_result_only=opts.verbose_test_result_only,
|
2014-07-28 16:46:21 +00:00
|
|
|
_opts_verbose=opts.verbose,
|
|
|
|
_opts_firmware_global_name=opts.firmware_global_name,
|
|
|
|
_opts_only_build_tests=opts.only_build_tests,
|
2015-03-12 09:55:05 +00:00
|
|
|
_opts_parallel_test_exec=opts.parallel_test_exec,
|
2014-07-30 10:03:32 +00:00
|
|
|
_opts_suppress_summary=opts.suppress_summary,
|
2014-08-04 13:29:20 +00:00
|
|
|
_opts_test_x_toolchain_summary=opts.test_x_toolchain_summary,
|
2014-08-07 10:48:21 +00:00
|
|
|
_opts_copy_method=opts.copy_method,
|
2014-08-08 12:57:19 +00:00
|
|
|
_opts_mut_reset_type=opts.mut_reset_type,
|
2014-08-12 09:20:41 +00:00
|
|
|
_opts_jobs=opts.jobs,
|
2014-09-02 10:43:08 +00:00
|
|
|
_opts_waterfall_test=opts.waterfall_test,
|
2015-06-08 19:51:13 +00:00
|
|
|
_opts_consolidate_waterfall_test=opts.consolidate_waterfall_test,
|
2015-09-23 15:54:41 +00:00
|
|
|
_opts_extend_test_timeout=opts.extend_test_timeout,
|
|
|
|
_opts_auto_detect=opts.auto_detect)
|
2014-07-28 16:20:58 +00:00
|
|
|
|
2014-08-05 08:32:44 +00:00
|
|
|
# Runs test suite in CLI mode
|
2015-06-19 16:53:38 +00:00
|
|
|
if (singletest_in_cli_mode(single_test)):
|
|
|
|
exit(0)
|
|
|
|
else:
|
|
|
|
exit(-1)
|