summaryrefslogtreecommitdiff
path: root/src/plugins/kdb/db2/libdb2/test/hash2.tests
diff options
context:
space:
mode:
authorCy Schubert <cy@FreeBSD.org>2017-07-07 17:03:42 +0000
committerCy Schubert <cy@FreeBSD.org>2017-07-07 17:03:42 +0000
commit33a9b234e7087f573ef08cd7318c6497ba08b439 (patch)
treed0ea40ad3bf5463a3c55795977c71bcb7d781b4b /src/plugins/kdb/db2/libdb2/test/hash2.tests
Notes
Diffstat (limited to 'src/plugins/kdb/db2/libdb2/test/hash2.tests')
-rw-r--r--src/plugins/kdb/db2/libdb2/test/hash2.tests/README72
-rw-r--r--src/plugins/kdb/db2/libdb2/test/hash2.tests/bigtest.c75
-rw-r--r--src/plugins/kdb/db2/libdb2/test/hash2.tests/passtest.c184
-rw-r--r--src/plugins/kdb/db2/libdb2/test/hash2.tests/passwd/genpass.c22
4 files changed, 353 insertions, 0 deletions
diff --git a/src/plugins/kdb/db2/libdb2/test/hash2.tests/README b/src/plugins/kdb/db2/libdb2/test/hash2.tests/README
new file mode 100644
index 000000000000..f29ccf7e1ba6
--- /dev/null
+++ b/src/plugins/kdb/db2/libdb2/test/hash2.tests/README
@@ -0,0 +1,72 @@
+# @(#)README 8.1 (Berkeley) 6/4/93
+
+This package implements a superset of the hsearch and dbm/ndbm libraries.
+
+Test Programs:
+ All test programs which need key/data pairs expect them entered
+ with key and data on separate lines
+
+ tcreat3.c
+ Takes
+ bucketsize (bsize),
+ fill factor (ffactor), and
+ initial number of elements (nelem).
+ Creates a hash table named hashtest containing the
+ keys/data pairs entered from standard in.
+ thash4.c
+ Takes
+ bucketsize (bsize),
+ fill factor (ffactor),
+ initial number of elements (nelem)
+ bytes of cache (ncached), and
+ file from which to read data (fname)
+ Creates a table from the key/data pairs on standard in and
+ then does a read of each key/data in fname
+ tdel.c
+ Takes
+ bucketsize (bsize), and
+ fill factor (ffactor).
+ file from which to read data (fname)
+ Reads each key/data pair from fname and deletes the
+ key from the hash table hashtest
+ tseq.c
+ Reads the key/data pairs in the file hashtest and writes them
+ to standard out.
+ tread2.c
+ Takes
+ butes of cache (ncached).
+ Reads key/data pairs from standard in and looks them up
+ in the file hashtest.
+ tverify.c
+ Reads key/data pairs from standard in, looks them up
+ in the file hashtest, and verifies that the data is
+ correct.
+
+NOTES:
+
+The file search.h is provided for using the hsearch compatible interface
+on BSD systems. On System V derived systems, search.h should appear in
+/usr/include.
+
+The man page ../man/db.3 explains the interface to the hashing system.
+The file hash.ps is a postscript copy of a paper explaining
+the history, implementation, and performance of the hash package.
+
+"bugs" or idiosyncracies
+
+If you have a lot of overflows, it is possible to run out of overflow
+pages. Currently, this will cause a message to be printed on stderr.
+Eventually, this will be indicated by a return error code.
+
+If you are using the ndbm interface and exit without flushing or closing the
+file, you may lose updates since the package buffers all writes. Also,
+the db interface only creates a single database file. To avoid overwriting
+the user's original file, the suffix ".db" is appended to the file name
+passed to dbm_open. Additionally, if your code "knows" about the historic
+.dir and .pag files, it will break.
+
+There is a fundamental difference between this package and the old hsearch.
+Hsearch requires the user to maintain the keys and data in the application's
+allocated memory while hash takes care of all storage management. The down
+side is that the byte strings passed in the ENTRY structure must be null
+terminated (both the keys and the data).
diff --git a/src/plugins/kdb/db2/libdb2/test/hash2.tests/bigtest.c b/src/plugins/kdb/db2/libdb2/test/hash2.tests/bigtest.c
new file mode 100644
index 000000000000..c8070c5038af
--- /dev/null
+++ b/src/plugins/kdb/db2/libdb2/test/hash2.tests/bigtest.c
@@ -0,0 +1,75 @@
+#include "db-int.h"
+#include <stdio.h>
+#include <fcntl.h>
+#include <assert.h>
+#include <stdlib.h>
+
+int
+main(void)
+{
+ HASHINFO info;
+ DB *db;
+ DBT key, value, returned;
+ int *data;
+ int n, i;
+
+ info.bsize = 512;
+ info.cachesize = 500;
+ info.lorder = 0;
+ info.ffactor = 4;
+ info.nelem = 0;
+ info.hash = NULL;
+
+ db = dbopen("big2.db", O_RDWR|O_CREAT|O_TRUNC|O_BINARY, 0664, DB_HASH, &info);
+ data = malloc(800 * sizeof(int));
+ for (n = 0; n < 800; n++)
+ data[n] = 0xDEADBEEF;
+ key.size = sizeof(int);
+ key.data = &n;
+ value.size = 800 * sizeof(int);
+ value.data = (void *)data;
+
+ for (n = 0; n < 200000; n++) {
+ returned.data = NULL;
+ if (n == 4627)
+ printf("");
+ if (n % 50 == 0)
+ printf("put n = %d\n", n);
+ if (db->put(db, &key, &value, 0) != 0)
+ printf("put error, n = %d\n", n);
+ if (db->get(db, &key, &returned, 0) != 0)
+ printf("Immediate get error, n = %d\n", n);
+ assert (returned.size == 3200);
+ for (i = 0; i < 800; i++)
+ if (((int *)returned.data)[i] != 0xDEADBEEF)
+ printf("ERRORRRRRR!!!\n");
+
+ }
+
+ for (n = 0; n < 200000; n++) {
+ if (n % 50 == 0)
+ printf("seq n = %d\n", n);
+ if ((db->seq(db, &key, &returned, 0)) != 0)
+ printf("Seq error, n = %d\n", n);
+
+ assert(returned.size == 3200);
+
+ for (i = 0; i < 800; i++)
+ if (((int *)returned.data)[i] != 0xDEADBEEF)
+ printf("ERRORRRRRR!!! seq %d\n", n);
+ }
+
+ for (n = 0; n < 2000; n++) {
+ if (n % 50 == 0)
+ printf("get n = %d\n", n);
+ if (db->get(db, &key, &returned, 0) != 0)
+ printf("Late get error, n = %d\n", n);
+ assert(returned.size == 1200);
+ for (i = 0; i < 300; i++)
+ if (((int *)returned.data)[i] != 0xDEADBEEF)
+ printf("ERRORRRRRR!!!, get %d\n", n);
+ }
+ db->close(db);
+ free(value.data);
+ return(0);
+}
diff --git a/src/plugins/kdb/db2/libdb2/test/hash2.tests/passtest.c b/src/plugins/kdb/db2/libdb2/test/hash2.tests/passtest.c
new file mode 100644
index 000000000000..43895a42933e
--- /dev/null
+++ b/src/plugins/kdb/db2/libdb2/test/hash2.tests/passtest.c
@@ -0,0 +1,184 @@
+#include "db-int.h"
+#include <fcntl.h>
+#include <stdio.h>
+#include <string.h>
+
+extern int hash_expansions;
+
+int
+main(void)
+{
+ FILE *keys, *vals;
+ DB *db;
+ DBT key, val;
+ char *key_line, *val_line, *get_key, *get_val, *old, *key2;
+ HASHINFO passwd;
+ int n = 0, i = 0, expected;
+
+ key_line = (char *)malloc(100);
+ val_line = (char *)malloc(300);
+ old = (char *)malloc(300);
+
+ keys = fopen("yp.keys", "rt");
+ vals = fopen("yp.total", "rt");
+
+ passwd.bsize = 1024;
+ passwd.cachesize = 1024 * 1024;
+ passwd.ffactor = 10;
+ passwd.hash = NULL;
+ passwd.nelem = 0;
+ passwd.lorder = 4321;
+
+
+ db = dbopen("/usr/tmp/passwd.db", O_RDWR|O_CREAT|O_TRUNC|O_BINARY, 0664, DB_HASH,
+ &passwd);
+ if (!db) {
+ fprintf(stderr, "create_db: couldn't create database file\n");
+ exit(1);
+ }
+
+ while ((key_line = fgets(key_line, 100, keys)) != NULL) {
+ if (n % 1000 == 0)
+ fprintf(stderr, "Putting #%d.\n", n);
+ n++;
+ fgets(val_line, 300, vals);
+ key.size = strlen(key_line);
+ key.data = (void *)key_line;
+ val.size = strlen(val_line);
+ val.data = (void *)val_line;
+ if (db->put(db, &key, &val, 0) != 0)
+ fprintf(stderr, "Put error, n = %d\n", n);
+ if (db->get(db, &key, &val, 0) != 0)
+ fprintf(stderr, "Immediate get error, n = %d\n", n);
+ }
+ fprintf(stderr, "Done with put!\n");
+ free(key_line);
+ free(val_line);
+ fclose(keys);
+ fclose(vals);
+ db->close(db);
+
+
+
+
+ keys = fopen("yp.keys", "rt");
+ vals = fopen("yp.total", "rt");
+ get_key = (char *)malloc(100);
+ get_val = (char *)malloc(300);
+
+ db = dbopen("/usr/tmp/passwd.db", O_RDWR|O_BINARY, 0664, DB_HASH, &passwd);
+ if (!db)
+ fprintf(stderr, "Could not open db!\n");
+ n = 0;
+ while ((get_key = fgets(get_key, 100, keys)) != NULL) {
+ n++;
+ if (n % 1000 == 0)
+ fprintf(stderr, "Getting #%d.\n", n);
+ key.size = strlen(get_key);
+ key.data = (void *)get_key;
+ if (db->get(db, &key, &val, 0) != 0)
+ fprintf(stderr, "Retrieval error on %s\n", get_key);
+ fgets(get_val, 300, vals);
+ if (memcmp(val.data, (void *)get_val, val.size)) {
+ fprintf(stderr, "Unmatched get on %s.\n", get_key);
+ fprintf(stderr, "Input = %s\nOutput = %s\n", get_val,
+ (char *)val.data);
+ }
+ }
+ expected = n;
+ fclose(vals);
+ fclose(keys);
+ free(get_key);
+ free(get_val);
+ db->close(db);
+
+
+
+
+ get_key = (char *)malloc(100);
+ get_val = (char *)malloc(300);
+
+ db = dbopen("/usr/tmp/passwd.db", O_RDWR, 0664, DB_HASH, &passwd);
+ if (!db)
+ fprintf(stderr, "Could not open db!\n");
+ n = 0;
+ for (;;) {
+ n++;
+ if (n % 1000 == 0)
+ fprintf(stderr, "Sequence getting #%d.\n", n);
+ if (db->seq(db, &key, &val, 0) != 0) {
+ fprintf(stderr,
+ "Exiting sequence retrieve; n = %d, expected = %d\n",
+ n - 1 , expected);
+ break;
+ }
+ }
+ free(get_key);
+ free(get_val);
+ db->close(db);
+
+ get_key = (char *)malloc(100);
+ key2 = (char *)malloc(100);
+
+ keys = fopen("yp.keys", "rt");
+ vals = fopen("yp.total", "rt");
+
+ db = dbopen("/usr/tmp/passwd.db", O_RDWR|O_BINARY, 0664, DB_HASH, &passwd);
+ n = 0;
+ while ((get_key = fgets(get_key, 100, keys)) != NULL) {
+ if (n % 1000 == 0)
+ fprintf(stderr, "Deleting #%d.\n", n);
+ n+=2;
+ key2 = fgets(get_key, 100, keys);
+ if (!key2)
+ break;
+ key.data = (void *)key2;
+ key.size = strlen(key2);
+ if (db->del(db, &key, 0) != 0)
+ fprintf(stderr, "Delete error on %d", n);
+ }
+
+ db->close(db);
+ free(get_key);
+ free(key2);
+ fclose(keys);
+ fclose(vals);
+
+ get_key = (char *)malloc(100);
+ key2 = (char *)malloc(100);
+ get_val = (char *)malloc(300);
+
+ keys = fopen("yp.keys", "rt");
+ vals = fopen("yp.total", "rt");
+
+ db = dbopen("/usr/tmp/passwd.db", O_RDWR|O_BINARY, 0664, DB_HASH, &passwd);
+ n = 0;
+ while ((get_key = fgets(get_key, 100, keys)) != NULL) {
+ n += 2;
+ if (n % 1000 == 0)
+ fprintf(stderr, "Re-retrieving #%d.\n", n);
+ key2 = fgets(key2, 100, keys);
+ if (!key2)
+ break;
+ key.data = (void *)get_key;
+ key.size = strlen(get_key);
+ if (db->get(db, &key, &val, 0) != 0)
+ fprintf(stderr, "Retrieval after delete error on %d\n", n);
+ fgets(get_val, 300, vals);
+ if (memcmp(val.data, (void *)get_val, val.size)) {
+ fprintf(stderr, "Unmatched get after delete on %s.\n", get_key);
+ fprintf(stderr, "Input = %s\nOutput = %s\n", get_val,
+ (char *)val.data);
+ }
+ fgets(get_val, 300, vals);
+ }
+
+ db->close(db);
+ free(get_key);
+ free(key2);
+ free(get_val);
+ fclose(keys);
+ fclose(vals);
+
+ exit(0);
+}
diff --git a/src/plugins/kdb/db2/libdb2/test/hash2.tests/passwd/genpass.c b/src/plugins/kdb/db2/libdb2/test/hash2.tests/passwd/genpass.c
new file mode 100644
index 000000000000..7d03e609cb5d
--- /dev/null
+++ b/src/plugins/kdb/db2/libdb2/test/hash2.tests/passwd/genpass.c
@@ -0,0 +1,22 @@
+#include <stdio.h>
+#include <stdlib.h>
+
+void
+main(int argc, char **argv)
+{
+ int i,j,n;
+ char *pass[8], r;
+
+ n = atoi(argv[1]);
+
+ srandom(101173);
+ for (i = 0; i < n; i++) {
+ for (j = 0; j < 8; j++) {
+ r = random() % 122;
+ while (r < 48)
+ r += random() % (122 - r);
+ printf("%c", r);
+ }
+ printf("\n");
+ }
+}