diff --git a/Makefile b/Makefile index f36a2450fa..6238a525b9 100644 --- a/Makefile +++ b/Makefile @@ -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 diff --git a/fileiotest.cc b/fileiotest.cc new file mode 100644 index 0000000000..5f8c4fae77 --- /dev/null +++ b/fileiotest.cc @@ -0,0 +1,45 @@ +/* + * Copyright (C) 2014 Cloudius Systems, Ltd. + */ + +#include +#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(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(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; +} + +