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 message queue is empty and O_NONBLOCK is set in the message queue,
12 * no message will be removed from the queue, mq_receive will return an
13 * error.
14 */
15
16#include <stdio.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 "posixtest.h"
25
26#define TEST "7-1"
27#define FUNCTION "mq_receive"
28#define ERROR_PREFIX "unexpected error: " FUNCTION " " TEST ": "
29
30#define NAMESIZE 50
31#define BUFFER 40
32
33int main()
34{
35        char mqname[NAMESIZE], msgrv[BUFFER];
36        mqd_t mqdes;
37	struct mq_attr attr;
38	int unresolved = 0, failure = 0;
39
40	sprintf(mqname, "/" FUNCTION "_" TEST "_%d", getpid());
41	attr.mq_msgsize = BUFFER;
42	attr.mq_maxmsg = BUFFER;
43	mqdes = mq_open(mqname, O_CREAT | O_NONBLOCK | O_RDWR, S_IRUSR | S_IWUSR, &attr);
44        if (mqdes == (mqd_t)-1) {
45                perror(ERROR_PREFIX "mq_open");
46		unresolved = 1;
47        }
48
49       	if (mq_receive(mqdes, msgrv, BUFFER, NULL) != -1) {
50		printf("mq_receive succeed unexpectly \n");
51		failure = 1;
52	}
53        if (mq_close(mqdes) != 0) {
54		perror(ERROR_PREFIX "mq_close");
55		unresolved = 1;
56        }
57
58        if (mq_unlink(mqname) != 0) {
59		perror(ERROR_PREFIX "mq_unlink");
60		unresolved = 1;
61        }
62
63	if (failure==1) {
64                printf("Test FAILED\n");
65                return PTS_FAIL;
66        }
67
68        if (unresolved==1) {
69                printf("Test UNRESOLVED\n");
70                return PTS_UNRESOLVED;
71        }
72	printf("Test PASSED\n");
73	return PTS_PASS;
74}
75
76