robbiew | 6d387ef | 2003-01-03 20:53:14 +0000 | [diff] [blame] | 1 | /* |
| 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_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 36 | #include <stdio.h> /* needed by testhead.h */ |
robbiew | 6eaecb2 | 2005-12-22 20:18:22 +0000 | [diff] [blame] | 37 | #ifdef CONFIG_COLDFIRE |
| 38 | #define __MALLOC_STANDARD__ |
| 39 | #endif |
Garrett Cooper | bacc849 | 2011-01-14 00:36:17 -0800 | [diff] [blame^] | 40 | #include <stdlib.h> |
robbiew | 6d387ef | 2003-01-03 20:53:14 +0000 | [diff] [blame] | 41 | #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 | |
| 50 | int local_flag = PASSED; |
| 51 | |
plars | 48049f3 | 2003-07-05 03:12:42 +0000 | [diff] [blame] | 52 | char *TCID = "mallopt01"; |
robbiew | 6d387ef | 2003-01-03 20:53:14 +0000 | [diff] [blame] | 53 | int block_number; |
robbiew | 6d387ef | 2003-01-03 20:53:14 +0000 | [diff] [blame] | 54 | FILE *temp; |
| 55 | int TST_TOTAL = 1; |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 56 | extern int Tst_COUNT; /* Test Case counter for tst_routines */ |
robbiew | 6d387ef | 2003-01-03 20:53:14 +0000 | [diff] [blame] | 57 | |
| 58 | void printinfo(); |
robbiew | 6d387ef | 2003-01-03 20:53:14 +0000 | [diff] [blame] | 59 | |
robbiew | d34d581 | 2005-07-11 22:28:09 +0000 | [diff] [blame] | 60 | #if !defined(UCLINUX) |
Garrett Cooper | a98d813 | 2010-08-18 01:40:20 -0700 | [diff] [blame] | 61 | /***** * * *****/ |
| 62 | struct mallinfo info; |
robbiew | d34d581 | 2005-07-11 22:28:09 +0000 | [diff] [blame] | 63 | |
robbiew | 6d387ef | 2003-01-03 20:53:14 +0000 | [diff] [blame] | 64 | /*--------------------------------------------------------------*/ |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 65 | int main(int argc, char *argv[]) |
robbiew | 6d387ef | 2003-01-03 20:53:14 +0000 | [diff] [blame] | 66 | { |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 67 | char *buf; |
robbiew | 6d387ef | 2003-01-03 20:53:14 +0000 | [diff] [blame] | 68 | int flag; |
| 69 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 70 | temp = stderr; |
robbiew | 6d387ef | 2003-01-03 20:53:14 +0000 | [diff] [blame] | 71 | tst_tmpdir(); |
| 72 | /*--------------------------------------------------------------*/ |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 73 | local_flag = PASSED; |
robbiew | 6d387ef | 2003-01-03 20:53:14 +0000 | [diff] [blame] | 74 | |
| 75 | flag = 0; |
| 76 | |
| 77 | if ((buf = malloc(20480)) == NULL) { |
vapier | cff4af0 | 2006-02-11 04:46:30 +0000 | [diff] [blame] | 78 | tst_resm(TBROK, "Reason: Malloc failed! %s", strerror(errno)); |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 79 | tst_exit(); |
robbiew | 6d387ef | 2003-01-03 20:53:14 +0000 | [diff] [blame] | 80 | } |
| 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 | }; |
robbiew | 6d387ef | 2003-01-03 20:53:14 +0000 | [diff] [blame] | 92 | 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_modak | 4bb656a | 2009-02-26 12:02:09 +0000 | [diff] [blame] | 101 | free(buf); |
robbiew | 6d387ef | 2003-01-03 20:53:14 +0000 | [diff] [blame] | 102 | |
| 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) { |
vapier | cff4af0 | 2006-02-11 04:46:30 +0000 | [diff] [blame] | 109 | tst_resm(TBROK, "Reason:Malloc failed. %s", strerror(errno)); |
robbiew | 6d387ef | 2003-01-03 20:53:14 +0000 | [diff] [blame] | 110 | tst_exit(); |
| 111 | } |
| 112 | |
| 113 | free(buf); |
| 114 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 115 | (local_flag == PASSED) ? tst_resm(TPASS, |
| 116 | "Test passed") : tst_resm(TFAIL, |
| 117 | "Test failed"); |
robbiew | 6d387ef | 2003-01-03 20:53:14 +0000 | [diff] [blame] | 118 | /*--------------------------------------------------------------*/ |
| 119 | /* Clean up any files created by test before call to anyfail. */ |
| 120 | |
| 121 | unlink("core"); |
| 122 | tst_rmdir(); |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 123 | tst_exit(); /* THIS CALL DOES NOT RETURN - EXITS!! */ |
Garrett Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame] | 124 | tst_exit(); |
robbiew | 6d387ef | 2003-01-03 20:53:14 +0000 | [diff] [blame] | 125 | } |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 126 | |
robbiew | 6d387ef | 2003-01-03 20:53:14 +0000 | [diff] [blame] | 127 | /*--------------------------------------------------------------*/ |
| 128 | void 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 | |
robbiew | d34d581 | 2005-07-11 22:28:09 +0000 | [diff] [blame] | 144 | #else |
robbiew | 6d387ef | 2003-01-03 20:53:14 +0000 | [diff] [blame] | 145 | |
robbiew | d34d581 | 2005-07-11 22:28:09 +0000 | [diff] [blame] | 146 | int main() |
| 147 | { |
vapier | 81a6307 | 2006-02-27 04:29:21 +0000 | [diff] [blame] | 148 | tst_resm(TINFO, "test is not available on uClinux"); |
Garrett Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame] | 149 | tst_exit(); |
robbiew | d34d581 | 2005-07-11 22:28:09 +0000 | [diff] [blame] | 150 | } |
| 151 | |
Garrett Cooper | bacc849 | 2011-01-14 00:36:17 -0800 | [diff] [blame^] | 152 | #endif /* if !defined(UCLINUX) */ |