File: test-repeat.sh

package info (click to toggle)
rclone 1.60.1%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 34,820 kB
  • sloc: sh: 957; xml: 857; python: 655; javascript: 612; makefile: 264; ansic: 101; php: 74
file content (97 lines) | stat: -rwxr-xr-x 2,150 bytes parent folder | download | duplicates (2)
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
#!/bin/bash

# defaults
buildflags=""
binary="test.binary"
flags=""
iterations="100"
logprefix="test.out"

help="
This runs go tests repeatedly logging all the failures to separate
files. It is very useful for debugging with printf for tests which
don't fail very often.

Syntax: $0 [flags]

Note that flags for 'go test' need to be expanded, e.g. '-test.v' instead
of just '-v'. '-race' does not need to be expanded.

Flags this script understands

-h, --help
    show this help
-i=N, --iterations=N
    do N iterations (default ${iterations})
-b=NAME,--binary=NAME
    call the output binary NAME (default ${binary})
-l=NAME,--logprefix=NAME
    the log files generated will start with NAME (default ${logprefix})
-race
    build the binary with race testing enabled
-tags=TAGS
    build the binary with the tags supplied

Any other flags will be past to go test.

Example

    $0 flags -race -test.run 'TestRWFileHandleOpenTests'

"

if [[ "$@" == "" ]]; then
    echo "${help}"
    exit 1
fi

for i in "$@"
do
    case $i in
        -h|--help)
            echo "${help}"
            exit 1
            ;;
        -b=*|--binary=*)
            binary="${i#*=}"
            shift # past argument=value
            ;;
        -l=*|--log-prefix=*)
            logprefix="${i#*=}"
            shift # past argument=value
            ;;
        -i=*|--iterations=*)
            iterations="${i#*=}"
            shift # past argument=value
            ;;
        -race|--race|-tags=*|--tags=*)
            buildflags="${buildflags} $i"
            shift # past argument with no value
            ;;
        *)
            # unknown option
            flags="${flags} ${i#*=}"
            shift
            ;;
    esac
done

echo -n "Compiling ${buildflags} ${binary} ... "
go test ${buildflags} -c -o "${binary}" || {
    echo "build failed"
    exit 1
}
echo "OK"

for i in $(seq -w ${iterations}); do
    echo -n "Test ${buildflags} ${flags} ${i} "
    log="${logprefix}${i}.log"
    ./${binary} ${flags} > ${log} 2>&1
    ok=$?
    if [[ ${ok} == 0 ]]; then
        echo "OK"
        rm ${log}
    else
        echo "FAIL - log in ${log}"
    fi
done