gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GNUnet-SVN] r6237 - GNUnet/src/applications/fs/ecrs


From: gnunet
Subject: [GNUnet-SVN] r6237 - GNUnet/src/applications/fs/ecrs
Date: Sun, 10 Feb 2008 15:27:33 -0700 (MST)

Author: grothoff
Date: 2008-02-10 15:27:32 -0700 (Sun, 10 Feb 2008)
New Revision: 6237

Added:
   GNUnet/src/applications/fs/ecrs/updowntest.c
Modified:
   GNUnet/src/applications/fs/ecrs/Makefile.am
   GNUnet/src/applications/fs/ecrs/ecrstest.c
   GNUnet/src/applications/fs/ecrs/upload.c
Log:
fx

Modified: GNUnet/src/applications/fs/ecrs/Makefile.am
===================================================================
--- GNUnet/src/applications/fs/ecrs/Makefile.am 2008-02-10 20:32:06 UTC (rev 
6236)
+++ GNUnet/src/applications/fs/ecrs/Makefile.am 2008-02-10 22:27:32 UTC (rev 
6237)
@@ -37,7 +37,8 @@
   metatest2 \
   searchtest \
   directorytest \
-  ecrstest 
+  ecrstest \
+  updowntest 
 
 TESTS = $(check_PROGRAMS)
 
@@ -72,6 +73,11 @@
 ecrstest_LDADD = \
   $(top_builddir)/src/applications/fs/ecrs/libgnunetecrs.la 
 
+updowntest_SOURCES = \
+  updowntest.c
+updowntest_LDADD = \
+  $(top_builddir)/src/applications/fs/ecrs/libgnunetecrs.la 
+
 downloadtest_SOURCES = \
   downloadtest.c
 downloadtest_LDADD = \

Modified: GNUnet/src/applications/fs/ecrs/ecrstest.c
===================================================================
--- GNUnet/src/applications/fs/ecrs/ecrstest.c  2008-02-10 20:32:06 UTC (rev 
6236)
+++ GNUnet/src/applications/fs/ecrs/ecrstest.c  2008-02-10 22:27:32 UTC (rev 
6237)
@@ -50,6 +50,8 @@
 
 static struct GNUNET_GC_Configuration *cfg;
 
