Skip to content

Commit

Permalink
No public description
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 579308232
  • Loading branch information
ksteuck authored and copybara-github committed Nov 3, 2023
1 parent f2f3724 commit 689ba3e
Show file tree
Hide file tree
Showing 13 changed files with 62 additions and 999 deletions.
45 changes: 11 additions & 34 deletions runner/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -40,16 +40,6 @@ DISABLE_ARM_TAGS = [
"not_run:arm",
]

cc_library_plus_nolibc(
name = "baked_snap_corpus",
srcs = ["baked_snap_corpus.cc"],
hdrs = ["default_snap_corpus.h"],
deps = [
"@silifuzz//snap",
"@silifuzz//util:arch",
],
)

cc_library_plus_nolibc(
name = "loading_snap_corpus",
srcs = ["loading_snap_corpus.cc"],
Expand Down Expand Up @@ -226,19 +216,27 @@ cc_test_nolibc(
name = "runner_test",
timeout = "short",
srcs = ["runner_test.cc"],
data = [
"@silifuzz//snap/testing:test_corpus",
],
env = {"TEST_CORPUS": "$(location @silifuzz//snap/testing:test_corpus)"},
linkopts = [
"-Xlinker",
"--image-base=" + SILIFUZZ_RUNNER_BASE_ADDRESS,
],
linkstatic = 1,
deps = [
":loading_snap_corpus",
":runner",
":runner_main_options",
":runner_util",
":snap_runner_util",
"@silifuzz//common:snapshot_test_enum",
"@silifuzz//snap",
"@silifuzz//snap:exit_sequence",
"@silifuzz//snap/testing:snap_test_snaps",
"@silifuzz//util:arch",
"@silifuzz//util:checks",
"@silifuzz//util:itoa",
"@silifuzz//util:nolibc_gunit",
],
)
Expand All @@ -256,20 +254,6 @@ cc_library_nolibc(
],
)

cc_binary_nolibc(
name = "runner_test_helper",
testonly = 1,
linkopts = [
"-Xlinker",
"--image-base=" + SILIFUZZ_RUNNER_BASE_ADDRESS,
],
deps = [
":baked_snap_corpus",
":runner_main_as_lib",
"@silifuzz//snap/testing:snap_test_snaps",
],
)

