From 123ca8b87e73ad7f613e44f0d4fac65c7468862e Mon Sep 17 00:00:00 2001 From: Ben Noordhuis Date: Thu, 28 Jun 2012 19:03:53 +0200 Subject: [PATCH] test: make fmt() function global --- test/benchmark-fs-stat.c | 29 ----------------------------- test/runner.c | 29 +++++++++++++++++++++++++++++ test/task.h | 3 +++ 3 files changed, 32 insertions(+), 29 deletions(-) diff --git a/test/benchmark-fs-stat.c b/test/benchmark-fs-stat.c index 53aa60b14e..e6b8a637b1 100644 --- a/test/benchmark-fs-stat.c +++ b/test/benchmark-fs-stat.c @@ -43,35 +43,6 @@ struct async_req { }; -static const char* fmt(double d) { - uint64_t v; - char* p; - - p = (char *) calloc(1, 32) + 31; /* leaks memory */ - v = d; - -#if 0 /* works but we don't care about fractional precision */ - if (d - v >= 0.01) { - *--p = '0' + (uint64_t) (d * 100) % 10; - *--p = '0' + (uint64_t) (d * 10) % 10; - *--p = '.'; - } -#endif - - if (v == 0) - *--p = '0'; - - while (v) { - if (v) *--p = '0' + (v % 10), v /= 10; - if (v) *--p = '0' + (v % 10), v /= 10; - if (v) *--p = '0' + (v % 10), v /= 10; - if (v) *--p = ','; - } - - return p; -} - - static void warmup(const char* path) { uv_fs_t reqs[MAX_CONCURRENT_REQS]; int i; diff --git a/test/runner.c b/test/runner.c index 214c9a0dd0..5f878a4936 100644 --- a/test/runner.c +++ b/test/runner.c @@ -37,6 +37,35 @@ static void log_progress(int total, int passed, int failed, const char* name) { } +const char* fmt(double d) { + uint64_t v; + char* p; + + p = (char *) calloc(1, 32) + 31; /* leaks memory */ + v = d; + +#if 0 /* works but we don't care about fractional precision */ + if (d - v >= 0.01) { + *--p = '0' + (uint64_t) (d * 100) % 10; + *--p = '0' + (uint64_t) (d * 10) % 10; + *--p = '.'; + } +#endif + + if (v == 0) + *--p = '0'; + + while (v) { + if (v) *--p = '0' + (v % 10), v /= 10; + if (v) *--p = '0' + (v % 10), v /= 10; + if (v) *--p = '0' + (v % 10), v /= 10; + if (v) *--p = ','; + } + + return p; +} + + int run_tests(int timeout, int benchmark_output) { int total, passed, failed; task_entry_t* task; diff --git a/test/task.h b/test/task.h index 04497342f7..34d28a1e79 100644 --- a/test/task.h +++ b/test/task.h @@ -106,4 +106,7 @@ typedef enum { /* Pause the calling thread for a number of milliseconds. */ void uv_sleep(int msec); +/* Format big numbers nicely. WARNING: leaks memory. */ +const char* fmt(double d); + #endif /* TASK_H_ */