robbiew | 544b604 | 2005-05-26 20:38:47 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) Wipro Technologies Ltd, 2005. All Rights Reserved. |
Cyril Hrubis | 6c5ad9b | 2013-10-23 16:17:07 +0200 | [diff] [blame] | 3 | * Author: Prashant P Yendigeri <prashant.yendigeri@wipro.com> |
robbiew | 544b604 | 2005-05-26 20:38:47 +0000 | [diff] [blame] | 4 | * |
| 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 Gao | fed9641 | 2012-10-24 10:10:29 +0800 | [diff] [blame] | 14 | * with this program; if not, write the Free Software Foundation, Inc., |
| 15 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
robbiew | 544b604 | 2005-05-26 20:38:47 +0000 | [diff] [blame] | 16 | */ |
robbiew | 544b604 | 2005-05-26 20:38:47 +0000 | [diff] [blame] | 17 | |
robbiew | f0b5149 | 2005-10-03 18:57:05 +0000 | [diff] [blame] | 18 | #include <features.h> |
robbiew | f0b5149 | 2005-10-03 18:57:05 +0000 | [diff] [blame] | 19 | |
robbiew | 544b604 | 2005-05-26 20:38:47 +0000 | [diff] [blame] | 20 | #include <stdio.h> |
| 21 | #include <unistd.h> |
| 22 | #include <errno.h> |
| 23 | #include <ucontext.h> |
| 24 | |
| 25 | #include "test.h" |
robbiew | 544b604 | 2005-05-26 20:38:47 +0000 | [diff] [blame] | 26 | |
Cyril Hrubis | fdce7d5 | 2013-04-04 18:35:48 +0200 | [diff] [blame] | 27 | char *TCID = "getcontext01"; |
Carmelo AMOROSO | 595642c | 2012-01-23 11:01:08 +0100 | [diff] [blame] | 28 | |
| 29 | #if !defined(__UCLIBC__) |
| 30 | |
Cyril Hrubis | 6c5ad9b | 2013-10-23 16:17:07 +0200 | [diff] [blame] | 31 | static void setup(void); |
| 32 | static void cleanup(void); |
robbiew | 544b604 | 2005-05-26 20:38:47 +0000 | [diff] [blame] | 33 | |
Cyril Hrubis | fdce7d5 | 2013-04-04 18:35:48 +0200 | [diff] [blame] | 34 | int TST_TOTAL = 1; |
robbiew | 544b604 | 2005-05-26 20:38:47 +0000 | [diff] [blame] | 35 | |
Honggyu Kim | ecd42f7 | 2013-10-23 21:07:30 +0900 | [diff] [blame] | 36 | static 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 Hrubis | 6c5ad9b | 2013-10-23 16:17:07 +0200 | [diff] [blame] | 44 | tst_resm(TCONF, "getcontext not implemented in libc"); |
Honggyu Kim | ecd42f7 | 2013-10-23 21:07:30 +0900 | [diff] [blame] | 45 | else |
| 46 | tst_resm(TFAIL | TTERRNO, "getcontext failed"); |
Cyril Hrubis | 6c5ad9b | 2013-10-23 16:17:07 +0200 | [diff] [blame] | 47 | } else if (TEST_RETURN == 0) { |
Honggyu Kim | ecd42f7 | 2013-10-23 21:07:30 +0900 | [diff] [blame] | 48 | tst_resm(TPASS, "getcontext passed"); |
Cyril Hrubis | 6c5ad9b | 2013-10-23 16:17:07 +0200 | [diff] [blame] | 49 | } else { |
| 50 | tst_resm(TFAIL, "Unexpected return value %li", TEST_RETURN); |
| 51 | } |
Honggyu Kim | ecd42f7 | 2013-10-23 21:07:30 +0900 | [diff] [blame] | 52 | } |
| 53 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 54 | int main(int ac, char **av) |
robbiew | 544b604 | 2005-05-26 20:38:47 +0000 | [diff] [blame] | 55 | { |
Cyril Hrubis | 89af32a | 2012-10-24 16:39:11 +0200 | [diff] [blame] | 56 | int lc; |
Cyril Hrubis | 0b9589f | 2014-05-27 17:40:33 +0200 | [diff] [blame] | 57 | const char *msg; |
robbiew | 544b604 | 2005-05-26 20:38:47 +0000 | [diff] [blame] | 58 | |
Garrett Cooper | 45e285d | 2010-11-22 12:19:25 -0800 | [diff] [blame] | 59 | if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL) |
Garrett Cooper | 60fa801 | 2010-11-22 13:50:58 -0800 | [diff] [blame] | 60 | tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg); |
robbiew | 544b604 | 2005-05-26 20:38:47 +0000 | [diff] [blame] | 61 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 62 | setup(); |
robbiew | 544b604 | 2005-05-26 20:38:47 +0000 | [diff] [blame] | 63 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 64 | for (lc = 0; TEST_LOOPING(lc); lc++) { |
robbiew | 544b604 | 2005-05-26 20:38:47 +0000 | [diff] [blame] | 65 | |
Caspar Zhang | d59a659 | 2013-03-07 14:59:12 +0800 | [diff] [blame] | 66 | tst_count = 0; |
robbiew | 544b604 | 2005-05-26 20:38:47 +0000 | [diff] [blame] | 67 | |
Honggyu Kim | ecd42f7 | 2013-10-23 21:07:30 +0900 | [diff] [blame] | 68 | test_getcontext(); |
Garrett Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame] | 69 | } |
robbiew | 544b604 | 2005-05-26 20:38:47 +0000 | [diff] [blame] | 70 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 71 | cleanup(); |
Garrett Cooper | 1569799 | 2010-12-18 06:31:28 -0800 | [diff] [blame] | 72 | tst_exit(); |
Garrett Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame] | 73 | } |
robbiew | 544b604 | 2005-05-26 20:38:47 +0000 | [diff] [blame] | 74 | |
Cyril Hrubis | 6c5ad9b | 2013-10-23 16:17:07 +0200 | [diff] [blame] | 75 | static void setup(void) |
robbiew | 544b604 | 2005-05-26 20:38:47 +0000 | [diff] [blame] | 76 | { |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 77 | tst_sig(NOFORK, DEF_HANDLER, cleanup); |
robbiew | 544b604 | 2005-05-26 20:38:47 +0000 | [diff] [blame] | 78 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 79 | TEST_PAUSE; |
Garrett Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame] | 80 | } |
robbiew | 544b604 | 2005-05-26 20:38:47 +0000 | [diff] [blame] | 81 | |
Cyril Hrubis | 6c5ad9b | 2013-10-23 16:17:07 +0200 | [diff] [blame] | 82 | static void cleanup(void) |
robbiew | 544b604 | 2005-05-26 20:38:47 +0000 | [diff] [blame] | 83 | { |
Garrett Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame] | 84 | } |
robbiew | 544b604 | 2005-05-26 20:38:47 +0000 | [diff] [blame] | 85 | |
robbiew | f0b5149 | 2005-10-03 18:57:05 +0000 | [diff] [blame] | 86 | #else /* systems that dont support obsolete getcontext */ |
Cyril Hrubis | 6c5ad9b | 2013-10-23 16:17:07 +0200 | [diff] [blame] | 87 | int main(void) |
robbiew | f0b5149 | 2005-10-03 18:57:05 +0000 | [diff] [blame] | 88 | { |
Garrett Cooper | 1569799 | 2010-12-18 06:31:28 -0800 | [diff] [blame] | 89 | tst_brkm(TCONF, NULL, "system doesn't have getcontext support"); |
robbiew | f0b5149 | 2005-10-03 18:57:05 +0000 | [diff] [blame] | 90 | } |
Carmelo AMOROSO | 595642c | 2012-01-23 11:01:08 +0100 | [diff] [blame] | 91 | #endif |