pipe-bug.c 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. #include "../config-host.h"
  2. // SPDX-License-Identifier: MIT
  3. /*
  4. * Description: tests bug fixed in
  5. * "io_uring: don't gate task_work run on TIF_NOTIFY_SIGNAL"
  6. *
  7. * See: https://github.com/axboe/liburing/issues/665
  8. */
  9. #include <stdio.h>
  10. #include <string.h>
  11. #include <unistd.h>
  12. #include "helpers.h"
  13. #include "liburing.h"
  14. #define CHECK(x) \
  15. do { \
  16. if (!(x)) { \
  17. fprintf(stderr, "%s:%d %s failed\n", __FILE__, __LINE__, #x); \
  18. return -1; \
  19. } \
  20. } while (0)
  21. static int pipe_bug(void)
  22. {
  23. struct io_uring_params p;
  24. struct io_uring ring;
  25. struct io_uring_sqe *sqe;
  26. struct io_uring_cqe *cqe;
  27. char buf[1024];
  28. int fds[2];
  29. struct __kernel_timespec to = {
  30. .tv_sec = 1
  31. };
  32. CHECK(pipe(fds) == 0);
  33. memset(&p, 0, sizeof(p));
  34. CHECK(t_create_ring_params(8, &ring, &p) == 0);
  35. /* WRITE */
  36. sqe = io_uring_get_sqe(&ring);
  37. CHECK(sqe);
  38. io_uring_prep_write(sqe, fds[1], "foobar", strlen("foobar"), 0); /* or -1 */
  39. CHECK(io_uring_submit(&ring) == 1);
  40. CHECK(io_uring_wait_cqe(&ring, &cqe) == 0);
  41. io_uring_cqe_seen(&ring, cqe);
  42. /* CLOSE */
  43. sqe = io_uring_get_sqe(&ring);
  44. CHECK(sqe);
  45. io_uring_prep_close(sqe, fds[1]);
  46. CHECK(io_uring_submit(&ring) == 1);
  47. CHECK(io_uring_wait_cqe_timeout(&ring, &cqe, &to) == 0);
  48. io_uring_cqe_seen(&ring, cqe);
  49. /* READ */
  50. sqe = io_uring_get_sqe(&ring);
  51. CHECK(sqe);
  52. io_uring_prep_read(sqe, fds[0], buf, sizeof(buf), 0); /* or -1 */
  53. CHECK(io_uring_submit(&ring) == 1);
  54. CHECK(io_uring_wait_cqe_timeout(&ring, &cqe, &to) == 0);
  55. io_uring_cqe_seen(&ring, cqe);
  56. memset(buf, 0, sizeof(buf));
  57. /* READ */
  58. sqe = io_uring_get_sqe(&ring);
  59. CHECK(sqe);
  60. io_uring_prep_read(sqe, fds[0], buf, sizeof(buf), 0); /* or -1 */
  61. CHECK(io_uring_submit(&ring) == 1);
  62. CHECK(io_uring_wait_cqe_timeout(&ring, &cqe, &to) == 0);
  63. io_uring_cqe_seen(&ring, cqe);
  64. close(fds[0]);
  65. io_uring_queue_exit(&ring);
  66. return 0;
  67. }
  68. int main(int argc, char *argv[])
  69. {
  70. int i;
  71. if (argc > 1)
  72. return T_EXIT_SKIP;
  73. for (i = 0; i < 10000; i++) {
  74. if (pipe_bug())
  75. return T_EXIT_FAIL;
  76. }
  77. return T_EXIT_PASS;
  78. }