Skip to content

Commit

Permalink
Debug
Browse files Browse the repository at this point in the history
Build base_unittests hermetically.
b/397476624
  • Loading branch information
y4vor committed Feb 22, 2025
1 parent c633b62 commit 7abdd80
Show file tree
Hide file tree
Showing 15 changed files with 102 additions and 60 deletions.
1 change: 1 addition & 0 deletions .github/config/linux-evergreen.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
],
"targets": [
"base",
"base_unittests",
"nplb"
],
"includes": [
Expand Down
84 changes: 54 additions & 30 deletions base/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -105,15 +105,7 @@ if (is_apple) {
"mac requires mach absolute time ticks")
}

# TODO: b/384652502 - Cobalt: Fix compiler errors building hermetically.
# ../../third_party/libevent/signal.c:43:10: fatal error: 'sys/queue.h' file not found
# #include <sys/queue.h>
# Determines whether libevent should be dep.
if (is_cobalt_hermetic_build) {
dep_libevent = false
} else {
dep_libevent = !is_fuchsia && !is_win && !is_mac && !is_nacl
}
dep_libevent = !is_fuchsia && !is_win && !is_mac && !is_nacl

# Determines whether message_pump_libevent should be used.
use_libevent = dep_libevent && !is_ios
Expand Down Expand Up @@ -1760,15 +1752,12 @@ component("base") {
"debug/proc_maps_linux.cc",
"debug/proc_maps_linux.h",
"files/dir_reader_linux.h",
"files/scoped_file_linux.cc",
"process/internal_linux.cc",
"process/internal_linux.h",
"process/memory_linux.cc",
"process/process_handle_linux.cc",
"process/process_iterator_linux.cc",
"process/process_linux.cc",
"process/process_metrics_linux.cc",
"threading/platform_thread_linux.cc",
"threading/thread_type_delegate.cc",
"threading/thread_type_delegate.h",

Expand All @@ -1789,19 +1778,12 @@ component("base") {
# ../../base/process/process_metrics_posix.cc:119:27: error: invalid use of incomplete type 'mallinfo'
# struct mallinfo minfo = mallinfo();
"process/process_metrics_posix.cc",
"scoped_native_library.cc",
"sync_socket_posix.cc",

# base/posix/unix_domain_socket.cc:91:22: error: implicit conversion loses integer precision:
"posix/unix_domain_socket.cc",
"posix/unix_domain_socket.h",

# SHIM_ALWAYS_EXPORT size_t malloc_usable_size(void* address) __THROW {
# ^
# ../../third_party/musl/include/malloc.h:19:8: note: previous declaration is here
# size_t malloc_usable_size(void *);
"allocator/partition_allocator/shim/allocator_shim_override_cpp_symbols.h",
"allocator/partition_allocator/shim/allocator_shim_override_glibc_weak_symbols.h",
"allocator/partition_allocator/shim/allocator_shim_override_libc_symbols.h",
]
}

Expand Down Expand Up @@ -3568,14 +3550,19 @@ test("base_unittests") {
"//starboard:starboard_group",
"//starboard/common",
]
}
data_deps = [
"//base/test:immediate_crash_test_helper",
"//testing/buildbot/filters:base_unittests_filters",
]
} else {

data_deps = [
"//base/test:immediate_crash_test_helper",
"//base/test:test_child_process",
"//base/test:test_shared_library",
"//testing/buildbot/filters:base_unittests_filters",
]
data_deps = [
"//base/test:immediate_crash_test_helper",
"//base/test:test_child_process",
"//base/test:test_shared_library",
"//testing/buildbot/filters:base_unittests_filters",
]
}

if (is_android && enable_chrome_android_internal) {
data_deps += [ "//clank/build/bot/filters:base_unittests_filters" ]
Expand Down Expand Up @@ -3682,6 +3669,31 @@ test("base_unittests") {
}
}

if (is_starboard) {
sources -= [
"debug/proc_maps_linux_unittest.cc",
"debug/stack_trace_unittest.cc",
"files/file_util_unittest.cc",
"files/scoped_file_linux_unittest.cc",
"immediate_crash_unittest.cc",
"memory/platform_shared_memory_region_unittest.cc",
"metrics/field_trial_unittest.cc",
"native_library_unittest.cc",
"process/process_metrics_unittest.cc",
"process/process_util_unittest.cc",
"process/process_unittest.cc",
"profiler/module_cache_unittest.cc",
"profiler/stack_sampling_profiler_unittest.cc",
"profiler/stack_sampler_unittest.cc",
"sync_socket_unittest.cc",
"system/sys_info_unittest.cc",
"test/launcher/test_launcher_unittest.cc",
"test/launcher/test_results_tracker_unittest.cc",
"test/task_environment_unittest.cc",
"task/thread_pool/thread_pool_impl_unittest.cc",
]
}

