#!/usr/bin/env expect
############################################################################
# Purpose: Test hetjob step output file labling and different commands/args
############################################################################
# Copyright (C) SchedMD LLC.
# 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 file_out    "$test_dir/output"

if {[get_config_param "SchedulerType"] ne "sched/backfill"} {
	skip "This test requires SchedulerType = sched/backfill"
}

set nb_nodes [get_partition_param [default_partition] "TotalNodes"]
if {$nb_nodes < 2} {
	skip "Need 2 or more nodes in default partition"
}

set timeout $max_job_delay
spawn $srun -t1 -n1 -l -o $file_out --mpi=none $bin_echo one : -n1 $bin_echo two
expect {
	timeout {
		fail "srun not responding"
	}
	eof {
		wait
	}
}
wait_for_file -fail $file_out
set matches 0
spawn $bin_sort $file_out
expect {
	-re "0: one" {
		incr matches
		exp_continue
	}
	-re "1: two" {
		incr matches
		exp_continue
	}
	eof {
		wait
	}
}
if {$matches != 2} {
	fail "srun output file contents invalid"
}
