tst-mqueue10.c 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. /* Check for large timeout with mq_timedsend and mq_timedreceive.
  2. Copyright (C) 2021-2026 Free Software Foundation, Inc.
  3. This file is part of the GNU C Library.
  4. The GNU C Library is free software; you can redistribute it and/or
  5. modify it under the terms of the GNU Lesser General Public
  6. License as published by the Free Software Foundation; either
  7. version 2.1 of the License, or (at your option) any later version.
  8. The GNU C Library is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. Lesser General Public License for more details.
  12. You should have received a copy of the GNU Lesser General Public
  13. License along with the GNU C Library; if not, see
  14. <https://www.gnu.org/licenses/>. */
  15. #include <errno.h>
  16. #include <intprops.h>
  17. #include <mqueue.h>
  18. #include <stdio.h>
  19. #include <support/check.h>
  20. #include <support/support.h>
  21. #include <support/temp_file.h>
  22. #include <unistd.h>
  23. static char name[sizeof "/tst-mqueue10-" + INT_BUFSIZE_BOUND (pid_t)];
  24. static void
  25. do_cleanup (void)
  26. {
  27. mq_unlink (name);
  28. }
  29. #define CLEANUP_HANDLER do_cleanup
  30. static int
  31. do_test (void)
  32. {
  33. snprintf (name, sizeof (name), "/tst-mqueue10-%u", getpid ());
  34. char msg[8] = { 0x55 };
  35. struct mq_attr attr = { .mq_maxmsg = 1, .mq_msgsize = sizeof (msg) };
  36. mqd_t q = mq_open (name, O_CREAT | O_EXCL | O_RDWR, 0600, &attr);
  37. if (q == (mqd_t) -1)
  38. {
  39. if (errno == ENOSYS)
  40. FAIL_UNSUPPORTED ("mq_open not supported");
  41. printf ("mq_open failed with: %m\n");
  42. return 1;
  43. }
  44. struct timespec ts = { TYPE_MAXIMUM (time_t), 0 };
  45. {
  46. timer_t timer = support_create_timer (0, 100000000, false, NULL);
  47. TEST_COMPARE (mq_timedreceive (q, msg, sizeof (msg), NULL, &ts), -1);
  48. TEST_VERIFY (errno == EINTR || errno == EOVERFLOW);
  49. support_delete_timer (timer);
  50. }
  51. {
  52. timer_t timer = support_create_timer (0, 100000000, false, NULL);
  53. /* Fill the internal buffer first. */
  54. TEST_COMPARE (mq_timedsend (q, msg, sizeof (msg), 0,
  55. &(struct timespec) { 0, 0 }), 0);
  56. TEST_COMPARE (mq_timedsend (q, msg, sizeof (msg), 0, &ts), -1);
  57. TEST_VERIFY (errno == EINTR || errno == EOVERFLOW);
  58. support_delete_timer (timer);
  59. }
  60. mq_unlink (name);
  61. return 0;
  62. }
  63. #include <support/test-driver.c>