mirror of https://github.com/ARMmbed/mbed-os.git
Refactored few more tests to support autodetection: basic, call_before_main, dev_null, rtc, stdio
parent
6903b54b9e
commit
a8506caa1d
|
@ -1,4 +1,9 @@
|
|||
#include "test_env.h"
|
||||
|
||||
int main() {
|
||||
notify_completion(true);
|
||||
TEST_TIMEOUT(20);
|
||||
TEST_HOSTTEST(default_auto);
|
||||
TEST_DESCRIPTION(Basic);
|
||||
TEST_START("MBED_A1");
|
||||
TEST_RESULT(true);
|
||||
}
|
||||
|
|
|
@ -10,6 +10,12 @@ extern "C" void mbed_main() {
|
|||
}
|
||||
|
||||
int main() {
|
||||
TEST_TIMEOUT(20);
|
||||
TEST_HOSTTEST(default_auto);
|
||||
TEST_DESCRIPTION(Call function mbed_main before main);
|
||||
TEST_START("MBED_A21");
|
||||
|
||||
printf("MBED: main() starts now!\r\n");
|
||||
notify_completion(mbed_main_called);
|
||||
|
||||
TEST_RESULT(mbed_main_called);
|
||||
}
|
||||
|
|
|
@ -1,8 +1,7 @@
|
|||
#include "mbed.h"
|
||||
#include "test_env.h"
|
||||
|
||||
class DevNull : public Stream
|
||||
{
|
||||
class DevNull : public Stream {
|
||||
public:
|
||||
DevNull(const char *name = NULL) : Stream(name) {}
|
||||
|
||||
|
@ -17,12 +16,15 @@ protected:
|
|||
|
||||
DevNull null("null");
|
||||
|
||||
int main()
|
||||
{
|
||||
int main() {
|
||||
TEST_TIMEOUT(20);
|
||||
TEST_HOSTTEST(dev_null_auto);
|
||||
TEST_DESCRIPTION(stdout redirected to dev null);
|
||||
TEST_START("EXAMPLE_1");
|
||||
|
||||
printf("MBED: re-routing stdout to /null\r\n");
|
||||
freopen("/null", "w", stdout);
|
||||
printf("MBED: printf redirected to /null\r\n"); // This shouldn't appear
|
||||
// If failure message can be seen test should fail :)
|
||||
notify_completion(false); // This is 'false' on purpose
|
||||
return 0;
|
||||
TEST_RESULT(false); // This is 'false' on purpose
|
||||
}
|
||||
|
|
|
@ -6,8 +6,7 @@ Serial pc(USBTX, USBRX);
|
|||
#define FILENAME "/local/out.txt"
|
||||
#define TEST_STRING "Hello World!"
|
||||
|
||||
FILE *test_open(const char *mode)
|
||||
{
|
||||
FILE *test_open(const char *mode) {
|
||||
FILE *f = fopen(FILENAME, mode);
|
||||
if (f == NULL) {
|
||||
printf("Error opening file"NL);
|
||||
|
@ -16,8 +15,7 @@ FILE *test_open(const char *mode)
|
|||
return f;
|
||||
}
|
||||
|
||||
void test_write(FILE *f, char *str, int str_len)
|
||||
{
|
||||
void test_write(FILE *f, char *str, int str_len) {
|
||||
int n = fprintf(f, str);
|
||||
|
||||
if (n != str_len) {
|
||||
|
@ -26,8 +24,7 @@ void test_write(FILE *f, char *str, int str_len)
|
|||
}
|
||||
}
|
||||
|
||||
void test_read(FILE *f, char *str, int str_len)
|
||||
{
|
||||
void test_read(FILE *f, char *str, int str_len) {
|
||||
int n = fread(str, sizeof(unsigned char), str_len, f);
|
||||
|
||||
if (n != str_len) {
|
||||
|
@ -36,8 +33,7 @@ void test_read(FILE *f, char *str, int str_len)
|
|||
}
|
||||
}
|
||||
|
||||
void test_close(FILE *f)
|
||||
{
|
||||
void test_close(FILE *f) {
|
||||
int rc = fclose(f);
|
||||
|
||||
if (rc != 0) {
|
||||
|
@ -46,8 +42,12 @@ void test_close(FILE *f)
|
|||
}
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
int main() {
|
||||
TEST_TIMEOUT(20);
|
||||
TEST_HOSTTEST(default_auto);
|
||||
TEST_DESCRIPTION(Semihost file system);
|
||||
TEST_START("MBED_A2");
|
||||
|
||||
pc.printf("Test the Stream class\n");
|
||||
|
||||
printf("connected: %s\n", (semihost_connected()) ? ("Yes") : ("No"));
|
||||
|
@ -74,5 +74,5 @@ int main()
|
|||
test_close(f);
|
||||
|
||||
// Check the two strings are equal
|
||||
notify_completion((strncmp(buffer, str, str_len) == 0));
|
||||
TEST_RESULT((strncmp(buffer, str, str_len) == 0));
|
||||
}
|
||||
|
|
|
@ -1,8 +1,14 @@
|
|||
#include "mbed.h"
|
||||
#include "test_env.h"
|
||||
|
||||
#define CUSTOM_TIME 1256729737
|
||||
|
||||
int main() {
|
||||
TEST_TIMEOUT(20);
|
||||
TEST_HOSTTEST(rtc_auto);
|
||||
TEST_DESCRIPTION(RTC);
|
||||
TEST_START("MBED_16");
|
||||
|
||||
char buffer[32] = {0};
|
||||
set_time(CUSTOM_TIME); // Set RTC time to Wed, 28 Oct 2009 11:35:37
|
||||
while(1) {
|
||||
|
|
|
@ -7,19 +7,23 @@
|
|||
*/
|
||||
|
||||
int main() {
|
||||
TEST_TIMEOUT(20);
|
||||
TEST_HOSTTEST(stdio_auto);
|
||||
TEST_DESCRIPTION(stdio);
|
||||
TEST_START("MBED_2");
|
||||
|
||||
DigitalOut led1(LED1);
|
||||
DigitalOut led2(LED2);
|
||||
|
||||
|
||||
union {
|
||||
int value_int;
|
||||
};
|
||||
|
||||
notify_start();
|
||||
notify_start(); // Just to sync with host test supervisor
|
||||
|
||||
const char* PRINT_PATTERN = "MBED: Your value was: %d\r\n";
|
||||
|
||||
while (true)
|
||||
{
|
||||
|
||||
while (true) {
|
||||
// SCANF PRINTF family
|
||||
value_int = 0;
|
||||
led1 = 1;
|
||||
|
|
|
@ -19,6 +19,9 @@ from host_registry import HostRegistry
|
|||
from default_auto import DefaultAuto
|
||||
from hello_auto import HelloTest
|
||||
from wait_us_auto import WaitusTest
|
||||
from stdio_auto import StdioTest
|
||||
from dev_null_auto import DevNullTest
|
||||
from rtc_auto import RTCTest
|
||||
|
||||
|
||||
HOSTREGISTRY = HostRegistry()
|
||||
|
@ -26,6 +29,9 @@ HOSTREGISTRY.register_host_test("default", DefaultAuto())
|
|||
HOSTREGISTRY.register_host_test("default_auto", DefaultAuto())
|
||||
HOSTREGISTRY.register_host_test("hello_auto", HelloTest())
|
||||
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())
|
||||
|
||||
###############################################################################
|
||||
# Functional interface for test supervisor registry
|
||||
|
|
|
@ -15,25 +15,22 @@ See the License for the specific language governing permissions and
|
|||
limitations under the License.
|
||||
"""
|
||||
|
||||
from host_test import DefaultTest
|
||||
class DevNullTest():
|
||||
|
||||
|
||||
class DevNullTest(DefaultTest):
|
||||
|
||||
def check_readline(self, text):
|
||||
def check_readline(self, selftest, text):
|
||||
""" Reads line from serial port and checks if text was part of read string
|
||||
"""
|
||||
result = False
|
||||
c = self.mbed.serial_readline()
|
||||
c = selftest.mbed.serial_readline()
|
||||
if c and text in c:
|
||||
result = True
|
||||
return result
|
||||
|
||||
def test(self):
|
||||
def test(self, selftest):
|
||||
result = True
|
||||
# Test should print some text and later stop printing
|
||||
# 'MBED: re-routing stdout to /null'
|
||||
res = self.check_readline("re-routing stdout to /null")
|
||||
res = self.check_readline(selftest, "re-routing stdout to /null")
|
||||
if not res:
|
||||
# We haven't read preamble line
|
||||
result = False
|
||||
|
@ -41,17 +38,13 @@ class DevNullTest(DefaultTest):
|
|||
# Check if there are printed characters
|
||||
str = ''
|
||||
for i in range(3):
|
||||
c = self.mbed.serial_read(32)
|
||||
c = selftest.mbed.serial_read(32)
|
||||
if c is None:
|
||||
return self.RESULT_IO_SERIAL
|
||||
return selftest.RESULT_IO_SERIAL
|
||||
else:
|
||||
str += c
|
||||
if len(str) > 0:
|
||||
result = False
|
||||
break
|
||||
self.notify("Received %d bytes: %s"% (len(str), str))
|
||||
return self.RESULT_SUCCESS if result else self.RESULT_FAILURE
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
DevNullTest().run()
|
||||
selftest.notify("Received %d bytes: %s"% (len(str), str))
|
||||
return selftest.RESULT_SUCCESS if result else selftest.RESULT_FAILURE
|
||||
|
|
|
@ -254,6 +254,7 @@ class HostTestResults:
|
|||
self.RESULT_NO_IMAGE = 'no_image'
|
||||
self.RESULT_IOERR_COPY = "ioerr_copy"
|
||||
self.RESULT_PASSIVE = "passive"
|
||||
self.RESULT_NOT_DETECTED = "not_detected"
|
||||
|
||||
|
||||
import workspace_tools.host_tests as host_tests
|
||||
|
@ -348,31 +349,12 @@ class Test(HostTestResults):
|
|||
self.notify("\n{{%s}}\n{{end}}" % result)
|
||||
|
||||
|
||||
class DefaultTest(Test):
|
||||
class DefaultTestSelector(Test):
|
||||
""" Test class with serial port initialization
|
||||
"""
|
||||
def __init__(self):
|
||||
HostTestResults.__init__(self)
|
||||
Test.__init__(self)
|
||||
|
||||
|
||||
class Simple(DefaultTest):
|
||||
""" Simple, basic host test's test runner waiting for serial port
|
||||
output from MUT, no supervision over test running in MUT is executed.
|
||||
"""
|
||||
def test(self):
|
||||
result = self.RESULT_SUCCESS
|
||||
try:
|
||||
while True:
|
||||
c = self.mbed.serial_read(512)
|
||||
if c is None:
|
||||
return self.RESULT_IO_SERIAL
|
||||
stdout.write(c)
|
||||
stdout.flush()
|
||||
except KeyboardInterrupt, _:
|
||||
self.notify("\r\n[CTRL+C] exit")
|
||||
result = self.RESULT_ERROR
|
||||
return result
|
||||
|
||||
if __name__ == '__main__':
|
||||
Simple().run()
|
||||
DefaultTestSelector().run()
|
||||
|
|
|
@ -16,24 +16,22 @@ limitations under the License.
|
|||
"""
|
||||
|
||||
import re
|
||||
from host_test import DefaultTest
|
||||
from time import time, strftime, gmtime
|
||||
|
||||
|
||||
class RTCTest(DefaultTest):
|
||||
class RTCTest():
|
||||
PATTERN_RTC_VALUE = "\[(\d+)\] \[(\d+-\d+-\d+ \d+:\d+:\d+ [AaPpMm]{2})\]"
|
||||
re_detect_rtc_value = re.compile(PATTERN_RTC_VALUE)
|
||||
|
||||
def test(self):
|
||||
def test(self, selftest):
|
||||
test_result = True
|
||||
start = time()
|
||||
sec_prev = 0
|
||||
for i in range(0, 5):
|
||||
# Timeout changed from default: we need to wait longer for some boards to start-up
|
||||
c = self.mbed.serial_readline(timeout=10)
|
||||
c = selftest.mbed.serial_readline(timeout=10)
|
||||
if c is None:
|
||||
return self.RESULT_IO_SERIAL
|
||||
self.notify(c.strip())
|
||||
return selftest.RESULT_IO_SERIAL
|
||||
selftest.notify(c.strip())
|
||||
delta = time() - start
|
||||
m = self.re_detect_rtc_value.search(c)
|
||||
if m and len(m.groups()):
|
||||
|
@ -42,14 +40,10 @@ class RTCTest(DefaultTest):
|
|||
correct_time_str = strftime("%Y-%m-%d %H:%M:%S %p", gmtime(float(sec)))
|
||||
test_result = test_result and (time_str == correct_time_str)
|
||||
result_msg = "OK" if (time_str == correct_time_str and sec > 0 and sec > sec_prev) else "FAIL"
|
||||
self.notify("HOST: [%s] [%s] received time %+d sec after %.2f sec... %s"% (sec, time_str, sec - sec_prev, delta, result_msg))
|
||||
selftest.notify("HOST: [%s] [%s] received time %+d sec after %.2f sec... %s"% (sec, time_str, sec - sec_prev, delta, result_msg))
|
||||
sec_prev = sec
|
||||
else:
|
||||
test_result = False
|
||||
break
|
||||
start = time()
|
||||
return self.RESULT_SUCCESS if test_result else self.RESULT_FAILURE
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
RTCTest().run()
|
||||
return selftest.RESULT_SUCCESS if test_result else selftest.RESULT_FAILURE
|
||||
|
|
|
@ -18,32 +18,30 @@ limitations under the License.
|
|||
import re
|
||||
import random
|
||||
from time import time
|
||||
from host_test import DefaultTest
|
||||
|
||||
|
||||
class StdioTest(DefaultTest):
|
||||
class StdioTest():
|
||||
PATTERN_INT_VALUE = "Your value was: (-?\d+)"
|
||||
re_detect_int_value = re.compile(PATTERN_INT_VALUE)
|
||||
|
||||
def test(self):
|
||||
def test(self, selftest):
|
||||
test_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
|
||||
self.notify(c)
|
||||
return selftest.RESULT_IO_SERIAL
|
||||
selftest.notify(c)
|
||||
|
||||
for i in range(0, 10):
|
||||
random_integer = random.randint(-99999, 99999)
|
||||
self.notify("HOST: Generated number: " + str(random_integer))
|
||||
selftest.notify("HOST: Generated number: " + str(random_integer))
|
||||
start = time()
|
||||
self.mbed.serial_write(str(random_integer) + "\n")
|
||||
selftest.mbed.serial_write(str(random_integer) + "\n")
|
||||
|
||||
serial_stdio_msg = self.mbed.serial_readline()
|
||||
serial_stdio_msg = selftest.mbed.serial_readline()
|
||||
if serial_stdio_msg is None:
|
||||
return self.RESULT_IO_SERIAL
|
||||
return selftest.RESULT_IO_SERIAL
|
||||
delay_time = time() - start
|
||||
self.notify(serial_stdio_msg.strip())
|
||||
selftest.notify(serial_stdio_msg.strip())
|
||||
|
||||
# Searching for reply with scanned values
|
||||
m = self.re_detect_int_value.search(serial_stdio_msg)
|
||||
|
@ -51,12 +49,8 @@ class StdioTest(DefaultTest):
|
|||
int_value = m.groups()[0]
|
||||
int_value_cmp = random_integer == int(int_value)
|
||||
test_result = test_result and int_value_cmp
|
||||
self.notify("HOST: Number %s read after %.3f sec ... [%s]"% (int_value, delay_time, "OK" if int_value_cmp else "FAIL"))
|
||||
selftest.notify("HOST: Number %s read after %.3f sec ... [%s]"% (int_value, delay_time, "OK" if int_value_cmp else "FAIL"))
|
||||
else:
|
||||
test_result = False
|
||||
break
|
||||
return self.RESULT_SUCCESS if test_result else self.RESULT_FAILURE
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
StdioTest().run()
|
||||
return selftest.RESULT_SUCCESS if test_result else selftest.RESULT_FAILURE
|
||||
|
|
|
@ -329,7 +329,7 @@ TESTS = [
|
|||
"dependencies": [MBED_LIBRARIES, TEST_MBED_LIB],
|
||||
"duration": 20,
|
||||
"automated": True,
|
||||
"host_test": "stdio_auto"
|
||||
#"host_test": "stdio_auto"
|
||||
},
|
||||
{
|
||||
"id": "MBED_3", "description": "PortOut",
|
||||
|
@ -411,9 +411,9 @@ TESTS = [
|
|||
{
|
||||
"id": "MBED_16", "description": "RTC",
|
||||
"source_dir": join(TEST_DIR, "mbed", "rtc"),
|
||||
"dependencies": [MBED_LIBRARIES],
|
||||
"dependencies": [MBED_LIBRARIES, TEST_MBED_LIB],
|
||||
"automated": True,
|
||||
"host_test": "rtc_auto",
|
||||
#"host_test": "rtc_auto",
|
||||
"duration": 15
|
||||
},
|
||||
{
|
||||
|
@ -862,7 +862,7 @@ TESTS = [
|
|||
"source_dir": join(TEST_DIR, "mbed", "dev_null"),
|
||||
"dependencies": [MBED_LIBRARIES, TEST_MBED_LIB],
|
||||
"automated": True,
|
||||
"host_test" : "dev_null_auto",
|
||||
#"host_test" : "dev_null_auto",
|
||||
},
|
||||
{
|
||||
"id": "EXAMPLE_2", "description": "FS + RTOS",
|
||||
|
|
Loading…
Reference in New Issue