diff options
Diffstat (limited to 'src/datacache/test_datacache_quota.c')
-rw-r--r-- | src/datacache/test_datacache_quota.c | 84 |
1 files changed, 35 insertions, 49 deletions
diff --git a/src/datacache/test_datacache_quota.c b/src/datacache/test_datacache_quota.c index d956ac36f..f943844a4 100644 --- a/src/datacache/test_datacache_quota.c +++ b/src/datacache/test_datacache_quota.c | |||
@@ -46,8 +46,7 @@ static const char *plugin_name; | |||
46 | static void | 46 | static void |
47 | run (void *cls, | 47 | run (void *cls, |
48 | char *const *args, | 48 | char *const *args, |
49 | const char *cfgfile, | 49 | const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg) |
50 | const struct GNUNET_CONFIGURATION_Handle *cfg) | ||
51 | { | 50 | { |
52 | struct GNUNET_DATACACHE_Handle *h; | 51 | struct GNUNET_DATACACHE_Handle *h; |
53 | GNUNET_HashCode k; | 52 | GNUNET_HashCode k; |
@@ -58,56 +57,43 @@ run (void *cls, | |||
58 | struct GNUNET_TIME_Absolute exp; | 57 | struct GNUNET_TIME_Absolute exp; |
59 | 58 | ||
60 | ok = 0; | 59 | ok = 0; |
61 | h = GNUNET_DATACACHE_create (cfg, | 60 | h = GNUNET_DATACACHE_create (cfg, "testcache"); |
62 | "testcache"); | ||
63 | 61 | ||
64 | if (h == NULL) | 62 | if (h == NULL) |
65 | { | 63 | { |
66 | fprintf (stderr, | 64 | fprintf (stderr, |
67 | "Failed to initialize datacache. Database likely not setup, skipping test.\n"); | 65 | "Failed to initialize datacache. Database likely not setup, skipping test.\n"); |
68 | return; | 66 | return; |
69 | } | 67 | } |
70 | exp = GNUNET_TIME_absolute_get (); | 68 | exp = GNUNET_TIME_absolute_get (); |
71 | exp.abs_value += 20 * 60 * 1000; | 69 | exp.abs_value += 20 * 60 * 1000; |
72 | memset (buf, 1, sizeof (buf)); | 70 | memset (buf, 1, sizeof (buf)); |
73 | memset (&k, 0, sizeof (GNUNET_HashCode)); | 71 | memset (&k, 0, sizeof (GNUNET_HashCode)); |
74 | for (i = 0; i < 10; i++) | 72 | for (i = 0; i < 10; i++) |
73 | { | ||
74 | fprintf (stderr, "."); | ||
75 | GNUNET_CRYPTO_hash (&k, sizeof (GNUNET_HashCode), &n); | ||
76 | for (j = i; j < sizeof (buf); j += 10) | ||
75 | { | 77 | { |
76 | fprintf (stderr, "."); | 78 | exp.abs_value++; |
77 | GNUNET_CRYPTO_hash (&k, sizeof (GNUNET_HashCode), &n); | 79 | buf[j] = i; |
78 | for (j = i; j < sizeof (buf); j += 10) | 80 | ASSERT (GNUNET_OK == GNUNET_DATACACHE_put (h, &k, j, buf, 1 + i, exp)); |
79 | { | 81 | ASSERT (0 < GNUNET_DATACACHE_get (h, &k, 1 + i, NULL, NULL)); |
80 | exp.abs_value++; | ||
81 | buf[j] = i; | ||
82 | ASSERT (GNUNET_OK == | ||
83 | GNUNET_DATACACHE_put (h, | ||
84 | &k, | ||
85 | j, | ||
86 | buf, | ||
87 | 1+i, | ||
88 | exp)); | ||
89 | ASSERT (0 < GNUNET_DATACACHE_get (h, | ||
90 | &k, 1+i, | ||
91 | NULL, NULL)); | ||
92 | } | ||
93 | k = n; | ||
94 | } | 82 | } |
83 | k = n; | ||
84 | } | ||
95 | fprintf (stderr, "\n"); | 85 | fprintf (stderr, "\n"); |
96 | memset (&k, 0, sizeof (GNUNET_HashCode)); | 86 | memset (&k, 0, sizeof (GNUNET_HashCode)); |
97 | for (i = 0; i < 10; i++) | 87 | for (i = 0; i < 10; i++) |
98 | { | 88 | { |
99 | fprintf (stderr, "."); | 89 | fprintf (stderr, "."); |
100 | GNUNET_CRYPTO_hash (&k, sizeof (GNUNET_HashCode), &n); | 90 | GNUNET_CRYPTO_hash (&k, sizeof (GNUNET_HashCode), &n); |
101 | if (i < 2) | 91 | if (i < 2) |
102 | ASSERT (0 == GNUNET_DATACACHE_get (h, | 92 | ASSERT (0 == GNUNET_DATACACHE_get (h, &k, 1 + i, NULL, NULL)); |
103 | &k, 1+i, | 93 | if (i == 9) |
104 | NULL, NULL)); | 94 | ASSERT (0 < GNUNET_DATACACHE_get (h, &k, 1 + i, NULL, NULL)); |
105 | if (i == 9) | 95 | k = n; |
106 | ASSERT (0 < GNUNET_DATACACHE_get (h, | 96 | } |
107 | &k, 1+i, | ||
108 | NULL, NULL)); | ||
109 | k = n; | ||
110 | } | ||
111 | fprintf (stderr, "\n"); | 97 | fprintf (stderr, "\n"); |
112 | GNUNET_DATACACHE_destroy (h); | 98 | GNUNET_DATACACHE_destroy (h); |
113 | return; | 99 | return; |
@@ -123,7 +109,8 @@ main (int argc, char *argv[]) | |||
123 | { | 109 | { |
124 | char *pos; | 110 | char *pos; |
125 | char cfg_name[128]; | 111 | char cfg_name[128]; |
126 | char *const xargv[] = { | 112 | |
113 | char *const xargv[] = { | ||
127 | "test-datacache-quota", | 114 | "test-datacache-quota", |
128 | "-c", | 115 | "-c", |
129 | cfg_name, | 116 | cfg_name, |
@@ -135,7 +122,7 @@ main (int argc, char *argv[]) | |||
135 | struct GNUNET_GETOPT_CommandLineOption options[] = { | 122 | struct GNUNET_GETOPT_CommandLineOption options[] = { |
136 | GNUNET_GETOPT_OPTION_END | 123 | GNUNET_GETOPT_OPTION_END |
137 | }; | 124 | }; |
138 | 125 | ||
139 | GNUNET_log_setup ("test-datacache-quota", | 126 | GNUNET_log_setup ("test-datacache-quota", |
140 | #if VERBOSE | 127 | #if VERBOSE |
141 | "DEBUG", | 128 | "DEBUG", |
@@ -146,17 +133,16 @@ main (int argc, char *argv[]) | |||
146 | 133 | ||
147 | /* determine name of plugin to use */ | 134 | /* determine name of plugin to use */ |
148 | plugin_name = argv[0]; | 135 | plugin_name = argv[0]; |
149 | while (NULL != (pos = strstr(plugin_name, "_"))) | 136 | while (NULL != (pos = strstr (plugin_name, "_"))) |
150 | plugin_name = pos+1; | 137 | plugin_name = pos + 1; |
151 | if (NULL != (pos = strstr(plugin_name, "."))) | 138 | if (NULL != (pos = strstr (plugin_name, "."))) |
152 | pos[0] = 0; | 139 | pos[0] = 0; |
153 | else | 140 | else |
154 | pos = (char *) plugin_name; | 141 | pos = (char *) plugin_name; |
155 | 142 | ||
156 | GNUNET_snprintf (cfg_name, | 143 | GNUNET_snprintf (cfg_name, |
157 | sizeof (cfg_name), | 144 | sizeof (cfg_name), |
158 | "test_datacache_data_%s.conf", | 145 | "test_datacache_data_%s.conf", plugin_name); |
159 | plugin_name); | ||
160 | if (pos != plugin_name) | 146 | if (pos != plugin_name) |
161 | pos[0] = '.'; | 147 | pos[0] = '.'; |
162 | GNUNET_PROGRAM_run ((sizeof (xargv) / sizeof (char *)) - 1, | 148 | GNUNET_PROGRAM_run ((sizeof (xargv) / sizeof (char *)) - 1, |