test-generic.yaml 7.96 KB
Newer Older
1
2
3
4
5
6
7
8
9
# SPDX-License-Identifier: Apache-2.0
# SPDX-FileCopyrightText: Huawei Inc.

##
## Submits a job to LAVA with CI variables
##
.lava-test:
  interruptible: true
  image:
10
    name: registry.ostc-eu.org/ostc/oniro/bitbake-builder:latest
11
  variables:
Chase Qi's avatar
Chase Qi committed
12
    GIT_STRATEGY: none
13
    CI_LAVA_INSTANCE: "https://lava.ostc-eu.org/"
14
    CI_SQUAD_INSTANCE: "https://squadp.svc.ostc-eu.dev"
15
    CI_SQUAD_PROJECT_NAME: "oniro-test-mr"
16
17
18
    # 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"
19
  before_script:
20
21
22
    - 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 )
23
    # Check if the job is configured properly.
24
25
    - test -n "$MACHINE" || (
        echo "precondition failed - set MACHINE to the name of the target device for which the image is built"
26
27
28
29
        && 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 )
30
31
32
    - 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 )
33
34
35
36
37
    - 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 LAVA"
        && exit 1 )
  script:
    # Build callback URL for the "report" job
38
    - curl --silent "$CI_API_V4_URL/projects/$CI_PROJECT_ID/pipelines/$CI_PIPELINE_ID/jobs?per_page=100" > jobs-manual.json
39
40
    - 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)"
41
    - CALLBACK_URL="$CI_API_V4_URL/projects/$CI_PROJECT_ID/jobs/${job_id}/play"
42
43
44
    # Get the job definition from remote source.
    - curl --silent "$CI_LAVA_JOB_DEFINITION" > job_def.yaml
    # Update the job definition with CI data.
45
46
47
48
    - 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_pipeline_url@,'"$CI_PIPELINE_URL"','
49
      -e 's/@build_job_id@/'"$build_job_id"'/' job_def.yaml
50
51
    # Update the job with device configuration
    - sed -i -e 's/@BOARD_RAM_SIZE@/'"$BOARD_RAM_SIZE"'/' job_def.yaml
52
    # Generate test jobs.
53
    - |
54
      set -x
55
      rm -rf lava_jobs && mkdir lava_jobs
56
      # Generate job definitions for zephyr build
57
      if echo "${CI_BUILD_JOB_NAME}" | grep -i "zephyr" | grep -vi "twister"; then
58
        for image in $(find artifacts/images/${MACHINE} -name "*.elf" -exec basename {} \;); do
59
60
          image_basename=$(basename "${image}" ".elf")
          echo "--- Generating lava job definition ${image_basename}.yaml ---"
61
          sed "s/@image_basename@/$image_basename/" job_def.yaml | tee lava_jobs/"${image_basename}".yaml
62
        done
63
      # Generate job definitions for linux LTP test.
Chase Qi's avatar
Chase Qi committed
64
      elif grep -q "@TST_CMDFILES@" job_def.yaml; then
65
66
67
        for test_cmdfile in ${LTP_TST_CMDFILES}; do
          ltp_job_name="ltp-${test_cmdfile}.yaml"
          echo "--- Generating lava job definition ${ltp_job_name} ---"
68
          sed "s/@TST_CMDFILES@/${test_cmdfile}/" job_def.yaml | tee lava_jobs/"${ltp_job_name}"
69
        done
70
71
72
      else
        mv job_def.yaml lava_jobs/
      fi
73
      set +x
74
    # Submit the jobs to SQUAD.
75
76
    - |
      for job_def in $(find lava_jobs/ -name "*.yaml"); do
77
78
        echo $CI_SQUAD_INSTANCE/api/submitjob/oniro-core/$CI_SQUAD_PROJECT_NAME/$CI_PIPELINE_ID/$MACHINE --header "Auth-Token: $CI_SQUAD_TOKEN"  --form "backend=oniro_lava" --form "definition=@${job_def}"
        curl $CI_SQUAD_INSTANCE/api/submitjob/oniro-core/$CI_SQUAD_PROJECT_NAME/$CI_PIPELINE_ID/$MACHINE --header "Auth-Token: $CI_SQUAD_TOKEN"  --form "backend=oniro_lava" --form "definition=@${job_def}"
79
      done
80
      # Attach a callback to this build to trigger the lava-report job
81
      squad_build_id="$(curl --silent "$CI_SQUAD_INSTANCE/api/builds/?version=$CI_PIPELINE_ID" | jq -r '.results[0].id')"
82
83
84
85
86
      curl --silent \
        -X POST "$CI_SQUAD_INSTANCE/api/builds/$squad_build_id/callbacks/" \
        -H "Authorization: Token $CI_SQUAD_TOKEN" \
        -F "callback_url=$CALLBACK_URL" \
        -F "callback_record_response=true"
