test-pkg 5.64 KB
Newer Older
1
#!/usr/bin/env bash
2
3
4
5
6
7
set -e

TOOLCHAINS_URL='http://autobuild.buildroot.org/toolchains/configs/toolchain-configs.csv'

main() {
    local o O opts
8
    local cfg dir pkg random toolchain
9
    local ret nb nb_skip nb_fail nb_legal nb_tc build_dir
10
11
    local -a toolchains

12
13
    o='hc:d:p:r:'
    O='help,config-snippet:build-dir:package:,random:'
14
    opts="$(getopt -n "${my_name}" -o "${o}" -l "${O}" -- "${@}")"
15
16
    eval set -- "${opts}"

17
    random=0
18
19
20
21
22
23
24
25
26
27
28
29
30
31
    while [ ${#} -gt 0 ]; do
        case "${1}" in
        (-h|--help)
            help; exit 0
            ;;
        (-c|--config-snippet)
            cfg="${2}"; shift 2
            ;;
        (-d|--build-dir)
            dir="${2}"; shift 2
            ;;
        (-p|--package)
            pkg="${2}"; shift 2
            ;;
32
33
34
        (-r|--random)
            random="${2}"; shift 2
            ;;
35
36
37
38
39
40
41
42
        (--)
            shift; break
            ;;
        esac
    done
    if [ -z "${cfg}" ]; then
        printf "error: no config snippet specified\n" >&2; exit 1
    fi
43
44
45
    if [ ! -e "${cfg}" ]; then
        printf "error: %s: no such file\n" "${cfg}" >&2; exit 1
    fi
46
47
48
49
50
51
52
    if [ -z "${dir}" ]; then
        dir="${HOME}/br-test-pkg"
    fi

    # Extract the URLs of the toolchains; drop internal toolchains
    # E.g.: http://server/path/to/name.config,arch,libc
    #  -->  http://server/path/to/name.config
53
54
55
56
57
58
59
60
    toolchains=($(curl -s "${TOOLCHAINS_URL}" \
                  |sed -r -e 's/,.*//; /internal/d;' \
                  |if [ ${random} -gt 0 ]; then \
                      sort -R |head -n ${random}
                   else
                      cat
                   fi |sort
                 )
61
62
               )

63
64
    nb_tc="${#toolchains[@]}"
    if [ ${nb_tc} -eq 0 ]; then
65
66
67
        printf "error: no toolchain found (networking issue?)\n" >&2; exit 1
    fi

68
69
70
    nb=0
    nb_skip=0
    nb_fail=0
71
    nb_legal=0
72
    for toolchainconfig in "${toolchains[@]}"; do
73
        : $((nb++))
74
75
76
77
78
        # Using basename(1) on a URL works nicely
        toolchain="$(basename "${toolchainconfig}" .config)"
        build_dir="${dir}/${toolchain}"
        printf "%40s [%*d/%d]: " "${toolchain}" ${#nb_tc} ${nb} ${nb_tc}
        build_one "${build_dir}" "${toolchainconfig}" "${cfg}" "${pkg}" && ret=0 || ret=${?}
79
        case ${ret} in
80
81
82
        (0) printf "OK\n";;
        (1) : $((nb_skip++)); printf "SKIPPED\n";;
        (2) : $((nb_fail++)); printf "FAILED\n";;
83
        (3) : $((nb_legal++)); printf "FAILED\n";;
84
        esac
85
    done
86

87
88
    printf "%d builds, %d skipped, %d build failed, %d legal-info failed\n" \
        ${nb} ${nb_skip} ${nb_fail} ${nb_legal}
89
90
91
92
93
94
95
96
97
98
99
}

build_one() {
    local dir="${1}"
    local url="${2}"
    local cfg="${3}"
    local pkg="${4}"

    mkdir -p "${dir}"

    if ! curl -s "${url}" >"${dir}/.config"; then
100
        return 2
101
102
    fi

103
    cat "support/config-fragments/minimal.config" "${cfg}" >>"${dir}/.config"
104

105
    if ! make O="${dir}" olddefconfig > "${dir}/logfile" 2>&1; then
106
        return 2
107
108
109
110
111
    fi
    # We want all the options from the snippet to be present as-is (set
    # or not set) in the actual .config; if one of them is not, it means
    # some dependency from the toolchain or arch is not available, in
    # which case this config is untestable and we skip it.
112
113
114
115
    # We don't care about the locale to sort in, as long as both sort are
    # done in the same locale.
    comm -23 <(sort "${cfg}") <(sort "${dir}/.config") >"${dir}/missing.config"
    if [ -s "${dir}/missing.config" ]; then
116
        return 1
117
118
119
    fi
    # Remove file, it's empty anyway.
    rm -f "${dir}/missing.config"
120
121
122

    if [ -n "${pkg}" ]; then
        if ! make O="${dir}" "${pkg}-dirclean" >> "${dir}/logfile" 2>&1; then
123
            return 2
124
125
126
127
128
        fi
    fi

    # shellcheck disable=SC2086
    if ! make O="${dir}" ${pkg} >> "${dir}/logfile" 2>&1; then
129
        return 2
130
    fi
131
132
133
134
135
136
137
138

    # legal-info done systematically, because some packages have different
    # sources depending on the configuration (e.g. lua-5.2 vs. lua-5.3)
    if [ -n "${pkg}" ]; then
        if ! make O="${dir}" "${pkg}-legal-info" >> "${dir}/logfile" 2>&1; then
            return 3
        fi
    fi
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
}

help() {
    cat <<_EOF_
test-pkg: test-build a package against various toolchains and architectures

The supplied config snippet is appended to each toolchain config, the
resulting configuration is checked to ensure it still contains all options
specified in the snippet; if any is missing, the build is skipped, on the
assumption that the package under test requires a toolchain or architecture
feature that is missing.

In case failures are noticed, you can fix the package and just re-run the
same command again; it will re-run the test where it failed. If you did
specify a package (with -p), the package build dir will be removed first.

The list of toolchains is retrieved from the Buildroot autobuilders, available
at ${TOOLCHAINS_URL}.

Options:

    -h, --help
        Print this help.

    -c CFG, --config-snippet CFG
        Use the CFG file as the source for the config snippet. This file
        should contain all the config options required to build a package.

    -d DIR, --build-dir DIR
        Do the builds in directory DIR, one sub-dir per toolchain.

    -p PKG, --package PKG
        Test-build the package PKG, by running 'make PKG'; if not specified,
        just runs 'make'.

174
175
176
177
    -r N, --random N
        Limit the tests to the N randomly selected toolchains, instead of
        building with all toolchains.

178
179
180
181
182
183
184
185
186
187
188
189
190
191
Example:

    Testing libcec would require a config snippet that contains:
        BR2_PACKAGE_LIBCEC=y

    Testing libcurl with openSSL support would require a snippet such as:
        BR2_PACKAGE_OPENSSL=y
        BR2_PACKAGE_LIBCURL=y

_EOF_
}

my_name="${0##*/}"
main "${@}"