blob: 85faa5fd8d97a688f6f0fe04276158dade4c529d [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 expected usage of ffx target list in fx scripts
BT_FILE_DEPS=(
"scripts/fx"
"tools/devshell/lib/vars.sh"
"tools/devshell/lib/fx-cmd-locator.sh"
"tools/devshell/lib/fx-optional-features.sh"
"tools/devshell/lib/platform.sh"
"tools/devshell/set-device"
"tools/devshell/get-device-addr"
"tools/devshell/shell"
)
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)"
}
not_expect_args() {
local mock_state_file="$1"
shift
for arg in "$@"; do
if btf::does-mock-args-contain "${mock_state_file}" "$arg"; then
btf::_fail 1 "Argument ${arg} found but not expected in call to ffx: ${mock_state_file}"
return 1
fi
done
}
expect_args() {
local mock_state_file="$1"
shift
for arg in "$@"; do
if btf::does-mock-args-not-contain "${mock_state_file}" "$arg"; then
btf::_fail 1 "Expected argument ${arg} not found in call to ffx: ${mock_state_file}"
return 1
fi
done
}
# ensure that set-device invocations of ffx use the proper network flags
TEST_setdevice() {
${fx} set-device >/dev/null 2>&1
expect_args "${ffx}.mock_state" "target" "list" "--format" "s"
}
# ensure that get-fuchsia-device-addr doesn't try to resolve IPv4 addresses
TEST_getdeviceaddr_resolved_ipv4_addresses() {
local addrs=("127.0.0.1" "255.255.255.255" "1.0.0.1")
for addr in "${addrs[@]}"; do
BT_EXPECT_EQ "$(${fx} -d "${addr}" get-device-addr)" "${addr}"
BT_EXPECT_EQ "$(${fx} -d "${addr}:8022" get-device-addr)" "${addr}"
BT_EXPECT_FILE_DOES_NOT_EXIST "${ffx}.mock_state"
BT_EXPECT_FILE_DOES_NOT_EXIST "${ffx}.mock_state.1"
done
}
# ensure that get-fuchsia-device-addr doesn't try to resolve IPv6 addresses
# using "fx set-device 'address'"
TEST_getdeviceaddr_resolved_ipv6_addresses_setdevice() {
local addrs=("1:2:3:4" "1::" "b1::8" "1:2:3:4:5:6::8" \
"1:2:3:4:5:6::8" "1::7:f8" "1:a2:3:b4:5::7:8" "1:2:3:d4:5e::8" "a1::6:7:8" \
"1:2:c3:4a::6:7:8f" "1:2:3:4::8" "1::5:6:d7:8" "1:2:3::5:6:7:8" "d1:2:3::8" \
"1::4:5:6:7:8" "1:2::4:5:6:7:8" "1:2::8" "c1::e3:4:5:6:7:8" "1::3:4:5:6:7:8" \
"c1::8" "::8" "::" "fe80::7:8%eth0" "fe80::7:8%1" )
for addr in "${addrs[@]}"; do
# fx syntax requires that IPv6 address is surrounded by square brackets
BT_EXPECT ${fx} set-device "[${addr}]" >/dev/null
BT_EXPECT_EQ "$(${fx} get-device-addr)" "${addr}"
BT_EXPECT_FILE_DOES_NOT_EXIST "${ffx}.mock_state"
BT_EXPECT_FILE_DOES_NOT_EXIST "${ffx}.mock_state.1"
done
}
# ensure that get-fuchsia-device-addr doesn't try to resolve IPv6 addresses
# using "fx -d 'address' ..."
TEST_getdeviceaddr_resolved_ipv6_addresses() {
local addrs=("1:2:3:4" "1::" "b1::8" "1:2:3:4:5:6::8" \
"1:2:3:4:5:6::8" "1::7:f8" "1:a2:3:b4:5::7:8" "1:2:3:d4:5e::8" "a1::6:7:8" \
"1:2:c3:4a::6:7:8f" "1:2:3:4::8" "1::5:6:d7:8" "1:2:3::5:6:7:8" "d1:2:3::8" \
"1::4:5:6:7:8" "1:2::4:5:6:7:8" "1:2::8" "c1::e3:4:5:6:7:8" "1::3:4:5:6:7:8" \
"c1::8" "::8" "::" "fe80::7:8%eth0" "fe80::7:8%1" )
for addr in "${addrs[@]}"; do
# fx syntax requires that IPv6 address is surrounded by square brackets
BT_EXPECT_EQ "$(${fx} -d "[${addr}]" get-device-addr)" "${addr}"
# also test with ssh port
BT_EXPECT_FILE_DOES_NOT_EXIST "${ffx}.mock_state"
BT_EXPECT_FILE_DOES_NOT_EXIST "${ffx}.mock_state.1"
done
}
# test a name that looks like an ipv4 ip but is not
TEST_getdeviceaddr_name_looks_like_ipv4() {
local name="1.1.244"
ip="127.0.0.1"
echo "${ip}" > "${ffx}.mock_stdout"
BT_EXPECT_EQ "$(${fx} -d "${name}" get-device-addr)" "${ip}"
}
# ensure that get-fuchsia-device-addr invocations of ffx use the proper network flags
TEST_getdeviceaddr_singledevice() {
local ip="fe80::c0ff:eec0:ffee%coffee"
echo "${ip}" > "${ffx}.mock_stdout"
${fx} get-device-addr >/dev/null
not_expect_args "${ffx}.mock_state" "-mdns=false"
}
# ensure that get-fuchsia-device-addr invocations of ffx use the proper network flags
TEST_getdeviceaddr_multipledevice() {
local ip1="ccff::c0ff:eec0:ffee%coffee"
local ip2="00ee::c0ff:eec0:ffee%coffee"
echo -e "${ip1}\n${ip2}" > "${ffx}.mock_stdout"
# in this test we don't care about the results of get-device-addr
${fx} get-device-addr >/dev/null 2>&1
# first ffx call is for a regular list and
# second ffx call is for a -full list. Both require the same network
# flags.
not_expect_args "${ffx}.mock_state.1" "-mdns=false"
not_expect_args "${ffx}.mock_state.2" "-mdns=false"
}
BT_RUN_TESTS "$@"