diff options
author | Dan Willemsen <dwillemsen@google.com> | 2015-07-22 17:05:51 -0700 |
---|---|---|
committer | Dan Willemsen <dwillemsen@google.com> | 2015-07-23 22:04:42 -0700 |
commit | f04c55172fb4810fc8aa463322a40ac130375df7 (patch) | |
tree | f045680f46c573f867c68e0a159801f10cf971cf | |
parent | 21b6f37ceeb18a81e4e712d575d1f56a55775132 (diff) | |
download | android_build_blueprint-f04c55172fb4810fc8aa463322a40ac130375df7.tar.gz android_build_blueprint-f04c55172fb4810fc8aa463322a40ac130375df7.tar.bz2 android_build_blueprint-f04c55172fb4810fc8aa463322a40ac130375df7.zip |
Add test suite for bootstrapping
This only checks to make sure that for a given updated file, the
bootstrap stage is properly run. It doesn't actually check to make sure
that anything was rebuilt.
Change-Id: I9cb6ff1d483264da30e43d5580361d93b148f42c
-rw-r--r-- | .gitignore | 1 | ||||
-rw-r--r-- | .travis.yml | 1 | ||||
-rw-r--r-- | bootstrap/bootstrap.go | 2 | ||||
-rw-r--r-- | build.ninja.in | 2 | ||||
-rwxr-xr-x | tests/bootstrap.bash | 7 | ||||
-rw-r--r-- | tests/expected_all | 2 | ||||
-rw-r--r-- | tests/expected_manifest | 2 | ||||
-rw-r--r-- | tests/expected_none | 0 | ||||
-rw-r--r-- | tests/expected_rebuild_test | 2 | ||||
-rw-r--r-- | tests/expected_regen | 2 | ||||
-rw-r--r-- | tests/expected_start | 1 | ||||
-rw-r--r-- | tests/expected_start2 | 1 | ||||
-rw-r--r-- | tests/expected_start_add_tests | 1 | ||||
-rwxr-xr-x | tests/test.sh | 89 |
14 files changed, 111 insertions, 2 deletions
diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..de99854 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +out.test diff --git a/.travis.yml b/.travis.yml index 5b17240..9268df0 100644 --- a/.travis.yml +++ b/.travis.yml @@ -11,3 +11,4 @@ script: - ../bootstrap.bash - ninja - diff -us ../build.ninja.in ../build.ninja.in.orig + - ../tests/test.sh diff --git a/bootstrap/bootstrap.go b/bootstrap/bootstrap.go index 1b6d4e7..66a4036 100644 --- a/bootstrap/bootstrap.go +++ b/bootstrap/bootstrap.go @@ -70,7 +70,7 @@ var ( bootstrap = pctx.StaticRule("bootstrap", blueprint.RuleParams{ - Command: "$bootstrapCmd -i $in", + Command: "echo \"Choosing $$(basename $in) for next stage\" && $bootstrapCmd -i $in", Description: "bootstrap $in", Generator: true, }) diff --git a/build.ninja.in b/build.ninja.in index 0bc9450..77661e9 100644 --- a/build.ninja.in +++ b/build.ninja.in @@ -32,7 +32,7 @@ g.bootstrap.srcDir = @@SrcDir@@ builddir = .bootstrap rule g.bootstrap.bootstrap - command = ${g.bootstrap.bootstrapCmd} -i ${in} + command = echo "Choosing $$(basename ${in}) for next stage" && ${g.bootstrap.bootstrapCmd} -i ${in} description = bootstrap ${in} generator = true diff --git a/tests/bootstrap.bash b/tests/bootstrap.bash new file mode 100755 index 0000000..4b58b19 --- /dev/null +++ b/tests/bootstrap.bash @@ -0,0 +1,7 @@ +#!/bin/bash + +export BOOTSTRAP="${BASH_SOURCE[0]}" +export SRCDIR=".." +export BOOTSTRAP_MANIFEST="src.build.ninja.in" + +../bootstrap.bash "$@" diff --git a/tests/expected_all b/tests/expected_all new file mode 100644 index 0000000..380b0cc --- /dev/null +++ b/tests/expected_all @@ -0,0 +1,2 @@ +Choosing build.ninja.in for next stage +Choosing main.ninja.in for next stage diff --git a/tests/expected_manifest b/tests/expected_manifest new file mode 100644 index 0000000..380b0cc --- /dev/null +++ b/tests/expected_manifest @@ -0,0 +1,2 @@ +Choosing build.ninja.in for next stage +Choosing main.ninja.in for next stage diff --git a/tests/expected_none b/tests/expected_none new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/tests/expected_none diff --git a/tests/expected_rebuild_test b/tests/expected_rebuild_test new file mode 100644 index 0000000..162d1db --- /dev/null +++ b/tests/expected_rebuild_test @@ -0,0 +1,2 @@ +Choosing src.build.ninja.in for next stage +Choosing main.ninja.in for next stage diff --git a/tests/expected_regen b/tests/expected_regen new file mode 100644 index 0000000..162d1db --- /dev/null +++ b/tests/expected_regen @@ -0,0 +1,2 @@ +Choosing src.build.ninja.in for next stage +Choosing main.ninja.in for next stage diff --git a/tests/expected_start b/tests/expected_start new file mode 100644 index 0000000..dc55ac3 --- /dev/null +++ b/tests/expected_start @@ -0,0 +1 @@ +Choosing main.ninja.in for next stage diff --git a/tests/expected_start2 b/tests/expected_start2 new file mode 100644 index 0000000..dc55ac3 --- /dev/null +++ b/tests/expected_start2 @@ -0,0 +1 @@ +Choosing main.ninja.in for next stage diff --git a/tests/expected_start_add_tests b/tests/expected_start_add_tests new file mode 100644 index 0000000..dc55ac3 --- /dev/null +++ b/tests/expected_start_add_tests @@ -0,0 +1 @@ +Choosing main.ninja.in for next stage diff --git a/tests/test.sh b/tests/test.sh new file mode 100755 index 0000000..08caa64 --- /dev/null +++ b/tests/test.sh @@ -0,0 +1,89 @@ +#!/bin/bash + +# Go to srcdir +cd $(dirname ${BASH_SOURCE[0]})/.. + +rm -rf out.test +mkdir out.test +cd out.test +../bootstrap.bash + +# Run ninja, filter the output, and compare against expectations +# $1: Name of test +function testcase() +{ + echo -n "Running $1..." + if ! ninja -v -d explain >log_$1 2>&1; then + echo " Failed." + echo "Test $1 Failed:" >>failed + tail log_$1 >>failed + return + fi + grep -E "^(Choosing|Newer|Stage)" log_$1 >test_$1 + if ! cmp -s test_$1 ../tests/expected_$1; then + echo " Failed." + echo "Test $1 Failed:" >>failed + diff -u ../tests/expected_$1 test_$1 >>failed + else + echo " Passed." + fi +} + + + + +testcase start + +# The 2 second sleeps are needed until ninja understands sub-second timestamps +# https://github.com/martine/ninja/issues/371 + +# This test affects all bootstrap stages +sleep 2 +touch ../Blueprints +testcase all + +# This test affects nothing, nothing should be done +sleep 2 +testcase none + +# This test will cause the source build.ninja.in to be copied into the first +# stage. +sleep 2 +touch ../build.ninja.in +testcase manifest + +# From now on, we're going to be modifying the build.ninja.in, so let's make our +# own copy +sleep 2 +../tests/bootstrap.bash -r + +sleep 2 +testcase start2 + +# This is similar to the last test, but incorporates a change into the source +# build.ninja.in, so that we'll restart into the new version created by the +# build. +sleep 2 +echo "# test" >>src.build.ninja.in +testcase regen + +# Add tests to our build by using '-t' +sleep 2 +../tests/bootstrap.bash -r -t + +sleep 2 +testcase start_add_tests + +# Make sure that updating a test file causes us to go back to the bootstrap +# stage +sleep 2 +touch ../parser/parser_test.go +testcase rebuild_test + + + + +if [ -f failed ]; then + cat failed + exit 1 +fi |