| #!/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 |
| |
| 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 |
| } |
| |
| bootstrap_ssh() { |
| mkdir -p "$HOME/.ssh" |
| [[ -f "$HOME/.ssh/fuchsia_ed25519" ]] || ssh-keygen -P "" -t ed25519 -f "$HOME/.ssh/fuchsia_ed25519" |
| [[ -f "$HOME/.ssh/fuchsia_authorized_keys" ]] || ssh-keygen -y -f "$HOME/.ssh/fuchsia_ed25519" > "$HOME/.ssh/fuchsia_authorized_keys" |
| } |
| |
| 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:samples_repository |
| |
| bootstrap_ssh |
| |
| print_and_run tools/ffx doctor --restart-daemon |
| |
| current_target="$(tools/ffx target default get)" |
| |
| product_name="workstation_eng.qemu-x64" |
| repo_name="workstation-eng.qemu-x64" |
| pb_name="gs://fuchsia/development/$(tools/ffx sdk version)/sdk/product_bundles.json#${product_name}" |
| # 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 |
| |
| print_and_run tools/ffx emu start "$pb_name" --headless --name $emu_name |
| |
| if [[ $keep_emu -eq 0 ]]; then |
| trap "stop_emu" EXIT |
| fi |
| |
| wait_for_emu_rcs |
| |
| # start the package server |
| print_and_run tools/ffx repository server start |
| |
| 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 |
| |
| # build rust target |
| print_and_run tools/bazel build "src/hello_rust" |
| |
| # run tests on the emulator |
| # print_and_run tools/bazel test "src/hello_world:test_pkg" |
| # print_and_run tools/bazel test "src/echo:test_pkg" |
| |
| # TODO(fxbug.dev/103976): uncomment after bug is fixed |
| # print_and_run tools/bazel test "src/routing:test_pkg" |
| |
| echo "Success!" |
| } |
| |
| 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 "$@" |