aboutsummaryrefslogtreecommitdiff
path: root/src/ats-tests/ats-testing-experiment.c
diff options
context:
space:
mode:
authorMatthias Wachs <wachs@net.in.tum.de>2014-01-23 12:28:32 +0000
committerMatthias Wachs <wachs@net.in.tum.de>2014-01-23 12:28:32 +0000
commit74e92716b7dd1e117cb8ef932348335c98daa0e1 (patch)
treefdd8133d903f337b6e0d3c8f67965cd8bf2f4a46 /src/ats-tests/ats-testing-experiment.c
parentd3ce95bec0495962ad80d3eba9b5e11e09a2b25d (diff)
downloadgnunet-74e92716b7dd1e117cb8ef932348335c98daa0e1.tar.gz
gnunet-74e92716b7dd1e117cb8ef932348335c98daa0e1.zip
experimentation basics
Diffstat (limited to 'src/ats-tests/ats-testing-experiment.c')
-rw-r--r--src/ats-tests/ats-testing-experiment.c130
1 files changed, 130 insertions, 0 deletions
diff --git a/src/ats-tests/ats-testing-experiment.c b/src/ats-tests/ats-testing-experiment.c
new file mode 100644
index 000000000..d0e74d1c3
--- /dev/null
+++ b/src/ats-tests/ats-testing-experiment.c
@@ -0,0 +1,130 @@
1/*
2 This file is part of GNUnet.
3 (C) 2010-2013 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 * @file ats-tests/ats-testing-experiment.c
22 * @brief ats benchmark: controlled experiment execution
23 * @author Christian Grothoff
24 * @author Matthias Wachs
25 */
26#include "platform.h"
27#include "gnunet_util_lib.h"
28#include "ats-testing.h"
29
30static struct Experiment *
31create_experiment ()
32{
33 struct Experiment *e;
34 e = GNUNET_new (struct Experiment);
35 e->name = NULL;
36 e->num_masters = 0;
37 e->num_slaves = 0;
38
39 return e;
40}
41
42static void
43free_experiment (struct Experiment *e)
44{
45 GNUNET_free_non_null (e->name);
46 GNUNET_free_non_null (e->cfg_file);
47 GNUNET_free (e);
48}
49
50struct Experiment *
51GNUNET_ATS_TEST_experimentation_start (char *filename)
52{
53 struct Experiment *e;
54 struct GNUNET_CONFIGURATION_Handle *cfg;
55 e = NULL;
56
57 cfg = GNUNET_CONFIGURATION_create();
58 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_load (cfg, filename))
59 {
60 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to load `%s'\n", filename);
61 GNUNET_CONFIGURATION_destroy (cfg);
62 return NULL;
63 }
64
65 e = create_experiment ();
66
67 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string(cfg, "experiment",
68 "name", &e->name))
69 {
70 fprintf (stderr, "Invalid %s", "name");
71 free_experiment (e);
72 return NULL;
73 }
74 else
75 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Experiment name: `%s'\n", e->name);
76
77 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_filename (cfg, "experiment",
78 "cfg_file", &e->cfg_file))
79 {
80 fprintf (stderr, "Invalid %s", "cfg_file");
81 free_experiment (e);
82 return NULL;
83 }
84 else
85 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Experiment name: `%s'\n", e->cfg_file);
86
87 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number(cfg, "experiment",
88 "masters", &e->num_masters))
89 {
90 fprintf (stderr, "Invalid %s", "masters");
91 free_experiment (e);
92 return NULL;
93 }
94 else
95 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Experiment masters: `%llu'\n",
96 e->num_masters);
97
98 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number(cfg, "experiment",
99 "slaves", &e->num_slaves))
100 {
101 fprintf (stderr, "Invalid %s", "slaves");
102 free_experiment (e);
103 return NULL;
104 }
105 else
106 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Experiment slaves: `%llu'\n",
107 e->num_slaves);
108
109 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_time(cfg, "experiment",
110 "max_duration", &e->max_duration))
111 {
112 fprintf (stderr, "Invalid %s", "max_duration");
113 free_experiment (e);
114 return NULL;
115 }
116 else
117 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Experiment duration: `%s'\n",
118 GNUNET_STRINGS_relative_time_to_string (e->max_duration, GNUNET_YES));
119
120 return e;
121}
122
123void
124GNUNET_ATS_TEST_experimentation_stop (struct Experiment *e)
125{
126 free_experiment (e);
127}
128
129/* end of file ats-testing-experiment.c*/
130