mirror of
https://github.com/sheumann/hush.git
synced 2025-01-22 19:30:51 +00:00
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>
This commit is contained in:
parent
d077565bb2
commit
718e228adc
@ -17,8 +17,6 @@
|
|||||||
|
|
||||||
#include "libbb.h"
|
#include "libbb.h"
|
||||||
|
|
||||||
#define WANT_TIMING 0
|
|
||||||
|
|
||||||
static llist_t *tests = NULL;
|
static llist_t *tests = NULL;
|
||||||
static unsigned tests_registered = 0;
|
static unsigned tests_registered = 0;
|
||||||
static int test_retval;
|
static int test_retval;
|
||||||
@ -34,38 +32,22 @@ void bbunit_settestfailed(void)
|
|||||||
test_retval = -1;
|
test_retval = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if WANT_TIMING
|
|
||||||
static void timeval_diff(struct timeval* res,
|
|
||||||
const struct timeval* x,
|
|
||||||
const struct timeval* y)
|
|
||||||
{
|
|
||||||
long udiff = x->tv_usec - y->tv_usec;
|
|
||||||
|
|
||||||
res->tv_sec = x->tv_sec - y->tv_sec - (udiff < 0);
|
|
||||||
res->tv_usec = (udiff >= 0 ? udiff : udiff + 1000000);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
int unit_main(int argc UNUSED_PARAM, char **argv UNUSED_PARAM) MAIN_EXTERNALLY_VISIBLE;
|
int unit_main(int argc UNUSED_PARAM, char **argv UNUSED_PARAM) MAIN_EXTERNALLY_VISIBLE;
|
||||||
int unit_main(int argc UNUSED_PARAM, char **argv UNUSED_PARAM)
|
int unit_main(int argc UNUSED_PARAM, char **argv UNUSED_PARAM)
|
||||||
{
|
{
|
||||||
unsigned tests_run = 0;
|
unsigned tests_run = 0;
|
||||||
unsigned tests_failed = 0;
|
unsigned tests_failed = 0;
|
||||||
#if WANT_TIMING
|
|
||||||
struct timeval begin;
|
|
||||||
struct timeval end;
|
|
||||||
struct timeval time_spent;
|
|
||||||
gettimeofday(&begin, NULL);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
bb_error_msg("Running %d test(s)...", tests_registered);
|
bb_error_msg("Running %d test(s)...", tests_registered);
|
||||||
for (;;) {
|
for (;;) {
|
||||||
struct bbunit_listelem* el = llist_pop(&tests);
|
struct bbunit_listelem* el = llist_pop(&tests);
|
||||||
if (!el)
|
if (!el)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
bb_error_msg("Case: [%s]", el->name);
|
bb_error_msg("Case: [%s]", el->name);
|
||||||
test_retval = 0;
|
test_retval = 0;
|
||||||
el->testfunc();
|
el->testfunc();
|
||||||
|
|
||||||
if (test_retval < 0) {
|
if (test_retval < 0) {
|
||||||
bb_error_msg("[ERROR] [%s]: TEST FAILED", el->name);
|
bb_error_msg("[ERROR] [%s]: TEST FAILED", el->name);
|
||||||
tests_failed++;
|
tests_failed++;
|
||||||
@ -73,17 +55,11 @@ int unit_main(int argc UNUSED_PARAM, char **argv UNUSED_PARAM)
|
|||||||
tests_run++;
|
tests_run++;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if WANT_TIMING
|
|
||||||
gettimeofday(&end, NULL);
|
|
||||||
timeval_diff(&time_spent, &end, &begin);
|
|
||||||
bb_error_msg("Elapsed time %u.%06u seconds",
|
|
||||||
(int)time_spent.tv_sec,
|
|
||||||
(int)time_spent.tv_usec);
|
|
||||||
#endif
|
|
||||||
if (tests_failed > 0) {
|
if (tests_failed > 0) {
|
||||||
bb_error_msg("[ERROR] %u test(s) FAILED", tests_failed);
|
bb_error_msg("[ERROR] %u test(s) FAILED", tests_failed);
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
bb_error_msg("All tests passed");
|
bb_error_msg("All tests passed");
|
||||||
return EXIT_SUCCESS;
|
return EXIT_SUCCESS;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user