Skip to content

Commit

Permalink
Skip or adjust tests to work with PROTOBUF_FORCE_SPLIT.
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 595488861
  • Loading branch information
protobuf-github-bot authored and copybara-github committed Jan 4, 2024
1 parent fd69938 commit 47ecbab
Showing 1 changed file with 75 additions and 0 deletions.
75 changes: 75 additions & 0 deletions src/google/protobuf/compiler/cpp/message_size_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,8 @@ TEST(GeneratedMessageTest, EmptyMessageWithExtensionsSize) {
}

TEST(GeneratedMessageTest, RecursiveMessageSize) {
// TODO: remove once synthetic_pdproto lands.
#ifndef PROTOBUF_FORCE_SPLIT
struct MockGenerated : public MockMessageBase { // 16 bytes
int has_bits[1]; // 4 bytes
int cached_size; // 4 bytes
Expand All @@ -111,6 +113,17 @@ TEST(GeneratedMessageTest, RecursiveMessageSize) {
// + 0-4 bytes padding
};
ABSL_CHECK_MESSAGE_SIZE(MockGenerated, 40);
#else // !PROTOBUF_FORCE_SPLIT
struct MockGenerated : public MockMessageBase { // 16 bytes
int has_bits[1]; // 4 bytes
int cached_size; // 4 bytes
void* split; // 8 bytes
PROTOBUF_TSAN_DECLARE_MEMBER; // 0-4 bytes
// + 0-4 bytes padding
};
ABSL_CHECK_MESSAGE_SIZE(MockGenerated, 32);
#endif // PROTOBUF_FORCE_SPLIT

EXPECT_EQ(sizeof(protobuf_unittest::TestRecursiveMessage),
sizeof(MockGenerated));
}
Expand All @@ -128,13 +141,24 @@ TEST(GeneratedMessageTest, OneStringSize) {
}

TEST(GeneratedMessageTest, MoreStringSize) {
// TODO: remove once synthetic_pdproto lands.
#ifndef PROTOBUF_FORCE_SPLIT
struct MockGenerated : public MockMessageBase { // 16 bytes
int cached_size; // 4 bytes
PROTOBUF_TSAN_DECLARE_MEMBER; // 0-4 bytes
// + 0-4 bytes padding
MockRepeatedPtrField data; // 24 bytes
};
ABSL_CHECK_MESSAGE_SIZE(MockGenerated, 48);
#else // !PROTOBUF_FORCE_SPLIT
struct MockGenerated : public MockMessageBase { // 16 bytes
int cached_size; // 4 bytes
void* split; // 8 bytes
PROTOBUF_TSAN_DECLARE_MEMBER; // 0-4 bytes
// + 0-4 bytes padding
};
ABSL_CHECK_MESSAGE_SIZE(MockGenerated, 32);
#endif // PROTOBUF_FORCE_SPLIT
EXPECT_EQ(sizeof(protobuf_unittest::MoreString), sizeof(MockGenerated));
}

Expand Down Expand Up @@ -188,6 +212,8 @@ TEST(GeneratedMessageTest, OneofSize) {
}

TEST(GeneratedMessageTest, Oneof2Size) {
// TODO: remove once synthetic_pdproto lands.
#ifndef PROTOBUF_FORCE_SPLIT
struct MockGenerated : public MockMessageBase { // 16 bytes
int has_bits[1]; // 4 bytes
int cached_size; // 4 bytes
Expand All @@ -201,10 +227,25 @@ TEST(GeneratedMessageTest, Oneof2Size) {
uint32_t oneof_case[2]; // 8 bytes
};
ABSL_CHECK_MESSAGE_SIZE(MockGenerated, 64);
#else // !PROTOBUF_FORCE_SPLIT
struct MockGenerated : public MockMessageBase { // 16 bytes
int has_bits[1]; // 4 bytes
int cached_size; // 4 bytes
PROTOBUF_TSAN_DECLARE_MEMBER; // 0-4 bytes
// + 0-4 bytes padding
void* split; // 8 bytes
void* foo; // 8 bytes
void* bar; // 8 bytes
uint32_t oneof_case[2]; // 8 bytes
};
ABSL_CHECK_MESSAGE_SIZE(MockGenerated, 56);
#endif // PROTOBUF_FORCE_SPLIT
EXPECT_EQ(sizeof(protobuf_unittest::TestOneof2), sizeof(MockGenerated));
}

TEST(GeneratedMessageTest, FieldOrderingsSize) {
// TODO: remove once synthetic_pdproto lands.
#ifndef PROTOBUF_FORCE_SPLIT
struct MockGenerated : public MockMessageBase { // 16 bytes
int has_bits[1]; // 4 bytes
int cached_size; // 4 bytes
Expand All @@ -217,11 +258,24 @@ TEST(GeneratedMessageTest, FieldOrderingsSize) {
// + 0-4 bytes padding
};
ABSL_CHECK_MESSAGE_SIZE(MockGenerated, 80);
#else // !PROTOBUF_FORCE_SPLIT
struct MockGenerated : public MockMessageBase { // 16 bytes
int has_bits[1]; // 4 bytes
int cached_size; // 4 bytes
MockExtensionSet extensions; // 24 bytes
void* split; // 8 bytes
PROTOBUF_TSAN_DECLARE_MEMBER; // 0-4 bytes
// + 0-4 bytes padding
};
ABSL_CHECK_MESSAGE_SIZE(MockGenerated, 56);
#endif // PROTOBUF_FORCE_SPLIT
EXPECT_EQ(sizeof(protobuf_unittest::TestFieldOrderings), sizeof(MockGenerated));
}

TEST(GeneratedMessageTest, TestMessageSize) {
// We expect the message to contain (not in this order):
// TODO: remove once synthetic_pdproto lands.
#ifndef PROTOBUF_FORCE_SPLIT
struct MockGenerated : public MockMessageBase { // 16 bytes
int has_bits[1]; // 4 bytes
int cached_size; // 4 bytes
Expand All @@ -236,10 +290,22 @@ TEST(GeneratedMessageTest, TestMessageSize) {
int64_t m6; // 8 bytes
};
ABSL_CHECK_MESSAGE_SIZE(MockGenerated, 56);
#else // !PROTOBUF_FORCE_SPLIT
struct MockGenerated : public MockMessageBase { // 16 bytes
int has_bits[1]; // 4 bytes
int cached_size; // 4 bytes
void* split; // 8 bytes
PROTOBUF_TSAN_DECLARE_MEMBER; // 0-4 bytes
// + 0-4 bytes padding
};
ABSL_CHECK_MESSAGE_SIZE(MockGenerated, 32);
#endif // PROTOBUF_FORCE_SPLIT
EXPECT_EQ(sizeof(protobuf_unittest::TestMessageSize), sizeof(MockGenerated));
}

TEST(GeneratedMessageTest, PackedTypesSize) {
// TODO: remove once synthetic_pdproto lands.
#ifndef PROTOBUF_FORCE_SPLIT
struct MockGenerated : public MockMessageBase { // 16 bytes
MockRepeatedField packed_int32; // 16 bytes
int packed_int32_cached_byte_size; // 4 bytes + 4 bytes padding
Expand Down Expand Up @@ -267,6 +333,15 @@ TEST(GeneratedMessageTest, PackedTypesSize) {
// + 0-4 bytes padding
};
ABSL_CHECK_MESSAGE_SIZE(MockGenerated, 16 * 15 + 8 * 6 + 8);
#else // !PROTOBUF_FORCE_SPLIT
struct MockGenerated : public MockMessageBase { // 16 bytes
int cached_size; // 4 bytes + 4 bytes padding
void* split; // 8 bytes
PROTOBUF_TSAN_DECLARE_MEMBER; // 0-4 bytes
// + 0-4 bytes padding
};
ABSL_CHECK_MESSAGE_SIZE(MockGenerated, 32);
#endif // PROTOBUF_FORCE_SPLIT
EXPECT_EQ(sizeof(protobuf_unittest::TestPackedTypes), sizeof(MockGenerated));
}

Expand Down

0 comments on commit 47ecbab

Please sign in to comment.