2 This file is part of GNUnet.
3 (C) 2010-2013 Christian Grothoff (and other contributing authors)
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.
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.
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.
21 * @file ats-tests/ats-testing-experiment.c
22 * @brief ats benchmark: controlled experiment execution
23 * @author Christian Grothoff
24 * @author Matthias Wachs
27 #include "gnunet_util_lib.h"
28 #include "ats-testing.h"
30 static struct Experiment *
34 e = GNUNET_new (struct Experiment);
39 e->total_duration = GNUNET_TIME_UNIT_ZERO;
44 free_experiment (struct Experiment *e)
50 for (cur = next; NULL != cur; cur = next)
56 GNUNET_free_non_null (e->name);
57 GNUNET_free_non_null (e->cfg_file);
62 load_episodes (struct Experiment *e, struct GNUNET_CONFIGURATION_Handle *cfg)
66 struct GNUNET_TIME_Relative e_duration;
74 GNUNET_asprintf(&sec_name, "episode-%u", e_counter);
75 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_time(cfg,
76 sec_name, "duration", &e_duration))
78 GNUNET_free (sec_name);
82 cur = GNUNET_new (struct Episode);
83 cur->duration = e_duration;
86 fprintf (stderr, "Found episode %u with duration %s \n",
88 GNUNET_STRINGS_relative_time_to_string(cur->duration, GNUNET_YES));
90 /* Update experiment */
92 e->total_duration = GNUNET_TIME_relative_add(e->total_duration, cur->duration);
93 /* Put in linked list */
99 GNUNET_free (sec_name);
107 timeout_experiment (void *cls, const struct GNUNET_SCHEDULER_TaskContext* tc)
109 struct Experiment *e = cls;
110 e->experiment_timeout_task = GNUNET_SCHEDULER_NO_TASK;
111 fprintf (stderr, "Experiment timeout!\n");
113 e->e_done_cb (e, GNUNET_SYSERR);
117 timeout_episode (void *cls, const struct GNUNET_SCHEDULER_TaskContext* tc)
119 struct Experiment *e = cls;
120 e->episode_timeout_task = GNUNET_SCHEDULER_NO_TASK;
121 e->ep_done_cb (e->cur);
123 /* Scheduling next */
124 e->cur = e->cur->next;
128 fprintf (stderr, "Last episode done!\n");
129 if (GNUNET_SCHEDULER_NO_TASK != e->experiment_timeout_task)
131 GNUNET_SCHEDULER_cancel (e->experiment_timeout_task);
132 e->experiment_timeout_task = GNUNET_SCHEDULER_NO_TASK;
134 e->e_done_cb (e, GNUNET_OK);
138 fprintf (stderr, "Running episode %u with timeout %s\n",
140 GNUNET_STRINGS_relative_time_to_string(e->cur->duration, GNUNET_YES));
141 e->episode_timeout_task = GNUNET_SCHEDULER_add_delayed (e->cur->duration,
142 &timeout_episode, e);
147 GNUNET_ATS_TEST_experimentation_run (struct Experiment *e,
148 GNUNET_ATS_TESTING_EpisodeDoneCallback ep_done_cb,
149 GNUNET_ATS_TESTING_ExperimentDoneCallback e_done_cb)
151 fprintf (stderr, "Running experiment `%s' with timeout %s\n", e->name,
152 GNUNET_STRINGS_relative_time_to_string(e->max_duration, GNUNET_YES));
153 e->e_done_cb = e_done_cb;
154 e->ep_done_cb = ep_done_cb;
156 /* Start total time out */
157 e->experiment_timeout_task = GNUNET_SCHEDULER_add_delayed (e->max_duration,
158 &timeout_experiment, e);
162 fprintf (stderr, "Running episode %u with timeout %s\n",
164 GNUNET_STRINGS_relative_time_to_string(e->cur->duration, GNUNET_YES));
165 e->episode_timeout_task = GNUNET_SCHEDULER_add_delayed (e->cur->duration,
166 &timeout_episode, e);
172 GNUNET_ATS_TEST_experimentation_load (char *filename)
174 struct Experiment *e;
175 struct GNUNET_CONFIGURATION_Handle *cfg;
178 cfg = GNUNET_CONFIGURATION_create();
179 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_load (cfg, filename))
181 fprintf (stderr, "Failed to load `%s'\n", filename);
182 GNUNET_CONFIGURATION_destroy (cfg);
186 e = create_experiment ();
188 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string(cfg, "experiment",
191 fprintf (stderr, "Invalid %s", "name");
196 fprintf (stderr, "Experiment name: `%s'\n", e->name);
198 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_filename (cfg, "experiment",
199 "cfg_file", &e->cfg_file))
201 fprintf (stderr, "Invalid %s", "cfg_file");
206 fprintf (stderr, "Experiment name: `%s'\n", e->cfg_file);
208 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number(cfg, "experiment",
209 "masters", &e->num_masters))
211 fprintf (stderr, "Invalid %s", "masters");
216 fprintf (stderr, "Experiment masters: `%llu'\n",
219 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number(cfg, "experiment",
220 "slaves", &e->num_slaves))
222 fprintf (stderr, "Invalid %s", "slaves");
227 fprintf (stderr, "Experiment slaves: `%llu'\n",
230 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_time(cfg, "experiment",
231 "max_duration", &e->max_duration))
233 fprintf (stderr, "Invalid %s", "max_duration");
238 fprintf (stderr, "Experiment duration: `%s'\n",
239 GNUNET_STRINGS_relative_time_to_string (e->max_duration, GNUNET_YES));
241 load_episodes (e, cfg);
242 fprintf (stderr, "Loaded %u episodes with total duration %s\n",
244 GNUNET_STRINGS_relative_time_to_string (e->total_duration, GNUNET_YES));
246 GNUNET_CONFIGURATION_destroy (cfg);
251 GNUNET_ATS_TEST_experimentation_stop (struct Experiment *e)
253 if (GNUNET_SCHEDULER_NO_TASK != e->experiment_timeout_task)
255 GNUNET_SCHEDULER_cancel (e->experiment_timeout_task);
256 e->experiment_timeout_task = GNUNET_SCHEDULER_NO_TASK;
261 /* end of file ats-testing-experiment.c*/