#  Copyright(c) 01/18/01 Sun Microsystems, Inc.
#  All rights reserved.

#ident  "@(#)odd_disk_test  1.10  01/01/18  SMI."

global System ed_cmd Syslist Testlist
set ed_path [exec pkgparam SUNWedag BASEDIR]
set ed_cmd $ed_path/SUNWsymon/addons/AdvancedMonitoring/lib/agent/ed_cmd

proc list-listing { node } {

	global System Syslist

	lappend Syslist $node
	foreach item $System($node) {
		if {$item != 0} {
			list-listing $item
		}
	}
}

proc print-listing { num node } {

	global System

	for {set i 0} { $i < $num } {incr i 1} {
		puts -nonewline "\t"
	}
	puts $node
	foreach item $System($node) {
		if {$item != 0} {
			print-listing [expr $num + 1] $item
		}
	}
}

proc create-listing { new } {

	global System ed_cmd

	#puts stdout $new

	set l [exec $ed_cmd list $new]
	#puts stdout $l

	set l2 [string trimleft $l $new]
	#puts stdout $l2

	set l [string trimleft $l2 {~\{}]
	#puts stdout $l

	if {[string match {*none} $l] == 1} {
		set l2 [string trimright $l {"none":\}~}]
		#puts stdout $l2
	} else {
		set l2 [string trimright $l {"disabled":\}~}]
		#puts stdout $l2
	}

	set l [split $l2 {,}]

	foreach val $l {
		set l2 [string trimright $val {"disabled"}]
		set item [string trimright $l2 {:~}]
		lappend items $item
	}
	#puts stdout $items
	set System($new) $items

	foreach item $items {
		if {$item != 0} {
			create-listing $item
		}
	}
}

proc search_list { devices pattern } {

	global Testlist

	set num [lsearch $devices *$pattern*]

	set item [lindex $devices $num]
	
	set end [llength $devices]

	set rest [lrange $devices [expr $num + 1] [expr $end - 1]]

	if {$num != -1} {
		lappend Testlist $item
		search_list $rest $pattern
	}

}

set c [exec $ed_cmd set tmode 2]
#puts stdout $c

set c [exec $ed_cmd deselect /]
#puts stdout $c

create-listing \/
#print-listing 0 \/

list-listing \/
#puts stdout $Syslist

search_list $Syslist disktest
#puts stdout $Testlist

set num [llength $Testlist]

for {set i 0} { $i < $num } {incr i 2} {
	set device [lindex $Testlist $i]
	#puts stdout $device
	set c [exec $ed_cmd select $device]
	#puts stdout $c
}

set c [exec $ed_cmd reset]

set c [exec $ed_cmd start]

set c [exec $ed_cmd option \/\[Stress\:disabled,Verbose\:enabled,Core File\:disabled,Run On Error\:disabled,Max System Errors\:0,Max Passes\:1,Max Errors\:1,Max Time\:0,Num. of Instances\:1,\] \/]
