device_type: rzn1d
job_name: SE ${MACHINE} prod-image (u-boot,ubi) ${MANIFEST_BRANCH}-${KERNEL_VERSION_PATCHLEVEL} ${BUILD_NUMBER}

timeouts:
  job:
    minutes: 100
  action:
    minutes: 70
  connection:
    minutes: 20
priority: medium
visibility: public

actions:

####################
# Deploy QSPI images
####################
- deploy:
    namespace: dfu-firmware
    to: tmpfs
    images:
      sf_fsbl:
        image_arg: --alt sf_fsbl --download {sf_fsbl}
        url: ${FSBL_URL}
      sf_trustedfw0:
        image_arg: --alt sf_trustedfw0 --download {sf_trustedfw0}
        url: ${OPTEE_ITB_URL}
      sf_trustedfw1:
        image_arg: --alt sf_trustedfw1 --download {sf_trustedfw1}
        url: ${OPTEE_ITB_URL}
      sf_uboot0:
        image_arg: --alt sf_uboot0 --download {sf_uboot0}
        url: ${UBOOT_ITB_URL}
      sf_uboot1:
        image_arg: --alt sf_uboot1 --download {sf_uboot1}
        url: ${UBOOT_ITB_URL}

- command:
    namespace: dfu-firmware
    name: set_boot_to_nand

- boot:
    namespace: dfu-firmware
    method: dfu
    timeout:
      minutes: 10

- command:
    namespace: test
    name: set_boot_to_qspi

##########################
# Configure ethernet ports
##########################
- command:
    namespace: test
    name: j17_off
- command:
    namespace: test
    name: j21_on
- command:
    namespace: test
    name: j22_off
- command:
    namespace: test
    name: j23_off
- command:
    namespace: test
    name: j24_off

###############
# u-boot
###############
- deploy:
    namespace: test-uboot
    timeout:
      minutes: 15
    to: tftp
    kernel:
      # This is a known kernel image used for CRC checks only
      url: https://releases.linaro.org/members/schneider/openembedded/2019.09-warrior/soca9/zImage--4.19.72+git0+7549a49ae5-r0-snarc-soca9-20191003145415.bin
      type: zimage

- boot:
    namespace: test-uboot
    connection-namespace: dfu-firmware
    timeout:
      minutes: 20
    method: bootloader
    bootloader: u-boot
    commands: []
    prompts: ["=>"]

# Run some U-Boot tests
- test:
    namespace: test-uboot
    timeout:
      minutes: 5
    interactive:
    - name: uboot-tests
      prompts: ["=> ", "/ # "]
      script:
      - command: echo "u-boot echo test"
        name: echo
        successes:
        - message: "u-boot echo test"
      - command: version
        name: version
        successes:
        - message: "U-Boot"
      - command: help test
        name: help
        successes:
        - message: "test - minimal test like /bin/sh"
      # saveenv and printenv
      - command: setenv test_var test123
      - command: printenv
        name: setenv-and-printenv
        successes:
        - message: "test_var=test123"
    - name: memory-test
      prompts: ["=> ", "/ # "]
      script:
      # memory test
      # base - print or set address offset
      - command: base
        name: print-default-base-address-offset
        successes:
        - message: "Base Address: 0x"
      - command: base 80000000
        name: set-address-offset-0x80000000
        successes:
        - message: "Base Address: 0x80000000"
      - command: base
        name: check-address-offset-0x80000000
        successes:
        - message: "Base Address: 0x80000000"
      # crc32 - checksum calculation
      - command: mw.b 00000000 aa 400
      - command: crc32 -v 80000000 400 3c6f327d
      - command: echo return code $$?
        name: compute-CRC32-checksum
        successes:
        - message: "return code 0"
      # mw - memory write
      # md - memory display
      - command: mw 100000 aabbccdd 10
      - command: md 100000 10
        name: mw-md-100000
        successes:
        - message: "aabbccdd"
      # md - memory display
      # cp - memory copy
      - command: cp 100000 200000 10
      - command: md 200000 10
        name: cp-md-200000
        successes:
        - message: "aabbccdd"
      # cmp - memory compare
      - command: cmp 100000 200000 10
        name: cmp-100000-200000-10
        successes:
        - message: "Total of 16 word\\(s\\) were the same"
    - name: dhcp-cmds
      prompts: ["=> ", "/ # "]
      script:
      # dhcp
      - command: setenv autoload no ; dhcp ; dhcp
        name: dhcp
        successes:
        - message: "DHCP client bound to address"
    - name: ping-cmds
      prompts: ["=> ", "/ # "]
      script:
      # ping
      - command: ping {SERVER_IP}
        name: ping
        successes:
        - message: "is alive"
    - name: tftp-cmds
      prompts: ["=> ", "/ # "]
      script:
      # TFTP
      - command: setenv serverip {SERVER_IP} ; tftp {KERNEL_ADDR} {KERNEL}
        name: tftp
        successes:
        - message: "Bytes transferred = 6752784"
      - command: crc32 -v {KERNEL_ADDR} 670a10 ca050911
      - command: echo return code $$?
        successes:
        - message: "return code 0"
    - name: nand-commands
      prompts: ["=> ", "/ # "]
      script:
      # nand
      - command: nand info
        name: nand-info
        successes:
        - message: nand0, sector size 128 KiB

