diff options
author | 2018-01-22 07:53:56 -0800 | |
---|---|---|
committer | 2018-01-22 07:56:03 -0800 | |
commit | 28c20f79e3d265f897e8c644a4c31bd2b3d6ac67 (patch) | |
tree | 9bff0a6a653b741228dd352e6324a0f13946155a /src/test | |
parent | 4c8fa1bab507fa7f0a1cbeac0724751d9b574f89 (diff) |
Add option to optionally wipe state at the end of a build.
This will serve as an alternative to --batch, leaving behind a server without state from the previous build.
RELNOTES: Introduces --[no]keep_state_after_build
PiperOrigin-RevId: 182778500
Diffstat (limited to 'src/test')
-rw-r--r-- | src/test/shell/integration/BUILD | 10 | ||||
-rw-r--r-- | src/test/shell/integration/discard_graph_edges_lib.sh | 27 | ||||
-rwxr-xr-x | src/test/shell/integration/discard_graph_edges_test.sh | 2 | ||||
-rwxr-xr-x | src/test/shell/integration/nonincremental_builds_test.sh | 103 |
4 files changed, 134 insertions, 8 deletions
diff --git a/src/test/shell/integration/BUILD b/src/test/shell/integration/BUILD index 37a19332ce..95f6498193 100644 --- a/src/test/shell/integration/BUILD +++ b/src/test/shell/integration/BUILD @@ -230,6 +230,16 @@ sh_test( ) sh_test( + name = "nonincremental_builds_test", + size = "medium", + srcs = ["nonincremental_builds_test.sh"], + data = [ + ":discard_graph_edges_lib.sh", + ":test-deps", + ], +) + +sh_test( name = "build_event_stream_test", size = "medium", srcs = ["build_event_stream_test.sh"], diff --git a/src/test/shell/integration/discard_graph_edges_lib.sh b/src/test/shell/integration/discard_graph_edges_lib.sh index af51665fb3..88a6c4783f 100644 --- a/src/test/shell/integration/discard_graph_edges_lib.sh +++ b/src/test/shell/integration/discard_graph_edges_lib.sh @@ -36,17 +36,23 @@ function run_test_actions_deleted_after_execution() { readonly local extra_build_arg="$4" rm -rf histodump mkdir -p histodump || fail "Couldn't create directory" - readonly local wait_fifo="$TEST_TMPDIR/wait_fifo" - readonly local exec_fifo="$TEST_TMPDIR/exec_fifo" readonly local server_pid_file="$TEST_TMPDIR/server_pid.txt" + # Use fifo objects to block the execution phase of the dummy build. + readonly local exec_has_started_fifo="$TEST_TMPDIR/exec_fifo" + readonly local unblock_exec_fifo="$TEST_TMPDIR/wait_fifo" + + # Create the chain of four genrules, using fifos to block execution cat > histodump/BUILD <<EOF || fail "Couldn't create BUILD file" genrule(name = 'action0', outs = ['wait.out'], local = 1, - cmd = 'echo "" > $exec_fifo; cat $wait_fifo > /dev/null; touch \$@' + cmd = 'echo "" > $exec_has_started_fifo; ' + + 'cat $unblock_exec_fifo > /dev/null; ' + + 'touch \$@' ) EOF for i in $(seq 1 3); do + # Outputs a histogram of the server's memory, logging failures. iminus=$((i-1)) cat >> histodump/BUILD <<EOF || fail "Couldn't append" genrule(name = 'action${i}', @@ -63,7 +69,8 @@ genrule(name = 'action${i}', ) EOF done - mkfifo "$wait_fifo" "$exec_fifo" + + mkfifo "$unblock_exec_fifo" "$exec_has_started_fifo" local readonly histo_root="$("$product" info \ "${PRODUCT_NAME:-$product}-genfiles" 2> /dev/null)/histodump/histo." "$product" clean >& "$TEST_log" || fail "Couldn't clean" @@ -72,7 +79,10 @@ EOF "$product" $STARTUP_FLAGS build --show_timestamps $BUILD_FLAGS \ $extra_build_arg //histodump:action3 >> "$TEST_log" 2>&1 & subshell_pid="$!" - cat "$exec_fifo" > /dev/null + # We will only get past the following line once execution has started, + # at which point we can look for the pid. + cat "$exec_has_started_fifo" > /dev/null + # We plan to remove batch mode from the relevant flags for discarding # incrementality state. In the interim, tests that are not in batch mode # explicitly pass --nobatch, so we can use it as a signal. @@ -89,9 +99,12 @@ EOF echo "$server_pid" > "$server_pid_file" echo "Finished writing pid to fifo at " >> "$TEST_log" date >> "$TEST_log" - echo "" > "$wait_fifo" - # Wait for previous command to finish. + + # Now that all of the above is finished, unblock the execution of action0 + echo "" > "$unblock_exec_fifo" + # Wait for the build to finish. wait "$subshell_pid" || fail "Bazel command failed" + local genrule_action_count=100 for i in $(seq 1 3); do local histo_file="$histo_root$i" diff --git a/src/test/shell/integration/discard_graph_edges_test.sh b/src/test/shell/integration/discard_graph_edges_test.sh index 0ec8559979..b64a62b8b2 100755 --- a/src/test/shell/integration/discard_graph_edges_test.sh +++ b/src/test/shell/integration/discard_graph_edges_test.sh @@ -434,7 +434,7 @@ function test_warns_on_unexpected_combos() { expect_log "--batch and --discard_analysis_cache specified, but --notrack_incremental_state not specified" bazel build --nobuild --discard_analysis_cache --notrack_incremental_state \ >& "$TEST_log" || fail "Expected success" - expect_log "--batch not specified with --notrack_incremental_state" + expect_log "--notrack_incremental_state was specified, but without --nokeep_state_after_build." } run_suite "test for --discard_graph_edges" diff --git a/src/test/shell/integration/nonincremental_builds_test.sh b/src/test/shell/integration/nonincremental_builds_test.sh new file mode 100755 index 0000000000..56caa676ac --- /dev/null +++ b/src/test/shell/integration/nonincremental_builds_test.sh @@ -0,0 +1,103 @@ +#!/bin/bash +# +# Copyright 2018 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. +# +# nonincremental_builds_test.sh: tests for the --keep_state_after_build flag. +CURRENT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +source "${CURRENT_DIR}/../integration_test_setup.sh" \ + || { echo "integration_test_setup.sh not found!" >&2; exit 1; } +source "${CURRENT_DIR}/discard_graph_edges_lib.sh" \ + || { echo "${CURRENT_DIR}/discard_graph_edges_lib.sh not found!" >&2; exit 1; } + +#### SETUP ############################################################# +set -e + +function tear_down() { + bazel shutdown || fail "Failed to shut down bazel" +} + +#### TESTS ############################################################# +function create_minimal_target() { + rm -rf simpletarget + mkdir simpletarget + cat > simpletarget/BUILD <<EOF || fail "Couldn't make BUILD file" +genrule( + name = 'top', + outs = ['final.out'], + local = 1, + cmd = 'touch \$@' +) +EOF + INCREMENTAL_ANALYSIS_LOGLINE="Analysed target //simpletarget:top (0 packages loaded)" + NONINCREMENTAL_ANALYSIS_LOGLINE="Analysed target //simpletarget:top ([1-9][0-9]* packages loaded)" +} + +# Test that the execution is not repeated, test to validate the test case +# for the nonincremental test below. +function test_build_is_incremental_with_keep_state() { + create_minimal_target + bazel build simpletarget:top &> "$TEST_log" \ + || fail "Couldn't build simpletarget" + expect_log_once $NONINCREMENTAL_ANALYSIS_LOGLINE \ + "First build expected to execute the target." + + bazel build simpletarget:top &> "$TEST_log" \ + || fail "Couldn't build simpletarget" + expect_log_once $INCREMENTAL_ANALYSIS_LOGLINE \ + "Second build not expected to reexecute." +} + +# Test that the execution is actually repeated, indirect test that the state +# was not reused. +function test_build_is_nonincremental_with_nokeep_state() { + create_minimal_target + bazel build --nokeep_state_after_build simpletarget:top &> "$TEST_log" \ + || fail "Couldn't build simpletarget" + expect_log_once $NONINCREMENTAL_ANALYSIS_LOGLINE \ + "First build expected to execute the target." + + bazel build simpletarget:top &> "$TEST_log" \ + || fail "Couldn't build simpletarget" + expect_log_once $NONINCREMENTAL_ANALYSIS_LOGLINE \ + "Second build should not use the cached state." +} + +# Test directly that the inmemory state does persist after the build by default. +function test_inmemory_state_present_after_build() { + create_minimal_target + bazel build simpletarget:top &> "$TEST_log" \ + || fail "Couldn't build simpletarget" + local server_pid="$(bazel info server_pid 2>> "$TEST_log")" + "$bazel_javabase"/bin/jmap -histo:live "$server_pid" > histo.txt + + cat histo.txt >> "$TEST_log" + assert_contains "GenRuleAction" histo.txt + assert_contains "InMemoryNodeEntry" histo.txt +} + +# Test directly that the inmemory state does not persist after the build. +function test_inmemory_state_absent_after_build_with_nokeep_state() { + create_minimal_target + bazel build --nokeep_state_after_build simpletarget:top &> "$TEST_log" \ + || fail "Couldn't build simpletarget" + local server_pid="$(bazel info server_pid 2>> "$TEST_log")" + "$bazel_javabase"/bin/jmap -histo:live "$server_pid" > histo.txt + + cat histo.txt >> "$TEST_log" + assert_not_contains "GenRuleAction" histo.txt + assert_not_contains "InMemoryNodeEntry" histo.txt +} + +run_suite "test for --keep_state_after_build" |