Home | History | Annotate | Download | only in mq_notify
      1 /*
      2  * Copyright (c) 2014 Fujitsu Ltd.
      3  * Author: Zeng Linggang <zenglg.jy (at) cn.fujitsu.com>
      4  *
      5  * This program is free software; you can redistribute it and/or modify it
      6  * under the terms of version 2 of the GNU General Public License as
      7  * published by the Free Software Foundation.
      8  *
      9  * This program is distributed in the hope that it would be useful, but
     10  * WITHOUT ANY WARRANTY; without even the implied warranty of
     11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
     12  *
     13  * You should have received a copy of the GNU General Public License along
     14  * with this program.
     15  */
     16 /*
     17  * ALGORITHM
     18  *	test 1:
     19  *		sevp->sigev_notify = -1, EINVAL should be returned.
     20  *	test 2:
     21  *		sevp->sigev_notify = SIGEV_SIGNAL and sevp->sigev_signo > _NSG,
     22  *		EINVAL should be returned.
     23  */
     24 
     25 #include <errno.h>
     26 #include <mqueue.h>
     27 #include "test.h"
     28 
     29 char *TCID = "mq_notify02";
     30 static void setup(void);
     31 static void cleanup(void);
     32 
     33 static struct test_case_t {
     34 	struct sigevent sevp;
     35 	int exp_errno;
     36 } test_cases[] = {
     37 	{{.sigev_notify = -1}, EINVAL},
     38 	{{.sigev_notify = SIGEV_SIGNAL, .sigev_signo = _NSIG+1}, EINVAL},
     39 };
     40 
     41 int TST_TOTAL = ARRAY_SIZE(test_cases);
     42 static void mq_notify_verify(struct test_case_t *);
     43 
     44 int main(int argc, char **argv)
     45 {
     46 	int lc;
     47 	int i;
     48 
     49 	tst_parse_opts(argc, argv, NULL, NULL);
     50 
     51 	setup();
     52 
     53 	for (lc = 0; TEST_LOOPING(lc); lc++) {
     54 		tst_count = 0;
     55 		for (i = 0; i < TST_TOTAL; i++)
     56 			mq_notify_verify(&test_cases[i]);
     57 	}
     58 	cleanup();
     59 	tst_exit();
     60 }
     61 
     62 static void setup(void)
     63 {
     64 	tst_sig(NOFORK, DEF_HANDLER, cleanup);
     65 
     66 	TEST_PAUSE;
     67 }
     68 
     69 static void mq_notify_verify(struct test_case_t *test)
     70 {
     71 	TEST(mq_notify(0, &(test->sevp)));
     72 
     73 	if (TEST_RETURN != -1) {
     74 		tst_resm(TFAIL, "mq_notify() succeeded unexpectedly");
     75 		return;
     76 	}
     77 
     78 	if (TEST_ERRNO == test->exp_errno) {
     79 		tst_resm(TPASS | TTERRNO, "mq_notify failed as expected");
     80 	} else {
     81 		tst_resm(TFAIL | TTERRNO,
     82 			 "mq_notify failed unexpectedly; expected: %d - %s",
     83 			 test->exp_errno, strerror(test->exp_errno));
     84 	}
     85 }
     86 
     87 static void cleanup(void)
     88 {
     89 }
     90