Skip to content

Commit 649bc1c

Browse files
Fix test for some 32-bit platforms.
PiperOrigin-RevId: 740373246
1 parent f4072cb commit 649bc1c

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

src/google/protobuf/micro_string_test.cc

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1052,7 +1052,15 @@ TEST(MicroStringTest, MemoryUsageComparison) {
10521052
int64_t this_micro_str_used = micro_str.SpaceUsedExcludingSelfLong();
10531053
int64_t this_arena_str_used = SpaceUsedExcludingSelfLong(arena_str);
10541054
// We expect to always use the same or less memory.
1055-
EXPECT_LE(this_micro_str_used, this_arena_str_used);
1055+
if (sizeof(void*) >= 8) {
1056+
EXPECT_LE(this_micro_str_used, this_arena_str_used);
1057+
} else {
1058+
// Except that in 32-bit platforms we have heap alignment to 4 bytes, but
1059+
// arena alignment is always 8. Take that fact into account by rounding up
1060+
// the ArenaStringPtr use.
1061+
EXPECT_LE(this_micro_str_used,
1062+
ArenaAlignDefault::Ceil(this_arena_str_used));
1063+
}
10561064

10571065
int64_t diff = micro_str_used - arena_str_used;
10581066
int64_t this_diff = this_micro_str_used - this_arena_str_used;

0 commit comments

Comments
 (0)