summaryrefslogtreecommitdiff
path: root/ci/_test-git-branch.sh
blob: 05886a767d7f8de12df08d8f27cb6525b9c33104 (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
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
#!/bin/bash

set -o nounset
set -o errexit
set -o errtrace

ktest_verbose=0

KTEST_DIR=$(dirname "$(readlink -e "$0")")/..
JOBSERVER_LINUX_REPO=ssh://$JOBSERVER/$JOBSERVER_HOME/linux

. $KTEST_DIR/lib/common.sh

git_fetch()
{
    local repo=$1
    shift

    git fetch ssh://$JOBSERVER/$JOBSERVER_HOME/$repo $@
}

sync_git_repos()
{
    local repo

    for repo in ${JOBSERVER_GIT_REPOS[@]}; do
	(cd ~/$repo; git_fetch $repo && git checkout -f FETCH_HEAD) || true > /dev/null
    done
}

echo "Getting test job"

TEST_JOB=( $(ssh $JOBSERVER get-test-job.sh) )

BRANCH=${TEST_JOB[0]}
COMMIT=${TEST_JOB[1]}
TEST_PATH=${TEST_JOB[2]}
TEST_NAME=$(basename -s .ktest $TEST_PATH)
SUBTESTS=( "${TEST_JOB[@]:3}" )
OUTPUT=$JOBSERVER_OUTPUT_DIR/$COMMIT

if [[ -z $BRANCH ]]; then
    echo "Error getting test job: need git branch"
    exit 1
fi

if [[ -z $COMMIT ]]; then
    echo "Error getting test job: need git commit"
    exit 1
fi

if [[ -z $TEST_PATH ]]; then
    echo "Error getting test job: need test to run"
    exit 1
fi

echo "Running test $TEST_NAME for branch $BRANCH and commit $COMMIT"

run_quiet "Syncing git repos" sync_git_repos

run_quiet "Fetching $COMMIT" git_fetch linux $COMMIT
run_quiet "Checking out $COMMIT" git checkout FETCH_HEAD

run_quiet "Fetching ci-monkeypatch" git_fetch linux ci-monkeypatch
run_quiet "Merging ci-monkeypatch"  git merge --no-edit FETCH_HEAD || git reset --hard

rm -rf ktest-out/out
mkdir -p ktest-out/out

# Mark tests as not run:
for t in ${SUBTESTS[@]}; do
    t=$(echo "$t"|tr / .)

    mkdir ktest-out/out/$TEST_NAME.$t
    echo "========= NOT STARTED" > ktest-out/out/$TEST_NAME.$t/status
done

make -C "$KTEST_DIR/lib" supervisor

while (( ${#SUBTESTS[@]} )); do
    FULL_LOG=$TEST_NAME.$(hostname).$(date -Iseconds).log

    for t in ${SUBTESTS[@]}; do
	FNAME=$(echo "$t"|tr / .)
	ln -sfr "ktest-out/out/$FULL_LOG.br"			\
	    "ktest-out/out/$TEST_NAME.$FNAME/full_log.br"
    done

    echo "Running test $TEST_NAME ${SUBTESTS[@]}"

    $KTEST_DIR/lib/supervisor -T 1200 -f "$FULL_LOG" -S -F	\
	-b $TEST_NAME -o ktest-out/out				\
	-- build-test-kernel run $TEST_PATH ${SUBTESTS[@]} > /dev/null &
    wait

    SUBTESTS_REMAINING=()

    for t in ${SUBTESTS[@]:1}; do
	FNAME=$(echo "$t"|tr / .)

	if grep -q "NOT STARTED" ktest-out/out/$TEST_NAME.$FNAME/status; then
	    SUBTESTS_REMAINING+=($t)
	fi
    done

    SUBTESTS=( "${SUBTESTS_REMAINING[@]}" )
done

echo "Compressing output"
find ktest-out/out -type f -name \*log -print0|xargs -0 brotli --rm -9

ssh $JOBSERVER mkdir -p $OUTPUT

echo "Sending results to jobserver"
(cd ktest-out/out; tar --create --file - *)|
    ssh $JOBSERVER "(cd $OUTPUT; tar --extract --file -)"