Home | History | Annotate | Download | only in mq_timedsend
      1 /*
      2  * Copyright (c) 2003, 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 errno == EINVAL if msg_prio is >= MQ_PRIO_MAX or < 0 (<0 N/A
     11  * for an unsigned, so not tested).
     12  */
     13 
     14 #include <stdio.h>
     15 #include <limits.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 <errno.h>
     23 #include <time.h>
     24 #include "posixtest.h"
     25 
     26 #define NAMESIZE 50
     27 #define MSGSTR "0123456789"
     28 #define NUMINVALID 3
     29 
     30 static unsigned invalidpri[NUMINVALID] = {
     31 	MQ_PRIO_MAX, MQ_PRIO_MAX + 1, MQ_PRIO_MAX + 5
     32 };
     33 
     34 int main(void)
     35 {
     36 	char qname[NAMESIZE];
     37 	const char *msgptr = MSGSTR;
     38 	struct timespec ts;
     39 	mqd_t queue;
     40 	int unresolved = 0, failure = 0, i;
     41 
     42 	sprintf(qname, "/mq_timedsend_13-1_%d", getpid());
     43 
     44 	queue = mq_open(qname, O_CREAT | O_RDWR, S_IRUSR | S_IWUSR, NULL);
     45 	if (queue == (mqd_t) - 1) {
     46 		perror("mq_open() did not return success");
     47 		return PTS_UNRESOLVED;
     48 	}
     49 
     50 	ts.tv_sec = time(NULL) + 1;
     51 	ts.tv_nsec = 0;
     52 	for (i = 0; i < NUMINVALID; i++) {
     53 		if (mq_timedsend(queue, msgptr,
     54 				 strlen(msgptr), invalidpri[i], &ts) == 0) {
     55 			printf("mq_timedsend() ret success on invalid %d\n",
     56 			       invalidpri[i]);
     57 			failure = 1;
     58 		}
     59 		if (errno != EINVAL) {
     60 			printf("errno not == EINVAL for invalid %d\n",
     61 			       invalidpri[i]);
     62 			failure = 1;
     63 		}
     64 	}
     65 
     66 	if (mq_close(queue) != 0) {
     67 		perror("mq_close() did not return success");
     68 		unresolved = 1;
     69 	}
     70 
     71 	if (mq_unlink(qname) != 0) {
     72 		perror("mq_unlink() did not return success");
     73 		unresolved = 1;
     74 	}
     75 
     76 	if (failure == 1) {
     77 		printf("Test FAILED\n");
     78 		return PTS_FAIL;
     79 	}
     80 
     81 	if (unresolved == 1) {
     82 		printf("Test UNRESOLVED\n");
     83 		return PTS_UNRESOLVED;
     84 	}
     85 
     86 	printf("Test PASSED\n");
     87 	return PTS_PASS;
     88 }
     89