source: mainline/contrib/tools/random_check.sh@ 91e057c

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 91e057c was 9f40318f, checked in by Jakub Jermar <jakub@…>, 11 years ago

No need for -S in random_check.sh now.

  • Property mode set to 100755
File size: 4.6 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:hs 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)
52 echo "COMPILER=gcc_native" >>"$PRUNE_CONFIG_FILE"
53 echo "COMPILER=gcc_helenos" >>"$PRUNE_CONFIG_FILE"
54 echo "COMPILER=icc" >>"$PRUNE_CONFIG_FILE"
55 ;;
56 *|h)
57 echo "Usage: $0 [options]"
58 echo "where [options] could be:"
59 echo
60 echo " -n LOOPS"
61 echo " How many configurations to check."
62 echo " (Default is one configuration.)"
63 echo " -j PARALLELISM"
64 echo " How many parallel jobs to execute by 'make'."
65 echo " (Default is single job configuration.)"
66 echo " -s"
67 echo " Use only supported compilers."
68 echo " (That is, only GCC cross-compiler and Clang.)"
69 echo " -x CONFIG_OPTION=value"
70 echo " Skip the configuration if this option is present."
71 echo " (Example: CONFIG_BINUTILS=n means that only configurations"
72 echo " where binutils *are* included would be built.)"
73 echo " -h"
74 echo " Print this help and exit."
75 echo
76 if [ "$option" = "h" ]; then
77 exit 0
78 else
79 exit 1
80 fi
81 ;;
82 esac
83done
84
85
86COUNTER=0
87FAILED=0
88while [ $COUNTER -lt $LOOPS ]; do
89 COUNTER=$(( $COUNTER + 1 ))
90 echo "Try #$COUNTER ($FAILED failed):" >&2
91
92 (
93 echo " Cleaning after previous build." >&2
94 make distclean -j$JOBS 2>&1 || exit 1
95
96
97 echo " Preparing random configuration." >&2
98 # It would be nicer to allow set the constraints directly to
99 # the tools/config.py script but this usually works.
100 # We retry $MAX_RETRIES before aborting this run completely.
101 RETRIES=0
102 while true; do
103 RETRIES=$(( $RETRIES + 1 ))
104 if [ $RETRIES -ge $MAX_RETRIES ]; then
105 echo " Failed to generate random configuration with given constraints after $RETRIES tries." >&2
106 exit 2
107 fi
108
109 make random-config 2>&1 || exit 1
110
111 tr -d ' ' <Makefile.config >"${FILENAME_PREFIX}config.trimmed"
112
113 THIS_CONFIG_OKAY=true
114 while read pattern; do
115 if grep -q -e "$pattern" "${FILENAME_PREFIX}config.trimmed"; then
116 THIS_CONFIG_OKAY=false
117 break
118 fi
119 done <"$PRUNE_CONFIG_FILE"
120
121 rm -f "${FILENAME_PREFIX}config.trimmed"
122
123 if $THIS_CONFIG_OKAY; then
124 break
125 fi
126 done
127
128
129 # Report basic info about the configuration and build it
130 BASIC_CONFIG=`sed -n \
131 -e 's#PLATFORM = \(.*\)#\1#p' \
132 -e 's#MACHINE = \(.*\)#\1#p' \
133 -e 's#COMPILER = \(.*\)#\1#p' \
134 Makefile.config \
135 | paste '-sd,' | sed 's#,#, #g'`
136 echo -n " Building ($BASIC_CONFIG)... " >&2
137
138 make -j$JOBS 2>&1
139 if [ $? -eq 0 ]; then
140 echo "okay." >&2
141 exit 0
142 else
143 echo "failed." >&2
144 exit 1
145 fi
146
147 ) >random_run_$COUNTER.log
148 RC=$?
149
150 if [ $RC -ne 0 ]; then
151 tail -n 10 random_run_$COUNTER.log | sed 's#.*# | &#'
152 FAILED=$(( $FAILED + 1 ))
153 fi
154
155 if [ -e Makefile.config ]; then
156 cp Makefile.config "$FILENAME_PREFIX$COUNTER.Makefile.config"
157 cp config.h "$FILENAME_PREFIX$COUNTER.config.h"
158 fi
159done
160
161rm "$PRUNE_CONFIG_FILE"
162
163echo "Out of $LOOPS tries, $FAILED configurations failed to compile." >&2
Note: See TracBrowser for help on using the repository browser.