fixing drq code
[oweals/gnunet.git] / src / fs / test_fs_start_stop.c
1 /*
2      This file is part of GNUnet.
3      (C) 2004, 2005, 2006, 2009 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 2, 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 fs/test_fs_start_stop.c
23  * @brief testcase for fs.c (start-stop only)
24  * @author Christian Grothoff
25  */
26
27 #include "platform.h"
28 #include "gnunet_util_lib.h"
29 #include "gnunet_arm_service.h"
30 #include "gnunet_fs_service.h"
31
32 #define START_ARM GNUNET_YES
33
34 static struct GNUNET_SCHEDULER_Handle *sched;
35
36 static struct PeerContext p1;
37
38 struct PeerContext
39 {
40   struct GNUNET_CONFIGURATION_Handle *cfg;
41 #if START_ARM
42   pid_t arm_pid;
43 #endif
44 };
45
46
47 static void *
48 progress_cb (void *cls, 
49              const struct GNUNET_FS_ProgressInfo *event)
50 {
51   return NULL;
52 }
53
54
55 static void
56 setup_peer (struct PeerContext *p, const char *cfgname)
57 {
58   p->cfg = GNUNET_CONFIGURATION_create ();
59 #if START_ARM
60   p->arm_pid = GNUNET_OS_start_process ("gnunet-service-arm",
61                                         "gnunet-service-arm",
62 #if VERBOSE
63                                         "-L", "DEBUG",
64 #endif
65                                         "-c", cfgname, NULL);
66 #endif
67   GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname));
68   GNUNET_ARM_start_services (p->cfg, sched, "core", NULL);
69 }
70
71
72 static void
73 stop_arm (struct PeerContext *p)
74 {
75 #if START_ARM
76   if (0 != PLIBC_KILL (p->arm_pid, SIGTERM))
77     GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill");
78   if (GNUNET_OS_process_wait(p->arm_pid) != GNUNET_OK)
79     GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "waitpid");
80   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
81               "ARM process %u stopped\n", p->arm_pid);
82 #endif
83   GNUNET_CONFIGURATION_destroy (p->cfg);
84 }
85
86
87 static void
88 run (void *cls,
89      struct GNUNET_SCHEDULER_Handle *s,
90      char *const *args,
91      const char *cfgfile,
92      const struct GNUNET_CONFIGURATION_Handle *cfg)
93 {
94   struct GNUNET_FS_Handle *fs;
95
96   sched = s;
97   setup_peer (&p1, "test_fs_data.conf");
98   fs = GNUNET_FS_start (sched,
99                         cfg,
100                         "test-fs-start-stop",
101                         &progress_cb,
102                         NULL,
103                         GNUNET_FS_FLAGS_NONE,
104                         GNUNET_FS_OPTIONS_END);
105   GNUNET_assert (NULL != fs); 
106   sleep (1); /* FIXME */
107   GNUNET_FS_stop (fs);
108 }
109
110
111 int
112 main (int argc, char *argv[])
113 {
114   char *const argvx[] = { 
115     "test-fs-start-stop",
116     "-c",
117     "test_fs_data.conf",
118 #if VERBOSE
119     "-L", "DEBUG",
120 #endif
121     NULL
122   };
123   struct GNUNET_GETOPT_CommandLineOption options[] = {
124     GNUNET_GETOPT_OPTION_END
125   };
126
127   GNUNET_log_setup ("test_fs_start_stop", 
128 #if VERBOSE
129                     "DEBUG",
130 #else
131                     "WARNING",
132 #endif
133                     NULL);
134   GNUNET_PROGRAM_run ((sizeof (argvx) / sizeof (char *)) - 1,
135                       argvx, "test-fs-start-stop",
136                       "nohelp", options, &run, NULL);
137   stop_arm (&p1);
138   GNUNET_DISK_directory_remove ("/tmp/gnunet-test-fs/");
139   return 0;
140 }
141
142 /* end of test_fs_start_stop.c */