aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2012-05-31 18:51:04 +0000
committerChristian Grothoff <christian@grothoff.org>2012-05-31 18:51:04 +0000
commitcc983a47bc9a0d6a32f37b494b65bbb79c16c0c6 (patch)
treee50e41f3d2fc33e9ecfbaa639fd7ec98491d8949 /src
parent7de9f07b0fc3729679ad2678ce1a04aed88e0f7f (diff)
downloadgnunet-cc983a47bc9a0d6a32f37b494b65bbb79c16c0c6.tar.gz
gnunet-cc983a47bc9a0d6a32f37b494b65bbb79c16c0c6.zip
-fixing speedup test
Diffstat (limited to 'src')
-rw-r--r--src/util/speedup.c28
-rw-r--r--src/util/test_speedup.c92
2 files changed, 66 insertions, 54 deletions
diff --git a/src/util/speedup.c b/src/util/speedup.c
index 6a17f3132..0a005c035 100644
--- a/src/util/speedup.c
+++ b/src/util/speedup.c
@@ -29,25 +29,26 @@
29 29
30#define LOG(kind,...) GNUNET_log_from (kind, "util", __VA_ARGS__) 30#define LOG(kind,...) GNUNET_log_from (kind, "util", __VA_ARGS__)
31 31
32static long long current_offset; 32
33static struct GNUNET_TIME_Relative interval; 33static struct GNUNET_TIME_Relative interval;
34
34static struct GNUNET_TIME_Relative delta; 35static struct GNUNET_TIME_Relative delta;
35 36
36static GNUNET_SCHEDULER_TaskIdentifier speedup_task; 37static GNUNET_SCHEDULER_TaskIdentifier speedup_task;
37 38
39
38static void 40static void
39do_speedup (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) 41do_speedup (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
40{ 42{
43 static long long current_offset;
44
41 speedup_task = GNUNET_SCHEDULER_NO_TASK; 45 speedup_task = GNUNET_SCHEDULER_NO_TASK;
42
43 if (0 != (GNUNET_SCHEDULER_REASON_SHUTDOWN & tc->reason)) 46 if (0 != (GNUNET_SCHEDULER_REASON_SHUTDOWN & tc->reason))
44 return; 47 return;
45
46 current_offset += delta.rel_value; 48 current_offset += delta.rel_value;
47 GNUNET_TIME_set_offset (current_offset); 49 GNUNET_TIME_set_offset (current_offset);
48 50 LOG (GNUNET_ERROR_TYPE_DEBUG,
49 LOG (GNUNET_ERROR_TYPE_DEBUG, "Speed up execution time by %llu ms\n", delta.rel_value); 51 "Speeding up execution time by %llu ms\n", delta.rel_value);
50
51 speedup_task = GNUNET_SCHEDULER_add_delayed (interval, &do_speedup, NULL); 52 speedup_task = GNUNET_SCHEDULER_add_delayed (interval, &do_speedup, NULL);
52} 53}
53 54
@@ -60,21 +61,20 @@ GNUNET_SPEEDUP_start_ (const struct GNUNET_CONFIGURATION_Handle *cfg)
60 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_time (cfg, "testing", "SPEEDUP_DELTA", &delta)) 61 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_time (cfg, "testing", "SPEEDUP_DELTA", &delta))
61 return GNUNET_SYSERR; 62 return GNUNET_SYSERR;
62 63
63 if ((interval.rel_value == 0) || (delta.rel_value == 0)) 64 if ((0 == interval.rel_value) || (0 == delta.rel_value))
64 { 65 {
65 LOG (GNUNET_ERROR_TYPE_DEBUG, 66 LOG (GNUNET_ERROR_TYPE_DEBUG,
66 "Speed up disabled\n"); 67 "Speed up disabled\n");
67 return GNUNET_OK; 68 return GNUNET_OK;
68 } 69 }
69
70 LOG (GNUNET_ERROR_TYPE_DEBUG, 70 LOG (GNUNET_ERROR_TYPE_DEBUG,
71 "Speed up execution time %llu ms every %llu ms\n", 71 "Speed up execution time %llu ms every %llu ms\n",
72 delta.rel_value, interval.rel_value); 72 delta.rel_value, interval.rel_value);
73
74 speedup_task = GNUNET_SCHEDULER_add_now_with_lifeness (GNUNET_NO, &do_speedup, NULL); 73 speedup_task = GNUNET_SCHEDULER_add_now_with_lifeness (GNUNET_NO, &do_speedup, NULL);
75 return GNUNET_OK; 74 return GNUNET_OK;
76} 75}
77 76
77
78void 78void
79GNUNET_SPEEDUP_stop_ ( ) 79GNUNET_SPEEDUP_stop_ ( )
80{ 80{
@@ -82,11 +82,9 @@ GNUNET_SPEEDUP_stop_ ( )
82 { 82 {
83 GNUNET_SCHEDULER_cancel (speedup_task); 83 GNUNET_SCHEDULER_cancel (speedup_task);
84 speedup_task = GNUNET_SCHEDULER_NO_TASK; 84 speedup_task = GNUNET_SCHEDULER_NO_TASK;
85
86 } 85 }
87
88 LOG (GNUNET_ERROR_TYPE_DEBUG, 86 LOG (GNUNET_ERROR_TYPE_DEBUG,
89 "Stopped execution speed up\n"); 87 "Stopped execution speed up\n");
90} 88}
91 89
92 90
diff --git a/src/util/test_speedup.c b/src/util/test_speedup.c
index 47603d35c..03cffbd54 100644
--- a/src/util/test_speedup.c
+++ b/src/util/test_speedup.c
@@ -27,36 +27,54 @@
27#include "gnunet_time_lib.h" 27#include "gnunet_time_lib.h"
28#include "gnunet_strings_lib.h" 28#include "gnunet_strings_lib.h"
29 29
30 30/**
31#define VERBOSE GNUNET_NO 31 * Start time of the testcase
32 32 */
33static struct GNUNET_TIME_Absolute start; 33static struct GNUNET_TIME_Absolute start;
34
35/**
36 * End-time of the testcase (affected by speed-up)
37 */
34static struct GNUNET_TIME_Absolute end; 38static struct GNUNET_TIME_Absolute end;
35static int cycles;
36 39
40/**
41 * Number of cycles we have spent in 'run'.
42 */
43static unsigned int cycles;
44
45
46/**
47 * Main task that is scheduled with the speed-up.
48 *
49 * @param cls NULL
50 * @param tc scheduler context, unused
51 */
37static void 52static void
38run (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) 53run (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
39{ 54{
40 55 cycles++;
41 cycles ++; 56 fprintf (stderr, "..%u", cycles);
42 printf ("..%u", cycles);
43 fflush(stdout);
44 if (cycles <= 5) 57 if (cycles <= 5)
45 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, &run, NULL);
46 else
47 { 58 {
48 end = GNUNET_TIME_absolute_get(); 59 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, &run, NULL);
49 printf ("\n"); 60 return;
50 fflush(stdout);
51 } 61 }
62 end = GNUNET_TIME_absolute_get();
63 fprintf (stderr, "\n");
64 fflush(stdout);
52} 65}
53 66
54void check (void *cls, char *const *args, 67
55 const char *cfgfile, 68/**
56 const struct GNUNET_CONFIGURATION_Handle * 69 *
57 cfg) 70 */
71static void
72check (void *cls, char *const *args,
73 const char *cfgfile,
74 const struct GNUNET_CONFIGURATION_Handle *
75 cfg)
58{ 76{
59 printf ("0"); 77 fprintf (stderr, "0");
60 fflush(stdout); 78 fflush(stdout);
61 GNUNET_SCHEDULER_add_now(&run, NULL); 79 GNUNET_SCHEDULER_add_now(&run, NULL);
62} 80}
@@ -65,42 +83,38 @@ void check (void *cls, char *const *args,
65int 83int
66main (int argc, char *argv[]) 84main (int argc, char *argv[])
67{ 85{
68 time_t start_real;
69 time_t end_real;
70 struct GNUNET_TIME_Relative delta;
71
72 static char *const argvn[] = { "test-speedup", 86 static char *const argvn[] = { "test-speedup",
73 "-c", 87 "-c", "test_speedup_data.conf",
74 "test_speedup_data.conf",
75#if VERBOSE
76 "-L", "DEBUG",
77#endif
78 NULL 88 NULL
79 }; 89 };
80 start_real = time (NULL);
81 start = GNUNET_TIME_absolute_get();
82 static struct GNUNET_GETOPT_CommandLineOption options[] = { 90 static struct GNUNET_GETOPT_CommandLineOption options[] = {
83 GNUNET_GETOPT_OPTION_END 91 GNUNET_GETOPT_OPTION_END
84 }; 92 };
85 93 time_t start_real;
94 time_t end_real;
95 struct GNUNET_TIME_Relative delta;
96
97 start_real = time (NULL);
98 start = GNUNET_TIME_absolute_get();
86 GNUNET_PROGRAM_run ((sizeof (argvn) / sizeof (char *)) - 1, argvn, "test-speedup", 99 GNUNET_PROGRAM_run ((sizeof (argvn) / sizeof (char *)) - 1, argvn, "test-speedup",
87 "nohelp", options, &check, NULL); 100 "nohelp", options, &check, NULL);
88 101
89 end_real = time (NULL); 102 end_real = time (NULL);
90 delta = GNUNET_TIME_absolute_get_difference(start, end); 103 delta = GNUNET_TIME_absolute_get_difference(start, end);
91 104
92 if (delta.rel_value > ((end_real - start_real) * 1500)) 105 if (delta.rel_value > ((end_real - start_real) * 1500LL))
93 { 106 {
94 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Execution time in GNUnet time: %llu ms\n", delta.rel_value); 107 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Execution time in GNUnet time: %llu ms\n",
95 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Execution time in system time: %llu ms\n", (end_real - start_real) * 1000); 108 (unsigned long long) delta.rel_value);
109 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Execution time in system time: %llu ms\n",
110 (unsigned long long) ((end_real - start_real) * 1000LL));
96 return 0; 111 return 0;
97 } 112 }
98 else 113 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Execution time in GNUnet time: %llu ms\n",
99 { 114 (unsigned long long) delta.rel_value);
100 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Execution time in GNUnet time: %llu ms\n", delta.rel_value); 115 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Execution time in system time: %llu ms\n",
101 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Execution time in system time: %llu ms\n", (end_real - start_real) * 1000); 116 (unsigned long long) ((end_real - start_real) * 1000LL));
102 return 1; 117 return 1;
103 }
104} 118}
105 119
106/* end of test_speedup.c */ 120/* end of test_speedup.c */