Diff
Modified: trunk/Tools/ChangeLog (104636 => 104637)
--- trunk/Tools/ChangeLog 2012-01-10 23:19:03 UTC (rev 104636)
+++ trunk/Tools/ChangeLog 2012-01-10 23:33:59 UTC (rev 104637)
@@ -1,3 +1,53 @@
+2012-01-09 Dirk Pranke <[email protected]>
+
+ webkitpy: add os_name, os_version to platforminfo
+ https://bugs.webkit.org/show_bug.cgi?id=75931
+
+ Reviewed by Eric Siedel.
+
+ As a first step in cleaning up the version parsing logic in
+ webkitpy.layout_tests.port, this adds common routines for
+ getting the os_name and os_version fields to the PlatformInfo
+ class. Nothing uses them yet but I've added FIXME's to some of
+ the code that needs to be deleted in the port files.
+
+ * Scripts/webkitpy/common/system/platforminfo.py:
+ (PlatformInfo.__init__):
+ (PlatformInfo):
+ (PlatformInfo._determine_os_name):
+ (PlatformInfo._determine_mac_version):
+ (PlatformInfo._determine_linux_version):
+ (PlatformInfo._determine_win_version):
+ (PlatformInfo.display_name):
+ (PlatformInfo.total_bytes_memory):
+ (PlatformInfo._compute_bytes_from_vm_stat_output):
+ (PlatformInfo.free_bytes_memory):
+ * Scripts/webkitpy/common/system/platforminfo_unittest.py: Added.
+ (TestPlatformInfo):
+ (TestPlatformInfo.make_info):
+ (TestPlatformInfo.make_info.mock_run_command):
+ (TestPlatformInfo.setUp):
+ (TestPlatformInfo.tearDown):
+ (TestPlatformInfo.test_basic):
+ (TestPlatformInfo.integration_test_basic):
+ (TestPlatformInfo.test_display_name_mac):
+ (TestPlatformInfo.test_display_name_win32):
+ (TestPlatformInfo.test_memory_mac):
+ (TestPlatformInfo.test_memory_win32):
+ (TestPlatformInfo.test_determine_os_name):
+ (TestPlatformInfo.test_determine_mac_version):
+ (TestPlatformInfo.test_determine_linux_version):
+ (TestPlatformInfo.test_determine_win_version_from_tuple):
+ (TestPlatformInfo.test_determine_win_version_from_cmd):
+ * Scripts/webkitpy/layout_tests/port/apple.py:
+ (ApplePort.__init__):
+ * Scripts/webkitpy/layout_tests/port/chromium_mac.py:
+ (ChromiumMacPort.__init__):
+ * Scripts/webkitpy/layout_tests/port/mac.py:
+ (MacPort):
+ * Scripts/webkitpy/layout_tests/port/win.py:
+ (WinPort):
+
2012-01-10 Adam Roben <[email protected]>
Make it possible to type data: URLs into MiniBrowser on Windows
Modified: trunk/Tools/Scripts/webkitpy/common/system/platforminfo.py (104636 => 104637)
--- trunk/Tools/Scripts/webkitpy/common/system/platforminfo.py 2012-01-10 23:19:03 UTC (rev 104636)
+++ trunk/Tools/Scripts/webkitpy/common/system/platforminfo.py 2012-01-10 23:33:59 UTC (rev 104637)
@@ -1,4 +1,4 @@
-# Copyright (c) 2010 Google Inc. All rights reserved.
+# Copyright (c) 2011 Google Inc. All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are
@@ -26,46 +26,118 @@
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-import platform
import re
-# We use this instead of calls to platform directly to allow mocking.
class PlatformInfo(object):
- def __init__(self, executive):
+ """This class provides a consistent (and mockable) interpretation of
+ system-specific values (like sys.platform and platform.mac_ver())
+ to be used by the rest of the webkitpy code base.
+
+ Public (static) properties:
+ -- os_name
+ -- os_version
+
+ Note that 'future' is returned for os_version if the operating system is
+ newer than one known to the code.
+ """
+
+ def __init__(self, sys_module, platform_module, executive):
self._executive = executive
+ self._platform_module = platform_module
+ self.os_name = self._determine_os_name(sys_module.platform)
+ if self.os_name == 'linux':
+ self.os_version = self._determine_linux_version()
+ if self.os_name.startswith('mac'):
+ self.os_version = self._determine_mac_version(platform_module.mac_ver()[0])
+ if self.os_name.startswith('win'):
+ self.os_version = self._determine_win_version(self._win_version_tuple(sys_module))
+ def is_mac(self):
+ return self.os_name == 'mac'
+
+ def is_win(self):
+ return self.os_name == 'win'
+
+ def is_linux(self):
+ return self.os_name == 'linux'
+
def display_name(self):
# platform.platform() returns Darwin information for Mac, which is just confusing.
- if platform.system() == "Darwin":
- return "Mac OS X %s" % platform.mac_ver()[0]
+ if self.is_mac():
+ return "Mac OS X %s" % self._platform_module.mac_ver()[0]
# Returns strings like:
# Linux-2.6.18-194.3.1.el5-i686-with-redhat-5.5-Final
# Windows-2008ServerR2-6.1.7600
- return platform.platform()
+ return self._platform_module.platform()
+ def free_bytes_memory(self):
+ if self.is_mac():
+ vm_stat_output = self._executive.run_command(["vm_stat"])
+ free_bytes = self._compute_bytes_from_vm_stat_output("Pages free", vm_stat_output)
+ # Per https://bugs.webkit.org/show_bug.cgi?id=74650 include inactive memory since the OS is lazy about freeing memory.
+ free_bytes += self._compute_bytes_from_vm_stat_output("Pages inactive", vm_stat_output)
+ return free_bytes
+ return None
+
def total_bytes_memory(self):
- system_name = platform.system()
- if system_name == "Darwin":
+ if self.is_mac():
return int(self._executive.run_command(["sysctl", "-n", "hw.memsize"]))
return None
+ def _determine_os_name(self, sys_platform):
+ if sys_platform == 'darwin':
+ return 'mac'
+ if sys_platform.startswith('linux'):
+ return 'linux'
+ if sys_platform in ('win32', 'cygwin'):
+ return 'win'
+ raise AssertionError('unrecognized platform string "%s"' % sys_platform)
+
+ def _determine_mac_version(self, mac_version_string):
+ release_version = mac_version_string.split('.')[1]
+ version_strings = {
+ '5': 'leopard',
+ '6': 'snowleopard',
+ '7': 'lion',
+ }
+ assert release_version >= min(version_strings.keys())
+ return version_strings.get(release_version, 'future')
+
+ def _determine_linux_version(self):
+ # FIXME: we ignore whatever the real version is and pretend it's lucid for now.
+ return 'lucid'
+
+ def _determine_win_version(self, win_version_tuple):
+ if win_version_tuple[:3] == (6, 1, 7600):
+ return '7sp0'
+ if win_version_tuple[:2] == (6, 0):
+ return 'vista'
+ if win_version_tuple[:2] == (5, 1):
+ return 'xp'
+ assert win_version_tuple[0] > 6 or win_version_tuple[1] >= 1, 'Unrecognized Windows version tuple: "%s"' % (win_version_tuple,)
+ return 'future'
+
+ def _win_version_tuple(self, sys_module):
+ if hasattr(sys_module, 'getwindowsversion'):
+ return sys_module.getwindowsversion()
+ return self._win_version_tuple_from_cmd()
+
+ def _win_version_tuple_from_cmd(self):
+ # Note that this should only ever be called on windows, so this should always work.
+ ver_output = self._executive.run_command(['cmd', '/c', 'ver'])
+ match_object = re.search(r'(?P<major>\d)\.(?P<minor>\d)\.(?P<build>\d+)', ver_output)
+ assert match_object, 'cmd returned an unexpected version string: ' + ver_output
+ return tuple(map(int, match_object.groups()))
+
def _compute_bytes_from_vm_stat_output(self, label_text, vm_stat_output):
page_size_match = re.search(r"page size of (\d+) bytes", vm_stat_output)
free_pages_match = re.search(r"%s:\s+(\d+)." % label_text, vm_stat_output)
- if not page_size_match or not free_pages_match:
- return None
+
+ # Fail hard if vmstat's output isn't what we expect.
+ assert(page_size_match and free_pages_match)
+
free_page_count = int(free_pages_match.group(1))
page_size = int(page_size_match.group(1))
return free_page_count * page_size
-
- def free_bytes_memory(self):
- system_name = platform.system()
- if system_name == "Darwin":
- vm_stat_output = self._executive.run_command(["vm_stat"])
- free_bytes = self._compute_bytes_from_vm_stat_output("Pages free", vm_stat_output)
- # Per https://bugs.webkit.org/show_bug.cgi?id=74650 include inactive memory since the OS is lazy about freeing memory.
- free_bytes += self._compute_bytes_from_vm_stat_output("Pages inactive", vm_stat_output)
- return free_bytes
- return None
Modified: trunk/Tools/Scripts/webkitpy/common/system/platforminfo_mock.py (104636 => 104637)
--- trunk/Tools/Scripts/webkitpy/common/system/platforminfo_mock.py 2012-01-10 23:19:03 UTC (rev 104636)
+++ trunk/Tools/Scripts/webkitpy/common/system/platforminfo_mock.py 2012-01-10 23:33:59 UTC (rev 104637)
@@ -28,6 +28,18 @@
class MockPlatformInfo(object):
+ os_name = 'mac'
+ os_version = 'snowleopard'
+
+ def is_mac(self):
+ return True
+
+ def is_linux(self):
+ return False
+
+ def is_windows(self):
+ return False
+
def display_name(self):
return "MockPlatform 1.0"
Added: trunk/Tools/Scripts/webkitpy/common/system/platforminfo_unittest.py (0 => 104637)
--- trunk/Tools/Scripts/webkitpy/common/system/platforminfo_unittest.py (rev 0)
+++ trunk/Tools/Scripts/webkitpy/common/system/platforminfo_unittest.py 2012-01-10 23:33:59 UTC (rev 104637)
@@ -0,0 +1,174 @@
+# Copyright (C) 2011 Google Inc. All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions are
+# met:
+#
+# * Redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer.
+# * Redistributions in binary form must reproduce the above
+# copyright notice, this list of conditions and the following disclaimer
+# in the documentation and/or other materials provided with the
+# distribution.
+# * Neither the name of Google Inc. nor the names of its
+# contributors may be used to endorse or promote products derived from
+# this software without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+import platform
+import sys
+import unittest
+
+from webkitpy.common.system.executive import Executive
+from webkitpy.common.system.executive_mock import MockExecutive, MockExecutive2
+from webkitpy.common.system.platforminfo import PlatformInfo
+
+
+def fake_sys(platform_str='darwin', windows_version_tuple=None):
+
+ class FakeSysModule(object):
+ platform = platform_str
+ if windows_version_tuple:
+ getwindowsversion = lambda x: windows_version_tuple
+
+ return FakeSysModule()
+
+
+def fake_platform(mac_version_string='10.6.3'):
+
+ class FakePlatformModule(object):
+ def mac_ver(self):
+ return tuple([mac_version_string, tuple(['', '', '']), 'i386'])
+
+ def platform(self):
+ return 'foo'
+
+ return FakePlatformModule()
+
+
+def fake_executive(output=None):
+ if output:
+ return MockExecutive2(output=output)
+ return MockExecutive2(exception=SystemError)
+
+
+class TestPlatformInfo(unittest.TestCase):
+ def make_info(self, sys_module=None, platform_module=None, executive=None):
+ return PlatformInfo(sys_module or fake_sys(), platform_module or fake_platform(), executive or fake_executive())
+
+ # FIXME: This should be called integration_test_real_code(), but integration tests aren't
+ # yet run by default and there's no reason not to run this everywhere by default.
+ def test_real_code(self):
+ # This test makes sure the real (unmocked) code actually works.
+ info = PlatformInfo(sys, platform, Executive())
+ self.assertNotEquals(info.os_name, '')
+ self.assertNotEquals(info.os_version, '')
+ self.assertNotEquals(info.display_name(), '')
+ self.assertTrue(info.is_mac() or info.is_win() or info.is_linux())
+
+ if info.is_mac():
+ self.assertTrue(info.total_bytes_memory() > 0)
+ self.assertTrue(info.free_bytes_memory() > 0)
+ else:
+ self.assertEquals(info.total_bytes_memory(), None)
+ self.assertEquals(info.free_bytes_memory(), None)
+
+ def test_os_name_and_wrappers(self):
+ info = self.make_info(fake_sys('linux2'))
+ self.assertTrue(info.is_linux())
+ self.assertFalse(info.is_mac())
+ self.assertFalse(info.is_win())
+
+ info = self.make_info(fake_sys('linux3'))
+ self.assertTrue(info.is_linux())
+ self.assertFalse(info.is_mac())
+ self.assertFalse(info.is_win())
+
+ info = self.make_info(fake_sys('darwin'), fake_platform('10.6.3'))
+ self.assertEquals(info.os_name, 'mac')
+ self.assertFalse(info.is_linux())
+ self.assertTrue(info.is_mac())
+ self.assertFalse(info.is_win())
+
+ info = self.make_info(fake_sys('win32', tuple([6, 1, 7600])))
+ self.assertEquals(info.os_name, 'win')
+ self.assertFalse(info.is_linux())
+ self.assertFalse(info.is_mac())
+ self.assertTrue(info.is_win())
+
+ info = self.make_info(fake_sys('cygwin'), executive=fake_executive('6.1.7600'))
+ self.assertEquals(info.os_name, 'win')
+ self.assertFalse(info.is_linux())
+ self.assertFalse(info.is_mac())
+ self.assertTrue(info.is_win())
+
+ self.assertRaises(AssertionError, self.make_info, fake_sys('vms'))
+
+ def test_os_version(self):
+ self.assertRaises(AssertionError, self.make_info, fake_sys('darwin'), fake_platform('10.4.3'))
+ self.assertEquals(self.make_info(fake_sys('darwin'), fake_platform('10.5.1')).os_version, 'leopard')
+ self.assertEquals(self.make_info(fake_sys('darwin'), fake_platform('10.6.1')).os_version, 'snowleopard')
+ self.assertEquals(self.make_info(fake_sys('darwin'), fake_platform('10.7.1')).os_version, 'lion')
+ self.assertEquals(self.make_info(fake_sys('darwin'), fake_platform('10.8.0')).os_version, 'future')
+
+ self.assertEquals(self.make_info(fake_sys('linux2')).os_version, 'lucid')
+
+ self.assertRaises(AssertionError, self.make_info, fake_sys('win32', tuple([5, 0, 1234])))
+ self.assertEquals(self.make_info(fake_sys('win32', tuple([6, 2, 1234]))).os_version, 'future')
+ self.assertEquals(self.make_info(fake_sys('win32', tuple([6, 1, 7600]))).os_version, '7sp0')
+ self.assertEquals(self.make_info(fake_sys('win32', tuple([6, 0, 1234]))).os_version, 'vista')
+ self.assertEquals(self.make_info(fake_sys('win32', tuple([5, 1, 1234]))).os_version, 'xp')
+
+ self.assertRaises(AssertionError, self.make_info, fake_sys('win32'), executive=fake_executive('5.0.1234'))
+ self.assertEquals(self.make_info(fake_sys('cygwin'), executive=fake_executive('6.2.1234')).os_version, 'future')
+ self.assertEquals(self.make_info(fake_sys('cygwin'), executive=fake_executive('6.1.7600')).os_version, '7sp0')
+ self.assertEquals(self.make_info(fake_sys('cygwin'), executive=fake_executive('6.0.1234')).os_version, 'vista')
+ self.assertEquals(self.make_info(fake_sys('cygwin'), executive=fake_executive('5.1.1234')).os_version, 'xp')
+
+ def test_display_name(self):
+ info = self.make_info(fake_sys('darwin'))
+ self.assertNotEquals(info.display_name(), '')
+
+ info = self.make_info(fake_sys('win32', tuple([6, 1, 7600])))
+ self.assertNotEquals(info.display_name(), '')
+
+ info = self.make_info(fake_sys('linux2'))
+ self.assertNotEquals(info.display_name(), '')
+
+ def test_total_bytes_memory(self):
+ info = self.make_info(fake_sys('darwin'), fake_platform('10.6.3'), fake_executive('1234'))
+ self.assertEquals(info.total_bytes_memory(), 1234)
+
+ info = self.make_info(fake_sys('win32', tuple([6, 1, 7600])))
+ self.assertEquals(info.total_bytes_memory(), None)
+
+ info = self.make_info(fake_sys('linux2'))
+ self.assertEquals(info.total_bytes_memory(), None)
+
+ def test_free_bytes_memory(self):
+ vmstat_output = ("Mach Virtual Memory Statistics: (page size of 4096 bytes)\n"
+ "Pages free: 1.\n"
+ "Pages inactive: 1.\n")
+ info = self.make_info(fake_sys('darwin'), fake_platform('10.6.3'), fake_executive(vmstat_output))
+ self.assertEquals(info.free_bytes_memory(), 8192)
+
+ info = self.make_info(fake_sys('win32', tuple([6, 1, 7600])))
+ self.assertEquals(info.free_bytes_memory(), None)
+
+ info = self.make_info(fake_sys('linux2'))
+ self.assertEquals(info.free_bytes_memory(), None)
+
+
+if __name__ == '__main__':
+ unittest.main()
Property changes on: trunk/Tools/Scripts/webkitpy/common/system/platforminfo_unittest.py
___________________________________________________________________
Added: svn:eol-style
Modified: trunk/Tools/Scripts/webkitpy/common/system/systemhost.py (104636 => 104637)
--- trunk/Tools/Scripts/webkitpy/common/system/systemhost.py 2012-01-10 23:19:03 UTC (rev 104636)
+++ trunk/Tools/Scripts/webkitpy/common/system/systemhost.py 2012-01-10 23:33:59 UTC (rev 104637)
@@ -27,6 +27,8 @@
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
import os
+import platform
+import sys
from webkitpy.common.system import environment, executive, filesystem, platforminfo, user, workspace
@@ -36,7 +38,7 @@
self.executive = executive.Executive()
self.filesystem = filesystem.FileSystem()
self.user = user.User()
- self.platform = platforminfo.PlatformInfo(self.executive)
+ self.platform = platforminfo.PlatformInfo(sys, platform, self.executive)
self.workspace = workspace.Workspace(self.filesystem, self.executive)
def copy_current_environment(self):
Modified: trunk/Tools/Scripts/webkitpy/layout_tests/port/apple.py (104636 => 104637)
--- trunk/Tools/Scripts/webkitpy/layout_tests/port/apple.py 2012-01-10 23:19:03 UTC (rev 104636)
+++ trunk/Tools/Scripts/webkitpy/layout_tests/port/apple.py 2012-01-10 23:33:59 UTC (rev 104637)
@@ -67,6 +67,7 @@
self.set_option_default('webkit_test_runner', True)
if port_name == self.port_name:
+ # FIXME: Use host.platforminfo.os_version instead.
self._version = self._detect_version(os_version_string) or self.FUTURE_VERSION
self._name = self.port_name + '-' + self._version
else:
Modified: trunk/Tools/Scripts/webkitpy/layout_tests/port/chromium_mac.py (104636 => 104637)
--- trunk/Tools/Scripts/webkitpy/layout_tests/port/chromium_mac.py 2012-01-10 23:19:03 UTC (rev 104636)
+++ trunk/Tools/Scripts/webkitpy/layout_tests/port/chromium_mac.py 2012-01-10 23:33:59 UTC (rev 104637)
@@ -83,6 +83,7 @@
port_name = port_name or 'chromium-mac'
chromium.ChromiumPort.__init__(self, host, port_name=port_name, **kwargs)
if port_name.endswith('-mac'):
+ # FIXME: Use host.platforminfo.os_version instead.
self._version = mac.os_version(os_version_string, self.SUPPORTED_OS_VERSIONS)
self._name = port_name + '-' + self._version
else:
Modified: trunk/Tools/Scripts/webkitpy/layout_tests/port/mac.py (104636 => 104637)
--- trunk/Tools/Scripts/webkitpy/layout_tests/port/mac.py 2012-01-10 23:19:03 UTC (rev 104636)
+++ trunk/Tools/Scripts/webkitpy/layout_tests/port/mac.py 2012-01-10 23:33:59 UTC (rev 104637)
@@ -36,7 +36,7 @@
_log = logging.getLogger(__name__)
-
+# FIXME: Delete this when we switch to using host.platforminfo.os_version instead.
def os_version(os_version_string=None, supported_versions=None):
if not os_version_string:
if hasattr(platform, 'mac_ver') and platform.mac_ver()[0]:
@@ -64,6 +64,7 @@
# and the order of fallback between them. Matches ORWT.
VERSION_FALLBACK_ORDER = ["mac-leopard", "mac-snowleopard", "mac-lion", "mac"]
+ # FIXME: Delete this when we switch to using host.platforminfo.os_version instead.
def _detect_version(self, os_version_string):
# FIXME: MacPort and WinPort implement _detect_version differently.
# WinPort uses os_version_string as a replacement for self.version.
Modified: trunk/Tools/Scripts/webkitpy/layout_tests/port/win.py (104636 => 104637)
--- trunk/Tools/Scripts/webkitpy/layout_tests/port/win.py 2012-01-10 23:19:03 UTC (rev 104636)
+++ trunk/Tools/Scripts/webkitpy/layout_tests/port/win.py 2012-01-10 23:33:59 UTC (rev 104637)
@@ -45,6 +45,7 @@
# and the order of fallback between them. Matches ORWT.
VERSION_FALLBACK_ORDER = ["win-xp", "win-vista", "win-7sp0", "win"]
+ # FIXME: Use host.platforminfo.os_version instead.
def _version_string_from_windows_version_tuple(self, windows_version_tuple):
if windows_version_tuple[:3] == (6, 1, 7600):
return '7sp0'