Home | History | Annotate | Download | only in mq_setattr
      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_setattr() test plan:
     10  * If omqstat is non_NULL, the mq_setattr() function will store, in the
     11  * location referenced by omqstat, the previous message queue attributes and
     12  * the current queue status. These values will be the same as would be
     13  * returned by a call to mq_getattr() at that point.
     14  *
     15  *  2/17/2004   call mq_close and mq_unlink before exit to release mq
     16  *		resources
     17  */
     18 
     19 #include <stdio.h>
     20 #include <mqueue.h>
     21 #include <fcntl.h>
     22 #include <sys/stat.h>
     23 #include <sys/types.h>
     24 #include <unistd.h>
     25 #include <string.h>
     26 #include "posixtest.h"
     27 
     28 #define TEST "2-1"
     29 #define FUNCTION "mq_setattr"
     30 #define NAMESIZE	50
     31 #define MQFLAGS		0
     32 #define MQMAXMSG	666
     33 #define MQMSGSIZE	777
     34 #define MQCURMSGS	555
     35 
     36 int main(void)
     37 {
     38 	char mqname[NAMESIZE];
     39 	mqd_t mqdes;
     40 	struct mq_attr omqstat, mqstat, nmqstat;
     41 	int unresolved = 0;
     42 	int failure = 0;
     43 
     44 	sprintf(mqname, "/" FUNCTION "_" TEST "_%d", getpid());
     45 
     46 	mqdes = mq_open(mqname, O_CREAT | O_RDWR, S_IRUSR | S_IWUSR, 0);
     47 	if (mqdes == (mqd_t) - 1) {
     48 		perror("mq_open() did not return success");
     49 		return PTS_UNRESOLVED;
     50 	}
     51 	memset(&mqstat, 0, sizeof(mqstat));
     52 	memset(&omqstat, 0, sizeof(omqstat));
     53 	memset(&nmqstat, 0, sizeof(nmqstat));
     54 
     55 	if (mq_getattr(mqdes, &omqstat) == -1) {
     56 		perror("mq_getattr() did not return success");
     57 		unresolved = 1;
     58 	}
     59 	if (mq_unlink(mqname) != 0) {
     60 		perror("mq_unlink()");
     61 		return PTS_UNRESOLVED;
     62 	}
     63 	nmqstat.mq_flags = MQFLAGS;
     64 	nmqstat.mq_maxmsg = MQMAXMSG;
     65 	nmqstat.mq_msgsize = MQMSGSIZE;
     66 	nmqstat.mq_curmsgs = MQCURMSGS;
     67 
     68 	if (mq_setattr(mqdes, &nmqstat, &mqstat) != 0) {
     69 		failure = 1;
     70 	}
     71 	if ((omqstat.mq_flags != mqstat.mq_flags) ||
     72 	    (omqstat.mq_maxmsg != mqstat.mq_maxmsg) ||
     73 	    (omqstat.mq_msgsize != mqstat.mq_msgsize) ||
     74 	    (omqstat.mq_curmsgs != mqstat.mq_curmsgs)) {
     75 		failure = 1;
     76 	}
     77 
     78 	mq_close(mqdes);
     79 	mq_unlink(mqname);
     80 
     81 	if (failure == 1) {
     82 		printf("Test FAILED\n");
     83 		return PTS_FAIL;
     84 	}
     85 	if (unresolved == 1) {
     86 		printf("Test UNRESOLVED\n");
     87 		return PTS_UNRESOLVED;
     88 	}
     89 
     90 	printf("Test PASSED \n");
     91 	return PTS_PASS;
     92 }
     93