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

Commit 0a6115c0 authored by Treehugger Robot's avatar Treehugger Robot Committed by Gerrit Code Review
Browse files

Merge "PDL: Add test pdl for rust code generation"

parents 004dc93d 0428ca39
Loading
Loading
Loading
Loading
+30 −0
Original line number Diff line number Diff line
@@ -590,6 +590,36 @@ rust_test_host {
    ],
}

// Generate and run tests of rust pdl parser for tests packets
genrule {
    name: "TestGeneratedPackets_rust",
    tools: [
        "bluetooth_packetgen",
    ],
    cmd: "$(location bluetooth_packetgen) --include=packages/modules/Bluetooth/system/gd --out=$(genDir) $(in) --rust",
    srcs: [
        "packet/parser/test/rust_test_packets.pdl",
    ],
    out: [
        "packet/parser/test/rust_test_packets.rs",
    ],
}

rust_test_host {
    name: "packets_test_rust",
    defaults: ["gd_rust_defaults"],
    srcs: ["rust/packets/test_lib.rs", ":TestGeneratedPackets_rust"],
    test_suites: ["general-tests"],
    edition: "2018",
    proc_macros: ["libnum_derive"],
    rustlibs: [
        "libbytes",
        "libnum_traits",
        "libthiserror",
        "liblog_rust",
    ],
}

// Generates binary schema data to be bundled and source file generated
genrule {
    name: "BluetoothGeneratedDumpsysBinarySchema_bfbs",
+126 −0
Original line number Diff line number Diff line
little_endian_packets

// Test Packets #1
enum OpCode: 8 {
    ADD_ERR = 0,
    SUB_ERR = 1,
    ADD_RES = 2,
    SUB_RES = 3,
    ADD = 4,
    SUB = 5,
}

packet Command {
  op_code : OpCode,
  _size_(_payload_) : 8,
  _payload_,
}

// Packets for interfaces

packet ComputeCommand : Command { _payload_, }
packet ResCommand: Command { _payload_, }
packet ErrCommand: Command { _payload_, }


packet AddRes: ResCommand (op_code = ADD_RES) {
}

packet SubRes: ResCommand (op_code = SUB_RES) {
}

packet AddCommand: ComputeCommand (op_code = ADD) {
}

packet SubCommand: ComputeCommand (op_code = SUB) {
}

packet AddErr: ErrCommand(op_code = ADD_ERR) {
}

packet SubErr: ErrCommand(op_code = SUB_ERR) {
}

test AddRes {
  "\x00\x04\x04\x01\x04\x04",
}

test SubRes {
  "\x01\x04\x04\x01\x04\x04",
}

test AddCommand {
  "\x02\x04\x04\x01\x04\x04",
}

test SubCommand {
  "\x03\x04\x04\x01\x04\x04",
}

test AddErr {
  "\x04\x04\x04\x01\x04\x04",
}

test SubErr {
  "\x05\x04\x04\x01\x04\x04",
}


// Test Packets #2
enum Number : 8 {
  ZERO = 0,
  ONE = 1,
  TWO = 2,
  THREE = 3,
  FOUR = 4,
}

packet GrandParent {
  field_one : Number,
  field_two : Number,
  field_three: Number,
  field_x: Number,
  _payload_,
}

packet Parent : GrandParent {
  field_four: Number,
  field_five: Number,
  field_y: Number,
  _payload_,
}


packet ChildOneTwo: Parent (field_one = ONE, field_two = TWO) {
}

packet ChildThreeFour : Parent (field_one = THREE, field_two = FOUR) {
}

packet ChildThree: Parent(field_three = THREE) {
  _fixed_  = 5 : 8,
}

packet GrandChildThreeFive: ChildThree(field_five = ZERO) {
}

packet GrandChildThreeY: ChildThree(field_y = FOUR) {
}

test ChildOneTwo {
  "\x01\x02\x03\x01",
}

test ChildThreeFour {
  "\x03\x03\x03\x01",
}

test ChildThree {
  "\x02\x01\x04\x01",
}

test GrandChildThreeFive {
  "\x01\x02\x03\x01",
}

+13 −0
Original line number Diff line number Diff line
//! reimport of generated packets (to go away once rust_genrule exists)

#![allow(clippy::all)]
#![allow(unused)]
#![allow(missing_docs)]

pub mod custom_types;

pub mod hci {
    use crate::custom_types::*;

    include!(concat!(env!("OUT_DIR"), "/rust_test_packets.rs"));
}