#include "snapshot/linux/process_reader_linux.h"
#include <dlfcn.h>
#include <elf.h>
#include <errno.h>
#include <link.h>
#include <pthread.h>
#include <sched.h>
#include <stdlib.h>
#include <sys/mman.h>
#include <sys/resource.h>
#include <sys/syscall.h>
#include <unistd.h>
#include <iterator>
#include <map>
#include <memory>
#include <string>
#include <utility>
#include "base/format_macros.h"
#include "base/memory/free_deleter.h"
#include "base/strings/stringprintf.h"
#include "build/build_config.h"
#include "gtest/gtest.h"
#include "snapshot/linux/test_modules.h"
#include "test/errors.h"
#include "test/linux/fake_ptrace_connection.h"
#include "test/linux/get_tls.h"
#include "test/multiprocess.h"
#include "test/scoped_module_handle.h"
#include "test/scoped_set_thread_name.h"
#include "test/test_paths.h"
#include "util/file/file_io.h"
#include "util/file/file_writer.h"
#include "util/file/filesystem.h"
#include "util/linux/direct_ptrace_connection.h"
#include "util/misc/address_sanitizer.h"
#include "util/misc/from_pointer_cast.h"
#include "util/misc/memory_sanitizer.h"
#include "util/posix/scoped_mmap.h"
#include "util/synchronization/semaphore.h"
#if BUILDFLAG(IS_ANDROID)
#include <android/api-level.h>
#include <android/set_abort_message.h>
#include "dlfcn_internal.h"
extern "C" void android_set_abort_message(const char* msg)
__attribute__((weak));
#endif
namespace crashpad {
namespace test {
namespace {
pid_t gettid() { … }
TEST(ProcessReaderLinux, DISABLED_SelfBasic) { … }
constexpr char kTestMemory[] = …;
class BasicChildTest : public Multiprocess { … };
TEST(ProcessReaderLinux, ChildBasic) { … }
class TestThreadPool { … };
ThreadMap;
ThreadNameMap;
void ExpectThreads(const ThreadMap& thread_map,
const ThreadNameMap& thread_name_map,
const std::vector<ProcessReaderLinux::Thread>& threads,
PtraceConnection* connection) { … }
class ChildThreadTest : public Multiprocess { … };
TEST(ProcessReaderLinux, ChildWithThreads) { … }
TEST(ProcessReaderLinux, ChildThreadsWithSmallUserStacks) { … }
class ChildWithSplitStackTest : public Multiprocess { … };
#if defined(ADDRESS_SANITIZER)
#define MAYBE_ChildWithSplitStack …
#else
#define MAYBE_ChildWithSplitStack …
#endif
TEST(ProcessReaderLinux, MAYBE_ChildWithSplitStack) { … }
#if !BUILDFLAG(IS_ANDROID) || !defined(ARCH_CPU_ARMEL) || __ANDROID_API__ >= 21
int ExpectFindModule(dl_phdr_info* info, size_t size, void* data) { … }
#endif
void ExpectModulesFromSelf(
const std::vector<ProcessReaderLinux::Module>& modules) { … }
#if !defined(ADDRESS_SANITIZER) && !defined(MEMORY_SANITIZER)
void ExpectTestModule(ProcessReaderLinux* reader,
const std::string& module_name) { … }
#endif
TEST(ProcessReaderLinux, SelfModules) { … }
class ChildModuleTest : public Multiprocess { … };
TEST(ProcessReaderLinux, ChildModules) { … }
#if BUILDFLAG(IS_ANDROID)
const char kTestAbortMessage[] = "test abort message";
TEST(ProcessReaderLinux, AbortMessage) {
if (!crashpad::internal::Dlsym(RTLD_DEFAULT,
"android_fdsan_close_with_tag")) {
GTEST_SKIP();
}
android_set_abort_message(kTestAbortMessage);
FakePtraceConnection connection;
connection.Initialize(getpid());
ProcessReaderLinux process_reader;
ASSERT_TRUE(process_reader.Initialize(&connection));
EXPECT_EQ(kTestAbortMessage, process_reader.AbortMessage());
}
#endif
}
}
}