aboutsummaryrefslogtreecommitdiff
blob: ef387709a271413fa275220b7c91ebea5c1d3999 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
#!/usr/bin/env bash

# Avoid bash localization of error messages
export LC_ALL=C

functions_script="${EPREFIX}/lib/gentoo/functions.sh"
source "${functions_script}" || {
	echo "${argv0}: Could not source ${functions_script}!" 1>&2

	ebegin() { printf '%s*%s %s ... ' "${GOOD}" "${NORMAL}" "$*" ; }

	eend() {
		local r=${1:-0}
		shift
		if [[ $r -eq 0 ]] ; then
		printf '[ %sok%s ]\n' "${GOOD}" "${NORMAL}"
		else
			printf '%s [ %s!!%s ]\n' "$*" "${BAD}" "${NORMAL}"
		fi
		return $r
	}
}

die() { echo "$*" 1>&2; exit 1; }

vars=( CHOST GCC_CONFIG ROOT TROOT NOCOLOR RC_NOCOLOR )
unset ${vars[@]}

TROOT=${PWD}
GCC_CONFIG="${TROOT}/../.gcc-config"
if ! "${GCC_CONFIG}" --help >/dev/null ; then
	die "could not find gcc-config in ${TROOT}/../"
fi
PATH="${TROOT}/..:${PATH}"

NOCOLOR="true"
RC_NOCOLOR="yes" # Older baselayout/openrc versions.
# This CHOST value doesn't matter.  It could be anything.
# As long as all the configs we test are based on this being
# the CHOST value.
CHOST="x86_64-pc-linux-gnu"

cmp_log() {
	local ret log=$1 exp=$2
	local v args=()
	for v in "${vars[@]}" ; do
		args+=( -e "s:@${v}@:${!v}:g" )
	done
	args+=( -e "s|: line [0-9]*: |: |g" )
	sed "${args[@]}" "${exp}" > "${exp}.tmp"
	sed "${args[@]}" "${log}" > "${log}.tmp"
	diff -uw "${exp}.tmp" "${log}.tmp" > "${log}.diff"
	ret=$?
	rm "${exp}.tmp"
	return ${ret}
}

rm -f */*.log* */*.runit
rm -rf TMP-*-rw-*

if [[ $# -eq 0 ]] ; then
	set -- */test*
else
	set -- "${@/%//test*}"
	set -- "${@//\/\///}"
fi

max_jobs=$(getconf _NPROCESSORS_ONLN)
jobs=()
tret=0
for t in "$@" ; do
	[[ ${t} == *.exp ]] && continue

	(
	out=$(
	(
	ebegin "Running ${t}"

	test=${t##*/}
	tdir=${t%/*}
	if [[ ${tdir} == rw-* ]] ; then
		cp -pPR "${tdir}" "TMP-${test}-${tdir}"
		tdir="TMP-${test}-${tdir}"
	fi

	ROOT=${TROOT}/${tdir}

	r="${ROOT}/${test}.runit"
	cat <<-EOF > "${r}"
	#!/bin/bash
	cd "${ROOT}"
	$(for v in PATH ${vars[@]} ; do printf '%s="%s"\n' ${v} "${!v}" ; done)
	export ${vars[@]}
	gcc-config() { bash -c ". \${GCC_CONFIG}" gcc-config "\$@" ; }
	. ./${test}
	EOF
	chmod a+rx "${r}"

	log=${ROOT}/${test}.log
	"${r}" >& "${log}"
	ret=$?
	reason="exit failure"

	if [[ ${ret} -eq 0 ]] ; then
		reason="log difference"
		cmp_log "${log}" "${log%.log}.exp"
		ret=$?
	fi
	if eend ${ret} "due to ${reason}; see ${log}" ; then
		rm -f "${log}"* "${r}"
		[[ ${tdir} == TMP-${test}-rw-* ]] && rm -rf "${tdir}"
	else
		: $(( tret += $? ))
	fi

	) 2>&1
	)
	echo "${out}"
	) &

	# Run all the tests in parallel.
	jobs+=( $! )
	if [[ ${#jobs[@]} -ge ${max_jobs} ]] ; then
		wait ${jobs[0]}
		: $(( tret += $? ))
		jobs=( ${jobs[@]:1} )
	fi
done
for j in ${jobs[@]} ; do
	wait ${j}
	: $(( tret += $? ))
done
exit ${tret}