test_ats_api.c 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  1. /*
  2. This file is part of GNUnet.
  3. Copyright (C) 2010-2015 GNUnet e.V.
  4. GNUnet is free software: you can redistribute it and/or modify it
  5. under the terms of the GNU Affero General Public License as published
  6. by the Free Software Foundation, either version 3 of the License,
  7. or (at your option) any later version.
  8. GNUnet is distributed in the hope that it will be useful, but
  9. WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. Affero General Public License for more details.
  12. You should have received a copy of the GNU Affero General Public License
  13. along with this program. If not, see <http://www.gnu.org/licenses/>.
  14. SPDX-License-Identifier: AGPL3.0-or-later
  15. */
  16. /**
  17. * @file ats/test_ats_api.c
  18. * @brief test ATS
  19. * @author Christian Grothoff
  20. */
  21. #include "platform.h"
  22. #include "test_ats_lib.h"
  23. /**
  24. * Global timeout for the testcase.
  25. */
  26. #define TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 3)
  27. /**
  28. * Definition of the test as a sequence of commands.
  29. */
  30. static struct Command test_commands[] = {
  31. {
  32. .code = CMD_ADD_ADDRESS,
  33. .label = "add-address-0-0",
  34. .details.add_address = {
  35. .pid = 0,
  36. .addr_num = 0,
  37. .addr_flags = GNUNET_HELLO_ADDRESS_INFO_NONE,
  38. .session = 0,
  39. .properties = {
  40. .scope = GNUNET_NT_LAN
  41. }
  42. }
  43. },
  44. /* 1: adding same address again should fail */
  45. {
  46. .code = CMD_ADD_ADDRESS,
  47. .label = "add-address-0-0:FAIL",
  48. .details.add_address = {
  49. .pid = 0,
  50. .addr_num = 0,
  51. .addr_flags = GNUNET_HELLO_ADDRESS_INFO_NONE,
  52. .session = 0,
  53. .properties = {
  54. .scope = GNUNET_NT_LAN
  55. },
  56. .expect_fail = 1
  57. }
  58. },
  59. /* 2: some solver still require explicit start */
  60. {
  61. .code = CMD_REQUEST_CONNECTION_START,
  62. .label = "request-0",
  63. .details.request_connection_start = {
  64. .pid = 0
  65. }
  66. },
  67. /* 3: check we got an address */
  68. {
  69. .code = CMD_AWAIT_ADDRESS_SUGGESTION,
  70. .details.await_address_suggestion = {
  71. .add_label = "add-address-0-0"
  72. }
  73. },
  74. /* 4: check monitor also got the address */
  75. {
  76. .code = CMD_AWAIT_ADDRESS_INFORMATION,
  77. .details.await_address_information = {
  78. .add_label = "add-address-0-0"
  79. }
  80. },
  81. /* 5: test session API */
  82. {
  83. .code = CMD_ADD_SESSION,
  84. .label = "add-session-0-0-1",
  85. .details.add_session = {
  86. .add_label = "add-address-0-0",
  87. .session = 1
  88. }
  89. },
  90. {
  91. .code = CMD_DEL_SESSION,
  92. .details.del_session = {
  93. .add_session_label = "add-session-0-0-1",
  94. }
  95. },
  96. /* 7: test preference API */
  97. {
  98. .code = CMD_CHANGE_PREFERENCE,
  99. .details.change_preference = {
  100. .pid = 0
  101. /* FIXME: preference details */
  102. }
  103. },
  104. {
  105. .code = CMD_PROVIDE_FEEDBACK,
  106. .details.provide_feedback = {
  107. .pid = 0,
  108. .scope = { 50LL }
  109. /* FIXME: preference details */
  110. }
  111. },
  112. /* 9: test sanity check address listing */
  113. {
  114. .code = CMD_LIST_ADDRESSES,
  115. .details.list_addresses = {
  116. .pid = 0,
  117. .all = 1,
  118. .min_calls = 2, // ?
  119. .max_calls = 2,
  120. .min_active_calls = 1,
  121. .max_active_calls = 1
  122. }
  123. },
  124. /* 10: remove address testing */
  125. {
  126. .code = CMD_DEL_ADDRESS,
  127. .details.del_address = {
  128. .add_label = "add-address-0-0"
  129. }
  130. },
  131. /* 11: check we got disconnected */
  132. {
  133. .code = CMD_AWAIT_DISCONNECT_SUGGESTION,
  134. .details.await_disconnect_suggestion = {
  135. .pid = 0
  136. }
  137. },
  138. /* 12: just for symmetry, also stop asking for the connection */
  139. {
  140. .code = CMD_REQUEST_CONNECTION_STOP,
  141. .details.request_connection_stop = {
  142. .connect_label = "request-0",
  143. }
  144. },
  145. /* 13: add address again */
  146. {
  147. .code = CMD_ADD_ADDRESS,
  148. .label = "add-address-0-0:1",
  149. .details.add_address = {
  150. .pid = 0,
  151. .addr_num = 0,
  152. .session = 0,
  153. .properties = {
  154. .scope = GNUNET_NT_LAN
  155. }
  156. }
  157. },
  158. /* 14: some solver still require explicit start */
  159. {
  160. .code = CMD_REQUEST_CONNECTION_START,
  161. .label = "request-0",
  162. .details.request_connection_start = {
  163. .pid = 0
  164. }
  165. },
  166. /* 15: check we got an address */
  167. {
  168. .code = CMD_AWAIT_ADDRESS_SUGGESTION,
  169. .details.await_address_suggestion = {
  170. .add_label = "add-address-0-0:1"
  171. }
  172. },
  173. /* 16: add alternative address */
  174. {
  175. .code = CMD_ADD_ADDRESS,
  176. .label = "add-address-0-1",
  177. .details.add_address = {
  178. .pid = 0,
  179. .addr_num = 1,
  180. .addr_flags = GNUNET_HELLO_ADDRESS_INFO_NONE,
  181. .session = 0,
  182. .properties = {
  183. .scope = GNUNET_NT_LAN
  184. }
  185. }
  186. },
  187. /* 17: remove original address */
  188. {
  189. .code = CMD_DEL_ADDRESS,
  190. .details.del_address = {
  191. .add_label = "add-address-0-0:1"
  192. }
  193. },
  194. /* 18: check we switched to alternative address */
  195. {
  196. .code = CMD_AWAIT_ADDRESS_SUGGESTION,
  197. .details.await_address_suggestion = {
  198. .add_label = "add-address-0-1"
  199. }
  200. },
  201. /* 19: remove alternative address */
  202. {
  203. .code = CMD_DEL_ADDRESS,
  204. .details.del_address = {
  205. .add_label = "add-address-0-1"
  206. }
  207. },
  208. /* 20: check we got disconnected */
  209. {
  210. .code = CMD_AWAIT_DISCONNECT_SUGGESTION,
  211. .details.await_disconnect_suggestion = {
  212. .pid = 0
  213. }
  214. },
  215. /* 21: just for symmetry, also stop asking for the connection */
  216. {
  217. .code = CMD_REQUEST_CONNECTION_STOP,
  218. .details.request_connection_stop = {
  219. .connect_label = "request-0",
  220. }
  221. },
  222. /* Test ends successfully */
  223. {
  224. .code = CMD_END_PASS
  225. }
  226. };
  227. int
  228. main(int argc,
  229. char *argv[])
  230. {
  231. return TEST_ATS_run(argc,
  232. argv,
  233. test_commands,
  234. TIMEOUT);
  235. }
  236. /* end of file test_ats_api.c */