forked from ARMmbed/htrun
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add functions to detect host OS (helpful when porting some plugins pe…
…r OS)
- Loading branch information
1 parent
1d5bed7
commit a52e8af
Showing
2 changed files
with
87 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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 |
---|---|---|
|
@@ -17,6 +17,10 @@ | |
Author: Przemyslaw Wirkus <[email protected]> | ||
""" | ||
|
||
import os | ||
import sys | ||
import platform | ||
|
||
from os import access, F_OK | ||
from sys import stdout | ||
from time import sleep | ||
|
@@ -152,3 +156,30 @@ def run_command(self, cmd, shell=True): | |
self.print_plugin_error("[ret=%d] Command: %s"% (int(ret), cmd)) | ||
self.print_plugin_error(str(e)) | ||
return result | ||
|
||
def mbed_os_info(self): | ||
"""! Returns information about host OS | ||
@return Returns tuple with information about OS and host platform | ||
""" | ||
result = (os.name, | ||
platform.system(), | ||
platform.release(), | ||
platform.version(), | ||
sys.platform) | ||
return result | ||
|
||
def mbed_os_support(self): | ||
"""! Function used to determine host OS | ||
@return Returns None if host OS is unknown, else string with name | ||
@details This function should be ported for new OS support | ||
""" | ||
result = None | ||
os_info = self.mbed_os_info() | ||
if (os_info[0] == 'nt' and os_info[1] == 'Windows'): | ||
result = 'Windows7' | ||
elif (os_info[0] == 'posix' and os_info[1] == 'Linux' and ('Ubuntu' in os_info[3])): | ||
result = 'Ubuntu' | ||
elif (os_info[0] == 'posix' and os_info[1] == 'Darwin'): | ||
result = 'Darwin' | ||
return result |
This file contains 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,56 @@ | ||
#!/usr/bin/env python | ||
""" | ||
mbed SDK | ||
Copyright (c) 2011-2015 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 unittest | ||
|
||
import os | ||
import sys | ||
import platform | ||
from mbed_host_tests.host_tests_plugins.host_test_plugins import HostTestPluginBase | ||
|
||
class HostOSDetectionTestCase(unittest.TestCase): | ||
|
||
def setUp(self): | ||
self.plugin_base = HostTestPluginBase() | ||
|
||
pass | ||
|
||
def tearDown(self): | ||
pass | ||
|
||
def test_os_info(self): | ||
self.assertNotEqual(None, self.plugin_base.mbed_os_info()) | ||
|
||
def test_os_support(self): | ||
self.assertNotEqual(None, self.plugin_base.mbed_os_support()) | ||
|
||
def test_supported_os_name(self): | ||
os_names = ['Windows7', 'Ubuntu', 'Darwin'] | ||
self.assertIn(self.plugin_base.mbed_os_support(), os_names) | ||
|
||
def test_detect_os_support_ext(self): | ||
os_info = (os.name, | ||
platform.system(), | ||
platform.release(), | ||
platform.version(), | ||
sys.platform) | ||
|
||
self.assertEqual(os_info, self.plugin_base.mbed_os_info()) | ||
|
||
if __name__ == '__main__': | ||
unittest.main() |