def __exit__(self, type, value, traceback): """ Remove the working directory completely. Ignore any warnings about it still containing files. """ rmtree(self.work_dir, True) log("Removed working directory.")
def get(): try: return q.get() except Empty: log("Completed in %.02f." % (time() - start)) sys.exit(1) return None
def __init__(self, hostname): self.name = str(uuid1()) self.hostname = hostname self.download_dir = "/tmp/dmut" self.work_dir = "/tmp/%s" % self.name self._init() log("Waiting for work.")
def test(self, id): """ Performs the testing of a particular mutant. Returns True if all tests pass, False if one fails. """ self.id = id status = True test = self.fs.get(self.id) patch_file = test.read() log("Retrieved patch.") log("Executing operator %s on file %s." % (test.op, test.file_name)) self._setup(patch_file) for test_name in self.settings["tests"]: if not self._run_test_case(test_name): log("%s failed." % test_name) status = False break self._teardown() if not status: self.fs.killed(self.id)
def _init(self): mkdir_p(self.download_dir) mkdir_p(self.work_dir) # Load settings from the specified hostname. u = urlopen("http://%s/client.settings" % self.hostname) self.settings = loads(u.read().decode("utf-8")) log("Loaded client.settings.") self.fs = FileStore(self.settings["database"]["name"]) log("Initialized storage.") self.source_path = join(self.download_dir, self.settings["source"]["name"]) if not exists(self.source_path): u = urlopen(self.settings["source"]["location"]) f = open(self.source_path, "wb") f.write(u.read()) log("Downloaded source file.") chdir(self.work_dir) log("Moved into work directory.")
def _clean(self): if self._exec_command_quiet(self.settings["commands"]["clean"]): log("Cleaned project.") else: raise Exception()
def _teardown(self): """ Removes old mutated code. """ rmtree(join(self.work_dir, "*"), True) log("Removed working directory.")
def __exit__(self, type, value, traceback): """ Remove the working directory completely. Ignore any warnings about it still containing files. """ rmtree(self.work_dir, True) log("Removed working directory.") if len(sys.argv) != 3: raise ValueError("Usage: %s %s <http hostname> <master hostname>" % (sys.executable, sys.argv[0])) http_hostname = sys.argv[1] master_hostname = sys.argv[2] master = ServerProxy("http://%s" % master_hostname) with Slave(http_hostname) as s: while True: id = master.get() if not id: log("No more work. Terminating.") break try: s.test(id) except: log("*** ERROR ***: Something went wrong with the test.")
def _setup(self, patch_file): """ Cleans up, applies patch. """ z = ZipFile(self.source_path) z.extractall(self.work_dir) log("Extracted source file.") for cmd in self.settings["commands"]["preprocess"]: self._exec_command_quiet(cmd) log("Executed pre-processing commands.") self._clean() log("Cleaned working directory.") chdir(join(self.work_dir, self.settings["source"]["dir"])) patch(patch_file) chdir(self.work_dir) log("Applied patch.") log("Building code. This may take a while.") if self._exec_command_quiet(self.settings["commands"]["build"]): log("Built current code.") else: self.fs.build_error(self.id) raise Exception()
from time import time from xmlrpc.server import SimpleXMLRPCServer import os import sys sys.path.append(os.getcwd()) from dmut.common.util import log db = Connection()["mutants"] mutants = db.fs.files q = Queue() log("Populating queue with mutants.") for mutant in mutants.find({"killed": False}): q.put(str(mutant["_id"])) log("Queue populated. Ready to serve.") start = time() def get(): try: return q.get() except Empty: log("Completed in %.02f." % (time() - start)) sys.exit(1)