-trying to fix #2391: limit connect rate from topology
[oweals/gnunet.git] / src / testing / test_testing_new_servicestartup.c
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  */
40 static 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  */
48 static void
49 shutdown_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  */
62 static void
63 test_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  */
75 int 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 }