TEST_F(DlExtRelroSharingTest, VerifyMemorySaving) { if (geteuid() != 0) { GTEST_LOG_(INFO) << "This test must be run as root.\n"; return; } TemporaryFile tf; // Use tf to get an unique filename. ASSERT_NOERROR(close(tf.fd)); ASSERT_NO_FATAL_FAILURE(CreateRelroFile(LIBNAME, tf.filename)); int pipefd[2]; ASSERT_NOERROR(pipe(pipefd)); size_t without_sharing, with_sharing; ASSERT_NO_FATAL_FAILURE(SpawnChildrenAndMeasurePss(LIBNAME, false, &without_sharing)); ASSERT_NO_FATAL_FAILURE(SpawnChildrenAndMeasurePss(LIBNAME, true, &with_sharing)); // We expect the sharing to save at least 10% of the total PSS. In practice // it saves 40%+ for this test. size_t expected_size = without_sharing - (without_sharing/10); EXPECT_LT(with_sharing, expected_size); // Use destructor of tf to close and unlink the file. tf.fd = extinfo_.relro_fd; }
TEST_F(DlExtRelroSharingTest, VerifyMemorySaving) { ASSERT_NO_FATAL_FAILURE(CreateRelroFile(LIBNAME)); int relro_fd = open(relro_file_, O_RDONLY); ASSERT_NOERROR(relro_fd); extinfo_.flags |= ANDROID_DLEXT_USE_RELRO; extinfo_.relro_fd = relro_fd; int pipefd[2]; ASSERT_NOERROR(pipe(pipefd)); size_t without_sharing, with_sharing; ASSERT_NO_FATAL_FAILURE(SpawnChildrenAndMeasurePss(LIBNAME, false, &without_sharing)); ASSERT_NO_FATAL_FAILURE(SpawnChildrenAndMeasurePss(LIBNAME, true, &with_sharing)); // We expect the sharing to save at least 10% of the total PSS. In practice // it saves 40%+ for this test. size_t expected_size = without_sharing - (without_sharing/10); EXPECT_LT(with_sharing, expected_size); }