From 17805e9d3a5a78fe4e1ff3283f7782c05efcdf34 Mon Sep 17 00:00:00 2001 From: "Jan (janneke) Nieuwenhuizen" Date: Sun, 16 Aug 2020 08:56:56 +0200 Subject: [PATCH] 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. --- build-aux/pointer.sh | 3 ++- simple.make | 17 ++++++++++++++-- src/gc.c | 2 +- src/test/gc.c | 46 ++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 64 insertions(+), 4 deletions(-) create mode 100644 src/test/gc.c diff --git a/build-aux/pointer.sh b/build-aux/pointer.sh index ab7683ce..38a19e89 100755 --- a/build-aux/pointer.sh +++ b/build-aux/pointer.sh @@ -63,4 +63,5 @@ sed -ri \ src/struct.c \ src/symbol.c \ src/vector.c \ - simple.make + src/test/gc.c \ + simple.make \ diff --git a/simple.make b/simple.make index 227eecc3..08c2a977 100644 --- a/simple.make +++ b/simple.make @@ -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 \ diff --git a/src/gc.c b/src/gc.c index 4d994aae..bb473efe 100644 --- a/src/gc.c +++ b/src/gc.c @@ -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; diff --git a/src/test/gc.c b/src/test/gc.c new file mode 100644 index 00000000..bac4c7b2 --- /dev/null +++ b/src/test/gc.c @@ -0,0 +1,46 @@ +/* -*-comment-start: "//";comment-end:""-*- + * GNU Mes --- Maxwell Equations of Software + * Copyright © 2019 Jan (janneke) Nieuwenhuizen + * + * 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 . + */ + +#include "mes/lib.h" +#include "mes/mes.h" + +#include + +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; +}