###############
# prod-image.ubi
###############
- deploy:
    namespace: test-ubi
    to: tmpfs
    images:
      n_fs1:
        image_arg: --alt n_fs1 --download {n_fs1}
        url: ${UBI_IMAGE_URL}

- command:
    namespace: test-ubi
    name: set_boot_to_nand
- boot:
    namespace: test-ubi
    method: dfu
    timeout:
      minutes: 10
- command:
    namespace: test-ubi
    name: set_boot_to_qspi

- boot:
    namespace: test-ubi
    connection-namespace: test-ubi
    timeout:
      minutes: 20
    method: u-boot
    commands:
      - setenv bootargs $$bootargs audit=0
      - run linux_bestla
    auto_login:
      login_prompt: "login:"
      username: root
      password_prompt: "Password:"
      password: "P@ssword-1"
      login_commands:
      - "P@ssword-1"
      - "azertAZERT12345"
      - "azertAZERT12345"
      - "azertAZERT12345"
    prompts:
    - "Current password: "
    - "New password: "
    - "Retype new password: "
    - "root@rzn1d400-bestla:"

- test:
    namespace: test-ubi
    connection-namespace: test-ubi
    timeout:
      minutes: 60
    interactive:
    - name: basic-cmds-ubi
      prompts: ["root@snarc-soca9", "root@rzn1d400-bestla"]
      script:
      - command: uname -a
      - command: cat /proc/device-tree/model ; echo ""
      - command: ps aux --sort -rss
      - command: cat /proc/meminfo
      - command: cat /proc/cpuinfo
      - command: free -h
      - command: sysctl -a | grep vm.min_free_kbytes
      - command: mount
      - command: systemctl --no-pager status systemd-resolved
      - command: systemctl --no-pager restart systemd-resolved
      - command: systemctl --no-pager status systemd-resolved
      - command: ifconfig -a
      - command: ping -c 3 github.com
      - command: which docker
      - command: systemctl --no-pager status docker
      - command: sleep 100
      - command: systemctl --no-pager status docker
      - command: ifconfig -a
      - command: docker run hello-world
      - command: docker run -it ubuntu uname -a


##################
# Reboot/Poweroff Tests
##################
- test:
    namespace: test-reboot
    connection-namespace: test-ubi
    timeout:
      minutes: 5
    interactive:
    - name: reboot-cmds-1
      prompts: ["root@snarc-soca9", "root@rzn1d400-bestla", "=> "]
      script:
      - command: reboot ; sleep 10

# Trigger 2nd boot
- boot:
    namespace: test-reboot
    connection-namespace: test-ubi
    timeout:
      minutes: 10
    method: u-boot
    commands:
    - setenv bootargs $$bootargs audit=0
    - run linux_bestla
    auto_login:
      login_prompt: "login:"
      username: root
      password_prompt: "Password:"
      password: azertAZERT12345
    prompts:
    - "root@snarc-soca9:"
    - "root@rzn1d400-bestla:"

- test:
    namespace: test-reboot
    connection-namespace: test-ubi
    timeout:
      minutes: 5
    interactive:
    - name: check-1st-reboot
      prompts: ["root@snarc-soca9", "root@rzn1d400-bestla"]
      script:
      - command: echo "We came back from a reboot"


# Reboot the board a 2nd time
- test:
    namespace: test-reboot-2
    connection-namespace: test-ubi
    timeout:
      minutes: 5
    interactive:
    - name: reboot-cmds-2
      prompts: ["root@snarc-soca9", "root@rzn1d400-bestla", "=> "]
      script:
      - command: reboot ; sleep 10

# Trigger a new boot
- boot:
    namespace: test-reboot-2
    connection-namespace: test-ubi
    timeout:
      minutes: 10
    method: u-boot
    commands:
    - setenv bootargs $$bootargs audit=0
    - run linux_bestla
    auto_login:
      login_prompt: "login:"
      username: root
      password_prompt: "Password:"
      password: "azertAZERT12345"
    prompts:
    - "root@snarc-soca9:"
    - "root@rzn1d400-bestla:"

- test:
    namespace: test-reboot-2
    connection-namespace: test-ubi
    timeout:
      minutes: 5
    interactive:
    - name: check-2nd-reboot
      prompts: ["root@snarc-soca9", "root@rzn1d400-bestla", "=> "]
      script:
      - command: echo "We came back from the 2nd reboot"

# Test poweroff
- test:
    namespace: test-poweroff
    connection-namespace: test-ubi
    timeout:
      minutes: 5
    interactive:
    - name: poweroff-cmds
      prompts: ["root@snarc-soca9", "root@rzn1d400-bestla", "=> ", "reboot: Power down"]
      script:
      - command: poweroff ; sleep 10

# Check we are in u-boot after poweroff
# - test:
#     namespace: test-poweroff
#     connection-namespace: test-ubi
#     timeout:
#       minutes: 5
#     interactive:
#     - name: check-poweroff
#       prompts: ["=> "]
#       script:
#       - command: version
#         successes:
#         - message: "U-Boot"

metadata:
  machine: ${MACHINE}
  manifest branch: ${MANIFEST_BRANCH}-${KERNEL_VERSION_PATCHLEVEL}
  manifest commit: ${MANIFEST_COMMIT}
  build url: ${BUILD_URL}
  build location: ${PUBLISH_SERVER}${PUB_DEST}

notify:
    recipients:
    - to:
        method: email
        email: ralph.siemsen@linaro.org
    criteria:
        status: incomplete
    verbosity: verbose
