aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSree Harsha Totakura <totakura@in.tum.de>2012-05-31 21:44:02 +0000
committerSree Harsha Totakura <totakura@in.tum.de>2012-05-31 21:44:02 +0000
commiteaa7823b3793e185f947f8bf4ad254078f7d915d (patch)
tree6410c764af58546be61e74f733d8ea1147befa36 /src
parent1efc19b93376335334628ca6d25a78e01e360370 (diff)
downloadgnunet-eaa7823b3793e185f947f8bf4ad254078f7d915d.tar.gz
gnunet-eaa7823b3793e185f947f8bf4ad254078f7d915d.zip
-test case for service_startup()
Diffstat (limited to 'src')
-rw-r--r--src/testing/Makefile.am12
-rw-r--r--src/testing/test_testing_new_servicestartup.c110
-rw-r--r--src/testing/testing_new.c4
3 files changed, 123 insertions, 3 deletions
diff --git a/src/testing/Makefile.am b/src/testing/Makefile.am
index 50b6d77b3..572c03330 100644
--- a/src/testing/Makefile.am
+++ b/src/testing/Makefile.am
@@ -91,7 +91,8 @@ check_PROGRAMS = \
91 test_testing_topology_none \ 91 test_testing_topology_none \
92 test_testing_topology_scale_free \ 92 test_testing_topology_scale_free \
93 test_testing_new_portreservation \ 93 test_testing_new_portreservation \
94 test_testing_new_peerstartup 94 test_testing_new_peerstartup \
95 test_testing_new_servicestartup
95 96
96if ENABLE_TEST_RUN 97if ENABLE_TEST_RUN
97TESTS = \ 98TESTS = \
@@ -101,7 +102,8 @@ TESTS = \
101 test_testing_group \ 102 test_testing_group \
102 test_testing_peergroup \ 103 test_testing_peergroup \
103 test_testing_new_portreservation \ 104 test_testing_new_portreservation \
104 test_testing_new_peerstartup 105 test_testing_new_peerstartup \
106 test_testing_new_servicestartup
105endif 107endif
106 108
107gnunet_testing_SOURCES = \ 109gnunet_testing_SOURCES = \
@@ -279,6 +281,12 @@ test_testing_new_peerstartup_LDADD = \
279 $(top_builddir)/src/testing/libgnunettesting_new.la \ 281 $(top_builddir)/src/testing/libgnunettesting_new.la \
280 $(top_builddir)/src/util/libgnunetutil.la 282 $(top_builddir)/src/util/libgnunetutil.la
281 283
284test_testing_new_servicestartup_SOURCES = \
285 test_testing_new_servicestartup.c
286test_testing_new_servicestartup_LDADD = \
287 $(top_builddir)/src/testing/libgnunettesting_new.la \
288 $(top_builddir)/src/util/libgnunetutil.la
289
282EXTRA_DIST = \ 290EXTRA_DIST = \
283 test_testing_defaults.conf \ 291 test_testing_defaults.conf \
284 test_testing_data.conf \ 292 test_testing_data.conf \
diff --git a/src/testing/test_testing_new_servicestartup.c b/src/testing/test_testing_new_servicestartup.c
new file mode 100644
index 000000000..3b9868869
--- /dev/null
+++ b/src/testing/test_testing_new_servicestartup.c
@@ -0,0 +1,110 @@
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_servicestartup.c
23 * @brief test case for testing service startup using new testing API
24 * @author Sree Harsha Totakura
25 */
26
27#include "platform.h"
28#include "gnunet_testing_lib-new.h"
29
30
31#define LOG(kind,...) \
32 GNUNET_log (kind, __VA_ARGS__)
33
34#define TIME_REL_SEC(sec) \
35 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, sec)
36
37/**
38 * Global test status
39 */
40static int test_success;
41
42/**
43 * The shutdown task. Used to signal that testing is done and service has to be
44 * stopped
45 *
46 * @param cls NULL
47 */
48static void
49shutdown_task(void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
50{
51 test_success = GNUNET_YES;
52 GNUNET_SCHEDULER_shutdown ();
53}
54
55
56/**
57 * The testing callback function
58 *
59 * @param cls NULL
60 * @param cfg the configuration with which the current testing service is run
61 */
62static void
63test_run (void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg)
64{
65 GNUNET_assert (NULL == cls);
66 GNUNET_assert (NULL != cfg);
67 LOG (GNUNET_ERROR_TYPE_DEBUG, "Service arm started successfully\n");
68 GNUNET_SCHEDULER_add_delayed (TIME_REL_SEC (3), &shutdown_task, NULL);
69}
70
71
72/**
73 * The main point of execution
74 */
75int main (int argc, char *argv[])
76{
77 char *_tmpdir;
78 char *tmpdir;
79#ifdef MINGW
80 char *tmpdir_w;
81#endif
82
83 GNUNET_log_setup ("test_testing_new_servicestartup", "DEBUG", NULL);
84 _tmpdir = getenv ("TMP");
85 if (NULL == _tmpdir)
86 _tmpdir = getenv ("TEMP");
87 if (NULL == _tmpdir)
88 _tmpdir = getenv ("TMPDIR");
89 if (NULL == _tmpdir)
90 _tmpdir = "/tmp";
91 GNUNET_asprintf (&tmpdir, "%s/%s", _tmpdir, "test-gnunet-testing_new-XXXXXX");
92#ifdef MINGW
93 tmpdir_w = GNUNET_malloc (MAX_PATH + 1);
94 GNUNET_assert (ERROR_SUCCESS == plibc_conv_to_win_path (tmpdir, tmpdir_w));
95 GNUNET_free (tmpdir);
96 tmpdir = tmpdir_w;
97 //GNUNET_assert (0 == _mktemp_s (tmpdir, strlen (tmpdir) + 1));
98#else
99 GNUNET_assert (mkdtemp (tmpdir) == tmpdir);
100#endif
101
102 test_success = GNUNET_NO;
103 GNUNET_assert (0 == GNUNET_TESTING_service_run (tmpdir,
104 "arm",
105 "test_testing_defaults.conf",
106 &test_run,
107 NULL));
108 GNUNET_free (tmpdir);
109 return (GNUNET_YES == test_success) ? 0 : 1;
110}
diff --git a/src/testing/testing_new.c b/src/testing/testing_new.c
index c19f5c8e1..c45b89e29 100644
--- a/src/testing/testing_new.c
+++ b/src/testing/testing_new.c
@@ -965,9 +965,11 @@ GNUNET_TESTING_service_run (const char *tmppath,
965 if (NULL == peer) 965 if (NULL == peer)
966 { 966 {
967 GNUNET_CONFIGURATION_destroy (cfg); 967 GNUNET_CONFIGURATION_destroy (cfg);
968 GNUNET_TESTING_hostkeys_unload (system);
968 GNUNET_TESTING_system_destroy (system, GNUNET_YES); 969 GNUNET_TESTING_system_destroy (system, GNUNET_YES);
969 return 1; 970 return 1;
970 } 971 }
972 GNUNET_TESTING_hostkeys_unload (system);
971 GNUNET_free (peer->main_binary); 973 GNUNET_free (peer->main_binary);
972 GNUNET_asprintf (&peer->main_binary, "gnunet-service-%s", service_name); 974 GNUNET_asprintf (&peer->main_binary, "gnunet-service-%s", service_name);
973 if (GNUNET_OK != GNUNET_TESTING_peer_start (peer)) 975 if (GNUNET_OK != GNUNET_TESTING_peer_start (peer))