From 99f17d3d83558604c66f147d5b5f2c9b51d01d56 Mon Sep 17 00:00:00 2001
From: Moe Jette <jette1@llnl.gov>
Date: Wed, 13 Dec 2006 17:11:10 +0000
Subject: [PATCH] Add test to check for open files in spawned tasks.

---
 testsuite/expect/Makefile.am    |   2 +
 testsuite/expect/Makefile.in    |   2 +
 testsuite/expect/README         |   2 +
 testsuite/expect/test7.9        | 119 ++++++++++++++++++++++++++++++++
 testsuite/expect/test7.9.prog.c |  43 ++++++++++++
 5 files changed, 168 insertions(+)
 create mode 100755 testsuite/expect/test7.9
 create mode 100644 testsuite/expect/test7.9.prog.c

diff --git a/testsuite/expect/Makefile.am b/testsuite/expect/Makefile.am
index 67d720d440d..d1c6fa6757d 100644
--- a/testsuite/expect/Makefile.am
+++ b/testsuite/expect/Makefile.am
@@ -155,6 +155,8 @@ EXTRA_DIST = \
 	test7.7.prog.c			\
 	test7.8				\
 	test7.8.prog.c			\
+	test7.9				\
+	test7.9.prog.c			\
 	test8.1				\
 	test8.2				\
 	test8.3				\
diff --git a/testsuite/expect/Makefile.in b/testsuite/expect/Makefile.in
index 97fd58f882a..5816e2dac8a 100644
--- a/testsuite/expect/Makefile.in
+++ b/testsuite/expect/Makefile.in
@@ -399,6 +399,8 @@ EXTRA_DIST = \
 	test7.7.prog.c			\
 	test7.8				\
 	test7.8.prog.c			\
+	test7.9				\
+	test7.9.prog.c			\
 	test8.1				\
 	test8.2				\
 	test8.3				\
diff --git a/testsuite/expect/README b/testsuite/expect/README
index e5e24f251d2..d736a1b2909 100644
--- a/testsuite/expect/README
+++ b/testsuite/expect/README
@@ -262,6 +262,8 @@ test7.7    Test of sched/wiki2 plugin. This is intended to execute in the
 test7.8    Test of sched/wiki plugin. This is intended to execute in the
            place of Maui and emulate its actions to confirm proper
            operation of the plugin.
+test7.9    Test that no files are open in spawned tasks (except stdin,
+           stdout, and stderr) to insure successful checkpoint/restart.
 
 
 test8.#    Test of Blue Gene specific functionality.
diff --git a/testsuite/expect/test7.9 b/testsuite/expect/test7.9
new file mode 100755
index 00000000000..0a642d869fb
--- /dev/null
+++ b/testsuite/expect/test7.9
@@ -0,0 +1,119 @@
+#!/usr/bin/expect
+############################################################################
+# Purpose: Test of SLURM functionality
+#          Test that no files are open in spawned tasks (except stdin,
+#          stdout, and stderr) to insure successful checkpoint/restart.
+#
+# 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) 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          "7.9"
+set exit_code        0
+set file_in          "test$test_id.input"
+set file_out         "test$test_id.output"
+set file_prog        "test$test_id.prog"
+set interations      50
+
+print_header $test_id
+
+#
+# Delete left-over programs and rebuild them.
+# We use our own program to get ulimit values since the output 
+# of the ulimit program is inconsistent across systems.
+#
+exec $bin_rm -f $file_prog $file_in $file_out
+exec $bin_make -f /dev/null $file_prog
+
+make_bash_script $file_in "
+  $bin_echo 'testing within script'
+  $file_prog
+  $bin_echo ' '
+  $bin_echo 'testing $interations sets of spawned tasks'
+  inx=1
+  while \[ \$inx -le $interations \]
+  do
+    $srun $file_prog
+    inx=\$((inx+1))
+  done
+"
+
+spawn $sbatch --output=$file_out -t1 ./$file_in
+expect {
+	-re "Submitted batch job ($number)" {
+		set job_id $expect_out(1,string)
+		exp_continue
+	}
+	eof {
+		wait
+	}
+}
+if {$job_id == 0} {
+	send_user "\nFAILURE: batch submit failure\n"
+	exit 1
+}
+
+#
+# Wait for job to complete
+#
+if {[wait_for_job $job_id "DONE"] != 0} {
+	send_user "\nFAILURE: waiting for job to complete\n"
+	exit 1
+}
+
+#
+# Inspect the job's output file
+#
+if {[wait_for_file $file_out] != 0} {
+	exit 1
+}
+set matches 0
+spawn $bin_cat $file_out
+expect {
+	-re "FAILED" {
+		incr matches
+		exp_continue
+	}
+	timeout {
+		send_user "\nFAILURE: /bin/cat not responding\n"
+		set exit_code 1
+	}
+	eof {
+		wait
+	}
+}
+if {$matches != 0} {
+	send_user "FAILURE: $matches of $interations tests failed\n"
+	set exit_code 1
+}
+
+if {$exit_code == 0} {
+	send_user "\nSUCCESS\n"
+        exec $bin_rm -f $file_in $file_prog $file_out
+
+}
+exit $exit_code
diff --git a/testsuite/expect/test7.9.prog.c b/testsuite/expect/test7.9.prog.c
new file mode 100644
index 00000000000..cca3312f538
--- /dev/null
+++ b/testsuite/expect/test7.9.prog.c
@@ -0,0 +1,43 @@
+/*****************************************************************************\
+ *  test7.9.prog Report any open files (other than stdin, stdout, and stderr).
+ *****************************************************************************
+ *  Copyright (C) 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.
+\*****************************************************************************/
+#include <stdio.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <unistd.h>
+
+main (int argc, char **argv) 
+{
+	int i;
+	struct stat buf;
+
+	/* start at fd=3
+	 * skip stdin, stdout, and stderr */
+	for (i=3; i<256; i++) {
+		if (fstat(i, &buf) == 0)
+			printf("FAILED: File descriptor %d is open\n", i);
+	}
+	exit(0);
+}
-- 
GitLab