Commit 616f02b2 authored by Dan Melnic's avatar Dan Melnic Committed by Facebook Github Bot

Skip the EventBase tests if the backend is not available

Summary: Skip the EventBase tests if the backend is not available

Reviewed By: yfeldblum

Differential Revision: D19002064

fbshipit-source-id: a995df02998c80de2f9076ea16a0281b6288d6b5
parent c4ce1953
...@@ -102,8 +102,17 @@ void testOverflow(bool overflow) { ...@@ -102,8 +102,17 @@ void testOverflow(bool overflow) {
static constexpr size_t kEventFdCount = 16; static constexpr size_t kEventFdCount = 16;
auto total = kNumEventFds * kEventFdCount; auto total = kNumEventFds * kEventFdCount;
folly::EventBase evb(std::make_unique<folly::IoUringBackend>( std::unique_ptr<folly::EventBaseBackendBase> backend;
kBackendCapacity, kBackendMaxSubmit));
try {
backend = std::make_unique<folly::IoUringBackend>(
kBackendCapacity, kBackendMaxSubmit);
} catch (const folly::IoUringBackend::NotAvailable&) {
}
SKIP_IF(!backend) << "Backend not available";
folly::EventBase evb(std::move(backend));
std::vector<std::unique_ptr<EventFD>> eventsVec; std::vector<std::unique_ptr<EventFD>> eventsVec;
eventsVec.reserve(kNumEventFds); eventsVec.reserve(kNumEventFds);
...@@ -128,26 +137,27 @@ TEST(IoUringBackend, Overflow) { ...@@ -128,26 +137,27 @@ TEST(IoUringBackend, Overflow) {
testOverflow(true); testOverflow(true);
} }
int main(int argc, char** argv) { namespace folly {
::testing::InitGoogleTest(&argc, argv); namespace test {
folly::init(&argc, &argv); static constexpr size_t kCapacity = 16 * 1024;
static constexpr size_t kMaxSubmit = 128;
bool avail = folly::IoUringBackend::isAvailable(); struct IoUringBackendProvider {
LOG(INFO) << "folly::IoUringBackend::isAvailable() returned " << avail; static std::unique_ptr<folly::EventBaseBackendBase> getBackend() {
if (!avail) { try {
LOG(INFO) return std::make_unique<folly::IoUringBackend>(kCapacity, kMaxSubmit);
<< "Not running tests since IoUringBackend is not available on this kernel version"; } catch (const IoUringBackend::NotAvailable&) {
return 0; return nullptr;
}
} }
};
static constexpr size_t kCapacity = 16 * 1024; INSTANTIATE_TYPED_TEST_CASE_P(
static constexpr size_t kMaxSubmit = 128; EventBaseTest,
folly::test::EventBaseBackendProvider::GetBackendFunc func; EventBaseTest,
func = []() { IoUringBackendProvider);
return std::make_unique<folly::IoUringBackend>(kCapacity, kMaxSubmit); INSTANTIATE_TYPED_TEST_CASE_P(
}; EventBaseTest1,
EventBaseTest1,
folly::test::EventBaseBackendProvider::setGetBackendFunc(std::move(func)); IoUringBackendProvider);
} // namespace test
return RUN_ALL_TESTS(); } // namespace folly
}
...@@ -18,15 +18,20 @@ ...@@ -18,15 +18,20 @@
#include <folly/io/async/test/EventBaseTestLib.h> #include <folly/io/async/test/EventBaseTestLib.h>
#include <folly/portability/GTest.h> #include <folly/portability/GTest.h>
int main(int argc, char** argv) { namespace folly {
::testing::InitGoogleTest(&argc, argv); namespace test {
folly::init(&argc, &argv); struct DefaultBackendProvider {
static std::unique_ptr<folly::EventBaseBackendBase> getBackend() {
folly::test::EventBaseBackendProvider::GetBackendFunc func = []() {
return folly::EventBase::getDefaultBackend(); return folly::EventBase::getDefaultBackend();
}; }
};
folly::test::EventBaseBackendProvider::setGetBackendFunc(std::move(func)); INSTANTIATE_TYPED_TEST_CASE_P(
EventBaseTest,
return RUN_ALL_TESTS(); EventBaseTest,
} DefaultBackendProvider);
INSTANTIATE_TYPED_TEST_CASE_P(
EventBaseTest1,
EventBaseTest1,
DefaultBackendProvider);
} // namespace test
} // namespace folly
This diff is collapsed.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment