d77a67ed5f27.c 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. #include "../config-host.h"
  2. /* SPDX-License-Identifier: MIT */
  3. #include <stdio.h>
  4. #include <unistd.h>
  5. #include <string.h>
  6. #include <signal.h>
  7. #include <stdlib.h>
  8. #include "liburing.h"
  9. #include "helpers.h"
  10. static void sig_alrm(int sig)
  11. {
  12. fprintf(stderr, "Timed out!\n");
  13. exit(1);
  14. }
  15. int main(int argc, char *argv[])
  16. {
  17. struct io_uring_sqe *sqe;
  18. struct io_uring_cqe *cqe;
  19. struct io_uring_params p;
  20. struct io_uring ring;
  21. int ret, data;
  22. if (argc > 1)
  23. return T_EXIT_SKIP;
  24. signal(SIGALRM, sig_alrm);
  25. memset(&p, 0, sizeof(p));
  26. p.sq_thread_idle = 100;
  27. p.flags = IORING_SETUP_SQPOLL;
  28. ret = t_create_ring_params(4, &ring, &p);
  29. if (ret == T_SETUP_SKIP)
  30. return T_EXIT_SKIP;
  31. else if (ret < 0)
  32. return T_EXIT_FAIL;
  33. /* make sure sq thread is sleeping at this point */
  34. usleep(150000);
  35. alarm(1);
  36. sqe = io_uring_get_sqe(&ring);
  37. if (!sqe) {
  38. fprintf(stderr, "sqe get failed\n");
  39. return T_EXIT_FAIL;
  40. }
  41. io_uring_prep_nop(sqe);
  42. io_uring_sqe_set_data(sqe, (void *) (unsigned long) 42);
  43. io_uring_submit_and_wait(&ring, 1);
  44. ret = io_uring_peek_cqe(&ring, &cqe);
  45. if (ret) {
  46. fprintf(stderr, "cqe get failed\n");
  47. return 1;
  48. }
  49. data = (unsigned long) io_uring_cqe_get_data(cqe);
  50. if (data != 42) {
  51. fprintf(stderr, "invalid data: %d\n", data);
  52. return T_EXIT_FAIL;
  53. }
  54. return T_EXIT_PASS;
  55. }