Exemple #1
0
def prepare_env_and_recheck(input_dir, out_dir, target, num_jobs, config_file):
    if not common.check_if_dir_exists(input_dir):
        common.print_and_exit("Can't use input directory")
    common.check_dir_and_create(out_dir)

    run_gen.gen_test_makefile_and_copy(out_dir, config_file)
    run_gen.dump_testing_sets(target)
    run_gen.print_compilers_version(target)

    lock = multiprocessing.Lock()

    task_queue = multiprocessing.JoinableQueue()
    process_dir(input_dir, task_queue)
    failed_queue = multiprocessing.SimpleQueue()
    passed_queue = multiprocessing.SimpleQueue()

    task_threads = [0] * num_jobs
    for num in range(num_jobs):
        task_threads[num] = \
            multiprocessing.Process(target=recheck,
                                    args=(num, lock, task_queue, failed_queue, passed_queue, target, out_dir))
        task_threads[num].start()

    task_queue.join()
    task_queue.close()

    for num in range(num_jobs):
        task_threads[num].join()
def prepare_and_start(work_dir, config_file, timeout, num_jobs,
                      csmith_bin_path, csmith_runtime, csmith_args, optsets):
    common.check_dir_and_create(work_dir)

    # Check for binary of generator
    csmith_home = os.environ.get("CSMITH_HOME")
    if csmith_home is None:
        common.print_and_exit("Please set CSMITH_HOME envirnoment variable")
    csmith_bin = os.path.abspath(csmith_home + os.sep + csmith_bin_path +
                                 os.sep + "csmith")
    common.check_and_copy(csmith_bin, work_dir)
    os.chdir(work_dir)
    ret_code, output, err_output, time_expired, elapsed_time = \
        common.run_cmd(["." + os.sep + "csmith", "-v"], csmith_timeout, 0)
    csmith_version_str = str(output, "utf-8")
    # TODO: need to add some check, but I hope that it is safe
    common.log_msg(logging.DEBUG, "Csmith version: " + csmith_version_str)

    gen_test_makefile.set_standard("c99")
    gen_test_makefile.parse_config(config_file)

    compiler_run_args = {}
    optsets_list = optsets.split()
    target_was_found = False
    failed_targets = []
    for i in optsets_list:
        for target in gen_test_makefile.CompilerTarget.all_targets:
            if target.name != i:
                continue
            target_was_found = True
            common.log_msg(logging.DEBUG,
                           "Trying to form compiler args for " + str(i))
            run_str = target.specs.comp_c_name + " "
            run_str += target.args + " "
            if target.arch.comp_name != "":
                run_str += " " + target.specs.arch_prefix + target.arch.comp_name + " "
            run_str += gen_test_makefile.StatisticsOptions.get_options(
                target.specs) + " "
            run_str += csmith_runtime + " "
            common.log_msg(logging.DEBUG, "Formed compiler args: " + run_str)
            compiler_run_args[i] = run_str

        if not target_was_found:
            failed_targets.append(i)
        target_was_found = False

    if len(failed_targets) > 0:
        common.log_msg(logging.WARNING,
                       "Can't find relevant target: " + str(failed_targets))

    for i in range(num_jobs):
        common.check_dir_and_create(run_gen.process_dir + str(i))

    manager_obj = run_gen.manager()
    stat = manager_obj.Statistics()

    start_time = time.time()
    end_time = start_time + timeout * 60
    if timeout == -1:
        end_time = -1

    task_threads = [0] * num_jobs
    for num in range(num_jobs):
        task_threads[num] = multiprocessing.Process(target=run_csmith,
                                                    args=(num, csmith_args,
                                                          compiler_run_args,
                                                          end_time, stat))
        task_threads[num].start()

    print_statistics(stat, task_threads, num_jobs)

    sys.stdout.write("\n")
    for i in range(num_jobs):
        common.log_msg(logging.DEBUG,
                       "Removing " + run_gen.process_dir + str(i) + " dir")
        shutil.rmtree(run_gen.process_dir + str(i))

    stat_str, verbose_stat_str, prev_len = form_statistics(stat, 0)
    sys.stdout.write(verbose_stat_str)
    sys.stdout.flush()