1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187
|
// Copyright 2024 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "base/android/pre_freeze_background_memory_trimmer.h"
#include <sys/fcntl.h>
#include <sys/mman.h>
#include <sys/utsname.h>
#include <optional>
#include "base/android/self_compaction_manager.h"
#include "base/compiler_specific.h"
#include "base/files/file_util.h"
#include "base/files/scoped_temp_file.h"
#include "base/memory/page_size.h"
#include "base/task/thread_pool.h"
#include "base/test/metrics/histogram_tester.h"
#include "base/test/scoped_feature_list.h"
#include "base/test/task_environment.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace base::android {
namespace {
static int s_counter = 0;
void ResetGlobalCounter() {
s_counter = 0;
}
void IncGlobalCounter() {
s_counter++;
}
void DecGlobalCounter() {
s_counter--;
}
void PostDelayedIncGlobal() {
PreFreezeBackgroundMemoryTrimmer::PostDelayedBackgroundTask(
SingleThreadTaskRunner::GetCurrentDefault(), FROM_HERE,
base::BindRepeating(&IncGlobalCounter), base::Seconds(10));
}
class MockMetric final
: public PreFreezeBackgroundMemoryTrimmer::PreFreezeMetric {
public:
MockMetric() : PreFreezeBackgroundMemoryTrimmer::PreFreezeMetric("Mock") {
count_++;
}
std::optional<uint64_t> Measure() const override { return 0; }
static size_t count_;
~MockMetric() override { count_--; }
};
size_t MockMetric::count_ = 0;
std::optional<const debug::MappedMemoryRegion> GetMappedMemoryRegion(
uintptr_t addr) {
std::vector<debug::MappedMemoryRegion> regions;
std::string proc_maps;
if (!debug::ReadProcMaps(&proc_maps) || !ParseProcMaps(proc_maps, ®ions)) {
return std::nullopt;
}
for (const auto& region : regions) {
if (region.start <= addr && addr < region.end) {
return region;
}
}
return std::nullopt;
}
std::optional<const debug::MappedMemoryRegion> GetMappedMemoryRegion(
void* addr) {
return GetMappedMemoryRegion(reinterpret_cast<uintptr_t>(addr));
}
size_t CountResidentPagesInRange(void* addr, size_t size) {
DCHECK((reinterpret_cast<uintptr_t>(addr) & (base::GetPageSize() - 1)) == 0);
DCHECK(size % base::GetPageSize() == 0);
std::vector<unsigned char> pages(size / base::GetPageSize());
mincore(addr, size, &pages[0]);
size_t tmp = 0;
for (const auto& v : pages) {
tmp += v & 0x01;
}
return tmp;
}
} // namespace
class PreFreezeBackgroundMemoryTrimmerTest : public testing::Test {
public:
void SetUp() override {
PreFreezeBackgroundMemoryTrimmer::SetSupportsModernTrimForTesting(true);
PreFreezeBackgroundMemoryTrimmer::ClearMetricsForTesting();
ResetGlobalCounter();
}
protected:
size_t pending_task_count() {
return PreFreezeBackgroundMemoryTrimmer::Instance()
.GetNumberOfPendingBackgroundTasksForTesting();
}
bool did_register_tasks() {
return PreFreezeBackgroundMemoryTrimmer::Instance()
.DidRegisterTasksForTesting();
}
size_t measurements_count() {
return PreFreezeBackgroundMemoryTrimmer::Instance()
.GetNumberOfKnownMetricsForTesting();
}
size_t values_before_count() {
return PreFreezeBackgroundMemoryTrimmer::Instance()
.GetNumberOfValuesBeforeForTesting();
}
test::TaskEnvironment task_environment_{
base::test::TaskEnvironment::TimeSource::MOCK_TIME};
};
class PreFreezeSelfCompactionTest : public testing::Test {
public:
void SetUp() override { SelfCompactionManager::ResetCompactionForTesting(); }
bool ShouldContinueCompaction(base::TimeTicks compaction_started_at) {
return SelfCompactionManager::Instance().ShouldContinueCompaction(
compaction_started_at);
}
bool CompactionIsSupported() {
return SelfCompactionManager::CompactionIsSupported();
}
std::optional<int64_t> CompactRegion(debug::MappedMemoryRegion region) {
return SelfCompactionManager::CompactRegion(region);
}
// |size| is in bytes.
void* Map(size_t size) {
DCHECK_EQ(size % base::GetPageSize(), 0u);
void* addr = mmap(nullptr, size, PROT_WRITE | PROT_READ,
MAP_PRIVATE | MAP_ANON, -1, 0);
debug::MappedMemoryRegion region;
region.permissions = debug::MappedMemoryRegion::WRITE |
debug::MappedMemoryRegion::READ |
debug::MappedMemoryRegion::PRIVATE;
region.inode = 0;
region.dev_major = 0;
region.dev_minor = 0;
region.start = reinterpret_cast<uintptr_t>(addr);
region.end = region.start + size;
mapped_regions_.push_back(region);
// We memset to guarantee that the memory we just allocated is resident.
UNSAFE_TODO(memset(addr, 02, size));
return addr;
}
virtual std::string GetMetricName(std::string_view name) {
return StrCat({"Memory.SelfCompact2.Renderer.", name});
}
// |addr| must have been allocated using |Map|. |size| is in bytes.
void Unmap(void* addr, size_t size) {
munmap(addr, size);
std::erase_if(mapped_regions_,
[&](const debug::MappedMemoryRegion& region) {
return region.start == reinterpret_cast<uintptr_t>(addr);
});
}
// Returns a copy of the regions that have been allocated via |Map|.
void GetMappedMemoryRegions(
std::vector<debug::MappedMemoryRegion>* regions) const {
*regions = mapped_regions_;
}
test::TaskEnvironment task_environment_{
base::test::TaskEnvironment::TimeSource::MOCK_TIME};
private:
std::vector<debug::MappedMemoryRegion> mapped_regions_;
};
class PreFreezeSelfCompactionTestWithParam
: public PreFreezeSelfCompactionTest,
public testing::WithParamInterface<int> {
public:
std::unique_ptr<SelfCompactionManager::CompactionState> GetState(
const base::TimeTicks& triggered_at) {
auto task_runner = task_environment_.GetMainThreadTaskRunner();
if (UseRunningCompact()) {
return SelfCompactionManager::GetRunningCompactionStateForTesting(
task_runner, triggered_at);
} else {
return SelfCompactionManager::GetSelfCompactionStateForTesting(
task_runner, triggered_at);
}
}
void ExpectTotalCount(std::string_view name, size_t count) {
histograms_.ExpectTotalCount(GetMetricName(name), count);
}
std::string GetMetricName(std::string_view name) override {
if (UseRunningCompact()) {
return StrCat({"Memory.RunningCompact.Renderer.", name});
} else {
return StrCat({"Memory.SelfCompact2.Renderer.", name});
}
}
base::HistogramTester histograms_;
private:
bool UseRunningCompact() {
switch (GetParam()) {
case 0:
return false;
case 1:
return true;
default:
NOTREACHED();
}
}
};
// We do not expect any tasks to be registered with
// PreFreezeBackgroundMemoryTrimmer on Android versions before U.
TEST_F(PreFreezeBackgroundMemoryTrimmerTest, PostTaskPreFreezeUnsupported) {
PreFreezeBackgroundMemoryTrimmer::SetSupportsModernTrimForTesting(false);
ASSERT_FALSE(did_register_tasks());
PreFreezeBackgroundMemoryTrimmer::PostDelayedBackgroundTask(
SingleThreadTaskRunner::GetCurrentDefault(), FROM_HERE,
base::BindRepeating(&IncGlobalCounter), base::Seconds(30));
ASSERT_EQ(pending_task_count(), 0u);
ASSERT_FALSE(did_register_tasks());
task_environment_.FastForwardBy(base::Seconds(30));
ASSERT_EQ(pending_task_count(), 0u);
EXPECT_EQ(s_counter, 1);
}
// TODO(thiabaud): Test that the histograms are recorded too.
TEST_F(PreFreezeBackgroundMemoryTrimmerTest, RegisterMetric) {
ASSERT_EQ(measurements_count(), 0u);
ASSERT_EQ(MockMetric::count_, 0u);
{
MockMetric mock_metric;
PreFreezeBackgroundMemoryTrimmer::RegisterMemoryMetric(&mock_metric);
EXPECT_EQ(MockMetric::count_, 1u);
EXPECT_EQ(measurements_count(), 1u);
PreFreezeBackgroundMemoryTrimmer::UnregisterMemoryMetric(&mock_metric);
// Unregistering does not destroy the metric.
EXPECT_EQ(MockMetric::count_, 1u);
EXPECT_EQ(measurements_count(), 0u);
}
EXPECT_EQ(MockMetric::count_, 0u);
EXPECT_EQ(measurements_count(), 0u);
}
TEST_F(PreFreezeBackgroundMemoryTrimmerTest, UnregisterDuringPreFreeze) {
ASSERT_EQ(measurements_count(), 0u);
ASSERT_EQ(MockMetric::count_, 0u);
{
MockMetric mock_metric;
PreFreezeBackgroundMemoryTrimmer::RegisterMemoryMetric(&mock_metric);
EXPECT_EQ(MockMetric::count_, 1u);
EXPECT_EQ(measurements_count(), 1u);
// This posts a metrics task.
PreFreezeBackgroundMemoryTrimmer::OnPreFreezeForTesting();
EXPECT_EQ(measurements_count(), 1u);
EXPECT_EQ(values_before_count(), 1u);
PreFreezeBackgroundMemoryTrimmer::UnregisterMemoryMetric(&mock_metric);
// Unregistering does not destroy the metric, but does remove its value
// from |before_values_|.
EXPECT_EQ(MockMetric::count_, 1u);
EXPECT_EQ(measurements_count(), 0u);
EXPECT_EQ(values_before_count(), 0u);
}
EXPECT_EQ(MockMetric::count_, 0u);
EXPECT_EQ(measurements_count(), 0u);
EXPECT_EQ(values_before_count(), 0u);
}
TEST_F(PreFreezeBackgroundMemoryTrimmerTest, PostDelayedTaskSimple) {
PreFreezeBackgroundMemoryTrimmer::PostDelayedBackgroundTask(
SingleThreadTaskRunner::GetCurrentDefault(), FROM_HERE,
base::BindRepeating(&IncGlobalCounter), base::Seconds(30));
ASSERT_TRUE(did_register_tasks());
ASSERT_EQ(pending_task_count(), 1u);
task_environment_.FastForwardBy(base::Seconds(30));
ASSERT_EQ(pending_task_count(), 0u);
EXPECT_EQ(s_counter, 1);
}
TEST_F(PreFreezeBackgroundMemoryTrimmerTest, PostDelayedTaskMultiple) {
PreFreezeBackgroundMemoryTrimmer::PostDelayedBackgroundTask(
SingleThreadTaskRunner::GetCurrentDefault(), FROM_HERE,
base::BindRepeating(&IncGlobalCounter), base::Seconds(40));
PreFreezeBackgroundMemoryTrimmer::PostDelayedBackgroundTask(
SingleThreadTaskRunner::GetCurrentDefault(), FROM_HERE,
base::BindRepeating(&IncGlobalCounter), base::Seconds(30));
ASSERT_EQ(pending_task_count(), 2u);
task_environment_.FastForwardBy(base::Seconds(30));
ASSERT_EQ(pending_task_count(), 1u);
EXPECT_EQ(s_counter, 1);
task_environment_.FastForwardBy(base::Seconds(10));
ASSERT_EQ(pending_task_count(), 0u);
EXPECT_EQ(s_counter, 2);
}
TEST_F(PreFreezeBackgroundMemoryTrimmerTest, PostDelayedTaskPreFreeze) {
PreFreezeBackgroundMemoryTrimmer::PostDelayedBackgroundTask(
SingleThreadTaskRunner::GetCurrentDefault(), FROM_HERE,
base::BindRepeating(&IncGlobalCounter), base::Seconds(60));
ASSERT_EQ(pending_task_count(), 1u);
task_environment_.FastForwardBy(base::Seconds(30));
PreFreezeBackgroundMemoryTrimmer::OnPreFreezeForTesting();
ASSERT_EQ(pending_task_count(), 0u);
EXPECT_EQ(s_counter, 1);
}
TEST_F(PreFreezeBackgroundMemoryTrimmerTest, PostDelayedTaskMultiThreaded) {
base::WaitableEvent event1(base::WaitableEvent::ResetPolicy::MANUAL,
base::WaitableEvent::InitialState::NOT_SIGNALED);
base::WaitableEvent event2(base::WaitableEvent::ResetPolicy::MANUAL,
base::WaitableEvent::InitialState::NOT_SIGNALED);
auto task_runner =
base::ThreadPool::CreateSequencedTaskRunner({base::MayBlock()});
ASSERT_FALSE(task_runner->RunsTasksInCurrentSequence());
task_runner->PostTask(
FROM_HERE,
base::BindOnce(
[](scoped_refptr<base::SequencedTaskRunner> task_runner,
base::WaitableEvent* event1, base::WaitableEvent* event2) {
PreFreezeBackgroundMemoryTrimmer::PostDelayedBackgroundTask(
task_runner, FROM_HERE,
base::BindOnce(
[](base::WaitableEvent* event) {
IncGlobalCounter();
event->Signal();
},
base::Unretained(event2)),
base::Seconds(30));
event1->Signal();
},
task_runner, base::Unretained(&event1), base::Unretained(&event2)));
task_environment_.FastForwardBy(base::Seconds(1));
event1.Wait();
ASSERT_EQ(pending_task_count(), 1u);
PreFreezeBackgroundMemoryTrimmer::OnPreFreezeForTesting();
event2.Wait();
ASSERT_EQ(pending_task_count(), 0u);
EXPECT_EQ(s_counter, 1);
}
TEST_F(PreFreezeBackgroundMemoryTrimmerTest,
PostDelayedTaskBeforeAndAfterPreFreeze) {
PreFreezeBackgroundMemoryTrimmer::PostDelayedBackgroundTask(
SingleThreadTaskRunner::GetCurrentDefault(), FROM_HERE,
base::BindRepeating(&IncGlobalCounter), base::Seconds(60));
PreFreezeBackgroundMemoryTrimmer::PostDelayedBackgroundTask(
SingleThreadTaskRunner::GetCurrentDefault(), FROM_HERE,
base::BindRepeating(&IncGlobalCounter), base::Seconds(30));
ASSERT_EQ(pending_task_count(), 2u);
task_environment_.FastForwardBy(base::Seconds(30));
ASSERT_EQ(pending_task_count(), 1u);
EXPECT_EQ(s_counter, 1);
PreFreezeBackgroundMemoryTrimmer::OnPreFreezeForTesting();
ASSERT_EQ(pending_task_count(), 0u);
EXPECT_EQ(s_counter, 2);
}
TEST_F(PreFreezeBackgroundMemoryTrimmerTest, AddDuringPreFreeze) {
PreFreezeBackgroundMemoryTrimmer::PostDelayedBackgroundTask(
SingleThreadTaskRunner::GetCurrentDefault(), FROM_HERE,
base::BindRepeating(&PostDelayedIncGlobal), base::Seconds(10));
ASSERT_EQ(pending_task_count(), 1u);
PreFreezeBackgroundMemoryTrimmer::OnPreFreezeForTesting();
ASSERT_EQ(pending_task_count(), 1u);
EXPECT_EQ(s_counter, 0);
// Fast forward to run the metrics task.
task_environment_.FastForwardBy(base::Seconds(2));
PreFreezeBackgroundMemoryTrimmer::OnPreFreezeForTesting();
ASSERT_EQ(pending_task_count(), 0u);
EXPECT_EQ(s_counter, 1);
}
TEST_F(PreFreezeBackgroundMemoryTrimmerTest, AddDuringPreFreezeRunNormally) {
PreFreezeBackgroundMemoryTrimmer::PostDelayedBackgroundTask(
SingleThreadTaskRunner::GetCurrentDefault(), FROM_HERE,
base::BindRepeating(&PostDelayedIncGlobal), base::Seconds(10));
ASSERT_EQ(pending_task_count(), 1u);
PreFreezeBackgroundMemoryTrimmer::OnPreFreezeForTesting();
ASSERT_EQ(pending_task_count(), 1u);
EXPECT_EQ(s_counter, 0);
task_environment_.FastForwardBy(base::Seconds(30));
ASSERT_EQ(pending_task_count(), 0u);
EXPECT_EQ(s_counter, 1);
}
TEST_F(PreFreezeBackgroundMemoryTrimmerTest, TimerNeverStarted) {
OneShotDelayedBackgroundTimer timer;
ASSERT_EQ(pending_task_count(), 0u);
ASSERT_FALSE(timer.IsRunning());
task_environment_.FastForwardBy(base::Seconds(30));
ASSERT_EQ(pending_task_count(), 0u);
ASSERT_FALSE(timer.IsRunning());
ASSERT_FALSE(did_register_tasks());
EXPECT_EQ(s_counter, 0);
}
TEST_F(PreFreezeBackgroundMemoryTrimmerTest, TimerFastForward) {
OneShotDelayedBackgroundTimer timer;
ASSERT_EQ(pending_task_count(), 0u);
ASSERT_FALSE(timer.IsRunning());
ASSERT_FALSE(did_register_tasks());
timer.Start(FROM_HERE, base::Seconds(30), base::BindOnce(&IncGlobalCounter));
ASSERT_EQ(pending_task_count(), 1u);
ASSERT_TRUE(timer.IsRunning());
ASSERT_TRUE(did_register_tasks());
task_environment_.FastForwardBy(base::Seconds(30));
ASSERT_EQ(pending_task_count(), 0u);
ASSERT_FALSE(timer.IsRunning());
EXPECT_EQ(s_counter, 1);
}
TEST_F(PreFreezeBackgroundMemoryTrimmerTest, TimerOnPreFreeze) {
OneShotDelayedBackgroundTimer timer;
ASSERT_EQ(pending_task_count(), 0u);
ASSERT_FALSE(timer.IsRunning());
ASSERT_FALSE(did_register_tasks());
timer.Start(FROM_HERE, base::Seconds(30), base::BindOnce(&IncGlobalCounter));
ASSERT_EQ(pending_task_count(), 1u);
ASSERT_TRUE(timer.IsRunning());
ASSERT_TRUE(did_register_tasks());
PreFreezeBackgroundMemoryTrimmer::OnPreFreezeForTesting();
ASSERT_EQ(pending_task_count(), 0u);
ASSERT_FALSE(timer.IsRunning());
EXPECT_EQ(s_counter, 1);
}
TEST_F(PreFreezeBackgroundMemoryTrimmerTest, TimerStopSingle) {
OneShotDelayedBackgroundTimer timer;
ASSERT_EQ(pending_task_count(), 0u);
ASSERT_FALSE(timer.IsRunning());
ASSERT_FALSE(did_register_tasks());
timer.Start(FROM_HERE, base::Seconds(30), base::BindOnce(&IncGlobalCounter));
ASSERT_EQ(pending_task_count(), 1u);
ASSERT_TRUE(timer.IsRunning());
ASSERT_TRUE(did_register_tasks());
timer.Stop();
PreFreezeBackgroundMemoryTrimmer::OnPreFreezeForTesting();
ASSERT_EQ(pending_task_count(), 0u);
ASSERT_FALSE(timer.IsRunning());
EXPECT_EQ(s_counter, 0);
}
TEST_F(PreFreezeBackgroundMemoryTrimmerTest, TimerStopMultiple) {
OneShotDelayedBackgroundTimer timer;
ASSERT_EQ(pending_task_count(), 0u);
ASSERT_FALSE(timer.IsRunning());
ASSERT_FALSE(did_register_tasks());
timer.Start(FROM_HERE, base::Seconds(30), base::BindOnce(&IncGlobalCounter));
ASSERT_EQ(pending_task_count(), 1u);
ASSERT_TRUE(timer.IsRunning());
ASSERT_TRUE(did_register_tasks());
timer.Stop();
timer.Stop();
PreFreezeBackgroundMemoryTrimmer::OnPreFreezeForTesting();
ASSERT_EQ(pending_task_count(), 0u);
ASSERT_FALSE(timer.IsRunning());
EXPECT_EQ(s_counter, 0);
}
TEST_F(PreFreezeBackgroundMemoryTrimmerTest, TimerDestroyed) {
// Add scope here to destroy timer.
{
OneShotDelayedBackgroundTimer timer;
ASSERT_EQ(pending_task_count(), 0u);
ASSERT_FALSE(timer.IsRunning());
ASSERT_FALSE(did_register_tasks());
timer.Start(FROM_HERE, base::Seconds(30),
base::BindOnce(&IncGlobalCounter));
ASSERT_EQ(pending_task_count(), 1u);
ASSERT_TRUE(timer.IsRunning());
ASSERT_TRUE(did_register_tasks());
}
ASSERT_EQ(pending_task_count(), 0u);
PreFreezeBackgroundMemoryTrimmer::OnPreFreezeForTesting();
ASSERT_EQ(pending_task_count(), 0u);
EXPECT_EQ(s_counter, 0);
}
TEST_F(PreFreezeBackgroundMemoryTrimmerTest, TimerStartedWhileRunning) {
IncGlobalCounter();
ASSERT_EQ(s_counter, 1);
OneShotDelayedBackgroundTimer timer;
ASSERT_EQ(pending_task_count(), 0u);
ASSERT_FALSE(timer.IsRunning());
ASSERT_FALSE(did_register_tasks());
timer.Start(FROM_HERE, base::Seconds(30), base::BindOnce(&IncGlobalCounter));
ASSERT_EQ(pending_task_count(), 1u);
ASSERT_TRUE(timer.IsRunning());
ASSERT_TRUE(did_register_tasks());
timer.Start(FROM_HERE, base::Seconds(10), base::BindOnce(&DecGlobalCounter));
// Previous task was cancelled, so s_counter should still be 1.
ASSERT_EQ(s_counter, 1);
ASSERT_EQ(pending_task_count(), 1u);
ASSERT_TRUE(timer.IsRunning());
ASSERT_TRUE(did_register_tasks());
PreFreezeBackgroundMemoryTrimmer::OnPreFreezeForTesting();
ASSERT_EQ(pending_task_count(), 0u);
ASSERT_FALSE(timer.IsRunning());
ASSERT_TRUE(did_register_tasks());
// Expect 0 here because we decremented it. The incrementing task was
// cancelled when we restarted the experiment.
EXPECT_EQ(s_counter, 0);
}
TEST_F(PreFreezeBackgroundMemoryTrimmerTest, BoolTaskRunDirectly) {
std::optional<MemoryReductionTaskContext> called_task_type = std::nullopt;
PreFreezeBackgroundMemoryTrimmer::PostDelayedBackgroundTask(
SingleThreadTaskRunner::GetCurrentDefault(), FROM_HERE,
base::BindOnce(
[](std::optional<MemoryReductionTaskContext>& called_task_type,
MemoryReductionTaskContext task_type) {
called_task_type = task_type;
},
std::ref(called_task_type)),
base::Seconds(30));
ASSERT_FALSE(called_task_type.has_value());
ASSERT_EQ(pending_task_count(), 1u);
task_environment_.FastForwardBy(base::Seconds(30));
ASSERT_EQ(pending_task_count(), 0u);
EXPECT_EQ(called_task_type.value(),
MemoryReductionTaskContext::kDelayExpired);
}
TEST_F(PreFreezeBackgroundMemoryTrimmerTest, BoolTaskRunFromPreFreeze) {
std::optional<MemoryReductionTaskContext> called_task_type = std::nullopt;
PreFreezeBackgroundMemoryTrimmer::PostDelayedBackgroundTask(
SingleThreadTaskRunner::GetCurrentDefault(), FROM_HERE,
base::BindOnce(
[](std::optional<MemoryReductionTaskContext>& called_task_type,
MemoryReductionTaskContext task_type) {
called_task_type = task_type;
},
std::ref(called_task_type)),
base::Seconds(30));
ASSERT_FALSE(called_task_type.has_value());
ASSERT_EQ(pending_task_count(), 1u);
PreFreezeBackgroundMemoryTrimmer::OnPreFreezeForTesting();
ASSERT_EQ(pending_task_count(), 0u);
EXPECT_EQ(called_task_type.value(), MemoryReductionTaskContext::kProactive);
}
TEST_F(PreFreezeBackgroundMemoryTrimmerTest, TimerBoolTaskRunDirectly) {
OneShotDelayedBackgroundTimer timer;
std::optional<MemoryReductionTaskContext> called_task_type = std::nullopt;
ASSERT_EQ(pending_task_count(), 0u);
ASSERT_FALSE(timer.IsRunning());
timer.Start(
FROM_HERE, base::Seconds(30),
base::BindOnce(
[](std::optional<MemoryReductionTaskContext>& called_task_type,
MemoryReductionTaskContext task_type) {
called_task_type = task_type;
},
std::ref(called_task_type)));
ASSERT_FALSE(called_task_type.has_value());
ASSERT_EQ(pending_task_count(), 1u);
task_environment_.FastForwardBy(base::Seconds(30));
ASSERT_EQ(pending_task_count(), 0u);
EXPECT_EQ(called_task_type.value(),
MemoryReductionTaskContext::kDelayExpired);
}
TEST_F(PreFreezeBackgroundMemoryTrimmerTest, TimerBoolTaskRunFromPreFreeze) {
OneShotDelayedBackgroundTimer timer;
std::optional<MemoryReductionTaskContext> called_task_type = std::nullopt;
ASSERT_EQ(pending_task_count(), 0u);
ASSERT_FALSE(timer.IsRunning());
timer.Start(
FROM_HERE, base::Seconds(30),
base::BindOnce(
[](std::optional<MemoryReductionTaskContext>& called_task_type,
MemoryReductionTaskContext task_type) {
called_task_type = task_type;
},
std::ref(called_task_type)));
ASSERT_FALSE(called_task_type.has_value());
ASSERT_EQ(pending_task_count(), 1u);
PreFreezeBackgroundMemoryTrimmer::OnPreFreezeForTesting();
ASSERT_EQ(pending_task_count(), 0u);
EXPECT_EQ(called_task_type.value(), MemoryReductionTaskContext::kProactive);
}
INSTANTIATE_TEST_SUITE_P(PreFreezeSelfCompactionTestWithParam,
PreFreezeSelfCompactionTestWithParam,
testing::Values(0, 1));
TEST_F(PreFreezeSelfCompactionTest, Simple) {
// MADV_PAGEOUT is only supported starting from Linux 5.4. So, on devices
// don't support it, we bail out early. This is a known problem on some 32
// bit devices.
if (!CompactionIsSupported()) {
GTEST_SKIP() << "No kernel support";
}
const size_t kPageSize = base::GetPageSize();
const size_t kNumPages = 24;
const size_t size = kNumPages * kPageSize;
void* addr = nullptr;
addr = mmap(nullptr, size, PROT_WRITE | PROT_READ, MAP_PRIVATE | MAP_ANON, -1,
0);
ASSERT_NE(addr, MAP_FAILED);
// we touch the memory here to dirty it, so that it is definitely resident.
UNSAFE_TODO(memset((void*)addr, 1, size));
EXPECT_EQ(CountResidentPagesInRange(addr, size), kNumPages);
const auto region = GetMappedMemoryRegion(addr);
ASSERT_TRUE(region);
const auto result = CompactRegion(std::move(*region));
ASSERT_EQ(result, size);
EXPECT_EQ(CountResidentPagesInRange(addr, size), 0u);
munmap(addr, size);
}
TEST_F(PreFreezeSelfCompactionTest, File) {
// MADV_PAGEOUT is only supported starting from Linux 5.4. So, on devices
// don't support it, we bail out early. This is a known problem on some 32
// bit devices.
if (!CompactionIsSupported()) {
GTEST_SKIP() << "No kernel support";
}
const size_t kPageSize = base::GetPageSize();
const size_t kNumPages = 2;
const size_t size = kNumPages * kPageSize;
ScopedTempFile file;
ASSERT_TRUE(file.Create());
int fd = open(file.path().value().c_str(), O_RDWR);
ASSERT_NE(fd, -1);
ASSERT_TRUE(base::WriteFile(file.path(), std::string(size, 1)));
void* addr = nullptr;
addr = mmap(nullptr, size, PROT_WRITE | PROT_READ, MAP_PRIVATE, fd, 0);
ASSERT_NE(addr, MAP_FAILED);
// we touch the memory here to dirty it, so that it is definitely resident.
UNSAFE_TODO(memset((void*)addr, 2, size));
EXPECT_EQ(CountResidentPagesInRange(addr, size), kNumPages);
const auto region = GetMappedMemoryRegion(addr);
ASSERT_TRUE(region);
const auto result = CompactRegion(std::move(*region));
ASSERT_EQ(result, 0);
EXPECT_EQ(CountResidentPagesInRange(addr, size), kNumPages);
munmap(addr, size);
}
TEST_F(PreFreezeSelfCompactionTest, Inaccessible) {
// MADV_PAGEOUT is only supported starting from Linux 5.4. So, on devices
// don't support it, we bail out early. This is a known problem on some 32
// bit devices.
if (!CompactionIsSupported()) {
GTEST_SKIP() << "No kernel support";
}
const size_t kPageSize = base::GetPageSize();
const size_t kNumPages = 2;
const size_t size = kNumPages * kPageSize;
void* addr = nullptr;
addr = mmap(nullptr, size, PROT_NONE, MAP_PRIVATE | MAP_ANON, -1, 0);
ASSERT_NE(addr, MAP_FAILED);
const auto region = GetMappedMemoryRegion(addr);
ASSERT_TRUE(region);
// We expect to not count this region.
const auto result = CompactRegion(std::move(*region));
ASSERT_EQ(result, 0);
munmap(addr, size);
}
TEST_F(PreFreezeSelfCompactionTest, Locked) {
// MADV_PAGEOUT is only supported starting from Linux 5.4. So, on devices
// don't support it, we bail out early. This is a known problem on some 32
// bit devices.
if (!CompactionIsSupported()) {
GTEST_SKIP() << "No kernel support";
}
const size_t kPageSize = base::GetPageSize();
// We use a small number of pages here because Android has a low limit on
// the max locked size allowed (~64 KiB on many devices).
const size_t kNumPages = 2;
const size_t size = kNumPages * kPageSize;
void* addr = nullptr;
addr = mmap(nullptr, size, PROT_WRITE | PROT_READ, MAP_PRIVATE | MAP_ANON, -1,
0);
ASSERT_NE(addr, MAP_FAILED);
ASSERT_EQ(mlock(addr, size), 0);
// we touch the memory here to dirty it, so that it is definitely resident.
UNSAFE_TODO(memset((void*)addr, 1, size));
EXPECT_EQ(CountResidentPagesInRange(addr, size), kNumPages);
const auto region = GetMappedMemoryRegion(addr);
ASSERT_TRUE(region);
const auto result = CompactRegion(std::move(*region));
ASSERT_EQ(result, 0);
EXPECT_EQ(CountResidentPagesInRange(addr, size), kNumPages);
munlock(addr, size);
munmap(addr, size);
}
TEST_F(PreFreezeSelfCompactionTest, SimpleCancel) {
auto triggered_at = base::TimeTicks::Now();
EXPECT_TRUE(ShouldContinueCompaction(triggered_at));
SelfCompactionManager::MaybeCancelCompaction(
SelfCompactionManager::CompactCancellationReason::kPageResumed);
EXPECT_FALSE(ShouldContinueCompaction(triggered_at));
}
TEST_P(PreFreezeSelfCompactionTestWithParam, Cancel) {
// MADV_PAGEOUT is only supported starting from Linux 5.4. So, on devices
// don't support it, we bail out early. This is a known problem on some 32
// bit devices.
if (!CompactionIsSupported()) {
GTEST_SKIP() << "No kernel support";
}
ASSERT_EQ(task_environment_.GetPendingMainThreadTaskCount(), 0u);
std::array<void*, 5> addrs;
for (size_t i = 1; i < 5; i++) {
addrs[i] = Map(i * base::GetPageSize());
ASSERT_NE(addrs[i], MAP_FAILED);
}
// We should not record the metric here, because we are not currently
// running.
SelfCompactionManager::MaybeCancelCompaction(
SelfCompactionManager::CompactCancellationReason::kPageResumed);
// This metric is used for both self compaction and running compaction, with
// the same prefix for both.
histograms_.ExpectTotalCount(
"Memory.RunningOrSelfCompact.Renderer.Cancellation.Reason", 0);
// We want the triggered time to be slightly after the last cancelled time;
// checks for whether we should cancel depend on this.
task_environment_.FastForwardBy(base::Seconds(1));
const auto triggered_at = base::TimeTicks::Now();
auto state = GetState(triggered_at);
GetMappedMemoryRegions(&state->regions_);
ASSERT_EQ(state->regions_.size(), 4u);
{
base::AutoLock locker(PreFreezeBackgroundMemoryTrimmer::lock());
SelfCompactionManager::Instance().compaction_last_triggered_ = triggered_at;
}
SelfCompactionManager::Instance().StartCompaction(std::move(state));
EXPECT_EQ(task_environment_.GetPendingMainThreadTaskCount(), 1u);
task_environment_.FastForwardBy(
task_environment_.NextMainThreadPendingTaskDelay());
EXPECT_EQ(task_environment_.GetPendingMainThreadTaskCount(), 1u);
SelfCompactionManager::MaybeCancelCompaction(
SelfCompactionManager::CompactCancellationReason::kPageResumed);
task_environment_.FastForwardBy(
task_environment_.NextMainThreadPendingTaskDelay());
EXPECT_EQ(task_environment_.GetPendingMainThreadTaskCount(), 0u);
task_environment_.FastForwardBy(base::Seconds(60));
// We should have exactly one metric recorded, the metric telling us we
// cancelled self compaction.
EXPECT_EQ(histograms_.GetTotalCountsForPrefix("Memory.SelfCompact2").size(),
0);
EXPECT_EQ(histograms_.GetTotalCountsForPrefix("Memory.RunningCompact").size(),
0);
histograms_.ExpectTotalCount(
"Memory.RunningOrSelfCompact.Renderer.Cancellation.Reason", 1);
// Still only expect it to be recorded once, because we were not running the
// second time we tried to cancel.
SelfCompactionManager::MaybeCancelCompaction(
SelfCompactionManager::CompactCancellationReason::kPageResumed);
histograms_.ExpectTotalCount(
"Memory.RunningOrSelfCompact.Renderer.Cancellation.Reason", 1);
for (size_t i = 1; i < 5; i++) {
Unmap(addrs[i], i * base::GetPageSize());
}
}
TEST_P(PreFreezeSelfCompactionTestWithParam, TimeoutCancel) {
// MADV_PAGEOUT is only supported starting from Linux 5.4. So, on devices
// don't support it, we bail out early. This is a known problem on some 32
// bit devices.
if (!CompactionIsSupported()) {
GTEST_SKIP() << "No kernel support";
}
ASSERT_EQ(task_environment_.GetPendingMainThreadTaskCount(), 0u);
std::array<void*, 5> addrs;
for (size_t i = 1; i < 5; i++) {
addrs[i] = Map(i * base::GetPageSize());
ASSERT_NE(addrs[i], MAP_FAILED);
}
// This metric is used for both self compaction and running compaction, with
// the same prefix for both.
histograms_.ExpectTotalCount(
"Memory.RunningOrSelfCompact.Renderer.Cancellation.Reason", 0);
const auto triggered_at = base::TimeTicks::Now();
auto state = GetState(triggered_at);
GetMappedMemoryRegions(&state->regions_);
ASSERT_EQ(state->regions_.size(), 4u);
{
base::AutoLock locker(PreFreezeBackgroundMemoryTrimmer::lock());
SelfCompactionManager::Instance().compaction_last_triggered_ = triggered_at;
}
SelfCompactionManager::Instance().StartCompaction(std::move(state));
EXPECT_EQ(task_environment_.GetPendingMainThreadTaskCount(), 1u);
// We should have 4 sections here, based on the sizes mapped above.
// |StartCompaction| doesn't run right away, but rather schedules a task.
// Because of the cancellation, we expect only three tasks to run. The first
// two should compact memory, the last should be cancelled below when we
// advance the clock.
for (size_t i = 0; i < 1; i++) {
EXPECT_EQ(task_environment_.GetPendingMainThreadTaskCount(), 1u);
task_environment_.FastForwardBy(
task_environment_.NextMainThreadPendingTaskDelay());
}
EXPECT_EQ(task_environment_.GetPendingMainThreadTaskCount(), 1u);
// Advance the clock here, to simulate a hang. This will not run any tasks.
task_environment_.AdvanceClock(base::Seconds(10));
task_environment_.RunUntilIdle();
for (size_t i = 1; i < 3; i++) {
size_t len = i * base::GetPageSize();
EXPECT_EQ(CountResidentPagesInRange(addrs[i], len), i);
Unmap(addrs[i], len);
}
for (size_t i = 3; i < 5; i++) {
size_t len = i * base::GetPageSize();
// Compaction is flakey in tests sometimes, so check LE here.
EXPECT_LE(CountResidentPagesInRange(addrs[i], len), i);
Unmap(addrs[i], len);
}
histograms_.ExpectTotalCount(
"Memory.RunningOrSelfCompact.Renderer.Cancellation.Reason", 1);
// Bucket #2 is "Timeout".
EXPECT_THAT(histograms_.GetAllSamples(
"Memory.RunningOrSelfCompact.Renderer.Cancellation.Reason"),
BucketsAre(Bucket(0, 0), Bucket(1, 0), Bucket(2, 1)));
}
TEST_F(PreFreezeSelfCompactionTest, NotCanceled) {
// MADV_PAGEOUT is only supported starting from Linux 5.4. So, on devices
// don't support it, we bail out early. This is a known problem on some 32
// bit devices.
if (!CompactionIsSupported()) {
GTEST_SKIP() << "No kernel support";
}
ASSERT_EQ(task_environment_.GetPendingMainThreadTaskCount(), 0u);
std::array<void*, 5> addrs;
for (size_t i = 1; i < 5; i++) {
size_t len = i * base::GetPageSize();
addrs[i] = Map(len);
ASSERT_NE(addrs[i], MAP_FAILED);
}
base::HistogramTester histograms;
const auto triggered_at = base::TimeTicks::Now();
auto state = SelfCompactionManager::GetSelfCompactionStateForTesting(
task_environment_.GetMainThreadTaskRunner(), triggered_at);
GetMappedMemoryRegions(&state->regions_);
ASSERT_EQ(state->regions_.size(), 4u);
SelfCompactionManager::Instance().StartCompaction(std::move(state));
// We should have 4 sections here, based on the sizes mapped above.
// |StartCompaction| doesn't run right away, but rather schedules a task.
// So, we expect to have 4 tasks to run here.
for (size_t i = 0; i < 4; i++) {
EXPECT_EQ(task_environment_.GetPendingMainThreadTaskCount(), 1u);
task_environment_.FastForwardBy(
task_environment_.NextMainThreadPendingTaskDelay());
}
// Fast forward to run the metrics tasks too.
task_environment_.FastForwardBy(base::Seconds(60));
EXPECT_EQ(task_environment_.GetPendingMainThreadTaskCount(), 0u);
// We check here for the names of each metric we expect to be recorded. We
// can't easily check for the exact values of these metrics unfortunately,
// since they depend on reading /proc/self/smaps_rollup.
for (const auto& name : {"Rss", "Pss", "PssAnon", "PssFile", "SwapPss"}) {
for (const auto& timing :
{"Before", "After", "After1s", "After10s", "After60s"}) {
histograms.ExpectTotalCount(StrCat({GetMetricName(name), ".", timing}),
1);
}
for (const auto& timing :
{"BeforeAfter", "After1s", "After10s", "After60s"}) {
const auto metric = StrCat({GetMetricName(name), ".Diff.", timing});
base::HistogramTester::CountsMap diff_metrics;
diff_metrics[StrCat({metric, ".Increase"})] = 1;
diff_metrics[StrCat({metric, ".Decrease"})] = 1;
EXPECT_THAT(histograms.GetTotalCountsForPrefix(metric),
testing::IsSubsetOf(diff_metrics));
}
}
// We also check that no other histograms (other than the ones expected above)
// were recorded.
EXPECT_EQ(histograms.GetTotalCountsForPrefix(GetMetricName("")).size(), 47);
for (size_t i = 1; i < 5; i++) {
size_t len = i * base::GetPageSize();
EXPECT_EQ(CountResidentPagesInRange(addrs[i], len), 0);
Unmap(addrs[i], len);
}
}
// Test that we still record metrics even when the feature is disabled.
TEST_P(PreFreezeSelfCompactionTestWithParam, Disabled) {
// Although we are not actually compacting anything, the self compaction
// code will exit out before metrics are recorded in the case where compaction
// is not supported.
if (!CompactionIsSupported()) {
GTEST_SKIP() << "No kernel support";
}
base::test::ScopedFeatureList feature_list_;
feature_list_.InitWithFeatures({}, {kShouldFreezeSelf, kUseRunningCompact});
auto triggered_at = base::TimeTicks::Now();
auto state = GetState(triggered_at);
SelfCompactionManager::CompactSelf(std::move(state));
// Run metrics
task_environment_.FastForwardBy(base::Seconds(60));
// We check here for the names of each metric we expect to be recorded. We
// can't easily check for the exact values of these metrics unfortunately,
// since they depend on reading /proc/self/smaps_rollup.
for (const auto& name : {"Rss", "Pss", "PssAnon", "PssFile", "SwapPss"}) {
for (const auto& timing :
{"Before", "After", "After1s", "After10s", "After60s"}) {
histograms_.ExpectTotalCount(StrCat({GetMetricName(name), ".", timing}),
1);
}
for (const auto& timing :
{"BeforeAfter", "After1s", "After10s", "After60s"}) {
const auto metric = StrCat({GetMetricName(name), ".Diff.", timing});
base::HistogramTester::CountsMap diff_metrics;
diff_metrics[StrCat({metric, ".Increase"})] = 1;
diff_metrics[StrCat({metric, ".Decrease"})] = 1;
EXPECT_THAT(histograms_.GetTotalCountsForPrefix(metric),
testing::IsSubsetOf(diff_metrics));
}
}
// We also check that no other histograms (other than the ones expected above)
// were recorded.
EXPECT_EQ(histograms_.GetTotalCountsForPrefix(GetMetricName("")).size(), 48);
}
TEST_F(PreFreezeSelfCompactionTest, OnSelfFreezeCancel) {
base::test::ScopedFeatureList feature_list_;
feature_list_.InitAndEnableFeature(kShouldFreezeSelf);
auto state = SelfCompactionManager::GetSelfCompactionStateForTesting(
task_environment_.GetMainThreadTaskRunner(), TimeTicks::Now());
{
base::AutoLock locker(SelfCompactionManager::lock());
SelfCompactionManager::Instance().OnTriggerCompact(std::move(state));
}
EXPECT_EQ(task_environment_.GetPendingMainThreadTaskCount(), 1u);
// We advance here because |MaybeCancelCompaction| relies on the current
// time to determine cancellation, which will not work correctly with mocked
// time otherwise.
task_environment_.FastForwardBy(base::Seconds(1));
SelfCompactionManager::MaybeCancelCompaction(
SelfCompactionManager::CompactCancellationReason::kPageResumed);
EXPECT_EQ(task_environment_.GetPendingMainThreadTaskCount(), 1u);
task_environment_.FastForwardBy(
task_environment_.NextMainThreadPendingTaskDelay());
EXPECT_EQ(task_environment_.GetPendingMainThreadTaskCount(), 0u);
}
} // namespace base::android
|