mincore_ut.cpp 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. #include <library/cpp/testing/unittest/registar.h>
  2. #include "filemap.h"
  3. #include "info.h"
  4. #include "mincore.h"
  5. #include "mlock.h"
  6. #include "tempfile.h"
  7. #include <util/generic/size_literals.h>
  8. Y_UNIT_TEST_SUITE(MincoreSuite) {
  9. static const char* FileName_("./mappped_file");
  10. Y_UNIT_TEST(TestLockAndInCore) {
  11. TVector<char> content(2_MB);
  12. TTempFile cleanup(FileName_);
  13. TFile file(FileName_, CreateAlways | WrOnly);
  14. file.Write(content.data(), content.size());
  15. file.Close();
  16. TFileMap mappedFile(FileName_, TMemoryMapCommon::oRdWr);
  17. mappedFile.Map(0, mappedFile.Length());
  18. UNIT_ASSERT_EQUAL(mappedFile.MappedSize(), content.size());
  19. UNIT_ASSERT_EQUAL(mappedFile.Length(), static_cast<i64>(content.size()));
  20. LockMemory(mappedFile.Ptr(), mappedFile.Length());
  21. TVector<unsigned char> incore(mappedFile.Length() / NSystemInfo::GetPageSize());
  22. InCoreMemory(mappedFile.Ptr(), mappedFile.Length(), incore.data(), incore.size());
  23. // compile and run on all platforms, but assume non-zero results only on Linux
  24. #if defined(_linux_)
  25. for (const auto& flag : incore) {
  26. UNIT_ASSERT(IsPageInCore(flag));
  27. }
  28. #endif
  29. }
  30. } // Y_UNIT_TEST_SUITE(MincoreSuite)