2 This file is part of GNUnet.
3 Copyright (C) 2006, 2009, 2010 GNUnet e.V.
5 GNUnet is free software: you can redistribute it and/or modify it
6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation, either version 3 of the License,
8 or (at your option) any later version.
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details.
15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
18 SPDX-License-Identifier: AGPL3.0-or-later
21 * @file datacache/test_datacache_quota.c
22 * @brief Test for the quota code of the datacache implementations.
26 #include "gnunet_util_lib.h"
27 #include "gnunet_datacache_lib.h"
28 #include "gnunet_testing_lib.h"
30 #define ASSERT(x) do { if (! (x)) { printf ("Error at %s:%d\n", __FILE__, \
31 __LINE__); goto FAILURE; \
37 * Name of plugin under test.
39 static const char *plugin_name;
42 * Quota is 1 MB. Each iteration of the test puts in about 1 MB of
43 * data. We do 10 iterations. Afterwards we check that the data from
44 * the first 5 iterations has all been discarded and that at least
45 * some of the data from the last iteration is still there.
51 const struct GNUNET_CONFIGURATION_Handle *cfg)
53 struct GNUNET_DATACACHE_Handle *h;
54 struct GNUNET_HashCode k;
55 struct GNUNET_HashCode n;
57 struct GNUNET_TIME_Absolute exp;
63 h = GNUNET_DATACACHE_create (cfg,
70 "Failed to initialize datacache. Database likely not setup, skipping test.\n");
73 exp = GNUNET_TIME_relative_to_absolute (GNUNET_TIME_UNIT_HOURS);
74 memset (buf, 1, sizeof(buf));
75 memset (&k, 0, sizeof(struct GNUNET_HashCode));
76 for (unsigned int i = 0; i < 10; i++)
81 GNUNET_CRYPTO_hash (&k,
82 sizeof(struct GNUNET_HashCode),
84 for (unsigned int j = i; j < sizeof(buf); j += 10)
89 GNUNET_DATACACHE_put (h,
98 ASSERT (0 < GNUNET_DATACACHE_get (h, &k, 1 + i, NULL, NULL));
102 fprintf (stderr, "%s", "\n");
103 memset (&k, 0, sizeof(struct GNUNET_HashCode));
104 for (unsigned int i = 0; i < 10; i++)
106 fprintf (stderr, "%s", ".");
107 GNUNET_CRYPTO_hash (&k, sizeof(struct GNUNET_HashCode), &n);
109 ASSERT (0 == GNUNET_DATACACHE_get (h, &k, 1 + i, NULL, NULL));
111 ASSERT (0 < GNUNET_DATACACHE_get (h, &k, 1 + i, NULL, NULL));
114 fprintf (stderr, "%s", "\n");
115 GNUNET_DATACACHE_destroy (h);
119 GNUNET_DATACACHE_destroy (h);
128 char cfg_name[PATH_MAX];
129 char *const xargv[] = {
130 "test-datacache-quota",
135 struct GNUNET_GETOPT_CommandLineOption options[] = {
136 GNUNET_GETOPT_OPTION_END
140 GNUNET_log_setup ("test-datacache-quota",
144 plugin_name = GNUNET_TESTING_get_testname_from_underscore (argv[0]);
145 GNUNET_snprintf (cfg_name,
147 "test_datacache_data_%s.conf",
149 GNUNET_PROGRAM_run ((sizeof(xargv) / sizeof(char *)) - 1,
151 "test-datacache-quota",
158 "Missed some testcases: %d\n",
164 /* end of test_datacache_quota.c */