2 * Copyright (c) 2009, Stathis Kamperis
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
14 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
15 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
16 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
17 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
18 * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
19 * INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING,
20 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
21 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
22 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
23 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
24 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28 #define _XOPEN_SOURCE 600
38 #define MQNAME "/t_asdssds"
43 * Create an empty message queue for mq_timedreceive() to block on it
48 md = mq_open(MQNAME, O_CREAT | O_EXCL | O_RDONLY, 0700, NULL);
49 assert(md != (mqd_t)-1);
51 /* Timeout in 3 seconds, if the queue doesn't fill in (it won't). */
52 struct timespec now, timeout;
54 assert(clock_gettime(CLOCK_REALTIME, &now) == 0);
55 timeout.tv_sec = now.tv_sec + 3;
56 timeout.tv_nsec = now.tv_nsec;
59 * Since we don't trust mq_timedreceive(), we are going to manually measure
60 * the time ellapsed until the function call times out.
62 struct timeval tv1, tv2;
64 assert(gettimeofday(&tv1, NULL) == 0);
66 /* This should timeout in ~3 seconds. */
67 char buf[8192]; /* Implementation defined */
69 assert(mq_timedreceive(md, buf, sizeof(buf), /* priority */ NULL,
70 &timeout) == -1 && errno == ETIMEDOUT);
73 assert(gettimeofday(&tv2, NULL) == 0);
75 /* Make sure the time ellapsed is roughly 3sec. */
78 msec = (tv2.tv_sec - tv1.tv_sec) * 1000 +
79 (tv2.tv_usec - tv1.tv_usec) / 1000;
80 assert(msec >= 2900 && msec <= 3100);
83 assert(mq_close(md) != -1);
84 assert(mq_unlink(MQNAME) != -1);
88 return (EXIT_SUCCESS);