Merge "libsnapshot: Set compile_multilib to "first"" into main
diff --git a/libcutils/ashmem_test.cpp b/libcutils/ashmem_test.cpp
index ccbb8c9..7abc370 100644
--- a/libcutils/ashmem_test.cpp
+++ b/libcutils/ashmem_test.cpp
@@ -84,6 +84,11 @@
ASSERT_EQ(0, memcmp(region1, data.data(), size));
EXPECT_EQ(0, munmap(region1, size));
+ // This part of the test forks a separate process via ASSERT_EXIT() and
+ // clears the ashmem buffer.
+ //
+ // This is to ensure that updates to the contents of the buffer are visible
+ // across processes with a reference to the buffer.
ASSERT_EXIT(
{
if (!ashmem_valid(fd)) {
@@ -176,26 +181,22 @@
const size_t size = getpagesize();
void *region;
- ASSERT_NO_FATAL_FAILURE(TestCreateRegion(size, fd, PROT_READ));
+ ASSERT_NO_FATAL_FAILURE(TestCreateRegion(size, fd, PROT_READ | PROT_EXEC));
TestProtDenied(fd, size, PROT_WRITE);
- TestProtIs(fd, PROT_READ);
+ TestProtIs(fd, PROT_READ | PROT_EXEC);
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));
+ ASSERT_NO_FATAL_FAILURE(TestCreateRegion(size, fd, PROT_READ | PROT_WRITE |
+ PROT_EXEC));
+ TestProtIs(fd, PROT_READ | PROT_WRITE | PROT_EXEC);
+ ASSERT_EQ(0, ashmem_set_prot_region(fd, PROT_READ | PROT_EXEC));
errno = 0;
- ASSERT_EQ(-1, ashmem_set_prot_region(fd, PROT_READ | PROT_WRITE))
+ ASSERT_EQ(-1, ashmem_set_prot_region(fd, PROT_READ | PROT_WRITE |
+ PROT_EXEC))
<< "kernel shouldn't allow adding protection bits";
EXPECT_EQ(EINVAL, errno);
- TestProtIs(fd, PROT_READ);
+ TestProtIs(fd, PROT_READ | PROT_EXEC);
TestProtDenied(fd, size, PROT_WRITE);
}
@@ -203,22 +204,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_EXIT(
- {
- if (!ashmem_valid(fd)) {
- _exit(3);
- } else if (ashmem_set_prot_region(fd, protFlags[i]) >= 0) {
- _exit(0);
- } else {
- _exit(1);
- }
- },
- ::testing::ExitedWithCode(0), "");
- ASSERT_NO_FATAL_FAILURE(TestProtDenied(fd, size, protFlags[1-i]));
- }
+ 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 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) {
@@ -237,6 +245,13 @@
EXPECT_EQ(0, munmap(region, size));
}
+ // This part of the test creates a child process via ASSERT_EXIT()
+ // that clears each of the ashmem buffers that were created earlier.
+ //
+ // The intent of this is for the parent process to check each region to make
+ // sure that the updates from the child process are visible, thereby showing
+ // that updates across multiple shared buffers are visible across multiple
+ // processes.
ASSERT_EXIT({
for (int i = 0; i < nRegions; i++) {
if (!ashmem_valid(fd[i])) {