Files
buildroot/support/testing/tests/package/test_weston.py
Romain Naour c9df1b64b2 support/testing: generate runtime test jobs with runner tags
We have our own GitLab-CI runner, but with only one we can't run many
jobs in parallel so it takes a very long time before all the tests have
completed. In addition, if that runner goes down, we have nothing at
all.

GitLab offers the following machine types for hosted runners on Linux
x86-64 [1]. The default is the "small" runner. Using a larger runner
increases the "Cost factor" [2].

For opensource projects, the Cost factor is reduced to 0.5 (1 minute per
2 minutes of job time) whatever the runner type.

Runner Tag                                             vCPUs   Memory  Storage  Cost factor (OSS)
saas-linux-small-amd64 (default)                           2     8 GB    30 GB     1 (0.5)
saas-linux-medium-amd64                                    4    16 GB    50 GB     2 (0.5)
saas-linux-large-amd64 (Premium and Ultimate only)         8    32 GB   100 GB     3 (0.5)
saas-linux-xlarge-amd64 (Premium and Ultimate only)       16    64 GB   200 GB     6 (0.5)
saas-linux-2xlarge-amd64 (Premium and Ultimate only)      32   128 GB   200 GB    12 (0.5)

Compute minutes consumed by a job is calculated by:

  Job duration / 60 * Cost factor

(Job duration: The time, in seconds, that a job took to run, not
including time spent in the created or pending statuses.)

Thanks to the GitLab OSS program [3], Buildroot benefits from a free
Ultimate subscription and can use GitLab shared runners tagged with
saas-linux-{large, xlarge, 2xlarge}-amd64. In addition, we receive
50,000 free runner minutes per month.

In order to use one of those tags in Buildroot GitLab-CI jobs, we have
to classify all tests by resource requirement, to make sure the job
doesn't fail because it times out or has insufficient memory or disk
space. While we usually shouldn't use the largest runner for
everything, we can use larger runner without cost penalty thanks to
the cost factor reduced to 0.5 for opensource projects. This will
reduce the CI minutes consumed by a CPU intensive job.

First we introduce some new templates used to add the corresponding
runner tag to a runtime test job (reusing the GitLab terminology).

    .runner-{small,medium,large,xlarge,2xlarge}

Most of our tests are fast (checkpackage, test_external_bootlin...), so
saas-linux-small-amd64 runner tag is enough. Default to this tag if
nothing else is specified.

Add a comment next to the test class to provide the runner tag.
This runner tag is retrieved when generating the
generated-gitlab-ci.yml file used to create the child pipeline where
the runtime test jobs are executed.

We use the list of runtime tests returned by node2:

  "tests.boot.test_edk2.TestEdk2.test_run"

We convert each element of this list to get the path to the test source
file and the name of the test:

  "support/testing/tests/boot/test_edk2.py"

  TestEdk2

With that, we can grep into the test source file to retrieve the runner
tag placed one line above the test class:

  # GitLab-runner: large
  class TestEdk2(infra.basetest.BRTest):

Once the runner tag is retrieved, it's used to use the corresponding
runner template to the runtime test job:

  tests.boot.test_edk2.TestEdk2.test_run: { extends: [ .runtime_test_base, .runner-large ]}

GitLab runners hosted by the Buildroot project should be able to run
any jobs, so they should be tagged with Gitlab runner tags
(saas-linux-{small,medium,large,xlarge,2xlarge}-amd64).
A specific runner tag "buildroot-runner" can be used to allow running
a job only on such runners.

If a test can't be executed by any shared GitLab-CI runners, we have
to use a runner owned by the Buildroot project. In this case we have
to use a specific template ".runner-buildroot-runner-only" in order to
add the specific runner tag "buildroot-runner" to the job running the
test. There is no such runtime test at the moment.

The proposed classification is based on a previous pipeline analysis
[5]:

  - Tests lasting more than 3 hours will use 2xlarge runners.
  - Tests lasting more than 2 hours will use xlarge runners.
  - Tests lasting more than 1 hours will use large runners.
  - Tests building a kernel or a toolchain will use medium runners.
  - All other tests will use small runners when possible.

CI minute cost estimate:

tests.package.test_clang.TestClangCompilerRT.test_run lasts 4h25 on the
Buildroot runner. If we this duration for 2xlarge runners, the CI
minute consumed would be:

  (15900 / 60) * 0.5 = 133

With 6 jobs using a 2xlarge runners we used ~795 CI minutes.

tests.package.test_kmscube.TestKmsCube.test_run list 2h04 on the
Buildroot runner. If we	this duration for xlarge runners, the CI
minute consumed would be:

  (7440 / 60) * 0.5 = 62

