Add asynchronous I/O test

- launch 10,000 concurrent writes
 - when any one of these complete, launch a read for the same offset
 - compare read/write data
 - when all reads complete, terminate
This commit is contained in:
Avi Kivity
2014-08-21 13:50:36 +03:00
parent ec7b440a99
commit 91f10b8a9c
2 changed files with 49 additions and 1 deletions

View File

@@ -14,7 +14,7 @@ libs = -laio
CXXFLAGS = -std=gnu++1y -g -Wall -Werror $(opt) -MD -MT $@ -MP -flto $(sanitize) -fvisibility=hidden $(libs)
tests = test-reactor
tests = test-reactor fileiotest
all: seastar $(tests) httpd
@@ -30,4 +30,7 @@ test-reactor: test-reactor.o reactor.o
httpd: httpd.o reactor.o
$(CXX) $(CXXFLAGS) -o $@ $^
fileiotest: fileiotest.o reactor.o
$(CXX) $(CXXFLAGS) -o $@ $^
-include *.d

45
fileiotest.cc Normal file
View File

@@ -0,0 +1,45 @@
/*
* Copyright (C) 2014 Cloudius Systems, Ltd.
*/
#include <algorithm>
#include "reactor.hh"
struct file_test {
file_test(file&& f) : f(std::move(f)) {}
file f;
semaphore sem = { 0 };
};
int main(int ac, char** av) {
static constexpr auto max = 10000;
the_reactor.open_file_dma("testfile.tmp").then([] (file f) {
auto ft = new file_test{std::move(f)};
for (size_t i = 0; i < 10000; ++i) {
auto wbuf = allocate_aligned_buffer<unsigned char>(4096, 4096);
std::fill(wbuf.get(), wbuf.get() + 4096, i);
auto wb = wbuf.get();
ft->f.dma_write(i * 4096, wb, 4096).then(
[ft, i, wbuf = std::move(wbuf)] (size_t ret) mutable {
assert(ret == 4096);
auto rbuf = allocate_aligned_buffer<unsigned char>(4096, 4096);
auto rb = rbuf.get();
ft->f.dma_read(i * 4096, rb, 4096).then(
[ft, i, rbuf = std::move(rbuf), wbuf = std::move(wbuf)] (size_t) mutable {
bool eq = std::equal(rbuf.get(), rbuf.get() + 4096, wbuf.get());
assert(eq);
ft->sem.signal(1);
});
});
}
ft->sem.wait(max).then([ft] {
std::cout << "done\n";
delete ft;
::exit(0);
});
});
the_reactor.run();
return 0;
}