device_type: "qemu"

{% if tests %}
job_name: "tuxrun@{{ device.name }}: {{ tests|map(attribute="name")|join(", ")}}"
{% else %}
job_name: "tuxrun@{{ device.name }}: boot"
{% endif %}
priority: "medium"
visibility: "public"

context:
    arch: "{{ lava_arch }}"
    machine: "{{ machine }}"
    cpu: "{{ cpu }}"
{% if memory %}
    memory: "{{ memory }}"
{% endif %}
    extra_options: ["-no-reboot", "{{ '", "'.join(extra_options) }}"]
    no_kvm: {{ no_kvm|lower }}
    no_network: {{ no_network|lower}}

{%- set deploy_timeout = timeouts.deploy|default(5) %}
{%- set boot_timeout = timeouts.boot|default(15) %}

{% block timeouts %}
timeouts:
  job:
    minutes: {{ deploy_timeout + boot_timeout + tests_timeout }}
  action:
   minutes: 5
  actions:
    power-off:
      seconds: 30
{% endblock %}

actions:
- deploy:
    to: tmpfs
    timeout:
      minutes: {{ deploy_timeout }}
    os: oe
    images:
      kernel:
        image_arg: '-kernel {kernel} -append "console={{ console }},115200 rootwait root={{ rootfs_dev }}{{ rootfs_partition|default("", true) }} debug verbose console_msg_format=syslog systemd.log_level=warning{% if tux_boot_args %} {{ tux_boot_args }}{% endif %} earlycon"{% if shared %} -virtfs local,path={{ shared.0 }},mount_tag=tuxrun,security_model=mapped{% endif %}'
        url: "{{ kernel }}"
{% if compression(kernel)[1] is not none %}
        compression: {{ compression(kernel)[1] }}
{% endif %}
{% if bios %}
      bios:
        image_arg: "-bios {bios}"
        url: "{{ bios }}"
{% endif %}
{% if dtb %}
      dtb:
        image_arg: "-dtb {dtb}"
        url: "{{ dtb }}"
{% endif %}
      rootfs:
        image_arg: "{{ rootfs_arg }}"
        url: "{{ rootfs }}"
{% if compression(rootfs)[1] is not none %}
        compression: {{ compression(rootfs)[1] }}
{% endif %}
        format: ext4
{% if overlays %}
        overlays:
{% if tests %}
          lava: true
{% endif %}
{% for name, overlay, dst in overlays %}
          {{ name }}:
            url: "{{ overlay }}"
            format: {{ compression(overlay)[0] }}
{% if compression(overlay)[1] is not none %}
            compression: {{ compression(overlay)[1] }}
            path: "{{ dst }}"
{% else %}
            path: "{{ dst }}{{ overlay.split('/')[-1] }}"
{% endif %}
{% endfor %}
{% elif tests %}
        overlays:
          lava: true
{% endif %}
- boot:
    method: qemu
{% if qemu_image %}
    docker:
      image: {{ qemu_image }}
{% endif %}
    timeout:
      minutes: {{ boot_timeout }}
{% if not enable_trustzone or "tfa-tests" not in tests|map(attribute="name")|join(", ") %}
    auto_login:
      login_prompt: 'login:'
      username: root
{% if shared %}
      login_commands:
      - mkdir -p {{ shared.1 }}
      - mount -t 9p -o trans=virtio tuxrun {{ shared.1 }}
{% endif %}
    prompts:
    - 'root@(.*):[/~]#'
{% for prompt in tux_prompt %}
    - "{{ prompt }}"{% endfor %}
{% endif %}
