Exemplo n.º 1
0
def print_compilation_status(printer: Printer, solution: str, max_sol_len: int,
                             loading_char: str,
                             status: SourceFileCompilationStatus):
    """
    Print the status of the compilation of a file
    """
    print_solution_column(printer, solution, max_sol_len)
    if status == SourceFileCompilationStatus.WAITING:
        printer.text("...")
    elif status == SourceFileCompilationStatus.COMPILING:
        printer.text(loading_char)
    elif status == SourceFileCompilationStatus.DONE:
        printer.green("OK", bold=True)
    else:
        printer.red("FAIL", bold=True)
    printer.text("\n")
Exemplo n.º 2
0
def print_subtask_result(printer: Printer, text: str,
                         result: SubtaskSolutionResult):
    """
    Print a string with a color based on the status of a subtask
    """
    if result == SubtaskSolutionResult.WAITING:
        printer.text(text)
    elif result == SubtaskSolutionResult.RUNNING:
        printer.text(text)
    elif result == SubtaskSolutionResult.ACCEPTED:
        printer.green(text)
    elif result == SubtaskSolutionResult.PARTIAL:
        printer.yellow(text)
    elif result == SubtaskSolutionResult.REJECTED:
        printer.red(text)
    else:
        raise ValueError(result)
Exemplo n.º 3
0
    def make_booklet(frontend: Frontend, config: Config,
                     tasks: List[Tuple[str, IOITask]]) -> int:
        statements = dict()  # type: Dict[str, List[OIITexStatement]]
        for path, task in tasks:
            config.task_dir = path
            os.chdir(path)
            tex_files = list_files(["statement/*.tex", "testo/*.tex"],
                                   valid_extensions=[".tex"])
            for tex_file in tex_files:
                lang = os.path.basename(tex_file)[:-4]
                statement = OIITexStatement(task, os.path.abspath(tex_file))
                if lang not in statements:
                    statements[lang] = list()
                statements[lang].append(statement)

        if config.ui == UIS.PRINT:
            printer = StdoutPrinter()
        else:
            printer = Printer()
        ui_printer = UIPrinter(printer, config.ui == UIS.JSON)
        pool = ExecutionPool(config, frontend, ui_printer)

        successful_compilations = 0
        for lang, texts in statements.items():
            file_name = "booklet_%s.pdf" % lang
            target_file = os.path.join(config.contest_dir, file_name)
            compilation, pdf_file, deps = OIITexStatement.compile_booklet(
                pool, texts, lang)
            if not pool.config.dry_run:
                pdf_file.getContentsToFile(target_file)

            def on_done(res: Result):
                nonlocal successful_compilations
                if res.status == ResultStatus.SUCCESS or \
                        res.status == ResultStatus.RETURN_CODE:
                    successful_compilations += 1

            compilation.bind(on_done)

        pool.start()
        return len(statements) - successful_compilations
Exemplo n.º 4
0
    def __init__(self, task: Task, do_print: bool, json: bool, tmsocial=False):
        """
        :param task: The task this UIInterface is bound to
        :param do_print: Whether the logs should be printed to stdout (print
        interface)
        """
        self.task = task
        self.non_solutions = dict(
        )  # type: Dict[str, SourceFileCompilationResult]
        self.solutions = dict()  # type: Dict[str, SourceFileCompilationResult]
        self.statements = dict()  # type: Dict[str, Statement]
        self.warnings = list()  # type: List[str]
        self.errors = list()  # type: List[str]
        self.pool = None  # type: ExecutionPool

        if do_print:
            self.printer = StdoutPrinter()
        else:
            self.printer = Printer()

        if tmsocial:
            self.ui_printer = UITMSocialPrinter()
        else:
            self.ui_printer = UIPrinter(self.printer, json)
