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/>.
19 * @file datacache/test_datacache_quota.c
20 * @brief Test for the quota code of the datacache implementations.
24 #include "gnunet_util_lib.h"
25 #include "gnunet_datacache_lib.h"
26 #include "gnunet_testing_lib.h"
28 #define ASSERT(x) do { if (! (x)) { printf("Error at %s:%d\n", __FILE__, __LINE__); goto FAILURE;} } while (0)
33 * Name of plugin under test.
35 static const char *plugin_name;
38 * Quota is 1 MB. Each iteration of the test puts in about 1 MB of
39 * data. We do 10 iterations. Afterwards we check that the data from
40 * the first 5 iterations has all been discarded and that at least
41 * some of the data from the last iteration is still there.
44 run (void *cls, char *const *args, const char *cfgfile,
45 const struct GNUNET_CONFIGURATION_Handle *cfg)
47 struct GNUNET_DATACACHE_Handle *h;
48 struct GNUNET_HashCode k;
49 struct GNUNET_HashCode n;
51 struct GNUNET_TIME_Absolute exp;
54 h = GNUNET_DATACACHE_create (cfg, "testcache");
60 "Failed to initialize datacache. Database likely not setup, skipping test.\n");
63 exp = GNUNET_TIME_relative_to_absolute (GNUNET_TIME_UNIT_HOURS);
64 memset (buf, 1, sizeof (buf));
65 memset (&k, 0, sizeof (struct GNUNET_HashCode));
66 for (unsigned int i = 0; i < 10; i++)
71 GNUNET_CRYPTO_hash (&k,
72 sizeof (struct GNUNET_HashCode),
74 for (unsigned int j = i; j < sizeof (buf); j += 10)
79 GNUNET_DATACACHE_put (h,
88 ASSERT (0 < GNUNET_DATACACHE_get (h, &k, 1 + i, NULL, NULL));
92 FPRINTF (stderr, "%s", "\n");
93 memset (&k, 0, sizeof (struct GNUNET_HashCode));
94 for (unsigned int i = 0; i < 10; i++)
96 FPRINTF (stderr, "%s", ".");
97 GNUNET_CRYPTO_hash (&k, sizeof (struct GNUNET_HashCode), &n);
99 ASSERT (0 == GNUNET_DATACACHE_get (h, &k, 1 + i, NULL, NULL));
101 ASSERT (0 < GNUNET_DATACACHE_get (h, &k, 1 + i, NULL, NULL));
104 FPRINTF (stderr, "%s", "\n");
105 GNUNET_DATACACHE_destroy (h);
109 GNUNET_DATACACHE_destroy (h);
115 main (int argc, char *argv[])
118 char *const xargv[] = {
119 "test-datacache-quota",
124 struct GNUNET_GETOPT_CommandLineOption options[] = {
125 GNUNET_GETOPT_OPTION_END
128 GNUNET_log_setup ("test-datacache-quota",
132 plugin_name = GNUNET_TESTING_get_testname_from_underscore (argv[0]);
133 GNUNET_snprintf (cfg_name, sizeof (cfg_name), "test_datacache_data_%s.conf",
135 GNUNET_PROGRAM_run ((sizeof (xargv) / sizeof (char *)) - 1, xargv,
136 "test-datacache-quota", "nohelp", options, &run, NULL);
138 FPRINTF (stderr, "Missed some testcases: %d\n", ok);
142 /* end of test_datacache_quota.c */