test_testing_portreservation.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. /*
  2. This file is part of GNUnet
  3. Copyright (C) 2008, 2009, 2012 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 testing/test_testing_new_portreservation.c
  18. * @brief test case for testing port reservation routines from the new testing
  19. * library API
  20. * @author Sree Harsha Totakura
  21. */
  22. #include "platform.h"
  23. #include "gnunet_util_lib.h"
  24. #include "gnunet_testing_lib.h"
  25. #define LOG(kind, ...) \
  26. GNUNET_log (kind, __VA_ARGS__)
  27. /**
  28. * The status of the test
  29. */
  30. int status;
  31. /**
  32. * Main point of test execution
  33. */
  34. static void
  35. run (void *cls, char *const *args, const char *cfgfile,
  36. const struct GNUNET_CONFIGURATION_Handle *cfg)
  37. {
  38. struct GNUNET_TESTING_System *system;
  39. uint16_t new_port1;
  40. uint16_t new_port2;
  41. uint16_t old_port1;
  42. system = GNUNET_TESTING_system_create ("/tmp/gnunet-testing-new",
  43. "localhost", NULL, NULL);
  44. GNUNET_assert (NULL != system);
  45. new_port1 = GNUNET_TESTING_reserve_port (system);
  46. LOG (GNUNET_ERROR_TYPE_DEBUG,
  47. "Reserved TCP port %u\n", new_port1);
  48. if (0 == new_port1)
  49. goto end;
  50. new_port2 = GNUNET_TESTING_reserve_port (system);
  51. LOG (GNUNET_ERROR_TYPE_DEBUG,
  52. "Reserved TCP port %u\n", new_port2);
  53. if (0 == new_port2)
  54. goto end;
  55. GNUNET_assert (new_port1 != new_port2);
  56. GNUNET_TESTING_release_port (system, new_port1);
  57. old_port1 = new_port1;
  58. new_port1 = 0;
  59. new_port1 = GNUNET_TESTING_reserve_port (system);
  60. LOG (GNUNET_ERROR_TYPE_DEBUG,
  61. "Reserved TCP port %u\n", new_port1);
  62. GNUNET_assert (0 != new_port1);
  63. GNUNET_assert (old_port1 == new_port1);
  64. GNUNET_TESTING_release_port (system, new_port1);
  65. GNUNET_TESTING_release_port (system, new_port2);
  66. status = GNUNET_OK;
  67. end:
  68. GNUNET_TESTING_system_destroy (system, GNUNET_YES);
  69. }
  70. int
  71. main (int argc, char *argv[])
  72. {
  73. struct GNUNET_GETOPT_CommandLineOption options[] = {
  74. GNUNET_GETOPT_OPTION_END
  75. };
  76. status = GNUNET_SYSERR;
  77. if (GNUNET_OK !=
  78. GNUNET_PROGRAM_run (argc,
  79. argv,
  80. "test_testing_new_portreservation",
  81. "test case for testing port reservation routines"
  82. " from the new testing library API",
  83. options,
  84. &run,
  85. NULL))
  86. return 1;
  87. return (GNUNET_OK == status) ? 0 : 1;
  88. }
  89. /* end of test_testing_portreservation.c */