Skip to content

Commit

Permalink
Merge pull request #4788 from grondo/taskmap-unknown
Browse files Browse the repository at this point in the history
libtaskmap: support RFC 34 unknown task maps
  • Loading branch information
mergify[bot] committed Dec 1, 2022
2 parents 68a7ea6 + 8248d4c commit 22828cd
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 4 deletions.
17 changes: 13 additions & 4 deletions src/common/libtaskmap/taskmap.c
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,12 @@ struct taskmap *taskmap_create (void)
return NULL;
}

bool taskmap_unknown (const struct taskmap *map)
{
/* A zero-length mapping indicates that the task map is unknown */
return zlistx_size (map->blocklist) == 0;
}

static char *to_string (int n, char *buf, int len)
{
(void) snprintf (buf, len, "%d", n);
Expand Down Expand Up @@ -350,7 +356,7 @@ const struct idset *taskmap_taskids (const struct taskmap *map, int nodeid)
struct taskmap_block *block;
struct idset *taskids;

if (!map || nodeid < 0) {
if (!map || nodeid < 0 || taskmap_unknown (map)) {
errno = EINVAL;
return NULL;
}
Expand Down Expand Up @@ -391,7 +397,7 @@ int taskmap_nodeid (const struct taskmap *map, int taskid)
struct taskmap_block *block;
int current = 0;

if (!map || taskid < 0) {
if (!map || taskid < 0 || taskmap_unknown (map)) {
errno = EINVAL;
return -1;
}
Expand Down Expand Up @@ -425,7 +431,7 @@ int taskmap_nnodes (const struct taskmap *map)
struct taskmap_block *block;
int n;

if (!map) {
if (!map || taskmap_unknown (map)) {
errno = EINVAL;
return -1;
}
Expand All @@ -446,7 +452,7 @@ int taskmap_total_ntasks (const struct taskmap *map)
struct taskmap_block *block;
int n;

if (!map) {
if (!map || taskmap_unknown (map)) {
errno = EINVAL;
return -1;
}
Expand Down Expand Up @@ -612,6 +618,9 @@ static char *taskmap_encode_pmi (const struct taskmap *map)
zlistx_t *l;
int saved_errno;

if (taskmap_unknown (map))
return strdup ("");

if (!(l = zlistx_new ())) {
errno = ENOMEM;
return NULL;
Expand Down
4 changes: 4 additions & 0 deletions src/common/libtaskmap/taskmap.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ struct taskmap *taskmap_decode (const char *map, flux_error_t *errp);
*/
char *taskmap_encode (const struct taskmap *map, int flags);

/* Return true if the task mapping is uknown.
*/
bool taskmap_unknown (const struct taskmap *map);

/* Return an idset of taskids encoded in 'map' for nodeid 'nodeid'.
* Returns an idset on success, which may only be vaild until the next
* call to taskmap_taskids(), caller should use idset_copy() if necessary.
Expand Down
20 changes: 20 additions & 0 deletions src/common/libtaskmap/test/taskmap.c
Original file line number Diff line number Diff line change
Expand Up @@ -80,12 +80,16 @@ static void rfc34_tests ()
is (s, t->expected,
"taskmap raw=%s",
s);
if (strlen (s))
ok (taskmap_unknown (map) == false,
"taskmap is known");
taskmap_destroy (map);
free (s);
}
}

struct test_vector pmi_tests[] = {
{ "[]", "" },
{ "[[0,4,4,1]]", "(vector,(0,4,4))" },
{ "[[0,4,2,1],[4,2,4,1]]", "(vector,(0,4,2),(4,2,4))" },
{ "[[0,4,1,4]]", "(vector,(0,4,1),(0,4,1),(0,4,1),(0,4,1))" },
Expand Down Expand Up @@ -225,6 +229,22 @@ static void error_tests ()
if (!(map = taskmap_create ()))
BAIL_OUT ("taskmap_create");

/* Test "unknown" task map errors */
ok (taskmap_unknown (map),
"taskmap_unknown returns true for empty task map");
ok (taskmap_nnodes (map) < 0 && errno == EINVAL,
"taskmap_nnodes on unknown taskmap returns EINVAL");
ok (taskmap_total_ntasks (map) < 0 && errno == EINVAL,
"taskmap_nnodes on unknown taskmap returns EINVAL");
ok (taskmap_nodeid (map, 0) < 0 && errno == EINVAL,
"taskmap_nodeid on unknown taskmap returns EINVAL");
ok (taskmap_taskids (map, 0) == NULL && errno == EINVAL,
"taskmap_taskids on unknown taskmap returns EINVAL");

/* Add one task to taskmap so it is no longer unknown */
ok (taskmap_append (map, 0, 1, 1) == 0,
"add one task to taskmap so it is no longer unknown");

ok (taskmap_encode (NULL, 0) == NULL && errno == EINVAL,
"taskmap_encode (NULL) returns EINVAL");
ok (taskmap_encode (map, 0xff) == NULL && errno == EINVAL,
Expand Down
4 changes: 4 additions & 0 deletions src/shell/info.c
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,10 @@ int shell_info_set_taskmap (struct shell_info *info,
errno = EINVAL;
return -1;
}
if (taskmap_unknown (map)) {
shell_log_error ("invalid taskmap: mapping is unknown");
return -1;
}
if (info->taskmap
&& taskmap_check (info->taskmap, map, &error) < 0) {
shell_log_error ("invalid taskmap: %s", error.text);
Expand Down
4 changes: 4 additions & 0 deletions t/t2616-job-shell-taskmap.t
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,10 @@ test_expect_success 'taskmap=manual works' '
| jq -e ".context.taskmap.map == [[1,3,4,1],[0,1,4,1]]" &&
test_check_taskmap $id
'
test_expect_success 'taskmap=manual with unknown taskmap fails' '
test_must_fail_or_be_terminated \
flux mini run --taskmap="manual:[]" true
'
test_expect_success 'invalid taskmap causes job failure' '
test_must_fail_or_be_terminated \
flux mini run -vvv --taskmap=foo true
Expand Down

0 comments on commit 22828cd

Please sign in to comment.