Skip to content

Commit a475d5e

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

File tree

1 file changed

+56
-1
lines changed

1 file changed

+56
-1
lines changed

resource/planner/test/planner_test01.cpp

Lines changed: 56 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -723,9 +723,62 @@ static int test_constructors_and_overload ()
723723
return 0;
724724
}
725725

726+
static int test_update ()
727+
{
728+
int rc;
729+
int64_t span;
730+
bool bo = false;
731+
uint64_t resource_total = 100000;
732+
uint64_t resource1 = 36;
733+
uint64_t resource2 = 3600;
734+
uint64_t resource3 = 1800;
735+
uint64_t resource4 = 2304;
736+
uint64_t resource5 = 468;
737+
uint64_t resource6 = 50000;
738+
int64_t avail, avail1 = 0;
739+
const char resource_type[] = "core";
740+
planner_t *ctx, *ctx2 = NULL;
741+
742+
ctx = planner_new (0, INT64_MAX, resource_total, resource_type);
743+
// Add some spans
744+
planner_add_span (ctx, 0, 600, resource1);
745+
planner_add_span (ctx, 0, 57600, resource2);
746+
planner_add_span (ctx, 57600, 57600, resource3);
747+
planner_add_span (ctx, 172800, 57600, resource4);
748+
planner_add_span (ctx, 115200, 900, resource5);
749+
750+
avail = planner_avail_resources_at (ctx, 0);
751+
752+
ctx2 = planner_copy (ctx);
753+
754+
rc = planner_update_total (ctx, 100000);
755+
756+
bo = (bo || !(planners_equal (ctx, ctx)));
757+
ok (!bo, "update with same resource count shouldn't change planner");
758+
759+
rc = planner_update_total (ctx, 50000);
760+
avail1 = planner_avail_resources_at (ctx, 0);
761+
bo = (bo || !(planners_equal (ctx, ctx)));
762+
ok (!bo, "avail difference for valid reduction is correct");
763+
764+
rc = planner_update_total (ctx, 100000);
765+
bo = (bo || !(planners_equal (ctx, ctx2)));
766+
ok (!bo, "re-adding resources shouldn't change planner");
767+
768+
rc = planner_update_total (ctx, 40000);
769+
span = planner_add_span (ctx, 1152000, 57600, resource6);
770+
bo = (bo || (planners_equal (ctx, ctx2)) || span != -1);
771+
ok (!bo, "reducing resources below request should prevent scheduling");
772+
773+
planner_destroy (&ctx);
774+
planner_destroy (&ctx2);
775+
776+
return 0;
777+
}
778+
726779
int main (int argc, char *argv[])
727780
{
728-
plan (63);
781+
plan (67);
729782

730783
test_planner_getters ();
731784

@@ -749,6 +802,8 @@ int main (int argc, char *argv[])
749802

750803
test_constructors_and_overload ();
751804

805+
test_update ();
806+
752807
done_testing ();
753808

754809
return EXIT_SUCCESS;

0 commit comments

Comments
 (0)