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