1/******************************************************************************/
2/* Copyright (c) Crackerjack Project., 2007                                   */
3/*                                                                            */
4/* This program is free software;  you can redistribute it and/or modify      */
5/* it under the terms of the GNU General Public License as published by       */
6/* the Free Software Foundation; either version 2 of the License, or          */
7/* (at your option) any later version.                                        */
8/*                                                                            */
9/* This program is distributed in the hope that it will be useful,            */
10/* but WITHOUT ANY WARRANTY;  without even the implied warranty of            */
11/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See                  */
12/* the GNU General Public License for more details.                           */
13/*                                                                            */
14/* You should have received a copy of the GNU General Public License          */
15/* along with this program;  if not, write to the Free Software Foundation,   */
16/* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA           */
17/*                                                                            */
18/* History:     Porting from Crackerjack to LTP is done by                    */
19/*              Manas Kumar Nayak maknayak@in.ibm.com>                        */
20/******************************************************************************/
21
22/******************************************************************************/
23/* Description: This tests the rt_sigaction() syscall                         */
24/*		rt_sigaction Expected EFAULT error check                      */
25/******************************************************************************/
26
27#define _GNU_SOURCE
28#include <stdio.h>
29#include <stdlib.h>
30#include <unistd.h>
31#include <signal.h>
32#include <errno.h>
33#include <sys/syscall.h>
34#include <string.h>
35
36#include "test.h"
37#include "lapi/syscalls.h"
38#include "lapi/rt_sigaction.h"
39
40char *TCID = "rt_sigaction02";
41static int testno;
42int TST_TOTAL = 1;
43
44void cleanup(void)
45{
46	tst_rmdir();
47
48	tst_exit();
49}
50
51void setup(void)
52{
53	TEST_PAUSE;
54	tst_tmpdir();
55}
56
57static int test_flags[] =
58    { SA_RESETHAND | SA_SIGINFO, SA_RESETHAND, SA_RESETHAND | SA_SIGINFO,
59SA_RESETHAND | SA_SIGINFO, SA_NOMASK };
60char *test_flags_list[] =
61    { "SA_RESETHAND|SA_SIGINFO", "SA_RESETHAND", "SA_RESETHAND|SA_SIGINFO",
62"SA_RESETHAND|SA_SIGINFO", "SA_NOMASK" };
63
64static struct test_case_t {
65	int exp_errno;
66	char *errdesc;
67} test_cases[] = {
68	{
69	EFAULT, "EFAULT"}
70};
71
72int main(int ac, char **av)
73{
74	unsigned int flag;
75	int signal;
76	int lc;
77
78	tst_parse_opts(ac, av, NULL, NULL);
79
80	setup();
81
82	for (lc = 0; TEST_LOOPING(lc); ++lc) {
83		tst_count = 0;
84		for (testno = 0; testno < TST_TOTAL; ++testno) {
85			for (signal = SIGRTMIN; signal <= SIGRTMAX; signal++) {
86				tst_resm(TINFO, "Signal %d", signal);
87
88				for (flag = 0; flag < ARRAY_SIZE(test_flags); flag++) {
89
90					/*                                                              *
91					 * long sys_rt_sigaction (int sig, const struct sigaction *act, *
92					 * truct sigaction *oact, size_t sigsetsize);                   *
93					 * EFAULT:                                                      *
94					 * An invalid act or oact value was specified                   *
95					 */
96
97					TEST(ltp_rt_sigaction(signal,
98						INVAL_SA_PTR, NULL, SIGSETSIZE));
99					if ((TEST_RETURN == -1)
100					    && (TEST_ERRNO ==
101						test_cases[0].exp_errno)) {
102						tst_resm(TINFO,
103							 "sa.sa_flags = %s ",
104							 test_flags_list[flag]);
105						tst_resm(TPASS,
106							 "%s failure with sig: %d as expected errno  = %s : %s",
107							 TCID, signal,
108							 test_cases[0].errdesc,
109							 strerror(TEST_ERRNO));
110					} else {
111						tst_resm(TFAIL,
112							 "rt_sigaction call succeeded: result = %ld got error %d:but expected  %d",
113							 TEST_RETURN,
114							 TEST_ERRNO,
115							 test_cases[0].
116							 exp_errno);
117						tst_resm(TINFO,
118							 "sa.sa_flags = %s ",
119							 test_flags_list[flag]);
120					}
121				}
122			}
123
124		}
125	}
126	cleanup();
127	tst_exit();
128}
129