@@@ more mess
[mLib] / hash / t / hash-test.c
index 6298b82..756232d 100644 (file)
@@ -81,28 +81,30 @@ static void test_unihash(const struct tvec_reg *in, struct tvec_reg *out,
 static void bench_unihash(const struct tvec_reg *in, struct tvec_reg *out,
                          void *ctx)
   { unihash_hash(ctx, 0, in[RM].v.bytes.p, in[RM].v.bytes.sz); }
-
-static int setup_unihash(const struct tvec_reg *in, struct tvec_reg *out,
-                        const union tvec_misc *arg, void *ctx)
+static int setup_unihash(struct tvec_state *tv,
+                        const struct tvec_env *env, void *pctx, void *ctx)
   { unihash_setkey(ctx, 0); return (0); }
+static const struct tvec_env unihash_benchenv =
+  { sizeof(unihash_info), setup_unihash, 0, 0 };
 
-static int run_step(struct tvec_state *tv)
+static void run_step(struct tvec_state *tv, tvec_testfn *fn, void *ctx)
 {
   static const size_t steps[] = { 1, 5, 6, 7, 8, 23 };
   struct step step;
   size_t i;
 
-  tv->test->fn(tv->in, tv->out, 0);
+  fn(tv->in, tv->out, 0);
   tvec_check(tv, "whole buffer");
 
   for (i = 0; i < N(steps); i++) {
     step.s = steps[i];
-    tv->test->fn(tv->in, tv->out, &step);
+    fn(tv->in, tv->out, &step);
     tvec_check(tv, "step = %lu", (unsigned long)steps[i]);
   }
-  return (0);
 }
 
+static const struct tvec_env step_testenv = { 0, 0, 0, 0, run_step, 0, 0 };
+
 static const struct tvec_regdef unihash_regs[] = {
   { "k", RK, &tvty_uint, 0, { &tvrange_u32 } },
   { "m", RM, &tvty_bytes, 0 },
@@ -121,30 +123,23 @@ static const struct tvec_regdef bench_regs[] = {
   { 0, 0, 0, 0 }
 };
 
-static const struct tvec_bench crc32_bench = {
-  1, -1, RM,
-  0, 0, 0, 0, { 0 }
-};
-
-static const struct tvec_bench unihash_bench = {
-  1, -1, RM,
-  sizeof(unihash_info), setup_unihash, 0, 0, { 0 }
-};
+static const struct tvec_bench crc32_bench =
+  { TVEC_BENCHINIT, 1, -1, RM, 0 };
+static const struct tvec_bench unihash_bench =
+  { TVEC_BENCHINIT, 1, -1, RM, &unihash_benchenv };
 
 static const struct tvec_test tests[] = {
-  { "crc32",crc32_regs, 0, run_step, test_crc32 },
-  { "unihash", unihash_regs, 0, run_step, test_unihash },
-  { "crc32-bench", bench_regs, 0,
-    tvec_bench, bench_crc32, { &crc32_bench } },
-  { "unihash-bench", bench_regs, 0,
-    tvec_bench, bench_unihash, { &unihash_bench } },
-  { 0, 0, 0, 0, 0 }
+  { "crc32", crc32_regs, &step_testenv, test_crc32 },
+  { "unihash", unihash_regs, &step_testenv, test_unihash },
+  { "crc32-bench", bench_regs, &crc32_bench._env, bench_crc32 },
+  { "unihash-bench", bench_regs, &unihash_bench._env, bench_unihash },
+  { 0, 0, 0, 0 }
 };
 
-static const struct tvec_info testinfo =
+static const struct tvec_config testconfig =
   { tests, NROUT, NREG, sizeof(struct tvec_reg) };
 
 int main(int argc, char *argv[])
-  { return (tvec_main(argc, argv, &testinfo, 0)); }
+  { return (tvec_main(argc, argv, &testconfig, 0)); }
 
 /*----- That's all, folks -------------------------------------------------*/