aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/test
diff options
context:
space:
mode:
Diffstat (limited to 'src/test')
-rw-r--r--src/test/shell/integration/BUILD11
-rw-r--r--src/test/shell/integration/discard_graph_edges_lib.sh99
-rwxr-xr-xsrc/test/shell/integration/discard_graph_edges_test.sh68
3 files changed, 112 insertions, 66 deletions
diff --git a/src/test/shell/integration/BUILD b/src/test/shell/integration/BUILD
index e647ee73f9..1790710358 100644
--- a/src/test/shell/integration/BUILD
+++ b/src/test/shell/integration/BUILD
@@ -197,11 +197,20 @@ sh_test(
data = [":test-deps"],
)
+sh_library(
+ name = "discard_graph_edges_lib",
+ testonly = 1,
+ srcs = ["discard_graph_edges_lib.sh"],
+)
+
sh_test(
name = "discard_graph_edges_test",
size = "medium",
srcs = ["discard_graph_edges_test.sh"],
- data = [":test-deps"],
+ data = [
+ ":discard_graph_edges_lib.sh",
+ ":test-deps",
+ ],
shard_count = 5,
)
diff --git a/src/test/shell/integration/discard_graph_edges_lib.sh b/src/test/shell/integration/discard_graph_edges_lib.sh
new file mode 100644
index 0000000000..84770166ea
--- /dev/null
+++ b/src/test/shell/integration/discard_graph_edges_lib.sh
@@ -0,0 +1,99 @@
+#!/bin/bash
+#
+# Copyright 2017 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_lib.sh: functions needed by discard_graph_edges_test.sh
+
+STARTUP_FLAGS="--batch"
+BUILD_FLAGS="--keep_going --discard_analysis_cache"
+
+function extract_histogram_count() {
+ local histofile="$1"
+ local item="$2"
+ # We can't use + here because Macs don't recognize it as a special character
+ # by default.
+ grep "$item" "$histofile" \
+ | sed -e 's/^ *[0-9][0-9]*: *\([0-9][0-9]*\) .*$/\1/' \
+ || fail "Couldn't get item from $histofile"
+}
+
+function run_test_actions_deleted_after_execution() {
+ readonly local product="$1"
+ readonly local javabase="$2"
+ readonly local get_pid_expression="$3"
+ 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"
+ 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 \$@'
+ )
+EOF
+ for i in $(seq 1 3); do
+ iminus=$((i-1))
+ cat >> histodump/BUILD <<EOF || fail "Couldn't append"
+genrule(name = 'action${i}',
+ srcs = [':action${iminus}'],
+ outs = ['histo.${i}'],
+ local = 1,
+ cmd = 'server_pid=\$\$(cat $server_pid_file) ; ' +
+ '$javabase/bin/jmap -histo:live \$\$server_pid > ' +
+ '\$(location histo.${i}) ' +
+ '|| echo "server_pid in genrule: \$\$server_pid"'
+ )
+EOF
+ done
+ mkfifo "$wait_fifo" "$exec_fifo"
+ local readonly histo_root="$("$product" info \
+ "${PRODUCT_NAME:-$product}-genfiles" 2> /dev/null)/histodump/histo."
+ "$product" clean >& "$TEST_log" || fail "Couldn't clean"
+ "$product" $STARTUP_FLAGS build --show_timestamps $BUILD_FLAGS \
+ $extra_build_arg //histodump:action3 >> "$TEST_log" 2>&1 &
+ subshell_pid="$!"
+ cat "$exec_fifo" > /dev/null
+ if [[ -z "$get_pid_expression" ]]; then
+ server_pid="$subshell_pid"
+ else
+ server_pid="$($get_pid_expression)"
+ fi
+ echo "server_pid in main thread is ${server_pid}" # >> "$TEST_log"
+ 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.
+ 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"
+ local new_genrule_action_count="$(extract_histogram_count "$histo_file" \
+ "GenRuleAction$")"
+ if [[ "$new_genrule_action_count" -ge "$genrule_action_count" ]]; then
+ cat "$histo_file" >> "$TEST_log"
+ fail "Number of genrule actions did not decrease: $new_genrule_action_count vs. $genrule_action_count"
+ fi
+ if [[ -z "$new_genrule_action_count" ]]; then
+ cat "$histo_file" >> "$TEST_log"
+ fail "No genrule actions? Class may have been renamed"
+ fi
+ genrule_action_count="$new_genrule_action_count"
+ done
+}
+
diff --git a/src/test/shell/integration/discard_graph_edges_test.sh b/src/test/shell/integration/discard_graph_edges_test.sh
index e035a44760..3857256a0b 100755
--- a/src/test/shell/integration/discard_graph_edges_test.sh
+++ b/src/test/shell/integration/discard_graph_edges_test.sh
@@ -20,6 +20,8 @@
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 #############################################################
@@ -32,9 +34,6 @@ function set_up() {
echo "int main() {return 0;}" > testing/mytest.cc || fail
}
-STARTUP_FLAGS="--batch"
-BUILD_FLAGS="--keep_going --discard_analysis_cache"
-
#### TESTS #############################################################
function test_build() {
@@ -115,14 +114,6 @@ EOF
[[ -e "bazel-bin/foo/dep.out.aspect" ]] || fail "Aspect bar not run"
}
-function extract_histogram_count() {
- local histofile="$1"
- local item="$2"
- # We can't use + here because Macs don't recognize it as a special character by default.
- grep "$item" "$histofile" | sed -e 's/^ *[0-9][0-9]*: *\([0-9][0-9]*\) .*$/\1/' \
- || fail "Couldn't get item from $histofile"
-}
-
function prepare_histogram() {
readonly local build_args="$1"
rm -rf histodump
@@ -231,60 +222,7 @@ function test_packages_cleared() {
}
function test_actions_deleted_after_execution() {
- rm -rf histodump
- mkdir -p histodump || fail "Couldn't create directory"
- readonly local wait_fifo="$TEST_TMPDIR/wait_fifo"
- readonly local server_pid_file="$TEST_TMPDIR/server_pid.txt"
- cat > histodump/BUILD <<EOF || fail "Couldn't create BUILD file"
-genrule(name = 'action0',
- outs = ['wait.out'],
- local = 1,
- cmd = 'cat $wait_fifo > /dev/null; touch \$@'
- )
-EOF
- for i in $(seq 1 3); do
- iminus=$((i-1))
- cat >> histodump/BUILD <<EOF || fail "Couldn't append"
-genrule(name = 'action${i}',
- srcs = [':action${iminus}'],
- outs = ['histo.${i}'],
- local = 1,
- cmd = 'server_pid=\$\$(cat $server_pid_file) ; ' +
- '${bazel_javabase}/bin/jmap -histo:live \$\$server_pid > ' +
- '\$(location histo.${i}) ' +
- '|| echo "server_pid in genrule: \$\$server_pid"'
- )
-EOF
- done
- mkfifo "$wait_fifo"
- local readonly histo_root="$(bazel info "${PRODUCT_NAME}-genfiles" \
- 2> /dev/null)/histodump/histo."
- bazel clean >& "$TEST_log" || fail "Couldn't clean"
- bazel $STARTUP_FLAGS build --show_timestamps $BUILD_FLAGS \
- //histodump:action3 >> "$TEST_log" 2>&1 &
- server_pid=$!
- echo "server_pid in main thread is ${server_pid}" >> "$TEST_log"
- 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.
- wait "$server_pid" || fail "Bazel command failed"
- local genrule_action_count=100
- for i in $(seq 1 3); do
- local histo_file="$histo_root$i"
- local new_genrule_action_count="$(extract_histogram_count "$histo_file" \
- "GenRuleAction$")"
- if [[ "$new_genrule_action_count" -ge "$genrule_action_count" ]]; then
- cat "$histo_file" >> "$TEST_log"
- fail "Number of genrule actions did not decrease: $new_genrule_action_count vs. $genrule_action_count"
- fi
- if [[ -z "$new_genrule_action_count" ]]; then
- cat "$histo_file" >> "$TEST_log"
- fail "No genrule actions? Class may have been renamed"
- fi
- genrule_action_count="$new_genrule_action_count"
- done
+ run_test_actions_deleted_after_execution bazel "$bazel_javabase" '' ''
}
# Action conflicts can cause deletion of nodes, and deletion is tricky with no edges.