jjb: binutils-gdb: collect test result artifacts in gerrit job
[lttng-ci.git] / scripts / binutils-gdb / build.sh
CommitLineData
91ba8aa1
MJ
1#!/bin/bash
2#
3# Copyright (C) 2021 Michael Jeanson <mjeanson@efficios.com>
4#
5# This program is free software: you can redistribute it and/or modify
6# it under the terms of the GNU General Public License as published by
7# the Free Software Foundation, either version 3 of the License, or
8# (at your option) any later version.
9#
10# This program is distributed in the hope that it will be useful,
11# but WITHOUT ANY WARRANTY; without even the implied warranty of
12# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13# GNU General Public License for more details.
14#
15# You should have received a copy of the GNU General Public License
16# along with this program. If not, see <http://www.gnu.org/licenses/>.
17
18set -exu
19
20failed_configure() {
21 # Assume we are in the configured build directory
22 echo "#################### BEGIN config.log ####################"
23 cat config.log
24 echo "#################### END config.log ####################"
25 exit 1
26}
27
28sum2junit() {
29 local infile="$1"
30 local outfile="$2"
31
bcd0bdf1
SM
32cat <<EOF > sum2junit.py
33import sys
34from datetime import datetime
35import re
36from xml.etree.ElementTree import ElementTree, Element, SubElement
37
38line_re = re.compile(
39 r"^(PASS|XPASS|FAIL|XFAIL|KFAIL|DUPLICATE|UNTESTED|UNSUPPORTED|UNRESOLVED): (.*?\.exp): (.*)"
40)
41
42pass_count = 0
43fail_count = 0
44skip_count = 0
45error_count = 0
46now = datetime.now().isoformat(timespec="seconds")
47
48testsuites = Element(
49 "testsuites",
50 {
51 "xmlns": "https://raw.githubusercontent.com/windyroad/JUnit-Schema/master/JUnit.xsd"
52 },
53)
54testsuite = SubElement(
55 testsuites,
56 "testsuite",
57 {
58 "name": "GDB",
59 "package": "package",
60 "id": "0",
61 "time": "1",
62 "timestamp": now,
63 "hostname": "hostname",
64 },
65)
66SubElement(testsuite, "properties")
67
68for line in sys.stdin:
69 m = line_re.match(line)
70 if not m:
71 continue
72
73 state, exp_filename, test_name = m.groups()
74
75 testcase_name = "{} - {}".format(exp_filename, test_name)
76
77 testcase = SubElement(
78 testsuite,
79 "testcase",
80 {"name": testcase_name, "classname": "classname", "time": "0"},
81 )
82
83 if state in ("PASS", "XFAIL", "KFAIL"):
84 pass_count += 1
85 elif state in ("FAIL", "XPASS"):
86 fail_count += 1
87 SubElement(testcase, "failure", {"type": state})
88 elif state in ("UNRESOLVED", "DUPLICATE"):
89 error_count += 1
90 SubElement(testcase, "error", {"type": state})
91 elif state in ("UNTESTED", "UNSUPPORTED"):
92 skip_count += 1
93 SubElement(testcase, "skipped")
94 else:
95 assert False
96
97testsuite.attrib["tests"] = str(pass_count + fail_count + skip_count)
98testsuite.attrib["failures"] = str(fail_count)
99testsuite.attrib["skipped"] = str(skip_count)
100testsuite.attrib["errors"] = str(error_count)
101
102SubElement(testsuite, "system-out")
103SubElement(testsuite, "system-err")
104
105et = ElementTree(testsuites)
106et.write(sys.stdout, encoding="unicode")
107
108sys.exit(1 if fail_count > 0 or error_count > 0 else 0)
91ba8aa1
MJ
109EOF
110
bcd0bdf1 111 python3 sum2junit.py < "$infile" > "$outfile"
91ba8aa1
MJ
112}
113
114# Required variables
115WORKSPACE=${WORKSPACE:-}
116
117arch=${arch:-}
118conf=${conf:-}
119build=${build:-}
120cc=${cc:-}
121
122
123SRCDIR="$WORKSPACE/src/binutils-gdb"
124TMPDIR="$WORKSPACE/tmp"
125PREFIX="/build"
126
127# Create tmp directory
128rm -rf "$TMPDIR"
129mkdir -p "$TMPDIR"
130
131export TMPDIR
132export CFLAGS="-O2 -fsanitize=address"
133export CXXFLAGS="-O2 -fsanitize=address -D_GLIBCXX_DEBUG=1"
134export LDFLAGS="-fsanitize=address"
135
136# Set platform variables
137case "$arch" in
138*)
139 export MAKE=make
140 export TAR=tar
141 export NPROC=nproc
142 ;;
143esac
144
145# Print build env details
146print_os || true
147print_tooling || true
148
149# Enter the source directory
150cd "$SRCDIR"
151
152# Run bootstrap in the source directory prior to configure
153#./bootstrap
154
155# Get source version from configure script
156#eval "$(grep '^PACKAGE_VERSION=' ./configure)"
157#PACKAGE_VERSION=${PACKAGE_VERSION//\-pre*/}
158
159# Set configure options and environment variables for each build
160# configuration.
161CONF_OPTS=("--prefix=$PREFIX")
162
163case "$conf" in
164*)
165 echo "Standard configuration"
166
167 # Use system tools
168 CONF_OPTS+=("--disable-binutils" "--disable-ld" "--disable-gold" "--disable-gas" "--disable-sim" "--disable-gprof")
169
170 # Use system libs
171 CONF_OPTS+=("--with-system-readline" "--with-system-zlib")
172
173 # Enable optional features
174 CONF_OPTS+=("--enable-targets=all" "--with-expat=yes" "--with-python=python3" "--with-guile=guile-2.2" "--enable-libctf")
175
176 CONF_OPTS+=("--enable-build-warnings" "--enable-gdb-build-warnings" "--enable-unit-tests")
177
178 ;;
179esac
180
181# Build type
182# oot : out-of-tree build
183# dist : build via make dist
184# oot-dist: build via make dist out-of-tree
185# * : normal tree build
186#
187# Make sure to move to the build directory and run configure
188# before continuing.
189case "$build" in
190*)
191 echo "Out of tree build"
192
193 # Create and enter a temporary build directory
194 builddir=$(mktemp -d)
195 cd "$builddir"
196
197 "$SRCDIR/configure" "${CONF_OPTS[@]}" || failed_configure
198 ;;
199esac
200
201# We are now inside a configured build directory
202
203# BUILD!
204$MAKE -j "$($NPROC)" V=1 MAKEINFO=/bin/true
205
206# Install in the workspace
207$MAKE install DESTDIR="$WORKSPACE"
208
bcd0bdf1
SM
209# Run tests, don't fail now, we know that "make check" is going to fail,
210# since some tests don't pass.
adb01414
SM
211#
212# Disable ASan leaks reporting, it might break some tests since it adds
213# unexpected output when GDB exits.
bcd0bdf1 214ASAN_OPTIONS=detect_leaks=0 $MAKE -C gdb --keep-going check -j "$($NPROC)" || true
91ba8aa1
MJ
215
216# Copy the dejagnu test results for archiving before cleaning the build dir
217mkdir "${WORKSPACE}/results"
f5dbc8e5 218cp gdb/testsuite/gdb.log "${WORKSPACE}/results/"
91ba8aa1 219cp gdb/testsuite/gdb.sum "${WORKSPACE}/results/"
bcd0bdf1
SM
220
221# Convert results to JUnit format.
222failed_tests=0
223sum2junit gdb/testsuite/gdb.sum "${WORKSPACE}/results/gdb.xml" || failed_tests=1
91ba8aa1
MJ
224
225# Clean the build directory
226$MAKE clean
227
228# Cleanup rpath in executables and shared libraries
229#find "$WORKSPACE/$PREFIX/bin" -type f -perm -0500 -exec chrpath --delete {} \;
230#find "$WORKSPACE/$PREFIX/lib" -name "*.so" -exec chrpath --delete {} \;
231
232# Remove libtool .la files
233find "$WORKSPACE/$PREFIX/lib" -name "*.la" -exec rm -f {} \;
234
235# Exit with failure if any of the tests failed
236exit $failed_tests
237
238# EOF
This page took 0.030913 seconds and 4 git commands to generate.