| #!/usr/bin/env expect |
| ############################################################################ |
| # Purpose: Test of Slurm functionality |
| # Test that multiple srun programs execute simultaneously in the |
| # background. |
| ############################################################################ |
| # Copyright (C) SchedMD LLC. |
| # |
| # 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 file_in "$test_dir/script" |
| set test_timer "$test_dir/test_timer" |
| set test_srun "$test_dir/test_srun" |
| set sync_dir "$test_dir/sync" |
| set run_timer 10 |
| |
| set nb_nodes [get_partition_param [default_partition] "TotalNodes"] |
| if {[check_config_select "linear"]} { |
| if {$nb_nodes < $run_timer} { |
| skip "This test is incompatible with select/linear and only one node" |
| } |
| } elseif {[default_part_exclusive]} { |
| if {$nb_nodes < $run_timer} { |
| skip "This test is incompatible with exclusive node allocations and only one node" |
| } |
| } |
| |
| if {[param_contains [get_config_param "SelectTypeParameters"] "CR_*MEMORY"]} { |
| set mem_opt "--mem=10" |
| } else { |
| set mem_opt "--comment=no_mem" |
| } |
| |
| make_bash_script $test_timer " |
| mkdir -p $sync_dir |
| echo \"JOB STARTED: \$SLURM_JOB_ID\" |
| touch $sync_dir/\$SLURM_JOB_ID.ready |
| while \[ \$(ls $sync_dir/*.ready 2>/dev/null | wc -l) -lt $run_timer \]; do |
| sleep 0.5 |
| done |
| for i in \{1..10\} |
| do |
| echo \"timer \$a time \$i\" |
| sleep 0.5 |
| done |
| echo \"Timer \$a finished\" |
| " |
| |
| make_bash_script $test_srun " |
| set -m |
| for a in \{1..$run_timer\} |
| do |
| export a |
| $srun -v $mem_opt -t2 $test_timer & |
| done |
| " |
| |
| make_bash_script $file_in " |
| $bin_bash -i $test_srun |
| " |
| |
| # We make sure that all timers run at the same time by checking that all |
| # expected output is present. Order is not enforced since concurrent jobs |
| # may produce output in any order depending on system load. |
| set output [run_command_output -fail "bash -i $file_in"] |
| |
| set jobs [regexp -all {JOB STARTED:} $output] |
| set timer_match 0 |
| set fini_match 0 |
| for {set t 1} {$t <= $run_timer} {incr t} { |
| for {set i 1} {$i <= 10} {incr i} { |
| if {[regexp "timer $t time $i" $output]} { |
| incr timer_match |
| } |
| } |
| if {[regexp "Timer $t finished" $output]} { |
| incr fini_match |
| } |
| } |
| |
| subtest {$timer_match == [expr $run_timer*10]} "srun should execute all timers" "$timer_match != [expr $run_timer*10]" |
| subtest {$fini_match == $run_timer} "srun should finish the submitted program" "$fini_match != $run_timer" |
| subtest {$jobs == $run_timer} "All jobs should be started before timers start" |