From da0aae8584e524595e7c17cf3f2cce3090fbb035 Mon Sep 17 00:00:00 2001 From: Gabor X Toth <*@tg-x.net> Date: Thu, 6 Oct 2016 16:01:51 +0000 Subject: [PATCH] psycstore: mysql stmt fix, logging for tests --- src/my/my.c | 2 +- src/psycstore/plugin_psycstore_mysql.c | 15 +++---- src/psycstore/test_plugin_psycstore.c | 59 +++++++++++++++++++++++++- 3 files changed, 64 insertions(+), 12 deletions(-) diff --git a/src/my/my.c b/src/my/my.c index dd0e40251..5816663b6 100644 --- a/src/my/my.c +++ b/src/my/my.c @@ -104,7 +104,7 @@ GNUNET_MY_exec_prepared (struct GNUNET_MYSQL_Context *mc, /** * Free all memory that was allocated in @a qp during - * #GNUNET_MY_exect_prepared(). + * #GNUNET_MY_exec_prepared(). * * @param qp query specification to clean up * @param qbind array of parameter to clean up diff --git a/src/psycstore/plugin_psycstore_mysql.c b/src/psycstore/plugin_psycstore_mysql.c index 42c12119e..d857262d6 100644 --- a/src/psycstore/plugin_psycstore_mysql.c +++ b/src/psycstore/plugin_psycstore_mysql.c @@ -423,7 +423,7 @@ database_setup (struct Plugin *plugin) " multicast_flags, psycstore_flags, data\n" "FROM messages\n" "WHERE channel_id = (SELECT id FROM channels WHERE pub_key = ?)\n" - " AND ? <= message_id AND message_id <= ?" + " AND ? <= message_id AND message_id <= ?\n" "LIMIT ?;", &plugin->select_messages); @@ -1101,21 +1101,16 @@ fragment_row (struct GNUNET_MYSQL_StatementHandle *stmt, static int -fragment_select (struct Plugin *plugin, struct GNUNET_MYSQL_StatementHandle *stmt, +fragment_select (struct Plugin *plugin, + struct GNUNET_MYSQL_StatementHandle *stmt, struct GNUNET_MY_QueryParam *params, uint64_t *returned_fragments, - GNUNET_PSYCSTORE_FragmentCallback cb, void *cb_cls) + GNUNET_PSYCSTORE_FragmentCallback cb, + void *cb_cls) { int ret = GNUNET_SYSERR; int sql_ret; - // FIXME - if (NULL == plugin->mc || NULL == stmt || NULL == params) - { - fprintf(stderr, "%p %p %p\n", plugin->mc, stmt, params); - return GNUNET_SYSERR; - } - sql_ret = GNUNET_MY_exec_prepared (plugin->mc, stmt, params); switch (sql_ret) { diff --git a/src/psycstore/test_plugin_psycstore.c b/src/psycstore/test_plugin_psycstore.c index 53971bf23..c1a456e60 100644 --- a/src/psycstore/test_plugin_psycstore.c +++ b/src/psycstore/test_plugin_psycstore.c @@ -25,6 +25,9 @@ * @file * Test for the PSYCstore plugins. */ + +#include + #include "platform.h" #include "gnunet_util_lib.h" #include "gnunet_testing_lib.h" @@ -175,6 +178,8 @@ run (void *cls, char *const *args, const char *cfgfile, /* Store & test membership */ + LOG (GNUNET_ERROR_TYPE_INFO, "MEMBERSHIP\n"); + channel_key = GNUNET_CRYPTO_eddsa_key_create (); slave_key = GNUNET_CRYPTO_ecdsa_key_create (); @@ -182,10 +187,14 @@ run (void *cls, char *const *args, const char *cfgfile, &channel_pub_key); GNUNET_CRYPTO_ecdsa_key_get_public (slave_key, &slave_pub_key); + LOG (GNUNET_ERROR_TYPE_INFO, "membership_store()\n"); + GNUNET_assert (GNUNET_OK == db->membership_store (db->cls, &channel_pub_key, &slave_pub_key, GNUNET_YES, 4, 2, 1)); + LOG (GNUNET_ERROR_TYPE_INFO, "membership_test()\n"); + GNUNET_assert (GNUNET_YES == db->membership_test (db->cls, &channel_pub_key, &slave_pub_key, 4)); @@ -195,9 +204,10 @@ run (void *cls, char *const *args, const char *cfgfile, GNUNET_assert (GNUNET_NO == db->membership_test (db->cls, &channel_pub_key, &slave_pub_key, 1)); - /* Store & get messages */ + LOG (GNUNET_ERROR_TYPE_INFO, "MESSAGES\n"); + struct GNUNET_MULTICAST_MessageHeader *msg = GNUNET_malloc (sizeof (*msg) + sizeof (channel_pub_key)); GNUNET_assert (msg != NULL); @@ -228,6 +238,8 @@ run (void *cls, char *const *args, const char *cfgfile, GNUNET_assert (GNUNET_OK == GNUNET_CRYPTO_eddsa_sign (channel_key, &msg->purpose, &msg->signature)); + LOG (GNUNET_ERROR_TYPE_INFO, "fragment_store()\n"); + struct FragmentClosure fcls = { 0 }; fcls.n = 0; fcls.msg[0] = msg; @@ -237,6 +249,8 @@ run (void *cls, char *const *args, const char *cfgfile, GNUNET_OK == db->fragment_store (db->cls, &channel_pub_key, msg, fcls.flags[0])); + LOG (GNUNET_ERROR_TYPE_INFO, "fragment_get(%" PRIu64 ")\n", fragment_id); + uint64_t ret_frags = 0; GNUNET_assert ( GNUNET_OK == db->fragment_get (db->cls, &channel_pub_key, @@ -244,8 +258,19 @@ run (void *cls, char *const *args, const char *cfgfile, &ret_frags, fragment_cb, &fcls)); GNUNET_assert (fcls.n == 1); + LOG (GNUNET_ERROR_TYPE_INFO, "fragment_get(%" PRIu64 ")\n", fragment_id+1); + + ret_frags = 0; + GNUNET_assert ( + GNUNET_OK == db->fragment_get (db->cls, &channel_pub_key, + fragment_id+1, fragment_id+1, + &ret_frags, fragment_cb, &fcls)); + GNUNET_assert (fcls.n == 1); + // FIXME: test fragment_get_latest and message_get_latest + LOG (GNUNET_ERROR_TYPE_INFO, "message_get_fragment()\n"); + fcls.n = 0; GNUNET_assert ( @@ -255,11 +280,15 @@ run (void *cls, char *const *args, const char *cfgfile, fragment_cb, &fcls)); GNUNET_assert (fcls.n == 1); + LOG (GNUNET_ERROR_TYPE_INFO, "message_add_flags()\n"); + GNUNET_assert ( GNUNET_OK == db->message_add_flags (db->cls, &channel_pub_key, GNUNET_ntohll (msg->message_id), GNUNET_PSYCSTORE_MESSAGE_STATE_APPLIED)); + LOG (GNUNET_ERROR_TYPE_INFO, "fragment_get(%" PRIu64 ")\n", fragment_id); + fcls.n = 0; fcls.flags[0] |= GNUNET_PSYCSTORE_MESSAGE_STATE_APPLIED; @@ -270,6 +299,8 @@ run (void *cls, char *const *args, const char *cfgfile, GNUNET_assert (fcls.n == 1); + LOG (GNUNET_ERROR_TYPE_INFO, "fragment_store()\n"); + struct GNUNET_MULTICAST_MessageHeader *msg1 = GNUNET_malloc (sizeof (*msg1) + sizeof (channel_pub_key)); @@ -285,6 +316,8 @@ run (void *cls, char *const *args, const char *cfgfile, GNUNET_assert (GNUNET_OK == db->fragment_store (db->cls, &channel_pub_key, msg1, fcls.flags[1])); + LOG (GNUNET_ERROR_TYPE_INFO, "message_get()\n"); + GNUNET_assert ( GNUNET_OK == db->message_get (db->cls, &channel_pub_key, message_id, message_id, 0, @@ -293,6 +326,8 @@ run (void *cls, char *const *args, const char *cfgfile, /* Message counters */ + LOG (GNUNET_ERROR_TYPE_INFO, "counters_message_get()\n"); + fragment_id = 0; message_id = 0; group_generation = 0; @@ -306,6 +341,10 @@ run (void *cls, char *const *args, const char *cfgfile, /* Modify state */ + LOG (GNUNET_ERROR_TYPE_INFO, "STATE\n"); + + LOG (GNUNET_ERROR_TYPE_INFO, "state_modify_*()\n"); + message_id = GNUNET_ntohll (fcls.msg[0]->message_id) + 1; GNUNET_assert (GNUNET_OK == db->state_modify_begin (db->cls, &channel_pub_key, message_id, 0)); @@ -323,6 +362,8 @@ run (void *cls, char *const *args, const char *cfgfile, GNUNET_assert (GNUNET_OK == db->state_modify_end (db->cls, &channel_pub_key, message_id)); + LOG (GNUNET_ERROR_TYPE_INFO, "state_get()\n"); + struct StateClosure scls = { 0 }; scls.n = 0; scls.value[0] = "one two three"; @@ -332,6 +373,8 @@ run (void *cls, char *const *args, const char *cfgfile, state_cb, &scls)); GNUNET_assert (scls.n == 1); + LOG (GNUNET_ERROR_TYPE_INFO, "state_get_prefix()\n"); + scls.n = 0; scls.value[1] = slave_key; scls.value_size[1] = sizeof (*slave_key); @@ -340,14 +383,20 @@ run (void *cls, char *const *args, const char *cfgfile, "_foo", state_cb, &scls)); GNUNET_assert (scls.n == 2); + LOG (GNUNET_ERROR_TYPE_INFO, "state_get_signed()\n"); + scls.n = 0; GNUNET_assert (GNUNET_NO == db->state_get_signed (db->cls, &channel_pub_key, state_cb, &scls)); GNUNET_assert (scls.n == 0); + LOG (GNUNET_ERROR_TYPE_INFO, "state_update_signed()\n"); + GNUNET_assert (GNUNET_OK == db->state_update_signed (db->cls, &channel_pub_key)); + LOG (GNUNET_ERROR_TYPE_INFO, "state_get_signed()\n"); + scls.n = 0; GNUNET_assert (GNUNET_YES == db->state_get_signed (db->cls, &channel_pub_key, state_cb, &scls)); @@ -355,6 +404,8 @@ run (void *cls, char *const *args, const char *cfgfile, /* State counters */ + LOG (GNUNET_ERROR_TYPE_INFO, "counters_state_get()\n"); + uint64_t max_state_msg_id = 0; GNUNET_assert (GNUNET_OK == db->counters_state_get (db->cls, &channel_pub_key, &max_state_msg_id) @@ -362,6 +413,8 @@ run (void *cls, char *const *args, const char *cfgfile, /* State sync */ + LOG (GNUNET_ERROR_TYPE_INFO, "state_sync_*()\n"); + scls.n = 0; scls.value[0] = channel_key; scls.value_size[0] = sizeof (*channel_key); @@ -397,6 +450,8 @@ run (void *cls, char *const *args, const char *cfgfile, /* Modify state after sync */ + LOG (GNUNET_ERROR_TYPE_INFO, "state_modify_*()\n"); + message_id = GNUNET_ntohll (fcls.msg[0]->message_id) + 6; GNUNET_assert (GNUNET_OK == db->state_modify_begin (db->cls, &channel_pub_key, message_id, @@ -412,6 +467,8 @@ run (void *cls, char *const *args, const char *cfgfile, /* Reset state */ + LOG (GNUNET_ERROR_TYPE_INFO, "state_reset()\n"); + scls.n = 0; GNUNET_assert (GNUNET_OK == db->state_reset (db->cls, &channel_pub_key)); GNUNET_assert (scls.n == 0); -- 2.25.1