test_multicast.c 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. /*
  2. * This file is part of GNUnet
  3. * (C) 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 multicast/test_multicast.c
  22. * @brief Tests for the Multicast API.
  23. * @author Gabor X Toth
  24. */
  25. #include <inttypes.h>
  26. #include "platform.h"
  27. #include "gnunet_crypto_lib.h"
  28. #include "gnunet_common.h"
  29. #include "gnunet_util_lib.h"
  30. #include "gnunet_testing_lib.h"
  31. #include "gnunet_multicast_service.h"
  32. #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 30)
  33. /**
  34. * Return value from 'main'.
  35. */
  36. static int res;
  37. static const struct GNUNET_CONFIGURATION_Handle *cfg;
  38. /**
  39. * Handle for task for timeout termination.
  40. */
  41. static GNUNET_SCHEDULER_TaskIdentifier end_badly_task;
  42. /**
  43. * Clean up all resources used.
  44. */
  45. static void
  46. cleanup ()
  47. {
  48. }
  49. /**
  50. * Terminate the test case (failure).
  51. *
  52. * @param cls NULL
  53. * @param tc scheduler context
  54. */
  55. static void
  56. end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
  57. {
  58. res = 1;
  59. cleanup ();
  60. GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Test FAILED.\n");
  61. }
  62. /**
  63. * Terminate the test case (success).
  64. *
  65. * @param cls NULL
  66. * @param tc scheduler context
  67. */
  68. static void
  69. end_normally (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
  70. {
  71. res = 0;
  72. cleanup ();
  73. GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Test PASSED.\n");
  74. }
  75. /**
  76. * Finish the test case (successfully).
  77. */
  78. static void
  79. end ()
  80. {
  81. GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Ending tests.\n");
  82. if (end_badly_task != GNUNET_SCHEDULER_NO_TASK)
  83. {
  84. GNUNET_SCHEDULER_cancel (end_badly_task);
  85. end_badly_task = GNUNET_SCHEDULER_NO_TASK;
  86. }
  87. GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MILLISECONDS,
  88. &end_normally, NULL);
  89. }
  90. /**
  91. * Main function of the test, run from scheduler.
  92. *
  93. * @param cls NULL
  94. * @param cfg configuration we use (also to connect to Multicast service)
  95. * @param peer handle to access more of the peer (not used)
  96. */
  97. static void
  98. #if DEBUG_TEST_MULTICAST
  99. run (void *cls, char *const *args, const char *cfgfile,
  100. const struct GNUNET_CONFIGURATION_Handle *c)
  101. #else
  102. run (void *cls,
  103. const struct GNUNET_CONFIGURATION_Handle *c,
  104. struct GNUNET_TESTING_Peer *peer)
  105. #endif
  106. {
  107. cfg = c;
  108. end_badly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly, NULL);
  109. /* FIXME: add tests */
  110. end ();
  111. }
  112. int
  113. main (int argc, char *argv[])
  114. {
  115. res = 1;
  116. #if DEBUG_TEST_MULTICAST
  117. const struct GNUNET_GETOPT_CommandLineOption opts[] = {
  118. GNUNET_GETOPT_OPTION_END
  119. };
  120. if (GNUNET_OK != GNUNET_PROGRAM_run (argc, argv, "test-multicast",
  121. "test-multicast [options]",
  122. opts, &run, NULL))
  123. return 1;
  124. #else
  125. if (0 != GNUNET_TESTING_peer_run ("test-multicast", "test_multicast.conf", &run, NULL))
  126. return 1;
  127. #endif
  128. return res;
  129. }
  130. /* end of test_multicast.c */