From be67f3061e3ca86b41afd17be872b65f54d449ac Mon Sep 17 00:00:00 2001
From: Moe Jette <jette1@llnl.gov>
Date: Thu, 10 Aug 2006 23:01:51 +0000
Subject: [PATCH] Tweak tests, mostly adding logic to handle slurm job_id.

---
 testsuite/expect/test18.10        |   8 +-
 testsuite/expect/test18.11        |  16 ++--
 testsuite/expect/test18.13        |   2 +-
 testsuite/expect/test18.15        |   2 +-
 testsuite/expect/test18.16        |   2 +-
 testsuite/expect/test18.17        |   2 +-
 testsuite/expect/test18.19        | 153 ++++++++++++++++++++++++++++++
 testsuite/expect/test18.19.prog.c |  81 ++++++++++++++++
 8 files changed, 252 insertions(+), 14 deletions(-)
 create mode 100755 testsuite/expect/test18.19
 create mode 100644 testsuite/expect/test18.19.prog.c

diff --git a/testsuite/expect/test18.10 b/testsuite/expect/test18.10
index d3529915f6b..0e646b4627e 100755
--- a/testsuite/expect/test18.10
+++ b/testsuite/expect/test18.10
@@ -42,7 +42,7 @@ print_header $test_id
 # Spawn a program via slaunch with stdout forwarding disabled
 #
 set timeout $max_job_delay
