From 3cc2cc95f7abf512f3198f49f70876373a691d0c Mon Sep 17 00:00:00 2001
From: Don Lipari <lipari1@llnl.gov>
Date: Tue, 28 Dec 2010 21:15:12 +0000
Subject: [PATCH] Added expect/test7.14 - Tests ability to modify
 DerivedExitCode/Str

---
 testsuite/expect/Makefile.am      |   3 +
 testsuite/expect/Makefile.in      |   3 +
 testsuite/expect/README           |   3 +
 testsuite/expect/test7.14         | 180 ++++++++++++++++++++++++++++++
 testsuite/expect/test7.14.prog1.c |   7 ++
 testsuite/expect/test7.14.prog2.c |   7 ++
 6 files changed, 203 insertions(+)
 create mode 100755 testsuite/expect/test7.14
 create mode 100644 testsuite/expect/test7.14.prog1.c
 create mode 100644 testsuite/expect/test7.14.prog2.c

diff --git a/testsuite/expect/Makefile.am b/testsuite/expect/Makefile.am
index cbb33e115a1..6bbc48ef02d 100644
--- a/testsuite/expect/Makefile.am
+++ b/testsuite/expect/Makefile.am
@@ -186,6 +186,9 @@ EXTRA_DIST = \
 	test7.13			\
 	test7.13.prog1.c		\
 	test7.13.prog2.c		\
+	test7.14			\
+	test7.14.prog1.c		\
+	test7.14.prog2.c		\
 	test8.1				\
 	test8.2				\
 	test8.3				\
diff --git a/testsuite/expect/Makefile.in b/testsuite/expect/Makefile.in
index f191ebb9172..f7601d865ad 100644
--- a/testsuite/expect/Makefile.in
+++ b/testsuite/expect/Makefile.in
@@ -458,6 +458,9 @@ EXTRA_DIST = \
 	test7.13			\
 	test7.13.prog1.c		\
 	test7.13.prog2.c		\
+	test7.14			\
+	test7.14.prog1.c		\
+	test7.14.prog2.c		\
 	test8.1				\
 	test8.2				\
 	test8.3				\
diff --git a/testsuite/expect/README b/testsuite/expect/README
index 2c2c9de42e9..788606a2150 100644
--- a/testsuite/expect/README
+++ b/testsuite/expect/README
@@ -285,6 +285,7 @@ test6.13   Test routing all signals through slurmctld rather than directly
            to slurmd (undocumented --ctld option).
 test6.14   Test scancel nodelist option (--nodelist or -w)
 
+
 test7.#    Testing of other functionality.
 ==========================================
 test7.1    Test priorities slurmctld assigns to jobs. Uses srun --hold and
@@ -310,6 +311,8 @@ test7.10   Test if we can trick SLURM into using the wrong user ID
 test7.11   Test of SPANK plugin.
 test7.12   Test of slurm_job_step_stat() API call.
 test7.13   Verify the correct setting of a job's ExitCode
+test7.14   Verify the ability to modify the Derived Exit Code/String fields
+           of a job record in the database
 
 
 test8.#    Test of Blue Gene specific functionality.
