| 1 |
Continuous Integration |
| 2 |
====================== |
| 3 |
|
| 4 |
GitLab CI |
| 5 |
--------- |
| 6 |
|
| 7 |
GitLab provides a convenient framework for running commands in response to Git pushes. |
| 8 |
We use it to test merge requests (MRs) before merging them (pre-merge testing), |
| 9 |
as well as post-merge testing, for everything that hits ``main`` |
| 10 |
(this is necessary because we still allow commits to be pushed outside of MRs, |
| 11 |
and even then the MR CI runs in the forked repository, which might have been |
| 12 |
modified and thus is unreliable). |
| 13 |
|
| 14 |
The CI runs a number of tests, from trivial build-testing to complex GPU rendering: |
| 15 |
|
| 16 |
- Build testing for a number of configurations and platforms |
| 17 |
- Sanity checks (``meson test``) |
| 18 |
- Most drivers are also tested using several test suites, such as the |
| 19 |
`Vulkan/GL/GLES conformance test suite <https://github.com/KhronosGroup/VK-GL-CTS>`__, |
| 20 |
`Piglit <https://gitlab.freedesktop.org/mesa/piglit>`__, and others. |
| 21 |
- Replay of application traces |
| 22 |
|
| 23 |
A typical run takes between 20 and 30 minutes, although it can go up very quickly |
| 24 |
if the GitLab runners are overwhelmed, which happens sometimes. When it does happen, |
| 25 |
not much can be done besides waiting it out, or cancel it. |
| 26 |
|
| 27 |
It is a good practice to check the ``Marge`` |
| 28 |
`queue <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests?assignee_username=marge-bot>`__ |
| 29 |
to evaluate if it is the right moment to trigger some testing jobs. ``Marge`` |
| 30 |
is configured to pick the MRs by assignment time, and this sort option is not |
| 31 |
available in the Web UI. The `marge_queue <#marge-queue>`__ CLI tool |
| 32 |
provides the list sorted by assignment time. The recommended way to manage the |
| 33 |
trigger of those jobs is using our :abbr:`crnm (bin/ci/ci_run_n_monitor.sh)` |
| 34 |
`cli tool <#running-specific-ci-jobs>`__. |
| 35 |
|
| 36 |
Due to limited resources, we currently do not run the CI automatically |
| 37 |
on every push; instead, we only run it automatically once the MR has |
| 38 |
been assigned to ``Marge``, our merge bot. |
| 39 |
|
| 40 |
If you're interested in the details, the main configuration file is ``.gitlab-ci.yml``, |
| 41 |
and it references a number of other files in ``.gitlab-ci/``. |
| 42 |
|
| 43 |
If the GitLab CI doesn't seem to be running on your fork (or MRs, as they run |
| 44 |
in the context of your fork), you should check the "Settings" of your fork. |
| 45 |
Under "CI / CD" → "General pipelines", make sure "Custom CI config path" is |
| 46 |
empty (or set to the default ``.gitlab-ci.yml``), and that the |
| 47 |
"Project-based pipeline visibility" box is checked. |
| 48 |
|
| 49 |
If a specific CI farm is failing for reasons unrelated to your changes, make an |
| 50 |
MR to disable the farm following the `farm management <#farm-management>`__ |
| 51 |
instructions. |
| 52 |
|
| 53 |
If you're having other issues with the GitLab CI, your best bet is to ask |
| 54 |
about it on ``#freedesktop`` on OFTC and tag `Daniel Stone |
| 55 |
<https://gitlab.freedesktop.org/daniels>`__ (``daniels`` on IRC) or |
| 56 |
`Eric Engestrom <https://gitlab.freedesktop.org/eric>`__ (``eric_engestrom`` on |
| 57 |
IRC). |
| 58 |
|
| 59 |
The three GitLab CI systems currently integrated are: |
| 60 |
|
| 61 |
|
| 62 |
.. toctree:: |
| 63 |
:maxdepth: 1 |
| 64 |
|
| 65 |
bare-metal |
| 66 |
LAVA |
| 67 |
docker |
| 68 |
|
| 69 |
Farm management |
| 70 |
--------------- |
| 71 |
|
| 72 |
.. note:: |
| 73 |
Never mix disabling/re-enabling a farm with any change that can affect a job |
| 74 |
that runs in another farm! |
| 75 |
|
| 76 |
When the farm starts failing for any reason (power, network, out-of-space), it needs to be disabled by pushing separate MR with |
| 77 |
|
| 78 |
.. code-block:: sh |
| 79 |
|
| 80 |
git mv .ci-farms{,-disabled}/$farm_name |
| 81 |
|
| 82 |
Find the GitLab handle of the farm's admin in ``.gitlab-ci/farm-rules.yml`` and |
| 83 |
ping them on the MR. MRs to disable farms do not need to go through review, and |
| 84 |
can be assigned to ``Marge`` directly. |
| 85 |
|
| 86 |
After farm restore functionality can be enabled by pushing a new merge request, |
| 87 |
which contains |
| 88 |
|
| 89 |
.. code-block:: sh |
| 90 |
|
| 91 |
git mv .ci-farms{-disabled,}/$farm_name |
| 92 |
|
| 93 |
.. warning:: |
| 94 |
Pushing (``git push``) directly to ``main`` is forbidden; this change must |
| 95 |
be sent as a :ref:`Merge Request <merging>`. |
| 96 |
|
| 97 |
Application traces replay |
| 98 |
------------------------- |
| 99 |
|
| 100 |
The CI replays application traces with various drivers in two different jobs. The first |
| 101 |
job replays traces listed in ``src/<driver>/ci/traces-<driver>.yml`` files and if any |
| 102 |
of those traces fail the pipeline fails as well. The second job replays traces listed in |
| 103 |
``src/<driver>/ci/restricted-traces-<driver>.yml`` and it is allowed to fail. This second |
| 104 |
job is only created when the pipeline is triggered by ``marge-bot`` or any other user that |
| 105 |
has been granted access to these traces. |
| 106 |
|
| 107 |
A traces YAML file also includes a ``download-url`` pointing to a MinIO |
| 108 |
instance where to download the traces from. While the first job should always work with |
| 109 |
publicly accessible traces, the second job could point to an URL with restricted access. |
| 110 |
|
| 111 |
Restricted traces are those that have been made available to Mesa developers without a |
| 112 |
license to redistribute at will, and thus should not be exposed to the public. Failing to |
| 113 |
access that URL would not prevent the pipeline to pass, therefore forks made by |
| 114 |
contributors without permissions to download non-redistributable traces can be merged |
| 115 |
without friction. |
| 116 |
|
| 117 |
As an aside, only maintainers of such non-redistributable traces are responsible for |
| 118 |
ensuring that replays are successful, since other contributors would not be able to |
| 119 |
download and test them by themselves. |
| 120 |
|
| 121 |
Those Mesa contributors that believe they could have permission to access such |
| 122 |
non-redistributable traces can request permission to Daniel Stone <[email protected]>. |
| 123 |
|
| 124 |
gitlab.freedesktop.org accounts that are to be granted access to these traces will be |
| 125 |
added to the OPA policy for the MinIO repository as per |
| 126 |
https://gitlab.freedesktop.org/freedesktop/helm-gitlab-infra/-/commit/a3cd632743019f68ac8a829267deb262d9670958 . |
| 127 |
|
| 128 |
So the jobs are created in personal repositories, the name of the user's account needs |
| 129 |
to be added to the rules attribute of the GitLab CI job that accesses the restricted |
| 130 |
accounts. |
| 131 |
|
| 132 |
.. toctree:: |
| 133 |
:maxdepth: 1 |
| 134 |
|
| 135 |
local-traces |
| 136 |
|
| 137 |
Intel CI |
| 138 |
-------- |
| 139 |
|
| 140 |
The Intel CI is not yet integrated into the GitLab CI. |
| 141 |
For now, special access must be manually given (file a issue in |
| 142 |
`the Intel CI configuration repo <https://gitlab.freedesktop.org/Mesa_CI/mesa_jenkins>`__ |
| 143 |
if you think you or Mesa would benefit from you having access to the Intel CI). |
| 144 |
Results can be seen on `mesa-ci.01.org <https://mesa-ci.01.org>`__ |
| 145 |
if you are *not* an Intel employee, but if you are you |
| 146 |
can access a better interface on |
| 147 |
`mesa-ci-results.jf.intel.com <http://mesa-ci-results.jf.intel.com>`__. |
| 148 |
|
| 149 |
The Intel CI runs a much larger array of tests, on a number of generations |
| 150 |
of Intel hardware and on multiple platforms (X11, Wayland, DRM & Android), |
| 151 |
with the purpose of detecting regressions. |
| 152 |
Tests include |
| 153 |
`Crucible <https://gitlab.freedesktop.org/mesa/crucible>`__, |
| 154 |
`VK-GL-CTS <https://github.com/KhronosGroup/VK-GL-CTS>`__, |
| 155 |
`dEQP <https://android.googlesource.com/platform/external/deqp>`__, |
| 156 |
`Piglit <https://gitlab.freedesktop.org/mesa/piglit>`__, |
| 157 |
`Skia <https://skia.googlesource.com/skia>`__, |
| 158 |
`VkRunner <https://github.com/Igalia/vkrunner>`__, |
| 159 |
`WebGL <https://github.com/KhronosGroup/WebGL>`__, |
| 160 |
and a few other tools. |
| 161 |
A typical run takes between 30 minutes and an hour. |
| 162 |
|
| 163 |
If you're having issues with the Intel CI, your best bet is to ask about |
| 164 |
it on ``#dri-devel`` on OFTC and tag `Nico Cortes |
| 165 |
<https://gitlab.freedesktop.org/ngcortes>`__ (``ngcortes`` on IRC). |
| 166 |
|
| 167 |
.. _CI-job-user-expectations: |
| 168 |
|
| 169 |
CI job user expectations |
| 170 |
------------------------ |
| 171 |
|
| 172 |
To make sure that testing of one vendor's drivers doesn't block |
| 173 |
unrelated work by other vendors, we require that a given driver's test |
| 174 |
farm produces a spurious failure no more than once a week. If every |
| 175 |
driver had CI and failed once a week, we would be seeing someone's |
| 176 |
code getting blocked on a spurious failure daily, which is an |
| 177 |
unacceptable cost to the project. |
| 178 |
|
| 179 |
To ensure that, driver maintainers with CI enabled should watch the Flakes panel |
| 180 |
of the `CI flakes dashboard |
| 181 |
<https://ci-stats-grafana.freedesktop.org/d/Ae_TLIwVk/mesa-ci-quality-false-positives?orgId=1>`__, |
| 182 |
particularly the "Flake jobs" pane, to inspect jobs in their driver where the |
| 183 |
automatic retry of a failing job produced a success a second time. |
| 184 |
Additionally, most CI reports test-level flakes to an IRC channel, and flakes |
| 185 |
reported as NEW are not expected and could cause spurious failures in jobs. |
| 186 |
Please track the NEW reports in jobs and add them as appropriate to the |
| 187 |
``-flakes.txt`` file for your driver. |
| 188 |
|
| 189 |
Additionally, the test farm needs to be able to provide a short enough |
| 190 |
turnaround time that we can get our MRs through marge-bot without the pipeline |
| 191 |
backing up. As a result, we require that the test farm be able to handle a |
| 192 |
whole pipeline's worth of jobs in less than 15 minutes (to compare, the build |
| 193 |
stage is about 10 minutes). Given boot times and intermittent network delays, |
| 194 |
this generally means that the test runtime as reported by deqp-runner should be |
| 195 |
kept to 10 minutes. |
| 196 |
|
| 197 |
If a test farm is short the HW to provide these guarantees, consider dropping |
| 198 |
tests to reduce runtime. dEQP job logs print the slowest tests at the end of |
| 199 |
the run, and Piglit logs the runtime of tests in the results.json.bz2 in the |
| 200 |
artifacts. Or, you can add the following to your job to only run some fraction |
| 201 |
(in this case, 1/10th) of the dEQP tests. |
| 202 |
|
| 203 |
.. code-block:: yaml |
| 204 |
|
| 205 |
variables: |
| 206 |
DEQP_FRACTION: 10 |
| 207 |
|
| 208 |
to just run 1/10th of the test list. |
| 209 |
|
| 210 |
For Collabora's LAVA farm, the `device types |
| 211 |
<https://lava.collabora.dev/scheduler/device_types>`__ page can tell you how |
| 212 |
many boards of a specific tag are currently available by adding the "Idle" and |
| 213 |
"Busy" columns. For bare-metal, a gitlab admin can look at the `runners |
| 214 |
<https://gitlab.freedesktop.org/admin/runners>`__ page. A pipeline should |
| 215 |
probably not create more jobs for a board type than there are boards, unless you |
| 216 |
clearly have some short-runtime jobs. |
| 217 |
|
| 218 |
If a HW CI farm goes offline (network dies and all CI pipelines end up |
| 219 |
stalled) or its runners are consistently spuriously failing (disk |
| 220 |
full?), and the maintainer is not immediately available to fix the |
| 221 |
issue, please push through an MR disabling that farm's jobs according |
| 222 |
to the `Farm Management <#farm-management>`__ instructions. |
| 223 |
|
| 224 |
Personal runners |
| 225 |
---------------- |
| 226 |
|
| 227 |
Mesa's CI is currently run primarily on packet.net's m1xlarge nodes |
| 228 |
(2.2Ghz Sandy Bridge), with each job getting 8 cores allocated. You |
| 229 |
can speed up your personal CI builds (and marge-bot merges) by using a |
| 230 |
faster personal machine as a runner. You can find the gitlab-runner |
| 231 |
package in Debian, or use GitLab's own builds. |
| 232 |
|
| 233 |
To do so, follow `GitLab's instructions |
| 234 |
<https://docs.gitlab.com/ci/runners/runners_scope/#create-a-project-runner-with-a-runner-authentication-token>`__ |
| 235 |
to register your personal GitLab runner in your Mesa fork. Then, tell |
| 236 |
Mesa how many jobs it should serve (``concurrent=``) and how many |
| 237 |
cores those jobs should use (``FDO_CI_CONCURRENT=``) by editing these |
| 238 |
lines in ``/etc/gitlab-runner/config.toml``, for example: |
| 239 |
|
| 240 |
.. code-block:: toml |
| 241 |
|
| 242 |
concurrent = 2 |
| 243 |
|
| 244 |
[[runners]] |
| 245 |
environment = ["FDO_CI_CONCURRENT=16"] |
| 246 |
|
| 247 |
|
| 248 |
Docker caching |
| 249 |
-------------- |
| 250 |
|
| 251 |
The CI system uses Docker images extensively to cache |
| 252 |
infrequently-updated build content like the CTS. The `freedesktop.org |
| 253 |
CI templates |
| 254 |
<https://gitlab.freedesktop.org/freedesktop/ci-templates/>`__ help us |
| 255 |
manage the building of the images to reduce how frequently rebuilds |
| 256 |
happen, and trim down the images (stripping out manpages, cleaning the |
| 257 |
apt cache, and other such common pitfalls of building Docker images). |
| 258 |
|
| 259 |
When running a container job, the templates will look for an existing |
| 260 |
build of that image in the container registry under |
| 261 |
``MESA_IMAGE_TAG``. If it's found it will be reused, and if |
| 262 |
not, the associated ``.gitlab-ci/containers/<jobname>.sh`` will be run |
| 263 |
to build it. So, when developing any change to container build |
| 264 |
scripts, you need to update the associated ``MESA_IMAGE_TAG`` to |
| 265 |
a new unique string. We recommend using the current date plus some |
| 266 |
string related to your branch (so that if you rebase on someone else's |
| 267 |
container update from the same day, you will get a Git conflict |
| 268 |
instead of silently reusing their container) |
| 269 |
|
| 270 |
When developing a given change to your Docker image, you would have to |
| 271 |
bump the tag on each ``git commit --amend`` to your development |
| 272 |
branch, which can get tedious. Instead, you can navigate to the |
| 273 |
`container registry |
| 274 |
<https://gitlab.freedesktop.org/mesa/mesa/container_registry>`__ for |
| 275 |
your repository and delete the tag to force a rebuild. When your code |
| 276 |
is eventually merged to main, a full image rebuild will occur again |
| 277 |
(forks inherit images from the main repo, but MRs don't propagate |
| 278 |
images from the fork into the main repo's registry). |
| 279 |
|
| 280 |
Building locally using CI docker images |
| 281 |
--------------------------------------- |
| 282 |
|
| 283 |
It can be frustrating to debug build failures on an environment you |
| 284 |
don't personally have. If you're experiencing this with the CI |
| 285 |
builds, you can use Docker to use their build environment locally. Go |
| 286 |
to your job log, and at the top you'll see a line like:: |
| 287 |
|
| 288 |
Pulling docker image registry.freedesktop.org/anholt/mesa/debian/android_build:2020-09-11 |
| 289 |
|
| 290 |
We'll use a volume mount to make our current Mesa tree be what the |
| 291 |
Docker container uses, so they'll share everything (their build will |
| 292 |
go in _build, according to ``meson-build.sh``). We're going to be |
| 293 |
using the image non-interactively so we use ``run --rm $IMAGE |
| 294 |
command`` instead of ``run -it $IMAGE bash`` (which you may also find |
| 295 |
useful for debug). Extract your build setup variables from |
| 296 |
.gitlab-ci.yml and run the CI meson build script: |
| 297 |
|
| 298 |
.. code-block:: sh |
| 299 |
|
| 300 |
IMAGE=registry.freedesktop.org/anholt/mesa/debian/android_build:2020-09-11 |
| 301 |
sudo docker pull $IMAGE |
| 302 |
sudo docker run --rm -v `pwd`:/mesa -w /mesa $IMAGE env PKG_CONFIG_PATH=/usr/local/lib/aarch64-linux-android/pkgconfig/:/android-ndk-r21d/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/lib/aarch64-linux-android/pkgconfig/ GALLIUM_DRIVERS=freedreno UNWIND=disabled EXTRA_OPTION="-D android-stub=true -D llvm=disabled" DRI_LOADERS="-D glx=disabled -D gbm=disabled -D egl=enabled -D platforms=android" CROSS=aarch64-linux-android ./.gitlab-ci/meson-build.sh |
| 303 |
|
| 304 |
All you have left over from the build is its output, and a _build |
| 305 |
directory. You can hack on mesa and iterate testing the build with: |
| 306 |
|
| 307 |
.. code-block:: sh |
| 308 |
|
| 309 |
sudo docker run --rm -v `pwd`:/mesa $IMAGE meson compile -C /mesa/_build |
| 310 |
|
| 311 |
Running specific CI jobs |
| 312 |
------------------------ |
| 313 |
|
| 314 |
You can use ``bin/ci/ci_run_n_monitor.py`` to run specific CI jobs. It |
| 315 |
will automatically take care of running all the jobs yours depends on, |
| 316 |
and cancel the rest to avoid wasting resources. |
| 317 |
|
| 318 |
See ``bin/ci/ci_run_n_monitor.py --help`` for all the options. |
| 319 |
|
| 320 |
**Target jobs** |
| 321 |
|
| 322 |
The ``--target`` argument takes a regex that you can use to select the |
| 323 |
jobs names you want to run, e.g. ``--target 'zink.*'`` will run all the |
| 324 |
Zink jobs, leaving the other drivers' jobs free for others to use. |
| 325 |
|
| 326 |
Note that in fork pipelines, GitLab only adds the jobs for the files that have |
| 327 |
changed **since the last push**, so you might not get the jobs you expect. |
| 328 |
You can work around that by adding a dummy change in a file core to what you're |
| 329 |
working on and then making a new push with that change, and removing that change |
| 330 |
before you create the MR. |
| 331 |
|
| 332 |
**GitLab token** |
| 333 |
|
| 334 |
The ``--token`` argument is used to provide a GitLab token with rights to |
| 335 |
interact with the pipeline. Using the argument, one can provide the value or |
| 336 |
the name of the file having the value. If the argument is not provided, then |
| 337 |
it checks if the value of ``$XDG_CONFIG_HOME`` has a valid directory (if not, |
| 338 |
then uses ``$HOME/.config``), and there is a file called ``gitlab-token`` that |
| 339 |
contains a token. The token required to work with this tool needs ``api`` |
| 340 |
scope permissions. |
| 341 |
|
| 342 |
.. note:: |
| 343 |
To create that token, refer to |
| 344 |
`create-a-personal-access-token <https://docs.gitlab.com/user/profile/personal_access_tokens/#create-a-personal-access-token>`_ |
| 345 |
and select the ``api`` scope. The token will only be shown once after creation, |
| 346 |
so make sure you store it securely. |
| 347 |
|
| 348 |
Marge queue |
| 349 |
----------- |
| 350 |
|
| 351 |
You can use ``bin/ci/marge_queue.sh`` to check how long the Marge queue is. As |
| 352 |
mentioned, the merge flow is to assign MR to the ``Marge`` bot, to serialize |
| 353 |
the verification and merge. Looking at the |
| 354 |
`merge requests assigned to Marge <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests?assignee_username=marge-bot>`__ |
| 355 |
you can evaluate the size of the queue, since the ``marge_queue`` tool provides |
| 356 |
sorted and summarized information about those MR in queue. |
| 357 |
|
| 358 |
The tool requires a GitLab token as described in the |
| 359 |
`crnm <#running-specific-ci-jobs>`__ section. It outputs the current queue |
| 360 |
sorted by the ``assigned at`` to ``Marge``. It can also be used as an active |
| 361 |
wait for another action in a pipe, using the ``--wait`` until the queue is |
| 362 |
empty. The return code corresponds to the number of MRs in the queue, so when |
| 363 |
it returns ``0``, one can, for example, start the ``crnm`` tool on a certain |
| 364 |
pipeline. |
| 365 |
|
| 366 |
Conformance Tests |
| 367 |
----------------- |
| 368 |
|
| 369 |
Some conformance tests require a special treatment to be maintained on GitLab CI. |
| 370 |
This section lists their documentation pages. |
| 371 |
|
| 372 |
.. toctree:: |
| 373 |
:maxdepth: 1 |
| 374 |
|
| 375 |
skqp |
| 376 |
|
| 377 |
|
| 378 |
Updating GitLab CI Linux Kernel |
| 379 |
------------------------------- |
| 380 |
|
| 381 |
GitLab CI usually runs a bleeding-edge kernel. The following documentation has |
| 382 |
instructions on how to uprev Linux Kernel in the GitLab CI ecosystem. |
| 383 |
|
| 384 |
.. toctree:: |
| 385 |
:maxdepth: 1 |
| 386 |
|
| 387 |
kernel |
| 388 |
|
| 389 |
Structured tagging |
| 390 |
------------------ |
| 391 |
|
| 392 |
Some build scripts can be tagged with a deterministic tag to allow for |
| 393 |
testing and validation of the build output. This section lists the |
| 394 |
documentation pages for the structured tagging feature. |
| 395 |
|
| 396 |
.. toctree:: |
| 397 |
:maxdepth: 1 |
| 398 |
|
| 399 |
structured-tagging |
| 400 |
|
| 401 |
Reusing CI scripts for other projects |
| 402 |
-------------------------------------- |
| 403 |
|
| 404 |
The CI scripts in ``.gitlab-ci/`` can be reused for other projects, to |
| 405 |
facilitate reuse of the infrastructure, our scripts can be used as tools |
| 406 |
to create containers and run tests on the available farms. |
| 407 |
|
| 408 |
.. envvar:: EXTRA_LOCAL_PACKAGES |
| 409 |
|
| 410 |
Define extra Debian packages to be installed in the container. |