library_prefetcher_unittest.cc 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. // Copyright 2015 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #include "base/android/library_loader/library_prefetcher.h"
  5. #include <stddef.h>
  6. #include <stdint.h>
  7. #include <sys/mman.h>
  8. #include "base/android/library_loader/anchor_functions_buildflags.h"
  9. #include "base/memory/writable_shared_memory_region.h"
  10. #include "build/build_config.h"
  11. #include "testing/gtest/include/gtest/gtest.h"
  12. #if BUILDFLAG(SUPPORTS_CODE_ORDERING)
  13. namespace base {
  14. namespace android {
  15. // Fails with ASAN, crbug.com/570423.
  16. #if !defined(ADDRESS_SANITIZER)
  17. namespace {
  18. const size_t kPageSize = 4096;
  19. } // namespace
  20. // https://crbug.com/1056021 - flaky on Nexus 5.
  21. TEST(NativeLibraryPrefetcherTest, DISABLED_TestPercentageOfResidentCode) {
  22. size_t length = 4 * kPageSize;
  23. auto shared_region = base::WritableSharedMemoryRegion::Create(length);
  24. ASSERT_TRUE(shared_region.IsValid());
  25. auto mapping = shared_region.Map();
  26. ASSERT_TRUE(mapping.IsValid());
  27. void* address = mapping.memory();
  28. size_t start = reinterpret_cast<size_t>(address);
  29. size_t end = start + length;
  30. // Remove everything.
  31. ASSERT_EQ(0, madvise(address, length, MADV_DONTNEED));
  32. EXPECT_EQ(0, NativeLibraryPrefetcher::PercentageOfResidentCode(start, end));
  33. // Get everything back.
  34. ASSERT_EQ(0, mlock(address, length));
  35. EXPECT_EQ(100, NativeLibraryPrefetcher::PercentageOfResidentCode(start, end));
  36. munlock(address, length);
  37. }
  38. #endif // !defined(ADDRESS_SANITIZER)
  39. } // namespace android
  40. } // namespace base
  41. #endif // BUILDFLAG(SUPPORTS_CODE_ORDERING)