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__, __LINE__); goto FAILURE;} } while (0)
35 * Name of plugin under test.
37 static const char *plugin_name;
40 * Quota is 1 MB. Each iteration of the test puts in about 1 MB of
41 * data. We do 10 iterations. Afterwards we check that the data from
42 * the first 5 iterations has all been discarded and that at least
43 * some of the data from the last iteration is still there.
49 const struct GNUNET_CONFIGURATION_Handle *cfg)
51 struct GNUNET_DATACACHE_Handle *h;
52 struct GNUNET_HashCode k;
53 struct GNUNET_HashCode n;
55 struct GNUNET_TIME_Absolute exp;
61 h = GNUNET_DATACACHE_create (cfg,
68 "Failed to initialize datacache. Database likely not setup, skipping test.\n");
71 exp = GNUNET_TIME_relative_to_absolute (GNUNET_TIME_UNIT_HOURS);
72 memset (buf, 1, sizeof (buf));
73 memset (&k, 0, sizeof (struct GNUNET_HashCode));
74 for (unsigned int i = 0; i < 10; i++)
79 GNUNET_CRYPTO_hash (&k,
80 sizeof (struct GNUNET_HashCode),
82 for (unsigned int j = i; j < sizeof (buf); j += 10)
87 GNUNET_DATACACHE_put (h,
96 ASSERT (0 < GNUNET_DATACACHE_get (h, &k, 1 + i, NULL, NULL));
100 fprintf (stderr, "%s", "\n");
101 memset (&k, 0, sizeof (struct GNUNET_HashCode));
102 for (unsigned int i = 0; i < 10; i++)
104 fprintf (stderr, "%s", ".");
105 GNUNET_CRYPTO_hash (&k, sizeof (struct GNUNET_HashCode), &n);
107 ASSERT (0 == GNUNET_DATACACHE_get (h, &k, 1 + i, NULL, NULL));
109 ASSERT (0 < GNUNET_DATACACHE_get (h, &k, 1 + i, NULL, NULL));
112 fprintf (stderr, "%s", "\n");
113 GNUNET_DATACACHE_destroy (h);
117 GNUNET_DATACACHE_destroy (h);
126 char cfg_name[PATH_MAX];
127 char *const xargv[] = {
128 "test-datacache-quota",
133 struct GNUNET_GETOPT_CommandLineOption options[] = {
134 GNUNET_GETOPT_OPTION_END
138 GNUNET_log_setup ("test-datacache-quota",
142 plugin_name = GNUNET_TESTING_get_testname_from_underscore (argv[0]);
143 GNUNET_snprintf (cfg_name,
145 "test_datacache_data_%s.conf",
147 GNUNET_PROGRAM_run ((sizeof (xargv) / sizeof (char *)) - 1,
149 "test-datacache-quota",
156 "Missed some testcases: %d\n",
161 /* end of test_datacache_quota.c */