1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160
|
#!/usr/bin/env expect
############################################################################
# Purpose: Test of Slurm functionality
# Confirm that sbatch stdout, and stderr options work (--output
# and --error option respectively, including use of %j specification)
############################################################################
# Copyright (C) 2006-2007 The Regents of the University of California.
# Copyright (C) 2008 Lawrence Livermore National Security.
# Produced at Lawrence Livermore National Laboratory (cf, DISCLAIMER).
# Written by Morris Jette <jette1@llnl.gov>
# CODE-OCEC-09-009. All rights reserved.
#
# This file is part of Slurm, a resource management program.
# For details, see <https://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 user_name ""
set file_in "$test_dir/input"
set file_script "$test_dir/script"
set file_out "$test_dir/output"
set file_err "$test_dir/error"
set file_err_perc "$test_dir/error.%%"
set file_err_perc_result "$test_dir/error.%"
set file_out_perc "$test_dir/output.%%"
set file_out_perc_result "$test_dir/output.%"
set file_out_j "$test_dir/output.j.%j"
set file_err_j "$test_dir/error.j.%j"
set file_out_u "$test_dir/output.%u"
set file_err_u "$test_dir/error.%u"
#
# Delete left-over stdin/out/err files
# Build stdin file
#
make_bash_script $file_in "
$bin_id
$bin_sleep aaa
exit 0
"
#
# Get the name of the current user
#
set user_name [get_my_user_name]
proc test_job_output_files {job_id file_out file_err} {
#
# Wait for job to complete
#
wait_for_job -fail $job_id "DONE"
#
# Check for desired output
#
subtest {![wait_for_file $file_out]} "Check for file $file_out"
subtest {![wait_for_file $file_err]} "Check for file $file_err"
}
#
# Spawn a sbatch command to verify that the default output file is
# created and contain the correct contents
#
set job_id [submit_job -fail "-t1 -N1 $file_in"]
set def_out "slurm-$job_id\.out"
test_job_output_files $job_id $def_out $def_out
#
# Check for desired output
#
set output [run_command_output -fail "$bin_cat $def_out"]
set got_stdout [regexp -all "uid=" $output]
incr got_stdout [regexp -all "$sleep_error_message" $output]
subtest {$got_stdout == 2} "Check for expected stdout contents" "$got_stdout != 2"
# Remove the output file after it has been checked
exec $bin_rm -f $def_out
#
# Spawn a shell via sbatch that uses stdout/err and confirm their contents
#
set job_id [submit_job -fail "-N1 --output=$file_out --error=$file_err -t1 $file_in"]
#
# Wait for job to complete
#
wait_for_job -fail $job_id "DONE"
wait_for_file -fail $file_out
wait_for_file -fail $file_err
#
# Check for desired output
#
set output [run_command_output -fail "$bin_cat $file_out"]
subtest {[regexp "uid=" $output]} "Check for expected stdout contents"
set output [run_command_output -fail "$bin_cat $file_err"]
subtest {[regexp "$sleep_error_message" $output] ||
[regexp "Specify time as a positive integer.*\n" $output]} "Check for expected stderr contents"
#
# Spawn a shell via sbatch that uses literal %% in their file names
#
set job_id [submit_job -fail "-N1 --output=$file_out_perc --error=$file_err_perc -t1 $file_in"]
test_job_output_files $job_id $file_out_perc_result $file_err_perc_result
#
# Spawn a shell via sbatch that uses stdout/err with %j in their names
#
set job_id [submit_job -fail "-N1 --output=$file_out_j --error=$file_err_j -t1 $file_in"]
test_job_output_files $job_id "$test_dir/output.j.$job_id" "$test_dir/error.j.$job_id"
#
# Perform previous test using environment variables
#
run_command "$bin_rm $test_dir/output.j.$job_id $test_dir/error.j.$job_id"
set job_id [submit_job -fail -env "SBATCH_OUTPUT=$file_out_j SBATCH_ERROR=$file_err_j" "-N1 -t1 $file_in"]
test_job_output_files $job_id "$test_dir/output.j.$job_id" "$test_dir/error.j.$job_id"
#
# Spawn a shell via sbatch that uses stdout/err with %u in their names
#
set job_id [submit_job -fail "-N1 --output=$file_out_u --error=$file_err_u -t1 $file_in"]
test_job_output_files $job_id "$test_dir/output.$user_name" "$test_dir/error.$user_name"
#
# Spawn a program to run for a while with no output or error
#
set job_id [submit_job -fail "--output=none --error=none -t1 -N1 $file_in"]
#
# Wait for job to complete
#
wait_for_job -fail $job_id "DONE"
#
# Check for stdout/err files
#
set file_out2 slurm-$job_id.out
set file_err2 slurm-$job_id.err
log_debug "Checking for files $file_err2 and $file_out2"
subtest {[wait_for_file -timeout 5 $file_out2]} "Stdout file should not be created with --output=none"
subtest {[wait_for_file -timeout 5 $file_err2]} "Stderr file should not be created with --error=none"
|