test_speedup.c 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. /*
  2. This file is part of GNUnet.
  3. Copyright (C) 2011-2013 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 util/test_speedup.c
  18. * @brief testcase for speedup.c
  19. */
  20. #include "platform.h"
  21. #include "gnunet_util_lib.h"
  22. /**
  23. * Start time of the testcase
  24. */
  25. static struct GNUNET_TIME_Absolute start;
  26. /**
  27. * End-time of the testcase (affected by speed-up)
  28. */
  29. static struct GNUNET_TIME_Absolute end;
  30. /**
  31. * Number of cycles we have spent in 'run'.
  32. */
  33. static unsigned int cycles;
  34. /**
  35. * Main task that is scheduled with the speed-up.
  36. *
  37. * @param cls NULL
  38. * @param tc scheduler context, unused
  39. */
  40. static void
  41. run (void *cls)
  42. {
  43. cycles++;
  44. fprintf (stderr, "..%u", cycles);
  45. if (cycles <= 5)
  46. {
  47. GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS,
  48. &run,
  49. NULL);
  50. return;
  51. }
  52. end = GNUNET_TIME_absolute_get ();
  53. fprintf (stderr, "\n");
  54. fflush (stdout);
  55. }
  56. /**
  57. *
  58. */
  59. static void
  60. check (void *cls,
  61. char *const *args,
  62. const char *cfgfile,
  63. const struct GNUNET_CONFIGURATION_Handle *cfg)
  64. {
  65. fprintf (stderr, "0");
  66. fflush (stdout);
  67. GNUNET_SCHEDULER_add_now (&run, NULL);
  68. }
  69. int
  70. main (int argc, char *argv[])
  71. {
  72. static char *const argvn[] = {
  73. "test-speedup",
  74. "-c", "test_speedup_data.conf",
  75. NULL
  76. };
  77. static struct GNUNET_GETOPT_CommandLineOption options[] = {
  78. GNUNET_GETOPT_OPTION_END
  79. };
  80. time_t start_real;
  81. time_t end_real;
  82. struct GNUNET_TIME_Relative delta;
  83. start_real = time (NULL);
  84. start = GNUNET_TIME_absolute_get ();
  85. GNUNET_PROGRAM_run ((sizeof(argvn) / sizeof(char *)) - 1, argvn,
  86. "test-speedup",
  87. "nohelp", options, &check, NULL);
  88. end_real = time (NULL);
  89. delta = GNUNET_TIME_absolute_get_difference (start, end);
  90. if (delta.rel_value_us > ((end_real - start_real) * 1500LL * 1000LL))
  91. {
  92. GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
  93. "Execution time in GNUnet time: %s\n",
  94. GNUNET_STRINGS_relative_time_to_string (delta, GNUNET_YES));
  95. GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
  96. "Execution time in system time: %llu ms\n",
  97. (unsigned long long) ((end_real - start_real) * 1000LL));
  98. return 0;
  99. }
  100. GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
  101. "Execution time in GNUnet time: %s\n",
  102. GNUNET_STRINGS_relative_time_to_string (delta, GNUNET_YES));
  103. GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
  104. "Execution time in system time: %llu ms\n",
  105. (unsigned long long) ((end_real - start_real) * 1000LL));
  106. return 1;
  107. }
  108. /* end of test_speedup.c */