Skip to content

Commit

Permalink
fuchsia: base_unittests (mostly) compiling
Browse files Browse the repository at this point in the history
Things that are compiled out of base at the moment (without replacements
implemented in this CL): message loop, process control, signal handling
in test runner, and backtraces, all of which will need to be implemented
in Fuchsia-specific ways in subsequent patches, rather than using the
Linux-y/Posix-y ways.

Two functions in trace_event are also stubbed for now, not for any good
reason, just because I'm not sure how to implement them yet, and this
gets things compiling.

BUG=706592

Review-Url: https://codereview.chromium.org/2884353004
Cr-Commit-Position: refs/heads/master@{#472983}
  • Loading branch information
sgraham authored and Commit bot committed May 19, 2017
1 parent c705be4 commit 6ea9ff3
Show file tree
Hide file tree
Showing 13 changed files with 54 additions and 25 deletions.
2 changes: 1 addition & 1 deletion BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -557,7 +557,7 @@ group("gn_all") {
deps +=
[ "//chrome/installer/mini_installer:next_version_mini_installer" ]
}
} else if (!is_android && !is_ios) {
} else if (!is_android && !is_ios && !is_fuchsia) {
deps += [ "//breakpad:symupload($host_toolchain)" ]
}

Expand Down
17 changes: 14 additions & 3 deletions base/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -1105,7 +1105,7 @@ component("base") {
"base_paths_win.h",
]

if (is_linux) {
if (is_linux || is_fuchsia) {
sources += [ "base_paths_posix.cc" ]
}
}
Expand Down Expand Up @@ -1230,6 +1230,17 @@ component("base") {
sources += [ "power_monitor/power_monitor_device_source_chromeos.cc" ]
}

if (is_fuchsia) {
sources -= [
"debug/stack_trace_posix.cc",
"message_loop/message_pump_libevent.cc",
"message_loop/message_pump_libevent.h",
"process/kill_posix.cc",
"process/launch_posix.cc",
"process/process_posix.cc",
]
}

# NaCl.
if (is_nacl) {
# We reset sources_assignment_filter in order to explicitly include
Expand Down Expand Up @@ -1442,7 +1453,7 @@ component("base") {
"winmm.lib",
]
all_dependent_configs += [ ":base_win_linker_flags" ]
} else if (!is_nacl || is_nacl_nonsfi) {
} else if ((!is_nacl && !is_fuchsia) || is_nacl_nonsfi) {
# Non-Windows.
deps += [ "//base/third_party/libevent" ]
}
Expand Down Expand Up @@ -2337,7 +2348,7 @@ test("base_unittests") {
sources -= [ "message_loop/message_pump_glib_unittest.cc" ]
}

