def __init__(self, config_path): with open(config_path) as yml: self.config = load(yml) # ensure that the bug is built before launching threads b = bugzoo.BugZoo() bug = b.bugs[self.config['bugzoo_id']] b.bugs.build(bug=bug)
def main(): bz = bugzoo.BugZoo() bug = bz.bugs["tse2012:zune"] bz.bugs.build(bug, force=True) files = ['zune.c'] # files = ['atris_comb.c'] with rooibos.ephemeral_server() as client_rooibos: coverage = bz.bugs.coverage(bug) problem = darjeeling.problem.Problem(bz, bug, coverage, client_rooibos=client_rooibos) snippets = SnippetDatabase.from_problem(problem) # FIXME add filtering print("\n[SNIPPETS]") for (i, snippet) in enumerate(snippets): print("{}: {}".format(i, snippet)) print("[\SNIPPETS]\n") time_limit = datetime.timedelta(minutes=15) # let's setup logging log_to_stdout = logging.StreamHandler() log_to_stdout.setLevel(logging.DEBUG) logging.getLogger('darjeeling').addHandler(log_to_stdout) patches, report = darjeeling.repair.repair(bz, problem, threads=10, seed=0, time_limit=time_limit)
def test_add_source(self): bz = bugzoo.BugZoo() manybugs_url = 'https://github.com/squaresLab/ManyBugs' # attempt to install ManyBugs self.run_command(['source', 'add', 'manybugs', manybugs_url]) # check that the source has been registered try: bz.sources.refresh() bz.sources['manybugs'] except KeyError: self.fail("Failed to find registered source.") # remove the source self.run_command(['source', 'remove', 'manybugs']) bz.sources.refresh() with self.assertRaises(KeyError): bz.sources['manybugs'] # re-add ManyBugs! self.run_command(['source', 'add', 'manybugs', manybugs_url]) try: bz.sources.refresh() bz.sources['manybugs'] except KeyError: self.fail("Failed to find registered source.")
def main(): # setup logging log_to_stdout = logging.StreamHandler() log_to_stdout.setLevel(logging.DEBUG) FORMAT = '%(asctime)-15s %(message)s' logging.basicConfig(format=FORMAT) logging.getLogger('houston').addHandler(log_to_stdout) logging.getLogger('bugzoo').addHandler(log_to_stdout) bz = bugzoo.BugZoo() # construct a test environment = Environment({}) configuration = ArduCopter.configuration(speedup=1, time_per_metre_travelled=5.0, constant_timeout_offset=1.0, min_parachute_alt=10.0) commands = [ # ArmDisarm(arm=True), # ArmDisarm(arm=False), Takeoff(altitude=3.0), GoTo(latitude=-35.3632607, longitude=149.1662351, altitude=3.4) # SetMode(mode='LAND'), # ArmDisarm(arm=False) ] state_initial = ArduCopter.state(home_latitude=-35.3632607, home_longitude=149.1652351, latitude=-35.3632607, longitude=149.1652351, altitude=0.0, armed=False, armable=True, mode="GUIDED", ekf_ok=True, yaw=0.0, roll=0.0, pitch=0.0, roll_channel=0.0, throttle_channel=0.0, heading=0.0, groundspeed=0.0, airspeed=0.0, vx=0.0, vy=0.0, vz=0.0, time_offset=0.0) mission = Mission(configuration, environment, state_initial, commands, ArduCopter) for c in ArduCopter.commands: print(c) # the Docker image that provides the SUT snapshot = 'ardubugs:742cdf6b' #with Sandbox.for_snapshot(bz, snapshot, state_initial, environment, configuration) as sandbox: # noqa: pycodestyle # outcome = sandbox.run(commands) outcome = mission.run(bz, snapshot, "example/temp.jsn") print(outcome)
def thread(self, index, return_dict, edits_to_make, num_edits, neg_tests, exp_number): output_folder = self.config['output_directory'] + self.config[ 'program'] + '/' + str(exp_number) + '/' # create bugzoo instance b = bugzoo.BugZoo() bug = b.bugs[self.config['bugzoo_id']] genprog = b.tools['genprog'] container = b.containers.provision(bug=bug, tools=[genprog]) # copy in coverage paths to skip sanity and coverage check time call("docker cp " + self.config['output_directory'] + "coverage.path.pos " + container.uid + ":/experiment/coverage.path.pos", shell=True) call("docker cp " + self.config['output_directory'] + "coverage.path.neg " + container.uid + ":/experiment/coverage.path.neg", shell=True) invoke_genprog = 'cd /experiment && /opt/genprog/bin/genprog configuration-default --oracle-genome ' + \ "\'\"\'" + edits_to_make + "\'\"\'" + ' --search pd-oracle --skip-failed-sanity-tests ' \ '--allow-coverage-fail' tuple_returned = b.containers.command(container=container, cmd=invoke_genprog) call("mkdir -p " + output_folder, shell=True) with open(output_folder + str(index), 'w') as out_file: out_file.write(tuple_returned.output) # TODO: fix this logic; skipping for now # Force cleanup of container before thread exits call("docker stop " + str(container.uid), shell=True) # parse for neutrality text = str(tuple_returned.output) was_neutral = False was_repair = False if text.find("was neutral") != -1: was_neutral = True if text.find("passed " + str(neg_tests)) != -1: was_repair = True return_dict[index] = { "index": index, "edits_to_make": edits_to_make, "num_edits": num_edits, "neutral": was_neutral, "repair": was_repair }
def gen_single_mutations(bugzoo_id, output_directory): """ :return: a list of single edits """ # bugzoo setup b = bugzoo.BugZoo() print("Instantiating bug reference") bug = b.bugs[bugzoo_id] b.bugs.build(bug=bug) print("Running GenProg to generate coverage paths") genprog = b.tools['genprog'] container = b.containers.provision(bug=bug, tools=[genprog]) outcome = b.containers.command( container=container, cmd= "genprog configuration-default --search ga --generations 1 --popsize 1" " --seed 0 --skip-failed-sanity-tests --allow-coverage-fail" " && cat coverage.path.pos && cat coverage.path.neg") call("mkdir -p " + output_directory, shell=True) call("docker cp " + container.uid + ":/experiment/coverage.path.pos " + output_directory + "coverage.path.pos", shell=True) call("docker cp " + container.uid + ":/experiment/coverage.path.neg " + output_directory + "coverage.path.neg", shell=True) call("docker cp " + container.uid + ":/experiment/repair.debug.0 " + output_directory + "repair.debug.0", shell=True) print("Generating search space from single edits") coverage_paths = [ output_directory + 'coverage.path.pos', output_directory + 'coverage.path.neg' ] indices = exhaustive.parse_lists(coverage_paths) max_index = exhaustive.get_max_index(program_path=output_directory) single_edits = exhaustive.generate_single_edits(covered_indices=indices, max_index=max_index) exhaustive.write_edits_to_file(list_to_write=single_edits, folder_path=output_directory, filename="single_edits") call("docker stop " + str(container.uid), shell=True) return single_edits
#!/usr/bin/env python import bugzoo from darjeeling.problem import Problem from darjeeling.repair import repair if __name__ == '__main__': # how many threads would you like to use? threads = 32 # construct a description of the problem for Darjeeling in_files = ['APMrover2/commands_logic.cpp'] # retrieve the bug that we wish to fix from the BugZoo bz = bugzoo.BugZoo() bug = bz.bugs["ardudemo:ardupilot:overflow"] problem = Problem(bug, in_files) # Since we can't obtain coverage information for ArduPilot right now, # this isn't actually used. metric = bugzoo.localization.suspiciousness.tarantula # this will run indefinitely until a repair is found. repair(problem, metric, threads=threads)
def thread(self, index): """ Contains the logic for evaluating the neutrality of a single mutation; thread-safe afaik :param index: the index number of the thread being run :return: """ end = datetime.datetime.now() + datetime.timedelta( days=float(self.config["days_to_run_neutrality"])) config = self.config edits_per_thread = int( int(config["single_edit_cardinality"]) / int(config["parallel_workers"])) range_min = 0 + (index * edits_per_thread) range_max = (edits_per_thread + (index * edits_per_thread)) if index < (int(config["parallel_workers"]) - 1) \ else int(config["single_edit_cardinality"]) # bugzoo setup per thread b = bugzoo.BugZoo() bug = b.bugs[config['bugzoo_id']] genprog = b.tools['genprog'] # iterate through assigned range for a in range(range_min, range_max): # check that the work has not been done already (check-pointing) if not os.path.exists(config["output_directory"] + 'neutral_check_directory/' + str(a) + '/'): # check that time limit for neutrality evaluation has not been exceeded if not datetime.datetime.now() > end: print(a) container = b.containers.provision(bug=bug, tools=[genprog]) # copy in coverage paths to skip sanity and coverage check time call("docker cp " + config['output_directory'] + "coverage.path.pos " + container.uid + ":/experiment/coverage.path.pos", shell=True) call("docker cp " + config['output_directory'] + "coverage.path.neg " + container.uid + ":/experiment/coverage.path.neg", shell=True) # apply edit a edit_string = self.edit_list[a] ret = b.containers.command( container=container, cmd= 'rm *.cache; genprog configuration-default --search pd-oracle ' '--skip-failed-sanity-tests --allow-coverage-fail --oracle-genome ' + "\'\"\'" + edit_string.strip('\n') + "\'\"\'") # save to file output_folder = config[ "output_directory"] + 'neutral_check_directory/' + str( a) + '/' call('mkdir -p ' + output_folder, shell=True) with open(output_folder + "repair.debug.oracle", 'w') as out_file: out_file.write(ret.output) # clean up thread before exiting call("docker stop " + str(container.uid), shell=True) print("thread " + str(index) + " is done")