+static const struct tvec_env common_testenv = {
+ sizeof(struct test_context),
+ common_setup, common_set,
+ 0, common_run, common_after,
+ 0
+};
+
+/*----- Single-type copy tests --------------------------------------------*/
+
+static void test_copy_simple
+ (const struct tvec_reg *in, struct tvec_reg *out, void *ctx)
+ { out->v = in->v; }
+
+static void test_copy_string
+ (const struct tvec_reg *in, struct tvec_reg *out, void *ctx)
+{
+ tvec_allocstring(&out->v, in->v.str.sz);
+ memcpy(out->v.str.p, in->v.str.p, in->v.str.sz);
+}
+
+static void test_copy_bytes
+ (const struct tvec_reg *in, struct tvec_reg *out, void *ctx)
+{
+ tvec_allocstring(&out->v, in->v.str.sz);
+ memcpy(out->v.str.p, in->v.str.p, in->v.str.sz);
+}
+
+#define test_copy_int test_copy_simple
+#define test_copy_uint test_copy_simple
+#define test_copy_ienum test_copy_simple
+#define test_copy_uenum test_copy_simple
+#define test_copy_fenum test_copy_simple
+#define test_copy_penum test_copy_simple
+#define test_copy_char test_copy_simple
+#define test_copy_flags test_copy_simple
+#define test_copy_float test_copy_simple
+#define test_copy_fltish test_copy_simple
+#define test_copy_buffer test_copy_bytes
+
+#define COPYREG(name, i, ty, argslot, argval) \
+ static DSGINIT(const) struct tvec_regdef name##_copyregs[] = { \
+ { #name, RVOUT, &tvty_##ty, 0, DSGINIT({ .argslot = argval }) }, \
+ { 0 } \
+ };
+TYPEREGS(COPYREG)
+#undef COPYREG
+
+/*----- Single-type serialization tests -----------------------------------*/
+
+static void setup_regdef(struct tvec_regdef *rd, unsigned i,
+ struct tvec_state *tv)
+{
+ const struct tvec_regdef *r;
+
+ for (r = tv->test->regs; r->name; r++) if (r->i == i) goto found;
+ tvec_error(tv, "internel: register definition not found"); exit(2);
+found:
+ rd[0] = *r; rd[1].name = 0;
+}
+
+static void test_single_serialize
+ (const struct tvec_reg *in, struct tvec_reg *out, void *ctx)
+{
+ struct test_context *tctx = ctx;
+ struct tvec_state *tv = tctx->tv;
+ struct tvec_regdef rd[2];
+ dbuf b = DBUF_INIT;
+ int rc;
+
+ setup_regdef(rd, RV, tv);
+ rc = tvec_serialize(tv->in, DBUF_BUF(&b), rd, NREG,
+ sizeof(struct tvec_reg));
+ out[RRC].v.i = rc;
+ if (rc)
+ out[RSEROUT].f &= ~TVRF_LIVE;
+ else {
+ tvec_allocbytes(&out[RSEROUT].v, BLEN(DBUF_BUF(&b)));
+ memcpy(out[RSEROUT].v.bytes.p, BBASE(DBUF_BUF(&b)), BLEN(DBUF_BUF(&b)));
+ }
+}
+
+static void test_single_deserialize
+ (const struct tvec_reg *in, struct tvec_reg *out, void *ctx)
+{
+ struct test_context *tctx = ctx;
+ struct tvec_state *tv = tctx->tv;
+ struct tvec_regdef rd[2];
+ buf b;
+ int rc;
+
+ setup_regdef(rd, RV, tv);
+ buf_init(&b, in[RSER].v.bytes.p, in[RSER].v.bytes.sz);
+ rc = tvec_deserialize(tv->out, &b, rd, NREG, sizeof(struct tvec_reg));
+ out[RRC].v.i = rc;
+ if (rc) out[RVOUT].f &= ~TVRF_LIVE;
+}
+
+#define SERREG(name, i, ty, argslot, argval) \
+ static DSGINIT(const) struct tvec_regdef name##_serregs[] = { \
+ { #name, RV, &tvty_##ty, 0, DSGINIT({ .argslot = argval }) }, \
+ { "buf", RSEROUT, &tvty_bytes }, \
+ { "rc", RRC, &tvty_int, TVRF_OPT, { &tvrange_int } }, \
+ TVEC_ENDREGS \
+ }; \
+ static DSGINIT(const) struct tvec_regdef name##_deserregs[] = { \
+ { "buf", RSER, &tvty_bytes }, \
+ { #name, RVOUT, &tvty_##ty, 0, DSGINIT({ .argslot = argval }) }, \
+ { "left", RLEFT, &tvty_uint, TVRF_OPT, { &tvrange_size } }, \
+ { "rc", RRC, &tvty_int, TVRF_OPT, { &tvrange_int } }, \
+ TVEC_ENDREGS \
+ };
+TYPEREGS(SERREG)
+#undef SERREG
+
+static int before_single_serialize(struct tvec_state *tv, void *ctx)