Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit dd367bec authored by Martin Geisler's avatar Martin Geisler
Browse files

pdl: Derive big-endian test files automatically

This allows us to update just a single file instead of keeping two
files in sync all the time.

Tag: #feature
Bug: 228306436
Test: atest pdl_rust_generator_tests_{le,be} pdl_python_generator_test
Change-Id: Ic8519e3bb07667513c73de07faa7e330836b641e
parent fed8932c
Loading
Loading
Loading
Loading
+37 −4
Original line number Diff line number Diff line
@@ -124,6 +124,39 @@ genrule_defaults {
    ],
}

// The generators support more features for LE packets than for BE
// packets. We use a single input written for LE packets and remove
// the parts that don't work for BE packets. We do this by removing
// everything between
//
// // Start: little_endian_only
//
// and
//
// // End: little_endian_only
//
// from the LE packet input.
genrule_defaults {
    name: "pdl_be_test_file_defaults",
    cmd: "sed -e 's/little_endian_packets/big_endian_packets/' " +
        "     -e '/Start: little_endian_only/,/End: little_endian_only/d' " +
        " < $(in) > $(out)",
}

genrule {
    name: "pdl_be_rust_test_file",
    defaults: ["pdl_be_test_file_defaults"],
    srcs: ["tests/canonical/le_rust_test_file.pdl"],
    out: ["be_rust_test_file.pdl"],
}

genrule {
    name: "pdl_be_test_file",
    defaults: ["pdl_be_test_file_defaults"],
    srcs: ["tests/canonical/le_test_file.pdl"],
    out: ["be_test_file.pdl"],
}

