Skip to content

Commit

Permalink
Merge branch 'master' into version_0_0_2
Browse files Browse the repository at this point in the history
  • Loading branch information
theotherjimmy authored Jan 28, 2019
2 parents 5e531f1 + 64f82a0 commit bcd938d
Show file tree
Hide file tree
Showing 4 changed files with 104 additions and 9 deletions.
30 changes: 22 additions & 8 deletions src/mbed_os_tools/test/host_tests_runner/host_test_default.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,14 +179,9 @@ def callback__notify_prn(key, value, timestamp):
}

if self.options.global_resource_mgr:
grm_module, grm_host, grm_port = self.options.global_resource_mgr.split(':')

config.update({
"conn_resource" : 'grm',
"grm_module" : grm_module,
"grm_host" : grm_host,
"grm_port" : grm_port,
})
grm_config = self._parse_grm(self.options.global_resource_mgr)
grm_config["conn_resource"] = "grm"
config.update(grm_config)

if self.options.fast_model_connection:

Expand Down Expand Up @@ -572,3 +567,22 @@ def match_log(self, line):
# May not be a regular expression
return False
return self.compare_log_idx == len(self.compare_log)

@staticmethod
def _parse_grm(grm_arg):
grm_module, leftover = grm_arg.split(':', 1)
parts = leftover.rsplit(':', 1)

try:
grm_host, grm_port = parts
_ = int(grm_port)
except ValueError:
# No valid port was found, so assume no port was supplied
grm_host = leftover
grm_port = None

return {
"grm_module" : grm_module,
"grm_host" : grm_host,
"grm_port" : grm_port,
}
12 changes: 11 additions & 1 deletion src/mbed_os_tools/test/mbed_test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -570,7 +570,17 @@ def parse_global_resource_mgr(global_resource_mgr):
@return tuple wity four elements from GRM or None if error
"""
try:
platform_name, module_name, ip_name, port_name = global_resource_mgr.split(':')
platform_name, module_name, leftover = global_resource_mgr.split(':', 2)
parts = leftover.rsplit(':', 1)

try:
ip_name, port_name = parts
_ = int(port_name)
except ValueError:
# No valid port was found, so assume no port was supplied
ip_name = leftover
port_name = None

except ValueError as e:
return False
return platform_name, module_name, ip_name, port_name
Expand Down
54 changes: 54 additions & 0 deletions test/test/host_test_default.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# Copyright (c) 2018, Arm Limited and affiliates.
# SPDX-License-Identifier: Apache-2.0
#
# 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 unittest
from mbed_os_tools.test.host_tests_runner.host_test_default import DefaultTestSelector


class HostTestDefaultTestCase(unittest.TestCase):

def test_os_info(self):
expected = {
"grm_module" : "module_name",
"grm_host" : "10.2.123.43",
"grm_port" : "3334",
}

# Case that includes an IP address but no protocol
arg = [expected["grm_module"], expected["grm_host"], expected["grm_port"]]
result = DefaultTestSelector._parse_grm(":".join(arg))
self.assertEqual(result, expected)

# Case that includes an IP address but no protocol nor a no port
expected["grm_port"] = None
arg = [expected["grm_module"], expected["grm_host"]]
result = DefaultTestSelector._parse_grm(":".join(arg))
self.assertEqual(result, expected)

# Case that includes an IP address and a protocol
expected["grm_host"] = "https://10.2.123.43"
expected["grm_port"] = "443"
arg = [expected["grm_module"], expected["grm_host"], expected["grm_port"]]
result = DefaultTestSelector._parse_grm(":".join(arg))
self.assertEqual(result, expected)

# Case that includes an IP address and a protocol, but no port
expected["grm_port"] = None
arg = [expected["grm_module"], expected["grm_host"]]
result = DefaultTestSelector._parse_grm(":".join(arg))
self.assertEqual(result, expected)

if __name__ == '__main__':
unittest.main()
17 changes: 17 additions & 0 deletions test/test/mbed_gt_test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -599,5 +599,22 @@ def test_run_htrun_unicode(self):
_run_command.return_value = p_mock
returncode, htrun_output = mbed_test_api.run_htrun("dummy", True)

def test_parse_global_resource_mgr(self):
expected = ("K64F", "module_name", "10.2.123.43", "3334")
result = mbed_test_api.parse_global_resource_mgr(":".join(expected))
self.assertEqual(result, expected)

expected = ("K64F", "module_name", "10.2.123.43", None)
result = mbed_test_api.parse_global_resource_mgr(":".join(expected[:3]))
self.assertEqual(result, expected)

expected = ("K64F", "module_name", "https://10.2.123.43", "3334")
result = mbed_test_api.parse_global_resource_mgr(":".join(expected))
self.assertEqual(result, expected)

expected = ("K64F", "module_name", "https://10.2.123.43", None)
result = mbed_test_api.parse_global_resource_mgr(":".join(expected[:3]))
self.assertEqual(result, expected)

if __name__ == '__main__':
unittest.main()

0 comments on commit bcd938d

Please sign in to comment.