| #!/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" | |
| 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" | |
| "tools/devshell/tests/subcommands/data/fx_set_test/myproduct.gni" | |
| "tools/devshell/tests/subcommands/data/fx_set_test/myboard.gni" | |
| ) | |
| export BT_MOCKED_TOOLS=( | |
| "tools/devshell/lib/metrics.sh" | |
| "tools/devshell/lib/platform.sh" | |
| "${MOCKED_GN}" | |
| ) | |
| export BT_MKDIR_DEPS=( | |
| ".jiri_root" | |
| "products" | |
| "boards" | |
| ) | |
| BT_SET_UP() { | |
| # These tests are specific to the legacy version of fx set. | |
| export FUCHSIA_DISABLED_legacy_set=0 | |
| _FUCHSIA_DIR="${BT_TEMP_DIR}" | |
| 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 | |
| local build_dir="$_FUCHSIA_DIR/out/default" | |
| cat > "${_FUCHSIA_DIR}/${MOCKED_GN}.mock_side_effects" <<EOF | |
| # The mocked GN executable needs to produce an 'fx.config' file in the output | |
| # directory, or else 'fx-change-build-dir' will fail. | |
| mkdir -p "$build_dir" | |
| touch "${build_dir}/fx.config" | |
| # Print the GN command line so that tests can inspect stdout to see what | |
| # arguments 'fx set' passed to GN. | |
| echo "\$@" | |
| EOF | |
| } | |
| # ensure that "fx set product.board" calls gn with the expected args | |
| TEST_fx-set() { | |
| local output | |
| output="$(BT_ASSERT "$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 | |
| output="$(BT_ASSERT "$fx" set myproduct.myboard --no-goma --with //bundles:tests,//src:tests --with //tools: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","//src:tests","//tools: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 | |
| output="$(BT_ASSERT "$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 | |
| output="$(BT_ASSERT "$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 | |
| output="$(BT_ASSERT "$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 | |
| output="$(BT_ASSERT "$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 "$@" |