job_name: hikey-MutliNode-CTS-sharding-CtsNetTestCases
timeouts:
  job:
    hours: 4
priority: medium
visibility: public
reboot_to_fastboot: false

metadata:
  # Using the following images as newer version images I found has no good support for USB Ethernet dongle.
  android: 7.1.1
  link: https://developers.google.com/android/images-preview#hikey

protocols:
  lava-lxc:
    master:
      name: lxc-master
      distribution: ubuntu
      release: xenial
      arch: amd64
      verbose: true
    worker:
      name: lxc-worker
      distribution: ubuntu
      release: xenial
      arch: amd64
      verbose: true

  lava-multinode:
    # Use lxc device as master/host to run Tradefed shell. Tradefed shell shards a CTS run
    # into the number of workers independent chunks, and runs on the worker devices in parallel.
    roles:
      master:
        count: 1
        device_type: lxc
        timeout:
          minutes: 30
      worker:
        expect_role: master
        host_role: master
        count: 2
        device_type: hi6220-hikey-r2
        tags:
        - static-ip
        timeout:
          minutes: 30

actions:
- deploy:
    namespace: tlxc
    role:
    - master
    - worker
    to: lxc
    os: debian
    timeout:
      minutes: 10
    packages:
    - unzip
    - wget
    - zip
    - usbutils

- boot:
    namespace: tlxc
    role:
    - master
    - worker
    prompts:
    - 'root@(.*):/#'
    timeout:
      minutes: 5
    method: lxc

- test:
    namespace: tlxc
    role:
    - master
    - worker 
    timeout:
      minutes: 10
    definitions:
    - repository: https://github.com/Linaro/test-definitions
      from: git
      path: automated/linux/android-platform-tools/install.yaml
      name: install-android-platform-tools-latest

- deploy:
    timeout:
      minutes: 15
    to: fastboot
    namespace: droid
    role:
    - worker
    images:
      ptable:
        url: http://people.linaro.org/~chase.qi/archives/hikey/aosp_v7.1.1/ptable-aosp-8g.img
        reboot: hard-reset
      boot:
        url: http://people.linaro.org/~chase.qi/archives/hikey/aosp_v7.1.1/boot.img.xz
        compression: xz
        reboot: hard-reset
      cache:
        url: http://people.linaro.org/~chase.qi/archives/hikey/aosp_v7.1.1/cache.img.xz
        compression: xz
      userdata:
        url: http://people.linaro.org/~chase.qi/archives/hikey/aosp_v7.1.1/userdata.img.xz
        compression: xz
      system:
        url: http://people.linaro.org/~chase.qi/archives/hikey/aosp_v7.1.1/system.img.xz
        compression: xz
        apply-overlay: true
    os: debian
    protocols:
      lava-lxc:
      - action: fastboot-deploy
        request: pre-power-command
        timeout:
          minutes: 2

- boot:
    namespace: droid
    role:
    - worker 
    prompts:
      - 'root@(.*):/#'
      - 'hikey:/'
    timeout:
      minutes: 15
    method: fastboot

- test:
    namespace: tlxc
    role:
    - worker
    timeout:
      minutes: 10
    definitions:
    # Wait for DUT boot.
    - repository: https://github.com/Linaro/test-definitions
      from: git
      path: automated/android/wait-single-boot-completed.yaml
      name: wait-single-boot-completed

# Enable adb over TCP/IP
- test:
    namespace: tlxc
    role:
    - worker
    timeout:
      minutes: 10
    definitions:
    - repository:
        metadata:
          format: Lava-Test Test Definition 1.0
          name: enable-adb-tcpip
          description: "enable adb over tcpip"
          os:
          - ubuntu
          scope:
          - functional
        run:
          steps:
          - adb devices
          - adb tcpip 5555|| lava-test-raise "Failed to enable adb over tcpip"
      from: inline
      name: enable-adb-tcpip
      path: inline/enable-adb-tcpip.yaml

# Test and share adb over TCP/IP
- test:
    namespace: tlxc
    role:
    - worker
    timeout:
      minutes: 10
    protocols:
      lava-lxc:
      - action: multinode-test
        request: pre-os-command
        timeout:
          minutes: 2
    definitions:
    - repository:
        metadata:
          format: Lava-Test Test Definition 1.0
          name: test-adb-tcpip
          description: "test adb over tcpip"
          os:
          - ubuntu
          scope:
          - functional
        run:
          steps:
          - |
              set +e
              sleep 120
              dut_address="$(lava-target-ip):5555"
              ping -c 10 "${dut_address}"
              adb devices
              adb connect "${dut_address}"
              adb devices
              adb -s "${dut_address}" shell echo ok || lava-test-raise "adb-tcpip: Failed to execute adb shell cmd"
              set -e
          - |
              lava-sync start_handover
              lava-send dut_address dut_address="${dut_address}"
              lava-sync finish_handover
      from: inline
      name: test-adb-tcpip
      path: inline/test-adb-tcpip.yaml

- test:
    namespace: tlxc
    role:
    - worker
    timeout:
      hours: 2
    definitions:
    - repository: https://github.com/chase-qi/test-definitions
      from: git
      branch: tm2
      path: automated/android/multinode/wait-and-keep-local-device-accessible.yaml
      name: wait-and-keep-local-device-accessible
      params:
        # The sum of these timeouts must be smaller than the lava-multinode timeout for the master.
        BOOT_TIMEOUT_SECS: "480"
        NETWORK_TIMEOUT_SECS: "300"
        ADB_CONNECT_TEST_TIMEOUT_SECS: "60"
        ADB_PORT: "5555"

- test:
    namespace: tlxc
    role:
    - worker
    timeout:
      minutes: 15
    definitions:
    - repository: https://github.com/chase-qi/test-definitions
      from: git
      branch: tm2
      path: automated/android/multinode/wait-for-release-and-reset.yaml
      name: wait-for-release-and-reset

- test:
    namespace: tlxc
    role:
    - master
    timeout:
      minutes: 15
    definitions:
    - repository: https://github.com/chase-qi/test-definitions
      from: git
      branch: tm2
      path: automated/android/multinode/connect-to-remote-adb-tcpip-devices.yaml
      name: connect-to-remote-adb-tcpip-devices
      params:
        ADB_CONNECT_TIMEOUT_SECS: 300

- test:
    namespace: tlxc
    role:
    - master
    timeout:
      hours: 2
    definitions:
    - repository: https://github.com/chase-qi/test-definitions
      from: git
      branch: tm2
      path: automated/android/multinode/tradefed/tradefed-multinode.yaml
      params:
        TEST_PARAMS: "run cts --disable-reboot --include-filter CtsNetTestCases"
        TEST_RETRY_PARAMS: "run cts --disable-reboot"
        TEST_PATH: "android-cts"
        TEST_URL: "https://dl.google.com/dl/android/cts/android-cts-7.1_r24-linux_x86-arm.zip"
        STATE_CHECK_FREQUENCY_SECS: "300"
        MAX_NUM_RUNS: "25"
        RUNS_IF_UNCHANGED: "5"
        FAILURES_PRINTED: "50"
        # For Artifactorial:
        # URL: ""
        # TOKEN: ""
      name: cts

- test:
    namespace: tlxc
    role:
    - master
    timeout:
      minutes: 10
    definitions:
    - repository: https://github.com/chase-qi/test-definitions
      from: git
      branch: tm2
      path: automated/android/multinode/release-remote-adb-tcpip-devices.yaml
      name: release-remote-adb-tcpip-devices
