2 * Copyright (c) 2021 Omar Polo <op@omarpolo.com>
4 * Permission to use, copy, modify, and distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
19 #include <sys/socket.h>
48 static const char *argv0;
50 static uint8_t *lastmsg;
52 static struct imsgbuf ibuf;
53 static int ibuf_inuse;
54 static int child_out = -1;
56 static struct procs procs = TAILQ_HEAD_INITIALIZER(procs);
57 static struct tests tests = TAILQ_HEAD_INITIALIZER(tests);
61 static struct opstacks blocks = TAILQ_HEAD_INITIALIZER(blocks);
62 static struct opstacks args = TAILQ_HEAD_INITIALIZER(args);
64 #define STACK_HEIGHT 64
65 static struct value vstack[STACK_HEIGHT];
68 static struct envs envs = TAILQ_HEAD_INITIALIZER(envs);
70 static struct value v_false = {.type = V_NUM, .v = {.num = 0}};
71 static struct value v_true = {.type = V_NUM, .v = {.num = 1}};
73 static uint8_t lasttag;
76 static int syntaxcheck;
78 static const char *filler;
90 check_for_output(void)
92 static char buf[BUFSIZ];
98 if (poll(&pfd, 1, 0) == -1)
101 if (!(pfd.revents & POLLIN))
105 if ((r = read(child_out, buf, sizeof(buf))) == -1) {
113 fwrite(buf, 1, r, stdout);
118 peekn(int depth, struct value *v)
121 errx(1, "can't peek the stack at %d: underflow",
123 memcpy(v, &vstack[stackh - depth], sizeof(*v));
126 printf("peeking(%d) ", depth); pp_val(v); printf("\n");
131 popv(struct value *v)
134 errx(1, "can't pop the stack: underflow");
135 memcpy(v, &vstack[--stackh], sizeof(*v));
138 printf("popping "); pp_val(v); printf("\n");
152 pushv(struct value *v)
154 if (stackh == STACK_HEIGHT)
155 errx(1, "can't push the stack: overflow");
158 printf("pushing "); pp_val(v); printf("\n");
161 memcpy(&vstack[stackh++], v, sizeof(*v));
167 pushv(n ? &v_true : &v_false);
180 static inline struct opstack *
181 pushstack(struct opstacks *stack)
185 ops = xcalloc(1, sizeof(*ops));
186 TAILQ_INSERT_HEAD(stack, ops, entry);
190 static inline struct opstack *
191 peek(struct opstacks *stack)
193 if (TAILQ_EMPTY(stack))
194 errx(1, "%s: args underflow", __func__);
196 return TAILQ_FIRST(stack);
199 static inline struct op *
200 finalize(struct opstacks *stack, int *argc)
205 if (TAILQ_EMPTY(stack))
206 errx(1, "%s: args underflow", __func__);
209 TAILQ_REMOVE(&args, ops, entry);
213 *argc = ops->counter;
220 push(struct opstacks *stack, struct op *op)
225 if (ops->last == NULL) {
229 ops->last->next = op;
241 e = xcalloc(1, sizeof(*e));
242 TAILQ_INSERT_HEAD(&envs, e, entry);
245 static inline struct env *
248 assert(!TAILQ_EMPTY(&envs));
249 return TAILQ_FIRST(&envs);
256 struct binding *b, *tb;
259 TAILQ_REMOVE(&envs, e, entry);
261 TAILQ_FOREACH_SAFE(b, &e->bindings, entry, tb)
268 setvar(char *sym, struct op *op)
275 if ((ret = eval(op)) != EVAL_OK)
278 if (stackh != height + 1) {
280 printf("trying to assign to `%s' a void value: ", sym);
286 b = xcalloc(1, sizeof(*b));
290 e = TAILQ_FIRST(&envs);
291 TAILQ_INSERT_HEAD(&e->bindings, b, entry);
297 setvar_raw(char *sym, struct op *op)
302 b = xcalloc(1, sizeof(*b));
306 e = TAILQ_FIRST(&envs);
307 TAILQ_INSERT_HEAD(&e->bindings, b, entry);
311 getvar(const char *sym, struct value *v)
316 TAILQ_FOREACH(e, &envs, entry) {
317 TAILQ_FOREACH(b, &e->bindings, entry) {
318 if (!strcmp(sym, b->name)) {
319 memcpy(v, &b->val, sizeof(*v));
326 fprintf(stderr, "unbound variable %s\n", sym);
331 getvar_raw(const char *sym, struct op **raw)
336 TAILQ_FOREACH(e, &envs, entry) {
337 TAILQ_FOREACH(b, &e->bindings, entry) {
338 if (!strcmp(sym, b->name)) {
349 global_set(char *sym, struct op *op)
354 /* TODO: check for duplicates */
356 if (op->type != OP_LITERAL &&
357 (op->type == OP_CAST && op->v.cast.expr->type != OP_LITERAL))
360 b = xcalloc(1, sizeof(*b));
363 /* it's only a cast on a literal! */
364 if (op->type == OP_CAST) {
365 if (eval(op) != EVAL_OK) {
371 memcpy(&b->val, &op->v.literal, sizeof(b->val));
373 e = TAILQ_LAST(&envs, envs);
374 TAILQ_INSERT_HEAD(&e->bindings, b, entry);
384 op = xcalloc(1, sizeof(*op));
391 free_op_rec(struct op *op)
403 free_op(struct op *op)
414 free(op->v.assign.name);
415 free_op_rec(op->v.assign.expr);
418 free_op_rec(op->v.assert);
421 free_op_rec(op->v.funcall.argv);
427 free_op_rec(op->v.cast.expr);
430 free_op_rec(op->v.cmp_eq.a);
431 free_op_rec(op->v.cmp_eq.b);
434 free_op_rec(op->v.faccess.expr);
435 free(op->v.faccess.field);
438 free(op->v.sfail.msg);
439 free_op_rec(op->v.sfail.expr);
452 return newop(OP_REST);
456 op_assign(char *sym, struct op *expr)
460 op = newop(OP_ASSIGN);
461 op->v.assign.name = sym;
462 op->v.assign.expr = expr;
468 op_assert(struct op *expr)
472 op = newop(OP_ASSERT);
490 op_lit_str(char *str)
494 op = newop(OP_LITERAL);
495 op->v.literal.type = V_STR;
496 op->v.literal.v.str = str;
502 op_lit_num(uint64_t n)
506 op = newop(OP_LITERAL);
507 op->v.literal.type = V_NUM;
508 op->v.literal.v.num = n;
514 op_cmp_eq(struct op *a, struct op *b)
518 op = newop(OP_CMP_EQ);
526 op_cast(struct op *expr, int totype)
531 op->v.cast.expr = expr;
532 op->v.cast.totype = totype;
538 op_faccess(struct op *expr, char *field)
542 op = newop(OP_FACCESS);
543 op->v.faccess.expr = expr;
544 op->v.faccess.field = field;
550 op_sfail(struct op *expr, char *msg)
554 op = newop(OP_SFAIL);
555 op->v.sfail.expr = expr;
556 op->v.sfail.msg = msg;
566 op = newop(OP_VARGS);
572 ppf_val(FILE *f, struct value *val)
578 fprintf(f, "%s", val->v.str);
581 fprintf(f, "\"%s\"", val->v.str);
584 fprintf(f, "%"PRIi64, val->v.num);
587 fprintf(f, "%"PRIu8, val->v.u8);
590 fprintf(f, "%"PRIu16, val->v.u16);
593 fprintf(f, "%"PRIu32, val->v.u32);
597 for (i = 0; i < val->v.msg.len; ++i)
598 fprintf(f, "%x%s", val->v.msg.msg[i],
599 i == val->v.msg.len-1 ? "" : " ");
603 fprintf(f, "qids[n=%zu]", val->v.qidvec.len);
606 fprintf(f, "<unknown value>");
612 pp_val(struct value *val)
614 ppf_val(stdout, val);
618 val_type(struct value *v)
621 case V_SYM: return "symbol";
622 case V_STR: return "string";
623 case V_NUM: return "number";
624 case V_MSG: return "message";
625 case V_QID: return "qid";
626 case V_U8: return "u8";
627 case V_U16: return "u16";
628 case V_U32: return "u32";
629 default: return "unknown";
634 val_trueish(struct value *a)
642 val_isnum(struct value *a)
644 return a->type == V_NUM
651 val_tonum(struct value *a)
654 case V_NUM: return a->v.num;
655 case V_U8: return a->v.u8;
656 case V_U16: return a->v.u16;
657 case V_U32: return a->v.u32;
660 fprintf(stderr, "%s: given value is not a number\n", __func__);
666 val_eq(struct value *a, struct value *b)
668 if (val_isnum(a) && val_isnum(b))
669 return val_tonum(a) == val_tonum(b);
671 if (a->type != b->type)
677 return !strcmp(a->v.str, b->v.str);
683 static inline const char *
684 pp_totype(int totype)
687 * Not all of these are valid cast type thought, including
688 * every possibility only to aid debugging.
691 case V_STR: return "str";
692 case V_SYM: return "sym";
693 case V_NUM: return "num";
694 case V_QID: return "qid";
695 case V_U8: return "u8";
696 case V_U16: return "u16";
697 case V_U32: return "u32";
698 default: return "unknown";
703 val_cast(struct value *a, int totype)
707 #define NUMCAST(val, t, c, totype, max) do { \
710 fprintf(stderr, "can't cast %"PRIu64 \
711 " to %s\n", val, pp_totype(totype)); \
719 if (a->type == totype)
724 fprintf(stderr, "can't cast ");
726 fprintf(stderr, " to type %s\n", pp_totype(totype));
732 case V_U8: NUMCAST(v, u8, uint8_t, totype, UINT8_MAX);
733 case V_U16: NUMCAST(v, u16, uint16_t, totype, UINT16_MAX);
734 case V_U32: NUMCAST(v, u32, uint32_t, totype, UINT32_MAX);
737 fprintf(stderr, "can't cast %"PRIu64" to %s\n",
738 v, pp_totype(totype));
746 val_faccess(struct value *a, const char *field, struct value *ret)
752 #define MSGTYPE(m) *(m.msg + 4) /* skip the length */
756 /* TODO: add path. needs uint64_t values thought! */
757 if (!strcmp(field, "vers")) {
759 memcpy(&ret->v.u32, a->v.qid+1, 4);
761 } else if (!strcmp(field, "type")) {
763 ret->v.u8 = *a->v.qid;
769 mtype = MSGTYPE(a->v.msg);
770 if (!strcmp(field, "type")) {
772 ret->v.u8 = MSGTYPE(a->v.msg);
774 } else if (!strcmp(field, "tag")) {
776 memcpy(&ret->v.u16, &a->v.msg.msg[5], 2);
777 ret->v.u16 = le16toh(ret->v.u16);
779 } else if (!strcmp(field, "msize") && mtype == Rversion) {
781 memcpy(&ret->v.u32, &a->v.msg.msg[7], 4);
782 ret->v.u32 = le32toh(ret->v.u32);
784 } else if (!strcmp(field, "qid") && mtype == Rattach) {
786 memcpy(&ret->v.qid, &a->v.msg.msg[7], QIDSIZE);
788 } else if (!strcmp(field, "nwqid") && mtype == Rwalk) {
790 memcpy(&ret->v.u16, &a->v.msg.msg[7], 2);
791 ret->v.u16 = le16toh(ret->v.u16);
793 } else if (!strcmp(field, "wqid") && mtype == Rwalk) {
794 ret->type = V_QIDVEC;
795 ret->v.qidvec.start = &a->v.msg.msg[9];
796 memcpy(&len, &a->v.msg.msg[7], 2);
798 ret->v.qidvec.len = len;
804 len = strtonum(field, 0, MAXWELEM, &errstr);
805 if (errstr != NULL) {
807 printf("can't access qid #%s: %s\n", field, errstr);
811 if (len >= a->v.qidvec.len) {
813 printf("can't access qid #%d: out-of-bound "
814 "(max %zu)\n", len, a->v.qidvec.len);
819 memcpy(&ret->v.qid, a->v.qidvec.start + len * QIDSIZE,
829 printf("can't access field `%s' on type %s (", field, val_type(a));
847 printf("%s = ", op->v.assign.name);
848 pp_op(op->v.assign.expr);
855 printf("funcall %s(", op->v.funcall.proc->name);
856 for (aux = op->v.funcall.argv; aux != NULL; aux = aux->next) {
858 if (aux->next != NULL)
864 pp_val(&op->v.literal);
867 printf("%s", op->v.var);
870 pp_op(op->v.cast.expr);
872 switch (op->v.cast.totype) {
873 case V_U8: printf("u8"); break;
874 case V_U16: printf("u16"); break;
875 case V_U32: printf("u32"); break;
876 case V_STR: printf("str"); break;
877 default: printf("???"); break;
881 pp_op(op->v.cmp_eq.a);
883 pp_op(op->v.cmp_eq.b);
886 pp_op(op->v.faccess.expr);
887 printf(".%s", op->v.faccess.field);
890 printf("should-fail ");
891 pp_op(op->v.sfail.expr);
892 if (op->v.sfail.msg != NULL)
893 printf(": \"%s\"", op->v.sfail.msg);
899 printf(" ???[%d] ", op->type);
904 pp_block(struct op *op)
920 struct op *t, *tnext;
931 * Try to load the rest argument. Note that it can be
934 if ((ret = getvar_raw("...", &t)) == EVAL_OK)
935 if ((ret = eval(t)) != EVAL_OK)
940 ret = setvar(op->v.assign.name, op->v.assign.expr);
946 if ((ret = eval(op->v.assert)) != EVAL_OK)
949 if (!val_trueish(&a)) {
951 printf("assertion failed: ");
959 /* assume airity matches */
961 proc = op->v.funcall.proc;
962 if (proc->nativefn != NULL) {
964 * Push arguments on the stack for builtin
965 * functions. Counting the height of the
966 * stack is done to compute the correct number
967 * in the vararg case. argc only counts the
968 * "syntactical" arguments, i.e. foo(x, ...)
969 * has argc == 2, but at runtime argc may be
970 * 1, 2 or a greater number!
974 t = op->v.funcall.argv;
975 if (t != NULL && (ret = eval(t)) != EVAL_OK)
981 if ((ret = proc->nativefn(i))
985 if (proc->body == NULL) {
987 printf("warn: calling the empty proc `%s'\n",
994 for (t = op->v.funcall.argv, i = 0;
998 * Push a pseudo variable `...' (and
999 * don't evaluate it) in the vararg
1000 * case. A special case is when the
1001 * variable is itself `...'.
1003 if (proc->vararg && i == proc->minargs) {
1004 if (t->type != OP_REST)
1005 setvar_raw(xstrdup("..."), t);
1010 * The arguments are a linked list of
1011 * ops. Setvar will call eval that
1012 * will evaluate *all* the arguments.
1013 * The dance here that sets next to
1014 * NULL and then restores it is to
1015 * avoid this behaviour.
1019 ret = setvar(proc->args[i], t);
1026 if ((ret = eval(proc->body)) != EVAL_OK)
1035 pushv(&op->v.literal);
1039 if ((ret = getvar(op->v.var, &a)) != EVAL_OK)
1045 if ((ret = eval(op->v.cast.expr)) != EVAL_OK)
1048 if ((ret = val_cast(&a, op->v.cast.totype)) != EVAL_OK)
1054 if ((ret = eval(op->v.cmp_eq.a)) != EVAL_OK)
1056 if ((ret = eval(op->v.cmp_eq.b)) != EVAL_OK)
1061 pushbool(val_eq(&a, &b));
1066 if ((ret = eval(op->v.faccess.expr)) != EVAL_OK)
1069 if ((ret = val_faccess(&a, op->v.faccess.field, &b))
1076 if ((ret = eval(op->v.sfail.expr)) == EVAL_OK) {
1078 printf("expecting failure");
1079 if (op->v.sfail.msg != NULL)
1080 printf(" \"%s\"", op->v.sfail.msg);
1082 printf("expression: ");
1083 pp_op(op->v.sfail.expr);
1087 if (ret == EVAL_SKIP)
1092 if ((ret = getvar_raw("...", &t)) == EVAL_OK) {
1093 for (i = 0; t != NULL; t = t->next)
1102 fprintf(stderr, "invalid op, aborting.\n");
1107 return eval(op->next);
1112 prepare_funcall(void)
1118 push_arg(struct op *op)
1124 op_funcall(struct proc *proc)
1126 struct op *op, *argv;
1129 argv = finalize(&args, &argc);
1131 op = newop(OP_FUNCALL);
1132 op->v.funcall.proc = proc;
1133 op->v.funcall.argv = argv;
1134 op->v.funcall.argc = argc;
1140 add_builtin_proc(const char *name, int (*fn)(int), int argc, int vararg)
1144 proc = xcalloc(1, sizeof(*proc));
1145 proc->name = xstrdup(name);
1146 proc->nativefn = fn;
1147 proc->minargs = argc;
1148 proc->vararg = vararg;
1150 TAILQ_INSERT_HEAD(&procs, proc, entry);
1160 proc_setup_body(void)
1162 struct opstack *argv;
1167 for (i = 0, op = argv->base.next; op != NULL; i++) {
1169 * TODO: should free the whole list on error but..,
1170 * we're gonna exit real soon(tm)!
1172 if (op->type != OP_VAR && op->type != OP_REST)
1178 assert(i == argv->counter);
1184 proc_done(char *name)
1187 struct op *op, *next, *argv, *body;
1190 argv = finalize(&args, &argc);
1191 body = finalize(&blocks, NULL);
1193 proc = xcalloc(1, sizeof(*proc));
1195 proc->minargs = argc;
1197 for (i = 0, op = argv; op != NULL; ++i) {
1198 if (op->type == OP_REST) {
1204 proc->args[i] = xstrdup(op->v.var);
1210 assert(i == argc || (proc->vararg && i == proc->minargs));
1214 TAILQ_INSERT_HEAD(&procs, proc, entry);
1218 block_push(struct op *op)
1224 proc_by_name(const char *name)
1228 TAILQ_FOREACH(p, &procs, entry) {
1229 if (!strcmp(p->name, name))
1243 test_done(int shouldfail, char *name, char *dir)
1247 test = xcalloc(1, sizeof(*test));
1248 test->shouldfail = shouldfail;
1251 test->body = finalize(&blocks, NULL);
1253 if (TAILQ_EMPTY(&tests))
1254 TAILQ_INSERT_HEAD(&tests, test, entry);
1256 TAILQ_INSERT_TAIL(&tests, test, entry);
1262 builtin_print(int argc)
1269 for (i = argc; i > 0; --i) {
1271 if (v.type == V_STR)
1272 printf("%s", v.v.str);
1286 builtin_debug(int argc)
1289 return builtin_print(argc);
1296 builtin_skip(int argc)
1302 builtin_iota(int argc)
1307 if ((v.v.u16 = ++lasttag) == 255)
1308 v.v.u16 = ++lasttag;
1315 builtin_send(int argc)
1326 * Compute the length of the packet. 4 is for the initial
1331 for (i = argc; i > 0; --i) {
1335 len += 2; /* count */
1336 len += strlen(v.v.str);
1353 printf("%s: can't serialize ", __func__);
1360 if (len > UINT16_MAX) {
1362 printf("%s: message size too long: got %d when max is %d\n",
1363 __func__, len, UINT16_MAX);
1367 if ((buf = imsg_create(&ibuf, IMSG_BUF, 0, 0, len)) == NULL)
1368 fatal("imsg_create(%d)", len);
1371 imsg_add(buf, &len, sizeof(len));
1373 for (i = argc; i > 0; --i) {
1377 slen = strlen(v.v.str);
1378 slen = htole16(slen);
1379 imsg_add(buf, &slen, sizeof(slen));
1380 imsg_add(buf, v.v.str, strlen(v.v.str));
1384 imsg_add(buf, &v.v.u8, 1);
1388 v.v.u16 = htole16(v.v.u16);
1389 imsg_add(buf, &v.v.u16, 2);
1393 v.v.u32 = htole32(v.v.u32);
1394 imsg_add(buf, &v.v.u32, 4);
1399 imsg_close(&ibuf, buf);
1401 if (imsg_flush(&ibuf) == -1) {
1404 printf("%s: imsg_flush failed: %s\n", __func__, strerror(i));
1413 builtin_recv(int argc)
1421 if (lastmsg != NULL) {
1427 pfd.events = POLLIN;
1428 if (poll(&pfd, 1, INFTIM) == -1) {
1431 printf("%s: poll failed: %s\n", __func__, strerror(serrno));
1436 if ((n = imsg_read(&ibuf)) == -1) {
1437 if (errno == EAGAIN)
1444 printf("child disconnected\n");
1451 /* read only one message */
1452 if ((n = imsg_get(&ibuf, &imsg)) == -1)
1457 datalen = imsg.hdr.len - IMSG_HEADER_SIZE;
1458 switch (imsg.hdr.type) {
1461 if ((v.v.msg.msg = malloc(datalen)) == NULL)
1463 memcpy(v.v.msg.msg, imsg.data, datalen);
1464 v.v.msg.len = datalen;
1471 printf("subprocess closed the connection\n");
1481 printf("got unknown message from subprocess: %d\n",
1489 spawn_client_proc(void)
1491 const char *argv[4];
1492 int p[2], out[2], argc = 0;
1495 if (child_out != -1)
1498 if (socketpair(AF_UNIX, SOCK_STREAM | SOCK_CLOEXEC | SOCK_NONBLOCK,
1499 PF_UNSPEC, p) == -1)
1500 fatal("socketpair");
1502 if (socketpair(AF_UNIX, SOCK_STREAM | SOCK_CLOEXEC | SOCK_NONBLOCK,
1503 PF_UNSPEC, out) == -1)
1504 fatal("socketpair");
1506 switch (pid = fork()) {
1508 fatal("cannot fork");
1516 msgbuf_clear(&ibuf.w);
1519 imsg_init(&ibuf, p[0]);
1527 if (dup2(out[1], 1) == -1 ||
1528 dup2(out[1], 2) == -1)
1532 if (dup2(p[1], 3) == -1)
1533 fatal("cannot setup imsg fd");
1534 } else if (fcntl(F_SETFD, 0) == -1)
1535 fatal("cannot setup imsg fd");
1537 argv[argc++] = argv0;
1538 argv[argc++] = "-Tc";
1541 argv[argc++] = "-v";
1544 argv[argc++] = NULL;
1546 execvp(argv0, (char *const *)argv);
1551 prepare_child_for_test(struct test *t)
1556 if (stat(t->dir, &sb) == -1)
1557 fatal("stat(\"%s\")", t->dir);
1559 if ((pw = getpwuid(sb.st_uid)) == NULL)
1560 fatal("getpwuid(%d)", sb.st_uid);
1562 imsg_compose(&ibuf, IMSG_AUTH, 0, 0, -1,
1563 pw->pw_name, strlen(pw->pw_name)+1);
1564 imsg_compose(&ibuf, IMSG_AUTH_DIR, 0, 0, -1,
1565 t->dir, strlen(t->dir)+1);
1567 if (imsg_flush(&ibuf) == -1)
1568 fatal("imsg_flush");
1572 run_test(struct test *t)
1579 puts("=====================");
1581 puts("=====================");
1587 if (t->body == NULL) {
1589 printf("no instructions, skipping...\n");
1593 pid = spawn_client_proc();
1594 prepare_child_for_test(t);
1595 ret = eval(t->body);
1597 imsg_compose(&ibuf, IMSG_CONN_GONE, 0, 0, -1, NULL, 0);
1600 while (waitpid(pid, NULL, 0) != pid)
1605 if (t->shouldfail) {
1606 if (ret == EVAL_OK) {
1608 printf("test was expected to fail\n");
1610 } else if (ret == EVAL_ERR)
1618 main(int argc, char **argv)
1621 int ch, i, r, passed = 0, failed = 0, skipped = 0;
1624 assert(argv0 = argv[0]);
1626 signal(SIGPIPE, SIG_IGN);
1628 log_init(1, LOG_DAEMON);
1631 /* prepare the global env */
1634 add_builtin_proc("print", builtin_print, 1, 1);
1635 add_builtin_proc("debug", builtin_debug, 1, 1);
1636 add_builtin_proc("skip", builtin_skip, 0, 0);
1637 add_builtin_proc("iota", builtin_iota, 0, 0);
1638 add_builtin_proc("send", builtin_send, 2, 1);
1639 add_builtin_proc("recv", builtin_recv, 0, 0);
1641 while ((ch = getopt(argc, argv, "nT:v")) != -1) {
1647 assert(*optarg == 'c');
1654 fprintf(stderr, "Usage: %s [-nv] [files...]\n",
1665 for (i = 0; i < argc; ++i)
1669 fprintf(stderr, "files OK\n");
1673 /* Check for root privileges. */
1675 fatalx("need root privileges");
1678 TAILQ_FOREACH(t, &tests, entry) {
1679 printf("===> [%d/%d] running test \"%s\"... ", i+1, ntests,
1698 printf("skipped\n");
1709 printf("passed %d/%d (%d skipped and %d failed)\n",
1710 passed, i, skipped, failed);