| #!/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 "*** $@" |
| local cmd=$1 |
| shift |
| if [[ "$cmd" == "ffx" ]]; then |
| cmd="$ffx_full" |
| fi |
| "$cmd" "$@" |
| } |
| |
| wait_for_emu_rcs() { |
| local i=0 |
| while [[ $i -lt 120 ]] && |
| [[ "$($ffx_full 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 .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 |
| local skip_build=0 |
| while [[ $# -gt 0 ]]; do |
| if [[ "$1" == "--keep" ]]; then |
| keep_emu=1 |
| elif [[ "$1" == "--no-build" ]]; then |
| skip_build=1 |
| elif [[ "$1" == "--no-clean" ]]; then |
| skip_clean=1 |
| else |
| echo >&2 "Invalid argument: $1" |
| echo >&2 "Syntax: $0 [--keep] [--no-clean] [--no-build]" |
| return 1 |
| fi |
| shift |
| done |
| |
| echo "Build starting!" |
| |
| if [[ $skip_build -eq 0 ]]; then |
| if [[ $skip_clean -eq 0 ]]; then |
| # clear previously fetched dependencies to ensure a clean environment |
| print_and_run third_party/sdk-integration/tools/bazel clean --expunge |
| fi |
| |
| # fetch dependencies and build the samples source code |
| print_and_run third_party/sdk-integration/tools/bazel build --config=fuchsia_x64 src:samples_repository |
| fi |
| |
| export ffx_full="$(third_party/sdk-integration/tools/bazel query --noshow_progress "@fuchsia_sdk//tools:x64/ffx" --output location | cut -f1 -d:)" |
| |
| bootstrap_ssh |
| |
| print_and_run ffx doctor --restart-daemon |
| |
| # fetch an emulator image of workstation and start an emulator |
| print_and_run ffx product-bundle get workstation.qemu-x64 |
| |
| stop_emu |
| |
| print_and_run ffx emu start workstation.qemu-x64 --headless --name $emu_name \ |
| --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 |
| |
| # start the package server |
| print_and_run ffx repository server start |
| |
| # enable experimental ffx driver plugin |
| print_and_run ffx config set driver true |
| |
| # register the package repository with on-demand prebuilt packages |
| print_and_run ffx -t $emu_name target repository register -r workstation.qemu-x64 --alias fuchsia.com |
| |
| # register the package repository with these samples packages |
| print_and_run ffx repository add-from-pm -r fuchsiasamples.com bazel-bin/src/fuchsiasamples.com.repo |
| print_and_run ffx -t $emu_name target repository register -r fuchsiasamples.com |
| |
| # register a driver and verify that it registered succesfully |
| print_and_run ffx -t $emu_name driver register "fuchsia-pkg://fuchsiasamples.com/qemu_edu#meta/qemu_edu.cm" |
| # wait for driver to load |
| sleep 1 |
| print_and_run ffx -t $emu_name driver list --loaded | grep qemu_edu |
| |
| # interact with driver |
| print_and_run ffx -t $emu_name component run "fuchsia-pkg://fuchsiasamples.com/eductl#meta/eductl.cm" |
| |
| # run tests on the emulator |
| # TODO: this repo doesn't yet have tests |
| #print_and_run ffx -t $emu_name test run fuchsia-pkg://fuchsiasamples.com/hello_test#meta/hello_gtest.cm |
| |
| echo "Success!" |
| } |
| |
| stop_emu() { |
| # stop the emulator |
| if [[ -x $ffx_full ]] && $ffx_full emu show $emu_name >/dev/null 2>&1; then |
| $ffx_full emu stop $emu_name || return 0 |
| fi |
| return 0 |
| } |
| |
| time main "$@" |