#!/usr/bin/expect
############################################################################
# Purpose: Test of POE functionality
#          Test of Network options being set correctly. 
#          (-euilib and -euidevice)
#          
#
# Output:  "TEST: #.#" followed by "SUCCESS" if test was successful, OR
#          "FAILURE: ..." otherwise with an explanation of the failure, OR
#          anything else indicates a failure mode that must be investigated.
#
############################################################################
# Copyright (C) 2002-2006 The Regents of the University of California.
# Produced at Lawrence Livermore National Laboratory (cf, DISCLAIMER).
# Written by Danny Auble <da@llnl.gov>
# LLNL-CODE-402394.
# 
# This file is part of SLURM, a resource management program.
# For details, see <http://www.llnl.gov/linux/slurm/>.
#  
# SLURM is free software; you can redistribute it and/or modify it under
# the terms of the GNU General Public License as published by the Free
# Software Foundation; either version 2 of the License, or (at your option)
# any later version.
# 
# SLURM is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
# details.
# 
# You should have received a copy of the GNU General Public License along
# with SLURM; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301  USA.
############################################################################
source ./globals

set test_id     "11.2"
set env(SLURM_LL_API_DEBUG) "2"
set exit_code   0
set mode        "us"
set device      "sn0"
set found_mode  ""
set found_device ""
set job_id      0

print_header $test_id

if { ![file exists $poe] } {
	send_user "WARNING: poe must be installed on the\
	    system to run this test.\n"
	exit $exit_code
}


#
# execute poe with a specific node count
#
if { [string length $partition] == 0 } {
	set partition [default_partition]
}
spawn $poe hostname -rmpool $partition\
    -euidevice $device -retry wait

expect {
	-re "ERROR: don't specify the sn adapter" {
		set found_device 1
		exp_continue
	}
	-re "Error configuring interconnect" {
		set found_device 1
		exp_continue
	}
	timeout {
		send_user "\nFAILURE: poe not responding\n"
		cancel_job $job_id
		set exit_code 1
	}
	eof {
	}
}
		

if { $found_device != 1 } {
	send_user "\nFAILURE: device '$device' was not set correctly\
got '$found_device'\n"
	set exit_code 1
}

#
# execute poe with a specific node count
#
spawn $poe hostname -rmpool $partition -euilib $mode -retry wait

expect {
	-re "LL_AdapterUsageMode = ($alpha_numeric_under)" {
		set found_mode $expect_out(1,string)
		exp_continue
	}
	timeout {
		send_user "\nFAILURE: poe not responding\n"
		cancel_job $job_id
		set exit_code 1
	}
	eof {
	}
}
		

if {[string compare $mode $found_mode]} {
	send_user "\nFAILURE: mode '$mode' was not set correctly\
got '$found_mode'\n"
	set exit_code 1
}

set mode        "ip"
set device      "en0"
set found_mode  ""
set found_device ""

#
# execute poe with a specific node count
#
spawn $poe hostname -rmpool $partition -euilib $mode\
    -euidevice $device -retry wait

expect {
	-re "LL_AdapterUsageMode = ($alpha_numeric_under)" {
		set found_mode $expect_out(1,string)
		exp_continue
	}
	-re "LL_AdapterUsageDevice = ($alpha_numeric_under)" {
		set found_device $expect_out(1,string)
		exp_continue
	}
	timeout {
		send_user "\nFAILURE: poe not responding\n"
		cancel_job $job_id
		set exit_code 1
	}
	eof {
	}
}
		

if {[string compare $mode $found_mode]} {
	send_user "\nFAILURE: mode '$mode' was not set correctly\
got '$found_mode'\n"
	set exit_code 1
}
	
if {[string compare $device $found_device]} {
	send_user "\nFAILURE: device '$device' was not set correctly\
got '$found_device'\n"
	set exit_code 1
}
	
if {$exit_code == 0} {
	send_user "\nSUCCESS\n"
}
exit $exit_code
