• Home
  • Raw
  • Download

Lines Matching refs:fd_cmp

285 struct fd_cmp {  struct
298 static int fd_cmp_check_activity(struct fd_cmp *fd_cmp) in fd_cmp_check_activity() argument
303 if (fd_cmp == NULL || fd_cmp->fd < 0 || fd_cmp->activity) in fd_cmp_check_activity()
307 if (stat(fd_cmp->path, &st) == 0 && st.st_size == 0) in fd_cmp_check_activity()
311 fd_cmp->name); in fd_cmp_check_activity()
316 static bool fd_cmp_is_active(struct fd_cmp *fd_cmp) in fd_cmp_is_active() argument
318 return fd_cmp->fd != -1; in fd_cmp_is_active()
321 static int fd_cmp_open_monitor(struct fd_cmp *fd_cmp, int fd, int fd_ep) in fd_cmp_open_monitor() argument
326 ep.data.ptr = fd_cmp; in fd_cmp_open_monitor()
335 static int fd_cmp_open_std(struct fd_cmp *fd_cmp, in fd_cmp_open_std() argument
347 ep.data.ptr = fd_cmp; in fd_cmp_open_std()
358 static int fd_cmp_open(struct fd_cmp **fd_cmp_out, in fd_cmp_open()
363 struct fd_cmp *fd_cmp; in fd_cmp_open() local
365 fd_cmp = calloc(1, sizeof(*fd_cmp)); in fd_cmp_open()
366 if (fd_cmp == NULL) { in fd_cmp_open()
373 err = fd_cmp_open_monitor(fd_cmp, fd, fd_ep); in fd_cmp_open()
376 fd_cmp->name = "STDOUT"; in fd_cmp_open()
377 err = fd_cmp_open_std(fd_cmp, fn, fd, fd_ep); in fd_cmp_open()
380 fd_cmp->name = "STDERR"; in fd_cmp_open()
381 err = fd_cmp_open_std(fd_cmp, fn, fd, fd_ep); in fd_cmp_open()
389 free(fd_cmp); in fd_cmp_open()
393 fd_cmp->fd_match = err; in fd_cmp_open()
394 fd_cmp->fd = fd; in fd_cmp_open()
395 fd_cmp->type = type; in fd_cmp_open()
396 fd_cmp->path = fn; in fd_cmp_open()
398 *fd_cmp_out = fd_cmp; in fd_cmp_open()
402 static int fd_cmp_check_ev_in(struct fd_cmp *fd_cmp) in fd_cmp_check_ev_in() argument
404 if (fd_cmp->type == FD_CMP_MONITOR) { in fd_cmp_check_ev_in()
408 fd_cmp->activity = true; in fd_cmp_check_ev_in()
413 static void fd_cmp_delete_ep(struct fd_cmp *fd_cmp, int fd_ep) in fd_cmp_delete_ep() argument
415 if (epoll_ctl(fd_ep, EPOLL_CTL_DEL, fd_cmp->fd, NULL) < 0) { in fd_cmp_delete_ep()
416 ERR("could not remove fd %d from epoll: %m\n", fd_cmp->fd); in fd_cmp_delete_ep()
418 fd_cmp->fd = -1; in fd_cmp_delete_ep()
421 static void fd_cmp_close(struct fd_cmp *fd_cmp) in fd_cmp_close() argument
423 if (fd_cmp == NULL) in fd_cmp_close()
426 if (fd_cmp->fd >= 0) in fd_cmp_close()
427 close(fd_cmp->fd); in fd_cmp_close()
428 free(fd_cmp); in fd_cmp_close()
443 static bool fd_cmp_regex(struct fd_cmp *fd_cmp, const struct test *t) in fd_cmp_regex() argument
448 if (fd_cmp->head >= sizeof(fd_cmp->buf)) { in fd_cmp_regex()
449 ERR("Read %zu bytes without a newline\n", sizeof(fd_cmp->buf)); in fd_cmp_regex()
450 ERR("output: %.*s", (int)sizeof(fd_cmp->buf), fd_cmp->buf); in fd_cmp_regex()
454 r = read(fd_cmp->fd, fd_cmp->buf + fd_cmp->head, in fd_cmp_regex()
455 sizeof(fd_cmp->buf) - fd_cmp->head); in fd_cmp_regex()
459 fd_cmp->head += r; in fd_cmp_regex()
467 p = memchr(fd_cmp->buf + done, '\n', fd_cmp->head - done); in fd_cmp_regex()
472 p_match = memchr(fd_cmp->buf_match + done_match, '\n', in fd_cmp_regex()
473 fd_cmp->head_match - done_match); in fd_cmp_regex()
475 if (fd_cmp->head_match >= sizeof(fd_cmp->buf_match)) { in fd_cmp_regex()
476 ERR("Read %zu bytes without a match\n", sizeof(fd_cmp->buf_match)); in fd_cmp_regex()
477 ERR("output: %.*s", (int)sizeof(fd_cmp->buf_match), fd_cmp->buf_match); in fd_cmp_regex()
482 r = read(fd_cmp->fd_match, fd_cmp->buf_match + fd_cmp->head_match, in fd_cmp_regex()
483 sizeof(fd_cmp->buf_match) - fd_cmp->head_match); in fd_cmp_regex()
485 ERR("could not read match fd %d\n", fd_cmp->fd_match); in fd_cmp_regex()
488 fd_cmp->head_match += r; in fd_cmp_regex()
489 p_match = memchr(fd_cmp->buf_match + done_match, '\n', in fd_cmp_regex()
490 fd_cmp->head_match - done_match); in fd_cmp_regex()
492 ERR("could not find match line from fd %d\n", fd_cmp->fd_match); in fd_cmp_regex()
498 if (!fd_cmp_regex_one(fd_cmp->buf_match + done_match, fd_cmp->buf + done)) { in fd_cmp_regex()
499 ERR("Output does not match pattern on %s:\n", fd_cmp->name); in fd_cmp_regex()
500 ERR("pattern: %s\n", fd_cmp->buf_match + done_match); in fd_cmp_regex()
501 ERR("output : %s\n", fd_cmp->buf + done); in fd_cmp_regex()
505 done = p - fd_cmp->buf + 1; in fd_cmp_regex()
506 done_match = p_match - fd_cmp->buf_match + 1; in fd_cmp_regex()
514 if (fd_cmp->head - done) in fd_cmp_regex()
515 memmove(fd_cmp->buf, fd_cmp->buf + done, fd_cmp->head - done); in fd_cmp_regex()
516 fd_cmp->head -= done; in fd_cmp_regex()
520 if (fd_cmp->head_match - done_match) in fd_cmp_regex()
521 memmove(fd_cmp->buf_match, fd_cmp->buf_match + done_match, in fd_cmp_regex()
522 fd_cmp->head_match - done_match); in fd_cmp_regex()
523 fd_cmp->head_match -= done_match; in fd_cmp_regex()
530 static bool fd_cmp_exact(struct fd_cmp *fd_cmp, const struct test *t) in fd_cmp_exact() argument
534 r = read(fd_cmp->fd, fd_cmp->buf, sizeof(fd_cmp->buf) - 1); in fd_cmp_exact()
541 rmatch = read(fd_cmp->fd_match, fd_cmp->buf_match + done, r - done); in fd_cmp_exact()
548 ERR("could not read match fd %d\n", fd_cmp->fd_match); in fd_cmp_exact()
555 fd_cmp->buf[r] = '\0'; in fd_cmp_exact()
556 fd_cmp->buf_match[r] = '\0'; in fd_cmp_exact()
559 printf("%s: %s\n", fd_cmp->name, fd_cmp->buf); in fd_cmp_exact()
561 if (!streq(fd_cmp->buf, fd_cmp->buf_match)) { in fd_cmp_exact()
562 ERR("Outputs do not match on %s:\n", fd_cmp->name); in fd_cmp_exact()
563 ERR("correct:\n%s\n", fd_cmp->buf_match); in fd_cmp_exact()
564 ERR("wrong:\n%s\n", fd_cmp->buf); in fd_cmp_exact()
577 struct fd_cmp *fd_cmp_out = NULL; in test_run_parent_check_outputs()
578 struct fd_cmp *fd_cmp_err = NULL; in test_run_parent_check_outputs()
579 struct fd_cmp *fd_cmp_monitor = NULL; in test_run_parent_check_outputs()
631 struct fd_cmp *fd_cmp = ev[i].data.ptr; in test_run_parent_check_outputs() local
635 err = fd_cmp_check_ev_in(fd_cmp); in test_run_parent_check_outputs()
640 ret = fd_cmp_regex(fd_cmp, t); in test_run_parent_check_outputs()
642 ret = fd_cmp_exact(fd_cmp, t); in test_run_parent_check_outputs()
649 fd_cmp_delete_ep(fd_cmp, fd_ep); in test_run_parent_check_outputs()