| #!/bin/bash |
| |
| # Copyright 2022 The Fuchsia Authors. All rights reserved. |
| # Use of this source code is governed by a BSD-style license that can be |
| # found in the LICENSE file. |
| |
| |
| # Run this from the root of the repo with `scripts/smoke_test.sh` |
| set -e -o pipefail |
| |
| emu_name=_smoke_test |
| |
| if [[ -z "$HOME" ]]; then |
| export HOME=$(pwd) |
| fi |
| |
| failure() { |
| echo >&2 "ERROR: $0 line $1" |
| } |
| |
| print_and_run() { |
| echo |
| echo "*** $@" |
| "$@" |
| } |
| |
| wait_for_emu_rcs() { |
| local i=0 |
| while [[ $i -lt 120 ]] && |
| [[ "$(tools/ffx target list 2>&1 | grep $emu_name | awk '{print $6;}')" != "Y" ]]; do |
| echo -n . |
| sleep 0.5 |
| i+=1 |
| done |
| echo |
| } |
| |
| no_kvm() { |
| [[ "$(uname -s)" == "Linux" && ! -w /dev/kvm ]] && return 0 |
| return 1 |
| } |
| |
| main() { |
| trap 'failure $LINENO' ERR |
| local keep_emu=0 |
| local skip_clean=0 |
| while [[ $# -gt 0 ]]; do |
| if [[ "$1" == "--keep" ]]; then |
| keep_emu=1 |
| elif [[ "$1" == "--no-clean" ]]; then |
| skip_clean=1 |
| else |
| echo >&2 "Invalid argument: $1" |
| echo >&2 "Syntax: $0 [--keep] [--no-clean]" |
| return 1 |
| fi |
| shift |
| done |
| |
| print_and_run scripts/bootstrap.sh |
| |
| echo "Build starting!" |
| |
| if [[ $skip_clean -eq 0 ]]; then |
| # clear previously fetched dependencies to ensure a clean environment |
| print_and_run tools/bazel clean --expunge |
| fi |
| |
| # build all samples in this repository |
| print_and_run tools/bazel build src:fuchsia_samples |
| # other build commands in https://fuchsia.dev/fuchsia-src/get-started/sdk/get-started-with-driver |
| print_and_run tools/bazel build --config=fuchsia_x64 //src/qemu_edu/drivers:qemu_edu |
| |
| print_and_run tools/ffx doctor --restart-daemon |
| print_and_run tools/ffx sdk version |
| |
| current_target="$(tools/ffx target default get)" |
| |
| repo_name="workstation-packages" |
| pb_name="workstation_eng.qemu-x64" |
| |
| # fetch an emulator image of workstation and start an emulator |
| print_and_run tools/ffx product-bundle get "$pb_name" --repository "$repo_name" |
| stop_emu |
| |
| emu_options="" |
| # If KVM is not available, need to fall back to an alternative emulator that works fxbug.dev/113237 |
| # otherwise it fails to start up properly, and ffx emu does not handle this yet. |
| if no_kvm; then |
| emu_options="--engine qemu --startup-timeout 720 --accel none --device qemu-x64-emu-min" |
| fi |
| print_and_run tools/ffx emu start "$pb_name" --headless --name $emu_name $emu_options \ |
| --kernel-args "devmgr.enable-ephemeral=true" \ |
| --kernel-args "driver_manager.use_driver_framework_v2=true" \ |
| --kernel-args "driver_manager.root-driver=fuchsia-boot:///#meta/platform-bus.cm" |
| |
| if [[ $keep_emu -eq 0 ]]; then |
| trap "stop_emu" EXIT |
| fi |
| |
| wait_for_emu_rcs |
| |
| # CQ actually uses mawk and not awk or gawk, so does not support symbols in search string |
| check_output() { |
| if ! awk -v SEARCH="$@" '$0 ~ SEARCH{rc=1; print "Found match: "$0}{print $0}; END{exit !rc}'; then |
| echo "Failed to find expected string: $@" |
| exit 1 |
| fi |
| } |
| |
| # start the package server |
| print_and_run tools/ffx repository server start |
| |
| # enable experimental ffx driver plugin |
| print_and_run tools/ffx config set driver true |
| |
| print_and_run tools/ffx target default set $emu_name |
| |
| # register the package repository with on-demand prebuilt packages |
| print_and_run tools/ffx target repository register -r $repo_name --alias fuchsia.com --alias chromium.org |
| print_and_run tools/ffx repository list |
| |
| # register a driver and verify that it registered succesfully |
| print_and_run tools/bazel run src/qemu_edu/drivers:pkg.component | check_output "Node 'root.sys.platform.pt.PCI0.bus" |
| |
| # wait for driver to load |
| sleep 1 |
| print_and_run tools/ffx driver list --loaded | check_output "qemu_edu" |
| |
| # TODO: fxbug.dev/114888 the tests and eductl fail on an emulator without KVM support due to device ids changing |
| if ! no_kvm; then |
| # run tests on the emulator |
| print_and_run tools/bazel test src/qemu_edu/tests:pkg |
| # interact with driver |
| print_and_run tools/bazel run src/qemu_edu/tools:pkg.eductl_tool -- fact 12 |
| print_and_run tools/bazel run --config=fuchsia_x64 //src/qemu_edu/tools:pkg.eductl_tool -- live |
| # TODO: fxbug.dev/113254 | check_output "Liveness check passed" |
| print_and_run tools/bazel run --config=fuchsia_x64 //src/qemu_edu/tools:pkg.eductl_tool -- fact 12 |
| # TODO: fxbug.dev/113254 | check_output "479001600" |
| fi |
| |
| # other run commands in https://fuchsia.dev/fuchsia-src/get-started/sdk/get-started-with-driver |
| print_and_run tools/bazel run --config=fuchsia_x64 //src/qemu_edu/drivers:pkg.component | check_output "No new nodes were bound" |
| print_and_run tools/ffx component show qemu_edu.cm | check_output "Moniker: /bootstrap/universe-pkg-drivers:root.sys.platform.pt.PCI0.bus." |
| print_and_run tools/ffx driver list-devices | check_output "root.sys.platform.pt.PCI0.bus." |
| # The PCI id changes depending if /dev/kvm is available |
| if no_kvm; then |
| print_and_run tools/ffx driver list-devices root.sys.platform.pt.PCI0.bus.00_05_0_ --verbose | check_output "Name : 00_05_0_" |
| else |
| print_and_run tools/ffx driver list-devices root.sys.platform.pt.PCI0.bus.00_06_0_ --verbose | check_output "Name : 00_06_0_" |
| fi |
| print_and_run tools/ffx driver list-hosts | check_output "fuchsia-pkg://bazel.pkg.component/qemu_edu#meta/qemu_edu.cm" |
| print_and_run tools/ffx driver lspci | check_output "Host bridge:" |
| # check debugging tools work |
| test_zxdb() { echo quit | tools/ffx debug connect; } |
| print_and_run test_zxdb | check_output "Connected successfully" |
| print_and_run test_fidlcat |
| # CQ uses a non-HOME directory for .ssh so pass in the private key directly for all cases |
| print_and_run tools/fssh -sshconfig scripts/sshconfig.local -private-key "${HOME}/.ssh/fuchsia_ed25519" uname -a | check_output "Zircon" |
| |
| echo "Success!" |
| } |
| |
| test_fidlcat() { |
| local bazel_out |
| bazel_out="$(tools/bazel info output_path)" |
| timeout 10s tools/ffx debug fidl --remote-name qemu_edu.cm --fidl-ir-path "$bazel_out" || if [ "$?" != "124" ]; then /bin/false; fi |
| } |
| |
| stop_emu() { |
| # stop the emulator |
| if tools/ffx emu show $emu_name >/dev/null 2>&1; then |
| tools/ffx emu stop $emu_name || true |
| fi |
| if [[ -n "${current_target}" ]]; then |
| tools/ffx target default set "${current_target}" || true |
| else |
| tools/ffx target default unset || true |
| fi |
| |
| return 0 |
| } |
| |
| time main "$@" |