summaryrefslogtreecommitdiffabout
path: root/tests
authorSergey Poznyakoff <gray@gnu.org.ua>2016-07-15 16:36:39 (GMT)
committer Sergey Poznyakoff <gray@gnu.org.ua>2016-07-15 16:36:39 (GMT)
commit493772dc60886a315c749bf31fc1cbe682df5973 (patch) (side-by-side diff)
tree9743f55e082e3306cf7ea3add00c152323afd065 /tests
parent44ca2b760b393e993b2a42fc489fa170910ad810 (diff)
downloadgdbm-493772dc60886a315c749bf31fc1cbe682df5973.tar.gz
gdbm-493772dc60886a315c749bf31fc1cbe682df5973.tar.bz2
New gdbm_setopt option to get the actual block size value
* src/gdbm.h.in (GDBM_GETBLOCKSIZE): New option. * src/gdbmcount.c (gdbm_count): Fix memory leak on error. * src/gdbmsetopt.c (gdbm_setopt): Rewrite. Handle GDBM_GETBLOCKSIZE. * NEWS: Document GDBM_GETBLOCKSIZE * doc/gdbm.texi: Likewise. * tests/gtload.c: New options -bsexact and -verbose. * tests/Makefile.am: Add new testcases. * tests/testsuite.at: Likewise. * tests/blocksize00.at: New testcase. * tests/blocksize01.at: Likewise. * tests/blocksize02.at: Likewise.
Diffstat (limited to 'tests') (more/less context) (ignore whitespace changes)
-rw-r--r--tests/Makefile.am3
-rw-r--r--tests/blocksize00.at36
-rw-r--r--tests/blocksize01.at32
-rw-r--r--tests/blocksize02.at28
-rw-r--r--tests/gtload.c23
-rw-r--r--tests/testsuite.at5
6 files changed, 124 insertions, 3 deletions
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 42335e8..f706213 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -48,6 +48,9 @@ $(srcdir)/package.m4: $(top_srcdir)/configure.ac $(srcdir)/Makefile.am
TESTSUITE_AT = \
testsuite.at\
+ blocksize00.at\
+ blocksize01.at\
+ blocksize02.at\
cloexec00.at\
cloexec01.at\
cloexec02.at\
diff --git a/tests/blocksize00.at b/tests/blocksize00.at
new file mode 100644
index 0000000..a8ceab4
--- a/dev/null
+++ b/tests/blocksize00.at
@@ -0,0 +1,36 @@
+# This file is part of GDBM test suite.
+# Copyright (C) 2016 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([block size adjustment])
+AT_KEYWORDS([gdbm create blocksize blocksize00])
+
+AT_CHECK([
+AT_SORT_PREREQ
+num2word 1:1000 > input
+gtload -blocksize=518 -clear -verbose test.db < input
+gtdump test.db | sort -k1n,2n > output
+cmp -s input output || diff -u input output
+
+gtload -blocksize=1025 -clear -verbose test.db < input
+gtdump test.db | sort -k1n,2n > output
+cmp -s input output || diff -u input output
+],
+[0],
+[blocksize=1024
+blocksize=2048
+])
+
+AT_CLEANUP
diff --git a/tests/blocksize01.at b/tests/blocksize01.at
new file mode 100644
index 0000000..444ae8c
--- a/dev/null
+++ b/tests/blocksize01.at
@@ -0,0 +1,32 @@
+# This file is part of GDBM test suite.
+# Copyright (C) 2016 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([exact blocksize])
+AT_KEYWORDS([gdbm create blocksize blocksize01])
+
+AT_CHECK([
+AT_SORT_PREREQ
+num2word 1:1000 > input
+gtload -blocksize=1024 -bsexact -clear -verbose test.db < input
+gtdump test.db | sort -k1n,2n > output
+cmp -s input output || diff -u input output
+],
+[0],
+[blocksize=1024
+])
+
+AT_CLEANUP
+
diff --git a/tests/blocksize02.at b/tests/blocksize02.at
new file mode 100644
index 0000000..7e0d7af
--- a/dev/null
+++ b/tests/blocksize02.at
@@ -0,0 +1,28 @@
+# This file is part of GDBM test suite.
+# Copyright (C) 2016 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([incorrect blocksize])
+AT_KEYWORDS([gdbm create blocksize blocksize02])
+
+AT_CHECK([
+gtload -blocksize=1025 -bsexact -clear -verbose test.db < /dev/null
+],
+[1],
+[],
+[gdbm_open failed: Block size error
+])
+
+AT_CLEANUP
diff --git a/tests/gtload.c b/tests/gtload.c
index 2920463..60e8504 100644
--- a/tests/gtload.c
+++ b/tests/gtload.c
@@ -1,5 +1,5 @@
/* This file is part of GDBM test suite.
- Copyright (C) 2011 Free Software Foundation, Inc.
+ Copyright (C) 2011, 2016 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
@@ -39,6 +39,8 @@ main (int argc, char **argv)
int delim = '\t';
int data_z = 0;
size_t mapped_size_max = 0;
+ int blksize;
+ int verbose = 0;
while (--argc)
{
@@ -46,7 +48,7 @@ main (int argc, char **argv)
if (strcmp (arg, "-h") == 0)
{
- printf ("usage: %s [-replace] [-clear] [-blocksize=N] [-null] [-nolock] [-nommap] [-maxmap=N] [-sync] [-delim=CHR] DBFILE\n", progname);
+ printf ("usage: %s [-replace] [-clear] [-blocksize=N] [-bsexact] [-verbose] [-null] [-nolock] [-nommap] [-maxmap=N] [-sync] [-delim=CHR] DBFILE\n", progname);
exit (0);
}
else if (strcmp (arg, "-replace") == 0)
@@ -61,6 +63,10 @@ main (int argc, char **argv)
flags |= GDBM_NOMMAP;
else if (strcmp (arg, "-sync") == 0)
flags |= GDBM_SYNC;
+ else if (strcmp (arg, "-bsexact") == 0)
+ flags |= GDBM_BSEXACT;
+ else if (strcmp (arg, "-verbose") == 0)
+ verbose = 1;
else if (strncmp (arg, "-blocksize=", 11) == 0)
block_size = atoi (arg + 11);
else if (strncmp (arg, "-maxmap=", 8) == 0)
@@ -119,11 +125,22 @@ main (int argc, char **argv)
if (gdbm_setopt (dbf, GDBM_SETMAXMAPSIZE, &mapped_size_max,
sizeof (mapped_size_max)))
{
- fprintf (stderr, "gdbm_setopt failed: %s\n",
+ fprintf (stderr, "GDBM_SETMAXMAPSIZE failed: %s\n",
gdbm_strerror (gdbm_errno));
exit (1);
}
}
+
+ if (verbose)
+ {
+ if (gdbm_setopt (dbf, GDBM_GETBLOCKSIZE, &blksize, sizeof blksize))
+ {
+ fprintf (stderr, "GDBM_GETBLOCKSIZE failed: %s\n",
+ gdbm_strerror (gdbm_errno));
+ exit (1);
+ }
+ printf ("blocksize=%d\n", blksize);
+ }
while (fgets (buf, sizeof buf, stdin))
{
diff --git a/tests/testsuite.at b/tests/testsuite.at
index 1e7373c..822d172 100644
--- a/tests/testsuite.at
+++ b/tests/testsuite.at
@@ -43,6 +43,11 @@ m4_include([delete00.at])
m4_include([delete01.at])
m4_include([delete02.at])
+AT_BANNER([Block size selection])
+m4_include([blocksize00.at])
+m4_include([blocksize01.at])
+m4_include([blocksize02.at])
+
AT_BANNER([Compatibility library (dbm/ndbm)])
m4_include([dbmcreate00.at])

Return to:

Send suggestions and report system problems to the System administrator.