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 /* 10 * mq_timedreceive() test plan: 11 * mq_timedreceive() will fail with EBADF, if mqdes is not a valid message 12 * message queue descriptor. 13 */ 14 15 #include <stdio.h> 16 #include <errno.h> 17 #include <mqueue.h> 18 #include <fcntl.h> 19 #include <sys/stat.h> 20 #include <sys/types.h> 21 #include <unistd.h> 22 #include <string.h> 23 #include <stdlib.h> 24 #include <time.h> 25 #include "posixtest.h" 26 27 #define TEST "14-1" 28 #define FUNCTION "mq_timedreceive" 29 #define ERROR_PREFIX "unexpected error: " FUNCTION " " TEST ": " 30 31 #define NAMESIZE 50 32 #define BUFFER 40 33 34 int main(void) 35 { 36 char mqname[NAMESIZE]; 37 mqd_t mqdes; 38 char msgrv[BUFFER]; 39 struct timespec ts; 40 struct mq_attr attr; 41 int unresolved = 0, failure = 0; 42 43 sprintf(mqname, "/" FUNCTION "_" TEST "_%d", getpid()); 44 45 attr.mq_msgsize = BUFFER; 46 attr.mq_maxmsg = BUFFER; 47 mqdes = mq_open(mqname, O_CREAT | O_RDWR, S_IRUSR | S_IWUSR, &attr); 48 if (mqdes == (mqd_t) - 1) { 49 perror(ERROR_PREFIX "mq_open()"); 50 unresolved = 1; 51 } 52 mqdes = mqdes + 1; 53 ts.tv_sec = time(NULL) + 1; 54 ts.tv_nsec = 0; 55 if (mq_timedreceive(mqdes, msgrv, BUFFER, NULL, &ts) == -1) { 56 if (EBADF != errno) { 57 printf("errno != EBADF\n"); 58 failure = 1; 59 } 60 } else { 61 printf("mq_timedreceive() succeed unexpectly\n"); 62 failure = 1; 63 } 64 if (mq_close(mqdes - 1) != 0) { 65 perror(ERROR_PREFIX "mq_close()"); 66 unresolved = 1; 67 } 68 if (mq_unlink(mqname) != 0) { 69 perror(ERROR_PREFIX "mq_unlink()"); 70 unresolved = 1; 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 printf("Test PASSED\n"); 81 return PTS_PASS; 82 } 83