+static struct GNUNET_ECRS_URI * want;
+
 static char *
 makeName (unsigned int i)
 {
@@ -96,7 +98,7 @@
       struct GNUNET_ECRS_MetaData *meta;
       struct GNUNET_ECRS_URI *key;
       const char *keywords[2];
-
+      
       keywords[0] = name;
       keywords[1] = NULL;
 
@@ -105,7 +107,7 @@
       ret = GNUNET_ECRS_publish_under_keyword (NULL, cfg, key, 0, 0, 
GNUNET_get_time () + 10 * GNUNET_CRON_MINUTES,     /* expire */
                                                uri, meta);
       GNUNET_ECRS_meta_data_destroy (meta);
-      GNUNET_ECRS_uri_destroy (uri);
+      want = uri;
       GNUNET_free (name);
       if (ret == GNUNET_OK)
         {
@@ -131,13 +133,16 @@
   struct GNUNET_ECRS_URI **my = closure;
   char *tmp;
 
+  if (! GNUNET_ECRS_uri_test_equal(want,
+                                  fi->uri))
+    return GNUNET_OK;
   tmp = GNUNET_ECRS_uri_to_string (fi->uri);
   GNUNET_GE_LOG (NULL,
                  GNUNET_GE_DEBUG | GNUNET_GE_REQUEST | GNUNET_GE_USER,
                  "Search found URI `%s'\n", tmp);
   GNUNET_free (tmp);
   GNUNET_GE_ASSERT (NULL, NULL == *my);
-  *my = GNUNET_ECRS_uri_duplicate (fi->uri);
+  *my = want;
   return GNUNET_SYSERR;         /* abort search */
 }
 

Added: GNUnet/src/applications/fs/ecrs/updowntest.c
===================================================================
--- GNUnet/src/applications/fs/ecrs/updowntest.c                                
(rev 0)
+++ GNUnet/src/applications/fs/ecrs/updowntest.c        2008-02-10 22:27:32 UTC 
(rev 6237)
@@ -0,0 +1,229 @@
+/*
+     This file is part of GNUnet.
+     (C) 2004, 2005, 2006, 2008 Christian Grothoff (and other contributing 
authors)
+
+     GNUnet 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.
+
+     GNUnet 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 GNUnet; see the file COPYING.  If not, write to the
+     Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+     Boston, MA 02111-1307, USA.
+*/
+
+/**
+ * @file applications/fs/ecrs/updowntest.c
+ * @brief testcase for ecrs (upload-download)
+ * @author Christian Grothoff
+ */
+
+#include "platform.h"
+#include "gnunet_util.h"
+#include "gnunet_ecrs_lib.h"
+#include "tree.h"
+
+#define START_DAEMON 1
+
+#define CHECK(a) if (!(a)) { ok = GNUNET_NO; GNUNET_GE_BREAK(NULL, 0); goto 
FAILURE; }
+
+static int
+testTerminate (void *unused)
+{
+  return GNUNET_OK;
+}
+
+static struct GNUNET_GC_Configuration *cfg;
+
+static char *
+makeName (unsigned int i)
+{
+  char *fn;
+
+  fn = GNUNET_malloc (strlen ("/tmp/gnunet-updown/ECRSTEST") + 14);
+  GNUNET_snprintf (fn,
+                   strlen ("/tmp/gnunet-updown/ECRSTEST") + 14,
+                   "/tmp/gnunet-updown/ECRSTEST%u", i);
+  GNUNET_disk_directory_create_for_file (NULL, fn);
+  return fn;
+}
+
+static struct GNUNET_ECRS_URI *
+uploadFile (unsigned int size)
+{
+  int ret;
+  char *name;
+  int fd;
+  char *buf;
+  struct GNUNET_ECRS_URI *uri;
+  int i;
+
+  name = makeName (size);
+  fd =
+    GNUNET_disk_file_open (NULL, name, O_WRONLY | O_CREAT, S_IWUSR | S_IRUSR);
+  buf = GNUNET_malloc (size);
+  memset (buf, size + size / 253, size);
+  for (i = 0; i < (int) (size - 42 - 2 * sizeof (GNUNET_HashCode));
+       i += sizeof (GNUNET_HashCode))
+    GNUNET_hash (&buf[i], 42,
+                 (GNUNET_HashCode *) & buf[i + sizeof (GNUNET_HashCode)]);
+  WRITE (fd, buf, size);
+  GNUNET_free (buf);
+  CLOSE (fd);
+  uri = NULL;
+  ret = GNUNET_ECRS_file_upload (NULL, cfg, name, GNUNET_YES,   /* index */
+                                 0,     /* anon */
+                                 0,     /* prio */
+                                 GNUNET_get_time () + 10 * 
GNUNET_CRON_MINUTES, /* expire */
+                                 NULL,  /* progress */
+                                 NULL, &testTerminate, NULL, &uri);
+  GNUNET_free(name);
+  return uri;
+}
+
+static int
+downloadFile (unsigned int size, const struct GNUNET_ECRS_URI *uri)
+{
+  int ret;
+  char *tmpName;
+  int fd;
+  char *buf;
+  char *in;
+  int i;
+  char *tmp;
+
+  tmp = GNUNET_ECRS_uri_to_string (uri);
+  GNUNET_GE_LOG (NULL,
+                 GNUNET_GE_DEBUG | GNUNET_GE_REQUEST | GNUNET_GE_USER,
+                 "Starting download of `%s'\n", tmp);
+  GNUNET_free (tmp);
+  tmpName = makeName (0);
+  ret = GNUNET_SYSERR;
+  if (GNUNET_OK == GNUNET_ECRS_file_download (NULL,
+                                              cfg,
+                                              uri,
+                                              tmpName, 0, NULL, NULL,
+                                              &testTerminate, NULL))
+    {
+      fd = GNUNET_disk_file_open (NULL, tmpName, O_RDONLY);
+      buf = GNUNET_malloc (size);
+      in = GNUNET_malloc (size);
+      memset (buf, size + size / 253, size);
+      for (i = 0; i < (int) (size - 42 - 2 * sizeof (GNUNET_HashCode));
+           i += sizeof (GNUNET_HashCode))
+        GNUNET_hash (&buf[i], 42,
+                     (GNUNET_HashCode *) & buf[i + sizeof (GNUNET_HashCode)]);
+      if (size != READ (fd, in, size))
+        ret = GNUNET_SYSERR;
+      else if (0 == memcmp (buf, in, size))
+        ret = GNUNET_OK;
+      GNUNET_free (buf);
+      GNUNET_free (in);
+      CLOSE (fd);
+    }
+  else
+    {
+      fprintf (stderr, "? ");
+    }
+  UNLINK (tmpName);
+  GNUNET_free (tmpName);
+  return ret;
+}
+
+
+static int
+unindexFile (unsigned int size)
+{
+  int ret;
+  char *name;
+
+  name = makeName (size);
+  ret =
+    GNUNET_ECRS_file_unindex (NULL, cfg, name, NULL, NULL, &testTerminate,
+                              NULL);
+  if (0 != UNLINK (name))
+    ret = GNUNET_SYSERR;
+  GNUNET_free (name);
+  return ret;
+}
+
+int
+main (int argc, char *argv[])
+{
+  static unsigned int filesizes[] = {
+    DBLOCK_SIZE - 1,
+    DBLOCK_SIZE,
+    DBLOCK_SIZE + 1,
+    DBLOCK_SIZE * CHK_PER_INODE - 1,
+    DBLOCK_SIZE * CHK_PER_INODE,
+    DBLOCK_SIZE * CHK_PER_INODE + 1,
+    1,
+    2,
+    4,
+    16,
+    32,
+    1024,
+    0
+  };
+#if START_DAEMON
+  pid_t daemon;
+#endif
+  int ok;
+  struct GNUNET_ClientServerConnection *sock = NULL;
+  struct GNUNET_ECRS_URI *uri;
+  int i;
+
+  cfg = GNUNET_GC_create ();
+  if (-1 == GNUNET_GC_parse_configuration (cfg, "check.conf"))
+    {
+      GNUNET_GC_free (cfg);
+      return -1;
+    }
+#if START_DAEMON
+  daemon = GNUNET_daemon_start (NULL, cfg, "peer.conf", GNUNET_NO);
+  GNUNET_GE_ASSERT (NULL, daemon > 0);
+  CHECK (GNUNET_OK ==
+         GNUNET_wait_for_daemon_running (NULL, cfg,
+                                         30 * GNUNET_CRON_SECONDS));
+  GNUNET_thread_sleep (5 * GNUNET_CRON_SECONDS);        /* give apps time to 
start */
+#endif
+  ok = GNUNET_YES;
+  sock = GNUNET_client_connection_create (NULL, cfg);
+  CHECK (sock != NULL);
+
+  /* ACTUAL TEST CODE */
+  i = 0;
+  while (filesizes[i] != 0)
+    {
+      fprintf (stderr, "Testing filesize %u ", filesizes[i]);
+      uri = uploadFile (filesizes[i]);
+      if (uri == NULL)
+       {
+         fprintf (stderr, "Error.\n");
+         CHECK(0);
+       }
+      CHECK (GNUNET_OK == downloadFile (filesizes[i], uri));
+      GNUNET_ECRS_uri_destroy (uri);
+      CHECK (GNUNET_OK == unindexFile (filesizes[i]));
+      fprintf (stderr, "Ok.\n");
+      i++;
+    }
+
+  /* END OF TEST CODE */
+FAILURE:
+  if (sock != NULL)
+    GNUNET_client_connection_destroy (sock);
+#if START_DAEMON
+  GNUNET_GE_ASSERT (NULL, GNUNET_OK == GNUNET_daemon_stop (NULL, daemon));
+#endif
+  GNUNET_GC_free (cfg);
+  return (ok == GNUNET_YES) ? 0 : 1;
+}
+
+/* end of updowntest.c */


