blob: 1853521181dd7426ec8d3b4ef755228214d6bab1 [file] [log] [blame]
plars865695b2001-08-27 22:15:12 +00001/*
2 * Copyright (c) 2000 Silicon Graphics, Inc. All Rights Reserved.
Zeng Linggang0ee24c52014-04-23 11:51:34 +08003 * AUTHOR : William Roske
4 * CO-PILOT : Dave Fenner
plars865695b2001-08-27 22:15:12 +00005 *
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 Gaofed96412012-10-24 10:10:29 +080022 * with this program; if not, write the Free Software Foundation, Inc.,
23 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
plars865695b2001-08-27 22:15:12 +000024 *
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 Linggang0ee24c52014-04-23 11:51:34 +080035/*
36 * DESCRIPTION
37 * 1.) test sbrk(8192) should return successfully.
38 * 2.) test sbrk(-8192) should return successfully.
39 */
plars865695b2001-08-27 22:15:12 +000040
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"
plars865695b2001-08-27 22:15:12 +000048
Cyril Hrubisfdce7d52013-04-04 18:35:48 +020049char *TCID = "sbrk01";
plars865695b2001-08-27 22:15:12 +000050
Zeng Linggang0ee24c52014-04-23 11:51:34 +080051static struct test_case_t {
52 long increment;
53} test_cases[] = {
54 {8192},
55 {-8192},
56};
plars865695b2001-08-27 22:15:12 +000057
Zeng Linggang0ee24c52014-04-23 11:51:34 +080058static void setup(void);
59static void sbrk_verify(const struct test_case_t *);
60static void cleanup(void);
61
62int TST_TOTAL = ARRAY_SIZE(test_cases);
robbiewd34d5812005-07-11 22:28:09 +000063
subrata_modak56207ce2009-03-23 13:35:39 +000064int main(int ac, char **av)
plars865695b2001-08-27 22:15:12 +000065{
Cyril Hrubis89af32a2012-10-24 16:39:11 +020066 int lc;
Cyril Hrubis0b9589f2014-05-27 17:40:33 +020067 const char *msg;
Zeng Linggang0ee24c52014-04-23 11:51:34 +080068 int i;
subrata_modak56207ce2009-03-23 13:35:39 +000069
Zeng Linggang0ee24c52014-04-23 11:51:34 +080070 msg = parse_opts(ac, av, NULL, NULL);
71 if (msg != NULL)
subrata_modak56207ce2009-03-23 13:35:39 +000072 tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
Garrett Cooper2c282152010-12-16 00:55:50 -080073
subrata_modak56207ce2009-03-23 13:35:39 +000074 setup();
plars865695b2001-08-27 22:15:12 +000075
subrata_modak56207ce2009-03-23 13:35:39 +000076 for (lc = 0; TEST_LOOPING(lc); lc++) {
plars865695b2001-08-27 22:15:12 +000077
Caspar Zhangd59a6592013-03-07 14:59:12 +080078 tst_count = 0;
plars865695b2001-08-27 22:15:12 +000079
Zeng Linggang0ee24c52014-04-23 11:51:34 +080080 for (i = 0; i < TST_TOTAL; i++)
81 sbrk_verify(&test_cases[i]);
Garrett Cooper2c282152010-12-16 00:55:50 -080082 }
plars865695b2001-08-27 22:15:12 +000083
subrata_modak56207ce2009-03-23 13:35:39 +000084 cleanup();
Garrett Cooper1e6f5a62010-12-19 09:58:10 -080085 tst_exit();
plars865695b2001-08-27 22:15:12 +000086
Garrett Cooper2c282152010-12-16 00:55:50 -080087}
plars865695b2001-08-27 22:15:12 +000088
Zeng Linggang0ee24c52014-04-23 11:51:34 +080089static void setup(void)
robbiewd34d5812005-07-11 22:28:09 +000090{
subrata_modak56207ce2009-03-23 13:35:39 +000091 tst_sig(NOFORK, DEF_HANDLER, cleanup);
plars865695b2001-08-27 22:15:12 +000092
subrata_modak56207ce2009-03-23 13:35:39 +000093 TEST_PAUSE;
Garrett Cooper2c282152010-12-16 00:55:50 -080094}
plars865695b2001-08-27 22:15:12 +000095
Zeng Linggang0ee24c52014-04-23 11:51:34 +080096static void sbrk_verify(const struct test_case_t *test)
plars865695b2001-08-27 22:15:12 +000097{
Zeng Linggang0ee24c52014-04-23 11:51:34 +080098 void *tret;
99
100 tret = sbrk(test->increment);
101 TEST_ERRNO = errno;
102
103 if (tret == (void *)-1) {
104 tst_resm(TFAIL | TTERRNO, "sbrk - Increase by %ld bytes failed",
105 test->increment);
106 } else {
107 tst_resm(TPASS, "sbrk - Increase by %ld bytes returned %p",
108 test->increment, tret);
109 }
110}
111
112static void cleanup(void)
113{
Chris Dearmanec6edca2012-10-17 19:54:01 -0700114}