diff options
Diffstat (limited to 'src/datacache/test_datacache_quota.c')
-rw-r--r-- | src/datacache/test_datacache_quota.c | 156 |
1 files changed, 78 insertions, 78 deletions
diff --git a/src/datacache/test_datacache_quota.c b/src/datacache/test_datacache_quota.c index 0201df3b3..36e369abb 100644 --- a/src/datacache/test_datacache_quota.c +++ b/src/datacache/test_datacache_quota.c | |||
@@ -16,7 +16,7 @@ | |||
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
18 | SPDX-License-Identifier: AGPL3.0-or-later | 18 | SPDX-License-Identifier: AGPL3.0-or-later |
19 | */ | 19 | */ |
20 | /* | 20 | /* |
21 | * @file datacache/test_datacache_quota.c | 21 | * @file datacache/test_datacache_quota.c |
22 | * @brief Test for the quota code of the datacache implementations. | 22 | * @brief Test for the quota code of the datacache implementations. |
@@ -27,7 +27,7 @@ | |||
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__, __LINE__); goto FAILURE; } } while (0) |
31 | 31 | ||
32 | static int ok; | 32 | static int ok; |
33 | 33 | ||
@@ -43,10 +43,10 @@ static const char *plugin_name; | |||
43 | * some of the data from the last iteration is still there. | 43 | * some of the data from the last iteration is still there. |
44 | */ | 44 | */ |
45 | static void | 45 | static void |
46 | run (void *cls, | 46 | run(void *cls, |
47 | char *const *args, | 47 | char *const *args, |
48 | const char *cfgfile, | 48 | const char *cfgfile, |
49 | const struct GNUNET_CONFIGURATION_Handle *cfg) | 49 | const struct GNUNET_CONFIGURATION_Handle *cfg) |
50 | { | 50 | { |
51 | struct GNUNET_DATACACHE_Handle *h; | 51 | struct GNUNET_DATACACHE_Handle *h; |
52 | struct GNUNET_HashCode k; | 52 | struct GNUNET_HashCode k; |
@@ -54,74 +54,74 @@ run (void *cls, | |||
54 | char buf[3200]; | 54 | char buf[3200]; |
55 | struct GNUNET_TIME_Absolute exp; | 55 | struct GNUNET_TIME_Absolute exp; |
56 | 56 | ||
57 | (void) cls; | 57 | (void)cls; |
58 | (void) args; | 58 | (void)args; |
59 | (void) cfgfile; | 59 | (void)cfgfile; |
60 | ok = 0; | 60 | ok = 0; |
61 | h = GNUNET_DATACACHE_create (cfg, | 61 | h = GNUNET_DATACACHE_create(cfg, |
62 | "testcache"); | 62 | "testcache"); |
63 | 63 | ||
64 | if (h == NULL) | 64 | if (h == NULL) |
65 | { | 65 | { |
66 | fprintf (stderr, | 66 | fprintf(stderr, |
67 | "%s", | 67 | "%s", |
68 | "Failed to initialize datacache. Database likely not setup, skipping test.\n"); | 68 | "Failed to initialize datacache. Database likely not setup, skipping test.\n"); |
69 | return; | 69 | return; |
70 | } | 70 | } |
71 | exp = GNUNET_TIME_relative_to_absolute (GNUNET_TIME_UNIT_HOURS); | 71 | exp = GNUNET_TIME_relative_to_absolute(GNUNET_TIME_UNIT_HOURS); |
72 | memset (buf, 1, sizeof (buf)); | 72 | memset(buf, 1, sizeof(buf)); |
73 | memset (&k, 0, sizeof (struct GNUNET_HashCode)); | 73 | memset(&k, 0, sizeof(struct GNUNET_HashCode)); |
74 | for (unsigned int i = 0; i < 10; i++) | 74 | for (unsigned int i = 0; i < 10; i++) |
75 | { | ||
76 | fprintf (stderr, | ||
77 | "%s", | ||
78 | "."); | ||
79 | GNUNET_CRYPTO_hash (&k, | ||
80 | sizeof (struct GNUNET_HashCode), | ||
81 | &n); | ||
82 | for (unsigned int j = i; j < sizeof (buf); j += 10) | ||
83 | { | 75 | { |
84 | exp.abs_value_us++; | 76 | fprintf(stderr, |
85 | buf[j] = i; | 77 | "%s", |
86 | ASSERT (GNUNET_OK == | 78 | "."); |
87 | GNUNET_DATACACHE_put (h, | 79 | GNUNET_CRYPTO_hash(&k, |
88 | &k, | 80 | sizeof(struct GNUNET_HashCode), |
89 | GNUNET_YES, | 81 | &n); |
90 | j, | 82 | for (unsigned int j = i; j < sizeof(buf); j += 10) |
91 | buf, | 83 | { |
92 | 1 + i, | 84 | exp.abs_value_us++; |
93 | exp, | 85 | buf[j] = i; |
94 | 0, | 86 | ASSERT(GNUNET_OK == |
95 | NULL)); | 87 | GNUNET_DATACACHE_put(h, |
96 | ASSERT (0 < GNUNET_DATACACHE_get (h, &k, 1 + i, NULL, NULL)); | 88 | &k, |
89 | GNUNET_YES, | ||
90 | j, | ||
91 | buf, | ||
92 | 1 + i, | ||
93 | exp, | ||
94 | 0, | ||
95 | NULL)); | ||
96 | ASSERT(0 < GNUNET_DATACACHE_get(h, &k, 1 + i, NULL, NULL)); | ||
97 | } | ||
98 | k = n; | ||
97 | } | 99 | } |
98 | k = n; | 100 | fprintf(stderr, "%s", "\n"); |
99 | } | 101 | memset(&k, 0, sizeof(struct GNUNET_HashCode)); |
100 | fprintf (stderr, "%s", "\n"); | ||
101 | memset (&k, 0, sizeof (struct GNUNET_HashCode)); | ||
102 | for (unsigned int i = 0; i < 10; i++) | 102 | for (unsigned int i = 0; i < 10; i++) |
103 | { | 103 | { |
104 | fprintf (stderr, "%s", "."); | 104 | fprintf(stderr, "%s", "."); |
105 | GNUNET_CRYPTO_hash (&k, sizeof (struct GNUNET_HashCode), &n); | 105 | GNUNET_CRYPTO_hash(&k, sizeof(struct GNUNET_HashCode), &n); |
106 | if (i < 2) | 106 | if (i < 2) |
107 | ASSERT (0 == GNUNET_DATACACHE_get (h, &k, 1 + i, NULL, NULL)); | 107 | ASSERT(0 == GNUNET_DATACACHE_get(h, &k, 1 + i, NULL, NULL)); |
108 | if (i == 9) | 108 | if (i == 9) |
109 | ASSERT (0 < GNUNET_DATACACHE_get (h, &k, 1 + i, NULL, NULL)); | 109 | ASSERT(0 < GNUNET_DATACACHE_get(h, &k, 1 + i, NULL, NULL)); |
110 | k = n; | 110 | k = n; |
111 | } | 111 | } |
112 | fprintf (stderr, "%s", "\n"); | 112 | fprintf(stderr, "%s", "\n"); |
113 | GNUNET_DATACACHE_destroy (h); | 113 | GNUNET_DATACACHE_destroy(h); |
114 | return; | 114 | return; |
115 | FAILURE: | 115 | FAILURE: |
116 | if (h != NULL) | 116 | if (h != NULL) |
117 | GNUNET_DATACACHE_destroy (h); | 117 | GNUNET_DATACACHE_destroy(h); |
118 | ok = GNUNET_SYSERR; | 118 | ok = GNUNET_SYSERR; |
119 | } | 119 | } |
120 | 120 | ||
121 | 121 | ||
122 | int | 122 | int |
123 | main (int argc, | 123 | main(int argc, |
124 | char *argv[]) | 124 | char *argv[]) |
125 | { | 125 | { |
126 | char cfg_name[PATH_MAX]; | 126 | char cfg_name[PATH_MAX]; |
127 | char *const xargv[] = { | 127 | char *const xargv[] = { |
@@ -134,27 +134,27 @@ main (int argc, | |||
134 | GNUNET_GETOPT_OPTION_END | 134 | GNUNET_GETOPT_OPTION_END |
135 | }; | 135 | }; |
136 | 136 | ||
137 | (void) argc; | 137 | (void)argc; |
138 | GNUNET_log_setup ("test-datacache-quota", | 138 | GNUNET_log_setup("test-datacache-quota", |
139 | "WARNING", | 139 | "WARNING", |
140 | NULL); | 140 | NULL); |
141 | 141 | ||
142 | plugin_name = GNUNET_TESTING_get_testname_from_underscore (argv[0]); | 142 | plugin_name = GNUNET_TESTING_get_testname_from_underscore(argv[0]); |
143 | GNUNET_snprintf (cfg_name, | 143 | GNUNET_snprintf(cfg_name, |
144 | sizeof (cfg_name), | 144 | sizeof(cfg_name), |
145 | "test_datacache_data_%s.conf", | 145 | "test_datacache_data_%s.conf", |
146 | plugin_name); | 146 | plugin_name); |
147 | GNUNET_PROGRAM_run ((sizeof (xargv) / sizeof (char *)) - 1, | 147 | GNUNET_PROGRAM_run((sizeof(xargv) / sizeof(char *)) - 1, |
148 | xargv, | 148 | xargv, |
149 | "test-datacache-quota", | 149 | "test-datacache-quota", |
150 | "nohelp", | 150 | "nohelp", |
151 | options, | 151 | options, |
152 | &run, | 152 | &run, |
153 | NULL); | 153 | NULL); |
154 | if (0 != ok) | 154 | if (0 != ok) |
155 | fprintf (stderr, | 155 | fprintf(stderr, |
156 | "Missed some testcases: %d\n", | 156 | "Missed some testcases: %d\n", |
157 | ok); | 157 | ok); |
158 | return ok; | 158 | return ok; |
159 | } | 159 | } |
160 | 160 | ||