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

Commit 810527ed authored by Aka (Chih-Yu) Huang's avatar Aka (Chih-Yu) Huang Committed by Android (Google) Code Review
Browse files

Merge "Merge "Fix rust packet parser test and generator" am: 10aaf084 am:...

Merge "Merge "Fix rust packet parser test and generator" am: 10aaf084 am: 302d0399 am: 88b0d0ea am: dd72e6d6 am: 6a94cf77" into tm-mainline-prod
parents e806e4a1 96590af5
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -3832,6 +3832,10 @@ packet LeSetExtendedAdvertisingEnable : LeAdvertisingCommand (op_code = LE_SET_E
}

test LeSetExtendedAdvertisingEnable {
  "\x39\x20\x06\x01\x01\x01\x00\x00\x00",
}

test LeSetExtendedAdvertisingDisable {
  "\x39\x20\x06\x00\x01\x01\x00\x00\x00",
}

+2 −2
Original line number Diff line number Diff line
@@ -1406,8 +1406,8 @@ void PacketDef::GenRustBuilderTest(std::ostream& s) const {
    }
    for (size_t i = 1; i < lineage.size(); i++) {
      s << "_ => {";
      s << "println!(\"Couldn't parse " << util::CamelCaseToUnderScore(lineage[lineage.size() - i]->name_);
      s << "{:02x?}\", " << util::CamelCaseToUnderScore(lineage[lineage.size() - i - 1]->name_) << "_packet); ";
      s << "panic!(\"Couldn't parse " << util::CamelCaseToUnderScore(lineage[lineage.size() - i]->name_);
      s << "\n {:#02x?}\", " << util::CamelCaseToUnderScore(lineage[lineage.size() - i - 1]->name_) << "_packet); ";
      s << "}}}";
    }

+2 −0
Original line number Diff line number Diff line
@@ -613,6 +613,8 @@ void ParentDef::GenRustConformanceCheck(std::ostream& s) const {
      FixedScalarField::kFieldType,
  });

  s << "if bytes.len() < " << this->GetSize(false).bytes() << " { return false; }";

  for (auto const& field : fields) {
    auto start_offset = GetOffsetForField(field->GetName(), false);
    auto end_offset = GetOffsetForField(field->GetName(), true);
+10 −10
Original line number Diff line number Diff line
@@ -82,27 +82,27 @@ packet SubErr: ErrCommand(op_code = SUB_ERR) {
}

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

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

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

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

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

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


@@ -148,17 +148,17 @@ packet GrandChildThreeY: ChildThree(field_y = FOUR) {
}

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

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

test ChildThree {
  "\x02\x01\x04\x01",
  "\x01\x04\x03\x04\x03\x00\x02\x05",
}

test GrandChildThreeFive {
  "\x01\x02\x03\x01",
  "\x01\x04\x03\x04\x03\x00\x02\x05",
}
+7 −0
Original line number Diff line number Diff line
@@ -98,4 +98,11 @@ pub mod test {
        let res = TestBodySizePacket::parse(&input);
        assert!(res.is_ok());
    }

    #[test]
    fn test_invalid_grand_child_three_five_size() {
        let input = [0x1, 0x4, 0x3, 0x4, 0x3, 0x0, 0x2 /*, 0x5*/];
        let res = GrandParentPacket::parse(&input);
        assert!(res.is_err());
    }
}