diff options
author | Bartosz Golaszewski <bartekgola@gmail.com> | 2015-08-13 15:57:22 +0200 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2015-08-17 17:01:49 +0200 |
commit | 718e228adcd7b9592b504b55217d13f4216a0450 (patch) | |
tree | a71ff8f79bc080820d74f33b1dcd8ad1932cde0d | |
parent | d077565bb27966c47ea6f0e9de092133954b5807 (diff) | |
download | busybox-w32-718e228adcd7b9592b504b55217d13f4216a0450.tar.gz busybox-w32-718e228adcd7b9592b504b55217d13f4216a0450.tar.bz2 busybox-w32-718e228adcd7b9592b504b55217d13f4216a0450.zip |
unit-tests: remove code depending on WANT_TIMING
Since there is no interest in merging a config option for WANT_TIMING,
remove the parts of code depending on it altogether.
While we're at it: add some newlines to improve readability.
Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r-- | libbb/bbunit.c | 30 |
1 files changed, 3 insertions, 27 deletions
diff --git a/libbb/bbunit.c b/libbb/bbunit.c index 66a7df945..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 | |||
22 | static llist_t *tests = NULL; | 20 | static llist_t *tests = NULL; |
23 | static unsigned tests_registered = 0; | 21 | static unsigned tests_registered = 0; |
24 | static int test_retval; | 22 | static int test_retval; |
@@ -34,38 +32,22 @@ void bbunit_settestfailed(void) | |||
34 | test_retval = -1; | 32 | test_retval = -1; |
35 | } | 33 | } |
36 | 34 | ||
37 | #if WANT_TIMING | ||
38 | static 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 | |||
49 | int unit_main(int argc UNUSED_PARAM, char **argv UNUSED_PARAM) MAIN_EXTERNALLY_VISIBLE; | 35 | int unit_main(int argc UNUSED_PARAM, char **argv UNUSED_PARAM) MAIN_EXTERNALLY_VISIBLE; |
50 | int unit_main(int argc UNUSED_PARAM, char **argv UNUSED_PARAM) | 36 | int 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++; |
@@ -73,17 +55,11 @@ int unit_main(int argc UNUSED_PARAM, char **argv UNUSED_PARAM) | |||
73 | tests_run++; | 55 | tests_run++; |
74 | } | 56 | } |
75 | 57 | ||
76 | #if WANT_TIMING | ||
77 | gettimeofday(&end, NULL); | ||
78 | timeval_diff(&time_spent, &end, &begin); | ||
79 | bb_error_msg("Elapsed time %u.%06u seconds", | ||
80 | (int)time_spent.tv_sec, | ||
81 | (int)time_spent.tv_usec); | ||
82 | #endif | ||
83 | if (tests_failed > 0) { | 58 | if (tests_failed > 0) { |
84 | bb_error_msg("[ERROR] %u test(s) FAILED", tests_failed); | 59 | bb_error_msg("[ERROR] %u test(s) FAILED", tests_failed); |
85 | return EXIT_FAILURE; | 60 | return EXIT_FAILURE; |
86 | } | 61 | } |
62 | |||
87 | bb_error_msg("All tests passed"); | 63 | bb_error_msg("All tests passed"); |
88 | return EXIT_SUCCESS; | 64 | return EXIT_SUCCESS; |
89 | } | 65 | } |