Skip to content
This repository has been archived by the owner on May 4, 2018. It is now read-only.

Commit

Permalink
test: make fmt() function global
Browse files Browse the repository at this point in the history
  • Loading branch information
bnoordhuis committed Jun 29, 2012
1 parent b779a0d commit 123ca8b
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 29 deletions.
29 changes: 0 additions & 29 deletions test/benchmark-fs-stat.c
Expand Up @@ -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;
Expand Down
29 changes: 29 additions & 0 deletions test/runner.c
Expand Up @@ -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;
Expand Down
3 changes: 3 additions & 0 deletions test/task.h
Expand Up @@ -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_ */

0 comments on commit 123ca8b

Please sign in to comment.