1#!/usr/bin/env expect
2############################################################################
3# Purpose: Test of Slurm functionality
4#          Test of --nice and --job-name options.
5############################################################################
6# Copyright (C) 2002-2006 The Regents of the University of California.
7# Produced at Lawrence Livermore National Laboratory (cf, DISCLAIMER).
8# Written by Morris Jette <jette1@llnl.gov>
9# CODE-OCEC-09-009. All rights reserved.
10#
11# This file is part of Slurm, a resource management program.
12# For details, see <https://slurm.schedmd.com/>.
13# Please also read the included file: DISCLAIMER.
14#
15# Slurm is free software; you can redistribute it and/or modify it under
16# the terms of the GNU General Public License as published by the Free
17# Software Foundation; either version 2 of the License, or (at your option)
18# any later version.
19#
20# Slurm is distributed in the hope that it will be useful, but WITHOUT ANY
21# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
22# FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
23# details.
24#
25# You should have received a copy of the GNU General Public License along
26# with Slurm; if not, write to the Free Software Foundation, Inc.,
27# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301  USA.
28############################################################################
29source ./globals
30
31set exit_code   0
32set job_id      0
33set job_name    "jobname$test_id"
34set name_read   ""
35
36if {[get_config_param "PriorityType"] eq "priority/multifactor"} {
37	skip "Not compatible with priority/multifactor"
38}
39
40#
41# Test setting job's name and get priority
42#
43set priority1  0
44set matches    0
45set timeout $max_job_delay
46set salloc_pid [spawn $salloc -t1 --job-name=$job_name $bin_bash]
47expect {
48	-re "Granted job allocation ($number)" {
49		set job_id $expect_out(1,string)
50		send "$scontrol show job $job_id\r"
51		exp_continue
52	}
53	-re "Name=$job_name" {
54		set matches 1
55		exp_continue
56	}
57	-re "Priority=($number)" {
58		set priority1 $expect_out(1,string)
59		send "exit\r"
60		exp_continue
61	}
62	timeout {
63		log_error "salloc not responding"
64		cancel_job $job_id
65		slow_kill [expr 0 - $salloc_pid]
66		set exit_code 1
67	}
68	eof {
69		wait
70	}
71}
72if {$job_id == 0} {
73	log_error "salloc failed to initiate job"
74	set exit_code 1
75}
76if {$matches == 0} {
77	log_error "Failed to set job name"
78	set exit_code 1
79}
80
81#
82# Test setting job's name and get priority
83#
84set job_id     0
85set priority2  0
86set salloc_pid [spawn $salloc -t1 --nice=1000 $bin_bash]
87expect {
88	-re "Granted job allocation ($number)" {
89		set job_id $expect_out(1,string)
90		send "$scontrol show job $job_id\r"
91		exp_continue
92	}
93	-re "Priority=($number)" {
94		set priority2 $expect_out(1,string)
95		send "exit\r"
96		exp_continue
97        }
98	timeout {
99		log_error "salloc not responding"
100		cancel_job $job_id
101		slow_kill [expr 0 - $salloc_pid]
102		set exit_code 1
103		exp_continue
104	}
105	eof {
106		wait
107	}
108}
109set delta_prio [expr $priority1 - $priority2]
110if {$delta_prio < 950} {
111	fail "Failed to process nice option"
112}
113
114if {$exit_code != 0} {
115	fail "Test failed due to previous errors (\$exit_code = $exit_code)"
116}
117