##
# Get output of the target machine via Intel AMT's SoL feature
#
# \param --amt-host       network address of target machine
# \param --amt-password   AMT password for target machine
#

source [genode_dir]/tool/run/log.inc
source [genode_dir]/tool/run/amt.inc


proc log_amt_host { } {
	return [get_cmd_arg_first --log-amt-host ""]
}


proc log_amt_password { } {
	return [get_cmd_arg_first --log-amt-password ""]
}


##
# Log output of the test machine using Intel's AMT
#
proc run_log { wait_for_re timeout_value } {
	global output_spawn_id

	if {![is_amt_available [log_amt_host] [log_amt_password]]} {
		set exit_result 1
		return false
	}

	#
	# grab output
	#
	set amtterm  "amtterm -u admin -p [log_amt_password] -v [log_amt_host]"
	if {$wait_for_re == "forever"} {
		set timeout -1
	} else {
		set timeout [expr $timeout_value + 30]
	}
	set exit_result 1

	eval spawn $amtterm
	set output_spawn_id $spawn_id

	set kernel_msg [run_boot_string]

	expect {
		-i $output_spawn_id $kernel_msg { }
		eof         {
			puts stderr "Aborting, received EOF"
			return false
		}
		timeout     {
			puts stderr "Boot process timed out"
			close
			return false
		}
	}

	wait_for_output $wait_for_re $timeout_value $output_spawn_id
	return true
}
