-
Notifications
You must be signed in to change notification settings - Fork 3k
Socket closing improvements and tests adjustments #8499
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
""" | ||
Copyright 2018 ARM Limited | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
|
||
http://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
""" | ||
|
||
import threading | ||
import time | ||
|
||
from icetea_lib.bench import Bench | ||
from interface import interfaceUp, interfaceDown | ||
#from mbed_clitest.tools import test_case | ||
#from mbed_clitest.TestStepError import SkippedTestcaseException | ||
from icetea_lib.TestStepError import TestStepFail | ||
|
||
class Testcase(Bench): | ||
def __init__(self): | ||
Bench.__init__(self, | ||
name="TCPSOCKET_ACCEPT", | ||
title = "TCPSOCKET_ACCEPT", | ||
purpose = "Test that TCPSocket::bind(), TCPSocket::listen() and TCPSocket::accept() works", | ||
status = "released", | ||
component= ["mbed-os", "netsocket"], | ||
type="smoke", | ||
subtype="socket", | ||
requirements={ | ||
"duts": { | ||
'*': { #requirements for all nodes | ||
"count":2, | ||
"type": "hardware", | ||
"application": { | ||
"name": "TEST_APPS-device-socket_app" | ||
} | ||
}, | ||
"1": {"nick": "dut1"}, | ||
"2": {"nick": "dut2"} | ||
} | ||
} | ||
) | ||
|
||
def setup(self): | ||
interface = interfaceUp(self, ["dut1"]) | ||
self.server_ip = interface["dut1"]["ip"] | ||
interface = interfaceUp(self, ["dut2"]) | ||
self.client_ip = interface["dut2"]["ip"] | ||
|
||
def clientThread(self): | ||
self.logger.info("Starting") | ||
time.sleep(5) #wait accept from server | ||
self.command("dut2", "socket " + str(self.client_socket_id) + " open") | ||
self.command("dut2", "socket " + str(self.client_socket_id) + " connect " + str(self.server_ip) + " " + str(self.used_port)) | ||
|
||
|
||
def case(self): | ||
self.used_port = 2000 | ||
|
||
response = self.command("dut1", "socket new TCPSocket") | ||
self.server_base_socket_id = int(response.parsed['socket_id']) | ||
|
||
self.command("dut1", "socket " + str(self.server_base_socket_id) + " open") | ||
response = self.command("dut1", "socket " + str(self.server_base_socket_id) + " bind port " + str(self.used_port), report_cmd_fail = False) | ||
if response.retcode == -1: | ||
if (response.verify_trace("NSAPI_ERROR_UNSUPPORTED", break_in_fail = False)): | ||
raise SkippedTestcaseException("UNSUPPORTED") | ||
else: | ||
TestStepFail("Bind port failed") | ||
self.command("dut1", "socket " + str(self.server_base_socket_id) + " listen") | ||
|
||
response = self.command("dut2", "socket new TCPSocket") | ||
self.client_socket_id = int(response.parsed['socket_id']) | ||
|
||
#Create a thread which calls client connect() | ||
t = threading.Thread(name='clientThread', target=self.clientThread) | ||
t.start() | ||
|
||
response = self.command("dut1", "socket " + str(self.server_base_socket_id) + " accept") | ||
|
||
t.join() | ||
self.accept_socket_id = int(response.parsed['socket_id']) | ||
if response.timedelta < 5.0: # Check that socket accept call blocks | ||
raise TestStepFail("Longer response time expected") | ||
|
||
self.command("dut1", "socket " + str(self.accept_socket_id) + " send hello") | ||
|
||
response = self.command("dut2", "socket " + str(self.client_socket_id) + " recv 5") | ||
data = response.parsed['data'].replace(":","") | ||
|
||
if data != "hello": | ||
raise TestStepFail("Received data doesn't match the sent data") | ||
|
||
def teardown(self): | ||
response = self.command("dut2", "socket " + str(self.client_socket_id) + " delete") | ||
response = self.command("dut1", "socket " + str(self.server_base_socket_id) + " delete") | ||
response = self.command("dut1", "socket " + str(self.accept_socket_id) + " close") | ||
|
||
interfaceDown(self, ["dut1"]) | ||
interfaceDown(self, ["dut2"]) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.