blob: d356cb21fbb1db6e3603ef8fc6471485b43a3781 [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
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 */
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
subrata_modak56207ce2009-03-23 13:35:39 +000036#include <stdio.h> /* needed by testhead.h */
robbiew6eaecb22005-12-22 20:18:22 +000037#ifdef CONFIG_COLDFIRE
38#define __MALLOC_STANDARD__
39#endif
Garrett Cooperbacc8492011-01-14 00:36:17 -080040#include <stdlib.h>
robbiew6d387ef2003-01-03 20:53:14 +000041#include <errno.h>
42
43/***** LTP Port *****/
44#include "test.h"
45#include "usctest.h"
46
47#define FAILED 0
48#define PASSED 1
49
50int local_flag = PASSED;
51
plars48049f32003-07-05 03:12:42 +000052char *TCID = "mallopt01";
robbiew6d387ef2003-01-03 20:53:14 +000053int block_number;
robbiew6d387ef2003-01-03 20:53:14 +000054FILE *temp;
55int TST_TOTAL = 1;
subrata_modak56207ce2009-03-23 13:35:39 +000056extern int Tst_COUNT; /* Test Case counter for tst_routines */
robbiew6d387ef2003-01-03 20:53:14 +000057
58void printinfo();
robbiew6d387ef2003-01-03 20:53:14 +000059
robbiewd34d5812005-07-11 22:28:09 +000060#if !defined(UCLINUX)
Garrett Coopera98d8132010-08-18 01:40:20 -070061/***** * * *****/
62struct mallinfo info;
robbiewd34d5812005-07-11 22:28:09 +000063
robbiew6d387ef2003-01-03 20:53:14 +000064/*--------------------------------------------------------------*/
subrata_modak56207ce2009-03-23 13:35:39 +000065int main(int argc, char *argv[])
robbiew6d387ef2003-01-03 20:53:14 +000066{
subrata_modak56207ce2009-03-23 13:35:39 +000067 char *buf;
robbiew6d387ef2003-01-03 20:53:14 +000068 int flag;
69
subrata_modak56207ce2009-03-23 13:35:39 +000070 temp = stderr;
robbiew6d387ef2003-01-03 20:53:14 +000071 tst_tmpdir();
72/*--------------------------------------------------------------*/
subrata_modak56207ce2009-03-23 13:35:39 +000073 local_flag = PASSED;
robbiew6d387ef2003-01-03 20:53:14 +000074
75 flag = 0;
76
77 if ((buf = malloc(20480)) == NULL) {
vapiercff4af02006-02-11 04:46:30 +000078 tst_resm(TBROK, "Reason: Malloc failed! %s", strerror(errno));
subrata_modak56207ce2009-03-23 13:35:39 +000079 tst_exit();
robbiew6d387ef2003-01-03 20:53:14 +000080 }
81
82 /*
83 * Check space usage.
84 */
85
86 info = mallinfo();
87 if (info.uordblks < 20480) {
88 fprintf(temp, "mallinfo failed: uordblks < 20K\n");
89 flag = 1;
90 local_flag = FAILED;
91 };
robbiew6d387ef2003-01-03 20:53:14 +000092 if (info.smblks != 0) {
93 fprintf(temp, "mallinfo failed: smblks != 0\n");
94 flag = 1;
95 local_flag = FAILED;
96 }
97 if (flag == 1) {
98 printinfo();
99 flag = 0;
100 }
subrata_modak4bb656a2009-02-26 12:02:09 +0000101 free(buf);
robbiew6d387ef2003-01-03 20:53:14 +0000102
103 /*
104 * Test mallopt's M_MXFAST and M_NLBLKS cmds.
105 */
106 mallopt(M_MXFAST, 2048);
107 mallopt(M_NLBLKS, 50);
108 if ((buf = malloc(1024)) == NULL) {
vapiercff4af02006-02-11 04:46:30 +0000109 tst_resm(TBROK, "Reason:Malloc failed. %s", strerror(errno));
robbiew6d387ef2003-01-03 20:53:14 +0000110 tst_exit();
111 }
112
113 free(buf);
114
subrata_modak56207ce2009-03-23 13:35:39 +0000115 (local_flag == PASSED) ? tst_resm(TPASS,
116 "Test passed") : tst_resm(TFAIL,
117 "Test failed");
robbiew6d387ef2003-01-03 20:53:14 +0000118/*--------------------------------------------------------------*/
119/* Clean up any files created by test before call to anyfail. */
120
121 unlink("core");
122 tst_rmdir();
subrata_modak56207ce2009-03-23 13:35:39 +0000123 tst_exit(); /* THIS CALL DOES NOT RETURN - EXITS!! */
Garrett Cooper2c282152010-12-16 00:55:50 -0800124 tst_exit();
robbiew6d387ef2003-01-03 20:53:14 +0000125}
subrata_modak56207ce2009-03-23 13:35:39 +0000126
robbiew6d387ef2003-01-03 20:53:14 +0000127/*--------------------------------------------------------------*/
128void printinfo()
129{
130
131 fprintf(temp, "mallinfo structure:\n");
132 fprintf(temp, "mallinfo.arena = %d\n", info.arena);
133 fprintf(temp, "mallinfo.ordblks = %d\n", info.ordblks);
134 fprintf(temp, "mallinfo.smblks = %d\n", info.smblks);
135 fprintf(temp, "mallinfo.hblkhd = %d\n", info.hblkhd);
136 fprintf(temp, "mallinfo.hblks = %d\n", info.hblks);
137 fprintf(temp, "mallinfo.usmblks = %d\n", info.usmblks);
138 fprintf(temp, "mallinfo.fsmblks = %d\n", info.fsmblks);
139 fprintf(temp, "mallinfo.uordblks = %d\n", info.uordblks);
140 fprintf(temp, "mallinfo.fordblks = %d\n", info.fordblks);
141 fprintf(temp, "mallinfo.keepcost = %d\n", info.keepcost);
142}
143
robbiewd34d5812005-07-11 22:28:09 +0000144#else
robbiew6d387ef2003-01-03 20:53:14 +0000145
robbiewd34d5812005-07-11 22:28:09 +0000146int main()
147{
vapier81a63072006-02-27 04:29:21 +0000148 tst_resm(TINFO, "test is not available on uClinux");
Garrett Cooper2c282152010-12-16 00:55:50 -0800149 tst_exit();
robbiewd34d5812005-07-11 22:28:09 +0000150}
151
Garrett Cooperbacc8492011-01-14 00:36:17 -0800152#endif /* if !defined(UCLINUX) */