# RTC test

assert_spec x86

if {[expr ![have_include power_on/qemu]]} {
	puts "Test requires Qemu."
	exit 0
}

set build_components {
	test/system_rtc
	test/libc_rtc
}

create_boot_directory

import_from_depot [depot_user]/src/[base_src] \
                  [depot_user]/src/init \
                  [depot_user]/src/vfs \
                  [depot_user]/pkg/drivers_rtc-pc

build $build_components


set config {
<config prio_levels="2" verbose="yes">
	<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="100"/>

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

	<start name="report_rom">
		<resource name="RAM" quantum="1M"/>
		<provides> <service name="Report"/> <service name="ROM"/> </provides>
		<config verbose="yes">
			<policy label="rtc_drv -> set_rtc"    report="test-system_rtc -> drv_set_rtc"/>
			<policy label="system_rtc -> set_rtc" report="test-system_rtc -> sys_set_rtc"/>
		</config>
	</start>

	<start name="rtc_drv" priority="-1">
		<resource name="RAM" quantum="1M"/>
		<provides><service name="Rtc"/></provides>
		<config allow_setting_rtc="true"/>
		<route>
			<service name="ROM" label="set_rtc">
				<child name="report_rom"/>
			</service>
			<any-service> <parent/> </any-service>
		</route>
	</start>

	<start name="system_rtc" priority="-1">
		<resource name="RAM" quantum="1M"/>
		<provides><service name="Rtc"/></provides>
		<config allow_setting_rtc="true"/>
		<route>
			<service name="ROM" label="set_rtc"> <child name="report_rom"/> </service>
			<service name="Rtc"> <child name="rtc_drv"/> </service>
			<service name="Timer"> <child name="timer"/> </service>
			<any-service> <parent/> </any-service>
		</route>
	</start>

	<start name="test-system_rtc" priority="-1">
		<resource name="RAM" quantum="1M"/>
		<config/>
		<route>
			<service name="Report"> <child name="report_rom"/> </service>
			<service name="Rtc"> <child name="system_rtc"/> </service>
			<service name="Timer"> <child name="timer"/> </service>
			<any-service> <parent/> </any-service>
		</route>
	</start>

	<start name="test-libc_rtc" caps="150">
		<resource name="RAM" quantum="4M"/>
		<config>
			<vfs> <dir name="dev"> <log/> <rtc/> </dir> </vfs>
			<libc stdout="/dev/log" stderr="/dev/log" rtc="/dev/rtc"/>
		</config>
		<route>
			<service name="Rtc"> <child name="system_rtc"/> </service>
			<service name="Timer"> <child name="timer"/> </service>
			<any-service> <parent/> </any-service>
		</route>
	</start>

</config>}

install_config $config

set boot_components {
	test-system_rtc
	test-libc_rtc libc.lib.so libm.lib.so posix.lib.so
}

build_boot_image $boot_components

append qemu_args " -nographic  "

run_genode_until ".*--- system RTC test finished ---.*\n" 60
