From dcce4d7cded777412c79e88441ca041ae4c81ff7 Mon Sep 17 00:00:00 2001 From: Przemek Wirkus Date: Tue, 27 Jan 2015 13:24:11 +0000 Subject: [PATCH] Refactored detection test to use new autodetection of host test --- libraries/tests/mbed/detect/main.cpp | 7 ++++- workspace_tools/host_tests/__init__.py | 2 ++ workspace_tools/host_tests/detect_auto.py | 38 ++++++++++------------- workspace_tools/tests.py | 2 +- 4 files changed, 26 insertions(+), 23 deletions(-) diff --git a/libraries/tests/mbed/detect/main.cpp b/libraries/tests/mbed/detect/main.cpp index 59d0634866..d7ad0c26dd 100644 --- a/libraries/tests/mbed/detect/main.cpp +++ b/libraries/tests/mbed/detect/main.cpp @@ -2,9 +2,14 @@ #include "test_env.h" int main() { + TEST_TIMEOUT(10); + TEST_HOSTTEST(detect_auto); + TEST_DESCRIPTION(Simple detect test); + TEST_START("DTCT_1"); + notify_start(); printf("MBED: Target '%s'\r\n", TEST_SUITE_TARGET_NAME); printf("MBED: Test ID '%s'\r\n", TEST_SUITE_TEST_ID); printf("MBED: UUID '%s'\r\n", TEST_SUITE_UUID); - notify_completion(true); + TEST_RESULT(true); } diff --git a/workspace_tools/host_tests/__init__.py b/workspace_tools/host_tests/__init__.py index 3b9f1319ea..28e1017867 100644 --- a/workspace_tools/host_tests/__init__.py +++ b/workspace_tools/host_tests/__init__.py @@ -23,6 +23,7 @@ from stdio_auto import StdioTest from dev_null_auto import DevNullTest from rtc_auto import RTCTest from echo import EchoTest +from detect_auto import DetectPlatformTest HOSTREGISTRY = HostRegistry() @@ -34,6 +35,7 @@ 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()) +HOSTREGISTRY.register_host_test("detect_auto", DetectPlatformTest()) ############################################################################### # Functional interface for test supervisor registry diff --git a/workspace_tools/host_tests/detect_auto.py b/workspace_tools/host_tests/detect_auto.py index 03ff17fa9d..2999946c08 100644 --- a/workspace_tools/host_tests/detect_auto.py +++ b/workspace_tools/host_tests/detect_auto.py @@ -16,44 +16,40 @@ limitations under the License. """ import re -from host_test import DefaultTest - -class DetectPlatformTest(DefaultTest): +class DetectPlatformTest(): PATTERN_MICRO_NAME = "Target '(\w+)'" re_detect_micro_name = re.compile(PATTERN_MICRO_NAME) - def test(self): + def test(self, selftest): result = True - c = self.mbed.serial_readline() # {{start}} preamble + c = selftest.mbed.serial_readline() # {{start}} preamble if c is None: - return self.RESULT_IO_SERIAL + return selftest.RESULT_IO_SERIAL - self.notify(c.strip()) - self.notify("HOST: Detecting target name...") + selftest.notify(c.strip()) + selftest.notify("HOST: Detecting target name...") - c = self.mbed.serial_readline() + c = selftest.mbed.serial_readline() if c is None: - return self.RESULT_IO_SERIAL - self.notify(c.strip()) + return selftest.RESULT_IO_SERIAL + selftest.notify(c.strip()) # Check for target name m = self.re_detect_micro_name.search(c) if m and len(m.groups()): micro_name = m.groups()[0] - micro_cmp = self.mbed.options.micro == micro_name + micro_cmp = selftest.mbed.options.micro == micro_name result = result and micro_cmp - self.notify("HOST: MUT Target name '%s', expected '%s'... [%s]"% (micro_name, self.mbed.options.micro, "OK" if micro_cmp else "FAIL")) + selftest.notify("HOST: MUT Target name '%s', expected '%s'... [%s]"% (micro_name, + selftest.mbed.options.micro, + "OK" if micro_cmp else "FAIL")) for i in range(0, 2): - c = self.mbed.serial_readline() + c = selftest.mbed.serial_readline() if c is None: - return self.RESULT_IO_SERIAL - self.notify(c.strip()) + return selftest.RESULT_IO_SERIAL + selftest.notify(c.strip()) - return self.RESULT_SUCCESS if result else self.RESULT_FAILURE - - -if __name__ == '__main__': - DetectPlatformTest().run() + return selftest.RESULT_SUCCESS if result else selftest.RESULT_FAILURE diff --git a/workspace_tools/tests.py b/workspace_tools/tests.py index bca01247de..8c6499b636 100644 --- a/workspace_tools/tests.py +++ b/workspace_tools/tests.py @@ -906,7 +906,7 @@ TESTS = [ "source_dir": join(TEST_DIR, "mbed", "detect"), "dependencies": [MBED_LIBRARIES, TEST_MBED_LIB], "automated": True, - "host_test" : "detect_auto", + #"host_test" : "detect_auto", }, ]