File: config-sub.sh

package info (click to toggle)
autotools-dev 20240727.1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 496 kB
  • sloc: sh: 4,082; makefile: 39; perl: 20
file content (119 lines) | stat: -rw-r--r-- 2,568 bytes parent folder | download
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
#!/bin/bash
#
# Copyright 2004-2024 Free Software Foundation, Inc.
# Contributed by Ben Elliston <bje@gnu.org>.
#
# This test reads pairs from config-sub.data: an alias and its
# canonical triplet.  config.sub is invoked and the test checks that
# the alias expands to the expected canonical triplet.

set -eu
shopt -s lastpipe
verbose=false
maxprocs=16

# Run a single config.sub invocation.
run_one_config_sub()
{
	alias=$1
	canonical=$2
	output=$(sh -eu ../config.sub "$alias")
	if test "$output" != "$canonical" ; then
	    echo "FAIL: $alias -> $output, but expected $canonical"
	    return 1
	else
	    $verbose && echo "PASS: $alias -> $canonical"
	fi
	return 0
}

run_config_sub()
{
	local -i rc=0 jobs=0
	numtests=0
	name="checks"
	while read -r alias canonical ; do
		run_one_config_sub "$alias" "$canonical" &
		numtests+=1 jobs+=1
		if test $jobs -eq $maxprocs ; then
			for pid in $(jobs -p) ; do
				wait "$pid"
				rc=$((rc || $?))
			done
			jobs=0
		fi
	done < config-sub.data
	for pid in $(jobs -p) ; do
		wait "$pid"
		rc=$((rc || $?))
	done
	return $rc
}

# Run a single config.sub invocation for idempotency checks.
run_one_config_sub_idempotent()
{
    canonical=$1
    output=$(sh -eu ../config.sub "$canonical")
    if test "$output" != "$canonical" ; then
	echo "FAIL: $canonical -> $output, but $canonical should map to itself"
	return 1
    else
	$verbose && echo "PASS: $canonical -> $canonical"
    fi
    return 0
}

run_config_sub_idempotent()
{
	local -i rc=0 jobs=0
	numtests=0
	name="idempotency checks"
	sed -r 's/\t+/\t/g' < config-sub.data | cut -f 2 | uniq | while read -r canonical ; do
		run_one_config_sub_idempotent "$canonical" &
		numtests+=1 jobs+=1
		if test $jobs -eq $maxprocs ; then
			for pid in $(jobs -p) ; do
				wait "$pid"
				rc=$((rc || $?))
			done
			jobs=0
		fi
	done
	for pid in $(jobs -p) ; do
		wait "$pid"
		rc=$((rc || $?))
	done
	return $rc
}

run_config_sub_with_guess_triplets()
{
	local -i rc=0
	numtests=0
	name="canonicalise each config.guess testcase"

	awk -F '|' '{ print $6 }' < config-guess.data | while read -r triplet ; do
	    output=$(sh -eu ../config.sub "$triplet")
	    if test "$triplet" != "$output" ; then
		echo "FAIL: $triplet -> $output, but $triplet should map to itself"
		rc=1
	    fi
	    numtests+=1
	done
	return $rc
}


declare -i rc=0 numtests
declare name

for testsuite in run_config_sub run_config_sub_idempotent run_config_sub_with_guess_triplets ; do
	if $testsuite; then
		$verbose || echo "PASS: config.sub $name ($numtests tests)"
	else
		rc=1
	fi
done

exit $rc