Go to:
Gentoo Home
Documentation
Forums
Lists
Bugs
Planet
Store
Wiki
Get Gentoo!
Gentoo's Bugzilla – Attachment 397280 Details for
Bug 531724
sys-apps/portage: PipeReaderPtyTestCase tests fail intermittently
Home
|
New
–
[Ex]
|
Browse
|
Search
|
Privacy Policy
|
[?]
|
Reports
|
Requests
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
C equivalent standalone test case (read regardless of EPOLLIN like portage-2.2.17 does)
test_read_pty.c (text/x-csrc), 3.45 KB, created by
Zac Medico
on 2015-02-22 22:27:09 UTC
(
hide
)
Description:
C equivalent standalone test case (read regardless of EPOLLIN like portage-2.2.17 does)
Filename:
MIME Type:
Creator:
Zac Medico
Created:
2015-02-22 22:27:09 UTC
Size:
3.45 KB
patch
obsolete
>// Attempt to read for all events (regardless of EPOLLIN), >// like portage-2.2.17 does: >// https://github.com/gentoo/portage/commit/b3bba4dc8f4f93adeaeaf662870bb00a09bb1de7 >// >// build: gcc -lutil test_read_pty.c -o test_read_pty >// usage: for x in {1..100} ; do ./test_read_pty || break ; done > >#include <errno.h> >#include <fcntl.h> >#include <pty.h> >#include <stdio.h> >#include <stdlib.h> >#include <string.h> >#include <sys/epoll.h> >#include <unistd.h> > >#define MAXEVENTS 64 >#define BUFSIZE 4096 >#define TEST_COUNT 11 > >ssize_t test_read(ssize_t length, char* error_msg) >{ > int eof, epfd, producer_fd, consumer_fd, > flags, s, i, n, total_read, pid; > ssize_t count; > char *buf; > struct epoll_event event; > struct epoll_event *events; > > s = openpty(&consumer_fd, &producer_fd, NULL, NULL, NULL); > if (s < 0) > { > perror("openpty"); > abort(); > } > > flags = fcntl(consumer_fd, F_GETFL, 0); > if (flags == -1) > { > perror("fcntl"); > abort(); > } > > flags |= O_NONBLOCK; > s = fcntl (consumer_fd, F_SETFL, flags); > if (s == -1) > { > perror("fcntl"); > abort(); > } > > pid = fork(); > if (pid == 0) > { > close(consumer_fd); > buf = calloc(BUFSIZE, sizeof(char)); > if (buf == NULL) > { > perror("calloc"); > abort(); > } > while (length > 0) > { > count = length % BUFSIZE; > if (count == 0) > count = BUFSIZE; > count = write(producer_fd, buf, count); > if (count == -1) > { > perror("write"); > break; > } > else > { > length -= count; > } > } > close(producer_fd); > free(buf); > if (length > 0) > _exit(EXIT_FAILURE); > else > _exit(EXIT_SUCCESS); > } > else if (pid == -1) > { > perror("fork"); > abort(); > } > > close(producer_fd); > epfd = epoll_create1(EPOLL_CLOEXEC); > if (epfd == -1) > { > perror("epoll_create1"); > abort(); > } > > event.data.fd = consumer_fd; > event.events = EPOLLIN; > s = epoll_ctl(epfd, EPOLL_CTL_ADD, consumer_fd, &event); > if (s == -1) > { > perror("epoll_ctl"); > abort(); > } > > events = calloc(MAXEVENTS, sizeof event); > if (events == NULL) > { > perror("calloc"); > abort(); > } > buf = calloc(BUFSIZE, sizeof(char)); > if (buf == NULL) > { > perror("calloc"); > abort(); > } > eof = 0; > total_read = 0; > while (!eof) > { > n = epoll_wait(epfd, events, MAXEVENTS, -1); > for (i = 0; i < n; i++) > { > while (!eof) > { > count = read(events[i].data.fd, buf, BUFSIZE); > if (count == -1) > { > if (errno != EAGAIN) > { > eof = 1; > sprintf(error_msg, "%s", strerror(errno)); > } > break; > } > else if (count == 0) > { > eof = 1; > sprintf(error_msg, "read returned 0 bytes"); > break; > } > total_read += count; > } > > if (events[i].events & EPOLLHUP) > { > eof = 1; > sprintf(error_msg, "EPOLLHUP"); > break; > } > > if (events[i].events & EPOLLERR) > { > eof = 1; > sprintf(error_msg, "EPOLLERR"); > break; > } > } > } > > free(events); > free(buf); > close(epfd); > close(consumer_fd); > > return total_read; >} > >int run_tests() >{ > char error_msg[32]; > int i; > ssize_t result; > ssize_t test_lengths[TEST_COUNT] = > {1, 2, 5, 6, 7, 8, 1 << 5, 1 << 10, 1 << 12, 1 << 13, 1 << 14}; > for (i = 0; i < TEST_COUNT; i++) > { > //fprintf(stdout, "testing %d\n", test_lengths[i]); > result = test_read(test_lengths[i], error_msg); > if (result != test_lengths[i]) > { > fprintf(stderr, "%d != %d eof: %s\n", (int)test_lengths[i], > (int)result, error_msg); > return EXIT_FAILURE; > } > } > return EXIT_SUCCESS; >} > >int main (int argc, char *argv[]) >{ > if (argc != 1) > { > fprintf(stderr, "Usage: %s\n", argv[0]); > exit(EXIT_FAILURE); > } > > return run_tests(); >}
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Raw
Actions:
View
Attachments on
bug 531724
:
392412
|
392414
|
392416
|
396310
| 397280