summaryrefslogtreecommitdiff
path: root/tests/malloc_test.cpp
diff options
context:
space:
mode:
authorRyan Savitski <rsavitski@google.com>2018-12-14 15:57:21 +0000
committerRyan Savitski <rsavitski@google.com>2019-01-23 18:30:54 +0000
commitecc37e38771aaf994a97c51104017a7d1b73a568 (patch)
tree2b1a1d908e99eb5181cdaf77e06005a4459dcaa1 /tests/malloc_test.cpp
parent176d2fbcaefe4691b8fd7844f6cec8e7a1a22c76 (diff)
conditional zygote child heap profiling + android_internal_mallopt
On user builds, heapprofd should only be allowed to profile apps that are either debuggable, or profileable (according to the manifest). This change exposes extra zygote-specific knowledge to bionic, and makes the dedicated signal handler check for the special case of being in a zygote child. With this & the corresponding framework change, we should now be handling the 4 combinations of: {java, native} x {profile_at_runtime, profile_at_startup}. See internal go/heapprofd-java-trigger for further context. Test: on-device unit tests (shared & static) on blueline-userdebug. Test: flashed blueline-userdebug, confirmed that java profiling activates from startup and at runtime. Bug: 120409382 Change-Id: Ic251afeca4324dc650ac1d4f46976b526eae692a (cherry picked from commit 998792e2b6e1b84222b5d124f13ecdcb446cb22f) Merged-In: Ic251afeca4324dc650ac1d4f46976b526eae692a
Diffstat (limited to 'tests/malloc_test.cpp')
-rw-r--r--tests/malloc_test.cpp30
1 files changed, 30 insertions, 0 deletions
diff --git a/tests/malloc_test.cpp b/tests/malloc_test.cpp
index 4a012786d..25066915f 100644
--- a/tests/malloc_test.cpp
+++ b/tests/malloc_test.cpp
@@ -25,6 +25,7 @@
#include <tinyxml2.h>
#include "private/bionic_config.h"
+#include "private/bionic_malloc.h"
#include "utils.h"
#if defined(__BIONIC__)
@@ -601,3 +602,32 @@ TEST(malloc, mallinfo) {
GTEST_LOG_(INFO) << "Host glibc does not pass this test, skipping.\n";
#endif
}
+
+TEST(android_mallopt, error_on_unexpected_option) {
+#if defined(__BIONIC__)
+ const int unrecognized_option = -1;
+ errno = 0;
+ EXPECT_EQ(false, android_mallopt(unrecognized_option, nullptr, 0));
+ EXPECT_EQ(ENOTSUP, errno);
+#else
+ GTEST_LOG_(INFO) << "This tests a bionic implementation detail.\n";
+#endif
+}
+
+TEST(android_mallopt, init_zygote_child_profiling) {
+#if defined(__BIONIC__)
+ // Successful call.
+ errno = 0;
+ EXPECT_EQ(true, android_mallopt(M_INIT_ZYGOTE_CHILD_PROFILING, nullptr, 0));
+ EXPECT_EQ(0, errno);
+
+ // Unexpected arguments rejected.
+ errno = 0;
+ char unexpected = 0;
+ EXPECT_EQ(false, android_mallopt(M_INIT_ZYGOTE_CHILD_PROFILING, &unexpected, 1));
+ EXPECT_EQ(EINVAL, errno);
+#else
+ GTEST_LOG_(INFO) << "This tests a bionic implementation detail.\n";
+#endif
+}
+