From cb1b2a5e9445891e02c9b05b343e80c4587ee4c5 Mon Sep 17 00:00:00 2001 From: Ryan Rhodes Newton Date: Sun, 27 Nov 2022 17:33:41 -0800 Subject: [PATCH 1/3] [hermit][open-source] Add an extremely basic test script Summary: While we wait to port our full buck testing setup to the OSS build, it's best to get at least a few integration tests running. This diff uses a bash script for the purpose, though the next step would be to replace it with Rust code, possibly using libtest directly. Test Plan: Reviewers: Subscribers: Tasks: Tags: --- .github/workflows/ci.yml | 2 ++ scripts/basic_oss_tests.sh | 31 +++++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+) create mode 100755 scripts/basic_oss_tests.sh diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index a7a843e..41e2ba2 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -20,3 +20,5 @@ jobs: run: sudo apt-get install -y libunwind-dev - name: Build run: cargo build + - name: Run basic tests. + run: ./scripts/basic_oss_tests.sh diff --git a/scripts/basic_oss_tests.sh b/scripts/basic_oss_tests.sh new file mode 100755 index 0000000..669e2ea --- /dev/null +++ b/scripts/basic_oss_tests.sh @@ -0,0 +1,31 @@ +#!/bin/bash +# Copyright (c) Meta Platforms, Inc. and affiliates. +# All rights reserved. +# +# This source code is licensed under the BSD-style license found in the +# LICENSE file in the root directory of this source tree. + +# The full hermit testing setup is Buck-based, and is not working in the OSS release yet. +# This extremely basic test harness is a stop-gap. + +set -eEuo pipefail + +rootdir="$(pwd)" +hermit="$rootdir/target/debug/hermit" +hverify="$rootdir/target/debug/hermit-verify" + +function hermit_verify { + "$hverify" --hermit-bin="$hermit" run --isolate-workdir \ + --hermit-arg="--base-env=empty" --hermit-arg="--env=HERMIT_MODE=strict" --hermit-arg="--preemption-timeout=80000000" \ + "$1" +} + +for script in "$rootdir"/tests/shell/*.sh; do + echo; echo "Running shell test: $script" +# hermit_verify "$script" +done + +for bin in $(ls "$rootdir"/target/debug/rustbin_* | grep -v '\.d'); do + echo; echo "Running rust test: $bin" + hermit_verify "$bin" +done From 7e2f9da026380230dfd17f2ede686317e1733d8c Mon Sep 17 00:00:00 2001 From: Ryan Rhodes Newton Date: Mon, 28 Nov 2022 08:11:16 -0800 Subject: [PATCH 2/3] [hermit][open-source] Turn off RCBs for github actions tests Summary: The VMs running github actions do not expose perf counters, as seen here: https://github.com/facebookexperimental/hermit/actions/runs/3560943420/jobs/5981398423 WARNING: --preemption-timout requires hardware perf counters which is not supported on this host, resetting preemption-timeout to 0 Therefore, we run only a limited subset of tests under hermit run *without* RCB-based preemption of threads (i.e. busy-wait breaking). Test Plan: Reviewers: Subscribers: Tasks: Tags: --- scripts/basic_oss_tests.sh | 48 +++++++++++++++++++++++++++++++++----- 1 file changed, 42 insertions(+), 6 deletions(-) diff --git a/scripts/basic_oss_tests.sh b/scripts/basic_oss_tests.sh index 669e2ea..a66c510 100755 --- a/scripts/basic_oss_tests.sh +++ b/scripts/basic_oss_tests.sh @@ -10,22 +10,58 @@ set -eEuo pipefail +cd "$(dirname $0)" +cd "../" + rootdir="$(pwd)" hermit="$rootdir/target/debug/hermit" hverify="$rootdir/target/debug/hermit-verify" function hermit_verify { + # Github Actions VMs don't expose the perf counters we need to use RCBs: "$hverify" --hermit-bin="$hermit" run --isolate-workdir \ - --hermit-arg="--base-env=empty" --hermit-arg="--env=HERMIT_MODE=strict" --hermit-arg="--preemption-timeout=80000000" \ + --hermit-arg="--base-env=empty" --hermit-arg="--env=HERMIT_MODE=strict" \ + --hermit-arg="--no-rcb-time" --hermit-arg="--preemption-timeout=disabled" \ "$1" } -for script in "$rootdir"/tests/shell/*.sh; do +for script in $(ls "$rootdir"/tests/shell/*.sh); do echo; echo "Running shell test: $script" -# hermit_verify "$script" + hermit_verify "$script" done -for bin in $(ls "$rootdir"/target/debug/rustbin_* | grep -v '\.d'); do - echo; echo "Running rust test: $bin" - hermit_verify "$bin" +rust_tests=( + rustbin_bind_connect_race + rustbin_clock_gettime + rustbin_futex_timeout + rustbin_futex_wait_child + rustbin_heap_ptrs + rustbin_interrogate_tty + rustbin_nanosleep + rustbin_network_hello_world + rustbin_poll + rustbin_print_clock_nanosleep_monotonic_abs_race + rustbin_print_clock_nanosleep_monotonic_race + rustbin_print_clock_nanosleep_realtime_abs_race + rustbin_print_nanosleep_race + rustbin_rdtsc + rustbin_sched_yield + rustbin_socketpair + rustbin_stack_ptr + rustbin_thread_random +) +# Some tests don't work without RCB-timed based preemptions. +# rustbin_clock_total_order +# rustbin_exit_group +# rustbin_futex_and_print +# rustbin_futex_wake_some +# rustbin_mem_race +# rustbin_pipe_basics +# rustbin_poll_spin + +for test in "${rust_tests[@]}"; +do + echo; echo "Running rust test: $test" + file="$rootdir/target/debug/$test" + hermit_verify "$file" done From 0130dcaaa1de1248395de986d86c6d676e29a3fa Mon Sep 17 00:00:00 2001 From: Ryan Rhodes Newton Date: Mon, 28 Nov 2022 12:13:02 -0800 Subject: [PATCH 3/3] [hermit][open-source] minor: add a smoke-test hermit run call before hermit-verify --- scripts/basic_oss_tests.sh | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/scripts/basic_oss_tests.sh b/scripts/basic_oss_tests.sh index a66c510..2eec7f3 100755 --- a/scripts/basic_oss_tests.sh +++ b/scripts/basic_oss_tests.sh @@ -17,6 +17,9 @@ rootdir="$(pwd)" hermit="$rootdir/target/debug/hermit" hverify="$rootdir/target/debug/hermit-verify" +# Hello world smoke test: +"$hermit" run --no-rcb-time --preemption-timeout=disabled -- /bin/echo hello + function hermit_verify { # Github Actions VMs don't expose the perf counters we need to use RCBs: "$hverify" --hermit-bin="$hermit" run --isolate-workdir \ @@ -65,3 +68,4 @@ do file="$rootdir/target/debug/$test" hermit_verify "$file" done +