blob: 749e3c9daab7358c10e70a5058b2ba43ca49e6d1 [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
MOCKED_GN="prebuilt/third_party/gn/test/gn"
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"
"tools/devshell/tests/subcommands/data/fx_set_test/myproduct.gni"
"tools/devshell/tests/subcommands/data/fx_set_test/myboard.gni"
)
BT_MOCKED_TOOLS=(
"tools/devshell/lib/metrics.sh"
"tools/devshell/lib/platform.sh"
"${MOCKED_GN}"
)
BT_MKDIR_DEPS=(
".jiri_root"
"products"
"boards"
)
BT_SET_UP() {
_FUCHSIA_DIR="${BT_TEMP_DIR}"
_FUCHSIA_BUILD_DIR="${_FUCHSIA_DIR}/out/default"
fx="${_FUCHSIA_DIR}/scripts/fx"
BT_ASSERT_FILE_EXISTS "${fx}"
cp "${_FUCHSIA_DIR}/tools/devshell/tests/subcommands/data/fx_set_test/myproduct.gni" "${_FUCHSIA_DIR}/products"
cp "${_FUCHSIA_DIR}/tools/devshell/tests/subcommands/data/fx_set_test/myboard.gni" "${_FUCHSIA_DIR}/boards"
cat > "${_FUCHSIA_DIR}/tools/devshell/lib/metrics.sh.mock_side_effects" <<EOF
function track-command-execution {
echo ""
}
function track-command-finished {
echo ""
}
EOF
cat > "${_FUCHSIA_DIR}/tools/devshell/lib/platform.sh.mock_side_effects" <<EOF
readonly PREBUILT_GN="\${FUCHSIA_DIR}/${MOCKED_GN}"
EOF
cat > "${_FUCHSIA_DIR}/${MOCKED_GN}.mock_side_effects" <<EOF
echo "\$@"
EOF
}
# ensure that "fx set product.board" calls gn with the expected args
TEST_fx-set() {
local output="$(${fx} set myproduct.myboard --no-goma)"
BT_EXPECT_STRING_CONTAINS_SUBSTRING "${output}" 'import("//products/myproduct.gni'
BT_EXPECT_STRING_CONTAINS_SUBSTRING "${output}" 'import("//boards/myboard.gni'
BT_EXPECT_STRING_CONTAINS_SUBSTRING "${output}" 'base_package_labels+=[]'
BT_EXPECT_STRING_CONTAINS_SUBSTRING "${output}" 'cache_package_labels+=[]'
BT_EXPECT_STRING_CONTAINS_SUBSTRING "${output}" 'universe_package_labels+=[]'
BT_EXPECT_STRING_CONTAINS_SUBSTRING "${output}" 'host_labels+=[]'
}
# ensure that "fx set product.board --with ..." calls gn with the expected args
TEST_fx-set-with() {
local output="$(${fx} set myproduct.myboard --no-goma --with "//bundles:tests")"
BT_EXPECT_STRING_CONTAINS_SUBSTRING "${output}" 'import("//products/myproduct.gni'
BT_EXPECT_STRING_CONTAINS_SUBSTRING "${output}" 'import("//boards/myboard.gni'
BT_EXPECT_STRING_CONTAINS_SUBSTRING "${output}" 'base_package_labels+=[]'
BT_EXPECT_STRING_CONTAINS_SUBSTRING "${output}" 'cache_package_labels+=[]'
BT_EXPECT_STRING_CONTAINS_SUBSTRING "${output}" 'universe_package_labels+=["//bundles:tests"'
BT_EXPECT_STRING_CONTAINS_SUBSTRING "${output}" 'host_labels+=[]'
}
# ensure that "fx set product.board --with-base ..." calls gn with the expected args
TEST_fx-set-with-base() {
local output="$(${fx} set myproduct.myboard --no-goma --with-base "//bundles:tests")"
BT_EXPECT_STRING_CONTAINS_SUBSTRING "${output}" 'import("//products/myproduct.gni'
BT_EXPECT_STRING_CONTAINS_SUBSTRING "${output}" 'import("//boards/myboard.gni'
BT_EXPECT_STRING_CONTAINS_SUBSTRING "${output}" 'base_package_labels+=["//bundles:tests"'
BT_EXPECT_STRING_CONTAINS_SUBSTRING "${output}" 'cache_package_labels+=[]'
BT_EXPECT_STRING_CONTAINS_SUBSTRING "${output}" 'universe_package_labels+=[]'
BT_EXPECT_STRING_CONTAINS_SUBSTRING "${output}" 'host_labels+=[]'
}
# ensure that "fx set product.board --with-cache ..." calls gn with the expected args
TEST_fx-set-with-cache() {
local output="$(${fx} set myproduct.myboard --no-goma --with-cache "//bundles:tests")"
BT_EXPECT_STRING_CONTAINS_SUBSTRING "${output}" 'import("//products/myproduct.gni'
BT_EXPECT_STRING_CONTAINS_SUBSTRING "${output}" 'import("//boards/myboard.gni'
BT_EXPECT_STRING_CONTAINS_SUBSTRING "${output}" 'base_package_labels+=[]'
BT_EXPECT_STRING_CONTAINS_SUBSTRING "${output}" 'cache_package_labels+=["//bundles:tests"'
BT_EXPECT_STRING_CONTAINS_SUBSTRING "${output}" 'universe_package_labels+=[]'
BT_EXPECT_STRING_CONTAINS_SUBSTRING "${output}" 'host_labels+=[]'
}
# ensure that "fx set product.board --with-host ..." calls gn with the expected args
TEST_fx-set-with-host() {
local output="$(${fx} set myproduct.myboard --no-goma --with-host "//bundles:tests")"
BT_EXPECT_STRING_CONTAINS_SUBSTRING "${output}" 'import("//products/myproduct.gni'
BT_EXPECT_STRING_CONTAINS_SUBSTRING "${output}" 'import("//boards/myboard.gni'
BT_EXPECT_STRING_CONTAINS_SUBSTRING "${output}" 'base_package_labels+=[]'
BT_EXPECT_STRING_CONTAINS_SUBSTRING "${output}" 'cache_package_labels+=[]'
BT_EXPECT_STRING_CONTAINS_SUBSTRING "${output}" 'universe_package_labels+=[]'
BT_EXPECT_STRING_CONTAINS_SUBSTRING "${output}" 'host_labels+=["//bundles:tests"'
}
# ensure that "fx set product.board --fuzz-with ..." calls gn with the expected args
TEST_fx-set-fuzz-with() {
local output="$(${fx} set myproduct.myboard --no-goma --fuzz-with foosan)"
local select_variant='select_variant=\['
select_variant+='{variant="foosan-fuzzer" target_type=\["fuzzed_executable"\]},'
select_variant+='{variant="foosan" label=\["//sdk/lib/fdio"\]},'
select_variant+='\]'
BT_EXPECT_STRING_CONTAINS_SUBSTRING "${output}" "$select_variant"
}
BT_RUN_TESTS "$@"