diff --git a/fuzztest/internal/fixture_driver.h b/fuzztest/internal/fixture_driver.h index 164aa3f4..61a1abc6 100644 --- a/fuzztest/internal/fixture_driver.h +++ b/fuzztest/internal/fixture_driver.h @@ -52,6 +52,17 @@ class FixtureWithExplicitSetUp { static void TearDownTestSuite() {} }; +class FixtureWithReentrantSetUp { + public: + virtual ~FixtureWithReentrantSetUp() = default; + + virtual void SetUp() = 0; + virtual void TearDown() = 0; + + static void SetUpTestSuite() {} + static void TearDownTestSuite() {} +}; + // Marker interfaces for specifying the fixture's instantiation semantics: // // - Per-iteration semantics: The fixture object is instantiated and discarded diff --git a/fuzztest/internal/registry.h b/fuzztest/internal/registry.h index a9d201e3..c464de12 100644 --- a/fuzztest/internal/registry.h +++ b/fuzztest/internal/registry.h @@ -34,6 +34,41 @@ namespace fuzztest { namespace internal { +template +class FuzzTestFuzzerProvider; + +#if defined(FUZZTEST_COMPATIBILITY_MODE) && defined(FUZZTEST_USE_CENTIPEDE) +#error FuzzTest compatibility mode cannot work together with Centipede. +#endif +#if defined(FUZZTEST_COMPATIBILITY_MODE) +template +class FuzzTestFuzzerProvider< + Fixture, std::enable_if_t>>> + : public FuzzTestExternalEngineAdaptor { + public: + using FuzzTestExternalEngineAdaptor::FuzzTestExternalEngineAdaptor; +}; +#elif defined(FUZZTEST_USE_CENTIPEDE) +template +class FuzzTestFuzzerProvider< + Fixture, std::enable_if_t>>> + : public CentipedeFuzzerAdaptor { + public: + using CentipedeFuzzerAdaptor::CentipedeFuzzerAdaptor; +}; +#else +template +class FuzzTestFuzzerProvider< + Fixture, std::enable_if_t>>> + : public FuzzTestFuzzerImpl { + public: + using FuzzTestFuzzerImpl::FuzzTestFuzzerImpl; +}; +#endif + void RegisterImpl(BasicTestInfo test_info, FuzzTestFuzzerFactory factory); void ForEachTest(absl::FunctionRef func); @@ -70,16 +105,7 @@ struct RegistrationToken { typename SeedProvider> static FuzzTestFuzzerFactory GetFuzzTestFuzzerFactory( Registration&& reg) { -#if defined(FUZZTEST_COMPATIBILITY_MODE) && defined(FUZZTEST_USE_CENTIPEDE) -#error FuzzTest compatibility mode cannot work together with Centipede. -#endif -#if defined(FUZZTEST_COMPATIBILITY_MODE) - using FuzzerImpl = FuzzTestExternalEngineAdaptor; -#elif defined(FUZZTEST_USE_CENTIPEDE) - using FuzzerImpl = CentipedeFuzzerAdaptor; -#else - using FuzzerImpl = FuzzTestFuzzerImpl; -#endif + using FuzzerImpl = FuzzTestFuzzerProvider; return [target_function = reg.target_function_, domain = reg.GetDomains(), seeds = reg.seeds(), seed_provider = reg.seed_provider()](