From ce27637469da61970731a3d9982489281ac4d706 Mon Sep 17 00:00:00 2001
From: Chase Qi <chase.qi@linaro.org>
Date: Fri, 17 Jun 2022 10:32:38 +0800
Subject: [PATCH] ci: enable pre-merge testing in LAVA on qemu devices

Signed-off-by: Chase Qi <chase.qi@linaro.org>
---
 .gitlab-ci.yml              | 72 ++++++++++++-------------------------
 .oniro-ci/test-generic.yaml |  9 +++--
 2 files changed, 29 insertions(+), 52 deletions(-)

diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index 10d41ac7..4a0fe536 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -196,20 +196,14 @@ publish-seco-intel-b68:
     # Run the build for scheduled pipelines.
     - if: '$CI_PIPELINE_SOURCE == "schedule"'
 
-# Mimic the updated rules for lava-test from the bitbake-workspace.
-.lava-test:
-  rules:
-    - if: '$CI_LAVA_TOKEN == null'
-      when: never
-    - if: '$CI_PIPELINE_SOURCE == "schedule"'
-
-# Mimic the updated rules for lava-report from the bitbake-workspace.
-.lava-report:
+.lava-test-scheduled:
+  extends: .lava-test
+  variables:
+    CI_SQUAD_PROJECT_NAME: "oniro"
   rules:
-    - if: '$CI_LAVA_TOKEN == null'
+    - if: '$CI_SQUAD_TOKEN == null'
       when: never
     - if: '$CI_PIPELINE_SOURCE == "schedule"'
-      when: manual
 
 ##
 ## Submit jobs to LAVA
@@ -237,7 +231,7 @@ lava-qemu-x86_64:
 lava-raspberrypi4-64:
   needs: [linux-raspberrypi4-64]
   stage: test
-  extends: .lava-test
+  extends: .lava-test-scheduled
   variables:
     MACHINE: raspberrypi4-64
     CI_BUILD_JOB_NAME: linux-raspberrypi4-64
@@ -247,7 +241,7 @@ lava-raspberrypi4-64:
 lava-seco-intel-b68:
   needs: [linux-seco-intel-b68]
   stage: test
-  extends: .lava-test
+  extends: .lava-test-scheduled
   variables:
     MACHINE: seco-intel-b68
     CI_BUILD_JOB_NAME: linux-seco-intel-b68
@@ -257,7 +251,7 @@ lava-seco-intel-b68:
 lava-seco-c61:
   needs: [linux-seco-imx8mm-c61-4gb]
   stage: test
-  extends: .lava-test
+  extends: .lava-test-scheduled
   variables:
     MACHINE: seco-imx8mm-c61-4gb
     CI_BUILD_JOB_NAME: linux-seco-imx8mm-c61-4gb
@@ -267,7 +261,7 @@ lava-seco-c61:
 lava-qemu-x86-ltp:
   needs: [linux-qemu-x86]
   stage: test
-  extends: .lava-test
+  extends: .lava-test-scheduled
   variables:
     MACHINE: qemux86
     CI_BUILD_JOB_NAME: linux-qemu-x86
@@ -277,7 +271,7 @@ lava-qemu-x86-ltp:
 lava-qemu-x86_64-ltp:
   needs: [linux-qemu-x86_64]
   stage: test
-  extends: .lava-test
+  extends: .lava-test-scheduled
   variables:
     MACHINE: qemux86-64
     CI_BUILD_JOB_NAME: linux-qemu-x86_64
@@ -287,7 +281,7 @@ lava-qemu-x86_64-ltp:
 lava-raspberrypi4-64-ltp:
   needs: [linux-raspberrypi4-64]
   stage: test
-  extends: .lava-test
+  extends: .lava-test-scheduled
   variables:
     MACHINE: raspberrypi4-64
     CI_BUILD_JOB_NAME: linux-raspberrypi4-64
@@ -297,7 +291,7 @@ lava-raspberrypi4-64-ltp:
 lava-seco-intel-b68-ltp:
   needs: [linux-seco-intel-b68]
   stage: test
-  extends: .lava-test
+  extends: .lava-test-scheduled
   variables:
     MACHINE: seco-intel-b68
     CI_BUILD_JOB_NAME: linux-seco-intel-b68
@@ -307,7 +301,7 @@ lava-seco-intel-b68-ltp:
 lava-seco-c61-ltp:
   needs: [linux-seco-imx8mm-c61-4gb]
   stage: test
-  extends: .lava-test
+  extends: .lava-test-scheduled
   variables:
     MACHINE: seco-imx8mm-c61-4gb
     CI_BUILD_JOB_NAME: linux-seco-imx8mm-c61-4gb
@@ -317,7 +311,7 @@ lava-seco-c61-ltp:
 lava-qemu-x86_64-kselftest:
   needs: [linux-qemu-x86_64]
   stage: test
-  extends: .lava-test
+  extends: .lava-test-scheduled
   variables:
     MACHINE: qemux86-64
     CI_BUILD_JOB_NAME: linux-qemu-x86_64
@@ -327,7 +321,7 @@ lava-qemu-x86_64-kselftest:
 lava-raspberrypi4-64-kselftest:
   needs: [linux-raspberrypi4-64]
   stage: test
-  extends: .lava-test
+  extends: .lava-test-scheduled
   variables:
     MACHINE: raspberrypi4-64
     CI_BUILD_JOB_NAME: linux-raspberrypi4-64
@@ -337,7 +331,7 @@ lava-raspberrypi4-64-kselftest:
 lava-seco-c61-kselftest:
   needs: [linux-seco-imx8mm-c61-4gb]
   stage: test
