test_fs_test_lib.c 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. /*
  2. This file is part of GNUnet.
  3. (C) 2010 Christian Grothoff (and other contributing authors)
  4. GNUnet is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published
  6. by the Free Software Foundation; either version 3, or (at your
  7. 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. General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with GNUnet; see the file COPYING. If not, write to the
  14. Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  15. Boston, MA 02111-1307, USA.
  16. */
  17. /**
  18. * @file fs/test_fs_test_lib.c
  19. * @brief test fs test library
  20. * @author Christian Grothoff
  21. */
  22. #include "platform.h"
  23. #include "fs_test_lib.h"
  24. #define VERBOSE GNUNET_NO
  25. /**
  26. * File-size we use for testing.
  27. */
  28. #define FILESIZE (1024 * 1024 * 2)
  29. /**
  30. * How long until we give up on transmitting the message?
  31. */
  32. #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 300)
  33. #define NUM_DAEMONS 2
  34. #define SEED 42
  35. static struct GNUNET_FS_TestDaemon *daemons[NUM_DAEMONS];
  36. static int ret;
  37. static void
  38. do_stop (void *cls,
  39. const struct GNUNET_SCHEDULER_TaskContext *tc)
  40. {
  41. if (0 == (tc->reason & GNUNET_SCHEDULER_REASON_PREREQ_DONE))
  42. {
  43. GNUNET_break (0);
  44. ret = 1;
  45. }
  46. else
  47. {
  48. GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
  49. "Finished download, shutting down\n",
  50. (unsigned long long) FILESIZE);
  51. }
  52. GNUNET_FS_TEST_daemons_stop (NUM_DAEMONS,
  53. daemons);
  54. }
  55. static void
  56. do_download (void *cls,
  57. const struct GNUNET_FS_Uri *uri)
  58. {
  59. if (NULL == uri)
  60. {
  61. GNUNET_break (0);
  62. GNUNET_SCHEDULER_add_now (&do_stop,
  63. NULL);
  64. ret = 1;
  65. return;
  66. }
  67. GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
  68. "Downloading %llu bytes\n",
  69. (unsigned long long) FILESIZE);
  70. GNUNET_FS_TEST_download (daemons[0],
  71. TIMEOUT,
  72. 1, SEED, uri,
  73. VERBOSE,
  74. &do_stop, NULL);
  75. }
  76. static void
  77. do_publish (void *cls,
  78. const struct GNUNET_SCHEDULER_TaskContext *tc)
  79. {
  80. if (0 == (tc->reason & GNUNET_SCHEDULER_REASON_PREREQ_DONE))
  81. {
  82. GNUNET_break (0);
  83. ret = 1;
  84. GNUNET_SCHEDULER_add_now (&do_stop,
  85. NULL);
  86. return;
  87. }
  88. GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
  89. "Publishing %llu bytes\n",
  90. (unsigned long long) FILESIZE);
  91. GNUNET_FS_TEST_publish (daemons[0],
  92. TIMEOUT,
  93. 1, GNUNET_NO, FILESIZE, SEED,
  94. VERBOSE,
  95. &do_download, NULL);
  96. }
  97. static void
  98. do_connect (void *cls,
  99. const struct GNUNET_SCHEDULER_TaskContext *tc)
  100. {
  101. if (0 == (tc->reason & GNUNET_SCHEDULER_REASON_PREREQ_DONE))
  102. {
  103. GNUNET_break (0);
  104. ret = 1;
  105. GNUNET_SCHEDULER_add_now (&do_stop,
  106. NULL);
  107. return;
  108. }
  109. GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
  110. "Daemons started, will now try to connect them\n");
  111. GNUNET_FS_TEST_daemons_connect (daemons[0],
  112. daemons[1],
  113. TIMEOUT,
  114. &do_publish,
  115. NULL);
  116. }
  117. static void
  118. run (void *cls,
  119. char *const *args,
  120. const char *cfgfile,
  121. const struct GNUNET_CONFIGURATION_Handle *cfg)
  122. {
  123. GNUNET_FS_TEST_daemons_start ("fs_test_lib_data.conf",
  124. TIMEOUT,
  125. NUM_DAEMONS,
  126. daemons,
  127. &do_connect,
  128. NULL);
  129. }
  130. int
  131. main (int argc, char *argv[])
  132. {
  133. char *const argvx[] = {
  134. "test-fs-test-lib",
  135. "-c",
  136. "fs_test_lib_data.conf",
  137. #if VERBOSE
  138. "-L", "DEBUG",
  139. #endif
  140. NULL
  141. };
  142. struct GNUNET_GETOPT_CommandLineOption options[] = {
  143. GNUNET_GETOPT_OPTION_END
  144. };
  145. GNUNET_DISK_directory_remove ("/tmp/gnunet-test-fs-lib/");
  146. GNUNET_log_setup ("test_fs_test_lib",
  147. #if VERBOSE
  148. "DEBUG",
  149. #else
  150. "WARNING",
  151. #endif
  152. NULL);
  153. GNUNET_PROGRAM_run ((sizeof (argvx) / sizeof (char *)) - 1,
  154. argvx, "test-fs-test-lib",
  155. "nohelp", options, &run, NULL);
  156. GNUNET_DISK_directory_remove ("/tmp/gnunet-test-fs-lib/");
  157. return ret;
  158. }
  159. /* end of test_fs_test_lib.c */