Port most of crashpad_util_test to Linux/Android

- In the ProcessInfo test, port the global argc/argv getter to Linux by
   reading /proc/self/cmdline.
 - Use <inttypes.h> format macros for 64-bit types.
 - Only #include <sys/sysctl.h> on macOS.
 - #include <signal.h> instead of <sys/signal.h>.

In order to test on Linux/Android, the following changes to the
crashpad_util_test target must be made until more porting is complete:

 - Remove the dependency on crashpad_client because that library has not
   been ported yet.
 - Remove process_info_test.cc because it depends on crashpad_client and
   there is no implementation of ProcessInfo for Linux yet.
 - Remove http_transport_test.cc because there is no HTTPTransport
   implementation for Linux or Android yet.
 - Remove checked_address_range_test.cc because checked_address_range.cc
   does not yet expose a cross-bit usable type for addresses and sizes
   on Linux.

BUG=crashpad:30
TEST=crashpad_util_test

Change-Id: Ic17cf26bdf19b3eff3915bb1acdaa701f28222cd
Reviewed-on: https://chromium-review.googlesource.com/405647
Reviewed-by: Robert Sesek <rsesek@chromium.org>
This commit is contained in:
Mark Mentovai 2016-10-31 15:48:24 -04:00
parent d1aafe78ea
commit b978b03fa1
5 changed files with 38 additions and 8 deletions

View File

@ -14,11 +14,11 @@
#include "util/misc/clock.h"
#include <stdint.h>
#include <sys/types.h>
#include <algorithm>
#include "base/format_macros.h"
#include "base/logging.h"
#include "base/macros.h"
#include "base/strings/stringprintf.h"
@ -85,8 +85,8 @@ TEST(Clock, SleepNanoseconds) {
for (size_t index = 0; index < arraysize(kTestData); ++index) {
const uint64_t nanoseconds = kTestData[index];
SCOPED_TRACE(
base::StringPrintf("index %zu, nanoseconds %llu", index, nanoseconds));
SCOPED_TRACE(base::StringPrintf(
"index %zu, nanoseconds %" PRIu64, index, nanoseconds));
TestSleepNanoseconds(nanoseconds);
}

View File

@ -122,7 +122,7 @@ TEST(CheckedAddressRange, IsValid) {
for (size_t index = 0; index < arraysize(kTestData); ++index) {
const TestData& testcase = kTestData[index];
SCOPED_TRACE(base::StringPrintf("index %" PRIuS
", base 0x%llx, size 0x%llx",
", base 0x%" PRIx64 ", size 0x%" PRIx64,
index,
testcase.base,
testcase.size));
@ -173,7 +173,7 @@ TEST(CheckedAddressRange, ContainsValue) {
for (size_t index = 0; index < arraysize(kTestData); ++index) {
const TestData& testcase = kTestData[index];
SCOPED_TRACE(base::StringPrintf(
"index %" PRIuS ", value 0x%llx", index, testcase.value));
"index %" PRIuS ", value 0x%" PRIx64, index, testcase.value));
EXPECT_EQ(testcase.expectation,
parent_range_32.ContainsValue(testcase.value));
@ -230,7 +230,7 @@ TEST(CheckedAddressRange, ContainsRange) {
for (size_t index = 0; index < arraysize(kTestData); ++index) {
const TestData& testcase = kTestData[index];
SCOPED_TRACE(base::StringPrintf("index %" PRIuS
", base 0x%llx, size 0x%llx",
", base 0x%" PRIx64 ", size 0x%" PRIx64,
index,
testcase.base,
testcase.size));

View File

@ -15,7 +15,6 @@
#ifndef CRASHPAD_UTIL_POSIX_PROCESS_INFO_H_
#define CRASHPAD_UTIL_POSIX_PROCESS_INFO_H_
#include <sys/sysctl.h>
#include <sys/time.h>
#include <sys/types.h>
#include <unistd.h>
@ -30,6 +29,7 @@
#if defined(OS_MACOSX)
#include <mach/mach.h>
#include <sys/sysctl.h>
#endif
namespace crashpad {

View File

@ -15,12 +15,14 @@
#include "util/posix/process_info.h"
#include <time.h>
#include <stdio.h>
#include <unistd.h>
#include <set>
#include <string>
#include <vector>
#include "base/files/scoped_file.h"
#include "build/build_config.h"
#include "gtest/gtest.h"
#include "test/errors.h"
@ -98,6 +100,34 @@ void TestSelfProcess(const ProcessInfo& process_info) {
#if defined(OS_MACOSX)
int expect_argc = *_NSGetArgc();
char** expect_argv = *_NSGetArgv();
#elif defined(OS_LINUX) || defined(OS_ANDROID)
std::vector<std::string> expect_arg_vector;
{
base::ScopedFILE cmdline(fopen("/proc/self/cmdline", "r"));
ASSERT_NE(nullptr, cmdline.get()) << ErrnoMessage("fopen");
int expect_arg_char;
std::string expect_arg_string;
while ((expect_arg_char = fgetc(cmdline.get())) != EOF) {
if (expect_arg_char != '\0') {
expect_arg_string.append(1, expect_arg_char);
} else {
expect_arg_vector.push_back(expect_arg_string);
expect_arg_string.clear();
}
}
ASSERT_EQ(0, ferror(cmdline.get())) << ErrnoMessage("fgetc");
ASSERT_TRUE(expect_arg_string.empty());
}
std::vector<const char*> expect_argv_storage;
for (const std::string& expect_arg_string : expect_arg_vector) {
expect_argv_storage.push_back(expect_arg_string.c_str());
}
int expect_argc = expect_argv_storage.size();
const char* const* expect_argv =
!expect_argv_storage.empty() ? &expect_argv_storage[0] : nullptr;
#else
#error Obtain expect_argc and expect_argv correctly on your system.
#endif

View File

@ -14,7 +14,7 @@
#include "util/posix/symbolic_constants_posix.h"
#include <sys/signal.h>
#include <signal.h>
#include <sys/types.h>
#include "base/macros.h"