[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] r6801 - in GNUnet/src/applications/fs: ecrs fsui
From: |
gnunet |
Subject: |
[GNUnet-SVN] r6801 - in GNUnet/src/applications/fs: ecrs fsui |
Date: |
Sun, 11 May 2008 22:06:09 -0600 (MDT) |
Author: grothoff
Date: 2008-05-11 22:05:54 -0600 (Sun, 11 May 2008)
New Revision: 6801
Added:
GNUnet/src/applications/fs/fsui/basic_fsui_test.c
GNUnet/src/applications/fs/fsui/download_persistence_test.c
GNUnet/src/applications/fs/fsui/fsui_start_stop_test.c
GNUnet/src/applications/fs/fsui/recursive_download_persistence_test.c
GNUnet/src/applications/fs/fsui/recursive_download_test.c
GNUnet/src/applications/fs/fsui/search_linked_download_persistence_test.c
GNUnet/src/applications/fs/fsui/search_pause_resume_persistence_test.c
GNUnet/src/applications/fs/fsui/search_persistence_test.c
GNUnet/src/applications/fs/fsui/search_ranking_test.c
GNUnet/src/applications/fs/fsui/upload_unindex_persistence_test.c
Removed:
GNUnet/src/applications/fs/ecrs/metatest2.c
GNUnet/src/applications/fs/fsui/downloadtest.c
GNUnet/src/applications/fs/fsui/fsuitest.c
GNUnet/src/applications/fs/fsui/fsuitest2.c
GNUnet/src/applications/fs/fsui/recursivetest.c
GNUnet/src/applications/fs/fsui/searchtest.c
GNUnet/src/applications/fs/fsui/serializetest.c
GNUnet/src/applications/fs/fsui/serializetest2.c
GNUnet/src/applications/fs/fsui/serializetest3.c
GNUnet/src/applications/fs/fsui/serializetest4.c
Modified:
GNUnet/src/applications/fs/ecrs/Makefile.am
GNUnet/src/applications/fs/ecrs/metatest.c
GNUnet/src/applications/fs/fsui/Makefile.am
GNUnet/src/applications/fs/fsui/fsui.c
GNUnet/src/applications/fs/fsui/search.c
Log:
fixing and cleaning up testcases
Modified: GNUnet/src/applications/fs/ecrs/Makefile.am
===================================================================
--- GNUnet/src/applications/fs/ecrs/Makefile.am 2008-05-11 22:33:29 UTC (rev
6800)
+++ GNUnet/src/applications/fs/ecrs/Makefile.am 2008-05-12 04:05:54 UTC (rev
6801)
@@ -34,7 +34,6 @@
namespacetest \
uritest \
metatest \
- metatest2 \
searchtest \
directorytest \
ecrstest \
Modified: GNUnet/src/applications/fs/ecrs/metatest.c
===================================================================
--- GNUnet/src/applications/fs/ecrs/metatest.c 2008-05-11 22:33:29 UTC (rev
6800)
+++ GNUnet/src/applications/fs/ecrs/metatest.c 2008-05-12 04:05:54 UTC (rev
6801)
@@ -154,6 +154,40 @@
return 0;
}
+static int
+testMetaLink ()
+{
+ struct GNUNET_ECRS_MetaData *m;
+ char *val;
+ unsigned int size;
+
+ m = GNUNET_ECRS_meta_data_create ();
+ if (GNUNET_OK !=
+ GNUNET_ECRS_meta_data_insert (m, EXTRACTOR_UNKNOWN, "link"))
+ ABORT (m);
+ if (GNUNET_OK !=
+ GNUNET_ECRS_meta_data_insert (m, EXTRACTOR_FILENAME, "lib-link.m4"))
+ ABORT (m);
+ size =
+ GNUNET_ECRS_meta_data_get_serialized_size (m, GNUNET_ECRS_SERIALIZE_FULL);
+ val = GNUNET_malloc (size);
+ if (size != GNUNET_ECRS_meta_data_serialize (NULL,
+ m, val, size,
+ GNUNET_ECRS_SERIALIZE_FULL))
+ {
+ GNUNET_free (val);
+ ABORT (m);
+ }
+ GNUNET_ECRS_meta_data_destroy (m);
+ m = GNUNET_ECRS_meta_data_deserialize (NULL, val, size);
+ GNUNET_free (val);
+ if (m == NULL)
+ ABORT (m);
+ GNUNET_ECRS_meta_data_destroy (m);
+ return 0;
+}
+
+
int
main (int argc, char *argv[])
{
@@ -164,6 +198,7 @@
failureCount += testMeta (i);
for (i = 1; i < 255; i++)
failureCount += testMetaMore (i);
+ failureCount += testMetaLink ();
if (failureCount != 0)
return 1;
Deleted: GNUnet/src/applications/fs/ecrs/metatest2.c
===================================================================
--- GNUnet/src/applications/fs/ecrs/metatest2.c 2008-05-11 22:33:29 UTC (rev
6800)
+++ GNUnet/src/applications/fs/ecrs/metatest2.c 2008-05-12 04:05:54 UTC (rev
6801)
@@ -1,87 +0,0 @@
-/*
- This file is part of GNUnet.
- (C) 2003, 2004, 2006 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/metatest2.c
- * @brief Test for meta.c
- * @author Christian Grothoff
- */
-
-#include "platform.h"
-#include <extractor.h>
-#include "gnunet_util.h"
-#include "gnunet_ecrs_lib.h"
-#include "ecrs.h"
-
-#define ABORT() { fprintf(stderr, "Error at %s:%d\n", __FILE__, __LINE__);
return 1; }
-
-static int
-testMeta ()
-{
- struct GNUNET_ECRS_MetaData *m;
- char *val;
- unsigned int size;
-
- m = GNUNET_ECRS_meta_data_create ();
- if (GNUNET_OK !=
- GNUNET_ECRS_meta_data_insert (m, EXTRACTOR_UNKNOWN, "link"))
- {
- GNUNET_ECRS_meta_data_destroy (m);
- ABORT ();
- }
- if (GNUNET_OK !=
- GNUNET_ECRS_meta_data_insert (m, EXTRACTOR_FILENAME, "lib-link.m4"))
- {
- GNUNET_ECRS_meta_data_destroy (m);
- ABORT ();
- }
- size =
- GNUNET_ECRS_meta_data_get_serialized_size (m, GNUNET_ECRS_SERIALIZE_FULL);
- val = GNUNET_malloc (size);
- if (size != GNUNET_ECRS_meta_data_serialize (NULL,
- m, val, size,
- GNUNET_ECRS_SERIALIZE_FULL))
- {
- GNUNET_ECRS_meta_data_destroy (m);
- GNUNET_free (val);
- ABORT ();
- }
- GNUNET_ECRS_meta_data_destroy (m);
- m = GNUNET_ECRS_meta_data_deserialize (NULL, val, size);
- GNUNET_free (val);
- if (m == NULL)
- ABORT ();
- GNUNET_ECRS_meta_data_destroy (m);
- return 0;
-}
-
-int
-main (int argc, char *argv[])
-{
- int failureCount = 0;
-
- failureCount += testMeta ();
-
- if (failureCount != 0)
- return 1;
- return 0;
-}
-
-/* end of metatest2.c */
Modified: GNUnet/src/applications/fs/fsui/Makefile.am
===================================================================
--- GNUnet/src/applications/fs/fsui/Makefile.am 2008-05-11 22:33:29 UTC (rev
6800)
+++ GNUnet/src/applications/fs/fsui/Makefile.am 2008-05-12 04:05:54 UTC (rev
6801)
@@ -33,78 +33,86 @@
$(top_builddir)/src/util/libgnunetutil.la
check_PROGRAMS = \
- fsuitest \
- fsuitest2 \
- searchtest \
- serializetest \
- serializetest2 \
- serializetest3 \
- serializetest4 \
- downloadtest \
- recursivetest
+ fsui_start_stop_test \
+ basic_fsui_test \
+ upload_unindex_persistence_test \
+ search_ranking_test \
+ search_persistence_test \
+ search_pause_resume_persistence_test \
+ search_linked_download_persistence_test \
+ recursive_download_test \
+ download_persistence_test \
+ recursive_download_persistence_test
TESTS = $(check_PROGRAMS)
-fsuitest_SOURCES = \
- fsuitest.c
-fsuitest_LDADD = \
+basic_fsui_test_SOURCES = \
+ basic_fsui_test.c
+basic_fsui_test_LDADD = \
$(top_builddir)/src/applications/fs/ecrs/libgnunetecrs.la \
$(top_builddir)/src/applications/fs/fsui/libgnunetfsui.la \
$(top_builddir)/src/util/libgnunetutil.la
-fsuitest2_SOURCES = \
- fsuitest2.c
-fsuitest2_LDADD = \
+fsui_start_stop_test_SOURCES = \
+ fsui_start_stop_test.c
+fsui_start_stop_test_LDADD = \
$(top_builddir)/src/applications/fs/ecrs/libgnunetecrs.la \
$(top_builddir)/src/applications/fs/fsui/libgnunetfsui.la \
$(top_builddir)/src/util/libgnunetutil.la
-searchtest_SOURCES = \
- searchtest.c
-searchtest_LDADD = \
+search_pause_resume_persistence_test_SOURCES = \
+ search_pause_resume_persistence_test.c
+search_pause_resume_persistence_test_LDADD = \
$(top_builddir)/src/applications/fs/ecrs/libgnunetecrs.la \
$(top_builddir)/src/applications/fs/fsui/libgnunetfsui.la \
$(top_builddir)/src/util/libgnunetutil.la
-downloadtest_SOURCES = \
- downloadtest.c
-downloadtest_LDADD = \
+search_ranking_test_SOURCES = \
+ search_ranking_test.c
+search_ranking_test_LDADD = \
$(top_builddir)/src/applications/fs/ecrs/libgnunetecrs.la \
$(top_builddir)/src/applications/fs/fsui/libgnunetfsui.la \
$(top_builddir)/src/util/libgnunetutil.la
-recursivetest_SOURCES = \
- recursivetest.c
-recursivetest_LDADD = \
+download_persistence_test_SOURCES = \
+ download_persistence_test.c
+download_persistence_test_LDADD = \
$(top_builddir)/src/applications/fs/ecrs/libgnunetecrs.la \
$(top_builddir)/src/applications/fs/fsui/libgnunetfsui.la \
$(top_builddir)/src/util/libgnunetutil.la
-serializetest_SOURCES = \
- serializetest.c
-serializetest_LDADD = \
+recursive_download_test_SOURCES = \
+ recursive_download_test.c
+recursive_download_test_LDADD = \
$(top_builddir)/src/applications/fs/ecrs/libgnunetecrs.la \
$(top_builddir)/src/applications/fs/fsui/libgnunetfsui.la \
$(top_builddir)/src/util/libgnunetutil.la
-serializetest2_SOURCES = \
- serializetest2.c
-serializetest2_LDADD = \
+upload_unindex_persistence_test_SOURCES = \
+ upload_unindex_persistence_test.c
+upload_unindex_persistence_test_LDADD = \
$(top_builddir)/src/applications/fs/ecrs/libgnunetecrs.la \
$(top_builddir)/src/applications/fs/fsui/libgnunetfsui.la \
$(top_builddir)/src/util/libgnunetutil.la
-serializetest3_SOURCES = \
- serializetest3.c
-serializetest3_LDADD = \
+search_linked_download_persistence_test_SOURCES = \
+ search_linked_download_persistence_test.c
+search_linked_download_persistence_test_LDADD = \
$(top_builddir)/src/applications/fs/ecrs/libgnunetecrs.la \
$(top_builddir)/src/applications/fs/fsui/libgnunetfsui.la \
$(top_builddir)/src/util/libgnunetutil.la
+search_persistence_test_SOURCES = \
+ search_persistence_test.c
+search_persistence_test_LDADD = \
+ $(top_builddir)/src/applications/fs/ecrs/libgnunetecrs.la \
+ $(top_builddir)/src/applications/fs/fsui/libgnunetfsui.la \
+ $(top_builddir)/src/util/libgnunetutil.la
-serializetest4_SOURCES = \
- serializetest4.c
-serializetest4_LDADD = \
+
+recursive_download_persistence_test_SOURCES = \
+ recursive_download_persistence_test.c
+recursive_download_persistence_test_LDADD = \
$(top_builddir)/src/applications/fs/ecrs/libgnunetecrs.la \
$(top_builddir)/src/applications/fs/fsui/libgnunetfsui.la \
$(top_builddir)/src/util/libgnunetutil.la
Copied: GNUnet/src/applications/fs/fsui/basic_fsui_test.c (from rev 6789,
GNUnet/src/applications/fs/fsui/fsuitest.c)
===================================================================
--- GNUnet/src/applications/fs/fsui/basic_fsui_test.c
(rev 0)
+++ GNUnet/src/applications/fs/fsui/basic_fsui_test.c 2008-05-12 04:05:54 UTC
(rev 6801)
@@ -0,0 +1,258 @@
+/*
+ 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/fsui/basic_fsui_test.c
+ * @brief testcase for fsui (upload-search-download-unindex)
+ * @author Christian Grothoff
+ */
+
+#include "platform.h"
+#include "gnunet_util.h"
+#include "gnunet_fsui_lib.h"
+
+#define DEBUG_VERBOSE GNUNET_NO
+
+#define CHECK(a) if (!(a)) { ok = GNUNET_NO; GNUNET_GE_BREAK(NULL, 0); goto
FAILURE; }
+
+static char *
+makeName (unsigned int i)
+{
+ char *fn;
+
+ fn =
+ GNUNET_malloc (strlen ("/tmp/gnunet-basic_fsui_test/BASIC_FSUI_TEST") +
14);
+ GNUNET_snprintf (fn, strlen ("/tmp/gnunet-basic_fsui_test/BASIC_FSUI_TEST")
+ 14,
+ "/tmp/gnunet-basic_fsui_test/BASIC_FSUI_TEST%u", i);
+ GNUNET_disk_directory_create_for_file (NULL, fn);
+ return fn;
+}
+
+static volatile enum GNUNET_FSUI_EventType lastEvent;
+
+static struct GNUNET_ECRS_MetaData *search_meta;
+
+static struct GNUNET_ECRS_URI *search_uri;
+
+static struct GNUNET_FSUI_Context *ctx;
+
+static void *
+eventCallback (void *cls, const GNUNET_FSUI_Event * event)
+{
+ static char unused;
+
+ switch (event->type)
+ {
+ case GNUNET_FSUI_search_resumed:
+ case GNUNET_FSUI_download_resumed:
+ case GNUNET_FSUI_upload_resumed:
+ case GNUNET_FSUI_unindex_resumed:
+ return &unused;
+ case GNUNET_FSUI_search_result:
+#if DEBUG_VERBOSE
+ printf ("Received search result\n");
+#endif
+ search_uri = GNUNET_ECRS_uri_duplicate(event->data.SearchResult.fi.uri);
+ search_meta =
GNUNET_ECRS_meta_data_duplicate(event->data.SearchResult.fi.meta);
+ break;
+ case GNUNET_FSUI_upload_completed:
+#if DEBUG_VERBOSE
+ printf ("Upload complete.\n");
+#endif
+ break;
+ case GNUNET_FSUI_download_completed:
+#if DEBUG_VERBOSE
+ printf ("Download complete.\n");
+#endif
+ break;
+ case GNUNET_FSUI_unindex_completed:
+#if DEBUG_VERBOSE
+ printf ("Unindex complete.\n");
+#endif
+ break;
+ default:
+ break;
+ }
+ lastEvent = event->type;
+ return NULL;
+}
+
+#define START_DAEMON 1
+
+int
+main (int argc, char *argv[])
+{
+#if START_DAEMON
+ pid_t daemon;
+#endif
+ int ok;
+ struct GNUNET_ECRS_URI *uri;
+ char *filename = NULL;
+ char *keywords[] = {
+ "fsui_foo",
+ "fsui_bar",
+ };
+ char keyword[40];
+ char *fn;
+ int prog;
+ struct GNUNET_ECRS_MetaData *meta;
+ struct GNUNET_ECRS_URI *kuri;
+ struct GNUNET_GC_Configuration *cfg;
+ struct GNUNET_FSUI_UploadList *upload = NULL;
+ struct GNUNET_FSUI_SearchList *search = NULL;
+ struct GNUNET_FSUI_UnindexList *unindex = NULL;
+ struct GNUNET_FSUI_DownloadList *download = NULL;
+
+ 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,
+ 60 * GNUNET_CRON_SECONDS));
+#endif
+ GNUNET_thread_sleep (5 * GNUNET_CRON_SECONDS); /* give apps time to
start */
+ ok = GNUNET_YES;
+
+ /* ACTUAL TEST CODE */
+ ctx = GNUNET_FSUI_start (NULL, cfg, "basic_fsui_test", 32, /* thread pool
size */
+ GNUNET_NO, /* no resume */
+ &eventCallback, NULL);
+ CHECK (ctx != NULL);
+ filename = makeName (42);
+ GNUNET_disk_file_write (NULL,
+ filename,
+ "foo bar test!", strlen ("foo bar test!"), "600");
+ meta = GNUNET_ECRS_meta_data_create ();
+ kuri =
+ GNUNET_ECRS_keyword_command_line_to_uri (NULL, 2,
+ (const char **) keywords);
+ /* upload */
+ upload = GNUNET_FSUI_upload_start (ctx, filename,
+ (GNUNET_FSUI_DirectoryScanCallback) &
GNUNET_disk_directory_scan, NULL,
+ 0, /* anonymity */
+ 0, /* priority */
+ GNUNET_YES,
+ GNUNET_NO,
+ GNUNET_NO,
+ GNUNET_get_time () +
+ 5 * GNUNET_CRON_HOURS, meta, kuri, kuri);
+ CHECK (upload != NULL);
+ GNUNET_ECRS_uri_destroy (kuri);
+ GNUNET_ECRS_meta_data_destroy (meta);
+ prog = 0;
+ while (lastEvent != GNUNET_FSUI_upload_completed)
+ {
+ prog++;
+ CHECK (prog <
+ 10000) GNUNET_thread_sleep (50 * GNUNET_CRON_MILLISECONDS);
+ if (GNUNET_shutdown_test () == GNUNET_YES)
+ break;
+ }
+
+ /* search */
+ GNUNET_snprintf (keyword, 40, "+%s +%s", keywords[0], keywords[1]);
+ uri = GNUNET_ECRS_keyword_string_to_uri (NULL, keyword);
+ search = GNUNET_FSUI_search_start (ctx, 0, uri);
+ GNUNET_ECRS_uri_destroy (uri);
+ CHECK (search != NULL);
+ prog = 0;
+ while (lastEvent != GNUNET_FSUI_search_result)
+ {
+ prog++;
+ CHECK (prog < 10000);
+ GNUNET_thread_sleep (50 * GNUNET_CRON_MILLISECONDS);
+ if (GNUNET_shutdown_test () == GNUNET_YES)
+ break;
+ }
+ GNUNET_FSUI_search_abort (search);
+ GNUNET_FSUI_search_stop (search);
+
+ /* download */
+ fn = makeName (43);
+ download = GNUNET_FSUI_download_start (ctx,
+ 0,
+ GNUNET_NO,
+ search_uri,
+ search_meta,
+ fn, NULL, NULL);
+ GNUNET_free (fn);
+ prog = 0;
+ while (lastEvent != GNUNET_FSUI_download_completed)
+ {
+ prog++;
+ CHECK (prog < 10000);
+ GNUNET_thread_sleep (50 * GNUNET_CRON_MILLISECONDS);
+ if (GNUNET_shutdown_test () == GNUNET_YES)
+ break;
+ }
+ GNUNET_FSUI_download_stop(download);
+ download = NULL;
+ GNUNET_ECRS_uri_destroy (search_uri);
+ GNUNET_ECRS_meta_data_destroy (search_meta);
+ /* unindex */
+ unindex = GNUNET_FSUI_unindex_start (ctx, filename);
+ prog = 0;
+ while (lastEvent != GNUNET_FSUI_unindex_completed)
+ {
+ prog++;
+ CHECK (prog < 10000);
+ GNUNET_thread_sleep (50 * GNUNET_CRON_MILLISECONDS);
+ if (GNUNET_shutdown_test () == GNUNET_YES)
+ break;
+ }
+ if (lastEvent != GNUNET_FSUI_unindex_completed)
+ GNUNET_FSUI_unindex_abort (unindex);
+ GNUNET_FSUI_unindex_stop (unindex);
+
+
+ /* END OF TEST CODE */
+FAILURE:
+ if (ctx != NULL)
+ GNUNET_FSUI_stop (ctx);
+ if (filename != NULL)
+ {
+ UNLINK (filename);
+ GNUNET_free (filename);
+ }
+ if (download != NULL)
+ {
+ GNUNET_FSUI_download_abort(download);
+ GNUNET_FSUI_download_stop(download);
+ }
+ filename = makeName (43);
+ /* TODO: verify file 'filename(42)' == file 'filename(43)' */
+ UNLINK (filename);
+ GNUNET_free (filename);
+
+#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 basic_fsui_test.c */
Copied: GNUnet/src/applications/fs/fsui/download_persistence_test.c (from rev
6789, GNUnet/src/applications/fs/fsui/downloadtest.c)
===================================================================
--- GNUnet/src/applications/fs/fsui/download_persistence_test.c
(rev 0)
+++ GNUnet/src/applications/fs/fsui/download_persistence_test.c 2008-05-12
04:05:54 UTC (rev 6801)
@@ -0,0 +1,318 @@
+/*
+ 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/fsui/download_persistence_test.c
+ * @brief testcase for fsui download persistence (upload-download)
+ * @author Christian Grothoff
+ */
+
+#include "platform.h"
+#include "gnunet_util.h"
+#include "gnunet_fsui_lib.h"
+
+#define DEBUG_VERBOSE GNUNET_NO
+
+#define CHECK(a) if (!(a)) { ok = GNUNET_NO; GNUNET_GE_BREAK(ectx, 0); goto
FAILURE; }
+
+static volatile int suspendRestart = 0;
+
+static struct GNUNET_GE_Context *ectx;
+
+static char *
+makeName (unsigned int i)
+{
+ char *fn;
+
+ fn = GNUNET_malloc (strlen
("/tmp/gnunet-fsui-download_persistence_test/FSUITEST") + 14);
+ GNUNET_snprintf (fn,
+ strlen
("/tmp/gnunet-fsui-download_persistence_test/FSUITEST") + 14,
+ "/tmp/gnunet-fsui-download_persistence_test/FSUITEST%u", i);
+ GNUNET_disk_directory_create_for_file (NULL, fn);
+ return fn;
+}
+
+static volatile enum GNUNET_FSUI_EventType lastEvent;
+static volatile enum GNUNET_FSUI_EventType waitForEvent;
+static volatile int download_done;
+static struct GNUNET_FSUI_Context *ctx;
+static struct GNUNET_ECRS_URI *upURI;
+static struct GNUNET_FSUI_DownloadList *download;
+
+static void *
+eventCallback (void *cls, const GNUNET_FSUI_Event * event)
+{
+ switch (event->type)
+ {
+ case GNUNET_FSUI_download_suspended:
+ download = NULL;
+ break;
+ case GNUNET_FSUI_download_resumed:
+#if DEBUG_VERBOSE
+ printf ("Download resuming\n");
+#endif
+ download = event->data.DownloadResumed.dc.pos;
+ break;
+ case GNUNET_FSUI_upload_progress:
+#if DEBUG_VERBOSE > 1
+ printf ("Upload is progressing (%llu/%llu)...\n",
+ event->data.UploadProgress.completed,
+ event->data.UploadProgress.total);
+#endif
+ break;
+ case GNUNET_FSUI_upload_completed:
+ upURI = GNUNET_ECRS_uri_duplicate (event->data.UploadCompleted.uri);
+#if DEBUG_VERBOSE
+ printf ("Upload complete.\n");
+#endif
+ break;
+ case GNUNET_FSUI_download_completed:
+#if DEBUG_VERBOSE
+ printf ("Download complete.\n");
+#endif
+ download_done = 1;
+ break;
+ case GNUNET_FSUI_download_progress:
+#if DEBUG_VERBOSE > 1
+ printf ("Download is progressing (%llu/%llu)...\n",
+ event->data.DownloadProgress.completed,
+ event->data.DownloadProgress.total);
+#endif
+ break;
+ case GNUNET_FSUI_unindex_progress:
+#if DEBUG_VERBOSE > 1
+ printf ("Unindex is progressing (%llu/%llu)...\n",
+ event->data.UnindexProgress.completed,
+ event->data.UnindexProgress.total);
+#endif
+ break;
+ case GNUNET_FSUI_unindex_completed:
+#if DEBUG_VERBOSE
+ printf ("Unindex complete.\n");
+#endif
+ break;
+ case GNUNET_FSUI_unindex_error:
+ case GNUNET_FSUI_upload_error:
+ case GNUNET_FSUI_download_error:
+ fprintf (stderr, "Received ERROR: %d\n", event->type);
+ GNUNET_GE_BREAK (ectx, 0);
+ break;
+ case GNUNET_FSUI_download_aborted:
+#if DEBUG_VERBOSE
+ printf ("Received download aborted event.\n");
+#endif
+ break;
+ case GNUNET_FSUI_unindex_suspended:
+ case GNUNET_FSUI_upload_suspended:
+#if DEBUG_VERBOSE
+ fprintf (stderr, "Received SUSPENDING: %d\n", event->type);
+#endif
+ break;
+ case GNUNET_FSUI_upload_started:
+ case GNUNET_FSUI_upload_stopped:
+ case GNUNET_FSUI_download_started:
+ case GNUNET_FSUI_download_stopped:
+ case GNUNET_FSUI_unindex_started:
+ case GNUNET_FSUI_unindex_stopped:
+ break;
+ default:
+ printf ("Unexpected event: %d\n", event->type);
+ break;
+ }
+ if (lastEvent == waitForEvent)
+ return NULL; /* ignore all other events */
+ lastEvent = event->type;
+ return NULL;
+}
+
+#define FILESIZE (1024 * 1024 * 2)
+
+#define START_DAEMON 1
+
+int
+main (int argc, char *argv[])
+{
+#if START_DAEMON
+ pid_t daemon;
+#endif
+ int ok;
+ int i;
+ char *fn = NULL;
+ char *keywords[] = {
+ "down_foo",
+ "down_bar",
+ };
+ int prog;
+ char *buf;
+ struct GNUNET_ECRS_MetaData *meta;
+ struct GNUNET_ECRS_URI *kuri = NULL;
+ struct GNUNET_GC_Configuration *cfg;
+ struct GNUNET_FSUI_UnindexList *unindex = NULL;
+ struct GNUNET_FSUI_UploadList *upload = NULL;
+
+ ok = GNUNET_YES;
+ cfg = GNUNET_GC_create ();
+ if (-1 == GNUNET_GC_parse_configuration (cfg, "check.conf"))
+ {
+ GNUNET_GC_free (cfg);
+ return -1;
+ }
+#if START_DAEMON
+ GNUNET_disk_directory_remove (NULL,
"/tmp/gnunet-fsui-download_persistence_test/");
+ 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 */
+ /* ACTUAL TEST CODE */
+#endif
+ ctx = GNUNET_FSUI_start (NULL,
+ cfg, "fsuidownload_persistence_test", 32,
GNUNET_YES,
+ &eventCallback, NULL);
+ CHECK (ctx != NULL);
+
+ /* upload */
+ fn = makeName (42);
+ buf = GNUNET_malloc (FILESIZE);
+ for (i = 0; i < FILESIZE; i++)
+ buf[i] = GNUNET_random_u32 (GNUNET_RANDOM_QUALITY_WEAK, 256);
+ GNUNET_disk_file_write (ectx, fn, buf, FILESIZE, "600");
+ GNUNET_free (buf);
+ meta = GNUNET_ECRS_meta_data_create ();
+ kuri =
+ GNUNET_ECRS_keyword_command_line_to_uri (ectx, 2,
+ (const char **) keywords);
+ waitForEvent = GNUNET_FSUI_upload_completed;
+ upload = GNUNET_FSUI_upload_start (ctx,
+ fn,
+ (GNUNET_FSUI_DirectoryScanCallback) &
+ GNUNET_disk_directory_scan, NULL, 0, 0,
+ GNUNET_YES, GNUNET_NO, GNUNET_NO,
+ GNUNET_get_time () +
+ 5 * GNUNET_CRON_HOURS, meta, kuri, kuri);
+ CHECK (upload != NULL);
+ GNUNET_ECRS_uri_destroy (kuri);
+ kuri = NULL;
+ prog = 0;
+ while (lastEvent != GNUNET_FSUI_upload_completed)
+ {
+ prog++;
+ CHECK (prog < 5000);
+ GNUNET_thread_sleep (50 * GNUNET_CRON_MILLISECONDS);
+ if (GNUNET_shutdown_test () == GNUNET_YES)
+ break;
+ }
+ GNUNET_FSUI_upload_stop (upload);
+
+ /* download */
+ waitForEvent = GNUNET_FSUI_download_completed;
+ GNUNET_free (fn);
+ fn = makeName (43);
+ download_done = 0;
+ download = GNUNET_FSUI_download_start (ctx,
+ 0,
+ GNUNET_NO,
+ upURI,
+ meta, fn, NULL, NULL);
+ CHECK(download != NULL);
+ GNUNET_free (fn);
+ suspendRestart = 4;
+ prog = 0;
+ while (download_done == 0)
+ {
+ prog++;
+ CHECK (prog < 1000);
+ GNUNET_thread_sleep (50 * GNUNET_CRON_MILLISECONDS);
+ if ((suspendRestart > 0)
+ && (GNUNET_random_u32 (GNUNET_RANDOM_QUALITY_WEAK, 4) == 0))
+ {
+#if 1
+#if DEBUG_VERBOSE
+ printf ("Testing FSUI suspend-resume\n");
+#endif
+ GNUNET_FSUI_stop (ctx); /* download possibly incomplete
+ at this point, thus testing resume
*/
+ ctx = GNUNET_FSUI_start (NULL,
+ cfg,
+ "fsuidownload_persistence_test",
+ 32, GNUNET_YES, &eventCallback, NULL);
+#if DEBUG_VERBOSE
+ printf ("Resumed...\n");
+#endif
+#endif
+ suspendRestart--;
+ }
+ if (GNUNET_shutdown_test () == GNUNET_YES)
+ break;
+ }
+ GNUNET_FSUI_download_stop (download);
+ download = NULL;
+
+ /* unindex */
+ waitForEvent = GNUNET_FSUI_unindex_completed;
+ fn = makeName (42);
+ unindex = GNUNET_FSUI_unindex_start (ctx, fn);
+ CHECK (unindex != NULL);
+ prog = 0;
+ while (lastEvent != GNUNET_FSUI_unindex_completed)
+ {
+ prog++;
+ CHECK (prog < 5000);
+ GNUNET_thread_sleep (50 * GNUNET_CRON_MILLISECONDS);
+ CHECK (lastEvent != GNUNET_FSUI_unindex_error);
+ if (GNUNET_shutdown_test () == GNUNET_YES)
+ break;
+ }
+ CHECK (lastEvent == GNUNET_FSUI_unindex_completed);
+ /* END OF TEST CODE */
+FAILURE:
+ if (meta != NULL)
+ GNUNET_ECRS_meta_data_destroy (meta);
+ if (ctx != NULL)
+ {
+ if (unindex != NULL)
+ GNUNET_FSUI_unindex_stop (unindex);
+ if (download != NULL)
+ GNUNET_FSUI_download_stop (download);
+ GNUNET_FSUI_stop (ctx);
+ }
+ if (fn != NULL)
+ {
+ UNLINK (fn);
+ GNUNET_free (fn);
+ }
+ if (kuri != NULL)
+ GNUNET_ECRS_uri_destroy (kuri);
+ fn = makeName (43);
+ /* TODO: verify file 'fn(42)' == file 'fn(43)' */
+ UNLINK (fn);
+ GNUNET_free (fn);
+ if (upURI != NULL)
+ GNUNET_ECRS_uri_destroy (upURI);
+
+#if START_DAEMON
+ GNUNET_GE_BREAK (NULL, GNUNET_OK == GNUNET_daemon_stop (NULL, daemon));
+#endif
+ GNUNET_GC_free (cfg);
+ return (ok == GNUNET_YES) ? 0 : 1;
+}
+
+/* end of download_persistence_test.c */
Deleted: GNUnet/src/applications/fs/fsui/downloadtest.c
===================================================================
--- GNUnet/src/applications/fs/fsui/downloadtest.c 2008-05-11 22:33:29 UTC
(rev 6800)
+++ GNUnet/src/applications/fs/fsui/downloadtest.c 2008-05-12 04:05:54 UTC
(rev 6801)
@@ -1,366 +0,0 @@
-/*
- 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/fsui/downloadtest.c
- * @brief testcase for fsui download persistence (upload-download)
- * @author Christian Grothoff
- */
-
-#include "platform.h"
-#include "gnunet_util.h"
-#include "gnunet_fsui_lib.h"
-
-#define DEBUG_VERBOSE GNUNET_YES
-
-#define CHECK(a) if (!(a)) { ok = GNUNET_NO; GNUNET_GE_BREAK(ectx, 0); goto
FAILURE; }
-
-static volatile int suspendRestart = 0;
-
-static struct GNUNET_GE_Context *ectx;
-
-static char *
-makeName (unsigned int i)
-{
- char *fn;
-
- fn = GNUNET_malloc (strlen ("/tmp/gnunet-fsui-downloadtest/FSUITEST") + 14);
- GNUNET_snprintf (fn,
- strlen ("/tmp/gnunet-fsui-downloadtest/FSUITEST") + 14,
- "/tmp/gnunet-fsui-downloadtest/FSUITEST%u", i);
- GNUNET_disk_directory_create_for_file (NULL, fn);
- return fn;
-}
-
-static volatile enum GNUNET_FSUI_EventType lastEvent;
-static volatile enum GNUNET_FSUI_EventType waitForEvent;
-static volatile int search_done;
-static struct GNUNET_FSUI_Context *ctx;
-static struct GNUNET_ECRS_URI *upURI;
-static struct GNUNET_FSUI_SearchList *search;
-static struct GNUNET_FSUI_DownloadList *download;
-
-static void *
-eventCallback (void *cls, const GNUNET_FSUI_Event * event)
-{
- char *fn;
-
- switch (event->type)
- {
- case GNUNET_FSUI_search_suspended:
- search = NULL;
- break;
- case GNUNET_FSUI_download_suspended:
- download = NULL;
- break;
- case GNUNET_FSUI_search_resumed:
-#if DEBUG_VERBOSE
- printf ("Search resuming\n");
-#endif
- search = event->data.SearchResumed.sc.pos;
- break;
- case GNUNET_FSUI_download_resumed:
-#if DEBUG_VERBOSE
- printf ("Download resuming\n");
-#endif
- download = event->data.DownloadResumed.dc.pos;
- break;
- case GNUNET_FSUI_search_result:
- if (download == NULL)
- {
- char *u;
-
- u = GNUNET_ECRS_uri_to_string (event->data.SearchResult.fi.uri);
- if (!GNUNET_ECRS_uri_test_equal
- (upURI, event->data.SearchResult.fi.uri))
- {
-#if DEBUG_VERBOSE
- printf ("Received result for different file: %s.\n", u);
-#endif
- GNUNET_free (u);
- return NULL; /* ignore */
- }
-#if DEBUG_VERBOSE
- printf ("Received search result; download started: %s.\n", u);
-#endif
- GNUNET_free (u);
- fn = makeName (43);
- download = GNUNET_FSUI_download_start (ctx,
- 0,
- GNUNET_NO,
- event->data.SearchResult.fi.
- uri,
- event->data.SearchResult.fi.
- meta, fn, NULL, NULL);
- if (download == NULL)
- {
- GNUNET_GE_BREAK (ectx, 0);
- return NULL;
- }
- GNUNET_free (fn);
- suspendRestart = 4;
- }
- break;
- case GNUNET_FSUI_upload_progress:
-#if DEBUG_VERBOSE > 1
- printf ("Upload is progressing (%llu/%llu)...\n",
- event->data.UploadProgress.completed,
- event->data.UploadProgress.total);
-#endif
- break;
- case GNUNET_FSUI_upload_completed:
- upURI = GNUNET_ECRS_uri_duplicate (event->data.UploadCompleted.uri);
-#if DEBUG_VERBOSE
- printf ("Upload complete.\n");
-#endif
- break;
- case GNUNET_FSUI_download_completed:
-#if DEBUG_VERBOSE
- printf ("Download complete.\n");
-#endif
- search_done = 1;
- break;
- case GNUNET_FSUI_download_progress:
-#if DEBUG_VERBOSE > 1
- printf ("Download is progressing (%llu/%llu)...\n",
- event->data.DownloadProgress.completed,
- event->data.DownloadProgress.total);
-#endif
- break;
- case GNUNET_FSUI_unindex_progress:
-#if DEBUG_VERBOSE > 1
- printf ("Unindex is progressing (%llu/%llu)...\n",
- event->data.UnindexProgress.completed,
- event->data.UnindexProgress.total);
-#endif
- break;
- case GNUNET_FSUI_unindex_completed:
-#if DEBUG_VERBOSE
- printf ("Unindex complete.\n");
-#endif
- break;
- case GNUNET_FSUI_unindex_error:
- case GNUNET_FSUI_upload_error:
- case GNUNET_FSUI_download_error:
- fprintf (stderr, "Received ERROR: %d\n", event->type);
- GNUNET_GE_BREAK (ectx, 0);
- break;
- case GNUNET_FSUI_download_aborted:
-#if DEBUG_VERBOSE
- printf ("Received download aborted event.\n");
-#endif
- break;
- case GNUNET_FSUI_unindex_suspended:
- case GNUNET_FSUI_upload_suspended:
-#if DEBUG_VERBOSE
- fprintf (stderr, "Received SUSPENDING: %d\n", event->type);
-#endif
- break;
- case GNUNET_FSUI_upload_started:
- case GNUNET_FSUI_upload_stopped:
- case GNUNET_FSUI_download_started:
- case GNUNET_FSUI_download_stopped:
- case GNUNET_FSUI_search_started:
- case GNUNET_FSUI_search_aborted:
- case GNUNET_FSUI_search_stopped:
- case GNUNET_FSUI_search_update:
- case GNUNET_FSUI_unindex_started:
- case GNUNET_FSUI_unindex_stopped:
- break;
- default:
- printf ("Unexpected event: %d\n", event->type);
- break;
- }
- if (lastEvent == waitForEvent)
- return NULL; /* ignore all other events */
- lastEvent = event->type;
- return NULL;
-}
-
-#define FILESIZE (1024 * 1024 * 2)
-
-#define START_DAEMON 1
-
-int
-main (int argc, char *argv[])
-{
-#if START_DAEMON
- pid_t daemon;
-#endif
- int ok;
- int i;
- struct GNUNET_ECRS_URI *uri = NULL;
- char *fn = NULL;
- char *keywords[] = {
- "down_foo",
- "down_bar",
- };
- char keyword[40];
- int prog;
- char *buf;
- struct GNUNET_ECRS_MetaData *meta;
- struct GNUNET_ECRS_URI *kuri = NULL;
- struct GNUNET_GC_Configuration *cfg;
- struct GNUNET_FSUI_UnindexList *unindex = NULL;
- struct GNUNET_FSUI_UploadList *upload = NULL;
-
- ok = GNUNET_YES;
- cfg = GNUNET_GC_create ();
- if (-1 == GNUNET_GC_parse_configuration (cfg, "check.conf"))
- {
- GNUNET_GC_free (cfg);
- return -1;
- }
-#if START_DAEMON
- GNUNET_disk_directory_remove (NULL, "/tmp/gnunet-fsui-test/content/");
- 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 */
- /* ACTUAL TEST CODE */
-#endif
- ctx = GNUNET_FSUI_start (NULL,
- cfg, "fsuidownloadtest", 32, GNUNET_YES,
- &eventCallback, NULL);
- CHECK (ctx != NULL);
- fn = makeName (42);
- buf = GNUNET_malloc (FILESIZE);
- for (i = 0; i < FILESIZE; i++)
- buf[i] = GNUNET_random_u32 (GNUNET_RANDOM_QUALITY_WEAK, 256);
- GNUNET_disk_file_write (ectx, fn, buf, FILESIZE, "600");
- GNUNET_free (buf);
- meta = GNUNET_ECRS_meta_data_create ();
- kuri =
- GNUNET_ECRS_keyword_command_line_to_uri (ectx, 2,
- (const char **) keywords);
- waitForEvent = GNUNET_FSUI_upload_completed;
- upload = GNUNET_FSUI_upload_start (ctx,
- fn,
- (GNUNET_FSUI_DirectoryScanCallback) &
- GNUNET_disk_directory_scan, NULL, 0, 0,
- GNUNET_YES, GNUNET_NO, GNUNET_NO,
- GNUNET_get_time () +
- 5 * GNUNET_CRON_HOURS, meta, kuri, kuri);
- CHECK (upload != NULL);
- GNUNET_ECRS_uri_destroy (kuri);
- kuri = NULL;
- GNUNET_ECRS_meta_data_destroy (meta);
- prog = 0;
- while (lastEvent != GNUNET_FSUI_upload_completed)
- {
- prog++;
- CHECK (prog < 5000);
- GNUNET_thread_sleep (50 * GNUNET_CRON_MILLISECONDS);
- if (GNUNET_shutdown_test () == GNUNET_YES)
- break;
- }
- GNUNET_FSUI_upload_stop (upload);
- GNUNET_snprintf (keyword, 40, "+%s +%s", keywords[0], keywords[1]);
- uri = GNUNET_ECRS_keyword_string_to_uri (ectx, keyword);
- waitForEvent = GNUNET_FSUI_download_completed;
- search_done = 0;
- search = GNUNET_FSUI_search_start (ctx, 0, uri);
- CHECK (search != NULL);
- prog = 0;
- while (search_done == 0)
- {
- prog++;
- CHECK (prog < 1000);
- GNUNET_thread_sleep (50 * GNUNET_CRON_MILLISECONDS);
- if ((suspendRestart > 0)
- && (GNUNET_random_u32 (GNUNET_RANDOM_QUALITY_WEAK, 4) == 0))
- {
-#if 1
-#if DEBUG_VERBOSE
- printf ("Testing FSUI suspend-resume\n");
-#endif
- GNUNET_FSUI_stop (ctx); /* download possibly incomplete
- at this point, thus testing resume
*/
- CHECK (search == NULL);
- CHECK (download == NULL);
- ctx = GNUNET_FSUI_start (NULL,
- cfg,
- "fsuidownloadtest",
- 32, GNUNET_YES, &eventCallback, NULL);
-#if DEBUG_VERBOSE
- printf ("Resumed...\n");
-#endif
-#endif
- suspendRestart--;
- }
- if (GNUNET_shutdown_test () == GNUNET_YES)
- break;
- }
- GNUNET_FSUI_search_abort (search);
- GNUNET_FSUI_search_stop (search);
- search = NULL;
- CHECK (download != NULL);
- waitForEvent = GNUNET_FSUI_unindex_completed;
- unindex = GNUNET_FSUI_unindex_start (ctx, fn);
- CHECK (unindex != NULL);
- prog = 0;
- while (lastEvent != GNUNET_FSUI_unindex_completed)
- {
- prog++;
- CHECK (prog < 5000);
- GNUNET_thread_sleep (50 * GNUNET_CRON_MILLISECONDS);
- CHECK (lastEvent != GNUNET_FSUI_unindex_error);
- if (GNUNET_shutdown_test () == GNUNET_YES)
- break;
- }
- CHECK (lastEvent == GNUNET_FSUI_unindex_completed);
- /* END OF TEST CODE */
-FAILURE:
- if (ctx != NULL)
- {
- if (unindex != NULL)
- GNUNET_FSUI_unindex_stop (unindex);
- if (download != NULL)
- GNUNET_FSUI_download_stop (download);
- if (search != NULL)
- GNUNET_FSUI_search_stop (search);
- GNUNET_FSUI_stop (ctx);
- }
- if (fn != NULL)
- {
- UNLINK (fn);
- GNUNET_free (fn);
- }
- if (uri != NULL)
- GNUNET_ECRS_uri_destroy (uri);
- if (kuri != NULL)
- GNUNET_ECRS_uri_destroy (kuri);
- fn = makeName (43);
- /* TODO: verify file 'fn(42)' == file 'fn(43)' */
- UNLINK (fn);
- GNUNET_free (fn);
- if (upURI != NULL)
- GNUNET_ECRS_uri_destroy (upURI);
-
-#if START_DAEMON
- GNUNET_GE_BREAK (NULL, GNUNET_OK == GNUNET_daemon_stop (NULL, daemon));
-#endif
- GNUNET_GC_free (cfg);
- return (ok == GNUNET_YES) ? 0 : 1;
-}
-
-/* end of downloadtest.c */
Modified: GNUnet/src/applications/fs/fsui/fsui.c
===================================================================
--- GNUnet/src/applications/fs/fsui/fsui.c 2008-05-11 22:33:29 UTC (rev
6800)
+++ GNUnet/src/applications/fs/fsui/fsui.c 2008-05-12 04:05:54 UTC (rev
6801)
@@ -694,6 +694,7 @@
{
GNUNET_ECRS_file_download_partial_stop (res->test_download);
res->test_download = NULL;
+ ctx->active_probes--;
}
res = res->next;
}
Copied: GNUnet/src/applications/fs/fsui/fsui_start_stop_test.c (from rev 6789,
GNUnet/src/applications/fs/fsui/fsuitest2.c)
===================================================================
--- GNUnet/src/applications/fs/fsui/fsui_start_stop_test.c
(rev 0)
+++ GNUnet/src/applications/fs/fsui/fsui_start_stop_test.c 2008-05-12
04:05:54 UTC (rev 6801)
@@ -0,0 +1,89 @@
+/*
+ This file is part of GNUnet.
+ (C) 2004, 2005, 2006 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/fsui/fsui_start_stop_test.c
+ * @brief testcase for fsui (start-stop only)
+ * @author Christian Grothoff
+ */
+
+#include "platform.h"
+#include "gnunet_util.h"
+#include "gnunet_fsui_lib.h"
+
+#define CHECK(a) if (!(a)) { ok = GNUNET_NO; GNUNET_GE_BREAK(NULL, 0); goto
FAILURE; }
+
+
+static struct GNUNET_FSUI_Context *ctx;
+
+static void *
+eventCallback (void *cls, const GNUNET_FSUI_Event * event)
+{
+ return NULL;
+}
+
+#define START_DAEMON 1
+
+int
+main (int argc, char *argv[])
+{
+#if START_DAEMON
+ pid_t daemon;
+#endif
+ int ok;
+ struct GNUNET_GC_Configuration *cfg;
+
+ 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,
+ 60 * GNUNET_CRON_SECONDS));
+#endif
+ ok = GNUNET_YES;
+ GNUNET_thread_sleep (5 * GNUNET_CRON_SECONDS); /* give apps time to
start */
+
+ /* ACTUAL TEST CODE */
+ ctx = GNUNET_FSUI_start (NULL, cfg, "fsui_start_stop_test", 32, GNUNET_YES,
/* do resume! */
+ &eventCallback, NULL);
+ CHECK (ctx != NULL);
+ GNUNET_FSUI_stop (ctx);
+ ctx =
+ GNUNET_FSUI_start (NULL, cfg, "fsui_start_stop_test", 32, GNUNET_YES,
&eventCallback,
+ NULL);
+ CHECK (ctx != NULL);
+FAILURE:
+ if (ctx != NULL)
+ GNUNET_FSUI_stop (ctx);
+#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 fsui_start_stop_test.c */
Deleted: GNUnet/src/applications/fs/fsui/fsuitest.c
===================================================================
--- GNUnet/src/applications/fs/fsui/fsuitest.c 2008-05-11 22:33:29 UTC (rev
6800)
+++ GNUnet/src/applications/fs/fsui/fsuitest.c 2008-05-12 04:05:54 UTC (rev
6801)
@@ -1,228 +0,0 @@
-/*
- This file is part of GNUnet.
- (C) 2004, 2005, 2006 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/fsui/fsuitest.c
- * @brief testcase for fsui (upload-download)
- * @author Christian Grothoff
- */
-
-#include "platform.h"
-#include "gnunet_util.h"
-#include "gnunet_fsui_lib.h"
-
-#define DEBUG_VERBOSE GNUNET_NO
-
-#define CHECK(a) if (!(a)) { ok = GNUNET_NO; GNUNET_GE_BREAK(NULL, 0); goto
FAILURE; }
-
-static char *
-makeName (unsigned int i)
-{
- char *fn;
-
- fn =
- GNUNET_malloc (strlen ("/tmp/gnunet-fsui-serializetest/FSUITEST") + 14);
- GNUNET_snprintf (fn, strlen ("/tmp/gnunet-fsui-test/FSUITEST") + 14,
- "/tmp/gnunet-fsui-test/FSUITEST%u", i);
- GNUNET_disk_directory_create_for_file (NULL, fn);
- return fn;
-}
-
-static volatile enum GNUNET_FSUI_EventType lastEvent;
-
-static struct GNUNET_FSUI_Context *ctx;
-
-static struct GNUNET_FSUI_DownloadList *download;
-
-static void *
-eventCallback (void *cls, const GNUNET_FSUI_Event * event)
-{
- static char unused;
- char *fn;
-
- switch (event->type)
- {
- case GNUNET_FSUI_search_resumed:
- case GNUNET_FSUI_download_resumed:
- case GNUNET_FSUI_upload_resumed:
- case GNUNET_FSUI_unindex_resumed:
- return &unused;
- case GNUNET_FSUI_search_result:
-#if DEBUG_VERBOSE
- printf ("Received search result\n");
-#endif
- fn = makeName (43);
- download = GNUNET_FSUI_download_start (ctx,
- 0,
- GNUNET_NO,
- event->data.SearchResult.fi.uri,
- event->data.SearchResult.fi.meta,
- fn, NULL, NULL);
- GNUNET_free (fn);
- break;
- case GNUNET_FSUI_upload_completed:
-#if DEBUG_VERBOSE
- printf ("Upload complete.\n");
-#endif
- break;
- case GNUNET_FSUI_download_completed:
-#if DEBUG_VERBOSE
- printf ("Download complete.\n");
-#endif
- break;
- case GNUNET_FSUI_unindex_completed:
-#if DEBUG_VERBOSE
- printf ("Unindex complete.\n");
-#endif
- break;
- default:
- break;
- }
- lastEvent = event->type;
- return NULL;
-}
-
-#define START_DAEMON 1
-
-int
-main (int argc, char *argv[])
-{
-#if START_DAEMON
- pid_t daemon;
-#endif
- int ok;
- struct GNUNET_ECRS_URI *uri;
- char *filename = NULL;
- char *keywords[] = {
- "fsui_foo",
- "fsui_bar",
- };
- char keyword[40];
- int prog;
- struct GNUNET_ECRS_MetaData *meta;
- struct GNUNET_ECRS_URI *kuri;
- struct GNUNET_GC_Configuration *cfg;
- struct GNUNET_FSUI_UploadList *upload;
- struct GNUNET_FSUI_SearchList *search;
- struct GNUNET_FSUI_UnindexList *unindex;
-
- 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,
- 60 * GNUNET_CRON_SECONDS));
-#endif
- GNUNET_thread_sleep (5 * GNUNET_CRON_SECONDS); /* give apps time to
start */
- ok = GNUNET_YES;
-
- /* ACTUAL TEST CODE */
- ctx = GNUNET_FSUI_start (NULL, cfg, "fsuitest", 32, /* thread pool size */
- GNUNET_NO, /* no resume */
- &eventCallback, NULL);
- CHECK (ctx != NULL);
- filename = makeName (42);
- GNUNET_disk_file_write (NULL,
- filename,
- "foo bar test!", strlen ("foo bar test!"), "600");
- meta = GNUNET_ECRS_meta_data_create ();
- kuri =
- GNUNET_ECRS_keyword_command_line_to_uri (NULL, 2,
- (const char **) keywords);
- upload = GNUNET_FSUI_upload_start (ctx, filename,
(GNUNET_FSUI_DirectoryScanCallback) & GNUNET_disk_directory_scan, NULL, 0, /*
anonymity */
- 0, /* priority */
- GNUNET_YES,
- GNUNET_NO,
- GNUNET_NO,
- GNUNET_get_time () +
- 5 * GNUNET_CRON_HOURS, meta, kuri, kuri);
- CHECK (upload != NULL);
- GNUNET_ECRS_uri_destroy (kuri);
- GNUNET_ECRS_meta_data_destroy (meta);
- prog = 0;
- while (lastEvent != GNUNET_FSUI_upload_completed)
- {
- prog++;
- CHECK (prog <
- 10000) GNUNET_thread_sleep (50 * GNUNET_CRON_MILLISECONDS);
- if (GNUNET_shutdown_test () == GNUNET_YES)
- break;
- }
- GNUNET_snprintf (keyword, 40, "%s %s %s", keywords[0], _("AND"),
- keywords[1]);
- uri = GNUNET_ECRS_keyword_string_to_uri (NULL, keyword);
- search = GNUNET_FSUI_search_start (ctx, 0, uri);
- GNUNET_ECRS_uri_destroy (uri);
- CHECK (search != NULL);
- prog = 0;
- while (lastEvent != GNUNET_FSUI_download_completed)
- {
- prog++;
- CHECK (prog < 10000);
- GNUNET_thread_sleep (50 * GNUNET_CRON_MILLISECONDS);
- if (GNUNET_shutdown_test () == GNUNET_YES)
- break;
- }
- GNUNET_FSUI_search_abort (search);
- GNUNET_FSUI_search_stop (search);
- unindex = GNUNET_FSUI_unindex_start (ctx, filename);
- prog = 0;
- while (lastEvent != GNUNET_FSUI_unindex_completed)
- {
- prog++;
- CHECK (prog < 10000);
- GNUNET_thread_sleep (50 * GNUNET_CRON_MILLISECONDS);
- if (GNUNET_shutdown_test () == GNUNET_YES)
- break;
- }
- if (lastEvent != GNUNET_FSUI_unindex_completed)
- GNUNET_FSUI_unindex_abort (unindex);
- GNUNET_FSUI_unindex_stop (unindex);
-
-
- /* END OF TEST CODE */
-FAILURE:
- if (ctx != NULL)
- GNUNET_FSUI_stop (ctx);
- if (filename != NULL)
- {
- UNLINK (filename);
- GNUNET_free (filename);
- }
- filename = makeName (43);
- /* TODO: verify file 'filename(42)' == file 'filename(43)' */
- UNLINK (filename);
- GNUNET_free (filename);
-
-#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 fsuitest.c */
Deleted: GNUnet/src/applications/fs/fsui/fsuitest2.c
===================================================================
--- GNUnet/src/applications/fs/fsui/fsuitest2.c 2008-05-11 22:33:29 UTC (rev
6800)
+++ GNUnet/src/applications/fs/fsui/fsuitest2.c 2008-05-12 04:05:54 UTC (rev
6801)
@@ -1,89 +0,0 @@
-/*
- This file is part of GNUnet.
- (C) 2004, 2005, 2006 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/fsui/fsuitest2.c
- * @brief testcase for fsui (upload-download)
- * @author Christian Grothoff
- */
-
-#include "platform.h"
-#include "gnunet_util.h"
-#include "gnunet_fsui_lib.h"
-
-#define CHECK(a) if (!(a)) { ok = GNUNET_NO; GNUNET_GE_BREAK(NULL, 0); goto
FAILURE; }
-
-
-static struct GNUNET_FSUI_Context *ctx;
-
-static void *
-eventCallback (void *cls, const GNUNET_FSUI_Event * event)
-{
- return NULL;
-}
-
-#define START_DAEMON 1
-
-int
-main (int argc, char *argv[])
-{
-#if START_DAEMON
- pid_t daemon;
-#endif
- int ok;
- struct GNUNET_GC_Configuration *cfg;
-
- 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,
- 60 * GNUNET_CRON_SECONDS));
-#endif
- ok = GNUNET_YES;
- GNUNET_thread_sleep (5 * GNUNET_CRON_SECONDS); /* give apps time to
start */
-
- /* ACTUAL TEST CODE */
- ctx = GNUNET_FSUI_start (NULL, cfg, "fsuitest2", 32, GNUNET_YES, /* do
resume! */
- &eventCallback, NULL);
- CHECK (ctx != NULL);
- GNUNET_FSUI_stop (ctx);
- ctx =
- GNUNET_FSUI_start (NULL, cfg, "fsuitest2", 32, GNUNET_YES, &eventCallback,
- NULL);
- CHECK (ctx != NULL);
-FAILURE:
- if (ctx != NULL)
- GNUNET_FSUI_stop (ctx);
-#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 fsuitest2.c */
Copied: GNUnet/src/applications/fs/fsui/recursive_download_persistence_test.c
(from rev 6789, GNUnet/src/applications/fs/fsui/serializetest4.c)
===================================================================
--- GNUnet/src/applications/fs/fsui/recursive_download_persistence_test.c
(rev 0)
+++ GNUnet/src/applications/fs/fsui/recursive_download_persistence_test.c
2008-05-12 04:05:54 UTC (rev 6801)
@@ -0,0 +1,426 @@
+/*
+ This file is part of GNUnet.
+ (C) 2004, 2005, 2006 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/fsui/recursive_download_persistence_test.c
+ * @brief testcase for fsui download persistence for recursive
+ * download
+ * @author Christian Grothoff
+ */
+
+#include "platform.h"
+#include "gnunet_util.h"
+#include "gnunet_fsui_lib.h"
+
+#define DEBUG_VERBOSE GNUNET_NO
+
+#define UPLOAD_PREFIX "/tmp/gnunet-fsui-recursive_download_persistence_test"
+
+#define CHECK(a) if (!(a)) { ok = GNUNET_NO; GNUNET_GE_BREAK(ectx, 0); goto
FAILURE; }
+
+static struct GNUNET_GE_Context *ectx;
+
+static char *
+makeName (unsigned int i)
+{
+ char *fn;
+
+ fn = GNUNET_malloc (strlen (UPLOAD_PREFIX "/FSUITEST") + 14);
+ GNUNET_snprintf (fn,
+ strlen (UPLOAD_PREFIX "/FSUITEST") + 14,
+ UPLOAD_PREFIX "/FSUITEST%u", i);
+ GNUNET_disk_directory_create_for_file (NULL, fn);
+ return fn;
+}
+
+static struct GNUNET_FSUI_Context *ctx;
+static struct GNUNET_ECRS_URI *upURI;
+static struct GNUNET_FSUI_DownloadList *download;
+static int have_error;
+
+/**
+ * Set to 1 if we are about to stop the search and
+ * thus our simple tests for download event correctness
+ * would not work correctly.
+ */
+static int no_check;
+
+static void *
+eventCallback (void *cls, const GNUNET_FSUI_Event * event)
+{
+ if (no_check)
+ return NULL;
+ switch (event->type)
+ {
+ case GNUNET_FSUI_download_suspended:
+ if (event->data.DownloadSuspended.dc.spos != NULL)
+ {
+ fprintf (stderr,
+ "Download suspended but search reference not set
correctly.\n");
+ have_error = 1;
+ }
+ if ((event->data.DownloadSuspended.dc.pos == download) &&
+ (event->data.DownloadSuspended.dc.ppos != NULL))
+ {
+ fprintf (stderr,
+ "Download suspended but parent reference not set to
NULL.\n");
+ have_error = 1;
+ }
+ if ((event->data.DownloadSuspended.dc.pos != download) &&
+ (event->data.DownloadSuspended.dc.ppos != download))
+ {
+ fprintf (stderr,
+ "Download suspended but parent reference not set correctly
(%p instead of %p).\n",
+ event->data.DownloadSuspended.dc.ppos, download);
+ have_error = 1;
+ }
+ if (event->data.DownloadSuspended.dc.pos == download)
+ download = NULL;
+ break;
+ case GNUNET_FSUI_download_resumed:
+ if (download == NULL)
+ download = event->data.DownloadResumed.dc.pos;
+ if (event->data.DownloadResumed.dc.spos != NULL)
+ {
+ fprintf (stderr,
+ "Download resuming but search reference not set
correctly.\n");
+ have_error = 1;
+ }
+ if ((event->data.DownloadResumed.dc.pos == download) &&
+ (event->data.DownloadResumed.dc.ppos != NULL))
+ {
+ fprintf (stderr,
+ "Download resuming but parent reference not set to
NULL.\n");
+ have_error = 1;
+ }
+ if ((event->data.DownloadResumed.dc.pos != download) &&
+ (event->data.DownloadResumed.dc.ppos != download))
+ {
+ fprintf (stderr,
+ "Download resuming but parent reference not set
correctly.\n");
+ have_error = 1;
+ }
+#if DEBUG_VERBOSE
+ printf ("Download resuming\n");
+#endif
+ break;
+ case GNUNET_FSUI_upload_progress:
+#if DEBUG_VERBOSE
+ printf ("Upload is progressing (%llu/%llu)...\n",
+ event->data.UploadProgress.completed,
+ event->data.UploadProgress.total);
+#endif
+ break;
+ case GNUNET_FSUI_upload_completed:
+ if (upURI != NULL)
+ GNUNET_ECRS_uri_destroy (upURI);
+ upURI = GNUNET_ECRS_uri_duplicate (event->data.UploadCompleted.uri);
+#if DEBUG_VERBOSE
+ printf ("Upload complete.\n");
+#endif
+ break;
+ case GNUNET_FSUI_download_completed:
+ if (event->data.DownloadCompleted.dc.spos != NULL)
+ {
+ fprintf (stderr,
+ "Download completed but search reference not set
correctly.\n");
+ have_error = 1;
+ }
+ if ((event->data.DownloadCompleted.dc.pos == download) &&
+ (event->data.DownloadCompleted.dc.ppos != NULL))
+ {
+ fprintf (stderr,
+ "Download completed but parent reference not set to
NULL.\n");
+ have_error = 1;
+ }
+ if ((event->data.DownloadCompleted.dc.pos != download) &&
+ (event->data.DownloadCompleted.dc.ppos != download))
+ {
+ fprintf (stderr,
+ "Download completed but parent reference not set
correctly.\n");
+ have_error = 1;
+ }
+#if DEBUG_VERBOSE
+ printf ("Download complete.\n");
+#endif
+ break;
+ case GNUNET_FSUI_download_progress:
+ if (event->data.DownloadResumed.dc.spos != NULL)
+ {
+ fprintf (stderr,
+ "Download progressing but search reference not set
correctly.\n");
+ have_error = 1;
+ }
+ if ((event->data.DownloadResumed.dc.pos == download) &&
+ (event->data.DownloadResumed.dc.ppos != NULL))
+ {
+ fprintf (stderr,
+ "Download progressing but parent reference not set to
NULL.\n");
+ have_error = 1;
+ }
+ if ((event->data.DownloadResumed.dc.pos != download) &&
+ (event->data.DownloadResumed.dc.ppos != download))
+ {
+ fprintf (stderr,
+ "Download progressing but parent reference not set
correctly.\n");
+ have_error = 1;
+ }
+#if DEBUG_VERBOSE
+ printf ("Download is progressing (%llu/%llu)...\n",
+ event->data.DownloadProgress.completed,
+ event->data.DownloadProgress.total);
+#endif
+ break;
+ case GNUNET_FSUI_unindex_progress:
+#if DEBUG_VERBOSE
+ printf ("Unindex is progressing (%llu/%llu)...\n",
+ event->data.UnindexProgress.completed,
+ event->data.UnindexProgress.total);
+#endif
+ break;
+ case GNUNET_FSUI_unindex_completed:
+#if DEBUG_VERBOSE
+ printf ("Unindex complete.\n");
+#endif
+ break;
+ case GNUNET_FSUI_unindex_error:
+ case GNUNET_FSUI_upload_error:
+ case GNUNET_FSUI_download_error:
+ fprintf (stderr, "Received ERROR: %d\n", event->type);
+ GNUNET_GE_BREAK (ectx, 0);
+ break;
+ case GNUNET_FSUI_download_aborted:
+#if DEBUG_VERBOSE
+ printf ("Received download aborted event.\n");
+#endif
+ break;
+ case GNUNET_FSUI_unindex_suspended:
+ case GNUNET_FSUI_upload_suspended:
+#if DEBUG_VERBOSE
+ fprintf (stderr, "Received SUSPENDING: %d\n", event->type);
+#endif
+ break;
+ case GNUNET_FSUI_download_started:
+ if (download == NULL)
+ download = event->data.DownloadStarted.dc.pos;
+ if (event->data.DownloadStarted.dc.spos != NULL)
+ {
+ fprintf (stderr,
+ "Download started but search reference not set
correctly.\n");
+ have_error = 1;
+ }
+ if ((event->data.DownloadStarted.dc.pos == download) &&
+ (event->data.DownloadStarted.dc.ppos != NULL))
+ {
+ fprintf (stderr,
+ "Download started but parent reference not set to NULL.\n");
+ have_error = 1;
+ }
+ if ((event->data.DownloadStarted.dc.pos != download) &&
+ (event->data.DownloadStarted.dc.ppos != download))
+ {
+ fprintf (stderr,
+ "Download started but parent reference not set
correctly.\n");
+ have_error = 1;
+ }
+ break;
+ case GNUNET_FSUI_download_stopped:
+ if (event->data.DownloadStopped.dc.spos != NULL)
+ {
+ fprintf (stderr,
+ "Download stopped but search reference not set
correctly.\n");
+ have_error = 1;
+ }
+ if ((event->data.DownloadStopped.dc.pos == download) &&
+ (event->data.DownloadStopped.dc.ppos != NULL))
+ {
+ fprintf (stderr,
+ "Download stopped but parent reference not set to NULL.\n");
+ have_error = 1;
+ }
+ if ((event->data.DownloadStopped.dc.pos != download) &&
+ (event->data.DownloadStopped.dc.ppos != download))
+ {
+ fprintf (stderr,
+ "Download stopped but parent reference not set
correctly.\n");
+ have_error = 1;
+ }
+ break;
+ case GNUNET_FSUI_upload_started:
+ case GNUNET_FSUI_upload_stopped:
+ case GNUNET_FSUI_search_started:
+ case GNUNET_FSUI_search_aborted:
+ case GNUNET_FSUI_search_stopped:
+ case GNUNET_FSUI_unindex_started:
+ case GNUNET_FSUI_unindex_stopped:
+ break;
+ default:
+ printf ("Unexpected event: %d\n", event->type);
+ break;
+ }
+ return NULL;
+}
+
+#define FILESIZE (1024)
+
+#define START_DAEMON 1
+
+int
+main (int argc, char *argv[])
+{
+#if START_DAEMON
+ pid_t daemon;
+#endif
+ int ok;
+ int i;
+ int j;
+ struct GNUNET_ECRS_URI *uri = NULL;
+ char *fn = NULL;
+ char *keywords[] = {
+ "down_foo",
+ "down_bar",
+ };
+ char keyword[40];
+ int prog;
+ char *buf;
+ struct GNUNET_ECRS_MetaData *meta;
+ struct GNUNET_ECRS_URI *kuri = NULL;
+ struct GNUNET_GC_Configuration *cfg;
+ struct GNUNET_FSUI_UnindexList *unindex = NULL;
+ struct GNUNET_FSUI_UploadList *upload = NULL;
+ int suspendRestart = 0;
+
+
+ ok = GNUNET_YES;
+ 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 */
+ /* ACTUAL TEST CODE */
+#endif
+ ctx = GNUNET_FSUI_start (NULL,
+ cfg, "recursive_download_persistence_test", 32,
GNUNET_YES,
+ &eventCallback, NULL);
+ CHECK (ctx != NULL);
+ for (j = 4; j < 16; j += 4)
+ {
+ fn = makeName (j);
+ buf = GNUNET_malloc (FILESIZE * j);
+ for (i = 0; i < FILESIZE; i++)
+ buf[i] = GNUNET_random_u32 (GNUNET_RANDOM_QUALITY_WEAK, 256);
+ GNUNET_disk_file_write (ectx, fn, buf, FILESIZE, "600");
+ GNUNET_free (buf);
+ GNUNET_free (fn);
+ }
+ meta = GNUNET_ECRS_meta_data_create ();
+ kuri =
+ GNUNET_ECRS_keyword_command_line_to_uri (ectx, 2,
+ (const char **) keywords);
+ GNUNET_ECRS_meta_data_insert (meta, EXTRACTOR_MIMETYPE,
+ GNUNET_DIRECTORY_MIME);
+ upload =
+ GNUNET_FSUI_upload_start (ctx, UPLOAD_PREFIX,
+ (GNUNET_FSUI_DirectoryScanCallback) &
+ GNUNET_disk_directory_scan, NULL, 0, 0,
+ GNUNET_YES, GNUNET_NO, GNUNET_NO,
+ GNUNET_get_time () + 5 * GNUNET_CRON_HOURS,
+ meta, kuri, kuri);
+ CHECK (upload != NULL);
+ GNUNET_ECRS_uri_destroy (kuri);
+ kuri = NULL;
+ GNUNET_FSUI_upload_stop (upload);
+ CHECK (upURI != NULL);
+ GNUNET_snprintf (keyword, 40, "+%s +%s", keywords[0], keywords[1]);
+ uri = GNUNET_ECRS_keyword_string_to_uri (ectx, keyword);
+ download = GNUNET_FSUI_download_start (ctx,
+ 0,
+ GNUNET_YES,
+ upURI,
+ meta, UPLOAD_PREFIX "-download",
+ NULL, NULL);
+ GNUNET_ECRS_meta_data_destroy (meta);
+ prog = 0;
+ suspendRestart = 10;
+ while (prog < 100)
+ {
+ prog++;
+ GNUNET_thread_sleep (50 * GNUNET_CRON_MILLISECONDS);
+ if ((suspendRestart > 0)
+ && (GNUNET_random_u32 (GNUNET_RANDOM_QUALITY_WEAK, 10) == 0))
+ {
+#if 1
+#if DEBUG_VERBOSE
+ printf ("Testing FSUI suspend-resume\n");
+#endif
+ GNUNET_FSUI_stop (ctx); /* download possibly incomplete
+ at this point, thus testing resume
*/
+ CHECK (download == NULL);
+ ctx = GNUNET_FSUI_start (NULL,
+ cfg,
+ "recursive_download_persistence_test", 32,
GNUNET_YES,
+ &eventCallback, NULL);
+#if DEBUG_VERBOSE
+ printf ("Resumed...\n");
+#endif
+#endif
+ suspendRestart--;
+ }
+ if (GNUNET_shutdown_test () == GNUNET_YES)
+ break;
+ }
+ GNUNET_FSUI_download_stop (download);
+ for (j = 4; j < 16; j += 4)
+ {
+ fn = makeName (j);
+ unindex = GNUNET_FSUI_unindex_start (ctx, fn);
+ GNUNET_FSUI_unindex_stop (unindex);
+ UNLINK (fn);
+ GNUNET_free (fn);
+ }
+ /* END OF TEST CODE */
+FAILURE:
+ if (ctx != NULL)
+ GNUNET_FSUI_stop (ctx);
+ if (uri != NULL)
+ GNUNET_ECRS_uri_destroy (uri);
+ if (kuri != NULL)
+ GNUNET_ECRS_uri_destroy (kuri);
+ if (upURI != NULL)
+ GNUNET_ECRS_uri_destroy (upURI);
+
+#if START_DAEMON
+ GNUNET_GE_BREAK (NULL, GNUNET_OK == GNUNET_daemon_stop (NULL, daemon));
+#endif
+ GNUNET_GC_free (cfg);
+ if (have_error)
+ ok = GNUNET_NO;
+ return (ok == GNUNET_YES) ? 0 : 1;
+}
+
+/* end of recursive_download_persistence_test.c */
Copied: GNUnet/src/applications/fs/fsui/recursive_download_test.c (from rev
6789, GNUnet/src/applications/fs/fsui/recursivetest.c)
===================================================================
--- GNUnet/src/applications/fs/fsui/recursive_download_test.c
(rev 0)
+++ GNUnet/src/applications/fs/fsui/recursive_download_test.c 2008-05-12
04:05:54 UTC (rev 6801)
@@ -0,0 +1,376 @@
+/*
+ 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/fsui/recursive_download_test.c
+ * @brief testcase for fsui recursive upload-download
+ * @author Christian Grothoff
+ * @author Heikki Lindholm
+ */
+
+#include "platform.h"
+#include "gnunet_util.h"
+#include "gnunet_fsui_lib.h"
+
+#define DEBUG_VERBOSE GNUNET_NO
+
+#define CHECK(a) if (!(a)) { ok = GNUNET_NO; GNUNET_GE_BREAK(ectx, 0); goto
FAILURE; }
+
+#define FILESIZE (1024 * 1024 * 2)
+/* depth-first directory tree d=dir f=file .=end of level*/
+#define DIRECTORY_TREE_SPEC "dddf.f.d"
+
+static struct GNUNET_GE_Context *ectx;
+
+volatile int download_done;
+
+static char *
+makeName (unsigned int i)
+{
+ char *fn;
+
+ fn =
+ GNUNET_malloc (strlen
("/tmp/gnunet-fsui-recursive_download_test/FSUITEST") + 15);
+ GNUNET_snprintf (fn,
+ strlen
("/tmp/gnunet-fsui-recursive_download_test/FSUITEST") + 15,
+ "/tmp/gnunet-fsui-recursive_download_test/FSUITEST%u/", i);
+ return fn;
+}
+
+static int
+makeHierarchyHelper (const char *current, const char *tree, int index,
+ int check)
+{
+ unsigned int fi, i;
+ int done;
+ char *s, *buf;
+
+ fi = 0;
+ done = 0;
+ while (!done && tree[index] != '\0')
+ {
+ s = GNUNET_malloc (strlen (current) + strlen (DIR_SEPARATOR_STR) + 14);
+ GNUNET_snprintf (s, strlen (current) + strlen (DIR_SEPARATOR_STR) + 14,
+ "%s%s%u", current, DIR_SEPARATOR_STR, fi);
+ switch (tree[index++])
+ {
+ case 'd':
+ if (check)
+ {
+ if (GNUNET_disk_directory_test (NULL, s) == GNUNET_NO)
+ {
+ index = -1;
+ done = 1;
+ }
+ }
+ else
+ {
+ GNUNET_disk_directory_create (NULL, s);
+ }
+ if (!done)
+ index = makeHierarchyHelper (s, tree, index, check);
+ break;
+ case 'f':
+ if (check)
+ {
+ /* TODO: compare file contents */
+ if (GNUNET_disk_directory_test (NULL, s) != GNUNET_NO)
+ {
+ index = -1;
+ done = 1;
+ }
+ }
+ else
+ {
+ buf = GNUNET_malloc (FILESIZE);
+ for (i = 0; i < FILESIZE; i++)
+ buf[i] = GNUNET_random_u32 (GNUNET_RANDOM_QUALITY_WEAK, 256);
+ GNUNET_disk_file_write (ectx, s, buf, FILESIZE, "600");
+ GNUNET_free (buf);
+ }
+ break;
+ case '.':
+ done = 1;
+ break;
+ default:
+ break;
+ }
+ GNUNET_free (s);
+ fi++;
+ }
+ return index;
+}
+
+static char *
+makeHierarchy (unsigned int i, const char *tree)
+{
+ char *fn;
+
+ fn = makeName (i);
+ makeHierarchyHelper (fn, tree, 0, 0);
+ return fn;
+}
+
+static int
+checkHierarchy (unsigned int i, const char *tree)
+{
+ char *fn;
+ int res;
+
+ fn = makeName (i);
+ if (GNUNET_disk_directory_test (NULL, fn) != GNUNET_YES)
+ return GNUNET_SYSERR;
+ res = ((makeHierarchyHelper (fn, tree, 0, 1) == -1) ?
+ GNUNET_SYSERR : GNUNET_OK);
+ GNUNET_free (fn);
+ return res;
+}
+
+
+static volatile enum GNUNET_FSUI_EventType lastEvent;
+static volatile enum GNUNET_FSUI_EventType waitForEvent;
+static struct GNUNET_FSUI_Context *ctx;
+static struct GNUNET_ECRS_URI *upURI;
+static struct GNUNET_FSUI_DownloadList *download;
+
+static void *
+eventCallback (void *cls, const GNUNET_FSUI_Event * event)
+{
+ char *fn;
+
+ switch (event->type)
+ {
+ case GNUNET_FSUI_download_suspended:
+ download = NULL;
+ break;
+ case GNUNET_FSUI_download_resumed:
+ download = event->data.DownloadResumed.dc.pos;
+ break;
+ break;
+ case GNUNET_FSUI_upload_progress:
+#if DEBUG_VERBOSE > 1
+ printf ("Upload is progressing (%llu/%llu)...\n",
+ event->data.UploadProgress.completed,
+ event->data.UploadProgress.total);
+#endif
+ break;
+ case GNUNET_FSUI_upload_completed:
+ upURI = GNUNET_ECRS_uri_duplicate (event->data.UploadCompleted.uri);
+#if DEBUG_VERBOSE
+ printf ("Upload of `%s' complete.\n",
+ event->data.UploadCompleted.filename);
+#endif
+ break;
+ case GNUNET_FSUI_download_completed:
+#if DEBUG_VERBOSE
+ printf ("Download of `%s' complete.\n",
+ event->data.DownloadCompleted.filename);
+#endif
+ if (checkHierarchy (43, DIRECTORY_TREE_SPEC) == GNUNET_OK)
+ download_done = 1;
+#if DEBUG_VERBOSE
+ else
+ printf ("Hierarchy check not successful yet...\n");
+#endif
+ break;
+ case GNUNET_FSUI_download_progress:
+#if DEBUG_VERBOSE > 1
+ printf ("Download is progressing (%llu/%llu)...\n",
+ event->data.DownloadProgress.completed,
+ event->data.DownloadProgress.total);
+#endif
+ break;
+ case GNUNET_FSUI_unindex_progress:
+#if DEBUG_VERBOSE > 1
+ printf ("Unindex is progressing (%llu/%llu)...\n",
+ event->data.UnindexProgress.completed,
+ event->data.UnindexProgress.total);
+#endif
+ break;
+ case GNUNET_FSUI_unindex_completed:
+#if DEBUG_VERBOSE
+ printf ("Unindex complete.\n");
+#endif
+ break;
+ case GNUNET_FSUI_unindex_error:
+ fprintf (stderr, "Error unindexing: %s\n",
+ event->data.UnindexError.message);
+ break;
+ case GNUNET_FSUI_upload_error:
+ fprintf (stderr, "Error uploading: %s\n",
+ event->data.UploadError.message);
+ break;
+ case GNUNET_FSUI_download_error:
+ fprintf (stderr, "Error downloading: %s\n",
+ event->data.DownloadError.message);
+ break;
+ case GNUNET_FSUI_download_aborted:
+#if DEBUG_VERBOSE
+ printf ("Received download aborted event.\n");
+#endif
+ break;
+ case GNUNET_FSUI_unindex_suspended:
+ case GNUNET_FSUI_upload_suspended:
+ case GNUNET_FSUI_upload_started:
+ case GNUNET_FSUI_upload_stopped:
+ case GNUNET_FSUI_download_started:
+ case GNUNET_FSUI_download_stopped:
+ case GNUNET_FSUI_unindex_started:
+ case GNUNET_FSUI_unindex_stopped:
+ break;
+ default:
+ printf ("Unexpected event: %d\n", event->type);
+ break;
+ }
+ if (lastEvent == waitForEvent)
+ return NULL; /* ignore all other events */
+ lastEvent = event->type;
+ return NULL;
+}
+
+
+#define START_DAEMON 1
+
+int
+main (int argc, char *argv[])
+{
+#if START_DAEMON
+ pid_t daemon;
+#endif
+ int ok;
+ struct GNUNET_ECRS_URI *uri = NULL;
+ char *fn = NULL;
+ char *fn43 = NULL;
+ char *keywords[] = {
+ "down_foo",
+ "down_bar",
+ };
+ char keyword[40];
+ int prog;
+ struct GNUNET_ECRS_MetaData *meta;
+ struct GNUNET_ECRS_URI *kuri = NULL;
+ struct GNUNET_GC_Configuration *cfg;
+ struct GNUNET_FSUI_UnindexList *unindex = NULL;
+ struct GNUNET_FSUI_UploadList *upload = NULL;
+
+ ok = GNUNET_YES;
+ cfg = GNUNET_GC_create ();
+ if (-1 == GNUNET_GC_parse_configuration (cfg, "check.conf"))
+ {
+ GNUNET_GC_free (cfg);
+ return -1;
+ }
+#if START_DAEMON
+ GNUNET_disk_directory_remove (NULL, "/tmp/gnunet-fsui-test/content/");
+ 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 */
+ /* ACTUAL TEST CODE */
+#endif
+ ctx = GNUNET_FSUI_start (NULL,
+ cfg, "fsuirecursive_download_test", 32, GNUNET_YES,
+ &eventCallback, NULL);
+ CHECK (ctx != NULL);
+ fn = makeHierarchy (42, DIRECTORY_TREE_SPEC);
+ meta = GNUNET_ECRS_meta_data_create ();
+ kuri =
+ GNUNET_ECRS_keyword_command_line_to_uri (ectx, 2,
+ (const char **) keywords);
+ waitForEvent = GNUNET_FSUI_upload_completed;
+ upload = GNUNET_FSUI_upload_start (ctx,
+ fn,
+ (GNUNET_FSUI_DirectoryScanCallback) &
+ GNUNET_disk_directory_scan, NULL, 0, 0,
+ GNUNET_YES, GNUNET_NO, GNUNET_NO,
+ GNUNET_get_time () +
+ 5 * GNUNET_CRON_HOURS, meta, kuri, kuri);
+ CHECK (upload != NULL);
+ GNUNET_ECRS_uri_destroy (kuri);
+ kuri = NULL;
+ prog = 0;
+ while (lastEvent != GNUNET_FSUI_upload_completed)
+ {
+ prog++;
+ CHECK (prog < 5000);
+ GNUNET_thread_sleep (50 * GNUNET_CRON_MILLISECONDS);
+ if (GNUNET_shutdown_test () == GNUNET_YES)
+ break;
+ }
+ GNUNET_FSUI_upload_stop (upload);
+ GNUNET_snprintf (keyword, 40, "+%s +%s", keywords[0], keywords[1]);
+ uri = GNUNET_ECRS_keyword_string_to_uri (ectx, keyword);
+ waitForEvent = GNUNET_FSUI_download_completed;
+
+
+ fn43 = makeName (43);
+ download = GNUNET_FSUI_download_start (ctx,
+ 0,
+ GNUNET_YES,
+ upURI,
+ meta, fn, NULL, NULL);
+ CHECK(download != NULL);
+ GNUNET_free (fn43);
+ fn43 = NULL;
+ prog = 0;
+ while (!download_done)
+ {
+ prog++;
+ CHECK (prog < 5000);
+ GNUNET_thread_sleep (50 * GNUNET_CRON_MILLISECONDS);
+ if (GNUNET_shutdown_test () == GNUNET_YES)
+ break;
+ }
+FAILURE:
+ if (meta != NULL)
+ GNUNET_ECRS_meta_data_destroy (meta);
+ if (ctx != NULL)
+ {
+ if (unindex != NULL)
+ GNUNET_FSUI_unindex_stop (unindex);
+ if (download != NULL)
+ GNUNET_FSUI_download_stop (download);
+ GNUNET_FSUI_stop (ctx);
+ }
+ if (fn != NULL)
+ {
+ GNUNET_disk_directory_remove (NULL, fn);
+ GNUNET_free (fn);
+ }
+ if (uri != NULL)
+ GNUNET_ECRS_uri_destroy (uri);
+ if (kuri != NULL)
+ GNUNET_ECRS_uri_destroy (kuri);
+ fn43 = makeName (43);
+ GNUNET_disk_directory_remove (NULL, fn43);
+ GNUNET_free (fn43);
+ if (upURI != NULL)
+ GNUNET_ECRS_uri_destroy (upURI);
+
+#if START_DAEMON
+ GNUNET_GE_BREAK (NULL, GNUNET_OK == GNUNET_daemon_stop (NULL, daemon));
+#endif
+ GNUNET_GC_free (cfg);
+ return (ok == GNUNET_YES) ? 0 : 1;
+}
+
+/* end of recursive_download_test.c */
Deleted: GNUnet/src/applications/fs/fsui/recursivetest.c
===================================================================
--- GNUnet/src/applications/fs/fsui/recursivetest.c 2008-05-11 22:33:29 UTC
(rev 6800)
+++ GNUnet/src/applications/fs/fsui/recursivetest.c 2008-05-12 04:05:54 UTC
(rev 6801)
@@ -1,414 +0,0 @@
-/*
- 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/fsui/recursivetest.c
- * @brief testcase for fsui recursive upload-download
- * @author Christian Grothoff
- * @author Heikki Lindholm
- */
-
-#include "platform.h"
-#include "gnunet_util.h"
-#include "gnunet_fsui_lib.h"
-
-#define DEBUG_VERBOSE GNUNET_NO
-
-#define CHECK(a) if (!(a)) { ok = GNUNET_NO; GNUNET_GE_BREAK(ectx, 0); goto
FAILURE; }
-
-#define FILESIZE (1024 * 1024 * 2)
-/* depth-first directory tree d=dir f=file .=end of level*/
-#define DIRECTORY_TREE_SPEC "dddf.f.d"
-
-static struct GNUNET_GE_Context *ectx;
-
-volatile int search_done;
-
-static char *
-makeName (unsigned int i)
-{
- char *fn;
-
- fn =
- GNUNET_malloc (strlen ("/tmp/gnunet-fsui-recursivetest/FSUITEST") + 15);
- GNUNET_snprintf (fn,
- strlen ("/tmp/gnunet-fsui-recursivetest/FSUITEST") + 15,
- "/tmp/gnunet-fsui-recursivetest/FSUITEST%u/", i);
- return fn;
-}
-
-static int
-makeHierarchyHelper (const char *current, const char *tree, int index,
- int check)
-{
- unsigned int fi, i;
- int done;
- char *s, *buf;
-
- fi = 0;
- done = 0;
- while (!done && tree[index] != '\0')
- {
- s = GNUNET_malloc (strlen (current) + strlen (DIR_SEPARATOR_STR) + 14);
- GNUNET_snprintf (s, strlen (current) + strlen (DIR_SEPARATOR_STR) + 14,
- "%s%s%u", current, DIR_SEPARATOR_STR, fi);
- switch (tree[index++])
- {
- case 'd':
- if (check)
- {
- if (GNUNET_disk_directory_test (NULL, s) == GNUNET_NO)
- {
- index = -1;
- done = 1;
- }
- }
- else
- {
- GNUNET_disk_directory_create (NULL, s);
- }
- if (!done)
- index = makeHierarchyHelper (s, tree, index, check);
- break;
- case 'f':
- if (check)
- {
- /* TODO: compare file contents */
- if (GNUNET_disk_directory_test (NULL, s) != GNUNET_NO)
- {
- index = -1;
- done = 1;
- }
- }
- else
- {
- buf = GNUNET_malloc (FILESIZE);
- for (i = 0; i < FILESIZE; i++)
- buf[i] = GNUNET_random_u32 (GNUNET_RANDOM_QUALITY_WEAK, 256);
- GNUNET_disk_file_write (ectx, s, buf, FILESIZE, "600");
- GNUNET_free (buf);
- }
- break;
- case '.':
- done = 1;
- break;
- default:
- break;
- }
- GNUNET_free (s);
- fi++;
- }
- return index;
-}
-
-static char *
-makeHierarchy (unsigned int i, const char *tree)
-{
- char *fn;
-
- fn = makeName (i);
- makeHierarchyHelper (fn, tree, 0, 0);
- return fn;
-}
-
-static int
-checkHierarchy (unsigned int i, const char *tree)
-{
- char *fn;
- int res;
-
- fn = makeName (i);
- if (GNUNET_disk_directory_test (NULL, fn) != GNUNET_YES)
- return GNUNET_SYSERR;
- res = ((makeHierarchyHelper (fn, tree, 0, 1) == -1) ?
- GNUNET_SYSERR : GNUNET_OK);
- GNUNET_free (fn);
- return res;
-}
-
-
-static volatile enum GNUNET_FSUI_EventType lastEvent;
-static volatile enum GNUNET_FSUI_EventType waitForEvent;
-static struct GNUNET_FSUI_Context *ctx;
-static struct GNUNET_ECRS_URI *upURI;
-static struct GNUNET_FSUI_SearchList *search;
-static struct GNUNET_FSUI_DownloadList *download;
-
-static void *
-eventCallback (void *cls, const GNUNET_FSUI_Event * event)
-{
- char *fn;
-
- switch (event->type)
- {
- case GNUNET_FSUI_search_suspended:
- search = NULL;
- break;
- case GNUNET_FSUI_download_suspended:
- download = NULL;
- break;
- case GNUNET_FSUI_search_resumed:
- search = event->data.SearchResumed.sc.pos;
- break;
- case GNUNET_FSUI_download_resumed:
- download = event->data.DownloadResumed.dc.pos;
- break;
- case GNUNET_FSUI_search_result:
- if (upURI == NULL)
- break;
- if (download == NULL)
- {
- char *u;
-
- u = GNUNET_ECRS_uri_to_string (event->data.SearchResult.fi.uri);
- if (!GNUNET_ECRS_uri_test_equal
- (upURI, event->data.SearchResult.fi.uri))
- {
-#if DEBUG_VERBOSE && 0
- printf ("Received result for different file: %s.\n", u);
-#endif
- GNUNET_free (u);
- return NULL; /* ignore */
- }
-#if DEBUG_VERBOSE
- printf ("Received search result; download started: %s.\n", u);
-#endif
- GNUNET_free (u);
- fn = makeName (43);
- download = GNUNET_FSUI_download_start (ctx,
- 0,
- GNUNET_YES,
- event->data.SearchResult.fi.
- uri,
- event->data.SearchResult.fi.
- meta, fn, NULL, NULL);
- if (download == NULL)
- {
- GNUNET_GE_BREAK (ectx, 0);
- return NULL;
- }
- GNUNET_free (fn);
- }
- break;
- case GNUNET_FSUI_upload_progress:
-#if DEBUG_VERBOSE > 1
- printf ("Upload is progressing (%llu/%llu)...\n",
- event->data.UploadProgress.completed,
- event->data.UploadProgress.total);
-#endif
- break;
- case GNUNET_FSUI_upload_completed:
- upURI = GNUNET_ECRS_uri_duplicate (event->data.UploadCompleted.uri);
-#if DEBUG_VERBOSE
- printf ("Upload of `%s' complete.\n",
- event->data.UploadCompleted.filename);
-#endif
- break;
- case GNUNET_FSUI_download_completed:
-#if DEBUG_VERBOSE
- printf ("Download of `%s' complete.\n",
- event->data.DownloadCompleted.filename);
-#endif
- if (checkHierarchy (43, DIRECTORY_TREE_SPEC) == GNUNET_OK)
- search_done = 1;
- break;
- case GNUNET_FSUI_download_progress:
-#if DEBUG_VERBOSE > 1
- printf ("Download is progressing (%llu/%llu)...\n",
- event->data.DownloadProgress.completed,
- event->data.DownloadProgress.total);
-#endif
- break;
- case GNUNET_FSUI_unindex_progress:
-#if DEBUG_VERBOSE > 1
- printf ("Unindex is progressing (%llu/%llu)...\n",
- event->data.UnindexProgress.completed,
- event->data.UnindexProgress.total);
-#endif
- break;
- case GNUNET_FSUI_unindex_completed:
-#if DEBUG_VERBOSE
- printf ("Unindex complete.\n");
-#endif
- break;
- case GNUNET_FSUI_unindex_error:
- fprintf (stderr, "Error unindexing: %s\n",
- event->data.UnindexError.message);
- break;
- case GNUNET_FSUI_upload_error:
- fprintf (stderr, "Error uploading: %s\n",
- event->data.UploadError.message);
- break;
- case GNUNET_FSUI_download_error:
- fprintf (stderr, "Error downloading: %s\n",
- event->data.DownloadError.message);
- break;
- case GNUNET_FSUI_download_aborted:
-#if DEBUG_VERBOSE
- printf ("Received download aborted event.\n");
-#endif
- break;
- case GNUNET_FSUI_unindex_suspended:
- case GNUNET_FSUI_upload_suspended:
- case GNUNET_FSUI_upload_started:
- case GNUNET_FSUI_upload_stopped:
- case GNUNET_FSUI_download_started:
- case GNUNET_FSUI_download_stopped:
- case GNUNET_FSUI_search_started:
- case GNUNET_FSUI_search_aborted:
- case GNUNET_FSUI_search_stopped:
- case GNUNET_FSUI_search_update:
- case GNUNET_FSUI_unindex_started:
- case GNUNET_FSUI_unindex_stopped:
- break;
- default:
- printf ("Unexpected event: %d\n", event->type);
- break;
- }
- if (lastEvent == waitForEvent)
- return NULL; /* ignore all other events */
- lastEvent = event->type;
- return NULL;
-}
-
-
-#define START_DAEMON 1
-
-int
-main (int argc, char *argv[])
-{
-#if START_DAEMON
- pid_t daemon;
-#endif
- int ok;
- struct GNUNET_ECRS_URI *uri = NULL;
- char *fn = NULL;
- char *keywords[] = {
- "down_foo",
- "down_bar",
- };
- char keyword[40];
- int prog;
- struct GNUNET_ECRS_MetaData *meta;
- struct GNUNET_ECRS_URI *kuri = NULL;
- struct GNUNET_GC_Configuration *cfg;
- struct GNUNET_FSUI_UnindexList *unindex = NULL;
- struct GNUNET_FSUI_UploadList *upload = NULL;
-
- ok = GNUNET_YES;
- cfg = GNUNET_GC_create ();
- if (-1 == GNUNET_GC_parse_configuration (cfg, "check.conf"))
- {
- GNUNET_GC_free (cfg);
- return -1;
- }
-#if START_DAEMON
- GNUNET_disk_directory_remove (NULL, "/tmp/gnunet-fsui-test/content/");
- 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 */
- /* ACTUAL TEST CODE */
-#endif
- ctx = GNUNET_FSUI_start (NULL,
- cfg, "fsuirecursivetest", 32, GNUNET_YES,
- &eventCallback, NULL);
- CHECK (ctx != NULL);
- fn = makeHierarchy (42, DIRECTORY_TREE_SPEC);
- meta = GNUNET_ECRS_meta_data_create ();
- kuri =
- GNUNET_ECRS_keyword_command_line_to_uri (ectx, 2,
- (const char **) keywords);
- waitForEvent = GNUNET_FSUI_upload_completed;
- upload = GNUNET_FSUI_upload_start (ctx,
- fn,
- (GNUNET_FSUI_DirectoryScanCallback) &
- GNUNET_disk_directory_scan, NULL, 0, 0,
- GNUNET_YES, GNUNET_NO, GNUNET_NO,
- GNUNET_get_time () +
- 5 * GNUNET_CRON_HOURS, meta, kuri, kuri);
- CHECK (upload != NULL);
- GNUNET_ECRS_uri_destroy (kuri);
- kuri = NULL;
- GNUNET_ECRS_meta_data_destroy (meta);
- prog = 0;
- while (lastEvent != GNUNET_FSUI_upload_completed)
- {
- prog++;
- CHECK (prog < 5000);
- GNUNET_thread_sleep (50 * GNUNET_CRON_MILLISECONDS);
- if (GNUNET_shutdown_test () == GNUNET_YES)
- break;
- }
- GNUNET_FSUI_upload_stop (upload);
- GNUNET_snprintf (keyword, 40, "+%s +%s", keywords[0], keywords[1]);
- uri = GNUNET_ECRS_keyword_string_to_uri (ectx, keyword);
- waitForEvent = GNUNET_FSUI_download_completed;
- search = GNUNET_FSUI_search_start (ctx, 0, uri);
- CHECK (search != NULL);
- prog = 0;
- while (!search_done)
- {
- prog++;
- CHECK (prog < 5000);
- GNUNET_thread_sleep (50 * GNUNET_CRON_MILLISECONDS);
- if (GNUNET_shutdown_test () == GNUNET_YES)
- break;
- }
- GNUNET_FSUI_search_abort (search);
- GNUNET_FSUI_search_stop (search);
- search = NULL;
- CHECK (download != NULL);
-FAILURE:
- if (ctx != NULL)
- {
- if (unindex != NULL)
- GNUNET_FSUI_unindex_stop (unindex);
- if (download != NULL)
- GNUNET_FSUI_download_stop (download);
- if (search != NULL)
- GNUNET_FSUI_search_stop (search);
- GNUNET_FSUI_stop (ctx);
- }
- if (fn != NULL)
- {
- GNUNET_disk_directory_remove (NULL, fn);
- GNUNET_free (fn);
- }
- if (uri != NULL)
- GNUNET_ECRS_uri_destroy (uri);
- if (kuri != NULL)
- GNUNET_ECRS_uri_destroy (kuri);
- fn = makeName (43);
- GNUNET_disk_directory_remove (NULL, fn);
- GNUNET_free (fn);
- if (upURI != NULL)
- GNUNET_ECRS_uri_destroy (upURI);
-
-#if START_DAEMON
- GNUNET_GE_BREAK (NULL, GNUNET_OK == GNUNET_daemon_stop (NULL, daemon));
-#endif
- GNUNET_GC_free (cfg);
- return (ok == GNUNET_YES) ? 0 : 1;
-}
-
-/* end of recursivetest.c */
Modified: GNUnet/src/applications/fs/fsui/search.c
===================================================================
--- GNUnet/src/applications/fs/fsui/search.c 2008-05-11 22:33:29 UTC (rev
6800)
+++ GNUnet/src/applications/fs/fsui/search.c 2008-05-12 04:05:54 UTC (rev
6801)
@@ -73,6 +73,7 @@
ctx->ctx->ecb (ctx->ctx->ecbClosure, &event);
}
+void bug() { abort(); }
/**
* Process results found by ECRS.
@@ -112,10 +113,8 @@
sizeof (GNUNET_HashCode))))
{
#if DEBUG_SEARCH
- GNUNET_GE_LOG (ectx,
- GNUNET_GE_DEBUG | GNUNET_GE_REQUEST |
- GNUNET_GE_USER,
- "Received search result that I have seen
before.\n");
+ fprintf(stderr,
+ "Received search result that I have seen before.\n");
#endif
GNUNET_mutex_unlock (pos->lock);
return GNUNET_OK; /* seen before */
@@ -130,6 +129,7 @@
{
GNUNET_GE_BREAK (NULL, 0);
GNUNET_mutex_unlock (pos->lock);
+ bug();
return GNUNET_OK; /* should have matching search */
}
GNUNET_array_append (srl->matchingSearches,
@@ -141,13 +141,27 @@
else
GNUNET_GE_BREAK (NULL, 0);
update = 0;
+#if DEBUG_SEARCH
+ fprintf(stderr,
+ "Received mandatory search result\n");
+#endif
}
else
{
update = 1;
+#if DEBUG_SEARCH
+ fprintf(stderr,
+ "Received optional search result\n");
+#endif
}
if (srl->mandatoryMatchesRemaining == 0)
- processResult (pos, srl, update);
+ {
+#if DEBUG_SEARCH
+ fprintf(stderr,
+ "Passing result to client\n");
+#endif
+ processResult (pos, srl, update);
+ }
GNUNET_mutex_unlock (pos->lock);
return GNUNET_OK;
}
@@ -163,6 +177,7 @@
{
GNUNET_GE_BREAK (NULL, 0);
GNUNET_mutex_unlock (pos->lock);
+ bug();
return GNUNET_OK; /* should have matching search */
}
srl = GNUNET_malloc (sizeof (struct SearchResultList));
@@ -177,11 +192,28 @@
srl->mandatoryMatchesRemaining--;
else
GNUNET_GE_BREAK (NULL, 0);
+#if DEBUG_SEARCH
+ fprintf(stderr,
+ "Received new mandatory result\n");
+#endif
}
+ else
+ {
+#if DEBUG_SEARCH
+ fprintf(stderr,
+ "Received new optional result\n");
+#endif
+ }
srl->next = pos->resultsReceived;
pos->resultsReceived = srl;
if (srl->mandatoryMatchesRemaining == 0)
- processResult (pos, srl, 0);
+ {
+#if DEBUG_SEARCH
+ fprintf(stderr,
+ "Passing new result to client\n");
+#endif
+ processResult (pos, srl, 0);
+ }
GNUNET_mutex_unlock (pos->lock);
return GNUNET_OK;
}
@@ -198,6 +230,12 @@
struct GNUNET_FSUI_SearchList *pos = closure;
struct SearchRecordList *srl;
+#if DEBUG_SEARCH
+ fprintf(stderr,
+ "Starting search for `%s' (%d)\n",
+ keyword,
+ is_mandatory);
+#endif
srl = GNUNET_malloc (sizeof (struct SearchRecordList));
memset (srl, 0, sizeof (struct SearchRecordList));
srl->uri = GNUNET_ECRS_keyword_command_line_to_uri (pos->ctx->ectx,
Copied:
GNUnet/src/applications/fs/fsui/search_linked_download_persistence_test.c (from
rev 6796, GNUnet/src/applications/fs/fsui/serializetest2.c)
===================================================================
--- GNUnet/src/applications/fs/fsui/search_linked_download_persistence_test.c
(rev 0)
+++ GNUnet/src/applications/fs/fsui/search_linked_download_persistence_test.c
2008-05-12 04:05:54 UTC (rev 6801)
@@ -0,0 +1,468 @@
+/*
+ This file is part of GNUnet.
+ (C) 2004, 2005, 2006 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/fsui/search_linked_download_persistence_test.c
+ * @brief testcase for fsui download persistence for recursive
+ * download linked to search
+ * @author Christian Grothoff
+ */
+
+#include "platform.h"
+#include "gnunet_util.h"
+#include "gnunet_fsui_lib.h"
+
+#define DEBUG_VERBOSE GNUNET_NO
+
+#define UPLOAD_PREFIX
"/tmp/gnunet-fsui-search_linked_download_persistence_test"
+
+#define CHECK(a) if (!(a)) { ok = GNUNET_NO; GNUNET_GE_BREAK(ectx, 0); goto
FAILURE; }
+
+static struct GNUNET_GE_Context *ectx;
+
+static char *
+makeName (unsigned int i)
+{
+ char *fn;
+
+ fn = GNUNET_malloc (strlen (UPLOAD_PREFIX "/FSUITEST") + 14);
+ GNUNET_snprintf (fn,
+ strlen (UPLOAD_PREFIX "/FSUITEST") + 14,
+ UPLOAD_PREFIX "/FSUITEST%u", i);
+ GNUNET_disk_directory_create_for_file (NULL, fn);
+ return fn;
+}
+
+static struct GNUNET_FSUI_Context *ctx;
+static struct GNUNET_ECRS_URI *upURI;
+static struct GNUNET_FSUI_SearchList *search;
+static struct GNUNET_FSUI_DownloadList *download;
+static int have_error;
+
+/**
+ * Set to 1 if we are about to stop the search and
+ * thus our simple tests for download event correctness
+ * would not work correctly.
+ */
+static int no_check;
+
+static void *
+eventCallback (void *cls, const GNUNET_FSUI_Event * event)
+{
+ if (no_check)
+ return NULL;
+ switch (event->type)
+ {
+ case GNUNET_FSUI_search_suspended:
+ search = NULL;
+ break;
+ case GNUNET_FSUI_download_suspended:
+ if (event->data.DownloadSuspended.dc.spos != search)
+ {
+ fprintf (stderr,
+ "Download suspended but search reference not set
correctly.\n");
+ have_error = 1;
+ }
+ if ((event->data.DownloadSuspended.dc.pos == download) &&
+ (event->data.DownloadSuspended.dc.ppos != NULL))
+ {
+ fprintf (stderr,
+ "Download suspended but parent reference not set to
NULL.\n");
+ have_error = 1;
+ }
+ if ((event->data.DownloadSuspended.dc.pos != download) &&
+ (event->data.DownloadSuspended.dc.ppos != download))
+ {
+ fprintf (stderr,
+ "Download suspended but parent reference not set correctly
(%p instead of %p).\n",
+ event->data.DownloadSuspended.dc.ppos, download);
+ have_error = 1;
+ }
+ if (event->data.DownloadSuspended.dc.pos == download)
+ download = NULL;
+ break;
+ case GNUNET_FSUI_search_resumed:
+#if DEBUG_VERBOSE
+ printf ("Search resuming\n");
+#endif
+ search = event->data.SearchResumed.sc.pos;
+ break;
+ case GNUNET_FSUI_download_resumed:
+ if (download == NULL)
+ download = event->data.DownloadResumed.dc.pos;
+ if (event->data.DownloadResumed.dc.spos != search)
+ {
+ fprintf (stderr,
+ "Download resuming but search reference not set
correctly.\n");
+ abort();
+ have_error = 1;
+ }
+ if ((event->data.DownloadResumed.dc.pos == download) &&
+ (event->data.DownloadResumed.dc.ppos != NULL))
+ {
+ fprintf (stderr,
+ "Download resuming but parent reference not set to
NULL.\n");
+ have_error = 1;
+ }
+ if ((event->data.DownloadResumed.dc.pos != download) &&
+ (event->data.DownloadResumed.dc.ppos != download))
+ {
+ fprintf (stderr,
+ "Download resuming but parent reference not set
correctly.\n");
+ have_error = 1;
+ }
+#if DEBUG_VERBOSE
+ printf ("Download resuming\n");
+#endif
+ break;
+ case GNUNET_FSUI_search_result:
+#if DEBUG_VERBOSE
+ printf ("Received search result\n");
+#endif
+ break;
+ case GNUNET_FSUI_upload_progress:
+#if DEBUG_VERBOSE
+ printf ("Upload is progressing (%llu/%llu)...\n",
+ event->data.UploadProgress.completed,
+ event->data.UploadProgress.total);
+#endif
+ break;
+ case GNUNET_FSUI_upload_completed:
+ if (upURI != NULL)
+ GNUNET_ECRS_uri_destroy (upURI);
+ upURI = GNUNET_ECRS_uri_duplicate (event->data.UploadCompleted.uri);
+#if DEBUG_VERBOSE
+ printf ("Upload complete.\n");
+#endif
+ break;
+ case GNUNET_FSUI_download_completed:
+ if (event->data.DownloadCompleted.dc.spos != search)
+ {
+ fprintf (stderr,
+ "Download completed but search reference not set
correctly.\n");
+ have_error = 1;
+ }
+ if ((event->data.DownloadCompleted.dc.pos == download) &&
+ (event->data.DownloadCompleted.dc.ppos != NULL))
+ {
+ fprintf (stderr,
+ "Download completed but parent reference not set to
NULL.\n");
+ have_error = 1;
+ }
+ if ((event->data.DownloadCompleted.dc.pos != download) &&
+ (event->data.DownloadCompleted.dc.ppos != download))
+ {
+ fprintf (stderr,
+ "Download completed but parent reference not set
correctly.\n");
+ have_error = 1;
+ }
+#if DEBUG_VERBOSE
+ printf ("Download complete.\n");
+#endif
+ break;
+ case GNUNET_FSUI_download_progress:
+ if (event->data.DownloadResumed.dc.spos != search)
+ {
+ fprintf (stderr,
+ "Download progressing but search reference not set
correctly.\n");
+ have_error = 1;
+ }
+ if ((event->data.DownloadResumed.dc.pos == download) &&
+ (event->data.DownloadResumed.dc.ppos != NULL))
+ {
+ fprintf (stderr,
+ "Download progressing but parent reference not set to
NULL.\n");
+ have_error = 1;
+ }
+ if ((event->data.DownloadResumed.dc.pos != download) &&
+ (event->data.DownloadResumed.dc.ppos != download))
+ {
+ fprintf (stderr,
+ "Download progressing but parent reference not set
correctly.\n");
+ have_error = 1;
+ }
+#if DEBUG_VERBOSE
+ printf ("Download is progressing (%llu/%llu)...\n",
+ event->data.DownloadProgress.completed,
+ event->data.DownloadProgress.total);
+#endif
+ break;
+ case GNUNET_FSUI_unindex_progress:
+#if DEBUG_VERBOSE
+ printf ("Unindex is progressing (%llu/%llu)...\n",
+ event->data.UnindexProgress.completed,
+ event->data.UnindexProgress.total);
+#endif
+ break;
+ case GNUNET_FSUI_unindex_completed:
+#if DEBUG_VERBOSE
+ printf ("Unindex complete.\n");
+#endif
+ break;
+ case GNUNET_FSUI_unindex_error:
+ fprintf (stderr,
+ "Received ERROR: %d %s\n",
+ event->type, event->data.UnindexError.message);
+ GNUNET_GE_BREAK (ectx, 0);
+ break;
+ case GNUNET_FSUI_upload_error:
+ fprintf (stderr,
+ "Received ERROR: %d %s\n",
+ event->type, event->data.UploadError.message);
+ GNUNET_GE_BREAK (ectx, 0);
+ break;
+ case GNUNET_FSUI_download_error:
+ fprintf (stderr,
+ "Received ERROR: %d %s\n",
+ event->type, event->data.DownloadError.message);
+ GNUNET_GE_BREAK (ectx, 0);
+ break;
+ case GNUNET_FSUI_download_aborted:
+#if DEBUG_VERBOSE
+ printf ("Received download aborted event.\n");
+#endif
+ break;
+ case GNUNET_FSUI_unindex_suspended:
+ case GNUNET_FSUI_upload_suspended:
+#if DEBUG_VERBOSE
+ fprintf (stderr, "Received SUSPENDING: %d\n", event->type);
+#endif
+ break;
+ case GNUNET_FSUI_download_started:
+ if (download == NULL)
+ download = event->data.DownloadStarted.dc.pos;
+ if (event->data.DownloadStarted.dc.spos != search)
+ {
+ fprintf (stderr,
+ "Download started but search reference not set
correctly.\n");
+ have_error = 1;
+ }
+ if ((event->data.DownloadStarted.dc.pos == download) &&
+ (event->data.DownloadStarted.dc.ppos != NULL))
+ {
+ fprintf (stderr,
+ "Download started but parent reference not set to NULL.\n");
+ have_error = 1;
+ }
+ if ((event->data.DownloadStarted.dc.pos != download) &&
+ (event->data.DownloadStarted.dc.ppos != download))
+ {
+ fprintf (stderr,
+ "Download started but parent reference not set
correctly.\n");
+ have_error = 1;
+ }
+ break;
+ case GNUNET_FSUI_download_stopped:
+ if (event->data.DownloadStopped.dc.spos != search)
+ {
+ fprintf (stderr,
+ "Download stopped but search reference not set
correctly.\n");
+ have_error = 1;
+ }
+ if ((event->data.DownloadStopped.dc.pos == download) &&
+ (event->data.DownloadStopped.dc.ppos != NULL))
+ {
+ fprintf (stderr,
+ "Download stopped but parent reference not set to NULL.\n");
+ have_error = 1;
+ }
+ if ((event->data.DownloadStopped.dc.pos != download) &&
+ (event->data.DownloadStopped.dc.ppos != download))
+ {
+ fprintf (stderr,
+ "Download stopped but parent reference not set
correctly.\n");
+ have_error = 1;
+ }
+ break;
+ case GNUNET_FSUI_search_update:
+ case GNUNET_FSUI_upload_started:
+ case GNUNET_FSUI_upload_stopped:
+ case GNUNET_FSUI_search_started:
+ case GNUNET_FSUI_search_aborted:
+ case GNUNET_FSUI_search_stopped:
+ case GNUNET_FSUI_unindex_started:
+ case GNUNET_FSUI_unindex_stopped:
+ break;
+ default:
+ printf ("Unexpected event: %d\n", event->type);
+ break;
+ }
+ return NULL;
+}
+
+#define FILESIZE (1024)
+
+#define START_DAEMON 1
+
+int
+main (int argc, char *argv[])
+{
+#if START_DAEMON
+ pid_t daemon;
+#endif
+ int ok;
+ int i;
+ int j;
+ struct GNUNET_ECRS_URI *uri = NULL;
+ char *fn = NULL;
+ char *keywords[] = {
+ "down_foo",
+ "down_bar",
+ };
+ char keyword[40];
+ int prog;
+ char *buf;
+ struct GNUNET_ECRS_MetaData *meta;
+ struct GNUNET_ECRS_URI *kuri = NULL;
+ struct GNUNET_GC_Configuration *cfg;
+ struct GNUNET_FSUI_UnindexList *unindex = NULL;
+ struct GNUNET_FSUI_UploadList *upload = NULL;
+ int suspendRestart = 0;
+
+
+ ok = GNUNET_YES;
+ 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 */
+ /* ACTUAL TEST CODE */
+#endif
+ ctx = GNUNET_FSUI_start (NULL,
+ cfg, "search_linked_download_persistence_test", 32,
GNUNET_YES,
+ &eventCallback, NULL);
+ CHECK (ctx != NULL);
+ for (j = 4; j < 256; j += 4)
+ {
+ fn = makeName (j);
+ buf = GNUNET_malloc (FILESIZE * j);
+ for (i = 0; i < FILESIZE; i++)
+ buf[i] = GNUNET_random_u32 (GNUNET_RANDOM_QUALITY_WEAK, 256);
+ GNUNET_disk_file_write (ectx, fn, buf, FILESIZE, "600");
+ GNUNET_free (buf);
+ GNUNET_free (fn);
+ }
+ meta = GNUNET_ECRS_meta_data_create ();
+ kuri =
+ GNUNET_ECRS_keyword_command_line_to_uri (ectx, 2,
+ (const char **) keywords);
+ GNUNET_ECRS_meta_data_insert (meta, EXTRACTOR_MIMETYPE,
+ GNUNET_DIRECTORY_MIME);
+ upload =
+ GNUNET_FSUI_upload_start (ctx, UPLOAD_PREFIX,
+ (GNUNET_FSUI_DirectoryScanCallback) &
+ GNUNET_disk_directory_scan, NULL, 0, 0,
+ GNUNET_YES, GNUNET_NO, GNUNET_NO,
+ GNUNET_get_time () + 5 * GNUNET_CRON_HOURS,
+ meta, kuri, kuri);
+ CHECK (upload != NULL);
+ GNUNET_ECRS_uri_destroy (kuri);
+ kuri = NULL;
+ GNUNET_FSUI_upload_stop (upload);
+ CHECK (upURI != NULL);
+ GNUNET_snprintf (keyword, 40, "+%s +%s", keywords[0], keywords[1]);
+ uri = GNUNET_ECRS_keyword_string_to_uri (ectx, keyword);
+ search = GNUNET_FSUI_search_start (ctx, 0, uri);
+ CHECK (search != NULL);
+ download = GNUNET_FSUI_download_start (ctx,
+ 0,
+ GNUNET_YES,
+ upURI,
+ meta,
+ UPLOAD_PREFIX "-download", search,
+ NULL);
+ GNUNET_ECRS_meta_data_destroy (meta);
+ prog = 0;
+ suspendRestart = 10;
+ while (prog < 1000)
+ {
+ prog++;
+ GNUNET_thread_sleep (50 * GNUNET_CRON_MILLISECONDS);
+ if ((suspendRestart > 0)
+ && (GNUNET_random_u32 (GNUNET_RANDOM_QUALITY_WEAK, 100) == 0))
+ {
+#if 1
+#if DEBUG_VERBOSE
+ printf ("Testing FSUI suspend-resume\n");
+#endif
+ GNUNET_FSUI_stop (ctx); /* download possibly incomplete
+ at this point, thus testing resume
*/
+ CHECK (search == NULL);
+ CHECK (download == NULL);
+ ctx = GNUNET_FSUI_start (NULL,
+ cfg,
+ "search_linked_download_persistence_test",
32, GNUNET_YES,
+ &eventCallback, NULL);
+#if DEBUG_VERBOSE
+ printf ("Resumed...\n");
+#endif
+#endif
+ suspendRestart--;
+ }
+ if ((search != NULL) && (suspendRestart >= 5))
+ {
+ no_check = 1;
+ GNUNET_thread_sleep (50 * GNUNET_CRON_MILLISECONDS);
+ GNUNET_FSUI_search_abort (search);
+ GNUNET_FSUI_search_stop (search);
+ search = NULL;
+ no_check = 0;
+ }
+ if (GNUNET_shutdown_test () == GNUNET_YES)
+ break;
+ }
+ GNUNET_FSUI_download_stop (download);
+ for (j = 4; j < 256; j += 4)
+ {
+ fn = makeName (j);
+ unindex = GNUNET_FSUI_unindex_start (ctx, fn);
+ GNUNET_FSUI_unindex_stop (unindex);
+ UNLINK (fn);
+ GNUNET_free (fn);
+ }
+ /* END OF TEST CODE */
+FAILURE:
+ if (ctx != NULL)
+ GNUNET_FSUI_stop (ctx);
+ if (uri != NULL)
+ GNUNET_ECRS_uri_destroy (uri);
+ if (kuri != NULL)
+ GNUNET_ECRS_uri_destroy (kuri);
+ if (upURI != NULL)
+ GNUNET_ECRS_uri_destroy (upURI);
+
+#if START_DAEMON
+ GNUNET_GE_BREAK (NULL, GNUNET_OK == GNUNET_daemon_stop (NULL, daemon));
+#endif
+ GNUNET_GC_free (cfg);
+ if (have_error)
+ ok = GNUNET_NO;
+ return (ok == GNUNET_YES) ? 0 : 1;
+}
+
+/* end of search_linked_download_persistence_test.c */
Copied: GNUnet/src/applications/fs/fsui/search_pause_resume_persistence_test.c
(from rev 6789, GNUnet/src/applications/fs/fsui/searchtest.c)
===================================================================
--- GNUnet/src/applications/fs/fsui/search_pause_resume_persistence_test.c
(rev 0)
+++ GNUnet/src/applications/fs/fsui/search_pause_resume_persistence_test.c
2008-05-12 04:05:54 UTC (rev 6801)
@@ -0,0 +1,294 @@
+/*
+ This file is part of GNUnet.
+ (C) 2004, 2005, 2006 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/fsui/search_pause_resume_persistence_test.c
+ * @brief testcase for fsui search persistence, pause and resume
+ * @author Christian Grothoff
+ */
+
+#include "platform.h"
+#include "gnunet_util.h"
+#include "gnunet_fsui_lib.h"
+
+#define CHECK_VERBOSE GNUNET_NO
+
+#define CHECK(a) if (!(a)) { ok = GNUNET_NO; GNUNET_GE_BREAK(NULL, 0); goto
FAILURE; }
+
+static char *
+makeName (unsigned int i)
+{
+ char *fn;
+
+ fn = GNUNET_malloc (strlen
("/tmp/gnunet-fsui-search_pause_resume_persistence_test/FSUITEST") + 14);
+ GNUNET_snprintf (fn,
+ strlen
("/tmp/gnunet-fsui-search_pause_resume_persistence_test/FSUITEST") + 14,
+
"/tmp/gnunet-fsui-search_pause_resume_persistence_test/FSUITEST%u", i);
+ GNUNET_disk_directory_create_for_file (NULL, fn);
+ return fn;
+}
+
+static volatile enum GNUNET_FSUI_EventType lastEvent;
+
+static struct GNUNET_FSUI_SearchList *search;
+
+static struct GNUNET_ECRS_URI *uri;
+
+static struct GNUNET_FSUI_Context *ctx;
+
+static struct GNUNET_Mutex *lock;
+
+static volatile enum GNUNET_FSUI_EventType waitForEvent;
+
+static void *
+eventCallback (void *cls, const GNUNET_FSUI_Event * event)
+{
+ static char unused;
+
+ GNUNET_mutex_lock (lock);
+ switch (event->type)
+ {
+ case GNUNET_FSUI_search_resumed:
+ search = event->data.SearchResumed.sc.pos;
+ break;
+ case GNUNET_FSUI_search_suspended:
+ search = NULL;
+ break;
+ case GNUNET_FSUI_search_paused:
+ case GNUNET_FSUI_search_restarted:
+ break;
+ case GNUNET_FSUI_download_resumed:
+ case GNUNET_FSUI_upload_resumed:
+ case GNUNET_FSUI_unindex_resumed:
+ GNUNET_mutex_unlock (lock);
+ return &unused;
+ case GNUNET_FSUI_search_result:
+#if CHECK_VERBOSE
+ printf ("Received search result\n");
+#endif
+ uri = GNUNET_ECRS_uri_duplicate (event->data.SearchResult.fi.uri);
+ break;
+ case GNUNET_FSUI_upload_completed:
+#if CHECK_VERBOSE
+ printf ("Upload complete.\n");
+#endif
+ break;
+ case GNUNET_FSUI_download_completed:
+#if CHECK_VERBOSE
+ printf ("Download complete.\n");
+#endif
+ break;
+ case GNUNET_FSUI_unindex_completed:
+#if CHECK_VERBOSE
+ printf ("Unindex complete.\n");
+#endif
+ break;
+ case GNUNET_FSUI_upload_error:
+ printf ("Upload error.\n");
+ break;
+ case GNUNET_FSUI_download_error:
+ printf ("Download error.\n");
+ break;
+ case GNUNET_FSUI_unindex_error:
+ printf ("Unindex error.\n");
+ break;
+ default:
+ break;
+ }
+ if (lastEvent != waitForEvent)
+ lastEvent = event->type;
+ GNUNET_mutex_unlock (lock);
+ return NULL;
+}
+
+#define START_DAEMON 1
+
+int
+main (int argc, char *argv[])
+{
+#if START_DAEMON
+ pid_t daemon;
+#endif
+ int ok;
+ char *fn = NULL;
+ char *keywords[] = {
+ "search_foo",
+ "search_bar",
+ };
+ char keyword[40];
+ int prog;
+ struct GNUNET_ECRS_MetaData *meta;
+ struct GNUNET_ECRS_URI *kuri;
+ struct GNUNET_GC_Configuration *cfg;
+ struct GNUNET_FSUI_UploadList *upload;
+ struct GNUNET_FSUI_UnindexList *unindex;
+ struct GNUNET_FSUI_DownloadList *download;
+ struct GNUNET_ECRS_URI *luri;
+
+ ok = GNUNET_YES;
+ cfg = GNUNET_GC_create ();
+ if (-1 == GNUNET_GC_parse_configuration (cfg, "check.conf"))
+ {
+ GNUNET_GC_free (cfg);
+ return -1;
+ }
+#if START_DAEMON
+ GNUNET_disk_directory_remove (NULL,
"/tmp/gnunet-fsui-search_pause_resume_persistence_test/");
+ 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 */
+ /* ACTUAL TEST CODE */
+#endif
+ lock = GNUNET_mutex_create (GNUNET_NO);
+ ctx = GNUNET_FSUI_start (NULL,
+ cfg, "fsuisearch_pause_resume_persistence_test",
32, GNUNET_YES,
+ &eventCallback, NULL);
+ CHECK (ctx != NULL);
+ GNUNET_snprintf (keyword, 40, "+%s +%s", keywords[0], keywords[1]);
+ luri = GNUNET_ECRS_keyword_string_to_uri (NULL, keyword);
+ uri = NULL;
+ search = GNUNET_FSUI_search_start (ctx, 0, luri);
+ GNUNET_ECRS_uri_destroy (luri);
+ CHECK (NULL != search);
+ GNUNET_FSUI_stop (ctx);
+ /* resume search! */
+ ctx = GNUNET_FSUI_start (NULL,
+ cfg, "fsuisearch_pause_resume_persistence_test",
32, GNUNET_YES,
+ &eventCallback, NULL);
+ GNUNET_FSUI_search_pause (search);
+ GNUNET_FSUI_stop (ctx);
+ /* resume search! */
+ ctx = GNUNET_FSUI_start (NULL,
+ cfg, "fsuisearch_pause_resume_persistence_test",
32, GNUNET_YES,
+ &eventCallback, NULL);
+ GNUNET_FSUI_search_restart (search);
+
+ fn = makeName (42);
+ GNUNET_disk_file_write (NULL,
+ fn, "foo bar test!", strlen ("foo bar test!"),
+ "600");
+ meta = GNUNET_ECRS_meta_data_create ();
+ kuri =
+ GNUNET_ECRS_keyword_command_line_to_uri (NULL, 2,
+ (const char **) keywords);
+ waitForEvent = GNUNET_FSUI_upload_completed;
+ upload =
+ GNUNET_FSUI_upload_start (ctx,
+ fn,
+ (GNUNET_FSUI_DirectoryScanCallback) &
+ GNUNET_disk_directory_scan, NULL, 0, 0,
+ GNUNET_YES, GNUNET_NO, GNUNET_NO,
+ GNUNET_get_time () + 5 * GNUNET_CRON_HOURS,
+ meta, kuri, kuri);
+ CHECK (NULL != upload);
+ GNUNET_free (fn);
+ fn = NULL;
+ GNUNET_ECRS_uri_destroy (kuri);
+ GNUNET_ECRS_meta_data_destroy (meta);
+ prog = 0;
+ while (lastEvent != GNUNET_FSUI_upload_completed)
+ {
+ prog++;
+ if (prog == 10000)
+ {
+ fprintf (stderr,
+ "Upload failed to complete -- last event: %u\n",
+ lastEvent);
+ }
+ CHECK (prog < 10000);
+ GNUNET_thread_sleep (50 * GNUNET_CRON_MILLISECONDS);
+ if (GNUNET_shutdown_test () == GNUNET_YES)
+ break;
+ }
+ GNUNET_FSUI_upload_stop (upload);
+ GNUNET_FSUI_search_pause (search);
+ GNUNET_FSUI_search_restart (search);
+ while ((uri == NULL) && (GNUNET_shutdown_test () != GNUNET_YES))
+ {
+ prog++;
+ CHECK (prog < 10000);
+ GNUNET_thread_sleep (50 * GNUNET_CRON_MILLISECONDS);
+ }
+ GNUNET_FSUI_search_abort (search);
+ GNUNET_FSUI_search_stop (search);
+ CHECK (uri != NULL);
+ fn = makeName (43);
+ meta = GNUNET_ECRS_meta_data_create ();
+ waitForEvent = GNUNET_FSUI_download_completed;
+ download =
+ GNUNET_FSUI_download_start (ctx, 0, GNUNET_NO, uri, meta, fn, NULL, NULL);
+ GNUNET_ECRS_meta_data_destroy (meta);
+ GNUNET_free (fn);
+ fn = NULL;
+ GNUNET_ECRS_uri_destroy (uri);
+
+ prog = 0;
+ while (lastEvent != GNUNET_FSUI_download_completed)
+ {
+ prog++;
+ CHECK (prog < 10000);
+ GNUNET_thread_sleep (50 * GNUNET_CRON_MILLISECONDS);
+ if (GNUNET_shutdown_test () == GNUNET_YES)
+ break;
+ }
+ GNUNET_FSUI_download_stop (download);
+ fn = makeName (42);
+ waitForEvent = GNUNET_FSUI_unindex_completed;
+ unindex = GNUNET_FSUI_unindex_start (ctx, fn);
+ GNUNET_free (fn);
+ fn = NULL;
+ CHECK (NULL != unindex);
+ prog = 0;
+ while (lastEvent != GNUNET_FSUI_unindex_completed)
+ {
+ prog++;
+ CHECK (prog < 10000);
+ GNUNET_thread_sleep (50 * GNUNET_CRON_MILLISECONDS);
+ if (GNUNET_shutdown_test () == GNUNET_YES)
+ break;
+ }
+ GNUNET_FSUI_unindex_stop (unindex);
+
+ /* END OF TEST CODE */
+FAILURE:
+ if (ctx != NULL)
+ GNUNET_FSUI_stop (ctx);
+ if (lock != NULL)
+ GNUNET_mutex_destroy (lock);
+ GNUNET_free_non_null (fn);
+ /* TODO: verify file 'fn(42)' == file 'fn(43)' */
+ fn = makeName (42);
+ UNLINK (fn);
+ GNUNET_free (fn);
+ fn = makeName (43);
+ UNLINK (fn);
+ GNUNET_free (fn);
+
+#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 search_pause_resume_persistence_test.c */
Copied: GNUnet/src/applications/fs/fsui/search_persistence_test.c (from rev
6789, GNUnet/src/applications/fs/fsui/serializetest3.c)
===================================================================
--- GNUnet/src/applications/fs/fsui/search_persistence_test.c
(rev 0)
+++ GNUnet/src/applications/fs/fsui/search_persistence_test.c 2008-05-12
04:05:54 UTC (rev 6801)
@@ -0,0 +1,213 @@
+/*
+ This file is part of GNUnet.
+ (C) 2004, 2005, 2006 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/fsui/search_persistence_test.c
+ * @brief testcase for fsui download persistence for search
+ * @author Christian Grothoff
+ */
+
+#include "platform.h"
+#include "gnunet_util.h"
+#include "gnunet_fsui_lib.h"
+
+#define DEBUG_VERBOSE GNUNET_NO
+
+#define UPLOAD_PREFIX "/tmp/gnunet-fsui-search_persistence_test"
+
+#define CHECK(a) if (!(a)) { ok = GNUNET_NO; GNUNET_GE_BREAK(ectx, 0); goto
FAILURE; }
+
+static struct GNUNET_GE_Context *ectx;
+
+static struct GNUNET_FSUI_Context *ctx;
+static struct GNUNET_FSUI_SearchList *search;
+static int have_error;
+
+static void *
+eventCallback (void *cls, const GNUNET_FSUI_Event * event)
+{
+ switch (event->type)
+ {
+ case GNUNET_FSUI_search_suspended:
+ search = NULL;
+ break;
+ case GNUNET_FSUI_search_resumed:
+#if DEBUG_VERBOSE
+ printf ("Search resuming\n");
+#endif
+ search = event->data.SearchResumed.sc.pos;
+ break;
+ case GNUNET_FSUI_search_result:
+#if DEBUG_VERBOSE
+ printf ("Received search result\n");
+#endif
+ break;
+ case GNUNET_FSUI_upload_progress:
+#if DEBUG_VERBOSE
+ printf ("Upload is progressing (%llu/%llu)...\n",
+ event->data.UploadProgress.completed,
+ event->data.UploadProgress.total);
+#endif
+ break;
+ case GNUNET_FSUI_upload_completed:
+#if DEBUG_VERBOSE
+ printf ("Upload complete.\n");
+#endif
+ break;
+ case GNUNET_FSUI_unindex_progress:
+#if DEBUG_VERBOSE
+ printf ("Unindex is progressing (%llu/%llu)...\n",
+ event->data.UnindexProgress.completed,
+ event->data.UnindexProgress.total);
+#endif
+ break;
+ case GNUNET_FSUI_unindex_completed:
+#if DEBUG_VERBOSE
+ printf ("Unindex complete.\n");
+#endif
+ break;
+ case GNUNET_FSUI_unindex_error:
+ case GNUNET_FSUI_upload_error:
+ case GNUNET_FSUI_download_error:
+ fprintf (stderr, "Received ERROR: %d\n", event->type);
+ GNUNET_GE_BREAK (ectx, 0);
+ break;
+ case GNUNET_FSUI_download_aborted:
+#if DEBUG_VERBOSE
+ printf ("Received download aborted event.\n");
+#endif
+ break;
+ case GNUNET_FSUI_unindex_suspended:
+ case GNUNET_FSUI_upload_suspended:
+#if DEBUG_VERBOSE
+ fprintf (stderr, "Received SUSPENDING: %d\n", event->type);
+#endif
+ break;
+ case GNUNET_FSUI_upload_started:
+ case GNUNET_FSUI_upload_stopped:
+ case GNUNET_FSUI_search_started:
+ case GNUNET_FSUI_search_aborted:
+ case GNUNET_FSUI_search_stopped:
+ case GNUNET_FSUI_search_update:
+ case GNUNET_FSUI_unindex_started:
+ case GNUNET_FSUI_unindex_stopped:
+ break;
+ default:
+ printf ("Unexpected event: %d\n", event->type);
+ break;
+ }
+ return NULL;
+}
+
+#define FILESIZE (1024)
+
+#define START_DAEMON 1
+
+int
+main (int argc, char *argv[])
+{
+#if START_DAEMON
+ pid_t daemon;
+#endif
+ int ok;
+ struct GNUNET_ECRS_URI *uri = NULL;
+ char *keywords[] = {
+ "down_foo",
+ "down_bar",
+ };
+ char keyword[40];
+ int prog;
+ struct GNUNET_GC_Configuration *cfg;
+ int suspendRestart = 0;
+
+
+ ok = GNUNET_YES;
+ 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 */
+ /* ACTUAL TEST CODE */
+#endif
+ ctx = GNUNET_FSUI_start (NULL,
+ cfg, "search_persistence_test", 32, GNUNET_YES,
+ &eventCallback, NULL);
+ CHECK (ctx != NULL);
+ GNUNET_snprintf (keyword, 40, "+%s +%s", keywords[0], keywords[1]);
+ uri = GNUNET_ECRS_keyword_string_to_uri (ectx, keyword);
+ search = GNUNET_FSUI_search_start (ctx, 0, uri);
+ CHECK (search != NULL);
+ prog = 0;
+ suspendRestart = 10;
+ while (prog < 100)
+ {
+ prog++;
+ GNUNET_thread_sleep (50 * GNUNET_CRON_MILLISECONDS);
+ if ((suspendRestart > 0)
+ && (GNUNET_random_u32 (GNUNET_RANDOM_QUALITY_WEAK, 10) == 0))
+ {
+#if 1
+#if DEBUG_VERBOSE
+ printf ("Testing FSUI suspend-resume\n");
+#endif
+ GNUNET_FSUI_stop (ctx); /* download possibly incomplete
+ at this point, thus testing resume
*/
+ CHECK (search == NULL);
+ ctx = GNUNET_FSUI_start (NULL,
+ cfg,
+ "search_persistence_test", 32, GNUNET_YES,
+ &eventCallback, NULL);
+#if DEBUG_VERBOSE
+ printf ("Resumed...\n");
+#endif
+#endif
+ suspendRestart--;
+ }
+ if (GNUNET_shutdown_test () == GNUNET_YES)
+ break;
+ }
+ GNUNET_FSUI_search_abort (search);
+ GNUNET_FSUI_search_stop (search);
+ search = NULL;
+ /* END OF TEST CODE */
+FAILURE:
+ if (ctx != NULL)
+ GNUNET_FSUI_stop (ctx);
+ if (uri != NULL)
+ GNUNET_ECRS_uri_destroy (uri);
+
+#if START_DAEMON
+ GNUNET_GE_BREAK (NULL, GNUNET_OK == GNUNET_daemon_stop (NULL, daemon));
+#endif
+ GNUNET_GC_free (cfg);
+ if (have_error)
+ ok = GNUNET_NO;
+ return (ok == GNUNET_YES) ? 0 : 1;
+}
+
+/* end of search_persistence_test.c */
Added: GNUnet/src/applications/fs/fsui/search_ranking_test.c
===================================================================
--- GNUnet/src/applications/fs/fsui/search_ranking_test.c
(rev 0)
+++ GNUnet/src/applications/fs/fsui/search_ranking_test.c 2008-05-12
04:05:54 UTC (rev 6801)
@@ -0,0 +1,251 @@
+/*
+ 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/fsui/search_ranking_test.c
+ * @brief testcase for search ranking (availability, etc)
+ * @author Christian Grothoff
+ */
+
+#include "platform.h"
+#include "gnunet_util.h"
+#include "gnunet_fsui_lib.h"
+
+#define CHECK_VERBOSE GNUNET_NO
+
+#define CHECK(a) if (!(a)) { ok = GNUNET_NO; GNUNET_GE_BREAK(NULL, 0); goto
FAILURE; }
+
+static char *
+makeName (unsigned int i)
+{
+ char *fn;
+
+ fn = GNUNET_malloc (strlen ("/tmp/gnunet-fsui-searchranktest/FSUITEST") +
14);
+ GNUNET_snprintf (fn,
+ strlen ("/tmp/gnunet-fsui-searchranktest/FSUITEST") + 14,
+ "/tmp/gnunet-fsui-searchranktest/FSUITEST%u", i);
+ GNUNET_disk_directory_create_for_file (NULL, fn);
+ return fn;
+}
+
+static struct GNUNET_FSUI_SearchList *search;
+
+static volatile enum GNUNET_FSUI_EventType lastEvent;
+
+static volatile struct GNUNET_ECRS_URI *uri;
+
+static volatile int availability;
+
+static volatile unsigned int rank;
+
+static volatile enum GNUNET_FSUI_EventType waitForEvent;
+
+static void *
+eventCallback (void *cls, const GNUNET_FSUI_Event * event)
+{
+ static char unused;
+
+ switch (event->type)
+ {
+ case GNUNET_FSUI_search_resumed:
+ search = event->data.SearchResumed.sc.pos;
+ break;
+ case GNUNET_FSUI_search_suspended:
+ search = NULL;
+ break;
+ case GNUNET_FSUI_search_update:
+ availability = event->data.SearchUpdate.availability_rank;
+ rank = event->data.SearchUpdate.applicability_rank;
+ break;
+ case GNUNET_FSUI_search_paused:
+ case GNUNET_FSUI_search_restarted:
+ break;
+ case GNUNET_FSUI_download_resumed:
+ case GNUNET_FSUI_upload_resumed:
+ case GNUNET_FSUI_unindex_resumed:
+ return &unused;
+ case GNUNET_FSUI_search_result:
+#if CHECK_VERBOSE
+ printf ("Received search result\n");
+#endif
+ uri = GNUNET_ECRS_uri_duplicate (event->data.SearchResult.fi.uri);
+ break;
+ case GNUNET_FSUI_upload_completed:
+#if CHECK_VERBOSE
+ printf ("Upload complete.\n");
+#endif
+ break;
+ case GNUNET_FSUI_download_completed:
+#if CHECK_VERBOSE
+ printf ("Download complete.\n");
+#endif
+ break;
+ case GNUNET_FSUI_unindex_completed:
+#if CHECK_VERBOSE
+ printf ("Unindex complete.\n");
+#endif
+ break;
+ case GNUNET_FSUI_upload_error:
+ printf ("Upload error.\n");
+ break;
+ case GNUNET_FSUI_download_error:
+ printf ("Download error.\n");
+ break;
+ case GNUNET_FSUI_unindex_error:
+ printf ("Unindex error.\n");
+ break;
+ default:
+ break;
+ }
+ if (lastEvent != waitForEvent)
+ lastEvent = event->type;
+ return NULL;
+}
+
+#define START_DAEMON 1
+
+int
+main (int argc, char *argv[])
+{
+#if START_DAEMON
+ pid_t daemon;
+#endif
+ int ok;
+ char *fn = NULL;
+ char *keywords[] = {
+ "search_foo",
+ "search_bar",
+ };
+ char keyword[40];
+ int prog;
+ struct GNUNET_ECRS_MetaData *meta;
+ struct GNUNET_ECRS_URI *kuri;
+ struct GNUNET_GC_Configuration *cfg;
+ struct GNUNET_FSUI_UploadList *upload;
+ struct GNUNET_ECRS_URI *luri;
+ struct GNUNET_FSUI_Context *ctx;
+
+
+ ok = GNUNET_YES;
+ cfg = GNUNET_GC_create ();
+ if (-1 == GNUNET_GC_parse_configuration (cfg, "check.conf"))
+ {
+ GNUNET_GC_free (cfg);
+ return -1;
+ }
+#if START_DAEMON
+ GNUNET_disk_directory_remove (NULL, "/tmp/gnunet-fsui-searchranktest/");
+ 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 */
+ /* ACTUAL TEST CODE */
+#endif
+ ctx = GNUNET_FSUI_start (NULL,
+ cfg, "fsuisearchranktest", 32, GNUNET_YES,
+ &eventCallback, NULL);
+ CHECK (ctx != NULL);
+ /* upload */
+ fn = makeName (42);
+ GNUNET_disk_file_write (NULL,
+ fn, "foo bar test!", strlen ("foo bar test!"),
+ "600");
+ meta = GNUNET_ECRS_meta_data_create ();
+ kuri =
+ GNUNET_ECRS_keyword_command_line_to_uri (NULL, 2,
+ (const char **) keywords);
+ waitForEvent = GNUNET_FSUI_upload_completed;
+ upload =
+ GNUNET_FSUI_upload_start (ctx,
+ fn,
+ (GNUNET_FSUI_DirectoryScanCallback) &
+ GNUNET_disk_directory_scan, NULL, 0, 0,
+ GNUNET_YES, GNUNET_NO, GNUNET_NO,
+ GNUNET_get_time () + 5 * GNUNET_CRON_HOURS,
+ meta, kuri, kuri);
+ CHECK (NULL != upload);
+ GNUNET_free (fn);
+ fn = NULL;
+ GNUNET_ECRS_uri_destroy (kuri);
+ GNUNET_ECRS_meta_data_destroy (meta);
+ prog = 0;
+ while (lastEvent != GNUNET_FSUI_upload_completed)
+ {
+ prog++;
+ if (prog == 10000)
+ {
+ fprintf (stderr,
+ "Upload failed to complete -- last event: %u\n",
+ lastEvent);
+ }
+ CHECK (prog < 10000);
+ GNUNET_thread_sleep (50 * GNUNET_CRON_MILLISECONDS);
+ if (GNUNET_shutdown_test () == GNUNET_YES)
+ break;
+ }
+ GNUNET_FSUI_upload_stop (upload);
+
+ /* search */
+ GNUNET_snprintf (keyword, 40, "%s %s", keywords[0], keywords[1]);
+ luri = GNUNET_ECRS_keyword_string_to_uri (NULL, keyword);
+ uri = NULL;
+ search = GNUNET_FSUI_search_start (ctx, 0, luri);
+ GNUNET_ECRS_uri_destroy (luri);
+ luri = NULL;
+ CHECK (NULL != search);
+ GNUNET_FSUI_search_pause (search);
+ GNUNET_FSUI_search_restart (search);
+ while ( (uri == NULL) &&
+ (availability < 3) &&
+ (rank != 2) &&
+ (GNUNET_shutdown_test () != GNUNET_YES))
+ {
+ prog++;
+ CHECK (prog < 10000);
+ GNUNET_thread_sleep (50 * GNUNET_CRON_MILLISECONDS);
+ }
+ GNUNET_FSUI_search_abort (search);
+ GNUNET_FSUI_search_stop (search);
+ CHECK (uri != NULL);
+
+
+ /* END OF TEST CODE */
+FAILURE:
+ if (ctx != NULL)
+ GNUNET_FSUI_stop (ctx);
+ GNUNET_free_non_null (fn);
+ /* TODO: verify file 'fn(42)' == file 'fn(43)' */
+ fn = makeName (42);
+ UNLINK (fn);
+ GNUNET_free (fn);
+ fn = makeName (43);
+ UNLINK (fn);
+ GNUNET_free (fn);
+
+#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 searchtest.c */
Deleted: GNUnet/src/applications/fs/fsui/searchtest.c
===================================================================
--- GNUnet/src/applications/fs/fsui/searchtest.c 2008-05-11 22:33:29 UTC
(rev 6800)
+++ GNUnet/src/applications/fs/fsui/searchtest.c 2008-05-12 04:05:54 UTC
(rev 6801)
@@ -1,294 +0,0 @@
-/*
- This file is part of GNUnet.
- (C) 2004, 2005, 2006 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/fsui/searchtest.c
- * @brief testcase for fsui search persistence
- * @author Christian Grothoff
- */
-
-#include "platform.h"
-#include "gnunet_util.h"
-#include "gnunet_fsui_lib.h"
-
-#define CHECK_VERBOSE GNUNET_NO
-
-#define CHECK(a) if (!(a)) { ok = GNUNET_NO; GNUNET_GE_BREAK(NULL, 0); goto
FAILURE; }
-
-static char *
-makeName (unsigned int i)
-{
- char *fn;
-
- fn = GNUNET_malloc (strlen ("/tmp/gnunet-fsui-searchtest/FSUITEST") + 14);
- GNUNET_snprintf (fn,
- strlen ("/tmp/gnunet-fsui-searchtest/FSUITEST") + 14,
- "/tmp/gnunet-fsui-searchtest/FSUITEST%u", i);
- GNUNET_disk_directory_create_for_file (NULL, fn);
- return fn;
-}
-
-static volatile enum GNUNET_FSUI_EventType lastEvent;
-
-static struct GNUNET_FSUI_SearchList *search;
-
-static struct GNUNET_ECRS_URI *uri;
-
-static struct GNUNET_FSUI_Context *ctx;
-
-static struct GNUNET_Mutex *lock;
-
-static volatile enum GNUNET_FSUI_EventType waitForEvent;
-
-static void *
-eventCallback (void *cls, const GNUNET_FSUI_Event * event)
-{
- static char unused;
-
- GNUNET_mutex_lock (lock);
- switch (event->type)
- {
- case GNUNET_FSUI_search_resumed:
- search = event->data.SearchResumed.sc.pos;
- break;
- case GNUNET_FSUI_search_suspended:
- search = NULL;
- break;
- case GNUNET_FSUI_search_paused:
- case GNUNET_FSUI_search_restarted:
- break;
- case GNUNET_FSUI_download_resumed:
- case GNUNET_FSUI_upload_resumed:
- case GNUNET_FSUI_unindex_resumed:
- GNUNET_mutex_unlock (lock);
- return &unused;
- case GNUNET_FSUI_search_result:
-#if CHECK_VERBOSE
- printf ("Received search result\n");
-#endif
- uri = GNUNET_ECRS_uri_duplicate (event->data.SearchResult.fi.uri);
- break;
- case GNUNET_FSUI_upload_completed:
-#if CHECK_VERBOSE
- printf ("Upload complete.\n");
-#endif
- break;
- case GNUNET_FSUI_download_completed:
-#if CHECK_VERBOSE
- printf ("Download complete.\n");
-#endif
- break;
- case GNUNET_FSUI_unindex_completed:
-#if CHECK_VERBOSE
- printf ("Unindex complete.\n");
-#endif
- break;
- case GNUNET_FSUI_upload_error:
- printf ("Upload error.\n");
- break;
- case GNUNET_FSUI_download_error:
- printf ("Download error.\n");
- break;
- case GNUNET_FSUI_unindex_error:
- printf ("Unindex error.\n");
- break;
- default:
- break;
- }
- if (lastEvent != waitForEvent)
- lastEvent = event->type;
- GNUNET_mutex_unlock (lock);
- return NULL;
-}
-
-#define START_DAEMON 1
-
-int
-main (int argc, char *argv[])
-{
-#if START_DAEMON
- pid_t daemon;
-#endif
- int ok;
- char *fn = NULL;
- char *keywords[] = {
- "search_foo",
- "search_bar",
- };
- char keyword[40];
- int prog;
- struct GNUNET_ECRS_MetaData *meta;
- struct GNUNET_ECRS_URI *kuri;
- struct GNUNET_GC_Configuration *cfg;
- struct GNUNET_FSUI_UploadList *upload;
- struct GNUNET_FSUI_UnindexList *unindex;
- struct GNUNET_FSUI_DownloadList *download;
- struct GNUNET_ECRS_URI *luri;
-
- ok = GNUNET_YES;
- cfg = GNUNET_GC_create ();
- if (-1 == GNUNET_GC_parse_configuration (cfg, "check.conf"))
- {
- GNUNET_GC_free (cfg);
- return -1;
- }
-#if START_DAEMON
- GNUNET_disk_directory_remove (NULL, "/tmp/gnunet-check-fsui/");
- 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 */
- /* ACTUAL TEST CODE */
-#endif
- lock = GNUNET_mutex_create (GNUNET_NO);
- ctx = GNUNET_FSUI_start (NULL,
- cfg, "fsuisearchtest", 32, GNUNET_YES,
- &eventCallback, NULL);
- CHECK (ctx != NULL);
- GNUNET_snprintf (keyword, 40, "+%s +%s", keywords[0], keywords[1]);
- luri = GNUNET_ECRS_keyword_string_to_uri (NULL, keyword);
- uri = NULL;
- search = GNUNET_FSUI_search_start (ctx, 0, luri);
- GNUNET_ECRS_uri_destroy (luri);
- CHECK (NULL != search);
- GNUNET_FSUI_stop (ctx);
- /* resume search! */
- ctx = GNUNET_FSUI_start (NULL,
- cfg, "fsuisearchtest", 32, GNUNET_YES,
- &eventCallback, NULL);
- GNUNET_FSUI_search_pause (search);
- GNUNET_FSUI_stop (ctx);
- /* resume search! */
- ctx = GNUNET_FSUI_start (NULL,
- cfg, "fsuisearchtest", 32, GNUNET_YES,
- &eventCallback, NULL);
- GNUNET_FSUI_search_restart (search);
-
- fn = makeName (42);
- GNUNET_disk_file_write (NULL,
- fn, "foo bar test!", strlen ("foo bar test!"),
- "600");
- meta = GNUNET_ECRS_meta_data_create ();
- kuri =
- GNUNET_ECRS_keyword_command_line_to_uri (NULL, 2,
- (const char **) keywords);
- waitForEvent = GNUNET_FSUI_upload_completed;
- upload =
- GNUNET_FSUI_upload_start (ctx,
- fn,
- (GNUNET_FSUI_DirectoryScanCallback) &
- GNUNET_disk_directory_scan, NULL, 0, 0,
- GNUNET_YES, GNUNET_NO, GNUNET_NO,
- GNUNET_get_time () + 5 * GNUNET_CRON_HOURS,
- meta, kuri, kuri);
- CHECK (NULL != upload);
- GNUNET_free (fn);
- fn = NULL;
- GNUNET_ECRS_uri_destroy (kuri);
- GNUNET_ECRS_meta_data_destroy (meta);
- prog = 0;
- while (lastEvent != GNUNET_FSUI_upload_completed)
- {
- prog++;
- if (prog == 10000)
- {
- fprintf (stderr,
- "Upload failed to complete -- last event: %u\n",
- lastEvent);
- }
- CHECK (prog < 10000);
- GNUNET_thread_sleep (50 * GNUNET_CRON_MILLISECONDS);
- if (GNUNET_shutdown_test () == GNUNET_YES)
- break;
- }
- GNUNET_FSUI_upload_stop (upload);
- GNUNET_FSUI_search_pause (search);
- GNUNET_FSUI_search_restart (search);
- while ((uri == NULL) && (GNUNET_shutdown_test () != GNUNET_YES))
- {
- prog++;
- CHECK (prog < 10000);
- GNUNET_thread_sleep (50 * GNUNET_CRON_MILLISECONDS);
- }
- GNUNET_FSUI_search_abort (search);
- GNUNET_FSUI_search_stop (search);
- CHECK (uri != NULL);
- fn = makeName (43);
- meta = GNUNET_ECRS_meta_data_create ();
- waitForEvent = GNUNET_FSUI_download_completed;
- download =
- GNUNET_FSUI_download_start (ctx, 0, GNUNET_NO, uri, meta, fn, NULL, NULL);
- GNUNET_ECRS_meta_data_destroy (meta);
- GNUNET_free (fn);
- fn = NULL;
- GNUNET_ECRS_uri_destroy (uri);
-
- prog = 0;
- while (lastEvent != GNUNET_FSUI_download_completed)
- {
- prog++;
- CHECK (prog < 10000);
- GNUNET_thread_sleep (50 * GNUNET_CRON_MILLISECONDS);
- if (GNUNET_shutdown_test () == GNUNET_YES)
- break;
- }
- GNUNET_FSUI_download_stop (download);
- fn = makeName (42);
- waitForEvent = GNUNET_FSUI_unindex_completed;
- unindex = GNUNET_FSUI_unindex_start (ctx, fn);
- GNUNET_free (fn);
- fn = NULL;
- CHECK (NULL != unindex);
- prog = 0;
- while (lastEvent != GNUNET_FSUI_unindex_completed)
- {
- prog++;
- CHECK (prog < 10000);
- GNUNET_thread_sleep (50 * GNUNET_CRON_MILLISECONDS);
- if (GNUNET_shutdown_test () == GNUNET_YES)
- break;
- }
- GNUNET_FSUI_unindex_stop (unindex);
-
- /* END OF TEST CODE */
-FAILURE:
- if (ctx != NULL)
- GNUNET_FSUI_stop (ctx);
- if (lock != NULL)
- GNUNET_mutex_destroy (lock);
- GNUNET_free_non_null (fn);
- /* TODO: verify file 'fn(42)' == file 'fn(43)' */
- fn = makeName (42);
- UNLINK (fn);
- GNUNET_free (fn);
- fn = makeName (43);
- UNLINK (fn);
- GNUNET_free (fn);
-
-#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 searchtest.c */
Deleted: GNUnet/src/applications/fs/fsui/serializetest.c
===================================================================
--- GNUnet/src/applications/fs/fsui/serializetest.c 2008-05-11 22:33:29 UTC
(rev 6800)
+++ GNUnet/src/applications/fs/fsui/serializetest.c 2008-05-12 04:05:54 UTC
(rev 6801)
@@ -1,300 +0,0 @@
-/*
- This file is part of GNUnet.
- (C) 2004, 2005, 2006 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/fsui/serializetest.c
- * @brief testcase for fsui upload persistence
- * @author Christian Grothoff
- */
-
-#include "platform.h"
-#include "gnunet_util.h"
-#include "gnunet_fsui_lib.h"
-
-#define DEBUG_VERBOSE GNUNET_NO
-
-#define CHECK(a) if (!(a)) { ok = GNUNET_NO; GNUNET_GE_BREAK(ectx, 0); goto
FAILURE; }
-
-static volatile int suspendRestart = 0;
-
-static struct GNUNET_GE_Context *ectx;
-
-static char *
-makeName (unsigned int i)
-{
- char *fn;
-
- fn =
- GNUNET_malloc (strlen ("/tmp/gnunet-fsui-serializetest/FSUITEST") + 14);
- GNUNET_snprintf (fn,
- strlen ("/tmp/gnunet-fsui-serializetest/FSUITEST") + 14,
- "/tmp/gnunet-fsui-serializetest/FSUITEST%u", i);
- GNUNET_disk_directory_create_for_file (NULL, fn);
- return fn;
-}
-
-static volatile enum GNUNET_FSUI_EventType lastEvent;
-static volatile enum GNUNET_FSUI_EventType waitForEvent;
-static struct GNUNET_FSUI_Context *ctx;
-static struct GNUNET_ECRS_URI *upURI;
-static struct GNUNET_FSUI_UnindexList *unindex;
-static struct GNUNET_FSUI_UploadList *upload;
-
-
-static void *
-eventCallback (void *cls, const GNUNET_FSUI_Event * event)
-{
- switch (event->type)
- {
- case GNUNET_FSUI_upload_progress:
-#if DEBUG_VERBOSE
- printf ("Upload is progressing (%llu/%llu)...\n",
- event->data.UploadProgress.completed,
- event->data.UploadProgress.total);
-#endif
- break;
- case GNUNET_FSUI_upload_completed:
- upURI = GNUNET_ECRS_uri_duplicate (event->data.UploadCompleted.uri);
-#if DEBUG_VERBOSE
- printf ("Upload complete.\n");
-#endif
- break;
- case GNUNET_FSUI_unindex_progress:
-#if DEBUG_VERBOSE
- printf ("Unindex is progressing (%llu/%llu)...\n",
- event->data.UnindexProgress.completed,
- event->data.UnindexProgress.total);
-#endif
- break;
- case GNUNET_FSUI_unindex_completed:
-#if DEBUG_VERBOSE
- printf ("Unindex complete.\n");
-#endif
- break;
- case GNUNET_FSUI_unindex_error:
- case GNUNET_FSUI_upload_error:
- case GNUNET_FSUI_download_error:
- fprintf (stderr, "Received ERROR: %d\n", event->type);
- GNUNET_GE_BREAK (ectx, 0);
- break;
- case GNUNET_FSUI_download_aborted:
-#if DEBUG_VERBOSE
- printf ("Received download aborted event.\n");
-#endif
- break;
- case GNUNET_FSUI_unindex_resumed:
-#if DEBUG_VERBOSE
- fprintf (stderr, "Received RESUMING: %d\n", event->type);
-#endif
- unindex = event->data.UnindexResumed.uc.pos;
- break;
- case GNUNET_FSUI_upload_resumed:
-#if DEBUG_VERBOSE
- fprintf (stderr, "Received RESUMING: %d\n", event->type);
-#endif
- upload = event->data.UploadResumed.uc.pos;
- break;
- break;
- case GNUNET_FSUI_unindex_suspended:
- unindex = NULL;
-#if DEBUG_VERBOSE
- fprintf (stderr, "Received SUSPENDING: %d\n", event->type);
-#endif
- break;
- case GNUNET_FSUI_upload_suspended:
- upload = NULL;
-#if DEBUG_VERBOSE
- fprintf (stderr, "Received SUSPENDING: %d\n", event->type);
-#endif
- break;
- case GNUNET_FSUI_upload_started:
- case GNUNET_FSUI_upload_stopped:
- case GNUNET_FSUI_unindex_started:
- case GNUNET_FSUI_unindex_stopped:
- break;
- default:
- printf ("Unexpected event: %d\n", event->type);
- break;
- }
- if (lastEvent == waitForEvent)
- return NULL; /* ignore all other events */
- lastEvent = event->type;
- return NULL;
-}
-
-#define FILESIZE (1024 * 1024 * 2)
-
-#define START_DAEMON 1
-
-int
-main (int argc, char *argv[])
-{
-#if START_DAEMON
- pid_t daemon;
-#endif
- int ok;
- int i;
- char *fn = NULL;
- char *keywords[] = {
- "down_foo",
- "down_bar",
- };
- int prog;
- char *buf;
- struct GNUNET_ECRS_MetaData *meta;
- struct GNUNET_ECRS_URI *kuri = NULL;
- struct GNUNET_GC_Configuration *cfg;
-
- ok = GNUNET_YES;
- 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 */
- /* ACTUAL TEST CODE */
-#endif
- ctx = GNUNET_FSUI_start (NULL,
- cfg, "fsuiserializetest", 32, GNUNET_YES,
- &eventCallback, NULL);
- CHECK (ctx != NULL);
- fn = makeName (42);
- buf = GNUNET_malloc (FILESIZE);
- for (i = 0; i < FILESIZE; i++)
- buf[i] = GNUNET_random_u32 (GNUNET_RANDOM_QUALITY_WEAK, 256);
- GNUNET_disk_file_write (ectx, fn, buf, FILESIZE, "600");
- GNUNET_free (buf);
- meta = GNUNET_ECRS_meta_data_create ();
- kuri =
- GNUNET_ECRS_keyword_command_line_to_uri (ectx, 2,
- (const char **) keywords);
- waitForEvent = GNUNET_FSUI_upload_completed;
- upload = GNUNET_FSUI_upload_start (ctx,
- fn,
- (GNUNET_FSUI_DirectoryScanCallback) &
- GNUNET_disk_directory_scan, NULL, 0, 0,
- GNUNET_YES, GNUNET_NO, GNUNET_NO,
- GNUNET_get_time () +
- 5 * GNUNET_CRON_HOURS, meta, kuri, kuri);
- CHECK (upload != NULL);
- GNUNET_ECRS_uri_destroy (kuri);
- kuri = NULL;
- GNUNET_ECRS_meta_data_destroy (meta);
- prog = 0;
- suspendRestart = 4;
- while (lastEvent != GNUNET_FSUI_upload_completed)
- {
- if ((suspendRestart > 0)
- && (GNUNET_random_u32 (GNUNET_RANDOM_QUALITY_WEAK, 4) == 0))
- {
-#if 1
-#if DEBUG_VERBOSE
- printf ("Testing FSUI suspend-resume\n");
-#endif
- GNUNET_FSUI_stop (ctx); /* download possibly incomplete
- at this point, thus testing resume
*/
- ctx = GNUNET_FSUI_start (NULL,
- cfg,
- "fsuiserializetest",
- 32, GNUNET_YES, &eventCallback, NULL);
-#if DEBUG_VERBOSE
- printf ("Resumed...\n");
-#endif
-#endif
- suspendRestart--;
- }
- prog++;
- CHECK (prog < 5000);
- GNUNET_thread_sleep (50 * GNUNET_CRON_MILLISECONDS);
- if (GNUNET_shutdown_test () == GNUNET_YES)
- break;
- }
- GNUNET_FSUI_upload_stop (upload);
- waitForEvent = GNUNET_FSUI_unindex_completed;
- unindex = GNUNET_FSUI_unindex_start (ctx, fn);
- CHECK (unindex != NULL);
- prog = 0;
- suspendRestart = 4;
- while (lastEvent != GNUNET_FSUI_unindex_completed)
- {
- if ((suspendRestart > 0)
- && (GNUNET_random_u32 (GNUNET_RANDOM_QUALITY_WEAK, 4) == 0))
- {
-#if 1
-#if DEBUG_VERBOSE
- printf ("Testing FSUI suspend-resume\n");
-#endif
- GNUNET_FSUI_stop (ctx); /* download possibly incomplete
- at this point, thus testing resume
*/
- ctx = GNUNET_FSUI_start (NULL,
- cfg,
- "fsuiserializetest",
- 32, GNUNET_YES, &eventCallback, NULL);
-#if DEBUG_VERBOSE
- printf ("Resumed...\n");
-#endif
-#endif
- suspendRestart--;
- }
- prog++;
- CHECK (prog < 5000);
- GNUNET_thread_sleep (50 * GNUNET_CRON_MILLISECONDS);
- CHECK (lastEvent != GNUNET_FSUI_unindex_error);
- if (GNUNET_shutdown_test () == GNUNET_YES)
- break;
- }
- CHECK (lastEvent == GNUNET_FSUI_unindex_completed);
- /* END OF TEST CODE */
-FAILURE:
- if (ctx != NULL)
- {
- if (unindex != NULL)
- GNUNET_FSUI_unindex_stop (unindex);
- GNUNET_FSUI_stop (ctx);
- }
- if (fn != NULL)
- {
- UNLINK (fn);
- GNUNET_free (fn);
- }
- if (kuri != NULL)
- GNUNET_ECRS_uri_destroy (kuri);
- fn = makeName (43);
- /* TODO: verify file 'fn(42)' == file 'fn(43)' */
- UNLINK (fn);
- GNUNET_free (fn);
- if (upURI != NULL)
- GNUNET_ECRS_uri_destroy (upURI);
-
-#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 downloadtest.c */
Deleted: GNUnet/src/applications/fs/fsui/serializetest2.c
===================================================================
--- GNUnet/src/applications/fs/fsui/serializetest2.c 2008-05-11 22:33:29 UTC
(rev 6800)
+++ GNUnet/src/applications/fs/fsui/serializetest2.c 2008-05-12 04:05:54 UTC
(rev 6801)
@@ -1,468 +0,0 @@
-/*
- This file is part of GNUnet.
- (C) 2004, 2005, 2006 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/fsui/serializetest2.c
- * @brief testcase for fsui download persistence for recursive
- * download linked to search
- * @author Christian Grothoff
- */
-
-#include "platform.h"
-#include "gnunet_util.h"
-#include "gnunet_fsui_lib.h"
-
-#define DEBUG_VERBOSE GNUNET_NO
-
-#define UPLOAD_PREFIX "/tmp/gnunet-fsui-serializetest2"
-
-#define CHECK(a) if (!(a)) { ok = GNUNET_NO; GNUNET_GE_BREAK(ectx, 0); goto
FAILURE; }
-
-static struct GNUNET_GE_Context *ectx;
-
-static char *
-makeName (unsigned int i)
-{
- char *fn;
-
- fn = GNUNET_malloc (strlen (UPLOAD_PREFIX "/FSUITEST") + 14);
- GNUNET_snprintf (fn,
- strlen (UPLOAD_PREFIX "/FSUITEST") + 14,
- UPLOAD_PREFIX "/FSUITEST%u", i);
- GNUNET_disk_directory_create_for_file (NULL, fn);
- return fn;
-}
-
-static struct GNUNET_FSUI_Context *ctx;
-static struct GNUNET_ECRS_URI *upURI;
-static struct GNUNET_FSUI_SearchList *search;
-static struct GNUNET_FSUI_DownloadList *download;
-static int have_error;
-
-/**
- * Set to 1 if we are about to stop the search and
- * thus our simple tests for download event correctness
- * would not work correctly.
- */
-static int no_check;
-
-static void *
-eventCallback (void *cls, const GNUNET_FSUI_Event * event)
-{
- if (no_check)
- return NULL;
- switch (event->type)
- {
- case GNUNET_FSUI_search_suspended:
- search = NULL;
- break;
- case GNUNET_FSUI_download_suspended:
- if (event->data.DownloadSuspended.dc.spos != search)
- {
- fprintf (stderr,
- "Download suspended but search reference not set
correctly.\n");
- have_error = 1;
- }
- if ((event->data.DownloadSuspended.dc.pos == download) &&
- (event->data.DownloadSuspended.dc.ppos != NULL))
- {
- fprintf (stderr,
- "Download suspended but parent reference not set to
NULL.\n");
- have_error = 1;
- }
- if ((event->data.DownloadSuspended.dc.pos != download) &&
- (event->data.DownloadSuspended.dc.ppos != download))
- {
- fprintf (stderr,
- "Download suspended but parent reference not set correctly
(%p instead of %p).\n",
- event->data.DownloadSuspended.dc.ppos, download);
- have_error = 1;
- }
- if (event->data.DownloadSuspended.dc.pos == download)
- download = NULL;
- break;
- case GNUNET_FSUI_search_resumed:
-#if DEBUG_VERBOSE
- printf ("Search resuming\n");
-#endif
- search = event->data.SearchResumed.sc.pos;
- break;
- case GNUNET_FSUI_download_resumed:
- if (download == NULL)
- download = event->data.DownloadResumed.dc.pos;
- if (event->data.DownloadResumed.dc.spos != search)
- {
- fprintf (stderr,
- "Download resuming but search reference not set
correctly.\n");
- abort();
- have_error = 1;
- }
- if ((event->data.DownloadResumed.dc.pos == download) &&
- (event->data.DownloadResumed.dc.ppos != NULL))
- {
- fprintf (stderr,
- "Download resuming but parent reference not set to
NULL.\n");
- have_error = 1;
- }
- if ((event->data.DownloadResumed.dc.pos != download) &&
- (event->data.DownloadResumed.dc.ppos != download))
- {
- fprintf (stderr,
- "Download resuming but parent reference not set
correctly.\n");
- have_error = 1;
- }
-#if DEBUG_VERBOSE
- printf ("Download resuming\n");
-#endif
- break;
- case GNUNET_FSUI_search_result:
-#if DEBUG_VERBOSE
- printf ("Received search result\n");
-#endif
- break;
- case GNUNET_FSUI_upload_progress:
-#if DEBUG_VERBOSE
- printf ("Upload is progressing (%llu/%llu)...\n",
- event->data.UploadProgress.completed,
- event->data.UploadProgress.total);
-#endif
- break;
- case GNUNET_FSUI_upload_completed:
- if (upURI != NULL)
- GNUNET_ECRS_uri_destroy (upURI);
- upURI = GNUNET_ECRS_uri_duplicate (event->data.UploadCompleted.uri);
-#if DEBUG_VERBOSE
- printf ("Upload complete.\n");
-#endif
- break;
- case GNUNET_FSUI_download_completed:
- if (event->data.DownloadCompleted.dc.spos != search)
- {
- fprintf (stderr,
- "Download completed but search reference not set
correctly.\n");
- have_error = 1;
- }
- if ((event->data.DownloadCompleted.dc.pos == download) &&
- (event->data.DownloadCompleted.dc.ppos != NULL))
- {
- fprintf (stderr,
- "Download completed but parent reference not set to
NULL.\n");
- have_error = 1;
- }
- if ((event->data.DownloadCompleted.dc.pos != download) &&
- (event->data.DownloadCompleted.dc.ppos != download))
- {
- fprintf (stderr,
- "Download completed but parent reference not set
correctly.\n");
- have_error = 1;
- }
-#if DEBUG_VERBOSE
- printf ("Download complete.\n");
-#endif
- break;
- case GNUNET_FSUI_download_progress:
- if (event->data.DownloadResumed.dc.spos != search)
- {
- fprintf (stderr,
- "Download progressing but search reference not set
correctly.\n");
- have_error = 1;
- }
- if ((event->data.DownloadResumed.dc.pos == download) &&
- (event->data.DownloadResumed.dc.ppos != NULL))
- {
- fprintf (stderr,
- "Download progressing but parent reference not set to
NULL.\n");
- have_error = 1;
- }
- if ((event->data.DownloadResumed.dc.pos != download) &&
- (event->data.DownloadResumed.dc.ppos != download))
- {
- fprintf (stderr,
- "Download progressing but parent reference not set
correctly.\n");
- have_error = 1;
- }
-#if DEBUG_VERBOSE
- printf ("Download is progressing (%llu/%llu)...\n",
- event->data.DownloadProgress.completed,
- event->data.DownloadProgress.total);
-#endif
- break;
- case GNUNET_FSUI_unindex_progress:
-#if DEBUG_VERBOSE
- printf ("Unindex is progressing (%llu/%llu)...\n",
- event->data.UnindexProgress.completed,
- event->data.UnindexProgress.total);
-#endif
- break;
- case GNUNET_FSUI_unindex_completed:
-#if DEBUG_VERBOSE
- printf ("Unindex complete.\n");
-#endif
- break;
- case GNUNET_FSUI_unindex_error:
- fprintf (stderr,
- "Received ERROR: %d %s\n",
- event->type, event->data.UnindexError.message);
- GNUNET_GE_BREAK (ectx, 0);
- break;
- case GNUNET_FSUI_upload_error:
- fprintf (stderr,
- "Received ERROR: %d %s\n",
- event->type, event->data.UploadError.message);
- GNUNET_GE_BREAK (ectx, 0);
- break;
- case GNUNET_FSUI_download_error:
- fprintf (stderr,
- "Received ERROR: %d %s\n",
- event->type, event->data.DownloadError.message);
- GNUNET_GE_BREAK (ectx, 0);
- break;
- case GNUNET_FSUI_download_aborted:
-#if DEBUG_VERBOSE
- printf ("Received download aborted event.\n");
-#endif
- break;
- case GNUNET_FSUI_unindex_suspended:
- case GNUNET_FSUI_upload_suspended:
-#if DEBUG_VERBOSE
- fprintf (stderr, "Received SUSPENDING: %d\n", event->type);
-#endif
- break;
- case GNUNET_FSUI_download_started:
- if (download == NULL)
- download = event->data.DownloadStarted.dc.pos;
- if (event->data.DownloadStarted.dc.spos != search)
- {
- fprintf (stderr,
- "Download started but search reference not set
correctly.\n");
- have_error = 1;
- }
- if ((event->data.DownloadStarted.dc.pos == download) &&
- (event->data.DownloadStarted.dc.ppos != NULL))
- {
- fprintf (stderr,
- "Download started but parent reference not set to NULL.\n");
- have_error = 1;
- }
- if ((event->data.DownloadStarted.dc.pos != download) &&
- (event->data.DownloadStarted.dc.ppos != download))
- {
- fprintf (stderr,
- "Download started but parent reference not set
correctly.\n");
- have_error = 1;
- }
- break;
- case GNUNET_FSUI_download_stopped:
- if (event->data.DownloadStopped.dc.spos != search)
- {
- fprintf (stderr,
- "Download stopped but search reference not set
correctly.\n");
- have_error = 1;
- }
- if ((event->data.DownloadStopped.dc.pos == download) &&
- (event->data.DownloadStopped.dc.ppos != NULL))
- {
- fprintf (stderr,
- "Download stopped but parent reference not set to NULL.\n");
- have_error = 1;
- }
- if ((event->data.DownloadStopped.dc.pos != download) &&
- (event->data.DownloadStopped.dc.ppos != download))
- {
- fprintf (stderr,
- "Download stopped but parent reference not set
correctly.\n");
- have_error = 1;
- }
- break;
- case GNUNET_FSUI_search_update:
- case GNUNET_FSUI_upload_started:
- case GNUNET_FSUI_upload_stopped:
- case GNUNET_FSUI_search_started:
- case GNUNET_FSUI_search_aborted:
- case GNUNET_FSUI_search_stopped:
- case GNUNET_FSUI_unindex_started:
- case GNUNET_FSUI_unindex_stopped:
- break;
- default:
- printf ("Unexpected event: %d\n", event->type);
- break;
- }
- return NULL;
-}
-
-#define FILESIZE (1024)
-
-#define START_DAEMON 1
-
-int
-main (int argc, char *argv[])
-{
-#if START_DAEMON
- pid_t daemon;
-#endif
- int ok;
- int i;
- int j;
- struct GNUNET_ECRS_URI *uri = NULL;
- char *fn = NULL;
- char *keywords[] = {
- "down_foo",
- "down_bar",
- };
- char keyword[40];
- int prog;
- char *buf;
- struct GNUNET_ECRS_MetaData *meta;
- struct GNUNET_ECRS_URI *kuri = NULL;
- struct GNUNET_GC_Configuration *cfg;
- struct GNUNET_FSUI_UnindexList *unindex = NULL;
- struct GNUNET_FSUI_UploadList *upload = NULL;
- int suspendRestart = 0;
-
-
- ok = GNUNET_YES;
- 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 */
- /* ACTUAL TEST CODE */
-#endif
- ctx = GNUNET_FSUI_start (NULL,
- cfg, "serializetest2", 32, GNUNET_YES,
- &eventCallback, NULL);
- CHECK (ctx != NULL);
- for (j = 4; j < 256; j += 4)
- {
- fn = makeName (j);
- buf = GNUNET_malloc (FILESIZE * j);
- for (i = 0; i < FILESIZE; i++)
- buf[i] = GNUNET_random_u32 (GNUNET_RANDOM_QUALITY_WEAK, 256);
- GNUNET_disk_file_write (ectx, fn, buf, FILESIZE, "600");
- GNUNET_free (buf);
- GNUNET_free (fn);
- }
- meta = GNUNET_ECRS_meta_data_create ();
- kuri =
- GNUNET_ECRS_keyword_command_line_to_uri (ectx, 2,
- (const char **) keywords);
- GNUNET_ECRS_meta_data_insert (meta, EXTRACTOR_MIMETYPE,
- GNUNET_DIRECTORY_MIME);
- upload =
- GNUNET_FSUI_upload_start (ctx, UPLOAD_PREFIX,
- (GNUNET_FSUI_DirectoryScanCallback) &
- GNUNET_disk_directory_scan, NULL, 0, 0,
- GNUNET_YES, GNUNET_NO, GNUNET_NO,
- GNUNET_get_time () + 5 * GNUNET_CRON_HOURS,
- meta, kuri, kuri);
- CHECK (upload != NULL);
- GNUNET_ECRS_uri_destroy (kuri);
- kuri = NULL;
- GNUNET_FSUI_upload_stop (upload);
- CHECK (upURI != NULL);
- GNUNET_snprintf (keyword, 40, "+%s +%s", keywords[0], keywords[1]);
- uri = GNUNET_ECRS_keyword_string_to_uri (ectx, keyword);
- search = GNUNET_FSUI_search_start (ctx, 0, uri);
- CHECK (search != NULL);
- download = GNUNET_FSUI_download_start (ctx,
- 0,
- GNUNET_YES,
- upURI,
- meta,
- UPLOAD_PREFIX "-download", search,
- NULL);
- GNUNET_ECRS_meta_data_destroy (meta);
- prog = 0;
- suspendRestart = 10;
- while (prog < 1000)
- {
- prog++;
- GNUNET_thread_sleep (50 * GNUNET_CRON_MILLISECONDS);
- if ((suspendRestart > 0)
- && (GNUNET_random_u32 (GNUNET_RANDOM_QUALITY_WEAK, 100) == 0))
- {
-#if 1
-#if DEBUG_VERBOSE
- printf ("Testing FSUI suspend-resume\n");
-#endif
- GNUNET_FSUI_stop (ctx); /* download possibly incomplete
- at this point, thus testing resume
*/
- CHECK (search == NULL);
- CHECK (download == NULL);
- ctx = GNUNET_FSUI_start (NULL,
- cfg,
- "serializetest2", 32, GNUNET_YES,
- &eventCallback, NULL);
-#if DEBUG_VERBOSE
- printf ("Resumed...\n");
-#endif
-#endif
- suspendRestart--;
- }
- if ((search != NULL) && (suspendRestart >= 5))
- {
- no_check = 1;
- GNUNET_thread_sleep (50 * GNUNET_CRON_MILLISECONDS);
- GNUNET_FSUI_search_abort (search);
- GNUNET_FSUI_search_stop (search);
- search = NULL;
- no_check = 0;
- }
- if (GNUNET_shutdown_test () == GNUNET_YES)
- break;
- }
- GNUNET_FSUI_download_stop (download);
- for (j = 4; j < 256; j += 4)
- {
- fn = makeName (j);
- unindex = GNUNET_FSUI_unindex_start (ctx, fn);
- GNUNET_FSUI_unindex_stop (unindex);
- UNLINK (fn);
- GNUNET_free (fn);
- }
- /* END OF TEST CODE */
-FAILURE:
- if (ctx != NULL)
- GNUNET_FSUI_stop (ctx);
- if (uri != NULL)
- GNUNET_ECRS_uri_destroy (uri);
- if (kuri != NULL)
- GNUNET_ECRS_uri_destroy (kuri);
- if (upURI != NULL)
- GNUNET_ECRS_uri_destroy (upURI);
-
-#if START_DAEMON
- GNUNET_GE_BREAK (NULL, GNUNET_OK == GNUNET_daemon_stop (NULL, daemon));
-#endif
- GNUNET_GC_free (cfg);
- if (have_error)
- ok = GNUNET_NO;
- return (ok == GNUNET_YES) ? 0 : 1;
-}
-
-/* end of serializetest2.c */
Deleted: GNUnet/src/applications/fs/fsui/serializetest3.c
===================================================================
--- GNUnet/src/applications/fs/fsui/serializetest3.c 2008-05-11 22:33:29 UTC
(rev 6800)
+++ GNUnet/src/applications/fs/fsui/serializetest3.c 2008-05-12 04:05:54 UTC
(rev 6801)
@@ -1,213 +0,0 @@
-/*
- This file is part of GNUnet.
- (C) 2004, 2005, 2006 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/fsui/serializetest3.c
- * @brief testcase for fsui download persistence for search
- * @author Christian Grothoff
- */
-
-#include "platform.h"
-#include "gnunet_util.h"
-#include "gnunet_fsui_lib.h"
-
-#define DEBUG_VERBOSE GNUNET_NO
-
-#define UPLOAD_PREFIX "/tmp/gnunet-fsui-serializetest3"
-
-#define CHECK(a) if (!(a)) { ok = GNUNET_NO; GNUNET_GE_BREAK(ectx, 0); goto
FAILURE; }
-
-static struct GNUNET_GE_Context *ectx;
-
-static struct GNUNET_FSUI_Context *ctx;
-static struct GNUNET_FSUI_SearchList *search;
-static int have_error;
-
-static void *
-eventCallback (void *cls, const GNUNET_FSUI_Event * event)
-{
- switch (event->type)
- {
- case GNUNET_FSUI_search_suspended:
- search = NULL;
- break;
- case GNUNET_FSUI_search_resumed:
-#if DEBUG_VERBOSE
- printf ("Search resuming\n");
-#endif
- search = event->data.SearchResumed.sc.pos;
- break;
- case GNUNET_FSUI_search_result:
-#if DEBUG_VERBOSE
- printf ("Received search result\n");
-#endif
- break;
- case GNUNET_FSUI_upload_progress:
-#if DEBUG_VERBOSE
- printf ("Upload is progressing (%llu/%llu)...\n",
- event->data.UploadProgress.completed,
- event->data.UploadProgress.total);
-#endif
- break;
- case GNUNET_FSUI_upload_completed:
-#if DEBUG_VERBOSE
- printf ("Upload complete.\n");
-#endif
- break;
- case GNUNET_FSUI_unindex_progress:
-#if DEBUG_VERBOSE
- printf ("Unindex is progressing (%llu/%llu)...\n",
- event->data.UnindexProgress.completed,
- event->data.UnindexProgress.total);
-#endif
- break;
- case GNUNET_FSUI_unindex_completed:
-#if DEBUG_VERBOSE
- printf ("Unindex complete.\n");
-#endif
- break;
- case GNUNET_FSUI_unindex_error:
- case GNUNET_FSUI_upload_error:
- case GNUNET_FSUI_download_error:
- fprintf (stderr, "Received ERROR: %d\n", event->type);
- GNUNET_GE_BREAK (ectx, 0);
- break;
- case GNUNET_FSUI_download_aborted:
-#if DEBUG_VERBOSE
- printf ("Received download aborted event.\n");
-#endif
- break;
- case GNUNET_FSUI_unindex_suspended:
- case GNUNET_FSUI_upload_suspended:
-#if DEBUG_VERBOSE
- fprintf (stderr, "Received SUSPENDING: %d\n", event->type);
-#endif
- break;
- case GNUNET_FSUI_upload_started:
- case GNUNET_FSUI_upload_stopped:
- case GNUNET_FSUI_search_started:
- case GNUNET_FSUI_search_aborted:
- case GNUNET_FSUI_search_stopped:
- case GNUNET_FSUI_search_update:
- case GNUNET_FSUI_unindex_started:
- case GNUNET_FSUI_unindex_stopped:
- break;
- default:
- printf ("Unexpected event: %d\n", event->type);
- break;
- }
- return NULL;
-}
-
-#define FILESIZE (1024)
-
-#define START_DAEMON 1
-
-int
-main (int argc, char *argv[])
-{
-#if START_DAEMON
- pid_t daemon;
-#endif
- int ok;
- struct GNUNET_ECRS_URI *uri = NULL;
- char *keywords[] = {
- "down_foo",
- "down_bar",
- };
- char keyword[40];
- int prog;
- struct GNUNET_GC_Configuration *cfg;
- int suspendRestart = 0;
-
-
- ok = GNUNET_YES;
- 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 */
- /* ACTUAL TEST CODE */
-#endif
- ctx = GNUNET_FSUI_start (NULL,
- cfg, "serializetest3", 32, GNUNET_YES,
- &eventCallback, NULL);
- CHECK (ctx != NULL);
- GNUNET_snprintf (keyword, 40, "+%s +%s", keywords[0], keywords[1]);
- uri = GNUNET_ECRS_keyword_string_to_uri (ectx, keyword);
- search = GNUNET_FSUI_search_start (ctx, 0, uri);
- CHECK (search != NULL);
- prog = 0;
- suspendRestart = 10;
- while (prog < 100)
- {
- prog++;
- GNUNET_thread_sleep (50 * GNUNET_CRON_MILLISECONDS);
- if ((suspendRestart > 0)
- && (GNUNET_random_u32 (GNUNET_RANDOM_QUALITY_WEAK, 10) == 0))
- {
-#if 1
-#if DEBUG_VERBOSE
- printf ("Testing FSUI suspend-resume\n");
-#endif
- GNUNET_FSUI_stop (ctx); /* download possibly incomplete
- at this point, thus testing resume
*/
- CHECK (search == NULL);
- ctx = GNUNET_FSUI_start (NULL,
- cfg,
- "serializetest3", 32, GNUNET_YES,
- &eventCallback, NULL);
-#if DEBUG_VERBOSE
- printf ("Resumed...\n");
-#endif
-#endif
- suspendRestart--;
- }
- if (GNUNET_shutdown_test () == GNUNET_YES)
- break;
- }
- GNUNET_FSUI_search_abort (search);
- GNUNET_FSUI_search_stop (search);
- search = NULL;
- /* END OF TEST CODE */
-FAILURE:
- if (ctx != NULL)
- GNUNET_FSUI_stop (ctx);
- if (uri != NULL)
- GNUNET_ECRS_uri_destroy (uri);
-
-#if START_DAEMON
- GNUNET_GE_BREAK (NULL, GNUNET_OK == GNUNET_daemon_stop (NULL, daemon));
-#endif
- GNUNET_GC_free (cfg);
- if (have_error)
- ok = GNUNET_NO;
- return (ok == GNUNET_YES) ? 0 : 1;
-}
-
-/* end of serializetest3.c */
Deleted: GNUnet/src/applications/fs/fsui/serializetest4.c
===================================================================
--- GNUnet/src/applications/fs/fsui/serializetest4.c 2008-05-11 22:33:29 UTC
(rev 6800)
+++ GNUnet/src/applications/fs/fsui/serializetest4.c 2008-05-12 04:05:54 UTC
(rev 6801)
@@ -1,426 +0,0 @@
-/*
- This file is part of GNUnet.
- (C) 2004, 2005, 2006 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/fsui/serializetest4.c
- * @brief testcase for fsui download persistence for recursive
- * download
- * @author Christian Grothoff
- */
-
-#include "platform.h"
-#include "gnunet_util.h"
-#include "gnunet_fsui_lib.h"
-
-#define DEBUG_VERBOSE GNUNET_NO
-
-#define UPLOAD_PREFIX "/tmp/gnunet-fsui-serializetest4"
-
-#define CHECK(a) if (!(a)) { ok = GNUNET_NO; GNUNET_GE_BREAK(ectx, 0); goto
FAILURE; }
-
-static struct GNUNET_GE_Context *ectx;
-
-static char *
-makeName (unsigned int i)
-{
- char *fn;
-
- fn = GNUNET_malloc (strlen (UPLOAD_PREFIX "/FSUITEST") + 14);
- GNUNET_snprintf (fn,
- strlen (UPLOAD_PREFIX "/FSUITEST") + 14,
- UPLOAD_PREFIX "/FSUITEST%u", i);
- GNUNET_disk_directory_create_for_file (NULL, fn);
- return fn;
-}
-
-static struct GNUNET_FSUI_Context *ctx;
-static struct GNUNET_ECRS_URI *upURI;
-static struct GNUNET_FSUI_DownloadList *download;
-static int have_error;
-
-/**
- * Set to 1 if we are about to stop the search and
- * thus our simple tests for download event correctness
- * would not work correctly.
- */
-static int no_check;
-
-static void *
-eventCallback (void *cls, const GNUNET_FSUI_Event * event)
-{
- if (no_check)
- return NULL;
- switch (event->type)
- {
- case GNUNET_FSUI_download_suspended:
- if (event->data.DownloadSuspended.dc.spos != NULL)
- {
- fprintf (stderr,
- "Download suspended but search reference not set
correctly.\n");
- have_error = 1;
- }
- if ((event->data.DownloadSuspended.dc.pos == download) &&
- (event->data.DownloadSuspended.dc.ppos != NULL))
- {
- fprintf (stderr,
- "Download suspended but parent reference not set to
NULL.\n");
- have_error = 1;
- }
- if ((event->data.DownloadSuspended.dc.pos != download) &&
- (event->data.DownloadSuspended.dc.ppos != download))
- {
- fprintf (stderr,
- "Download suspended but parent reference not set correctly
(%p instead of %p).\n",
- event->data.DownloadSuspended.dc.ppos, download);
- have_error = 1;
- }
- if (event->data.DownloadSuspended.dc.pos == download)
- download = NULL;
- break;
- case GNUNET_FSUI_download_resumed:
- if (download == NULL)
- download = event->data.DownloadResumed.dc.pos;
- if (event->data.DownloadResumed.dc.spos != NULL)
- {
- fprintf (stderr,
- "Download resuming but search reference not set
correctly.\n");
- have_error = 1;
- }
- if ((event->data.DownloadResumed.dc.pos == download) &&
- (event->data.DownloadResumed.dc.ppos != NULL))
- {
- fprintf (stderr,
- "Download resuming but parent reference not set to
NULL.\n");
- have_error = 1;
- }
- if ((event->data.DownloadResumed.dc.pos != download) &&
- (event->data.DownloadResumed.dc.ppos != download))
- {
- fprintf (stderr,
- "Download resuming but parent reference not set
correctly.\n");
- have_error = 1;
- }
-#if DEBUG_VERBOSE
- printf ("Download resuming\n");
-#endif
- break;
- case GNUNET_FSUI_upload_progress:
-#if DEBUG_VERBOSE
- printf ("Upload is progressing (%llu/%llu)...\n",
- event->data.UploadProgress.completed,
- event->data.UploadProgress.total);
-#endif
- break;
- case GNUNET_FSUI_upload_completed:
- if (upURI != NULL)
- GNUNET_ECRS_uri_destroy (upURI);
- upURI = GNUNET_ECRS_uri_duplicate (event->data.UploadCompleted.uri);
-#if DEBUG_VERBOSE
- printf ("Upload complete.\n");
-#endif
- break;
- case GNUNET_FSUI_download_completed:
- if (event->data.DownloadCompleted.dc.spos != NULL)
- {
- fprintf (stderr,
- "Download completed but search reference not set
correctly.\n");
- have_error = 1;
- }
- if ((event->data.DownloadCompleted.dc.pos == download) &&
- (event->data.DownloadCompleted.dc.ppos != NULL))
- {
- fprintf (stderr,
- "Download completed but parent reference not set to
NULL.\n");
- have_error = 1;
- }
- if ((event->data.DownloadCompleted.dc.pos != download) &&
- (event->data.DownloadCompleted.dc.ppos != download))
- {
- fprintf (stderr,
- "Download completed but parent reference not set
correctly.\n");
- have_error = 1;
- }
-#if DEBUG_VERBOSE
- printf ("Download complete.\n");
-#endif
- break;
- case GNUNET_FSUI_download_progress:
- if (event->data.DownloadResumed.dc.spos != NULL)
- {
- fprintf (stderr,
- "Download progressing but search reference not set
correctly.\n");
- have_error = 1;
- }
- if ((event->data.DownloadResumed.dc.pos == download) &&
- (event->data.DownloadResumed.dc.ppos != NULL))
- {
- fprintf (stderr,
- "Download progressing but parent reference not set to
NULL.\n");
- have_error = 1;
- }
- if ((event->data.DownloadResumed.dc.pos != download) &&
- (event->data.DownloadResumed.dc.ppos != download))
- {
- fprintf (stderr,
- "Download progressing but parent reference not set
correctly.\n");
- have_error = 1;
- }
-#if DEBUG_VERBOSE
- printf ("Download is progressing (%llu/%llu)...\n",
- event->data.DownloadProgress.completed,
- event->data.DownloadProgress.total);
-#endif
- break;
- case GNUNET_FSUI_unindex_progress:
-#if DEBUG_VERBOSE
- printf ("Unindex is progressing (%llu/%llu)...\n",
- event->data.UnindexProgress.completed,
- event->data.UnindexProgress.total);
-#endif
- break;
- case GNUNET_FSUI_unindex_completed:
-#if DEBUG_VERBOSE
- printf ("Unindex complete.\n");
-#endif
- break;
- case GNUNET_FSUI_unindex_error:
- case GNUNET_FSUI_upload_error:
- case GNUNET_FSUI_download_error:
- fprintf (stderr, "Received ERROR: %d\n", event->type);
- GNUNET_GE_BREAK (ectx, 0);
- break;
- case GNUNET_FSUI_download_aborted:
-#if DEBUG_VERBOSE
- printf ("Received download aborted event.\n");
-#endif
- break;
- case GNUNET_FSUI_unindex_suspended:
- case GNUNET_FSUI_upload_suspended:
-#if DEBUG_VERBOSE
- fprintf (stderr, "Received SUSPENDING: %d\n", event->type);
-#endif
- break;
- case GNUNET_FSUI_download_started:
- if (download == NULL)
- download = event->data.DownloadStarted.dc.pos;
- if (event->data.DownloadStarted.dc.spos != NULL)
- {
- fprintf (stderr,
- "Download started but search reference not set
correctly.\n");
- have_error = 1;
- }
- if ((event->data.DownloadStarted.dc.pos == download) &&
- (event->data.DownloadStarted.dc.ppos != NULL))
- {
- fprintf (stderr,
- "Download started but parent reference not set to NULL.\n");
- have_error = 1;
- }
- if ((event->data.DownloadStarted.dc.pos != download) &&
- (event->data.DownloadStarted.dc.ppos != download))
- {
- fprintf (stderr,
- "Download started but parent reference not set
correctly.\n");
- have_error = 1;
- }
- break;
- case GNUNET_FSUI_download_stopped:
- if (event->data.DownloadStopped.dc.spos != NULL)
- {
- fprintf (stderr,
- "Download stopped but search reference not set
correctly.\n");
- have_error = 1;
- }
- if ((event->data.DownloadStopped.dc.pos == download) &&
- (event->data.DownloadStopped.dc.ppos != NULL))
- {
- fprintf (stderr,
- "Download stopped but parent reference not set to NULL.\n");
- have_error = 1;
- }
- if ((event->data.DownloadStopped.dc.pos != download) &&
- (event->data.DownloadStopped.dc.ppos != download))
- {
- fprintf (stderr,
- "Download stopped but parent reference not set
correctly.\n");
- have_error = 1;
- }
- break;
- case GNUNET_FSUI_upload_started:
- case GNUNET_FSUI_upload_stopped:
- case GNUNET_FSUI_search_started:
- case GNUNET_FSUI_search_aborted:
- case GNUNET_FSUI_search_stopped:
- case GNUNET_FSUI_unindex_started:
- case GNUNET_FSUI_unindex_stopped:
- break;
- default:
- printf ("Unexpected event: %d\n", event->type);
- break;
- }
- return NULL;
-}
-
-#define FILESIZE (1024)
-
-#define START_DAEMON 1
-
-int
-main (int argc, char *argv[])
-{
-#if START_DAEMON
- pid_t daemon;
-#endif
- int ok;
- int i;
- int j;
- struct GNUNET_ECRS_URI *uri = NULL;
- char *fn = NULL;
- char *keywords[] = {
- "down_foo",
- "down_bar",
- };
- char keyword[40];
- int prog;
- char *buf;
- struct GNUNET_ECRS_MetaData *meta;
- struct GNUNET_ECRS_URI *kuri = NULL;
- struct GNUNET_GC_Configuration *cfg;
- struct GNUNET_FSUI_UnindexList *unindex = NULL;
- struct GNUNET_FSUI_UploadList *upload = NULL;
- int suspendRestart = 0;
-
-
- ok = GNUNET_YES;
- 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 */
- /* ACTUAL TEST CODE */
-#endif
- ctx = GNUNET_FSUI_start (NULL,
- cfg, "serializetest4", 32, GNUNET_YES,
- &eventCallback, NULL);
- CHECK (ctx != NULL);
- for (j = 4; j < 16; j += 4)
- {
- fn = makeName (j);
- buf = GNUNET_malloc (FILESIZE * j);
- for (i = 0; i < FILESIZE; i++)
- buf[i] = GNUNET_random_u32 (GNUNET_RANDOM_QUALITY_WEAK, 256);
- GNUNET_disk_file_write (ectx, fn, buf, FILESIZE, "600");
- GNUNET_free (buf);
- GNUNET_free (fn);
- }
- meta = GNUNET_ECRS_meta_data_create ();
- kuri =
- GNUNET_ECRS_keyword_command_line_to_uri (ectx, 2,
- (const char **) keywords);
- GNUNET_ECRS_meta_data_insert (meta, EXTRACTOR_MIMETYPE,
- GNUNET_DIRECTORY_MIME);
- upload =
- GNUNET_FSUI_upload_start (ctx, UPLOAD_PREFIX,
- (GNUNET_FSUI_DirectoryScanCallback) &
- GNUNET_disk_directory_scan, NULL, 0, 0,
- GNUNET_YES, GNUNET_NO, GNUNET_NO,
- GNUNET_get_time () + 5 * GNUNET_CRON_HOURS,
- meta, kuri, kuri);
- CHECK (upload != NULL);
- GNUNET_ECRS_uri_destroy (kuri);
- kuri = NULL;
- GNUNET_FSUI_upload_stop (upload);
- CHECK (upURI != NULL);
- GNUNET_snprintf (keyword, 40, "+%s +%s", keywords[0], keywords[1]);
- uri = GNUNET_ECRS_keyword_string_to_uri (ectx, keyword);
- download = GNUNET_FSUI_download_start (ctx,
- 0,
- GNUNET_YES,
- upURI,
- meta, UPLOAD_PREFIX "-download",
- NULL, NULL);
- GNUNET_ECRS_meta_data_destroy (meta);
- prog = 0;
- suspendRestart = 10;
- while (prog < 100)
- {
- prog++;
- GNUNET_thread_sleep (50 * GNUNET_CRON_MILLISECONDS);
- if ((suspendRestart > 0)
- && (GNUNET_random_u32 (GNUNET_RANDOM_QUALITY_WEAK, 10) == 0))
- {
-#if 1
-#if DEBUG_VERBOSE
- printf ("Testing FSUI suspend-resume\n");
-#endif
- GNUNET_FSUI_stop (ctx); /* download possibly incomplete
- at this point, thus testing resume
*/
- CHECK (download == NULL);
- ctx = GNUNET_FSUI_start (NULL,
- cfg,
- "serializetest4", 32, GNUNET_YES,
- &eventCallback, NULL);
-#if DEBUG_VERBOSE
- printf ("Resumed...\n");
-#endif
-#endif
- suspendRestart--;
- }
- if (GNUNET_shutdown_test () == GNUNET_YES)
- break;
- }
- GNUNET_FSUI_download_stop (download);
- for (j = 4; j < 16; j += 4)
- {
- fn = makeName (j);
- unindex = GNUNET_FSUI_unindex_start (ctx, fn);
- GNUNET_FSUI_unindex_stop (unindex);
- UNLINK (fn);
- GNUNET_free (fn);
- }
- /* END OF TEST CODE */
-FAILURE:
- if (ctx != NULL)
- GNUNET_FSUI_stop (ctx);
- if (uri != NULL)
- GNUNET_ECRS_uri_destroy (uri);
- if (kuri != NULL)
- GNUNET_ECRS_uri_destroy (kuri);
- if (upURI != NULL)
- GNUNET_ECRS_uri_destroy (upURI);
-
-#if START_DAEMON
- GNUNET_GE_BREAK (NULL, GNUNET_OK == GNUNET_daemon_stop (NULL, daemon));
-#endif
- GNUNET_GC_free (cfg);
- if (have_error)
- ok = GNUNET_NO;
- return (ok == GNUNET_YES) ? 0 : 1;
-}
-
-/* end of serializetest4.c */
Copied: GNUnet/src/applications/fs/fsui/upload_unindex_persistence_test.c (from
rev 6789, GNUnet/src/applications/fs/fsui/serializetest.c)
===================================================================
--- GNUnet/src/applications/fs/fsui/upload_unindex_persistence_test.c
(rev 0)
+++ GNUnet/src/applications/fs/fsui/upload_unindex_persistence_test.c
2008-05-12 04:05:54 UTC (rev 6801)
@@ -0,0 +1,300 @@
+/*
+ This file is part of GNUnet.
+ (C) 2004, 2005, 2006 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/fsui/upload_unindex_persistence_test.c
+ * @brief testcase for fsui upload persistence
+ * @author Christian Grothoff
+ */
+
+#include "platform.h"
+#include "gnunet_util.h"
+#include "gnunet_fsui_lib.h"
+
+#define DEBUG_VERBOSE GNUNET_NO
+
+#define CHECK(a) if (!(a)) { ok = GNUNET_NO; GNUNET_GE_BREAK(ectx, 0); goto
FAILURE; }
+
+static volatile int suspendRestart = 0;
+
+static struct GNUNET_GE_Context *ectx;
+
+static char *
+makeName (unsigned int i)
+{
+ char *fn;
+
+ fn =
+ GNUNET_malloc (strlen
("/tmp/gnunet-fsui-upload-unindex-persistence-test/FSUITEST") + 14);
+ GNUNET_snprintf (fn,
+ strlen
("/tmp/gnunet-fsui-upload-unindex-persistence-test/FSUITEST") + 14,
+
"/tmp/gnunet-fsui-upload-unindex-persistence-test/FSUITEST%u", i);
+ GNUNET_disk_directory_create_for_file (NULL, fn);
+ return fn;
+}
+
+static volatile enum GNUNET_FSUI_EventType lastEvent;
+static volatile enum GNUNET_FSUI_EventType waitForEvent;
+static struct GNUNET_FSUI_Context *ctx;
+static struct GNUNET_ECRS_URI *upURI;
+static struct GNUNET_FSUI_UnindexList *unindex;
+static struct GNUNET_FSUI_UploadList *upload;
+
+
+static void *
+eventCallback (void *cls, const GNUNET_FSUI_Event * event)
+{
+ switch (event->type)
+ {
+ case GNUNET_FSUI_upload_progress:
+#if DEBUG_VERBOSE
+ printf ("Upload is progressing (%llu/%llu)...\n",
+ event->data.UploadProgress.completed,
+ event->data.UploadProgress.total);
+#endif
+ break;
+ case GNUNET_FSUI_upload_completed:
+ upURI = GNUNET_ECRS_uri_duplicate (event->data.UploadCompleted.uri);
+#if DEBUG_VERBOSE
+ printf ("Upload complete.\n");
+#endif
+ break;
+ case GNUNET_FSUI_unindex_progress:
+#if DEBUG_VERBOSE
+ printf ("Unindex is progressing (%llu/%llu)...\n",
+ event->data.UnindexProgress.completed,
+ event->data.UnindexProgress.total);
+#endif
+ break;
+ case GNUNET_FSUI_unindex_completed:
+#if DEBUG_VERBOSE
+ printf ("Unindex complete.\n");
+#endif
+ break;
+ case GNUNET_FSUI_unindex_error:
+ case GNUNET_FSUI_upload_error:
+ case GNUNET_FSUI_download_error:
+ fprintf (stderr, "Received ERROR: %d\n", event->type);
+ GNUNET_GE_BREAK (ectx, 0);
+ break;
+ case GNUNET_FSUI_download_aborted:
+#if DEBUG_VERBOSE
+ printf ("Received download aborted event.\n");
+#endif
+ break;
+ case GNUNET_FSUI_unindex_resumed:
+#if DEBUG_VERBOSE
+ fprintf (stderr, "Received RESUMING: %d\n", event->type);
+#endif
+ unindex = event->data.UnindexResumed.uc.pos;
+ break;
+ case GNUNET_FSUI_upload_resumed:
+#if DEBUG_VERBOSE
+ fprintf (stderr, "Received RESUMING: %d\n", event->type);
+#endif
+ upload = event->data.UploadResumed.uc.pos;
+ break;
+ break;
+ case GNUNET_FSUI_unindex_suspended:
+ unindex = NULL;
+#if DEBUG_VERBOSE
+ fprintf (stderr, "Received SUSPENDING: %d\n", event->type);
+#endif
+ break;
+ case GNUNET_FSUI_upload_suspended:
+ upload = NULL;
+#if DEBUG_VERBOSE
+ fprintf (stderr, "Received SUSPENDING: %d\n", event->type);
+#endif
+ break;
+ case GNUNET_FSUI_upload_started:
+ case GNUNET_FSUI_upload_stopped:
+ case GNUNET_FSUI_unindex_started:
+ case GNUNET_FSUI_unindex_stopped:
+ break;
+ default:
+ printf ("Unexpected event: %d\n", event->type);
+ break;
+ }
+ if (lastEvent == waitForEvent)
+ return NULL; /* ignore all other events */
+ lastEvent = event->type;
+ return NULL;
+}
+
+#define FILESIZE (1024 * 1024 * 2)
+
+#define START_DAEMON 1
+
+int
+main (int argc, char *argv[])
+{
+#if START_DAEMON
+ pid_t daemon;
+#endif
+ int ok;
+ int i;
+ char *fn = NULL;
+ char *keywords[] = {
+ "down_foo",
+ "down_bar",
+ };
+ int prog;
+ char *buf;
+ struct GNUNET_ECRS_MetaData *meta;
+ struct GNUNET_ECRS_URI *kuri = NULL;
+ struct GNUNET_GC_Configuration *cfg;
+
+ ok = GNUNET_YES;
+ 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 */
+ /* ACTUAL TEST CODE */
+#endif
+ ctx = GNUNET_FSUI_start (NULL,
+ cfg, "fsuiupload-unindex-persistence-test", 32,
GNUNET_YES,
+ &eventCallback, NULL);
+ CHECK (ctx != NULL);
+ fn = makeName (42);
+ buf = GNUNET_malloc (FILESIZE);
+ for (i = 0; i < FILESIZE; i++)
+ buf[i] = GNUNET_random_u32 (GNUNET_RANDOM_QUALITY_WEAK, 256);
+ GNUNET_disk_file_write (ectx, fn, buf, FILESIZE, "600");
+ GNUNET_free (buf);
+ meta = GNUNET_ECRS_meta_data_create ();
+ kuri =
+ GNUNET_ECRS_keyword_command_line_to_uri (ectx, 2,
+ (const char **) keywords);
+ waitForEvent = GNUNET_FSUI_upload_completed;
+ upload = GNUNET_FSUI_upload_start (ctx,
+ fn,
+ (GNUNET_FSUI_DirectoryScanCallback) &
+ GNUNET_disk_directory_scan, NULL, 0, 0,
+ GNUNET_YES, GNUNET_NO, GNUNET_NO,
+ GNUNET_get_time () +
+ 5 * GNUNET_CRON_HOURS, meta, kuri, kuri);
+ CHECK (upload != NULL);
+ GNUNET_ECRS_uri_destroy (kuri);
+ kuri = NULL;
+ GNUNET_ECRS_meta_data_destroy (meta);
+ prog = 0;
+ suspendRestart = 4;
+ while (lastEvent != GNUNET_FSUI_upload_completed)
+ {
+ if ((suspendRestart > 0)
+ && (GNUNET_random_u32 (GNUNET_RANDOM_QUALITY_WEAK, 4) == 0))
+ {
+#if 1
+#if DEBUG_VERBOSE
+ printf ("Testing FSUI suspend-resume\n");
+#endif
+ GNUNET_FSUI_stop (ctx); /* download possibly incomplete
+ at this point, thus testing resume
*/
+ ctx = GNUNET_FSUI_start (NULL,
+ cfg,
+ "fsuiupload-unindex-persistence-test",
+ 32, GNUNET_YES, &eventCallback, NULL);
+#if DEBUG_VERBOSE
+ printf ("Resumed...\n");
+#endif
+#endif
+ suspendRestart--;
+ }
+ prog++;
+ CHECK (prog < 5000);
+ GNUNET_thread_sleep (50 * GNUNET_CRON_MILLISECONDS);
+ if (GNUNET_shutdown_test () == GNUNET_YES)
+ break;
+ }
+ GNUNET_FSUI_upload_stop (upload);
+ waitForEvent = GNUNET_FSUI_unindex_completed;
+ unindex = GNUNET_FSUI_unindex_start (ctx, fn);
+ CHECK (unindex != NULL);
+ prog = 0;
+ suspendRestart = 4;
+ while (lastEvent != GNUNET_FSUI_unindex_completed)
+ {
+ if ((suspendRestart > 0)
+ && (GNUNET_random_u32 (GNUNET_RANDOM_QUALITY_WEAK, 4) == 0))
+ {
+#if 1
+#if DEBUG_VERBOSE
+ printf ("Testing FSUI suspend-resume\n");
+#endif
+ GNUNET_FSUI_stop (ctx); /* download possibly incomplete
+ at this point, thus testing resume
*/
+ ctx = GNUNET_FSUI_start (NULL,
+ cfg,
+ "fsuiupload-unindex-persistence-test",
+ 32, GNUNET_YES, &eventCallback, NULL);
+#if DEBUG_VERBOSE
+ printf ("Resumed...\n");
+#endif
+#endif
+ suspendRestart--;
+ }
+ prog++;
+ CHECK (prog < 5000);
+ GNUNET_thread_sleep (50 * GNUNET_CRON_MILLISECONDS);
+ CHECK (lastEvent != GNUNET_FSUI_unindex_error);
+ if (GNUNET_shutdown_test () == GNUNET_YES)
+ break;
+ }
+ CHECK (lastEvent == GNUNET_FSUI_unindex_completed);
+ /* END OF TEST CODE */
+FAILURE:
+ if (ctx != NULL)
+ {
+ if (unindex != NULL)
+ GNUNET_FSUI_unindex_stop (unindex);
+ GNUNET_FSUI_stop (ctx);
+ }
+ if (fn != NULL)
+ {
+ UNLINK (fn);
+ GNUNET_free (fn);
+ }
+ if (kuri != NULL)
+ GNUNET_ECRS_uri_destroy (kuri);
+ fn = makeName (43);
+ /* TODO: verify file 'fn(42)' == file 'fn(43)' */
+ UNLINK (fn);
+ GNUNET_free (fn);
+ if (upURI != NULL)
+ GNUNET_ECRS_uri_destroy (upURI);
+
+#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 upload-unindex-persistence-test.c */
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [GNUnet-SVN] r6801 - in GNUnet/src/applications/fs: ecrs fsui,
gnunet <=