예제 #1
0
def recheck(num, lock, task_queue, failed_queue, passed_queue, target,
            out_dir):
    common.log_msg(logging.DEBUG, "Started recheck. Process #" + str(num))
    cwd_save = os.getcwd()
    abs_out_dir = os.path.join(cwd_save, out_dir)
    job_finished = False
    while not job_finished:
        try:
            test_dir = task_queue.get_nowait()
            task_queue.task_done()
            common.log_msg(
                logging.DEBUG,
                "#" + str(num) + " test directory: " + str(test_dir))
            abs_test_dir = os.path.join(cwd_save, test_dir)
            common.check_and_copy(
                os.path.join(os.path.join(cwd_save, out_dir),
                             gen_test_makefile.Test_Makefile_name),
                os.path.join(abs_test_dir,
                             gen_test_makefile.Test_Makefile_name))
            os.chdir(os.path.join(cwd_save, abs_test_dir))

            valid_res = None
            out_res = set()
            prev_out_res_len = 1  # We can't check first result
            for i in gen_test_makefile.CompilerTarget.all_targets:
                if i.specs.name not in target.split():
                    continue

                common.log_msg(logging.DEBUG, "Re-checking target " + i.name)
                ret_code, output, err_output, time_expired, elapsed_time = \
                    common.run_cmd(["make", "-f", gen_test_makefile.Test_Makefile_name, i.name],
                                   run_gen.compiler_timeout, num)
                if time_expired or ret_code != 0:
                    failed_queue.put(test_dir)
                    common.log_msg(logging.DEBUG,
                                   "#" + str(num) + " Compilation failed")
                    common.copy_test_to_out(
                        abs_test_dir, os.path.join(abs_out_dir, test_dir),
                        lock)
                    break

                ret_code, output, err_output, time_expired, elapsed_time = \
                    common.run_cmd(["make", "-f", gen_test_makefile.Test_Makefile_name, "run_" + i.name],
                                   run_gen.run_timeout, num)
                if time_expired or ret_code != 0:
                    failed_queue.put(test_dir)
                    common.log_msg(logging.DEBUG,
                                   "#" + str(num) + " Execution failed")
                    common.copy_test_to_out(
                        abs_test_dir, os.path.join(abs_out_dir, test_dir),
                        lock)
                    break

                out_res.add(str(output, "utf-8").split()[-1])
                if len(out_res) > prev_out_res_len:
                    prev_out_res_len = len(out_res)
                    failed_queue.put(test_dir)
                    common.log_msg(logging.DEBUG,
                                   "#" + str(num) + " Out differs")
                    if not blame_opt.prepare_env_and_blame(
                            abs_test_dir, valid_res, i, abs_out_dir, lock,
                            num):
                        common.copy_test_to_out(
                            abs_test_dir, os.path.join(abs_out_dir, test_dir),
                            lock)
                    break
                valid_res = str(output, "utf-8").split()[-1]

            passed_queue.put(test_dir)
            os.chdir(cwd_save)

        except queue.Empty:
            job_finished = True
예제 #2
0
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()