Mbed Host Tests
conn_primitive.py
Go to the documentation of this file.
1#!/usr/bin/env python
2"""
3mbed SDK
4Copyright (c) 2011-2016 ARM Limited
5
6Licensed under the Apache License, Version 2.0 (the "License");
7you may not use this file except in compliance with the License.
8You may obtain a copy of the License at
9
10 http://www.apache.org/licenses/LICENSE-2.0
11
12Unless required by applicable law or agreed to in writing, software
13distributed under the License is distributed on an "AS IS" BASIS,
14WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15See the License for the specific language governing permissions and
16limitations under the License.
17"""
18
19from mbed_host_tests.host_tests_logger import HtrunLogger
20
21
22class ConnectorPrimitiveException(Exception):
23 """
24 Exception in connector primitive module.
25 """
26 pass
27
28
30
31 def __init__(self, name):
32 self.LAST_ERROR = None
33 self.logger = HtrunLogger(name)
35
36 def write_kv(self, key, value):
37 """! Forms and sends Key-Value protocol message.
38 @details On how to parse K-V sent from DUT see KiViBufferWalker::KIVI_REGEX
39 On how DUT sends K-V please see greentea_write_postamble() function in greentea-client
40 @return Returns buffer with K-V message sent to DUT on success, None on failure
41 """
42 # All Key-Value messages ends with newline character
43 kv_buff = "{{%s;%s}}"% (key, value) + '\n'
44
45 if self.write(kv_buff):
46 self.logger.prn_txd(kv_buff.rstrip())
47 return kv_buff
48 else:
49 return None
50
51 def read(self, count):
52 """! Read data from DUT
53 @param count Number of bytes to read
54 @return Bytes read
55 """
56 raise NotImplementedError
57
58 def write(self, payload, log=False):
59 """! Read data from DUT
60 @param payload Buffer with data to send
61 @param log Set to True if you want to enable logging for this function
62 @return Payload (what was actually sent - if possible to establish that)
63 """
64 raise NotImplementedError
65
66 def flush(self):
67 """! Flush read/write channels of DUT """
68 raise NotImplementedError
69
70 def reset(self):
71 """! Reset the dut
72 """
73 raise NotImplementedError
74
75 def connected(self):
76 """! Check if there is a connection to DUT
77 @return True if there is conenction to DUT (read/write/flush API works)
78 """
79 raise NotImplementedError
80
81 def error(self):
82 """! Returns LAST_ERROR value
83 @return Value of self.LAST_ERROR
84 """
85 return self.LAST_ERROR
86
87 def finish(self):
88 """! Handle DUT dtor like (close resource) operations here
89 """
90 raise NotImplementedError
def write(self, payload, log=False)
Read data from DUT.
def write_kv(self, key, value)
Forms and sends Key-Value protocol message.
def finish(self)
Handle DUT dtor like (close resource) operations here.
def connected(self)
Check if there is a connection to DUT.