From 7f59b4b7c8a3014f8896375fbb36e61ff33d34f1 Mon Sep 17 00:00:00 2001
From: Nathan Yee <nee32@schedmd.com>
Date: Thu, 6 Jun 2013 15:21:42 -0700
Subject: [PATCH] Add test for JobAcctGatherFrequency value being enforced

---
 testsuite/expect/Makefile.am |  1 +
 testsuite/expect/Makefile.in |  1 +
 testsuite/expect/README      |  2 +
 testsuite/expect/globals     | 76 ++++++++++++++++++++++++++++
 testsuite/expect/test1.72    | 97 ++++++++++++++++++++++++++++++++++++
 5 files changed, 177 insertions(+)
 create mode 100755 testsuite/expect/test1.72

diff --git a/testsuite/expect/Makefile.am b/testsuite/expect/Makefile.am
index 680332e5c2a..204a3268ed3 100644
--- a/testsuite/expect/Makefile.am
+++ b/testsuite/expect/Makefile.am
@@ -92,6 +92,7 @@ EXTRA_DIST = \
 	test1.69			\
 	test1.70			\
 	test1.71			\
+	test1.72			\
 	test1.80			\
 	test1.81			\
 	test1.82			\
diff --git a/testsuite/expect/Makefile.in b/testsuite/expect/Makefile.in
index 5a7c68593c2..2e84f8900a3 100644
--- a/testsuite/expect/Makefile.in
+++ b/testsuite/expect/Makefile.in
@@ -422,6 +422,7 @@ EXTRA_DIST = \
 	test1.69			\
 	test1.70			\
 	test1.71			\
+	test1.72			\
 	test1.80			\
 	test1.81			\
 	test1.82			\
diff --git a/testsuite/expect/README b/testsuite/expect/README
index 02dd507283f..46ba56f8fcc 100644
--- a/testsuite/expect/README
+++ b/testsuite/expect/README
@@ -179,6 +179,8 @@ test1.69   Test that multiple srun programs execute simultaneously in the
            background.
 test1.70   Validates that srun standard input and output work with binary files.
 test1.71   Validates that srun exit code matches that of a test program.
+test1.72   Validate that the JobAcctGatherFrequency value is enforced when
+	   used in srun.
 
 **NOTE**   The following tests attempt to utilize multiple CPUs or partitions,
 	   The test will print "WARNING" and terminate with an exit code of
diff --git a/testsuite/expect/globals b/testsuite/expect/globals
index 894231b5852..aae889b0157 100755
--- a/testsuite/expect/globals
+++ b/testsuite/expect/globals
@@ -1979,6 +1979,46 @@ proc check_acct_associations { } {
 	return $rc
 }
 
+################################################################
+#
+# Proc: get_job_acct_freq
+#
+# Purpose: gets the value of the job account gather frequency
+#
+# Returns: job account gather frequency
+#
+################################################################
+proc get_job_acct_freq { } {
+	global scontrol number
+
+	log_user 0
+	set freq_val 0
+
+	spawn $scontrol show config
+	expect {
+		-re "JobAcctGatherFrequency *= ($number)" {
+			set freq_val $expect_out(1,string)
+			if {$freq_val == 0} {
+				set freq_val 0
+			}
+		}
+		-re "JobAcctGatherFrequency *= task=($number)" {
+			set freq_val $expect_out(1,string)
+			if {$freq_val == 0} {
+				set freq_val 0
+			}
+		}
+		eof {
+			wait
+		}
+	}
+
+	log_user 1
+	return $freq_val
+
+
+}
+
 ################################################################
 #
 # Proc:check_accounting_admin_level
@@ -2522,3 +2562,39 @@ proc scale_to_ks { value factor } {
 
 	return $value
 }
+
+############################################################
+#
+# Proc: check_node_mem
+#
+# Purpose: check that the nodes have memory configured
+#
+# Returns: 1 if the nodes have memory, 0 otherwise
+#
+############################################################
+
+proc check_node_mem { } {
+	global scontrol number
+
+	log_user 0
+	set mem_size 0
+
+	spawn $scontrol show node
+	expect {
+		-re "RealMemory=($number)" {
+			set mem_size $expect_out(1,string)
+			exp_continue
+		}
+		eof {
+			wait
+		}
+	}
+
+	if {$mem_size == 1} {
+		return 0
+	} else {
+		return 1
+	}
+	log_user 1
+
+}
diff --git a/testsuite/expect/test1.72 b/testsuite/expect/test1.72
new file mode 100755
index 00000000000..80ec1e2c2a0
--- /dev/null
+++ b/testsuite/expect/test1.72
@@ -0,0 +1,97 @@
+#!/usr/bin/expect
+############################################################################
+# Purpose: Test of SLURM functionality
+#          Validates that the JobAcctGatherFrequency value is enforced
+#
+# 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) 2013 SchedMD LLC
+# Written by Nathan Yee <nyee32@schedmd.com>
+#
+# This file is part of SLURM, a resource management program.
+# For details, see <http://slurm.schedmd.com/>.
+# 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.,
+# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301  USA.
+############################################################################
+source ./globals
+
+set test_id   "1.72"
+set freq_val  0
+set exit_code 0
+
+if {[get_job_acct_freq] == 0} {
+	send_user "\nWARNING:this test requires JobAcctGatherFrequency to be set\n"
+	exit $exit_code
+}
+if {[check_node_mem] == 0} {
+	send_user "\nWARNING: this test requires that the nodes have memory\n"
+	exit $exit_code
+}
+
+print_header $test_id
+
+#
+# set value of freq_val to JobAcctGatherFrequency
+#
+set freq_val [get_job_acct_freq]
+
+set sub_match 0
+spawn $srun -v --mem=200 --acctg-freq=[expr $freq_val - 10] sleep 5
+expect {
+	-re "jobid" {
+		set sub_match 1
+		exp_continue
+	}
+	timeout {
+		send_user "\nFAILURE: srun is not responding\n"
+		set exit_code 1
+	}
+	eof {
+		wait
+	}
+}
+if {$sub_match != 1} {
+	send_user "\nFAILURE: srun did not submit job\n"
+	set exit_code 1
+}
+
+set sub_match 0
+spawn $srun -v --mem=200 --acctg-freq=[expr $freq_val + 10] sleep 5
+expect {
+	-re "Application launch failed: Invalid accounting" {
+		send_user "\nThis error is expect do not worry.\n"
+		set sub_match 1
+		exp_continue
+	}
+	timeout {
+		send_user "\nFAILURE: srun is not responding\n"
+		set exit_code 1
+	}
+	eof {
+		wait
+	}
+}
+if {$sub_match != 1} {
+	send_user "\nFAILURE: srun did not fail when it should have\n"
+	set exit_code 1
+}
+
+if {$exit_code == 0} {
+	send_user "\nSUCCESS\n"
+}
+exit $exit_code
-- 
GitLab