blob: bfe14b8922c277da31d9e84868b334b197d0ae1c [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 from the root of the repo with `scripts/smoke_test.sh`
set -e
emu_name=_smoke_test
is_mac() {
[[ "$(uname -s)" == "Darwin" ]] && return 0
return 1
}
failure() {
echo >&2 "ERROR: $0 line $1"
}
print_and_run() {
echo
echo "*** $@"
"$@"
}
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
echo "Build starting!"
if is_mac; then
net_mode="user"
else
net_mode="tap"
fi
if [[ $skip_clean -eq 0 ]]; then
# clear previously fetched dependencies to ensure a clean environment
print_and_run bazel clean --expunge
fi
# fetch dependencies and build the samples source code
print_and_run bazel build --config=fuchsia_x64 src:samples_repository
# fetch an emulator image of workstation and start an emulator
print_and_run tools/ffx product-bundle get workstation.qemu-x64
stop_emu
print_and_run tools/ffx emu start --net $net_mode workstation.qemu-x64 \
--headless --name $emu_name
if [[ $keep_emu -eq 0 ]]; then
trap "stop_emu" EXIT
fi
# start the package server
print_and_run tools/ffx repository server start
# register the package repository with on-demand prebuilt packages
print_and_run tools/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 tools/ffx repository add-from-pm -r fuchsiasamples.com bazel-bin/src/fuchsiasamples.com.repo
print_and_run tools/ffx -t $emu_name target repository register -r fuchsiasamples.com
# run tests on the emulator
print_and_run tools/ffx -t $emu_name test run "fuchsia-pkg://fuchsiasamples.com/hello_test#meta/hello_gtest.cm"
print_and_run tools/ffx -t $emu_name test run "fuchsia-pkg://fuchsiasamples.com/echo_unittests#meta/echo_unittests.cm"
print_and_run tools/ffx -t $emu_name test run "fuchsia-pkg://fuchsiasamples.com/echo_integration_test#meta/echo_integration_test.cm"
echo "Success!"
}
stop_emu() {
# stop the emulator
tools/ffx emu stop $emu_name >/dev/null 2>&1 || return 0
}
time main "$@"