~ubuntu-branches/ubuntu/precise/slurm-llnl/precise

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
#!/usr/bin/expect
############################################################################
# Purpose: Test of SLURM functionality
#          Test of sinfo cpu total and allocated
#
# 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) 2009 Lawrence Livermore National Security.
# Produced at Lawrence Livermore National Laboratory (cf, DISCLAIMER).
# Written by Joseph Donaghy <donaghy1@llnl.gov>
# CODE-OCEC-09-009. All rights reserved.
#
# This file is part of SLURM, a resource management program.
# For details, see <https://computing.llnl.gov/linux/slurm/>.
# Please also read the included file: DISCLAIMER.
#
# 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     "4.12"
set file_in     "test$test_id.in"
set exit_code   0
set pnumsc      0
set pnumsi      0
set aprocsc     0
set aprocsi     0
set inode_found 0
set inode_name  ""
set smallest    1
set layout "static"
set select_type ""
set node_scaling 0

proc scontrol_test { node proc_cnt } {
	global scontrol number prompt
	upvar spawn_id spawn_id

	set found 0
	set rc 0

	send "$scontrol show node $node\r"
	expect {
		-re "CPUAlloc=($number)" {
			set num_alloc $expect_out(1,string)
			set found 1
			if {$proc_cnt != $num_alloc} {
				send_user "\nFAILURE: requested $proc_cnt but got $num_alloc instead\n"
				set rc 1
			}
			exp_continue
		}
		-re $prompt {
		}
		timeout {
			send_user "\nFAILURE: scontrol not responding\n"
			slow_kill $mypid
			return 1
		}
		eof {
			wait
		}
	}

	if {!$found} {
		send_user "\nFAILURE: didn't get expected output from scontrol\n"
		set rc 1
	}

	return $rc
}

proc sinfo_test_1 { node proc_cnt total_procs idle_cpus } {
	global sinfo number prompt
	upvar spawn_id spawn_id

	set found 0
	set rc 0

	send "$sinfo -o \"%C %A %N\" -h -n $node\r"
	# make sure we get by the sinfo command so we don't
	# think the %'s are a prompt
	expect {
		"%C %A %N" {
		}
	}
	expect {
		-re "($number)(K?).($number)(K?).($number)(K?).($number)(K?) ($number)(K?).($number)(K?) $node" {
			set found 1
			set num_alloc $expect_out(1,string)
			if {[string compare $expect_out(2,string) ""]} {
				set num_alloc [expr $num_alloc * 1024]
			}
			set num_idle $expect_out(3,string)
			if {[string compare $expect_out(4,string) ""]} {
				set num_idle [expr $num_idle * 1024]
			}
			set num_other $expect_out(5,string)
			if {[string compare $expect_out(6,string) ""]} {
				set num_other [expr $num_other * 1024]
			}
			set num_total $expect_out(7,string)
			if {[string compare $expect_out(8,string) ""]} {
				set num_total [expr $num_total * 1024]
			}

			if { $num_alloc != $proc_cnt } {
				send_user "\nFAILURE: sinfo 1 allocated cpus wrong, got $num_alloc but needed $proc_cnt\n"
				set rc 1
			} elseif { $num_idle != $idle_cpus } {
				send_user "\nFAILURE: sinfo 1 idle cpus wrong, got $num_idle but needed $idle_cpus\n"
				set rc 1
			} elseif { $num_total != $total_procs } {
				send_user "\nFAILURE: sinfo 1 total cpus wrong, got $num_total but needed $total_procs\n"
				set rc 1
			}
			exp_continue
		}
		-re $prompt {
		}
		timeout {
			send_user "\nFAILURE: sinfo not responding\n"
			slow_kill $mypid
			return 1
		}
		eof {
			wait
		}
	}

	if {!$found} {
		send_user "\nFAILURE: didn't get expected output from sinfo\n"
		set rc 1
	}

	return $rc
}

proc sinfo_test_2 { node proc_cnt total_procs } {
	global sinfo number prompt node_scaling
	upvar spawn_id spawn_id

	set rc 0
	set num_alloc 0
	set num_idle 0
	set alloc_nodes 1
	set total_nodes 1

	if {$node_scaling} {
		set alloc_nodes [expr $proc_cnt / $node_scaling]
		set total_nodes [expr $total_procs / $node_scaling]
	}
	set idle_nodes [expr $total_nodes - $alloc_nodes]

	send "$sinfo -o \"%t %D %N\" -h -n $node\r"
	# make sure we get by the sinfo command so we don't
	# think the %'s are a prompt
	expect {
		"%t %D %N" {
		}
	}
	expect {
		-re "alloc ($number)(K?) $node" {
			set num_alloc $expect_out(1,string)
			if {[string compare $expect_out(2,string) ""]} {
				set num_alloc [expr $inode_procs * 1024]
			}
			exp_continue
		}
		-re "idle ($number)(K?) $node" {
			set num_idle $expect_out(1,string)
			if {[string compare $expect_out(2,string) ""]} {
				set num_idle [expr $num_idle * 1024]
			}
			exp_continue
		}
		-re $prompt {
		}
		timeout {
			send_user "\nFAILURE: sinfo not responding\n"
			slow_kill $mypid
			return 1
		}
		eof {
			wait
		}
	}

	if { $num_alloc != $alloc_nodes } {
		send_user "\nFAILURE: sinfo 2 allocated nodes wrong, got $num_alloc but needed $alloc_nodes\n"
		set rc 1
	} elseif { $num_idle != $idle_nodes } {
		send_user "\nFAILURE: sinfo 2 idle nodes wrong, got $num_idle but needed $idle_nodes\n"
		set rc 1
	}

	return $rc
}

