parjob registers sched_allocator_run with parjob_alloc_iface (accepts maxTasks > 1, bug-1767, plus its plan iterator); its private my_alloc() and claim helpers are gone. Characterization now pins the intended changes: a reason for every short host (2/6/5) and the bug-1893 shared reason. No other test expectation changed. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
798 lines
27 KiB
C
798 lines
27 KiB
C
/* test_alloc_equivalence_parjob.c - scheduler-allocator-runner 2.2/4.1:
|
|
* parjob through plugin->job_alloc_fn only (Req 2.2, 3.6, 3.7, 4.5, 5.1,
|
|
* 5.2, 5.4, 5.8, 7.2). OOM injection as test_alloc_equivalence_seqjob.c:
|
|
* sched_make_allocs() (hosts in claim order, then shared) and --wrap'ed
|
|
* make_host_alloc/make_job_alloc fail on call N. No bug-1892 layouts. */
|
|
#include <errno.h>
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
|
|
#include <unity/unity.h>
|
|
|
|
#include "preason.h"
|
|
#include "resobj.h"
|
|
#include "resreq.h"
|
|
#include "sched/alloc_iter.h"
|
|
#include "scheduler.h"
|
|
#include "xcealloc.h"
|
|
#include "xstring.h"
|
|
|
|
/* White-box sources under test. */
|
|
#include "../src/core.c"
|
|
#include "../src/resource.c"
|
|
#include "../src/schedobj.c"
|
|
#include "../src/host_iter.c"
|
|
#include "../src/alloc_runner.c"
|
|
#include "../src/plugins/parjob_allocator.c"
|
|
|
|
/* Link-satisfying stubs (same convention as test_seqjob_allocator.c). */
|
|
int plugin_register(void* s, void* p) { return (void)s, (void)p, 0; }
|
|
void plugin_unregister(void* arg) { (void)arg; }
|
|
|
|
/* plugin.c's fan-out, parjob's hook only; resets as plugin.c (bug-1883). */
|
|
int plugin_prepare_allocation(xce_sched_core_t* sched, xce_sched_ctx_t* ctx)
|
|
{
|
|
xce_sched_plugin_t fake_plugin;
|
|
|
|
if (ctx->worker == NULL) {
|
|
xvec_idval_fini(&(ctx->alloc_req.shared));
|
|
xvec_idval_init(&(ctx->alloc_req.shared), 8);
|
|
}
|
|
xvec_idval_fini(&(ctx->alloc_req.host));
|
|
xvec_idval_init(&(ctx->alloc_req.host), 8);
|
|
|
|
memset(&fake_plugin, 0, sizeof(fake_plugin));
|
|
fake_plugin.sched = sched;
|
|
fake_plugin.core = sched;
|
|
|
|
return parjob_prepare_allocation(&fake_plugin, ctx);
|
|
}
|
|
|
|
int plugin_job_update(void* s, xce_sched_job_t* j)
|
|
{
|
|
return (void)s, (void)j, 0;
|
|
}
|
|
|
|
int plugin_queue_update(void* s, xce_sched_queue_t* q)
|
|
{
|
|
return (void)s, (void)q, 0;
|
|
}
|
|
|
|
int plugin_job_rusage_update(void* s, xce_sched_job_t* j, xce_job_rusages_t* r)
|
|
{
|
|
return (void)s, (void)j, (void)r, 0;
|
|
}
|
|
|
|
/* Counters count every call; fail_on N > 0 fails call N (NULL, ENOMEM). */
|
|
static struct {
|
|
int make_allocs_calls, make_allocs_fail_on;
|
|
int host_alloc_calls, host_alloc_fail_on;
|
|
int job_alloc_calls, job_alloc_fail_on;
|
|
} g;
|
|
|
|
static void oom_injection_reset(void) { memset(&g, 0, sizeof(g)); }
|
|
|
|
/* scheduler.c's sched_make_allocs(): real make_alloc() records (duration -1
|
|
* for a NULL duration array, instid 0); NULL for nres <= 0 as the real one. */
|
|
xce_alloc_t** sched_make_allocs(xce_scheduler_t* sched, char* reserve,
|
|
int nres, int* idxs, float* vals,
|
|
int* duration)
|
|
{
|
|
xce_alloc_t** allocs;
|
|
int i;
|
|
|
|
g.make_allocs_calls++;
|
|
if ((g.make_allocs_fail_on > 0)
|
|
&& (g.make_allocs_calls == g.make_allocs_fail_on)) {
|
|
errno = ENOMEM;
|
|
return NULL;
|
|
}
|
|
|
|
if ((sched == NULL) || (nres <= 0) || (idxs == NULL) || (vals == NULL)) {
|
|
errno = EINVAL;
|
|
return NULL;
|
|
}
|
|
|
|
allocs = (xce_alloc_t**)calloc(nres, sizeof(*allocs));
|
|
if (allocs == NULL) {
|
|
return NULL;
|
|
}
|
|
|
|
for (i = 0; i < nres; i++) {
|
|
xce_resource_t* r = NULL;
|
|
|
|
vget(sched->core.resmgr, idxs[i], (void**)&r);
|
|
if (r == NULL) {
|
|
continue;
|
|
}
|
|
allocs[i] = make_alloc(r->name, reserve, 0, vals[i],
|
|
(duration != NULL) ? duration[i] : -1);
|
|
if (allocs[i] == NULL) {
|
|
free_ResAlloc_list(nres, allocs);
|
|
errno = ENOMEM;
|
|
return NULL;
|
|
}
|
|
}
|
|
|
|
return allocs;
|
|
}
|
|
|
|
xce_host_alloc_t* __real_make_host_alloc(char*, int, xce_alloc_t**);
|
|
xce_job_alloc_t* __real_make_job_alloc(uint64_t, int, xce_host_alloc_t**);
|
|
|
|
xce_host_alloc_t* __wrap_make_host_alloc(char* host, int nalloc,
|
|
xce_alloc_t** allocs)
|
|
{
|
|
g.host_alloc_calls++;
|
|
if ((g.host_alloc_fail_on > 0)
|
|
&& (g.host_alloc_calls == g.host_alloc_fail_on)) {
|
|
errno = ENOMEM;
|
|
return NULL;
|
|
}
|
|
return __real_make_host_alloc(host, nalloc, allocs);
|
|
}
|
|
|
|
xce_job_alloc_t* __wrap_make_job_alloc(uint64_t jobid, int nhost,
|
|
xce_host_alloc_t** hallocs)
|
|
{
|
|
g.job_alloc_calls++;
|
|
if ((g.job_alloc_fail_on > 0)
|
|
&& (g.job_alloc_calls == g.job_alloc_fail_on)) {
|
|
errno = ENOMEM;
|
|
return NULL;
|
|
}
|
|
return __real_make_job_alloc(jobid, nhost, hallocs);
|
|
}
|
|
|
|
void setUp(void) { oom_injection_reset(); }
|
|
void tearDown(void) { oom_injection_reset(); }
|
|
|
|
#define HOST_A "pq-host-a"
|
|
#define HOST_B "pq-host-b"
|
|
#define HOST_C "pq-host-c"
|
|
|
|
typedef struct {
|
|
xce_scheduler_t sched;
|
|
xce_resource_t* slots;
|
|
xce_resource_t* mem;
|
|
xce_resource_t* rack;
|
|
xce_resource_t* lic; /* shared (XCE_RESF_GLOBAL) */
|
|
xce_resource_t* tok; /* shared, pool 10, not requested by eq_run */
|
|
xce_sched_plugin_t* plugin;
|
|
xce_sched_obj_t obj;
|
|
xce_primary_schedobj_t primary_obj;
|
|
xce_sched_ctx_t ctx;
|
|
int ctx_ready;
|
|
} eq_fixture_t;
|
|
|
|
/* One primary request: `mem` per task, `lic` per job (0 = not requested),
|
|
* optional `rack == N` select. */
|
|
typedef struct {
|
|
xce_primary_resreq_t req;
|
|
rusage_value_t mem_rusage;
|
|
rusage_value_t lic_rusage;
|
|
xce_select_t select;
|
|
xce_select_node_t sel_res, sel_num, sel_eq;
|
|
} eq_primary_t;
|
|
|
|
/* Shared pools "licenses" (`lic_total`) and "tokens" (10), none in use. */
|
|
static void eq_fixture_init(eq_fixture_t* f, float lic_total)
|
|
{
|
|
int idx[2];
|
|
float val[2];
|
|
|
|
memset(f, 0, sizeof(*f));
|
|
TEST_ASSERT_EQUAL_INT(0, xce_sched_core_init(&(f->sched.core)));
|
|
/* xce_sched_core_fini() finalizes these; both drivers calloc them */
|
|
for (idx[0] = 0; idx[0] < 2; idx[0]++) {
|
|
f->sched.core.pend_updates[idx[0]]
|
|
= (dataq_t*)calloc(1, sizeof(dataq_t));
|
|
TEST_ASSERT_NOT_NULL(f->sched.core.pend_updates[idx[0]]);
|
|
dataq_init(f->sched.core.pend_updates[idx[0]], NULL);
|
|
}
|
|
|
|
#define EQ_RES(n, fl) \
|
|
makeResource(f->sched.core.resmgr, &(xce_resource_t){ .name = (char*)n, \
|
|
.flags = fl })
|
|
f->slots = EQ_RES("slots", 0);
|
|
f->mem = EQ_RES("mem", 0);
|
|
f->rack = EQ_RES("rack", 0);
|
|
f->lic = EQ_RES("licenses", XCE_RESF_GLOBAL);
|
|
f->tok = EQ_RES("tokens", XCE_RESF_GLOBAL);
|
|
#undef EQ_RES
|
|
TEST_ASSERT_NOT_NULL(f->slots);
|
|
TEST_ASSERT_NOT_NULL(f->mem);
|
|
TEST_ASSERT_NOT_NULL(f->rack);
|
|
TEST_ASSERT_NOT_NULL(f->lic);
|
|
TEST_ASSERT_NOT_NULL(f->tok);
|
|
|
|
idx[0] = f->lic->idx;
|
|
val[0] = lic_total;
|
|
idx[1] = f->tok->idx;
|
|
val[1] = 10.0f;
|
|
put_resvals(&(f->sched.core.sharedInst), 2, idx, val);
|
|
|
|
f->plugin = parjob_allocator_new_plugin();
|
|
TEST_ASSERT_NOT_NULL(f->plugin);
|
|
TEST_ASSERT_NOT_NULL(f->plugin->job_alloc_fn);
|
|
f->plugin->sched = &(f->sched);
|
|
f->plugin->core = &(f->sched.core);
|
|
}
|
|
|
|
static xce_sched_worker_t* eq_add_host(eq_fixture_t* f, const char* name,
|
|
float slots, float mem, float rack)
|
|
{
|
|
xce_sched_worker_t* w;
|
|
int idx[3] = { f->slots->idx, f->mem->idx, f->rack->idx };
|
|
float total[3] = { slots, mem, rack };
|
|
float inuse[2] = { 0.0f, 0.0f };
|
|
|
|
w = (xce_sched_worker_t*)calloc(1, sizeof(*w));
|
|
TEST_ASSERT_NOT_NULL(w);
|
|
w->name = makeString((char*)name);
|
|
TEST_ASSERT_NOT_NULL(w->name);
|
|
zarray_init(&(w->resvals), 8, (zarray_item_killer_t)kill_sched_resval);
|
|
zarray_init(&(w->resInUse), 8, (zarray_item_killer_t)kill_sched_resval);
|
|
put_resvals(&(w->resvals), 3, idx, total);
|
|
put_resvals(&(w->resInUse), 2, idx, inuse);
|
|
|
|
TEST_ASSERT_TRUE(sched_add_worker(&(f->sched.core), w) >= 0);
|
|
|
|
return w;
|
|
}
|
|
|
|
static void eq_primary_init(eq_primary_t* p, int max_tasks, float mem,
|
|
float lic, const eq_fixture_t* f, int rack)
|
|
{
|
|
memset(p, 0, sizeof(*p));
|
|
p->req.minTasks = (max_tasks > 0) ? 1 : 0;
|
|
p->req.maxTasks = max_tasks;
|
|
xlist_init(&(p->req.rusages), 4);
|
|
|
|
if (mem > 0.0f) {
|
|
p->mem_rusage.res = (char*)"mem";
|
|
p->mem_rusage.value = mem;
|
|
p->mem_rusage.per_flag = PER_TASK;
|
|
xlist_store(&(p->req.rusages), &(p->mem_rusage));
|
|
}
|
|
if (lic > 0.0f) {
|
|
p->lic_rusage.res = (char*)"licenses";
|
|
p->lic_rusage.value = lic;
|
|
p->lic_rusage.per_flag = PER_JOB;
|
|
xlist_store(&(p->req.rusages), &(p->lic_rusage));
|
|
}
|
|
if (rack > 0) {
|
|
p->sel_res.type = SEL_RESNAME;
|
|
p->sel_res.u.resname.res_idx = f->rack->idx;
|
|
p->sel_res.u.resname.res_type = RES_TYPE_NUMERIC;
|
|
p->sel_num.type = SEL_NUM;
|
|
p->sel_num.u.numval = (double)rack;
|
|
p->sel_eq.type = SEL_EQ;
|
|
p->sel_eq.u.binop.left = &(p->sel_res);
|
|
p->sel_eq.u.binop.right = &(p->sel_num);
|
|
p->select.root = &(p->sel_eq);
|
|
p->req.select = &(p->select);
|
|
}
|
|
}
|
|
|
|
/* ctx over a PRIMARY obj for `p`, job-level prepare pass included, exactly
|
|
* as sched_make_primary_allocation() drives it. */
|
|
static void eq_ctx_begin_primary(eq_fixture_t* f, eq_primary_t* p)
|
|
{
|
|
f->primary_obj.resreq = &(p->req);
|
|
f->obj.tag = XCE_RESREQ_PRIMARY;
|
|
f->obj.u.primary = &(f->primary_obj);
|
|
|
|
TEST_ASSERT_EQUAL_INT(0, sched_ctx_init(&(f->ctx), &(f->sched.core),
|
|
&(f->obj)));
|
|
f->ctx_ready = 1;
|
|
sched_ctx_set_primary(&(f->ctx), &(p->req));
|
|
}
|
|
|
|
static int eq_alloc(eq_fixture_t* f)
|
|
{
|
|
return f->plugin->job_alloc_fn(f->plugin, &(f->ctx));
|
|
}
|
|
|
|
static void eq_fixture_fini(eq_fixture_t* f)
|
|
{
|
|
if (f->ctx_ready) {
|
|
free_JobAlloc_ptr(&(f->ctx.alloc));
|
|
free_PendReason_ptr(&(f->ctx.reason));
|
|
sched_ctx_fini(&(f->ctx));
|
|
}
|
|
f->plugin->fini_fn(f->plugin);
|
|
xce_sched_core_fini(&(f->sched.core));
|
|
/* xce_sched_core_init() creates the process-wide string table on every
|
|
* call and xce_sched_core_fini() leaves it; release it per fixture */
|
|
xstring_table_fini();
|
|
}
|
|
|
|
static void eq_primary_fini(eq_primary_t* p) { xlist_fini(&(p->req.rusages)); }
|
|
|
|
static void eq_finish(eq_fixture_t* f, eq_primary_t* p)
|
|
{
|
|
eq_fixture_fini(f);
|
|
eq_primary_fini(p);
|
|
}
|
|
|
|
static float eq_host_uncomit(eq_fixture_t* f, xce_sched_worker_t* w,
|
|
xce_resource_t* r)
|
|
{
|
|
xvec_t* v = (xvec_t*)zarray_get(&(f->ctx.uncomitted.hosts), w->idx);
|
|
|
|
return (v == NULL) ? 0.0f : ((float*)v->data)[r->idx];
|
|
}
|
|
|
|
/* Per-host debit left in the attempt context: mem then slots. */
|
|
static void eq_assert_debit(eq_fixture_t* f, xce_sched_worker_t* w, float mem,
|
|
float slots)
|
|
{
|
|
TEST_ASSERT_EQUAL_FLOAT(mem, eq_host_uncomit(f, w, f->mem));
|
|
TEST_ASSERT_EQUAL_FLOAT(slots, eq_host_uncomit(f, w, f->slots));
|
|
}
|
|
|
|
static float eq_shared_uncomit(eq_fixture_t* f)
|
|
{
|
|
return ((float*)f->ctx.uncomitted.shared->data)[f->lic->idx];
|
|
}
|
|
|
|
static void eq_assert_record(xce_alloc_t* a, const char* resname, float value)
|
|
{
|
|
TEST_ASSERT_NOT_NULL(a);
|
|
TEST_ASSERT_EQUAL_STRING(resname, a->resname);
|
|
TEST_ASSERT_EQUAL_STRING("", a->reserve);
|
|
TEST_ASSERT_EQUAL_FLOAT(value, a->value);
|
|
TEST_ASSERT_EQUAL_INT(-1, a->duration);
|
|
}
|
|
|
|
/* One host allocation carrying mem then the bucket's slot count. */
|
|
static void eq_assert_host(xce_host_alloc_t* ha, const char* host, float mem,
|
|
float slots)
|
|
{
|
|
TEST_ASSERT_NOT_NULL(ha);
|
|
TEST_ASSERT_EQUAL_STRING(host, ha->host);
|
|
TEST_ASSERT_EQUAL_INT(2, ha->nallocs);
|
|
TEST_ASSERT_NOT_NULL(ha->allocs);
|
|
eq_assert_record(ha->allocs[0], "mem", mem);
|
|
eq_assert_record(ha->allocs[1], "slots", slots);
|
|
}
|
|
|
|
static void eq_assert_reason_counts(eq_fixture_t* f, int main_reason,
|
|
int nhost, int nres)
|
|
{
|
|
TEST_ASSERT_NOT_NULL(f->ctx.reason);
|
|
TEST_ASSERT_NOT_NULL(f->ctx.reason->reasons);
|
|
TEST_ASSERT_EQUAL_INT(main_reason, f->ctx.reason->reasons->main_reason);
|
|
TEST_ASSERT_EQUAL_INT(nhost, f->ctx.reason->reasons->nhost_reasons);
|
|
TEST_ASSERT_EQUAL_INT(nres, f->ctx.reason->reasons->nres_reasons);
|
|
}
|
|
|
|
static void eq_assert_res_reason(eq_fixture_t* f, int i, const char* host,
|
|
const char* res)
|
|
{
|
|
xce_res_reason_t* rr = f->ctx.reason->reasons->res_based_reasons[i];
|
|
|
|
TEST_ASSERT_NOT_NULL(rr);
|
|
TEST_ASSERT_EQUAL_STRING(host, rr->host);
|
|
TEST_ASSERT_EQUAL_STRING(res, rr->resource);
|
|
TEST_ASSERT_EQUAL_INT(PREASON_NO_RESOURCE, rr->reason);
|
|
}
|
|
|
|
static void eq_assert_calls(int make_allocs, int host_alloc, int job_alloc)
|
|
{
|
|
TEST_ASSERT_EQUAL_INT(make_allocs, g.make_allocs_calls);
|
|
TEST_ASSERT_EQUAL_INT(host_alloc, g.host_alloc_calls);
|
|
TEST_ASSERT_EQUAL_INT(job_alloc, g.job_alloc_calls);
|
|
}
|
|
|
|
/* `pool` licenses; hosts A, B, C (rack 1) with the given slots and mem; a
|
|
* job of `tasks` tasks, `task_mem` mem per task, `lic` licenses per job. */
|
|
typedef struct {
|
|
float pool;
|
|
int nhosts;
|
|
float slots[3], mem[3];
|
|
int tasks;
|
|
float task_mem, lic;
|
|
} eq_spec_t;
|
|
|
|
/* 1: plan [4] fails (slots), plan [2,2] claims A then B */
|
|
static const eq_spec_t EQ_TWO_BUCKETS = { 10, 2, { 2, 2 }, { 8, 8 }, 4, 1, 3 };
|
|
/* 2: 2 licenses, 3 wanted */
|
|
static const eq_spec_t EQ_SHORT_SHARED = { 2, 2, { 4, 4 }, { 8, 8 }, 2, 1, 3 };
|
|
/* 3: plans [2] and [1,1] both fail (mem, and slots for [2]) */
|
|
static const eq_spec_t EQ_SHORT_HOSTS = { 10, 2, { 1, 1 }, { 1, 1 }, 2, 4, 3 };
|
|
/* 4: [4] fails; [2,2] claims A, fails bucket 2, releases A; [2,1,1] wins */
|
|
static const eq_spec_t EQ_ROLLBACK
|
|
= { 10, 3, { 2, 1, 1 }, { 8, 8, 8 }, 4, 1, 3 };
|
|
|
|
static void eq_setup(eq_fixture_t* f, eq_primary_t* p, const eq_spec_t* s,
|
|
xce_sched_worker_t** w)
|
|
{
|
|
static const char* names[3] = { HOST_A, HOST_B, HOST_C };
|
|
int i;
|
|
|
|
eq_fixture_init(f, s->pool);
|
|
for (i = 0; i < s->nhosts; i++) {
|
|
w[i] = eq_add_host(f, names[i], s->slots[i], s->mem[i], 1.0f);
|
|
}
|
|
eq_primary_init(p, s->tasks, s->task_mem, s->lic, f, 0);
|
|
eq_ctx_begin_primary(f, p);
|
|
}
|
|
|
|
static int eq_run(eq_fixture_t* f, eq_primary_t* p, const eq_spec_t* s,
|
|
xce_sched_worker_t** w)
|
|
{
|
|
eq_setup(f, p, s, w);
|
|
return eq_alloc(f);
|
|
}
|
|
|
|
/* Main and host reasons none; at least `n` resource reasons. */
|
|
static void eq_assert_reason_prefix(eq_fixture_t* f, int n)
|
|
{
|
|
TEST_ASSERT_NOT_NULL(f->ctx.reason);
|
|
TEST_ASSERT_EQUAL_INT(0, f->ctx.reason->reasons->main_reason);
|
|
TEST_ASSERT_EQUAL_INT(0, f->ctx.reason->reasons->nhost_reasons);
|
|
TEST_ASSERT_TRUE(f->ctx.reason->reasons->nres_reasons >= n);
|
|
}
|
|
|
|
/* EQ_TWO_BUCKETS: plan [4] checks A first (slots short). */
|
|
static void eq_assert_plan1_reasons(eq_fixture_t* f)
|
|
{
|
|
eq_assert_reason_prefix(f, 1);
|
|
eq_assert_res_reason(f, 0, HOST_A, "slots");
|
|
}
|
|
|
|
/* 1. Multi-bucket success: two host allocations in claim order, each sized
|
|
* from its own bucket (2 tasks), one shared record. */
|
|
static void test_parjob_success_two_buckets_with_shared(void)
|
|
{
|
|
eq_fixture_t f;
|
|
eq_primary_t p;
|
|
xce_sched_worker_t* w[3];
|
|
|
|
TEST_ASSERT_EQUAL_INT(1, eq_run(&f, &p, &EQ_TWO_BUCKETS, w));
|
|
|
|
TEST_ASSERT_NOT_NULL(f.ctx.alloc);
|
|
TEST_ASSERT_EQUAL_UINT64(0, f.ctx.alloc->jobid);
|
|
TEST_ASSERT_EQUAL_INT(2, f.ctx.alloc->nhosts);
|
|
eq_assert_host(f.ctx.alloc->allocs[0], HOST_A, 2.0f, 2.0f);
|
|
eq_assert_host(f.ctx.alloc->allocs[1], HOST_B, 2.0f, 2.0f);
|
|
TEST_ASSERT_EQUAL_INT(1, f.ctx.alloc->nres_shared);
|
|
eq_assert_record(f.ctx.alloc->allocs_shared[0], "licenses", 3.0f);
|
|
|
|
eq_assert_debit(&f, w[0], 2.0f, 2.0f);
|
|
eq_assert_debit(&f, w[1], 2.0f, 2.0f);
|
|
TEST_ASSERT_EQUAL_FLOAT(3.0f, eq_shared_uncomit(&f));
|
|
|
|
eq_assert_plan1_reasons(&f);
|
|
eq_assert_calls(3, 2, 1);
|
|
|
|
eq_finish(&f, &p);
|
|
}
|
|
|
|
/* 2. Pending on the one shared resource the job requests, which is short:
|
|
* no host is tried and nothing is counted. */
|
|
static void test_parjob_pending_on_short_shared_resource(void)
|
|
{
|
|
eq_fixture_t f;
|
|
eq_primary_t p;
|
|
xce_sched_worker_t* w[3];
|
|
|
|
TEST_ASSERT_EQUAL_INT(0, eq_run(&f, &p, &EQ_SHORT_SHARED, w));
|
|
TEST_ASSERT_NULL(f.ctx.alloc);
|
|
TEST_ASSERT_NOT_NULL(f.ctx.reason);
|
|
TEST_ASSERT_EQUAL_INT(0, f.ctx.reason->reasons->main_reason);
|
|
TEST_ASSERT_EQUAL_INT(0, f.ctx.reason->reasons->nhost_reasons);
|
|
|
|
TEST_ASSERT_NULL(zarray_get(&(f.ctx.uncomitted.hosts), w[0]->idx));
|
|
TEST_ASSERT_NULL(zarray_get(&(f.ctx.uncomitted.hosts), w[1]->idx));
|
|
TEST_ASSERT_EQUAL_FLOAT(0.0f, eq_shared_uncomit(&f));
|
|
eq_assert_calls(0, 0, 0);
|
|
|
|
eq_finish(&f, &p);
|
|
}
|
|
|
|
/* 2, resource reasons (Req 2.2, bug-1893): two shared resources requested,
|
|
* only "licenses" short: exactly one host-less reason, naming it. */
|
|
static void test_parjob_pending_on_short_shared_names_short_one(void)
|
|
{
|
|
eq_fixture_t f;
|
|
eq_primary_t p;
|
|
rusage_value_t tok = { .res = (char*)"tokens", .value = 1.0f };
|
|
|
|
eq_fixture_init(&f, EQ_SHORT_SHARED.pool);
|
|
eq_add_host(&f, HOST_A, 4.0f, 8.0f, 1.0f);
|
|
eq_primary_init(&p, 2, 1.0f, 3.0f, &f, 0);
|
|
tok.per_flag = PER_JOB;
|
|
xlist_store(&(p.req.rusages), &tok);
|
|
eq_ctx_begin_primary(&f, &p);
|
|
|
|
TEST_ASSERT_EQUAL_INT(0, eq_alloc(&f));
|
|
eq_assert_reason_counts(&f, 0, 0, 1);
|
|
eq_assert_res_reason(&f, 0, "", "licenses"); /* host-less: "" */
|
|
|
|
eq_finish(&f, &p);
|
|
}
|
|
|
|
/* 3. Pending on hosts: no debit remains; the met shared request stays
|
|
* counted as uncommitted. */
|
|
static void test_parjob_pending_on_hosts(void)
|
|
{
|
|
eq_fixture_t f;
|
|
eq_primary_t p;
|
|
xce_sched_worker_t* w[3];
|
|
|
|
TEST_ASSERT_EQUAL_INT(0, eq_run(&f, &p, &EQ_SHORT_HOSTS, w));
|
|
TEST_ASSERT_NULL(f.ctx.alloc);
|
|
|
|
/* plan [2]'s first candidate A */
|
|
eq_assert_reason_prefix(&f, 2);
|
|
eq_assert_res_reason(&f, 0, HOST_A, "mem");
|
|
eq_assert_res_reason(&f, 1, HOST_A, "slots");
|
|
|
|
eq_assert_debit(&f, w[0], 0.0f, 0.0f);
|
|
eq_assert_debit(&f, w[1], 0.0f, 0.0f);
|
|
TEST_ASSERT_EQUAL_FLOAT(3.0f, eq_shared_uncomit(&f));
|
|
eq_assert_calls(0, 0, 0);
|
|
|
|
eq_finish(&f, &p);
|
|
}
|
|
|
|
/* 4. Mid-plan rollback, then a later plan wins: only the winning plan's
|
|
* debits remain (A holds 2 slots, not 4). */
|
|
static void test_parjob_mid_plan_rollback_then_later_plan_wins(void)
|
|
{
|
|
eq_fixture_t f;
|
|
eq_primary_t p;
|
|
xce_sched_worker_t* w[3];
|
|
|
|
TEST_ASSERT_EQUAL_INT(1, eq_run(&f, &p, &EQ_ROLLBACK, w));
|
|
|
|
TEST_ASSERT_NOT_NULL(f.ctx.alloc);
|
|
TEST_ASSERT_EQUAL_INT(3, f.ctx.alloc->nhosts);
|
|
eq_assert_host(f.ctx.alloc->allocs[0], HOST_A, 2.0f, 2.0f);
|
|
eq_assert_host(f.ctx.alloc->allocs[1], HOST_B, 1.0f, 1.0f);
|
|
eq_assert_host(f.ctx.alloc->allocs[2], HOST_C, 1.0f, 1.0f);
|
|
TEST_ASSERT_EQUAL_INT(1, f.ctx.alloc->nres_shared);
|
|
eq_assert_record(f.ctx.alloc->allocs_shared[0], "licenses", 3.0f);
|
|
|
|
eq_assert_debit(&f, w[0], 2.0f, 2.0f);
|
|
eq_assert_debit(&f, w[1], 1.0f, 1.0f);
|
|
eq_assert_debit(&f, w[2], 1.0f, 1.0f);
|
|
TEST_ASSERT_EQUAL_FLOAT(3.0f, eq_shared_uncomit(&f));
|
|
|
|
/* A then B, slots: plan [4]'s first two checks */
|
|
eq_assert_reason_prefix(&f, 2);
|
|
eq_assert_res_reason(&f, 0, HOST_A, "slots");
|
|
eq_assert_res_reason(&f, 1, HOST_B, "slots");
|
|
eq_assert_calls(4, 3, 1);
|
|
|
|
eq_finish(&f, &p);
|
|
}
|
|
|
|
static void eq_assert_reasons(eq_fixture_t* f, int n, const char** pairs)
|
|
{
|
|
int i;
|
|
|
|
eq_assert_reason_counts(f, 0, 0, n);
|
|
for (i = 0; i < n; i++) {
|
|
eq_assert_res_reason(f, i, pairs[2 * i], pairs[(2 * i) + 1]);
|
|
}
|
|
}
|
|
|
|
/* 1, 3, 4: host reasons (Req 3.6/3.7): exactly one per short resource of
|
|
* every selection-matching unclaimed short host of each bucket search. */
|
|
static void test_parjob_host_reasons_every_short_host(void)
|
|
{
|
|
static const char* two[] = { HOST_A, "slots", HOST_B, "slots" };
|
|
static const char* hosts[]
|
|
= { HOST_A, "mem", HOST_A, "slots", HOST_B, "mem",
|
|
HOST_B, "slots", HOST_A, "mem", HOST_B, "mem" };
|
|
static const char* back[] = { HOST_A, "slots", HOST_B, "slots", HOST_C,
|
|
"slots", HOST_B, "slots", HOST_C, "slots" };
|
|
eq_fixture_t f;
|
|
eq_primary_t p;
|
|
xce_sched_worker_t* w[3];
|
|
|
|
TEST_ASSERT_EQUAL_INT(1, eq_run(&f, &p, &EQ_TWO_BUCKETS, w));
|
|
eq_assert_reasons(&f, 2, two);
|
|
eq_finish(&f, &p);
|
|
|
|
TEST_ASSERT_EQUAL_INT(0, eq_run(&f, &p, &EQ_SHORT_HOSTS, w));
|
|
eq_assert_reasons(&f, 6, hosts);
|
|
eq_finish(&f, &p);
|
|
|
|
TEST_ASSERT_EQUAL_INT(1, eq_run(&f, &p, &EQ_ROLLBACK, w));
|
|
eq_assert_reasons(&f, 5, back);
|
|
eq_finish(&f, &p);
|
|
}
|
|
|
|
/* One host (4 slots, 8 mem), 10 licenses; 2 tasks of 1 mem, 3 licenses. */
|
|
static const eq_spec_t EQ_ONE_HOST = { 10, 1, { 4 }, { 8 }, 2, 1, 3 };
|
|
|
|
/* Nothing checked, counted or built, and no pend-reason record. */
|
|
static void eq_assert_untouched(eq_fixture_t* f, xce_sched_worker_t* a)
|
|
{
|
|
TEST_ASSERT_NULL(f->ctx.alloc);
|
|
TEST_ASSERT_NULL(f->ctx.reason);
|
|
TEST_ASSERT_NULL(zarray_get(&(f->ctx.uncomitted.hosts), a->idx));
|
|
TEST_ASSERT_EQUAL_FLOAT(0.0f, eq_shared_uncomit(f));
|
|
eq_assert_calls(0, 0, 0);
|
|
}
|
|
|
|
/* 5. A task count of 0 or 1 reaching parjob directly (bug-1767, Req 5.2):
|
|
* pending, no pend-reason record, no resource check. */
|
|
static void test_parjob_task_count_zero_and_one_pend_without_reason(void)
|
|
{
|
|
int tasks;
|
|
|
|
for (tasks = 0; tasks <= 1; tasks++) {
|
|
eq_fixture_t f;
|
|
eq_primary_t p;
|
|
xce_sched_worker_t* w[3];
|
|
eq_spec_t s = EQ_ONE_HOST;
|
|
|
|
s.tasks = tasks;
|
|
TEST_ASSERT_EQUAL_INT(0, eq_run(&f, &p, &s, w));
|
|
eq_assert_untouched(&f, w[0]);
|
|
eq_finish(&f, &p);
|
|
}
|
|
}
|
|
|
|
/* 6. Missing core, scheduler back-reference or primary (Req 5.1):
|
|
* -EINVAL, no pend-reason record, nothing checked or counted. */
|
|
static void test_parjob_missing_input_einval_no_reason(void)
|
|
{
|
|
int which;
|
|
|
|
for (which = 0; which < 3; which++) {
|
|
eq_fixture_t f;
|
|
eq_primary_t p;
|
|
xce_sched_worker_t* w[3];
|
|
|
|
eq_setup(&f, &p, &EQ_ONE_HOST, w);
|
|
if (which == 0) {
|
|
f.plugin->core = NULL;
|
|
} else if (which == 1) {
|
|
f.plugin->sched = NULL;
|
|
} else {
|
|
f.ctx.primary = NULL;
|
|
}
|
|
|
|
TEST_ASSERT_EQUAL_INT(-EINVAL, eq_alloc(&f));
|
|
eq_assert_untouched(&f, w[0]);
|
|
eq_finish(&f, &p);
|
|
}
|
|
}
|
|
|
|
/* 7. OOM building EQ_TWO_BUCKETS' result (claims A then B). Host stage:
|
|
* unconverted claims released, converted ones keep their debit; job alloc
|
|
* and shared records: every debit stays (design Error table). `a_kept` /
|
|
* `b_kept`: whether A's / B's debit (2 mem, 2 slots) remains. Steps: host
|
|
* 0/1 records (sched_make_allocs() 1/2), make_host_alloc() 1/2,
|
|
* make_job_alloc(), shared records (sched_make_allocs() 3). */
|
|
static void eq_check_oom(int make_allocs_fail_on, int host_alloc_fail_on,
|
|
int job_alloc_fail_on, int a_kept, int b_kept,
|
|
int make_allocs, int host_alloc, int job_alloc)
|
|
{
|
|
eq_fixture_t f;
|
|
eq_primary_t p;
|
|
xce_sched_worker_t* w[3];
|
|
|
|
g.make_allocs_fail_on = make_allocs_fail_on;
|
|
g.host_alloc_fail_on = host_alloc_fail_on;
|
|
g.job_alloc_fail_on = job_alloc_fail_on;
|
|
|
|
TEST_ASSERT_EQUAL_INT(-ENOMEM, eq_run(&f, &p, &EQ_TWO_BUCKETS, w));
|
|
TEST_ASSERT_NULL(f.ctx.alloc);
|
|
|
|
eq_assert_debit(&f, w[0], a_kept ? 2.0f : 0.0f, a_kept ? 2.0f : 0.0f);
|
|
eq_assert_debit(&f, w[1], b_kept ? 2.0f : 0.0f, b_kept ? 2.0f : 0.0f);
|
|
TEST_ASSERT_EQUAL_FLOAT(3.0f, eq_shared_uncomit(&f));
|
|
eq_assert_plan1_reasons(&f);
|
|
eq_assert_calls(make_allocs, host_alloc, job_alloc);
|
|
|
|
eq_finish(&f, &p);
|
|
}
|
|
|
|
/* One named test per injected step: fail-on counts, kept debits, calls. */
|
|
#define EQ_OOM_TEST(name, ...) \
|
|
static void name(void) { eq_check_oom(__VA_ARGS__); }
|
|
EQ_OOM_TEST(test_parjob_oom_records_host0_releases_all,
|
|
1, 0, 0, 0, 0, 1, 0, 0)
|
|
EQ_OOM_TEST(test_parjob_oom_records_later_host_releases_unconverted,
|
|
2, 0, 0, 1, 0, 2, 1, 0)
|
|
EQ_OOM_TEST(test_parjob_oom_host_alloc0_releases_all,
|
|
0, 1, 0, 0, 0, 1, 1, 0)
|
|
EQ_OOM_TEST(test_parjob_oom_host_alloc_later_releases_unconverted,
|
|
0, 2, 0, 1, 0, 2, 2, 0)
|
|
EQ_OOM_TEST(test_parjob_oom_job_alloc_debits_stay,
|
|
0, 0, 1, 1, 1, 2, 2, 1)
|
|
EQ_OOM_TEST(test_parjob_oom_shared_records_debits_stay,
|
|
3, 0, 0, 1, 1, 3, 2, 1)
|
|
|
|
/* 8. COMPOUND: two primaries in turn on one ctx (sched_make_compound_alloc_);
|
|
* rack 1 / rack 2 selects keep them apart. Each sized from its own request
|
|
* (Req 5.8): 2 x 1 mem + 3 licenses on A, 3 x 2 mem on B. */
|
|
static void test_parjob_compound_second_primary_sized_from_own_request(void)
|
|
{
|
|
eq_fixture_t f;
|
|
eq_primary_t p1;
|
|
eq_primary_t p2;
|
|
xce_compound_resreq_t cres;
|
|
xce_compound_schedobj_t cobj;
|
|
xce_job_alloc_t* first = NULL;
|
|
xce_sched_worker_t * a, *b;
|
|
|
|
eq_fixture_init(&f, 10.0f);
|
|
a = eq_add_host(&f, HOST_A, 2.0f, 8.0f, 1.0f);
|
|
b = eq_add_host(&f, HOST_B, 4.0f, 8.0f, 2.0f);
|
|
eq_primary_init(&p1, 2, 1.0f, 3.0f, &f, 1);
|
|
eq_primary_init(&p2, 3, 2.0f, 0.0f, &f, 2);
|
|
|
|
xlist_init(&(cres.primaries), 2);
|
|
xlist_store(&(cres.primaries), &(p1.req));
|
|
xlist_store(&(cres.primaries), &(p2.req));
|
|
memset(&cobj, 0, sizeof(cobj));
|
|
cobj.owner = &(f.obj);
|
|
cobj.resreq = &cres;
|
|
f.obj.tag = XCE_RESREQ_COMPOUND;
|
|
f.obj.u.compound = &cobj;
|
|
|
|
TEST_ASSERT_EQUAL_INT(0, sched_ctx_init(&(f.ctx), &(f.sched.core),
|
|
&(f.obj)));
|
|
f.ctx_ready = 1;
|
|
|
|
sched_ctx_set_primary(&(f.ctx), &(p1.req));
|
|
TEST_ASSERT_EQUAL_INT(1, eq_alloc(&f));
|
|
MOVE_PTR(first, f.ctx.alloc);
|
|
|
|
sched_ctx_set_primary(&(f.ctx), &(p2.req));
|
|
TEST_ASSERT_EQUAL_INT(1, eq_alloc(&f));
|
|
|
|
TEST_ASSERT_NOT_NULL(first);
|
|
TEST_ASSERT_EQUAL_INT(1, first->nhosts);
|
|
eq_assert_host(first->allocs[0], HOST_A, 2.0f, 2.0f);
|
|
TEST_ASSERT_EQUAL_INT(1, first->nres_shared);
|
|
eq_assert_record(first->allocs_shared[0], "licenses", 3.0f);
|
|
|
|
TEST_ASSERT_NOT_NULL(f.ctx.alloc);
|
|
TEST_ASSERT_EQUAL_INT(1, f.ctx.alloc->nhosts);
|
|
eq_assert_host(f.ctx.alloc->allocs[0], HOST_B, 6.0f, 3.0f);
|
|
TEST_ASSERT_EQUAL_INT(0, f.ctx.alloc->nres_shared);
|
|
TEST_ASSERT_NULL(f.ctx.alloc->allocs_shared);
|
|
|
|
eq_assert_debit(&f, a, 2.0f, 2.0f);
|
|
eq_assert_debit(&f, b, 6.0f, 3.0f);
|
|
TEST_ASSERT_EQUAL_FLOAT(3.0f, eq_shared_uncomit(&f));
|
|
eq_assert_reason_counts(&f, 0, 0, 0);
|
|
eq_assert_calls(3, 2, 2);
|
|
|
|
free_JobAlloc_ptr(&first);
|
|
xlist_fini(&(cres.primaries));
|
|
eq_fixture_fini(&f);
|
|
eq_primary_fini(&p1);
|
|
eq_primary_fini(&p2);
|
|
}
|
|
|
|
int main(void)
|
|
{
|
|
UNITY_BEGIN();
|
|
RUN_TEST(test_parjob_success_two_buckets_with_shared);
|
|
RUN_TEST(test_parjob_pending_on_short_shared_resource);
|
|
RUN_TEST(test_parjob_pending_on_short_shared_names_short_one);
|
|
RUN_TEST(test_parjob_pending_on_hosts);
|
|
RUN_TEST(test_parjob_mid_plan_rollback_then_later_plan_wins);
|
|
RUN_TEST(test_parjob_host_reasons_every_short_host);
|
|
RUN_TEST(test_parjob_task_count_zero_and_one_pend_without_reason);
|
|
RUN_TEST(test_parjob_missing_input_einval_no_reason);
|
|
RUN_TEST(test_parjob_oom_records_host0_releases_all);
|
|
RUN_TEST(test_parjob_oom_records_later_host_releases_unconverted);
|
|
RUN_TEST(test_parjob_oom_host_alloc0_releases_all);
|
|
RUN_TEST(test_parjob_oom_host_alloc_later_releases_unconverted);
|
|
RUN_TEST(test_parjob_oom_job_alloc_debits_stay);
|
|
RUN_TEST(test_parjob_oom_shared_records_debits_stay);
|
|
RUN_TEST(test_parjob_compound_second_primary_sized_from_own_request);
|
|
return UNITY_END();
|
|
}
|