#!/usr/bin/env python # This Source Code Form is subject to the terms of the Mozilla Public # License, v. 2.0. If a copy of the MPL was not distributed with this file, # You can obtain one at http://mozilla.org/MPL/2.0/. """ does_it_crash.py
Runs a thing to see if it crashes within a set period. """ import os import signal import subprocess import sys
import requests
sys.path.insert(1, os.path.dirname(sys.path[0]))
import mozinstall import mozprocess from mozharness.base.script import BaseScript
class DoesItCrash(BaseScript):
config_options = [
[
[ "--thing-url",
],
{ "action": "store", "dest": "thing_url", "type": str, "help": "An URL that points to a package containing the thing to run",
},
],
[
[ "--thing-to-run",
],
{ "action": "store", "dest": "thing_to_run", "type": str, "help": "The thing to run. If --thing-url is a package, this should be " "its location relative to the root of the package.",
},
],
[
[ "--thing-arg",
],
{ "action": "append", "dest": "thing_args", "type": str, "default": [], "help": "Args for the thing. May be passed multiple times",
},
],
[
[ "--run-for",
],
{ "action": "store", "dest": "run_for", "default": 30, "type": int, "help": "How long to run the thing for, in seconds",
},
],
]
thing = os.path.abspath(
os.path.join(self.install_dir, self.config["thing_to_run"])
) # thing_args is a LockedTuple, which mozprocess doesn't like
args = list(self.config["thing_args"])
timeout = self.config["run_for"]
self.log(f"Running {thing} with args {args}")
cmd = [thing]
cmd.extend(args)
mozprocess.run_and_wait(
cmd,
timeout=timeout,
timeout_handler=timeout_handler,
output_line_handler=output_line_handler,
) ifnot self.timed_out: # It crashed, oh no!
self.critical(
f"TEST-UNEXPECTED-FAIL: {thing} did not run for {timeout} seconds"
)
self.critical("Output was:") for l in self.output:
self.critical(l)
self.fatal("fail") else:
self.info(f"PASS: {thing} ran successfully for {timeout} seconds")
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.