plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2000 Silicon Graphics, Inc. All Rights Reserved. |
Zeng Linggang | 0ee24c5 | 2014-04-23 11:51:34 +0800 | [diff] [blame^] | 3 | * AUTHOR : William Roske |
| 4 | * CO-PILOT : Dave Fenner |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify it |
| 7 | * under the terms of version 2 of the GNU General Public License as |
| 8 | * published by the Free Software Foundation. |
| 9 | * |
| 10 | * This program is distributed in the hope that it would be useful, but |
| 11 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
| 13 | * |
| 14 | * Further, this software is distributed without any warranty that it is |
| 15 | * free of the rightful claim of any third person regarding infringement |
| 16 | * or the like. Any license provided herein, whether implied or |
| 17 | * otherwise, applies only to this software file. Patent licenses, if |
| 18 | * any, provided herein do not apply to combinations of this program with |
| 19 | * other software, or any other product whatsoever. |
| 20 | * |
| 21 | * 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] | 22 | * with this program; if not, write the Free Software Foundation, Inc., |
| 23 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 24 | * |
| 25 | * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy, |
| 26 | * Mountain View, CA 94043, or: |
| 27 | * |
| 28 | * http://www.sgi.com |
| 29 | * |
| 30 | * For further information regarding this notice, see: |
| 31 | * |
| 32 | * http://oss.sgi.com/projects/GenInfo/NoticeExplan/ |
| 33 | * |
| 34 | */ |
Zeng Linggang | 0ee24c5 | 2014-04-23 11:51:34 +0800 | [diff] [blame^] | 35 | /* |
| 36 | * DESCRIPTION |
| 37 | * 1.) test sbrk(8192) should return successfully. |
| 38 | * 2.) test sbrk(-8192) should return successfully. |
| 39 | */ |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 40 | |
| 41 | #include <unistd.h> |
| 42 | #include <errno.h> |
| 43 | #include <string.h> |
| 44 | #include <signal.h> |
| 45 | #include <sys/types.h> |
| 46 | |
| 47 | #include "test.h" |
| 48 | #include "usctest.h" |
| 49 | |
Cyril Hrubis | fdce7d5 | 2013-04-04 18:35:48 +0200 | [diff] [blame] | 50 | char *TCID = "sbrk01"; |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 51 | |
Zeng Linggang | 0ee24c5 | 2014-04-23 11:51:34 +0800 | [diff] [blame^] | 52 | static struct test_case_t { |
| 53 | long increment; |
| 54 | } test_cases[] = { |
| 55 | {8192}, |
| 56 | {-8192}, |
| 57 | }; |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 58 | |
Zeng Linggang | 0ee24c5 | 2014-04-23 11:51:34 +0800 | [diff] [blame^] | 59 | static void setup(void); |
| 60 | static void sbrk_verify(const struct test_case_t *); |
| 61 | static void cleanup(void); |
| 62 | |
| 63 | int TST_TOTAL = ARRAY_SIZE(test_cases); |
robbiew | d34d581 | 2005-07-11 22:28:09 +0000 | [diff] [blame] | 64 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 65 | int main(int ac, char **av) |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 66 | { |
Cyril Hrubis | 89af32a | 2012-10-24 16:39:11 +0200 | [diff] [blame] | 67 | int lc; |
| 68 | char *msg; |
Zeng Linggang | 0ee24c5 | 2014-04-23 11:51:34 +0800 | [diff] [blame^] | 69 | int i; |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 70 | |
Zeng Linggang | 0ee24c5 | 2014-04-23 11:51:34 +0800 | [diff] [blame^] | 71 | msg = parse_opts(ac, av, NULL, NULL); |
| 72 | if (msg != NULL) |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 73 | tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg); |
Garrett Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame] | 74 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 75 | setup(); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 76 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 77 | for (lc = 0; TEST_LOOPING(lc); lc++) { |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 78 | |
Caspar Zhang | d59a659 | 2013-03-07 14:59:12 +0800 | [diff] [blame] | 79 | tst_count = 0; |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 80 | |
Zeng Linggang | 0ee24c5 | 2014-04-23 11:51:34 +0800 | [diff] [blame^] | 81 | for (i = 0; i < TST_TOTAL; i++) |
| 82 | sbrk_verify(&test_cases[i]); |
Garrett Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame] | 83 | } |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 84 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 85 | cleanup(); |
Garrett Cooper | 1e6f5a6 | 2010-12-19 09:58:10 -0800 | [diff] [blame] | 86 | tst_exit(); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 87 | |
Garrett Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame] | 88 | } |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 89 | |
Zeng Linggang | 0ee24c5 | 2014-04-23 11:51:34 +0800 | [diff] [blame^] | 90 | static void setup(void) |
robbiew | d34d581 | 2005-07-11 22:28:09 +0000 | [diff] [blame] | 91 | { |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 92 | tst_sig(NOFORK, DEF_HANDLER, cleanup); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 93 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 94 | TEST_PAUSE; |
Garrett Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame] | 95 | } |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 96 | |
Zeng Linggang | 0ee24c5 | 2014-04-23 11:51:34 +0800 | [diff] [blame^] | 97 | static void sbrk_verify(const struct test_case_t *test) |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 98 | { |
Zeng Linggang | 0ee24c5 | 2014-04-23 11:51:34 +0800 | [diff] [blame^] | 99 | void *tret; |
| 100 | |
| 101 | tret = sbrk(test->increment); |
| 102 | TEST_ERRNO = errno; |
| 103 | |
| 104 | if (tret == (void *)-1) { |
| 105 | tst_resm(TFAIL | TTERRNO, "sbrk - Increase by %ld bytes failed", |
| 106 | test->increment); |
| 107 | } else { |
| 108 | tst_resm(TPASS, "sbrk - Increase by %ld bytes returned %p", |
| 109 | test->increment, tret); |
| 110 | } |
| 111 | } |
| 112 | |
| 113 | static void cleanup(void) |
| 114 | { |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 115 | TEST_CLEANUP; |
Chris Dearman | ec6edca | 2012-10-17 19:54:01 -0700 | [diff] [blame] | 116 | } |