87
88
  artifacts:
    paths:
89
      - lava_jobs/*.yaml
90
  rules:
91
92
    - if: '$CI_SQUAD_TOKEN == null'
      when: never
93
94
95
96
97
98
99
100
101
102
103
104
    # Run the build when it is scheduled.
    - if: $CI_PIPELINE_SOURCE == "schedule"
    # Do not run pipelines for draft merge requests unless manually triggered.
    - if: '$CI_PIPELINE_SOURCE == "merge_request_event" && $CI_MERGE_REQUEST_TITLE =~ /^(wip|draft):.*/i'
      when: manual
    # Run the build when a merge request is created.
    - if: '$CI_PIPELINE_SOURCE == "merge_request_event"'
    # Run the build when a tag is placed.
    - if: '$CI_COMMIT_TAG'

.lava-report:
  interruptible: true
105
106
  # Let the pipeline continue running 'lava-badge' job.
  allow_failure: true
107
  image:
108
    name: registry.ostc-eu.org/ostc/oniro/bitbake-builder:latest
109
  stage: report
110
  variables:
Chase Qi's avatar
Chase Qi committed
111
    GIT_STRATEGY: none
112
    CI_LAVA_INSTANCE: "https://lava.ostc-eu.org/"
113
    CI_SQUAD_INSTANCE: "https://squadp.svc.ostc-eu.dev"
114
115
  script:
    - |
116
117
118
      # Get the test_runs_incomplete value from build status. That will tell
      # us if any of the LAVA jobs failed and we can determine whether the
      # report job is successful or not.
119
120
121
122
      squad_build_id="$(curl --silent "$CI_SQUAD_INSTANCE/api/builds/?version=$CI_PIPELINE_ID" | jq -r '.results[0].id')"
      curl --silent "$CI_SQUAD_INSTANCE/api/builds/$squad_build_id/testjobs/" > test_jobs.json
      jq -r '.results | .[] | .external_url, .job_status' test_jobs.json | tee job_status.txt
      if grep -qi "incomplete" job_status.txt; then
123
124
125
        echo "ERROR: Incomplete test job reported: exit code 1"
        exit 1
      fi
126
  rules:
127
128
    - if: '$CI_SQUAD_TOKEN == null'
      when: never
129
130
131
132
133
134
135
136
137
138
139
140
    # Run the build when it is scheduled.
    - if: $CI_PIPELINE_SOURCE == "schedule"
      when: manual
    # Do not run pipelines for draft merge requests unless manually triggered.
    - if: '$CI_PIPELINE_SOURCE == "merge_request_event" && $CI_MERGE_REQUEST_TITLE =~ /^(wip|draft):.*/i'
      when: manual
    # Run the build when a merge request is created.
    - if: '$CI_PIPELINE_SOURCE == "merge_request_event"'
      when: manual
    # Run the build when a tag is placed.
    - if: '$CI_COMMIT_TAG'
      when: manual
Chase Qi's avatar
Chase Qi committed
141
142
143
144

.lava-badge:
  interruptible: true
  image:
145
    name: registry.ostc-eu.org/ostc/oniro/bitbake-builder:latest
Chase Qi's avatar
Chase Qi committed
146
147
148
  stage: report
  variables:
    GIT_STRATEGY: none
149
    CI_SQUAD_INSTANCE: "https://squadp.svc.ostc-eu.dev"
Chase Qi's avatar
Chase Qi committed
150
151
152
  script:
    - |
      set -x
153
154
155
156
157
158
159
160
161
      squad_build_id="$(curl --silent "$CI_SQUAD_INSTANCE/api/builds/?version=$CI_PIPELINE_ID" | jq -r '.results[0].id')"
      status_uri="$CI_SQUAD_INSTANCE/api/builds/$squad_build_id/status/"
      pass_percentage="$(curl --silent $status_uri | jq -r '.pass_percentage')"
      if [ "pass_percentage" != "null" ]; then
        success_rate=`printf "%.2f" $pass_percentage`
      else
        echo "ERROR: Failed to query pass percentage via $status_uri"
        exit 1
      fi
Chase Qi's avatar
Chase Qi committed
162
163
164
165
166
167
168
169
170
      anybadge --label=lava-test --value=${success_rate} --suffix='%' --file=lava-test.svg 50=red 60=orange 80=yellow 100=green
      set +x
  artifacts:
    when: always
    paths:
      - lava-test.svg
  rules:
    # Run the build when it is scheduled.
    - if: $CI_PIPELINE_SOURCE == "schedule"
171
172
173
    # Do not run pipelines for draft merge requests unless manually triggered.
    - if: '$CI_PIPELINE_SOURCE == "merge_request_event" && $CI_MERGE_REQUEST_TITLE =~ /^(wip|draft):.*/i'
      when: manual