check_stress.c 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. /*
  2. * Check: a unit test framework for C
  3. * Copyright (C) 2001, 2002 Arien Malec
  4. *
  5. * This library is free software; you can redistribute it and/or
  6. * modify it under the terms of the GNU Lesser General Public
  7. * License as published by the Free Software Foundation; either
  8. * version 2.1 of the License, or (at your option) any later version.
  9. *
  10. * This library is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13. * Lesser General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU Lesser General Public
  16. * License along with this library; if not, write to the
  17. * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
  18. * MA 02110-1301, USA.
  19. */
  20. #include "../lib/libcompat.h"
  21. /* note: this test appears pretty useless, so we aren't including it
  22. in the TESTS variable of Makefile.am */
  23. #include <stdlib.h>
  24. #include <stdio.h>
  25. #include <check.h>
  26. Suite *s;
  27. TCase *tc;
  28. SRunner *sr;
  29. START_TEST(test_pass)
  30. {
  31. ck_assert_msg(1,"Shouldn't see this message");
  32. }
  33. END_TEST
  34. START_TEST(test_fail)
  35. {
  36. ck_abort_msg("This test fails");
  37. }
  38. END_TEST
  39. static void run (int num_iters)
  40. {
  41. int i;
  42. s = suite_create ("Stress");
  43. tc = tcase_create ("Stress");
  44. sr = srunner_create (s);
  45. suite_add_tcase(s, tc);
  46. for (i = 0; i < num_iters; i++) {
  47. tcase_add_test (tc, test_pass);
  48. tcase_add_test (tc, test_fail);
  49. }
  50. srunner_run_all(sr, CK_SILENT);
  51. if (srunner_ntests_failed (sr) != num_iters) {
  52. printf ("Error: expected %d failures, got %d\n",
  53. num_iters, srunner_ntests_failed(sr));
  54. return;
  55. }
  56. srunner_free(sr);
  57. }
  58. int main(void)
  59. {
  60. int i;
  61. time_t t1;
  62. int iters[] = {1, 100, 1000, 2000, 4000, 8000, 10000, 20000, 40000, -1};
  63. for (i = 0; iters[i] != -1; i++) {
  64. t1 = time(NULL);
  65. run(iters[i]);
  66. printf ("%d, %d\n", iters[i], (int) difftime(time(NULL), t1));
  67. }
  68. return 0;
  69. }