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