blob: 5e787b2feace831316eeeb82a1b2f975bfb969ad [file] [log] [blame]
robbiew544b6042005-05-26 20:38:47 +00001/*
2 * Copyright (c) Wipro Technologies Ltd, 2005. All Rights Reserved.
Cyril Hrubis6c5ad9b2013-10-23 16:17:07 +02003 * Author: Prashant P Yendigeri <prashant.yendigeri@wipro.com>
robbiew544b6042005-05-26 20:38:47 +00004 *
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
Wanlong Gaofed96412012-10-24 10:10:29 +080014 * with this program; if not, write the Free Software Foundation, Inc.,
15 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
robbiew544b6042005-05-26 20:38:47 +000016 */
robbiew544b6042005-05-26 20:38:47 +000017
robbiewf0b51492005-10-03 18:57:05 +000018#include <features.h>
robbiewf0b51492005-10-03 18:57:05 +000019
robbiew544b6042005-05-26 20:38:47 +000020#include <stdio.h>
21#include <unistd.h>
22#include <errno.h>
23#include <ucontext.h>
24
25#include "test.h"
robbiew544b6042005-05-26 20:38:47 +000026
Cyril Hrubisfdce7d52013-04-04 18:35:48 +020027char *TCID = "getcontext01";
Carmelo AMOROSO595642c2012-01-23 11:01:08 +010028
29#if !defined(__UCLIBC__)
30
Cyril Hrubis6c5ad9b2013-10-23 16:17:07 +020031static void setup(void);
32static void cleanup(void);
robbiew544b6042005-05-26 20:38:47 +000033
Cyril Hrubisfdce7d52013-04-04 18:35:48 +020034int TST_TOTAL = 1;
robbiew544b6042005-05-26 20:38:47 +000035
Honggyu Kimecd42f72013-10-23 21:07:30 +090036static void test_getcontext(void)
37{
38 ucontext_t ptr;
39
40 TEST(getcontext(&ptr));
41
42 if (TEST_RETURN == -1) {
43 if (errno == ENOSYS)
Cyril Hrubis6c5ad9b2013-10-23 16:17:07 +020044 tst_resm(TCONF, "getcontext not implemented in libc");
Honggyu Kimecd42f72013-10-23 21:07:30 +090045 else
46 tst_resm(TFAIL | TTERRNO, "getcontext failed");
Cyril Hrubis6c5ad9b2013-10-23 16:17:07 +020047 } else if (TEST_RETURN == 0) {
Honggyu Kimecd42f72013-10-23 21:07:30 +090048 tst_resm(TPASS, "getcontext passed");
Cyril Hrubis6c5ad9b2013-10-23 16:17:07 +020049 } else {
50 tst_resm(TFAIL, "Unexpected return value %li", TEST_RETURN);
51 }
Honggyu Kimecd42f72013-10-23 21:07:30 +090052}
53
subrata_modak56207ce2009-03-23 13:35:39 +000054int main(int ac, char **av)
robbiew544b6042005-05-26 20:38:47 +000055{
Cyril Hrubis89af32a2012-10-24 16:39:11 +020056 int lc;
Cyril Hrubis0b9589f2014-05-27 17:40:33 +020057 const char *msg;
robbiew544b6042005-05-26 20:38:47 +000058
Garrett Cooper45e285d2010-11-22 12:19:25 -080059 if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL)
Garrett Cooper60fa8012010-11-22 13:50:58 -080060 tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
robbiew544b6042005-05-26 20:38:47 +000061
subrata_modak56207ce2009-03-23 13:35:39 +000062 setup();
robbiew544b6042005-05-26 20:38:47 +000063
subrata_modak56207ce2009-03-23 13:35:39 +000064 for (lc = 0; TEST_LOOPING(lc); lc++) {
robbiew544b6042005-05-26 20:38:47 +000065
Caspar Zhangd59a6592013-03-07 14:59:12 +080066 tst_count = 0;
robbiew544b6042005-05-26 20:38:47 +000067
Honggyu Kimecd42f72013-10-23 21:07:30 +090068 test_getcontext();
Garrett Cooper2c282152010-12-16 00:55:50 -080069 }
robbiew544b6042005-05-26 20:38:47 +000070
subrata_modak56207ce2009-03-23 13:35:39 +000071 cleanup();
Garrett Cooper15697992010-12-18 06:31:28 -080072 tst_exit();
Garrett Cooper2c282152010-12-16 00:55:50 -080073}
robbiew544b6042005-05-26 20:38:47 +000074
Cyril Hrubis6c5ad9b2013-10-23 16:17:07 +020075static void setup(void)
robbiew544b6042005-05-26 20:38:47 +000076{
subrata_modak56207ce2009-03-23 13:35:39 +000077 tst_sig(NOFORK, DEF_HANDLER, cleanup);
robbiew544b6042005-05-26 20:38:47 +000078
subrata_modak56207ce2009-03-23 13:35:39 +000079 TEST_PAUSE;
Garrett Cooper2c282152010-12-16 00:55:50 -080080}
robbiew544b6042005-05-26 20:38:47 +000081
Cyril Hrubis6c5ad9b2013-10-23 16:17:07 +020082static void cleanup(void)
robbiew544b6042005-05-26 20:38:47 +000083{
Garrett Cooper2c282152010-12-16 00:55:50 -080084}
robbiew544b6042005-05-26 20:38:47 +000085
robbiewf0b51492005-10-03 18:57:05 +000086#else /* systems that dont support obsolete getcontext */
Cyril Hrubis6c5ad9b2013-10-23 16:17:07 +020087int main(void)
robbiewf0b51492005-10-03 18:57:05 +000088{
Garrett Cooper15697992010-12-18 06:31:28 -080089 tst_brkm(TCONF, NULL, "system doesn't have getcontext support");
robbiewf0b51492005-10-03 18:57:05 +000090}
Carmelo AMOROSO595642c2012-01-23 11:01:08 +010091#endif