mirror of https://github.com/ARMmbed/mbed-os.git
Host test plugins: refactored TCP ECHO SERVER testcase to use test() method instead of run()
parent
52f0b33e7a
commit
b404b21098
|
@ -32,12 +32,11 @@ class TCPEchoServerTest(DefaultTest):
|
||||||
PATTERN_SERVER_IP = "Server IP Address is (\d+).(\d+).(\d+).(\d+):(\d+)"
|
PATTERN_SERVER_IP = "Server IP Address is (\d+).(\d+).(\d+).(\d+):(\d+)"
|
||||||
re_detect_server_ip = re.compile(PATTERN_SERVER_IP)
|
re_detect_server_ip = re.compile(PATTERN_SERVER_IP)
|
||||||
|
|
||||||
def run(self):
|
def test(self):
|
||||||
result = False
|
result = False
|
||||||
c = self.mbed.serial_readline()
|
c = self.mbed.serial_readline()
|
||||||
if c is None:
|
if c is None:
|
||||||
self.print_result(self.RESULT_IO_SERIAL)
|
return self.RESULT_IO_SERIAL
|
||||||
return
|
|
||||||
self.notify(c)
|
self.notify(c)
|
||||||
|
|
||||||
m = self.re_detect_server_ip.search(c)
|
m = self.re_detect_server_ip.search(c)
|
||||||
|
@ -52,15 +51,20 @@ class TCPEchoServerTest(DefaultTest):
|
||||||
self.s.connect((self.ECHO_SERVER_ADDRESS, self.ECHO_PORT))
|
self.s.connect((self.ECHO_SERVER_ADDRESS, self.ECHO_PORT))
|
||||||
except Exception, e:
|
except Exception, e:
|
||||||
self.s = None
|
self.s = None
|
||||||
self.notify("HOST: Error: %s"% e)
|
self.notify("HOST: Socket error: %s"% e)
|
||||||
self.print_result(self.RESULT_ERROR)
|
return self.RESULT_ERROR
|
||||||
exit(-1)
|
|
||||||
|
|
||||||
print 'HOST: Sending %d echo strings...'% self.ECHO_LOOPs,
|
print 'HOST: Sending %d echo strings...'% self.ECHO_LOOPs,
|
||||||
for i in range(0, self.ECHO_LOOPs):
|
for i in range(0, self.ECHO_LOOPs):
|
||||||
TEST_STRING = str(uuid.uuid4())
|
TEST_STRING = str(uuid.uuid4())
|
||||||
self.s.sendall(TEST_STRING)
|
try:
|
||||||
data = self.s.recv(128)
|
self.s.sendall(TEST_STRING)
|
||||||
|
data = self.s.recv(128)
|
||||||
|
except Exception, e:
|
||||||
|
self.s = None
|
||||||
|
self.notify("HOST: Socket error: %s"% e)
|
||||||
|
return self.RESULT_ERROR
|
||||||
|
|
||||||
received_str = repr(data)[1:-1]
|
received_str = repr(data)[1:-1]
|
||||||
if TEST_STRING == received_str: # We need to cut not needed single quotes from the string
|
if TEST_STRING == received_str: # We need to cut not needed single quotes from the string
|
||||||
sys.stdout.write('.')
|
sys.stdout.write('.')
|
||||||
|
@ -77,22 +81,10 @@ class TCPEchoServerTest(DefaultTest):
|
||||||
if self.s is not None:
|
if self.s is not None:
|
||||||
self.s.close()
|
self.s.close()
|
||||||
else:
|
else:
|
||||||
print "HOST: TCP Server not found"
|
self.notify("HOST: TCP Server not found")
|
||||||
result = False
|
result = False
|
||||||
|
return self.RESULT_SUCCESS if result else self.RESULT_FAILURE
|
||||||
|
|
||||||
self.print_result(self.RESULT_SUCCESS if result else self.RESULT_FAILURE)
|
|
||||||
|
|
||||||
# Receiving
|
|
||||||
try:
|
|
||||||
while True:
|
|
||||||
c = self.mbed.serial_read(512)
|
|
||||||
if c is None:
|
|
||||||
self.print_result(self.RESULT_IO_SERIAL)
|
|
||||||
break
|
|
||||||
stdout.write(c)
|
|
||||||
stdout.flush()
|
|
||||||
except KeyboardInterrupt, _:
|
|
||||||
print "\n[CTRL+c] exit"
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
TCPEchoServerTest().run()
|
TCPEchoServerTest().run()
|
||||||
|
|
Loading…
Reference in New Issue