From dc7602b0f190d4b71a045ecacb9e1b18c1feb0b7 Mon Sep 17 00:00:00 2001 From: Avi Kivity Date: Sun, 28 Feb 2016 19:27:04 +0200 Subject: [PATCH] Refactored test setup into a separate function --- fsqual.cc | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/fsqual.cc b/fsqual.cc index 6e8398b..fcf2c99 100644 --- a/fsqual.cc +++ b/fsqual.cc @@ -11,6 +11,7 @@ #include #include #include +#include template typename std::result_of::type @@ -33,12 +34,7 @@ with_ctxsw_counting(Counter& counter, Func&& func) { return func(); } -int main(int ac, char** av) { - io_context_t ioctx = {}; - io_setup(1, &ioctx); - auto fname = "fsqual.tmp"; - int fd = open(fname, O_CREAT|O_EXCL|O_RDWR|O_DIRECT, 0600); - unlink(fname); +void test_append(io_context_t ioctx, int fd) { auto nr = 1000; auto bufsize = 4096; auto ctxsw = 0; @@ -56,6 +52,21 @@ int main(int ac, char** av) { auto rate = float(ctxsw) / nr; auto verdict = rate < 0.1 ? "GOOD" : "BAD"; std::cout << "context switch per appending io: " << rate - << " (" << verdict << ")\n"; + << " (" << verdict << ")\n"; +} + +void run_test(std::function func) { + io_context_t ioctx = {}; + io_setup(1, &ioctx); + auto fname = "fsqual.tmp"; + int fd = open(fname, O_CREAT|O_EXCL|O_RDWR|O_DIRECT, 0600); + unlink(fname); + func(ioctx, fd); + close(fd); + io_destroy(ioctx); +} + +int main(int ac, char** av) { + run_test(test_append); return 0; } -- 2.49.0