summaryrefslogtreecommitdiff
path: root/.gitlab-ci.yml
blob: 069ffca1f5ad31100732c7de32ddaba88d2bc745 (plain)
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
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
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
# Copyright 2021 The Chromium OS Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

image: sjg20/ubuntu-25feb22c

# You can update that image using this repo:
#   https://gitlab.com/zephyr-ec/gitlab-ci-runner/-/tree/main

# Change pip's cache directory to be inside the project directory since we can
# only cache local items.
variables:
  PIP_CACHE_DIR: "$CI_PROJECT_DIR/.cache/pip"

# Pip's cache doesn't store the python packages
# https://pip.pypa.io/en/stable/reference/pip_install/#caching
#
# If you want to also cache the installed packages, you have to install
# them in a virtualenv and cache it as well.
cache:
  key: ${CI_COMMIT_SHA}
  policy: pull
  paths:
    - .cache/pip
    - venv/
    - modules/
    - zephyr/


# The directory structure is:
#
# /zephyr
# /builds/zephyr-ec/ec       EC_DIR
before_script:
  - export MODULES_DIR="$CI_PROJECT_DIR/modules"
  - mkdir -p "${MODULES_DIR}"
  - export ZEPHYR_BASE="${CI_PROJECT_DIR}/zephyr/main"
  - mkdir -p "${ZEPHYR_BASE}"
  - test -d "${ZEPHYR_BASE}/.git" || git clone --depth 1 -b main https://chromium.googlesource.com/chromiumos/third_party/zephyr "${ZEPHYR_BASE}"
  - test -d "${MODULES_DIR}/cmsis" || git clone --depth 1 -b chromeos-main https://chromium.googlesource.com/chromiumos/third_party/zephyr/cmsis "${MODULES_DIR}/cmsis"
  - test -d "${MODULES_DIR}/hal_stm32" || git clone --depth 1 -b chromeos-main https://chromium.googlesource.com/chromiumos/third_party/zephyr/hal_stm32 "${MODULES_DIR}/hal_stm32"
  - test -d "${MODULES_DIR}/nanopb" || git clone --depth 1 -b main https://chromium.googlesource.com/chromiumos/third_party/zephyr/nanopb "${MODULES_DIR}/nanopb"
  - test -d "${MODULES_DIR}/cryptoc" || git clone --depth 1 -b main https://chromium.googlesource.com/chromiumos/third_party/cryptoc "${MODULES_DIR}/cryptoc"
  - ln -s "$(pwd)" "${MODULES_DIR}/ec"
  - python3 -V  # Print out python version for debugging
  - python3 -m pip install 'zephyr/zmake[tests]' --user
  - python3 -m pip install pyyaml packaging
  - export BUILD_DIR=build
  - export PATH="$PATH:$HOME/.local/bin"
  - export PYTHONIOENCODING=utf-8
  - export EC_DIR=/builds/zephyr-ec/ec

seed_cache:
  stage: build
  needs: []
  cache:
    key: ${CI_COMMIT_SHA}
    paths:
      - .cache/pip
      - venv/
      - modules/
      - zephyr/
    policy: push
  script:
    - ls "${MODULES_DIR}" "${ZEPHYR_BASE}"

