From e3e49cb67d054cc425af7630673f0f11ce2ddf42 Mon Sep 17 00:00:00 2001 From: Przemek Wirkus Date: Tue, 23 Sep 2014 11:41:35 +0100 Subject: [PATCH] Small improvements to ETH test cases - handle not open socket on host test side --- workspace_tools/host_tests/tcpecho_server_auto.py | 5 ++++- workspace_tools/host_tests/udp_link_layer_auto.py | 12 +++++++++--- workspace_tools/host_tests/udpecho_server_auto.py | 5 ++++- 3 files changed, 17 insertions(+), 5 deletions(-) diff --git a/workspace_tools/host_tests/tcpecho_server_auto.py b/workspace_tools/host_tests/tcpecho_server_auto.py index 2829171456..f98f0264ff 100644 --- a/workspace_tools/host_tests/tcpecho_server_auto.py +++ b/workspace_tools/host_tests/tcpecho_server_auto.py @@ -53,6 +53,7 @@ class TCPEchoServerTest(DefaultTest): self.s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) self.s.connect((self.ECHO_SERVER_ADDRESS, self.ECHO_PORT)) except Exception, e: + self.s = None print "HOST: Error: %s" % e self.print_result('error') exit(-1) @@ -74,7 +75,9 @@ class TCPEchoServerTest(DefaultTest): print "'%s'"% received_str result = False break - self.s.close() + + if self.s is not None: + self.s.close() else: print "HOST: TCP Server not found" result = False diff --git a/workspace_tools/host_tests/udp_link_layer_auto.py b/workspace_tools/host_tests/udp_link_layer_auto.py index e7d04f5854..156b3a143d 100644 --- a/workspace_tools/host_tests/udp_link_layer_auto.py +++ b/workspace_tools/host_tests/udp_link_layer_auto.py @@ -71,8 +71,11 @@ class UDPEchoServerTest(DefaultTest): def get_control_data(self, command="stat\n"): BUFFER_SIZE = 256 - s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) - s.connect((self.ECHO_SERVER_ADDRESS, self.CONTROL_PORT)) + try: + s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) + s.connect((self.ECHO_SERVER_ADDRESS, self.CONTROL_PORT)) + except Exception, e: + data = None s.send(command) data = s.recv(BUFFER_SIZE) s.close() @@ -97,6 +100,7 @@ class UDPEchoServerTest(DefaultTest): try: self.s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) except Exception, e: + self.s = None print "HOST: Error: %s" % e self.print_result('error') return @@ -114,7 +118,9 @@ class UDPEchoServerTest(DefaultTest): self.s.sendto(payload, (self.ECHO_SERVER_ADDRESS, self.ECHO_PORT)) dict_udp_sent_datagrams[payload] = time() sleep(self.TEST_STRESS_FACTOR) - self.s.close() + + if self.s is not None: + self.s.close() # Wait 5 seconds for packets to come result = True diff --git a/workspace_tools/host_tests/udpecho_server_auto.py b/workspace_tools/host_tests/udpecho_server_auto.py index c63c76e519..5697a42821 100644 --- a/workspace_tools/host_tests/udpecho_server_auto.py +++ b/workspace_tools/host_tests/udpecho_server_auto.py @@ -53,6 +53,7 @@ class UDPEchoServerTest(DefaultTest): try: self.s = socket(AF_INET, SOCK_DGRAM) except Exception, e: + self.s = None print "HOST: Error: %s" % e self.print_result('error') exit(-1) @@ -70,7 +71,9 @@ class UDPEchoServerTest(DefaultTest): else: result = False - self.s.close() + if self.s is not None: + self.s.close() + if result: self.print_result('success') else: