Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
.vscode/
bazel-bin
bazel-out
bazel-riegeli
bazel-testlogs
.bazelversion
configure.bazelrc
io_uring_test
17 changes: 17 additions & 0 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,13 @@ http_archive(
],
)

http_archive(
name = "com_google_googletest",
sha256 = "5cf189eb6847b4f8fc603a3ffff3b0771c08eec7dd4bd961bfd45477dd13eb73",
strip_prefix = "googletest-609281088cfefc76f9d0ce82e1ff6c30cc3591e5",
urls = ["https://github.com/google/googletest/archive/609281088cfefc76f9d0ce82e1ff6c30cc3591e5.zip"],
)

http_archive(
name = "org_brotli",
sha256 = "6e69be238ff61cef589a3fa88da11b649c7ff7a5932cb12d1e6251c8c2e17a2f",
Expand Down Expand Up @@ -68,6 +75,16 @@ http_archive(
],
)

http_archive(
name = "liburing",
build_file = "//third_party:liburing.BUILD",
sha256 = "ca069ecc4aa1baf1031bd772e4e97f7e26dfb6bb733d79f70159589b22ab4dc0",
strip_prefix = "liburing-liburing-2.0",
urls = [
"https://github.com/axboe/liburing/archive/refs/tags/liburing-2.0.tar.gz",
],
)

