Committer:
borlanic
Date:
Fri Mar 30 14:07:05 2018 +0000
Revision:
4:75df35ef4fb6
Parent:
0:380207fcb5c1
commentar

Who changed what in which revision?

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