diff --git a/resource/planner/test/planner_test01.cpp b/resource/planner/test/planner_test01.cpp index 97793d715..6abc2516f 100644 --- a/resource/planner/test/planner_test01.cpp +++ b/resource/planner/test/planner_test01.cpp @@ -723,9 +723,62 @@ static int test_constructors_and_overload () return 0; } +static int test_update () +{ + int rc; + int64_t span; + bool bo = false; + uint64_t resource_total = 100000; + uint64_t resource1 = 36; + uint64_t resource2 = 3600; + uint64_t resource3 = 1800; + uint64_t resource4 = 2304; + uint64_t resource5 = 468; + uint64_t resource6 = 50000; + int64_t avail, avail1 = 0; + const char resource_type[] = "core"; + planner_t *ctx, *ctx2 = NULL; + + ctx = planner_new (0, INT64_MAX, resource_total, resource_type); + // Add some spans + planner_add_span (ctx, 0, 600, resource1); + planner_add_span (ctx, 0, 57600, resource2); + planner_add_span (ctx, 57600, 57600, resource3); + planner_add_span (ctx, 172800, 57600, resource4); + planner_add_span (ctx, 115200, 900, resource5); + + avail = planner_avail_resources_at (ctx, 0); + + ctx2 = planner_copy (ctx); + + rc = planner_update (ctx, 100000); + + bo = (bo || !(planners_equal (ctx, ctx))); + ok (!bo, "update with same resource count shouldn't change planner"); + + rc = planner_update (ctx, 50000); + avail1 = planner_avail_resources_at (ctx, 0); + bo = (bo || !(planners_equal (ctx, ctx))); + ok (!bo, "avail difference for valid reduction is correct"); + + rc = planner_update (ctx, 100000); + bo = (bo || !(planners_equal (ctx, ctx2))); + ok (!bo, "re-adding resources shouldn't change planner"); + + rc = planner_update (ctx, 40000); + span = planner_add_span (ctx, 1152000, 57600, resource6); + bo = (bo || (planners_equal (ctx, ctx2)) || span != -1); + ok (!bo, "reducing resources below request should prevent scheduling"); + + planner_destroy (&ctx); + planner_destroy (&ctx2); + + return 0; +} + int main (int argc, char *argv[]) { - plan (63); + plan (67); test_planner_getters (); @@ -749,6 +802,8 @@ int main (int argc, char *argv[]) test_constructors_and_overload (); + test_update (); + done_testing (); return EXIT_SUCCESS;