1 /* 2 * Copyright (c) 2003, Intel Corporation. All rights reserved. 3 * Created by: julie.n.fleischer REMOVE-THIS AT intel DOT com 4 * This file is licensed under the GPL license. For the full content 5 * of this license, see the COPYING file at the top level of this 6 * source tree. 7 */ 8 9 /* 10 * Test that msg_prio can be equal to MQ_PRIO_MAX-1. 11 * 12 * 3/13/03 - Added fix from Gregoire Pichon for specifying an attr 13 * with a mq_maxmsg >= BUFFER. 14 * 15 */ 16 17 #include <stdio.h> 18 #include <limits.h> 19 #include <mqueue.h> 20 #include <fcntl.h> 21 #include <sys/stat.h> 22 #include <sys/types.h> 23 #include <unistd.h> 24 #include <string.h> 25 #include <time.h> 26 #include "posixtest.h" 27 28 #define NAMESIZE 50 29 #define MSGSTR "0123456789" 30 #define BUFFER 40 31 #define MAXMSG 5 32 33 int main(void) 34 { 35 char qname[NAMESIZE], msgrcd[BUFFER]; 36 const char *msgptr = MSGSTR; 37 struct timespec ts; 38 mqd_t queue; 39 struct mq_attr attr; 40 int unresolved = 0, failure = 0; 41 unsigned pri; 42 43 sprintf(qname, "/mq_timedsend_4-3_%d", getpid()); 44 45 attr.mq_msgsize = BUFFER; 46 attr.mq_maxmsg = MAXMSG; 47 queue = mq_open(qname, O_CREAT | O_RDWR, S_IRUSR | S_IWUSR, &attr); 48 if (queue == (mqd_t) - 1) { 49 perror("mq_open() did not return success"); 50 return PTS_UNRESOLVED; 51 } 52 53 ts.tv_sec = time(NULL) + 1; 54 ts.tv_nsec = 0; 55 if (mq_timedsend(queue, msgptr, strlen(msgptr), MQ_PRIO_MAX - 1, &ts) 56 != 0) { 57 perror("mq_timedsend() did not return success"); 58 failure = 1; 59 } 60 61 if (mq_receive(queue, msgrcd, BUFFER, &pri) == -1) { 62 perror("mq_receive() returned failure"); 63 failure = 1; 64 } 65 66 if (strncmp(msgptr, msgrcd, strlen(msgptr)) != 0) { 67 printf("FAIL: sent %s received %s\n", msgptr, msgrcd); 68 failure = 1; 69 } 70 71 if (mq_close(queue) != 0) { 72 perror("mq_close() did not return success"); 73 unresolved = 1; 74 } 75 76 if (mq_unlink(qname) != 0) { 77 perror("mq_unlink() did not return success"); 78 unresolved = 1; 79 } 80 81 if (failure == 1) { 82 printf("Test FAILED\n"); 83 return PTS_FAIL; 84 } 85 86 if (unresolved == 1) { 87 printf("Test UNRESOLVED\n"); 88 return PTS_UNRESOLVED; 89 } 90 91 printf("Test PASSED\n"); 92 return PTS_PASS; 93 } 94