1#!/usr/bin/env expect
2############################################################################
3# Purpose: Test of TotalView termination logic for srun.
4#
5# Note:    This script generates and then deletes files in the working directory
6#          named test7.5.prog
7############################################################################
8# Copyright (C) 2002-2007 The Regents of the University of California.
9# Copyright (C) 2008-2009 Lawrence Livermore National Security.
10# Produced at Lawrence Livermore National Laboratory (cf, DISCLAIMER).
11# Written by Morris Jette <jette1@llnl.gov>
12# CODE-OCEC-09-009. All rights reserved.
13#
14# This file is part of Slurm, a resource management program.
15# For details, see <https://slurm.schedmd.com/>.
16# Please also read the included file: DISCLAIMER.
17#
18# Slurm is free software; you can redistribute it and/or modify it under
19# the terms of the GNU General Public License as published by the Free
20# Software Foundation; either version 2 of the License, or (at your option)
21# any later version.
22#
23# Slurm is distributed in the hope that it will be useful, but WITHOUT ANY
24# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
25# FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
26# details.
27#
28# You should have received a copy of the GNU General Public License along
29# with Slurm; if not, write to the Free Software Foundation, Inc.,
30# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301  USA.
31############################################################################
32source ./globals
33
34set exit_code   0
35set file_prog   "test$test_id.prog"
36set matches     0
37set fini_cnt    0
38set usr1cnt     0
39set usr2cnt     0
40
41proc cleanup {} {
42	global bin_rm file_prog
43
44	exec $bin_rm -f $file_prog
45}
46
47#
48# Delete left-over program and rebuild it
49#
50exec $bin_rm -f $file_prog
51exec $bin_cc -O ${file_prog}.c -o $file_prog
52exec $bin_chmod 700 $file_prog
53
54#
55# Get uid
56#
57set uid [get_my_uid]
58
59
60#
61# Spawn initial program via srun and terminate with SIGTERM
62# Note: For systems supporting proper pthreads, instead use
63#       exec $bin_kill -TERM $srun_pid, otherwise we need pkill
64#       and can get multiple signals delivered
65# Note: We send the signal right after task startup rather than
66#	interspersed with messages because some versions of
67#	Expect have difficulties handling unbuffered srun output
68#
69set timeout $max_job_delay
70set srun_pid [spawn $srun -N1 -t1 --debugger-test --unbuffered ./$file_prog]
71expect {
72	-re "task:.*, host:.*, pid:.*, executable:.*" {
73		incr matches
74		# sleep to make sure the process is actually running
75		exec $bin_sleep 1
76		exec $bin_kill -TERM $srun_pid
77		log_debug "Sent SIGTERM"
78		exp_continue
79	}
80	-re "Received signal" {
81		log_error "Unexpected signal processed"
82		set exit_code 1
83		log_debug "Sent SIGTERM"
84		exp_continue
85	}
86	-re "WAITING" {
87		log_error "Job not stopped in debugger mode"
88		set exit_code 1
89		log_debug "Sent SIGTERM"
90		exp_continue
91	}
92	-re "TIME LIMIT" {
93		log_error "Job not terminated with SIGINT"
94		set exit_code 1
95		exp_continue
96	}
97	-re "error.*not running" {
98		log_debug "Don't worry about the error.."
99		exp_continue
100	}
101	-re "FINI" {
102		incr fini_cnt
103		exp_continue
104	}
105	timeout {
106		slow_kill $srun_pid
107		fail "srun not responding"
108	}
109	eof {
110		log_debug "EOF"
111		wait
112	}
113}
114if {$matches != 1} {
115	log_error "srun failed to initialize properly ($matches != 1)"
116	set exit_code 1
117}
118if {$fini_cnt > 0} {
119	log_error "srun failed to terminate properly ($fini_cnt > 0)"
120	set exit_code 1
121}
122
123if {$exit_code == 0} {
124	log_debug "So far, so good"
125} else {
126	fail "Test failed due to previous errors (\$exit_code = $exit_code)"
127}
128
129#
130# Spawn initial program via srun and terminate with SIGINT * 3
131#
132set matches  0
133set fini_cnt 0
134set srun_pid [spawn $srun -N1 -t1 --debugger-test --unbuffered ./$file_prog]
135expect {
136	-re "task:.*, host:.*, pid:.*, executable:.*" {
137		incr matches
138		# sleep to make sure the process is actually running
139		exec $bin_sleep 1
140		exec $bin_kill -INT $srun_pid
141		exec $bin_kill -INT $srun_pid
142		log_debug "Sent SIGINT * 2"
143		exp_continue
144	}
145	-re "Received signal" {
146		log_error "Unexpected signal processed"
147		set exit_code 1
148		log_debug "Sent SIGTERM"
149		exp_continue
150	}
151	-re "WAITING" {
152		log_error "Job not stopped in debugger mode"
153		set exit_code 1
154		log_debug "Sent SIGTERM"
155		exp_continue
156	}
157	-re "TIME LIMIT" {
158		log_error "Job not terminated with SIGINT"
159		set exit_code 1
160		exp_continue
161	}
162	-re "error.*not running" {
163		log_debug "Don't worry about the error.."
164		exp_continue
165	}
166	-re "FINI" {
167		incr fini_cnt
168		exp_continue
169	}
170	timeout {
171		slow_kill $srun_pid
172		fail "srun not responding"
173	}
174	eof {
175		log_debug "EOF"
176		wait
177	}
178}
179if {$matches != 1} {
180	fail "srun failed to initialize properly ($matches != 1)"
181}
182if {$fini_cnt > 0} {
183	fail "srun failed to terminate properly ($fini_cnt > 0)"
184}
185
186#
187# Post-processing
188#
189if {$exit_code != 0} {
190	fail "Test failed due to previous errors (\$exit_code = $exit_code)"
191}
192