Skip to content

Commit 9014f8c

Browse files
committed
libtaskmap: test decode of raw taskmaps in unit test
Problem: There are no unit tests for raw taskmap decode. Add a series of tests that ensure raw taskmaps are properly decoded (and not) as expected to the taskmap unit test.
1 parent cc1210d commit 9014f8c

File tree

1 file changed

+43
-1
lines changed

1 file changed

+43
-1
lines changed

src/common/libtaskmap/test/taskmap.c

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,22 @@ static void rfc34_tests ()
8585
"taskmap is known");
8686
taskmap_destroy (map);
8787
free (s);
88+
89+
/* Try raw back to taskmap:
90+
*/
91+
map = taskmap_decode (t->expected, NULL);
92+
ok (map != NULL,
93+
"taskmap_decode (%s)",
94+
t->expected);
95+
if (map) {
96+
ok ((s = taskmap_encode (map, 0)) != NULL,
97+
"taskmap_encode works");
98+
is (s, t->taskmap,
99+
"taskmap=%s",
100+
s);
101+
taskmap_destroy (map);
102+
free (s);
103+
}
88104
}
89105
}
90106

@@ -272,7 +288,6 @@ static void main_tests ()
272288

273289
static const char *invalid[] = {
274290
"}",
275-
"42",
276291
"{}",
277292
"{\"version\":1}",
278293
"{\"version\":1,\"map\":{}}",
@@ -553,6 +568,32 @@ void test_deranged (void)
553568
taskmap_destroy (map);
554569
}
555570

571+
struct test_vector raw_tests[] = {
572+
{ "-1", "error parsing range '-1'" },
573+
{ "1-3;a-b", "error parsing range 'a-b'" },
574+
{ "1,1", "range '1' is out of order" },
575+
{ "0-1;1-2", "duplicate taskid specified: 1" },
576+
{ "5-15;0-10", "duplicate taskids specified: 5-10" },
577+
{ "1", "missing taskid: 0" },
578+
{ "3-4;0-1", "missing taskid: 2" },
579+
{ "0-1;10-11", "missing taskids: 2-9" },
580+
{ NULL, NULL },
581+
};
582+
583+
static void test_raw_decode_errors (void)
584+
{
585+
struct test_vector *t;
586+
for (t = &raw_tests[0]; t->taskmap != NULL; t++) {
587+
flux_error_t error;
588+
ok (taskmap_decode (t->taskmap, &error) == NULL,
589+
"taskmap_decode (%s) fails",
590+
t->taskmap);
591+
is (error.text, t->expected,
592+
"taskmap_decode: %s",
593+
error.text);
594+
}
595+
}
596+
556597
int main (int ac, char **av)
557598
{
558599
plan (NO_PLAN);
@@ -565,6 +606,7 @@ int main (int ac, char **av)
565606
append_cyclic_one ();
566607
test_check ();
567608
test_deranged ();
609+
test_raw_decode_errors ();
568610
done_testing ();
569611
}
570612

0 commit comments

Comments
 (0)