From f6a8e5b70c2a2ce22e910a74f26d0c8ae7d3376c Mon Sep 17 00:00:00 2001
From: "Christopher J. Morrone" <morrone2@llnl.gov>
Date: Tue, 15 Aug 2006 03:31:49 +0000
Subject: [PATCH] Rewrite test18.14 to print useful errors. Fix batch
 environment variable setting.

---
 src/common/env.c           |   7 ++-
 src/slaunch/slaunch.c      |  13 ++--
 testsuite/expect/test18.14 | 121 ++++++++++++++-----------------------
 3 files changed, 60 insertions(+), 81 deletions(-)

diff --git a/src/common/env.c b/src/common/env.c
index 1c5cc45063f..64c55cc1755 100644
--- a/src/common/env.c
+++ b/src/common/env.c
@@ -927,8 +927,11 @@ int env_array_overwrite(char ***array_ptr, const char *name,
 
 char **env_array_copy(const char **array)
 {
-	error("env_array_copy not implented");
-	return NULL;
+	char **ptr = NULL;
+
+	env_array_merge(&ptr, array);
+
+	return ptr;
 }
 
 /*
diff --git a/src/slaunch/slaunch.c b/src/slaunch/slaunch.c
index aa9983536c9..00b9559fc59 100644
--- a/src/slaunch/slaunch.c
+++ b/src/slaunch/slaunch.c
@@ -127,7 +127,9 @@ int slaunch(int argc, char **argv)
 	int rc;
 	uint32_t *hostids = NULL;
 	log_init(xbasename(argv[0]), logopt, 0, NULL);
+	char **env;
 	int i, j;
+
 	
 	/* Initialize plugin stack, read options from plugins, etc. */
 	if (spank_init(NULL) < 0)
@@ -167,8 +169,7 @@ int slaunch(int argc, char **argv)
 	step_req.user_id = getuid();
 	step_req.node_count = opt.num_nodes;
 	step_req.num_tasks = opt.num_tasks;
-/* 	step_req.cpu_count = opt.cpus_per_task; */
-	step_req.cpu_count = 0; /* FIXME */
+	step_req.cpu_count = opt.num_tasks * opt.cpus_per_task;
 	step_req.relative = opt.relative;
 	step_req.task_dist = opt.distribution;
 	step_req.overcommit = opt.overcommit ? 1 : 0;
@@ -207,8 +208,12 @@ int slaunch(int argc, char **argv)
 	params.argc = opt.argc;
 	params.argv = opt.argv;
 	params.multi_prog = opt.multi_prog ? true : false;
-	params.envc = envcount(environ);
-	params.env = environ;
+	env = env_array_copy(environ);
+	/* FIXME - should find a better place to set this than here */
+	env_array_overwrite_fmt(&env, "SLURM_CPUS_PER_TASK",
+				"%d", opt.cpus_per_task);
+	params.envc = envcount(env);
+	params.env = env;
 	params.cwd = opt.cwd;
 	params.slurmd_debug = opt.slurmd_debug;
 	params.buffered_stdio = opt.unbuffered ? false : true;
diff --git a/testsuite/expect/test18.14 b/testsuite/expect/test18.14
index 726571ac65e..632ac1daf59 100755
--- a/testsuite/expect/test18.14
+++ b/testsuite/expect/test18.14
@@ -48,79 +48,8 @@ expect {
 		set job_id $expect_out(1,string)
 		exp_continue
 	}
-	-re "SLURM_($alpha_under)=($alpha_numeric)" {
-		if {[string compare $expect_out(1,string) "CPUS_ON_NODE"] == 0
-		&& $expect_out(2,string) > 0} {
-			incr matches
-			exp_continue
-		}
-		if {[string compare $expect_out(1,string) "CPUS_PER_TASK"] == 0
-		&& $expect_out(2,string) > 0} {
-			incr matches
-			exp_continue
-		}
-                if {[string compare $expect_out(1,string) "JOBID"] == 0
-		&& $expect_out(2,string) > 0} {
-			incr matches
-			exp_continue
-		}
-                if {[string compare $expect_out(1,string) "LAUNCH_NODE_IPADDR"] == 0} {
-                        incr matches
-			exp_continue
-                }
-                if {[string compare $expect_out(1,string) "LOCALID"] == 0} {
-                        incr matches
-			exp_continue
-                }
-                if {[string compare $expect_out(1,string) "NNODES"] == 0
-		&& $expect_out(2,string) > 0} {
-                        incr matches
-			exp_continue
-                }
-                if {[string compare $expect_out(1,string) "NODEID"] == 0} {
-                        incr matches
-			exp_continue
-                }
-		if {[string compare $expect_out(1,string) "NODELIST"] == 0} {
-			incr matches
-			exp_continue
-		}
-		if {[string compare $expect_out(1,string) "NPROCS"] == 0
-		&& $expect_out(2,string) > 0} {
-			incr matches
-			exp_continue
-		}
-		if {[string compare $expect_out(1,string) "PROCID"] == 0} {
-			incr matches
-			exp_continue
-		}
-		if {[string compare $expect_out(1,string) "SRUN_COMM_HOST"] == 0} {
-			incr matches
-			exp_continue
-		}
-		if {[string compare $expect_out(1,string) "SRUN_COMM_PORT"] == 0
-		&& $expect_out(2,string) > 0} {
-			incr matches
-			exp_continue
-		}
-		if {[string compare $expect_out(1,string) "STEPID"] == 0} {
-			incr matches
-			exp_continue
-		}
-		if {[string compare $expect_out(1,string) "TASKS_PER_NODE"] == 0
-		&& $expect_out(2,string) > 0} {
-			incr matches
-			exp_continue
-		}
-		if {[string compare $expect_out(1,string) "TASK_PID"] == 0
-		&& $expect_out(2,string) > 0} {
-			incr matches
-			exp_continue
-		}
-		if {[string compare $expect_out(1,string) "UMASK"] == 0} {
-			incr matches
-			exp_continue
-		}
+	-re "(SLURM_$alpha_under)=($alpha_numeric)" {
+		set found_vars($expect_out(1,string)) "$expect_out(2,string)"
 		exp_continue
 	}
 	timeout {
@@ -137,8 +66,50 @@ expect {
 		wait
 	}
 }
-if {$matches != 16} {
-	send_user "\nFAILURE: Not all SLURM environment variables set ($matches of 16)\n"
+
+# These are the variables for which we are checking existence
+# If the number following a variable name is 1, then we check to make
+# certain that the value of the env variable is greater than 0
+array set good_vars {
+    SLURM_CPUS_ON_NODE 1
+    SLURM_CPUS_PER_TASK 1
+    SLURM_JOBID 1
+    SLURM_LAUNCH_NODE_IPADDR 0
+    SLURM_LOCALID 0
+    SLURM_NNODES 0
+    SLURM_NODEID 0
+    SLURM_NODELIST 0
+    SLURM_NPROCS 1
+    SLURM_PROCID 0
+    SLURM_SRUN_COMM_HOST 0
+    SLURM_SRUN_COMM_PORT 1
+    SLURM_STEPID 0
+    SLURM_TASKS_PER_NODE 1
+    SLURM_TASK_PID 1
+    SLURM_UMASK 0
+}
+
+set total 0
+set good 0
+send_user "\n"
+foreach {slurm_var check_flag} [array get good_vars] {
+    incr total
+    if {[info exists found_vars($slurm_var)]} {
+	if { $check_flag == 1 && $found_vars($slurm_var) <= 0 } {
+		send_user "FAILURE: Found $slurm_var, but $found_vars($slurm_var) <= 0\n"
+	} else {
+	    incr good
+	}
+    } else {
+	send_user "FAILURE: Variable $slurm_var not found\n"
+    }
+}
+
+
+
+
+if {$good < $total} {
+	send_user "\nFAILURE: Not all SLURM environment variables set ($good of $total)\n"
 	set exit_code 1
 }
 
-- 
GitLab