From bfe526094ad0bbc5415b0ff5e95c761c02d5dc47 Mon Sep 17 00:00:00 2001 From: Jon Janzen Date: Tue, 3 Dec 2024 10:20:13 -0800 Subject: [PATCH] Rewrite TARGETS files to BUCK files for facebookexperimental/hermit (#52) Summary: Pull Request resolved: https://github.com/facebookexperimental/hermit/pull/52 This diff migrates TARGETS file to BUCK files that are synced for an open source project. Reviewed By: dtolnay Differential Revision: D66561351 --- tests/TARGETS | 605 -------------------------------------------------- 1 file changed, 605 deletions(-) delete mode 100644 tests/TARGETS diff --git a/tests/TARGETS b/tests/TARGETS deleted file mode 100644 index 093f7b4..0000000 --- a/tests/TARGETS +++ /dev/null @@ -1,605 +0,0 @@ -# Copyright (c) Meta Platforms, Inc. and affiliates. -# All rights reserved. -# -# This build configuration is licensed under the BSD-style license found in the -# LICENSE file in the root directory of this source tree. - -load("@bazel_skylib//lib:paths.bzl", "paths") -load("@fbcode_macros//build_defs:cpp_binary.bzl", "cpp_binary") -load("@fbcode_macros//build_defs:export_files.bzl", "export_file") -load("@fbcode_macros//build_defs:native_rules.bzl", "buck_genrule", "buck_sh_binary", "buck_sh_test") -load("@fbcode_macros//build_defs:rust_binary.bzl", "rust_binary") -load("//hermetic_infra/common:wrap_test_suite.bzl", "RR_TEST_TARGETS", "wrap_test_suite") -load(":helpers.bzl", "hermit_bin_test", "hermit_c_test", "hermit_chaos_stress_test", "hermit_python_test", "hermit_rust_test", "hermit_shell_test", "hermit_verify_c_bin") - -# Everything in each of these test folders is an active test. To -# disable it, delete or move to a disabled/ folder. - -# REQUIREMENT: the basename of all test files must be UNIQUE, -# irrespective of what subdirectories they live in within this -# directory. - -oncall("hermit") - -[ - hermit_shell_test( - chaos = True, - chaosreplay = - # TODO(T124815884): add disabled test(s) as they work: - (p != "shell/py_hello.sh") and - (p != "shell/devrand.sh"), - no_deterministic_io = False, - no_sequentialize_threads = False, - path = p, - raw = True, - record_and_replay = False, - run = True, - tracereplay = True, - tracereplay_chaos = - not p in [ - # TODO: fix a register divergence here: - "shell/py_hello.sh", - "shell/par_work.sh", - ], - ) - for p in glob(["shell/*.sh"]) -] - -[ - hermit_shell_test( - chaos = False, - chaosreplay = False, - no_deterministic_io = True, - no_sequentialize_threads = True, - path = p, - raw = True, - record_and_replay = False, - run = True, - tracereplay = False, - tracereplay_chaos = False, - ) - # TODO(T124816271): phase out these non_strict tests as they work under strict mode: - for p in glob(["shell/non_strict/*.sh"]) -] - -[ - buck_sh_test( - name = "standalone__" + paths.replace_extension( - paths.basename(p), - "", - ), - args = [ - "$(location //hermetic_infra/hermit/hermit-cli:hermit)", - ], - env = { - "HERMIT_BIN": "$(location //hermetic_infra/hermit/hermit-cli:hermit)", - "MINIMAL_HELLO": "$(location //hermetic_infra/hermit/tests:minimal_hello)", - }, - test = p, - ) - for p in glob( - ["standalone/*.sh"], - exclude = ["standalone/test_no_networking_network_bind.sh"], - ) -] - -# Additional standalone test(s) in Rust: -rust_binary( - name = "standalone_stacktrace_events", - srcs = ["standalone/stacktrace_events.rs"], - crate_root = "standalone/stacktrace_events.rs", - deps = [ - "fbsource//third-party/rust:regex", - "fbsource//third-party/rust:tempfile", - "//hermetic_infra/hermit/detcore:detcore", - ], -) - -rust_binary( - name = "network_bind_rs", - srcs = ["standalone/network_bind.rs"], - crate_root = "standalone/network_bind.rs", - deps = [ - ], -) - -rust_binary( - name = "network_bind_full_rs", - srcs = ["standalone/network_bind_full.rs"], - crate_root = "standalone/network_bind_full.rs", - deps = [ - "fbsource//third-party/rust:libc", - ], -) - -buck_sh_test( - name = "test_no_networking_network_bind", - args = [ - "$(location //hermetic_infra/hermit/hermit-cli:hermit)", - "$(location :network_bind_rs)", - ], - test = "standalone/test_no_networking_network_bind.sh", -) - -buck_sh_test( - name = "test_no_networking_network_bind_full", - args = [ - "$(location //hermetic_infra/hermit/hermit-cli:hermit)", - "$(location :network_bind_full_rs)", - ], - test = "standalone/test_no_networking_network_bind.sh", -) - -[ - buck_sh_test( - name = "test_standalone_stacktrace_events__" + binname, - args = [ - "$(location //hermetic_infra/hermit/hermit-cli:hermit)", - target, - ], - test = ":standalone_stacktrace_events", - ) - for (binname, target) in [ - ("nanosleep-threads-nocrash", "$(location :nanosleep-threads-nocrash)"), - ("nanosleep-threads-simple", "$(location :nanosleep-threads-simple)"), - ("cas_sequence_easy", "$(location :chaos_cas_sequence_bin)"), - # TODO: add branch-based preemption tests like memrace. - ] -] - -[ - buck_sh_test( - name = "verify_replay__" + test_target[1:], - args = [ - "$(location {})".format(test_target), - ], - env = { - "HERMIT_BIN": "$(location //hermetic_infra/hermit/hermit-cli:hermit)", - }, - test = "./util/hermit_verify_trace_replay.sh", - ) - for test_target in [ - # TODO: Fixme, currently broken: - # ":cbin_just_spin", - ":nanosleep-threads-simple", - ] -] - -# TODO: Analyze v2 of cas_sequence is currently broken -[ - buck_sh_test( - name = "analyze_" + name, - args = [ - "$(location //hermetic_infra/hermit/hermit-cli:hermit)", - target, - ], - env = { - "ANALYZE_OPTS": analyze_opts, - "EXPECTED_OUTPUT": expected_output, - }, - test = "./util/hermit_analyze_test.sh", - ) - for (name, target, analyze_opts, expected_output) in [ - # ("hello_race_mini", "$(location //hermetic_infra/hermit/flaky-tests:hello_race_mini)", "", ""), - # TODO: switch to --base-env=empty: - ( - "hello_race", - "$(location //hermetic_infra/hermit/flaky-tests:hello_race)", - "--run-arg=--base-env=host", - "", - ), - # This one doesn't crash/exit-with-error, rather it is detected based on stdout. - # Here we require the test to blame a specific line. Must be updated if the file changes: - ( - "racewrite_nostdlib", - "$(location //hermetic_infra/hermit/tests:racewrite_nostdlib)", - "--selfcheck --run-arg=--base-env=empty --target-exit-code=0 --target-stdout=barfoo", - "simple/racewrite_nostdlib.c:35", - ), - # TODO: enable more analyze tests: - # ("cas_sequence", "$(location //hermetic_infra/hermit/tests:chaos_cas_sequence_bin)"), - ( - "nanosleep-threads-nocrash", - "$(location //hermetic_infra/hermit/tests:nanosleep-threads-nocrash)", - # TODO(T139493442): this test exits under the baseline hermit run currently, so we could use a feature to - # flip the target/baseline automatically - "--run-arg=--base-env=empty --target-exit-code=0", - # TODO: indicate the right lines to blame: - "", - ), - ] -] - -[ - hermit_python_test( - chaos = True, - module_base = "hermetic_infra.hermit.tests.python", - no_deterministic_io = False, - no_sequentialize_threads = False, - path = p, - raw = True, - record_and_replay = False, - run = True, - tracereplay = True, - tracereplay_chaos = True, - ) - for p in glob(["python/*.py"]) -] - -[ - hermit_python_test( - chaos = False, - module_base = "hermetic_infra.hermit.tests.python.non_strict", - no_deterministic_io = True, - no_sequentialize_threads = True, - path = p, - raw = True, - record_and_replay = False, - run = True, - tracereplay = False, - tracereplay_chaos = False, - ) - # TODO(T124816271): phase out these non_strict tests as they work under strict mode: - for p in glob(["python/non_strict/*.py"]) -] - -tracereplay_exempt_c = [ - "c/vforkExec.c", -] - -[ - hermit_c_test( - chaos = True, - chaosreplay = True, - no_deterministic_io = False, - no_sequentialize_threads = False, - path = p, - raw = True, - record_and_replay = True, - run = True, - tracereplay = - # TODO(T124837711): get the rest of the tests working under trace replay: - not p in tracereplay_exempt_c, - tracereplay_chaos = - # TODO(T124837711): get the rest of the tests working under trace replay: - not p in tracereplay_exempt_c and - not p in [ - "c/just_spin.c", - ], - ) - for p in glob(["c/*.c"]) -] - -# Similar to C tests but built in custom ways. -[ - hermit_bin_test( - bin_target = t, - chaos = True, - chaosreplay = True, - no_deterministic_io = False, - no_sequentialize_threads = False, - raw = True, - record_and_replay = True, - run = True, - tracereplay = True, - tracereplay_chaos = True, - ) - for t in [ - "//hermetic_infra/hermit/tests:minimal_hello", - ] -] - -# Similar to trace-replay tests but with lower preemption timeout and schedule split - -[ - hermit_verify_c_bin( - args = [ - "trace-replay", - "--split-branches", - ], - env = {}, - guest_args = [], - hermit_args = hermit_args, - name_suffix = "trace_replay_split", - path = path, - ) - for path, hermit_args in { - "c/just_spin.c": [ - "--preemption-timeout=10000000", - ], - }.items() -] - -buck_genrule( - name = "minimal_hello", - srcs = ["c/simple/hello_nostdlib.c"], - out = "minimal_hello.bin", - cmd = "clang.par -g -nostdlib c/simple/hello_nostdlib.c -o $OUT", - # Is there an efficient/correct way to depend on clang as a buck target? - # cmd = "$(location fbsource//third-party/llvm-project/12.0.0-fbcode:bin/clang-12) -nostdlib c/simple/hello_nostdlib.c -o $OUT", - executable = True, -) - -buck_genrule( - name = "racewrite_nostdlib", - srcs = ["c/simple/racewrite_nostdlib.c"], - out = "racewrite_nostdlib.bin", - cmd = "clang.par -g -nostdlib c/simple/racewrite_nostdlib.c -o $OUT", - # Is there an efficient/correct way to depend on clang as a buck target? - # cmd = "$(location fbsource//third-party/llvm-project/12.0.0-fbcode:bin/clang-12) -nostdlib c/simple/hello_nostdlib.c -o $OUT", - executable = True, -) - -# Split this out into its own target so that we can specify the allocator. -cpp_binary( - name = "nanosleep-threads-simple", - srcs = [ - "c/simple/nanosleep-threads-simple.c", - ], - allocator = "malloc", - external_deps = [ - ("glibc", None, "pthread"), - ], -) - -cpp_binary( - name = "nanosleep-threads-nocrash", - srcs = [ - "c/simple/nanosleep-threads-nocrash.c", - ], - allocator = "malloc", - external_deps = [ - ("glibc", None, "pthread"), - ], -) - -# TODO(T124837711): get the rest of the tests working under trace replay: -tracereplay_exempt_rs = [ - "rust/bind_connect_race.rs", - "rust/clock_total_order.rs", - "rust/exit_group.rs", - # Seems to run tid 9 instead of tid 3: - "rust/futex_and_print.rs", - "rust/futex_wake_some.rs", - "rust/poll_spin.rs", - "rust/thread_random.rs", -] - -[ - hermit_rust_test( - chaos = True, - chaosreplay = - # TODO(T124815884): add disabled test(s) as they work: - (p != "rust/thread_random.rs") and - (p != "rust/poll_spin.rs"), - no_deterministic_io = False, - no_sequentialize_threads = False, - path = p, - raw = True, - record_and_replay = True, - run = True, - tracereplay = not p in tracereplay_exempt_rs, - tracereplay_chaos = - not p in tracereplay_exempt_rs and - not p in [ - "rust/print_nanosleep_race.rs", - "rust/print_clock_nanosleep_monotonic_abs_race.rs", - "rust/print_clock_nanosleep_monotonic_race.rs", - "rust/print_clock_nanosleep_realtime_abs_race.rs", - ], - ) - for p in glob(["rust/*.rs"]) -] - -[ - hermit_rust_test( - chaos = False, - chaosreplay = True, - no_deterministic_io = True, - no_sequentialize_threads = True, - path = p, - raw = True, - record_and_replay = True, - run = True, - ) - # TODO(T124816271): phase out these non_strict tests as they work under strict mode: - for p in glob(["rust/non_strict/*.rs"]) -] - -# === Chaos Tests === - -rust_binary( - name = "nanosleep-threads-nocrash-rust", - srcs = ["chaos/nanosleep-threads-nocrash-rust.rs"], - allocator = "malloc", - crate_root = "chaos/nanosleep-threads-nocrash-rust.rs", - deps = [ - "fbsource//third-party/rust:libc", - ], -) - -rust_binary( - name = "chaos_hello_chaos", - srcs = ["chaos/hello_chaos.rs"], - crate_root = "chaos/hello_chaos.rs", -) - -hermit_chaos_stress_test( - name = "hello_chaos", - bin_target = ":chaos_hello_chaos", - max_iterations = 100, - preempt_interval = 500000, -) - -rust_binary( - name = "chaos_cas_sequence_bin", - srcs = ["chaos/cas_sequence.rs"], - allocator = "malloc", - crate_root = "chaos/cas_sequence.rs", -) - -hermit_chaos_stress_test( - name = "cas_sequence", - bin_target = ":chaos_cas_sequence_bin", - max_iterations = 1000, - preempt_interval = 120000, -) - -rust_binary( - name = "chaos_keyvalue_bin", - srcs = ["chaos/keyvalue.rs"], - crate_root = "chaos/keyvalue.rs", -) - -hermit_chaos_stress_test( - name = "keyvalue", - bin_target = ":chaos_keyvalue_bin", - max_iterations = 1000, - preempt_interval = 50000, -) - -cpp_binary( - name = "chaos_lock_granularity_bin", - srcs = ["chaos/lock_granularity.c"], - external_deps = [ - ("glibc", None, "pthread"), - ], -) - -hermit_chaos_stress_test( - name = "lock_granularity", - bin_target = ":chaos_lock_granularity_bin", - max_iterations = 1000, - preempt_interval = 50000, -) - -cpp_binary( - name = "chaos_order_violation_bin", - srcs = ["chaos/order_violation.c"], - external_deps = [ - ("glibc", None, "pthread"), - ], -) - -hermit_chaos_stress_test( - name = "order_violation", - bin_target = ":chaos_order_violation_bin", - max_iterations = 1000, - preempt_interval = 50000, -) - -# For reuse as a dependency in other tests: -export_file( - name = "simplest_server_py", - src = "util/simplest_server.py", - visibility = ["//hermetic_infra/hermit/tests/..."], -) - -cpp_binary( - name = "memoryPress", - srcs = ["c/memoryPress.c"], -) - -buck_sh_binary( - name = "chaos_stress_wrapper", - main = "util/chaos_stress_wrapper.sh", -) -# TODO: In the future add Java tests, go tests, etc. - -wrap_test_suite( - args = [ - "run", - "--base-env=minimal", - "--verify", - "--preemption-timeout=80000000", - "--workdir=/tmp", - ], - exclude = [ - # fails - "rr_redzone_integrity", - "rr_nanosleep", - "rr_sem", - "rr_switch_read", - "rr_sigstop", - "rr_utimes", - "rr_sock_names_opts", - "rr_sigprocmask_exec", - "rr_vfork_shared", - "rr_wait_sigstop", - "rr_vsyscall", - "rr_scm_rights", - "rr_robust_futex", - "rr_intr_futex_wait_restart", - "rr_grandchild_threads_parent_alive", - "rr_seccomp_null", - "rr_perf_event", - "rr_packet_mmap_disable", - "rr_timerfd", - "rr_intr_read_no_restart", - "rr_intr_read_restart", - "rr_pthread_pi_mutex", - "rr_int3", - "rr_intr_sleep_no_restart", - "rr_intr_sleep", - "rr_fcntl_notify", - "rr_send_block", # T121482036 - "rr_intr_pselect", # TODO(T137258824): fully support Select/PSelect6 - - # verify failures, i.e. non-deterministic - "rr_sigprocmask_ensure_delivery", - "rr_times", - "rr_mount_ns_exec", - "rr_mount_ns_exec2", - "rr_pivot_root", - "rr_prctl_caps", - "rr_syscallbuf_signal_blocking", - "rr_exit_status", - "rr_two_signals_with_mask", - "rr_ioctl_pty", - "rr_mmap_shared", - "rr_mmap_shared_subpage", - "rr_mmap_shared_grow", - "rr_mq", - "rr_samask", - "rr_grandchild_threads", - "rr_save_data_fd", - "rr_sigstop2", - "rr_fatal_sigsegv_thread", - "rr_orphan_process", - "rr_statfs", - "rr_sigreturnmask", # T121482215 - - # timeout - "rr_wait", - "rr_unexpected_exit_execve", - "rr_sigsuspend", - "rr_sigrt", - "rr_pid_ns_kill_threads", - "rr_msg", - "rr_intr_poll", - "rr_unexpected_exit", - "rr_pid_ns_kill_child_threads", - "rr_set_tid_address", - "rr_record_replay_subject", - "rr_pidfd", - "rr_unexpected_exit_execve_twice", - "rr_main_thread_exit", - "rr_prctl_deathsig", - "rr_grandchild_threads_thread_running", - "rr_pid_ns_kill_child", - "rr_grandchild_threads_main_running", - "rr_pid_ns_segv", - "rr_pid_ns_kill_child_zombie", - "rr_fd_tracking_across_threads", - "rr_pid_ns_reap", - "rr_proc_mem", - "rr_pid_ns_kill_threads_exit_wait", - "rr_pid_ns_shutdown", - "rr_fcntl_owner_ex", - "rr_hooks", - ], - name_prefix = "test_hermit_strict__", - suite_name = "rr_tests", - target = "//hermetic_infra/hermit/hermit-cli:hermit", - test_targets = RR_TEST_TARGETS, -)