test/gc: Add gc inspection test.

* src/test/gc.c (main): New unit test.
* simple.make (test-gcc, test-m2): New target to build it.
* build-aux/pointer.sh: Add it.
This commit is contained in:
Jan (janneke) Nieuwenhuizen 2020-08-16 08:56:56 +02:00
parent c247733bcd
commit 17805e9d3a
No known key found for this signature in database
GPG Key ID: F3C1A0D9C1D65273
4 changed files with 64 additions and 4 deletions

View File

@ -63,4 +63,5 @@ sed -ri \
src/struct.c \
src/symbol.c \
src/vector.c \
simple.make
src/test/gc.c \
simple.make \

View File

@ -52,7 +52,7 @@ CFLAGS:= \
-Wno-incompatible-pointer-types \
-Wno-int-conversion
MES_SOURCES = \
LIBMES_SOURCES = \
src/builtins.c \
src/core.c \
src/display.c \
@ -61,7 +61,6 @@ MES_SOURCES = \
src/hash.c \
src/lib.c \
src/math.c \
src/mes.c \
src/module.c \
src/posix.c \
src/reader.c \
@ -71,6 +70,14 @@ MES_SOURCES = \
src/symbol.c \
src/vector.c
MES_SOURCES = \
$(LIBMES_SOURCES) \
src/mes.c
TEST_GC_SOURCES = \
$(LIBMES_SOURCES) \
src/test/gc.c
M2_SOURCES = \
lib/linux/x86-mes-m2/crt1.c \
lib/linux/x86-mes-m2/_exit.c \
@ -168,9 +175,15 @@ GCC_SOURCES = \
mes-gcc: bin/mes-gcc
mes-m2: bin/mes-m2
gc-gcc: bin/gc-gcc
gc-m2: bin/gc-m2
bin/mes-gcc: simple.make $(GCC_SOURCES) $(MES_SOURCES) $(INCLUDES) | bin
$(CC) $(CFLAGS) $(GCC_SOURCES) $(MES_SOURCES) -o $@
bin/gc-gcc: simple.make $(GCC_SOURCES) $(TEST_GC_SOURCES) $(INCLUDES) | bin
$(CC) $(CFLAGS) -D GC_TEST=1 $(GCC_SOURCES) $(TEST_GC_SOURCES) -o $@
M2_PLANET_INCLUDES = \
include/m2/lib.h \
include/linux/x86/syscall.h \

View File

@ -294,7 +294,7 @@ gc_init_news ()
#else
g_news = g_cells + g_free;
NTYPE (cell_arena) = TVECTOR;
NLENGTH (cell_arena) = 1000;
NLENGTH (cell_arena) = LENGTH (cell_arena - 1);
NVECTOR (cell_arena) = 0;
g_news = g_news + 1;
NTYPE (cell_arena) = TCHAR;

46
src/test/gc.c Normal file
View File

@ -0,0 +1,46 @@
/* -*-comment-start: "//";comment-end:""-*-
* GNU Mes --- Maxwell Equations of Software
* Copyright © 2019 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
*
* This file is part of GNU Mes.
*
* GNU Mes is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or (at
* your option) any later version.
*
* GNU Mes is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with GNU Mes. If not, see <http://www.gnu.org/licenses/>.
*/
#include "mes/lib.h"
#include "mes/mes.h"
#include <stdlib.h>
int g_debug;
int
main (int argc, char **argv, char **envp)
{
char *p;
if (p = getenv ("MES_DEBUG"))
g_debug = atoi (p);
gc_init ();
SCM v = -1;
LENGTH (v) = 10;
eputs ("arena: "); write_ (v); eputs ("\n");
gc_stats_ ("0");
gc_ ();
v = -1;
eputs ("arena: "); write_ (v); eputs ("\n");
gc_stats_ ("1");
return 0;
}