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