1 /* 2 * Copyright (c) 2002, 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 mq_send() will fail if msg_len is not <= mq_attr->mq_msgsize. 11 */ 12 13 #include <stdio.h> 14 #include <mqueue.h> 15 #include <fcntl.h> 16 #include <sys/stat.h> 17 #include <sys/types.h> 18 #include <unistd.h> 19 #include <string.h> 20 #include "posixtest.h" 21 22 #define NAMESIZE 50 23 #define MSGSTR "01234567890123456789" 24 #define MSGSIZE 10 // < strlen(MSGSTR) 25 26 int main(void) 27 { 28 char qname[NAMESIZE]; 29 const char *msgptr = MSGSTR; 30 mqd_t queue; 31 int unresolved = 0, failure = 0; 32 struct mq_attr attr; 33 34 sprintf(qname, "/mq_send_2-1_%d", getpid()); 35 36 attr.mq_msgsize = MSGSIZE; 37 attr.mq_maxmsg = MSGSIZE; 38 39 queue = mq_open(qname, O_CREAT | O_RDWR, S_IRUSR | S_IWUSR, &attr); 40 if (queue == (mqd_t) - 1) { 41 perror("mq_open() did not return success"); 42 return PTS_UNRESOLVED; 43 } 44 45 if (mq_send(queue, msgptr, strlen(msgptr), 1) == 0) { 46 printf("mq_send() returned success when msg_len>=mq_msgsize\n"); 47 failure = 1; 48 } 49 50 if (mq_close(queue) != 0) { 51 perror("mq_close() did not return success"); 52 unresolved = 1; 53 } 54 55 if (mq_unlink(qname) != 0) { 56 perror("mq_unlink() did not return success"); 57 unresolved = 1; 58 } 59 60 if (failure == 1) { 61 printf("Test FAILED\n"); 62 return PTS_FAIL; 63 } 64 65 if (unresolved == 1) { 66 printf("Test UNRESOLVED\n"); 67 return PTS_UNRESOLVED; 68 } 69 70 printf("Test PASSED\n"); 71 return PTS_PASS; 72 } 73