def plot_objectives(logbooks): for obj in range(0, 3): y_min, y_max = find_ylim_objective(logbooks, obj) for i, logbook in enumerate(logbooks): two_d_line.y_min = y_min two_d_line.y_max = y_max two_d_line.plot(logbook, obj, app_dirs[i])
def draw_graphs(logbook, instrumented_app_dir): # draw graphs two_d_line.plot(logbook, 0, instrumented_app_dir) two_d_line.plot(logbook, 1, instrumented_app_dir) two_d_line.plot(logbook, 2, instrumented_app_dir) two_d_line.plotProportionParetoOptimal(logbook, instrumented_app_dir) two_d_line.plotPopulationDiameter(logbook, instrumented_app_dir) two_d_line.plotRelativeDiameter(logbook, instrumented_app_dir) two_d_line.plotPopulationDiversity(logbook, instrumented_app_dir) two_d_line.plotGraphMetrics(logbook, instrumented_app_dir) two_d_line.plotHypervolume(logbook, instrumented_app_dir)
def main(folder_name, instrumented_app_dir, seed=None): random.seed(seed) # generate initial population print "### Initialising population ...." population = toolbox.population(n=settings.POPULATION_SIZE) hof = tools.ParetoFront() stats = tools.Statistics(lambda ind: ind.fitness.values) stats.register("avg", numpy.mean, axis=0) stats.register("std", numpy.std, axis=0) stats.register("min", numpy.min, axis=0) stats.register("max", numpy.max, axis=0) population, logbook = evolve(population, toolbox, settings.POPULATION_SIZE, settings.OFFSPRING_SIZE, cxpb=settings.CXPB, mutpb=settings.MUTPB, ngen=settings.GENERATION, stats=stats, halloffame=hof, verbose=True) # draw graphs two_d_line.plot(logbook, 0, instrumented_app_dir) two_d_line.plot(logbook, 1, instrumented_app_dir) two_d_line.plot(logbook, 2, instrumented_app_dir) two_d_line.plotProportionParetoOptimal(logbook, instrumented_app_dir) two_d_line.plotPopulationDiameter(logbook, instrumented_app_dir) two_d_line.plotRelativeDiameter(logbook, instrumented_app_dir) two_d_line.plotPopulationDiversity(logbook, instrumented_app_dir) two_d_line.plotStats(logbook, instrumented_app_dir, 'kconnec', 'kconnec', 'weight') two_d_line.plotHypervolume(logbook, instrumented_app_dir) time.sleep(5) os.system('cd ' + instrumented_app_dir + '/intermediate && mkdir ' + folder_name) os.system('cd ' + instrumented_app_dir + '/intermediate && mv *.pdf ' + folder_name + '/') os.system( 'cd ' + instrumented_app_dir + '/intermediate/ ' + folder_name + ' && pdfunite obj_0.pdf obj_1.pdf obj_2.pdf hv_standard.pdf ' 'proportion_pareto_optimal.pdf population_diameter.pdf rel_diameter.pdf ' 'population_diversity.pdf kconnec.pdf summary.pdf')
def main(instrumented_app_dir): """ Test one apk :param instrumented_app_dir: The instrumentation folder of the app | apk file path for closed-source app """ host_system = platform.system() if host_system == "Darwin": print "Running on Mac OS" settings.TIMEOUT_CMD = "gtimeout" elif host_system == "Linux": print "Running on Linux" else: print "Runnning on unknown OS" package_name, apk_path = get_package_name(instrumented_app_dir) # for css subjects if instrumented_app_dir.endswith(".apk"): instrumented_app_dir += "_output" os.system("mkdir " + instrumented_app_dir) print "### Working on apk:", package_name # get emulator device print "Preparing devices ..." emulator.boot_devices() emulator.prepare_motifcore() emulator.clean_sdcard() # log the devices devices = emulator.get_devices() # static analysis if settings.ENABLE_STRING_SEEDING: output_dir = None if instrumented_app_dir.endswith(".apk_output"): output_dir = instrumented_app_dir else: output_dir = instrumented_app_dir + "/bin" static_analyser.decode_apk(apk_path, output_dir) # will use dummy 0 if disabled for device in devices: decoded_dir = None if instrumented_app_dir.endswith(".apk_output"): decoded_dir = instrumented_app_dir + "/" + apk_path.split("/")[-1].split(".apk")[0] else: decoded_dir = instrumented_app_dir + "/bin/" + apk_path.split("/")[-1].split(".apk")[0] static_analyser.upload_string_xml(device, decoded_dir, package_name) os.system("adb -s " + device + " shell rm /mnt/sdcard/bugreport.crash") os.system("adb -s " + device + " uninstall " + package_name) os.system("adb -s " + device + " install " + apk_path) # intermediate should be in app folder os.system("rm -rf " + instrumented_app_dir + "/intermediate") os.system("mkdir " + instrumented_app_dir + "/intermediate") os.system("rm -rf " + instrumented_app_dir + "/crashes") os.system("mkdir " + instrumented_app_dir + "/crashes") os.system("rm -rf " + instrumented_app_dir + "/coverages") os.system("mkdir " + instrumented_app_dir + "/coverages") # generate initial population print "### Initialising population ...." population = toolbox.population(n=settings.POPULATION_SIZE, apk_dir=instrumented_app_dir, package_name=package_name) print "### Individual Lengths: " for indi in population: for seq in indi: print len(seq), print "" history.update(population) # hof = tools.HallOfFame(6) # pareto front can be large, there is a similarity option parameter hof = tools.ParetoFront() stats = tools.Statistics(lambda ind: ind.fitness.values) # axis = 0, the numpy.mean will return an array of results stats.register("avg", numpy.mean, axis=0) stats.register("std", numpy.std, axis=0) stats.register("min", numpy.min, axis=0) stats.register("max", numpy.max, axis=0) stats.register("pop_fitness", return_as_is) # evolve print "\n\n\n### Start to Evolve" population, logbook = eaMuPlusLambdaParallel.evolve(population, toolbox, settings.POPULATION_SIZE, settings.OFFSPRING_SIZE, cxpb=settings.CXPB, mutpb=settings.MUTPB, ngen=settings.GENERATION, apk_dir=instrumented_app_dir, package_name=package_name, stats=stats, halloffame=hof, verbose=True) # persistent logbook_file = open(instrumented_app_dir + "/intermediate/logbook.pickle", 'wb') pickle.dump(logbook, logbook_file) logbook_file.close() hof_file = open(instrumented_app_dir + "/intermediate/hof.pickle", 'wb') pickle.dump(hof, hof_file) hof_file.close() history_file = open(instrumented_app_dir + "/intermediate/history.pickle", 'wb') pickle.dump(history, history_file) history_file.close() # draw graph two_d_line.plot(logbook, 0, instrumented_app_dir) two_d_line.plot(logbook, 1, instrumented_app_dir) two_d_line.plot(logbook, 2, instrumented_app_dir)