guix-env: some update.
[oweals/gnunet.git] / src / ats / test_ats_api.c
1 /*
2      This file is part of GNUnet.
3      Copyright (C) 2010-2015 GNUnet e.V.
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., 51 Franklin Street, Fifth Floor,
18      Boston, MA 02110-1301, USA.
19 */
20 /**
21  * @file ats/test_ats_api.c
22  * @brief test ATS
23  * @author Christian Grothoff
24  */
25 #include "platform.h"
26 #include "test_ats_lib.h"
27
28 /**
29  * Global timeout for the testcase.
30  */
31 #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 3)
32
33 /**
34  * Definition of the test as a sequence of commands.
35  */
36 static struct Command test_commands[] = {
37   {
38     .code = CMD_ADD_ADDRESS,
39     .label = "add-address-0-0",
40     .details.add_address = {
41       .pid = 0,
42       .addr_num = 0,
43       .addr_flags = GNUNET_HELLO_ADDRESS_INFO_NONE,
44       .session = 0,
45       .properties = {
46         .scope = GNUNET_ATS_NET_LAN
47       }
48     }
49   },
50   /* 1: adding same address again should fail */
51   {
52     .code = CMD_ADD_ADDRESS,
53     .label = "add-address-0-0:FAIL",
54     .details.add_address = {
55       .pid = 0,
56       .addr_num = 0,
57       .addr_flags = GNUNET_HELLO_ADDRESS_INFO_NONE,
58       .session = 0,
59       .properties = {
60         .scope = GNUNET_ATS_NET_LAN
61       },
62       .expect_fail = 1
63     }
64   },
65   /* 2: some solver still require explicit start */
66   {
67     .code = CMD_REQUEST_CONNECTION_START,
68     .label = "request-0",
69     .details.request_connection_start = {
70       .pid = 0
71     }
72   },
73   /* 3: check we got an address */
74   {
75     .code = CMD_AWAIT_ADDRESS_SUGGESTION,
76     .details.await_address_suggestion = {
77       .add_label = "add-address-0-0"
78     }
79   },
80   /* 4: check monitor also got the address */
81   {
82     .code = CMD_AWAIT_ADDRESS_INFORMATION,
83     .details.await_address_information = {
84       .add_label = "add-address-0-0"
85     }
86   },
87   /* 5: test session API */
88   {
89     .code = CMD_ADD_SESSION,
90     .label = "add-session-0-0-1",
91     .details.add_session = {
92       .add_label ="add-address-0-0",
93       .session = 1
94     }
95   },
96   {
97     .code = CMD_DEL_SESSION,
98     .details.del_session = {
99       .add_session_label = "add-session-0-0-1",
100     }
101   },
102   /* 7: test preference API */
103   {
104     .code = CMD_CHANGE_PREFERENCE,
105     .details.change_preference = {
106       .pid = 0
107       /* FIXME: preference details */
108     }
109   },
110   {
111     .code = CMD_PROVIDE_FEEDBACK,
112     .details.provide_feedback = {
113       .pid = 0,
114       .scope = { 50LL }
115       /* FIXME: preference details */
116     }
117   },
118   /* 9: test sanity check address listing */
119   {
120     .code = CMD_LIST_ADDRESSES,
121     .details.list_addresses = {
122       .pid = 0,
123       .all = 1,
124       .min_calls = 2, // ?
125       .max_calls = 2,
126       .min_active_calls = 1,
127       .max_active_calls = 1
128     }
129   },
130   /* 10: remove address testing */
131   {
132     .code = CMD_DEL_ADDRESS,
133     .details.del_address = {
134       .add_label = "add-address-0-0"
135     }
136   },
137   /* 11: check we got disconnected */
138   {
139     .code = CMD_AWAIT_DISCONNECT_SUGGESTION,
140     .details.await_disconnect_suggestion = {
141       .pid = 0
142     }
143   },
144   /* 12: just for symmetry, also stop asking for the connection */
145   {
146     .code = CMD_REQUEST_CONNECTION_STOP,
147     .details.request_connection_stop = {
148       .connect_label = "request-0",
149     }
150   },
151   /* 13: add address again */
152   {
153     .code = CMD_ADD_ADDRESS,
154     .label = "add-address-0-0:1",
155     .details.add_address = {
156       .pid = 0,
157       .addr_num = 0,
158       .session = 0,
159       .properties = {
160         .scope = GNUNET_ATS_NET_LAN
161       }
162     }
163   },
164   /* 14: some solver still require explicit start */
165   {
166     .code = CMD_REQUEST_CONNECTION_START,
167     .label = "request-0",
168     .details.request_connection_start = {
169       .pid = 0
170     }
171   },
172   /* 15: check we got an address */
173   {
174     .code = CMD_AWAIT_ADDRESS_SUGGESTION,
175     .details.await_address_suggestion = {
176       .add_label = "add-address-0-0:1"
177     }
178   },
179   /* 16: add alternative address */
180   {
181     .code = CMD_ADD_ADDRESS,
182     .label = "add-address-0-1",
183     .details.add_address = {
184       .pid = 0,
185       .addr_num = 1,
186       .addr_flags = GNUNET_HELLO_ADDRESS_INFO_NONE,
187       .session = 0,
188       .properties = {
189         .scope = GNUNET_ATS_NET_LAN
190       }
191     }
192   },
193   /* 17: remove original address */
194   {
195     .code = CMD_DEL_ADDRESS,
196     .details.del_address = {
197       .add_label = "add-address-0-0:1"
198     }
199   },
200   /* 18: check we switched to alternative address */
201   {
202     .code = CMD_AWAIT_ADDRESS_SUGGESTION,
203     .details.await_address_suggestion = {
204       .add_label = "add-address-0-1"
205     }
206   },
207   /* 19: remove alternative address */
208   {
209     .code = CMD_DEL_ADDRESS,
210     .details.del_address = {
211       .add_label = "add-address-0-1"
212     }
213   },
214   /* 20: check we got disconnected */
215   {
216     .code = CMD_AWAIT_DISCONNECT_SUGGESTION,
217     .details.await_disconnect_suggestion = {
218       .pid = 0
219     }
220   },
221   /* 21: just for symmetry, also stop asking for the connection */
222   {
223     .code = CMD_REQUEST_CONNECTION_STOP,
224     .details.request_connection_stop = {
225       .connect_label = "request-0",
226     }
227   },
228   /* Test ends successfully */
229   {
230     .code = CMD_END_PASS
231   }
232 };
233
234
235 int
236 main (int argc,
237       char *argv[])
238 {
239   return TEST_ATS_run (argc,
240                        argv,
241                        test_commands,
242                        TIMEOUT);
243 }
244
245
246 /* end of file test_ats_api.c */