diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/.cvsignore | 4 | ||||
-rw-r--r-- | tests/Makefile.am | 13 | ||||
-rw-r--r-- | tests/cloexec00.at | 25 | ||||
-rw-r--r-- | tests/cloexec01.at | 25 | ||||
-rw-r--r-- | tests/cloexec02.at | 27 | ||||
-rw-r--r-- | tests/cloexec03.at | 26 | ||||
-rw-r--r-- | tests/d_creat_ce.c | 90 | ||||
-rw-r--r-- | tests/fdop.c | 36 | ||||
-rw-r--r-- | tests/g_open_ce.c | 66 | ||||
-rw-r--r-- | tests/g_reorg_ce.c | 72 | ||||
-rw-r--r-- | tests/testsuite.at | 7 |
11 files changed, 390 insertions, 1 deletions
diff --git a/tests/.cvsignore b/tests/.cvsignore index 3275961..0883563 100644 --- a/tests/.cvsignore +++ b/tests/.cvsignore @@ -5,10 +5,14 @@ Makefile Makefile.in atconfig atlocal +d_creat_ce dtdel dtdump dtfetch dtload +fdop +g_open_ce +g_reorg_ce gtdel gtdump gtfetch diff --git a/tests/Makefile.am b/tests/Makefile.am index bfbcd9e..95d7fff 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -48,6 +48,10 @@ $(srcdir)/package.m4: $(top_srcdir)/configure.ac $(srcdir)/Makefile.am TESTSUITE_AT = \ testsuite.at\ + cloexec00.at\ + cloexec01.at\ + cloexec02.at\ + cloexec03.at\ dbmcreate00.at\ dbmdel00.at\ dbmdel01.at\ @@ -94,10 +98,13 @@ check-local: atconfig atlocal $(TESTSUITE) if COMPAT_OPT DBMINCLUDES = -I$(top_srcdir)/compat - DBMPROGS = dtload dtdump dtfetch dtdel + DBMPROGS = dtload dtdump dtfetch dtdel d_creat_ce endif check_PROGRAMS = \ + fdop\ + g_open_ce\ + g_reorg_ce\ gtdel\ gtdump\ gtfetch\ @@ -116,9 +123,13 @@ gtfetch_LDADD = ../src/libgdbm.la gtver_LDADD = ../src/libgdbm.la gtopt_LDADD = ../src/libgdbm.la +g_open_ce_LDADD = ../src/libgdbm.la +g_reorg_ce_LDADD = ../src/libgdbm.la + dtload_LDADD = ../src/libgdbm.la ../compat/libgdbm_compat.la dtdump_LDADD = ../src/libgdbm.la ../compat/libgdbm_compat.la dtfetch_LDADD = ../src/libgdbm.la ../compat/libgdbm_compat.la dtdel_LDADD = ../src/libgdbm.la ../compat/libgdbm_compat.la +d_creat_ce_LDADD = ../src/libgdbm.la ../compat/libgdbm_compat.la diff --git a/tests/cloexec00.at b/tests/cloexec00.at new file mode 100644 index 0000000..022b12f --- /dev/null +++ b/tests/cloexec00.at @@ -0,0 +1,25 @@ +# This file is part of GDBM. -*- autoconf -*- +# Copyright (C) 2011 Free Software Foundation, Inc. +# +# GDBM 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 2, or (at your option) +# any later version. +# +# GDBM 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 GDBM. If not, see <http://www.gnu.org/licenses/>. */ + +AT_SETUP([cloexec: gdbm_open]) +AT_KEYWORDS([gdbm gdbm_open cloexec cloexec00]) + +AT_CHECK([ +g_open_ce "$abs_builddir/fdop" +], +0) + +AT_CLEANUP diff --git a/tests/cloexec01.at b/tests/cloexec01.at new file mode 100644 index 0000000..21baac6 --- /dev/null +++ b/tests/cloexec01.at @@ -0,0 +1,25 @@ +# This file is part of GDBM. -*- autoconf -*- +# Copyright (C) 2011 Free Software Foundation, Inc. +# +# GDBM 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 2, or (at your option) +# any later version. +# +# GDBM 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 GDBM. If not, see <http://www.gnu.org/licenses/>. */ + +AT_SETUP([cloexec: gdbm_reorganize]) +AT_KEYWORDS([gdbm gdbm_reorganize cloexec cloexec01]) + +AT_CHECK([ +g_reorg_ce "$abs_builddir/fdop" +], +0) + +AT_CLEANUP diff --git a/tests/cloexec02.at b/tests/cloexec02.at new file mode 100644 index 0000000..9d1b7e3 --- /dev/null +++ b/tests/cloexec02.at @@ -0,0 +1,27 @@ +# This file is part of GDBM. -*- autoconf -*- +# Copyright (C) 2011 Free Software Foundation, Inc. +# +# GDBM 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 2, or (at your option) +# any later version. +# +# GDBM 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 GDBM. If not, see <http://www.gnu.org/licenses/>. */ + +AT_SETUP([cloexec: dbm_open]) +AT_KEYWORDS([ndbm dbm_open cloexec cloexec02]) + +AT_CHECK([ +AT_COMPAT_PREREQ +num2word 1:10 | dtload file +d_creat_ce "$abs_builddir/fdop" +], +0) + +AT_CLEANUP diff --git a/tests/cloexec03.at b/tests/cloexec03.at new file mode 100644 index 0000000..5fa1c0f --- /dev/null +++ b/tests/cloexec03.at @@ -0,0 +1,26 @@ +# This file is part of GDBM. -*- autoconf -*- +# Copyright (C) 2011 Free Software Foundation, Inc. +# +# GDBM 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 2, or (at your option) +# any later version. +# +# GDBM 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 GDBM. If not, see <http://www.gnu.org/licenses/>. */ + +AT_SETUP([cloexec: dbm_open -creat]) +AT_KEYWORDS([ndbm dbm_open cloexec cloexec03]) + +AT_CHECK([ +AT_COMPAT_PREREQ +d_creat_ce "$abs_builddir/fdop" -creat +], +0) + +AT_CLEANUP diff --git a/tests/d_creat_ce.c b/tests/d_creat_ce.c new file mode 100644 index 0000000..6a6cff2 --- /dev/null +++ b/tests/d_creat_ce.c @@ -0,0 +1,90 @@ +/* This file is part of GDBM test suite. + Copyright (C) 2011 Free Software Foundation, Inc. + + GDBM 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 2, or (at your option) + any later version. + + GDBM 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 GDBM. If not, see <http://www.gnu.org/licenses/>. +*/ +#include "autoconf.h" +#include <stdlib.h> +#include <stdio.h> +#include <string.h> +#include <unistd.h> +#include <sys/stat.h> +#include <fcntl.h> +#include <ndbm.h> + +char * +ntos (int n, char *buf, size_t size) +{ + char *p = buf + size; + *--p = 0; + do + { + int x = n % 10; + *--p = '0' + x; + n /= 10; + } + while (n); + return p; +} + +#ifndef O_CLOEXEC +# define O_CLOEXEC 0 +#endif + +int +main (int argc, char *argv[]) +{ + DBM *d; + char fdbuf[2][80]; + int i; + int flags = O_RDONLY; + + if (argc < 2) + { + fprintf (stderr, "usage: %s PATH-TO-FDOP [-creat] [-write]\n", argv[0]); + return 2; + } + + for (i = 2; i < argc; i++) + { + if (strcmp (argv[i], "-creat") == 0) + flags = O_RDWR|O_CREAT; + else if (strcmp (argv[i], "-write") == 0) + flags = O_RDWR; + else + { + fprintf (stderr, "%s: unknown option: %s\n", + argv[0], argv[i]); + return 2; + } + + } + + if (!O_CLOEXEC) + return 77; + + d = dbm_open ("file", flags|O_CLOEXEC, 0600); + if (!d) + { + perror ("dbm_open"); + return 3; + } + + execl (argv[1], "fdop", + ntos (dbm_pagfno (d), fdbuf[0], sizeof (fdbuf[0])), + ntos (dbm_dirfno (d), fdbuf[1], sizeof (fdbuf[1])), + NULL); + return 127; +} + diff --git a/tests/fdop.c b/tests/fdop.c new file mode 100644 index 0000000..1729323 --- /dev/null +++ b/tests/fdop.c @@ -0,0 +1,36 @@ +/* This file is part of GDBM test suite. + Copyright (C) 2011 Free Software Foundation, Inc. + + GDBM 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 2, or (at your option) + any later version. + + GDBM 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 GDBM. If not, see <http://www.gnu.org/licenses/>. +*/ +#include "autoconf.h" +#include <stdlib.h> +#include <unistd.h> + +/* usage: fdop FD [FD...] + Return: false if any of the FDs is open, true otherwise. +*/ +int +main (int argc, char **argv) +{ + int fd = dup (0); + + while (--argc) + { + int n = atoi (*++argv); + if (n < fd) + return 1; + } + return 0; +} diff --git a/tests/g_open_ce.c b/tests/g_open_ce.c new file mode 100644 index 0000000..4f1fcd4 --- /dev/null +++ b/tests/g_open_ce.c @@ -0,0 +1,66 @@ +/* This file is part of GDBM test suite. + Copyright (C) 2011 Free Software Foundation, Inc. + + GDBM 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 2, or (at your option) + any later version. + + GDBM 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 GDBM. If not, see <http://www.gnu.org/licenses/>. +*/ +#include "autoconf.h" +#include <stdlib.h> +#include <stdio.h> +#include <unistd.h> +#include <fcntl.h> +#include <gdbm.h> + +char * +ntos (int n, char *buf, size_t size) +{ + char *p = buf + size; + *--p = 0; + do + { + int x = n % 10; + *--p = '0' + x; + n /= 10; + } + while (n); + return p; +} + +#ifndef O_CLOEXEC +# define O_CLOEXEC 0 +#endif + +int +main (int argc, char *argv[]) +{ + GDBM_FILE d; + char fdbuf[80]; + + if (argc != 2) + { + fprintf (stderr, "usage: %s PATH-TO-FDOP\n", argv[0]); + return 2; + } + if (!O_CLOEXEC) + return 77; + d = gdbm_open ("file.db", 0, GDBM_NEWDB|GDBM_CLOEXEC, 0600, NULL); + if (!d) + { + fprintf (stderr, "gdbm_open: %s\n", gdbm_strerror (gdbm_errno)); + return 3; + } + execl (argv[1], "fdop", + ntos (gdbm_fdesc (d), fdbuf, sizeof (fdbuf)), NULL); + return 127; +} + diff --git a/tests/g_reorg_ce.c b/tests/g_reorg_ce.c new file mode 100644 index 0000000..f72afa2 --- /dev/null +++ b/tests/g_reorg_ce.c @@ -0,0 +1,72 @@ +/* This file is part of GDBM test suite. + Copyright (C) 2011 Free Software Foundation, Inc. + + GDBM 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 2, or (at your option) + any later version. + + GDBM 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 GDBM. If not, see <http://www.gnu.org/licenses/>. +*/ +#include "autoconf.h" +#include <stdlib.h> +#include <stdio.h> +#include <unistd.h> +#include <fcntl.h> +#include <gdbm.h> + +char * +ntos (int n, char *buf, size_t size) +{ + char *p = buf + size; + *--p = 0; + do + { + int x = n % 10; + *--p = '0' + x; + n /= 10; + } + while (n); + return p; +} + +#ifndef O_CLOEXEC +# define O_CLOEXEC 0 +#endif + +int +main (int argc, char *argv[]) +{ + GDBM_FILE d; + char fdbuf[80]; + + if (argc != 2) + { + fprintf (stderr, "usage: %s PATH-TO-FDOP\n", argv[0]); + return 2; + } + if (!O_CLOEXEC) + return 77; + d = gdbm_open ("file.db", 0, GDBM_NEWDB|GDBM_CLOEXEC, 0600, NULL); + if (!d) + { + fprintf (stderr, "gdbm_open: %s\n", gdbm_strerror (gdbm_errno)); + return 3; + } + if (gdbm_reorganize (d)) + { + fprintf (stderr, "gdbm_reorganize: %s\n", + gdbm_strerror (gdbm_errno)); + return 3; + } + execl (argv[1], "fdop", + ntos (gdbm_fdesc (d), fdbuf, sizeof (fdbuf)), NULL); + return 127; +} + diff --git a/tests/testsuite.at b/tests/testsuite.at index a13b3fb..1e7373c 100644 --- a/tests/testsuite.at +++ b/tests/testsuite.at @@ -63,4 +63,11 @@ AT_BANNER([DB options]) m4_include([setopt00.at]) m4_include([setopt01.at]) +AT_BANNER([Cloexec]) + +m4_include([cloexec00.at]) +m4_include([cloexec01.at]) +m4_include([cloexec02.at]) +m4_include([cloexec03.at]) + # End of testsuite.at |