if (is_posix && !is_ios) {
if (is_posix && !is_ios && !is_fuchsia) {
sources += [ "message_loop/message_pump_libevent_unittest.cc" ]
deps += [ "//base/third_party/libevent" ]
}
Expand Down
5 changes: 3 additions & 2 deletions base/files/file_enumerator_posix.cc
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,9 @@ bool FileEnumerator::ReadDirectory(std::vector<FileInfo>* entries,
if (!dir)
return false;

#if !defined(OS_LINUX) && !defined(OS_MACOSX) && !defined(OS_BSD) && \
!defined(OS_SOLARIS) && !defined(OS_ANDROID) && !defined(OS_AIX)
#if !defined(OS_LINUX) && !defined(OS_MACOSX) && !defined(OS_BSD) && \
!defined(OS_SOLARIS) && !defined(OS_ANDROID) && !defined(OS_AIX) && \
!defined(OS_FUCHSIA)
#error Port warning: depending on the definition of struct dirent, \
additional space for pathname may be needed
#endif
Expand Down
1 change: 0 additions & 1 deletion base/files/file_util_posix.cc
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/errno.h>
#include <sys/mman.h>
#include <sys/param.h>
#include <sys/stat.h>
Expand Down
12 changes: 7 additions & 5 deletions base/message_loop/message_loop.cc
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,13 @@ MessageLoop::MessagePumpFactory* message_pump_for_ui_factory_ = NULL;

#if defined(OS_IOS)
typedef MessagePumpIOSForIO MessagePumpForIO;
#elif defined(OS_NACL_SFI)
#elif defined(OS_NACL_SFI) || defined(OS_FUCHSIA)
typedef MessagePumpDefault MessagePumpForIO;
#elif defined(OS_POSIX)
typedef MessagePumpLibevent MessagePumpForIO;
#endif

#if !defined(OS_NACL_SFI)
#if !defined(OS_NACL_SFI) && !defined(OS_FUCHSIA)
MessagePumpForIO* ToPumpIO(MessagePump* pump) {
return static_cast<MessagePumpForIO*>(pump);
}
Expand Down Expand Up @@ -170,9 +170,11 @@ std::unique_ptr<MessagePump> MessageLoop::CreateMessagePumpForType(Type type) {

#if defined(OS_IOS) || defined(OS_MACOSX)
#define MESSAGE_PUMP_UI std::unique_ptr<MessagePump>(MessagePumpMac::Create())
#elif defined(OS_NACL) || defined(OS_AIX)
// Currently NaCl doesn't have a UI MessageLoop.
#elif defined(OS_NACL) || defined(OS_AIX) || defined(OS_FUCHSIA)
// Currently NaCl and AIX don't have a UI MessageLoop.
// TODO(abarth): Figure out if we need this.
// TODO(fuchsia): Fuchsia may require one once more UI-level things have been
// ported. See https://crbug.com/706592.
#define MESSAGE_PUMP_UI std::unique_ptr<MessagePump>()
#else
#define MESSAGE_PUMP_UI std::unique_ptr<MessagePump>(new MessagePumpForUI())
Expand Down Expand Up @@ -634,7 +636,7 @@ bool MessageLoopForIO::RegisterJobObject(HANDLE job, IOHandler* handler) {
bool MessageLoopForIO::WaitForIOCompletion(DWORD timeout, IOHandler* filter) {
return ToPumpIO(pump_.get())->WaitForIOCompletion(timeout, filter);
}
#elif defined(OS_POSIX)
#elif defined(OS_POSIX) && !defined(OS_FUCHSIA)
bool MessageLoopForIO::WatchFileDescriptor(int fd,
bool persistent,
Mode mode,
Expand Down
8 changes: 5 additions & 3 deletions base/process/process_metrics.h
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ BASE_EXPORT void SetFdLimit(unsigned int max_descriptors);
#endif // defined(OS_POSIX)

#if defined(OS_WIN) || defined(OS_MACOSX) || defined(OS_LINUX) || \
defined(OS_ANDROID) || defined(OS_AIX)
defined(OS_ANDROID) || defined(OS_AIX) || defined(OS_FUCHSIA)
// Data about system-wide memory consumption. Values are in KB. Available on
// Windows, Mac, Linux, Android and Chrome OS.
//
Expand Down Expand Up @@ -351,7 +351,8 @@ struct BASE_EXPORT SystemMemoryInfoKB {
int swap_free = 0;
#endif

#if defined(OS_ANDROID) || defined(OS_LINUX) || defined(OS_AIX)
#if defined(OS_ANDROID) || defined(OS_LINUX) || defined(OS_AIX) || \
defined(OS_FUCHSIA)
int buffers = 0;
int cached = 0;
int active_anon = 0;
Expand All @@ -365,7 +366,8 @@ struct BASE_EXPORT SystemMemoryInfoKB {
unsigned long pswpin = 0;
unsigned long pswpout = 0;
unsigned long pgmajfault = 0;
#endif // defined(OS_ANDROID) || defined(OS_LINUX) || defined(OS_AIX)
#endif // defined(OS_ANDROID) || defined(OS_LINUX) || defined(OS_AIX) ||
// defined(OS_FUCHSIA)

#if defined(OS_CHROMEOS)
int shmem = 0;
Expand Down
2 changes: 2 additions & 0 deletions base/process/process_metrics_posix.cc
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ static const rlim_t kSystemDefaultMaxFds = 256;
static const rlim_t kSystemDefaultMaxFds = 8192;
#elif defined(OS_FREEBSD)
static const rlim_t kSystemDefaultMaxFds = 8192;
#elif defined(OS_FUCHSIA)
static const rlim_t kSystemDefaultMaxFds = 8192;
#elif defined(OS_NETBSD)
static const rlim_t kSystemDefaultMaxFds = 1024;
#elif defined(OS_OPENBSD)
Expand Down
17 changes: 11 additions & 6 deletions base/test/launcher/test_launcher.cc
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,10 @@ TestLauncherTracer* GetTestLauncherTracer() {
return tracer;
}

#if defined(OS_POSIX)
// TODO(fuchsia): Fuchsia does not have POSIX signals, but equivalent
// functionality will probably be necessary eventually. See
// https://crbug.com/706592.
#if defined(OS_POSIX) && !defined(OS_FUCHSIA)
// Self-pipe that makes it possible to do complex shutdown handling
// outside of the signal handler.
int g_shutdown_pipe[2] = { -1, -1 };
Expand Down Expand Up @@ -170,7 +173,7 @@ void OnShutdownPipeReadable() {
// The signal would normally kill the process, so exit now.
_exit(1);
}
#endif // defined(OS_POSIX)
#endif // defined(OS_POSIX) && !defined(OS_FUCHSIA)

// Parses the environment variable var as an Int32. If it is unset, returns
// true. If it is set, unsets it then converts it to Int32 before
Expand Down Expand Up @@ -524,7 +527,9 @@ bool TestLauncher::Run() {
// original value.
int requested_cycles = cycles_;

#if defined(OS_POSIX)
// TODO(fuchsia): Fuchsia does not have POSIX signals. Something similiar to
// this will likely need to be implemented. See https://crbug.com/706592.
#if defined(OS_POSIX) && !defined(OS_FUCHSIA)
CHECK_EQ(0, pipe(g_shutdown_pipe));

struct sigaction action;
Expand All @@ -538,7 +543,7 @@ bool TestLauncher::Run() {

auto controller = base::FileDescriptorWatcher::WatchReadable(
g_shutdown_pipe[0], base::Bind(&OnShutdownPipeReadable));
#endif // defined(OS_POSIX)
#endif // defined(OS_POSIX) && !defined(OS_FUCHSIA)

// Start the watchdog timer.
watchdog_timer_.Reset();
Expand Down Expand Up @@ -679,9 +684,9 @@ void TestLauncher::OnTestFinished(const TestResult& original_result) {
test_broken_count_);
fflush(stdout);

#if defined(OS_POSIX)
#if defined(OS_POSIX) && !defined(OS_FUCHSIA)
KillSpawnedTestProcesses();
#endif // defined(OS_POSIX)
#endif // defined(OS_POSIX) && !defined(OS_FUCHSIA)

MaybeSaveSummaryAsJSON({"BROKEN_TEST_EARLY_EXIT", kUnreliableResultsTag});

Expand Down
2 changes: 1 addition & 1 deletion base/threading/platform_thread_posix.cc
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ PlatformThreadId PlatformThread::CurrentId() {
return syscall(__NR_gettid);
#elif defined(OS_ANDROID)
return gettid();
#elif defined(OS_SOLARIS) || defined(OS_QNX)
#elif defined(OS_SOLARIS) || defined(OS_QNX) || defined(OS_FUCHSIA)
return pthread_self();
#elif defined(OS_NACL) && defined(__GLIBC__)
return pthread_self();
Expand Down
2 changes: 2 additions & 0 deletions base/trace_event/malloc_dump_provider.cc
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,8 @@ bool MallocDumpProvider::OnMemoryDump(const MemoryDumpArgs& args,
resident_size = main_heap_info.committed_size;
allocated_objects_size = main_heap_info.allocated_size;
allocated_objects_count = main_heap_info.block_count;
#elif defined(OS_FUCHSIA)
// TODO(fuchsia): Port, see https://crbug.com/706592.
#else
struct mallinfo info = mallinfo();
DCHECK_GE(info.arena + info.hblkhd, info.uordblks);
Expand Down
5 changes: 3 additions & 2 deletions base/trace_event/memory_allocator_dump_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -182,8 +182,9 @@ TEST(MemoryAllocatorDumpTest, GetSize) {
EXPECT_EQ(1u, dump->GetSize());
}

// DEATH tests are not supported in Android / iOS.
#if !defined(NDEBUG) && !defined(OS_ANDROID) && !defined(OS_IOS)
// DEATH tests are not supported in Android/iOS/Fuchsia.
#if !defined(NDEBUG) && !defined(OS_ANDROID) && !defined(OS_IOS) && \
!defined(OS_FUCHSIA)
TEST(MemoryAllocatorDumpTest, ForbidDuplicatesDeathTest) {
FakeMemoryAllocatorDumpProvider fmadp;
MemoryDumpArgs dump_args = {MemoryDumpLevelOfDetail::DETAILED};
Expand Down
4 changes: 4 additions & 0 deletions base/trace_event/process_memory_dump.cc
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,10 @@ size_t ProcessMemoryDump::CountResidentBytes(void* start_address,

for (size_t i = 0; i < page_count; i++)
resident_page_count += vec[i].VirtualAttributes.Valid;
#elif defined(OS_FUCHSIA)
// TODO(fuchsia): Port, see https://crbug.com/706592.
ALLOW_UNUSED_LOCAL(chunk_start);
ALLOW_UNUSED_LOCAL(page_count);
#elif defined(OS_POSIX)
int error_counter = 0;
int result = 0;
Expand Down
2 changes: 1 addition & 1 deletion third_party/libxml/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ static_library("libxml") {
"//third_party/zlib",
]

if (is_mac || is_ios || is_android) {
if (is_mac || is_ios || is_android || is_fuchsia) {
# http://www.xmlsoft.org/threads.html says that this is required when using
# libxml from several threads, which can possibly happen in chrome. On
# linux, this is picked up by transitivity from pkg-config output from
Expand Down

0 comments on commit 6ea9ff3

Please sign in to comment.