Merge "Make bionic tests build for linux_bionic"
diff --git a/linker/linker_config.cpp b/linker/linker_config.cpp
index f6d5072..e036c05 100644
--- a/linker/linker_config.cpp
+++ b/linker/linker_config.cpp
@@ -375,15 +375,6 @@
bool is_asan,
const Config** config,
std::string* error_msg) {
- // TODO(b/38114603) Currently, multiple namespaces does not support ASAN mode
- // where some symbols should be intercepted via LD_PRELOAD; LD_PRELOADed libs
- // are not being preloaded into the linked namespaces other than the default
- // namespace. Until we fix the problem, we temporarily disable ld.config.txt
- // in ASAN mode.
- if (is_asan) {
- return false;
- }
-
g_config.clear();
std::unordered_map<std::string, PropertyValue> property_map;
diff --git a/linker/tests/linker_config_test.cpp b/linker/tests/linker_config_test.cpp
index 87609d0..c6fade9 100644
--- a/linker/tests/linker_config_test.cpp
+++ b/linker/tests/linker_config_test.cpp
@@ -168,7 +168,6 @@
run_linker_config_smoke_test(false);
}
-// TODO(b/38114603) revive this test when ld.config.txt is enabled for ASAN mode
-//TEST(linker_config, asan_smoke) {
-// run_linker_config_smoke_test(true);
-//}
+TEST(linker_config, asan_smoke) {
+ run_linker_config_smoke_test(true);
+}
diff --git a/tests/leak_test.cpp b/tests/leak_test.cpp
index a356640..de08869 100644
--- a/tests/leak_test.cpp
+++ b/tests/leak_test.cpp
@@ -35,20 +35,6 @@
using namespace std::chrono_literals;
-static size_t GetMappingSize() {
- std::vector<map_record> maps;
- if (!Maps::parse_maps(&maps)) {
- err(1, "failed to parse maps");
- }
-
- size_t result = 0;
- for (const map_record& map : maps) {
- result += map.addr_end - map.addr_start;
- }
-
- return result;
-}
-
static void WaitUntilAllExited(pid_t* pids, size_t pid_count) {
// Wait until all children have exited.
bool alive = true;
@@ -70,6 +56,9 @@
class LeakChecker {
public:
LeakChecker() {
+ // Avoid resizing and using memory later.
+ // 64Ki is the default limit on VMAs per process.
+ maps_.reserve(64*1024);
Reset();
}
@@ -87,6 +76,7 @@
private:
size_t previous_size_;
+ std::vector<map_record> maps_;
void Check() {
auto current_size = GetMappingSize();
@@ -94,6 +84,19 @@
FAIL() << "increase in process map size: " << previous_size_ << " -> " << current_size;
}
}
+
+ size_t GetMappingSize() {
+ if (!Maps::parse_maps(&maps_)) {
+ err(1, "failed to parse maps");
+ }
+
+ size_t result = 0;
+ for (const map_record& map : maps_) {
+ result += map.addr_end - map.addr_start;
+ }
+
+ return result;
+ }
};
std::ostream& operator<<(std::ostream& os, const LeakChecker& lc) {
@@ -116,27 +119,24 @@
LeakChecker lc;
for (size_t pass = 0; pass < 2; ++pass) {
+ constexpr int kThreadCount = 100;
+ struct thread_data { pthread_barrier_t* barrier; pid_t* tid; } threads[kThreadCount] = {};
+
pthread_barrier_t barrier;
- constexpr int thread_count = 100;
- ASSERT_EQ(pthread_barrier_init(&barrier, nullptr, thread_count + 1), 0);
+ ASSERT_EQ(pthread_barrier_init(&barrier, nullptr, kThreadCount + 1), 0);
// Start child threads.
- struct thread_data { pthread_barrier_t* barrier; pid_t* tid; };
- pid_t tids[thread_count];
- for (int i = 0; i < thread_count; ++i) {
- thread_data* td = new thread_data{&barrier, &tids[i]};
+ pid_t tids[kThreadCount];
+ for (int i = 0; i < kThreadCount; ++i) {
+ threads[i] = {&barrier, &tids[i]};
const auto thread_function = +[](void* ptr) -> void* {
thread_data* data = static_cast<thread_data*>(ptr);
*data->tid = gettid();
pthread_barrier_wait(data->barrier);
- // Doing this delete allocates new VMAs for jemalloc bookkeeping,
- // but the two-pass nature of this test means we can check that
- // it's a pool rather than an unbounded leak.
- delete data;
return nullptr;
};
pthread_t thread;
- ASSERT_EQ(0, pthread_create(&thread, nullptr, thread_function, td));
+ ASSERT_EQ(0, pthread_create(&thread, nullptr, thread_function, &threads[i]));
ASSERT_EQ(0, pthread_detach(thread));
}
diff --git a/tests/unistd_test.cpp b/tests/unistd_test.cpp
index 8af2263..cd51e1b 100644
--- a/tests/unistd_test.cpp
+++ b/tests/unistd_test.cpp
@@ -784,12 +784,6 @@
EXPECT_GT(_XOPEN_IOV_MAX, 0);
EXPECT_GT(_XOPEN_UNIX, 0);
- // In O, the headers still have -1 (even though all the functionality has
- // been there for a long time). This was fixed in O-DR, but there isn't a
- // separate CTS for O-DR, so we'll accept both.
- EXPECT_TRUE(_POSIX_THREAD_PROCESS_SHARED == -1 ||
- _POSIX_THREAD_PROCESS_SHARED == _POSIX_VERSION);
-
#if defined(__BIONIC__)
// These tests only pass on bionic, as bionic and glibc has different support on these macros.
// Macros like _POSIX_ASYNCHRONOUS_IO are not supported on bionic yet.
diff --git a/tests/utils.h b/tests/utils.h
index 8638850..daf382e 100644
--- a/tests/utils.h
+++ b/tests/utils.h
@@ -71,15 +71,13 @@
class Maps {
public:
static bool parse_maps(std::vector<map_record>* maps) {
- FILE* fp = fopen("/proc/self/maps", "re");
- if (fp == nullptr) {
- return false;
- }
+ maps->clear();
- auto fp_guard = android::base::make_scope_guard([&]() { fclose(fp); });
+ std::unique_ptr<FILE, decltype(&fclose)> fp(fopen("/proc/self/maps", "re"), fclose);
+ if (!fp) return false;
char line[BUFSIZ];
- while (fgets(line, sizeof(line), fp) != nullptr) {
+ while (fgets(line, sizeof(line), fp.get()) != nullptr) {
map_record record;
uint32_t dev_major, dev_minor;
int path_offset;