summaryrefslogtreecommitdiff
path: root/Tools/Scripts/webkitpy/common/system
diff options
context:
space:
mode:
authorSimon Hausmann <simon.hausmann@nokia.com>2012-06-20 13:01:08 +0200
committerSimon Hausmann <simon.hausmann@nokia.com>2012-06-20 13:01:08 +0200
commit49233e234e5c787396cadb2cea33b31ae0cd65c1 (patch)
tree5410cb9a8fd53168bb60d62c54b654d86f03c38d /Tools/Scripts/webkitpy/common/system
parentb211c645d8ab690f713515dfdc84d80b11c27d2c (diff)
downloadqtwebkit-49233e234e5c787396cadb2cea33b31ae0cd65c1.tar.gz
Imported WebKit commit 3a8c29f35d00659d2ce7a0ccdfa8304f14e82327 (http://svn.webkit.org/repository/webkit/trunk@120813)
New snapshot with Windows build fixes
Diffstat (limited to 'Tools/Scripts/webkitpy/common/system')
-rw-r--r--Tools/Scripts/webkitpy/common/system/executive.py8
-rw-r--r--Tools/Scripts/webkitpy/common/system/executive_unittest.py5
-rw-r--r--Tools/Scripts/webkitpy/common/system/outputcapture.py16
-rw-r--r--Tools/Scripts/webkitpy/common/system/path.py14
-rw-r--r--Tools/Scripts/webkitpy/common/system/path_unittest.py77
-rw-r--r--Tools/Scripts/webkitpy/common/system/platforminfo.py26
-rw-r--r--Tools/Scripts/webkitpy/common/system/platforminfo_mock.py8
-rw-r--r--Tools/Scripts/webkitpy/common/system/platforminfo_unittest.py18
8 files changed, 62 insertions, 110 deletions
diff --git a/Tools/Scripts/webkitpy/common/system/executive.py b/Tools/Scripts/webkitpy/common/system/executive.py
index 8759c719a..cb36b5dc0 100644
--- a/Tools/Scripts/webkitpy/common/system/executive.py
+++ b/Tools/Scripts/webkitpy/common/system/executive.py
@@ -454,7 +454,13 @@ class Executive(object):
def run_in_parallel(self, command_lines_and_cwds, processes=None):
"""Runs a list of (cmd_line list, cwd string) tuples in parallel and returns a list of (retcode, stdout, stderr) tuples."""
- return multiprocessing.Pool(processes=processes).map(_run_command_thunk, command_lines_and_cwds)
+ if sys.platform in ('cygwin', 'win32'):
+ return map(_run_command_thunk, command_lines_and_cwds)
+ pool = multiprocessing.Pool(processes=processes)
+ results = pool.map(_run_command_thunk, command_lines_and_cwds)
+ pool.close()
+ pool.join()
+ return results
def _run_command_thunk(cmd_line_and_cwd):
diff --git a/Tools/Scripts/webkitpy/common/system/executive_unittest.py b/Tools/Scripts/webkitpy/common/system/executive_unittest.py
index 466e2ec02..212896a4a 100644
--- a/Tools/Scripts/webkitpy/common/system/executive_unittest.py
+++ b/Tools/Scripts/webkitpy/common/system/executive_unittest.py
@@ -218,6 +218,10 @@ class ExecutiveTest(unittest.TestCase):
self.assertTrue(os.getpid() in pids)
def test_run_in_parallel(self):
+ if sys.platform in ("win32", "cygwin"):
+ return # This function isn't implemented properly on windows yet.
+ import multiprocessing
+
NUM_PROCESSES = 4
DELAY_SECS = 0.25
cmd_line = [sys.executable, '-c', 'import time; time.sleep(%f); print "hello"' % DELAY_SECS]
@@ -228,6 +232,7 @@ class ExecutiveTest(unittest.TestCase):
done = time.time()
self.assertTrue(done - start < NUM_PROCESSES * DELAY_SECS)
self.assertEquals([output[1] for output in command_outputs], ["hello\n"] * NUM_PROCESSES)
+ self.assertEquals([], multiprocessing.active_children())
def main(platform, stdin, stdout, cmd, args):
diff --git a/Tools/Scripts/webkitpy/common/system/outputcapture.py b/Tools/Scripts/webkitpy/common/system/outputcapture.py
index 66188c0cb..4f931b7d1 100644
--- a/Tools/Scripts/webkitpy/common/system/outputcapture.py
+++ b/Tools/Scripts/webkitpy/common/system/outputcapture.py
@@ -3,7 +3,7 @@
# 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
@@ -13,7 +13,7 @@
# * 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
@@ -35,6 +35,13 @@ from StringIO import StringIO
class OutputCapture(object):
+ # By default we capture the output to a stream. Other modules may override
+ # this function in order to do things like pass through the output. See
+ # webkitpy.test.main for an example.
+ @staticmethod
+ def stream_wrapper(stream):
+ return StringIO()
+
def __init__(self):
self.saved_outputs = dict()
self._log_level = logging.INFO
@@ -45,8 +52,9 @@ class OutputCapture(object):
self._logs_handler.setLevel(self._log_level)
def _capture_output_with_name(self, output_name):
- self.saved_outputs[output_name] = getattr(sys, output_name)
- captured_output = StringIO()
+ stream = getattr(sys, output_name)
+ captured_output = self.stream_wrapper(stream)
+ self.saved_outputs[output_name] = stream
setattr(sys, output_name, captured_output)
return captured_output
diff --git a/Tools/Scripts/webkitpy/common/system/path.py b/Tools/Scripts/webkitpy/common/system/path.py
index b7ad3723a..e5a66bf87 100644
--- a/Tools/Scripts/webkitpy/common/system/path.py
+++ b/Tools/Scripts/webkitpy/common/system/path.py
@@ -35,11 +35,9 @@ import threading
import urllib
-def abspath_to_uri(path, platform=None):
+def abspath_to_uri(platform, path):
"""Converts a platform-specific absolute path to a file: URL."""
- if platform is None:
- platform = sys.platform
- return "file:" + _escape(_convert_path(path, platform))
+ return "file:" + _escape(_convert_path(platform, path))
def cygpath(path):
@@ -118,12 +116,12 @@ def _escape(path):
return urllib.quote(path, safe='/+:')
-def _convert_path(path, platform):
+def _convert_path(platform, path):
"""Handles any os-specific path separators, mappings, etc."""
- if platform == 'win32':
- return _winpath_to_uri(path)
- if platform == 'cygwin':
+ if platform.is_cygwin():
return _winpath_to_uri(cygpath(path))
+ if platform.is_win():
+ return _winpath_to_uri(path)
return _unixypath_to_uri(path)
diff --git a/Tools/Scripts/webkitpy/common/system/path_unittest.py b/Tools/Scripts/webkitpy/common/system/path_unittest.py
index e08212a2c..954d32d71 100644
--- a/Tools/Scripts/webkitpy/common/system/path_unittest.py
+++ b/Tools/Scripts/webkitpy/common/system/path_unittest.py
@@ -29,69 +29,41 @@
import unittest
import sys
-import path
+from webkitpy.common.system.systemhost import SystemHost
+from webkitpy.common.system.platforminfo import PlatformInfo
+from webkitpy.common.system.platforminfo_mock import MockPlatformInfo
+from webkitpy.common.system import path
class AbspathTest(unittest.TestCase):
- def assertMatch(self, test_path, expected_uri,
- platform=None):
- if platform == 'cygwin' and sys.platform != 'cygwin':
- return
- self.assertEqual(path.abspath_to_uri(test_path, platform=platform),
- expected_uri)
+ def platforminfo(self):
+ return SystemHost().platform
def test_abspath_to_uri_cygwin(self):
if sys.platform != 'cygwin':
return
+ self.assertEquals(path.abspath_to_uri(self.platforminfo(), '/cygdrive/c/foo/bar.html'),
+ 'file:///C:/foo/bar.html')
- self.assertMatch('/cygdrive/c/foo/bar.html',
- 'file:///C:/foo/bar.html',
- platform='cygwin')
- self.assertEqual(path.abspath_to_uri('/cygdrive/c/foo/bar.html',
- platform='cygwin'),
- 'file:///C:/foo/bar.html')
-
- def test_abspath_to_uri_darwin(self):
- self.assertMatch('/foo/bar.html',
- 'file:///foo/bar.html',
- platform='darwin')
- self.assertEqual(path.abspath_to_uri("/foo/bar.html",
- platform='darwin'),
- "file:///foo/bar.html")
-
- def test_abspath_to_uri_linux2(self):
- self.assertMatch('/foo/bar.html',
- 'file:///foo/bar.html',
- platform='darwin')
- self.assertEqual(path.abspath_to_uri("/foo/bar.html",
- platform='linux2'),
- "file:///foo/bar.html")
- self.assertEqual(path.abspath_to_uri("/foo/bar.html",
- platform='linux3'),
- "file:///foo/bar.html")
+ def test_abspath_to_uri_unixy(self):
+ self.assertEquals(path.abspath_to_uri(MockPlatformInfo(), "/foo/bar.html"),
+ 'file:///foo/bar.html')
def test_abspath_to_uri_win(self):
- self.assertMatch('c:\\foo\\bar.html',
- 'file:///c:/foo/bar.html',
- platform='win32')
- self.assertEqual(path.abspath_to_uri("c:\\foo\\bar.html",
- platform='win32'),
- "file:///c:/foo/bar.html")
+ if sys.platform != 'win32':
+ return
+ self.assertEquals(path.abspath_to_uri(self.platforminfo(), 'c:\\foo\\bar.html'),
+ 'file:///c:/foo/bar.html')
- def test_abspath_to_uri_escaping(self):
- self.assertMatch('/foo/bar + baz%?.html',
- 'file:///foo/bar%20+%20baz%25%3F.html',
- platform='darwin')
- self.assertMatch('/foo/bar + baz%?.html',
- 'file:///foo/bar%20+%20baz%25%3F.html',
- platform='linux2')
- self.assertMatch('/foo/bar + baz%?.html',
- 'file:///foo/bar%20+%20baz%25%3F.html',
- platform='linux3')
+ def test_abspath_to_uri_escaping_unixy(self):
+ self.assertEquals(path.abspath_to_uri(MockPlatformInfo(), '/foo/bar + baz%?.html'),
+ 'file:///foo/bar%20+%20baz%25%3F.html')
# Note that you can't have '?' in a filename on windows.
- self.assertMatch('/cygdrive/c/foo/bar + baz%.html',
- 'file:///C:/foo/bar%20+%20baz%25.html',
- platform='cygwin')
+ def test_abspath_to_uri_escaping_cygwin(self):
+ if sys.platform != 'cygwin':
+ return
+ self.assertEquals(path.abspath_to_uri(self.platforminfo(), '/cygdrive/c/foo/bar + baz%.html'),
+ 'file:///C:/foo/bar%20+%20baz%25.html')
def test_stop_cygpath_subprocess(self):
if sys.platform != 'cygwin':
@@ -106,6 +78,3 @@ class AbspathTest(unittest.TestCase):
# Ensure that it is stopped.
self.assertFalse(path._CygPath._singleton.is_running())
-
-if __name__ == '__main__':
- unittest.main()
diff --git a/Tools/Scripts/webkitpy/common/system/platforminfo.py b/Tools/Scripts/webkitpy/common/system/platforminfo.py
index 22cafbbee..74cff5412 100644
--- a/Tools/Scripts/webkitpy/common/system/platforminfo.py
+++ b/Tools/Scripts/webkitpy/common/system/platforminfo.py
@@ -54,6 +54,7 @@ class PlatformInfo(object):
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))
+ self._is_cygwin = sys_module.platform == 'cygwin'
def is_mac(self):
return self.os_name == 'mac'
@@ -61,6 +62,9 @@ class PlatformInfo(object):
def is_win(self):
return self.os_name == 'win'
+ def is_cygwin(self):
+ return self._is_cygwin
+
def is_linux(self):
return self.os_name == 'linux'
@@ -77,18 +81,9 @@ class PlatformInfo(object):
# Windows-2008ServerR2-6.1.7600
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):
if self.is_mac():
- return int(self._executive.run_command(["sysctl", "-n", "hw.memsize"]))
+ return long(self._executive.run_command(["sysctl", "-n", "hw.memsize"]))
return None
def _determine_os_name(self, sys_platform):
@@ -137,14 +132,3 @@ class PlatformInfo(object):
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)
-
- # 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
diff --git a/Tools/Scripts/webkitpy/common/system/platforminfo_mock.py b/Tools/Scripts/webkitpy/common/system/platforminfo_mock.py
index c953aa185..34fa97fb4 100644
--- a/Tools/Scripts/webkitpy/common/system/platforminfo_mock.py
+++ b/Tools/Scripts/webkitpy/common/system/platforminfo_mock.py
@@ -41,6 +41,9 @@ class MockPlatformInfo(object):
def is_win(self):
return self.os_name == 'win'
+ def is_cygwin(self):
+ return False
+
def is_freebsd(self):
return self.os_name == 'freebsd'
@@ -48,7 +51,4 @@ class MockPlatformInfo(object):
return "MockPlatform 1.0"
def total_bytes_memory(self):
- return 2 * 1024 * 1024 * 1024 # 2GB is a reasonable amount of ram to mock.
-
- def free_bytes_memory(self):
- return 1 * 1024 * 1024 * 1024 # 1GB is a reasonable amount of ram to mock as free.
+ return 3 * 1024 * 1024 * 1024 # 3GB is a reasonable amount of ram to mock.
diff --git a/Tools/Scripts/webkitpy/common/system/platforminfo_unittest.py b/Tools/Scripts/webkitpy/common/system/platforminfo_unittest.py
index 5a1f85fc3..8fc961b08 100644
--- a/Tools/Scripts/webkitpy/common/system/platforminfo_unittest.py
+++ b/Tools/Scripts/webkitpy/common/system/platforminfo_unittest.py
@@ -82,10 +82,8 @@ class TestPlatformInfo(unittest.TestCase):
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'))
@@ -180,22 +178,6 @@ class TestPlatformInfo(unittest.TestCase):
info = self.make_info(fake_sys('freebsd9'))
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)
-
- info = self.make_info(fake_sys('freebsd9'))
- self.assertEquals(info.free_bytes_memory(), None)
-
if __name__ == '__main__':
unittest.main()