// Copyright © Advanced Micro Devices, Inc., or its affiliates. // SPDX-License-Identifier: MIT #include #include #include #include #include #include #include #include "TestHelpers.hpp" #include "engines/ExampleProviderEngine.hpp" using namespace example_provider; using namespace example_provider::test_helpers; /// Mock PlanBuilder with controllable isApplicable() return value. class MockPlanBuilder : public hipdnn_plugin_sdk::IPlanBuilder { public: explicit MockPlanBuilder(bool applicable) : _applicable(applicable) { } bool isApplicable( const ExampleProviderHandle& /*handle*/, const hipdnn_flatbuffers_sdk::flatbuffer_utilities::IGraph& /*opGraph*/) const override { return _applicable; } size_t getMaxWorkspaceSize(const ExampleProviderHandle& /*handle*/, const hipdnn_flatbuffers_sdk::flatbuffer_utilities::IGraph& /*opGraph*/, const ExampleProviderSettings& /*executionSettings*/) const override { return 0; } void initializeExecutionSettings( const ExampleProviderHandle& /*handle*/, const hipdnn_flatbuffers_sdk::flatbuffer_utilities::IGraph& /*opGraph*/, const hipdnn_flatbuffers_sdk::flatbuffer_utilities::IEngineConfig& /*engineConfig*/, ExampleProviderSettings& /*executionSettings*/) const override { } void buildPlan(const ExampleProviderHandle& /*handle*/, const hipdnn_flatbuffers_sdk::flatbuffer_utilities::IGraph& /*opGraph*/, [[maybe_unused]] const hipdnn_flatbuffers_sdk::flatbuffer_utilities:: IEngineConfig& /*engineConfig*/, ExampleProviderContext& /*executionContext*/) const override { } std::vector getCustomKnobs( const ExampleProviderHandle& /*handle*/, const hipdnn_flatbuffers_sdk::flatbuffer_utilities::IGraph& /*opGraph*/) const override { return {}; } private: bool _applicable; }; class ExampleProviderEngineTest : public ::testing::Test { protected: ExampleProviderHandle _handle; }; TEST_F(ExampleProviderEngineTest, IsApplicable_WithMatchingBuilder_ReturnsTrue) { ExampleProviderEngine engine(1); engine.addPlanBuilder(std::make_unique(true)); auto fbb = createReluFwdGraph(); const hipdnn_flatbuffers_sdk::flatbuffer_utilities::GraphWrapper graph(fbb.GetBufferPointer(), fbb.GetSize()); ASSERT_TRUE(graph.isValid()); EXPECT_TRUE(engine.isApplicable(_handle, graph)); } TEST_F(ExampleProviderEngineTest, IsApplicable_WithNoMatchingBuilder_ReturnsFalse) { ExampleProviderEngine engine(1); engine.addPlanBuilder(std::make_unique(false)); auto fbb = createReluFwdGraph(); const hipdnn_flatbuffers_sdk::flatbuffer_utilities::GraphWrapper graph(fbb.GetBufferPointer(), fbb.GetSize()); ASSERT_TRUE(graph.isValid()); EXPECT_FALSE(engine.isApplicable(_handle, graph)); }