if {![have_spec x86_64]} {
	puts "\nTest requires x86_64\n"
	exit 0
}

if {[have_spec linux]} {
	puts "\nRun script is not supported on this platform\n"
	exit 0
}

create_boot_directory

import_from_depot \
	[depot_user]/src/[base_src] \
	[depot_user]/src/init \
	[depot_user]/src/rtc_drv \

source ${genode_dir}/repos/base/run/platform_drv.inc

append config {
<config>
	<parent-provides>
		<service name="ROM"/>
		<service name="IRQ"/>
		<service name="IO_MEM"/>
		<service name="IO_PORT"/>
		<service name="PD"/>
		<service name="RM"/>
		<service name="CPU"/>
		<service name="LOG"/>
	</parent-provides>

	<default-route>
		<any-service> <parent/> <any-child/> </any-service>
	</default-route>
	<default caps="128"/>}

append_platform_drv_config

append config {
	<start name="timer" caps="96">
		<resource name="RAM" quantum="1M"/>
		<provides> <service name="Timer"/> </provides>
	</start>

	<start name="rtc_drv" caps="96">
		<resource name="RAM" quantum="1M"/>
		<provides> <service name="Rtc"/> </provides>
	</start>

	<start name="nic_drv" caps="150">
		<binary name="ipxe_nic_drv"/>
		<resource name="RAM" quantum="20M"/>
		<provides><service name="Nic"/></provides>
	</start>

	<start name="nic_bridge" caps="200">
		<resource name="RAM" quantum="8M"/>
		<provides><service name="Nic"/></provides>
		<config mac="02:02:02:02:03:00">
			<policy label_prefix="solo5" ip_addr="10.0.0.2"/>
			<default-policy/>
		</config>
		<route>
		<service name="Nic"> <child name="nic_drv"/> </service>
			<any-service> <parent/> <any-child/> </any-service>
		</route>
	</start>

	<start name="solo5-test_ping_serve" caps="256">
		<resource name="RAM" quantum="4M"/>
		<config>
			<solo5 cmdline="limit"/>
			<nic/>
		</config>
		<route>
			<service name="Nic"> <child name="nic_bridge"/> </service>
			<any-service> <parent/> <any-child/> </any-service>
		</route>
	</start>

	<start name="ping">
		<resource name="RAM" quantum="8M"/>
		<config interface="10.0.0.72/24"
		        dst_ip="10.0.0.2"
		        period_sec="1"
		        verbose="no"
		        count="8"/>
		<route>
			<service name="Nic"> <child name="nic_bridge"/> </service>
			<any-service> <parent/> <any-child/> </any-service>
		</route>
	</start>
</config>
}

install_config $config

append build_components {
	app/ping
	drivers/nic
	server/nic_bridge
	test/solo5/ping_serve
}

append_platform_drv_build_components
build $build_components

append boot_modules {
	nic_bridge
	ping
	ipxe_nic_drv
	solo5-test_ping_serve
	solo5.lib.so
}

append_platform_drv_boot_modules
build_boot_image $boot_modules

append qemu_args " -nographic "

run_genode_until {child "ping" exited with exit value 0} 60
