Refactored echo at 115200 test for new model of test autodetection

pull/900/head
Przemek Wirkus 2015-01-27 13:17:36 +00:00
parent a8506caa1d
commit d610f0b08a
5 changed files with 30 additions and 39 deletions

View File

@ -7,18 +7,18 @@
namespace {
const int BUFFER_SIZE = 48;
char buffer[BUFFER_SIZE] = {0};
}
int main() {
char buffer[BUFFER_SIZE] = {0};
TEST_TIMEOUT(20);
TEST_HOSTTEST(echo);
TEST_DESCRIPTION(Serial Echo at 115200);
TEST_START("MBED_A9");
Serial pc(TXPIN, RXPIN);
pc.baud(115200);
pc.puts("{{");
pc.puts(TEST_ENV_START); // Host test is expecting preamble
pc.puts("}}");
while (1) {
pc.gets(buffer, BUFFER_SIZE - 1);
pc.printf("%s", buffer);

View File

@ -22,6 +22,7 @@ from wait_us_auto import WaitusTest
from stdio_auto import StdioTest
from dev_null_auto import DevNullTest
from rtc_auto import RTCTest
from echo import EchoTest
HOSTREGISTRY = HostRegistry()
@ -32,6 +33,7 @@ HOSTREGISTRY.register_host_test("wait_us_auto", WaitusTest())
HOSTREGISTRY.register_host_test("stdio_auto", StdioTest())
HOSTREGISTRY.register_host_test("dev_null_auto", DevNullTest())
HOSTREGISTRY.register_host_test("rtc_auto", RTCTest())
HOSTREGISTRY.register_host_test("echo", EchoTest())
###############################################################################
# Functional interface for test supervisor registry

View File

@ -18,50 +18,35 @@ limitations under the License.
import sys
import uuid
from sys import stdout
from host_test import HostTestResults, Test
class EchoTest():
class EchoTest(Test):
""" This host test will use mbed serial port with
baudrate 115200 to perform echo test on that port.
"""
# Test parameters
TEST_SERIAL_BAUDRATE = 115200
TEST_LOOP_COUNT = 50
def __init__(self):
# Constructors
HostTestResults.__init__(self)
Test.__init__(self)
# Test parameters
self.TEST_SERIAL_BAUDRATE = 115200
self.TEST_LOOP_COUNT = 50
# Custom initialization for echo test
self.mbed.init_serial_params(serial_baud=self.TEST_SERIAL_BAUDRATE)
def test(self):
""" Test function, return True or False to get standard test notification on stdout
def test(self, selftest):
""" This host test will use mbed serial port with
baudrate 115200 to perform echo test on that port.
"""
c = self.mbed.serial_readline() # '{{start}}'
if c is None:
return self.RESULT_IO_SERIAL
# Custom initialization for echo test
selftest.mbed.init_serial_params(serial_baud=self.TEST_SERIAL_BAUDRATE)
selftest.mbed.init_serial()
self.mbed.flush()
self.notify("HOST: Starting the ECHO test")
# Test function, return True or False to get standard test notification on stdout
selftest.mbed.flush()
selftest.notify("HOST: Starting the ECHO test")
result = True
for i in range(0, self.TEST_LOOP_COUNT):
TEST_STRING = str(uuid.uuid4()) + "\n"
self.mbed.serial_write(TEST_STRING)
c = self.mbed.serial_readline()
selftest.mbed.serial_write(TEST_STRING)
c = selftest.mbed.serial_readline()
if c is None:
return self.RESULT_IO_SERIAL
return selftest.RESULT_IO_SERIAL
if c.strip() != TEST_STRING.strip():
self.notify('HOST: "%s" != "%s"'% (c, TEST_STRING))
selftest.notify('HOST: "%s" != "%s"'% (c, TEST_STRING))
result = False
else:
sys.stdout.write('.')
stdout.flush()
return self.RESULT_SUCCESS if result else self.RESULT_FAILURE
if __name__ == '__main__':
EchoTest().run()
return selftest.RESULT_SUCCESS if result else selftest.RESULT_FAILURE

View File

@ -126,6 +126,10 @@ class Mbed:
serial_baud = serial_baud if serial_baud is not None else self.serial_baud
serial_timeout = serial_timeout if serial_timeout is not None else self.serial_timeout
if self.serial:
self.serial.close()
self.serial = None
result = True
try:
self.serial = Serial(self.port, baudrate=serial_baud, timeout=serial_timeout)

View File

@ -137,7 +137,7 @@ TESTS = [
"source_dir": join(TEST_DIR, "mbed", "echo"),
"dependencies": [MBED_LIBRARIES, TEST_MBED_LIB],
"automated": True,
"host_test": "echo"
#"host_test": "echo"
},
{
"id": "MBED_A10", "description": "PortOut PortIn",