Fix build break
[chromium-blink-merge.git] / tools / valgrind / waterfall.sh
blobfc1830eec499b186a14fb98cae4ddcd56d103f2c
1 #!/bin/bash
3 # Copyright (c) 2011 The Chromium Authors. All rights reserved.
4 # Use of this source code is governed by a BSD-style license that can be
5 # found in the LICENSE file.
7 # This script can be used by waterfall sheriffs to fetch the status
8 # of Valgrind bots on the memory waterfall and test if their local
9 # suppressions match the reports on the waterfall.
11 set -e
13 THISDIR=$(dirname "${0}")
14 LOGS_DIR=$THISDIR/waterfall.tmp
15 WATERFALL_PAGE="http://build.chromium.org/p/chromium.memory/builders"
16 WATERFALL_FYI_PAGE="http://build.chromium.org/p/chromium.memory.fyi/builders"
18 download() {
19 # Download a file.
20 # $1 = URL to download
21 # $2 = Path to the output file
22 # {{{1
23 if [ "$(which curl)" != "" ]
24 then
25 if ! curl -s -o "$2" "$1"
26 then
27 echo
28 echo "Failed to download '$1'... aborting"
29 exit 1
31 elif [ "$(which wget)" != "" ]
32 then
33 if ! wget "$1" -O "$2" -q
34 then
35 echo
36 echo "Failed to download '$1'... aborting"
37 exit 1
39 else
40 echo "Need either curl or wget to download stuff... aborting"
41 exit 1
43 # }}}
46 fetch_logs() {
47 # Fetch Valgrind logs from the waterfall {{{1
49 # TODO(timurrrr,maruel): use JSON, see
50 # http://build.chromium.org/p/chromium.memory/json/help
52 rm -rf "$LOGS_DIR" # Delete old logs
53 mkdir "$LOGS_DIR"
55 echo "Fetching the list of builders..."
56 download $1 "$LOGS_DIR/builders"
57 SLAVES=$(grep "<a href=\"builders\/" "$LOGS_DIR/builders" | \
58 grep 'td class="box"' | \
59 sed "s/.*<a href=\"builders\///" | sed "s/\".*//" | \
60 sort | uniq)
62 for S in $SLAVES
64 SLAVE_URL=$1/$S
65 SLAVE_NAME=$(echo $S | sed -e "s/%20/ /g" -e "s/%28/(/g" -e "s/%29/)/g")
66 echo -n "Fetching builds by slave '${SLAVE_NAME}'"
67 download $SLAVE_URL "$LOGS_DIR/slave_${S}"
69 # We speed up the 'fetch' step by skipping the builds/tests which succeeded.
70 # TODO(timurrrr): OTOH, we won't be able to check
71 # if some suppression is not used anymore.
73 # The awk script here joins the lines ending with </td> to make it possible
74 # to find the failed builds.
75 LIST_OF_BUILDS=$(cat "$LOGS_DIR/slave_$S" | \
76 awk 'BEGIN { buf = "" }
78 if ($0 ~ /<\/td>/) { buf = (buf $0); }
79 else {
80 if (buf) { print buf; buf="" }
81 print $0
84 END {if (buf) print buf}' | \
85 grep "success\|failure" | \
86 head -n 3 | \
87 grep "failure" | \
88 grep -v "failed compile" | \
89 sed "s/.*\/builds\///" | sed "s/\".*//")
91 for BUILD in $LIST_OF_BUILDS
93 # We'll fetch a few tiny URLs now, let's use a temp file.
94 TMPFILE=$(mktemp -t memory_waterfall.XXXXXX)
95 download $SLAVE_URL/builds/$BUILD "$TMPFILE"
97 REPORT_FILE="$LOGS_DIR/report_${S}_${BUILD}"
98 rm -f $REPORT_FILE 2>/dev/null || true # make sure it doesn't exist
100 REPORT_URLS=$(grep -o "[0-9]\+/steps/\(memory\|heapcheck\).*/logs/[0-9A-F]\{16\}" \
101 "$TMPFILE" \
102 || true) # `true` is to succeed on empty output
103 FAILED_TESTS=$(grep -o "[0-9]\+/steps/\(memory\|heapcheck\).*/logs/[A-Za-z0-9_.]\+" \
104 "$TMPFILE" | grep -v "[0-9A-F]\{16\}" \
105 | grep -v "stdio" || true)
107 for REPORT in $REPORT_URLS
109 download "$SLAVE_URL/builds/$REPORT/text" "$TMPFILE"
110 echo "" >> "$TMPFILE" # Add a newline at the end
111 cat "$TMPFILE" | tr -d '\r' >> "$REPORT_FILE"
112 done
114 for FAILURE in $FAILED_TESTS
116 echo -n "FAILED:" >> "$REPORT_FILE"
117 echo "$FAILURE" | sed -e "s/.*\/logs\///" -e "s/\/.*//" \
118 >> "$REPORT_FILE"
119 done
121 rm "$TMPFILE"
122 echo $SLAVE_URL/builds/$BUILD >> "$REPORT_FILE"
123 done
124 echo " DONE"
125 done
126 # }}}
129 match_suppressions() {
130 PYTHONPATH=$THISDIR/../python/google \
131 python "$THISDIR/test_suppressions.py" "$LOGS_DIR/report_"*
134 match_gtest_excludes() {
135 for PLATFORM in "Linux" "Chromium%20Mac" "Chromium%20OS"
137 echo
138 echo "Test failures on ${PLATFORM}:" | sed "s/%20/ /"
139 grep -h -o "^FAILED:.*" -R "$LOGS_DIR"/*${PLATFORM}* | \
140 grep -v "FAILS\|FLAKY" | sort | uniq | \
141 sed -e "s/^FAILED://" -e "s/^/ /"
142 # Don't put any operators between "grep | sed" and "RESULT=$PIPESTATUS"
143 RESULT=$PIPESTATUS
145 if [ "$RESULT" == 1 ]
146 then
147 echo " None!"
148 else
149 echo
150 echo " Note: we don't check for failures already excluded locally yet"
151 echo " TODO(timurrrr): don't list tests we've already excluded locally"
153 done
154 echo
155 echo "Note: we don't print FAILS/FLAKY tests and 1200s-timeout failures"
158 if [ "$1" = "fetch" ]
159 then
160 fetch_logs $WATERFALL_PAGE
161 fetch_logs $WATERFALL_FYI_PAGE
162 elif [ "$1" = "match" ]
163 then
164 match_suppressions
165 match_gtest_excludes
166 elif [ "$1" = "blame" ]
167 then
168 echo The blame command died of bitrot. If you need it, please reimplement it.
169 echo Reimplementation is blocked on http://crbug.com/82688
170 else
171 THISNAME=$(basename "${0}")
172 echo "Usage: $THISNAME fetch|match"
173 echo " fetch - Fetch Valgrind logs from the memory waterfall"
174 echo " match - Test the local suppression files against the downloaded logs"