Skip to content

Commit

Permalink
Add functions to detect host OS (helpful when porting some plugins pe…
Browse files Browse the repository at this point in the history
…r OS)
  • Loading branch information
PrzemekWirkus committed Oct 9, 2015
1 parent 1d5bed7 commit a52e8af
Show file tree
Hide file tree
Showing 2 changed files with 87 additions and 0 deletions.
31 changes: 31 additions & 0 deletions mbed_host_tests/host_tests_plugins/host_test_plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
56 changes: 56 additions & 0 deletions test/host_test_plugins.py
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()

0 comments on commit a52e8af

Please sign in to comment.