blob: 9d16b69f3e0193e1d2f130bc9fc799f4ef8399da [file] [log] [blame]
Klaus Aehlig8a8a7fc2016-10-26 14:27:48 +00001#!/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
20CURRENT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
21source "${CURRENT_DIR}/../integration_test_setup.sh" \
22 || { echo "integration_test_setup.sh not found!" >&2; exit 1; }
23
24#### SETUP #############################################################
25
26set -e
27
28function set_up() {
29 mkdir -p pkg
30 cat > pkg/true.sh <<EOF
31#!/bin/sh
32exit 0
33EOF
34 chmod 755 pkg/true.sh
35 cat > pkg/BUILD <<EOF
36sh_test(
37 name = "true",
38 srcs = ["true.sh"],
39)
40test_suite(
41 name = "suite",
42 tests = ["true"],
43)
Klaus Aehlig74d716b2016-11-23 12:38:24 +000044genrule(
45 name = "fails_to_build",
46 outs = ["fails_to_build.txt"],
47 cmd = "false",
48)
Klaus Aehlig8a8a7fc2016-10-26 14:27:48 +000049EOF
50}
51
52#### TESTS #############################################################
53
54function 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
65function 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 Aehlig8d253622016-11-02 17:24:46 +000073function 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 Colaco8d8abe42016-11-03 15:33:47 +000084function test_multiple_transports() {
85 # Verifies usage of multiple build event transports at the same time
Klaus Aehligbac63f22016-11-17 17:10:08 +000086 outdir=$(mktemp -d ${TEST_TMPDIR}/bazel.XXXXXXXX)
Eduardo Colaco8d8abe42016-11-03 15:33:47 +000087 bazel test \
Klaus Aehligbac63f22016-11-17 17:10:08 +000088 --experimental_build_event_text_file=${outdir}/test_multiple_transports.txt \
89 --experimental_build_event_binary_file=${outdir}/test_multiple_transports.bin \
Eduardo Colaco8d8abe42016-11-03 15:33:47 +000090 pkg:suite || fail "bazel test failed"
Klaus Aehligbac63f22016-11-17 17:10:08 +000091 [ -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 Colaco8d8abe42016-11-03 15:33:47 +000093}
94
Klaus Aehlig74d716b2016-11-23 12:38:24 +000095function 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 Aehlig8a8a7fc2016-10-26 14:27:48 +0000110run_suite "Integration tests for the build event stream"