[RFC,2/2] selftests: restrictedmem: Add selftest for RMFD_HUGEPAGE
Commit Message
Tests that when RMFD_HUGEPAGE is specified, restrictedmem will be
backed by Transparent HugePages.
Signed-off-by: Ackerley Tng <ackerleytng@google.com>
---
.../restrictedmem_hugepage_test.c | 25 +++++++++++++++++++
1 file changed, 25 insertions(+)
@@ -180,6 +180,31 @@ TEST_F(reset_shmem_enabled, restrictedmem_fstat_shmem_enabled_always)
close(mfd);
}
+TEST(restrictedmem_invalid_flags)
+{
+ int mfd = memfd_restricted(99, NULL);
+
+ ASSERT_EQ(-1, mfd);
+ ASSERT_EQ(EINVAL, errno);
+}
+
+TEST_F(reset_shmem_enabled, restrictedmem_rmfd_hugepage)
+{
+ int mfd = -1;
+ struct stat stat;
+
+ ASSERT_EQ(0, set_shmem_thp_policy("never"));
+
+ mfd = memfd_restricted(RMFD_HUGEPAGE, NULL);
+ ASSERT_NE(-1, mfd);
+
+ ASSERT_EQ(0, fstat(mfd, &stat));
+
+ ASSERT_EQ(stat.st_blksize, get_hpage_pmd_size());
+
+ close(mfd);
+}
+
TEST(restrictedmem_tmpfile_no_mount_path)
{
int mfd = memfd_restricted(RMFD_TMPFILE, NULL);