Merge "netd: Remove hardcoded PAGE_SIZE usage in netd_test" into main am: 42f17cf688
Original change: https://android-review.googlesource.com/c/platform/system/netd/+/2959167
Change-Id: I40bcd6e2dde888a1788f707fb249bfd6020e0e4f
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
diff --git a/tests/netd_test.cpp b/tests/netd_test.cpp
index a1f222b..0190ed3 100644
--- a/tests/netd_test.cpp
+++ b/tests/netd_test.cpp
@@ -107,11 +107,13 @@
static void nsTest(int flags, bool success, thread_t newThread) {
// We need a minimal stack, but not clear if it will grow up or down,
// So allocate 2 pages and give a pointer to the middle.
- static char stack[PAGE_SIZE * 2];
+ static const size_t kPageSize = getpagesize();
+ static std::vector<char> stack(kPageSize * 2);
+
errno = 0;
// VFORK: if thread is successfully created, then kernel will wait for it
// to terminate before we resume -> hence static stack is safe to reuse.
- int tid = clone(newThread, &stack[PAGE_SIZE], flags | CLONE_VFORK, NULL);
+ int tid = clone(newThread, &stack[kPageSize], flags | CLONE_VFORK, NULL);
if (success) {
ASSERT_EQ(errno, 0);
ASSERT_GE(tid, 0);