blob: 13887cb743154e67f361fc1078781524a9340829 [file] [log] [blame]
plars865695b2001-08-27 22:15:12 +00001/*
2 *
3 * Copyright (c) International Business Machines Corp., 2001
Cyril Hrubis3a1e9bc2012-11-27 19:50:27 +01004 * Copyright (c) 2012 Cyril Hrubis <chrubis@suse.cz>
plars865695b2001-08-27 22:15:12 +00005 *
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
Wanlong Gao4548c6c2012-10-19 18:03:36 +080018 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
plars865695b2001-08-27 22:15:12 +000019 */
20
robbiew96d23372003-03-26 20:40:04 +000021#define _GNU_SOURCE 1
plars865695b2001-08-27 22:15:12 +000022
23#include "test.h"
plars865695b2001-08-27 22:15:12 +000024
25#include <errno.h>
26
subrata_modak56207ce2009-03-23 13:35:39 +000027char *TCID = "getsid02";
plars865695b2001-08-27 22:15:12 +000028int TST_TOTAL = 1;
plars865695b2001-08-27 22:15:12 +000029
Stanislav Kholmanskikh23b37f32014-06-30 14:48:24 +040030static pid_t unused_pid;
Cyril Hrubis3a1e9bc2012-11-27 19:50:27 +010031
32static void cleanup(void);
33static void setup(void);
34
robbiew96d23372003-03-26 20:40:04 +000035int main(int ac, char **av)
plars865695b2001-08-27 22:15:12 +000036{
Cyril Hrubis89af32a2012-10-24 16:39:11 +020037 int lc;
Cyril Hrubis0b9589f2014-05-27 17:40:33 +020038 const char *msg;
plars865695b2001-08-27 22:15:12 +000039
Cyril Hrubis3a1e9bc2012-11-27 19:50:27 +010040 if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL)
Garrett Cooper60fa8012010-11-22 13:50:58 -080041 tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
plars865695b2001-08-27 22:15:12 +000042
Cyril Hrubis3a1e9bc2012-11-27 19:50:27 +010043 setup();
plars865695b2001-08-27 22:15:12 +000044
plars865695b2001-08-27 22:15:12 +000045 for (lc = 0; TEST_LOOPING(lc); lc++) {
Caspar Zhangd59a6592013-03-07 14:59:12 +080046 tst_count = 0;
plars865695b2001-08-27 22:15:12 +000047
Stanislav Kholmanskikh23b37f32014-06-30 14:48:24 +040048 TEST(getsid(unused_pid));
subrata_modakbdbaec52009-02-26 12:14:51 +000049
subrata_modak56207ce2009-03-23 13:35:39 +000050 if (TEST_RETURN == 0) {
plars865695b2001-08-27 22:15:12 +000051 tst_resm(TFAIL, "call succeed when failure expected");
52 continue;
53 }
subrata_modakbdbaec52009-02-26 12:14:51 +000054
plars865695b2001-08-27 22:15:12 +000055 switch (TEST_ERRNO) {
56 case ESRCH:
57 tst_resm(TPASS, "expected failure - errno = %d - %s",
58 TEST_ERRNO, strerror(TEST_ERRNO));
59 break;
60 default:
61 tst_resm(TFAIL, "call failed to produce "
62 "expected error - errno = %d - %s",
63 TEST_ERRNO, strerror(TEST_ERRNO));
64 break;
65 }
66 }
67
68 cleanup();
Garrett Cooper7d0a4a52010-12-16 10:05:08 -080069 tst_exit();
plars865695b2001-08-27 22:15:12 +000070}
71
subrata_modak56207ce2009-03-23 13:35:39 +000072void setup(void)
plars865695b2001-08-27 22:15:12 +000073{
Stanislav Kholmanskikh23b37f32014-06-30 14:48:24 +040074 unused_pid = tst_get_unused_pid(cleanup);
Garrett Cooper2c282152010-12-16 00:55:50 -080075
plars865695b2001-08-27 22:15:12 +000076 tst_sig(NOFORK, DEF_HANDLER, cleanup);
Wanlong Gao354ebb42012-12-07 10:10:04 +080077
plars865695b2001-08-27 22:15:12 +000078 TEST_PAUSE;
79}
80
subrata_modak56207ce2009-03-23 13:35:39 +000081void cleanup(void)
plars865695b2001-08-27 22:15:12 +000082{
Chris Dearmanec6edca2012-10-17 19:54:01 -070083}