# 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 -e '1,/<<<<<< network/d' -e '/<<<<<< EOF/,$d' ; sed 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+\%)$/'