From 56edfeb18caf6f525cfcd3d0545992cf3241bbb1 Mon Sep 17 00:00:00 2001
From: Moe Jette <jette1@llnl.gov>
Date: Mon, 15 Jun 2009 17:21:48 +0000
Subject: [PATCH] Make test4.12 work properly when SelectType=select/cons_res
 with different values of SelectTypeParameter (allocate by socket, core,
 thread, etc.)

---
 testsuite/expect/globals  | 29 ++++++++++++++++++++++++++++
 testsuite/expect/test4.12 | 40 ++++++++++++++++++++++++++++++---------
 2 files changed, 60 insertions(+), 9 deletions(-)

diff --git a/testsuite/expect/globals b/testsuite/expect/globals
index e18ea57ff62..5efca537589 100755
--- a/testsuite/expect/globals
+++ b/testsuite/expect/globals
@@ -1044,6 +1044,35 @@ proc test_select_type { } {
 	return $type
 }
 
+################################################################
+#
+# Proc: test_select_type_params
+#
+# Purpose: Determine SelectTypeParameters being used
+#
+# Returns value of SelectTypeParameters
+#
+################################################################
+
+proc test_select_type_params { } {
+	global scontrol bin_bash bin_grep alpha_numeric_under
+
+	log_user 0
+	set params ""
+	spawn -noecho $bin_bash -c "exec $scontrol show config | $bin_grep SelectTypeParameters"
+	expect {
+		-re "SelectTypeParameters *= *($alpha_numeric_under)" {
+			set params $expect_out(1,string)
+			exp_continue
+		}
+		eof {
+			wait
+		}
+	}
+	log_user 1
+	
+	return $params
+}
 
 ################################################################
 #
diff --git a/testsuite/expect/test4.12 b/testsuite/expect/test4.12
index c08821cd2c8..91b6f07eb61 100755
--- a/testsuite/expect/test4.12
+++ b/testsuite/expect/test4.12
@@ -276,21 +276,26 @@ proc allocate_and_quit { node proc_cnt total_procs } {
 	return $rc
 }
 
+############################################################################
 # test starts here 
+############################################################################
 
 print_header $test_id
 
-#find me an idle node
+# find me an idle node
 log_user 0
 spawn $scontrol show node
 expect {
-	-re "NodeName=($alpha_numeric_under) State=IDLE Procs=($number)(k?)"  {
+	-re "NodeName=($alpha_numeric_under) State=IDLE Procs=($number)(k?).* Sockets=($number) CoresPerSocket=($number) ThreadsPerCore=($number)"  {
 		if {!$inode_found} {
 			set inode_name $expect_out(1,string) 
 			set inode_procs $expect_out(2,string)
 			if {[string compare $expect_out(3,string) ""]} {
 				set inode_procs [expr $inode_procs * 1024]
 			}
+			set inode_sockets $expect_out(4,string)
+			set inode_cores_per_socket $expect_out(5,string)
+			set inode_threads_per_core $expect_out(6,string)
 			set inode_found 1
 		}
 		exp_continue
@@ -356,17 +361,34 @@ if {![string compare $select_type "bluegene"]} {
 	}	
 	set node_scaling [get_bluegene_procs_per_cnode]
 	set smallest [expr $smallest * $node_scaling]
-} elseif {![string compare $select_type "cons_res"]} {
-#	SelectTypeParameter can be configured to allocated whole nodes,
-#	sockets, or cores (not threads) and the configuration can very by
-#	partition. so the smallest allocable unit isn't so simple to set here
-#	set smallest 1
+} elseif {![string compare $select_type "linear"]} {
 	set smallest $inode_procs
 } else {
-	set smallest $inode_procs
+#
+# Ignore for now, but if the partition's "Shared=Exclusive" then allocate
+# whole nodes to the jobs in that partition, set smallest $inode_procs
+#
+	set select_params [test_select_type_params]
+	if {![string compare $select_params "CR_CPU"]} {
+		set smallest $inode_threads_per_core
+	} elseif {![string compare $select_params "CR_CPU_MEMORY"]} {
+		set smallest $inode_threads_per_core
+	} elseif {![string compare $select_params "NONE"]} {
+		set smallest $inode_threads_per_core
+	} elseif {![string compare $select_params "CR_CORE"]} {
+		set smallest $inode_threads_per_core
+	} elseif {![string compare $select_params "CR_CORE_MEMORY"]} {
+		set smallest $inode_threads_per_core
+	} elseif {![string compare $select_params "CR_SOCKET"]} {
+		set smallest [expr $inode_cores_per_socket *$inode_threads_per_core]
+	} elseif {![string compare $select_params "CR_SOCKET_MEMORY"]} {
+		set smallest [expr $inode_cores_per_socket *$inode_threads_per_core]
+	} else {
+		send_user "\nWARNING: failed to parse SelectTypeParameters\n"
+		set smallest $inode_procs
+	}
 }
 
-
 set exit_code [allocate_and_quit $inode_name $smallest $inode_procs]
 if {!$exit_code && $smallest != $inode_procs} {
 		set exit_code [allocate_and_quit $inode_name $inode_procs $inode_procs]
-- 
GitLab