test: make fmt() function global

This commit is contained in:
Ben Noordhuis 2012-06-28 19:03:53 +02:00
parent b779a0db74
commit 123ca8b87e
3 changed files with 32 additions and 29 deletions

View File

@ -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;

View File

@ -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;

View File

@ -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_ */