Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
tools/compliance/ioper_runner.py@0:0e018d759a2a, 2016-11-08 (annotated)
- Committer:
- switches
- Date:
- Tue Nov 08 18:27:11 2016 +0000
- Revision:
- 0:0e018d759a2a
Initial commit
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| switches | 0:0e018d759a2a | 1 | #!/usr/bin/env python2 |
| switches | 0:0e018d759a2a | 2 | """ |
| switches | 0:0e018d759a2a | 3 | mbed SDK |
| switches | 0:0e018d759a2a | 4 | Copyright (c) 2011-2015 ARM Limited |
| switches | 0:0e018d759a2a | 5 | |
| switches | 0:0e018d759a2a | 6 | Licensed under the Apache License, Version 2.0 (the "License"); |
| switches | 0:0e018d759a2a | 7 | you may not use this file except in compliance with the License. |
| switches | 0:0e018d759a2a | 8 | You may obtain a copy of the License at |
| switches | 0:0e018d759a2a | 9 | |
| switches | 0:0e018d759a2a | 10 | http://www.apache.org/licenses/LICENSE-2.0 |
| switches | 0:0e018d759a2a | 11 | |
| switches | 0:0e018d759a2a | 12 | Unless required by applicable law or agreed to in writing, software |
| switches | 0:0e018d759a2a | 13 | distributed under the License is distributed on an "AS IS" BASIS, |
| switches | 0:0e018d759a2a | 14 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| switches | 0:0e018d759a2a | 15 | See the License for the specific language governing permissions and |
| switches | 0:0e018d759a2a | 16 | limitations under the License. |
| switches | 0:0e018d759a2a | 17 | |
| switches | 0:0e018d759a2a | 18 | Author: Przemyslaw Wirkus <Przemyslaw.Wirkus@arm.com> |
| switches | 0:0e018d759a2a | 19 | |
| switches | 0:0e018d759a2a | 20 | """ |
| switches | 0:0e018d759a2a | 21 | |
| switches | 0:0e018d759a2a | 22 | import sys |
| switches | 0:0e018d759a2a | 23 | import mbed_lstools |
| switches | 0:0e018d759a2a | 24 | from prettytable import PrettyTable |
| switches | 0:0e018d759a2a | 25 | |
| switches | 0:0e018d759a2a | 26 | try: |
| switches | 0:0e018d759a2a | 27 | from colorama import init |
| switches | 0:0e018d759a2a | 28 | except: |
| switches | 0:0e018d759a2a | 29 | pass |
| switches | 0:0e018d759a2a | 30 | |
| switches | 0:0e018d759a2a | 31 | COLORAMA = 'colorama' in sys.modules |
| switches | 0:0e018d759a2a | 32 | |
| switches | 0:0e018d759a2a | 33 | from ioper_base import IOperTestCaseBase |
| switches | 0:0e018d759a2a | 34 | from ioper_test_fs import IOperTest_FileStructure_Basic |
| switches | 0:0e018d759a2a | 35 | from ioper_test_fs import IOperTest_FileStructure_MbedEnabled |
| switches | 0:0e018d759a2a | 36 | from ioper_test_target_id import IOperTest_TargetID_Basic |
| switches | 0:0e018d759a2a | 37 | from ioper_test_target_id import IOperTest_TargetID_MbedEnabled |
| switches | 0:0e018d759a2a | 38 | |
| switches | 0:0e018d759a2a | 39 | |
| switches | 0:0e018d759a2a | 40 | TEST_LIST = [IOperTest_TargetID_Basic('basic'), |
| switches | 0:0e018d759a2a | 41 | IOperTest_TargetID_MbedEnabled('mbed-enabled'), |
| switches | 0:0e018d759a2a | 42 | IOperTest_FileStructure_Basic('basic'), |
| switches | 0:0e018d759a2a | 43 | IOperTest_FileStructure_MbedEnabled('mbed-enabled'), |
| switches | 0:0e018d759a2a | 44 | IOperTestCaseBase('all'), # Dummy used to add 'all' option |
| switches | 0:0e018d759a2a | 45 | ] |
| switches | 0:0e018d759a2a | 46 | |
| switches | 0:0e018d759a2a | 47 | |
| switches | 0:0e018d759a2a | 48 | class IOperTestRunner(): |
| switches | 0:0e018d759a2a | 49 | """ Calls all i/face interoperability tests |
| switches | 0:0e018d759a2a | 50 | """ |
| switches | 0:0e018d759a2a | 51 | |
| switches | 0:0e018d759a2a | 52 | def __init__(self, scope=None): |
| switches | 0:0e018d759a2a | 53 | """ Test scope: |
| switches | 0:0e018d759a2a | 54 | 'pedantic' - all |
| switches | 0:0e018d759a2a | 55 | 'mbed-enabled' - let's try to check if this device is mbed-enabled |
| switches | 0:0e018d759a2a | 56 | 'basic' - just simple, passive tests (no device flashing) |
| switches | 0:0e018d759a2a | 57 | """ |
| switches | 0:0e018d759a2a | 58 | self.requested_scope = scope # Test scope given by user |
| switches | 0:0e018d759a2a | 59 | self.raw_test_results = {} # Raw test results, can be used by exporters: { Platform: [test results]} |
| switches | 0:0e018d759a2a | 60 | |
| switches | 0:0e018d759a2a | 61 | # Test scope definitions |
| switches | 0:0e018d759a2a | 62 | self.SCOPE_BASIC = 'basic' # Basic tests, sanity checks |
| switches | 0:0e018d759a2a | 63 | self.SCOPE_MBED_ENABLED = 'mbed-enabled' # Let's try to check if this device is mbed-enabled |
| switches | 0:0e018d759a2a | 64 | self.SCOPE_PEDANTIC = 'pedantic' # Extensive tests |
| switches | 0:0e018d759a2a | 65 | self.SCOPE_ALL = 'all' # All tests, equal to highest scope level |
| switches | 0:0e018d759a2a | 66 | |
| switches | 0:0e018d759a2a | 67 | # This structure will help us sort test scopes so we can include them |
| switches | 0:0e018d759a2a | 68 | # e.g. pedantic also includes basic and mbed-enabled tests |
| switches | 0:0e018d759a2a | 69 | self.scopes = {self.SCOPE_BASIC : 0, |
| switches | 0:0e018d759a2a | 70 | self.SCOPE_MBED_ENABLED : 1, |
| switches | 0:0e018d759a2a | 71 | self.SCOPE_PEDANTIC : 2, |
| switches | 0:0e018d759a2a | 72 | self.SCOPE_ALL : 99, |
| switches | 0:0e018d759a2a | 73 | } |
| switches | 0:0e018d759a2a | 74 | |
| switches | 0:0e018d759a2a | 75 | if COLORAMA: |
| switches | 0:0e018d759a2a | 76 | init() # colorama.init() |
| switches | 0:0e018d759a2a | 77 | |
| switches | 0:0e018d759a2a | 78 | def run(self): |
| switches | 0:0e018d759a2a | 79 | """ Run tests, calculate overall score and print test results |
| switches | 0:0e018d759a2a | 80 | """ |
| switches | 0:0e018d759a2a | 81 | mbeds = mbed_lstools.create() |
| switches | 0:0e018d759a2a | 82 | muts_list = mbeds.list_mbeds() |
| switches | 0:0e018d759a2a | 83 | test_base = IOperTestCaseBase() |
| switches | 0:0e018d759a2a | 84 | |
| switches | 0:0e018d759a2a | 85 | self.raw_test_results = {} |
| switches | 0:0e018d759a2a | 86 | for i, mut in enumerate(muts_list): |
| switches | 0:0e018d759a2a | 87 | result = [] |
| switches | 0:0e018d759a2a | 88 | self.raw_test_results[mut['platform_name']] = [] |
| switches | 0:0e018d759a2a | 89 | |
| switches | 0:0e018d759a2a | 90 | print "MBEDLS: Detected %s, port: %s, mounted: %s"% (mut['platform_name'], |
| switches | 0:0e018d759a2a | 91 | mut['serial_port'], |
| switches | 0:0e018d759a2a | 92 | mut['mount_point']) |
| switches | 0:0e018d759a2a | 93 | print "Running interoperability test suite, scope '%s'" % (self.requested_scope) |
| switches | 0:0e018d759a2a | 94 | for test_case in TEST_LIST: |
| switches | 0:0e018d759a2a | 95 | if self.scopes[self.requested_scope] >= self.scopes[test_case.scope]: |
| switches | 0:0e018d759a2a | 96 | res = test_case.test(param=mut) |
| switches | 0:0e018d759a2a | 97 | result.extend(res) |
| switches | 0:0e018d759a2a | 98 | self.raw_test_results[mut['platform_name']].extend(res) |
| switches | 0:0e018d759a2a | 99 | |
| switches | 0:0e018d759a2a | 100 | columns = ['Platform', 'Test Case', 'Result', 'Scope', 'Description'] |
| switches | 0:0e018d759a2a | 101 | pt = PrettyTable(columns) |
| switches | 0:0e018d759a2a | 102 | for col in columns: |
| switches | 0:0e018d759a2a | 103 | pt.align[col] = 'l' |
| switches | 0:0e018d759a2a | 104 | |
| switches | 0:0e018d759a2a | 105 | for tr in result: |
| switches | 0:0e018d759a2a | 106 | severity, tr_name, tr_scope, text = tr |
| switches | 0:0e018d759a2a | 107 | tr = (test_base.COLOR(severity, mut['platform_name']), |
| switches | 0:0e018d759a2a | 108 | test_base.COLOR(severity, tr_name), |
| switches | 0:0e018d759a2a | 109 | test_base.COLOR(severity, severity), |
| switches | 0:0e018d759a2a | 110 | test_base.COLOR(severity, tr_scope), |
| switches | 0:0e018d759a2a | 111 | test_base.COLOR(severity, text)) |
| switches | 0:0e018d759a2a | 112 | pt.add_row(list(tr)) |
| switches | 0:0e018d759a2a | 113 | print pt.get_string(border=True, sortby='Result') |
| switches | 0:0e018d759a2a | 114 | if i + 1 < len(muts_list): |
| switches | 0:0e018d759a2a | 115 | |
| switches | 0:0e018d759a2a | 116 | return self.raw_test_results |
| switches | 0:0e018d759a2a | 117 | |
| switches | 0:0e018d759a2a | 118 | def get_available_oper_test_scopes(): |
| switches | 0:0e018d759a2a | 119 | """ Get list of available test scopes |
| switches | 0:0e018d759a2a | 120 | """ |
| switches | 0:0e018d759a2a | 121 | scopes = set() |
| switches | 0:0e018d759a2a | 122 | for oper_test in TEST_LIST: |
| switches | 0:0e018d759a2a | 123 | if oper_test.scope is not None: |
| switches | 0:0e018d759a2a | 124 | scopes.add(oper_test.scope) |
| switches | 0:0e018d759a2a | 125 | return list(scopes) |