if (is_mac) {
sources += [
"allocator/partition_allocator/shim/allocator_interception_mac_unittest.mm",
Expand Down Expand Up @@ -3720,7 +3732,14 @@ test("base_unittests") {
"posix/file_descriptor_shuffle_unittest.cc",
"posix/unix_domain_socket_unittest.cc",
]
if (!is_nacl && !is_apple) {
if (is_starboard) {
sources -= [
"message_loop/fd_watch_controller_posix_unittest.cc",
"files/file_descriptor_watcher_posix_unittest.cc",
"posix/unix_domain_socket_unittest.cc",
]
}
if (!is_nacl && !is_apple && !is_starboard) {
sources += [
"profiler/stack_base_address_posix_unittest.cc",
"profiler/stack_copier_signal_unittest.cc",
Expand Down Expand Up @@ -3898,6 +3917,11 @@ test("base_unittests") {
"allocator/partition_allocator/thread_cache_unittest.cc",
]

if (is_starboard) {
sources -= [
"allocator/partition_allocator/page_allocator_unittest.cc",
]
}
if (use_starscan) {
sources += [
"allocator/partition_allocator/starscan/pcscan_scheduling_unittest.cc",
Expand Down Expand Up @@ -3955,7 +3979,7 @@ test("base_unittests") {
}
}

if (is_fuchsia || is_linux || is_chromeos) {
if (is_fuchsia || (is_linux && !is_starboard) || is_chromeos) {
sources += [
"debug/elf_reader_unittest.cc",
"debug/test_elf_image_builder.cc",
Expand Down Expand Up @@ -4045,7 +4069,7 @@ test("base_unittests") {
[ "//build/config/fuchsia/test/logger.shard.test-cml" ]
}

if (!is_fuchsia && !is_ios) {
if (!is_fuchsia && !is_ios && !is_starboard) {
sources += [ "files/file_locking_unittest.cc" ]
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,12 @@
#endif

#if BUILDFLAG(IS_POSIX)
#if BUILDFLAG(IS_LINUX)
#if BUILDFLAG(IS_LINUX) && !defined(IS_COBALT_HERMETIC_BUILD)
// We need PKEY_DISABLE_WRITE in this file; glibc defines it in sys/mman.h but
// it's actually Linux-specific and other Linux libcs define it in linux/mman.h.
// We have to include both to be sure we get the definition.
#include <linux/mman.h>
#endif // BUILDFLAG(IS_LINUX)
#endif // BUILDFLAG(IS_LINUX) && !defined(IS_COBALT_HERMETIC_BUILD)
#include <sys/mman.h>
#include <sys/resource.h>
#include <sys/time.h>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ namespace allocator_shim::internal {
#if BUILDFLAG(USE_PARTITION_ALLOC_AS_MALLOC)

// Platforms on which we override weak libc symbols.
#if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS)
#if BUILDFLAG(IS_LINUX) && !defined(IS_COBALT_HERMETIC_BUILD) || BUILDFLAG(IS_CHROMEOS)

PA_NOINLINE void FreeForTest(void* data) {
free(data);
Expand Down Expand Up @@ -85,7 +85,7 @@ TEST(PartitionAllocAsMalloc, Mallinfo) {
#endif
}

#endif // BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS)
#endif // BUILDFLAG(IS_LINUX) && !defined(IS_COBALT_HERMETIC_BUILD) || BUILDFLAG(IS_CHROMEOS)

#endif // BUILDFLAG(USE_PARTITION_ALLOC_AS_MALLOC)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -393,14 +393,14 @@ TEST_F(AllocatorShimTest, InterceptLibcSymbols) {
ASSERT_GE(aligned_allocs_intercepted_by_alignment[128], 1u);
ASSERT_GE(aligned_allocs_intercepted_by_size[53], 1u);

#if BUILDFLAG(IS_POSIX) && !BUILDFLAG(IS_ANDROID)
#if BUILDFLAG(IS_POSIX) && !BUILDFLAG(IS_ANDROID) && !defined(IS_COBALT_HERMETIC_BUILD)
void* pvalloc_ptr = pvalloc(67);
ASSERT_NE(nullptr, pvalloc_ptr);
ASSERT_EQ(0u, reinterpret_cast<uintptr_t>(pvalloc_ptr) % kPageSize);
ASSERT_GE(aligned_allocs_intercepted_by_alignment[kPageSize], 1u);
// pvalloc rounds the size up to the next page.
ASSERT_GE(aligned_allocs_intercepted_by_size[kPageSize], 1u);
#endif // BUILDFLAG(IS_POSIX) && !BUILDFLAG(IS_ANDROID)
#endif // BUILDFLAG(IS_POSIX) && !BUILDFLAG(IS_ANDROID) && !defined(IS_COBALT_HERMETIC_BUILD)

#endif // !BUILDFLAG(IS_WIN) && !BUILDFLAG(IS_APPLE)

Expand Down Expand Up @@ -432,10 +432,10 @@ TEST_F(AllocatorShimTest, InterceptLibcSymbols) {
free(memalign_ptr);
ASSERT_GE(frees_intercepted_by_addr[Hash(memalign_ptr)], 1u);

#if BUILDFLAG(IS_POSIX) && !BUILDFLAG(IS_ANDROID)
#if BUILDFLAG(IS_POSIX) && !BUILDFLAG(IS_ANDROID) && !defined(IS_COBALT_HERMETIC_BUILD)
free(pvalloc_ptr);
ASSERT_GE(frees_intercepted_by_addr[Hash(pvalloc_ptr)], 1u);
#endif // BUILDFLAG(IS_POSIX) && !BUILDFLAG(IS_ANDROID)
#endif // BUILDFLAG(IS_POSIX) && !BUILDFLAG(IS_ANDROID) && !defined(IS_COBALT_HERMETIC_BUILD)

#endif // !BUILDFLAG(IS_WIN) && !BUILDFLAG(IS_APPLE)

Expand Down
2 changes: 1 addition & 1 deletion base/base_paths_posix.cc
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ bool PathProviderPosix(int key, FilePath* result) {
switch (key) {
case FILE_EXE:
case FILE_MODULE: { // TODO(evanm): is this correct?
#if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS)
#if BUILDFLAG(IS_LINUX) && !defined(IS_COBALT_HERMETIC_BUILD) || BUILDFLAG(IS_CHROMEOS)
FilePath bin_dir;
if (!ReadSymbolicLink(FilePath(kProcSelfExe), &bin_dir)) {
NOTREACHED() << "Unable to resolve " << kProcSelfExe << ".";
Expand Down
3 changes: 3 additions & 0 deletions base/debug/stack_trace.cc
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,10 @@ void StackTrace::Print() const {
}

void StackTrace::OutputToStream(std::ostream* os) const {
// TODO: (cobalt b/398296821) Use stack_trace_starboard.cc or port stack_trace_posix.cc.
#if !defined(IS_COBALT_HERMETIC_BUILD)
OutputToStreamWithPrefix(os, nullptr);
#endif
}

std::string StackTrace::ToString() const {
Expand Down
6 changes: 3 additions & 3 deletions base/files/file_util_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@
#include <sys/socket.h>
#endif

#if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS)
#if BUILDFLAG(IS_LINUX) && !defined(IS_COBALT_HERMETIC_BUILD) || BUILDFLAG(IS_CHROMEOS)
#include <linux/fs.h>
#endif

Expand Down Expand Up @@ -1912,7 +1912,7 @@ TEST_F(FileUtilTest, DeleteDirRecursiveWithOpenFile) {
File::FLAG_CREATE | File::FLAG_READ | File::FLAG_WRITE);
ASSERT_TRUE(PathExists(file_name3));

#if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS)
#if BUILDFLAG(IS_LINUX) && !defined(IS_COBALT_HERMETIC_BUILD) || BUILDFLAG(IS_CHROMEOS)
// On Windows, holding the file open in sufficient to make it un-deletable.
// The POSIX code is verifiable on Linux by creating an "immutable" file but
// this is best-effort because it's not supported by all file systems. Both
Expand All @@ -1933,7 +1933,7 @@ TEST_F(FileUtilTest, DeleteDirRecursiveWithOpenFile) {
DeletePathRecursively(test_subdir);
EXPECT_FALSE(PathExists(file_name2));

#if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS)
#if BUILDFLAG(IS_LINUX) && !defined(IS_COBALT_HERMETIC_BUILD) || BUILDFLAG(IS_CHROMEOS)
// Make sure that the test can clean up after itself.
if (file_attrs_supported) {
flags &= ~FS_IMMUTABLE_FL;
Expand Down
2 changes: 1 addition & 1 deletion base/files/important_file_writer_cleaner.cc
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ namespace base {
namespace {

base::Time GetUpperBoundTime() {
#if BUILDFLAG(IS_ANDROID) || BUILDFLAG(IS_IOS) || BUILDFLAG(IS_FUCHSIA)
#if BUILDFLAG(IS_ANDROID) || BUILDFLAG(IS_IOS) || BUILDFLAG(IS_FUCHSIA) || defined(IS_COBALT_HERMETIC_BUILD)
// If process creation time is not available then use instance creation
// time as the upper-bound for old files. Modification times may be
// rounded-down to coarse-grained increments, e.g. FAT has 2s granularity,
Expand Down
4 changes: 2 additions & 2 deletions base/process/memory_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ TEST_F(OutOfMemoryDeathTest, SecurityAlignedRealloc) {
#endif // BUILDFLAG(IS_WIN)
#endif // !BUILDFLAG(IS_MAC)

#if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS)
#if BUILDFLAG(IS_LINUX) && !defined(IS_COBALT_HERMETIC_BUILD) || BUILDFLAG(IS_CHROMEOS)

TEST_F(OutOfMemoryDeathTest, Valloc) {
ASSERT_OOM_DEATH({
Expand Down Expand Up @@ -413,7 +413,7 @@ TEST_F(OutOfMemoryDeathTest, ViaSharedLibraries) {
value_ = MallocWrapper(test_size_);
});
}
#endif // BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS)
#endif // BUILDFLAG(IS_LINUX) && !defined(IS_COBALT_HERMETIC_BUILD) || BUILDFLAG(IS_CHROMEOS)

// Android doesn't implement posix_memalign().
#if BUILDFLAG(IS_POSIX) && !BUILDFLAG(IS_ANDROID)
Expand Down
4 changes: 4 additions & 0 deletions base/profiler/module_cache.cc
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ ModuleCache::~ModuleCache() {
}

const ModuleCache::Module* ModuleCache::GetModuleForAddress(uintptr_t address) {
#if defined(IS_COBALT_HERMETIC_BUILD)
return nullptr;
#else
if (const ModuleCache::Module* module = GetExistingModuleForAddress(address))
return module;

Expand All @@ -77,6 +80,7 @@ const ModuleCache::Module* ModuleCache::GetModuleForAddress(uintptr_t address) {
// TODO(https://crbug.com/1131769): Reintroduce DCHECK(result.second) after
// fixing the issue that is causing it to fail.
return result.first->get();
#endif // defined(IS_COBALT_HERMETIC_BUILD)
}

std::vector<const ModuleCache::Module*> ModuleCache::GetModules() const {
Expand Down
30 changes: 17 additions & 13 deletions base/test/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ static_library("test_support") {

if (enable_base_tracing) {
public_deps += [ "//third_party/perfetto:perfetto_test_support" ]
if (!is_chromeos) {
if (!is_chromeos && !is_cobalt_hermetic_build) {
# TODO(rasikan): Add to ios and chromeos when unblocked by the chromiumos
# change to add the shared lib to the chrome-binary-tests directory.
public_deps += [ ":test_trace_processor" ]
Expand Down Expand Up @@ -292,7 +292,7 @@ static_library("test_support") {
]
}

if (use_blink) {
if (use_blink && !is_cobalt_hermetic_build) {
sources += [
"launcher/test_launcher.cc",
"launcher/test_launcher.h",
Expand Down Expand Up @@ -385,12 +385,14 @@ shared_library("immediate_crash_test_helper") {
}
}

# This shared library is dynamically loaded by NativeLibrary unittests.
shared_library("test_shared_library") {
testonly = true
sources = [ "test_shared_library.cc" ]
if (!is_starboard) {
# This shared library is dynamically loaded by NativeLibrary unittests.
shared_library("test_shared_library") {
testonly = true
sources = [ "test_shared_library.cc" ]

deps = [ ":native_library_test_utils" ]
deps = [ ":native_library_test_utils" ]
}
}

if (is_fuchsia || is_linux || is_chromeos) {
Expand Down Expand Up @@ -484,14 +486,16 @@ if (is_ios) {
}
}

# Trivial executable which outputs space-delimited argv to stdout,
# used for testing.
executable("test_child_process") {
testonly = true
sources = [ "test_child_process.cc" ]
if (!is_starboard) {
# Trivial executable which outputs space-delimited argv to stdout,
# used for testing.
executable("test_child_process") {
testonly = true
sources = [ "test_child_process.cc" ]
}
}

if (enable_base_tracing) {
if (enable_base_tracing && !is_cobalt_hermetic_build) {
# We encapsulate the trace processor in a separate shared library to prevent
# any duplicate symbol issues. Perfetto symbols are exported by chromium’s
# base via a public_dep on libperfetto; libtrace_processor also depends on
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 @@ -353,7 +353,7 @@ void PlatformThread::Detach(PlatformThreadHandle thread_handle) {

// static
bool PlatformThread::CanChangeThreadType(ThreadType from, ThreadType to) {
#if BUILDFLAG(IS_NACL)
#if BUILDFLAG(IS_NACL) || defined(IS_COBALT_HERMETIC_BUILD)
return false;
#else
if (from >= to) {
Expand Down
Loading

0 comments on commit 7abdd80

Please sign in to comment.