http_archive(
name = "highwayhash",
build_file = "//third_party:highwayhash.BUILD",
Expand Down
21 changes: 21 additions & 0 deletions io_uring_test/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
cc_test(
name = "io_uring_write_test",
srcs = ["io_uring_write_test.cc"],
deps = [
"//riegeli/bytes:fd_io_uring_writer",
"//riegeli/records:record_writer",
"//riegeli/bytes:fd_reader",
"//riegeli/records:record_reader",
"@com_google_googletest//:gtest_main",
],
)

cc_test(
name = "io_uring_test",
srcs = ["io_uring_test.cc"],
deps = [
"//riegeli/iouring:fd_async_io_uring",
"//riegeli/iouring:fd_sync_io_uring",
"@com_google_googletest//:gtest_main",
],
)
177 changes: 177 additions & 0 deletions io_uring_test/io_uring_test.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,177 @@
#include "riegeli/iouring/fd_async_io_uring.h"
#include "riegeli/iouring/fd_sync_io_uring.h"

#include <sys/types.h>
#include <fcntl.h>
#include <sys/stat.h>

#include "gtest/gtest.h"

namespace iouringtest {
using IoUringPtr = std::unique_ptr<riegeli::FdIoUring>;

TEST(IoUringTest, CreateAsynIoUring) {
IoUringPtr IoUring;
riegeli::FdIoUringOptions options;
options.set_async(true);
IoUring = std::make_unique<riegeli::FdAsyncIoUring>(options, 0);

EXPECT_EQ(IoUring -> Mode(), riegeli::FdIoUring::IoUringMode::ASYNCIOURING);
}

TEST(IoUringTest, CreateSynIoUring) {
IoUringPtr IoUring;
riegeli::FdIoUringOptions options;
options.set_async(false);
IoUring = std::make_unique<riegeli::FdSyncIoUring>(options, 0);

EXPECT_EQ(IoUring -> Mode(), riegeli::FdIoUring::IoUringMode::SYNCIOURING);
}

TEST(IoUringTest, SyncUnRegisterFd) {
IoUringPtr IoUring;
riegeli::FdIoUringOptions options;
options.set_async(false);
options.set_fd_register(false);
IoUring = std::make_unique<riegeli::FdSyncIoUring>(options, 0);

EXPECT_EQ(IoUring -> fd_register(), false);
EXPECT_EQ(IoUring -> fd(), -1);
}

TEST(IoUringTest, AsyncUnRegisterFd) {
IoUringPtr IoUring;
riegeli::FdIoUringOptions options;
options.set_async(true);
options.set_fd_register(false);
IoUring = std::make_unique<riegeli::FdAsyncIoUring>(options, 0);

EXPECT_EQ(IoUring -> fd_register(), false);
EXPECT_EQ(IoUring -> fd(), -1);
}

TEST(IoUringTest, SyncRegisterAndUnregisterFd) {
IoUringPtr IoUring;
riegeli::FdIoUringOptions options;
options.set_async(false);
options.set_fd_register(true);
IoUring = std::make_unique<riegeli::FdSyncIoUring>(options, 0);

EXPECT_EQ(IoUring -> fd_register(), true);
EXPECT_EQ(IoUring -> fd(), 0);

IoUring -> UnRegisterFd();
EXPECT_EQ(IoUring -> fd_register(), false);
EXPECT_EQ(IoUring -> fd(), -1);

}

TEST(IoUringTest, AsyncUnRegisterAndUnregisterFd) {
IoUringPtr IoUring;
riegeli::FdIoUringOptions options;
options.set_async(true);
options.set_fd_register(true);
IoUring = std::make_unique<riegeli::FdAsyncIoUring>(options, 0);

EXPECT_EQ(IoUring -> fd_register(), true);
EXPECT_EQ(IoUring -> fd(), 0);

IoUring -> UnRegisterFd();
EXPECT_EQ(IoUring -> fd_register(), false);
EXPECT_EQ(IoUring -> fd(), -1);
}

TEST(IoUringTest, SyncRegisterAndUpdateFd) {
IoUringPtr IoUring;
riegeli::FdIoUringOptions options;
options.set_async(false);
options.set_fd_register(true);
IoUring = std::make_unique<riegeli::FdSyncIoUring>(options, 0);

EXPECT_EQ(IoUring -> fd_register(), true);
EXPECT_EQ(IoUring -> fd(), 0);

std::string path = std::string(getenv("TEST_TMPDIR")) + "/io_uring_test_file";
int fd = open(path.c_str(), O_WRONLY | O_CREAT | O_TRUNC);
IoUring -> RegisterFd(fd);
EXPECT_EQ(IoUring -> fd_register(), true);
EXPECT_EQ(IoUring -> fd(), fd);

}

TEST(IoUringTest, AsyncUnRegisterAndUpdateFd) {
IoUringPtr IoUring;
riegeli::FdIoUringOptions options;
options.set_async(true);
options.set_fd_register(true);
IoUring = std::make_unique<riegeli::FdAsyncIoUring>(options, 0);

EXPECT_EQ(IoUring -> fd_register(), true);
EXPECT_EQ(IoUring -> fd(), 0);

std::string path = std::string(getenv("TEST_TMPDIR")) + "/io_uring_test_file";
int fd = open(path.c_str(), O_WRONLY | O_CREAT | O_TRUNC);
IoUring -> RegisterFd(fd);
EXPECT_EQ(IoUring -> fd_register(), true);
EXPECT_EQ(IoUring -> fd(), fd);
}

TEST(IoUringTest, SyncDefaultSize) {
IoUringPtr IoUring;
riegeli::FdIoUringOptions options;
options.set_async(false);
IoUring = std::make_unique<riegeli::FdSyncIoUring>(options, 0);

EXPECT_EQ(IoUring -> size(), 512);
}

TEST(IoUringTest, AsyncDefaultSize) {
IoUringPtr IoUring;
riegeli::FdIoUringOptions options;
options.set_async(true);
IoUring = std::make_unique<riegeli::FdAsyncIoUring>(options, 0);

EXPECT_EQ(IoUring -> size(), 512);
}

TEST(IoUringTest, SyncSize) {
IoUringPtr IoUring;
riegeli::FdIoUringOptions options;
options.set_async(false);
options.set_size(10);
IoUring = std::make_unique<riegeli::FdSyncIoUring>(options, 0);

EXPECT_EQ(IoUring -> size(), 16);
}

TEST(IoUringTest, AsyncSize) {
IoUringPtr IoUring;
riegeli::FdIoUringOptions options;
options.set_async(true);
options.set_size(10);
IoUring = std::make_unique<riegeli::FdAsyncIoUring>(options, 0);

EXPECT_EQ(IoUring -> size(), 16);
}

TEST(IoUringTest, SyncMaxSize) {
IoUringPtr IoUring;
riegeli::FdIoUringOptions options;
options.set_async(false);
options.set_size(4098);
IoUring = std::make_unique<riegeli::FdSyncIoUring>(options, 0);

EXPECT_EQ(IoUring -> size(), 4096);
}

TEST(IoUringTest, AsyncMaxSize) {
IoUringPtr IoUring;
riegeli::FdIoUringOptions options;
options.set_async(true);
options.set_size(4098);
IoUring = std::make_unique<riegeli::FdAsyncIoUring>(options, 0);

EXPECT_EQ(IoUring -> size(), 4096);
}

}
Loading