b5837bd5311d.c 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. #include "../config-host.h"
  2. /* SPDX-License-Identifier: MIT */
  3. /*
  4. * Description: Check to see if wait_nr is being honored.
  5. */
  6. #include <stdio.h>
  7. #include "liburing.h"
  8. #include "helpers.h"
  9. int main(int argc, char *argv[])
  10. {
  11. struct io_uring_sqe *sqe;
  12. struct io_uring_cqe *cqe;
  13. struct io_uring ring;
  14. int ret;
  15. struct __kernel_timespec ts = {
  16. .tv_sec = 0,
  17. .tv_nsec = 10000000
  18. };
  19. if (argc > 1)
  20. return T_EXIT_SKIP;
  21. if (io_uring_queue_init(4, &ring, 0) != 0) {
  22. fprintf(stderr, "ring setup failed\n");
  23. return T_EXIT_FAIL;
  24. }
  25. /*
  26. * First, submit the timeout sqe so we can actually finish the test
  27. * if everything is in working order.
  28. */
  29. sqe = io_uring_get_sqe(&ring);
  30. if (!sqe) {
  31. fprintf(stderr, "get sqe failed\n");
  32. return T_EXIT_FAIL;
  33. }
  34. io_uring_prep_timeout(sqe, &ts, (unsigned)-1, 0);
  35. ret = io_uring_submit(&ring);
  36. if (ret != 1) {
  37. fprintf(stderr, "Got submit %d, expected 1\n", ret);
  38. return T_EXIT_FAIL;
  39. }
  40. /*
  41. * Next, submit a nop and wait for two events. If everything is working
  42. * as it should, we should be waiting for more than a millisecond and we
  43. * should see two cqes. Otherwise, execution continues immediately
  44. * and we see only one cqe.
  45. */
  46. sqe = io_uring_get_sqe(&ring);
  47. if (!sqe) {
  48. fprintf(stderr, "get sqe failed\n");
  49. return T_EXIT_FAIL;
  50. }
  51. io_uring_prep_nop(sqe);
  52. ret = io_uring_submit_and_wait(&ring, 2);
  53. if (ret != 1) {
  54. fprintf(stderr, "Got submit %d, expected 1\n", ret);
  55. return T_EXIT_FAIL;
  56. }
  57. if (io_uring_peek_cqe(&ring, &cqe) != 0) {
  58. fprintf(stderr, "Unable to peek cqe!\n");
  59. return T_EXIT_FAIL;
  60. }
  61. io_uring_cqe_seen(&ring, cqe);
  62. if (io_uring_peek_cqe(&ring, &cqe) != 0) {
  63. fprintf(stderr, "Unable to peek cqe!\n");
  64. return T_EXIT_FAIL;
  65. }
  66. io_uring_queue_exit(&ring);
  67. return T_EXIT_PASS;
  68. }