From a3d87214eaac5154105c65a2b0a8ea900ba2c470 Mon Sep 17 00:00:00 2001 From: Jan Nieuwenhuizen Date: Sun, 24 Feb 2019 09:39:00 +0100 Subject: [PATCH] mescc: Mes C Library: Start test suite. TODO: move strict libc tests from scaffold/test/* here. * lib/tests/stdlib/getenv.c: New file. * lib/tests/stdlib/malloc.c: Move from scaffold. * build-aux/bootstrap.sh.in: Built them. * build-aux/build-mes.sh: Likewise. --- .gitignore | 1 - build-aux/bootstrap.sh.in | 4 +-- build-aux/build-mes.sh | 10 ++++-- lib/tests/stdlib/getenv.c | 38 ++++++++++++++++++++ lib/tests/stdlib/malloc.c | 57 ++++++++++++++++++++++++++++++ scaffold/{ => lib/stdlib}/malloc.c | 0 6 files changed, 105 insertions(+), 5 deletions(-) create mode 100644 lib/tests/stdlib/getenv.c create mode 100644 lib/tests/stdlib/malloc.c rename scaffold/{ => lib/stdlib}/malloc.c (100%) diff --git a/.gitignore b/.gitignore index 55b00357..85704447 100644 --- a/.gitignore +++ b/.gitignore @@ -65,7 +65,6 @@ /scaffold/argv /scaffold/hello /scaffold/main -/scaffold/malloc /scaffold/micro-mes /scaffold/tiny-mes /scaffold/mini-mes diff --git a/build-aux/bootstrap.sh.in b/build-aux/bootstrap.sh.in index ca1ece6f..e87ec4c5 100644 --- a/build-aux/bootstrap.sh.in +++ b/build-aux/bootstrap.sh.in @@ -51,9 +51,9 @@ mv lib/libc+gnu.x86-mes-o lib/x86-mes/libc+gnu.o @GUILE@ -e main -L module scripts/mescc.scm -v -g -L lib/linux/x86-mes -L lib/linux -L lib/x86-mes -L lib -L @MES_SEED@ -o scaffold/x86-mes-argv scaffold/argv.x86-mes-o -l c-mini -@GUILE@ -e main -L module scripts/mescc.scm -c -D 'VERSION="@VERSION@"' -D 'MODULEDIR="@moduledir@"' -D 'PREFIX="@prefix@"' -I . -I lib -I include -v -g -L lib/linux/x86-mes -L lib/linux -L lib/x86-mes -L lib -L @MES_SEED@ -o scaffold/malloc.x86-mes-o scaffold/malloc.c +@GUILE@ -e main -L module scripts/mescc.scm -c -D 'VERSION="@VERSION@"' -D 'MODULEDIR="@moduledir@"' -D 'PREFIX="@prefix@"' -I . -I lib -I include -v -g -L lib/linux/x86-mes -L lib/linux -L lib/x86-mes -L lib -L @MES_SEED@ -o lib/tests/stdlib/malloc.x86-mes-o lib/tests/stdlib/malloc.c -@GUILE@ -e main -L module scripts/mescc.scm -v -g -L lib/linux/x86-mes -L lib/linux -L lib/x86-mes -L lib -L @MES_SEED@ -o scaffold/x86-mes-malloc scaffold/malloc.x86-mes-o -l c +@GUILE@ -e main -L module scripts/mescc.scm -c -D 'VERSION="@VERSION@"' -D 'MODULEDIR="@moduledir@"' -D 'PREFIX="@prefix@"' -I . -I lib -I include -v -g -L lib/linux/x86-mes -L lib/linux -L lib/x86-mes -L lib -L @MES_SEED@ -o lib/tests/stdlib/getenv.x86-mes-o lib/tests/stdlib/getenv.c @GUILE@ -e main -L module scripts/mescc.scm -c -D 'VERSION="@VERSION@"' -D 'MODULEDIR="@moduledir@"' -D 'PREFIX="@prefix@"' -I . -I lib -I include -v -g -L lib/linux/x86-mes -L lib/linux -L lib/x86-mes -L lib -L @MES_SEED@ -o scaffold/micro-mes.x86-mes-o scaffold/micro-mes.c diff --git a/build-aux/build-mes.sh b/build-aux/build-mes.sh index ff19ec12..c0b2857b 100755 --- a/build-aux/build-mes.sh +++ b/build-aux/build-mes.sh @@ -69,10 +69,16 @@ compile scaffold/hello compile scaffold/argv (libc="-l c-mini" link scaffold/argv) -[ "$mes_p" ] && compile scaffold/malloc -[ "$mes_p" ] && link scaffold/malloc +[ "$mes_p" ] && compile lib/tests/stdlib/malloc +[ "$mes_p" ] && link lib/tests/stdlib/malloc + +[ "$mes_p" ] && compile lib/tests/stdlib/getenv +[ "$mes_p" ] && link lib/tests/stdlib/getenv + + [ "$mes_p" ] && compile scaffold/micro-mes [ "$mes_p" ] && link scaffold/micro-mes + [ "$mes_p" ] && compile scaffold/tiny-mes [ "$mes_p" ] && link scaffold/tiny-mes #[ "$mes_p" ] && compile scaffold/mini-mes diff --git a/lib/tests/stdlib/getenv.c b/lib/tests/stdlib/getenv.c new file mode 100644 index 00000000..40130793 --- /dev/null +++ b/lib/tests/stdlib/getenv.c @@ -0,0 +1,38 @@ +/* -*-comment-start: "//";comment-end:""-*- + * GNU Mes --- Maxwell Equations of Software + * Copyright © 2018 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 "libmes.h" +#include "string.h" +#include "stdlib.h" +#define strlen xstrlen +#define strncmp xstrncmp +#define getenv xgetenv +#include "lib/string/strlen.c" +#include "lib/string/strncmp.c" +#include "lib/stdlib/getenv.c" + +int +main (int argc, char const *argv[]) +{ + eputs ("test:getenv\n"); + if (getenv ("SHELL") == 0) + return 1; + return 0; +} diff --git a/lib/tests/stdlib/malloc.c b/lib/tests/stdlib/malloc.c new file mode 100644 index 00000000..4d022d1e --- /dev/null +++ b/lib/tests/stdlib/malloc.c @@ -0,0 +1,57 @@ +/* -*-comment-start: "//";comment-end:""-*- + * GNU Mes --- Maxwell Equations of Software + * Copyright © 2016,2017 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 . + */ + +#if POSIX +#error "POSIX not supported" +#endif + +#include +#include +#include + +int +main (int argc, char *argv[]) +{ + int size = 5000; + oputs ("m!\n"); + //int *p = 0; + char *p = 0; + p = malloc (size); + size = 5000; + oputs ("p="); + oputs (itoa (p)); + oputs ("\n"); + int i; + for (i = 0; i < size; i=i+1) + { + oputs ("set "); + oputs (itoa (i)); + oputs ("\n"); + p[i] = i; + } + for (i = 0; i < size; i=i+1) + { + oputs (itoa (i)); + oputs (": "); + oputs (itoa (p[i])); + oputs ("\n"); + } + return 0; +} diff --git a/scaffold/malloc.c b/scaffold/lib/stdlib/malloc.c similarity index 100% rename from scaffold/malloc.c rename to scaffold/lib/stdlib/malloc.c