aboutsummaryrefslogtreecommitdiff
path: root/src/fs/test_fs_test_lib.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/fs/test_fs_test_lib.c')
-rw-r--r--src/fs/test_fs_test_lib.c120
1 files changed, 49 insertions, 71 deletions
diff --git a/src/fs/test_fs_test_lib.c b/src/fs/test_fs_test_lib.c
index 3c6826181..9aa7b2ee3 100644
--- a/src/fs/test_fs_test_lib.c
+++ b/src/fs/test_fs_test_lib.c
@@ -47,112 +47,91 @@ static struct GNUNET_FS_TestDaemon *daemons[NUM_DAEMONS];
47static int ret; 47static int ret;
48 48
49static void 49static void
50do_stop (void *cls, 50do_stop (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
51 const struct GNUNET_SCHEDULER_TaskContext *tc)
52{ 51{
53 if (0 == (tc->reason & GNUNET_SCHEDULER_REASON_PREREQ_DONE)) 52 if (0 == (tc->reason & GNUNET_SCHEDULER_REASON_PREREQ_DONE))
54 { 53 {
55 GNUNET_break (0); 54 GNUNET_break (0);
56 ret = 1; 55 ret = 1;
57 } 56 }
58 else 57 else
59 { 58 {
60 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 59 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
61 "Finished download, shutting down\n", 60 "Finished download, shutting down\n",
62 (unsigned long long) FILESIZE); 61 (unsigned long long) FILESIZE);
63 } 62 }
64 GNUNET_FS_TEST_daemons_stop (NUM_DAEMONS, 63 GNUNET_FS_TEST_daemons_stop (NUM_DAEMONS, daemons);
65 daemons);
66} 64}
67 65
68 66
69static void 67static void
70do_download (void *cls, 68do_download (void *cls, const struct GNUNET_FS_Uri *uri)
71 const struct GNUNET_FS_Uri *uri)
72{ 69{
73 if (NULL == uri) 70 if (NULL == uri)
74 { 71 {
75 GNUNET_break (0); 72 GNUNET_break (0);
76 GNUNET_SCHEDULER_add_now (&do_stop, 73 GNUNET_SCHEDULER_add_now (&do_stop, NULL);
77 NULL); 74 ret = 1;
78 ret = 1; 75 return;
79 return; 76 }
80 }
81 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 77 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
82 "Downloading %llu bytes\n", 78 "Downloading %llu bytes\n", (unsigned long long) FILESIZE);
83 (unsigned long long) FILESIZE);
84 GNUNET_FS_TEST_download (daemons[0], 79 GNUNET_FS_TEST_download (daemons[0],
85 TIMEOUT, 80 TIMEOUT, 1, SEED, uri, VERBOSE, &do_stop, NULL);
86 1, SEED, uri,
87 VERBOSE,
88 &do_stop, NULL);
89} 81}
90 82
91 83
92static void 84static void
93do_publish (void *cls, 85do_publish (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
94 const struct GNUNET_SCHEDULER_TaskContext *tc)
95{ 86{
96 if (0 == (tc->reason & GNUNET_SCHEDULER_REASON_PREREQ_DONE)) 87 if (0 == (tc->reason & GNUNET_SCHEDULER_REASON_PREREQ_DONE))
97 { 88 {
98 GNUNET_break (0); 89 GNUNET_break (0);
99 ret = 1; 90 ret = 1;
100 GNUNET_SCHEDULER_add_now (&do_stop, 91 GNUNET_SCHEDULER_add_now (&do_stop, NULL);
101 NULL); 92 return;
102 return; 93 }
103 }
104 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 94 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
105 "Publishing %llu bytes\n", 95 "Publishing %llu bytes\n", (unsigned long long) FILESIZE);
106 (unsigned long long) FILESIZE);
107 GNUNET_FS_TEST_publish (daemons[0], 96 GNUNET_FS_TEST_publish (daemons[0],
108 TIMEOUT, 97 TIMEOUT,
109 1, GNUNET_NO, FILESIZE, SEED, 98 1, GNUNET_NO, FILESIZE, SEED,
110 VERBOSE, 99 VERBOSE, &do_download, NULL);
111 &do_download, NULL);
112} 100}
113 101
114 102
115static void 103static void
116do_connect (void *cls, 104do_connect (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
117 const struct GNUNET_SCHEDULER_TaskContext *tc)
118{ 105{
119 if (0 == (tc->reason & GNUNET_SCHEDULER_REASON_PREREQ_DONE)) 106 if (0 == (tc->reason & GNUNET_SCHEDULER_REASON_PREREQ_DONE))
120 { 107 {
121 GNUNET_break (0); 108 GNUNET_break (0);
122 ret = 1; 109 ret = 1;
123 GNUNET_SCHEDULER_add_now (&do_stop, 110 GNUNET_SCHEDULER_add_now (&do_stop, NULL);
124 NULL); 111 return;
125 return; 112 }
126 }
127 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 113 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
128 "Daemons started, will now try to connect them\n"); 114 "Daemons started, will now try to connect them\n");
129 GNUNET_FS_TEST_daemons_connect (daemons[0], 115 GNUNET_FS_TEST_daemons_connect (daemons[0],
130 daemons[1], 116 daemons[1], TIMEOUT, &do_publish, NULL);
131 TIMEOUT,
132 &do_publish,
133 NULL);
134} 117}
135 118
136 119
137static void 120static void
138run (void *cls, 121run (void *cls,
139 char *const *args, 122 char *const *args,
140 const char *cfgfile, 123 const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg)
141 const struct GNUNET_CONFIGURATION_Handle *cfg)
142{ 124{
143 GNUNET_FS_TEST_daemons_start ("fs_test_lib_data.conf", 125 GNUNET_FS_TEST_daemons_start ("fs_test_lib_data.conf",
144 TIMEOUT, 126 TIMEOUT,
145 NUM_DAEMONS, 127 NUM_DAEMONS, daemons, &do_connect, NULL);
146 daemons,
147 &do_connect,
148 NULL);
149} 128}
150 129
151 130
152int 131int
153main (int argc, char *argv[]) 132main (int argc, char *argv[])
154{ 133{
155 char *const argvx[] = { 134 char *const argvx[] = {
156 "test-fs-test-lib", 135 "test-fs-test-lib",
157 "-c", 136 "-c",
158 "fs_test_lib_data.conf", 137 "fs_test_lib_data.conf",
@@ -166,16 +145,15 @@ main (int argc, char *argv[])
166 }; 145 };
167 146
168 GNUNET_DISK_directory_remove ("/tmp/gnunet-test-fs-lib/"); 147 GNUNET_DISK_directory_remove ("/tmp/gnunet-test-fs-lib/");
169 GNUNET_log_setup ("test_fs_test_lib", 148 GNUNET_log_setup ("test_fs_test_lib",
170#if VERBOSE 149#if VERBOSE
171 "DEBUG", 150 "DEBUG",
172#else 151#else
173 "WARNING", 152 "WARNING",
174#endif 153#endif
175 NULL); 154 NULL);
176 GNUNET_PROGRAM_run ((sizeof (argvx) / sizeof (char *)) - 1, 155 GNUNET_PROGRAM_run ((sizeof (argvx) / sizeof (char *)) - 1,
177 argvx, "test-fs-test-lib", 156 argvx, "test-fs-test-lib", "nohelp", options, &run, NULL);
178 "nohelp", options, &run, NULL);
179 GNUNET_DISK_directory_remove ("/tmp/gnunet-test-fs-lib/"); 157 GNUNET_DISK_directory_remove ("/tmp/gnunet-test-fs-lib/");
180 return ret; 158 return ret;
181} 159}