[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] r25653 - gnunet-update/src/tests
From: |
gnunet |
Subject: |
[GNUnet-SVN] r25653 - gnunet-update/src/tests |
Date: |
Wed, 26 Dec 2012 21:06:35 +0100 |
Author: harsha
Date: 2012-12-26 21:06:35 +0100 (Wed, 26 Dec 2012)
New Revision: 25653
Added:
gnunet-update/src/tests/compatibility.conf
Modified:
gnunet-update/src/tests/Makefile.am
gnunet-update/src/tests/compatibility.c
gnunet-update/src/tests/test_util.py
Log:
- added fs compatibility checks
Modified: gnunet-update/src/tests/Makefile.am
===================================================================
--- gnunet-update/src/tests/Makefile.am 2012-12-26 11:59:15 UTC (rev 25652)
+++ gnunet-update/src/tests/Makefile.am 2012-12-26 20:06:35 UTC (rev 25653)
@@ -9,7 +9,8 @@
compatibility_test_data_to_string \
compatibility_test_hash \
compatibility_test_hash_to_aes_key \
- compatibility_test_aes_enc
+ compatibility_test_aes_enc \
+ compatibility_test_chk_hash
rebuild_compatibility_checks: $(check_PROGRAMS)
@@ -104,19 +105,24 @@
compatibility_test_data_to_string_SOURCES = \
compatibility.c
compatibility_test_data_to_string_LDADD = \
- -lgnunetutil
+ -lgnunetutil -lgnunetfs
compatibility_test_hash_SOURCES = \
compatibility.c
compatibility_test_hash_LDADD = \
- -lgnunetutil
+ -lgnunetutil -lgnunetfs
compatibility_test_hash_to_aes_key_SOURCES = \
compatibility.c
compatibility_test_hash_to_aes_key_LDADD = \
- -lgnunetutil
+ -lgnunetutil -lgnunetfs
compatibility_test_aes_enc_SOURCES = \
compatibility.c
compatibility_test_aes_enc_LDADD = \
- -lgnunetutil
\ No newline at end of file
+ -lgnunetutil -lgnunetfs
+
+compatibility_test_chk_hash_SOURCES = \
+ compatibility.c
+compatibility_test_chk_hash_LDADD = \
+ -lgnunetutil -lgnunetfs
\ No newline at end of file
Modified: gnunet-update/src/tests/compatibility.c
===================================================================
--- gnunet-update/src/tests/compatibility.c 2012-12-26 11:59:15 UTC (rev
25652)
+++ gnunet-update/src/tests/compatibility.c 2012-12-26 20:06:35 UTC (rev
25653)
@@ -27,7 +27,11 @@
#include <gnunet/platform.h>
#include <gnunet/gnunet_util_lib.h>
+#include <gnunet/gnunet_fs_service.h>
+#define ABORT_TIMEOUT \
+ GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10)
+
/**
* Test data; should be the same in the python test cases
*/
@@ -39,6 +43,21 @@
static void *enc_data;
/**
+ * Our FS handle
+ */
+static struct GNUNET_FS_Handle *fs;
+
+/**
+ * FS Publish context
+ */
+static struct GNUNET_FS_PublishContext *pc;
+
+/**
+ * Block options for FS publish
+ */
+static struct GNUNET_FS_BlockOptions bo = { {0LL}, 1, 365, 1 };
+
+/**
* hash code
*/
static struct GNUNET_HashCode hash;
@@ -53,7 +72,16 @@
*/
struct GNUNET_CRYPTO_AesInitializationVector iv;
+/**
+ * Shutdown task id
+ */
+GNUNET_SCHEDULER_TaskIdentifier shutdown_tid;
+/**
+ * Abort task id
+ */
+GNUNET_SCHEDULER_TaskIdentifier abort_tid;
+
enum Test
{
/**
@@ -77,6 +105,11 @@
TEST_AES_ENC,
/**
+ * test CHK hashing
+ */
+ TEST_CHK_HASH,
+
+ /**
* Marks the end of the tests;
*/
TEST_END
@@ -104,6 +137,11 @@
* test AES encryption
*/
"TEST_AES_ENC",
+
+ /**
+ * test CHK hashing
+ */
+ "TEST_CHK_HASH",
/**
* Marks the end of the strings
@@ -112,6 +150,62 @@
};
+/**
+ * The test we are running
+ */
+static enum Test test;
+
+/**
+ * Our return status code
+ */
+static int retcode;
+
+
+/**
+ * Shutdown Task
+ *
+ * @param cls NULL
+ * @param tc task context from scheduler
+ */
+static void
+shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
+{
+ shutdown_tid = GNUNET_SCHEDULER_NO_TASK;
+ if (GNUNET_SCHEDULER_NO_TASK != abort_tid)
+ GNUNET_SCHEDULER_cancel (abort_tid);
+ if (NULL != pc)
+ GNUNET_FS_publish_stop (pc);
+ pc = NULL;
+ GNUNET_FS_stop (fs);
+}
+
+/**
+ * Abort Task
+ *
+ * @param cls NULL
+ * @param tc task context from scheduler
+ */
+static void
+abort_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
+{
+ abort_tid = GNUNET_SCHEDULER_NO_TASK;
+ retcode = 1;
+ if (GNUNET_SCHEDULER_NO_TASK != shutdown_tid)
+ {
+ GNUNET_SCHEDULER_cancel (shutdown_tid);
+ shutdown_tid = GNUNET_SCHEDULER_NO_TASK;
+ }
+ shutdown_task (cls, tc);
+}
+
+static void
+abort_now ()
+{
+ if (abort_tid != GNUNET_SCHEDULER_NO_TASK)
+ GNUNET_SCHEDULER_cancel (abort_tid);
+ abort_tid = GNUNET_SCHEDULER_add_now (&abort_task, NULL);
+}
+
static enum Test
string_to_testname (const char *testname)
{
@@ -135,18 +229,21 @@
test_data_to_string ()
{
size_t size;
+ size_t outsize;
char out[1024];
char *c;
size = strlen (data);
+ outsize = ((size*8) + (((size*8) % 5) > 0 ? 5 -
+ ((size*8) % 5) : 0)) / 5;
c = GNUNET_STRINGS_data_to_string ((const unsigned char *) data,
size,
out,
- ((size*8) + (((size*8) % 5) > 0 ? 5 -
- ((size*8) % 5) : 0)) / 5);
+ outsize);
if (NULL == c)
return 1;
- PRINTF ("%s", out);
+ if (size != fwrite (out, 1, outsize, stdout))
+ return 1;
return 0;
}
@@ -199,51 +296,174 @@
}
-int main (int argc, char *argv[])
+/**
+ * Called by FS client to give information about the progress of an
+ * operation.
+ *
+ * @param cls closure
+ * @param info details about the event, specifying the event type
+ * and various bits about the event
+ * @return client-context (for the next progress call
+ * for this operation; should be set to NULL for
+ * SUSPEND and STOPPED events). The value returned
+ * will be passed to future callbacks in the respective
+ * field in the GNUNET_FS_ProgressInfo struct.
+ */
+static void *
+progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *info)
{
- const char *testname;
- int ret;
-
- if (NULL == (testname = strchr (argv[0], (int) '_')))
+ char *suri;
+
+ switch (info->status)
{
+ case GNUNET_FS_STATUS_PUBLISH_START:
+ break;
+ case GNUNET_FS_STATUS_PUBLISH_PROGRESS:
+ break;
+ case GNUNET_FS_STATUS_PUBLISH_ERROR:
+ GNUNET_break(0);
+ abort_now();
+ break;
+ case GNUNET_FS_STATUS_PUBLISH_COMPLETED:
+ suri = GNUNET_FS_uri_to_string
+ (info->value.publish.specifics.completed.chk_uri);
+ FPRINTF (stdout, "%s", suri);
+ GNUNET_free (suri);
+ shutdown_tid = GNUNET_SCHEDULER_add_now (&shutdown_task, NULL);
+ break;
+ case GNUNET_FS_STATUS_PUBLISH_STOPPED:
+ //GNUNET_break (NULL == pc);
+ return NULL;
+ case GNUNET_FS_STATUS_UNINDEX_PROGRESS:
GNUNET_break (0);
- return 1;
+ abort_now();
+ return NULL;
+ case GNUNET_FS_STATUS_UNINDEX_COMPLETED:
+ FPRINTF (stderr, "%s", _("Cleanup after abort complete.\n"));
+ GNUNET_break (0);
+ abort_now ();
+ return NULL;
+ default:
+ FPRINTF (stderr, _("Unexpected status: %d\n"), info->status);
+ GNUNET_break (0);
+ abort_now ();
+ return NULL;
}
- if (strlen (testname) <= 1)
- return 1;
- testname++;
- switch (string_to_testname (testname))
+ return ""; /* non-null */
+}
+
+
+/**
+ * Main function that will be run by the scheduler.
+ *
+ * @param cls closure
+ * @param args remaining command-line arguments
+ * @param cfgfile name of the configuration file used (for saving, can be
NULL!)
+ * @param c configuration
+ */
+static void
+run (void *cls, char *const *args, const char *cfgfile,
+ const struct GNUNET_CONFIGURATION_Handle *cfg)
+{
+ char *filename;
+ struct GNUNET_FS_FileInformation *fi;
+
+ switch (test)
{
case TEST_DATA_TO_STRING:
- return test_data_to_string ();
+ retcode = test_data_to_string ();
+ return;
case TEST_HASH:
- if (0 != (ret = test_hash()))
- return ret;
+ if (0 != (retcode = test_hash()))
+ return;
if (1 != fwrite (&hash, sizeof (hash), 1, stdout))
- return 1;
- return 0;
+ goto return_fail;
+ return;
case TEST_HASH_TO_AES_KEY:
- if (0 != (ret = test_hash_to_aes_key()))
- return ret;
+ if (0 != (retcode = test_hash_to_aes_key()))
+ return;
if (1 != fwrite (key.key, sizeof (key.key), 1, stdout))
- return 1;
+ goto return_fail;
if (1 != fwrite (&iv, sizeof (iv), 1 , stdout))
- return 1;
- return 0;
+ goto return_fail;
+ return;
case TEST_AES_ENC:
if (0 != test_aes_enc ())
{
GNUNET_free (enc_data);
- return 1;
+ goto return_fail;
}
if (strlen(data) != fwrite (enc_data, 1, strlen(data), stdout))
{
GNUNET_free (enc_data);
- return 1;
+ goto return_fail;
}
GNUNET_free (enc_data);
- return 0;
+ return;
+ case TEST_CHK_HASH:
+ if (GNUNET_OK !=
+ GNUNET_CONFIGURATION_get_value_filename (cfg,
+ "COMPATIBILITY",
+ "HASH_FILE",
+ &filename))
+ {
+ GNUNET_break (0);
+ goto return_fail;
+ }
+ if (NULL == (fs =
+ GNUNET_FS_start (cfg, "compatibility-test", &progress_cb,
NULL,
+ GNUNET_FS_FLAGS_NONE,
GNUNET_FS_OPTIONS_END)))
+ {
+ GNUNET_break (0);
+ goto return_fail;
+ }
+ fi = GNUNET_FS_file_information_create_from_file
+ (fs, NULL, filename,
+ NULL, NULL, GNUNET_SYSERR, &bo);
+ GNUNET_assert (NULL != fi);
+ GNUNET_free (filename);
+ pc = GNUNET_FS_publish_start (fs, fi, NULL, NULL, NULL,
+ GNUNET_FS_PUBLISH_OPTION_SIMULATE_ONLY);
+ if (NULL == pc)
+ {
+ abort_now();
+ return;
+ }
+ abort_tid = GNUNET_SCHEDULER_add_delayed (ABORT_TIMEOUT, &abort_task,
NULL);
+ break;
default:
- return 2;
+ GNUNET_assert (0);
}
+ return;
+
+ return_fail:
+ retcode = 1;
+ return;
}
+
+
+int main (int argc, char *argv[])
+{
+ const char *testname;
+ static const struct GNUNET_GETOPT_CommandLineOption options[] = {
+ GNUNET_GETOPT_OPTION_END
+ };
+
+ if (NULL == (testname = strchr (argv[0], (int) '_')))
+ {
+ GNUNET_break (0);
+ return 1;
+ }
+ if (strlen (testname) <= 1)
+ return 1;
+ testname++;
+ test = string_to_testname (testname);
+ if (TEST_END == test)
+ return 2;
+ retcode = (GNUNET_OK ==
+ GNUNET_PROGRAM_run (argc, argv, "compatibility_*",
+ gettext_noop
+ ("Program to check compatibility with GNUnet API"),
+ options, &run, NULL)) ? retcode : 1;
+ return retcode;
+}
Added: gnunet-update/src/tests/compatibility.conf
===================================================================
--- gnunet-update/src/tests/compatibility.conf (rev 0)
+++ gnunet-update/src/tests/compatibility.conf 2012-12-26 20:06:35 UTC (rev
25653)
@@ -0,0 +1,2 @@
+[COMPATIBILITY]
+HASH_FILE = Makefile.am
\ No newline at end of file
Modified: gnunet-update/src/tests/test_util.py
===================================================================
--- gnunet-update/src/tests/test_util.py 2012-12-26 11:59:15 UTC (rev
25652)
+++ gnunet-update/src/tests/test_util.py 2012-12-26 20:06:35 UTC (rev
25653)
@@ -255,9 +255,9 @@
(proc_out, proc_err) = proc.communicate ()
proc.stdout.close()
self.assertEqual (proc.returncode, 0)
- hash_obj = sha512()
- hash_obj.update(self.data)
- aes_key = util.AESKey(hash_obj.digest())
+ digest = util.sha512_hash (self.data)
+ self.assertEqual (len(digest), 64)
+ aes_key = util.AESKey(digest)
self.assertEqual (len (aes_key.key), 32)
self.assertEqual (aes_key.key + aes_key.iv, proc_out)
@@ -268,9 +268,9 @@
(proc_out, proc_err) = proc.communicate ()
proc.stdout.close()
self.assertEqual (proc.returncode, 0)
- hash_obj = sha512()
- hash_obj.update(self.data)
- aes_key = util.AESKey(hash_obj.digest())
+ digest = util.sha512_hash (self.data)
+ self.assertEqual (len(digest), 64)
+ aes_key = util.AESKey(digest)
enc_data = util.aes_encrypt (aes_key, self.data)
self.assertEqual (len(enc_data), len(proc_out))
self.assertEqual (enc_data, proc_out)
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [GNUnet-SVN] r25653 - gnunet-update/src/tests,
gnunet <=