source: mainline/contrib/tools/random_check.sh@ 787510d

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

random_check.sh refactoring

  • Property mode set to 100755
File size: 3.3 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
31LOOPS="$1"
32PARALLELISM="$2"
33COMPILERS="$3"
34[ -z "$LOOPS" ] && LOOPS=1
35[ -z "$PARALLELISM" ] && PARALLELISM=1
36# By default, skip icc and native GCC
37[ -z "$COMPILERS" ] && COMPILERS="gcc_cross gcc_helenos clang"
38
39COUNTER=0
40FAILED=0
41while [ $COUNTER -lt $LOOPS ]; do
42 COUNTER=$(( $COUNTER + 1 ))
43 echo "Try #$COUNTER ($FAILED failed):" >&2
44
45 (
46 echo " Cleaning after previous build." >&2
47 make distclean -j$PARALLELISM 2>&1 || exit 1
48
49
50 echo " Preparing random configuration." >&2
51 # It would be nicer to allow set the constraints directly to
52 # the tools/config.py script but this usually works.
53 # We retry several times if the compiler is wrong and abort if
54 # we do not succeed after many attempts.
55 RETRIES=0
56 while true; do
57 RETRIES=$(( $RETRIES + 1 ))
58 if [ $RETRIES -ge 20 ]; then
59 echo " Failed to generate random configuration with given constraints after $RETRIES tries." >&2
60 exit 2
61 fi
62
63 make random-config 2>&1 || exit 1
64
65 CC=`sed -n 's#^COMPILER = \(.*\)#\1#p' <Makefile.config`
66 if echo " $COMPILERS " | grep -q " $CC "; then
67 break
68 fi
69 done
70
71
72 # Report basic info about the configuration and build it
73 BASIC_CONFIG=`sed -n \
74 -e 's#PLATFORM = \(.*\)#\1#p' \
75 -e 's#MACHINE = \(.*\)#\1#p' \
76 -e 's#COMPILER = \(.*\)#\1#p' \
77 Makefile.config \
78 | paste '-sd,' | sed 's#,#, #g'`
79 echo -n " Building ($BASIC_CONFIG)... " >&2
80
81 make -j$PARALLELISM 2>&1
82 if [ $? -eq 0 ]; then
83 echo "okay." >&2
84 exit 0
85 else
86 echo "failed." >&2
87 exit 1
88 fi
89
90 ) >random_run_$COUNTER.log
91 RC=$?
92
93 if [ $RC -ne 0 ]; then
94 tail -n 10 random_run_$COUNTER.log | sed 's#.*# | &#'
95 FAILED=$(( $FAILED + 1 ))
96 fi
97
98 if [ -e Makefile.config ]; then
99 cp Makefile.config random_run_$COUNTER.Makefile.config
100 cp config.h random_run_$COUNTER.config.h
101 fi
102done
103
104
105echo "Out of $LOOPS tries, $FAILED configurations failed to compile." >&2
Note: See TracBrowser for help on using the repository browser.