CI: Add a check for building tools for PyPi
[platform/kernel/u-boot.git] / .gitlab-ci.yml
1 # SPDX-License-Identifier: GPL-2.0+
2
3 # Grab our configured image.  The source for this is found
4 # in the u-boot tree at tools/docker/Dockerfile
5 image: trini/u-boot-gitlab-ci-runner:jammy-20230126-17Feb2023
6
7 # We run some tests in different order, to catch some failures quicker.
8 stages:
9   - testsuites
10   - test.py
11   - world build
12
13 .buildman_and_testpy_template: &buildman_and_testpy_dfn
14   stage: test.py
15   before_script:
16     # Clone uboot-test-hooks
17     - git config --global --add safe.directory "${CI_PROJECT_DIR}"
18     - git clone --depth=1 https://source.denx.de/u-boot/u-boot-test-hooks /tmp/uboot-test-hooks
19     - ln -s travis-ci /tmp/uboot-test-hooks/bin/`hostname`
20     - ln -s travis-ci /tmp/uboot-test-hooks/py/`hostname`
21     - grub-mkimage --prefix="" -o ~/grub_x86.efi -O i386-efi normal  echo lsefimmap lsefi lsefisystab efinet tftp minicmd
22     - grub-mkimage --prefix="" -o ~/grub_x64.efi -O x86_64-efi normal  echo lsefimmap lsefi lsefisystab efinet tftp minicmd
23     - if [[ "${TEST_PY_BD}" == "qemu-riscv32_spl" ]]; then
24         wget -O - https://github.com/riscv/opensbi/releases/download/v0.9/opensbi-0.9-rv-bin.tar.xz | tar -C /tmp -xJ;
25         export OPENSBI=/tmp/opensbi-0.9-rv-bin/share/opensbi/ilp32/generic/firmware/fw_dynamic.bin;
26       fi
27     - if [[ "${TEST_PY_BD}" == "qemu-riscv64_spl" ]] || [[ "${TEST_PY_BD}" == "sifive_unleashed" ]]; then
28         wget -O - https://github.com/riscv/opensbi/releases/download/v0.9/opensbi-0.9-rv-bin.tar.xz | tar -C /tmp -xJ;
29         export OPENSBI=/tmp/opensbi-0.9-rv-bin/share/opensbi/lp64/generic/firmware/fw_dynamic.bin;
30       fi
31
32   after_script:
33     - rm -rf /tmp/uboot-test-hooks /tmp/venv
34   script:
35     # If we've been asked to use clang only do one configuration.
36     - export UBOOT_TRAVIS_BUILD_DIR=/tmp/${TEST_PY_BD}
37     - echo BUILD_ENV ${BUILD_ENV}
38     - if [ -n "${BUILD_ENV}" ]; then
39         export ${BUILD_ENV};
40       fi
41     - tools/buildman/buildman -o ${UBOOT_TRAVIS_BUILD_DIR} -w -E -W -e
42         --board ${TEST_PY_BD} ${OVERRIDE}
43     - cp ~/grub_x86.efi $UBOOT_TRAVIS_BUILD_DIR/
44     - cp ~/grub_x64.efi $UBOOT_TRAVIS_BUILD_DIR/
45     - cp /opt/grub/grubriscv64.efi $UBOOT_TRAVIS_BUILD_DIR/grub_riscv64.efi
46     - cp /opt/grub/grubaa64.efi $UBOOT_TRAVIS_BUILD_DIR/grub_arm64.efi
47     - cp /opt/grub/grubarm.efi $UBOOT_TRAVIS_BUILD_DIR/grub_arm.efi
48     # create sdcard / spi-nor images for sifive unleashed using genimage
49     - if [[ "${TEST_PY_BD}" == "sifive_unleashed" ]]; then
50         mkdir -p root;
51         cp ${UBOOT_TRAVIS_BUILD_DIR}/spl/u-boot-spl.bin .;
52         cp ${UBOOT_TRAVIS_BUILD_DIR}/u-boot.itb .;
53         rm -rf tmp;
54         genimage --inputpath . --config board/sifive/unleashed/genimage_sdcard.cfg;
55         cp images/sdcard.img ${UBOOT_TRAVIS_BUILD_DIR}/;
56         rm -rf tmp;
57         genimage --inputpath . --config board/sifive/unleashed/genimage_spi-nor.cfg;
58         cp images/spi-nor.img ${UBOOT_TRAVIS_BUILD_DIR}/;
59       fi
60     - if [[ "${TEST_PY_BD}" == "coreboot" ]]; then
61         wget -O -
62           "https://drive.google.com/uc?id=1x6nrtWIyIRPLS2cQBwYTnT2TbOI8UjmM&export=download" |
63           xz -dc >${UBOOT_TRAVIS_BUILD_DIR}/coreboot.rom;
64         wget -O -
65           "https://drive.google.com/uc?id=149Cz-5SZXHNKpi9xg6R_5XITWohu348y&export=download" >
66           cbfstool;
67         chmod a+x cbfstool;
68         ./cbfstool ${UBOOT_TRAVIS_BUILD_DIR}/coreboot.rom add-flat-binary -f ${UBOOT_TRAVIS_BUILD_DIR}/u-boot.bin -n fallback/payload -c LZMA -l 0x1110000 -e 0x1110000;
69       fi
70     - virtualenv -p /usr/bin/python3 /tmp/venv
71     - . /tmp/venv/bin/activate
72     - pip install -r test/py/requirements.txt
73     # "${var:+"-k $var"}" expands to "" if $var is empty, "-k $var" if not
74     - export PATH=/opt/qemu/bin:/tmp/uboot-test-hooks/bin:${PATH};
75       export PYTHONPATH=/tmp/uboot-test-hooks/py/travis-ci;
76       ./test/py/test.py -ra --bd ${TEST_PY_BD} ${TEST_PY_ID}
77         ${TEST_PY_TEST_SPEC:+"-k ${TEST_PY_TEST_SPEC}"}
78         --build-dir "$UBOOT_TRAVIS_BUILD_DIR"
79     # It seems that the files in /tmp go away, so copy out what we need
80     - if [[ "${TEST_PY_BD}" == "coreboot" ]]; then
81         cp -v /tmp/coreboot/*.{html,css} .;
82       fi
83
84 build all 32bit ARM platforms:
85   stage: world build
86   script:
87     - ret=0;
88       git config --global --add safe.directory "${CI_PROJECT_DIR}";
89       ./tools/buildman/buildman -o /tmp -PEWM arm -x aarch64 || ret=$?;
90       if [[ $ret -ne 0 ]]; then
91         ./tools/buildman/buildman -o /tmp -seP;
92         exit $ret;
93       fi;
94
95 build all 64bit ARM platforms:
96   stage: world build
97   script:
98     - virtualenv -p /usr/bin/python3 /tmp/venv
99     - . /tmp/venv/bin/activate
100     - ret=0;
101       git config --global --add safe.directory "${CI_PROJECT_DIR}";
102       ./tools/buildman/buildman -o /tmp -PEWM aarch64 || ret=$?;
103       if [[ $ret -ne 0 ]]; then
104         ./tools/buildman/buildman -o /tmp -seP;
105         exit $ret;
106       fi;
107
108 build all PowerPC platforms:
109   stage: world build
110   script:
111     - ret=0;
112       git config --global --add safe.directory "${CI_PROJECT_DIR}";
113       ./tools/buildman/buildman -o /tmp -P -E -W powerpc || ret=$?;
114       if [[ $ret -ne 0 ]]; then
115         ./tools/buildman/buildman -o /tmp -seP;
116         exit $ret;
117       fi;
118
119 build all other platforms:
120   stage: world build
121   script:
122     - ret=0;
123       git config --global --add safe.directory "${CI_PROJECT_DIR}";
124       ./tools/buildman/buildman -o /tmp -PEWM -x arm,powerpc || ret=$?;
125       if [[ $ret -ne 0 ]]; then
126         ./tools/buildman/buildman -o /tmp -seP;
127         exit $ret;
128       fi;
129
130 check for new CONFIG symbols outside Kconfig:
131   stage: testsuites
132   script:
133     - git config --global --add safe.directory "${CI_PROJECT_DIR}"
134     # If grep succeeds and finds a match the test fails as we should
135     # have no matches.
136     - git grep -E '^#[[:blank:]]*(define|undef)[[:blank:]]*CONFIG_'
137         :^doc/ :^arch/arm/dts/ :^scripts/kconfig/lkc.h
138         :^include/linux/kconfig.h :^tools/ && exit 1 || exit 0
139
140 # QA jobs for code analytics
141 # static code analysis with cppcheck (we can add --enable=all later)
142 cppcheck:
143   stage: testsuites
144   script:
145     - cppcheck -j$(nproc) --force --quiet --inline-suppr .
146
147 # search for TODO within source tree
148 grep TODO/FIXME/HACK:
149   stage: testsuites
150   script:
151     - grep -r TODO .
152     - grep -r FIXME .
153     # search for HACK within source tree and ignore HACKKIT board
154     - grep -r HACK . | grep -v HACKKIT
155
156 # build documentation
157 docs:
158   stage: testsuites
159   script:
160     - virtualenv -p /usr/bin/python3 /tmp/venvhtml
161     - . /tmp/venvhtml/bin/activate
162     - pip install -r doc/sphinx/requirements.txt
163     - make htmldocs
164     - make infodocs
165
166 # some statistics about the code base
167 sloccount:
168   stage: testsuites
169   script:
170     - sloccount .
171
172 # ensure all configs have MAINTAINERS entries
173 Check for configs without MAINTAINERS entry:
174   stage: testsuites
175   script:
176     - ./tools/buildman/buildman -R
177
178 # Ensure host tools build
179 Build tools-only:
180   stage: testsuites
181   script:
182     - make tools-only_config tools-only -j$(nproc)
183
184 # Ensure env tools build
185 Build envtools:
186   stage: testsuites
187   script:
188     - make tools-only_config envtools -j$(nproc)
189
190 Run binman, buildman, dtoc, Kconfig and patman testsuites:
191   stage: testsuites
192   script:
193     - git config --global user.name "GitLab CI Runner";
194       git config --global user.email trini@konsulko.com;
195       git config --global --add safe.directory "${CI_PROJECT_DIR}";
196       export USER=gitlab;
197       virtualenv -p /usr/bin/python3 /tmp/venv;
198       . /tmp/venv/bin/activate;
199       pip install -r test/py/requirements.txt;
200       export UBOOT_TRAVIS_BUILD_DIR=/tmp/sandbox_spl;
201       export PYTHONPATH="${UBOOT_TRAVIS_BUILD_DIR}/scripts/dtc/pylibfdt";
202       export PATH="${UBOOT_TRAVIS_BUILD_DIR}/scripts/dtc:${PATH}";
203       set +e;
204       ./tools/buildman/buildman -T0 -o ${UBOOT_TRAVIS_BUILD_DIR} -w
205         --board sandbox_spl;
206       set -e;
207       ./tools/binman/binman --toolpath ${UBOOT_TRAVIS_BUILD_DIR}/tools test;
208       ./tools/buildman/buildman -t;
209       ./tools/dtoc/dtoc -t;
210       ./tools/patman/patman test;
211       make testconfig
212
213 Run tests for Nokia RX-51 (aka N900):
214   stage: testsuites
215   script:
216     - mkdir nokia_rx51_tmp;
217       ln -s /opt/nokia/u-boot-gen-combined nokia_rx51_tmp/;
218       ln -s /opt/nokia/qemu-n900.tar.gz nokia_rx51_tmp/;
219       ln -s /opt/nokia/kernel_2.6.28-20103103+0m5_armel.deb nokia_rx51_tmp/;
220       ln -s /opt/nokia/libc6_2.5.1-1eglibc27+0m5_armel.deb nokia_rx51_tmp/;
221       ln -s /opt/nokia/busybox_1.10.2.legal-1osso30+0m5_armel.deb nokia_rx51_tmp/;
222       ln -s /opt/nokia/qemu-system-arm nokia_rx51_tmp/;
223       export PATH=/opt/gcc-12.2.0-nolibc/arm-linux-gnueabi/bin:$PATH;
224       test/nokia_rx51_test.sh
225
226 # Check for any pylint regressions
227 Run pylint:
228   stage: testsuites
229   script:
230     - git config --global --add safe.directory "${CI_PROJECT_DIR}"
231     - pip install -r test/py/requirements.txt
232     - pip install asteval pylint==2.12.2 pyopenssl
233     - export PATH=${PATH}:~/.local/bin
234     - echo "[MASTER]" >> .pylintrc
235     - echo "load-plugins=pylint.extensions.docparams" >> .pylintrc
236     - export UBOOT_TRAVIS_BUILD_DIR=/tmp/sandbox_spl
237     - set +e
238     - ./tools/buildman/buildman -T0 -o ${UBOOT_TRAVIS_BUILD_DIR} -w
239         --board sandbox_spl
240     - set -e
241     - pylint --version
242     - export PYTHONPATH="${UBOOT_TRAVIS_BUILD_DIR}/scripts/dtc/pylibfdt"
243     - make pylint_err
244
245 # Check for pre-schema driver model tags
246 Check for pre-schema tags:
247   stage: testsuites
248   script:
249     - git config --global --add safe.directory "${CI_PROJECT_DIR}";
250     # If grep succeeds and finds a match the test fails as we should
251     # have no matches.
252     - git grep u-boot,dm- -- '*.dts*' && exit 1 || exit 0
253
254 # Check we can package the Python tools
255 Check packing of Python tools:
256   stage: testsuites
257   script:
258     - make pip
259
260 # Test sandbox with test.py
261 sandbox test.py:
262   variables:
263     TEST_PY_BD: "sandbox"
264   <<: *buildman_and_testpy_dfn
265
266 sandbox with clang test.py:
267   variables:
268     TEST_PY_BD: "sandbox"
269     OVERRIDE: "-O clang-14"
270   <<: *buildman_and_testpy_dfn
271
272 sandbox without LTO test.py:
273   variables:
274     TEST_PY_BD: "sandbox"
275     BUILD_ENV: "NO_LTO=1"
276   <<: *buildman_and_testpy_dfn
277
278 sandbox_spl test.py:
279   variables:
280     TEST_PY_BD: "sandbox_spl"
281     TEST_PY_TEST_SPEC: "test_ofplatdata or test_handoff or test_spl"
282   <<: *buildman_and_testpy_dfn
283
284 sandbox_noinst_test.py:
285   variables:
286     TEST_PY_BD: "sandbox_noinst"
287     TEST_PY_TEST_SPEC: "test_ofplatdata or test_handoff or test_spl"
288   <<: *buildman_and_testpy_dfn
289
290 sandbox_vpl test.py:
291   variables:
292     TEST_PY_BD: "sandbox_vpl"
293     TEST_PY_TEST_SPEC: "test_vpl_help or test_spl"
294   <<: *buildman_and_testpy_dfn
295
296 # Enable tracing and disable LTO, to ensure functions are not elided
297 sandbox trace_test.py:
298   variables:
299     TEST_PY_BD: "sandbox"
300     BUILD_ENV: "FTRACE=1 NO_LTO=1"
301     TEST_PY_TEST_SPEC: "trace"
302     OVERRIDE: "-a CONFIG_TRACE=y -a CONFIG_TRACE_EARLY=y -a CONFIG_TRACE_EARLY_SIZE=0x01000000"
303   <<: *buildman_and_testpy_dfn
304
305 evb-ast2500 test.py:
306   variables:
307     TEST_PY_BD: "evb-ast2500"
308     TEST_PY_ID: "--id qemu"
309   <<: *buildman_and_testpy_dfn
310
311 evb-ast2600 test.py:
312   variables:
313     TEST_PY_BD: "evb-ast2600"
314     TEST_PY_ID: "--id qemu"
315   <<: *buildman_and_testpy_dfn
316
317 sandbox_flattree test.py:
318   variables:
319     TEST_PY_BD: "sandbox_flattree"
320   <<: *buildman_and_testpy_dfn
321
322 vexpress_ca9x4 test.py:
323   variables:
324     TEST_PY_BD: "vexpress_ca9x4"
325     TEST_PY_ID: "--id qemu"
326   <<: *buildman_and_testpy_dfn
327
328 integratorcp_cm926ejs test.py:
329   variables:
330     TEST_PY_BD: "integratorcp_cm926ejs"
331     TEST_PY_TEST_SPEC: "not sleep"
332     TEST_PY_ID: "--id qemu"
333   <<: *buildman_and_testpy_dfn
334
335 qemu_arm test.py:
336   variables:
337     TEST_PY_BD: "qemu_arm"
338     TEST_PY_TEST_SPEC: "not sleep"
339   <<: *buildman_and_testpy_dfn
340
341 qemu_arm64 test.py:
342   variables:
343     TEST_PY_BD: "qemu_arm64"
344     TEST_PY_TEST_SPEC: "not sleep"
345   <<: *buildman_and_testpy_dfn
346
347 qemu_malta test.py:
348   variables:
349     TEST_PY_BD: "malta"
350     TEST_PY_TEST_SPEC: "not sleep and not efi"
351     TEST_PY_ID: "--id qemu"
352   <<: *buildman_and_testpy_dfn
353
354 qemu_maltael test.py:
355   variables:
356     TEST_PY_BD: "maltael"
357     TEST_PY_TEST_SPEC: "not sleep and not efi"
358     TEST_PY_ID: "--id qemu"
359   <<: *buildman_and_testpy_dfn
360
361 qemu_malta64 test.py:
362   variables:
363     TEST_PY_BD: "malta64"
364     TEST_PY_TEST_SPEC: "not sleep and not efi"
365     TEST_PY_ID: "--id qemu"
366   <<: *buildman_and_testpy_dfn
367
368 qemu_malta64el test.py:
369   variables:
370     TEST_PY_BD: "malta64el"
371     TEST_PY_TEST_SPEC: "not sleep and not efi"
372     TEST_PY_ID: "--id qemu"
373   <<: *buildman_and_testpy_dfn
374
375 qemu-ppce500 test.py:
376   variables:
377     TEST_PY_BD: "qemu-ppce500"
378     TEST_PY_TEST_SPEC: "not sleep"
379   <<: *buildman_and_testpy_dfn
380
381 qemu-riscv32 test.py:
382   variables:
383     TEST_PY_BD: "qemu-riscv32"
384     TEST_PY_TEST_SPEC: "not sleep"
385   <<: *buildman_and_testpy_dfn
386
387 qemu-riscv64 test.py:
388   variables:
389     TEST_PY_BD: "qemu-riscv64"
390     TEST_PY_TEST_SPEC: "not sleep"
391   <<: *buildman_and_testpy_dfn
392
393 qemu-riscv32_spl test.py:
394   variables:
395     TEST_PY_BD: "qemu-riscv32_spl"
396     TEST_PY_TEST_SPEC: "not sleep"
397   <<: *buildman_and_testpy_dfn
398
399 qemu-riscv64_spl test.py:
400   variables:
401     TEST_PY_BD: "qemu-riscv64_spl"
402     TEST_PY_TEST_SPEC: "not sleep"
403   <<: *buildman_and_testpy_dfn
404
405 qemu-x86 test.py:
406   variables:
407     TEST_PY_BD: "qemu-x86"
408     TEST_PY_TEST_SPEC: "not sleep"
409   <<: *buildman_and_testpy_dfn
410
411 qemu-x86_64 test.py:
412   variables:
413     TEST_PY_BD: "qemu-x86_64"
414     TEST_PY_TEST_SPEC: "not sleep"
415   <<: *buildman_and_testpy_dfn
416
417 r2dplus_i82557c test.py:
418   variables:
419     TEST_PY_BD: "r2dplus"
420     TEST_PY_ID: "--id i82557c_qemu"
421   <<: *buildman_and_testpy_dfn
422
423 r2dplus_pcnet test.py:
424   variables:
425     TEST_PY_BD: "r2dplus"
426     TEST_PY_ID: "--id pcnet_qemu"
427   <<: *buildman_and_testpy_dfn
428
429 r2dplus_rtl8139 test.py:
430   variables:
431     TEST_PY_BD: "r2dplus"
432     TEST_PY_ID: "--id rtl8139_qemu"
433   <<: *buildman_and_testpy_dfn
434
435 r2dplus_tulip test.py:
436   variables:
437     TEST_PY_BD: "r2dplus"
438     TEST_PY_ID: "--id tulip_qemu"
439   <<: *buildman_and_testpy_dfn
440
441 sifive_unleashed_sdcard test.py:
442   variables:
443     TEST_PY_BD: "sifive_unleashed"
444     TEST_PY_ID: "--id sdcard_qemu"
445   <<: *buildman_and_testpy_dfn
446
447 sifive_unleashed_spi-nor test.py:
448   variables:
449     TEST_PY_BD: "sifive_unleashed"
450     TEST_PY_ID: "--id spi-nor_qemu"
451   <<: *buildman_and_testpy_dfn
452
453 xilinx_zynq_virt test.py:
454   variables:
455     TEST_PY_BD: "xilinx_zynq_virt"
456     TEST_PY_TEST_SPEC: "not sleep"
457     TEST_PY_ID: "--id qemu"
458   <<: *buildman_and_testpy_dfn
459
460 xilinx_versal_virt test.py:
461   variables:
462     TEST_PY_BD: "xilinx_versal_virt"
463     TEST_PY_TEST_SPEC: "not sleep"
464     TEST_PY_ID: "--id qemu"
465   <<: *buildman_and_testpy_dfn
466
467 xtfpga test.py:
468   variables:
469     TEST_PY_BD: "xtfpga"
470     TEST_PY_TEST_SPEC: "not sleep"
471     TEST_PY_ID: "--id qemu"
472   <<: *buildman_and_testpy_dfn
473
474 coreboot test.py:
475   variables:
476     TEST_PY_BD: "coreboot"
477     TEST_PY_TEST_SPEC: "not sleep"
478     TEST_PY_ID: "--id qemu"
479   artifacts:
480     paths:
481       - "*.html"
482       - "*.css"
483     expire_in: 1 week
484   <<: *buildman_and_testpy_dfn