blob: 874e7461a0a9fe2a7fe1bd698131aa2b01cffa8c [file] [log] [blame]
Zeng Linggang0feb2d72014-02-21 16:33:39 +08001/*
2 * Copyright (c) 2014 Fujitsu Ltd.
3 * Author: Zeng Linggang <zenglg.jy@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"
Zeng Linggang0feb2d72014-02-21 16:33:39 +080028
29char *TCID = "mq_notify02";
30static void setup(void);
31static void cleanup(void);
32
33static 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
41int TST_TOTAL = ARRAY_SIZE(test_cases);
42static void mq_notify_verify(struct test_case_t *);
Zeng Linggang0feb2d72014-02-21 16:33:39 +080043
44int main(int argc, char **argv)
45{
46 int lc;
47 int i;
Cyril Hrubis0b9589f2014-05-27 17:40:33 +020048 const char *msg;
Zeng Linggang0feb2d72014-02-21 16:33:39 +080049
50 msg = parse_opts(argc, argv, NULL, NULL);
51 if (msg != NULL)
52 tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
53
54 setup();
55
Zeng Linggang0feb2d72014-02-21 16:33:39 +080056 for (lc = 0; TEST_LOOPING(lc); lc++) {
57 tst_count = 0;
58 for (i = 0; i < TST_TOTAL; i++)
59 mq_notify_verify(&test_cases[i]);
60 }
61 cleanup();
62 tst_exit();
63}
64
65static void setup(void)
66{
67 tst_sig(NOFORK, DEF_HANDLER, cleanup);
68
69 TEST_PAUSE;
70}
71
72static void mq_notify_verify(struct test_case_t *test)
73{
74 TEST(mq_notify(0, &(test->sevp)));
75
76 if (TEST_RETURN != -1) {
77 tst_resm(TFAIL, "mq_notify() succeeded unexpectedly");
78 return;
79 }
80
81 if (TEST_ERRNO == test->exp_errno) {
82 tst_resm(TPASS | TTERRNO, "mq_notify failed as expected");
83 } else {
84 tst_resm(TFAIL | TTERRNO,
85 "mq_notify failed unexpectedly; expected: %d - %s",
86 test->exp_errno, strerror(test->exp_errno));
87 }
88}
89
90static void cleanup(void)
91{
Zeng Linggang0feb2d72014-02-21 16:33:39 +080092}