blob: 22c78360be2d461bba018950aa94cf57a0c7b6d2 [file] [log] [blame]
#!/bin/bash
# Copyright 2019 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 basic fx execution flows
export BT_FILE_DEPS=(
"scripts/fx"
"tools/devshell/set"
"tools/devshell/lib/fx-cmd-locator.sh"
"tools/devshell/lib/fx-optional-features.sh"
"tools/devshell/lib/vars.sh"
)
export BT_MOCKED_TOOLS=(
"tools/devshell/lib/metrics.sh"
"tools/devshell/lib/platform.sh"
"_isolated_path_for/git"
)
export BT_MKDIR_DEPS=(
".fx"
".jiri_root"
)
CURRENT_REVISION="abc123"
BT_SET_UP() {
PATH_DIR_FOR_TEST="${BT_TEMP_DIR}/_isolated_path_for"
export PATH="${PATH_DIR_FOR_TEST}:${PATH}"
_FUCHSIA_DIR="${BT_TEMP_DIR}"
fx="${_FUCHSIA_DIR}/scripts/fx"
BT_ASSERT_FILE_EXISTS "${fx}"
cat > "${_FUCHSIA_DIR}/tools/devshell/lib/metrics.sh.mock_side_effects" <<EOF
function track-command-execution {
echo ""
}
function track-command-finished {
echo ""
}
EOF
echo "echo $CURRENT_REVISION" > "${PATH_DIR_FOR_TEST}/git.mock_side_effects"
}
# Neither .fx/fx-set nor .fx/fx-set-revision exists.
TEST_fx-set-clean-build() {
fx_set_output="fx-set running"
# Mock an `fx go` command that produces an `fx-set` executable.
btf::make_mock "${BT_TEMP_DIR}/tools/devshell/go"
fx_set=${_FUCHSIA_DIR}/.fx/fx-set
echo "echo 'echo $fx_set_output' > '$fx_set' && chmod +x '$fx_set'" > "${BT_TEMP_DIR}/tools/devshell/go.mock_side_effects"
output="$(BT_ASSERT "$fx" set myproduct.myboard)"
BT_EXPECT_STRING_CONTAINS_SUBSTRING "$output" "$fx_set_output"
}
# .fx/fx-set and .fx/fx-set-revision both exist, and are up-to-date, so no
# rebuild is necessary.
TEST_fx-set-no-rebuild() {
# If the fx-set-revision and fx-set files are already present, no rebuild
# should happen.
echo "$CURRENT_REVISION" > "${_FUCHSIA_DIR}/.fx/fx-set-revision"
fx_set_output="fx-set running"
echo "echo '$fx_set_output'" > "${_FUCHSIA_DIR}/.fx/fx-set"
chmod +x "${_FUCHSIA_DIR}/.fx/fx-set"
# Make sure `fx go` fails if called.
btf::make_mock "${BT_TEMP_DIR}/tools/devshell/go"
cat > "${BT_TEMP_DIR}/tools/devshell/go.mock_side_effects" << "EOF"
exit 1
EOF
output="$(BT_ASSERT "$fx" set myproduct.myboard)"
BT_EXPECT_STRING_CONTAINS_SUBSTRING "$output" "$fx_set_output"
}
# .fx/fx-set exists but an old revision is stored in .fx/fx-set-revision, so we
# need to rebuild.
TEST_fx-set-out-of-date-rebuild() {
echo "old_revision" > "${_FUCHSIA_DIR}/.fx/fx-set-revision"
fx_set_output="fx-set running"
echo "echo '$fx_set_output'" > "${_FUCHSIA_DIR}/.fx/fx-set"
chmod +x "${_FUCHSIA_DIR}/.fx/fx-set"
# Make sure `fx go` prints a distinctive substring if called.
btf::make_mock "${BT_TEMP_DIR}/tools/devshell/go"
cat > "${BT_TEMP_DIR}/tools/devshell/go.mock_side_effects" << "EOF"
echo "rebuilding"
EOF
output="$(BT_ASSERT "$fx" set myproduct.myboard)"
BT_EXPECT_STRING_CONTAINS_SUBSTRING "$output" "$fx_set_output"
# `fx go build` should have been called.
BT_EXPECT_STRING_CONTAINS_SUBSTRING "$output" "rebuilding"
}
BT_RUN_TESTS "$@"