aboutsummaryrefslogtreecommitdiff
path: root/src/psyc/test_psyc.c
diff options
context:
space:
mode:
authorGabor X Toth <*@tg-x.net>2013-09-16 16:46:43 +0000
committerGabor X Toth <*@tg-x.net>2013-09-16 16:46:43 +0000
commit4839fff11f31cac9af0cfbe1d67b6961d5f1b88f (patch)
tree2ccae35bf637e1bec185656f8c25b2693d0a29d4 /src/psyc/test_psyc.c
parent2745a5145a07c6effa7075391fb9ea74288ec83a (diff)
downloadgnunet-4839fff11f31cac9af0cfbe1d67b6961d5f1b88f.tar.gz
gnunet-4839fff11f31cac9af0cfbe1d67b6961d5f1b88f.zip
psyc service skeleton
Diffstat (limited to 'src/psyc/test_psyc.c')
-rw-r--r--src/psyc/test_psyc.c144
1 files changed, 144 insertions, 0 deletions
diff --git a/src/psyc/test_psyc.c b/src/psyc/test_psyc.c
new file mode 100644
index 000000000..b37b3ceb1
--- /dev/null
+++ b/src/psyc/test_psyc.c
@@ -0,0 +1,144 @@
1/*
2 * This file is part of GNUnet
3 * (C) 2013 Christian Grothoff (and other contributing authors)
4 *
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.
9 *
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.
14 *
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.
19 */
20
21/**
22 * @file psycstore/test_psycstore.c
23 * @brief Test for the PSYCstore service.
24 * @author Gabor X Toth
25 * @author Christian Grothoff
26 */
27
28#include "platform.h"
29#include "gnunet_common.h"
30#include "gnunet_util_lib.h"
31#include "gnunet_psycstore_service.h"
32#include "gnunet_testing_lib.h"
33
34#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10)
35
36#define DEBUG_SERVICE 0
37
38
39/**
40 * Return value from 'main'.
41 */
42static int res;
43
44/**
45 * Handle for task for timeout termination.
46 */
47static GNUNET_SCHEDULER_TaskIdentifier end_badly_task;
48
49
50/**
51 * Clean up all resources used.
52 */
53static void
54cleanup ()
55{
56 GNUNET_SCHEDULER_shutdown ();
57}
58
59
60/**
61 * Terminate the testcase (failure).
62 *
63 * @param cls NULL
64 * @param tc scheduler context
65 */
66static void
67end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
68{
69 res = 1;
70 cleanup ();
71}
72
73
74/**
75 * Terminate the testcase (success).
76 *
77 * @param cls NULL
78 * @param tc scheduler context
79 */
80static void
81end_normally (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
82{
83 res = 0;
84 cleanup ();
85}
86
87
88/**
89 * Finish the testcase (successfully).
90 */
91static void
92end ()
93{
94 if (end_badly_task != GNUNET_SCHEDULER_NO_TASK)
95 {
96 GNUNET_SCHEDULER_cancel (end_badly_task);
97 end_badly_task = GNUNET_SCHEDULER_NO_TASK;
98 }
99 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MILLISECONDS,
100 &end_normally, NULL);
101}
102
103/**
104 * Main function of the test, run from scheduler.
105 *
106 * @param cls NULL
107 * @param cfg configuration we use (also to connect to PSYCstore service)
108 * @param peer handle to access more of the peer (not used)
109 */
110static void
111#if DEBUG_SERVICE
112run (void *cls, char *const *args, const char *cfgfile,
113 const struct GNUNET_CONFIGURATION_Handle *cfg)
114#else
115run (void *cls,
116 const struct GNUNET_CONFIGURATION_Handle *cfg,
117 struct GNUNET_TESTING_Peer *peer)
118#endif
119{
120 end_badly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly, NULL);
121}
122
123
124int
125main (int argc, char *argv[])
126{
127 res = 1;
128#if DEBUG_SERVICE
129 const struct GNUNET_GETOPT_CommandLineOption opts[] = {
130 GNUNET_GETOPT_OPTION_END
131 };
132 if (GNUNET_OK != GNUNET_PROGRAM_run (argc, argv, "test-psyc",
133 "test-psyc [options]",
134 opts, &run, NULL))
135 return 1;
136#else
137 if (0 != GNUNET_TESTING_service_run ("test-psyc", "psyc",
138 "test_psyc.conf", &run, NULL))
139 return 1;
140#endif
141 return res;
142}
143
144/* end of test_psyc.c */