diff options
author | Will Drewry <drewry@google.com> | 2015-10-26 08:54:06 -0700 |
---|---|---|
committer | Will Drewry <drewry@google.com> | 2015-10-26 11:21:50 -0700 |
commit | afb306e506d03623a92d1eaace760b39ac332dc2 (patch) | |
tree | 131bcf3aaa2c8a709aeef98494282afb7faa3af9 | |
parent | 296de802e44672a5cb864d016ac70ebe334a0cd3 (diff) | |
download | bdk-afb306e506d03623a92d1eaace760b39ac332dc2.tar.gz |
brunch: first integration tests
Until we have a dedicated mock library handy, this
change introduces a basic stubbed integration test
suite for validating all python code paths operate
as expected.
- remove PYTHONPATH fiddling in brunch
- make tools easier to inject a path for
- make envsetup "set -u" clean
- add a simple end to end test script
BUG=25215287
Change-Id: Ic6c5f184ce2e0aabb935f0e051061fcfee61aed4
-rwxr-xr-x | brunch/brunch | 9 | ||||
-rwxr-xr-x | brunch/brunch_tests.sh | 53 | ||||
-rw-r--r-- | brunch/lib/commands/product/tool.py | 10 | ||||
-rw-r--r-- | brunch/lib/core/product_templates.py | 2 | ||||
-rw-r--r-- | brunch/tests/README | 11 | ||||
-rw-r--r-- | brunch/tests/fresh_product.sh | 52 | ||||
-rw-r--r-- | brunch/tests/test_helpers | 55 |
7 files changed, 181 insertions, 11 deletions
diff --git a/brunch/brunch b/brunch/brunch index a8fe449..0cb0c6f 100755 --- a/brunch/brunch +++ b/brunch/brunch @@ -26,12 +26,5 @@ GetPath() { } BRUNCH_ROOT_DIR=$(GetPath "$0") - BRUNCH_LIB_DIR=${BRUNCH_ROOT_DIR}/lib -if [ -z "$PYTHONPATH" ]; then - export PYTHONPATH=${BRUNCH_LIB_DIR} -else - export PYTHONPATH=${BRUNCH_LIB_DIR}:${PYTHONPATH} -fi - -"${BRUNCH_PYTHON}" ${BRUNCH_PYTHON_ARGS} "${BRUNCH_LIB_DIR}/brunch.py" "$@"
\ No newline at end of file +"${BRUNCH_PYTHON}" ${BRUNCH_PYTHON_ARGS} "${BRUNCH_LIB_DIR}/brunch.py" "$@" diff --git a/brunch/brunch_tests.sh b/brunch/brunch_tests.sh new file mode 100755 index 0000000..29afdca --- /dev/null +++ b/brunch/brunch_tests.sh @@ -0,0 +1,53 @@ +#!/bin/bash + +# Copyright (C) 2015 The Android Open Source Project +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# +# This script is a simple harness for executing shell commands from +# the tests/ subdir. +# +# See tests/README for more details. + +GetPath() { + local _path=$(readlink -f $1) + local _brunch_dir=$(dirname $_path) + echo ${_brunch_dir} +} + +brunch_root=$(GetPath $0) + +cd ${brunch_root} +pass=0 +fail=0 +tests=`ls tests/*.sh 2>/dev/null` +rm -f test.1.log test.2.log +for t in $tests; do + echo -n "Running '${t}' . . . " + echo "===== $t =====" >> test.1.log + echo "===== $t =====" >> test.2.log + if bash $t >> test.1.log 2>> test.2.log; then + echo ok + pass=$((pass+1)) + else + echo fail + fail=$((fail+1)) + fi +done + +total=$((pass+fail)) + +echo "$pass/$total tests passed." +echo "$fail/$total tests failed." +exit $fail diff --git a/brunch/lib/commands/product/tool.py b/brunch/lib/commands/product/tool.py index d8adc98..85bac18 100644 --- a/brunch/lib/commands/product/tool.py +++ b/brunch/lib/commands/product/tool.py @@ -25,6 +25,12 @@ from core import util class Tool(clicommand.Command): """Run a host tool for a given product""" + TOOL_PATH_FMT = os.path.join('{0}', 'out', 'out-{1}', + 'host', '{2}', 'bin', '{3}') + + def __init__(self, tool_path_fmt=TOOL_PATH_FMT): + self._tool_path_format = tool_path_fmt + super(Tool, self).__init__() @staticmethod def Args(parser): @@ -42,8 +48,8 @@ class Tool(clicommand.Command): store = config.ProductStore(args.product_path) # TODO(wad) Add arch detection. - tool_path = os.path.join(args.product_path, 'out', 'out-%s' % store.device, - 'host', 'linux-x86', 'bin', args.tool) + tool_path = self._tool_path_format.format( + args.product_path, store.device, 'linux-x86', args.tool) if not os.path.isfile(tool_path): print "The product must be built once prior to using %s." % args.tool return 1 diff --git a/brunch/lib/core/product_templates.py b/brunch/lib/core/product_templates.py index d81045a..332e936 100644 --- a/brunch/lib/core/product_templates.py +++ b/brunch/lib/core/product_templates.py @@ -142,7 +142,7 @@ _envsetup_load() { # Make sure we're in the root of a product. # If the user explicitly exported a PRODUCT_PATH, then fail if it is wrong. - if test -n "$${PRODUCT_PATH}" && \ + if test -n "$${PRODUCT_PATH:-}" && \ ! test -e "$${PRODUCT_PATH}/.brunch_product.db"; then echo "Cannot find a product at PRODUCT_PATH: $${PRODUCT_PATH}" 1>&2 return 1 diff --git a/brunch/tests/README b/brunch/tests/README new file mode 100644 index 0000000..ac0c826 --- /dev/null +++ b/brunch/tests/README @@ -0,0 +1,11 @@ +Each file in this directory should provide a stubbed or faked test for +the brunch command. The primary purpose is not execution correctness, +but to fill the coverage gaps in exercising the python prior to better +unittest coverage. + +Additionally, this path may be used for landing tests for known fixed +bugs to limit regressions where they don't fit into the standard +testing options. + +See test-helpers for an example of how to setup a temporary path +and to stub out backing commands. diff --git a/brunch/tests/fresh_product.sh b/brunch/tests/fresh_product.sh new file mode 100644 index 0000000..ac28e51 --- /dev/null +++ b/brunch/tests/fresh_product.sh @@ -0,0 +1,52 @@ +#!/bin/bash + +# Copyright (C) 2015 The Android Open Source Project +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +. tests/test_helpers + +setup_working_path + +echo "Testing default product creation" +$BRUNCH product create product board +echo "Testing valid configuration" + +cd product +stub_make +stub_tools + +$BRUNCH product config +echo "Run reconfig" +$BRUNCH product reconfig + +echo "Source envsetup.sh" +. ./envsetup.sh + +echo "Build using m -j20" +m -j20 | grep -- -j20 + +echo "Build using mm -j12345" +mm -j12345 | grep -q 'ENVCMD=mm' + +echo "Testing make dist" +$BRUNCH product build dist | grep -q dist + +echo "Testing provision" +provision 1 2 3 4 5 | grep 5 + +echo "Testing adb" +adb 5 4 3 2 1 -help | grep -- -help + +echo "Testing fastboot" +fastboot a b c d e f | grep f diff --git a/brunch/tests/test_helpers b/brunch/tests/test_helpers new file mode 100644 index 0000000..397fc7b --- /dev/null +++ b/brunch/tests/test_helpers @@ -0,0 +1,55 @@ +#!/bin/bash + +# Copyright (C) 2015 The Android Open Source Project +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +set -xue +BRUNCH=$PWD/brunch +HOST_TOOL_PATH=out/out-board/host/linux-$(uname -m | cut -f1 -d_)/bin +TOOL_PATH=out/out-board/target/product/board + +# Changes to a temporary path that cleans itself up. +setup_working_path() { + local tmp=`mktemp -d` + trap "rm -rf $tmp" exit + cd $tmp +} + +# Places make in stubs/ and updates PATH +# Call this from within the product directory. +stub_make() { + echo "Replacing make with a stub" + mkdir stubs + cat <<-EOF >stubs/make + #!/bin/sh + echo "\$0" + while test -n "\$*"; do + echo "\$1" + shift + done + EOF + chmod +x stubs/make + export PATH=$PWD/stubs:$PATH +} + +# Run after stub_make from the same working directory. +# Places per-product tools in the right out/ paths. +# Call this from within the product directory. +stub_tools() { + mkdir -p $HOST_TOOL_PATH + cp stubs/make $HOST_TOOL_PATH/fastboot + cp stubs/make $HOST_TOOL_PATH/adb + mkdir -p $TOOL_PATH + cp stubs/make $TOOL_PATH/provision-device +} |