[GTK] WebDriver: run-webdriver-tests is leaking a DumpRenderTree directory in tmp
[WebKit-https.git] / Tools / Scripts / webkitpy / port / headlessdriver.py
1 # Copyright (C) 2017 Igalia S.L.
2 #
3 # Redistribution and use in source and binary forms, with or without
4 # modification, are permitted provided that the following conditions are
5 # met:
6 #
7 #     * Redistributions of source code must retain the above copyright
8 # notice, this list of conditions and the following disclaimer.
9 #
10 #     * Redistributions in binary form must reproduce the above
11 # copyright notice, this list of conditions and the following disclaimer
12 # in the documentation and/or other materials provided with the
13 # distribution.
14 #
15 #     * Neither the name of the copyright holder nor the names of its
16 # contributors may be used to endorse or promote products derived from
17 # this software without specific prior written permission.
18 #
19 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23 # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30
31 import logging
32 import os
33
34 from webkitpy.port.driver import Driver
35
36 _log = logging.getLogger(__name__)
37
38
39 class HeadlessDriver(Driver):
40     def _setup_environ_for_test(self):
41         driver_environment = self._port.setup_environ_for_server(self._server_name)
42         driver_environment['WPE_USE_HEADLESS_VIEW_BACKEND'] = "1"
43         driver_environment['LOCAL_RESOURCE_ROOT'] = self._port.layout_tests_dir()
44         if self._driver_tempdir is not None:
45             driver_environment['DUMPRENDERTREE_TEMP'] = str(self._driver_tempdir)
46             driver_environment['XDG_CACHE_HOME'] = self._port.host.filesystem.join(str(self._driver_tempdir), 'appcache')
47         return driver_environment
48
49     def _start(self, pixel_tests, per_test_args):
50         super(HeadlessDriver, self).stop()
51         self._driver_tempdir = self._port._driver_tempdir(self._target_host)
52         self._crashed_process_name = None
53         self._crashed_pid = None
54         self._server_process = self._port._server_process_constructor(self._port, self._server_name, self.cmd_line(pixel_tests, per_test_args), self._setup_environ_for_test())
55         self._server_process.start()