chiark / gitweb /
@@@ man wip
[mLib] / test / tvec-core.c
index 6a98f7368f02936307cb9139425837e86ca1ca70..ca71dd2b258de6de27c7a9a1fe27560d4a34593e 100644 (file)
@@ -256,7 +256,7 @@ void tvec_mismatch(struct tvec_state *tv, unsigned f)
   const struct tvec_reg *rin, *rout;
 
   for (rd = tv->test->regs; rd->name; rd++) {
-    if (rd->i >= tv->nrout) {
+    if (rd->i >= tv->cfg.nrout) {
       if (!(f&TVMF_IN)) continue;
       rin = TVEC_REG(tv, in, rd->i);
       tvec_dumpreg(tv, TVRD_INPUT, rin->f&TVRF_LIVE ? &rin->v : 0, rd);
@@ -572,9 +572,9 @@ void tvec_initregs(struct tvec_state *tv)
   struct tvec_reg *r;
 
   for (rd = tv->test->regs; rd->name; rd++) {
-    assert(rd->i < tv->nreg); r = TVEC_REG(tv, in, rd->i);
+    assert(rd->i < tv->cfg.nreg); r = TVEC_REG(tv, in, rd->i);
     rd->ty->init(&r->v, rd); r->f = 0;
-    if (rd->i < tv->nrout)
+    if (rd->i < tv->cfg.nrout)
       { r = TVEC_REG(tv, out, rd->i); rd->ty->init(&r->v, rd); r->f = 0; }
   }
 }
@@ -585,9 +585,9 @@ void tvec_releaseregs(struct tvec_state *tv)
   struct tvec_reg *r;
 
   for (rd = tv->test->regs; rd->name; rd++) {
-    assert(rd->i < tv->nreg); r = TVEC_REG(tv, in, rd->i);
+    assert(rd->i < tv->cfg.nreg); r = TVEC_REG(tv, in, rd->i);
     rd->ty->release(&r->v, rd); r->f = 0;
-    if (rd->i < tv->nrout)
+    if (rd->i < tv->cfg.nrout)
       { r = TVEC_REG(tv, out, rd->i); rd->ty->release(&r->v, rd); r->f = 0; }
   }
 }
@@ -611,8 +611,8 @@ void tvec_resetoutputs(struct tvec_state *tv)
   struct tvec_reg *r;
 
   for (rd = tv->test->regs; rd->name; rd++) {
-    assert(rd->i < tv->nreg);
-    if (rd->i >= tv->nrout) continue;
+    assert(rd->i < tv->cfg.nreg);
+    if (rd->i >= tv->cfg.nrout) continue;
     r = TVEC_REG(tv, out, rd->i);
     rd->ty->release(&r->v, rd);
     rd->ty->init(&r->v, rd);
@@ -643,7 +643,7 @@ int tvec_checkregs(struct tvec_state *tv)
   const struct tvec_reg *rin, *rout;
 
   for (rd = tv->test->regs; rd->name; rd++) {
-    if (rd->i >= tv->nrout) continue;
+    if (rd->i >= tv->cfg.nrout) continue;
     rin = TVEC_REG(tv, in, rd->i); rout = TVEC_REG(tv, out, rd->i);
     if (!rin->f&TVRF_LIVE) continue;
     if (!(rout->f&TVRF_LIVE) || !rd->ty->eq(&rin->v, &rout->v, rd))
@@ -790,9 +790,10 @@ static void check(struct tvec_state *tv, struct groupstate *g)
   if (!(tv->f&TVSF_OPEN)) return;
 
   for (rd = t->regs; rd->name; rd++) {
-    if (TVEC_REG(tv, in, rd->i)->f&TVRF_LIVE)
-      { if (rd->i < tv->nrout) TVEC_REG(tv, out, rd->i)->f |= TVRF_LIVE; }
-    else if (!(rd->f&TVRF_OPT)) {
+    if (TVEC_REG(tv, in, rd->i)->f&TVRF_LIVE) {
+      if (rd->i < tv->cfg.nrout)
+       TVEC_REG(tv, out, rd->i)->f |= TVRF_LIVE;
+    } else if (!(rd->f&TVRF_OPT)) {
       tvec_error(tv, "required register `%s' not set in test `%s'",
                 rd->name, t->name);
       f |= f_err;
@@ -957,7 +958,7 @@ static const struct tvec_uenuminfo outcome_enum =
   { "test-outcome", outcome_assoc, &outcome_range };
 static const struct tvec_vardef outcome_vardef =
   { sizeof(struct tvec_reg), core_setvar,
-    { "@outcome", 0, &tvty_uenum, 0, { &outcome_enum } } };
+    { "@outcome", &tvty_uenum, -1, 0, { &outcome_enum } } };
 
 static const struct tvec_vardef *core_findvar
   (struct tvec_state *tv, const char *name, void **ctx_out, void *ctx)
@@ -1023,7 +1024,7 @@ int tvec_read(struct tvec_state *tv, const char *infile, FILE *fp)
        ch = getc(tv->fp); if (ch != ']') tvec_syntax(tv, ch, "`]'");
 
        /* Find the matching test definition. */
-       for (test = tv->tests; test->name; test++)
+       for (test = tv->cfg.tests; test->name; test++)
          if (STRCMP(d.buf, ==, test->name)) goto found_test;
 
        /* There wasn't one.  Report the error.  Muffle errors about the
@@ -1211,19 +1212,18 @@ void tvec_begin(struct tvec_state *tv_out,
   tv_out->f = 0;
 
   assert(config->nrout <= config->nreg);
-  tv_out->nrout = config->nrout; tv_out->nreg = config->nreg;
-  tv_out->regsz = config->regsz;
-  tv_out->in = xmalloc(tv_out->nreg*tv_out->regsz);
-  tv_out->out = xmalloc(tv_out->nrout*tv_out->regsz);
-  for (i = 0; i < tv_out->nreg; i++) {
+  tv_out->cfg = *config;
+  tv_out->in = xmalloc(tv_out->cfg.nreg*tv_out->cfg.regsz);
+  tv_out->out = xmalloc(tv_out->cfg.nrout*tv_out->cfg.regsz);
+  for (i = 0; i < tv_out->cfg.nreg; i++) {
     TVEC_REG(tv_out, in, i)->f = 0;
-    if (i < tv_out->nrout) TVEC_REG(tv_out, out, i)->f = 0;
+    if (i < tv_out->cfg.nrout) TVEC_REG(tv_out, out, i)->f = 0;
   }
 
   for (i = 0; i < TVOUT_LIMIT; i++)
     tv_out->curr[i] = tv_out->all[i] = tv_out->grps[i] = 0;
 
-  tv_out->tests = config->tests; tv_out->test = 0;
+  tv_out->test = 0;
   tv_out->infile = 0; tv_out->lno = 0; tv_out->fp = 0;
   tv_out->output = o; tv_out->output->ops->bsession(tv_out->output, tv_out);
 }
@@ -1367,7 +1367,7 @@ static void fakefn(const struct tvec_reg *in, struct tvec_reg *out, void *p)
 void tvec_adhoc(struct tvec_state *tv, struct tvec_test *t)
 {
   t->name = "<unset>"; t->regs = &no_regs; t->env = 0; t->fn = fakefn;
-  tv->tests = t;
+  tv->cfg.tests = t;
 }
 
 /* --- @tvec_begingroup@ --- *
@@ -1387,7 +1387,7 @@ void tvec_adhoc(struct tvec_state *tv, struct tvec_test *t)
 void tvec_begingroup(struct tvec_state *tv, const char *name,
                     const char *file, unsigned lno)
 {
-  struct tvec_test *t = (/*unconst*/ struct tvec_test *)tv->tests;
+  struct tvec_test *t = (/*unconst*/ struct tvec_test *)tv->cfg.tests;
 
   t->name = name; tv->test = t;
   tv->infile = file; tv->lno = tv->test_lno = lno;