aboutsummaryrefslogtreecommitdiff
path: root/src/testing/test_testing_peerstartup2.c
diff options
context:
space:
mode:
authorSree Harsha Totakura <totakura@in.tum.de>2013-03-31 20:03:26 +0000
committerSree Harsha Totakura <totakura@in.tum.de>2013-03-31 20:03:26 +0000
commit1517375e5b33fb42d6cd50fcbbc8d990ddd5b81a (patch)
treedc96fc0e785a67d31091dddddae1e7a72711de4e /src/testing/test_testing_peerstartup2.c
parentb4cdd9e449679b5d38cdffef9e130b0dc7105b20 (diff)
downloadgnunet-1517375e5b33fb42d6cd50fcbbc8d990ddd5b81a.tar.gz
gnunet-1517375e5b33fb42d6cd50fcbbc8d990ddd5b81a.zip
- ARM based peer start stop
Diffstat (limited to 'src/testing/test_testing_peerstartup2.c')
-rw-r--r--src/testing/test_testing_peerstartup2.c176
1 files changed, 176 insertions, 0 deletions
diff --git a/src/testing/test_testing_peerstartup2.c b/src/testing/test_testing_peerstartup2.c
new file mode 100644
index 000000000..45d2280c7
--- /dev/null
+++ b/src/testing/test_testing_peerstartup2.c
@@ -0,0 +1,176 @@
1/*
2 This file is part of GNUnet
3 (C) 2008, 2009, 2012 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 testing/test_testing_new_peerstartup.c
23 * @brief test case for testing peer startup and shutdown using new testing
24 * library
25 * @author Sree Harsha Totakura
26 */
27
28#include "platform.h"
29#include "gnunet_configuration_lib.h"
30#include "gnunet_os_lib.h"
31#include "gnunet_testing_lib.h"
32
33#define LOG(kind,...) \
34 GNUNET_log (kind, __VA_ARGS__)
35
36/**
37 * The status of the test
38 */
39int status;
40
41/**
42 * The testing context
43 */
44struct TestingContext
45{
46 /**
47 * The testing system
48 */
49 struct GNUNET_TESTING_System *system;
50
51 /**
52 * The peer which has been started by the testing system
53 */
54 struct GNUNET_TESTING_Peer *peer;
55
56 /**
57 * The running configuration of the peer
58 */
59 struct GNUNET_CONFIGURATION_Handle *cfg;
60};
61
62
63static void
64do_shutdown2 (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
65{
66 struct TestingContext *test_ctx = cls;
67
68 if (NULL != test_ctx->peer)
69 GNUNET_TESTING_peer_destroy (test_ctx->peer);
70 if (NULL != test_ctx->cfg)
71 GNUNET_CONFIGURATION_destroy (test_ctx->cfg);
72 if (NULL != test_ctx->system)
73 GNUNET_TESTING_system_destroy (test_ctx->system, GNUNET_YES);
74 GNUNET_free (test_ctx);
75
76}
77
78static void
79peer_stop_cb (void *cls, struct GNUNET_TESTING_Peer *peer, int success)
80{
81 GNUNET_break (GNUNET_NO == success);
82 status = GNUNET_OK;
83 GNUNET_SCHEDULER_add_now (&do_shutdown2, cls);
84}
85
86
87/**
88 * Task for shutdown
89 *
90 * @param cls the testing context
91 * @param tc the tast context
92 */
93static void
94do_shutdown (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
95{
96 struct TestingContext *test_ctx = cls;
97
98 GNUNET_assert (NULL != test_ctx);
99 if (NULL != test_ctx->peer)
100 {
101 GNUNET_break (GNUNET_OK == GNUNET_TESTING_peer_stop2 (test_ctx->peer,
102 &peer_stop_cb,
103 test_ctx));
104 }
105 else
106 do_shutdown (test_ctx, tc);
107}
108
109static void
110ps_cb (void *cls, struct GNUNET_TESTING_Peer *peer, int success)
111{
112 struct TestingContext *test_ctx = cls;
113
114 GNUNET_break (GNUNET_YES == success);
115 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS,
116 &do_shutdown, test_ctx);
117}
118
119
120/**
121 * Main point of test execution
122 */
123static void
124run (void *cls, char *const *args, const char *cfgfile,
125 const struct GNUNET_CONFIGURATION_Handle *cfg)
126{
127 struct TestingContext *test_ctx;
128 char *emsg;
129 struct GNUNET_PeerIdentity id;
130
131 test_ctx = GNUNET_malloc (sizeof (struct TestingContext));
132 test_ctx->system =
133 GNUNET_TESTING_system_create ("test-gnunet-testing",
134 "127.0.0.1", NULL);
135 emsg = NULL;
136 if (NULL == test_ctx->system)
137 goto end;
138 test_ctx->cfg = GNUNET_CONFIGURATION_dup (cfg);
139 test_ctx->peer =
140 GNUNET_TESTING_peer_configure (test_ctx->system,
141 test_ctx->cfg,
142 0, &id, &emsg);
143 if (NULL == test_ctx->peer)
144 {
145 if (NULL != emsg)
146 printf ("Test failed upon error: %s", emsg);
147 goto end;
148 }
149 if (GNUNET_OK != GNUNET_TESTING_peer_start2 (test_ctx->peer,
150 &ps_cb, test_ctx))
151 goto end;
152 return;
153
154 end:
155 GNUNET_SCHEDULER_add_now (&do_shutdown, test_ctx);
156 GNUNET_free_non_null (emsg);
157}
158
159
160int main (int argc, char *argv[])
161{
162 struct GNUNET_GETOPT_CommandLineOption options[] = {
163 GNUNET_GETOPT_OPTION_END
164 };
165
166 status = GNUNET_SYSERR;
167 if (GNUNET_OK !=
168 GNUNET_PROGRAM_run (argc, argv,
169 "test_testing_new_peerstartup",
170 "test case for peerstartup using new testing library",
171 options, &run, NULL))
172 return 1;
173 return (GNUNET_OK == status) ? 0 : 1;
174}
175
176/* end of test_testing_peerstartup.c */