Skip to content

Commit 7ca4649

Browse files
committed
testsuite: add unit tests for planner_multi update
Problem: updating a `planner_multi` requires unit tests to maintain correct functionality. Add update unit tests for `planner_multi`.
1 parent a475d5e commit 7ca4649

File tree

1 file changed

+80
-1
lines changed

1 file changed

+80
-1
lines changed

resource/planner/test/planner_test02.cpp

Lines changed: 80 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -615,10 +615,87 @@ static int test_constructors_and_overload ()
615615

616616
}
617617

618+
static int test_multi_update ()
619+
{
620+
bool bo = false, found = true;
621+
size_t len = 5;
622+
size_t size = 0;
623+
int rc = -1;
624+
int64_t span = -1, avail = -1, avail1 = -1, total = -1;
625+
const uint64_t resource_totals[] = {10, 20, 30, 40, 50};
626+
const uint64_t resource_totals1[] = {5, 10, 20};
627+
const uint64_t resource_totals2[] = {10, 20, 30, 40, 50, 60, 70};
628+
const char *resource_types[] = {"A", "B", "C", "D", "E"};
629+
const char *resource_types1[] = {"B", "C", "D"};
630+
const char *resource_types2[] = {"B", "A", "C", "D", "G", "X", "Y"};
631+
const uint64_t request1[] = {1, 0, 0, 0, 0};
632+
const uint64_t request2[] = {0, 2, 0, 0, 0};
633+
const uint64_t request3[] = {0, 0, 3, 0, 0};
634+
const uint64_t request4[] = {0, 0, 20};
635+
const uint64_t request5[] = {0, 0, 21};
636+
const uint64_t request6[] = {10, 20, 30, 40, 50, 60, 70};
637+
planner_multi_t *ctx = NULL, *ctx2 = NULL;
638+
639+
ctx = planner_multi_new (0, INT64_MAX, resource_totals, resource_types, len);
640+
641+
planner_multi_add_span (ctx, 0, 1000, request1, len);
642+
span = planner_multi_add_span (ctx, 1000, 1000, request2, len);
643+
planner_multi_add_span (ctx, 2000, 1000, request3, len);
644+
avail = planner_multi_avail_resources_at (ctx, 0, 0);
645+
646+
ctx2 = planner_multi_copy (ctx);
647+
648+
rc = planner_multi_update (ctx, resource_totals, resource_types, len);
649+
avail1 = planner_multi_avail_resources_at (ctx, 0, 0);
650+
bo = (bo || !(planner_multis_equal (ctx, ctx2)) || avail != avail1 || rc != 0);
651+
ok (!bo, "update with same resource count shouldn't change planner_multi");
652+
653+
rc = planner_multi_update (ctx, resource_totals1, resource_types1, 3);
654+
avail1 = planner_multi_avail_resources_at (ctx, 1000, 0);
655+
bo = (bo || (planner_multis_equal (ctx, ctx2)) || avail1 != 3 || rc != 0);
656+
ok (!bo, "resource reduction results in expected resources and availability");
657+
658+
rc = planner_multi_update (ctx, resource_totals, resource_types, len);
659+
bo = (bo || (planner_multis_equal (ctx, ctx2)) || rc != 0);
660+
ok (!bo, "re-adding resources can't restore planner_multi state after removal");
661+
662+
rc = planner_multi_update (ctx, resource_totals1, resource_types1, 3);
663+
span = planner_multi_add_span (ctx, 2000, 1000, request4, 3);
664+
avail1 = planner_multi_avail_resources_at (ctx, 2000, 2);
665+
bo = (bo || avail1 != 0 || span == -1 || rc != 0);
666+
ok (!bo, "can allocate full updated resources");
667+
668+
span = planner_multi_add_span (ctx, 3000, 1000, request5, 3);
669+
avail1 = planner_multi_avail_resources_at (ctx, 3000, 2);
670+
bo = (bo || avail1 != 20 || span != -1 || rc != 0);
671+
ok (!bo, "can't overallocate updated resources");
672+
673+
rc = planner_multi_update (ctx, resource_totals2, resource_types2, 7);
674+
span = planner_multi_add_span (ctx, 4000, 1000, request6, 7);
675+
avail1 = planner_multi_avail_resources_at (ctx, 4000, 6);
676+
bo = (bo || avail1 != 0 || span == -1 || rc != 0);
677+
ok (!bo, "can allocate full added resources");
678+
679+
for (int i = 0; i < planner_multi_resources_len (ctx); ++i) {
680+
if (planner_multi_resource_total_by_type (ctx, resource_types2[i])
681+
!= resource_totals2[i]) {
682+
found = false;
683+
break;
684+
}
685+
}
686+
bo = (bo || !found);
687+
ok (!bo, "can look up resources by string");
688+
689+
planner_multi_destroy (&ctx);
690+
planner_multi_destroy (&ctx2);
691+
692+
return 0;
693+
694+
}
618695

619696
int main (int argc, char *argv[])
620697
{
621-
plan (91);
698+
plan (98);
622699

623700
test_multi_basics ();
624701

@@ -634,6 +711,8 @@ int main (int argc, char *argv[])
634711

635712
test_constructors_and_overload ();
636713

714+
test_multi_update ();
715+
637716
done_testing ();
638717

639718
return EXIT_SUCCESS;

0 commit comments

Comments
 (0)