1#!/usr/bin/env expect
2############################################################################
3# Purpose: Test of Slurm functionality
4#          Test performance/timing of job submissions.
5############################################################################
6# Copyright (C) 2014 SchedMD LLC
7# Written by Morris Jette <jette@schedmd.com>
8#
9# This file is part of Slurm, a resource management program.
10# For details, see <https://slurm.schedmd.com/>.
11# Please also read the included file: DISCLAIMER.
12#
13# Slurm is free software; you can redistribute it and/or modify it under
14# the terms of the GNU General Public License as published by the Free
15# Software Foundation; either version 2 of the License, or (at your option)
16# any later version.
17#
18# Slurm is distributed in the hope that it will be useful, but WITHOUT ANY
19# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
20# FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
21# details.
22#
23# You should have received a copy of the GNU General Public License along
24# with Slurm; if not, write to the Free Software Foundation, Inc.,
25# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301  USA.
26############################################################################
27source ./globals
28
29set file_in    "test$test_id\.in"
30set exit_code  0
31set job_cnt    100
32set target     200
33
34proc cleanup {} {
35	global bin_rm file_in
36
37	exec $bin_rm -f $file_in
38}
39
40if {[get_config_param "SwitchType"] eq "switch/cray"} {
41	set target 65
42}
43
44make_bash_script $file_in "
45inx=0
46while \[ \$inx -lt $job_cnt \]
47do
48	$sbatch --begin=midnight --job-name=$file_in --wrap date &
49	inx=\$((inx+1))
50done
51wait
52"
53
54set match 0
55set time_used  100000
56set timeout [expr $max_job_delay * 10]
57spawn $bin_bash -c "time -p ./$file_in"
58expect {
59	-re "Submitted batch job ($number)" {
60		incr match
61		exp_continue
62	}
63	-re "real *($number)\\.($digit)($digit)" {
64		set secs       $expect_out(1,string)
65		set tenths     $expect_out(2,string)
66		set hundredths $expect_out(3,string)
67		set time_used [expr $secs * 1000 + $tenths * 100 + $hundredths * 10]
68		exp_continue
69	}
70	-re "real *($number)\\.($digit)" {
71		set secs       $expect_out(1,string)
72		set tenths     $expect_out(2,string)
73		set time_used [expr $secs * 1000 + $tenths * 100]
74		exp_continue
75	}
76	-re "real *($number)" {
77		set secs       $expect_out(1,string)
78		set time_used [expr $secs * 1000]
79		exp_continue
80	}
81	timeout {
82		fail "sbatch is not responding"
83	}
84	eof {
85		wait
86	}
87}
88if {$match != $job_cnt} {
89	log_error "Job count mismatch ($match != $job_cnt)"
90	set exit_code 1
91}
92
93spawn $scancel --name=$file_in
94expect {
95	timeout {
96		fail "scancel is not responding"
97	}
98	eof {
99		wait
100	}
101}
102
103# Prevent zero divide
104if {$time_used == 0} {
105	set time_used 1
106}
107set rate [ expr ($job_cnt * 1000) / $time_used ]
108log_debug "Job submit rate $rate jobs per second ($job_cnt jobs in $time_used msec)"
109if {$rate < $target} {
110	fail "Job submit rate of $rate below target of $target. This may be due to use of NFS rather than local storage for logs or state information"
111}
112
113if {$exit_code != 0} {
114	fail "Test failed due to previous errors (\$exit_code = $exit_code)"
115}
116