# RTC test

create_boot_directory

set depot_pkgs "[depot_user]/src/[base_src] [depot_user]/src/init [depot_user]/src/report_rom"

if [have_board linux] {
	lappend depot_pkgs [depot_user]/src/linux_rtc_drv
} else {
	if [have_board pc] {
		lappend depot_pkgs [depot_user]/src/rtc_drv
	} else  {
		lappend depot_pkgs [depot_user]/src/dummy_rtc_drv
	}
}

puts $depot_pkgs
import_from_depot $depot_pkgs

# RTC setting tested on Qemu only
set test_update [have_include power_on/qemu]

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>}
append_if $test_update config {
	<start name="report_rom">
		<resource name="RAM" quantum="1M"/>
		<provides> <service name="Report"/> <service name="ROM"/> </provides>
		<config verbose="yes">
			<policy label_suffix="set_rtc" report="test-rtc -> set_rtc"/>
		</config>
	</start>}
append_if [have_board linux] config {
		<start name="linux_rtc_drv" priority="-1" ld="no">}
append_if [have_board pc] config {
		<start name="rtc_drv" priority="-1">}
append_if [expr ![have_board pc] && ![have_board linux]] config {
		<start name="dummy_rtc_drv" priority="-1">}
append config {
		<resource name="RAM" quantum="1M"/>
		<provides><service name="Rtc"/></provides>}
append_if $test_update config {
		<config allow_setting_rtc="true"/>
		<route>
			<service name="ROM" label="set_rtc">
				<child name="report_rom"/>
			</service>
			<any-service> <parent/> </any-service>
		</route>}
append config {
	</start>
	<start name="test-rtc" priority="-1">
		<resource name="RAM" quantum="1M"/>}
append_if $test_update config {
		<config set_rtc="yes" year="2069" month="12" day="31" hour="23" minute="55" second="0"/>}
append config {
	</start>
</config>
}

install_config $config

set build_components { test/rtc }
set boot_modules     { test-rtc }

build $build_components
build_boot_image $boot_modules

append qemu_args " -nographic  "

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