Mbed Host Tests
host_test.py
Go to the documentation of this file.
1 """
2 mbed SDK
3 Copyright (c) 2011-2016 ARM Limited
4 
5 Licensed under the Apache License, Version 2.0 (the "License");
6 you may not use this file except in compliance with the License.
7 You may obtain a copy of the License at
8 
9  http://www.apache.org/licenses/LICENSE-2.0
10 
11 Unless required by applicable law or agreed to in writing, software
12 distributed under the License is distributed on an "AS IS" BASIS,
13 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 See the License for the specific language governing permissions and
15 limitations under the License.
16 
17 Author: Przemyslaw Wirkus <Przemyslaw.Wirkus@arm.com>
18 """
19 
20 import pkg_resources # part of setuptools
21 from 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.TestResultsTestResults = self.enumenum(
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.TestResultsTestResults.__dict__:
53  if attr.startswith('RESULT_'):
54  setattr(self, attr, self.TestResultsTestResults.__dict__[attr])
55 
56  # Indexes of this list define string->int mapping between
57  # actual strings with results
58  self.TestResultsListTestResultsList = [
59  self.TestResultsTestResults.RESULT_SUCCESS,
60  self.TestResultsTestResults.RESULT_FAILURE,
61  self.TestResultsTestResults.RESULT_ERROR,
62  self.TestResultsTestResults.RESULT_END,
63  self.TestResultsTestResults.RESULT_UNDEF,
64  self.TestResultsTestResults.RESULT_TIMEOUT,
65  self.TestResultsTestResults.RESULT_IOERR_COPY,
66  self.TestResultsTestResults.RESULT_IOERR_DISK,
67  self.TestResultsTestResults.RESULT_IO_SERIAL,
68  self.TestResultsTestResults.RESULT_NO_IMAGE,
69  self.TestResultsTestResults.RESULT_NOT_DETECTED,
70  self.TestResultsTestResults.RESULT_MBED_ASSERT,
71  self.TestResultsTestResults.RESULT_PASSIVE,
72  self.TestResultsTestResults.RESULT_BUILD_FAILED,
73  self.TestResultsTestResults.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.TestResultsListTestResultsList:
79  return self.TestResultsListTestResultsList.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_intget_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.mbedmbed = 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.notifynotify("{{%s}}\n"% result)
120  self.notifynotify("{{%s}}\n"% self.RESULT_END)
121 
122  def finish(self):
123  """ dctor for this class, finishes tasks and closes resources
124  """
125  pass
126 
127  def get_hello_string(self):
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