cc_test(
name = "runner_integration_test",
size = "medium",
Expand Down Expand Up @@ -327,7 +311,7 @@ cc_test(
size = "medium",
srcs = ["disassembling_snap_tracer_test.cc"],
data = [
":sanless_runner_test_helper_nolibc",
"@silifuzz//snap/testing:test_corpus",
],
deps = [
":disassembling_snap_tracer",
Expand All @@ -338,6 +322,7 @@ cc_test(
"@silifuzz//runner/driver:runner_driver",
"@silifuzz//snap/testing:snap_test_snapshots",
"@silifuzz//util:arch",
"@silifuzz//util:data_dependency",
"@silifuzz//util/testing:status_macros",
"@silifuzz//util/testing:status_matchers",
"@com_google_absl//absl/functional:bind_front",
Expand Down Expand Up @@ -453,14 +438,6 @@ sh_test(
data = [":reading_runner_main_nolibc"],
)

nosan_filegroup(
name = "sanless_runner_test_helper_nolibc",
testonly = 1,
srcs = [
":runner_test_helper_nolibc",
],
)

nosan_filegroup(
name = "sanless_reading_runner_main_nolibc",
srcs = [
Expand Down
36 changes: 0 additions & 36 deletions runner/baked_snap_corpus.cc

This file was deleted.

4 changes: 3 additions & 1 deletion runner/disassembling_snap_tracer_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#include "./runner/runner_provider.h"
#include "./snap/testing/snap_test_snapshots.h"
#include "./util/arch.h"
#include "./util/data_dependency.h"
#include "./util/testing/status_macros.h"
#include "./util/testing/status_matchers.h"

Expand All @@ -43,7 +44,8 @@ using snapshot_types::SigNum;
using ::testing::ElementsAre;

RunnerDriver HelperDriver() {
return RunnerDriver::BakedRunner(RunnerTestHelperLocation());
return RunnerDriver::ReadingRunner(
RunnerLocation(), GetDataDependencyFilepath("snap/testing/test_corpus"));
}

auto InsnAtAddr(absl::string_view x, int addr, int size) {
Expand Down
1 change: 1 addition & 0 deletions runner/runner_main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#include "./runner/default_snap_corpus.h"
#include "./runner/runner.h"
#include "./runner/runner_flags.h"
#include "./runner/runner_main_options.h"
#include "./util/arch.h"
#include "./util/checks.h"
#include "./util/strcat.h"
Expand Down
36 changes: 31 additions & 5 deletions runner/runner_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,36 @@

#include "./runner/runner.h"

#include <cstdlib>

#include "./common/snapshot_test_enum.h"
#include "./runner/default_snap_corpus.h"
#include "./runner/runner_main_options.h"
#include "./runner/runner_util.h"
#include "./runner/snap_runner_util.h"
#include "./snap/exit_sequence.h"
#include "./snap/testing/snap_test_snaps.h"
#include "./snap/snap.h"
#include "./util/arch.h"
#include "./util/checks.h"
#include "./util/itoa.h"
#include "./util/nolibc_gunit.h"

namespace silifuzz {

namespace {

// An instance of the test corpus. main() loads this from $TEST_CORPUS.
const SnapCorpus<Host>* kSnapRunnerTestCorpus;

// Returns a Snap runner test Snap of the given type.
const Snap<Host>& GetSnapRunnerTestSnap(TestSnapshot type) {
const Snap<Host>* snap = kSnapRunnerTestCorpus->Find(EnumStr(type));
if (snap == nullptr) {
LOG_FATAL("Cannot find snap with ID: ", EnumStr(type));
}
return *snap;
}

// Runner tests do not run well with normal libc because of an invalid fs_base.
// We could make the tests work but it would not be how the runner is intended
// to be used.
Expand Down Expand Up @@ -67,16 +85,24 @@ TEST(Runner, SkipEndStateCheck) {
CHECK_EQ(result.outcome, RunSnapOutcome::kAsExpected);
}

// Initializes the test environment. Loads and maps the corpus, then drops into
// the seccomp sandbox.
void InitTestEnv() {
const char* corpus_file = getenv("TEST_CORPUS");
CHECK_NE(corpus_file, nullptr);
kSnapRunnerTestCorpus = LoadCorpus(corpus_file, true, nullptr);
InitSnapExit(&SnapExitImpl);
MapCorpus(*kSnapRunnerTestCorpus, -1, nullptr);
EnterSeccompStrictMode();
}

} // namespace
} // namespace silifuzz

// ========================================================================= //

NOLIBC_TEST_MAIN({
silifuzz::InitSnapExit(&SnapExitImpl);
silifuzz::MapCorpus(silifuzz::kSnapRunnerTestCorpus, -1, nullptr);
silifuzz::EnterSeccompStrictMode();

silifuzz::InitTestEnv();
RUN_TEST(Runner, EndsAsExpected);
RUN_TEST(Runner, RegsMismatch);
RUN_TEST(Runner, MemoryMismatch);
Expand Down
18 changes: 3 additions & 15 deletions snap/gen/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -97,20 +97,19 @@ cc_test(
"@silifuzz//common:memory_mapping",
"@silifuzz//common:memory_perms",
"@silifuzz//common:snapshot",
"@silifuzz//common:snapshot_test_enum",
"@silifuzz//common:snapshot_test_util",
"@silifuzz//snap",
"@silifuzz//snap:snap_relocator",
"@silifuzz//snap:snap_util",
"@silifuzz//snap/testing:snap_generator_test_lib",
"@silifuzz//snap/testing:snap_test_snapshots",
"@silifuzz//util:arch",
"@silifuzz//util:checks",
"@silifuzz//util:misc_util",
"@silifuzz//util:mmapped_memory_ptr",
"@silifuzz//util:platform",
"@silifuzz//util/testing:status_macros",
"@silifuzz//util/testing:status_matchers",
"@com_google_absl//absl/container:flat_hash_set",
"@com_google_absl//absl/status",
"@com_google_absl//absl/status:statusor",
"@com_google_googletest//:gtest_main",
],
)
Expand Down Expand Up @@ -170,7 +169,6 @@ cc_test(
cc_library(
name = "snap_generator",
srcs = [
"snap_generator.cc",
"snapify.cc",
],
hdrs = [
Expand All @@ -180,25 +178,18 @@ cc_library(
":repeating_byte_runs",
":reserved_memory_mappings",
"@silifuzz//common:mapped_memory_map",
"@silifuzz//common:memory_perms",
"@silifuzz//common:memory_state",
"@silifuzz//common:snapshot",
"@silifuzz//common:snapshot_util",
"@silifuzz//snap",
"@silifuzz//snap:exit_sequence",
"@silifuzz//snap:snap_checksum",
"@silifuzz//util:arch",
"@silifuzz//util:checks",
"@silifuzz//util:itoa",
"@silifuzz//util:platform",
"@silifuzz//util:reg_checksum",
"@silifuzz//util:reg_checksum_util",
"@silifuzz//util/ucontext:serialize",
"@silifuzz//util/ucontext:ucontext_types",
"@com_google_absl//absl/status",
"@com_google_absl//absl/status:statusor",
"@com_google_absl//absl/strings",
"@com_google_absl//absl/strings:str_format",
],
)

Expand All @@ -211,10 +202,7 @@ cc_test(
"@silifuzz//common:memory_perms",
"@silifuzz//common:memory_state",
"@silifuzz//common:snapshot",
"@silifuzz//snap",
"@silifuzz//snap:exit_sequence",
"@silifuzz//snap/testing:snap_generator_test_lib",
"@silifuzz//snap/testing:snap_test_snaps",
"@silifuzz//snap/testing:snap_test_snapshots",
"@silifuzz//snap/testing:snap_test_types",
"@silifuzz//util/testing:status_macros",
Expand Down
9 changes: 3 additions & 6 deletions snap/gen/relocatable_snap_generator_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,30 +20,27 @@

#include <cstddef>
#include <cstdint>
#include <memory>
#include <string>
#include <utility>
#include <vector>

#include "gtest/gtest.h"
#include "absl/container/flat_hash_set.h"
#include "absl/status/status.h"
#include "absl/status/statusor.h"
#include "./common/memory_mapping.h"
#include "./common/memory_perms.h"
#include "./common/snapshot.h"
#include "./common/snapshot_test_enum.h"
#include "./common/snapshot_test_util.h"
#include "./snap/gen/snap_generator.h"
#include "./snap/snap.h"
#include "./snap/snap_relocator.h"
#include "./snap/snap_util.h"
#include "./snap/testing/snap_generator_test_lib.h"
#include "./snap/testing/snap_test_snapshots.h"
#include "./util/arch.h"
#include "./util/checks.h"
#include "./util/misc_util.h"
#include "./util/mmapped_memory_ptr.h"
#include "./util/platform.h"
#include "./util/testing/status_macros.h"
#include "./util/testing/status_matchers.h"

namespace silifuzz {
namespace {
Expand Down
Loading

0 comments on commit 689ba3e

Please sign in to comment.