#include "coco/IR/KernelObject.h"
+#include <vector>
+#include <memory>
+
#include <gtest/gtest.h>
-TEST(IR_KERNEL_OBJECT, ctor_should_set_size)
+using namespace nncc::core::ADT;
+
+namespace
+{
+class KernelObjectTest : public ::testing::Test
{
- coco::PtrLink<coco::Bag, coco::BagInfo> link;
+protected:
+ coco::KernelObject *allocate(const kernel::Shape &shape)
+ {
+ auto o = new coco::KernelObject{&_bag_link, shape};
+ _allocated.emplace_back(o);
+ return o;
+ }
+private:
+ coco::PtrLink<coco::Bag, coco::BagInfo> _bag_link;
+
+private:
+ std::vector<std::unique_ptr<coco::KernelObject>> _allocated;
+};
+} // namespace
+
+TEST_F(KernelObjectTest, constructor)
+{
const nncc::core::ADT::kernel::Shape shape{1, 1, 3, 3};
- const coco::KernelObject o{&link, shape};
+ auto o = allocate(shape);
// TODO Use ASSERT_EQ(o.shape(), shape) (operator== overload is not yet available)
- ASSERT_EQ(o.shape().depth(), shape.depth());
- ASSERT_EQ(o.shape().count(), shape.count());
- ASSERT_EQ(o.shape().height(), shape.height());
- ASSERT_EQ(o.shape().width(), shape.width());
+ ASSERT_EQ(o->shape().depth(), shape.depth());
+ ASSERT_EQ(o->shape().count(), shape.count());
+ ASSERT_EQ(o->shape().height(), shape.height());
+ ASSERT_EQ(o->shape().width(), shape.width());
}
-TEST(IR_KERNEL_OBJECT, asKernel)
+TEST_F(KernelObjectTest, asKernel)
{
- coco::PtrLink<coco::Bag, coco::BagInfo> link;
-
const nncc::core::ADT::kernel::Shape shape{1, 1, 3, 3};
- coco::KernelObject o{&link, shape};
+ auto o = allocate(shape);
- coco::Object *mutable_object = &o;
- const coco::Object *immutable_object = &o;
+ coco::Object *mutable_object = o;
+ const coco::Object *immutable_object = o;
ASSERT_NE(mutable_object->asKernel(), nullptr);
ASSERT_EQ(mutable_object->asKernel(), immutable_object->asKernel());
}
-TEST(IR_KERNEL_OBJECT, at)
+TEST_F(KernelObjectTest, at)
{
- coco::PtrLink<coco::Bag, coco::BagInfo> link;
-
const uint32_t N = 1;
const uint32_t C = 1;
const uint32_t H = 3;
const uint32_t W = 3;
const nncc::core::ADT::kernel::Shape shape{N, C, H, W};
- coco::KernelObject o{&link, shape};
+ auto o = allocate(shape);
- coco::KernelObject *mutable_ptr = &o;
- const coco::KernelObject *immutable_ptr = &o;
+ coco::KernelObject *mutable_ptr = o;
+ const coco::KernelObject *immutable_ptr = o;
for (uint32_t n = 0; n < N; ++n)
{