# Users of this template must set:
# $PROJECT to the project to build. E.g., "lazor"
.build_template: &build_template
  stage: build
  needs: ["seed_cache"]
  script:
    - zmake --zephyr-base "${ZEPHYR_BASE}"
      --modules-dir "${MODULES_DIR}" -l DEBUG build
      -B "${BUILD_DIR}" -t ${TOOLCHAIN:-zephyr}
      "${PROJECT}"
    - for b in "${BUILD_DIR}/${PROJECT}"/build-* ; do
      bdir=$(basename ${b}) ;
      ninja -C ${b} ram_report >"${BUILD_DIR}/${PROJECT}/output/${bdir}_ram_report.txt" ;
      cp ${b}/ram.json "${BUILD_DIR}/${PROJECT}/output/${bdir}_ram.json" ;
      ninja -C ${b} rom_report >"${BUILD_DIR}/${PROJECT}/output/${bdir}_rom_report.txt" ;
      cp ${b}/rom.json "${BUILD_DIR}/${PROJECT}/output/${bdir}_rom.json" ;
      done
    - ls "${BUILD_DIR}/${PROJECT}" "${BUILD_DIR}/${PROJECT}/output"
  artifacts:
    paths:
      - build/${PROJECT}/output/*
    expire_in: 1 week

# Users of this template must set:
# $PROJECT to the project to build. E.g., "lazor"
# Builds the project with coverage enabled, removes the non-ec files.
# Then merges with the tests, excludes all files not used by this project,
# and generates a report.
# NOTE: If you change the lcov -r command below, also edit the one in
# merged_coverage
.coverage_template: &coverage_template
  stage: test
  needs: ["merged_coverage", "zephyr_coverage", "twister_coverage"]
  script:
    - zmake --zephyr-base "${ZEPHYR_BASE}"
      --modules-dir "${MODULES_DIR}" -l DEBUG build --coverage
      -B "${BUILD_DIR}" -t ${TOOLCHAIN:-zephyr}
      "${PROJECT}"
    - lcov --rc lcov_branch_coverage=1 -o "${BUILD_DIR}/${PROJECT}/output/merged_twister.info" -a "${BUILD_DIR}/${PROJECT}/output/zephyr.info" -a "${BUILD_DIR}/zephyr_codecov/fixed.info"
    - lcov --rc lcov_branch_coverage=1 -o "${BUILD_DIR}/${PROJECT}/output/merged_twister_no_ec.info" -e "${BUILD_DIR}/${PROJECT}/output/merged_twister.info" "${ZEPHYR_BASE}/**" "${MODULES_DIR}/**"
    - grep "SF:" "${BUILD_DIR}/${PROJECT}/output/zephyr.info" | sort -u |
      sed -e 's|^SF:||' | xargs lcov --rc lcov_branch_coverage=1
      -o "${BUILD_DIR}/${PROJECT}/output/filtered_twister.info"
      -e "${BUILD_DIR}/${PROJECT}/output/merged_twister_no_ec.info"
    - /usr/bin/genhtml --branch-coverage -q
      -o "${BUILD_DIR}/${PROJECT}/output/filtered_twister_rpt"
      -t "${PROJECT} coverage of twister tests"
      -s "${BUILD_DIR}/${PROJECT}/output/filtered_twister.info"
    - lcov --rc lcov_branch_coverage=1 -o "${BUILD_DIR}/${PROJECT}/output/merged.info"
      -a "${BUILD_DIR}/${PROJECT}/output/zephyr.info" -a build/merged.info
    - lcov --rc lcov_branch_coverage=1 -o "${BUILD_DIR}/${PROJECT}/output/no_zephyr.info"
      -r "${BUILD_DIR}/${PROJECT}/output/zephyr.info" "${ZEPHYR_BASE}/**"
      "${ZEPHYR_BASE}/**" "${MODULES_DIR}/**"
      "${EC_DIR}/zephyr/drivers/**" "${EC_DIR}/zephyr/include/drivers/**"
      "${EC_DIR}/zephyr/shim/chip/**" "${EC_DIR}/zephyr/shim/core/**"
      "${EC_DIR}/zephyr/projects/**" "/usr/include/x86_64-linux-gnu/**"
      "${EC_DIR}/build/*/build-*/zephyr/*/generated/**" "${EC_DIR}/test/**"
      "${EC_DIR}/zephyr/shim/chip/npcx/npcx_monitor/**"
      "${EC_DIR}/zephyr/emul/**" "${EC_DIR}/zephyr/test/**"
      "**/testsuite/**" "**/subsys/emul/**"
    - lcov --rc lcov_branch_coverage=1 -o "${BUILD_DIR}/${PROJECT}/output/merged_no_zephyr.info"
      -r "${BUILD_DIR}/${PROJECT}/output/merged.info"
      "${ZEPHYR_BASE}/**" "${MODULES_DIR}/**"
      "${EC_DIR}/zephyr/drivers/**" "${EC_DIR}/zephyr/include/drivers/**"
      "${EC_DIR}/zephyr/shim/chip/**" "${EC_DIR}/zephyr/shim/core/**"
      "${EC_DIR}/zephyr/projects/**" "/usr/include/x86_64-linux-gnu/**"
      "${EC_DIR}/build/*/build-*/zephyr/*/generated/**" "${EC_DIR}/test/**"
      "${EC_DIR}/zephyr/shim/chip/npcx/npcx_monitor/**"
      "${EC_DIR}/zephyr/emul/**" "${EC_DIR}/zephyr/test/**"
      "**/testsuite/**" "**/subsys/emul/**"
    - grep "SF:" "${BUILD_DIR}/${PROJECT}/output/no_zephyr.info" | sort -u |
      sed -e 's|^SF:||' | xargs lcov --rc lcov_branch_coverage=1
      -o "${BUILD_DIR}/${PROJECT}/output/filtered_no_zephyr.info"
      -e "${BUILD_DIR}/${PROJECT}/output/merged_no_zephyr.info"
    - /usr/bin/genhtml --branch-coverage -q
      -o "${BUILD_DIR}/${PROJECT}/output/filtered_no_zephyr_rpt"
      -t "${PROJECT} coverage w/o zephyr"
      -p ${EC_DIR}
      -s "${BUILD_DIR}/${PROJECT}/output/filtered_no_zephyr.info"
  artifacts:
    paths:
      - build/${PROJECT}/output/*.info
      - build/${PROJECT}/output/*_rpt
    expire_in: 1 week
    when: always
  coverage: '/lines\.*: \d+\.\d+%/'

herobrine:
  variables:
    PROJECT: "herobrine"
  <<: *build_template

herobrine_coverage:
  variables:
    PROJECT: "herobrine"
  <<: *coverage_template

it8xxx2_evb:
  variables:
    PROJECT: "it8xxx2_evb"
  <<: *build_template

kingler:
  variables:
    PROJECT: "kingler"
  <<: *build_template

kingler_coverage:
  variables:
    PROJECT: "kingler"
  <<: *coverage_template

krabby:
  variables:
    PROJECT: "krabby"
  <<: *build_template

krabby_coverage:
  variables:
    PROJECT: "krabby"
  <<: *coverage_template

lazor:
  variables:
    PROJECT: "lazor"
  <<: *build_template

native_posix:
  variables:
    PROJECT: "posix-ec"
    TOOLCHAIN: "host"
  <<: *build_template

npcx7_evb:
  variables:
    PROJECT: "npcx7"
  <<: *build_template

npcx9_evb:
  variables:
    PROJECT: "npcx9"
  <<: *build_template

skyrim:
  variables:
    PROJECT: "skyrim"
  <<: *build_template

skyrim_coverage:
  variables:
    PROJECT: "skyrim"
  <<: *coverage_template

ec_coverage:
  stage: test
  needs: ["seed_cache"]
  script:
    - make -j8 CRYPTOC_DIR="${MODULES_DIR}/cryptoc"
      HOSTGCOV='gcov'
      CROSS_COMPILE_arm=/opt/zephyr-sdk/arm-zephyr-eabi/bin/arm-zephyr-eabi-
      test-coverage
  artifacts:
    paths:
      - build/coverage/coverage_rpt/*
      - build/coverage/lcov.info
    expire_in: 1 week
  coverage: '/lines\.*: \d+\.\d+%/'

zephyr_coverage:
  stage: test
  needs: ["seed_cache"]
  script:
    - zmake --zephyr-base "${ZEPHYR_BASE}"
      --modules-dir "${MODULES_DIR}" -l DEBUG test
      --coverage --host-tests-only
  artifacts:
    paths:
      - build/zephyr/all_tests.info
    expire_in: 1 week
  coverage: '/lines\.*: \d+\.\d+%/'

zephyr_boards_coverage:
  stage: build
  needs: ["seed_cache"]
  script:
    - zmake --zephyr-base "${ZEPHYR_BASE}"
      --modules-dir "${MODULES_DIR}" -l DEBUG build
      --coverage --boards-only --delete-intermediates
  artifacts:
    paths:
      - build/zephyr/all_builds.info
    expire_in: 1 week
  coverage: '/lines\.*: \d+\.\d+%/'

# NOTE: If you change the lcov -r command below, also edit the one in
# .coverage_template
merged_coverage:
  stage: test
  needs: ["ec_coverage", "zephyr_coverage", "zephyr_boards_coverage"]
  script:
    - lcov --rc lcov_branch_coverage=1 -o build/merged.info
      -a build/coverage/lcov.info -a build/zephyr/all_tests.info
    - lcov --rc lcov_branch_coverage=1 -o build/merged_no_zephyr.info
      -r build/merged.info
      "${ZEPHYR_BASE}/**" "${MODULES_DIR}/**"
      "${EC_DIR}/zephyr/drivers/**" "${EC_DIR}/zephyr/include/drivers/**"
      "${EC_DIR}/zephyr/shim/chip/**" "${EC_DIR}/zephyr/shim/core/**"
      "${EC_DIR}/zephyr/projects/**" "/usr/include/x86_64-linux-gnu/**"
      "${EC_DIR}/build/*/build-*/zephyr/*/generated/**" "${EC_DIR}/test/**"
      "${EC_DIR}/zephyr/shim/chip/npcx/npcx_monitor/**"
      "${EC_DIR}/zephyr/emul/**" "${EC_DIR}/zephyr/test/**"
      "**/testsuite/**" "**/subsys/emul/**"
    - lcov --rc lcov_branch_coverage=1 -o "build/all_builds_merged.info"
      -a "build/zephyr/all_builds.info" -a build/merged.info
    - lcov --rc lcov_branch_coverage=1 -o "build/all_builds_no_zephyr.info"
      -r "build/all_builds_merged.info" "${ZEPHYR_BASE}/**"
      "${ZEPHYR_BASE}/**" "${MODULES_DIR}/**"
      "${EC_DIR}/zephyr/drivers/**" "${EC_DIR}/zephyr/include/drivers/**"
      "${EC_DIR}/zephyr/shim/chip/**" "${EC_DIR}/zephyr/shim/core/**"
      "${EC_DIR}/zephyr/projects/**" "/usr/include/x86_64-linux-gnu/**"
      "${EC_DIR}/build/*/build-*/zephyr/*/generated/**" "${EC_DIR}/test/**"
      "${EC_DIR}/zephyr/shim/chip/npcx/npcx_monitor/**"
      "${EC_DIR}/zephyr/emul/**" "${EC_DIR}/zephyr/test/**"
      "**/testsuite/**" "**/subsys/emul/**"
    - grep "SF:" "build/zephyr/all_builds.info" | sort -u |
      sed -e 's|^SF:||' | xargs lcov --rc lcov_branch_coverage=1
      -o "build/all_builds_filtered.info"
      -e "build/all_builds_no_zephyr.info"
    - /usr/bin/genhtml --branch-coverage -q
      -o "build/all_builds_filtered_rpt"
      -t "All boards coverage w/o zephyr"
      -p ${EC_DIR}
      -s "build/all_builds_filtered.info"
  artifacts:
    paths:
      - build/*.info
      - build/*_rpt
    expire_in: 1 week
  coverage: '/lines\.*: \d+\.\d+%/'

testall:
  stage: test
  needs: ["seed_cache"]
  script:
    - zmake --zephyr-base "${ZEPHYR_BASE}"
      --modules-dir "${MODULES_DIR}" -l DEBUG test --host-tests-only

twister_coverage:
  stage: test
  needs: ["seed_cache"]
  script:
    - mkdir -p build/zephyr_codecov
    - for commitid in $(cd "${ZEPHYR_BASE}" ; git fetch --depth=100 ; git log | awk '/GitOrigin-RevId:/ {print $2}') ; do
        echo "COMMITID = ${commitid?}" ;
        if wget -O /tmp/coverage.html "https://codecov.io/gh/zephyrproject-rtos/zephyr/commit/${commitid?}/build" ; then
          downloadurl=$(sed -e '/download\/build/!d' -e 's|^.*href="|https://codecov.io|' -e 's|".*$||' /tmp/coverage.html | head -1) ;
          echo "DOWNLOADURL = ${downloadurl?}" ;
          wget -O build/zephyr_codecov/merged.info.raw "${downloadurl?}" ;
          sed <build/zephyr_codecov/merged.info.raw >build/zephyr_codecov/merged.info
            -e '1,/<<<<<< network/d' -e '/<<<<<< EOF/,$d' ;
          sed <build/zephyr_codecov/merged.info >build/zephyr_codecov/fixed.info
            -e "s|/__w/zephyr/zephyr|${ZEPHYR_BASE}|"
            -e "s|/__w/zephyr/modules/hal/cmsis|${MODULES_DIR}/cmsis|"
            -e "s|/__w/zephyr/modules|${MODULES_DIR}|" ;
          break ;
        fi ;
      done
    - lcov --rc lcov_branch_coverage=1 --summary build/zephyr_codecov/fixed.info
  artifacts:
    paths:
      - build/zephyr_codecov/fixed.info
    expire_in: 1 week
  coverage: '/lines\.*: \d+\.\d+%/'

zmake_coverage:
  stage: test
  needs: ["seed_cache"]
  script:
    - cd zephyr/zmake
    - coverage run --source=zmake -m pytest .
    - coverage report
    - coverage html
  artifacts:
    paths:
      - zephyr/zmake/htmlcov/*
    expire_in: 1 week
  coverage: '/^TOTAL.+?(\d+\%)$/'