From c83584f85f627a8555cb06307c1c82e451e11c06 Mon Sep 17 00:00:00 2001 From: Jan Nieuwenhuizen Date: Wed, 26 Jun 2019 21:55:44 +0200 Subject: [PATCH] test: Add open-read test. * build-aux/test-c.sh: Support running by hand. * lib/tests/posix/50-open-read.c: New test. * lib/tests/posix/data/open-read: New file. * build-aux/check-mescc.sh (TESTS): Add it. --- build-aux/check-mescc.sh | 1 + build-aux/test-c.sh | 6 +++- lib/tests/posix/50-open-read.c | 54 ++++++++++++++++++++++++++++++++++ lib/tests/posix/data/open-read | 1 + 4 files changed, 61 insertions(+), 1 deletion(-) create mode 100644 lib/tests/posix/50-open-read.c create mode 100644 lib/tests/posix/data/open-read diff --git a/build-aux/check-mescc.sh b/build-aux/check-mescc.sh index 578346cd..0a18efd7 100755 --- a/build-aux/check-mescc.sh +++ b/build-aux/check-mescc.sh @@ -105,6 +105,7 @@ lib/tests/stdlib/50-malloc.c lib/tests/string/50-strcmp.c lib/tests/string/50-strcpy.c lib/tests/string/50-strncmp.c +lib/tests/posix/50-open-read.c lib/tests/scaffold/51-pointer-sub.c lib/tests/scaffold/54-argc.c lib/tests/scaffold/54-argv.c diff --git a/build-aux/test-c.sh b/build-aux/test-c.sh index 03a88665..0363df46 100755 --- a/build-aux/test-c.sh +++ b/build-aux/test-c.sh @@ -20,6 +20,10 @@ set -e +if test -z "$config_sh"; then + . ./config.sh +fi + if [ "$V" = 2 ]; then set -x fi @@ -29,7 +33,7 @@ b=$(dirname "$t")/$(basename "$t" .c) o="$b" o=lib/tests/${b#*lib/tests/} if [ "$o" = "$b" ]; then - o=$(basename "$t" .c) + o=./$(basename "$t" .c) fi rm -f "$o" diff --git a/lib/tests/posix/50-open-read.c b/lib/tests/posix/50-open-read.c new file mode 100644 index 00000000..2b955b09 --- /dev/null +++ b/lib/tests/posix/50-open-read.c @@ -0,0 +1,54 @@ +/* -*-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 +#include +#include +#include +#include +#include + +int +main (int argc, char const *argv[]) +{ + eputs ("test:getenv\n"); + char file_name[PATH_MAX]; + char *srcdir = getenv ("srcdir"); + if (!srcdir) + return 1; + strcpy (file_name, srcdir); + strcpy (file_name + strlen (srcdir), "/lib/tests/posix/data/open-read"); + eputs ("test open:"); + eputs (file_name); + eputs ("\n"); + int filedes = open (file_name, 0, 0); + if (filedes <= 2) + return 2; + char buf[20]; + int n = read (filedes, buf, sizeof (buf)); + if (n != 5) + return 3; + if (strcmp (buf, "hello")) + return 4; + eputs ("test read: "); + eputs (buf); + eputs ("\n"); + return 0; +} diff --git a/lib/tests/posix/data/open-read b/lib/tests/posix/data/open-read new file mode 100644 index 00000000..b6fc4c62 --- /dev/null +++ b/lib/tests/posix/data/open-read @@ -0,0 +1 @@ +hello \ No newline at end of file