EXPECT_EQ (hwmem->getData (), nullptr);
EXPECT_NE (hwmem->dealloc (), 0);
+ hwmem->setSize (size);
+ EXPECT_NE (hwmem->dealloc (), 0);
+ hwmem->setSize (0);
+
+ delete hwmem;
+}
+
+/**
+ * @brief check alloc() method, HWmemDevice, with error handling
+ */
+TEST (ne_core_hwmem_test, hwmem_device_alloc_n)
+{
+ INIT_TEST_DRIVER_API();
+
+ HWmem * hwmem = new HWmem (new HWmemDevice);
+ size_t size = 0x1000;
+
hwmem->setDriverAPI (api.get());
/** size zero is ignored */
EXPECT_EQ (hwmem->getData (), nullptr);
EXPECT_NE (hwmem->dealloc (), 0);
+ /** already allocated */
+ EXPECT_EQ (hwmem->alloc (size), 0);
+ EXPECT_NE (hwmem->alloc (size), 0);
+ EXPECT_EQ (hwmem->dealloc (), 0);
+
+ /** too large size */
+ size = UINT32_MAX;
+ EXPECT_NE (hwmem->alloc (size + 1), 0);
+ EXPECT_EQ (hwmem->getSize (), (size_t) 0);
+
+ delete hwmem;
+}
+
+/**
+ * @brief check dealloc() method, HWmemDevice, with error handling
+ */
+TEST (ne_core_hwmem_test, hwmem_device_dealloc_n)
+{
+ INIT_TEST_DRIVER_API();
+
+ HWmem * hwmem = new HWmem (new HWmemDevice);
+ size_t size = 0x1000;
+
+ hwmem->setDriverAPI (api.get());
+ hwmem->setSize (size);
+
+ /** without allocation */
+ EXPECT_NE (hwmem->dealloc (), 0);
+
+ delete hwmem;
+}
+
+/**
+ * @brief check getData() method, HWmemDevice, with error handling
+ */
+TEST (ne_core_hwmem_test, hwmem_device_get_data_n)
+{
+ INIT_TEST_DRIVER_API();
+
+ HWmem * hwmem = new HWmem (new HWmemDevice);
+ size_t size = 0x1000;
+ int dmabuf = 0x1234;
+
+ hwmem->setDriverAPI (api.get());
+ hwmem->setSize (size);
+ hwmem->setDmabuf (dmabuf);
+
+ /** without allocation */
+ EXPECT_EQ (hwmem->getData (), nullptr);
+
delete hwmem;
}
EXPECT_NE (chunk->getData (), nullptr);
EXPECT_EQ (chunk->getData (), parent->getData () + chunk->getOffset ());
+ EXPECT_EQ (chunk->dealloc (), 0);
+
delete chunk;
delete parent;
}
EXPECT_EQ (chunk->getData (), nullptr);
EXPECT_NE (chunk->dealloc (), 0);
+ chunk->setSize (size);
+ EXPECT_NE (chunk->dealloc (), 0);
+ chunk->setSize (0);
+
/** access chunk with parent, but not api set */
HWmem * parent;
EXPECT_EQ (chunk->getData (), nullptr);
EXPECT_NE (chunk->dealloc (), 0);
+ chunk->setSize (size);
+ EXPECT_NE (chunk->dealloc (), 0);
+ chunk->setSize (0);
+
/** access chunk with parent, but not allocated */
parent->setDriverAPI (api.get());
EXPECT_EQ (chunk->getData (), nullptr);
EXPECT_NE (chunk->dealloc (), 0);
+ chunk->setSize (size);
+ EXPECT_NE (chunk->dealloc (), 0);
+ chunk->setSize (0);
+
/** access chunk with valid parent, but invalid offset/size */
parent->alloc (size);
- chunk->setOffset (size * 2);
- EXPECT_NE (chunk->alloc (0), 0);
+ chunk->setOffset (size);
EXPECT_NE (chunk->alloc (size / 2), 0);
+ chunk->setOffset (size / 2);
+ EXPECT_NE (chunk->alloc (size / 2 + 1), 0);
+
delete chunk;
delete parent;
}
*/
TEST (ne_core_hwmem_test, hwmem_external)
{
+ INIT_TEST_DRIVER_API();
+
+ size_t size = 0x1000;
+ HWmem * hwmem;
+
+ hwmem = new HWmem (new HWmemDevice);
+ hwmem->setDriverAPI (api.get());
+ ASSERT_EQ (hwmem->alloc (size), 0);
+
+ char * buf = hwmem->getData ();
+ for (size_t i = 0; i < size; i++)
+ buf[i] = i % INT8_MAX;
+
+ HWmem * external;
+
+ external = new HWmem (new HWmemExternal);
+ external->setDriverAPI (api.get());
+ external->setSize (hwmem->getSize ());
+ external->setDmabuf (hwmem->getDmabuf ());
+
+ buf = external->getData ();
+ EXPECT_NE (external->getData (), nullptr);
+ for (size_t i = 0; i < size; i++)
+ EXPECT_EQ (buf[i], (char) (i % INT8_MAX));
+
+ delete hwmem;
+ delete external;
+}
+
+/**
+ * @brief check impl methods, HWmemExternal, with error handling
+ */
+TEST (ne_core_hwmem_test, hwmem_external_n)
+{
+ INIT_TEST_DRIVER_API();
+
+ size_t size = 0x1000;
+ HWmem * hwmem;
+
+ hwmem = new HWmem (new HWmemDevice);
+ hwmem->setDriverAPI (api.get());
+ ASSERT_EQ (hwmem->alloc (size), 0);
+
+ HWmem * external;
+
+ external = new HWmem (new HWmemExternal);
+
+ EXPECT_NE (hwmem->getData (), external->getData ());
+
+ external->setDriverAPI (api.get());
+ EXPECT_NE (hwmem->getData (), external->getData ());
+
+ external->setSize (hwmem->getSize ());
+ external->setDmabuf (-1);
+ EXPECT_NE (hwmem->getData (), external->getData ());
+
+ external->setSize (0);
+ external->setDmabuf (hwmem->getDmabuf ());
+ EXPECT_NE (hwmem->getData (), external->getData ());
+
+ external->setSize (hwmem->getSize ());
+ external->setDmabuf (0x1234);
+ EXPECT_NE (hwmem->getData (), external->getData ());
+
+ delete hwmem;
+ delete external;
+}
+
+/**
+ * @brief check impl methods, HWmemExternal with cgem
+ */
+TEST (ne_core_hwmem_test, hwmem_external_cgem)
+{
/** @todo Need a mechanism that automatically find the node of cgem */
const char cgem_dev_node[] = "/dev/card0";
const size_t size = 0x1000;
}
/**
- * @brief a negative test case of HWmemExternal impl methods
+ * @brief a negative test case of HWmemExternal impl methods with cgem
*/
-TEST (ne_core_hwmem_test, hwmem_external_n)
+TEST (ne_core_hwmem_test, hwmem_external_cgem_n)
{
/** @todo Need a mechanism that automatically find the node of cgem */
const char cgem_dev_node[] = "/dev/card0";