gnunet-svn
[Top][All Lists]
Advanced

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

[gnunet] branch master updated: -migrate meta data tests to FS. Fix BIO


From: gnunet
Subject: [gnunet] branch master updated: -migrate meta data tests to FS. Fix BIO error
Date: Tue, 06 Dec 2022 06:34:42 +0100

This is an automated email from the git hooks/post-receive script.

martin-schanzenbach pushed a commit to branch master
in repository gnunet.

The following commit(s) were added to refs/heads/master by this push:
     new c83dbd0f0 -migrate meta data tests to FS. Fix BIO error
c83dbd0f0 is described below

commit c83dbd0f063b7304ea6a4cfbfc663a2b864ad1ce
Author: Martin Schanzenbach <schanzen@gnunet.org>
AuthorDate: Tue Dec 6 14:34:33 2022 +0900

    -migrate meta data tests to FS. Fix BIO error
---
 src/fs/meta_data.c                   |  18 ++++--
 src/fs/test_fs_meta_data.c           | 117 ++++++++++++++++++++++++++++++++++-
 src/include/gnunet_bio_lib.h         |   9 +++
 src/util/bio.c                       |   7 +++
 src/util/test_common_logging_dummy.c |   6 +-
 5 files changed, 147 insertions(+), 10 deletions(-)

