TIVI-506: QA needs v0.9.8
[profile/ivi/check.git] / tests / check_stress.c
1 #include "../lib/libcompat.h"
2
3 /* note: this test appears pretty useless, so we aren't including it
4    in the TESTS variable of Makefile.am */
5
6 #include <stdlib.h>
7 #include <stdio.h>
8 #include <check.h>
9
10
11 Suite *s;
12 TCase *tc;
13 SRunner *sr;
14
15 START_TEST(test_pass)
16 {
17   fail_unless(1,"Shouldn't see this message");
18 }
19 END_TEST
20
21 START_TEST(test_fail)
22 {
23   fail("This test fails");
24 }
25 END_TEST
26
27
28 static void run (int num_iters)
29 {
30   int i;
31   s = suite_create ("Stress");
32   tc = tcase_create ("Stress");
33   sr = srunner_create (s);
34   suite_add_tcase(s, tc);
35
36   for (i = 0; i < num_iters; i++) {
37     tcase_add_test (tc, test_pass);
38     tcase_add_test (tc, test_fail);
39   }
40
41   srunner_run_all(sr, CK_SILENT);
42   if (srunner_ntests_failed (sr) != num_iters) {
43     printf ("Error: expected %d failures, got %d\n",
44             num_iters, srunner_ntests_failed(sr));
45     return;
46   }
47
48   srunner_free(sr);
49 }
50
51   
52 int main(void)
53 {
54   int i;
55   time_t t1;
56   int iters[] = {1, 100, 1000, 2000, 4000, 8000, 10000, 20000, 40000, -1};
57
58   for (i = 0; iters[i] != -1; i++) {
59     t1 = time(NULL);
60     run(iters[i]);
61     printf ("%d, %d\n", iters[i], (int) difftime(time(NULL), t1));
62   }
63   return 0;
64 }