blob: 2eacf82eb1076d26ef49f2e6bc3862916555b2c3 [file] [log] [blame]
#!/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
local is_atlas=0
local no_bootstrap_ssh=0
while [[ $# -gt 0 ]]; do
if [[ "$1" == "--keep" ]]; then
keep_emu=1
elif [[ "$1" == "--no-clean" ]]; then
skip_clean=1
elif [[ "$1" == "--atlas" ]]; then
is_atlas=1
elif [[ "$1" == "--no-bootstrap-ssh" ]]; then
no_bootstrap_ssh=1
else
echo >&2 "Invalid argument: $1"
echo >&2 "Syntax: $0 [--keep] [--no-clean] [--atlas] [--no-bootstrap-ssh]"
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
# fetch dependencies and build the source code
print_and_run tools/bazel build --config=fuchsia_x64 driver:pkg
if [[ $is_atlas -eq 0 ]]; then
target_name="$emu_name"
if [[ $no_bootstrap_ssh -eq 0 ]]; then
bootstrap_ssh
print_and_run tools/ffx doctor --restart-daemon
fi
current_target="$(tools/ffx target default get)"
product_name="workstation_eng.qemu-x64"
repo_name="workstation-repo"
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 $target_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 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
else
target_name="$(tools/ffx target list 2>&1 | grep 'fuchsia-' | awk '{print $1;}')"
target_name="${target_name//\*}"
fi
# run the unit tests
print_and_run tools/bazel run //driver:test_pkg.test_component -- -t $target_name
if [[ $is_atlas -eq 1 ]]; then
# run the driver
print_and_run tools/bazel run //driver:pkg.component -- -t $target_name
# wait for driver to load
sleep 1
print_and_run tools/ffx -t $target_name driver list --loaded | grep 'ffx\|backlight_driver'
fi
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 "$@"