hc
2024-08-16 a24a44ff9ca902811b99aa9663d697cf452e08ef
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
126
127
128
129
130
131
132
133
134
135
136
137
138
#!/usr/bin/env bash
set -e
set -o pipefail
 
main() {
    local template="${1}"
 
    preamble "${template}"
    gen_tests
}
 
preamble() {
    local template="${1}"
 
    cat - "${template}" <<-_EOF_
   # This file is generated; do not edit!
   # Builds appear on https://gitlab.com/buildroot.org/buildroot/pipelines
 
   image: ${CI_JOB_IMAGE}
 
_EOF_
}
 
gen_tests() {
    local -a basics defconfigs runtimes
    local do_basics do_defconfigs do_runtime do_testpkg
    local defconfigs_ext cfg tst
 
    basics=( DEVELOPERS flake8 package )
 
    defconfigs=( $(cd configs; LC_ALL=C ls -1 *_defconfig) )
 
    runtimes=( $(./support/testing/run-tests -l 2>&1 \
                 | sed -r -e '/^test_run \((.*)\).*/!d; s//\1/' \
                 | LC_ALL=C sort)
             )
 
    if [ -n "${CI_COMMIT_TAG}" ]; then
        # When a tag is added to the Buildroot git tree, we want
        # to run the runtime tests and only test Qemu defconfigs.
        defconfigs=( $(cd configs; LC_ALL=C ls -1 qemu_*_defconfig) )
        do_basics=true
        do_defconfigs=base
        do_runtime=true
    elif [ "${CI_PIPELINE_SOURCE}" = "trigger" ]; then
        case "${BR_SCHEDULE_JOBS}" in
          (basic)
            do_basics=true
            do_defconfigs=check
            defconfigs_ext=_check
            ;;
          (defconfig)
            do_defconfigs=base
            ;;
          (runtime)
            do_runtime=true
            ;;
        esac
    else
        case "${CI_COMMIT_REF_NAME}" in
          (*-basics)
            do_basics=true
            do_defconfigs=check
            defconfigs_ext=_check
            ;;
          (*-defconfigs)
            do_defconfigs=base
            ;;
          (*-*_defconfig)
            defconfigs=( "${CI_COMMIT_REF_NAME##*-}" )
            do_defconfigs=base
            ;;
          (*-runtime-tests)
            do_runtime=true
            ;;
          (*-tests.*)
            runtimes=( $(./support/testing/run-tests -l 2>&1 \
                         | sed -r -e '/^test_run \((.*)\).*/!d; s//\1/' \
                         | LC_ALL=C sort \
                         | grep "^${CI_COMMIT_REF_NAME##*-}")
                     )
            do_runtime=true
            ;;
        esac
    fi
 
    # Retrieve defconfig for test-pkg from the git commit message (if any)
    if grep -q -E '^test-pkg config:$' <<<"${CI_COMMIT_DESCRIPTION}"; then
        sed -r -n -e '/^test-pkg config:$/{:a;n;p;ba;}' \
            <<<"${CI_COMMIT_DESCRIPTION}" \
            >defconfig.frag
        if [ ! -s defconfig.frag ]; then
            printf "Empty configuration fragment.\n" >&2; exit 1
        fi
        # Use --all since we expect the user having already pre-tested the
        # new package with the default subset of toolchains.
        ./utils/test-pkg \
            --all --prepare-only \
            --config-snippet defconfig.frag \
            --build-dir br-test-pkg >&2
        do_testpkg=( $(ls -1 br-test-pkg/*/.config 2>/dev/null |xargs -r dirname ) )
        if [ "${#do_testpkg[@]}" -eq 0 ]; then
            printf "Configuration fragment enables no test.\n" >&2; exit 1
        fi
    fi
 
    # If nothing else, at least do the basics to generate a valid pipeline
    if [    -z "${do_defconfigs}" \
         -a -z "${do_runtime}" \
         -a -z "${do_testpkg}" \
       ]
    then
        do_basics=true
    fi
 
    if ${do_basics:-false}; then
        for tst in "${basics[@]}"; do
            printf 'check-%s: { extends: .check-%s_base }\n' "${tst}" "${tst}"
        done
    fi
 
    if [ -n "${do_defconfigs}" ]; then
        for cfg in "${defconfigs[@]}"; do
            printf '%s%s: { extends: .defconfig_%s }\n' \
                   "${cfg}" "${defconfigs_ext}" "${do_defconfigs}"
        done
    fi
 
    if ${do_runtime:-false}; then
        printf '%s: { extends: .runtime_test_base }\n' "${runtimes[@]}"
    fi
 
    if [ -n "${do_testpkg}" ]; then
        printf '%s: { extends: .test_pkg }\n' "${do_testpkg[@]}"
    fi
}
 
main "${@}"