With 4 jobs using a xlarge runners we used ~248 CI minutes.

tests.package.test_weston.TestWeston.test_run last 1h15 on th
Buildroot runner. If we this duration for large runners, the CI
minute consumed would be:

  (4500 / 60) * 0.5 = 37.5

With 28 jobs using a large runners we used ~1050 CI minutes.

tests.package.test_gstreamer1.TestGstreamer1.test_run last 46min on the
Buildroot runner. If we this duration for large runners, the CI
minute consumed would be:

  (2760 / 60) * 0.5 = 23

With 31 jobs using a medium runners we used ~713 CI minutes.

tests.package.test_python.TestPython3Py.test_run last 13min on the
Buildroot runner. If we this duration for large runners, the CI
minute consumed would be:

  (780 / 60) * 0.5 = 6.5

With 691 jobs using a medium runners we used ~4491 CI minutes.

In total, one pipeline for the runtime tests cost ~7297 CI minutes.
After a first try [6], we are actually using 8000 CI minutes per
pipeline.

We run such pipeline once a week (on Monday), one for each Buildroot
releases every 3 month, one for each stable and LTS release per month,
and one for each release candidate (3).

Worst case (release month):
(4 weeks + 1 release + 1 stable + 1 LTS + 3 release candidate) * 8000 CI
minutes: 80000 CI minutes / 50000.

So we would spend the minutes very quickly in the worst case scenario.
We have to keep one pipeline under 5000 CI minutes.

[1] https://docs.gitlab.com/ci/runners/hosted_runners/linux/#machine-types-available-for-linux---x86-64
[2] https://docs.gitlab.com/ci/pipelines/compute_minutes/#cost-factors
    https://docs.gitlab.com/ci/pipelines/compute_minutes/#compute-usage-calculation
    https://docs.gitlab.com/ci/pipelines/compute_minutes/#cost-factors-of-hosted-runners-for-gitlabcom
[3] https://gitlab.com/buildroot.org/gitlab-oss
[4] https://docs.gitlab.com/ci/runners/hosted_runners/#gitlabcom-hosted-runner-workflow
[5] https://gitlab.com/buildroot.org/buildroot/-/pipelines/2416603721
[6] https://gitlab.com/buildroot.org/buildroot/-/pipelines/2562421098

Signed-off-by: Romain Naour <romain.naour@smile.fr>
[Arnout:
 - simplify parsing of test_file and test_name;
 - match the entire test_name instead of substring;
 - assume "small" by default;
 - remove the "small" tags;
 - use "gitlab-runner" instead of "Gitlab-runner".
]
Signed-off-by: Arnout Vandecappelle <arnout@rnout.be>

Signed-off-by: Arnout Vandecappelle <arnout@rnout.be>
2026-05-30 22:26:13 +02:00

155 lines
6.1 KiB
Python

