Commit 803ead9a authored by qyearsley's avatar qyearsley Committed by Commit bot

In Linux Port, make a dummy HOME directory for running tests.

I haven't really confirmed that this solves the problem because I wasn't able to reproduce it again :-/

Note, there's a related change http://crrev.com/2143123004 which would make it so that the real os.environ isn't used in tests.

BUG=612730

Review-Url: https://codereview.chromium.org/2141093006
Cr-Commit-Position: refs/heads/master@{#405576}
parent 791f5272
......@@ -27,10 +27,9 @@
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
import logging
import os
from webkitpy.common.webkit_finder import WebKitFinder
from webkitpy.layout_tests.breakpad.dump_reader_multipart import DumpReaderLinux
from webkitpy.layout_tests.models import test_run_results
from webkitpy.layout_tests.port import base
from webkitpy.layout_tests.port import win
......@@ -68,6 +67,9 @@ class LinuxPort(base.Port):
if not self.get_option('disable_breakpad'):
self._dump_reader = DumpReaderLinux(host, self._build_path())
self._original_home = os.environ['HOME']
self._dummy_home = None
def additional_driver_flag(self):
flags = super(LinuxPort, self).additional_driver_flag()
if not self.get_option('disable_breakpad'):
......@@ -104,10 +106,45 @@ class LinuxPort(base.Port):
_log.error("Could not find apache. Not installed or unknown path.")
return None
def setup_test_run(self):
super(LinuxPort, self).setup_test_run()
self._setup_dummy_home_dir()
def clean_up_test_run(self):
super(LinuxPort, self).clean_up_test_run()
self._clean_up_dummy_home_dir()
#
# PROTECTED METHODS
#
def _setup_dummy_home_dir(self):
"""Creates a dummy home directory for running the test.
This is a workaround for crbug.com/595504; see crbug.com/612730.
If crbug.com/612730 is resolved in another way, then this may be
unnecessary.
"""
dummy_home = str(self._filesystem.mkdtemp())
os.environ['HOME'] = dummy_home
self._copy_files_to_dummy_home_dir(dummy_home)
def _copy_files_to_dummy_home_dir(self, dummy_home):
# Note: This may be unnecessary.
fs = self._filesystem
for filename in ['.Xauthority']:
original_path = fs.join(self._original_home, filename)
if not fs.exists(original_path):
continue
fs.copyfile(original_path, fs.join(dummy_home, filename))
def _clean_up_dummy_home_dir(self):
"""Cleans up the dummy dir and resets the HOME environment variable."""
dummy_home = os.environ['HOME']
assert dummy_home != self._original_home
self._filesystem.rmtree(dummy_home)
os.environ['HOME'] = self._original_home
def _check_apache_install(self):
result = self._check_file_exists(self.path_to_apache(), "apache2")
result = self._check_file_exists(self.path_to_apache_config_file(), "apache2 config file") and result
......
......@@ -26,13 +26,13 @@
# (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 os
from webkitpy.common.system import executive_mock
from webkitpy.common.system.systemhost_mock import MockSystemHost
from webkitpy.tool.mock_tool import MockOptions
from webkitpy.layout_tests.port import linux
from webkitpy.layout_tests.port import port_testcase
from webkitpy.tool.mock_tool import MockOptions
class LinuxPortTest(port_testcase.PortTestCase):
......@@ -42,6 +42,13 @@ class LinuxPortTest(port_testcase.PortTestCase):
full_port_name = 'linux-trusty'
port_maker = linux.LinuxPort
def setUp(self):
# TODO(qyearsley): Remove this when crbug.com/627887 is fixed.
self.original_environ = os.environ.copy()
def tearDown(self):
os.environ = self.original_environ
def assert_version_properties(self, port_name, os_version, expected_name,
expected_version,
driver_file_output=None):
......@@ -101,3 +108,21 @@ class LinuxPortTest(port_testcase.PortTestCase):
def test_path_to_image_diff(self):
self.assertEqual(self.make_port()._path_to_image_diff(), '/mock-checkout/out/Release/image_diff')
def test_dummy_home_dir_is_created_and_cleaned_up(self):
original_home = '/home/user'
os.environ['HOME'] = original_home
port = self.make_port()
port._filesystem.files['/home/user/.Xauthority'] = ''
# Set up the test run; the temporary home directory should be set up.
port.setup_test_run()
temp_home_dir = os.environ['HOME']
self.assertNotEqual(temp_home_dir, original_home)
self.assertTrue(port._filesystem.isdir(temp_home_dir))
self.assertTrue(port._filesystem.isfile(port._filesystem.join(temp_home_dir, '.Xauthority')))
# Clean up; HOME should be reset and the temp dir should be cleaned up.
port.clean_up_test_run()
self.assertEqual(os.environ.get('HOME'), original_home)
self.assertFalse(port._filesystem.exists(temp_home_dir))
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment