feat: implement build_host_eval_ctx — project resvals zarray to host_eval_ctx_t (6-7)
This commit is contained in:
parent
acda9bb228
commit
907d8d80a3
3 changed files with 87 additions and 11 deletions
|
|
@ -4,7 +4,7 @@ scheduler_test_src = [
|
|||
|
||||
scheduler_test_deps = [libxce_deps, librtti_dep, unity_dep, libxce_dep]
|
||||
|
||||
incdir = include_directories('../include', '../../include', '.')
|
||||
incdir = include_directories('../include', '../../include', '.', '../src', '../../lib')
|
||||
|
||||
scheduler_test = executable('sched_test',
|
||||
scheduler_test_src,
|
||||
|
|
|
|||
|
|
@ -5,17 +5,14 @@
|
|||
#include <stdatomic.h>
|
||||
#include <unity/unity.h>
|
||||
|
||||
#include "resreq.h"
|
||||
/* Pull resource.c into this TU so static helpers are visible for white-box testing.
|
||||
* This also brings in scheduler.h (with the real xce_scheduler_t) and all deps. */
|
||||
#include "../src/resource.c"
|
||||
|
||||
/* Minimal struct declaration to verify atomic fields exist.
|
||||
* We avoid including scheduler.h to prevent dependency on capnp headers. */
|
||||
typedef struct {
|
||||
/* Padding to represent fields before the atomic ones */
|
||||
char _dummy[968]; /* Approximate offset to atomic fields */
|
||||
_Atomic int session_active;
|
||||
_Atomic int eval_in_progress;
|
||||
_Atomic int staging_merge_complete;
|
||||
} xce_scheduler_t;
|
||||
/* Stubs for symbols used by resource.c functions not under test */
|
||||
xce_sched_worker_t* sched_get_worker(xce_scheduler_t* s, char* n) { (void)s; (void)n; return NULL; }
|
||||
int plugin_prepare_allocation(void* s, xce_sched_ctx_t* c) { (void)s; (void)c; return 0; }
|
||||
int sched_ctx_get_uncomit_host(xvec_t** v, xce_sched_ctx_t* c, int i) { (void)v; (void)c; (void)i; return 0; }
|
||||
|
||||
void setUp() { return; }
|
||||
|
||||
|
|
@ -78,6 +75,36 @@ static int check_test(struct arguments* args, char* x)
|
|||
return 0;
|
||||
}
|
||||
|
||||
static void
|
||||
test_build_host_eval_ctx_float(void)
|
||||
{
|
||||
/* Worker with one float resource at res_idx=2 (value=4.0) */
|
||||
xce_sched_worker_t w;
|
||||
memset(&w, 0, sizeof(w));
|
||||
zarray_init(&w.resvals, sizeof(xce_val_t*), NULL);
|
||||
|
||||
xce_val_t v;
|
||||
memset(&v, 0, sizeof(v));
|
||||
v.which = 5; /* Value_u_fvalue */
|
||||
v.u.fvalue = 4.0;
|
||||
|
||||
/* zarray stores xce_val_t* items; pass pointer-to-pointer */
|
||||
xce_val_t* vp = &v;
|
||||
zarray_put(&w.resvals, 2, &vp);
|
||||
|
||||
host_eval_ctx_t* ctx = build_host_eval_ctx(&w, 3);
|
||||
TEST_ASSERT_NOT_NULL(ctx);
|
||||
/* Unity is built without UNITY_INCLUDE_DOUBLE; compare via float cast */
|
||||
TEST_ASSERT_EQUAL_FLOAT(4.0f, (float)ctx->numvals[2]);
|
||||
TEST_ASSERT_NULL(ctx->strvals[2]);
|
||||
TEST_ASSERT_EQUAL_INT(3, ctx->num_res);
|
||||
|
||||
free((void*)ctx->numvals);
|
||||
free((void*)ctx->strvals);
|
||||
free(ctx);
|
||||
zarray_fini(&w.resvals);
|
||||
}
|
||||
|
||||
static void
|
||||
test_scheduler_t_has_atomic_gc_fields(void)
|
||||
{
|
||||
|
|
@ -116,6 +143,7 @@ int main(int argc, char* argv[])
|
|||
|
||||
UNITY_BEGIN();
|
||||
|
||||
TEST(test_build_host_eval_ctx_float);
|
||||
TEST(test_scheduler_t_has_atomic_gc_fields);
|
||||
TEST(test_sel_optimize_set_at_scheduler_startup);
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue