Skip to content

Commit 4b0dc31

Browse files
committed
testsuite: add t2616-job-shell-taskmap-hostfile.t
Problem: There are no tests of the job shell hostfile taskmap support. Since the hostfile support requires different hostnames for each "node" in an instance, create a new test specific to this taskmap type using the "system" test personality, which assigns fake hostnames to brokers.
1 parent 56cd401 commit 4b0dc31

File tree

2 files changed

+108
-0
lines changed

2 files changed

+108
-0
lines changed

t/Makefile.am

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,7 @@ TESTSCRIPTS = \
208208
t2614-job-shell-doom.t \
209209
t2615-job-shell-rlimit.t \
210210
t2616-job-shell-taskmap.t \
211+
t2616-job-shell-taskmap-hostfile.t \
211212
t2617-job-shell-stage-in.t \
212213
t2618-job-shell-signal.t \
213214
t2619-job-shell-hwloc.t \
Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
#!/bin/sh
2+
#
3+
test_description='Test hostfile taskmap plugin support'
4+
5+
. `dirname $0`/sharness.sh
6+
7+
# Use "system" personality to get fake hostnames for hostfile use
8+
test_under_flux 4 system
9+
10+
# Test that actual task ranks match expected ranks.
11+
# Assumes job output is `echo $FLUX_TASK_RANK: $(flux getattr rank)`
12+
test_check_taskmap() {
13+
local id=$1
14+
flux job attach $id | sort -n >$id.output &&
15+
flux job taskmap --to=multiline $id >$id.expected &&
16+
test_cmp $id.expected $id.output
17+
}
18+
19+
test_expect_success 'create script for testing task mapping' '
20+
cat <<-EOF >map.sh &&
21+
#!/bin/sh
22+
echo \$FLUX_TASK_RANK: \$(flux getattr rank)
23+
EOF
24+
chmod +x map.sh
25+
'
26+
test_expect_success 'taskmap=hostfile works' '
27+
cat <<-EOF >h1 &&
28+
fake3
29+
fake2
30+
fake1
31+
fake0
32+
EOF
33+
expected="[[3,1,1,1],[2,1,1,1],[1,1,1,1],[0,1,1,1]]" &&
34+
id=$(flux submit --taskmap=hostfile:h1 -N4 -n4 ./map.sh) &&
35+
flux job attach -vEX $id &&
36+
flux job wait-event -p exec -f json $id shell.start &&
37+
flux job wait-event -p exec -f json $id shell.start \
38+
| jq -e ".context.taskmap.map == $expected" &&
39+
test_check_taskmap $id
40+
'
41+
test_expect_success 'taskmap=hostfile works with multiple tasks per node' '
42+
cat <<-EOF >h2 &&
43+
fake3
44+
fake3
45+
fake2
46+
fake2
47+
fake1
48+
fake1
49+
fake0
50+
fake0
51+
EOF
52+
expected="[[3,1,2,1],[2,1,2,1],[1,1,2,1],[0,1,2,1]]" &&
53+
id=$(flux submit --taskmap=hostfile:h2 -N4 --tasks-per-node=2 ./map.sh) &&
54+
flux job attach -vEX $id &&
55+
flux job wait-event -p exec -f json $id shell.start &&
56+
flux job wait-event -p exec -f json $id shell.start \
57+
| jq -e ".context.taskmap.map == $expected" &&
58+
test_check_taskmap $id
59+
'
60+
test_expect_success 'taskmap=hostfile reuses hosts in short hostlist' '
61+
cat <<-EOF >h3 &&
62+
fake3
63+
fake2
64+
fake1
65+
fake0
66+
EOF
67+
expected="[[3,1,1,1],[2,1,1,1],[1,1,1,1],[0,1,1,1],[3,1,1,1],[2,1,1,1],[1,1,1,1],[0,1,1,1]]" &&
68+
id=$(flux submit --taskmap=hostfile:h3 -N4 --tasks-per-node=2 ./map.sh) &&
69+
flux job attach -vEX $id &&
70+
flux job wait-event -p exec -f json $id shell.start &&
71+
flux job wait-event -p exec -f json $id shell.start \
72+
| jq -e ".context.taskmap.map == $expected" &&
73+
test_check_taskmap $id
74+
'
75+
test_expect_success 'taskmap=hostfile works with hostlists' '
76+
cat <<-EOF >h4 &&
77+
fake[1,2]
78+
fake[3,0]
79+
EOF
80+
expected="[[1,3,1,1],[0,4,1,1],[0,1,1,1]]" &&
81+
id=$(flux submit --taskmap=hostfile:h4 -N4 --tasks-per-node=2 ./map.sh) &&
82+
flux job attach -vEX $id &&
83+
flux job wait-event -p exec -f json $id shell.start &&
84+
flux job wait-event -p exec -f json $id shell.start \
85+
| jq -e ".context.taskmap.map == $expected" &&
86+
test_check_taskmap $id
87+
'
88+
test_expect_success 'taskmap=hostfile fails with invalid hostlist' '
89+
echo "fake[0-3">h5 &&
90+
test_must_fail_or_be_terminated \
91+
flux run --taskmap=hostfile:h5 -N4 hostname
92+
'
93+
test_expect_success 'taskmap=hostfile fails with incorrect hosts' '
94+
echo "foo[0-3]">h6 &&
95+
test_must_fail_or_be_terminated \
96+
flux run --taskmap=hostfile:h6 -N4 hostname
97+
'
98+
test_expect_success 'taskmap=hostfile fails when not all hosts present' '
99+
echo "foo[0,0,1,2]">h7 &&
100+
test_must_fail_or_be_terminated \
101+
flux run --taskmap=hostfile:h7 -N4 hostname
102+
'
103+
test_expect_success 'taskmap=hostfile fails with invalid filename' '
104+
test_must_fail_or_be_terminated \
105+
flux run --taskmap=hostfile:badfile -N4 hostname
106+
'
107+
test_done

0 commit comments

Comments
 (0)