+TEST(MemoryMapping, Advise) {
+ File f = File::temporary();
+ size_t kPageSize = 4096;
+ size_t size = kPageSize + 10; // unaligned file size
+ PCHECK(ftruncateNoInt(f.fd(), size) == 0) << size;
+
+ MemoryMapping m(File(f.fd()));
+
+ // NOTE: advise crashes on bad input.
+
+ m.advise(MADV_NORMAL, 0, kPageSize);
+ m.advise(MADV_NORMAL, 1, kPageSize);
+ m.advise(MADV_NORMAL, 0, 2);
+ m.advise(MADV_NORMAL, 1, 2);
+
+ m.advise(MADV_NORMAL, kPageSize, 0);
+ m.advise(MADV_NORMAL, kPageSize, 1);
+ m.advise(MADV_NORMAL, kPageSize, size - kPageSize);
+
+ auto off = kPageSize + 1;
+ m.advise(MADV_NORMAL, off, size - off);
+
+ EXPECT_DEATH(m.advise(MADV_NORMAL, off, size - off + 1), "");
+}
+