Skip to content

Commit bcd938d

Browse files
Merge branch 'master' into version_0_0_2
2 parents 5e531f1 + 64f82a0 commit bcd938d

File tree

4 files changed

+104
-9
lines changed

4 files changed

+104
-9
lines changed

src/mbed_os_tools/test/host_tests_runner/host_test_default.py

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -179,14 +179,9 @@ def callback__notify_prn(key, value, timestamp):
179179
}
180180

181181
if self.options.global_resource_mgr:
182-
grm_module, grm_host, grm_port = self.options.global_resource_mgr.split(':')
183-
184-
config.update({
185-
"conn_resource" : 'grm',
186-
"grm_module" : grm_module,
187-
"grm_host" : grm_host,
188-
"grm_port" : grm_port,
189-
})
182+
grm_config = self._parse_grm(self.options.global_resource_mgr)
183+
grm_config["conn_resource"] = "grm"
184+
config.update(grm_config)
190185

191186
if self.options.fast_model_connection:
192187

@@ -572,3 +567,22 @@ def match_log(self, line):
572567
# May not be a regular expression
573568
return False
574569
return self.compare_log_idx == len(self.compare_log)
570+
571+
@staticmethod
572+
def _parse_grm(grm_arg):
573+
grm_module, leftover = grm_arg.split(':', 1)
574+
parts = leftover.rsplit(':', 1)
575+
576+
try:
577+
grm_host, grm_port = parts
578+
_ = int(grm_port)
579+
except ValueError:
580+
# No valid port was found, so assume no port was supplied
581+
grm_host = leftover
582+
grm_port = None
583+
584+
return {
585+
"grm_module" : grm_module,
586+
"grm_host" : grm_host,
587+
"grm_port" : grm_port,
588+
}

src/mbed_os_tools/test/mbed_test_api.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -570,7 +570,17 @@ def parse_global_resource_mgr(global_resource_mgr):
570570
@return tuple wity four elements from GRM or None if error
571571
"""
572572
try:
573-
platform_name, module_name, ip_name, port_name = global_resource_mgr.split(':')
573+
platform_name, module_name, leftover = global_resource_mgr.split(':', 2)
574+
parts = leftover.rsplit(':', 1)
575+
576+
try:
577+
ip_name, port_name = parts
578+
_ = int(port_name)
579+
except ValueError:
580+
# No valid port was found, so assume no port was supplied
581+
ip_name = leftover
582+
port_name = None
583+
574584
except ValueError as e:
575585
return False
576586
return platform_name, module_name, ip_name, port_name

test/test/host_test_default.py

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
# Copyright (c) 2018, Arm Limited and affiliates.
2+
# SPDX-License-Identifier: Apache-2.0
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
16+
import unittest
17+
from mbed_os_tools.test.host_tests_runner.host_test_default import DefaultTestSelector
18+
19+
20+
class HostTestDefaultTestCase(unittest.TestCase):
21+
22+
def test_os_info(self):
23+
expected = {
24+
"grm_module" : "module_name",
25+
"grm_host" : "10.2.123.43",
26+
"grm_port" : "3334",
27+
}
28+
29+
# Case that includes an IP address but no protocol
30+
arg = [expected["grm_module"], expected["grm_host"], expected["grm_port"]]
31+
result = DefaultTestSelector._parse_grm(":".join(arg))
32+
self.assertEqual(result, expected)
33+
34+
# Case that includes an IP address but no protocol nor a no port
35+
expected["grm_port"] = None
36+
arg = [expected["grm_module"], expected["grm_host"]]
37+
result = DefaultTestSelector._parse_grm(":".join(arg))
38+
self.assertEqual(result, expected)
39+
40+
# Case that includes an IP address and a protocol
41+
expected["grm_host"] = "https://10.2.123.43"
42+
expected["grm_port"] = "443"
43+
arg = [expected["grm_module"], expected["grm_host"], expected["grm_port"]]
44+
result = DefaultTestSelector._parse_grm(":".join(arg))
45+
self.assertEqual(result, expected)
46+
47+
# Case that includes an IP address and a protocol, but no port
48+
expected["grm_port"] = None
49+
arg = [expected["grm_module"], expected["grm_host"]]
50+
result = DefaultTestSelector._parse_grm(":".join(arg))
51+
self.assertEqual(result, expected)
52+
53+
if __name__ == '__main__':
54+
unittest.main()

test/test/mbed_gt_test_api.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -599,5 +599,22 @@ def test_run_htrun_unicode(self):
599599
_run_command.return_value = p_mock
600600
returncode, htrun_output = mbed_test_api.run_htrun("dummy", True)
601601

602+
def test_parse_global_resource_mgr(self):
603+
expected = ("K64F", "module_name", "10.2.123.43", "3334")
604+
result = mbed_test_api.parse_global_resource_mgr(":".join(expected))
605+
self.assertEqual(result, expected)
606+
607+
expected = ("K64F", "module_name", "10.2.123.43", None)
608+
result = mbed_test_api.parse_global_resource_mgr(":".join(expected[:3]))
609+
self.assertEqual(result, expected)
610+
611+
expected = ("K64F", "module_name", "https://10.2.123.43", "3334")
612+
result = mbed_test_api.parse_global_resource_mgr(":".join(expected))
613+
self.assertEqual(result, expected)
614+
615+
expected = ("K64F", "module_name", "https://10.2.123.43", None)
616+
result = mbed_test_api.parse_global_resource_mgr(":".join(expected[:3]))
617+
self.assertEqual(result, expected)
618+
602619
if __name__ == '__main__':
603620
unittest.main()

0 commit comments

Comments
 (0)