assert_spec x86

if {[have_spec linux]} {
	puts "The [run_name] scenario requires QEMU networking."
	exit 1
}

create_boot_directory
import_from_depot [depot_user]/src/[base_src] \
                  [depot_user]/pkg/[drivers_nic_pkg] \
                  [depot_user]/src/init \
                  [depot_user]/src/libc \
                  [depot_user]/src/libcrypto \
                  [depot_user]/src/libssl \
                  [depot_user]/src/posix \
                  [depot_user]/src/rtc_drv \
                  [depot_user]/src/vfs_jitterentropy \
                  [depot_user]/src/vfs_lxip \
                  [depot_user]/src/vfs
build { app/drill }


install_config {
<config>
	<parent-provides>
		<service name="CPU"/>
		<service name="IO_MEM"/>
		<service name="IO_PORT"/>
		<service name="IRQ"/>
		<service name="LOG"/>
		<service name="PD"/>
		<service name="RM"/>
		<service name="ROM"/>
	</parent-provides>
	<default-route>
		<any-service>  <parent/> <any-child/></any-service>
	</default-route>
	<default caps="100"/>

	<start name="timer">
		<resource name="RAM" quantum="1M"/>
		<provides><service name="Timer"/></provides>
	</start>

	<start name="drivers" caps="1000">
		<resource name="RAM" quantum="32M" constrain_phys="yes"/>
		<binary name="init"/>
		<route>
			<service name="ROM" label="config"> <parent label="drivers.config"/> </service>
			<service name="Timer"> <child name="timer"/> </service>
			<any-service> <parent/> </any-service>
		</route>
		<provides> <service name="Nic"/> </provides>
	</start>

	<start name="rtc_drv">
		<resource name="RAM" quantum="4M"/>
		<provides> <service name="Rtc"/> </provides>
	</start>

	<start name="drill" caps="256">
		<resource name="RAM" quantum="32M"/>
		<config>
			<libc stdout="/dev/log" stderr="/dev/log" rtc="/dev/rtc" socket="/socket"/>
			<vfs>
				<dir name="dev">
					<log/> <rtc/>
					<jitterentropy name="random"/>
					<jitterentropy name="urandom"/>
				</dir>
				<dir name="socket"> <lxip dhcp="yes"/> </dir>
			</vfs>
			<arg value="drill"/>
			<arg value="-T"/>
			<arg value="genode.org"/>
			<arg value="@10.0.2.3"/>
		</config>
	</start>
</config>
}

build_boot_image { drill }

append qemu_args " -nographic -net nic,model=e1000 -net user -net dump,file=[run_dir]/dump.pcap"

run_genode_until {child "drill" exited with exit value 0.*\n} 120
