diff options
author | Christian Grothoff <christian@grothoff.org> | 2012-09-09 13:28:48 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2012-09-09 13:28:48 +0000 |
commit | 9d732bb204de9177aad6ae70c910cbf2615d81a3 (patch) | |
tree | 44ddd6e9e1dad749db51003acfa46d7835593dc6 /src/fs/test_fs_test_lib.c | |
parent | a1d7926951beb7466a1462e43b9933530e5825f7 (diff) | |
download | gnunet-9d732bb204de9177aad6ae70c910cbf2615d81a3.tar.gz gnunet-9d732bb204de9177aad6ae70c910cbf2615d81a3.zip |
make fs tests build against new testbed library -- they do not pass yet
Diffstat (limited to 'src/fs/test_fs_test_lib.c')
-rw-r--r-- | src/fs/test_fs_test_lib.c | 98 |
1 files changed, 46 insertions, 52 deletions
diff --git a/src/fs/test_fs_test_lib.c b/src/fs/test_fs_test_lib.c index 29d5fe47f..bee7909a9 100644 --- a/src/fs/test_fs_test_lib.c +++ b/src/fs/test_fs_test_lib.c | |||
@@ -1,6 +1,6 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of GNUnet. | 2 | This file is part of GNUnet. |
3 | (C) 2010 Christian Grothoff (and other contributing authors) | 3 | (C) 2010, 2012 Christian Grothoff (and other contributing authors) |
4 | 4 | ||
5 | GNUnet is free software; you can redistribute it and/or modify | 5 | GNUnet is free software; you can redistribute it and/or modify |
6 | it under the terms of the GNU General Public License as published | 6 | it under the terms of the GNU General Public License as published |
@@ -42,20 +42,14 @@ | |||
42 | 42 | ||
43 | #define SEED 42 | 43 | #define SEED 42 |
44 | 44 | ||
45 | static struct GNUNET_FS_TestDaemon *daemons[NUM_DAEMONS]; | 45 | static struct GNUNET_TESTBED_Peer *the_peers[NUM_DAEMONS]; |
46 | |||
47 | static struct GNUNET_FS_TEST_ConnectContext *cc; | ||
48 | 46 | ||
49 | static int ret; | 47 | static int ret; |
50 | 48 | ||
49 | |||
51 | static void | 50 | static void |
52 | do_stop (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 51 | do_stop (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
53 | { | 52 | { |
54 | if (NULL != cc) | ||
55 | { | ||
56 | GNUNET_FS_TEST_daemons_connect_cancel (cc); | ||
57 | cc = NULL; | ||
58 | } | ||
59 | if (0 == (tc->reason & GNUNET_SCHEDULER_REASON_PREREQ_DONE)) | 53 | if (0 == (tc->reason & GNUNET_SCHEDULER_REASON_PREREQ_DONE)) |
60 | { | 54 | { |
61 | GNUNET_break (0); | 55 | GNUNET_break (0); |
@@ -66,7 +60,7 @@ do_stop (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
66 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Finished download, shutting down\n", | 60 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Finished download, shutting down\n", |
67 | (unsigned long long) FILESIZE); | 61 | (unsigned long long) FILESIZE); |
68 | } | 62 | } |
69 | GNUNET_FS_TEST_daemons_stop (NUM_DAEMONS, daemons); | 63 | GNUNET_SCHEDULER_shutdown (); |
70 | } | 64 | } |
71 | 65 | ||
72 | 66 | ||
@@ -76,80 +70,80 @@ do_download (void *cls, const struct GNUNET_FS_Uri *uri) | |||
76 | if (NULL == uri) | 70 | if (NULL == uri) |
77 | { | 71 | { |
78 | GNUNET_break (0); | 72 | GNUNET_break (0); |
79 | GNUNET_SCHEDULER_add_now (&do_stop, NULL); | 73 | GNUNET_SCHEDULER_shutdown (); |
80 | ret = 1; | 74 | ret = 1; |
81 | return; | 75 | return; |
82 | } | 76 | } |
83 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Downloading %llu bytes\n", | 77 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Downloading %llu bytes\n", |
84 | (unsigned long long) FILESIZE); | 78 | (unsigned long long) FILESIZE); |
85 | GNUNET_FS_TEST_download (daemons[0], TIMEOUT, 1, SEED, uri, VERBOSE, &do_stop, | 79 | GNUNET_FS_TEST_download (the_peers[0], TIMEOUT, 1, SEED, uri, VERBOSE, &do_stop, |
86 | NULL); | 80 | NULL); |
87 | } | 81 | } |
88 | 82 | ||
89 | 83 | ||
90 | static void | 84 | static void |
91 | do_publish (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 85 | do_publish (void *cls, |
86 | struct GNUNET_TESTBED_Operation *op, | ||
87 | const char *emsg) | ||
92 | { | 88 | { |
93 | cc = NULL; | 89 | if (NULL != emsg) |
94 | if (0 == (tc->reason & GNUNET_SCHEDULER_REASON_PREREQ_DONE)) | ||
95 | { | 90 | { |
91 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to connect peers: %s\n", emsg); | ||
96 | GNUNET_break (0); | 92 | GNUNET_break (0); |
97 | ret = 1; | 93 | ret = 1; |
98 | GNUNET_SCHEDULER_add_now (&do_stop, NULL); | 94 | GNUNET_SCHEDULER_shutdown (); |
99 | return; | 95 | return; |
100 | } | 96 | } |
97 | GNUNET_TESTBED_operation_done (op); | ||
101 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Publishing %llu bytes\n", | 98 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Publishing %llu bytes\n", |
102 | (unsigned long long) FILESIZE); | 99 | (unsigned long long) FILESIZE); |
103 | GNUNET_FS_TEST_publish (daemons[0], TIMEOUT, 1, GNUNET_NO, FILESIZE, SEED, | 100 | GNUNET_FS_TEST_publish (the_peers[0], TIMEOUT, 1, GNUNET_NO, FILESIZE, SEED, |
104 | VERBOSE, &do_download, NULL); | 101 | VERBOSE, &do_download, NULL); |
105 | } | ||
106 | |||
107 | 102 | ||
108 | static void | ||
109 | do_connect (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
110 | { | ||
111 | if (0 == (tc->reason & GNUNET_SCHEDULER_REASON_PREREQ_DONE)) | ||
112 | { | ||
113 | GNUNET_break (0); | ||
114 | ret = 1; | ||
115 | GNUNET_SCHEDULER_add_now (&do_stop, NULL); | ||
116 | return; | ||
117 | } | ||
118 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
119 | "Daemons started, will now try to connect them\n"); | ||
120 | cc = GNUNET_FS_TEST_daemons_connect (daemons[0], daemons[1], TIMEOUT, | ||
121 | &do_publish, NULL); | ||
122 | } | 103 | } |
123 | 104 | ||
124 | 105 | ||
106 | /** | ||
107 | * Actual main function for the test. | ||
108 | * | ||
109 | * @param cls closure | ||
110 | * @param num_peers number of peers in 'peers' | ||
111 | * @param peers handle to peers run in the testbed | ||
112 | */ | ||
125 | static void | 113 | static void |
126 | run (void *cls, char *const *args, const char *cfgfile, | 114 | run (void *cls, |
127 | const struct GNUNET_CONFIGURATION_Handle *cfg) | 115 | unsigned int num_peers, |
116 | struct GNUNET_TESTBED_Peer **peers) | ||
128 | { | 117 | { |
129 | GNUNET_FS_TEST_daemons_start ("fs_test_lib_data.conf", TIMEOUT, NUM_DAEMONS, | 118 | unsigned int i; |
130 | daemons, &do_connect, NULL); | 119 | |
120 | GNUNET_assert (NUM_DAEMONS == num_peers); | ||
121 | for (i=0;i<num_peers;i++) | ||
122 | the_peers[i] = peers[i]; | ||
123 | GNUNET_TESTBED_overlay_connect (NULL, | ||
124 | &do_publish, | ||
125 | NULL, | ||
126 | peers[0], | ||
127 | peers[1]); | ||
131 | } | 128 | } |
132 | 129 | ||
133 | 130 | ||
131 | /** | ||
132 | * Main function that initializes the testbed. | ||
133 | * | ||
134 | * @param argc ignored | ||
135 | * @param argv ignored | ||
136 | * @return 0 on success | ||
137 | */ | ||
134 | int | 138 | int |
135 | main (int argc, char *argv[]) | 139 | main (int argc, char *argv[]) |
136 | { | 140 | { |
137 | char *const argvx[] = { | ||
138 | "test-fs-test-lib", | ||
139 | "-c", | ||
140 | "fs_test_lib_data.conf", | ||
141 | NULL | ||
142 | }; | ||
143 | struct GNUNET_GETOPT_CommandLineOption options[] = { | ||
144 | GNUNET_GETOPT_OPTION_END | ||
145 | }; | ||
146 | |||
147 | GNUNET_DISK_directory_remove ("/tmp/gnunet-test-fs-lib/"); | 141 | GNUNET_DISK_directory_remove ("/tmp/gnunet-test-fs-lib/"); |
148 | GNUNET_log_setup ("test_fs_test_lib", | 142 | GNUNET_TESTBED_test_run ("test_fs_test_lib", |
149 | "WARNING", | 143 | "fs_test_lib_data.conf", |
150 | NULL); | 144 | NUM_DAEMONS, |
151 | GNUNET_PROGRAM_run ((sizeof (argvx) / sizeof (char *)) - 1, argvx, | 145 | 0, NULL, NULL, |
152 | "test-fs-test-lib", "nohelp", options, &run, NULL); | 146 | &run, NULL); |
153 | GNUNET_DISK_directory_remove ("/tmp/gnunet-test-fs-lib/"); | 147 | GNUNET_DISK_directory_remove ("/tmp/gnunet-test-fs-lib/"); |
154 | return ret; | 148 | return ret; |
155 | } | 149 | } |