blob: 90d4fd6e7eee8d2a140e67fa8a13ebd79b29574a [file] [log] [blame]
robbiew6d387ef2003-01-03 20:53:14 +00001/*
2 *
3 * Copyright (c) International Business Machines Corp., 2002
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
13 * the GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
Wanlong Gao4548c6c2012-10-19 18:03:36 +080017 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
robbiew6d387ef2003-01-03 20:53:14 +000018 */
19
20/* 01/02/2003 Port to LTP avenkat@us.ibm.com*/
21/* 06/30/2001 Port to Linux nsharoff@us.ibm.com */
22
23/*
24 * NAME
25 * mallopt
26 *
27 * CALLS
28 * malloc(3x), mallopt(3x), mallinfo(3x).
29 *
30 * ALGORITHM
31 * Set options, malloc memory, and check resource ussage.
32 *
33 * RESTRICTIONS
34 */
35
robbiew6eaecb22005-12-22 20:18:22 +000036#ifdef CONFIG_COLDFIRE
37#define __MALLOC_STANDARD__
38#endif
robbiew6d387ef2003-01-03 20:53:14 +000039#include <errno.h>
Chris Dearman37550cf2012-10-17 19:54:01 -070040/*
Garrett Cooper2789bc72011-01-14 09:45:16 -080041 * NOTE: struct mallinfo is only exported via malloc.h (not stdlib.h), even
Garrett Cooperc2ed6ed2011-01-14 09:49:08 -080042 * though it's an obsolete header for malloc(3).
Garrett Cooper2789bc72011-01-14 09:45:16 -080043 *
44 * Inconsistencies rock.
45 */
46#include <malloc.h>
47#include <stdio.h>
robbiew6d387ef2003-01-03 20:53:14 +000048
robbiew6d387ef2003-01-03 20:53:14 +000049#include "test.h"
Garrett Cooperc2ed6ed2011-01-14 09:49:08 -080050#include "safe_macros.h"
robbiew6d387ef2003-01-03 20:53:14 +000051
52#define FAILED 0
53#define PASSED 1
54
55int local_flag = PASSED;
56
plars48049f32003-07-05 03:12:42 +000057char *TCID = "mallopt01";
robbiew6d387ef2003-01-03 20:53:14 +000058int block_number;
robbiew6d387ef2003-01-03 20:53:14 +000059FILE *temp;
60int TST_TOTAL = 1;
Caspar Zhangd59a6592013-03-07 14:59:12 +080061extern int tst_COUNT; /* Test Case counter for tst_routines */
robbiew6d387ef2003-01-03 20:53:14 +000062
63void printinfo();
robbiew6d387ef2003-01-03 20:53:14 +000064
robbiewd34d5812005-07-11 22:28:09 +000065#if !defined(UCLINUX)
Garrett Coopera98d8132010-08-18 01:40:20 -070066struct mallinfo info;
robbiewd34d5812005-07-11 22:28:09 +000067
subrata_modak56207ce2009-03-23 13:35:39 +000068int main(int argc, char *argv[])
robbiew6d387ef2003-01-03 20:53:14 +000069{
subrata_modak56207ce2009-03-23 13:35:39 +000070 char *buf;
robbiew6d387ef2003-01-03 20:53:14 +000071
robbiew6d387ef2003-01-03 20:53:14 +000072 tst_tmpdir();
robbiew6d387ef2003-01-03 20:53:14 +000073
Garrett Cooperc2ed6ed2011-01-14 09:49:08 -080074 buf = SAFE_MALLOC(NULL, 20480);
robbiew6d387ef2003-01-03 20:53:14 +000075
76 /*
77 * Check space usage.
78 */
79
80 info = mallinfo();
81 if (info.uordblks < 20480) {
robbiew6d387ef2003-01-03 20:53:14 +000082 printinfo();
Garrett Cooper2789bc72011-01-14 09:45:16 -080083 tst_resm(TFAIL, "mallinfo failed: uordblks < 20K");
84 }
85 if (info.smblks != 0) {
86 printinfo();
87 tst_resm(TFAIL, "mallinfo failed: smblks != 0");
robbiew6d387ef2003-01-03 20:53:14 +000088 }
subrata_modak4bb656a2009-02-26 12:02:09 +000089 free(buf);
robbiew6d387ef2003-01-03 20:53:14 +000090
91 /*
92 * Test mallopt's M_MXFAST and M_NLBLKS cmds.
93 */
94 mallopt(M_MXFAST, 2048);
95 mallopt(M_NLBLKS, 50);
Garrett Cooperc2ed6ed2011-01-14 09:49:08 -080096 buf = SAFE_MALLOC(NULL, 1024);
robbiew6d387ef2003-01-03 20:53:14 +000097
98 free(buf);
99
robbiew6d387ef2003-01-03 20:53:14 +0000100 unlink("core");
101 tst_rmdir();
Garrett Cooper2c282152010-12-16 00:55:50 -0800102 tst_exit();
robbiew6d387ef2003-01-03 20:53:14 +0000103}
subrata_modak56207ce2009-03-23 13:35:39 +0000104
Mike Frysingerc57fba52014-04-09 18:56:30 -0400105void printinfo(void)
robbiew6d387ef2003-01-03 20:53:14 +0000106{
107
Garrett Cooper2789bc72011-01-14 09:45:16 -0800108 fprintf(stderr, "mallinfo structure:\n");
109 fprintf(stderr, "mallinfo.arena = %d\n", info.arena);
110 fprintf(stderr, "mallinfo.ordblks = %d\n", info.ordblks);
111 fprintf(stderr, "mallinfo.smblks = %d\n", info.smblks);
112 fprintf(stderr, "mallinfo.hblkhd = %d\n", info.hblkhd);
113 fprintf(stderr, "mallinfo.hblks = %d\n", info.hblks);
114 fprintf(stderr, "mallinfo.usmblks = %d\n", info.usmblks);
115 fprintf(stderr, "mallinfo.fsmblks = %d\n", info.fsmblks);
116 fprintf(stderr, "mallinfo.uordblks = %d\n", info.uordblks);
117 fprintf(stderr, "mallinfo.fordblks = %d\n", info.fordblks);
118 fprintf(stderr, "mallinfo.keepcost = %d\n", info.keepcost);
robbiew6d387ef2003-01-03 20:53:14 +0000119}
120
robbiewd34d5812005-07-11 22:28:09 +0000121#else
Mike Frysingerc57fba52014-04-09 18:56:30 -0400122int main(void)
robbiewd34d5812005-07-11 22:28:09 +0000123{
Garrett Cooper2789bc72011-01-14 09:45:16 -0800124 tst_brkm(TCONF, NULL, "test is not available on uClinux");
robbiewd34d5812005-07-11 22:28:09 +0000125}
Garrett Cooperbacc8492011-01-14 00:36:17 -0800126#endif /* if !defined(UCLINUX) */