-  extends: .lava-test
+  extends: .lava-test-scheduled
   variables:
     MACHINE: seco-imx8mm-c61-4gb
     CI_BUILD_JOB_NAME: linux-seco-imx8mm-c61-4gb
@@ -347,7 +341,7 @@ lava-seco-c61-kselftest:
 lava-zephyr-96b-nitrogen-twister:
   needs: [zephyr-96b-nitrogen-twister]
   stage: test
-  extends: .lava-test
+  extends: .lava-test-scheduled
   variables:
     MACHINE: 96b-nitrogen
     CI_BUILD_JOB_NAME: zephyr-96b-nitrogen-twister
@@ -357,7 +351,7 @@ lava-zephyr-96b-nitrogen-twister:
 lava-qemu-x86-perf:
   needs: [linux-qemu-x86]
   stage: test
-  extends: .lava-test
+  extends: .lava-test-scheduled
   variables:
     MACHINE: qemux86
     CI_BUILD_JOB_NAME: linux-qemu-x86
@@ -367,7 +361,7 @@ lava-qemu-x86-perf:
 lava-qemu-x86_64-perf:
   needs: [linux-qemu-x86_64]
   stage: test
-  extends: .lava-test
+  extends: .lava-test-scheduled
   variables:
     MACHINE: qemux86-64
     CI_BUILD_JOB_NAME: linux-qemu-x86_64
@@ -377,7 +371,7 @@ lava-qemu-x86_64-perf:
 lava-raspberrypi4-64-perf:
   needs: [linux-raspberrypi4-64]
   stage: test
-  extends: .lava-test
+  extends: .lava-test-scheduled
   variables:
     MACHINE: raspberrypi4-64
     CI_BUILD_JOB_NAME: linux-raspberrypi4-64
@@ -387,7 +381,7 @@ lava-raspberrypi4-64-perf:
 lava-seco-intel-b68-perf:
   needs: [linux-seco-intel-b68]
   stage: test
-  extends: .lava-test
+  extends: .lava-test-scheduled
   variables:
     MACHINE: seco-intel-b68
     CI_BUILD_JOB_NAME: linux-seco-intel-b68
@@ -397,7 +391,7 @@ lava-seco-intel-b68-perf:
 lava-seco-c61-perf:
   needs: [linux-seco-imx8mm-c61-4gb]
   stage: test
-  extends: .lava-test
+  extends: .lava-test-scheduled
   variables:
     MACHINE: seco-imx8mm-c61-4gb
     CI_BUILD_JOB_NAME: linux-seco-imx8mm-c61-4gb
@@ -425,28 +419,6 @@ lava-zephyr-qemu-x86:
     CI_REPORT_JOB_NAME: lava-report
 
 lava-report:
-  needs:
-    - lava-qemu-x86
-    - lava-qemu-x86_64
-    - lava-raspberrypi4-64
-    - lava-seco-intel-b68
-    - lava-seco-c61
-    - lava-qemu-x86-ltp
-    - lava-qemu-x86_64-ltp
-    - lava-raspberrypi4-64-ltp
-    - lava-seco-intel-b68-ltp
-    - lava-seco-c61-ltp
-    - lava-qemu-x86-perf
-    - lava-qemu-x86_64-perf
-    - lava-raspberrypi4-64-perf
-    - lava-seco-intel-b68-perf
-    - lava-seco-c61-perf
-    - lava-zephyr-96b-nitrogen-twister
-    - lava-zephyr-qemu-cortex-m3
-    - lava-zephyr-qemu-x86
-    - lava-qemu-x86_64-kselftest
-    - lava-raspberrypi4-64-kselftest
-    - lava-seco-c61-kselftest
   extends: .lava-report
 
 lava-badge:
diff --git a/.oniro-ci/test-generic.yaml b/.oniro-ci/test-generic.yaml
index d43bb57b..cc0db6b5 100644
--- a/.oniro-ci/test-generic.yaml
+++ b/.oniro-ci/test-generic.yaml
@@ -12,6 +12,7 @@
     GIT_STRATEGY: none
     CI_LAVA_INSTANCE: "https://lava.ostc-eu.org/"
     CI_SQUAD_INSTANCE: "https://squadp.svc.ostc-eu.dev"
+    CI_SQUAD_PROJECT_NAME: "oniro-test-mr"
     # 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"
@@ -71,8 +72,8 @@
     # Submit the jobs to SQUAD.
     - |
       for job_def in $(find lava_jobs/ -name "*.yaml"); do
-        echo $CI_SQUAD_INSTANCE/api/submitjob/oniro-core/$CI_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_PROJECT_NAME/$CI_PIPELINE_ID/$MACHINE --header "Auth-Token: $CI_SQUAD_TOKEN"  --form "backend=oniro_lava" --form "definition=@${job_def}"
+        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}"
       done
       # Attach a callback to this build to trigger the lava-report job
       curl -X POST $CI_SQUAD_INSTANCE/api/build/$CI_PIPELINE_ID/callbacks/ -F "callback_url=$CALLBACK_URL"
@@ -80,6 +81,8 @@
     paths:
       - lava_jobs/*.yaml
   rules:
+    - if: '$CI_SQUAD_TOKEN == null'
+      when: never
     # Run the build when it is scheduled.
     - if: $CI_PIPELINE_SOURCE == "schedule"
     # Do not run pipelines for draft merge requests unless manually triggered.
@@ -115,6 +118,8 @@
       fi
 
   rules:
+    - if: '$CI_SQUAD_TOKEN == null'
+      when: never
     # Run the build when it is scheduled.
     - if: $CI_PIPELINE_SOURCE == "schedule"
       when: manual
-- 
GitLab