1 /* 2 * Copyright (c) 2003, Intel Corporation. All rights reserved. 3 * Created by: crystal.xiong 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 * mq_getattr() test plan: 10 * mq_getattr gets mq_flags value, which is set by mq_setattr. 11 * 12 * 2/17/2004 call mq_close and mq_unlink before exit to release mq 13 * resources 14 * 15 */ 16 17 #include <stdio.h> 18 #include <mqueue.h> 19 #include <fcntl.h> 20 #include <sys/stat.h> 21 #include <sys/types.h> 22 #include <unistd.h> 23 #include <string.h> 24 #include "posixtest.h" 25 26 #define TEST "2-2" 27 #define FUNCTION "mq_getattr" 28 #define ERROR_PREFIX "unexpected error: " FUNCTION " " TEST ": " 29 30 #define NAMESIZE 50 31 #define MQFLAGS O_NONBLOCK 32 33 int main(void) 34 { 35 char mqname[NAMESIZE]; 36 mqd_t mqdes; 37 struct mq_attr mqstat, nmqstat; 38 int unresolved = 0; 39 int failure = 0; 40 41 sprintf(mqname, "/" FUNCTION "_" TEST "_%d", getpid()); 42 43 mqdes = mq_open(mqname, O_CREAT | O_RDWR, S_IRUSR | S_IWUSR, NULL); 44 if (mqdes == (mqd_t) - 1) { 45 perror(ERROR_PREFIX "mq_open()"); 46 return PTS_UNRESOLVED; 47 } 48 memset(&mqstat, 0, sizeof(mqstat)); 49 memset(&nmqstat, 0, sizeof(nmqstat)); 50 if (mq_getattr(mqdes, &mqstat) == -1) { 51 perror(ERROR_PREFIX "mq_getattr"); 52 unresolved = 1; 53 } 54 mqstat.mq_flags |= MQFLAGS; 55 if (mq_setattr(mqdes, &mqstat, NULL) == -1) { 56 perror(ERROR_PREFIX "mq_setattr"); 57 failure = 1; 58 } 59 if (mq_getattr(mqdes, &nmqstat) != 0) { 60 perror(ERROR_PREFIX "mq_getattr"); 61 unresolved = 1; 62 } 63 if (nmqstat.mq_flags != mqstat.mq_flags) { 64 printf("FAIL: mq_getattr didn't get the correct mq_flags " 65 "set by mq_setattr \n"); 66 failure = 1; 67 } 68 69 mq_close(mqdes); 70 mq_unlink(mqname); 71 72 if (failure == 1) { 73 printf("Test FAILED\n"); 74 return PTS_FAIL; 75 } 76 if (unresolved == 1) { 77 printf("Test UNRESOLVED\n"); 78 return PTS_UNRESOLVED; 79 } 80 81 printf("Test PASSED \n"); 82 return PTS_PASS; 83 } 84