diff --git a/testsuite/expect/test7.14 b/testsuite/expect/test7.14
new file mode 100755
index 00000000000..3539822e364
--- /dev/null
+++ b/testsuite/expect/test7.14
@@ -0,0 +1,180 @@
+#!/usr/bin/expect
+############################################################################
+# Purpose: Verify the ability to modify the Derived Exit Code/String fields
+#          of a job record in the database.
+#
+# 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) 2010 Lawrence Livermore National Security.
+# Produced at Lawrence Livermore National Laboratory (cf, DISCLAIMER).
+# Written by Don Lipari <lipari1@llnl.gov>
+# CODE-OCEC-09-009. All rights reserved.
+#
+# This file is part of SLURM, a resource management program.
+# For details, see <https://computing.llnl.gov/linux/slurm/>.
+# Please also read the included file: DISCLAIMER.
+#
+# 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.14"
+set exit_code        0
+set file_in          "test$test_id.input"
+set file_prog1       "test$test_id.prog1"
+set file_prog2       "test$test_id.prog2"
+
+print_header $test_id
+
+if { [test_account_storage] == 0 } {
+	send_user "\nWARNING: This test can't be run without a usable AccountStorageType\n"
+	exit 0
+}
+
+#
+# Delete left-over programs and rebuild them.
+#
+exec $bin_rm -f $file_in
+exec $bin_rm -f $file_prog1 $file_prog2
+exec $bin_cc -O -o $file_prog1 ${file_prog1}.c
+exec $bin_cc -O -o $file_prog2 ${file_prog2}.c
+
+#
+# Submit a script that returns a successful exit code and confirm that
+# the job record's ExitCode reflects this value.  $file_prog1 returns a
+# successful error code (0) and $file_prog2 returns an unsuccessful
+# error code (123).
+#
+# The failed job step should have no influence on the job's ExitCode
+# value.  However the DerivedExitCode value should be set to the
+# highest value of all the job steps, in this case, 123.
+#
+
+make_bash_script $file_in "
+  $bin_echo 'testing successful job return code'
+  $srun $file_prog1
+  $srun $file_prog2
+  exit 0
+"
+
+set job_id 0
+spawn $sbatch --output=/dev/null -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
+}
+
+#
+# Confirm correct ExitCode and DerivedExitCode settings in job record
+#
+set matches 0
+spawn $scontrol --detail show job $job_id
+expect {
+	-re "ExitCode=0:0" {
+		incr matches
+		exp_continue
+	}
+	-re "DerivedExitCode=123:0" {
+		incr matches
+		exp_continue
+	}
+	timeout {
+		send_user "\nFAILURE: scontrol not responding\n"
+		exit 1
+	}
+	eof {
+		wait
+	}
+}
+
+if {$matches != 2} {
+	send_user "\nFAILURE: Job ExitCode incorrect\n"
+	exit 1
+}
+
+#
+# Modify the DerivedExitCode and String of the job
+#
+set matches 0
+spawn $sacctmgr -i modify job job=$job_id set DerivedExitCode=22 DerivedExitString=hello
+expect {
+	-re "$job_id" {
+		incr matches
+		exp_continue
+	}
+	timeout {
+		send_user "\nFAILURE: sacctmgr modify job not responding\n"
+		exit 1
+	}
+	eof {
+		wait
+	}
+}
+
+if {$matches != 1} {
+	send_user "\nFAILURE: sacctmgr failed to change DerivedExitCode/String\n"
+	exit 1
+}
+
+#
+# Confirm the DerivedExitCode and String fields of the job record in the db
+# matches the above modification and that ExitCode did not change.
+#
+set matches 0
+spawn $sacct -n -P -X -j $job_id -o ExitCode,DerivedExitCode,DerivedExitStr
+expect {
+	-re "0:0\\|0:22\\|hello" {	# Job record
+		incr matches
+		exp_continue
+	}
+	timeout {
+		send_user "\nFAILURE: sacct not responding\n"
+		exit 1
+	}
+	eof {
+		wait
+	}
+}
+
+if {$matches != 1} {
+	send_user "\nFAILURE: sacct of $job_id failed ($matches)\n"
+	exit 1
+}
+
+if {$exit_code == 0} {
+	send_user "\nSUCCESS\n"
+	exec $bin_rm -f $file_in $file_prog1 $file_prog2
+}
+
+exit $exit_code
diff --git a/testsuite/expect/test7.14.prog1.c b/testsuite/expect/test7.14.prog1.c
new file mode 100644
index 00000000000..95d733eeacb
--- /dev/null
+++ b/testsuite/expect/test7.14.prog1.c
@@ -0,0 +1,7 @@
+#include <stdio.h>
+
+int main(int argc, char **argv)
+{
+	printf("fini 0\n");
+	return 0;
+}
diff --git a/testsuite/expect/test7.14.prog2.c b/testsuite/expect/test7.14.prog2.c
new file mode 100644
index 00000000000..c1f736686e2
--- /dev/null
+++ b/testsuite/expect/test7.14.prog2.c
@@ -0,0 +1,7 @@
+#include <stdio.h>
+
+int main(int argc, char **argv)
+{
+	printf("fini 123\n");
+	return 123;
+}
-- 
GitLab