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_receive test plan: 11 * If the buffer size is less than the mq_msgsize attribute, the function 12 * will fail and return an error. 13 */ 14 15#include <stdio.h> 16#include <mqueue.h> 17#include <fcntl.h> 18#include <sys/stat.h> 19#include <sys/types.h> 20#include <unistd.h> 21#include <string.h> 22#include "posixtest.h" 23 24#define TEST "2-1" 25#define FUNCTION "mq_receive" 26#define ERROR_PREFIX "unexpected error: " FUNCTION " " TEST ": " 27 28#define NAMESIZE 50 29#define BUFFER 20 30 31int main() 32{ 33 char mqname[NAMESIZE], msgrv[BUFFER]; 34 const char *msgptr = "test message"; 35 mqd_t mqdes; 36 int prio = 1; 37 struct mq_attr mqstat; 38 int unresolved = 0, failure = 0; 39 40 sprintf(mqname, "/" FUNCTION "_" TEST "_%d", getpid()); 41 memset(&mqstat,0,sizeof(mqstat)); 42 mqstat.mq_msgsize = BUFFER + 1; 43 mqstat.mq_maxmsg = BUFFER + 1; 44 45 mqdes = mq_open(mqname, O_CREAT | O_RDWR, S_IRUSR | S_IWUSR, &mqstat); 46 if (mqdes == (mqd_t)-1) { 47 perror(ERROR_PREFIX "mq_open"); 48 unresolved = 1; 49 } 50 51 if (mq_send(mqdes, msgptr, strlen(msgptr), prio) != 0) { 52 perror(ERROR_PREFIX "mq_send"); 53 unresolved = 1; 54 } 55 56 if (mq_receive(mqdes, msgrv, BUFFER, NULL) > 0) { 57 printf("FAIL: mq_receive succeed unexpectly \n"); 58 failure = 1; 59 } 60 if (mq_close(mqdes) != 0) { 61 perror(ERROR_PREFIX "mq_close"); 62 unresolved = 1; 63 } 64 if (mq_unlink(mqname) != 0) { 65 perror(ERROR_PREFIX "mq_unlink"); 66 unresolved = 1; 67 } 68 if (failure==1) { 69 printf("Test FAILED\n"); 70 return PTS_FAIL; 71 } 72 if (unresolved==1) { 73 printf("Test UNRESOLVED\n"); 74 return PTS_UNRESOLVED; 75 } 76 printf("Test PASSED\n"); 77 return PTS_PASS; 78} 79 80