summaryrefslogtreecommitdiff
path: root/test/scripts/testutils.sh
blob: 4d49be884c353bca887d386dfbf37d4e7c0333d4 (plain)
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
. ${top_srcdir}/test/test.shvars

fail() {
    echo "$@"
    false
}

assert_equal() {
    test "$2" = "$3" || fail "$1 $2 != expected $3"
}

wait_for_equal() {
    n=$4
    while [ $n -gt 0 ]; do
        currentvalue="$(eval "$2")"
        [ "${currentvalue}" = "$3" ] && return
        echo "still ${currentvalue}, not $3"
        n=$((n-1))
        sleep 1
    done
    assert_equal "$1" "$(eval "$2")" "$3"
}

get_treesize() {
    get_treesize_host ${BASEURL}
}
get_treesize_host() {
    ${top_srcdir}/tools/loginfo.py --localconfig current-merge-localconfig.cfg --treesize "$1"
}

check_sth() {
    check_sth_host ${BASEURL}
}
check_sth_host() {
    ${top_srcdir}/tools/check-sth.py "$1" --publickey=keys/logkey.pem --cur-sth=stored-sth --cafile httpsca/demoCA/cacert.pem || fail "Check STH failed"
}

do_merge() {
    n=3000
    expected_treesize=$1
    while [ $n -gt 0 ]; do
        ${top_srcdir}/tools/merge --config machine/merge-1/catlfish-test.cfg --timing --localconfig current-merge-localconfig.cfg || fail "Merge failed"
        ${top_srcdir}/tools/mergestatus.py --config machine/merge-1/catlfish-test.cfg --localconfig current-merge-localconfig.cfg
        n=$((n-1))
        treesize=$(get_treesize)
        [ "${treesize}" = "${expected_treesize}" ] && return
        sleep 1
    done
}