ashmem_test: Remove tests that remove read access
Memfds are always readable, and there is no way to restrict them
from being mapped as readable. There is also no known usecase for
which read access needs to be revoked. Therefore, remove tests that
rely on being able to remove read-access to ashmem buffers, since
those will fail when ashmem moves to using memfd.
Bug: 111903542
Change-Id: I9ef7c82f9dcf641b0bad997b7ca3d06f0344fb32
Signed-off-by: Isaac J. Manjarres <isaacmanjarres@google.com>
diff --git a/libcutils/ashmem_test.cpp b/libcutils/ashmem_test.cpp
index e78934f..9876914 100644
--- a/libcutils/ashmem_test.cpp
+++ b/libcutils/ashmem_test.cpp
@@ -187,12 +187,6 @@
ASSERT_NO_FATAL_FAILURE(TestMmap(fd, size, PROT_READ, ®ion));
EXPECT_EQ(0, munmap(region, size));
- ASSERT_NO_FATAL_FAILURE(TestCreateRegion(size, fd, PROT_WRITE));
- TestProtDenied(fd, size, PROT_READ);
- TestProtIs(fd, PROT_WRITE);
- ASSERT_NO_FATAL_FAILURE(TestMmap(fd, size, PROT_WRITE, ®ion));
- EXPECT_EQ(0, munmap(region, size));
-
ASSERT_NO_FATAL_FAILURE(TestCreateRegion(size, fd, PROT_READ | PROT_WRITE));
TestProtIs(fd, PROT_READ | PROT_WRITE);
ASSERT_EQ(0, ashmem_set_prot_region(fd, PROT_READ));
@@ -208,32 +202,29 @@
unique_fd fd;
const size_t size = getpagesize();
- int protFlags[] = { PROT_READ, PROT_WRITE };
- for (size_t i = 0; i < arraysize(protFlags); i++) {
- ASSERT_NO_FATAL_FAILURE(TestCreateRegion(size, fd, PROT_READ | PROT_WRITE));
+ ASSERT_NO_FATAL_FAILURE(TestCreateRegion(size, fd, PROT_READ | PROT_WRITE));
- // This part of the test forks a process via ASSERT_EXIT()
- // and has the child process change the mapping permissions of the
- // buffer.
- //
- // The intent of this is to ensure that updates to the buffer's
- // mapping permissions are visible across processes that reference the
- // buffer.
- //
- // In this case, the parent process attempts to map the buffer with a
- // permission that is denied, which should fail.
- ASSERT_EXIT(
- {
- if (!ashmem_valid(fd)) {
- _exit(3);
- } else if (ashmem_set_prot_region(fd, protFlags[i]) == -1) {
- _exit(1);
- }
- _exit(0);
- },
- ::testing::ExitedWithCode(0), "");
- ASSERT_NO_FATAL_FAILURE(TestProtDenied(fd, size, protFlags[1-i]));
- }
+ // This part of the test forks a process via ASSERT_EXIT()
+ // and has the child process change the mapping permissions of the
+ // buffer to read-only.
+ //
+ // The intent of this is to ensure that updates to the buffer's
+ // mapping permissions are visible across processes that reference the
+ // buffer.
+ //
+ // In this case, the parent process attempts to map the buffer with write
+ // permission, which should fail.
+ ASSERT_EXIT(
+ {
+ if (!ashmem_valid(fd)) {
+ _exit(3);
+ } else if (ashmem_set_prot_region(fd, PROT_READ) == -1) {
+ _exit(1);
+ }
+ _exit(0);
+ },
+ ::testing::ExitedWithCode(0), "");
+ ASSERT_NO_FATAL_FAILURE(TestProtDenied(fd, size, PROT_WRITE));
}
TEST(AshmemTest, ForkMultiRegionTest) {