source: mainline/contrib/tools/random_check.sh@ 3b065c9

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 3b065c9 was 3b065c9, checked in by Vojtech Horky <vojtechhorky@…>, 11 years ago

Easier random-checking of supported configurations

  • Property mode set to 100755
File size: 4.0 KB
Line 
1#!/bin/sh
2
3#
4# Copyright (c) 2014 Vojtech Horky
5# All rights reserved.
6#
7# Redistribution and use in source and binary forms, with or without
8# modification, are permitted provided that the following conditions
9# are met:
10#
11# - Redistributions of source code must retain the above copyright
12# notice, this list of conditions and the following disclaimer.
13# - Redistributions in binary form must reproduce the above copyright
14# notice, this list of conditions and the following disclaimer in the
15# documentation and/or other materials provided with the distribution.
16# - The name of the author may not be used to endorse or promote products
17# derived from this software without specific prior written permission.
18#
19# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
20# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
21# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
22# IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
23# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
24# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
28# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29#
30
31
32LOOPS=1
33JOBS=1
34MAX_RETRIES=20
35FILENAME_PREFIX=random_run_
36PRUNE_CONFIG_FILE=${FILENAME_PREFIX}prune.config
37
38echo -n "">"$PRUNE_CONFIG_FILE"
39
40while getopts n:j:x:sS option; do
41 case $option in
42 n)
43 LOOPS="$OPTARG"
44 ;;
45 j)
46 JOBS="$OPTARG"
47 ;;
48 x)
49 echo "$OPTARG" | tr -d ' ' >>"$PRUNE_CONFIG_FILE"
50 ;;
51 s|S)
52 echo "COMPILER=gcc_native" >>"$PRUNE_CONFIG_FILE"
53 echo "COMPILER=gcc_helenos" >>"$PRUNE_CONFIG_FILE"
54 echo "COMPILER=icc" >>"$PRUNE_CONFIG_FILE"
55 if [ "$option" = "S" ]; then
56 echo "CONFIG_PCC=y" >>"$PRUNE_CONFIG_FILE"
57 echo "CONFIG_BINUTILS=y" >>"$PRUNE_CONFIG_FILE"
58 echo "CONFIG_MSIM=y" >>"$PRUNE_CONFIG_FILE"
59 fi
60 ;;
61 *)
62 echo "Usage: $0 [-n loops] [-j paralellism] [-s] [-S] [-x excluded option [-x ...]]"
63 exit 1
64 ;;
65 esac
66done
67
68
69COUNTER=0
70FAILED=0
71while [ $COUNTER -lt $LOOPS ]; do
72 COUNTER=$(( $COUNTER + 1 ))
73 echo "Try #$COUNTER ($FAILED failed):" >&2
74
75 (
76 echo " Cleaning after previous build." >&2
77 make distclean -j$PARALLELISM 2>&1 || exit 1
78
79
80 echo " Preparing random configuration." >&2
81 # It would be nicer to allow set the constraints directly to
82 # the tools/config.py script but this usually works.
83 # We retry $MAX_RETRIES before aborting this run completely.
84 RETRIES=0
85 while true; do
86 RETRIES=$(( $RETRIES + 1 ))
87 if [ $RETRIES -ge 20 ]; then
88 echo " Failed to generate random configuration with given constraints after $RETRIES tries." >&2
89 exit 2
90 fi
91
92 make random-config 2>&1 || exit 1
93
94 tr -d ' ' <Makefile.config >"${FILENAME_PREFIX}config.trimmed"
95
96 THIS_CONFIG_OKAY=true
97 while read pattern; do
98 if grep -q -e "$pattern" "${FILENAME_PREFIX}config.trimmed"; then
99 THIS_CONFIG_OKAY=false
100 break
101 fi
102 done <"$PRUNE_CONFIG_FILE"
103
104 rm -f "${FILENAME_PREFIX}config.trimmed"
105
106 if $THIS_CONFIG_OKAY; then
107 break
108 fi
109 done
110
111
112 # Report basic info about the configuration and build it
113 BASIC_CONFIG=`sed -n \
114 -e 's#PLATFORM = \(.*\)#\1#p' \
115 -e 's#MACHINE = \(.*\)#\1#p' \
116 -e 's#COMPILER = \(.*\)#\1#p' \
117 Makefile.config \
118 | paste '-sd,' | sed 's#,#, #g'`
119 echo -n " Building ($BASIC_CONFIG)... " >&2
120
121 make -j$PARALLELISM 2>&1
122 if [ $? -eq 0 ]; then
123 echo "okay." >&2
124 exit 0
125 else
126 echo "failed." >&2
127 exit 1
128 fi
129
130 ) >random_run_$COUNTER.log
131 RC=$?
132
133 if [ $RC -ne 0 ]; then
134 tail -n 10 random_run_$COUNTER.log | sed 's#.*# | &#'
135 FAILED=$(( $FAILED + 1 ))
136 fi
137
138 if [ -e Makefile.config ]; then
139 cp Makefile.config "$FILENAME_PREFIX$COUNTER.Makefile.config"
140 cp config.h "$FILENAME_PREFIX$COUNTER.config.h"
141 fi
142done
143
144rm "$PRUNE_CONFIG_FILE"
145
146echo "Out of $LOOPS tries, $FAILED configurations failed to compile." >&2
Note: See TracBrowser for help on using the repository browser.