# allocate a set of nodes (node_cnt) and the quit right after
proc allocate_and_quit { node proc_cnt total_procs } {
	global salloc scontrol sinfo number alpha_numeric_under
	global prompt select_type procs_per_node

	set job_id 0
	set num_alloc 0
	set block ""
	set rc 0
	set timeout 60
	set idle_cpus [expr $total_procs - $proc_cnt]

	set mypid [spawn $salloc -w $node -N1 -n $proc_cnt bash]
	expect {
		-re "Granted job allocation ($number)" {
			set job_id $expect_out(1,string)
			exp_continue
		}

		-re $prompt {
			# test for scontrol to give me the correct cpu count
			if { [scontrol_test $node $proc_cnt] } {
				send "exit\r"
				return 1
			}


			# test for sinfo to give me the correct cpu count
			if { [sinfo_test_1 $node $proc_cnt $total_procs $idle_cpus] } {
				send "exit\r"
				return 1
			}
			# test for sinfo to give me the correct node count
			if { [sinfo_test_2 $node $proc_cnt $total_procs] } {
				send "exit\r"
				return 1
			}
			send "exit\r"
			exp_continue
		}

		-re "Unable to contact" {
			send_user "\nFAILURE: slurm appears to be down\n"
			exp_continue
		}
		timeout {
			send_user "\nFAILURE: salloc not responding\n"
			if {$job_id != 0} {
				cancel_job $job_id
			}
			slow_kill $mypid
			return 1
		}
		eof {
			wait
		}
	}

	return $rc
}

############################################################################
# test starts here
############################################################################

print_header $test_id

# find the default partition
set def_part [default_partition]

# find the nodes in the default partition
log_user 0
set def_hostlist ""
set part_exclusive 0
spawn $scontrol show part $def_part
expect {
	-re " Shared=EXCLUSIVE" {
		set part_exclusive 1
		exp_continue
	}
	-re " Nodes=($alpha_numeric_nodelist)"  {
		set def_hostlist $expect_out(1,string)
		exp_continue
	}
	-re " BasePartitions=($alpha_numeric_nodelist)" {
		set def_hostlist $expect_out(1,string)
		exp_continue
	}
	timeout {
		send_user "\nFAILURE: scontrol not responding\n"
		set exit_code 1
	}
	eof {
		wait
	}
}
set host_cnt 0
spawn $scontrol show hostnames $def_hostlist
expect {
	-re "($alpha_numeric_under)"  {
		set host_name($host_cnt) $expect_out(1,string)
		incr host_cnt
		exp_continue
	}
	timeout {
		send_user "\nFAILURE: scontrol not responding\n"
		set exit_code 1
	}
	eof {
		wait
	}
}
log_user 1
if {$host_cnt == 0} {
	send_user "\nFAILURE: could not find any nodes in default partition\n"
	exit 1
}

# find me an idle node in default partition
log_user 0
set inode_name ""
set inode_cores_per_socket 0
set inode_procs 0
set units ""
set inode_sockets 0
set inode_threads_per_core 0

set fd [open "|$scontrol --oneliner show node $def_hostlist"]
exp_internal 1
while {[gets $fd line] != -1} {
	if {[regexp {NodeName=(\w+).*CoresPerSocket=(\d+).*CPUTot=(\d+)(K?).*Sockets=(\d+) State=IDLE ThreadsPerCore=(\d+)} $line frag inode_name inode_cores_per_socket inode_procs units inode_sockets inode_threads_per_core] == 1} {
		break
	}
}
exp_internal 0
if {[string compare $units ""]} {
	set inode_procs [expr $inode_procs * 1024]
}
catch {close $fd}

log_user 1

if {!$inode_procs} {
	send_user "\nFAILURE: couldn't find an idle node in the default partition\n"
	exit 1
}

send_user "found idle node $inode_name with $inode_procs processors\n"

# figure out the select plugin we are using
set select_type [test_select_type]
if {![string compare $select_type "bluegene"]} {
	# figure out some things if a bluegene system
	set layout [get_bluegene_layout]
	if {$layout == 0} {
		send_user "\nFAILURE: No layout mode found for this system\n"
		exit 1
	}
	set psets [get_bluegene_psets]

	if {$psets == 0} {
		send_user "\nFAILURE: No psets are set on this system\n"
		exit 1
	}
	set type [get_bluegene_type]

	if {$type == 0} {
		send_user "\nFAILURE: No bluegene type found \n"
		exit 1
	}

	if {![string compare $type "P"]} {
		if {$psets >= 32} {
			set smallest 16
		} elseif {$psets >= 16} {
			set smallest 32
		} elseif {$psets >= 8} {
			set smallest 64
		} else {
			set smallest 128
		}
	} elseif {![string compare $type "L"]} {
		if {$psets >= 16} {
			set smallest 32
		} else {
			set smallest 128
		}
	} else {
		send_user "\nFAILURE: unknown bluegene system type '$type'\n";
		exit 1
	}
	set node_scaling [get_bluegene_procs_per_cnode]
	set smallest [expr $smallest * $node_scaling]
} elseif {![string compare $select_type "linear"]} {
	set smallest $inode_procs
} else {
	set select_params [test_select_type_params]
	if {$part_exclusive == 1} {
		set smallest $inode_procs
	} elseif {![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 '$select_params'\n"
		set smallest $inode_procs
	}
}

set exit_code [allocate_and_quit $inode_name $smallest $inode_procs]
if {!$exit_code && $smallest != $inode_procs} {
	# just to make sure we get a clean state we will sleep a bit
	sleep 1
	set exit_code [allocate_and_quit $inode_name $inode_procs $inode_procs]
}
if {$exit_code == 0} {
	send_user "\nSUCCESS\n"
} else {
	exit $exit_code
}