Exemplo n.º 5
0
def fuzz_checker(config: Config):
    in_file, out_file = config.fuzz_checker
    if not os.path.exists(in_file):
        raise ValueError("The input file does not exists")
    if not os.path.exists(out_file):
        raise ValueError("The output file does not exists")

    from task_maker.formats.ioi_format import get_task
    task = get_task(config)
    if not task.checker:
        raise ValueError("This task does not have a checker")

    results_dir = os.path.join(config.cwd, "fuzz_checker_" + task.name)
    os.makedirs(results_dir, exist_ok=True)
    shutil.copy(in_file, os.path.join(results_dir, "input.txt"))
    shutil.copy(out_file, os.path.join(results_dir, "output.txt"))

    ui_printer = UIPrinter(Printer(), False)
    state = FuzzCheckerState()
    while True:
        state.batch_num += 1
        frontend = get_frontend(config)
        pool = ExecutionPool(config, frontend, ui_printer)

        input = frontend.provideFile(in_file, "Input file")
        output = frontend.provideFile(out_file, "Output file")
        task.checker.unprepare()
        task.checker.prepare(pool)

        for num in range(BATCH_SIZE):
            seed = random.randint(0, 10 ** 9)
            gen = Execution(
                "Generation of output %d of batch %d" % (num, state.batch_num),
                pool,
                "radamsa", ["--seed", str(seed), "-"],
                "fuzz-checker-radamsa",
                ui_print_data={
                    "batch": state.batch_num,
                    "num": num,
                    "seed": seed
                },
                cache_on=[],
                stdin=output,
                store_stdout_bytes=True)
            fuzz_output = gen.stdout
            check = Execution(
                "Checking output %d of batch %d" % (num, state.batch_num),
                pool,
                task.checker, ["input", "output", "fuzz"],
                "fuzz-checker-checker",
                ui_print_data={
                    "batch": state.batch_num,
                    "num": num,
                    "seed": seed
                },
                cache_on=[],
                inputs={
                    "input": input,
                    "output": output,
                    "fuzz": fuzz_output
                },
                store_stdout_bytes=True,
                store_stderr_bytes=True)
            state.bind(results_dir, gen, check)

        def compilation_on_done(res: Result):
            if res.status != ResultStatus.SUCCESS:
                print("Failed to compile the checker")
                print(task.checker.compilation.stderr_content)
                pool.stop()

        if task.checker.compilation:
            task.checker.compilation.bind(compilation_on_done)

        pool.start()
        print(state)
        if pool.stopped:
            return state.num_fails
Exemplo n.º 6
0
def print_testcase_solution_result(printer: Printer, loading: str,
                                   info: TestcaseSolutionInfo):
    """
    Print the letter relative to the status of solution
    """
    if info.status == TestcaseSolutionStatus.WAITING:
        printer.text(".")
    elif info.status == TestcaseSolutionStatus.SOLVING:
        printer.blue(loading)
    elif info.status == TestcaseSolutionStatus.SOLVED:
        printer.text("s")
    elif info.status == TestcaseSolutionStatus.CHECKING:
        printer.text(loading)
    elif info.status == TestcaseSolutionStatus.SKIPPED:
        printer.text("X")
    elif info.checked and info.status == TestcaseSolutionStatus.ACCEPTED:
        printer.green("A", bold=True)
    elif info.checked and info.status == TestcaseSolutionStatus.WRONG_ANSWER:
        printer.red("W", bold=True)
    elif info.checked and info.status == TestcaseSolutionStatus.PARTIAL:
        printer.yellow("P", bold=True)
    elif info.checked and info.status == TestcaseSolutionStatus.FAILED:
        for res in info.result:
            if res.status != ResultStatus.SUCCESS:
                result = res
                break
        else:
            result = None
        # marked as failed even if no solution failed --> the checker
        if result is None:
            printer.bold("I", bold=True)
        elif result.status == ResultStatus.SIGNAL:
            printer.red("R", bold=True)
        elif result.status == ResultStatus.RETURN_CODE:
            printer.red("R", bold=True)
        elif result.status == ResultStatus.TIME_LIMIT:
            printer.red("T", bold=True)
        elif result.status == ResultStatus.WALL_LIMIT:
            printer.red("T", bold=True)
        elif result.status == ResultStatus.MEMORY_LIMIT:
            printer.red("M", bold=True)
        elif result.status == ResultStatus.MISSING_FILES:
            printer.red("F", bold=True)
        elif result.status == ResultStatus.INTERNAL_ERROR:
            printer.bold("I", bold=True)
        else:
            raise ValueError(result)
    elif not info.checked:
        printer.blue(loading)
    else:
        raise ValueError("{} {}".format(info.checked, info.status))
