Skip to content

Commit

Permalink
Create test targets for different queue implementations (uring, sdeve…
Browse files Browse the repository at this point in the history
…nt, priority_ordered)
  • Loading branch information
Oipo committed Oct 15, 2024
1 parent da92e78 commit f02cafc
Show file tree
Hide file tree
Showing 5 changed files with 417 additions and 31 deletions.
84 changes: 72 additions & 12 deletions test/AsyncFileIOTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include <ichor/event_queues/IOUringQueue.h>
#include <ichor/services/io/IOUringAsyncFileIO.h>
#include <ichor/stl/LinuxUtils.h>
#include <catch2/generators/catch_generators.hpp>

#define IOIMPL IOUringAsyncFileIO
#define QIMPL IOUringQueue
Expand Down Expand Up @@ -41,20 +42,35 @@ struct AsyncFileIOExpensiveSetup {
};

#ifdef TEST_URING
tl::optional<Version> emulateKernelVersion;

TEST_CASE_METHOD(AsyncFileIOExpensiveSetup, "AsyncFileIOTests_uring") {
auto version = Ichor::kernelVersion();

REQUIRE(version);
if(version < Version{5, 18, 0}) {
return;
}

auto gen_i = GENERATE(1, 2);

if(gen_i == 2) {
emulateKernelVersion = Version{5, 18, 0};
fmt::println("emulating kernel version {}", *emulateKernelVersion);
} else {
fmt::println("kernel version {}", *version);
}
#else
TEST_CASE_METHOD(AsyncFileIOExpensiveSetup, "AsyncFileIOTests") {
#endif

SECTION("Reading non-existent file should error") {
fmt::print("section 1\n");
auto queue = std::make_unique<QIMPL>();
#if defined(TEST_URING)
auto queue = std::make_unique<QIMPL>(500, 100'000'000, emulateKernelVersion);
#else
auto queue = std::make_unique<QIMPL>(500);
#endif
auto &dm = queue->createManager();
uint64_t ioSvcId{};

Expand Down Expand Up @@ -99,7 +115,11 @@ TEST_CASE_METHOD(AsyncFileIOExpensiveSetup, "AsyncFileIOTests") {

SECTION("Reading file without permissions should error") {
fmt::print("section 1\n");
auto queue = std::make_unique<QIMPL>();
#if defined(TEST_URING)
auto queue = std::make_unique<QIMPL>(500, 100'000'000, emulateKernelVersion);
#else
auto queue = std::make_unique<QIMPL>(500);
#endif
auto &dm = queue->createManager();
uint64_t ioSvcId{};

Expand Down Expand Up @@ -158,7 +178,11 @@ TEST_CASE_METHOD(AsyncFileIOExpensiveSetup, "AsyncFileIOTests") {

SECTION("Read whole file Small") {
fmt::print("section 2a\n");
auto queue = std::make_unique<QIMPL>();
#if defined(TEST_URING)
auto queue = std::make_unique<QIMPL>(500, 100'000'000, emulateKernelVersion);
#else
auto queue = std::make_unique<QIMPL>(500);
#endif
auto &dm = queue->createManager();
uint64_t ioSvcId{};

Expand Down Expand Up @@ -202,7 +226,11 @@ TEST_CASE_METHOD(AsyncFileIOExpensiveSetup, "AsyncFileIOTests") {
}
SECTION("Read whole file large") {
fmt::println("section 2b");
auto queue = std::make_unique<QIMPL>();
#if defined(TEST_URING)
auto queue = std::make_unique<QIMPL>(500, 100'000'000, emulateKernelVersion);
#else
auto queue = std::make_unique<QIMPL>(500);
#endif
auto &dm = queue->createManager();
uint64_t ioSvcId{};

Expand Down Expand Up @@ -246,7 +274,11 @@ TEST_CASE_METHOD(AsyncFileIOExpensiveSetup, "AsyncFileIOTests") {

SECTION("Copying non-existent file should error") {
fmt::print("section 3\n");
auto queue = std::make_unique<QIMPL>();
#if defined(TEST_URING)
auto queue = std::make_unique<QIMPL>(500, 100'000'000, emulateKernelVersion);
#else
auto queue = std::make_unique<QIMPL>(500);
#endif
auto &dm = queue->createManager();
uint64_t ioSvcId{};

Expand Down Expand Up @@ -286,7 +318,11 @@ TEST_CASE_METHOD(AsyncFileIOExpensiveSetup, "AsyncFileIOTests") {

SECTION("Copying file") {
fmt::print("section 4\n");
auto queue = std::make_unique<QIMPL>();
#if defined(TEST_URING)
auto queue = std::make_unique<QIMPL>(500, 100'000'000, emulateKernelVersion);
#else
auto queue = std::make_unique<QIMPL>(500);
#endif
auto &dm = queue->createManager();
uint64_t ioSvcId{};

Expand Down Expand Up @@ -337,7 +373,11 @@ TEST_CASE_METHOD(AsyncFileIOExpensiveSetup, "AsyncFileIOTests") {

SECTION("Copying large file") {
fmt::print("section 5\n");
auto queue = std::make_unique<QIMPL>();
#if defined(TEST_URING)
auto queue = std::make_unique<QIMPL>(500, 100'000'000, emulateKernelVersion);
#else
auto queue = std::make_unique<QIMPL>(500);
#endif
auto &dm = queue->createManager();
uint64_t ioSvcId{};

Expand Down Expand Up @@ -383,7 +423,11 @@ TEST_CASE_METHOD(AsyncFileIOExpensiveSetup, "AsyncFileIOTests") {

SECTION("Removing non-existing file should error") {
fmt::print("section 6\n");
auto queue = std::make_unique<QIMPL>();
#if defined(TEST_URING)
auto queue = std::make_unique<QIMPL>(500, 100'000'000, emulateKernelVersion);
#else
auto queue = std::make_unique<QIMPL>(500);
#endif
auto &dm = queue->createManager();
uint64_t ioSvcId{};

Expand Down Expand Up @@ -422,7 +466,11 @@ TEST_CASE_METHOD(AsyncFileIOExpensiveSetup, "AsyncFileIOTests") {

SECTION("Removing file") {
fmt::print("section 7\n");
auto queue = std::make_unique<QIMPL>();
#if defined(TEST_URING)
auto queue = std::make_unique<QIMPL>(500, 100'000'000, emulateKernelVersion);
#else
auto queue = std::make_unique<QIMPL>(500);
#endif
auto &dm = queue->createManager();
uint64_t ioSvcId{};

Expand Down Expand Up @@ -472,7 +520,11 @@ TEST_CASE_METHOD(AsyncFileIOExpensiveSetup, "AsyncFileIOTests") {

SECTION("Writing file") {
fmt::print("section 8\n");
auto queue = std::make_unique<QIMPL>();
#if defined(TEST_URING)
auto queue = std::make_unique<QIMPL>(500, 100'000'000, emulateKernelVersion);
#else
auto queue = std::make_unique<QIMPL>(500);
#endif
auto &dm = queue->createManager();
uint64_t ioSvcId{};

Expand Down Expand Up @@ -520,7 +572,11 @@ TEST_CASE_METHOD(AsyncFileIOExpensiveSetup, "AsyncFileIOTests") {

SECTION("Writing file - overwrite") {
fmt::print("section 9\n");
auto queue = std::make_unique<QIMPL>();
#if defined(TEST_URING)
auto queue = std::make_unique<QIMPL>(500, 100'000'000, emulateKernelVersion);
#else
auto queue = std::make_unique<QIMPL>(500);
#endif
auto &dm = queue->createManager();
uint64_t ioSvcId{};

Expand Down Expand Up @@ -572,7 +628,11 @@ TEST_CASE_METHOD(AsyncFileIOExpensiveSetup, "AsyncFileIOTests") {

SECTION("Appending file") {
fmt::print("section 10\n");
auto queue = std::make_unique<QIMPL>();
#if defined(TEST_URING)
auto queue = std::make_unique<QIMPL>(500, 100'000'000, emulateKernelVersion);
#else
auto queue = std::make_unique<QIMPL>(500);
#endif
auto &dm = queue->createManager();
uint64_t ioSvcId{};

Expand Down
6 changes: 3 additions & 3 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ foreach(filename ${PROJECT_TEST_SOURCES})
target_compile_definitions(${testname} PUBLIC ICHOR_SKIP_EXTERNAL_TESTS)
endif()
if(ICHOR_USE_LIBURING AND NOT (ICHOR_SKIP_EXTERNAL_TESTS AND ICHOR_AARCH64))
if(${testname} STREQUAL "TcpTests" OR ${testname} STREQUAL "AsyncFileIOTests" OR ${testname} STREQUAL "ServicesTests")
if(${testname} STREQUAL "TcpTests" OR ${testname} STREQUAL "AsyncFileIOTests" OR ${testname} STREQUAL "ServicesTests" OR ${testname} STREQUAL "CoroutineTests")
add_executable(${testname}_uring ${filename})
target_link_libraries(${testname}_uring ${CMAKE_THREAD_LIBS_INIT})
target_link_libraries(${testname}_uring ichor)
Expand All @@ -39,7 +39,7 @@ foreach(filename ${PROJECT_TEST_SOURCES})
endif()
endif()
if(ICHOR_USE_SDEVENT AND NOT (ICHOR_SKIP_EXTERNAL_TESTS AND ICHOR_AARCH64))
if(${testname} STREQUAL "ServicesTests")
if(${testname} STREQUAL "ServicesTests" OR ${testname} STREQUAL "CoroutineTests")
add_executable(${testname}_sdevent ${filename})
target_link_libraries(${testname}_sdevent ${CMAKE_THREAD_LIBS_INIT})
target_link_libraries(${testname}_sdevent ichor)
Expand All @@ -48,7 +48,7 @@ foreach(filename ${PROJECT_TEST_SOURCES})
catch_discover_tests(${testname}_sdevent)
endif()
endif()
if(${testname} STREQUAL "ServicesTests")
if(${testname} STREQUAL "ServicesTests" OR ${testname} STREQUAL "CoroutineTests")
add_executable(${testname}_ordered ${filename})
target_link_libraries(${testname}_ordered ${CMAKE_THREAD_LIBS_INIT})
target_link_libraries(${testname}_ordered ichor)
Expand Down
Loading

0 comments on commit f02cafc

Please sign in to comment.