aboutsummaryrefslogtreecommitdiff
path: root/src/testing/test_testing_servicestartup.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2012-06-10 00:28:14 +0000
committerChristian Grothoff <christian@grothoff.org>2012-06-10 00:28:14 +0000
commite96eef7d4ed698a008e66e9a24cfff360361ef74 (patch)
tree0faeb69ad7d5b455b656fbf629f0c678e214bd3e /src/testing/test_testing_servicestartup.c
parentbd790689b784f612e55e0df6e87c3c88b4b070e2 (diff)
downloadgnunet-e96eef7d4ed698a008e66e9a24cfff360361ef74.tar.gz
gnunet-e96eef7d4ed698a008e66e9a24cfff360361ef74.zip
-renamefest
Diffstat (limited to 'src/testing/test_testing_servicestartup.c')
-rw-r--r--src/testing/test_testing_servicestartup.c111
1 files changed, 111 insertions, 0 deletions
diff --git a/src/testing/test_testing_servicestartup.c b/src/testing/test_testing_servicestartup.c
new file mode 100644
index 000000000..0d3c6ca13
--- /dev/null
+++ b/src/testing/test_testing_servicestartup.c
@@ -0,0 +1,111 @@
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_scheduler_lib.h"
29#include "gnunet_testing_lib-new.h"
30
31
32#define LOG(kind,...) \
33 GNUNET_log (kind, __VA_ARGS__)
34
35#define TIME_REL_SEC(sec) \
36 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, sec)
37
38/**
39 * Global test status
40 */
41static int test_success;
42
43/**
44 * The shutdown task. Used to signal that testing is done and service has to be
45 * stopped
46 *
47 * @param cls NULL
48 */
49static void
50shutdown_task(void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
51{
52 test_success = GNUNET_YES;
53 GNUNET_SCHEDULER_shutdown ();
54}
55
56
57/**
58 * The testing callback function
59 *
60 * @param cls NULL
61 * @param cfg the configuration with which the current testing service is run
62 */
63static void
64test_run (void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg)
65{
66 GNUNET_assert (NULL == cls);
67 GNUNET_assert (NULL != cfg);
68 LOG (GNUNET_ERROR_TYPE_DEBUG, "Service arm started successfully\n");
69 GNUNET_SCHEDULER_add_delayed (TIME_REL_SEC (3), &shutdown_task, NULL);
70}
71
72
73/**
74 * The main point of execution
75 */
76int main (int argc, char *argv[])
77{
78 char *_tmpdir;
79 char *tmpdir;
80#ifdef MINGW
81 char *tmpdir_w;
82#endif
83
84 GNUNET_log_setup ("test_testing_new_servicestartup", "DEBUG", NULL);
85 _tmpdir = getenv ("TMP");
86 if (NULL == _tmpdir)
87 _tmpdir = getenv ("TEMP");
88 if (NULL == _tmpdir)
89 _tmpdir = getenv ("TMPDIR");
90 if (NULL == _tmpdir)
91 _tmpdir = "/tmp";
92 GNUNET_asprintf (&tmpdir, "%s/%s", _tmpdir, "test-gnunet-testing_new-XXXXXX");
93#ifdef MINGW
94 tmpdir_w = GNUNET_malloc (MAX_PATH + 1);
95 GNUNET_assert (ERROR_SUCCESS == plibc_conv_to_win_path (tmpdir, tmpdir_w));
96 GNUNET_free (tmpdir);
97 tmpdir = tmpdir_w;
98 //GNUNET_assert (0 == _mktemp_s (tmpdir, strlen (tmpdir) + 1));
99#else
100 GNUNET_assert (mkdtemp (tmpdir) == tmpdir);
101#endif
102
103 test_success = GNUNET_NO;
104 GNUNET_assert (0 == GNUNET_TESTING_service_run (tmpdir,
105 "arm",
106 "test_testing_defaults.conf",
107 &test_run,
108 NULL));
109 GNUNET_free (tmpdir);
110 return (GNUNET_YES == test_success) ? 0 : 1;
111}