Exemplo n.º 7
0
def print_testcase_generation_status(printer: Printer,
                                     status: TestcaseGenerationStatus):
    """
    Print the letter relative to the generation status
    """
    if status == TestcaseGenerationStatus.WAITING:
        printer.text(".")
    elif status == TestcaseGenerationStatus.GENERATING:
        printer.blue("g", bold=True)
    elif status == TestcaseGenerationStatus.GENERATED:
        printer.text("G")
    elif status == TestcaseGenerationStatus.VALIDATING:
        printer.blue("v", bold=True)
    elif status == TestcaseGenerationStatus.VALIDATED:
        printer.text("V")
    elif status == TestcaseGenerationStatus.SOLVING:
        printer.blue("s", bold=True)
    elif status == TestcaseGenerationStatus.DONE:
        printer.green("S", bold=True)
    else:
        printer.red("F", bold=True)
Exemplo n.º 8
0
def print_statement_result(printer: Printer, name: str, statement: Statement,
                           max_sol_len: int, loading: str):
    """
    Print the row of a statement file, including the dependencies
    """
    print_solution_column(printer, name, max_sol_len)
    if statement.compilation_status == StatementCompilationStatus.WAITING:
        printer.text("...")
    elif statement.compilation_status == \
            StatementCompilationStatus.COMPILING_DEPS:
        printer.blue("d")
    elif statement.compilation_status == \
            StatementCompilationStatus.COMPILED_DEPS:
        printer.text("D")
    elif statement.compilation_status == StatementCompilationStatus.COMPILING:
        printer.text(loading)
    elif statement.compilation_status == StatementCompilationStatus.DONE:
        printer.green("OK")
    elif statement.compilation_status == StatementCompilationStatus.FAILED:
        printer.red("FAIL")
    else:
        raise ValueError("Invalid compilation status " +
                         str(statement.compilation_status))
    printer.text(" ")
    if statement.other_executions:
        printer.text("[")
        for dep in statement.other_executions:
            if dep.status == StatementDepCompilationStatus.WAITING:
                printer.text(".")
            elif dep.status == StatementDepCompilationStatus.RUNNING:
                printer.text(loading)
            elif dep.status == StatementDepCompilationStatus.DONE:
                printer.green("✓")
            elif dep.status == StatementDepCompilationStatus.FAILED:
                printer.red("F")
            else:
                raise ValueError("Invalid dependency status " +
                                 str(dep.status))
        printer.text("]")
    printer.text("\n")
Exemplo n.º 9
0
def print_solution_column(printer: Printer, solution: str, max_sol_len: int):
    """
    Print the solution name padded to fit in the column
    """
    printer.text("%{}s ".format(max_sol_len) % solution)
Exemplo n.º 10
0
def print_solutions_result(printer: Printer, task: IOITask,
                           solutions: Dict[str, SolutionStatus],
                           max_sol_len: int, loading: str):
    """
    Print the matrix with the solutions' statuses
    """
    printer.text(" " * max_sol_len + " ")
    max_score = sum(st.max_score for st in task.subtasks.values())
    printer.bold("{:^5.0f}|".format(max_score))
    for subtask in task.subtasks.values():
        printer.bold("{:^5.0f}".format(subtask.max_score))
    printer.text("\n")

    for solution, status in solutions.items():
        print_solution_column(printer, solution, max_sol_len)
        if all([
                s == SubtaskSolutionResult.WAITING
                for s in status.subtask_results.values()
        ]):
            printer.text(" ... ")
        elif any([
                s == SubtaskSolutionResult.RUNNING
                for s in status.subtask_results.values()
        ]):
            printer.text("  {}  ".format(loading))
        else:
            printer.text(" {:^3.0f} ".format(status.score))
        printer.text("|")

        for st_num in status.subtask_results.keys():
            score = status.subtask_scores[st_num]
            result = status.subtask_results[st_num]
            if result == SubtaskSolutionResult.WAITING:
                printer.text(" ... ")
            elif result == SubtaskSolutionResult.RUNNING:
                printer.text("  {}  ".format(loading))
            else:
                print_subtask_result(printer, " {:^3.0f} ".format(score),
                                     result)

        printer.text("  ")
        for st_num in status.subtask_results.keys():
            testcases = status.testcase_results[st_num]
            st_result = status.subtask_results[st_num]
            print_subtask_result(printer, "[", st_result)
            for tc_num, testcase in testcases.items():
                print_testcase_solution_result(printer, loading, testcase)
            print_subtask_result(printer, "]", st_result)

        printer.text("\n")