def main()

in tools/incremental_test/main.py [0:0]


def main(arguments: argparse.Namespace) -> int:
    specification_path: Optional[Path] = arguments.specification
    try:
        LOG.info("Reading input JSON...")
        if specification_path is None:
            file_content = sys.stdin.read()
        else:
            with open(specification_path, "r") as specification_file:
                file_content = specification_file.read()
        specification_jsons = json.loads(file_content)
        if not isinstance(specification_jsons, list):
            raise InvalidSpecificationException("Input JSON is not a list")

        LOG.info("Parsing JSON into test specification...")
        specifications = [
            Specification.from_json(input_json) for input_json in specification_jsons
        ]

        if arguments.benchmark:
            LOG.info(f"Start benchmarking {len(specifications)} specifications...")
            results = run_batch_benchmark(SubprocessEnvironment(), specifications)
            _log_benchmark_statistics(results)
            LOG.info("Done benchmarking.")
        else:
            LOG.info(f"Start testing {len(specifications)} specifications...")
            results = run_batch_test(SubprocessEnvironment(), specifications)
            _log_test_statistics(results)
            LOG.info("Done testing.")

        logger = arguments.logger
        if logger is None:
            report.to_console(results, arguments.dont_show_discrepancy)
        else:
            report.to_logger(logger, results, arguments.test_identifier)
    except FileNotFoundError:
        LOG.exception(f"Specification file at {specification_path} does not exist")
        return ExitCode.FAILURE
    except json.JSONDecodeError:
        LOG.exception(f"Cannot parse JSON at {specification_path}")
        return ExitCode.FAILURE
    except InvalidSpecificationException:
        LOG.exception("Invalid specification JSON")
        return ExitCode.FAILURE
    except Exception:
        LOG.exception("Exception occurs in the check")
        return ExitCode.FAILURE
    all_passed = all(result.get_status() == "pass" for result in results)
    return ExitCode.SUCCESS if all_passed else ExitCode.FOUND_ERRORS