From: Pete Zaitcev <zaitcev@redhat.com>
To: Jeff Garzik <jeff@garzik.org>
Cc: Project Hail List <hail-devel@vger.kernel.org>
Subject: [tabled patch 1/1] Add a test for hstor_keys
Date: Mon, 27 Sep 2010 18:52:40 -0600 [thread overview]
Message-ID: <20100927185240.31f3265e@lembas.zaitcev.lan> (raw)
Our current tests do not invoke hstor_keys at all, and so they did not catch
a crash with double free in append_qparam.
Add a very basic test which at least calls hstor_keys to verify that it
does not crash right away. This test does not excercise complex modes
such as S3 paging, but better this than nothing.
Signed-off-by: Pete Zaitcev <zaitcev@redhat.com>
---
test/Makefile.am | 4 +
test/list-keys.c | 102 +++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 105 insertions(+), 1 deletion(-)
PASS: hdr-meta
tabled[6562]: client ::ffff:127.0.0.1 connected
chunkd[6560]: client host ::ffff:127.0.0.1 port 44394 connected
chunkd[6560]: client host ::ffff:127.0.0.1 port 44394 disconnected
*** glibc detected *** ./list-keys: double free or corruption (fasttop): 0x0000000000e93dc0 ***
/bin/sh: line 5: 6609 Segmentation fault (core dumped) top_srcdir=.. ${dir}$tst
FAIL: list-keys
diff --git a/test/Makefile.am b/test/Makefile.am
index 9264cba..cc4e6fe 100644
--- a/test/Makefile.am
+++ b/test/Makefile.am
@@ -26,11 +26,12 @@ TESTS = \
large-object \
hdr-content-type \
hdr-meta \
+ list-keys \
stop-daemon \
clean-db
check_PROGRAMS = basic-bucket basic-object it-works large-object \
- hdr-content-type hdr-meta wait-for-listen
+ hdr-content-type hdr-meta list-keys wait-for-listen
noinst_LIBRARIES = libtest.a
@@ -43,6 +44,7 @@ large_object_LDADD = $(TESTLDADD)
hdr_content_type_LDADD = $(TESTLDADD)
hdr_meta_LDADD = $(TESTLDADD)
it_works_LDADD = $(TESTLDADD)
+list_keys_LDADD = $(TESTLDADD)
wait_for_listen_LDADD = libtest.a
diff --git a/test/list-keys.c b/test/list-keys.c
new file mode 100644
index 0000000..8126e0a
--- /dev/null
+++ b/test/list-keys.c
@@ -0,0 +1,102 @@
+
+/*
+ * Copyright 2008-2010 Red Hat, Inc.
+ *
+ * This program 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.
+ *
+ * This program 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 this program; see the file COPYING. If not, write to
+ * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ */
+
+#define _GNU_SOURCE
+#include "tabled-config.h"
+
+#include <stdbool.h>
+#include <string.h>
+#include <stdlib.h>
+// #include <ctype.h>
+#include <locale.h>
+#include <glib.h>
+#include <hstor.h>
+#include "test.h"
+
+static char bucket[] = "test-hdr-meta";
+static char key[] = "test-key";
+static char value[] = "test-value";
+
+static void runtest(struct hstor_client *hstor)
+{
+ struct hstor_keylist *keylist;
+ struct hstor_object *obj;
+ GList *tmp;
+ int cnt;
+
+ keylist = hstor_keys(hstor, bucket, "", NULL, "/", 20);
+ OK(keylist);
+
+ cnt = 0;
+ tmp = keylist->contents;
+ while (tmp) {
+ obj = tmp->data;
+ if (strcmp(obj->key, key) != 0) {
+ fprintf(stderr, "bad object key %s\n", obj->key);
+ exit(1);
+ }
+ if (obj->size != sizeof(value)) {
+ fprintf(stderr, "bad object size %ld\n",
+ (long)obj->size);
+ exit(1);
+ }
+ cnt++;
+ tmp = tmp->next;
+ }
+ if (cnt != 1) {
+ fprintf(stderr, "bad object count %d\n", cnt);
+ exit(1);
+ }
+
+ hstor_free_keylist(keylist);
+}
+
+int main(int argc, char *argv[])
+{
+ struct hstor_client *hstor;
+ char accbuf[80];
+ int rc;
+ bool rcb;
+
+ setlocale(LC_ALL, "C");
+
+ rc = tb_readport(TEST_FILE_TB, accbuf, sizeof(accbuf));
+ OK(rc > 0);
+
+ hstor = hstor_new(accbuf, TEST_HOST, TEST_USER, TEST_USER_KEY);
+ OK(hstor);
+
+ /* add bucket - since tests are independent, we do not rely on others */
+ rcb = hstor_add_bucket(hstor, bucket);
+ OK(rcb);
+
+ rcb = hstor_put_inline(hstor, bucket, key, value, sizeof(value), NULL);
+ OK(rcb);
+
+ runtest(hstor);
+
+ rcb = hstor_del(hstor, bucket, key);
+ OK(rcb);
+
+ rcb = hstor_del_bucket(hstor, bucket);
+ OK(rcb);
+
+ return 0;
+}
+
next reply other threads:[~2010-09-28 0:52 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-09-28 0:52 Pete Zaitcev [this message]
2010-09-28 2:49 ` [tabled patch 1/1] Add a test for hstor_keys Jeff Garzik
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20100927185240.31f3265e@lembas.zaitcev.lan \
--to=zaitcev@redhat.com \
--cc=hail-devel@vger.kernel.org \
--cc=jeff@garzik.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).