[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] r262 - in GNUnet/src: applications/fs/ecrs applications/fs/
From: |
grothoff |
Subject: |
[GNUnet-SVN] r262 - in GNUnet/src: applications/fs/ecrs applications/fs/lib util |
Date: |
Mon, 14 Feb 2005 17:53:48 -0800 (PST) |
Author: grothoff
Date: 2005-02-14 17:53:47 -0800 (Mon, 14 Feb 2005)
New Revision: 262
Added:
GNUnet/src/applications/fs/ecrs/ecrstest.c
GNUnet/src/applications/fs/lib/check.conf
Modified:
GNUnet/src/applications/fs/ecrs/Makefile.am
GNUnet/src/applications/fs/lib/Makefile.am
GNUnet/src/applications/fs/lib/fslib.c
GNUnet/src/applications/fs/lib/fslibtest.c
GNUnet/src/util/storage.c
Log:
more fslibtest code
Modified: GNUnet/src/applications/fs/ecrs/Makefile.am
===================================================================
--- GNUnet/src/applications/fs/ecrs/Makefile.am 2005-02-15 01:03:07 UTC (rev
261)
+++ GNUnet/src/applications/fs/ecrs/Makefile.am 2005-02-15 01:53:47 UTC (rev
262)
@@ -25,8 +25,9 @@
check_PROGRAMS = \
+ uritest \
metatest \
- uritest
+ ecrstest
TESTS = $(check_PROGRAMS)
@@ -35,9 +36,12 @@
uritest_LDADD = \
$(top_builddir)/src/applications/fs/ecrs/libgnunetecrs.la
-
metatest_SOURCES = \
metatest.c
metatest_LDADD = \
$(top_builddir)/src/applications/fs/ecrs/libgnunetecrs.la
+ecrstest_SOURCES = \
+ ecrstest.c
+ecrstest_LDADD = \
+ $(top_builddir)/src/applications/fs/ecrs/libgnunetecrs.la
Added: GNUnet/src/applications/fs/ecrs/ecrstest.c
===================================================================
--- GNUnet/src/applications/fs/ecrs/ecrstest.c 2005-02-15 01:03:07 UTC (rev
261)
+++ GNUnet/src/applications/fs/ecrs/ecrstest.c 2005-02-15 01:53:47 UTC (rev
262)
@@ -0,0 +1,85 @@
+/**
+ * @file applications/fs/ecrs/ecrstest.c
+ * @brief testcase for ecrs (upload-download)
+ * @author Christian Grothoff
+ */
+
+#include "platform.h"
+#include "gnunet_util.h"
+#include "gnunet_ecrs_lib.h"
+#include <sys/wait.h>
+
+#define CHECK(a) if (!(a)) { ok = NO; BREAK(); goto FAILURE; }
+
+static int parseCommandLine(int argc,
+ char * argv[]) {
+ FREENONNULL(setConfigurationString("GNUNETD",
+ "_MAGIC_",
+ "NO"));
+ FREENONNULL(setConfigurationString("GNUNETD",
+ "LOGFILE",
+ NULL));
+ FREENONNULL(setConfigurationString("GNUNET",
+ "LOGLEVEL",
+ "WARNING"));
+ return OK;
+}
+
+
+int main(int argc, char * argv[]){
+ pid_t daemon;
+ int status;
+ int ok;
+ Mutex lock;
+ GNUNET_TCP_SOCKET * sock;
+ int i;
+
+ daemon = fork();
+ if (daemon == 0) {
+ /* FIXME: would be nice to be able to tell
+ gnunetd to use the check/debug DB and not
+ any real DB! */
+ if (0 != execlp("gnunetd", /* what binary to execute, must be in $PATH! */
+ "gnunetd", /* arg0, path to gnunet binary */
+ "-d", /* do not daemonize so we can easily kill you */
+ "-L",
+ "DEBUG", /* gnunetd loglevel */
+ NULL)) {
+ fprintf(stderr,
+ _("'%s' failed: %s\n"),
+ "execlp",
+ STRERROR(errno));
+ return -1;
+ }
+ }
+ ok = YES;
+ initUtil(argc, argv, &parseCommandLine);
+ startCron();
+ MUTEX_CREATE(&lock);
+ gnunet_util_sleep(5 * cronSECONDS); /* give gnunetd time to start */
+ sock = getClientSocket();
+ CHECK(sock != NULL);
+
+ /* ACTUAL TEST CODE */
+ /* TO BE ADDED */
+
+ /* END OF TEST CODE */
+ FAILURE:
+ if (sock != NULL)
+ releaseClientSocket(sock);
+ MUTEX_DESTROY(&lock);
+ stopCron();
+ doneUtil();
+ if (0 != kill(daemon, SIGTERM))
+ DIE_STRERROR("kill");
+ if (daemon != waitpid(daemon, &status, 0))
+ DIE_STRERROR("waitpid");
+
+ if ( (WEXITSTATUS(status) == 0) &&
+ (ok == YES) )
+ return 0;
+ else
+ return 1;
+}
+
+/* end of ecrstest.c */
Modified: GNUnet/src/applications/fs/lib/Makefile.am
===================================================================
--- GNUnet/src/applications/fs/lib/Makefile.am 2005-02-15 01:03:07 UTC (rev
261)
+++ GNUnet/src/applications/fs/lib/Makefile.am 2005-02-15 01:53:47 UTC (rev
262)
@@ -10,10 +10,6 @@
$(top_builddir)/src/applications/fs/libecrs_core.la
-################################
-# TESTCASES
-################################
-
check_PROGRAMS = \
fslibtest
@@ -24,3 +20,6 @@
fslibtest_LDADD = \
$(top_builddir)/src/applications/fs/lib/libgnunetfs.la \
$(top_builddir)/src/util/libgnunetutil.la
+
+EXTRA_DIST = \
+ check.conf
\ No newline at end of file
Added: GNUnet/src/applications/fs/lib/check.conf
===================================================================
--- GNUnet/src/applications/fs/lib/check.conf 2005-02-15 01:03:07 UTC (rev
261)
+++ GNUnet/src/applications/fs/lib/check.conf 2005-02-15 01:53:47 UTC (rev
262)
@@ -0,0 +1,49 @@
+# This is the configuration for the GNUnet daemon when running
+# the test in this directory (make check).
+
+GNUNETD_HOME = /tmp/gnunet-check
+
+[GNUNETD]
+HELOEXPIRES = 60
+LOGLEVEL = NOTHING
+LOGFILE = $GNUNETD_HOME/logs
+KEEPLOG = 0
+PIDFILE = $GNUNETD_HOME/gnunetd.pid
+HOSTS = $GNUNETD_HOME/data/hosts/
+APPLICATIONS = "fs"
+# TRANSPORTS = -- no transports!
+
+[MODULES]
+sqstore = "sqstore_mysql"
+# FIXME: use sqstore here once available!
+
+[NETWORK]
+PORT = 2087
+INTERFACE = eth0
+HELOEXCHANGE = NO
+TRUSTED = 127.0.0.0/8;
+
+[LOAD]
+INTERFACES = eth0
+BASICLIMITING = YES
+MAXNETUPBPSTOTAL = 50000
+MAXNETDOWNBPSTOTAL = 50000
+MAXCPULOAD = 100
+
+[FS]
+QUOTA = 1024
+ACTIVEMIGRATION = NO
+DIR = $GNUNETD_HOME/data/fs/
+INDEX-DIRECTORY = $GNUNETD_HOME/data/shared/
+INDEX-QUOTA = 8192
+
+[MYSQL]
+DELAYED = NO
+
+[GAP]
+TABLESIZE = 65536
+
+[DHT]
+BUCKETCOUNT = 160
+MASTER-TABLE-SIZE = 65536
+
Modified: GNUnet/src/applications/fs/lib/fslib.c
===================================================================
--- GNUnet/src/applications/fs/lib/fslib.c 2005-02-15 01:03:07 UTC (rev
261)
+++ GNUnet/src/applications/fs/lib/fslib.c 2005-02-15 01:53:47 UTC (rev
262)
@@ -261,6 +261,10 @@
RequestInsert * ri;
unsigned int size;
+ if (ntohl(block->size) <= sizeof(Datastore_Value)) {
+ BREAK();
+ return SYSERR;
+ }
size = ntohl(block->size) - sizeof(Datastore_Value);
ri = MALLOC(sizeof(RequestInsert) + size);
ri->header.size = htons(sizeof(RequestInsert) + size);
Modified: GNUnet/src/applications/fs/lib/fslibtest.c
===================================================================
--- GNUnet/src/applications/fs/lib/fslibtest.c 2005-02-15 01:03:07 UTC (rev
261)
+++ GNUnet/src/applications/fs/lib/fslibtest.c 2005-02-15 01:53:47 UTC (rev
262)
@@ -1,14 +1,17 @@
/**
* @file applications/fs/lib/fslibtest.c
* @brief testcase for fslib
+ * @author Christian Grothoff
*/
#include "platform.h"
#include "gnunet_util.h"
#include "gnunet_fs_lib.h"
+#include "gnunet_protocols.h"
+#include "ecrs_core.h"
#include <sys/wait.h>
-#define CHECK(a) if (!(a)) { ok = NO; goto FAILURE; }
+#define CHECK(a) if (!(a)) { ok = NO; BREAK(); goto FAILURE; }
static int parseCommandLine(int argc,
char * argv[]) {
@@ -24,6 +27,88 @@
return OK;
}
+static Datastore_Value * makeBlock(int i) {
+ Datastore_Value * block;
+ DBlock * db;
+
+ block = MALLOC(sizeof(Datastore_Value) +
+ sizeof(DBlock) + i);
+ block->size = htonl(sizeof(Datastore_Value) +
+ sizeof(DBlock) + i);
+ block->type = htonl(D_BLOCK);
+ block->prio = htonl(0);
+ block->anonymityLevel = htonl(0);
+ block->expirationTime = cronTime(NULL) + 1 * cronHOURS;
+ db = (DBlock*) &block[1];
+ db->type = htonl(D_BLOCK);
+ memset(&db[1],
+ i + (i /253),
+ i);
+ return block;
+}
+
+typedef struct {
+ Semaphore * sem;
+ int found;
+ int i;
+} TSC;
+
+static void abortSem(Semaphore * sem) {
+ SEMAPHORE_UP(sem);
+}
+
+static int searchResultCB(const HashCode160 * key,
+ const Datastore_Value * value,
+ TSC * cls) {
+ /* FIXME: verify result... */
+ cls->found = YES;
+ SEMAPHORE_UP(cls->sem);
+ return SYSERR;
+}
+
+static int trySearch(struct FS_SEARCH_CONTEXT * ctx,
+ int i) {
+ struct FS_SEARCH_HANDLE * handle;
+ cron_t now;
+ HashCode160 query;
+ TSC closure;
+ Datastore_Value * dv;
+ DBlock * db;
+
+ dv = makeBlock(i);
+ db = (DBlock*) &dv[1];
+ fileBlockGetQuery(db,
+ ntohl(dv->size) - sizeof(Datastore_Value),
+ &query);
+ FREE(dv);
+ closure.found = NO;
+ closure.i = i;
+ closure.sem = SEMAPHORE_NEW(0);
+ cronTime(&now);
+ handle = FS_start_search(ctx,
+ D_BLOCK,
+ 1,
+ &query,
+ 0,
+ 0,
+ now + 30 * cronSECONDS,
+ (Datum_Iterator)&searchResultCB,
+ &closure);
+ addCronJob((CronJob) &abortSem,
+ 30 * cronSECONDS,
+ 0,
+ closure.sem);
+ SEMAPHORE_DOWN(closure.sem);
+ FS_stop_search(ctx,
+ handle);
+ suspendCron();
+ delCronJob((CronJob) &abortSem, 0, closure.sem);
+ resumeCron();
+ SEMAPHORE_FREE(closure.sem);
+ return closure.found;
+}
+
+
int main(int argc, char * argv[]){
pid_t daemon;
int status;
@@ -31,39 +116,94 @@
struct FS_SEARCH_CONTEXT * ctx;
Mutex lock;
GNUNET_TCP_SOCKET * sock;
+ Datastore_Value * block;
+ HashCode160 hc;
+ int i;
+ memset(&hc, 42, sizeof(HashCode160));
daemon = fork();
if (daemon == 0) {
+ /* FIXME: would be nice to be able to tell
+ gnunetd to use the check/debug DB and not
+ any real DB! */
if (0 != execlp("gnunetd", /* what binary to execute, must be in $PATH! */
"gnunetd", /* arg0, path to gnunet binary */
"-d", /* do not daemonize so we can easily kill you */
"-L",
"DEBUG", /* gnunetd loglevel */
+ "-c",
+ "check.conf", /* configuration file */
NULL)) {
fprintf(stderr,
_("'%s' failed: %s\n"),
"execlp",
- strerror(errno));
+ STRERROR(errno));
return -1;
}
}
ok = YES;
initUtil(argc, argv, &parseCommandLine);
+ startCron();
MUTEX_CREATE(&lock);
gnunet_util_sleep(5 * cronSECONDS); /* give gnunetd time to start */
sock = getClientSocket();
CHECK(sock != NULL);
+ ctx = FS_SEARCH_makeContext(&lock);
+ CHECK(ctx != NULL);
/* ACTUAL TEST CODE */
+ for (i=1;i<32;i++) {
+ block = makeBlock(i);
+ CHECK(OK == FS_insert(sock,
+ block));
+ CHECK(OK == trySearch(ctx, i));
+ CHECK(OK == FS_delete(sock,
+ block));
+ hash(&((DBlock*)&block[1])[1],
+ ntohl(block->size) - sizeof(Datastore_Value) - sizeof(DBlock),
+ &hc);
+ CHECK(OK == FS_index(sock,
+ &hc,
+ block,
+ 0));
+ CHECK(OK == trySearch(ctx, i));
+ CHECK(OK == FS_unindex(sock,
+ MAX_BUFFER_SIZE,
+ &hc));
+ FREE(block);
+ }
+ for (i=32;i<MAX_BUFFER_SIZE;i*=2) {
+ block = makeBlock(i);
+ CHECK(OK == FS_insert(sock,
+ block));
+ CHECK(OK == trySearch(ctx, i));
+ CHECK(OK == FS_delete(sock,
+ block));
+ hash(&((DBlock*)&block[1])[1],
+ ntohl(block->size) - sizeof(Datastore_Value) - sizeof(DBlock),
+ &hc);
+ CHECK(OK == FS_index(sock,
+ &hc,
+ block,
+ 0));
+ CHECK(OK == trySearch(ctx, i));
+ CHECK(OK == FS_unindex(sock,
+ MAX_BUFFER_SIZE,
+ &hc));
+ FREE(block);
+ }
-
+ /* just to check if it crashes... */
+ FS_getAveragePriority(sock);
-
/* END OF TEST CODE */
FAILURE:
+ if (ctx != NULL)
+ FS_SEARCH_destroyContext(ctx);
if (sock != NULL)
releaseClientSocket(sock);
MUTEX_DESTROY(&lock);
+ stopCron();
doneUtil();
if (0 != kill(daemon, SIGTERM))
DIE_STRERROR("kill");
Modified: GNUnet/src/util/storage.c
===================================================================
--- GNUnet/src/util/storage.c 2005-02-15 01:03:07 UTC (rev 261)
+++ GNUnet/src/util/storage.c 2005-02-15 01:53:47 UTC (rev 262)
@@ -479,6 +479,10 @@
return;
handle = OPEN(fileName,
O_CREAT|O_WRONLY,S_IRUSR|S_IWUSR);
+ if (handle == -1) {
+ LOG_FILE_STRERROR(LOG_WARNING, "open", fileName);
+ return;
+ }
/* write the buffer take length from the beginning */
if (n != WRITE(handle, buffer, n))
LOG_FILE_STRERROR(LOG_WARNING, "write", fileName);
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [GNUnet-SVN] r262 - in GNUnet/src: applications/fs/ecrs applications/fs/lib util,
grothoff <=