#include "coco/IR/Op.h"
#include "coco/IR/ObjectManager.h"
+#include <vector>
+#include <memory>
+
#include <gtest/gtest.h>
-TEST(IR_OP_CONV2D, ctor)
+namespace
{
+class Conv2DTest : public ::testing::Test
+{
+protected:
+ coco::Conv2D *allocate(const coco::Conv2D::Param ¶m)
+ {
+ auto op = new coco::Conv2D{&op_link, param};
+ _allocated.emplace_back(op);
+ return op;
+ }
+
+protected:
const coco::PtrLink<coco::Op, coco::Instr> op_link;
- const coco::Conv2D::Param param{};
- const coco::Conv2D op{&op_link, param};
+
+private:
+ std::vector<std::unique_ptr<coco::Conv2D>> _allocated;
+};
+} // namespace
+
+TEST_F(Conv2DTest, ctor)
+{
+ auto op = allocate(coco::Conv2D::Param{});
// ker() should be initialized as nullptr on construction
- ASSERT_EQ(op.ker(), nullptr);
+ ASSERT_EQ(op->ker(), nullptr);
// uses() should be empty on construction
- ASSERT_EQ(op.uses().size(), 0);
+ ASSERT_EQ(op->uses().size(), 0);
// parent() should be nullptr on construction
- ASSERT_EQ(op.parent(), nullptr);
+ ASSERT_EQ(op->parent(), nullptr);
}
-TEST(IR_OP_CONV2D, asConv2D)
+TEST_F(Conv2DTest, asConv2D)
{
- const coco::PtrLink<coco::Op, coco::Instr> op_link;
- coco::Conv2D op{&op_link, coco::Conv2D::Param{}};
+ auto op = allocate(coco::Conv2D::Param{});
- coco::Op *mutable_base = &op;
- const coco::Op *immutable_base = &op;
+ coco::Op *mutable_base = op;
+ const coco::Op *immutable_base = op;
- ASSERT_EQ(mutable_base->asConv2D(), &op);
+ ASSERT_EQ(mutable_base->asConv2D(), op);
ASSERT_EQ(mutable_base->asConv2D(), immutable_base->asConv2D());
}
};
} // namespace
-TEST(IR_OP_CONV2D, ker_update)
+TEST_F(Conv2DTest, ker_update)
{
// Prepare a kernel object for testing
coco::PtrLink<coco::Bag, coco::BagInfo> bag_link;
auto obj = obj_mgr.create(nncc::core::ADT::kernel::Shape{1, 1, 3, 3});
// Test 'Conv2D' class
- const coco::PtrLink<coco::Op, coco::Instr> op_link;
- const coco::Conv2D::Param param{};
- coco::Conv2D op{&op_link, param};
+ auto op = allocate(coco::Conv2D::Param{});
- op.ker(obj);
- ASSERT_EQ(op.ker(), obj);
+ op->ker(obj);
+ ASSERT_EQ(op->ker(), obj);
// Op now uses 'obj'
{
- auto uses = op.uses();
+ auto uses = op->uses();
ASSERT_NE(uses.find(obj), uses.end());
}
}
-TEST(IR_OP_CONV2D, accept)
+TEST_F(Conv2DTest, accept)
{
// Test 'Conv2D' class
- const coco::PtrLink<coco::Op, coco::Instr> op_link;
- const coco::Conv2D::Param param{};
- coco::Conv2D op{&op_link, param};
+ auto op = allocate(coco::Conv2D::Param{});
- coco::Conv2D *mutable_ptr = &op;
- const coco::Conv2D *immutable_ptr = &op;
+ coco::Conv2D *mutable_ptr = op;
+ const coco::Conv2D *immutable_ptr = op;
ASSERT_TRUE(mutable_ptr->accept(IsConv2D{}));
ASSERT_TRUE(immutable_ptr->accept(IsConv2D{}));