]> git.kernelconcepts.de Git - karo-tx-redboot.git/blob - packages/net/autotest/v2_0/tests/memcheck.inl
Initial revision
[karo-tx-redboot.git] / packages / net / autotest / v2_0 / tests / memcheck.inl
1 //==========================================================================
2 //
3 //      tests/auto/memcheck.inl
4 //
5 //      Automated Testing by a Host Computer
6 //
7 //==========================================================================
8 //####ECOSGPLCOPYRIGHTBEGIN####
9 // -------------------------------------------
10 // This file is part of eCos, the Embedded Configurable Operating System.
11 // Copyright (C) 1998, 1999, 2000, 2001, 2002 Free Software Foundation, Inc.
12 //
13 // eCos is free software; you can redistribute it and/or modify it under
14 // the terms of the GNU General Public License as published by the Free
15 // Software Foundation; either version 2 or (at your option) any later version.
16 //
17 // eCos is distributed in the hope that it will be useful, but WITHOUT ANY
18 // WARRANTY; without even the implied warranty of MERCHANTABILITY or
19 // FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
20 // for more details.
21 //
22 // You should have received a copy of the GNU General Public License along
23 // with eCos; if not, write to the Free Software Foundation, Inc.,
24 // 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
25 //
26 // As a special exception, if other files instantiate templates or use macros
27 // or inline functions from this file, or you compile this file and link it
28 // with other works to produce a work based on this file, this file does not
29 // by itself cause the resulting work to be covered by the GNU General Public
30 // License. However the source code for this file must still be made available
31 // in accordance with section (3) of the GNU General Public License.
32 //
33 // This exception does not invalidate any other reasons why a work based on
34 // this file might be covered by the GNU General Public License.
35 //
36 // -------------------------------------------
37 //####ECOSGPLCOPYRIGHTEND####
38 //####BSDCOPYRIGHTBEGIN####
39 //
40 // -------------------------------------------
41 //
42 // Portions of this software may have been derived from OpenBSD or other sources,
43 // and are covered by the appropriate copyright disclaimers included herein.
44 //
45 // -------------------------------------------
46 //
47 //####BSDCOPYRIGHTEND####
48 //==========================================================================
49 //#####DESCRIPTIONBEGIN####
50 //
51 // Author(s):    hmt
52 // Contributors: hmt
53 // Date:         2000-11-10
54 // Purpose:      Check memory usage of the eCos TCP/IP Network Stack
55 // Description:  
56
57 #ifndef CYG_NET_GET_MEM_STATS_MISC
58 // API is not present, so dummies:
59 void memcheck_init( void )  {}
60 void memcheck_final( void ) {}
61 #else
62
63 #include <sys/mbuf.h>
64 extern struct  mbstat mbstat;
65
66 extern void cyg_kmem_print_stats( void );
67
68 cyg_mempool_info initial[3], final[3];
69
70 #define RATIO 15
71
72 static char *names[3] = { "Misc", "Mbufs", "Clusters" };
73
74 void memcheck_init( void )
75 {
76     int i;
77
78     cyg_kmem_print_stats();
79
80     for ( i = 0; i < 3; i++ )
81         if ( ! cyg_net_get_mem_stats( i, initial + i ) )
82             CYG_TEST_FAIL( "Getting initial mem stats" );
83 }
84
85 void memcheck_final( void )
86 {
87     int i;
88     for ( i = 0; i < 3; i++ )
89         if ( ! cyg_net_get_mem_stats( i, final + i ) )
90             CYG_TEST_FAIL( "Getting final mem stats" );
91
92     cyg_kmem_print_stats();
93
94     // NB do NOT check clusters (index 2) because clusters are managed
95     // differently.
96     for ( i = 0; i < 3; i++ ) {
97         int size = final[i].totalmem;
98         int initial_used = size - initial[i].freemem;
99         int margin = size * RATIO / 100;
100         int final_used = size - final[i].freemem;
101         int extra_used = final_used - initial_used;
102
103         if ( 2 == i ) {
104 #ifdef XFAIL
105             // ignore clusters if a faulty network is being simulated
106             // because memory gets eaten for partial packets awaiting
107             // reassembly.
108             continue; 
109 #else            
110             // Then it's clusters - they're managed differently
111             final_used -= (mbstat.m_clfree * final[i].blocksize);
112             extra_used = final_used - initial_used;
113 #endif
114         }
115
116         // Using up up to whatever was initially used -or- the percentage
117         // we test for; whichever is larger, is OK.
118         if ( (extra_used > initial_used) && (extra_used > margin) ) {
119             CYG_TEST_INFO( "Memory leak suspected" );
120             CYG_TEST_INFO( names[i] );
121             CYG_TEST_INFO( (final[i].blocksize > 0) ?
122                            "Variable mempool" : "Fixed mempool" );
123             CYG_TEST_FAIL( "Too much memory used - storeleak suspected" );
124         }
125     }
126 }
127
128 #undef RATIO
129
130 #endif
131
132 // EOF memcheck.inl