1
2/*
3 *
4 *   Copyright (c) International Business Machines  Corp., 2002
5 *
6 *   This program is free software;  you can redistribute it and/or modify
7 *   it under the terms of the GNU General Public License as published by
8 *   the Free Software Foundation; either version 2 of the License, or
9 *   (at your option) any later version.
10 *
11 *   This program is distributed in the hope that it will be useful,
12 *   but WITHOUT ANY WARRANTY;  without even the implied warranty of
13 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
14 *   the GNU General Public License for more details.
15 *
16 *   You should have received a copy of the GNU General Public License
17 *   along with this program;  if not, write to the Free Software
18 *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20
21/*
22 * NAME
23 * 	sigpending02.c
24 *
25 * DESCRIPTION
26 * 	Test to see the the proper errors are returned by sigpending
27 *$
28 * ALGORITHM
29 * 	test 1:
30 * 	Call sigpending(sigset_t*=-1), it should return -1 with errno EFAULT
31 *
32 * USAGE:  <for command-line>
33 *         -c n    Run n copies concurrently
34 *         -e      Turn on errno logging
35 *         -f      Turn off functional testing
36 *         -h      Show this help screen
37 *         -i n    Execute test n times
38 *         -I x    Execute test for x seconds
39 *         -p      Pause for SIGUSR1 before starting
40 *         -P x    Pause for x seconds between iterations
41 *         -t      Turn on syscall timing
42 *
43 * HISTORY
44 *	02/2002 Written by Paul Larson
45 *
46 * RESTRICTIONS
47 * 	None
48 */
49#include <sys/types.h>
50#include <fcntl.h>
51#include <sys/stat.h>
52#include <errno.h>
53#include <string.h>
54#include <signal.h>
55#include "test.h"
56
57void setup();
58void help();
59void cleanup();
60
61char *TCID = "sigpending02";
62int TST_TOTAL = 1;
63
64/***********************************************************************
65 * Main
66 ***********************************************************************/
67int main(int ac, char **av)
68{
69	int lc;
70	sigset_t *sigset;
71
72	tst_parse_opts(ac, av, NULL, NULL);
73
74    /***************************************************************
75     * perform global setup for test
76     ***************************************************************/
77	setup();
78
79	/* set sigset to point to an invalid location */
80	sigset = (sigset_t *) - 1;
81
82    /***************************************************************
83     * check looping state
84     ***************************************************************/
85	/* TEST_LOOPING() is a macro that will make sure the test continues
86	 * looping according to the standard command line args.
87	 */
88	for (lc = 0; TEST_LOOPING(lc); lc++) {
89
90		tst_count = 0;
91
92		TEST(sigpending(sigset));
93
94		/* check return code */
95		if (TEST_RETURN == -1) {
96			if (TEST_ERRNO != EFAULT)
97				tst_brkm(TFAIL, cleanup,
98					 "sigpending() Failed with wrong "
99					 "errno, expected errno=%d, got errno=%d : %s",
100					 EFAULT, TEST_ERRNO,
101					 strerror(TEST_ERRNO));
102			else
103				tst_resm(TPASS,
104					 "expected failure - errno = %d : %s",
105					 TEST_ERRNO, strerror(TEST_ERRNO));
106		} else {
107			tst_brkm(TFAIL, cleanup,
108				 "sigpending() Failed, expected "
109				 "return value=-1, got %ld", TEST_RETURN);
110		}
111	}
112
113    /***************************************************************
114     * cleanup and exit
115     ***************************************************************/
116	cleanup();
117	tst_exit();
118
119}
120
121/***************************************************************
122 * help
123 ***************************************************************/
124void help(void)
125{
126	printf("test\n");
127}
128
129/***************************************************************
130 * setup() - performs all ONE TIME setup for this test.
131 ***************************************************************/
132void setup(void)
133{
134	TEST_PAUSE;
135}
136
137/***************************************************************
138 * cleanup() - performs all ONE TIME cleanup for this test at
139 *		completion or premature exit.
140 ***************************************************************/
141void cleanup(void)
142{
143}
144