mirror of
https://gitlab.nic.cz/labs/bird.git
synced 2024-12-22 17:51:53 +00:00
Tests: added a simple benchmark
This commit is contained in:
parent
4e164bb374
commit
dc9297b712
@ -174,12 +174,14 @@ $(tests_targets): %: %.o $(tests_objs) | prepare
|
|||||||
$(tests_targets): LIBS += $(DAEMON_LIBS)
|
$(tests_targets): LIBS += $(DAEMON_LIBS)
|
||||||
|
|
||||||
$(tests_targets_ok): %.ok: %
|
$(tests_targets_ok): %.ok: %
|
||||||
$(Q)$* 2>/dev/null && touch $*.ok
|
$(Q)$* $(TESTFLAGS) 2>/dev/null && touch $*.ok
|
||||||
|
|
||||||
test: testsclean check
|
test: testsclean check
|
||||||
check: tests tests_run
|
check: tests tests_run
|
||||||
tests: $(tests_targets)
|
tests: $(tests_targets)
|
||||||
tests_run: $(tests_targets_ok)
|
tests_run: $(tests_targets_ok)
|
||||||
|
benchmark: test
|
||||||
|
benchmark: TESTFLAGS+=-b
|
||||||
|
|
||||||
tags:
|
tags:
|
||||||
cd $(srcdir) ; etags -lc `find $(dirs) -name *.[chY]`
|
cd $(srcdir) ; etags -lc `find $(dirs) -name *.[chY]`
|
||||||
|
@ -10,6 +10,7 @@
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
|
#include <time.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
#include <sys/ioctl.h>
|
#include <sys/ioctl.h>
|
||||||
@ -35,6 +36,7 @@ static int no_fork;
|
|||||||
static int no_timeout;
|
static int no_timeout;
|
||||||
static int is_terminal; /* Whether stdout is a live terminal or pipe redirect */
|
static int is_terminal; /* Whether stdout is a live terminal or pipe redirect */
|
||||||
|
|
||||||
|
int bt_benchmark;
|
||||||
uint bt_verbose;
|
uint bt_verbose;
|
||||||
const char *bt_filename;
|
const char *bt_filename;
|
||||||
const char *bt_test_id;
|
const char *bt_test_id;
|
||||||
@ -67,9 +69,14 @@ bt_init(int argc, char *argv[])
|
|||||||
bt_test_id = NULL;
|
bt_test_id = NULL;
|
||||||
is_terminal = isatty(fileno(stdout));
|
is_terminal = isatty(fileno(stdout));
|
||||||
|
|
||||||
while ((c = getopt(argc, argv, "lcftv")) >= 0)
|
while ((c = getopt(argc, argv, "blcftv")) >= 0)
|
||||||
switch (c)
|
switch (c)
|
||||||
{
|
{
|
||||||
|
case 'b':
|
||||||
|
bt_benchmark = 1;
|
||||||
|
no_timeout = 1;
|
||||||
|
break;
|
||||||
|
|
||||||
case 'l':
|
case 'l':
|
||||||
list_tests = 1;
|
list_tests = 1;
|
||||||
break;
|
break;
|
||||||
@ -155,10 +162,25 @@ int bt_run_test_fn(int (*fn)(const void *), const void *fn_arg, int timeout)
|
|||||||
int result;
|
int result;
|
||||||
alarm(timeout);
|
alarm(timeout);
|
||||||
|
|
||||||
if (fn_arg)
|
if (bt_benchmark) {
|
||||||
result = fn(fn_arg);
|
for (int i=0; i<11; i++) {
|
||||||
else
|
struct timespec begin, end;
|
||||||
result = ((int (*)(void))fn)();
|
clock_gettime(CLOCK_MONOTONIC, &begin);
|
||||||
|
if (fn_arg)
|
||||||
|
result = fn(fn_arg);
|
||||||
|
else
|
||||||
|
result = ((int (*)(void))fn)();
|
||||||
|
clock_gettime(CLOCK_MONOTONIC, &end);
|
||||||
|
s64 dif = (end.tv_sec - begin.tv_sec) * 1000000000 + end.tv_nsec - begin.tv_nsec;
|
||||||
|
if (i)
|
||||||
|
bt_log("benchmark: %ld", dif);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (fn_arg)
|
||||||
|
result = fn(fn_arg);
|
||||||
|
else
|
||||||
|
result = ((int (*)(void))fn)();
|
||||||
|
}
|
||||||
|
|
||||||
if (!bt_suite_result)
|
if (!bt_suite_result)
|
||||||
result = 0;
|
result = 0;
|
||||||
|
@ -20,6 +20,7 @@
|
|||||||
extern int bt_result;
|
extern int bt_result;
|
||||||
extern int bt_suite_result;
|
extern int bt_suite_result;
|
||||||
extern char bt_out_fmt_buf[1024];
|
extern char bt_out_fmt_buf[1024];
|
||||||
|
extern int bt_benchmark;
|
||||||
|
|
||||||
extern uint bt_verbose;
|
extern uint bt_verbose;
|
||||||
#define BT_VERBOSE_NO 0
|
#define BT_VERBOSE_NO 0
|
||||||
|
Loading…
Reference in New Issue
Block a user