diff options
author | Julius Bünger <buenger@mytum.de> | 2015-07-23 18:21:49 +0000 |
---|---|---|
committer | Julius Bünger <buenger@mytum.de> | 2015-07-23 18:21:49 +0000 |
commit | ff073fe2f2c6a0fe0532061533c570acfba60e7d (patch) | |
tree | 43bd8220c5414f04ba20ec8362e1cc2cd15057a4 /src/rps/test_rps.c | |
parent | 66fa52570d0d9f29d8b6bf8bd4667c18931b3806 (diff) | |
download | gnunet-ff073fe2f2c6a0fe0532061533c570acfba60e7d.tar.gz gnunet-ff073fe2f2c6a0fe0532061533c570acfba60e7d.zip |
get perfect sample of each sampler element
Diffstat (limited to 'src/rps/test_rps.c')
-rw-r--r-- | src/rps/test_rps.c | 68 |
1 files changed, 61 insertions, 7 deletions
diff --git a/src/rps/test_rps.c b/src/rps/test_rps.c index f6db147f9..47abe668a 100644 --- a/src/rps/test_rps.c +++ b/src/rps/test_rps.c | |||
@@ -27,7 +27,10 @@ | |||
27 | #include "platform.h" | 27 | #include "platform.h" |
28 | #include "gnunet_util_lib.h" | 28 | #include "gnunet_util_lib.h" |
29 | #include "gnunet_testbed_service.h" | 29 | #include "gnunet_testbed_service.h" |
30 | |||
30 | #include "gnunet_rps_service.h" | 31 | #include "gnunet_rps_service.h" |
32 | #include "rps-test_util.h" | ||
33 | #include "gnunet-service-rps_sampler_elem.h" | ||
31 | 34 | ||
32 | #include <inttypes.h> | 35 | #include <inttypes.h> |
33 | 36 | ||
@@ -257,7 +260,7 @@ struct SingleTestRun | |||
257 | * Append arguments to file | 260 | * Append arguments to file |
258 | */ | 261 | */ |
259 | static void | 262 | static void |
260 | to_file_ (char *file_name, char *line) | 263 | tofile_ (const char *file_name, char *line) |
261 | { | 264 | { |
262 | struct GNUNET_DISK_FileHandle *f; | 265 | struct GNUNET_DISK_FileHandle *f; |
263 | /* char output_buffer[512]; */ | 266 | /* char output_buffer[512]; */ |
@@ -312,7 +315,7 @@ to_file_ (char *file_name, char *line) | |||
312 | /** | 315 | /** |
313 | * This function is used to facilitate writing important information to disk | 316 | * This function is used to facilitate writing important information to disk |
314 | */ | 317 | */ |
315 | #define to_file(file_name, ...) do {\ | 318 | #define tofile(file_name, ...) do {\ |
316 | char tmp_buf[512];\ | 319 | char tmp_buf[512];\ |
317 | int size;\ | 320 | int size;\ |
318 | size = GNUNET_snprintf(tmp_buf,sizeof(tmp_buf),__VA_ARGS__);\ | 321 | size = GNUNET_snprintf(tmp_buf,sizeof(tmp_buf),__VA_ARGS__);\ |
@@ -320,7 +323,7 @@ to_file_ (char *file_name, char *line) | |||
320 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING,\ | 323 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING,\ |
321 | "Failed to create tmp_buf\n");\ | 324 | "Failed to create tmp_buf\n");\ |
322 | else\ | 325 | else\ |
323 | to_file_(file_name,tmp_buf);\ | 326 | tofile_(file_name,tmp_buf);\ |
324 | } while (0); | 327 | } while (0); |
325 | 328 | ||
326 | /** | 329 | /** |
@@ -386,7 +389,7 @@ make_oplist_entry () | |||
386 | 389 | ||
387 | 390 | ||
388 | /** | 391 | /** |
389 | * Callback to be called when NSE service is started or stopped at peers | 392 | * Callback to be called when RPS service is started or stopped at peers |
390 | * | 393 | * |
391 | * @param cls NULL | 394 | * @param cls NULL |
392 | * @param op the operation handle | 395 | * @param op the operation handle |
@@ -521,7 +524,7 @@ info_cb (void *cb_cls, | |||
521 | rps_peers[entry->index].rec_ids = NULL; | 524 | rps_peers[entry->index].rec_ids = NULL; |
522 | rps_peers[entry->index].num_rec_ids = 0; | 525 | rps_peers[entry->index].num_rec_ids = 0; |
523 | 526 | ||
524 | to_file ("/tmp/rps/peer_ids", | 527 | tofile ("/tmp/rps/peer_ids", |
525 | "%u\t%s\n", | 528 | "%u\t%s\n", |
526 | entry->index, | 529 | entry->index, |
527 | GNUNET_i2s_full (&rps_peer_ids[entry->index])); | 530 | GNUNET_i2s_full (&rps_peer_ids[entry->index])); |
@@ -972,7 +975,7 @@ profiler_reply_handle (void *cls, | |||
972 | GNUNET_i2s (&recv_peers[i])); | 975 | GNUNET_i2s (&recv_peers[i])); |
973 | 976 | ||
974 | /* GNUNET_array_append (rps_peer->rec_ids, rps_peer->num_rec_ids, recv_peers[i]); */ | 977 | /* GNUNET_array_append (rps_peer->rec_ids, rps_peer->num_rec_ids, recv_peers[i]); */ |
975 | to_file (file_name, | 978 | tofile (file_name, |
976 | "%s\n", | 979 | "%s\n", |
977 | GNUNET_i2s_full (&recv_peers[i])); | 980 | GNUNET_i2s_full (&recv_peers[i])); |
978 | } | 981 | } |
@@ -1010,6 +1013,57 @@ profiler_cb (struct RPSPeer *rps_peer) | |||
1010 | } | 1013 | } |
1011 | } | 1014 | } |
1012 | 1015 | ||
1016 | /** | ||
1017 | * Function called from #profiler_eval with a filename. | ||
1018 | * | ||
1019 | * @param cls closure | ||
1020 | * @param filename complete filename (absolute path) | ||
1021 | * @return #GNUNET_OK to continue to iterate, | ||
1022 | * #GNUNET_NO to stop iteration with no error, | ||
1023 | * #GNUNET_SYSERR to abort iteration with error! | ||
1024 | */ | ||
1025 | int | ||
1026 | file_name_cb (void *cls, const char *filename) | ||
1027 | { | ||
1028 | if (NULL != strstr (filename, "sampler_el")) | ||
1029 | { | ||
1030 | struct RPS_SamplerElement *s_elem; | ||
1031 | struct GNUNET_CRYPTO_AuthKey auth_key; | ||
1032 | const char *key_char; | ||
1033 | uint32_t i; | ||
1034 | |||
1035 | key_char = filename + 20; /* Length of "/tmp/rps/sampler_el-" */ | ||
1036 | tofile (filename, "--------------------------\n"); | ||
1037 | |||
1038 | auth_key = string_to_auth_key (key_char); | ||
1039 | s_elem = RPS_sampler_elem_create (); | ||
1040 | RPS_sampler_elem_set (s_elem, auth_key); | ||
1041 | |||
1042 | for (i = 0; i < num_peers; i++) | ||
1043 | { | ||
1044 | RPS_sampler_elem_next (s_elem, &rps_peer_ids[i]); | ||
1045 | } | ||
1046 | } | ||
1047 | return GNUNET_OK; | ||
1048 | } | ||
1049 | |||
1050 | /** | ||
1051 | * This is run after the test finished. | ||
1052 | * | ||
1053 | * Compute all perfect samples. | ||
1054 | */ | ||
1055 | int | ||
1056 | profiler_eval (void) | ||
1057 | { | ||
1058 | /* Compute perfect sample for each sampler element */ | ||
1059 | if (-1 == GNUNET_DISK_directory_scan ("/tmp/rps/", file_name_cb, NULL)) | ||
1060 | { | ||
1061 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Scan of directory failed\n"); | ||
1062 | } | ||
1063 | |||
1064 | return 0; | ||
1065 | } | ||
1066 | |||
1013 | 1067 | ||
1014 | /*********************************************************************** | 1068 | /*********************************************************************** |
1015 | * /Definition of tests | 1069 | * /Definition of tests |
@@ -1187,7 +1241,7 @@ main (int argc, char *argv[]) | |||
1187 | cur_test_run.pre_test = profiler_pre; | 1241 | cur_test_run.pre_test = profiler_pre; |
1188 | cur_test_run.main_test = profiler_cb; | 1242 | cur_test_run.main_test = profiler_cb; |
1189 | cur_test_run.reply_handle = profiler_reply_handle; | 1243 | cur_test_run.reply_handle = profiler_reply_handle; |
1190 | cur_test_run.eval_cb = no_eval; | 1244 | cur_test_run.eval_cb = profiler_eval; |
1191 | cur_test_run.request_interval = 2; | 1245 | cur_test_run.request_interval = 2; |
1192 | cur_test_run.num_requests = 50; | 1246 | cur_test_run.num_requests = 50; |
1193 | 1247 | ||