aboutsummaryrefslogtreecommitdiffhomepage
path: root/tools/test
diff options
context:
space:
mode:
authorGravatar Googler <noreply@google.com>2017-09-19 21:36:12 +0200
committerGravatar László Csomor <laszlocsomor@google.com>2017-09-20 09:03:32 +0200
commit36d2363f5a9cfd95c96c1af5303de2380e57d14e (patch)
tree5d0b92fd1adc2e77ca9a25dc1de126209114b516 /tools/test
parent446f0ba6749cee2a086a7ab0606b8ac3b1fd80d6 (diff)
Add support for writing undeclared outputs to TEST_UNDECLARED_OUTPUTS_DIR and TEST_UNDECLARED_OUTPUTS_ANNOTATIONS_DIR to Bazel.
After this change: - Any files written to the TEST_UNDECLARED_OUTPUTS_DIR directory will be zipped up and added to an outputs.zip file under bazel-testlogs. - Files will be listed in a MANIFEST file under bazel-testlogs. - Any files written to TEST_UNDECLARED_OUTPUTS_ANNOTATIONS_DIR will be concatenated together into an ANNOTATIONS file under bazel-testlogs. This provides a channel for tests to provide extra information outside of the test output itself. This is useful for things like verbose server logs. Note: The //src/test/shell/bazel:bazel_test_test target has a pre-existing breakage (see https://github.com/bazelbuild/bazel/issues/3727). But the new tests pass. RELNOTES: Tests can now write files to TEST_UNDECLARED_OUTPUTS_DIR and TEST_UNDECLARED_OUTPUTS_ANNOTATIONS_DIR and these will be reflected under bazel-testlogs. PiperOrigin-RevId: 169282528
Diffstat (limited to 'tools/test')
-rwxr-xr-xtools/test/test-setup.sh38
1 files changed, 38 insertions, 0 deletions
diff --git a/tools/test/test-setup.sh b/tools/test/test-setup.sh
index 18796c3704..77b02083ba 100755
--- a/tools/test/test-setup.sh
+++ b/tools/test/test-setup.sh
@@ -223,4 +223,42 @@ for signal in $signals; do
done
write_xml_output_file
+# Add all of the files from the undeclared outputs directory to the manifest.
+if [[ -n "$TEST_UNDECLARED_OUTPUTS_DIR" && -n "$TEST_UNDECLARED_OUTPUTS_MANIFEST" ]]; then
+ # For each file, write a tab-separated line with name (relative to
+ # TEST_UNDECLARED_OUTPUTS_DIR), size, and mime type to the manifest. e.g.
+ # foo.txt 9 text/plain
+ while read -r undeclared_output; do
+ rel_path="${undeclared_output#$TEST_UNDECLARED_OUTPUTS_DIR/}"
+ # stat has different flags for different systems. -c is supported by GNU,
+ # and -f by BSD (and thus OSX). Try both.
+ file_size="$(stat -f%z "$undeclared_output" 2>/dev/null || stat -c%s "$undeclared_output" 2>/dev/null || echo "Could not stat $undeclared_output")"
+ file_type="$(file -L -b --mime-type "$undeclared_output")"
+
+ printf "$rel_path\t$file_size\t$file_type\n"
+ done <<< "$(find -L "$TEST_UNDECLARED_OUTPUTS_DIR" -type f | sort)" \
+ > "$TEST_UNDECLARED_OUTPUTS_MANIFEST"
+ if [[ ! -s "$TEST_UNDECLARED_OUTPUTS_MANIFEST" ]]; then
+ rm "$TEST_UNDECLARED_OUTPUTS_MANIFEST"
+ fi
+fi
+
+# Add all of the custom manifest entries to the annotation file.
+if [[ -n "$TEST_UNDECLARED_OUTPUTS_ANNOTATIONS" && \
+ -n "$TEST_UNDECLARED_OUTPUTS_ANNOTATIONS_DIR" && \
+ -d "$TEST_UNDECLARED_OUTPUTS_ANNOTATIONS_DIR" ]]; then
+ (
+ shopt -s failglob
+ cat "$TEST_UNDECLARED_OUTPUTS_ANNOTATIONS_DIR"/*.part > "$TEST_UNDECLARED_OUTPUTS_ANNOTATIONS"
+ ) 2> /dev/null
+fi
+
+# Zip up undeclared outputs.
+if [[ -n "$TEST_UNDECLARED_OUTPUTS_ZIP" ]] && cd "$TEST_UNDECLARED_OUTPUTS_DIR"; then
+ (
+ shopt -s dotglob failglob
+ zip -qr "$TEST_UNDECLARED_OUTPUTS_ZIP" -- *
+ ) 2> /dev/null
+fi
+
exit $exitCode