// Generate the Rust parser+serializer backends.
genrule {
    name: "pdl_le_backend",
@@ -135,7 +168,7 @@ genrule {
genrule {
    name: "pdl_be_backend",
    defaults: ["pdl_rust_generator_defaults"],
    srcs: ["tests/canonical/be_rust_test_file.pdl"],
    srcs: [":pdl_be_rust_test_file"],
    out: ["be_backend.rs"],
}

@@ -269,8 +302,8 @@ genrule {
    ],
}

// Generate the python parser+serializer backend for the
// big endian test file located at tests/canonical/be_test_file.pdl.
// Generate the python parser+serializer backend for a big endian test
// file derived from tests/canonical/le_test_file.pdl.
genrule {
    name: "pdl_python_generator_be_test_gen",
    defaults: ["pdl_python_generator_defaults"],
@@ -282,7 +315,7 @@ genrule {
        "tests/custom_types.py",
    ],
    srcs: [
        "tests/canonical/be_test_file.pdl",
        ":pdl_be_test_file",
    ],
    out: [
        "be_pdl_test.py",
+0 −211
Original line number Diff line number Diff line
big_endian_packets

// Preliminary definitions

enum Enum7 : 7 {
    A = 1,
    B = 2,
}

enum Enum16 : 16 {
    A = 0xaabb,
    B = 0xccdd,
}

struct SizedStruct {
    a: 8,
}

struct UnsizedStruct {
    _size_(array): 2,
    _reserved_: 6,
    array: 8[],
}

enum MaxDiscriminantEnum : 64 {
     Max = 0xffffffffffffffff,
}

// Packet bit fields

// The parser must be able to handle bit fields with scalar values
// up to 64 bits wide.  The parser should generate a static size guard.
packet Packet_Scalar_Field {
    a: 7,
    c: 57,
}

// The parser must be able to handle bit fields with enum values
// up to 64 bits wide.  The parser should generate a static size guard.
packet Packet_Enum_Field {
    a: Enum7,
    c: 57,
}

// The parser must be able to handle bit fields with reserved fields
// up to 64 bits wide.  The parser should generate a static size guard.
packet Packet_Reserved_Field {
    a: 7,
    _reserved_: 2,
    c: 55,
}

// The parser must be able to handle bit fields with size fields
// up to 64 bits wide.  The parser should generate a static size guard.
packet Packet_Size_Field {
    _size_(b): 3,
    a: 61,
    b: 8[],
}


// The parser must be able to handle bit fields with count fields
// up to 64 bits wide.  The parser should generate a static size guard.
packet Packet_Count_Field {
    _count_(b): 3,
    a: 61,
    b: 8[],
}

// The parser must be able to handle bit fields with fixed scalar values
// up to 64 bits wide.  The parser should generate a static size guard.
packet Packet_FixedScalar_Field {
    _fixed_ = 7 : 7,
    b: 57,
}

// The parser must be able to handle bit fields with fixed enum values
// up to 64 bits wide. The parser should generate a static size guard.
packet Packet_FixedEnum_Field {
    _fixed_ = A : Enum7,
    b: 57,
}

packet Packet_Array_Field_ByteElement_ConstantSize {
    array: 8[4],
}

packet Packet_Array_Field_ByteElement_UnknownSize {
    array: 8[],
}

packet Packet_Array_Field_ScalarElement_ConstantSize {
    array: 16[4],
}

packet Packet_Array_Field_ScalarElement_UnknownSize {
    array: 16[],
}

packet Packet_Array_Field_EnumElement_ConstantSize {
    array: Enum16[4],
}

packet Packet_Array_Field_EnumElement_UnknownSize {
    array: Enum16[],
}

packet Packet_Array_Field_SizedElement_ConstantSize {
    array: SizedStruct[4],
}

packet Packet_Array_Field_SizedElement_UnknownSize {
    array: SizedStruct[],
}

packet Packet_Array_Field_UnsizedElement_ConstantSize {
    array: UnsizedStruct[4],
}

packet Packet_Array_Field_UnsizedElement_VariableSize {
    _size_(array) : 4,
    _reserved_: 4,
    array: UnsizedStruct[],
}

packet Packet_Array_Field_UnsizedElement_VariableCount {
    _count_(array) : 4,
    _reserved_: 4,
    array: UnsizedStruct[],
}

packet Packet_Array_Field_UnsizedElement_UnknownSize {
    array: UnsizedStruct[],
}

// The parser must be able to handle bit fields with fixed scalar values
// up to 64 bits wide.  The parser should generate a static size guard.
struct Struct_FixedScalar_Field_ {
    _fixed_ = 7 : 7,
    b: 57,
}

// The parser must be able to handle bit fields with fixed enum values
// up to 64 bits wide. The parser should generate a static size guard.
struct Struct_FixedEnum_Field_ {
    _fixed_ = A : Enum7,
    b: 57,
}

packet ScalarParent {
    a: 8,
    _size_(_payload_): 8,
    _payload_
}

packet EnumParent {
    a: Enum16,
    _size_(_payload_): 8,
    _payload_
}

// Packet inheritance

// The parser must handle specialization into
// any child packet of a parent packet with scalar constraints.
packet ScalarChild_A : ScalarParent (a = 0) {
    b: 8,
}

// The parser must handle specialization into
// any child packet of a parent packet with scalar constraints.
packet ScalarChild_B : ScalarParent (a = 1) {
    c: 16,
}

// The parser must handle specialization into
// any child packet of a parent packet with enum constraints.
packet EnumChild_A : EnumParent (a = A) {
    b: 8,
}

// The parser must handle specialization into
// any child packet of a parent packet with enum constraints.
packet EnumChild_B : EnumParent (a = B) {
    c: 16,
}

// Packet payload fields

// The parser must be able to handle sized payload fields without
// size modifier.
packet Packet_Payload_Field_VariableSize {
    _size_(_payload_): 3,
    _reserved_: 5,
    _payload_
}

// The parser must be able to handle payload fields of unkonwn size followed
// by fields of statically known size. The remaining span is integrated
// in the packet.
packet Packet_Payload_Field_UnknownSize {
    _payload_,
    a: 16,
}

// The parser must be able to handle payload fields of unkonwn size.
// The remaining span is integrated in the packet.
packet Packet_Payload_Field_UnknownSize_Terminal {
    a: 16,
    _payload_,
}
+0 −736

File deleted.

Preview size limit exceeded, changes collapsed.

+0 −1
Original line number Diff line number Diff line
@@ -58,7 +58,6 @@ packet Packet_Size_Field {
    b: 8[],
}


// The parser must be able to handle bit fields with count fields
// up to 64 bits wide.  The parser should generate a static size guard.
packet Packet_Count_Field {
+6 −0
Original line number Diff line number Diff line
@@ -50,6 +50,7 @@ packet EmptyParent : ScalarParent {
    _payload_
}

// Start: little_endian_only
packet PartialParent5 {
    a: 5,
    _payload_
@@ -59,6 +60,7 @@ packet PartialParent12 {
    a: 12,
    _payload_
}
// End: little_endian_only

// Packet bit fields

@@ -398,6 +400,8 @@ packet AliasedChild_B : EmptyParent (a = 3) {
    c: 16,
}

// Start: little_endian_only

// The parser must handle inheritance of packets with payloads starting
// on a shifted byte boundary, as long as the first fields of the child
// complete the bit fields.
@@ -426,6 +430,8 @@ packet PartialChild12_B : PartialParent12 (a = 3) {
    e: 20,
}

// End: little_endian_only

// Struct bit fields

// The parser must be able to handle bit fields with scalar values