Skip to content

Commit

Permalink
Merge pull request #31 from jameshcorbett/pals-apinfo-tests
Browse files Browse the repository at this point in the history
cray-pals: add apinfo content tests
  • Loading branch information
mergify[bot] authored Sep 9, 2022
2 parents b2db499 + 2b1a65f commit 4754145
Show file tree
Hide file tree
Showing 2 changed files with 126 additions and 0 deletions.
90 changes: 90 additions & 0 deletions t/scripts/apinfo_checker.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
#!/usr/bin/env python3

import struct
import os
import json
import sys


def get_comm_profiles(apinfo, size, offset, count):
comms = []
for comm in _get_structs(apinfo, size, offset, count, "40siii"):
tokenid, vni, vlan, traffic_classes = comm
comms.append(
{
"tokenid": tokenid,
"vni": vni,
"vlan": vlan,
"traffic_classes": traffic_classes,
}
)
return comms


def get_cmds(apinfo, size, offset, count):
cmds = []
for cmd in _get_structs(apinfo, size, offset, count, "iii"):
npes, pes_per_node, cpus_per_pe = cmd
cmds.append(
{"npes": npes, "pes_per_node": pes_per_node, "cpus_per_pe": cpus_per_pe}
)
return cmds


def get_pes(apinfo, size, offset, count):
pes = []
for pe in _get_structs(apinfo, size, offset, count, "iii"):
localidx, cmdidx, nodeidx = pe
pes.append({"localidx": localidx, "cmdidx": cmdidx, "nodeidx": nodeidx})
return pes


def get_nodes(apinfo, size, offset, count):
nodes = []
for node in _get_structs(apinfo, size, offset, count, "i64s"):
node_id, hostname = node
nodes.append(
{"id": node_id, "hostname": hostname.split(b"\x00")[0].decode("ascii")}
)
return nodes


def get_nics(apinfo, size, offset, count):
nics = []
for pe in _get_structs(apinfo, size, offset, count, "ii40s"):
nodeidx, address_type, address = pe
nics.append(
{
"nodeidx": nodeidx,
"address_type": address_type,
"address": address.split(b"\x00")[0].decode("ascii"),
}
)
return nics


def _get_structs(apinfo, size, offset, count, format):
for i in range(count):
yield struct.unpack(format, apinfo[offset : offset + size])
offset += size


def main():
with open(os.environ["PALS_APINFO"], "rb") as fd:
apinfo = fd.read()
header_format = "iNNNiNNiNNiNNiNNi"
header = struct.unpack(header_format, apinfo[: struct.calcsize(header_format)])
apinfo_dict = {
"version": header[0],
"comm_profiles": get_comm_profiles(apinfo, header[2], header[3], header[4]),
"cmds": get_cmds(apinfo, header[5], header[6], header[7]),
"pes": get_pes(apinfo, header[8], header[9], header[10]),
"nodes": get_nodes(apinfo, header[11], header[12], header[13]),
"nics": get_nics(apinfo, header[14], header[15], header[16]),
}
json.dump(apinfo_dict, sys.stdout)
print()


if __name__ == "__main__":
main()
36 changes: 36 additions & 0 deletions t/t1001-cray-pals.t
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,42 @@ test_expect_success 'shell: pals shell plugin creates apinfo file' '
&& test ! -z \$PALS_APINFO && test -f \$PALS_APINFO"
'

test_expect_success HAVE_JQ 'shell: apinfo file contents are valid for one task' '
apinfo=$(flux mini run -o userrc=$(pwd)/$USERRC_NAME -N1 -n1 ${PYTHON:-python3} \
${SHARNESS_TEST_SRCDIR}/scripts/apinfo_checker.py) &&
echo "$apinfo" | jq -e ".version == 1" &&
echo "$apinfo" | jq -e ".cmds[0].npes == 1" &&
echo "$apinfo" | jq -e ".pes[0].localidx == 0" &&
echo "$apinfo" | jq -e ".pes[0].cmdidx == 0" &&
echo "$apinfo" | jq -e ".pes[0].nodeidx == 0" &&
echo "$apinfo" | jq -e ".nodes[0].id == 0" &&
test $(hostname) = $(echo "$apinfo" | jq -r .nodes[0].hostname) &&
echo "$apinfo" | jq ".nics | length == 0" &&
echo "$apinfo" | jq ".comm_profiles | length == 0" &&
echo "$apinfo" | jq -e ".nodes | length == 1" &&
echo "$apinfo" | jq -e ".cmds | length == 1" &&
echo "$apinfo" | jq -e ".pes | length == 1"
'

test_expect_success HAVE_JQ 'shell: apinfo file contents are valid for multiple tasks' '
apinfo=$(flux mini run -o userrc=$(pwd)/$USERRC_NAME -N1 -n2 --label-io \
${PYTHON:-python3} ${SHARNESS_TEST_SRCDIR}/scripts/apinfo_checker.py \
| sed -n "s/^1: //p") &&
echo "$apinfo" | jq -e ".cmds[0].npes == 2" &&
echo "$apinfo" | jq -e ".cmds[0].pes_per_node == 2" &&
echo "$apinfo" | jq -e ".pes[0].localidx == 0" &&
echo "$apinfo" | jq -e ".pes[1].localidx == 1" &&
echo "$apinfo" | jq -e ".pes[0].cmdidx == 0" &&
echo "$apinfo" | jq -e ".pes[1].cmdidx == 0" &&
echo "$apinfo" | jq -e ".pes[0].nodeidx == 0" &&
echo "$apinfo" | jq -e ".pes[1].nodeidx == 0" &&
echo "$apinfo" | jq -e ".nics | length == 0" &&
echo "$apinfo" | jq -e ".comm_profiles | length == 0" &&
echo "$apinfo" | jq -e ".nodes | length ==1" &&
echo "$apinfo" | jq -e ".cmds | length == 1" &&
echo "$apinfo" | jq -e ".pes | length == 2"
'

test_expect_success 'shell: pals shell plugin handles resource oversubscription' '
flux mini run -o userrc=$(pwd)/$USERRC_NAME -N1 -n2 -oper-resource.type=core -oper-resource.count=2 \
env | grep PALS_RANKID=3 &&
Expand Down

0 comments on commit 4754145

Please sign in to comment.