Mbed Host Tests
host_test.py
Go to the documentation of this file.
1"""
2mbed SDK
3Copyright (c) 2011-2016 ARM Limited
4
5Licensed under the Apache License, Version 2.0 (the "License");
6you may not use this file except in compliance with the License.
7You may obtain a copy of the License at
8
9 http://www.apache.org/licenses/LICENSE-2.0
10
11Unless required by applicable law or agreed to in writing, software
12distributed under the License is distributed on an "AS IS" BASIS,
13WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14See the License for the specific language governing permissions and
15limitations under the License.
16
17Author: Przemyslaw Wirkus <Przemyslaw.Wirkus@arm.com>
18"""
19
20import pkg_resources # part of setuptools
21from sys import stdout
23
24
26 """! Test results set by host tests """
27
28 def enum(self, **enums):
29 return type('Enum', (), enums)
30
31 def __init__(self):
32 self.TestResults = self.enum(
33 RESULT_SUCCESS = 'success',
34 RESULT_FAILURE = 'failure',
35 RESULT_ERROR = 'error',
36 RESULT_END = 'end',
37 RESULT_UNDEF = 'undefined', # Rather for debug purpose
38 RESULT_TIMEOUT = 'timeout',
39 RESULT_IOERR_COPY = "ioerr_copy",
40 RESULT_IOERR_DISK = "ioerr_disk",
41 RESULT_IO_SERIAL = 'ioerr_serial',
42 RESULT_NO_IMAGE = 'no_image',
43 RESULT_NOT_DETECTED = "not_detected",
44 RESULT_MBED_ASSERT = "mbed_assert",
45 RESULT_PASSIVE = "passive",
46 RESULT_BUILD_FAILED = 'build_failed',
47 RESULT_SYNC_FAILED = 'sync_failed'
48 )
49
50 # Magically creates attributes in this class corresponding
51 # to RESULT_ elements in self.TestResults enum
52 for attr in self.TestResults.__dict__:
53 if attr.startswith('RESULT_'):
54 setattr(self, attr, self.TestResults.__dict__[attr])
55
56 # Indexes of this list define string->int mapping between
57 # actual strings with results
59 self.TestResults.RESULT_SUCCESS,
60 self.TestResults.RESULT_FAILURE,
61 self.TestResults.RESULT_ERROR,
62 self.TestResults.RESULT_END,
63 self.TestResults.RESULT_UNDEF,
64 self.TestResults.RESULT_TIMEOUT,
65 self.TestResults.RESULT_IOERR_COPY,
66 self.TestResults.RESULT_IOERR_DISK,
67 self.TestResults.RESULT_IO_SERIAL,
68 self.TestResults.RESULT_NO_IMAGE,
69 self.TestResults.RESULT_NOT_DETECTED,
70 self.TestResults.RESULT_MBED_ASSERT,
71 self.TestResults.RESULT_PASSIVE,
72 self.TestResults.RESULT_BUILD_FAILED,
73 self.TestResults.RESULT_SYNC_FAILED
74 ]
75
76 def get_test_result_int(self, test_result_str):
77 """! Maps test result string to unique integer """
78 if test_result_str in self.TestResultsList:
79 return self.TestResultsList.index(test_result_str)
80 return -1
81
82 def __getitem__(self, test_result_str):
83 """! Returns numerical result code """
84 return self.get_test_result_int(test_result_str)
85
86
88 """ Base class for host test's test runner
89 """
90 def __init__(self, options):
91 """ ctor
92 """
93 HostTestResults.__init__(self)
94 self.mbed = Mbed(options)
95
96 def run(self):
97 """ Test runner for host test. This function will start executing
98 test and forward test result via serial port to test suite
99 """
100 pass
101
102 def setup(self):
103 """! Setup and check if configuration for test is correct.
104 @details This function can for example check if serial port is already opened
105 """
106 pass
107
108 def notify(self, msg):
109 """! On screen notification function
110 @param msg Text message sent to stdout directly
111 """
112 stdout.write(msg)
113 stdout.flush()
114
115 def print_result(self, result):
116 """! Test result unified printing function
117 @param result Should be a member of HostTestResults.RESULT_* enums
118 """
119 self.notify("{{%s}}\n"% result)
120 self.notify("{{%s}}\n"% self.RESULT_END)
121
122 def finish(self):
123 """ dctor for this class, finishes tasks and closes resources
124 """
125 pass
126
128 """ Hello string used as first print
129 """
130 pkg = 'mbed-host-tests'
131 version = pkg_resources.require(pkg)[0].version
132 return "host test executor ver. " + version
133
134
136 """! Test class with serial port initialization
137 @details This is a base for other test selectors, initializes
138 """
139 def __init__(self, options):
140 Test.__init__(self, options=options)
def __getitem__(self, test_result_str)
Returns numerical result code.
Definition: host_test.py:82
def get_test_result_int(self, test_result_str)
Maps test result string to unique integer.
Definition: host_test.py:76
def notify(self, msg)
On screen notification function.
Definition: host_test.py:108
def print_result(self, result)
Test result unified printing function.
Definition: host_test.py:115
def setup(self)
Setup and check if configuration for test is correct.
Definition: host_test.py:102
Base class for a host driven test.
Definition: mbed_base.py:29