+/*----- Sleep test --------------------------------------------------------*/
+
+static void test_sleep(const struct tvec_reg *in, struct tvec_reg *out,
+ void *ctx)
+{
+ struct timeval now, when, tv;
+ int rc;
+
+ rc = gettimeofday(&now, 0); assert(!rc);
+ tv.tv_sec = in[RV].v.f; tv.tv_usec = 1e6*(in[RV].v.f - tv.tv_sec);
+
+ TV_ADD(&when, &now, &tv);
+ for (;;) {
+ rc = select(0, 0, 0, 0, &tv); assert(!rc);
+ rc = gettimeofday(&now, 0); assert(!rc);
+ if (TV_CMP(&now, >=, &when)) break;
+ TV_SUB(&tv, &when, &now);
+ }
+ out[RVOUT].v.f = in[RV].v.f;
+}
+
+static const struct tvec_timeoutenv sleep_subenv =
+ { TVEC_TIMEOUTINIT(ITIMER_REAL, 0.25) };
+static const struct tvec_remotefork sleep_testenv =
+ { TVEC_REMOTEFORK(&sleep_subenv._env, 0) };
+
+static const struct tvec_regdef sleep_regs[] = {
+ { "time", RV, &tvty_float, 0, { &tvflt_nonneg } },
+ { "z", RVOUT, &tvty_float, 0, { &tvflt_nonneg } },
+ TVEC_ENDREGS
+};
+