Klaus Aehlig | 8a8a7fc | 2016-10-26 14:27:48 +0000 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | # |
| 3 | # Copyright 2016 The Bazel Authors. All rights reserved. |
| 4 | # |
| 5 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | # you may not use this file except in compliance with the License. |
| 7 | # You may obtain a copy of the License at |
| 8 | # |
| 9 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | # |
| 11 | # Unless required by applicable law or agreed to in writing, software |
| 12 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | # See the License for the specific language governing permissions and |
| 15 | # limitations under the License. |
| 16 | # |
| 17 | # An end-to-end test that Bazel's experimental UI produces reasonable output. |
| 18 | |
| 19 | # Load the test setup defined in the parent directory |
| 20 | CURRENT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" |
| 21 | source "${CURRENT_DIR}/../integration_test_setup.sh" \ |
| 22 | || { echo "integration_test_setup.sh not found!" >&2; exit 1; } |
| 23 | |
| 24 | #### SETUP ############################################################# |
| 25 | |
| 26 | set -e |
| 27 | |
| 28 | function set_up() { |
| 29 | mkdir -p pkg |
| 30 | cat > pkg/true.sh <<EOF |
| 31 | #!/bin/sh |
| 32 | exit 0 |
| 33 | EOF |
| 34 | chmod 755 pkg/true.sh |
| 35 | cat > pkg/BUILD <<EOF |
| 36 | sh_test( |
| 37 | name = "true", |
| 38 | srcs = ["true.sh"], |
| 39 | ) |
| 40 | test_suite( |
| 41 | name = "suite", |
| 42 | tests = ["true"], |
| 43 | ) |
Klaus Aehlig | 74d716b | 2016-11-23 12:38:24 +0000 | [diff] [blame^] | 44 | genrule( |
| 45 | name = "fails_to_build", |
| 46 | outs = ["fails_to_build.txt"], |
| 47 | cmd = "false", |
| 48 | ) |
Klaus Aehlig | 8a8a7fc | 2016-10-26 14:27:48 +0000 | [diff] [blame] | 49 | EOF |
| 50 | } |
| 51 | |
| 52 | #### TESTS ############################################################# |
| 53 | |
| 54 | function test_basic() { |
| 55 | # Basic properties of the event stream |
| 56 | # - a completed target explicity requested should be reported |
| 57 | # - after success the stream should close naturally, without any |
| 58 | # reports about aborted events. |
| 59 | bazel test --experimental_build_event_text_file=$TEST_log pkg:true \ |
| 60 | || fail "bazel test failed" |
| 61 | expect_log 'pkg:true' |
| 62 | expect_not_log 'aborted' |
| 63 | } |
| 64 | |
| 65 | function test_suite() { |
| 66 | # ...same true when running a test suite containing that test |
| 67 | bazel test --experimental_build_event_text_file=$TEST_log pkg:suite \ |
| 68 | || fail "bazel test failed" |
| 69 | expect_log 'pkg:true' |
| 70 | expect_not_log 'aborted' |
| 71 | } |
| 72 | |
Klaus Aehlig | 8d25362 | 2016-11-02 17:24:46 +0000 | [diff] [blame] | 73 | function test_test_summary() { |
| 74 | # Requesting a test, we expect |
| 75 | # - precisely one test summary (for the single test we run) |
| 76 | # - that is properly chained (no additional progress events) |
| 77 | bazel test --experimental_build_event_text_file=$TEST_log pkg:true \ |
| 78 | || fail "bazel test failed" |
| 79 | expect_log_once '^test_summary ' |
| 80 | expect_log_once '^progress ' |
| 81 | expect_not_log 'aborted' |
| 82 | } |
| 83 | |
Eduardo Colaco | 8d8abe4 | 2016-11-03 15:33:47 +0000 | [diff] [blame] | 84 | function test_multiple_transports() { |
| 85 | # Verifies usage of multiple build event transports at the same time |
Klaus Aehlig | bac63f2 | 2016-11-17 17:10:08 +0000 | [diff] [blame] | 86 | outdir=$(mktemp -d ${TEST_TMPDIR}/bazel.XXXXXXXX) |
Eduardo Colaco | 8d8abe4 | 2016-11-03 15:33:47 +0000 | [diff] [blame] | 87 | bazel test \ |
Klaus Aehlig | bac63f2 | 2016-11-17 17:10:08 +0000 | [diff] [blame] | 88 | --experimental_build_event_text_file=${outdir}/test_multiple_transports.txt \ |
| 89 | --experimental_build_event_binary_file=${outdir}/test_multiple_transports.bin \ |
Eduardo Colaco | 8d8abe4 | 2016-11-03 15:33:47 +0000 | [diff] [blame] | 90 | pkg:suite || fail "bazel test failed" |
Klaus Aehlig | bac63f2 | 2016-11-17 17:10:08 +0000 | [diff] [blame] | 91 | [ -f ${outdir}/test_multiple_transports.txt ] || fail "Missing expected file test_multiple_transports.txt" |
| 92 | [ -f ${outdir}/test_multiple_transports.bin ] || fail "Missing expected file test_multiple_transports.bin" |
Eduardo Colaco | 8d8abe4 | 2016-11-03 15:33:47 +0000 | [diff] [blame] | 93 | } |
| 94 | |
Klaus Aehlig | 74d716b | 2016-11-23 12:38:24 +0000 | [diff] [blame^] | 95 | function test_root_cause_early() { |
| 96 | (bazel build --experimental_build_event_text_file=$TEST_log \ |
| 97 | pkg:fails_to_build && fail "bazel test failed") || true |
| 98 | # We expect precisely one action being reported (the failed one) and |
| 99 | # precisely on report on a completed target; moreover, the action has |
| 100 | # to be reported first. |
| 101 | expect_log_once '^action' |
| 102 | expect_log_once '^completed' |
| 103 | expect_not_log 'success' |
| 104 | local naction=`grep -n '^action' $TEST_log | cut -f 1 -d :` |
| 105 | local ncomplete=`grep -n '^completed' $TEST_log | cut -f 1 -d :` |
| 106 | [ $naction -lt $ncomplete ] \ |
| 107 | || fail "failed action not before compelted target" |
| 108 | } |
| 109 | |
Klaus Aehlig | 8a8a7fc | 2016-10-26 14:27:48 +0000 | [diff] [blame] | 110 | run_suite "Integration tests for the build event stream" |