#
# \brief  Test for running python
# \author Norman Feske
# \author Johannes Schlatow
# \date   2011-11-22
#

if {![have_spec x86]} {
	puts "Run script is only supported on x86"; exit 0 }

proc depot_user {} { return [get_cmd_arg --depot-user local] }

create_boot_directory

import_from_depot [depot_user]/pkg/python3

#
# Build
#

build {
	core init
	timer
	drivers/rtc
	server/dynamic_rom
}


#
# Generate config
#

proc rtc_start_attr { } {
	if {[have_spec linux]} { return {ld="no"} } else { return "" } }

install_config {
<config verbose="yes">
	<parent-provides>
		<service name="ROM"/>
		<service name="PD"/>
		<service name="RM"/>
		<service name="CPU"/>
		<service name="LOG"/>
		<service name="IO_PORT"/>
	</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="rtc_drv" } [rtc_start_attr] {>
		<resource name="RAM" quantum="1M"/>
		<provides> <service name="Rtc"/> </provides>
	</start>
	<start name="dynamic_rom">
		<resource name="RAM" quantum="1M"/>
		<provides> <service name="ROM" /> </provides>
		<config>
			<rom name="hello.py">
				<inline>
print(" \r\n\r");
print("        -============================-");
print("        ||                          ||");
print("        ||    Python Core 3         ||");
print("        ||                          ||");
print("        ||       Genode 18.05       ||");
print("        ||                          ||");
print("        -============================-");
print(" \r");
print("   2018 by Genode Labs www.genode-labs.com");
print(" \r\n\r");
				</inline>
				<sleep milliseconds="4000" />
				<inline>
print("Hello again")
				</inline>
				<sleep milliseconds="4000" />
			</rom>
		</config>
	</start>
	<start name="python3" caps="200">
		<resource name="RAM" quantum="16M"/>
		<route>
			<service name="ROM" label="hello.py"> <child name="dynamic_rom" /> </service>
			<any-service> <parent/> <any-child/> </any-service>
		</route>
		<config>
			<pythonpath name="/python/Lib/:" />
			<file name="hello.py" on-rom-update="hello.py" />
			<vfs>
				<dir name="dev">
					<log/>
					<jitterentropy name="urandom" />
					<jitterentropy name="random" />
					<rtc/>
					<zero/>
				</dir>
				<dir name="python">
					<tar name="python3.tar" />
				</dir>
				<rom name="hello.py" />
			</vfs>
			<libc stdin="/dev/zero" stdout="/dev/log" stderr="/dev/log" rtc="/dev/rtc"/>
		</config>
	</start>
</config>}


#
# Boot modules
#

# generic modules
append boot_modules {
	core init
	ld.lib.so 
	timer
	rtc_drv
	dynamic_rom
}

build_boot_image $boot_modules

#
# Execute test case
#

append qemu_args "  -nographic "

run_genode_until {.*Hello again.*} 60

grep_output {python3\]  }
compare_output_to {
[init -> python3]
[init -> python3]         -============================-
[init -> python3]         ||                          ||
[init -> python3]         ||    Python Core 3         ||
[init -> python3]         ||                          ||
[init -> python3]         ||       Genode 18.05       ||
[init -> python3]         ||                          ||
[init -> python3]         -============================-
[init -> python3]
[init -> python3]    2018 by Genode Labs www.genode-labs.com
[init -> python3]
}

# vi: set ft=tcl :
