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>
49 static const char *argv0;
51 static uint8_t *lastmsg;
53 static struct imsgbuf ibuf;
54 static int ibuf_inuse;
55 static int child_out = -1;
57 static struct procs procs = TAILQ_HEAD_INITIALIZER(procs);
58 static struct tests tests = TAILQ_HEAD_INITIALIZER(tests);
62 static struct opstacks blocks = TAILQ_HEAD_INITIALIZER(blocks);
63 static struct opstacks args = TAILQ_HEAD_INITIALIZER(args);
65 #define STACK_HEIGHT 64
66 static struct value vstack[STACK_HEIGHT];
69 static struct envs envs = TAILQ_HEAD_INITIALIZER(envs);
71 static struct value v_false = {.type = V_NUM, .v = {.num = 0}};
72 static struct value v_true = {.type = V_NUM, .v = {.num = 1}};
74 static uint8_t lasttag;
77 static int syntaxcheck;
79 static const char *filler;
91 check_for_output(void)
93 static char buf[BUFSIZ];
99 if (poll(&pfd, 1, 0) == -1)
102 if (!(pfd.revents & POLLIN))
106 if ((r = read(child_out, buf, sizeof(buf))) == -1) {
114 fwrite(buf, 1, r, stdout);
119 peekn(int depth, struct value *v)
122 errx(1, "can't peek the stack at %d: underflow",
124 memcpy(v, &vstack[stackh - depth], sizeof(*v));
127 printf("peeking(%d) ", depth); pp_val(v); printf("\n");
132 popv(struct value *v)
135 errx(1, "can't pop the stack: underflow");
136 memcpy(v, &vstack[--stackh], sizeof(*v));
139 printf("popping "); pp_val(v); printf("\n");
153 pushv(struct value *v)
155 if (stackh == STACK_HEIGHT)
156 errx(1, "can't push the stack: overflow");
159 printf("pushing "); pp_val(v); printf("\n");
162 memcpy(&vstack[stackh++], v, sizeof(*v));
168 pushv(n ? &v_true : &v_false);
181 static inline struct opstack *
182 pushstack(struct opstacks *stack)
186 ops = xcalloc(1, sizeof(*ops));
187 TAILQ_INSERT_HEAD(stack, ops, entry);
191 static inline struct opstack *
192 peek(struct opstacks *stack)
194 if (TAILQ_EMPTY(stack))
195 errx(1, "%s: args underflow", __func__);
197 return TAILQ_FIRST(stack);
200 static inline struct op *
201 finalize(struct opstacks *stack, int *argc)
206 if (TAILQ_EMPTY(stack))
207 errx(1, "%s: args underflow", __func__);
210 TAILQ_REMOVE(&args, ops, entry);
214 *argc = ops->counter;
221 push(struct opstacks *stack, struct op *op)
226 if (ops->last == NULL) {
230 ops->last->next = op;
242 e = xcalloc(1, sizeof(*e));
243 TAILQ_INSERT_HEAD(&envs, e, entry);
246 static inline struct env *
249 assert(!TAILQ_EMPTY(&envs));
250 return TAILQ_FIRST(&envs);
257 struct binding *b, *tb;
260 TAILQ_REMOVE(&envs, e, entry);
262 TAILQ_FOREACH_SAFE(b, &e->bindings, entry, tb)
269 setvar(char *sym, struct op *op)
276 if ((ret = eval(op)) != EVAL_OK)
279 if (stackh != height + 1) {
281 printf("trying to assign to `%s' a void value: ", sym);
287 b = xcalloc(1, sizeof(*b));
291 e = TAILQ_FIRST(&envs);
292 TAILQ_INSERT_HEAD(&e->bindings, b, entry);
298 setvar_raw(char *sym, struct op *op)
303 b = xcalloc(1, sizeof(*b));
307 e = TAILQ_FIRST(&envs);
308 TAILQ_INSERT_HEAD(&e->bindings, b, entry);
312 getvar(const char *sym, struct value *v)
317 TAILQ_FOREACH(e, &envs, entry) {
318 TAILQ_FOREACH(b, &e->bindings, entry) {
319 if (!strcmp(sym, b->name)) {
320 memcpy(v, &b->val, sizeof(*v));
327 fprintf(stderr, "unbound variable %s\n", sym);
332 getvar_raw(const char *sym, struct op **raw)
337 TAILQ_FOREACH(e, &envs, entry) {
338 TAILQ_FOREACH(b, &e->bindings, entry) {
339 if (!strcmp(sym, b->name)) {
350 global_set(char *sym, struct op *op)
355 /* TODO: check for duplicates */
357 if (op->type != OP_LITERAL &&
358 (op->type == OP_CAST && op->v.cast.expr->type != OP_LITERAL))
361 b = xcalloc(1, sizeof(*b));
364 /* it's only a cast on a literal! */
365 if (op->type == OP_CAST) {
366 if (eval(op) != EVAL_OK) {
372 memcpy(&b->val, &op->v.literal, sizeof(b->val));
374 e = TAILQ_LAST(&envs, envs);
375 TAILQ_INSERT_HEAD(&e->bindings, b, entry);
385 op = xcalloc(1, sizeof(*op));
392 free_op_rec(struct op *op)
404 free_op(struct op *op)
415 free(op->v.assign.name);
416 free_op_rec(op->v.assign.expr);
419 free_op_rec(op->v.assert);
422 free_op_rec(op->v.funcall.argv);
428 free_op_rec(op->v.cast.expr);
431 free_op_rec(op->v.cmp_eq.a);
432 free_op_rec(op->v.cmp_eq.b);
435 free_op_rec(op->v.faccess.expr);
436 free(op->v.faccess.field);
439 free(op->v.sfail.msg);
440 free_op_rec(op->v.sfail.expr);
453 return newop(OP_REST);
457 op_assign(char *sym, struct op *expr)
461 op = newop(OP_ASSIGN);
462 op->v.assign.name = sym;
463 op->v.assign.expr = expr;
469 op_assert(struct op *expr)
473 op = newop(OP_ASSERT);
491 op_lit_str(char *str)
495 op = newop(OP_LITERAL);
496 op->v.literal.type = V_STR;
497 op->v.literal.v.str = str;
503 op_lit_num(uint64_t n)
507 op = newop(OP_LITERAL);
508 op->v.literal.type = V_NUM;
509 op->v.literal.v.num = n;
515 op_cmp_eq(struct op *a, struct op *b)
519 op = newop(OP_CMP_EQ);
527 op_cast(struct op *expr, int totype)
532 op->v.cast.expr = expr;
533 op->v.cast.totype = totype;
539 op_faccess(struct op *expr, char *field)
543 op = newop(OP_FACCESS);
544 op->v.faccess.expr = expr;
545 op->v.faccess.field = field;
551 op_sfail(struct op *expr, char *msg)
555 op = newop(OP_SFAIL);
556 op->v.sfail.expr = expr;
557 op->v.sfail.msg = msg;
567 op = newop(OP_VARGS);
573 ppf_val(FILE *f, struct value *val)
579 fprintf(f, "%s", val->v.str);
582 fprintf(f, "\"%s\"", val->v.str);
585 fprintf(f, "%"PRIi64, val->v.num);
588 fprintf(f, "%"PRIu8, val->v.u8);
591 fprintf(f, "%"PRIu16, val->v.u16);
594 fprintf(f, "%"PRIu32, val->v.u32);
598 for (i = 0; i < val->v.msg.len; ++i)
599 fprintf(f, "%x%s", val->v.msg.msg[i],
600 i == val->v.msg.len-1 ? "" : " ");
604 fprintf(f, "qids[n=%zu]", val->v.qidvec.len);
607 fprintf(f, "<unknown value>");
613 pp_val(struct value *val)
615 ppf_val(stdout, val);
619 val_type(struct value *v)
622 case V_SYM: return "symbol";
623 case V_STR: return "string";
624 case V_NUM: return "number";
625 case V_MSG: return "message";
626 case V_QID: return "qid";
627 case V_U8: return "u8";
628 case V_U16: return "u16";
629 case V_U32: return "u32";
630 default: return "unknown";
635 val_trueish(struct value *a)
643 val_isnum(struct value *a)
645 return a->type == V_NUM
652 val_tonum(struct value *a)
655 case V_NUM: return a->v.num;
656 case V_U8: return a->v.u8;
657 case V_U16: return a->v.u16;
658 case V_U32: return a->v.u32;
661 fprintf(stderr, "%s: given value is not a number\n", __func__);
667 val_eq(struct value *a, struct value *b)
669 if (val_isnum(a) && val_isnum(b))
670 return val_tonum(a) == val_tonum(b);
672 if (a->type != b->type)
678 return !strcmp(a->v.str, b->v.str);
684 static inline const char *
685 pp_totype(int totype)
688 * Not all of these are valid cast type thought, including
689 * every possibility only to aid debugging.
692 case V_STR: return "str";
693 case V_SYM: return "sym";
694 case V_NUM: return "num";
695 case V_QID: return "qid";
696 case V_U8: return "u8";
697 case V_U16: return "u16";
698 case V_U32: return "u32";
699 default: return "unknown";
704 val_cast(struct value *a, int totype)
708 #define NUMCAST(val, t, c, totype, max) do { \
711 fprintf(stderr, "can't cast %"PRIu64 \
712 " to %s\n", val, pp_totype(totype)); \
720 if (a->type == totype)
725 fprintf(stderr, "can't cast ");
727 fprintf(stderr, " to type %s\n", pp_totype(totype));
733 case V_U8: NUMCAST(v, u8, uint8_t, totype, UINT8_MAX);
734 case V_U16: NUMCAST(v, u16, uint16_t, totype, UINT16_MAX);
735 case V_U32: NUMCAST(v, u32, uint32_t, totype, UINT32_MAX);
738 fprintf(stderr, "can't cast %"PRIu64" to %s\n",
739 v, pp_totype(totype));
747 val_faccess(struct value *a, const char *field, struct value *ret)
753 #define MSGTYPE(m) *(m.msg + 4) /* skip the length */
757 /* TODO: add path. needs uint64_t values thought! */
758 if (!strcmp(field, "vers")) {
760 memcpy(&ret->v.u32, a->v.qid+1, 4);
762 } else if (!strcmp(field, "type")) {
764 ret->v.u8 = *a->v.qid;
770 mtype = MSGTYPE(a->v.msg);
771 if (!strcmp(field, "type")) {
773 ret->v.u8 = MSGTYPE(a->v.msg);
775 } else if (!strcmp(field, "tag")) {
777 memcpy(&ret->v.u16, &a->v.msg.msg[5], 2);
778 ret->v.u16 = le16toh(ret->v.u16);
780 } else if (!strcmp(field, "msize") && mtype == Rversion) {
782 memcpy(&ret->v.u32, &a->v.msg.msg[7], 4);
783 ret->v.u32 = le32toh(ret->v.u32);
785 } else if (!strcmp(field, "qid") && mtype == Rattach) {
787 memcpy(&ret->v.qid, &a->v.msg.msg[7], QIDSIZE);
789 } else if (!strcmp(field, "nwqid") && mtype == Rwalk) {
791 memcpy(&ret->v.u16, &a->v.msg.msg[7], 2);
792 ret->v.u16 = le16toh(ret->v.u16);
794 } else if (!strcmp(field, "wqid") && mtype == Rwalk) {
795 ret->type = V_QIDVEC;
796 ret->v.qidvec.start = &a->v.msg.msg[9];
797 memcpy(&len, &a->v.msg.msg[7], 2);
799 ret->v.qidvec.len = len;
805 len = strtonum(field, 0, MAXWELEM, &errstr);
806 if (errstr != NULL) {
808 printf("can't access qid #%s: %s\n", field, errstr);
812 if (len >= a->v.qidvec.len) {
814 printf("can't access qid #%d: out-of-bound "
815 "(max %zu)\n", len, a->v.qidvec.len);
820 memcpy(&ret->v.qid, a->v.qidvec.start + len * QIDSIZE,
830 printf("can't access field `%s' on type %s (", field, val_type(a));
848 printf("%s = ", op->v.assign.name);
849 pp_op(op->v.assign.expr);
856 printf("funcall %s(", op->v.funcall.proc->name);
857 for (aux = op->v.funcall.argv; aux != NULL; aux = aux->next) {
859 if (aux->next != NULL)
865 pp_val(&op->v.literal);
868 printf("%s", op->v.var);
871 pp_op(op->v.cast.expr);
873 switch (op->v.cast.totype) {
874 case V_U8: printf("u8"); break;
875 case V_U16: printf("u16"); break;
876 case V_U32: printf("u32"); break;
877 case V_STR: printf("str"); break;
878 default: printf("???"); break;
882 pp_op(op->v.cmp_eq.a);
884 pp_op(op->v.cmp_eq.b);
887 pp_op(op->v.faccess.expr);
888 printf(".%s", op->v.faccess.field);
891 printf("should-fail ");
892 pp_op(op->v.sfail.expr);
893 if (op->v.sfail.msg != NULL)
894 printf(": \"%s\"", op->v.sfail.msg);
900 printf(" ???[%d] ", op->type);
905 pp_block(struct op *op)
921 struct op *t, *tnext;
932 * Try to load the rest argument. Note that it can be
935 if ((ret = getvar_raw("...", &t)) == EVAL_OK)
936 if ((ret = eval(t)) != EVAL_OK)
941 ret = setvar(op->v.assign.name, op->v.assign.expr);
947 if ((ret = eval(op->v.assert)) != EVAL_OK)
950 if (!val_trueish(&a)) {
952 printf("assertion failed: ");
960 /* assume airity matches */
962 proc = op->v.funcall.proc;
963 if (proc->nativefn != NULL) {
965 * Push arguments on the stack for builtin
966 * functions. Counting the height of the
967 * stack is done to compute the correct number
968 * in the vararg case. argc only counts the
969 * "syntactical" arguments, i.e. foo(x, ...)
970 * has argc == 2, but at runtime argc may be
971 * 1, 2 or a greater number!
975 t = op->v.funcall.argv;
976 if (t != NULL && (ret = eval(t)) != EVAL_OK)
982 if ((ret = proc->nativefn(i))
986 if (proc->body == NULL) {
988 printf("warn: calling the empty proc `%s'\n",
995 for (t = op->v.funcall.argv, i = 0;
999 * Push a pseudo variable `...' (and
1000 * don't evaluate it) in the vararg
1001 * case. A special case is when the
1002 * variable is itself `...'.
1004 if (proc->vararg && i == proc->minargs) {
1005 if (t->type != OP_REST)
1006 setvar_raw(xstrdup("..."), t);
1011 * The arguments are a linked list of
1012 * ops. Setvar will call eval that
1013 * will evaluate *all* the arguments.
1014 * The dance here that sets next to
1015 * NULL and then restores it is to
1016 * avoid this behaviour.
1020 ret = setvar(proc->args[i], t);
1027 if ((ret = eval(proc->body)) != EVAL_OK)
1036 pushv(&op->v.literal);
1040 if ((ret = getvar(op->v.var, &a)) != EVAL_OK)
1046 if ((ret = eval(op->v.cast.expr)) != EVAL_OK)
1049 if ((ret = val_cast(&a, op->v.cast.totype)) != EVAL_OK)
1055 if ((ret = eval(op->v.cmp_eq.a)) != EVAL_OK)
1057 if ((ret = eval(op->v.cmp_eq.b)) != EVAL_OK)
1062 pushbool(val_eq(&a, &b));
1067 if ((ret = eval(op->v.faccess.expr)) != EVAL_OK)
1070 if ((ret = val_faccess(&a, op->v.faccess.field, &b))
1077 if ((ret = eval(op->v.sfail.expr)) == EVAL_OK) {
1079 printf("expecting failure");
1080 if (op->v.sfail.msg != NULL)
1081 printf(" \"%s\"", op->v.sfail.msg);
1083 printf("expression: ");
1084 pp_op(op->v.sfail.expr);
1088 if (ret == EVAL_SKIP)
1093 if ((ret = getvar_raw("...", &t)) == EVAL_OK) {
1094 for (i = 0; t != NULL; t = t->next)
1103 fprintf(stderr, "invalid op, aborting.\n");
1108 return eval(op->next);
1113 prepare_funcall(void)
1119 push_arg(struct op *op)
1125 op_funcall(struct proc *proc)
1127 struct op *op, *argv;
1130 argv = finalize(&args, &argc);
1132 op = newop(OP_FUNCALL);
1133 op->v.funcall.proc = proc;
1134 op->v.funcall.argv = argv;
1135 op->v.funcall.argc = argc;
1141 add_builtin_proc(const char *name, int (*fn)(int), int argc, int vararg)
1145 proc = xcalloc(1, sizeof(*proc));
1146 proc->name = xstrdup(name);
1147 proc->nativefn = fn;
1148 proc->minargs = argc;
1149 proc->vararg = vararg;
1151 TAILQ_INSERT_HEAD(&procs, proc, entry);
1161 proc_setup_body(void)
1163 struct opstack *argv;
1168 for (i = 0, op = argv->base.next; op != NULL; i++) {
1170 * TODO: should free the whole list on error but..,
1171 * we're gonna exit real soon(tm)!
1173 if (op->type != OP_VAR && op->type != OP_REST)
1179 assert(i == argv->counter);
1185 proc_done(char *name)
1188 struct op *op, *next, *argv, *body;
1191 argv = finalize(&args, &argc);
1192 body = finalize(&blocks, NULL);
1194 proc = xcalloc(1, sizeof(*proc));
1196 proc->minargs = argc;
1198 for (i = 0, op = argv; op != NULL; ++i) {
1199 if (op->type == OP_REST) {
1205 proc->args[i] = xstrdup(op->v.var);
1211 assert(i == argc || (proc->vararg && i == proc->minargs));
1215 TAILQ_INSERT_HEAD(&procs, proc, entry);
1219 block_push(struct op *op)
1225 proc_by_name(const char *name)
1229 TAILQ_FOREACH(p, &procs, entry) {
1230 if (!strcmp(p->name, name))
1244 test_done(int shouldfail, char *name, char *dir)
1248 test = xcalloc(1, sizeof(*test));
1249 test->shouldfail = shouldfail;
1252 test->body = finalize(&blocks, NULL);
1254 if (TAILQ_EMPTY(&tests))
1255 TAILQ_INSERT_HEAD(&tests, test, entry);
1257 TAILQ_INSERT_TAIL(&tests, test, entry);
1263 builtin_print(int argc)
1270 for (i = argc; i > 0; --i) {
1272 if (v.type == V_STR)
1273 printf("%s", v.v.str);
1287 builtin_debug(int argc)
1290 return builtin_print(argc);
1297 builtin_skip(int argc)
1303 builtin_iota(int argc)
1308 if ((v.v.u16 = ++lasttag) == 255)
1309 v.v.u16 = ++lasttag;
1316 builtin_send(int argc)
1327 * Compute the length of the packet. 4 is for the initial
1332 for (i = argc; i > 0; --i) {
1336 len += 2; /* count */
1337 len += strlen(v.v.str);
1354 printf("%s: can't serialize ", __func__);
1361 if (len > UINT16_MAX) {
1363 printf("%s: message size too long: got %d when max is %d\n",
1364 __func__, len, UINT16_MAX);
1368 if ((buf = imsg_create(&ibuf, IMSG_BUF, 0, 0, len)) == NULL)
1369 fatal("imsg_create(%d)", len);
1372 imsg_add(buf, &len, sizeof(len));
1374 for (i = argc; i > 0; --i) {
1378 slen = strlen(v.v.str);
1379 slen = htole16(slen);
1380 imsg_add(buf, &slen, sizeof(slen));
1381 imsg_add(buf, v.v.str, strlen(v.v.str));
1385 imsg_add(buf, &v.v.u8, 1);
1389 v.v.u16 = htole16(v.v.u16);
1390 imsg_add(buf, &v.v.u16, 2);
1394 v.v.u32 = htole32(v.v.u32);
1395 imsg_add(buf, &v.v.u32, 4);
1400 imsg_close(&ibuf, buf);
1402 if (imsg_flush(&ibuf) == -1) {
1405 printf("%s: imsg_flush failed: %s\n", __func__, strerror(i));
1414 builtin_recv(int argc)
1422 if (lastmsg != NULL) {
1428 pfd.events = POLLIN;
1429 if (poll(&pfd, 1, INFTIM) == -1) {
1432 printf("%s: poll failed: %s\n", __func__, strerror(serrno));
1437 if ((n = imsg_read(&ibuf)) == -1) {
1438 if (errno == EAGAIN)
1445 printf("child disconnected\n");
1452 /* read only one message */
1453 if ((n = imsg_get(&ibuf, &imsg)) == -1)
1458 datalen = imsg.hdr.len - IMSG_HEADER_SIZE;
1459 switch (imsg.hdr.type) {
1462 if ((v.v.msg.msg = malloc(datalen)) == NULL)
1464 memcpy(v.v.msg.msg, imsg.data, datalen);
1465 v.v.msg.len = datalen;
1472 printf("subprocess closed the connection\n");
1482 printf("got unknown message from subprocess: %d\n",
1490 spawn_client_proc(void)
1492 const char *argv[4];
1493 int p[2], out[2], argc = 0;
1496 if (child_out != -1)
1499 if (socketpair(AF_UNIX, SOCK_STREAM | SOCK_CLOEXEC | SOCK_NONBLOCK,
1500 PF_UNSPEC, p) == -1)
1501 fatal("socketpair");
1503 if (socketpair(AF_UNIX, SOCK_STREAM | SOCK_CLOEXEC | SOCK_NONBLOCK,
1504 PF_UNSPEC, out) == -1)
1505 fatal("socketpair");
1507 switch (pid = fork()) {
1509 fatal("cannot fork");
1517 msgbuf_clear(&ibuf.w);
1520 imsg_init(&ibuf, p[0]);
1528 if (dup2(out[1], 1) == -1 ||
1529 dup2(out[1], 2) == -1)
1533 if (dup2(p[1], 3) == -1)
1534 fatal("cannot setup imsg fd");
1535 } else if (fcntl(F_SETFD, 0) == -1)
1536 fatal("cannot setup imsg fd");
1538 argv[argc++] = argv0;
1539 argv[argc++] = "-Tc";
1542 argv[argc++] = "-v";
1545 argv[argc++] = NULL;
1547 execvp(argv0, (char *const *)argv);
1552 prepare_child_for_test(struct test *t)
1557 if (stat(t->dir, &sb) == -1)
1558 fatal("stat(\"%s\")", t->dir);
1560 if ((pw = getpwuid(sb.st_uid)) == NULL)
1561 fatal("getpwuid(%d)", sb.st_uid);
1563 imsg_compose(&ibuf, IMSG_AUTH, 0, 0, -1,
1564 pw->pw_name, strlen(pw->pw_name)+1);
1565 imsg_compose(&ibuf, IMSG_AUTH_DIR, 0, 0, -1,
1566 t->dir, strlen(t->dir)+1);
1568 if (imsg_flush(&ibuf) == -1)
1569 fatal("imsg_flush");
1573 run_test(struct test *t)
1580 puts("=====================");
1582 puts("=====================");
1588 if (t->body == NULL) {
1590 printf("no instructions, skipping...\n");
1594 pid = spawn_client_proc();
1595 prepare_child_for_test(t);
1596 ret = eval(t->body);
1598 imsg_compose(&ibuf, IMSG_CONN_GONE, 0, 0, -1, NULL, 0);
1601 while (waitpid(pid, NULL, 0) != pid)
1606 if (t->shouldfail) {
1607 if (ret == EVAL_OK) {
1609 printf("test was expected to fail\n");
1611 } else if (ret == EVAL_ERR)
1619 main(int argc, char **argv)
1622 int ch, i, r, passed = 0, failed = 0, skipped = 0;
1624 const char *pat = NULL;
1627 assert(argv0 = argv[0]);
1629 signal(SIGPIPE, SIG_IGN);
1631 log_init(1, LOG_DAEMON);
1634 /* prepare the global env */
1637 add_builtin_proc("print", builtin_print, 1, 1);
1638 add_builtin_proc("debug", builtin_debug, 1, 1);
1639 add_builtin_proc("skip", builtin_skip, 0, 0);
1640 add_builtin_proc("iota", builtin_iota, 0, 0);
1641 add_builtin_proc("send", builtin_send, 2, 1);
1642 add_builtin_proc("recv", builtin_recv, 0, 0);
1644 while ((ch = getopt(argc, argv, "nT:vx:")) != -1) {
1650 assert(*optarg == 'c');
1660 fprintf(stderr, "Usage: %s [-nv] [files...]\n",
1674 if (regcomp(®, pat, REG_BASIC | REG_ICASE | REG_NOSUB) != 0)
1675 fatalx("invalid regexp: %s", pat);
1677 for (i = 0; i < argc; ++i)
1681 fprintf(stderr, "files OK\n");
1685 /* Check for root privileges. */
1687 fatalx("need root privileges");
1690 TAILQ_FOREACH(t, &tests, entry) {
1691 if (regexec(®, t->name, 0, NULL, 0) != 0)
1694 printf("===> [%d/%d] running test \"%s\"... ", i+1, ntests,
1713 printf("skipped\n");
1724 printf("%d/%d passed (%d skipped and %d failed)\n",
1725 passed, i, skipped, failed);