Property changes on: GNUnet/src/applications/fs/ecrs/updowntest.c
___________________________________________________________________
Name: svn:eol-style
   + native

Modified: GNUnet/src/applications/fs/ecrs/upload.c
===================================================================
--- GNUnet/src/applications/fs/ecrs/upload.c    2008-02-10 20:32:06 UTC (rev 
6236)
+++ GNUnet/src/applications/fs/ecrs/upload.c    2008-02-10 22:27:32 UTC (rev 
6237)
@@ -58,9 +58,6 @@
   GNUNET_DatastoreValue *value;
   DBlock *db;
   CHK ichk;
-#if DEBUG_UPLOAD
-  GNUNET_EncName enc;
-#endif
 
   size = ntohl (iblocks[level]->size);
   GNUNET_GE_ASSERT (NULL, size > sizeof (GNUNET_DatastoreValue));
@@ -290,14 +287,11 @@
       GNUNET_EC_file_block_get_key (db, size + sizeof (DBlock), &mchk.key);
       GNUNET_EC_file_block_get_query (db, size + sizeof (DBlock),
                                       &mchk.query);
-#if DEBUG_UPLOAD
-      IF_GELOG (ectx,
-                GNUNET_GE_DEBUG | GNUNET_GE_REQUEST | GNUNET_GE_USER,
-                GNUNET_hash_to_enc (&mchk.query, &enc));
-      GNUNET_GE_LOG (ectx,
-                     GNUNET_GE_DEBUG | GNUNET_GE_REQUEST | GNUNET_GE_USER,
-                     "Query for current block of size %u is %s\n", size,
-                     &enc);
+#if DEBUG_UPLOAD 
+      GNUNET_hash_to_enc (&mchk.query, &enc);
+      fprintf(stderr,
+             "Query for current block of size %u is `%s'\n", size,
+             (const char*) &enc);
 #endif
       if (doIndex)
         {





reply via email to

[Prev in Thread] Current Thread [Next in Thread]