diff options
Diffstat (limited to 'src/datacache/test_datacache.c')
-rw-r--r-- | src/datacache/test_datacache.c | 206 |
1 files changed, 104 insertions, 102 deletions
diff --git a/src/datacache/test_datacache.c b/src/datacache/test_datacache.c index 30ef81a70..58a03914b 100644 --- a/src/datacache/test_datacache.c +++ b/src/datacache/test_datacache.c | |||
@@ -27,7 +27,9 @@ | |||
27 | #include "gnunet_datacache_lib.h" | 27 | #include "gnunet_datacache_lib.h" |
28 | #include "gnunet_testing_lib.h" | 28 | #include "gnunet_testing_lib.h" |
29 | 29 | ||
30 | #define ASSERT(x) do { if (!(x)) { printf("Error at %s:%d\n", __FILE__, __LINE__); goto FAILURE; } } while (0) | 30 | #define ASSERT(x) do { if (! (x)) { printf ("Error at %s:%d\n", __FILE__, \ |
31 | __LINE__); goto FAILURE; \ | ||
32 | } } while (0) | ||
31 | 33 | ||
32 | static int ok; | 34 | static int ok; |
33 | 35 | ||
@@ -38,122 +40,122 @@ static const char *plugin_name; | |||
38 | 40 | ||
39 | 41 | ||
40 | static int | 42 | static int |
41 | checkIt(void *cls, | 43 | checkIt (void *cls, |
42 | const struct GNUNET_HashCode *key, | 44 | const struct GNUNET_HashCode *key, |
43 | size_t size, const char *data, | 45 | size_t size, const char *data, |
44 | enum GNUNET_BLOCK_Type type, | 46 | enum GNUNET_BLOCK_Type type, |
45 | struct GNUNET_TIME_Absolute exp, | 47 | struct GNUNET_TIME_Absolute exp, |
46 | unsigned int path_len, | 48 | unsigned int path_len, |
47 | const struct GNUNET_PeerIdentity *path) | 49 | const struct GNUNET_PeerIdentity *path) |
48 | { | 50 | { |
49 | (void)key; | 51 | (void) key; |
50 | (void)type; | 52 | (void) type; |
51 | (void)exp; | 53 | (void) exp; |
52 | (void)path_len; | 54 | (void) path_len; |
53 | (void)path; | 55 | (void) path; |
54 | if (size != sizeof(struct GNUNET_HashCode)) | 56 | if (size != sizeof(struct GNUNET_HashCode)) |
55 | { | 57 | { |
56 | GNUNET_break(0); | 58 | GNUNET_break (0); |
57 | ok = 2; | 59 | ok = 2; |
58 | } | 60 | } |
59 | if (0 != memcmp(data, cls, size)) | 61 | if (0 != memcmp (data, cls, size)) |
60 | { | 62 | { |
61 | GNUNET_break(0); | 63 | GNUNET_break (0); |
62 | ok = 3; | 64 | ok = 3; |
63 | } | 65 | } |
64 | return GNUNET_OK; | 66 | return GNUNET_OK; |
65 | } | 67 | } |
66 | 68 | ||
67 | 69 | ||
68 | static void | 70 | static void |
69 | run(void *cls, | 71 | run (void *cls, |
70 | char *const *args, | 72 | char *const *args, |
71 | const char *cfgfile, | 73 | const char *cfgfile, |
72 | const struct GNUNET_CONFIGURATION_Handle *cfg) | 74 | const struct GNUNET_CONFIGURATION_Handle *cfg) |
73 | { | 75 | { |
74 | struct GNUNET_DATACACHE_Handle *h; | 76 | struct GNUNET_DATACACHE_Handle *h; |
75 | struct GNUNET_HashCode k; | 77 | struct GNUNET_HashCode k; |
76 | struct GNUNET_HashCode n; | 78 | struct GNUNET_HashCode n; |
77 | struct GNUNET_TIME_Absolute exp; | 79 | struct GNUNET_TIME_Absolute exp; |
78 | 80 | ||
79 | (void)cls; | 81 | (void) cls; |
80 | (void)args; | 82 | (void) args; |
81 | (void)cfgfile; | 83 | (void) cfgfile; |
82 | ok = 0; | 84 | ok = 0; |
83 | h = GNUNET_DATACACHE_create(cfg, | 85 | h = GNUNET_DATACACHE_create (cfg, |
84 | "testcache"); | 86 | "testcache"); |
85 | if (h == NULL) | 87 | if (h == NULL) |
86 | { | 88 | { |
87 | fprintf(stderr, | 89 | fprintf (stderr, |
88 | "%s", | 90 | "%s", |
89 | "Failed to initialize datacache. Database likely not setup, skipping test.\n"); | 91 | "Failed to initialize datacache. Database likely not setup, skipping test.\n"); |
90 | ok = 77; /* mark test as skipped */ | 92 | ok = 77; /* mark test as skipped */ |
91 | return; | 93 | return; |
92 | } | 94 | } |
93 | exp = GNUNET_TIME_absolute_get(); | 95 | exp = GNUNET_TIME_absolute_get (); |
94 | exp.abs_value_us += 5 * 60 * 1000 * 1000LL; | 96 | exp.abs_value_us += 5 * 60 * 1000 * 1000LL; |
95 | memset(&k, 0, sizeof(struct GNUNET_HashCode)); | 97 | memset (&k, 0, sizeof(struct GNUNET_HashCode)); |
96 | for (unsigned int i = 0; i < 100; i++) | 98 | for (unsigned int i = 0; i < 100; i++) |
97 | { | 99 | { |
98 | GNUNET_CRYPTO_hash(&k, sizeof(struct GNUNET_HashCode), &n); | 100 | GNUNET_CRYPTO_hash (&k, sizeof(struct GNUNET_HashCode), &n); |
99 | ASSERT(GNUNET_OK == | 101 | ASSERT (GNUNET_OK == |
100 | GNUNET_DATACACHE_put(h, | 102 | GNUNET_DATACACHE_put (h, |
101 | &k, | 103 | &k, |
102 | GNUNET_YES, | 104 | GNUNET_YES, |
103 | sizeof(struct GNUNET_HashCode), | 105 | sizeof(struct GNUNET_HashCode), |
104 | (const char *)&n, 1 + i % 16, exp, | 106 | (const char *) &n, 1 + i % 16, exp, |
105 | 0, NULL)); | 107 | 0, NULL)); |
106 | k = n; | 108 | k = n; |
107 | } | 109 | } |
108 | memset(&k, | 110 | memset (&k, |
109 | 0, | 111 | 0, |
110 | sizeof(struct GNUNET_HashCode)); | 112 | sizeof(struct GNUNET_HashCode)); |
111 | for (unsigned int i = 0; i < 100; i++) | 113 | for (unsigned int i = 0; i < 100; i++) |
112 | { | 114 | { |
113 | GNUNET_CRYPTO_hash(&k, | 115 | GNUNET_CRYPTO_hash (&k, |
114 | sizeof(struct GNUNET_HashCode), | 116 | sizeof(struct GNUNET_HashCode), |
115 | &n); | 117 | &n); |
116 | ASSERT(1 == GNUNET_DATACACHE_get(h, | 118 | ASSERT (1 == GNUNET_DATACACHE_get (h, |
117 | &k, | 119 | &k, |
118 | 1 + i % 16, | 120 | 1 + i % 16, |
119 | &checkIt, | 121 | &checkIt, |
120 | &n)); | 122 | &n)); |
121 | k = n; | 123 | k = n; |
122 | } | 124 | } |
123 | 125 | ||
124 | memset(&k, | 126 | memset (&k, |
125 | 42, | 127 | 42, |
126 | sizeof(struct GNUNET_HashCode)); | 128 | sizeof(struct GNUNET_HashCode)); |
127 | GNUNET_CRYPTO_hash(&k, | 129 | GNUNET_CRYPTO_hash (&k, |
128 | sizeof(struct GNUNET_HashCode), | 130 | sizeof(struct GNUNET_HashCode), |
129 | &n); | 131 | &n); |
130 | ASSERT(GNUNET_OK == | 132 | ASSERT (GNUNET_OK == |
131 | GNUNET_DATACACHE_put(h, | 133 | GNUNET_DATACACHE_put (h, |
132 | &k, | 134 | &k, |
133 | GNUNET_YES, | 135 | GNUNET_YES, |
134 | sizeof(struct GNUNET_HashCode), | 136 | sizeof(struct GNUNET_HashCode), |
135 | (const char *)&n, | 137 | (const char *) &n, |
136 | 792, | 138 | 792, |
137 | GNUNET_TIME_UNIT_FOREVER_ABS, | 139 | GNUNET_TIME_UNIT_FOREVER_ABS, |
138 | 0, | 140 | 0, |
139 | NULL)); | 141 | NULL)); |
140 | ASSERT(0 != GNUNET_DATACACHE_get(h, | 142 | ASSERT (0 != GNUNET_DATACACHE_get (h, |
141 | &k, | 143 | &k, |
142 | 792, | 144 | 792, |
143 | &checkIt, | 145 | &checkIt, |
144 | &n)); | 146 | &n)); |
145 | GNUNET_DATACACHE_destroy(h); | 147 | GNUNET_DATACACHE_destroy (h); |
146 | ASSERT(ok == 0); | 148 | ASSERT (ok == 0); |
147 | return; | 149 | return; |
148 | FAILURE: | 150 | FAILURE: |
149 | if (h != NULL) | 151 | if (h != NULL) |
150 | GNUNET_DATACACHE_destroy(h); | 152 | GNUNET_DATACACHE_destroy (h); |
151 | ok = GNUNET_SYSERR; | 153 | ok = GNUNET_SYSERR; |
152 | } | 154 | } |
153 | 155 | ||
154 | 156 | ||
155 | int | 157 | int |
156 | main(int argc, char *argv[]) | 158 | main (int argc, char *argv[]) |
157 | { | 159 | { |
158 | char cfg_name[PATH_MAX]; | 160 | char cfg_name[PATH_MAX]; |
159 | char *const xargv[] = { | 161 | char *const xargv[] = { |
@@ -166,26 +168,26 @@ main(int argc, char *argv[]) | |||
166 | GNUNET_GETOPT_OPTION_END | 168 | GNUNET_GETOPT_OPTION_END |
167 | }; | 169 | }; |
168 | 170 | ||
169 | (void)argc; | 171 | (void) argc; |
170 | GNUNET_log_setup("test-datacache", | 172 | GNUNET_log_setup ("test-datacache", |
171 | "WARNING", | 173 | "WARNING", |
172 | NULL); | 174 | NULL); |
173 | plugin_name = GNUNET_TESTING_get_testname_from_underscore(argv[0]); | 175 | plugin_name = GNUNET_TESTING_get_testname_from_underscore (argv[0]); |
174 | GNUNET_snprintf(cfg_name, | 176 | GNUNET_snprintf (cfg_name, |
175 | sizeof(cfg_name), | 177 | sizeof(cfg_name), |
176 | "test_datacache_data_%s.conf", | 178 | "test_datacache_data_%s.conf", |
177 | plugin_name); | 179 | plugin_name); |
178 | GNUNET_PROGRAM_run((sizeof(xargv) / sizeof(char *)) - 1, | 180 | GNUNET_PROGRAM_run ((sizeof(xargv) / sizeof(char *)) - 1, |
179 | xargv, | 181 | xargv, |
180 | "test-datacache", | 182 | "test-datacache", |
181 | "nohelp", | 183 | "nohelp", |
182 | options, | 184 | options, |
183 | &run, | 185 | &run, |
184 | NULL); | 186 | NULL); |
185 | if ((0 != ok) && (77 != ok)) | 187 | if ((0 != ok) && (77 != ok)) |
186 | fprintf(stderr, | 188 | fprintf (stderr, |
187 | "Missed some testcases: %d\n", | 189 | "Missed some testcases: %d\n", |
188 | ok); | 190 | ok); |
189 | return ok; | 191 | return ok; |
190 | } | 192 | } |
191 | 193 | ||