tizen beta release
[framework/web/webkit-efl.git] / Tools / Scripts / run-gtk-tests
1 #!/usr/bin/env python
2 #
3 # Copyright (C) 2011 Igalia S.L.
4 #
5 # This library is free software; you can redistribute it and/or
6 # modify it under the terms of the GNU Library General Public
7 # License as published by the Free Software Foundation; either
8 # version 2 of the License, or (at your option) any later version.
9 #
10 # This library is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13 # Library General Public License for more details.
14 #
15 # You should have received a copy of the GNU Library General Public License
16 # along with this library; see the file COPYING.LIB.  If not, write to
17 # the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 # Boston, MA 02110-1301, USA.
19
20 from webkitpy.common.system.executive import Executive
21 import subprocess
22 import os, sys
23
24 class TestRunner:
25
26     TEST_DIRS = [ "unittests", "WebKit2APITests" ]
27     SKIPPED = [ "unittests/testdownload" ]
28
29     def __init__(self):
30         self._executive = Executive()
31
32         # FIXME: webkit-build-directory --configuration always returns
33         # Release because we never call set-webkit-configuration.
34         #build_directory_script = os.path.join(os.path.dirname(__file__), "webkit-build-directory")
35         #build_directory = self._executive.run_command([build_directory_script, "--configuration"]).rstrip()
36
37         def is_valid_build_directory(build_dir):
38             return os.path.exists(os.path.join(build_dir, ".libs"))
39
40         script_dir = os.path.dirname(__file__)
41         top_level = os.path.normpath(os.path.join(script_dir, "..", ".."))
42         build_directory = os.path.join(top_level, 'WebKitBuild', 'Release')
43         if not is_valid_build_directory(build_directory):
44             build_directory = os.path.join(top_level, 'WebKitBuild', 'Debug')
45
46         self._programs_path = os.path.join(build_directory, "Programs")
47         self._tests = []
48         for test_dir in self.TEST_DIRS:
49             for test_file in os.listdir(os.path.join(self._programs_path, test_dir)):
50                 test_relative_path = os.path.join(test_dir, test_file)
51                 if test_relative_path in self.SKIPPED:
52                     sys.stdout.write("Skipping test %s\n" % (test_relative_path))
53                     sys.stdout.flush()
54                     continue
55
56                 test_path = os.path.join(self._programs_path, test_relative_path)
57                 if os.path.isfile(test_path) and os.access(test_path, os.X_OK):
58                     self._tests.append(test_path)
59
60     def run(self):
61         if not self._tests:
62             sys.stderr.write("ERROR: tests not found in %s.\n" % (self._programs_path))
63             sys.stderr.flush()
64             return 1
65
66         test_env = os.environ
67         test_env["DISPLAY"] = ":31"
68
69         exit_status = [0]
70         def _error_handler(error):
71             exit_status[0] = error.exit_code
72
73         for test in self._tests:
74             out = self._executive.run_command(['gtester', test], env=test_env,
75                                               error_handler=_error_handler)
76             sys.stdout.write(out)
77             sys.stdout.flush()
78
79         if exit_status[0]:
80             sys.stdout.write("Tests failed\n")
81             sys.stdout.flush()
82
83         return exit_status[0]
84
85 if __name__ == "__main__":
86     try:
87         xvfb = Executive().popen(["Xvfb", ":31", "-screen", "0", "800x600x24", "-nolisten", "tcp"],
88                                  stdout=subprocess.PIPE, stderr=subprocess.PIPE)
89     except:
90         sys.stderr.write("Failed to run Xvfb\n")
91         sys.stderr.flush()
92         sys.exit(1)
93
94     try:
95         sys.exit(TestRunner().run())
96     finally:
97         xvfb.kill()