Skip to content
Snippets Groups Projects
Code owners
Assign users and groups as approvers for specific file changes. Learn more.
test-generic.yaml 9.11 KiB
# SPDX-License-Identifier: Apache-2.0
# SPDX-FileCopyrightText: Huawei Inc.

##
## Submits a job to LAVA with CI variables
##
.lava-test:
  interruptible: true
  image:
    name: registry.ostc-eu.org/ostc/oniro/bitbake-builder:latest
  variables:
    GIT_STRATEGY: none
    CI_LAVA_INSTANCE: "https://lava.ostc-eu.org/"
    CI_SQUAD_INSTANCE: "https://squadp.svc.ostc-eu.dev"
    CI_SQUAD_GROUP_NAME: ""
    CI_SQUAD_PROJECT_NAME: ""
    CI_LAVA_JOB_PRIORITY: "medium"
    # Run the same ltp test suites that using by LKFT project.
    # Reference: https://qa-reports.linaro.org/lkft/linux-stable-rc-linux-5.10.y/build/v5.10.98-75-g9f5cb871ceb9/testjobs/
    LTP_TST_CMDFILES: "cap_bounds cpuhotplug crypto nptl pty securebits fs controllers hugetlb mm tracing containers io dio syscalls math commands ipc fcntl-locktests filecaps fs_bind fs_perms_simple fsx sched cve"
  before_script:
    - test -n "$CI_LAVA_TOKEN" || (
        echo "precondition failed - please disable the child job if CI_LAVA_TOKEN not set in gitlab CI/CD variables"
        && exit 1 )
    # Check if the job is configured properly.
    - test -n "$MACHINE" || (
        echo "precondition failed - set MACHINE to the name of the target device for which the image is built"
        && exit 1 )
    - test -n "$CI_BUILD_JOB_NAME" || (
        echo "precondition failed - set CI_BUILD_JOB_NAME to the appropriate job name from which LAVA will pick up build artifact"
        && exit 1 )
    - test -n "$CI_LAVA_JOB_DEFINITION" || (
        echo "precondition failed - set CI_LAVA_JOB_DEFINITION to the URL of the LAVA test job definition"
        && exit 1 )
    - test -n "$CI_REPORT_JOB_NAME" || (
        echo "precondition failed - set CI_REPORT_JOB_NAME to the CI job name which will gather results back from Squad"
        && exit 1 )
    - test -n "$CI_SQUAD_GROUP_NAME" || (
        echo "precondition failed - set CI_SQUAD_GROUP_NAME to the squad group name."
        && exit 1 )
    - test -n "$CI_SQUAD_PROJECT_NAME" || (
        echo "precondition failed - set CI_SQUAD_PROJECT_NAME to the squad project name."
        && exit 1 )
    # If the test job name contains 'sysota', usage of update job name is
    # required.
    - |
      if [[ -z "$CI_UPDATE_JOB_NAME" ]] && [[ "$CI_JOB_NAME" == *"sysota"* ]]; then
        echo "precondition failed - jobs with 'sysota' in their name must have CI_UPDATE_JOB_NAME variable with the name of the 'update' CI job that contains rauc bundles"
        exit 1
      fi
  script:
    # Build callback URL for the "report" job
    - curl --silent "$CI_API_V4_URL/projects/$CI_PROJECT_ID/pipelines/$CI_PIPELINE_ID/jobs?per_page=100" > jobs-manual.json
    - job_id="$(jq -r ".[] | select(.name == \"$CI_REPORT_JOB_NAME\") | .id" jobs-manual.json)"
    - build_job_id="$(jq -r ".[] | select(.name == \"$CI_BUILD_JOB_NAME\") | .id" jobs-manual.json)"
    - update_job_id="$(jq -r ".[] | select(.name == \"$CI_UPDATE_JOB_NAME\") | .id" jobs-manual.json)"
    - CALLBACK_URL="$CI_API_V4_URL/projects/$CI_PROJECT_ID/jobs/${job_id}/play"
    # Get the job definition from remote source.
    - curl --silent "$CI_LAVA_JOB_DEFINITION" > job_def.yaml
    # Update the job definition with CI data.
    - sed -i -e 's/@ci_job_id@/'"$CI_JOB_ID"'/'
      -e 's/@ci_project_id@/'"$CI_PROJECT_ID"'/'
      -e 's/@ci_pipeline_id@/'"$CI_PIPELINE_ID"'/'
      -e 's/@ci_lava_job_priority@/'"$CI_LAVA_JOB_PRIORITY"'/'
      -e 's,@ci_pipeline_url@,'"$CI_PIPELINE_URL"','
      -e 's,@update_job_id@,'"$update_job_id"','
      -e 's/@build_job_id@/'"$build_job_id"'/' job_def.yaml
    # Update the job with device configuration
    - sed -i -e 's/@BOARD_RAM_SIZE@/'"$BOARD_RAM_SIZE"'/g' job_def.yaml
    # Generate test jobs.