Author: grothoff Date: 2008-02-25 21:32:09 -0700 (Mon, 25 Feb 2008) New Revision: 6465
Modified: GNUnet/src/applications/fs/fsui/downloadtest.c GNUnet/src/applications/fs/fsui/search.c GNUnet/src/applications/fs/fsui/serializetest3.c GNUnet/src/applications/fs/fsui/serializetest4.c Log: faster tests, code cleanup Modified: GNUnet/src/applications/fs/fsui/downloadtest.c =================================================================== --- GNUnet/src/applications/fs/fsui/downloadtest.c 2008-02-26 03:28:47 UTC (rev 6464) +++ GNUnet/src/applications/fs/fsui/downloadtest.c 2008-02-26 04:32:09 UTC (rev 6465) @@ -82,28 +82,27 @@ download = event->data.DownloadResumed.dc.pos; break; case GNUNET_FSUI_search_result: -#if DEBUG_VERBOSE - printf ("Received search result\n"); -#endif 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 search result for different file (download not started).\n"); + ("Received result for different file: %s.\n", + u); #endif + GNUNET_free(u); return NULL; /* ignore */ } - fn = makeName (43); - u = GNUNET_ECRS_uri_to_string (event->data.SearchResult.fi.uri); #if DEBUG_VERBOSE - printf ("Download started: %s.\n", u); + 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, @@ -121,7 +120,7 @@ } break; case GNUNET_FSUI_upload_progress: -#if DEBUG_VERBOSE +#if DEBUG_VERBOSE > 1 printf ("Upload is progressing (%llu/%llu)...\n", event->data.UploadProgress.completed, event->data.UploadProgress.total); @@ -142,14 +141,14 @@ search = NULL; break; case GNUNET_FSUI_download_progress: -#if DEBUG_VERBOSE +#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 +#if DEBUG_VERBOSE > 1 printf ("Unindex is progressing (%llu/%llu)...\n", event->data.UnindexProgress.completed, event->data.UnindexProgress.total); @@ -233,6 +232,7 @@ 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 == @@ -285,7 +285,7 @@ while (search != NULL) { prog++; - CHECK (prog < 10000); + CHECK (prog < 1000); GNUNET_thread_sleep (50 * GNUNET_CRON_MILLISECONDS); if ((suspendRestart > 0) && (GNUNET_random_u32 (GNUNET_RANDOM_QUALITY_WEAK, 4) == 0)) @@ -335,6 +335,8 @@ GNUNET_FSUI_unindex_stop (ctx, unindex); if (download != NULL) GNUNET_FSUI_download_stop (ctx, download); + if (search != NULL) + GNUNET_FSUI_search_stop (ctx, search); GNUNET_FSUI_stop (ctx); } if (fn != NULL) Modified: GNUnet/src/applications/fs/fsui/search.c =================================================================== --- GNUnet/src/applications/fs/fsui/search.c 2008-02-26 03:28:47 UTC (rev 6464) +++ GNUnet/src/applications/fs/fsui/search.c 2008-02-26 04:32:09 UTC (rev 6465) @@ -98,104 +98,97 @@ #endif return GNUNET_OK; /* seen before */ } - if (pos->numberOfURIKeys > 1) + if (pos->numberOfURIKeys == 1) { - if (key == NULL) - { - GNUNET_GE_BREAK (ectx, 0); #if DEBUG_SEARCH - GNUNET_GE_LOG (ectx, - GNUNET_GE_DEBUG | GNUNET_GE_REQUEST | GNUNET_GE_USER, - "Received search result without key to decrypt.\n"); + GNUNET_GE_LOG (ectx, + GNUNET_GE_DEBUG | GNUNET_GE_REQUEST | GNUNET_GE_USER, + "Received search result (showing client)!\n"); #endif - return GNUNET_SYSERR; - } - for (i = 0; i < pos->sizeUnmatchedResultsReceived; i++) - { - rp = &pos->unmatchedResultsReceived[i]; - if (GNUNET_ECRS_uri_test_equal (fi->uri, rp->fi.uri)) - { - for (j = 0; j < rp->matchingKeyCount; j++) - if (0 == memcmp (key, - &rp->matchingKeys[j], - sizeof (GNUNET_HashCode))) - { + processResult (fi, pos); + return GNUNET_OK; + } + if (key == NULL) + { + GNUNET_GE_BREAK (ectx, 0); #if DEBUG_SEARCH - GNUNET_GE_LOG (ectx, - GNUNET_GE_DEBUG | GNUNET_GE_REQUEST | - GNUNET_GE_USER, - "Received search result that I have seen before (missing keyword to show client).\n"); + GNUNET_GE_LOG (ectx, + GNUNET_GE_DEBUG | GNUNET_GE_REQUEST | GNUNET_GE_USER, + "Received search result without key to decrypt.\n"); #endif - return GNUNET_OK; - } - if (rp->matchingKeyCount + 1 == pos->numberOfURIKeys) - { + return GNUNET_SYSERR; + } + for (i = 0; i < pos->sizeUnmatchedResultsReceived; i++) + { + rp = &pos->unmatchedResultsReceived[i]; + if (! GNUNET_ECRS_uri_test_equal (fi->uri, rp->fi.uri)) + continue; + for (j = 0; j < rp->matchingKeyCount; j++) + if (0 == memcmp (key, + &rp->matchingKeys[j], + sizeof (GNUNET_HashCode))) + { #if DEBUG_SEARCH - GNUNET_GE_LOG (ectx, - GNUNET_GE_DEBUG | GNUNET_GE_REQUEST | - GNUNET_GE_USER, - "Received search result (showing client)!\n"); + GNUNET_GE_LOG (ectx, + GNUNET_GE_DEBUG | GNUNET_GE_REQUEST | + GNUNET_GE_USER, + "Received search result that I have seen before (missing keyword to show client).\n"); #endif - GNUNET_array_grow (rp->matchingKeys, rp->matchingKeyCount, - 0); - processResult (&rp->fi, pos); - GNUNET_ECRS_uri_destroy (rp->fi.uri); - GNUNET_ECRS_meta_data_destroy (rp->fi.meta); - pos->unmatchedResultsReceived[i] - = - pos->unmatchedResultsReceived[pos-> - sizeUnmatchedResultsReceived - - 1]; - GNUNET_array_grow (pos->unmatchedResultsReceived, - pos->sizeUnmatchedResultsReceived, - pos->sizeUnmatchedResultsReceived - 1); - return GNUNET_OK; - } - else - { - GNUNET_array_grow (rp->matchingKeys, - rp->matchingKeyCount, - rp->matchingKeyCount + 1); - rp->matchingKeys[rp->matchingKeyCount - 1] = *key; + return GNUNET_OK; + } + if (rp->matchingKeyCount + 1 == pos->numberOfURIKeys) + { #if DEBUG_SEARCH - GNUNET_GE_LOG (ectx, - GNUNET_GE_DEBUG | GNUNET_GE_REQUEST | - GNUNET_GE_USER, - "Received search result (waiting for more %u keys before showing client).\n", - pos->numberOfURIKeys - rp->matchingKeyCount); + GNUNET_GE_LOG (ectx, + GNUNET_GE_DEBUG | GNUNET_GE_REQUEST | + GNUNET_GE_USER, + "Received search result (showing client)!\n"); #endif - return GNUNET_OK; - } - } - } - GNUNET_array_grow (pos->unmatchedResultsReceived, - pos->sizeUnmatchedResultsReceived, - pos->sizeUnmatchedResultsReceived + 1); - rp = - &pos->unmatchedResultsReceived[pos->sizeUnmatchedResultsReceived - 1]; - rp->fi.meta = GNUNET_ECRS_meta_data_duplicate (fi->meta); - rp->fi.uri = GNUNET_ECRS_uri_duplicate (fi->uri); - rp->matchingKeys = NULL; - rp->matchingKeyCount = 0; - GNUNET_array_grow (rp->matchingKeys, rp->matchingKeyCount, 1); - rp->matchingKeys[0] = *key; + GNUNET_array_grow (rp->matchingKeys, rp->matchingKeyCount, + 0); + processResult (&rp->fi, pos); + GNUNET_ECRS_uri_destroy (rp->fi.uri); + GNUNET_ECRS_meta_data_destroy (rp->fi.meta); + pos->unmatchedResultsReceived[i] + = + pos->unmatchedResultsReceived[pos-> + sizeUnmatchedResultsReceived + - 1]; + GNUNET_array_grow (pos->unmatchedResultsReceived, + pos->sizeUnmatchedResultsReceived, + pos->sizeUnmatchedResultsReceived - 1); + return GNUNET_OK; + } + GNUNET_array_grow (rp->matchingKeys, + rp->matchingKeyCount, + rp->matchingKeyCount + 1); + rp->matchingKeys[rp->matchingKeyCount - 1] = *key; #if DEBUG_SEARCH GNUNET_GE_LOG (ectx, - GNUNET_GE_DEBUG | GNUNET_GE_REQUEST | GNUNET_GE_USER, - "Received search result (waiting for %u more keys before showing client).\n", - pos->numberOfURIKeys - rp->matchingKeyCount); + GNUNET_GE_DEBUG | GNUNET_GE_REQUEST | + GNUNET_GE_USER, + "Received search result (waiting for more %u keys before showing client).\n", + pos->numberOfURIKeys - rp->matchingKeyCount); #endif return GNUNET_OK; } - else - { + GNUNET_array_grow (pos->unmatchedResultsReceived, + pos->sizeUnmatchedResultsReceived, + pos->sizeUnmatchedResultsReceived + 1); + rp = + &pos->unmatchedResultsReceived[pos->sizeUnmatchedResultsReceived - 1]; + rp->fi.meta = GNUNET_ECRS_meta_data_duplicate (fi->meta); + rp->fi.uri = GNUNET_ECRS_uri_duplicate (fi->uri); + rp->matchingKeys = NULL; + rp->matchingKeyCount = 0; + GNUNET_array_grow (rp->matchingKeys, rp->matchingKeyCount, 1); + rp->matchingKeys[0] = *key; #if DEBUG_SEARCH - GNUNET_GE_LOG (ectx, - GNUNET_GE_DEBUG | GNUNET_GE_REQUEST | GNUNET_GE_USER, - "Received search result (showing client)!\n"); + GNUNET_GE_LOG (ectx, + GNUNET_GE_DEBUG | GNUNET_GE_REQUEST | GNUNET_GE_USER, + "Received search result (waiting for %u more keys before showing client).\n", + pos->numberOfURIKeys - rp->matchingKeyCount); #endif - processResult (fi, pos); - } return GNUNET_OK; } Modified: GNUnet/src/applications/fs/fsui/serializetest3.c =================================================================== --- GNUnet/src/applications/fs/fsui/serializetest3.c 2008-02-26 03:28:47 UTC (rev 6464) +++ GNUnet/src/applications/fs/fsui/serializetest3.c 2008-02-26 04:32:09 UTC (rev 6465) @@ -165,12 +165,12 @@ CHECK (search != NULL); prog = 0; suspendRestart = 10; - while (prog < 1000) + while (prog < 100) { prog++; GNUNET_thread_sleep (50 * GNUNET_CRON_MILLISECONDS); if ((suspendRestart > 0) - && (GNUNET_random_u32 (GNUNET_RANDOM_QUALITY_WEAK, 100) == 0)) + && (GNUNET_random_u32 (GNUNET_RANDOM_QUALITY_WEAK, 10) == 0)) { #if 1 #if DEBUG_VERBOSE Modified: GNUnet/src/applications/fs/fsui/serializetest4.c =================================================================== --- GNUnet/src/applications/fs/fsui/serializetest4.c 2008-02-26 03:28:47 UTC (rev 6464) +++ GNUnet/src/applications/fs/fsui/serializetest4.c 2008-02-26 04:32:09 UTC (rev 6465) @@ -354,6 +354,7 @@ GNUNET_ECRS_uri_destroy (kuri); kuri = NULL; GNUNET_FSUI_upload_stop (ctx, upload); + CHECK (upURI != NULL); GNUNET_snprintf (keyword, 40, "%s %s %s", keywords[0], _("AND"), keywords[1]); uri = GNUNET_ECRS_keyword_string_to_uri (ectx, keyword); @@ -366,12 +367,12 @@ GNUNET_ECRS_meta_data_destroy (meta); prog = 0; suspendRestart = 10; - while (prog < 1000) + while (prog < 100) { prog++; GNUNET_thread_sleep (50 * GNUNET_CRON_MILLISECONDS); if ((suspendRestart > 0) - && (GNUNET_random_u32 (GNUNET_RANDOM_QUALITY_WEAK, 100) == 0)) + && (GNUNET_random_u32 (GNUNET_RANDOM_QUALITY_WEAK, 10) == 0)) { #if 1 #if DEBUG_VERBOSE _______________________________________________ GNUnet-SVN mailing list GNUnet-SVN@gnu.org http://lists.gnu.org/mailman/listinfo/gnunet-svn