drop-submit.c 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. #include "../config-host.h"
  2. /* SPDX-License-Identifier: MIT */
  3. /*
  4. * Description: test IORING_SETUP_SUBMIT_ALL
  5. *
  6. */
  7. #include <errno.h>
  8. #include <stdio.h>
  9. #include <unistd.h>
  10. #include <stdlib.h>
  11. #include "liburing.h"
  12. #include "helpers.h"
  13. static int test(struct io_uring *ring, int expect_drops)
  14. {
  15. struct io_uring_sqe *sqe;
  16. char buf[32];
  17. int ret, i;
  18. for (i = 0; i < 4; i++) {
  19. sqe = io_uring_get_sqe(ring);
  20. if (!sqe) {
  21. fprintf(stderr, "get sqe failed\n");
  22. goto err;
  23. }
  24. io_uring_prep_nop(sqe);
  25. }
  26. /* prep two invalid reads, these will fail */
  27. for (i = 0; i < 2; i++) {
  28. sqe = io_uring_get_sqe(ring);
  29. if (!sqe) {
  30. fprintf(stderr, "get sqe failed\n");
  31. goto err;
  32. }
  33. io_uring_prep_read(sqe, 128, buf, sizeof(buf), 0);
  34. sqe->ioprio = (short) -1;
  35. }
  36. ret = io_uring_submit(ring);
  37. if (expect_drops) {
  38. if (ret != 5) {
  39. fprintf(stderr, "drops submit failed: %d\n", ret);
  40. goto err;
  41. }
  42. } else {
  43. if (ret != 6) {
  44. fprintf(stderr, "no drops submit failed: %d\n", ret);
  45. goto err;
  46. }
  47. }
  48. return 0;
  49. err:
  50. return 1;
  51. }
  52. int main(int argc, char *argv[])
  53. {
  54. struct io_uring ring;
  55. int ret;
  56. if (argc > 1)
  57. return T_EXIT_SKIP;
  58. ret = io_uring_queue_init(8, &ring, IORING_SETUP_SUBMIT_ALL);
  59. if (ret)
  60. return 0;
  61. ret = test(&ring, 0);
  62. if (ret) {
  63. fprintf(stderr, "test no drops failed\n");
  64. return ret;
  65. }
  66. io_uring_queue_exit(&ring);
  67. ret = io_uring_queue_init(8, &ring, 0);
  68. if (ret) {
  69. fprintf(stderr, "ring setup failed\n");
  70. return T_EXIT_FAIL;
  71. }
  72. ret = test(&ring, 1);
  73. if (ret) {
  74. fprintf(stderr, "test drops failed\n");
  75. return ret;
  76. }
  77. return T_EXIT_PASS;
  78. }