aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/test
diff options
context:
space:
mode:
authorGravatar John Cater <jcater@google.com>2016-09-14 11:46:36 +0000
committerGravatar Dmitry Lomov <dslomov@google.com>2016-09-14 14:48:27 +0000
commit1fbb50b947e39f73ba621a490683131c986ca317 (patch)
tree440060b2cc78d6c751b07e8949c41e13d6aeb3db /src/test
parent3617a54ae64fb5ca5a8ed7782c5d3f0c4b57140b (diff)
Open source discard_graph_edges_test.
-- MOS_MIGRATED_REVID=133113800
Diffstat (limited to 'src/test')
-rw-r--r--src/test/shell/integration/BUILD8
-rwxr-xr-xsrc/test/shell/integration/discard_graph_edges_test.sh107
2 files changed, 115 insertions, 0 deletions
diff --git a/src/test/shell/integration/BUILD b/src/test/shell/integration/BUILD
index 958ad1c62e..d57f0d48e8 100644
--- a/src/test/shell/integration/BUILD
+++ b/src/test/shell/integration/BUILD
@@ -129,6 +129,14 @@ sh_test(
data = [":test-deps"],
)
+sh_test(
+ name = "discard_graph_edges_test",
+ size = "medium",
+ srcs = ["discard_graph_edges_test.sh"],
+ data = [":test-deps"],
+ shard_count = 5,
+)
+
test_suite(
name = "all_tests",
visibility = ["//visibility:public"],
diff --git a/src/test/shell/integration/discard_graph_edges_test.sh b/src/test/shell/integration/discard_graph_edges_test.sh
new file mode 100755
index 0000000000..c2212c34a4
--- /dev/null
+++ b/src/test/shell/integration/discard_graph_edges_test.sh
@@ -0,0 +1,107 @@
+#!/bin/bash
+#
+# Copyright 2016 The Bazel Authors. All rights reserved.
+#
+# 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.
+#
+# discard_graph_edges_test.sh: basic tests for the --discard_graph_edges flag.
+
+# Load test environment
+source $(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/testenv.sh \
+ || { echo "testenv.sh not found!" >&2; exit 1; }
+
+create_and_cd_client
+put_bazel_on_path
+write_default_bazelrc
+
+#### SETUP #############################################################
+
+set -e
+
+function set_up() {
+ mkdir -p testing || fail "Couldn't create directory"
+ echo "cc_test(name='mytest', srcs=['mytest.cc'], malloc=':system_malloc')" > testing/BUILD || fail
+ echo "cc_library(name='system_malloc', srcs=[])" >> testing/BUILD || fail
+ echo "int main() {return 0;}" > testing/mytest.cc || fail
+}
+
+STARTUP_FLAGS="--batch"
+BUILD_FLAGS="--keep_going --discard_analysis_cache"
+
+#### TESTS #############################################################
+
+function test_build() {
+ bazel $STARTUP_FLAGS build $BUILD_FLAGS //testing:mytest >& $TEST_log \
+ || fail "Expected success"
+}
+
+function test_test() {
+ bazel $STARTUP_FLAGS test $BUILD_FLAGS //testing:mytest >& $TEST_log \
+ || fail "Expected success"
+}
+
+# bazel info inherits from bazel build, but it doesn't have much in common with it.
+function test_info() {
+ bazel $STARTUP_FLAGS info $BUILD_FLAGS >& $TEST_log || fail "Expected success"
+}
+
+function test_empty_build() {
+ bazel $STARTUP_FLAGS build $BUILD_FLAGS >& $TEST_log || fail "Expected success"
+}
+
+function test_query() {
+ bazel $STARTUP_FLAGS query 'somepath(//testing:mytest,//testing:system_malloc)' >& $TEST_log \
+ || fail "Expected success"
+ expect_log "//testing:mytest"
+ expect_log "//testing:system_malloc"
+}
+
+# Action conflicts can cause deletion of nodes, and deletion is tricky with no edges.
+function test_action_conflict() {
+ mkdir -p conflict || fail "Couldn't create directory"
+ cat > conflict/BUILD <<EOF || fail "Couldn't create BUILD file"
+cc_library(name='x', srcs=['foo.cc'])
+cc_binary(name='_objs/x/conflict/foo.pic.o', srcs=['bar.cc'])
+cc_binary(name='foo', deps=['x'], data=['_objs/x/conflict/foo.pic.o'])
+EOF
+ touch conflict/foo.cc || fail
+ touch conflict/bar.cc || fail
+
+ # --nocache_test_results to make log-grepping easier.
+ bazel $STARTUP_FLAGS test $BUILD_FLAGS --nocache_test_results //conflict:foo //testing:mytest >& $TEST_log \
+ && fail "Expected failure"
+ exit_code=$?
+ [ $exit_code -eq 1 ] || fail "Wrong exit code: $exit_code"
+ expect_log "is generated by these conflicting actions"
+ expect_not_log "Graph edges not stored"
+ expect_log "mytest *PASSED"
+}
+
+# The following tests are not expected to exercise codepath -- make sure nothing bad happens.
+
+function test_no_batch() {
+ bazel $STARTUP_FLAGS --nobatch test $BUILD_FLAGS //testing:mytest >& $TEST_log \
+ || fail "Expected success"
+}
+
+function test_no_keep_going() {
+ bazel $STARTUP_FLAGS test $BUILD_FLAGS --nokeep_going //testing:mytest >& $TEST_log \
+ || fail "Expected success"
+}
+
+function test_no_discard_analysis_cache() {
+ bazel $STARTUP_FLAGS test $BUILD_FLAGS --nodiscard_analysis_cache //testing:mytest >& $TEST_log \
+ || fail "Expected success"
+}
+
+run_suite "test for --discard_graph_edges"