-spawn $salloc -t1 -v $slaunch --local-output=none $bin_id
+spawn $salloc -t1 $slaunch --local-output=none $bin_id
 expect {
 	-re "Granted job allocation ($number)" {
 		set job_id $expect_out(1,string)
@@ -80,8 +80,12 @@ set job_id    0
 set matches   0
 spawn $salloc -t1 -v $slaunch --local-error=none -t1 $bin_sleep aaa
 expect {
+	-re "Pending job allocation ($number)" {
+		set job_id $expect_out(1,string)
+		exp_continue
+	}
 	-re "invalid" {
-		send_user "\nFAILURE: srun improperly forwarded stderr\n"
+		send_user "\nFAILURE: slaunch improperly forwarded stderr\n"
 		set exit_code 1
 		exp_continue
 	}
diff --git a/testsuite/expect/test18.11 b/testsuite/expect/test18.11
index f77a01774f3..e9f2741af84 100755
--- a/testsuite/expect/test18.11
+++ b/testsuite/expect/test18.11
@@ -1,8 +1,8 @@
 #!/usr/bin/expect
 ############################################################################
 # Purpose: Test of SLURM functionality
-#          Test slaunch stdout/err file name formatting (--local-output and 
-#          --local-error options with %j, %J, %n, %s and %t specifications).
+#          Test slaunch stdout/err file name formatting (--remote-output and 
+#          --remote-error options with %j, %J, %n, %s and %t specifications).
 #
 # Output:  "TEST: #.#" followed by "SUCCESS" if test was successful, OR
 #          "FAILURE: ..." otherwise with an explanation of the failure, OR
@@ -54,7 +54,7 @@ for {set task_id 0} {$task_id < $task_cnt} {incr task_id} {
 	exec $bin_rm -f $file_out_t_glob
 }
 set timeout $max_job_delay
-spawn $salloc -N1 -t1 -v $slaunch --local-output=$file_out_t -n$task_cnt --overcommit $bin_id
+spawn $salloc -N1 -t1 $slaunch --remote-output=$file_out_t -n$task_cnt --overcommit $bin_id
 expect {
 	-re "Granted job allocation ($number)" {
 		set job_id $expect_out(1,string)
@@ -100,7 +100,7 @@ if {$file_cnt != $task_cnt} {
 #
 set job_id    0
 set matches   0
-spawn $salloc -N1 -t1 -v $slaunch --local-output=/dev/null --local-error=$file_err_j -n$task_cnt --overcommit $bin_sleep aaa
+spawn $salloc -N1 -t1 $slaunch --remote-output=/dev/null --remote-error=$file_err_j -n$task_cnt --overcommit $bin_sleep aaa
 expect {
 	-re "Granted job allocation ($number)" {
 		set job_id $expect_out(1,string)
@@ -146,7 +146,7 @@ if {[wait_for_file $file_err_j_glob] == 0} {
 # file name and confirm it is created
 #
 set job_id   0
-spawn $salloc -N1 -t1 -v $slaunch --local-output=$file_out_J $bin_hostname
+spawn $salloc -N1 -t1 $slaunch --remote-output=$file_out_J $bin_hostname
 expect {
 	-re "Granted job allocation ($number)" {
 		set job_id $expect_out(1,string)
@@ -187,7 +187,7 @@ set file_out_n_glob  "test$test_id.n.$node_id.output"
 exec $bin_rm -f $file_out_n_glob
 
 set job_id   0
-spawn $salloc -N1 -t1 -v $slaunch --local-output=$file_out_n -n2 --overcommit $bin_hostname
+spawn $salloc -N1 -t1 $slaunch --remote-output=$file_out_n -n2 --overcommit $bin_hostname
 expect {
 	-re "Granted job allocation ($number)" {
 		set job_id $expect_out(1,string)
@@ -236,8 +236,8 @@ if {$file_cnt != 1} {
 # file name and confirm it is created. Use two step batch job.
 #
 make_bash_script $file_in "
-  $slaunch -n4 --overcommit --local-output=$file_out_s $bin_hostname
-  $slaunch -n4 --overcommit --local-output=$file_out_s $bin_hostname
+  $slaunch -n4 --overcommit --remote-output=$file_out_s $bin_hostname
+  $slaunch -n4 --overcommit --remote-output=$file_out_s $bin_hostname
 "
 
 for {set step_id 0} {$step_id < 4} {incr step_id} {
diff --git a/testsuite/expect/test18.13 b/testsuite/expect/test18.13
index 1c3172bd447..79413ec2403 100755
--- a/testsuite/expect/test18.13
+++ b/testsuite/expect/test18.13
@@ -54,7 +54,7 @@ if { [test_bluegene] } {
 }
 
 set job_id 0
-spawn $salloc -v -t1 -N$node_cnt $slaunch -l --threads=1 $bin_hostname  
+spawn $salloc -t1 -N$node_cnt $slaunch -l --threads=1 $bin_hostname  
 expect {
 	-re "Granted job allocation ($number)" {
 		set job_id $expect_out(1,string)
diff --git a/testsuite/expect/test18.15 b/testsuite/expect/test18.15
index 8ed5b670d47..85bec1c142d 100755
--- a/testsuite/expect/test18.15
+++ b/testsuite/expect/test18.15
@@ -48,7 +48,7 @@ print_header $test_id
 # Spawn a job via sbatch to print environment variables
 #
 set env($test_env_name) $test_env_val
-spawn $salloc -N1 -t1 -v $slaunch $bin_env
+spawn $salloc -N1 -t1 $slaunch $bin_env
 expect {
 	-re "Granted job allocation ($number)" {
 		set job_id $expect_out(1,string)
diff --git a/testsuite/expect/test18.16 b/testsuite/expect/test18.16
index 60c747ee88a..8eb3a1c4539 100755
--- a/testsuite/expect/test18.16
+++ b/testsuite/expect/test18.16
@@ -125,7 +125,7 @@ make_bash_script $file_in "
   ./$file_prog_get
 "
 
-spawn $salloc -N1 -t1 -v $slaunch ./$file_in
+spawn $salloc -N1 -t1 $slaunch ./$file_in
 expect {
 	-re "Granted job allocation ($number)" {
 		set job_id $expect_out(1,string)
diff --git a/testsuite/expect/test18.17 b/testsuite/expect/test18.17
index 91844f0b17f..c13345fd141 100755
--- a/testsuite/expect/test18.17
+++ b/testsuite/expect/test18.17
@@ -56,7 +56,7 @@ make_bash_script $test_script "
 set job_id 0
 set sum    0
 set timeout $max_job_delay
-spawn $salloc -N1 -t1 -v $slaunch -n2 --overcommit $exit_script
+spawn $salloc -N1 -t1 $slaunch -n2 --overcommit $exit_script
 expect {
 	-re "Granted job allocation ($number)" {
 		set job_id $expect_out(1,string)
diff --git a/testsuite/expect/test18.19 b/testsuite/expect/test18.19
new file mode 100755
index 00000000000..2413fc0a27d
--- /dev/null
+++ b/testsuite/expect/test18.19
@@ -0,0 +1,153 @@
+#!/usr/bin/expect
+############################################################################
+# Purpose: Test of SLURM functionality
+#          Test of slaunch signal forwarding (actually using scancel, for
+#          now anyway)
+#
+# 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.
+#
+# Note:    This script generates and then deletes files in the working directory
+#          named test18.19.prog
+############################################################################
+# Copyright (C) 2002-2006 The Regents of the University of California.
+# Produced at Lawrence Livermore National Laboratory (cf, DISCLAIMER).
+# Written by Morris Jette <jette1@llnl.gov>
+# UCRL-CODE-217948.
+# 
+# This file is part of SLURM, a resource management program.
+# For details, see <http://www.llnl.gov/linux/slurm/>.
+#  
+# 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.,
+# 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA.
+############################################################################
+source ./globals
+
+set test_id     "18.19"
+set exit_code   0
+set file_prog   "test$test_id.prog"
+set matches     0
+set usr1cnt     0
+set usr2cnt     0
+
+print_header $test_id
+
+if { [test_xcpu] } {
+	send_user "\nWARNING: This test is incompatable with XCPU systems\n"
+	exit $exit_code
+}
+
+#
+# Delete left-over program and rebuild it
+#
+exec $bin_rm -f $file_prog
+exec $bin_make -f /dev/null $file_prog
+exec $bin_chmod 700 $file_prog
+
+#
+# Get uid
+#
+spawn $bin_id -u
+expect {
+	-re "($number)" {
+		set uid $expect_out(1,string)
+	}
+	eof {
+		wait
+	}
+}
+
+#
+# Spawn initial program via salloc/slaunch
+# Note: For systems supporting proper pthreads, instead use
+#       exec $bin_kill -USR1 $salloc_pid, otherwise we need pkill 
+#       and can get multiple signals delivered
+# Note: We send the signals right after task startup rather than
+#	interspersed with messages because some versions of 
+#	Expect have difficulties handling unbuffered slaunch output
+#
+set timeout $max_job_delay
+set job_id       0
+set slaunch_pid  0
+spawn $salloc -N1 -t1 $slaunch -v --unbuffered $file_prog
+expect {
+	-re "Granted job allocation ($number)" {
+		set job_id $expect_out(1,string)
+		exp_continue
+	}
+	-re "slaunch pid ($number)" {
+		set slaunch_pid $expect_out(1,string)
+		exp_continue
+	}
+	-re "WAITING" {
+		incr matches
+                if {$slaunch_pid != 0} {
+#			exec $bin_kill -USR1 $slaunch_pid
+#			exec $bin_kill -USR2 $slaunch_pid
+			exec $scancel --signal=USR1 $job_id.0
+			exec $scancel --signal=USR2 $job_id.0
+			exp_continue
+		}
+	}
+	-re "SIGUSR1" {
+		set usr1cnt [expr $usr1cnt + 1]
+		exp_continue
+	}
+	-re "SIGUSR2" {
+		set usr2cnt [expr $usr2cnt + 1]
+		if {$job_id != 0} {
+			cancel_job $job_id
+		}
+	}
+	-re "error.*not running" {
+		send_user "\nDon't worry about the error...\n"
+		exp_continue
+	}
+	timeout {
+		send_user "\nFAILURE: salloc not responding\n"
+		if {$job_id == 0} {
+			kill_salloc
+		} else {
+			cancel_job $job_id
+		}
+		set exit_code 1
+		exp_continue
+	}
+	eof {
+		send_user "\nEOF\n"
+		wait
+	}
+}
+if {$matches != 1} {
+	send_user "\nFAILURE: salloc failed to initialize properly\n"
+	set exit_code 1
+}
+if {$usr1cnt != 1} {
+	send_user "\nFAILURE: $file_prog received $usr1cnt SIGUSR1 (not 1)\n"
+	set exit_code 1
+}
+if {$usr2cnt != 1} {
+	send_user "\nFAILURE: $file_prog received $usr2cnt SIGUSR2 (not 1)\n"
+	set exit_code 1
+}
+
+#
+# Post-processing
+#
+if {$exit_code == 0} {
+	exec $bin_rm -f $file_prog
+	send_user "\nSUCCESS\n"
+}
+exit $exit_code
diff --git a/testsuite/expect/test18.19.prog.c b/testsuite/expect/test18.19.prog.c
new file mode 100644
index 00000000000..b22ef879328
--- /dev/null
+++ b/testsuite/expect/test18.19.prog.c
@@ -0,0 +1,81 @@
+/*****************************************************************************\
+ *  prog18.19.prog.c - Simple signal catching test program for SLURM regression 
+ *  test18.19. Report caught signals. Exit after SIGUSR1 and SIGUSR2 received.
+ *****************************************************************************
+ *  Copyright (C) 2002 The Regents of the University of California.
+ *  Produced at Lawrence Livermore National Laboratory (cf, DISCLAIMER).
+ *  Written by Morris Jette <jette1@llnl.gov>
+ *  UCRL-CODE-217948.
+ *  
+ *  This file is part of SLURM, a resource management program.
+ *  For details, see <http://www.llnl.gov/linux/slurm/>.
+ *  
+ *  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.,
+ *  59 Temple Place, Suite 330, Boston, MA  02111-1307  USA.
+\*****************************************************************************/
+#include <signal.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <errno.h>
+#include <sys/types.h>
+#include <unistd.h>
+
+
+int sigusr1_cnt = 0, sigusr2_cnt = 0;
+
+void sig_handler(int sig)
+{
+	switch (sig)
+	{
+		case SIGUSR1:
+			printf("Received SIGUSR1\n");
+			fflush(stdout);
+			sigusr1_cnt++;
+			break;
+		case SIGUSR2:
+			printf("Received SIGUSR2\n");
+			fflush(stdout);
+			sigusr2_cnt++;
+			break;
+		default:
+			printf("Received signal %d\n", sig);
+			fflush(stdout);
+	}
+}
+
+main (int argc, char **argv) 
+{
+	struct sigaction act;
+
+	act.sa_handler = sig_handler;
+	sigemptyset(&act.sa_mask);
+	act.sa_flags = 0;
+	if (sigaction(SIGUSR1, &act, NULL) < 0) {
+		perror("setting SIGUSR1 handler");
+		exit(2);
+	}
+	if (sigaction(SIGUSR2, &act, NULL) < 0) {
+		perror("setting SIGUSR2 handler");
+		exit(2);
+	}
+
+	printf("WAITING\n");
+	fflush(stdout);
+
+	while (!sigusr1_cnt || !sigusr2_cnt) {
+		sleep(1);
+	}
+
+	exit(0);
+}
-- 
GitLab