Skip to content

Commit

Permalink
planner_multi: add unit tests for partial cancel
Browse files Browse the repository at this point in the history
  • Loading branch information
milroy committed Jun 28, 2024
1 parent 2a61c67 commit 7adf989
Showing 1 changed file with 86 additions and 1 deletion.
87 changes: 86 additions & 1 deletion resource/planner/test/planner_test02.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -699,9 +699,92 @@ static int test_multi_update ()

}

static int test_partial_cancel ()
{
bool bo = false, removed = false;
size_t len = 5;
int rc = -1;
int64_t span1 = -1, span2 = -1, span3 = -1, avail1 = -1,
avail2 = -1, avail3 = -1, avail4 = -1, avail5 = -1;
const uint64_t resource_totals[] = {10, 20, 30, 40, 50};
const char *resource_types[] = {"A", "B", "C", "D", "E"};
const char *resource_types1[] = {"B", "A", "E"};
const char *resource_types2[] = {"B", "A", "C", "D", "G", "X", "Y"};
const char *resource_types3[] = {"C", "D", "A", "B", "E"};
const char *resource_types4[] = {"D"};
const uint64_t reduce1[] = {1, 0, 0, 0, 0};
const uint64_t reduce2[] = {2, 1, 5};
const uint64_t reduce3[] = {2, 1, 5, 6, 7, 8, 9};
const uint64_t reduce4[] = {3, 3, 0, 0, 0};
const uint64_t reduce5[] = {1};
const uint64_t request1[] = {2, 0, 0, 0, 0};
const uint64_t request2[] = {1, 2, 3, 4, 5};
planner_multi_t *ctx = NULL;

ctx = planner_multi_new (0, INT64_MAX, resource_totals, resource_types, len);

span1 = planner_multi_add_span (ctx, 0, 1000, request1, len);
span2 = planner_multi_add_span (ctx, 0, 2000, request2, len);
rc = planner_multi_reduce_span (ctx, span1, reduce1, resource_types,
5, removed);
avail1 = planner_multi_avail_resources_at (ctx, 0, 0);
bo = (bo || avail1 != 8 || removed || rc != 0);
ok (!bo, "reducing span results in expected availability counts and doesn't remove span");

removed = false;
rc = planner_multi_reduce_span (ctx, span1, reduce1, resource_types,
5, removed);
avail1 = planner_multi_avail_resources_at (ctx, 0, 0);
bo = (bo || avail1 != 9 || !removed || rc != 0);
ok (!bo, "two partial reductions with appropriate removals totally remove span");

removed = false;
rc = planner_multi_reduce_span (ctx, span2, reduce2, resource_types1,
3, removed);
avail2 = planner_multi_avail_resources_at (ctx, 0, 1);
bo = (bo || avail2 != 20 || removed || rc != 0);
ok (!bo, "underspecified and reordered reduction types is handled correctly");

removed = false;
rc = planner_multi_reduce_span (ctx, span2, reduce3, resource_types2,
7, removed);
avail2 = planner_multi_avail_resources_at (ctx, 0, 2);
bo = (bo || avail2 != 27 || removed || rc != -1);
ok (!bo, "incorrect resource type reduction does not change availability");

removed = false;
rc = planner_multi_reduce_span (ctx, span2, reduce4, resource_types3,
5, removed);
avail2 = planner_multi_avail_resources_at (ctx, 0, 3);
bo = (bo || avail2 != 39 || removed || rc != 0);
ok (!bo, "reordered partial reduction results in correct availability");

removed = false;
rc = planner_multi_reduce_span (ctx, span2, reduce5, resource_types4,
1, removed);
avail2 = planner_multi_avail_resources_at (ctx, 0, 3);
bo = (bo || avail2 != 40 || !removed || rc != 0);
ok (!bo, "removing final span resource completely removes span");

span3 = planner_multi_add_span (ctx, 0, 2000, resource_totals, len);
avail1 = planner_multi_avail_resources_at (ctx, 1000, 0);
avail2 = planner_multi_avail_resources_at (ctx, 1000, 1);
avail3 = planner_multi_avail_resources_at (ctx, 1000, 2);
avail4 = planner_multi_avail_resources_at (ctx, 1000, 3);
avail5 = planner_multi_avail_resources_at (ctx, 1000, 4);
bo = (bo || avail1 != 0 || avail2 != 0 || avail3 != 0 || avail4 != 0
|| avail5 != 0 || !removed || rc != 0);
ok (!bo, "can fully allocate resources after partial removals");

planner_multi_destroy (&ctx);

return 0;

}

int main (int argc, char *argv[])
{
plan (98);
plan (105);

test_multi_basics ();

Expand All @@ -719,6 +802,8 @@ int main (int argc, char *argv[])

test_multi_update ();

test_partial_cancel ();

done_testing ();

return EXIT_SUCCESS;
Expand Down

0 comments on commit 7adf989

Please sign in to comment.