def serial_test_basic(self): # Give -u switch to force stdout and stderr to be unbuffered for Windows cmd = [ sys.executable, '-uc', 'import sys; print "stdout"; print >>sys.stderr, "stderr"; sys.stdin.readline();' ] host = SystemHost() factory = PortFactory(host) port = factory.get() now = time.time() proc = server_process.ServerProcess(port, 'python', cmd) proc.write('') self.assertEqual(proc.poll(), None) self.assertFalse(proc.has_crashed()) # check that doing a read after an expired deadline returns # nothing immediately. line = proc.read_stdout_line(now - 1) self.assertEqual(line, None) line = proc.read_stdout_line(now + 1.0) self.assertEqual(line.strip(), "stdout") line = proc.read_stderr_line(now + 1.0) self.assertEqual(line.strip(), "stderr") proc.write('End\n') time.sleep(0.1) # Give process a moment to close. self.assertEqual(proc.poll(), 0) proc.stop(0)
def test_process_crashing(self): cmd = [ sys.executable, '-c', 'import sys; print "stdout 1"; print "stdout 2"; print "stdout 3"; sys.stdout.flush(); sys.stdin.readline(); sys.exit(1);' ] host = SystemHost() factory = PortFactory(host) port = factory.get() now = time.time() proc = server_process.ServerProcess(port, 'python', cmd) proc.write('') line = proc.read_stdout_line(now + 1.0) self.assertEqual(line.strip(), 'stdout 1') proc.write('End\n') time.sleep(0.1) # Give process a moment to close. line = proc.read_stdout_line(now + 1.0) self.assertEqual(line.strip(), 'stdout 2') self.assertEqual(True, proc.has_crashed()) line = proc.read_stdout_line(now + 1.0) self.assertEqual(line, None) proc.stop(0)
def test_basic(self): cmd = [sys.executable, '-c', 'import sys; import time; time.sleep(0.02); print "stdout"; sys.stdout.flush(); print >>sys.stderr, "stderr"'] host = SystemHost() factory = PortFactory(host) port = factory.get() now = time.time() proc = server_process.ServerProcess(port, 'python', cmd) proc.write('') if sys.platform.startswith('win'): self.assertEqual(proc.poll(), 0) else: self.assertEqual(proc.poll(), None) self.assertFalse(proc.has_crashed()) # check that doing a read after an expired deadline returns # nothing immediately. line = proc.read_stdout_line(now - 1) self.assertEqual(line, None) # FIXME: This part appears to be flaky. line should always be non-None. # FIXME: https://bugs.webkit.org/show_bug.cgi?id=88280 line = proc.read_stdout_line(now + 1.0) if line: self.assertEqual(line.strip(), "stdout") line = proc.read_stderr_line(now + 1.0) if line: self.assertEqual(line.strip(), "stderr") proc.stop(0)
def test_basic(self): cmd = [sys.executable, '-c', 'import sys; import time; time.sleep(0.02); print "stdout"; sys.stdout.flush(); print >>sys.stderr, "stderr"'] host = SystemHost() factory = PortFactory(host) port = factory.get() now = time.time() proc = server_process.ServerProcess(port, 'python', cmd) proc.write('') self.assertEqual(proc.poll(), None) self.assertFalse(proc.has_crashed()) # check that doing a read after an expired deadline returns # nothing immediately. line = proc.read_stdout_line(now - 1) self.assertEqual(line, None) # FIXME: This part appears to be flaky. line should always be non-None. # FIXME: https://bugs.webkit.org/show_bug.cgi?id=88280 line = proc.read_stdout_line(now + 1.0) if line: self.assertEqual(line.strip(), "stdout") line = proc.read_stderr_line(now + 1.0) if line: self.assertEqual(line.strip(), "stderr") proc.stop(0)
def test_basic(self): cmd = [ sys.executable, '-c', 'import sys; print "stdout"; sys.stdout.flush(); print >>sys.stderr, "stderr"; sys.stdin.readline();' ] host = SystemHost() factory = PortFactory(host) port = factory.get() now = time.time() proc = server_process.ServerProcess(port, 'python', cmd) proc.write('') if sys.platform.startswith('win'): self.assertEqual(proc.poll(), 0) else: self.assertEqual(proc.poll(), None) self.assertFalse(proc.has_crashed()) # check that doing a read after an expired deadline returns # nothing immediately. line = proc.read_stdout_line(now - 1) self.assertEqual(line, None) line = proc.read_stdout_line(now + 1.0) self.assertEqual(line.strip(), "stdout") line = proc.read_stderr_line(now + 1.0) self.assertEqual(line.strip(), "stderr") proc.write('End\n') proc.stop(0)
def serial_test_process_crashing(self): # Give -u switch to force stdout to be unbuffered for Windows cmd = [ sys.executable, '-uc', 'import sys; print("stdout 1"); print("stdout 2"); print("stdout 3"); sys.stdin.readline(); sys.exit(1);' ] host = SystemHost() factory = PortFactory(host) port = factory.get() now = time.time() proc = server_process.ServerProcess(port, 'python', cmd) proc.write(b'') line = proc.read_stdout_line(now + 1.0) self.assertEqual(line.strip(), b'stdout 1') proc.write(b'End\n') time.sleep(0.1) # Give process a moment to close. line = proc.read_stdout_line(now + 1.0) self.assertEqual(line.strip(), b'stdout 2') self.assertEqual(True, proc.has_crashed()) line = proc.read_stdout_line(now + 1.0) self.assertEqual(line, None) proc.stop(0)
def __init__(self, options, args, host, stdin, stdout, stderr): self._options = options self._args = args self._host = host self._stdout = stdout self._stdin = stdin self._stderr = stderr port_name = None if options.platform: port_name = options.platform self._port = PortFactory(host).get(port_name=port_name, options=options) self._driver = self._port.create_driver(0)
def __init__(self, log_executive=False, executive_throws_when_run=None, initialize_scm_by_default=True, web=None, create_stub_repository_files=False): MockSystemHost.__init__(self, log_executive, executive_throws_when_run) add_unit_tests_to_mock_filesystem(self.filesystem) if create_stub_repository_files: add_checkout_information_json_to_mock_filesystem(self.filesystem) self.web = web or MockWeb() self._checkout = MockCheckout() self._scm = None # FIXME: we should never initialize the SCM by default, since the real # object doesn't either. This has caused at least one bug (see bug 89498). if initialize_scm_by_default: self.initialize_scm() self.bugs = MockBugzilla() self.buildbot = MockBuildBot() # Note: We're using a real PortFactory here. Tests which don't wish to depend # on the list of known ports should override this with a MockPortFactory. self.port_factory = PortFactory(self) self._watch_list = MockWatchList()
def assertTest(self, test_name, pixel_tests, expected_checksum=None, drt_output=None, host=None, expected_text=None): port_name = 'test' host = host or MockSystemHost() test.add_unit_tests_to_mock_filesystem(host.filesystem) port = PortFactory(host).get(port_name) drt_input, drt_output = self.make_input_output( port, test_name, pixel_tests, expected_checksum, drt_output, drt_input=None, expected_text=expected_text) args = ['--platform', port_name] + self.extra_args(pixel_tests) stdin = newstringio.StringIO(drt_input) stdout = newstringio.StringIO() stderr = newstringio.StringIO() options, args = mock_drt.parse_options(args) drt = self.make_drt(options, args, host, stdin, stdout, stderr) res = drt.run() self.assertEqual(res, 0) # We use the StringIO.buflist here instead of getvalue() because # the StringIO might be a mix of unicode/ascii and 8-bit strings. self.assertEqual(stdout.buflist, drt_output) self.assertEqual(stderr.getvalue(), '#EOF\n')
def assertTest(self, test_name, pixel_tests, expected_checksum=None, drt_output=None, host=None, expected_text=None): port_name = 'test' host = host or MockSystemHost() test.add_unit_tests_to_mock_filesystem(host.filesystem) port = PortFactory(host).get(port_name) drt_input, drt_output = self.make_input_output( port, test_name, pixel_tests, expected_checksum, drt_output, drt_input=None, expected_text=expected_text) args = ['--platform', port_name] + self.extra_args(pixel_tests) stdin = StringIO(drt_input) stdout = StringIO() stderr = StringIO() options, args = mock_drt.parse_options(args) drt = self.make_drt(options, args, host, stdin, stdout, stderr) res = drt.run() self.assertEqual(res, 0) self.assertEqual(stdout.getvalue(), ''.join(drt_output)) self.assertEqual(stderr.getvalue(), '#EOF\n')
def serial_test_read_after_process_exits(self): cmd = [sys.executable, '-uc', 'import sys; print("stdout"); {};'.format(self.stderr_print)] host = SystemHost() factory = PortFactory(host) port = factory.get() now = time.time() proc = server_process.ServerProcess(port, 'python', cmd) proc.write(b'') time.sleep(0.1) # Give process a moment to close. line = proc.read_stdout_line(now + 1.0) self.assertEqual(line.strip(), b"stdout") line = proc.read_stderr_line(now + 1.0) self.assertEqual(line.strip(), b"stderr") proc.stop(0)
def clean_args(self): if self.user_repo: os.environ["FLATPAK_USER_DIR"] = FLATPAK_USER_DIR_PATH + ".Local" else: os.environ["FLATPAK_USER_DIR"] = os.environ.get( "WEBKIT_FLATPAK_USER_DIR", FLATPAK_USER_DIR_PATH) self.flatpak_build_path = os.environ["FLATPAK_USER_DIR"] try: os.makedirs(self.flatpak_build_path) except OSError as e: pass configure_logging(logging.DEBUG if self.verbose else logging.INFO) _log.debug("Using flatpak user dir: %s" % self.flatpak_build_path) if not self.debug and not self.release: factory = PortFactory(SystemHost()) port = factory.get(self.platform) self.debug = port.default_configuration() == "Debug" self.build_type = "Debug" if self.debug else "Release" self.platform = self.platform.upper() if self.gdb is None and '--gdb' in sys.argv: self.gdb = True self.build_root = os.path.join(self.source_root, 'WebKitBuild') self.build_path = os.path.join(self.build_root, self.platform, self.build_type) self.config_file = os.path.join(self.flatpak_build_path, 'webkit_flatpak_config.json') Console.quiet = self.quiet if not check_flatpak(): return False self._reset_repository() try: with open(self.config_file) as config: json_config = json.load(config) self.icc_version = json_config['icecc_version'] except IOError as e: pass return True
def serial_test_process_crashing_no_data(self): cmd = [sys.executable, '-uc', 'import sys; sys.stdin.readline(); sys.exit(1);'] host = SystemHost() factory = PortFactory(host) port = factory.get() now = time.time() proc = server_process.ServerProcess(port, 'python', cmd) proc.write(b'') self.assertEqual(False, proc.has_crashed()) proc.write(b'End\n') time.sleep(0.1) # Give process a moment to close. line = proc.read_stdout_line(now + 1.0) self.assertEqual(line, None) self.assertEqual(True, proc.has_crashed()) proc.stop(0)
def __init__(self): SystemHost.__init__(self) self._checkout = None # FIXME: Unfortunately Port objects are currently the central-dispatch objects of the NRWT world. # In order to instantiate a port correctly, we have to pass it at least an executive, user, scm, and filesystem # so for now we just pass along the whole Host object. # FIXME: PortFactory doesn't belong on this Host object if Port is going to have a Host (circular dependency). self.port_factory = PortFactory(self) self._engage_awesome_locale_hacks()
def test_pixeltest__fails(self): host = MockSystemHost() url = '#URL:file://' url = url + '%s/failures/expected/image_checksum.html' % PortFactory(host).get('test').layout_tests_dir() self.assertTest('failures/expected/image_checksum.html', pixel_tests=True, expected_checksum='image_checksum', drt_output=[url + '\n', '#MD5:image_checksum-checksum\n', 'image_checksum-txt', '\n', '#EOF\n'], host=host) self.assertEqual(host.filesystem.written_files, {'/tmp/png_result0.png': 'image_checksum\x8a-pngtEXtchecksum\x00image_checksum-checksum'})
def __init__(self): SystemHost.__init__(self) self.web = web.Web() self._checkout = None # Everything below this line is WebKit-specific and belongs on a higher-level object. self.bugs = bugzilla.Bugzilla() self.buildbot = buildbot.BuildBot() # FIXME: Unfortunately Port objects are currently the central-dispatch objects of the NRWT world. # In order to instantiate a port correctly, we have to pass it at least an executive, user, scm, and filesystem # so for now we just pass along the whole Host object. # FIXME: PortFactory doesn't belong on this Host object if Port is going to have a Host (circular dependency). self.port_factory = PortFactory(self) self._engage_awesome_locale_hacks()
def __init__(self, host, port_name, **kwargs): self.__delegate = PortFactory(host).get(port_name.replace('mock-', ''), **kwargs)
class MockDRT(object): def __init__(self, options, args, host, stdin, stdout, stderr): self._options = options self._args = args self._host = host self._stdout = stdout self._stdin = stdin self._stderr = stderr port_name = None if options.platform: port_name = options.platform self._port = PortFactory(host).get(port_name=port_name, options=options) self._driver = self._port.create_driver(0) def run(self): while True: line = self._stdin.readline() if not line: return 0 driver_input = self.input_from_line(line) dirname, basename = self._port.split_test(driver_input.test_name) is_reftest = (self._port.reference_files(driver_input.test_name) or self._port.is_reference_html_file(self._port._filesystem, dirname, basename)) output = self.output_for_test(driver_input, is_reftest) self.write_test_output(driver_input, output, is_reftest) def input_from_line(self, line): vals = line.strip().split("'") if len(vals) == 1: uri = vals[0] checksum = None else: uri = vals[0] checksum = vals[1] if uri.startswith('http://') or uri.startswith('https://'): test_name = self._driver.uri_to_test(uri) else: test_name = self._port.relative_test_filename(uri) return DriverInput(test_name, 0, checksum, self._options.pixel_tests) def output_for_test(self, test_input, is_reftest): port = self._port actual_text = port.expected_text(test_input.test_name) actual_audio = port.expected_audio(test_input.test_name) actual_image = None actual_checksum = None if is_reftest: # Make up some output for reftests. actual_text = 'reference text\n' actual_checksum = 'mock-checksum' actual_image = 'blank' if test_input.test_name.endswith('-mismatch.html'): actual_text = 'not reference text\n' actual_checksum = 'not-mock-checksum' actual_image = 'not blank' elif self._options.pixel_tests and test_input.image_hash: actual_checksum = port.expected_checksum(test_input.test_name) actual_image = port.expected_image(test_input.test_name) return DriverOutput(actual_text, actual_image, actual_checksum, actual_audio) def write_test_output(self, test_input, output, is_reftest): if output.audio: self._stdout.write('Content-Type: audio/wav\n') self._stdout.write('Content-Transfer-Encoding: base64\n') self._stdout.write(base64.b64encode(output.audio)) else: self._stdout.write('Content-Type: text/plain\n') # FIXME: Note that we don't ensure there is a trailing newline! # This mirrors actual (Mac) DRT behavior but is a bug. if output.text: self._stdout.write(output.text) self._stdout.write('#EOF\n') if self._options.pixel_tests and output.image_hash: self._stdout.write('\n') self._stdout.write('ActualHash: %s\n' % output.image_hash) self._stdout.write('ExpectedHash: %s\n' % test_input.image_hash) if output.image_hash != test_input.image_hash: self._stdout.write('Content-Type: image/png\n') self._stdout.write('Content-Length: %s\n' % len(output.image)) self._stdout.write(output.image) self._stdout.write('#EOF\n') self._stdout.flush() self._stderr.write('#EOF\n') self._stderr.flush()
def clean_args(self): configure_logging(logging.DEBUG if self.verbose else logging.INFO) if not self.debug and not self.release: factory = PortFactory(SystemHost()) port = factory.get(self.platform) self.debug = port.default_configuration() == "Debug" self.build_type = "Debug" if self.debug else "Release" self.platform = self.platform.upper() if self.gdb is None and '--gdb' in sys.argv: self.gdb = "" self.command = "%s %s %s" % (os.path.join( self.sandbox_source_root, "Tools/Scripts/run-minibrowser"), "--" + self.platform.lower(), " --debug" if self.debug else " --release") self.name = "org.webkit.%s" % self.platform self.manifest_path = os.path.abspath( os.path.join(scriptdir, '../flatpak/org.webkit.WebKit.yaml')) self.build_name = self.name + "-generated" build_root = os.path.join(self.source_root, 'WebKitBuild') self.flatpak_build_path = os.path.join(build_root, self.platform, "FlatpakTree" + self.build_type) self.cache_path = os.path.join(build_root, "FlatpakCache") self.build_path = os.path.join(build_root, self.platform, self.build_type) try: os.makedirs(self.build_path) except OSError as e: if e.errno != errno.EEXIST: raise e Console.quiet = self.quiet if not check_flatpak(): return False repos = FlatpakRepos() self.sdk_repo = repos.add( FlatpakRepo( "flathub", url="https://dl.flathub.org/repo/", repo_file="https://dl.flathub.org/repo/flathub.flatpakrepo")) manifest = load_manifest(self.manifest_path) if not manifest: return False self.sdk_branch = manifest["runtime-version"] self.finish_args = manifest.get("finish-args", []) self.finish_args = remove_extension_points(self.finish_args) self.runtime = FlatpakPackage("org.gnome.Platform", self.sdk_branch, self.sdk_repo, "x86_64", hash=manifest.get("runtime-hash"), assumeyes=self.assumeyes) self.locale = FlatpakPackage("org.gnome.Platform.Locale", self.sdk_branch, self.sdk_repo, "x86_64", assumeyes=self.assumeyes) self.sdk = FlatpakPackage("org.gnome.Sdk", self.sdk_branch, self.sdk_repo, "x86_64", hash=manifest.get("sdk-hash"), assumeyes=self.assumeyes) self.packs = [self.runtime, self.locale, self.sdk] if self.debug: self.sdk_debug = FlatpakPackage("org.gnome.Sdk.Debug", self.sdk_branch, self.sdk_repo, "x86_64", assumeyes=self.assumeyes) self.packs.append(self.sdk_debug) self.manifest_generated_path = os.path.join(self.cache_path, self.build_name + ".json") return True
def clean_args(self): os.environ["FLATPAK_USER_DIR"] = os.environ.get("WEBKIT_FLATPAK_USER_DIR", os.path.realpath(os.path.join(scriptdir, "../../WebKitBuild", "UserFlatpak"))) try: os.makedirs(os.environ["FLATPAK_USER_DIR"]) except OSError as e: pass configure_logging(logging.DEBUG if self.verbose else logging.INFO) _log.debug("Using flatpak user dir: %s" % os.environ["FLATPAK_USER_DIR"]) if not self.debug and not self.release: factory = PortFactory(SystemHost()) port = factory.get(self.platform) self.debug = port.default_configuration() == "Debug" self.build_type = "Debug" if self.debug else "Release" self.platform = self.platform.upper() if self.gdb is None and '--gdb' in sys.argv: self.gdb = "" self.command = "%s %s %s" % (os.path.join(self.sandbox_source_root, "Tools/Scripts/run-minibrowser"), "--" + self.platform.lower(), " --debug" if self.debug else " --release") self.name = "org.webkit.%s" % self.platform if self.wpe_extension: manifest_filename = WPE_MANIFEST_MAP[self.wpe_extension] else: manifest_filename = "org.webkit.WebKit.yaml" self.manifest_path = os.path.abspath(os.path.join(scriptdir, '../flatpak/') + manifest_filename) self.build_name = self.name + "-generated" build_root = os.path.join(self.source_root, 'WebKitBuild') self.flatpak_build_path = os.path.join(build_root, self.platform, "FlatpakTree" + self.build_type) self.cache_path = os.path.join(build_root, "FlatpakCache") self.build_path = os.path.join(build_root, self.platform, self.build_type) try: os.makedirs(self.build_path) except OSError as e: if e.errno != errno.EEXIST: raise e self.config_file = os.path.join(self.build_path, 'webkit_flatpak_config.json') Console.quiet = self.quiet if not check_flatpak(): return False repos = FlatpakRepos() self.sdk_repo = repos.add( FlatpakRepo("flathub", url="https://dl.flathub.org/repo/", repo_file="https://dl.flathub.org/repo/flathub.flatpakrepo")) manifest = load_manifest(self.manifest_path, port_name=self.name) if not manifest: return False self.app = manifest['app-id'] self.sdk_branch = manifest["runtime-version"] self.finish_args = manifest.get("finish-args", []) self.finish_args = remove_extension_points(self.finish_args) self.runtime = FlatpakPackage(manifest['runtime'], self.sdk_branch, self.sdk_repo, "x86_64", hash=manifest.get("runtime-hash")) self.locale = FlatpakPackage(manifest['runtime'] + '.Locale', self.sdk_branch, self.sdk_repo, "x86_64") self.sdk = FlatpakPackage(manifest['sdk'], self.sdk_branch, self.sdk_repo, "x86_64", hash=manifest.get("sdk-hash")) self.packs = [self.runtime, self.locale, self.sdk] if self.debug: self.sdk_debug = FlatpakPackage(manifest['sdk'] + '.Debug', self.sdk_branch, self.sdk_repo, "x86_64") self.packs.append(self.sdk_debug) self.manifest_generated_path = os.path.join(self.cache_path, self.build_name + ".json") try: with open(self.config_file) as config: json_config = json.load(config) self.icc_version = json_config['icecc_version'] except IOError as e: pass return True
def clean_args(self): os.environ["FLATPAK_USER_DIR"] = os.environ.get( "WEBKIT_FLATPAK_USER_DIR", FLATPAK_USER_DIR_PATH) try: os.makedirs(os.environ["FLATPAK_USER_DIR"]) except OSError as e: pass configure_logging(logging.DEBUG if self.verbose else logging.INFO) _log.debug("Using flatpak user dir: %s" % os.environ["FLATPAK_USER_DIR"]) if not self.debug and not self.release: factory = PortFactory(SystemHost()) port = factory.get(self.platform) self.debug = port.default_configuration() == "Debug" self.build_type = "Debug" if self.debug else "Release" self.platform = self.platform.upper() if self.gdb is None and '--gdb' in sys.argv: self.gdb = True self.command = "%s %s %s" % (os.path.join( self.sandbox_source_root, "Tools/Scripts/run-minibrowser"), "--" + self.platform.lower(), " --debug" if self.debug else " --release") self.flatpak_build_path = os.environ["FLATPAK_USER_DIR"] build_root = os.path.join(self.source_root, 'WebKitBuild') self.build_path = os.path.join(build_root, self.platform, self.build_type) try: os.makedirs(self.build_path) except OSError as e: if e.errno != errno.EEXIST: raise e self.config_file = os.path.join(self.flatpak_build_path, 'webkit_flatpak_config.json') Console.quiet = self.quiet if not check_flatpak(): return False self.finish_args = [] self.repos = FlatpakRepos() self.sdk_repo = self.repos.add( FlatpakRepo( "webkit-sdk", url="https://software.igalia.com/webkit-sdk-repo/", repo_file= "https://software.igalia.com/flatpak-refs/webkit-sdk.flatpakrepo" )) try: with open(self.config_file) as config: json_config = json.load(config) self.icc_version = json_config['icecc_version'] except IOError as e: pass return True