- job:
    name: armnn-ci-benchmarking
    project-type: freestyle
    defaults: global
    description: |
        Updates source and builds ArmNN frequently to ensure builds are successful.
    properties:
        - authorization:
            anonymous:
                - job-read
                - job-extended-read
            everyone-flat:
                - job-read
                - job-extended-read
                - job-build
                - job-cancel
        - build-discarder:
            days-to-keep: 90
            num-to-keep: 90
        - github:
            url: https://git.mlplatform.org/ml/armnn.git

    parameters:
        - string:
            name: LAVA_SERVER
            default: 'https://validation.linaro.org/RPC2/'
    disabled: false
    node: docker-bionic-arm64
    display-name: 'Arm NN - CI Build: MLPerf Benchmark'

    wrappers:
        - timestamps
        - credentials-binding:
            - text:
                credential-id: QA_REPORTS_TOKEN
                variable: QA_REPORTS_TOKEN
    builders:
        - shell: |
            #!/bin/bash -e
            echo "DEVICE_TYPE=${DEVICE_TYPE}" > device_type_parameters
        - inject:
            properties-file: device_type_parameters
        - linaro-publish-token

        - shell: |
            #!/bin/bash -ex


            sudo apt-get -q update
            sudo apt-get install -y jq
            sudo apt-get install -y --no-install-recommends python-pip virtualenv python-dev python3-dev
            wget https://snapshots.linaro.org/components/armnn-master/latest/buildInfo.json

            LAVA_ID=( $(jq -r '.LAVA_ID' buildInfo.json))
            BUILD_NUM_ORIGIN=( $(jq -r '.BUILD_NUMBER' buildInfo.json))


            git clone https://github.com/Linaro/lava-test-plans.git


            curl \
                --header "Auth-Token: $QA_REPORTS_TOKEN" \
                https://qa-reports.linaro.org/api/createbuild/armnn/armnn-benchmarking/$LAVA_ID

            # submit tests to LAVA
            rm -rf venv | true
            virtualenv -p python3 venv
            source ./venv/bin/activate

            cd ./lava-test-plans
            pip install -r requirements.txt

            export DEVICE_TYPE=synquacer

            cat << EOF > ${WORKSPACE}/submit_for_testing_parameters
            LAVA_JOB_PRIORITY=50
            PROJECT_NAME=armnn-benchmarking
            PROJECT=projects/armnn/
            AUTO_LOGIN_PASSWORD_PROMPT='Password:'
            AUTO_LOGIN_PASSWORD='Linaro123'
            ARMNN_TARBALL_URL=https://snapshots.linaro.org/components/armnn-master/latest/armnn.tar.xz
            KERNEL_URL=http://images.validation.linaro.org/synquacer/hc/vmlinuz
            RAMDISK_URL=http://images.validation.linaro.org/synquacer/hc/initrd.img
            RAMDISK_URL_COMP=gz
            ROOTFS_URL=http://images.validation.linaro.org/synquacer/hc/rootfs.tar.xz
            ROOTFS_URL_COMP=xz
            DEPLOY_OS=debian
            OS_INFO=debian
            DEVICE_TYPE=${DEVICE_TYPE}
            BUILD_NUMBER=${BUILD_NUM_ORIGIN}
            EOF

            ./submit_for_testing.py --variables ${WORKSPACE}/submit_for_testing_parameters \
              --device-type ${DEVICE_TYPE} \
              --test-plan armnn-benchmarking \
              --qa-server-team armnn \
              --qa-server-project armnn \
              --lava-server ${LAVA_SERVER} \
              --build-id ${LAVA_ID}
