# RTC test

assert_spec x86

if {[expr ![have_include power_on/qemu] && ![have_spec linux]]} {
	puts "Test requires Qemu or Linux."
	exit 0
}

create_boot_directory

import_from_depot [depot_user]/src/[base_src] \
                  [depot_user]/src/init \
                  [depot_user]/src/vfs \
                  [depot_user]/src/libc \
                  [depot_user]/src/posix \
                  [depot_user]/pkg/system_rtc-[board]


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="system_rtc" caps="400" priority="-1">
		<resource name="RAM" quantum="6M"/>
		<binary name="init"/>
		<provides> <service name="Rtc"/> <service name="Report"/> </provides>
		<route>
			<service name="ROM" label="config">  <parent label="system_rtc.config"/> </service>
			<service name="IO_MEM">  <parent/> </service>
			<service name="IO_PORT"> <parent/> </service>
			<service name="IRQ">     <parent/> </service>
			<service name="LOG">     <parent/> </service>
			<service name="PD">      <parent/> </service>
			<service name="RM">      <parent/> </service>
			<service name="CPU">     <parent/> </service>
			<service name="ROM">     <parent/> </service>
			<service name="Timer">   <child name="timer"/> </service>
		</route>
	</start>

	<start name="test-system_rtc" priority="-1">
		<resource name="RAM" quantum="1M"/>
		<config/>
		<route>
			<service name="Report"> <child name="system_rtc"/> </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 build_components { test/system_rtc test/libc_rtc }
set boot_components  { test-system_rtc test-libc_rtc }

build            $build_components
build_boot_image $boot_components

append qemu_args " -nographic  "

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