[f857e8b] | 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 |
|
---|
[e36a1c2] | 31 |
|
---|
| 32 | LOOPS=1
|
---|
| 33 | JOBS=1
|
---|
| 34 | MAX_RETRIES=20
|
---|
| 35 | FILENAME_PREFIX=random_run_
|
---|
| 36 | PRUNE_CONFIG_FILE=${FILENAME_PREFIX}prune.config
|
---|
| 37 |
|
---|
| 38 | echo -n "">"$PRUNE_CONFIG_FILE"
|
---|
| 39 |
|
---|
[3b065c9] | 40 | while getopts n:j:x:sS option; do
|
---|
[e36a1c2] | 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 | ;;
|
---|
[3b065c9] | 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 | ;;
|
---|
[e36a1c2] | 61 | *)
|
---|
[3b065c9] | 62 | echo "Usage: $0 [-n loops] [-j paralellism] [-s] [-S] [-x excluded option [-x ...]]"
|
---|
[e36a1c2] | 63 | exit 1
|
---|
| 64 | ;;
|
---|
| 65 | esac
|
---|
| 66 | done
|
---|
| 67 |
|
---|
[f857e8b] | 68 |
|
---|
| 69 | COUNTER=0
|
---|
| 70 | FAILED=0
|
---|
| 71 | while [ $COUNTER -lt $LOOPS ]; do
|
---|
| 72 | COUNTER=$(( $COUNTER + 1 ))
|
---|
[787510d] | 73 | echo "Try #$COUNTER ($FAILED failed):" >&2
|
---|
| 74 |
|
---|
[f857e8b] | 75 | (
|
---|
[787510d] | 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.
|
---|
[e36a1c2] | 83 | # We retry $MAX_RETRIES before aborting this run completely.
|
---|
[787510d] | 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 |
|
---|
[e36a1c2] | 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
|
---|
[787510d] | 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
|
---|
[170e181] | 128 | fi
|
---|
[787510d] | 129 |
|
---|
[f857e8b] | 130 | ) >random_run_$COUNTER.log
|
---|
[170e181] | 131 | RC=$?
|
---|
[787510d] | 132 |
|
---|
| 133 | if [ $RC -ne 0 ]; then
|
---|
[f857e8b] | 134 | tail -n 10 random_run_$COUNTER.log | sed 's#.*# | &#'
|
---|
[170e181] | 135 | FAILED=$(( $FAILED + 1 ))
|
---|
[f857e8b] | 136 | fi
|
---|
[787510d] | 137 |
|
---|
| 138 | if [ -e Makefile.config ]; then
|
---|
[e36a1c2] | 139 | cp Makefile.config "$FILENAME_PREFIX$COUNTER.Makefile.config"
|
---|
| 140 | cp config.h "$FILENAME_PREFIX$COUNTER.config.h"
|
---|
[787510d] | 141 | fi
|
---|
[f857e8b] | 142 | done
|
---|
| 143 |
|
---|
[e36a1c2] | 144 | rm "$PRUNE_CONFIG_FILE"
|
---|
[787510d] | 145 |
|
---|
| 146 | echo "Out of $LOOPS tries, $FAILED configurations failed to compile." >&2
|
---|