File: findPatchThatBrokeUnitTest.sh

package info (click to toggle)
strigi 0.7.2-1
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 6,808 kB
  • ctags: 7,071
  • sloc: cpp: 44,468; ansic: 9,764; perl: 515; java: 367; python: 345; xml: 316; yacc: 176; sh: 153; makefile: 38
file content (125 lines) | stat: -rwxr-xr-x 3,448 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
#! /bin/bash
#
# (c) Jos van den Oever  <jos@vandenoever.info>
#
# This script checks out strigi and runs the given unit test. If the unit test
# fails, it goes back to the previous version, compiles and tests again.
# This goes on until the unit test is not present or runs successfully.

# current limitations:
# - only one instance of this script can be run because it relies on reusing
#   previous work to avoid expensive downloading and compiling.

# check the arguments
if (( $# != 1 && $# != 2)); then
    echo Usage: $0 testname [srcdir]
    echo Note: This script must be run from the base
    exit
fi
# if a second argument was given, go into this directory
if (( $# == 2 )); then
    DIR=$2;
    if [ ! -d $DIR ]; then
        echo Directory $DIR does not exist.
        exit
    fi
    cd $DIR
fi

# the path to the unit test executable
TESTNAME=$1

## Configuration parameters

# absolute path of the directory in which to run the tests
TESTDIR=/tmp/checksvnunittest

# the maximal number of log entries to download
MAXLOGENTRIES=300

# the maximal number of steps you wish to take
MAXSTEPS=300

# make exectable with arguments
MAKE="make -j8"

# should we do a drastic cleanup between runs or not?
FORCEFULLBUILD=0

####################

# function for testing a particular test in a particular revision
function runTest {
    REVISION=$1
    echo Testing revision $REVISION.

    # go back to the given revision
    cd $TESTDIR
    svn update $MODULE -r $REVISION
    if (( $? != 0 )); then
        # if updating failed, we have to get a fresh version
        rm -rf $TESTDIR/$MODULE
        svn checkout -r $REVISION $SVNURL
        if (( $? != 0 )); then exit; fi
    fi

    # configure the code
    # if we cannot configure the test, we continue to the next revision number
    if (( $FORCEFULLBUILD == 1 )); then
        rm -rf $TESTDIR/$MODULE/build
    fi
    mkdir $TESTDIR/$MODULE/build
    cd $TESTDIR/$MODULE/build
    cmake ..
    if (( $? != 0 )); then return; fi

    # get the name of the unit test and build it
    # if we cannot build the test, we continue to the next revision number
    echo $MAKE $TESTNAME
    $MAKE $TESTNAME
    if (( $? != 0 )); then return; fi

    # find the test executable
    TESTPATH=`find -name $TESTNAME -type f -perm -u+x`

    # run the unit test and exit if it ran without error
    $TESTPATH
    if (( $? == 0 )); then
        echo The last revision where the test $TESTNAME worked was $REVISION.
        BROKEN=`grep -B 1 $REVISION $TESTDIR/revisions |head -1`
        echo The first revision that was broken was $BROKEN:
        svn log -r $BROKEN $TESTDIR/$MODULE
        exit
    fi
}

# determine the URL of the svn repository
SVNURL=`svn info | grep -m 1 '^URL: ' | cut -b 6-`
if (( $? != 0 )); then exit; fi

# determine the module name
MODULE=`basename $SVNURL`

# initial checkout
mkdir $TESTDIR
cd $TESTDIR
svn checkout $SVNURL
if (( $? != 0 )); then
    # if checking out fails, we can try again from an empty directory
    rm -rf $TESTDIR/$MODULE
    svn checkout $SVNURL
    if (( $? != 0 )); then exit; fi
fi

# get the last 100 relevant version numbers
svn log $MODULE --limit $MAXLOGENTRIES --non-interactive \
	| grep -E '^r[0123456789]+' \
	| perl -pi -e 's/^r(\d+).*/\1/' | head -n $MAXSTEPS > revisions
if (( $? != 0 )); then exit; fi

for REVISION in `cat revisions`; do
    runTest $REVISION;
done

echo No revision was found in which the unit test worked.