Display running time
[ctestharness.git] / src / harness_demo.c
blob27985b81f779aa14168ef369d85ae2ecdd476017
1 #include "harness.h"
3 #include <stdio.h>
4 #include <stdlib.h>
5 #include <unistd.h>
7 static void
8 setup(void *user_data)
10 (void)user_data;
13 static void
14 teardown(void *user_data)
16 (void)user_data;
19 static int
20 test_foo(void *user_data)
22 int *data = (int *)user_data;
23 if (*data == 0) {
24 return (1);
27 return (0);
30 static int
31 test_fail(void *user_data)
33 (void)user_data;
34 return (1);
37 static int
38 test_pass(void *user_data)
40 (void)user_data;
41 return (0);
44 static int
45 test_long(void *user_data)
47 (void)user_data;
48 sleep(1);
49 return (0);
52 int
53 main(int argc, char *argv[])
55 int ret = EXIT_SUCCESS;
56 (void)argv;
58 struct harness_cfg cfg = {
59 .setup = setup,
60 .teardown = teardown,
61 .ntests = 0,
64 if (harness_init(&cfg) == 1) {
65 return (EXIT_FAILURE);
67 harness_add_test("bar", "test_foo", test_foo, (void *)&argc);
68 harness_add_test("bar", "test_fail", test_fail, NULL);
69 harness_add_test("baz", "test_foo", test_foo, (void *)&argc);
70 harness_add_test("baz", "test_pass", test_pass, NULL);
71 harness_add_test("bar", "test_pass", test_pass, NULL);
72 harness_add_test("baz", "test_fail", test_fail, NULL);
73 harness_add_test("baz", "test_long", test_long, NULL);
74 harness_add_test("bar", "test_long", test_long, NULL);
75 ret = harness_run(NULL);
76 harness_destroy(&cfg);
78 return (ret);