tst: fsbench: --empty-cache option

This commit is contained in:
Bill Zissimopoulos
2022-04-19 10:21:31 +01:00
parent 4b65871747
commit bda0477a79
4 changed files with 124 additions and 7 deletions

View File

@ -48,25 +48,51 @@ void tlib_add_test_opt(const char *name, void (*fn)(void))
add_test_to_list(name, fn, 1, &test_tail);
}
struct hook
{
void (*fn)(const char *name, void (*fn)(void), int v);
struct hook *next;
};
static struct hook hook_sentinel = { .next = &hook_sentinel };
static struct hook *hook_tail = &hook_sentinel;
static void add_hook_to_list(void (*fn)(void), struct hook **tail)
{
struct hook *hook = calloc(1, sizeof *hook);
hook->fn = fn;
hook->next = (*tail)->next;
(*tail)->next = hook;
(*tail) = hook;
}
void tlib_add_hook(void (*fn)(const char *name, void (*fn)(void), int v))
{
add_hook_to_list(fn, &hook_tail);
}
static FILE *tlib_out, *tlib_err;
static jmp_buf test_jmp_buf, *test_jmp;
static char assert_buf[256];
static void test_printf(const char *fmt, ...);
static double run_test(struct test *test)
{
double res;
for (struct hook *hook = hook_tail->next->next; 0 != hook->fn; hook = hook->next)
hook->fn(test->name, test->fn, +1);
#if defined(_WIN64) || defined(_WIN32)
#pragma comment(lib, "winmm.lib")
unsigned long __stdcall timeGetTime(void);
unsigned long t0 = timeGetTime();
test->fn();
unsigned long t1 = timeGetTime();
return (t1 - t0) / 1000.0;
res = (t1 - t0) / 1000.0;
#else
time_t t0 = time(0);
test->fn();
time_t t1 = time(0);
return difftime(t1, t0);
res = difftime(t1, t0);
#endif
for (struct hook *hook = hook_tail->next->next; 0 != hook->fn; hook = hook->next)
hook->fn(test->name, test->fn, -1);
return res;
}
static void do_test_default(struct test *test, int testno)
{

View File

@ -65,6 +65,23 @@ void tlib_add_test_suite(const char *name, void (*fn)(void));
void tlib_add_test(const char *name, void (*fn)(void));
void tlib_add_test_opt(const char *name, void (*fn)(void));
/**
* Register a test hook to be run before and after every test.
*
* Test hooks are functions with prototype
* <code>void testhook(const char *name, void (*fn)(void), int v)</code>.
* The parameter v specifies that a test is about to be executed (v is +1)
* or it was just executed (v is -1).
*/
#define TESTHOOK(fn)\
do\
{\
void fn(const char *name, void (*fn)(void), int v);\
tlib_add_hook(fn);\
} while (0)
void tlib_add_hook(void (*fn)(const char *name, void (*fn)(void), int v));
/**
* Printf function.
*