diff --git a/src/fs/meta_data.c b/src/fs/meta_data.c
index 3e2857101..7112a150a 100644
--- a/src/fs/meta_data.c
+++ b/src/fs/meta_data.c
@@ -1057,6 +1057,7 @@ GNUNET_FS_read_meta_data (struct GNUNET_BIO_ReadHandle *h,
 {
   uint32_t size;
   char *buf;
+  char *emsg;
   struct GNUNET_FS_MetaData *meta;
 
   if (GNUNET_OK != GNUNET_BIO_read_int32 (h,
@@ -1070,11 +1071,14 @@ GNUNET_FS_read_meta_data (struct GNUNET_BIO_ReadHandle 
*h,
   }
   if (MAX_META_DATA < size)
   {
-    GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
-                _ ("Serialized metadata `%s' larger than allowed (%u > %u)"),
-                what,
-                size,
-                MAX_META_DATA);
+    GNUNET_asprintf (&emsg,
+                     _ (
+                       "Serialized metadata `%s' larger than allowed (%u > 
%u)\n"),
+                     what,
+                     size,
+                     MAX_META_DATA);
+    GNUNET_BIO_read_set_error (h, emsg);
+    GNUNET_free (emsg);
     return GNUNET_SYSERR;
   }
   buf = GNUNET_malloc (size);
@@ -1119,6 +1123,10 @@ GNUNET_FS_write_meta_data (struct GNUNET_BIO_WriteHandle 
*h,
                                         &buf,
                                         MAX_META_DATA,
                                         GNUNET_FS_META_DATA_SERIALIZE_PART);
+  GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+              _ ("Serialized %ld bytes of metadata"),
+              size);
+
   if (-1 == size)
   {
     GNUNET_free (buf);
diff --git a/src/fs/test_fs_meta_data.c b/src/fs/test_fs_meta_data.c
index bee7844ea..4e7439d7b 100644
--- a/src/fs/test_fs_meta_data.c
+++ b/src/fs/test_fs_meta_data.c
@@ -352,19 +352,132 @@ check ()
 }
 
 
+static int
+test_bigmeta_rw (void)
+{
+  static char meta[1024 * 1024 * 10];
+  struct GNUNET_BIO_WriteHandle *wh;
+  struct GNUNET_BIO_ReadHandle *rh;
+  char *filename = GNUNET_DISK_mktemp ("gnunet_bio");
+  struct GNUNET_FS_MetaData *mdR = NULL;
+
+  memset (meta, 'b', sizeof (meta));
+  meta[sizeof (meta) - 1] = '\0';
+
+  wh = GNUNET_BIO_write_open_file (filename);
+  GNUNET_assert (NULL != wh);
+  if (GNUNET_OK != GNUNET_BIO_write_int32 (wh,
+                                           "test-bigmeta-rw-int32",
+                                           sizeof (meta)))
+  {
+    GNUNET_BIO_write_close (wh, NULL);
+    return 1;
+  }
+  if (GNUNET_OK != GNUNET_BIO_write (wh,
+                                     "test-bigmeta-rw-bytes",
+                                     meta,
+                                     sizeof (meta)))
+  {
+    GNUNET_BIO_write_close (wh, NULL);
+    return 1;
+  }
+  GNUNET_assert (GNUNET_OK == GNUNET_BIO_write_close (wh, NULL));
+
+  rh = GNUNET_BIO_read_open_file (filename);
+  GNUNET_assert (NULL != rh);
+  GNUNET_assert (GNUNET_SYSERR ==
+                 GNUNET_FS_read_meta_data (rh,
+                                           "test-bigmeta-rw-metadata",
+                                           &mdR));
+  GNUNET_assert (GNUNET_SYSERR == GNUNET_BIO_read_close (rh, NULL));
+
+  GNUNET_assert (NULL == mdR);
+
+  GNUNET_assert (GNUNET_OK == GNUNET_DISK_directory_remove (filename));
+  GNUNET_free (filename);
+  return 0;
+}
+
+static int
+test_fakemeta_rw (void)
+{
+  struct GNUNET_BIO_WriteHandle *wh;
+  struct GNUNET_BIO_ReadHandle *rh;
+  char *filename = GNUNET_DISK_mktemp ("gnunet_bio");
+  struct GNUNET_FS_MetaData *mdR = NULL;
+
+  wh = GNUNET_BIO_write_open_file (filename);
+  GNUNET_assert (NULL != wh);
+  if (GNUNET_OK != GNUNET_BIO_write_int32 (wh,
+                                           "test-fakestring-rw-int32",
+                                           2))
+  {
+    GNUNET_BIO_write_close (wh, NULL);
+    return 1;
+  }
+  GNUNET_assert (GNUNET_OK == GNUNET_BIO_write_close (wh, NULL));
+
+  rh = GNUNET_BIO_read_open_file (filename);
+  GNUNET_assert (NULL != rh);
+  GNUNET_assert (GNUNET_SYSERR ==
+                 GNUNET_FS_read_meta_data (rh,
+                                           "test-fakestring-rw-metadata",
+                                           &mdR));
+  GNUNET_assert (GNUNET_SYSERR == GNUNET_BIO_read_close (rh, NULL));
+
+  GNUNET_assert (NULL == mdR);
+
+  GNUNET_assert (GNUNET_OK == GNUNET_DISK_directory_remove (filename));
+  GNUNET_free (filename);
+  return 0;
+}
+
+static int
+test_fakebigmeta_rw (void)
+{
+  struct GNUNET_BIO_WriteHandle *wh;
+  struct GNUNET_BIO_ReadHandle *rh;
+  char *filename = GNUNET_DISK_mktemp ("gnunet_bio");
+  struct GNUNET_FS_MetaData *mdR = NULL;
+  int32_t wNum = 1024 * 1024 * 10;
+
+  wh = GNUNET_BIO_write_open_file (filename);
+  GNUNET_assert (NULL != wh);
+  GNUNET_assert (GNUNET_OK == GNUNET_BIO_write_int32 (wh,
+                                                      
"test-fakebigmeta-rw-int32",
+                                                      wNum));
+  GNUNET_assert (GNUNET_OK == GNUNET_BIO_write_close (wh, NULL));
+
+  rh = GNUNET_BIO_read_open_file (filename);
+  GNUNET_assert (NULL != rh);
+  GNUNET_assert (GNUNET_SYSERR ==
+                 GNUNET_FS_read_meta_data (rh,
+                                           "test-fakebigmeta-rw-metadata",
+                                           &mdR));
+  GNUNET_assert (GNUNET_SYSERR == GNUNET_BIO_read_close (rh, NULL));
+
+  GNUNET_assert (NULL == mdR);
+
+  GNUNET_assert (GNUNET_OK == GNUNET_DISK_directory_remove (filename));
+  GNUNET_free (filename);
+  return 0;
+}
+
 int
 main (int argc, char *argv[])
 {
   int failureCount = 0;
   int i;
 
-  GNUNET_log_setup ("test-container-meta-data", "WARNING", NULL);
+  GNUNET_log_setup ("test-fs-meta-data", "WARNING", NULL);
   for (i = 0; i < 255; i++)
     failureCount += testMeta (i);
   for (i = 1; i < 255; i++)
     failureCount += testMetaMore (i);
   failureCount += testMetaLink ();
-
+  failureCount += test_fakebigmeta_rw ();
+  failureCount += test_fakemeta_rw ();
+  failureCount +=  test_bigmeta_rw ();
   int ret = check ();
 
   if (ret == 1)
diff --git a/src/include/gnunet_bio_lib.h b/src/include/gnunet_bio_lib.h
index 6d42f554c..48a1a512d 100644
--- a/src/include/gnunet_bio_lib.h
+++ b/src/include/gnunet_bio_lib.h
@@ -91,6 +91,15 @@ GNUNET_BIO_read_open_buffer (void *buffer, size_t size);
 int
 GNUNET_BIO_read_close (struct GNUNET_BIO_ReadHandle *h, char **emsg);
 
+/**
+ * Set read error to handle
+ *
+ * @param h the handle
+ * @param emsg the message
+ */
+void
+GNUNET_BIO_read_set_error (struct GNUNET_BIO_ReadHandle *h, const char* emsg);
+
 
 /**
  * Read some contents into a buffer.
diff --git a/src/util/bio.c b/src/util/bio.c
index a19e4f3ba..70620aea7 100644
--- a/src/util/bio.c
+++ b/src/util/bio.c
@@ -182,6 +182,13 @@ GNUNET_BIO_read_close (struct GNUNET_BIO_ReadHandle *h, 
char **emsg)
   return err;
 }
 
+void
+GNUNET_BIO_read_set_error (struct GNUNET_BIO_ReadHandle *h, const char* emsg)
+{
+  GNUNET_assert (NULL == h->emsg);
+  h->emsg = GNUNET_strdup (emsg);
+}
+
 
 /**
  * Function used internally to read the contents of a file into a buffer.
diff --git a/src/util/test_common_logging_dummy.c 
b/src/util/test_common_logging_dummy.c
index fdb21ad5a..7e362c683 100644
--- a/src/util/test_common_logging_dummy.c
+++ b/src/util/test_common_logging_dummy.c
@@ -25,12 +25,12 @@
  * @author LRN
  */
 
-#undef GNUNET_EXTRA_LOGGING
-#define GNUNET_EXTRA_LOGGING GNUNET_YES
-
 #include "platform.h"
 #include "gnunet_util_lib.h"
 
+#undef GNUNET_EXTRA_LOGGING
+#define GNUNET_EXTRA_LOGGING GNUNET_YES
+
 /**
  * Artificial delay attached to each log call that is not skipped out.
  * This must be long enough for us to not to mistake skipped log call

-- 
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.



reply via email to

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