~statik/ubuntu/maverick/erlang/erlang-merge-testing

« back to all changes in this revision

Viewing changes to erts/emulator/test/alloc_SUITE_data/mseg_clear_cache.c

  • Committer: Bazaar Package Importer
  • Author(s): Sergei Golovan
  • Date: 2009-12-20 09:03:40 UTC
  • mto: (3.6.1 sid)
  • mto: This revision was merged to the branch mainline in revision 27.
  • Revision ID: james.westby@ubuntu.com-20091220090340-w3kbi1lj1wp7l2m3
Tags: upstream-13.b.3-dfsg
ImportĀ upstreamĀ versionĀ 13.b.3-dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* ``The contents of this file are subject to the Erlang Public License,
 
2
 * Version 1.1, (the "License"); you may not use this file except in
 
3
 * compliance with the License. You should have received a copy of the
 
4
 * Erlang Public License along with this software. If not, it can be
 
5
 * retrieved via the world wide web at http://www.erlang.org/.
 
6
 * 
 
7
 * Software distributed under the License is distributed on an "AS IS"
 
8
 * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
 
9
 * the License for the specific language governing rights and limitations
 
10
 * under the License.
 
11
 * 
 
12
 * The Initial Developer of the Original Code is Ericsson Utvecklings AB.
 
13
 * Portions created by Ericsson are Copyright 1999, Ericsson Utvecklings
 
14
 * AB. All Rights Reserved.''
 
15
 * 
 
16
 *     $Id$
 
17
 */
 
18
 
 
19
#include "testcase_driver.h"
 
20
#include "allocator_test.h"
 
21
 
 
22
#define MAX_SEGS 10
 
23
 
 
24
typedef struct {
 
25
    void *ptr;
 
26
    Ulong size;
 
27
} seg_t;
 
28
 
 
29
char *
 
30
testcase_name(void)
 
31
{
 
32
    return "mseg_clear_cache";
 
33
}
 
34
 
 
35
void
 
36
testcase_run(TestCaseState_t *tcs)
 
37
{
 
38
    int i;
 
39
    Ulong n;
 
40
    seg_t *seg;
 
41
 
 
42
    if (!HAVE_MSEG())
 
43
        testcase_skipped(tcs, "No mseg_alloc; nothing to test");
 
44
 
 
45
    seg = (seg_t *) testcase_alloc(sizeof(seg_t)*(MAX_SEGS+1));
 
46
 
 
47
    ASSERT(tcs, seg);
 
48
 
 
49
    for (i = 0; i <= MAX_SEGS; i++)
 
50
        seg[i].ptr = NULL;
 
51
 
 
52
    tcs->extra = &seg[0];
 
53
 
 
54
    for (i = 0; i < MAX_SEGS; i++) {
 
55
        seg[i].size = 1000;
 
56
        seg[i].ptr = MSEG_ALLOC(&seg[i].size);
 
57
        ASSERT(tcs, seg[i].ptr);
 
58
        ASSERT(tcs, seg[i].size >= 1000);
 
59
    }
 
60
 
 
61
    n = MSEG_NO();
 
62
    testcase_printf(tcs, "MSEG_NO() = %lu\n", n);
 
63
 
 
64
    ASSERT(tcs, n >= MAX_SEGS);
 
65
 
 
66
    testcase_printf(tcs, "Deallocating half of the segments\n");
 
67
    for (i = MAX_SEGS-1; i >= MAX_SEGS/2; i--) {
 
68
        MSEG_DEALLOC(seg[i].ptr, seg[i].size);
 
69
        seg[i].ptr = NULL;
 
70
    }
 
71
 
 
72
    n = MSEG_NO();
 
73
    testcase_printf(tcs, "MSEG_NO() = %lu\n", n);
 
74
 
 
75
    ASSERT(tcs, n >= MAX_SEGS/2);
 
76
 
 
77
    n = MSEG_CACHE_SIZE();
 
78
    testcase_printf(tcs, "MSEG_CACHE_SIZE() = %lu\n", n);
 
79
    ASSERT(tcs, n > 0); 
 
80
 
 
81
    testcase_printf(tcs, "MSEG_CLEAR_CACHE()\n");
 
82
    MSEG_CLEAR_CACHE();
 
83
 
 
84
    n = MSEG_CACHE_SIZE();
 
85
    testcase_printf(tcs, "MSEG_CACHE_SIZE() = %lu\n", n);
 
86
 
 
87
    ASSERT(tcs, n == 0); 
 
88
 
 
89
}
 
90
 
 
91
void
 
92
testcase_cleanup(TestCaseState_t *tcs)
 
93
{
 
94
    if (tcs->extra) {
 
95
        seg_t *seg = (seg_t *) tcs->extra;
 
96
        int i;
 
97
        for (i = 0; seg[i].ptr; i++)
 
98
            MSEG_DEALLOC(seg[i].ptr, seg[i].size);
 
99
        testcase_free((void *) seg);
 
100
        tcs->extra = NULL;
 
101
    }
 
102
}