2 This file is part of GNUnet.
3 (C) 2006, 2009, 2010 Christian Grothoff (and other contributing authors)
5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published
7 by the Free Software Foundation; either version 3, or (at your
8 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 General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with GNUnet; see the file COPYING. If not, write to the
17 Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
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"
29 #define VERBOSE GNUNET_NO
31 #define ASSERT(x) do { if (! (x)) { printf("Error at %s:%d\n", __FILE__, __LINE__); goto FAILURE;} } while (0)
36 * Name of plugin under test.
38 static const char *plugin_name;
41 * Quota is 1 MB. Each iteration of the test puts in about 1 MB of
42 * data. We do 10 iterations. Afterwards we check that the data from
43 * the first 5 iterations has all been discarded and that at least
44 * some of the data from the last iteration is still there.
48 struct GNUNET_SCHEDULER_Handle *sched,
51 const struct GNUNET_CONFIGURATION_Handle *cfg)
53 struct GNUNET_DATACACHE_Handle *h;
59 struct GNUNET_TIME_Absolute exp;
62 h = GNUNET_DATACACHE_create (sched,
69 "Failed to initialize datacache. Database likely not setup, skipping test.\n");
72 exp = GNUNET_TIME_absolute_get ();
73 exp.value += 20 * 60 * 1000;
74 memset (buf, 1, sizeof (buf));
75 memset (&k, 0, sizeof (GNUNET_HashCode));
76 for (i = 0; i < 10; i++)
78 fprintf (stderr, ".");
79 GNUNET_CRYPTO_hash (&k, sizeof (GNUNET_HashCode), &n);
80 for (j = i; j < sizeof (buf); j += 10)
85 GNUNET_DATACACHE_put (h,
91 fprintf (stderr, "G");
92 ASSERT (0 < GNUNET_DATACACHE_get (h,
98 fprintf (stderr, "\n");
99 memset (&k, 0, sizeof (GNUNET_HashCode));
100 for (i = 0; i < 10; i++)
102 fprintf (stderr, ".");
103 GNUNET_CRYPTO_hash (&k, sizeof (GNUNET_HashCode), &n);
105 ASSERT (0 == GNUNET_DATACACHE_get (h,
109 ASSERT (0 < GNUNET_DATACACHE_get (h,
114 fprintf (stderr, "\n");
115 GNUNET_DATACACHE_destroy (h);
119 GNUNET_DATACACHE_destroy (h);
125 main (int argc, char *argv[])
129 char *const xargv[] = {
130 "test-datacache-quota",
138 struct GNUNET_GETOPT_CommandLineOption options[] = {
139 GNUNET_GETOPT_OPTION_END
142 GNUNET_log_setup ("test-datacache-quota",
149 /* determine name of plugin to use */
150 plugin_name = argv[0];
151 while (NULL != (pos = strstr(plugin_name, "_")))
153 GNUNET_snprintf (cfg_name,
155 "test_datacache_data_%s.conf",
157 GNUNET_PROGRAM_run ((sizeof (xargv) / sizeof (char *)) - 1,
158 xargv, "test-datacache-quota", "nohelp",
159 options, &run, NULL);
161 fprintf (stderr, "Missed some testcases: %d\n", ok);
165 /* end of test_datacache_quota.c */