aboutsummaryrefslogtreecommitdiff
path: root/libbb/bbunit.c
diff options
context:
space:
mode:
Diffstat (limited to 'libbb/bbunit.c')
-rw-r--r--libbb/bbunit.c31
1 files changed, 3 insertions, 28 deletions
diff --git a/libbb/bbunit.c b/libbb/bbunit.c
index 4c692d59f..db67b1081 100644
--- a/libbb/bbunit.c
+++ b/libbb/bbunit.c
@@ -17,8 +17,6 @@
17 17
18#include "libbb.h" 18#include "libbb.h"
19 19
20#define WANT_TIMING 0
21
22static llist_t *tests = NULL; 20static llist_t *tests = NULL;
23static unsigned tests_registered = 0; 21static unsigned tests_registered = 0;
24static int test_retval; 22static int test_retval;
@@ -34,57 +32,34 @@ void bbunit_settestfailed(void)
34 test_retval = -1; 32 test_retval = -1;
35} 33}
36 34
37#if WANT_TIMING
38static void timeval_diff(struct timeval* res,
39 const struct timeval* x,
40 const struct timeval* y)
41{
42 long udiff = x->tv_usec - y->tv_usec;
43
44 res->tv_sec = x->tv_sec - y->tv_sec - (udiff < 0);
45 res->tv_usec = (udiff >= 0 ? udiff : udiff + 1000000);
46}
47#endif
48
49int unit_main(int argc UNUSED_PARAM, char **argv UNUSED_PARAM) MAIN_EXTERNALLY_VISIBLE; 35int unit_main(int argc UNUSED_PARAM, char **argv UNUSED_PARAM) MAIN_EXTERNALLY_VISIBLE;
50int unit_main(int argc UNUSED_PARAM, char **argv UNUSED_PARAM) 36int unit_main(int argc UNUSED_PARAM, char **argv UNUSED_PARAM)
51{ 37{
52 unsigned tests_run = 0; 38 unsigned tests_run = 0;
53 unsigned tests_failed = 0; 39 unsigned tests_failed = 0;
54#if WANT_TIMING
55 struct timeval begin;
56 struct timeval end;
57 struct timeval time_spent;
58 gettimeofday(&begin, NULL);
59#endif
60 40
61 bb_error_msg("Running %d test(s)...", tests_registered); 41 bb_error_msg("Running %d test(s)...", tests_registered);
62 for (;;) { 42 for (;;) {
63 struct bbunit_listelem* el = llist_pop(&tests); 43 struct bbunit_listelem* el = llist_pop(&tests);
64 if (!el) 44 if (!el)
65 break; 45 break;
46
66 bb_error_msg("Case: [%s]", el->name); 47 bb_error_msg("Case: [%s]", el->name);
67 test_retval = 0; 48 test_retval = 0;
68 el->testfunc(); 49 el->testfunc();
50
69 if (test_retval < 0) { 51 if (test_retval < 0) {
70 bb_error_msg("[ERROR] [%s]: TEST FAILED", el->name); 52 bb_error_msg("[ERROR] [%s]: TEST FAILED", el->name);
71 tests_failed++; 53 tests_failed++;
72 } 54 }
73 tests_run++; 55 tests_run++;
74 el = el->next;
75 } 56 }
76 57
77#if WANT_TIMING
78 gettimeofday(&end, NULL);
79 timeval_diff(&time_spent, &end, &begin);
80 bb_error_msg("Elapsed time %u.%06u seconds",
81 (int)time_spent.tv_sec,
82 (int)time_spent.tv_usec);
83#endif
84 if (tests_failed > 0) { 58 if (tests_failed > 0) {
85 bb_error_msg("[ERROR] %u test(s) FAILED", tests_failed); 59 bb_error_msg("[ERROR] %u test(s) FAILED", tests_failed);
86 return EXIT_FAILURE; 60 return EXIT_FAILURE;
87 } 61 }
62
88 bb_error_msg("All tests passed"); 63 bb_error_msg("All tests passed");
89 return EXIT_SUCCESS; 64 return EXIT_SUCCESS;
90} 65}