| #!/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 remote scripts |
| |
| BT_FILE_DEPS=( |
| "scripts/fx" |
| "tools/devshell/flash-remote" |
| "tools/devshell/serve-remote" |
| "tools/devshell/pave-remote" |
| "tools/devshell/lib/fvm.sh" |
| "tools/devshell/lib/fx-cmd-locator.sh" |
| "tools/devshell/lib/fx-flash.sh" |
| "tools/devshell/lib/fx-optional-features.sh" |
| "tools/devshell/lib/fx-remote.sh" |
| "tools/devshell/lib/image_build_vars.sh" |
| "tools/devshell/lib/platform.sh" |
| "tools/devshell/lib/vars.sh" |
| "tools/devshell/lib/verify-default-keys.sh" |
| "tools/devshell/lib/updates.sh" |
| ) |
| |
| declare fx ssh_mock scp_mock local_gensshkeys_mock remote_gensshkeys_mock compare_remote_and_local_mock |
| |
| 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)" |
| ssh_mock=$(btf::make_mock_binary "ssh") |
| btf::add_binary_to_path "$ssh_mock" |
| |
| scp_mock=$(btf::make_mock_binary "scp") |
| btf::add_binary_to_path "$scp_mock" |
| |
| local_gensshkeys_mock="${BT_TEMP_DIR}/tools/ssh-keys/gen-ssh-keys.sh" |
| remote_gensshkeys_mock="${BT_TEMP_DIR}/tools/ssh-keys/remote-gen-ssh-keys.sh" |
| compare_remote_and_local_mock="${BT_TEMP_DIR}/tools/ssh-keys/compare_remote_and_local.sh" |
| btf::make_mock "${local_gensshkeys_mock}" |
| btf::make_mock "${remote_gensshkeys_mock}" |
| btf::make_mock "${compare_remote_and_local_mock}" |
| { |
| echo "function run_remote_gen_ssh_keys { ${remote_gensshkeys_mock} --description \"\$@\"; }" |
| echo "function run_remote_gen_ssh_keys_no_new_key { ${remote_gensshkeys_mock} --no-new-key; }" |
| echo "function compare_remote_and_local { ${compare_remote_and_local_mock} \"\$@\"; }" |
| } >> "${BT_TEMP_DIR}/tools/devshell/lib/verify-default-keys.sh" |
| |
| ffx="$(btf::make_installed_hosttools_mock ffx)" |
| cat > "${ffx}.mock_side_effects" << "EOF" |
| echo "$@" 1>&2 |
| if [[ "$@" == "config get repository.server.mode" ]]; then |
| echo "\"ffx\"" |
| elif [[ "$@" == "config get repository.server.listen" ]]; then |
| echo "\"[::]:8083\"" |
| else |
| echo "127.0.0.1" |
| fi |
| EOF |
| } |
| |
| # test if the host/dir info is correctly stored in the cache file |
| TEST_fx-remote-config-file() { |
| local testhost=myhostname.my.server.com |
| local testdir=~/myfuchsia/directory |
| local out="${BT_TEMP_DIR}/output.log" |
| |
| BT_EXPECT ${fx} serve-remote "$testhost" "$testdir" >>${out} 2>&1 |
| BT_EXPECT_FILE_CONTAINS "${BT_TEMP_DIR}/.fx-remote-config" "${testhost}:${testdir}" |
| } |
| |
| # test if the cache file is used when no argument is given |
| TEST_fx-remote-default-args() { |
| local testhost=myhostname.my.server.com |
| local testdir=~/myfuchsia/directory |
| local out="${BT_TEMP_DIR}/output.log" |
| |
| echo "${testhost}:${testdir}" > "${BT_TEMP_DIR}/.fx-remote-config" |
| BT_EXPECT ${fx} serve-remote >>${out} 2>&1 |
| btf::does-mock-args-contain "${ssh_mock}.mock_state.1" "$testhost" |
| } |
| |
| # test if the given host is used even when there's a cache file, and that the |
| # cache file is updated with the given host |
| TEST_fx-remote-args-given() { |
| local testhost=myhostname.my.server.com |
| local testdir=~/myfuchsia/directory |
| local anotherhost=myhostname.my.server.com |
| local out="${BT_TEMP_DIR}/output.log" |
| |
| echo "${testhost}:${testdir}" > "${BT_TEMP_DIR}/.fx-remote-config" |
| BT_EXPECT ${fx} serve-remote "$anotherhost" "${testdir}" >>${out} 2>&1 |
| BT_EXPECT_FILE_CONTAINS "${BT_TEMP_DIR}/.fx-remote-config" "${anotherhost}:${testdir}" |
| btf::does-mock-args-contain "${ssh_mock}.mock_state.1" "$anotherhost" |
| } |
| |
| # keep in sync with //tools/ssh-keys/gen-ssh-keys.sh |
| readonly _ERROR_NO_KEY=112 |
| readonly _ERROR_MISMATCHED_KEYS=113 |
| # // keep in sync with //tools/ssh-keys/gen-ssh-keys.sh |
| |
| # test pave-remote if the given host is used even when there's a cache file, |
| # and that the cache file is updated with the given host |
| TEST_fx-pave-remote-args-given() { |
| local testhost=myhostname.my.server.com |
| local testdir=~/myfuchsia/directory |
| local anotherhost=myhostname.my.server.com |
| local out="${BT_TEMP_DIR}/output.log" |
| |
| { |
| echo "function fetch_remote_build_artifacts { :; }" |
| echo "function fetch_or_build_tool { :; }" |
| } >> "${BT_TEMP_DIR}/tools/devshell/lib/fx-remote.sh" |
| |
| echo "${testhost}:${testdir}" > "${BT_TEMP_DIR}/.fx-remote-config" |
| BT_EXPECT ${fx} pave-remote --no-pave "$anotherhost" "${testdir}" >>${out} 2>&1 |
| BT_EXPECT_FILE_CONTAINS "${BT_TEMP_DIR}/.fx-remote-config" "${anotherhost}:${testdir}" |
| btf::does-mock-args-contain "${ssh_mock}.mock_state" "$anotherhost" |
| } |
| |
| # test flash-remote if the fetched manifest from fx-remote is properly |
| # forwarded to the fx-flash layer |
| TEST_fx-flash-remote-manifest() { |
| local testhost=myhostname.my.server.com |
| local testdir=~/myfuchsia/directory |
| local out="${BT_TEMP_DIR}/output.log" |
| local artifact_dir="${BT_TEMP_DIR}/out/fetched" |
| local args_file="${BT_TEMP_DIR}/flash.args" |
| |
| { |
| echo "function find_remote_build_artifact { echo flash.json; }" |
| echo "function fetch_remote_build_artifacts { :; }" |
| echo "function fetch_remote_artifacts { :; }" |
| echo "function fetch_or_build_tool { :; }" |
| } >> "${BT_TEMP_DIR}/tools/devshell/lib/fx-remote.sh" |
| |
| { |
| echo "function fx-flash { echo "\$3" > ${args_file} ; }" |
| } >> "${BT_TEMP_DIR}/tools/devshell/lib/fx-flash.sh" |
| |
| mkdir -p "${artifact_dir}" |
| BT_EXPECT ${fx} flash-remote "$testhost" "${testdir}" >>${out} 2>&1 |
| BT_EXPECT_FILE_CONTAINS "$args_file" "${artifact_dir}/flash.json" |
| } |
| |
| BT_RUN_TESTS "$@" |