| 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 | |
| 32 | local tool |
| 33 | local skipped |
| 34 | local passes |
| 35 | local failures |
| 36 | local total |
| 37 | local s2jtmpfile |
| 38 | |
| 39 | local result |
| 40 | local name |
| 41 | local message |
| 42 | |
| 43 | set +x |
| 44 | |
| 45 | tool=$(grep "tests ===" "$infile" | tr -s ' ' | cut -d ' ' -f 2) |
| 46 | |
| 47 | # Get the counts for tests that didn't work properly |
| 48 | skipped=$(grep -E -c '^UNRESOLVED|^UNTESTED|^UNSUPPORTED' "$infile" || true) |
| 49 | if test x"${skipped}" = x; then |
| 50 | skipped=0 |
| 51 | fi |
| 52 | |
| 53 | # The total of successful results are PASS and XFAIL |
| 54 | passes=$(grep -E -c '^PASS|XFAIL' "$infile" || true) |
| 55 | if test x"${passes}" = x; then |
| 56 | passes=0 |
| 57 | fi |
| 58 | |
| 59 | # The total of failed results are FAIL and XPASS |
| 60 | failures=$(grep -E -c '^FAIL|XPASS' "$infile" || true) |
| 61 | if test x"${failures}" = x; then |
| 62 | failures=0 |
| 63 | fi |
| 64 | |
| 65 | # Calculate the total number of test cases |
| 66 | total=$((passes + failures)) |
| 67 | total=$((total + skipped)) |
| 68 | |
| 69 | cat <<EOF > "$outfile" |
| 70 | <?xml version="1.0"?> |
| 71 | |
| 72 | <testsuites> |
| 73 | <testsuite name="DejaGnu" tests="${total}" failures="${failures}" skipped="${skipped}"> |
| 74 | |
| 75 | EOF |
| 76 | |
| 77 | s2jtmpfile="$(mktemp)" |
| 78 | grep -E 'PASS|XPASS|FAIL|UNTESTED|UNSUPPORTED|UNRESOLVED' "$infile" > "$s2jtmpfile" || true |
| 79 | |
| 80 | while read -r line |
| 81 | do |
| 82 | echo -n "." |
| 83 | result=$(echo "$line" | cut -d ' ' -f 1 | tr -d ':') |
| 84 | name=$(echo "$line" | cut -d ' ' -f 2 | tr -d '\"><;:\[\]^\\&?@') |
| 85 | message=$(echo "$line" | cut -d ' ' -f 3-50 | tr -d '\"><;:\[\]^\\&?@') |
| 86 | |
| 87 | echo " <testcase name=\"${name}\" classname=\"${tool}-${result}\">" >> "$outfile" |
| 88 | case "${result}" in |
| 89 | PASS|XFAIL|KFAIL) |
| 90 | # No message for successful tests in junit |
| 91 | ;; |
| 92 | UNSUPPORTED|UNTESTED) |
| 93 | if test x"${message}" != x; then |
| 94 | echo -n " <skipped message=\"${message}\"/>" >> "$outfile" |
| 95 | else |
| 96 | echo -n " <skipped type=\"$result\"/>" >> "$outfile" |
| 97 | fi |
| 98 | ;; |
| 99 | XPASS|UNRESOLVED|DUPLICATE) |
| 100 | echo -n " <failure message=\"$message\"/>" >> "$outfile" |
| 101 | ;; |
| 102 | *) |
| 103 | echo -n " <failure message=\"$message\"/>" >> "$outfile" |
| 104 | esac |
| 105 | |
| 106 | echo " </testcase>" >> "$outfile" |
| 107 | done < "$s2jtmpfile" |
| 108 | |
| 109 | rm -f "$s2jtmpfile" |
| 110 | |
| 111 | # Write the closing tag for the test results |
| 112 | echo "</testsuite>" >> "$outfile" |
| 113 | echo "</testsuites>" >> "$outfile" |
| 114 | |
| 115 | set -x |
| 116 | } |
| 117 | |
| 118 | # Required variables |
| 119 | WORKSPACE=${WORKSPACE:-} |
| 120 | |
| 121 | arch=${arch:-} |
| 122 | conf=${conf:-} |
| 123 | build=${build:-} |
| 124 | cc=${cc:-} |
| 125 | |
| 126 | |
| 127 | SRCDIR="$WORKSPACE/src/binutils-gdb" |
| 128 | TMPDIR="$WORKSPACE/tmp" |
| 129 | PREFIX="/build" |
| 130 | |
| 131 | # Create tmp directory |
| 132 | rm -rf "$TMPDIR" |
| 133 | mkdir -p "$TMPDIR" |
| 134 | |
| 135 | export TMPDIR |
| 136 | export CFLAGS="-O2 -fsanitize=address" |
| 137 | export CXXFLAGS="-O2 -fsanitize=address -D_GLIBCXX_DEBUG=1" |
| 138 | export LDFLAGS="-fsanitize=address" |
| 139 | |
| 140 | # Set platform variables |
| 141 | case "$arch" in |
| 142 | *) |
| 143 | export MAKE=make |
| 144 | export TAR=tar |
| 145 | export NPROC=nproc |
| 146 | ;; |
| 147 | esac |
| 148 | |
| 149 | # Print build env details |
| 150 | print_os || true |
| 151 | print_tooling || true |
| 152 | |
| 153 | # Enter the source directory |
| 154 | cd "$SRCDIR" |
| 155 | |
| 156 | # Run bootstrap in the source directory prior to configure |
| 157 | #./bootstrap |
| 158 | |
| 159 | # Get source version from configure script |
| 160 | #eval "$(grep '^PACKAGE_VERSION=' ./configure)" |
| 161 | #PACKAGE_VERSION=${PACKAGE_VERSION//\-pre*/} |
| 162 | |
| 163 | # Set configure options and environment variables for each build |
| 164 | # configuration. |
| 165 | CONF_OPTS=("--prefix=$PREFIX") |
| 166 | |
| 167 | case "$conf" in |
| 168 | *) |
| 169 | echo "Standard configuration" |
| 170 | |
| 171 | # Use system tools |
| 172 | CONF_OPTS+=("--disable-binutils" "--disable-ld" "--disable-gold" "--disable-gas" "--disable-sim" "--disable-gprof") |
| 173 | |
| 174 | # Use system libs |
| 175 | CONF_OPTS+=("--with-system-readline" "--with-system-zlib") |
| 176 | |
| 177 | # Enable optional features |
| 178 | CONF_OPTS+=("--enable-targets=all" "--with-expat=yes" "--with-python=python3" "--with-guile=guile-2.2" "--enable-libctf") |
| 179 | |
| 180 | CONF_OPTS+=("--enable-build-warnings" "--enable-gdb-build-warnings" "--enable-unit-tests") |
| 181 | |
| 182 | ;; |
| 183 | esac |
| 184 | |
| 185 | # Build type |
| 186 | # oot : out-of-tree build |
| 187 | # dist : build via make dist |
| 188 | # oot-dist: build via make dist out-of-tree |
| 189 | # * : normal tree build |
| 190 | # |
| 191 | # Make sure to move to the build directory and run configure |
| 192 | # before continuing. |
| 193 | case "$build" in |
| 194 | *) |
| 195 | echo "Out of tree build" |
| 196 | |
| 197 | # Create and enter a temporary build directory |
| 198 | builddir=$(mktemp -d) |
| 199 | cd "$builddir" |
| 200 | |
| 201 | "$SRCDIR/configure" "${CONF_OPTS[@]}" || failed_configure |
| 202 | ;; |
| 203 | esac |
| 204 | |
| 205 | # We are now inside a configured build directory |
| 206 | |
| 207 | # BUILD! |
| 208 | $MAKE -j "$($NPROC)" V=1 MAKEINFO=/bin/true |
| 209 | |
| 210 | # Install in the workspace |
| 211 | $MAKE install DESTDIR="$WORKSPACE" |
| 212 | |
| 213 | # Run tests, don't fail now, we want to run the archiving steps |
| 214 | # |
| 215 | # Disable ASan leaks reporting, it might break some tests since it adds |
| 216 | # unexpected output when GDB exits. |
| 217 | failed_tests=0 |
| 218 | ASAN_OPTIONS=detect_leaks=0 $MAKE -C gdb --keep-going check -j "$($NPROC)" || failed_tests=1 |
| 219 | |
| 220 | # Copy the dejagnu test results for archiving before cleaning the build dir |
| 221 | mkdir "${WORKSPACE}/results" |
| 222 | cp gdb/testsuite/gdb.log "${WORKSPACE}/results/" |
| 223 | cp gdb/testsuite/gdb.sum "${WORKSPACE}/results/" |
| 224 | sum2junit gdb/testsuite/gdb.sum "${WORKSPACE}/results/gdb.xml" |
| 225 | |
| 226 | # Clean the build directory |
| 227 | $MAKE clean |
| 228 | |
| 229 | # Cleanup rpath in executables and shared libraries |
| 230 | #find "$WORKSPACE/$PREFIX/bin" -type f -perm -0500 -exec chrpath --delete {} \; |
| 231 | #find "$WORKSPACE/$PREFIX/lib" -name "*.so" -exec chrpath --delete {} \; |
| 232 | |
| 233 | # Remove libtool .la files |
| 234 | find "$WORKSPACE/$PREFIX/lib" -name "*.la" -exec rm -f {} \; |
| 235 | |
| 236 | # Exit with failure if any of the tests failed |
| 237 | exit $failed_tests |
| 238 | |
| 239 | # EOF |