blob: 970d1dec5663989a547f867606d0c154b0ad3162 [file] [log] [blame]
#!/bin/bash
# Copyright 2020 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.
### Test fx flash
BT_FILE_DEPS=(
"scripts/fx"
"tools/devshell/flash"
"tools/devshell/lib/fx-cmd-locator.sh"
"tools/devshell/lib/fx-flash.sh"
"tools/devshell/lib/fx-optional-features.sh"
"tools/devshell/lib/generate-ssh-config.sh"
"tools/devshell/lib/platform.sh"
"tools/devshell/lib/vars.sh"
)
BT_MOCKED_TOOLS=(
"tools/devshell/build"
)
declare fx ffx fastboot_mock flash_script flash_manifest
BT_SET_UP() {
source "${BT_TEMP_DIR}/tools/devshell/lib/vars.sh"
source "${BT_TEMP_DIR}/tools/devshell/tests/lib/fuchsia-mock.sh"
fx="$(btf::setup_fx)"
fx-config-read
ffx="$(btf::make_installed_hosttools_mock ffx)"
btf::make_mock "${BT_TEMP_DIR}/tools/devshell/get-flash-source"
btf::make_mock "${BT_TEMP_DIR}/tools/devshell/host-tool"
fastboot_mock="$(btf::make_mock_binary "fastboot")"
cat > "${BT_TEMP_DIR}/tools/devshell/host-tool.mock_side_effects" <<EOF
if [[ "\$1" == "fastboot" ]]; then
shift
"${fastboot_mock}" "\$@"
fi
if [[ "\$2" == "ffx" ]]; then
shift
"${ffx}" "\$@"
fi
EOF
cat > "${BT_TEMP_DIR}/tools/devshell/get-flash-source.mock_side_effects" <<EOF
echo flash-manifest:flash.json
EOF
btf::make_mock "${BT_TEMP_DIR}/tools/devshell/list-build-artifacts"
cat > "${BT_TEMP_DIR}/tools/devshell/list-build-artifacts.mock_side_effects" << "EOF"
if [[ "$@" == "flash" ]]; then
echo "flash"
else
echo "unknown command $@" 1>&2
exit 1
fi
EOF
}
TEST_fx_flash_ssh_with_ffx_product_bundle() {
cat >"${fastboot_mock}.mock_side_effects" <<INPUT
if [[ "\$1" == "devices" ]]; then
echo "97300YCABZZ5AA fastboot"
echo " "
fi
INPUT
cat >"${ffx}.mock_side_effects" <<INPUT
if [[ "\$7" == "ssh.pub" ]]; then
echo "${BT_TEMP_DIR}/.ssh/fuchsia_authorized_keys"
fi
INPUT
cat > "${BT_TEMP_DIR}/tools/devshell/get-flash-source.mock_side_effects" <<INPUT
echo product-bundle:obj/build/images/fuchsia/product_bundle
INPUT
mkdir -p "${BT_TEMP_DIR}/out/default/obj/build/images/fuchsia/product_bundle"
BT_EXPECT ${fx} flash --no-build
btf::expect-mock-args "${ffx}.mock_state.7" "ffx" "--config" "fuchsia.analytics.ffx_invoker=fx" "target" "flash" "--product-bundle" "${BT_TEMP_DIR}/out/default/obj/build/images/fuchsia/product_bundle" "--authorized-keys" "${BT_TEMP_DIR}/.ssh/fuchsia_authorized_keys"
}
BT_RUN_TESTS "$@"