#
# \brief  Environment for executing Genode on Linux
# \author Norman Feske
# \date   2010-08-16
#
# For the documentation of the implemented API functions,
# please refer to the comments in 'tool/run'.
#

proc create_boot_directory { } {
	exec rm -rf [run_dir]
	exec mkdir -p [run_dir]
}


proc install_config {config} {
	set fh [open "[run_dir]/config" "WRONLY CREAT TRUNC"]
	puts $fh $config
	close $fh
}


proc build_boot_image {binaries} {
	foreach binary $binaries {
		exec ln -sf ../../../bin/$binary [run_dir] }
}


proc run_genode_until {{wait_for_re forever} {timeout_value 0}} {
	global output
	set timeout $timeout_value
	set orig_pwd [pwd]
	cd [run_dir]
	set pid [spawn ./core]
	if {$wait_for_re == "forever"} { interact $pid }
	expect {
		-re $wait_for_re { }
		timeout { puts stderr "Error: Test execution timed out"; exit -2 }
	}
	cd $orig_pwd
	set output $expect_out(buffer)
}

