Example #1
0
 def test_tls(self) -> None:
     parser = Parser()
     for f in [
             "tls_alert.rflx", "tls_handshake.rflx", "tls_heartbeat.rflx",
             "tls_record.rflx"
     ]:
         parser.parse(f"{self.specdir}/{f}")
Example #2
0
 def assert_specifications(
         self, filenames: List[str],
         specifications: Dict[str, Specification]) -> None:
     parser = Parser()
     for filename in filenames:
         parser.parse(filename)
     self.assertEqual(parser.specifications(), specifications, filenames)
Example #3
0
def parse(files: List) -> Tuple[List, List]:
    parser = Parser()

    for f in files:
        if not Path(f).is_file():
            raise Error(f'file not found: "{f}"')

        print(f"Parsing {f}... ", end="", flush=True)
        parser.parse(f)
        print("OK")

    return (parser.messages, parser.refinements)
Example #4
0
    def assert_integration(self, basenames: List[str]) -> None:
        parser = Parser()
        for basename in basenames:
            parser.parse(f"{self.specdir}/{basename}.rflx")

        generator = Generator("RFLX.", reproducible=True)
        generator.generate(parser.messages, parser.refinements)

        for unit in generator.units.values():
            with open(f"{self.testdir}/{unit.name}.ads", "r") as f:
                self.assertEqual(unit.specification, f.read())
            if unit.body:
                with open(f"{self.testdir}/{unit.name}.adb", "r") as f:
                    self.assertEqual(unit.body, f.read())
Example #5
0
    def __init__(self, files: List[str]) -> None:
        parser = Parser()
        self.__packages: Dict[str, Package] = {}

        for f in files:
            if not Path(f).is_file():
                raise FileNotFoundError(f'file not found: "{f}"')
            parser.parse(Path(f))
        model = parser.create_model()
        packages = set(str(m.package) for m in model.messages)
        for p in packages:
            self.__packages[p] = Package(p)
            for m in [x for x in model.messages if str(x.package) == p]:
                self.__packages[p][str(m.name)] = MessageValue(
                    m, model.refinements)
Example #6
0
    def assert_dissector(self, basenames: List[str]) -> None:
        parser = Parser()
        for basename in basenames:
            parser.parse(f'{self.specdir}/{basename}.rflx')

        generator = Generator()
        generator.generate_dissector(parser.pdus, parser.refinements)

        for unit in generator.units():
            basename = unit.package.name.lower().replace('.', '-')
            with open(f'{self.testdir}/{basename}.ads', 'r') as f:
                self.assertEqual(unit.specification(), f.read())
            if unit.definition().strip():
                with open(f'{self.testdir}/{basename}.adb', 'r') as f:
                    self.assertEqual(unit.definition(), f.read())
def main(argv: Sequence[str]) -> int:
    arg_parser = argparse.ArgumentParser()
    arg_parser.add_argument("directory",
                            metavar="DIRECTORY",
                            help="output directory",
                            type=pathlib.Path)
    args = arg_parser.parse_args(argv[1:])

    parser = Parser()
    for f in SPECIFICATION_FILES:
        parser.parse(pathlib.Path(f))

    generator = Generator("RFLX", reproducible=True)
    generator.generate(parser.create_model())
    for model in MODELS:
        generator.generate(model)
    generator.write_units(args.directory)
    generator.write_library_files(args.directory)
    generator.write_top_level_package(args.directory)

    return 0
Example #8
0
def parse(files: List) -> Model:
    parser = Parser()

    error = RecordFluxError()
    for f in files:
        if not Path(f).is_file():
            error.append(f'file not found: "{f}"', Subsystem.CLI,
                         Severity.ERROR)
            continue
        try:
            parser.parse(Path(f))
        except RecordFluxError as e:
            error.extend(e)

    try:
        model = parser.create_model()
    except RecordFluxError as e:
        error.extend(e)

    error.propagate()
    return model
Example #9
0
 def assert_parser_error(self, filenames: List[str], regex: str) -> None:
     with self.assertRaisesRegex(ParserError, regex):
         parser = Parser()
         for filename in filenames:
             parser.parse(filename)
Example #10
0
 def assert_pdus(self, filenames: List[str], pdus: List[PDU]) -> None:
     parser = Parser()
     for filename in filenames:
         parser.parse(filename)
     self.assertEqual(parser.pdus, pdus, filenames)
Example #11
0
 def assert_messages_files(self, filenames: List[str],
                           messages: List[Message]) -> None:
     parser = Parser()
     for filename in filenames:
         parser.parse(filename)
     self.assert_messages(parser.messages, messages)