2
/*===========================================================================
4
* About : garbage collector test
6
* Copyright (C) 2006 Jun Inoue <jun.lambda@gmail.com>
7
* Copyright (c) 2007 SigScheme Project <uim AT freedesktop.org>
11
* Redistribution and use in source and binary forms, with or without
12
* modification, are permitted provided that the following conditions
15
* 1. Redistributions of source code must retain the above copyright
16
* notice, this list of conditions and the following disclaimer.
17
* 2. Redistributions in binary form must reproduce the above copyright
18
* notice, this list of conditions and the following disclaimer in the
19
* documentation and/or other materials provided with the distribution.
20
* 3. Neither the name of authors nor the names of its contributors
21
* may be used to endorse or promote products derived from this software
22
* without specific prior written permission.
24
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS
25
* IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
26
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
27
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR
28
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
29
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
30
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
31
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
32
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
33
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
34
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35
===========================================================================*/
36
#include <sigscheme/config.h>
37
#if !(SCM_USE_STORAGE_COMPACT || SCM_USE_STORAGE_FATTY)
38
#define TST_EXCLUDE_THIS
41
#include "sscm-test.h"
42
#include "sigscheme.h"
43
#include "sigschemeinternal.h"
44
#define HEAP_SIZE SCM_DEFAULT_HEAP_SIZE
47
void saturate_heap(size_t heap_size);
48
ScmObj alloc (TST_PARAMS_DECL);
49
void verify (ScmObj obj, TST_PARAMS_DECL);
52
saturate_heap (size_t size)
54
/* We overallocate objects to force the GC to kick in. This is
55
* problematic if the new objects occupy cells that were
56
* inadvertently freed due to a bug in GC. To guard against that
57
* possibility, we allocate closures (which the caller doesn't use
58
* by convention) so that type predicates that the caller will do
59
* on its objects won't accidentally succeed. */
61
SCM_MAKE_CLOSURE(SCM_NULL, SCM_NULL);
66
alloc (TST_PARAMS_DECL)
68
return CONS(LIST_1(MAKE_INT(1)), scm_intern("aaa"));
71
#define TST(cond) TST_COND(cond, #cond)
73
verify (ScmObj obj, TST_PARAMS_DECL)
75
TST_ASSERT(TST(CONSP(obj)));
76
TST_ASSERT(TST(SYMBOLP(CDR(obj))));
78
TST_ASSERT(TST(CONSP(obj)));
79
TST_ASSERT(TST(NULLP(CDR(obj))));
80
TST_ASSERT(TST(INTP(CAR(obj))));
81
TST_ASSERT(TST_COND(EQVP(CAR(obj), MAKE_INT(1)),
82
"integer=? after GC"));
85
#define ALLOC() alloc(TST_PARAMS)
86
#define VERIFY(o) verify((o), TST_PARAMS)
90
/* We run it twice to see if the contents of the stack makes a */ \
92
saturate_heap (HEAP_SIZE); \
94
saturate_heap (HEAP_SIZE); \
98
TST_CASE(tst_1, "GC mark stack")
107
TST_CASE(tst_2, "GC mark protected var")
111
var = malloc (sizeof (*var));
112
scm_gc_protect (var);
117
scm_gc_unprotect (var);
121
volatile scm_intobj_t false_ptr;
123
TST_CASE(tst_3, "GC pointer predicate false positives")
129
false_ptr = (scm_intobj_t)obj;
130
for (i = 0; i < sizeof (ScmCell); i++) {