blob: 41168203466108071438fe5594e1fe4792a24073 [file] [log] [blame]
Stanislav Kholmanskikh4d93b882014-06-17 13:08:16 +04001/******************************************************************************/
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_sigsuspend() syscall. */
24/******************************************************************************/
subrata_modak77336262009-05-21 18:28:46 +000025
26#include <stdio.h>
27#include <signal.h>
28#include <errno.h>
29
subrata_modak77336262009-05-21 18:28:46 +000030#include "test.h"
subrata_modak77336262009-05-21 18:28:46 +000031#include "linux_syscall_numbers.h"
Stanislav Kholmanskikhea537012014-06-17 13:08:17 +040032#include "lapi/rt_sigaction.h"
subrata_modak77336262009-05-21 18:28:46 +000033
Cyril Hrubisfdce7d52013-04-04 18:35:48 +020034char *TCID = "rt_sigsuspend01";
Cyril Hrubisfdce7d52013-04-04 18:35:48 +020035int TST_TOTAL = 1;
subrata_modak77336262009-05-21 18:28:46 +000036
Stanislav Kholmanskikh4d93b882014-06-17 13:08:16 +040037static void cleanup(void)
Wanlong Gao354ebb42012-12-07 10:10:04 +080038{
Garrett Cooper135924f2010-02-26 19:52:32 -080039 tst_rmdir();
subrata_modak77336262009-05-21 18:28:46 +000040}
41
Stanislav Kholmanskikh4d93b882014-06-17 13:08:16 +040042static void setup(void)
Wanlong Gao354ebb42012-12-07 10:10:04 +080043{
Garrett Cooper135924f2010-02-26 19:52:32 -080044 TEST_PAUSE;
45 tst_tmpdir();
subrata_modak77336262009-05-21 18:28:46 +000046}
47
Stanislav Kholmanskikh4d93b882014-06-17 13:08:16 +040048static void sig_handler(int sig)
subrata_modak77336262009-05-21 18:28:46 +000049{
50}
51
Wanlong Gao354ebb42012-12-07 10:10:04 +080052int main(int ac, char **av)
53{
subrata_modak77336262009-05-21 18:28:46 +000054 sigset_t set, set1, set2;
Cyril Hrubis89af32a2012-10-24 16:39:11 +020055 int lc;
Cyril Hrubis0b9589f2014-05-27 17:40:33 +020056 const char *msg;
Garrett Cooper2c282152010-12-16 00:55:50 -080057
Stanislav Kholmanskikh4d93b882014-06-17 13:08:16 +040058 msg = parse_opts(ac, av, NULL, NULL);
59 if (msg != NULL)
Wanlong Gao354ebb42012-12-07 10:10:04 +080060 tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
subrata_modak77336262009-05-21 18:28:46 +000061
Garrett Cooper135924f2010-02-26 19:52:32 -080062 setup();
subrata_modak77336262009-05-21 18:28:46 +000063
Garrett Cooper135924f2010-02-26 19:52:32 -080064 for (lc = 0; TEST_LOOPING(lc); ++lc) {
65
Caspar Zhangd59a6592013-03-07 14:59:12 +080066 tst_count = 0;
Garrett Cooper135924f2010-02-26 19:52:32 -080067
Stanislav Kholmanskikh4d93b882014-06-17 13:08:16 +040068 if (sigemptyset(&set) < 0)
Wanlong Gao354ebb42012-12-07 10:10:04 +080069 tst_brkm(TFAIL | TERRNO, cleanup, "sigemptyset failed");
Garrett Cooper135924f2010-02-26 19:52:32 -080070 struct sigaction act, oact;
Wanlong Gao354ebb42012-12-07 10:10:04 +080071 memset(&act, 0, sizeof(act));
72 memset(&oact, 0, sizeof(oact));
Garrett Cooper135924f2010-02-26 19:52:32 -080073 act.sa_handler = sig_handler;
Garrett Cooper135924f2010-02-26 19:52:32 -080074
Stanislav Kholmanskikhea537012014-06-17 13:08:17 +040075 TEST(ltp_rt_sigaction(SIGALRM, &act, &oact, SIGSETSIZE));
Stanislav Kholmanskikh4d93b882014-06-17 13:08:16 +040076 if (TEST_RETURN == -1)
Wanlong Gao354ebb42012-12-07 10:10:04 +080077 tst_brkm(TFAIL | TTERRNO, cleanup,
78 "rt_sigaction failed");
Stanislav Kholmanskikh4d93b882014-06-17 13:08:16 +040079
Jan Stancek359980f2013-02-15 10:16:05 +010080 TEST(ltp_syscall(__NR_rt_sigprocmask, SIG_UNBLOCK, 0,
Wanlong Gao354ebb42012-12-07 10:10:04 +080081 &set1, SIGSETSIZE));
Stanislav Kholmanskikh4d93b882014-06-17 13:08:16 +040082 if (TEST_RETURN == -1)
Wanlong Gao354ebb42012-12-07 10:10:04 +080083 tst_brkm(TFAIL | TTERRNO, cleanup,
84 "rt_sigprocmask failed");
Garrett Cooper2c282152010-12-16 00:55:50 -080085
Garrett Cooper135924f2010-02-26 19:52:32 -080086 TEST(alarm(5));
87 int result;
Jan Stancek359980f2013-02-15 10:16:05 +010088 TEST(result = ltp_syscall(__NR_rt_sigsuspend, &set,
89 SIGSETSIZE));
Garrett Cooper135924f2010-02-26 19:52:32 -080090 TEST(alarm(0));
91 if (result == -1 && TEST_ERRNO != EINTR) {
Jan Stancek359980f2013-02-15 10:16:05 +010092 TEST(ltp_syscall(__NR_rt_sigprocmask, SIG_UNBLOCK, 0,
93 &set2, SIGSETSIZE));
Garrett Cooper135924f2010-02-26 19:52:32 -080094 if (TEST_RETURN == -1) {
Wanlong Gao354ebb42012-12-07 10:10:04 +080095 tst_brkm(TFAIL | TTERRNO, cleanup,
96 "rt_sigprocmask failed");
Garrett Cooper135924f2010-02-26 19:52:32 -080097 } else if (set1.__val[0] != set2.__val[0]) {
Wanlong Gao354ebb42012-12-07 10:10:04 +080098 tst_brkm(TFAIL | TTERRNO, cleanup,
99 "rt_sigsuspend failed to "
100 "preserve signal mask");
Garrett Cooper135924f2010-02-26 19:52:32 -0800101 } else {
Wanlong Gao354ebb42012-12-07 10:10:04 +0800102 tst_resm(TPASS, "rt_sigsuspend PASSED");
Garrett Cooper135924f2010-02-26 19:52:32 -0800103 }
104 } else {
Wanlong Gao354ebb42012-12-07 10:10:04 +0800105 tst_resm(TFAIL | TTERRNO, "rt_sigsuspend failed");
Garrett Cooper135924f2010-02-26 19:52:32 -0800106 }
107
108 }
109
subrata_modak77336262009-05-21 18:28:46 +0000110 cleanup();
yaberauneya5833cc62010-01-26 08:24:52 +0000111
Garrett Cooperb0a973a2011-01-21 01:15:32 -0800112 tst_exit();
113}