Commit | Line | Data |
---|---|---|
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 | ||
18 | set -exu | |
19 | ||
20 | failed_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 | ||
28 | sum2junit() { | |
29 | local infile="$1" | |
30 | local outfile="$2" | |
31 | ||
bcd0bdf1 SM |
32 | cat <<EOF > sum2junit.py |
33 | import sys | |
34 | from datetime import datetime | |
35 | import re | |
36 | from xml.etree.ElementTree import ElementTree, Element, SubElement | |
37 | ||
38 | line_re = re.compile( | |
39 | r"^(PASS|XPASS|FAIL|XFAIL|KFAIL|DUPLICATE|UNTESTED|UNSUPPORTED|UNRESOLVED): (.*?\.exp): (.*)" | |
40 | ) | |
41 | ||
42 | pass_count = 0 | |
43 | fail_count = 0 | |
44 | skip_count = 0 | |
45 | error_count = 0 | |
46 | now = datetime.now().isoformat(timespec="seconds") | |
47 | ||
48 | testsuites = Element( | |
49 | "testsuites", | |
50 | { | |
51 | "xmlns": "https://raw.githubusercontent.com/windyroad/JUnit-Schema/master/JUnit.xsd" | |
52 | }, | |
53 | ) | |
54 | testsuite = 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 | ) | |
66 | SubElement(testsuite, "properties") | |
67 | ||
68 | for 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 | ||
97 | testsuite.attrib["tests"] = str(pass_count + fail_count + skip_count) | |
98 | testsuite.attrib["failures"] = str(fail_count) | |
99 | testsuite.attrib["skipped"] = str(skip_count) | |
100 | testsuite.attrib["errors"] = str(error_count) | |
101 | ||
102 | SubElement(testsuite, "system-out") | |
103 | SubElement(testsuite, "system-err") | |
104 | ||
105 | et = ElementTree(testsuites) | |
106 | et.write(sys.stdout, encoding="unicode") | |
107 | ||
108 | sys.exit(1 if fail_count > 0 or error_count > 0 else 0) | |
91ba8aa1 MJ |
109 | EOF |
110 | ||
bcd0bdf1 | 111 | python3 sum2junit.py < "$infile" > "$outfile" |
91ba8aa1 MJ |
112 | } |
113 | ||
114 | # Required variables | |
115 | WORKSPACE=${WORKSPACE:-} | |
116 | ||
117 | arch=${arch:-} | |
118 | conf=${conf:-} | |
119 | build=${build:-} | |
120 | cc=${cc:-} | |
121 | ||
122 | ||
123 | SRCDIR="$WORKSPACE/src/binutils-gdb" | |
124 | TMPDIR="$WORKSPACE/tmp" | |
125 | PREFIX="/build" | |
126 | ||
127 | # Create tmp directory | |
128 | rm -rf "$TMPDIR" | |
129 | mkdir -p "$TMPDIR" | |
130 | ||
131 | export TMPDIR | |
132 | export CFLAGS="-O2 -fsanitize=address" | |
133 | export CXXFLAGS="-O2 -fsanitize=address -D_GLIBCXX_DEBUG=1" | |
134 | export LDFLAGS="-fsanitize=address" | |
135 | ||
136 | # Set platform variables | |
137 | case "$arch" in | |
138 | *) | |
139 | export MAKE=make | |
140 | export TAR=tar | |
141 | export NPROC=nproc | |
142 | ;; | |
143 | esac | |
144 | ||
145 | # Print build env details | |
146 | print_os || true | |
147 | print_tooling || true | |
148 | ||
149 | # Enter the source directory | |
150 | cd "$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. | |
161 | CONF_OPTS=("--prefix=$PREFIX") | |
162 | ||
163 | case "$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 | ;; | |
179 | esac | |
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. | |
189 | case "$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 | ;; | |
199 | esac | |
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 | 214 | ASAN_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 | |
217 | mkdir "${WORKSPACE}/results" | |
f5dbc8e5 | 218 | cp gdb/testsuite/gdb.log "${WORKSPACE}/results/" |
91ba8aa1 | 219 | cp gdb/testsuite/gdb.sum "${WORKSPACE}/results/" |
bcd0bdf1 SM |
220 | |
221 | # Convert results to JUnit format. | |
222 | failed_tests=0 | |
223 | sum2junit 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 | |
233 | find "$WORKSPACE/$PREFIX/lib" -name "*.la" -exec rm -f {} \; | |
234 | ||
235 | # Exit with failure if any of the tests failed | |
236 | exit $failed_tests | |
237 | ||
238 | # EOF |