import os
import time
import infra.basetest
from ..graphics_base import GraphicsBase
# gitlab-runner: large
class TestWeston(infra.basetest.BRTest, GraphicsBase):
config = \
"""
BR2_aarch64=y
BR2_TOOLCHAIN_EXTERNAL=y
BR2_ROOTFS_DEVICE_CREATION_DYNAMIC_EUDEV=y
BR2_TARGET_GENERIC_GETTY_PORT="ttyAMA0"
BR2_ROOTFS_OVERLAY="{}"
BR2_PER_PACKAGE_DIRECTORIES=y
BR2_LINUX_KERNEL=y
BR2_LINUX_KERNEL_CUSTOM_VERSION=y
BR2_LINUX_KERNEL_CUSTOM_VERSION_VALUE="6.1.44"
BR2_LINUX_KERNEL_USE_CUSTOM_CONFIG=y
BR2_LINUX_KERNEL_CUSTOM_CONFIG_FILE="board/qemu/aarch64-virt/linux.config"
BR2_LINUX_KERNEL_CONFIG_FRAGMENT_FILES="{}"
BR2_PACKAGE_LIBDRM=y
BR2_PACKAGE_MESA3D=y
BR2_PACKAGE_MESA3D_GALLIUM_DRIVER_SOFTPIPE=y
BR2_PACKAGE_MESA3D_LLVM=y
BR2_PACKAGE_MESA3D_OPENGL_EGL=y
BR2_PACKAGE_MESA3D_OPENGL_ES=y
BR2_PACKAGE_WAYLAND_UTILS=y
BR2_PACKAGE_WESTON=y
BR2_PACKAGE_WESTON_SIMPLE_CLIENTS=y
BR2_TARGET_ROOTFS_CPIO=y
BR2_TARGET_ROOTFS_CPIO_GZIP=y
# BR2_TARGET_ROOTFS_TAR is not set
""".format(
infra.filepath("tests/package/test_weston/overlay"),
infra.filepath("tests/package/test_weston/linux-vkms.fragment")
)
def start_weston(self):
self.assertRunOk("export XDG_RUNTIME_DIR=/tmp")
cmd = "( weston"
cmd += " --config=/etc/weston.ini"
cmd += " --continue-without-input"
cmd += " --log=/tmp/weston.log"
cmd += " &> /dev/null & )"
self.assertRunOk(cmd)
self.assertRunOk("export WAYLAND_DISPLAY=wayland-1")
def wait_for_weston(self):
# We wait for the wayland socket to appear...
wayland_socket = "${XDG_RUNTIME_DIR}/${WAYLAND_DISPLAY}"
cmd = f"while [ ! -e \"{wayland_socket}\" ] ; do sleep 1 ; done"
self.assertRunOk(cmd, timeout=10)
time.sleep(4)
def stop_weston(self):
cmd = "killall weston"
self.assertRunOk(cmd)
time.sleep(3)
def test_run(self):
img = os.path.join(self.builddir, "images", "rootfs.cpio.gz")
kern = os.path.join(self.builddir, "images", "Image")
self.emulator.boot(arch="aarch64",
kernel=kern,
kernel_cmdline=["console=ttyAMA0", "vt.global_cursor_default=0"],
options=["-M", "virt",
"-cpu", "cortex-a57",
"-smp", "4",
"-m", "512M",
"-initrd", img])
self.emulator.login()
# This test uses the vkms DRM Kernel driver. This driver can
# generate kernel warning messages in some cases (e.g. "vblank
# timer overrun"). Those messages can happen on slow test
# runners. This warning is not an issue in this test: it is
# not checking performance here; it just checks the rendering
# pipeline is functional. For that reason, this test adds the
# file "/etc/default/klogd" to only show emergency messages
# (level value 0) on the console.
# Check the weston binary can execute
self.assertRunOk("weston --version")
self.start_weston()
self.wait_for_weston()
# Check a simple info client can communicate with the compositor
self.assertRunOk("wayland-info", timeout=10)
# We get 10 consecutive DRM frame CRCs and count how many
# unique CRCs we have. Since weston is supposed to run idle,
# we should have 10 times the same display CRC.
self.assertTrue(len(self.get_n_fb_crc(uniq=True)) == 1)
# We save the CRC value of an empty weston desktop for
# later...
weston_desktop_crc = self.get_n_fb_crc(count=1)[0]
# We start the weston-simple-egl in background... Every
# rendered frame is supposed to be different (as the triangle
# animation is derived from the system time). Since all the
# rendering (client application and compositor) is in
# software, we sleep a bit to let those program to settle.
self.assertRunOk("( weston-simple-egl >/dev/null 2>&1 & )")
# Since the weston-simple-egl client is supposed to run and
# display something, we are now supposed to measure a
# different display CRC than the one we measured when the
# desktop was empty.
for i in range(600):
crc = self.get_n_fb_crc(count=1)[0]
if crc != weston_desktop_crc:
break
time.sleep(1)
self.assertNotEqual(crc, weston_desktop_crc)
# While weston-simple-egl is running, we check the VKMS DRM
# CRCs are now changing. We get many CRCs, one per display
# driver refresh (at ~60Hz). Since all the rendering is in
# software, we can expect a slow frame rate. In 300 captured
# CRCs (5s), we expect at least 5 different values (i.e. 1 fps).
# This guarantees the rendering pipeline is working, while we
# remain very permissive to slow emulation situations.
# Increase timeout, as the command is expected to run about 5s,
# which is the default timeout.
crcs = self.get_n_fb_crc(count=300, timeout=10)
self.assertGreaterEqual(len(crcs), 5)
# We stop weston-simple-egl, and sleep a bit to let Weston do
# its cleanup and desktop repaint refresh...
self.assertRunOk("killall weston-simple-egl")
# After we stopped the application, we should have the initial
# weston desktop background. The CRC we measure now should be
# the same as the one we saved earlier.
for i in range(600):
crc = self.get_n_fb_crc(count=1)[0]
if crc == weston_desktop_crc:
break
time.sleep(1)
self.assertEqual(crc, weston_desktop_crc)
self.stop_weston()
# Now weston is supposed to be stopped,
# a simple client is expected to fail.
_, exit_code = self.emulator.run("wayland-info")
self.assertNotEqual(exit_code, 0)