Пример #1
0
 def test_type_derivation_spec(self) -> None:
     self.assert_specifications_string(
         """
             package Test is
                type T is mod 256;
                type Foo is
                   message
                      N : T;
                   end message;
                type Bar is new Foo;
             end Test;
         """,
         {
             "Test":
             Specification(
                 ContextSpec([]),
                 PackageSpec(
                     "Test",
                     [
                         ModularInteger("Test.T", Number(256)),
                         MessageSpec("Test.Foo", [Component("N", "T")]),
                         DerivationSpec("Test.Bar", "Foo"),
                     ],
                 ),
             )
         },
     )
Пример #2
0
 def test_context_spec(self) -> None:
     self.assert_specifications(
         [f"{self.testdir}/context.rflx"],
         {
             "Test":
             Specification(ContextSpec(["Foo", "Bar"]),
                           PackageSpec("Test", []))
         },
     )
Пример #3
0
 def test_message_type_spec(self) -> None:
     spec = {
         "Test":
         Specification(
             ContextSpec([]),
             PackageSpec(
                 "Test",
                 [
                     ModularInteger("Test.T", Number(256)),
                     MessageSpec(
                         "Test.PDU",
                         [
                             Component(
                                 "Foo",
                                 "T",
                                 [
                                     Then(
                                         "Bar",
                                         UNDEFINED,
                                         UNDEFINED,
                                         And(
                                             Equal(Length("Foo"),
                                                   Number(1)),
                                             LessEqual(
                                                 Variable("Foo"),
                                                 Number(30, 16)),
                                         ),
                                     ),
                                     Then(
                                         "Baz",
                                         condition=And(
                                             Equal(Length("Foo"),
                                                   Number(1)),
                                             Greater(
                                                 Variable("Foo"),
                                                 Number(30, 16)),
                                         ),
                                     ),
                                 ],
                             ),
                             Component("Bar", "T"),
                             Component("Baz", "T"),
                         ],
                     ),
                     MessageSpec(
                         "Test.Simple_PDU",
                         [Component("Bar", "T"),
                          Component("Baz", "T")]),
                     MessageSpec("Test.Empty_PDU", []),
                 ],
             ),
         )
     }
     self.assert_specifications([f"{self.testdir}/message_type.rflx"], spec)
Пример #4
0
 def test_array_type_spec(self) -> None:
     spec = {
         "Test":
         Specification(
             ContextSpec([]),
             PackageSpec(
                 "Test",
                 [
                     ModularInteger("Test.Byte", Number(256)),
                     Array("Test.Bytes", Reference("Test.Byte")),
                     MessageSpec("Test.Foo", [Component("Byte", "Byte")]),
                     Array("Test.Bar", Reference("Test.Foo")),
                 ],
             ),
         )
     }
     self.assert_specifications([f"{self.testdir}/array_type.rflx"], spec)
Пример #5
0
 def test_integer_type_spec(self) -> None:
     spec = {
         "Test":
         Specification(
             ContextSpec([]),
             PackageSpec(
                 "Test",
                 [
                     RangeInteger("Test.Page_Num", Number(1), Number(2000),
                                  Number(16)),
                     RangeInteger("Test.Line_Size", Number(0), Number(255),
                                  Number(8)),
                     ModularInteger("Test.Byte", Number(256)),
                     ModularInteger("Test.Hash_Index", Number(64)),
                 ],
             ),
         )
     }
     self.assert_specifications([f"{self.testdir}/integer_type.rflx"], spec)
Пример #6
0
 def test_enumeration_type_spec(self) -> None:
     spec = {
         "Test":
         Specification(
             ContextSpec([]),
             PackageSpec(
                 "Test",
                 [
                     Enumeration(
                         "Test.Day",
                         {
                             "Mon": Number(1),
                             "Tue": Number(2),
                             "Wed": Number(3),
                             "Thu": Number(4),
                             "Fri": Number(5),
                             "Sat": Number(6),
                             "Sun": Number(7),
                         },
                         Number(3),
                         False,
                     ),
                     Enumeration("Test.Gender", {
                         "M": Number(0),
                         "F": Number(1)
                     }, Number(1), False),
                     Enumeration(
                         "Test.Priority",
                         {
                             "LOW": Number(1),
                             "MEDIUM": Number(4),
                             "HIGH": Number(7)
                         },
                         Number(3),
                         True,
                     ),
                 ],
             ),
         )
     }
     self.assert_specifications([f"{self.testdir}/enumeration_type.rflx"],
                                spec)
Пример #7
0
    def test_ethernet_spec(self) -> None:
        spec = {
            "Ethernet":
            Specification(
                ContextSpec([]),
                PackageSpec(
                    "Ethernet",
                    [
                        ModularInteger("Ethernet.Address",
                                       Pow(Number(2), Number(48))),
                        RangeInteger(
                            "Ethernet.Type_Length",
                            Number(46),
                            Sub(Pow(Number(2), Number(16)), Number(1)),
                            Number(16),
                        ),
                        RangeInteger("Ethernet.TPID", Number(0x8100, 16),
                                     Number(0x8100, 16), Number(16)),
                        ModularInteger("Ethernet.TCI",
                                       Pow(Number(2), Number(16))),
                        MessageSpec(
                            "Ethernet.Frame",
                            [
                                Component("Destination", "Address"),
                                Component("Source", "Address"),
                                Component(
                                    "Type_Length_TPID",
                                    "Type_Length",
                                    [
                                        Then(
                                            "TPID",
                                            First("Type_Length_TPID"),
                                            UNDEFINED,
                                            Equal(Variable("Type_Length_TPID"),
                                                  Number(33024, 16)),
                                        ),
                                        Then(
                                            "Type_Length",
                                            First("Type_Length_TPID"),
                                            UNDEFINED,
                                            NotEqual(
                                                Variable("Type_Length_TPID"),
                                                Number(33024, 16)),
                                        ),
                                    ],
                                ),
                                Component("TPID", "TPID"),
                                Component("TCI", "TCI"),
                                Component(
                                    "Type_Length",
                                    "Type_Length",
                                    [
                                        Then(
                                            "Payload",
                                            UNDEFINED,
                                            Mul(Variable("Type_Length"),
                                                Number(8)),
                                            LessEqual(Variable("Type_Length"),
                                                      Number(1500)),
                                        ),
                                        Then(
                                            "Payload",
                                            UNDEFINED,
                                            Sub(Last("Message"),
                                                Last("Type_Length")),
                                            GreaterEqual(
                                                Variable("Type_Length"),
                                                Number(1536)),
                                        ),
                                    ],
                                ),
                                Component(
                                    "Payload",
                                    "Payload",
                                    [
                                        Then(
                                            "null",
                                            UNDEFINED,
                                            UNDEFINED,
                                            And(
                                                GreaterEqual(
                                                    Div(
                                                        Length("Payload"),
                                                        Number(8)),
                                                    Number(46)),
                                                LessEqual(
                                                    Div(
                                                        Length("Payload"),
                                                        Number(8)),
                                                    Number(1500)),
                                            ),
                                        )
                                    ],
                                ),
                            ],
                        ),
                    ],
                ),
            )
        }

        self.assert_specifications([f"{self.specdir}/ethernet.rflx"], spec)
Пример #8
0
 def test_package_spec(self) -> None:
     self.assert_specifications(
         [f"{self.testdir}/package.rflx"],
         {"Test": Specification(ContextSpec([]), PackageSpec("Test", []))},
     )