Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Run all unittests with shared library binaries #4833

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/actions/on_host_tests/action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ runs:
cd "${test_dir}"

for test_binary_path in $(cat out/${{ matrix.platform}}_${{ matrix.config }}/test_targets.json | jq -cr '.executables | join(" ")'); do
test_binary=$(basename "${test_binary_path}")
test_binary=$(basename "${test_binary_path}" _loader)
echo "Running tests for suite: ${test_binary}"

test_filter="*"
Expand Down
16 changes: 1 addition & 15 deletions base/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
# for multiple conditions, prefer to duplicate it in both lists. This makes it
# a bit easier to see which files apply in which cases rather than having a
# huge sequence of random-looking conditionals.

import("//base/allocator/allocator.gni")
import("//base/allocator/partition_allocator/partition_alloc.gni")
import("//base/debug/debug.gni")
Expand Down Expand Up @@ -1792,22 +1791,9 @@ component("base") {
"process/process_metrics_posix.cc",
"sync_socket_posix.cc",

# ../../base/allocator/partition_allocator/shim/allocator_shim_default_dispatch_to_partition_alloc.cc:748:36: error: incomplete result type 'struct mallinfo' in function definition
# SHIM_ALWAYS_EXPORT struct mallinfo mallinfo(void) __THROW {
"allocator/partition_allocator/shim/allocator_shim_default_dispatch_to_partition_alloc.cc",
"allocator/partition_allocator/shim/allocator_shim_default_dispatch_to_partition_alloc.h",

# In file included from ../../base/rand_util_posix.cc:26:
# ../../third_party/lss/linux_syscall_support.h:118:10: fatal error: 'linux/unistd.h' file not found
"base_paths_posix.h",
"memory/madv_free_discardable_memory_allocator_posix.cc",
"memory/madv_free_discardable_memory_allocator_posix.h",
"memory/madv_free_discardable_memory_posix.cc",
"memory/madv_free_discardable_memory_posix.h",
# base/posix/unix_domain_socket.cc:91:22: error: implicit conversion loses integer precision:
"posix/unix_domain_socket.cc",
"posix/unix_domain_socket.h",
"rand_util_posix.cc",
"system/sys_info_posix.cc",

# SHIM_ALWAYS_EXPORT size_t malloc_usable_size(void* address) __THROW {
# ^
Expand Down
4 changes: 0 additions & 4 deletions base/allocator/partition_allocator/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -232,10 +232,6 @@ component("partition_alloc") {
"partition_alloc_base/time/time_conversion_posix.cc",
]

# TODO: b/384652502 - Cobalt: Fix compiler errors building hermetically.
if (is_cobalt && is_cobalt_hermetic_build) {
sources -= [ "partition_alloc_base/rand_util_posix.cc" ]
}

if (is_android || is_chromeos_ash) {
sources += [ "partition_alloc_base/time/time_android.cc" ]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
#include "base/allocator/partition_allocator/partition_alloc_check.h"
#include "build/build_config.h"

#if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS)
#if (BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS)) && !defined(IS_COBALT_HERMETIC_BUILD)
#include "third_party/lss/linux_syscall_support.h"
#elif BUILDFLAG(IS_MAC)
// TODO(crbug.com/995996): Waiting for this header to appear in the iOS SDK.
Expand Down Expand Up @@ -68,7 +68,7 @@ namespace partition_alloc::internal::base {
// (https://chromium-review.googlesource.com/c/chromium/src/+/1545096) and land
// it or some form of it.
void RandBytes(void* output, size_t output_length) {
#if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS)
#if (BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS)) && !defined(IS_COBALT_HERMETIC_BUILD)
// We have to call `getrandom` via Linux Syscall Support, rather than through
// the libc wrapper, because we might not have an up-to-date libc (e.g. on
// some bots).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -744,7 +744,7 @@ SHIM_ALWAYS_EXPORT int mallopt(int cmd, int value) __THROW {

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

#if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS)
#if (BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS)) && !defined(IS_COBALT_HERMETIC_BUILD)
SHIM_ALWAYS_EXPORT struct mallinfo mallinfo(void) __THROW {
partition_alloc::SimplePartitionStatsDumper allocator_dumper;
Allocator()->DumpStats("malloc", true, &allocator_dumper);
Expand Down
2 changes: 1 addition & 1 deletion base/rand_util_posix.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
#include "base/time/time.h"
#include "build/build_config.h"

#if (BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS)) && !BUILDFLAG(IS_NACL)
#if (BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS)) && !BUILDFLAG(IS_NACL) && !defined(IS_COBALT_HERMETIC_BUILD)
#include "third_party/lss/linux_syscall_support.h"
#elif BUILDFLAG(IS_MAC)
// TODO(crbug.com/995996): Waiting for this header to appear in the iOS SDK.
Expand Down
6 changes: 5 additions & 1 deletion build/config/gcc/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,11 @@ if (is_component_build && !is_android) {
# Settings for executables.
config("executable_config") {
configs = executable_and_shared_library_configs_
ldflags = [ "-pie" ]
if (is_starboard) {
ldflags = []
} else {
ldflags = [ "-pie" ]
}
if (is_android) {
ldflags += [
"-Bdynamic",
Expand Down
63 changes: 63 additions & 0 deletions cobalt/build/testing/cobalt_test_templates.gni
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
# Copyright 2025 The Cobalt Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

template("cobalt_test") {
actual_target_name = target_name
shlib_target_name = actual_target_name
loader_target_name = "${actual_target_name}_loader"

shared_library(shlib_target_name) {
output_name = actual_target_name
forward_variables_from(invoker, "*", TESTONLY_AND_VISIBILITY)
testonly = true
_runtime_deps_file = "$root_build_dir/${actual_target_name}.runtime_deps"

if (defined(invoker.data_deps)) {
data_deps += [ ":${loader_target_name}($starboard_toolchain)" ]
} else {
data_deps = [ ":${loader_target_name}($starboard_toolchain)" ]
}
data_deps += [ "//starboard($starboard_toolchain)" ]

write_runtime_deps = _runtime_deps_file
}

if (current_toolchain == starboard_toolchain) {
executable(loader_target_name) {
sources = [ "//$starboard_path/starboard_loader.cc" ]
testonly = true

if (defined(extra_platform_loader_sources)) {
sources += extra_platform_loader_sources
}

if (use_asan) {
sources += [ "//$starboard_path/sanitizer_options.cc" ]
}

output_dir = root_build_dir
defines = [ "SB_LOADER_MODULE=\"$actual_target_name\"" ]
configs += [ "//starboard/build/config:starboard_implementation" ]

ldflags = [
"-Wl,-rpath=" + rebase_path("$root_build_dir/starboard"),
"-Wl,-rpath=" + rebase_path("$root_build_dir"),
"-Wl,-rpath=\$ORIGIN/../lib",
"-Wl,-rpath=\$ORIGIN",
]

deps = [ "//starboard($starboard_toolchain)" ]
}
}
}
59 changes: 29 additions & 30 deletions cobalt/build/testing/targets/linux-x64x11/test_targets.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,35 +33,34 @@
"starboard/nplb:nplb"
],
"executables": [
"out/linux-x64x11_devel/base_unittests",
"out/linux-x64x11_devel/cc_perftests",
"out/linux-x64x11_devel/cc_unittests",
"out/linux-x64x11_devel/viz_perftests",
"out/linux-x64x11_devel/viz_unittests",
"out/linux-x64x11_devel/crypto_unittests",
"out/linux-x64x11_devel/device_unittests",
"out/linux-x64x11_devel/gcm_unit_tests",
"out/linux-x64x11_devel/google_apis_unittests",
"out/linux-x64x11_devel/gles2_conform_test",
"out/linux-x64x11_devel/command_buffer_perftests",
"out/linux-x64x11_devel/gl_tests",
"out/linux-x64x11_devel/gpu_benchmark",
"out/linux-x64x11_devel/gpu_perftests",
"out/linux-x64x11_devel/gpu_unittests",
"out/linux-x64x11_devel/ipc_tests",
"out/linux-x64x11_devel/capture_unittests",
"out/linux-x64x11_devel/media_unittests",
"out/linux-x64x11_devel/midi_unittests",
"out/linux-x64x11_devel/mojo_perftests",
"out/linux-x64x11_devel/ozone_unittests",
"out/linux-x64x11_devel/ppapi_perftests",
"out/linux-x64x11_devel/ppapi_unittests",
"out/linux-x64x11_devel/service_manager_unittests",
"out/linux-x64x11_devel/skia_unittests",
"out/linux-x64x11_devel/sql_unittests",
"out/linux-x64x11_devel/wm_unittests",
"out/linux-x64x11_devel/url_perftests",
"out/linux-x64x11_devel/url_unittests",
"out/linux-x64x11_devel/nplb"
"out/linux-x64x11_devel/base_unittests_loader",
"out/linux-x64x11_devel/cc_perftests_loader",
"out/linux-x64x11_devel/cc_unittests_loader",
"out/linux-x64x11_devel/viz_perftests_loader",
"out/linux-x64x11_devel/viz_unittests_loader",
"out/linux-x64x11_devel/crypto_unittests_loader",
"out/linux-x64x11_devel/device_unittests_loader",
"out/linux-x64x11_devel/gcm_unit_tests_loader",
"out/linux-x64x11_devel/google_apis_unittests_loader",
"out/linux-x64x11_devel/gles2_conform_test_loader",
"out/linux-x64x11_devel/command_buffer_perftests_loader",
"out/linux-x64x11_devel/gl_tests_loader",
"out/linux-x64x11_devel/gpu_benchmark_loader",
"out/linux-x64x11_devel/gpu_perftests_loader",
"out/linux-x64x11_devel/gpu_unittests_loader",
"out/linux-x64x11_devel/ipc_tests_loader",
"out/linux-x64x11_devel/capture_unittests_loader",
"out/linux-x64x11_devel/media_unittests_loader",
"out/linux-x64x11_devel/midi_unittests_loader",
"out/linux-x64x11_devel/mojo_perftests_loader",
"out/linux-x64x11_devel/ozone_unittests_loader",
"out/linux-x64x11_devel/ppapi_perftests_loader",
"out/linux-x64x11_devel/ppapi_unittests_loader",
"out/linux-x64x11_devel/service_manager_unittests_loader",
"out/linux-x64x11_devel/skia_unittests_loader",
"out/linux-x64x11_devel/sql_unittests_loader",
"out/linux-x64x11_devel/wm_unittests_loader",
"out/linux-x64x11_devel/url_perftests_loader",
"out/linux-x64x11_devel/url_unittests_loader"
]
}
8 changes: 8 additions & 0 deletions device/bluetooth/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,14 @@ source_set("deprecated_experimental_mojo") {
]
}

# TODO: b/384652502 - Cobalt: Fix linker errors.
if(is_starboard) {
sources -= [
"bluez/metrics_recorder.cc",
"bluez/metrics_recorder.h",
]
}

deps = [
":bluetooth",
"//device/bluetooth/public/mojom:deprecated_experimental_interfaces",
Expand Down
18 changes: 17 additions & 1 deletion starboard/linux/x64x11/starboard_loader.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,24 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#include <dlfcn.h>
#include <iostream>
#include "starboard/event.h"

int main(int argc, char** argv) {
return SbRunStarboardMain(argc, argv, SbEventHandle);
static const char* s_target_lib_path = "lib" SB_LOADER_MODULE ".so";
int start_result;

void* handle_ = dlopen(s_target_lib_path, RTLD_LAZY);
if (!handle_) {
std::cerr << "dlopen failure: " << dlerror() << std::endl;
}

void* callback = nullptr;
callback = dlsym(handle_, "SbEventHandle");
if (!callback) {
std::cerr << "dlsym failure: " << dlerror() << std::endl;
}
return SbRunStarboardMain(argc, argv,
reinterpret_cast<SbEventHandleCallback>(callback));
}
10 changes: 10 additions & 0 deletions testing/test.gni
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ import("//build/config/gclient_args.gni")
import("//build/config/rts.gni")
import("//build/rust/rust_static_library.gni")
import("//build_overrides/build.gni")
if (is_starboard) {
import("//cobalt/build/testing/cobalt_test_templates.gni")
}

declare_args() {
# Some component repos (e.g. ANGLE) import //testing but do not have
Expand Down Expand Up @@ -957,6 +960,13 @@ template("test") {
data_deps += [ ":${invoker.target_name}__rts_filters" ]
}
}
} else if (is_starboard) {
cobalt_test(target_name) {
forward_variables_from(invoker,
"*",
TESTONLY_AND_VISIBILITY + [ "use_xvfb" ])
testonly = true
}
} else if (!is_nacl) {
if (is_mac || is_win) {
assert(!defined(invoker.use_xvfb) || !invoker.use_xvfb)
Expand Down
6 changes: 6 additions & 0 deletions url/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,12 @@ test("url_unittests") {
"//testing/gtest",
]

if (is_starboard) {
# Replace the standard runner with the starboard test runner in mojo.
sources -= [ "run_all_unittests.cc" ]
deps += [ "//mojo/core/test:run_all_unittests" ]
}

if (use_platform_icu_alternatives) {
# Unit tests that are not supported by the current ICU alternatives on Android.
if (is_android) {
Expand Down
Loading