|
| 1 | +#!/usr/bin/env bash |
| 2 | +# resources: machine |
| 3 | +# 1039 -- two builds that find the std module missing compile it once (#906 self-review). |
| 4 | +# |
| 5 | +# The std module of a toolchain and flag set is one entry of the home's build cache, shared by every |
| 6 | +# build. Two processes that found it missing compiled into the same files at once: the second clang |
| 7 | +# read a std.pcm the first was rewriting (SIGBUS), and a build went on with no std.o (e2e 957 and 987, |
| 8 | +# run side by side on one runner). The entry is now built under its own lock. |
| 9 | +# |
| 10 | +# Criteria: with the entry two projects use removed, the two build at once and both succeed; the entry |
| 11 | +# is whole afterwards (its BMI, object and record). |
| 12 | +# |
| 13 | +# It holds the machine: it removes an entry of the shared home's cache, which no other test may be |
| 14 | +# building from at that moment. |
| 15 | +set -e |
| 16 | +TMP=$(mktemp -d) |
| 17 | +trap 'rm -rf "$TMP"' EXIT |
| 18 | +fail() { echo "FAIL: $1"; shift; for f in "$@"; do echo "--- $f ---"; cat "$f" 2>/dev/null; done; exit 1; } |
| 19 | +PY=python3; command -v python3 >/dev/null 2>&1 || PY=python |
| 20 | + |
| 21 | +cd "$TMP" |
| 22 | +for p in one two; do "$MCPP" new "$p" > /dev/null 2>&1 || fail "mcpp new $p"; done |
| 23 | +(cd one && "$MCPP" build > ../first.log 2>&1) || fail "the first build" first.log |
| 24 | + |
| 25 | +# The entry the first build used: the std module whose record it marked last. |
| 26 | +home="${MCPP_HOME:-$HOME/.mcpp}" |
| 27 | +entry="$("$PY" - "$home/build-cache/v1/std" <<'PY' |
| 28 | +import os, sys |
| 29 | +root = sys.argv[1] |
| 30 | +records = [os.path.join(root, d, "std-module.json") for d in os.listdir(root)] if os.path.isdir(root) else [] |
| 31 | +records = [r for r in records if os.path.isfile(r)] |
| 32 | +print(os.path.dirname(max(records, key=os.path.getmtime)) if records else "") |
| 33 | +PY |
| 34 | +)" |
| 35 | +[ -n "$entry" ] || fail "no std module entry under $home/build-cache/v1/std" first.log |
| 36 | +rm -rf "$entry" |
| 37 | + |
| 38 | +(cd one && "$MCPP" build > ../one.log 2>&1) & a=$! |
| 39 | +(cd two && "$MCPP" build > ../two.log 2>&1) & b=$! |
| 40 | +sa=0; sb=0; wait $a || sa=$?; wait $b || sb=$? |
| 41 | +[ "$sa" = 0 ] || fail "the first of two builds at once (exit $sa)" one.log two.log |
| 42 | +[ "$sb" = 0 ] || fail "the second of two builds at once (exit $sb)" one.log two.log |
| 43 | +[ -f "$entry/std-module.json" ] || fail "the entry has no record afterwards" one.log two.log |
| 44 | +ls "$entry"/*.o > /dev/null 2>&1 || fail "the entry has no object afterwards" one.log two.log |
| 45 | + |
| 46 | +echo "PASS: 1039 two builds that find the std module missing compile it once" |
0 commit comments