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

Commit 10aaf084 authored by Treehugger Robot's avatar Treehugger Robot Committed by Gerrit Code Review
Browse files

Merge "Fix rust packet parser test and generator"

parents 3e0b7ad0 0bbd6c7c
Loading
Loading
Loading
Loading
+4 −0
Original line number Original line Diff line number Diff line
@@ -3832,6 +3832,10 @@ packet LeSetExtendedAdvertisingEnable : LeAdvertisingCommand (op_code = LE_SET_E
}
}


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

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


+2 −2
Original line number Original line 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++) {
    for (size_t i = 1; i < lineage.size(); i++) {
      s << "_ => {";
      s << "_ => {";
      s << "println!(\"Couldn't parse " << util::CamelCaseToUnderScore(lineage[lineage.size() - i]->name_);
      s << "panic!(\"Couldn't parse " << util::CamelCaseToUnderScore(lineage[lineage.size() - i]->name_);
      s << "{:02x?}\", " << util::CamelCaseToUnderScore(lineage[lineage.size() - i - 1]->name_) << "_packet); ";
      s << "\n {:#02x?}\", " << util::CamelCaseToUnderScore(lineage[lineage.size() - i - 1]->name_) << "_packet); ";
      s << "}}}";
      s << "}}}";
    }
    }


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


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

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


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


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


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


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


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


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




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


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


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


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


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