| #!/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 the helper functions defined in //tools/devshell/README.md#helper-functions | |
| source "$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)"/../../lib/vars.sh || exit $? | |
| declare fx ffx | |
| BT_SET_UP() { | |
| source "${BT_TEMP_DIR}/tools/devshell/tests/lib/fuchsia-mock.sh" | |
| fx="$(btf::setup_fx)" | |
| ffx="$(btf::make_installed_hosttools_mock ffx)" | |
| } | |
| BT_FILE_DEPS=( | |
| "prebuilt/third_party/jq/${HOST_PLATFORM}/bin/jq" | |
| "tools/devshell/jq.fx" | |
| "tools/devshell/lib/fx-cmd-locator.sh" | |
| "tools/devshell/lib/fx-optional-features.sh" | |
| "tools/devshell/lib/generate-ssh-config.sh" | |
| "tools/devshell/lib/vars.sh" | |
| "tools/devshell/lib/is_invoked_by_agent.sh" | |
| "tools/devshell/lib/agents.txt" | |
| "tools/devshell/lib/platform.sh" | |
| ) | |
| unset -f fx-gen | |
| # Replace fx-gen with a stub. | |
| fx-gen() { | |
| return 0 | |
| } | |
| unset -f fx-regenerator | |
| function fx-regenerator { | |
| return 0 | |
| } | |
| TEST_clean_local_environment() { | |
| # This variable should be empty. | |
| BT_EXPECT_EMPTY "${devshell_lib_dir}" | |
| } | |
| TEST_fx-config-read() { | |
| BT_ASSERT_FUNCTION_EXISTS fx-config-read | |
| BT_ASSERT_FUNCTION_EXISTS fx-change-build-dir | |
| local -r BUILD_DIR_REL="out/x64test" | |
| local -r HOST_OUT_REL="host_x64" | |
| local -r EXPECT_BUILD_DIR="${FUCHSIA_DIR}/${BUILD_DIR_REL}" | |
| local -r EXPECT_HOST_OUT="${EXPECT_BUILD_DIR}/${HOST_OUT_REL}" | |
| # fx-build-config-load expects a {build}/fx.config | |
| mkdir -p "${EXPECT_BUILD_DIR}" | |
| { | |
| echo "FUCHSIA_BUILD_DIR='${EXPECT_BUILD_DIR}'" | |
| echo "HOST_OUT_DIR='${HOST_OUT_REL}'" | |
| } > "${EXPECT_BUILD_DIR}/fx.config" | |
| BT_EXPECT "( fx-change-build-dir "${BUILD_DIR_REL}" )" | |
| unset FUCHSIA_BUILD_DIR | |
| unset HOST_OUT_DIR | |
| fx-config-read | |
| BT_EXPECT_EQ "${FUCHSIA_BUILD_DIR}" "${EXPECT_BUILD_DIR}" | |
| BT_EXPECT_EQ "${HOST_OUT_DIR}" "${EXPECT_HOST_OUT}" | |
| } | |
| TEST_fx-info() { | |
| BT_ASSERT_FUNCTION_EXISTS fx-info | |
| # Capture stderr. | |
| local result | |
| result=$( fx-info some info 2>&1 ) | |
| BT_EXPECT_STRING_CONTAINS_SUBSTRING "${result}" "some info" | |
| } | |
| TEST_fx-warn() { | |
| BT_ASSERT_FUNCTION_EXISTS fx-warn | |
| # Capture stderr. | |
| local result | |
| result=$( fx-warn some warning 2>&1 ) | |
| BT_EXPECT_STRING_CONTAINS_SUBSTRING "${result}" "some warning" | |
| } | |
| TEST_fx-error() { | |
| BT_ASSERT_FUNCTION_EXISTS fx-error | |
| # Capture stderr. | |
| local result | |
| result=$( fx-error some error 2>&1 ) | |
| BT_EXPECT_STRING_CONTAINS_SUBSTRING "${result}" "some error" | |
| } | |
| TEST_is-remote-workflow-device() { | |
| BT_ASSERT_FUNCTION_EXISTS is-remote-workflow-device | |
| local -r BUILD_DIR_REL="out/default" | |
| local -r HOST_OUT_REL="host-tools" | |
| local -r EXPECT_BUILD_DIR="${FUCHSIA_DIR}/${BUILD_DIR_REL}" | |
| # fx-build-config-load expects a {build}/fx.config | |
| mkdir -p "${EXPECT_BUILD_DIR}" | |
| { | |
| echo "FUCHSIA_BUILD_DIR='${EXPECT_BUILD_DIR}'" | |
| echo "HOST_OUT_DIR='${HOST_OUT_REL}'" | |
| } > "${EXPECT_BUILD_DIR}/fx.config" | |
| BT_EXPECT "( fx-change-build-dir "${BUILD_DIR_REL}" )" | |
| fx-config-read | |
| echo "foo" > "${ffx}.mock_stdout" | |
| echo "foo" > "${EXPECT_BUILD_DIR}.device" | |
| BT_EXPECT_EQ "foo" "$(get-device-raw)" | |
| BT_EXPECT_FAIL is-remote-workflow-device | |
| echo "${_FX_REMOTE_WORKFLOW_DEVICE_ADDR}" > "${ffx}.mock_stdout" | |
| echo "${_FX_REMOTE_WORKFLOW_DEVICE_ADDR}" > "${EXPECT_BUILD_DIR}.device" | |
| BT_EXPECT_EQ "${_FX_REMOTE_WORKFLOW_DEVICE_ADDR}" "$(get-device-raw)" | |
| BT_EXPECT is-remote-workflow-device | |
| # Test with ffx unbuilt | |
| mv "${ffx}" "${ffx}_unbuilt" | |
| echo "foo" > "${EXPECT_BUILD_DIR}.device" | |
| BT_EXPECT_FAIL is-remote-workflow-device | |
| echo "${_FX_REMOTE_WORKFLOW_DEVICE_ADDR}" > "${EXPECT_BUILD_DIR}.device" | |
| BT_EXPECT is-remote-workflow-device | |
| mv "${ffx}_unbuilt" "${ffx}" | |
| } | |
| BT_RUN_TESTS "$@" |