Skip to content

Commit d23661e

Browse files
committed
librlist: add tests for rlist_copy_core_spec()
Problem: There are no unit tests of the new function rlist_copy_core_spec(). Add unit tests.
1 parent 6e0ad75 commit d23661e

File tree

1 file changed

+69
-0
lines changed

1 file changed

+69
-0
lines changed

src/common/librlist/test/rlist.c

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2149,6 +2149,74 @@ static void test_issue_5868 (void)
21492149
free (R);
21502150
}
21512151

2152+
struct core_spec_test {
2153+
const char *ranks;
2154+
const char *cores;
2155+
const char *hosts;
2156+
2157+
const char *spec;
2158+
const char *result;
2159+
const char *error;
2160+
};
2161+
2162+
struct core_spec_test core_spec_tests[] = {
2163+
{ "0-3", "0-3", "foo[0-3]", "0", "rank[0-3]/core0", NULL },
2164+
{ "0-3", "0-3", "foo[0-3]", "0-1", "rank[0-3]/core[0-1]", NULL },
2165+
{ "0-3", "0-3", "foo[0-3]", "0@0", "rank0/core0", NULL },
2166+
{ "0-3", "0-3", "foo[0-3]", "0,2@0", "rank0/core[0,2]", NULL },
2167+
{ "0-3", "0-3", "foo[0-3]", "0@0-1", "rank[0-1]/core0", NULL },
2168+
{ "0-3", "0-3", "foo[0-3]", "0-7@0", "rank0/core[0-3]", NULL },
2169+
{ "0-3",
2170+
"0-3",
2171+
"foo[0-3]",
2172+
"0-3@0 0@1-3",
2173+
"rank0/core[0-3] rank[1-3]/core0",
2174+
NULL },
2175+
{ "0-3", "0-3", "foo[0-3]", "foo", NULL, "error parsing range 'foo'"},
2176+
{ "0-3", "0-3", "foo[0-3]", "0@", NULL, "ranks/cores cannot be empty"},
2177+
{ "0-3", "0-3", "foo[0-3]", "@0", NULL, "ranks/cores cannot be empty"},
2178+
{ "0-3", "0-3", "foo[0-3]", "0 0@", NULL, "ranks/cores cannot be empty"},
2179+
{ NULL, NULL, NULL, NULL, NULL, NULL },
2180+
};
2181+
2182+
static void test_core_spec (void)
2183+
{
2184+
struct core_spec_test *te = &core_spec_tests[0];
2185+
while (te && te->ranks) {
2186+
char *R;
2187+
struct rlist *rl;
2188+
struct rlist *result;
2189+
flux_error_t error;
2190+
2191+
if (!(R = R_create (te->ranks, te->cores, NULL, te->hosts, NULL)))
2192+
BAIL_OUT ("test_core_spec: R_create");
2193+
2194+
if (!(rl = rlist_from_R (R)))
2195+
BAIL_OUT ("test_core_spec: rlist_from_R() failed");
2196+
2197+
result = rlist_copy_core_spec (rl, te->spec, &error);
2198+
if (result) {
2199+
char *s = rlist_dumps (result);
2200+
pass ("rlist_copy_core_spec (%s) returned %s", te->spec, s);
2201+
if (te->result)
2202+
is (s, te->result, "got expected result");
2203+
else
2204+
fail ("got %s but expected failure", s);
2205+
free (s);
2206+
}
2207+
else if (te->error) {
2208+
pass ("rlist_copy_core_spec (%s) failed as expected", te->spec);
2209+
is (error.text, te->error, "got expected error: %s", error.text);
2210+
}
2211+
else
2212+
diag ("rlist_copy_core_spec (%s): %s", te->spec, error.text);
2213+
free (R);
2214+
rlist_destroy (rl);
2215+
rlist_destroy (result);
2216+
te++;
2217+
}
2218+
}
2219+
21522220
int main (int ac, char *av[])
21532221
{
21542222
plan (NO_PLAN);
@@ -2180,6 +2248,7 @@ int main (int ac, char *av[])
21802248
test_issue4290 ();
21812249
test_rlist_config_inval ();
21822250
test_issue_5868 ();
2251+
test_core_spec ();
21832252
done_testing ();
21842253
}
21852254

0 commit comments

Comments
 (0)