/**
* @brief Test for tensor_transform typecast (uint8 > uint32)
*/
-TEST (test_tensor_transform, typecast_1)
-{
- const guint num_buffers = 3;
- const guint array_size = 5;
-
- GstHarness *h;
- GstBuffer *in_buf, *out_buf;
- GstTensorConfig config;
- GstMemory *mem;
- GstMapInfo info;
- guint i, b;
- gsize data_in_size, data_out_size;
-
- h = gst_harness_new ("tensor_transform");
-
- g_object_set (h->element, "mode", GTT_TYPECAST, "option", "uint32", NULL);
- g_object_set (h->element, "acceleration", (gboolean) FALSE, NULL);
-
- /* input tensor info */
- config.info.type = _NNS_UINT8;
- gst_tensor_parse_dimension ("5", config.info.dimension);
- config.rate_n = 0;
- config.rate_d = 1;
-
- gst_harness_set_src_caps (h, gst_tensor_caps_from_config (&config));
- data_in_size = gst_tensor_info_get_size (&config.info);
-
- config.info.type = _NNS_UINT32;
- data_out_size = gst_tensor_info_get_size (&config.info);
-
- /* push buffers */
- for (b = 0; b < num_buffers; b++) {
- /* set input buffer */
- in_buf = gst_harness_create_buffer (h, data_in_size);
-
- mem = gst_buffer_peek_memory (in_buf, 0);
- ASSERT_TRUE (gst_memory_map (mem, &info, GST_MAP_WRITE));
-
- for (i = 0; i < array_size; i++) {
- uint8_t value = (i + 1) * (b + 1);
- ((uint8_t *) info.data)[i] = value;
- }
-
- gst_memory_unmap (mem, &info);
-
- EXPECT_EQ (gst_harness_push (h, in_buf), GST_FLOW_OK);
-
- /* get output buffer */
- out_buf = gst_harness_pull (h);
-
- ASSERT_TRUE (out_buf != NULL);
- ASSERT_EQ (gst_buffer_n_memory (out_buf), 1);
- ASSERT_EQ (gst_buffer_get_size (out_buf), data_out_size);
-
- mem = gst_buffer_peek_memory (out_buf, 0);
- ASSERT_TRUE (gst_memory_map (mem, &info, GST_MAP_READ));
-
- for (i = 0; i < array_size; i++) {
- uint32_t expected = (i + 1) * (b + 1);
- EXPECT_EQ (((uint32_t *) info.data)[i], expected);
- }
-
- gst_memory_unmap (mem, &info);
- gst_buffer_unref (out_buf);
- }
-
- EXPECT_EQ (gst_harness_buffers_received (h), num_buffers);
- gst_harness_teardown (h);
-}
-
-/**
- * @brief Test for tensor_transform typecast (acceleration, uint8 > uint32)
- */
-TEST (test_tensor_transform, typecast_1_accel)
-{
- const guint num_buffers = 3;
- const guint array_size = 5;
-
- GstHarness *h;
- GstBuffer *in_buf, *out_buf;
- GstTensorConfig config;
- GstMemory *mem;
- GstMapInfo info;
- guint i, b;
- gsize data_in_size, data_out_size;
-
- h = gst_harness_new ("tensor_transform");
-
- g_object_set (h->element, "mode", GTT_TYPECAST, "option", "uint32", NULL);
- g_object_set (h->element, "acceleration", (gboolean) TRUE, NULL);
-
- /* input tensor info */
- config.info.type = _NNS_UINT8;
- gst_tensor_parse_dimension ("5", config.info.dimension);
- config.rate_n = 0;
- config.rate_d = 1;
-
- gst_harness_set_src_caps (h, gst_tensor_caps_from_config (&config));
- data_in_size = gst_tensor_info_get_size (&config.info);
-
- config.info.type = _NNS_UINT32;
- data_out_size = gst_tensor_info_get_size (&config.info);
-
- /* push buffers */
- for (b = 0; b < num_buffers; b++) {
- /* set input buffer */
- in_buf = gst_harness_create_buffer (h, data_in_size);
-
- mem = gst_buffer_peek_memory (in_buf, 0);
- ASSERT_TRUE (gst_memory_map (mem, &info, GST_MAP_WRITE));
-
- for (i = 0; i < array_size; i++) {
- uint8_t value = (i + 1) * (b + 1);
- ((uint8_t *) info.data)[i] = value;
- }
-
- gst_memory_unmap (mem, &info);
-
- EXPECT_EQ (gst_harness_push (h, in_buf), GST_FLOW_OK);
-
- /* get output buffer */
- out_buf = gst_harness_pull (h);
-
- ASSERT_TRUE (out_buf != NULL);
- ASSERT_EQ (gst_buffer_n_memory (out_buf), 1);
- ASSERT_EQ (gst_buffer_get_size (out_buf), data_out_size);
-
- mem = gst_buffer_peek_memory (out_buf, 0);
- ASSERT_TRUE (gst_memory_map (mem, &info, GST_MAP_READ));
-
- for (i = 0; i < array_size; i++) {
- uint32_t expected = (i + 1) * (b + 1);
- EXPECT_EQ (((uint32_t *) info.data)[i], expected);
- }
-
- gst_memory_unmap (mem, &info);
- gst_buffer_unref (out_buf);
- }
-
- EXPECT_EQ (gst_harness_buffers_received (h), num_buffers);
- gst_harness_teardown (h);
-}
-
-/**
- * @brief Test for tensor_transform typecast (uint32 > float64)
- */
-TEST (test_tensor_transform, typecast_2)
-{
- const guint num_buffers = 3;
- const guint array_size = 5;
-
- GstHarness *h;
- GstBuffer *in_buf, *out_buf;
- GstTensorConfig config;
- GstMemory *mem;
- GstMapInfo info;
- guint i, b;
- gsize data_in_size, data_out_size;
-
- h = gst_harness_new ("tensor_transform");
-
- g_object_set (h->element, "mode", GTT_TYPECAST, "option", "float64", NULL);
- g_object_set (h->element, "acceleration", (gboolean) FALSE, NULL);
-
- /* input tensor info */
- config.info.type = _NNS_UINT32;
- gst_tensor_parse_dimension ("5", config.info.dimension);
- config.rate_n = 0;
- config.rate_d = 1;
-
- gst_harness_set_src_caps (h, gst_tensor_caps_from_config (&config));
- data_in_size = gst_tensor_info_get_size (&config.info);
-
- config.info.type = _NNS_FLOAT64;
- data_out_size = gst_tensor_info_get_size (&config.info);
-
- /* push buffers */
- for (b = 0; b < num_buffers; b++) {
- /* set input buffer */
- in_buf = gst_harness_create_buffer (h, data_in_size);
-
- mem = gst_buffer_peek_memory (in_buf, 0);
- ASSERT_TRUE (gst_memory_map (mem, &info, GST_MAP_WRITE));
-
- for (i = 0; i < array_size; i++) {
- uint32_t value = (i + 1) * (b + 1);
- ((uint32_t *) info.data)[i] = value;
- }
-
- gst_memory_unmap (mem, &info);
-
- EXPECT_EQ (gst_harness_push (h, in_buf), GST_FLOW_OK);
-
- /* get output buffer */
- out_buf = gst_harness_pull (h);
-
- ASSERT_TRUE (out_buf != NULL);
- ASSERT_EQ (gst_buffer_n_memory (out_buf), 1);
- ASSERT_EQ (gst_buffer_get_size (out_buf), data_out_size);
-
- mem = gst_buffer_peek_memory (out_buf, 0);
- ASSERT_TRUE (gst_memory_map (mem, &info, GST_MAP_READ));
-
- for (i = 0; i < array_size; i++) {
- double expected = (i + 1) * (b + 1);
- EXPECT_DOUBLE_EQ (((double *) info.data)[i], expected);
- }
-
- gst_memory_unmap (mem, &info);
- gst_buffer_unref (out_buf);
- }
-
- EXPECT_EQ (gst_harness_buffers_received (h), num_buffers);
- gst_harness_teardown (h);
-}
-
-/**
- * @brief Test for tensor_transform typecast (acceleration, uint32 > float64)
- */
-TEST (test_tensor_transform, typecast_2_accel)
-{
- const guint num_buffers = 3;
- const guint array_size = 5;
-
- GstHarness *h;
- GstBuffer *in_buf, *out_buf;
- GstTensorConfig config;
- GstMemory *mem;
- GstMapInfo info;
- guint i, b;
- gsize data_in_size, data_out_size;
-
- h = gst_harness_new ("tensor_transform");
-
- g_object_set (h->element, "mode", GTT_TYPECAST, "option", "float64", NULL);
- g_object_set (h->element, "acceleration", (gboolean) TRUE, NULL);
-
- /* input tensor info */
- config.info.type = _NNS_UINT32;
- gst_tensor_parse_dimension ("5", config.info.dimension);
- config.rate_n = 0;
- config.rate_d = 1;
-
- gst_harness_set_src_caps (h, gst_tensor_caps_from_config (&config));
- data_in_size = gst_tensor_info_get_size (&config.info);
-
- config.info.type = _NNS_FLOAT64;
- data_out_size = gst_tensor_info_get_size (&config.info);
-
- /* push buffers */
- for (b = 0; b < num_buffers; b++) {
- /* set input buffer */
- in_buf = gst_harness_create_buffer (h, data_in_size);
-
- mem = gst_buffer_peek_memory (in_buf, 0);
- ASSERT_TRUE (gst_memory_map (mem, &info, GST_MAP_WRITE));
-
- for (i = 0; i < array_size; i++) {
- uint32_t value = (i + 1) * (b + 1);
- ((uint32_t *) info.data)[i] = value;
- }
-
- gst_memory_unmap (mem, &info);
-
- EXPECT_EQ (gst_harness_push (h, in_buf), GST_FLOW_OK);
-
- /* get output buffer */
- out_buf = gst_harness_pull (h);
-
- ASSERT_TRUE (out_buf != NULL);
- ASSERT_EQ (gst_buffer_n_memory (out_buf), 1);
- ASSERT_EQ (gst_buffer_get_size (out_buf), data_out_size);
-
- mem = gst_buffer_peek_memory (out_buf, 0);
- ASSERT_TRUE (gst_memory_map (mem, &info, GST_MAP_READ));
-
- for (i = 0; i < array_size; i++) {
- double expected = (i + 1) * (b + 1);
- EXPECT_DOUBLE_EQ (((double *) info.data)[i], expected);
- }
-
- gst_memory_unmap (mem, &info);
- gst_buffer_unref (out_buf);
- }
-
- EXPECT_EQ (gst_harness_buffers_received (h), num_buffers);
- gst_harness_teardown (h);
-}
-
-/**
- * @brief Test for tensor_transform typecast (int32 > float32)
- */
-TEST (test_tensor_transform, typecast_3)
-{
- const guint num_buffers = 3;
- const guint array_size = 5;
-
- GstHarness *h;
- GstBuffer *in_buf, *out_buf;
- GstTensorConfig config;
- GstMemory *mem;
- GstMapInfo info;
- guint i, b;
- gsize data_in_size, data_out_size;
-
- h = gst_harness_new ("tensor_transform");
-
- g_object_set (h->element, "mode", GTT_TYPECAST, "option", "float32", NULL);
- g_object_set (h->element, "acceleration", (gboolean) FALSE, NULL);
-
- /* input tensor info */
- config.info.type = _NNS_INT32;
- gst_tensor_parse_dimension ("5", config.info.dimension);
- config.rate_n = 0;
- config.rate_d = 1;
-
- gst_harness_set_src_caps (h, gst_tensor_caps_from_config (&config));
- data_in_size = gst_tensor_info_get_size (&config.info);
-
- config.info.type = _NNS_FLOAT32;
- data_out_size = gst_tensor_info_get_size (&config.info);
-
- /* push buffers */
- for (b = 0; b < num_buffers; b++) {
- /* set input buffer */
- in_buf = gst_harness_create_buffer (h, data_in_size);
-
- mem = gst_buffer_peek_memory (in_buf, 0);
- ASSERT_TRUE (gst_memory_map (mem, &info, GST_MAP_WRITE));
-
- for (i = 0; i < array_size; i++) {
- int32_t value = (i + 1) * (b + 1) * (-1);
- ((int32_t *) info.data)[i] = value;
- }
-
- gst_memory_unmap (mem, &info);
-
- EXPECT_EQ (gst_harness_push (h, in_buf), GST_FLOW_OK);
-
- /* get output buffer */
- out_buf = gst_harness_pull (h);
-
- ASSERT_TRUE (out_buf != NULL);
- ASSERT_EQ (gst_buffer_n_memory (out_buf), 1);
- ASSERT_EQ (gst_buffer_get_size (out_buf), data_out_size);
-
- mem = gst_buffer_peek_memory (out_buf, 0);
- ASSERT_TRUE (gst_memory_map (mem, &info, GST_MAP_READ));
-
- for (i = 0; i < array_size; i++) {
- float expected = (i + 1) * (b + 1) * (-1.);
- EXPECT_FLOAT_EQ (((float *) info.data)[i], expected);
- }
-
- gst_memory_unmap (mem, &info);
- gst_buffer_unref (out_buf);
- }
-
- EXPECT_EQ (gst_harness_buffers_received (h), num_buffers);
- gst_harness_teardown (h);
-}
-
-/**
- * @brief Test for tensor_transform typecast (acceleration, int32 > float32)
- */
-TEST (test_tensor_transform, typecast_3_accel)
-{
- const guint num_buffers = 3;
- const guint array_size = 5;
-
- GstHarness *h;
- GstBuffer *in_buf, *out_buf;
- GstTensorConfig config;
- GstMemory *mem;
- GstMapInfo info;
- guint i, b;
- gsize data_in_size, data_out_size;
-
- h = gst_harness_new ("tensor_transform");
-
- g_object_set (h->element, "mode", GTT_TYPECAST, "option", "float32", NULL);
- g_object_set (h->element, "acceleration", (gboolean) TRUE, NULL);
-
- /* input tensor info */
- config.info.type = _NNS_INT32;
- gst_tensor_parse_dimension ("5", config.info.dimension);
- config.rate_n = 0;
- config.rate_d = 1;
-
- gst_harness_set_src_caps (h, gst_tensor_caps_from_config (&config));
- data_in_size = gst_tensor_info_get_size (&config.info);
-
- config.info.type = _NNS_FLOAT32;
- data_out_size = gst_tensor_info_get_size (&config.info);
-
- /* push buffers */
- for (b = 0; b < num_buffers; b++) {
- /* set input buffer */
- in_buf = gst_harness_create_buffer (h, data_in_size);
-
- mem = gst_buffer_peek_memory (in_buf, 0);
- ASSERT_TRUE (gst_memory_map (mem, &info, GST_MAP_WRITE));
-
- for (i = 0; i < array_size; i++) {
- int32_t value = (i + 1) * (b + 1) * (-1);
- ((int32_t *) info.data)[i] = value;
- }
-
- gst_memory_unmap (mem, &info);
-
- EXPECT_EQ (gst_harness_push (h, in_buf), GST_FLOW_OK);
-
- /* get output buffer */
- out_buf = gst_harness_pull (h);
-
- ASSERT_TRUE (out_buf != NULL);
- ASSERT_EQ (gst_buffer_n_memory (out_buf), 1);
- ASSERT_EQ (gst_buffer_get_size (out_buf), data_out_size);
-
- mem = gst_buffer_peek_memory (out_buf, 0);
- ASSERT_TRUE (gst_memory_map (mem, &info, GST_MAP_READ));
-
- for (i = 0; i < array_size; i++) {
- float expected = (i + 1) * (b + 1) * (-1.);
- EXPECT_FLOAT_EQ (((float *) info.data)[i], expected);
- }
-
- gst_memory_unmap (mem, &info);
- gst_buffer_unref (out_buf);
- }
-
- EXPECT_EQ (gst_harness_buffers_received (h), num_buffers);
- gst_harness_teardown (h);
-}
-
-/**
- * @brief Test for tensor_transform typecast (int8 > float32)
- */
-TEST (test_tensor_transform, typecast_4)
-{
- const guint num_buffers = 3;
- const guint array_size = 5;
-
- GstHarness *h;
- GstBuffer *in_buf, *out_buf;
- GstTensorConfig config;
- GstMemory *mem;
- GstMapInfo info;
- guint i, b;
- gsize data_in_size, data_out_size;
-
- h = gst_harness_new ("tensor_transform");
-
- g_object_set (h->element, "mode", GTT_TYPECAST, "option", "float32", NULL);
- g_object_set (h->element, "acceleration", (gboolean) FALSE, NULL);
-
- /* input tensor info */
- config.info.type = _NNS_INT8;
- gst_tensor_parse_dimension ("5", config.info.dimension);
- config.rate_n = 0;
- config.rate_d = 1;
-
- gst_harness_set_src_caps (h, gst_tensor_caps_from_config (&config));
- data_in_size = gst_tensor_info_get_size (&config.info);
-
- config.info.type = _NNS_FLOAT32;
- data_out_size = gst_tensor_info_get_size (&config.info);
-
- /* push buffers */
- for (b = 0; b < num_buffers; b++) {
- /* set input buffer */
- in_buf = gst_harness_create_buffer (h, data_in_size);
-
- mem = gst_buffer_peek_memory (in_buf, 0);
- ASSERT_TRUE (gst_memory_map (mem, &info, GST_MAP_WRITE));
-
- for (i = 0; i < array_size; i++) {
- int8_t value = (i + 1) * (b + 1) * (-1);
- ((int8_t *) info.data)[i] = value;
- }
-
- gst_memory_unmap (mem, &info);
-
- EXPECT_EQ (gst_harness_push (h, in_buf), GST_FLOW_OK);
-
- /* get output buffer */
- out_buf = gst_harness_pull (h);
-
- ASSERT_TRUE (out_buf != NULL);
- ASSERT_EQ (gst_buffer_n_memory (out_buf), 1);
- ASSERT_EQ (gst_buffer_get_size (out_buf), data_out_size);
-
- mem = gst_buffer_peek_memory (out_buf, 0);
- ASSERT_TRUE (gst_memory_map (mem, &info, GST_MAP_READ));
-
- for (i = 0; i < array_size; i++) {
- float expected = (i + 1) * (b + 1) * (-1.);
- EXPECT_FLOAT_EQ (((float *) info.data)[i], expected);
- }
-
- gst_memory_unmap (mem, &info);
- gst_buffer_unref (out_buf);
- }
-
- EXPECT_EQ (gst_harness_buffers_received (h), num_buffers);
- gst_harness_teardown (h);
-}
-
-/**
- * @brief Test for tensor_transform typecast (acceleration, int8 > float32)
- */
-TEST (test_tensor_transform, typecast_4_accel)
-{
- const guint num_buffers = 3;
- const guint array_size = 5;
-
- GstHarness *h;
- GstBuffer *in_buf, *out_buf;
- GstTensorConfig config;
- GstMemory *mem;
- GstMapInfo info;
- guint i, b;
- gsize data_in_size, data_out_size;
-
- h = gst_harness_new ("tensor_transform");
-
- g_object_set (h->element, "mode", GTT_TYPECAST, "option", "float32", NULL);
- g_object_set (h->element, "acceleration", (gboolean) TRUE, NULL);
-
- /* input tensor info */
- config.info.type = _NNS_INT8;
- gst_tensor_parse_dimension ("5", config.info.dimension);
- config.rate_n = 0;
- config.rate_d = 1;
-
- gst_harness_set_src_caps (h, gst_tensor_caps_from_config (&config));
- data_in_size = gst_tensor_info_get_size (&config.info);
-
- config.info.type = _NNS_FLOAT32;
- data_out_size = gst_tensor_info_get_size (&config.info);
-
- /* push buffers */
- for (b = 0; b < num_buffers; b++) {
- /* set input buffer */
- in_buf = gst_harness_create_buffer (h, data_in_size);
-
- mem = gst_buffer_peek_memory (in_buf, 0);
- ASSERT_TRUE (gst_memory_map (mem, &info, GST_MAP_WRITE));
-
- for (i = 0; i < array_size; i++) {
- int8_t value = (i + 1) * (b + 1) * (-1);
- ((int8_t *) info.data)[i] = value;
- }
-
- gst_memory_unmap (mem, &info);
-
- EXPECT_EQ (gst_harness_push (h, in_buf), GST_FLOW_OK);
-
- /* get output buffer */
- out_buf = gst_harness_pull (h);
-
- ASSERT_TRUE (out_buf != NULL);
- ASSERT_EQ (gst_buffer_n_memory (out_buf), 1);
- ASSERT_EQ (gst_buffer_get_size (out_buf), data_out_size);
-
- mem = gst_buffer_peek_memory (out_buf, 0);
- ASSERT_TRUE (gst_memory_map (mem, &info, GST_MAP_READ));
-
- for (i = 0; i < array_size; i++) {
- float expected = (i + 1) * (b + 1) * (-1.);
- EXPECT_FLOAT_EQ (((float *) info.data)[i], expected);
- }
-
- gst_memory_unmap (mem, &info);
- gst_buffer_unref (out_buf);
- }
-
- EXPECT_EQ (gst_harness_buffers_received (h), num_buffers);
- gst_harness_teardown (h);
-}
-
-/**
- * @brief Test for tensor_transform typecast (uint8 > float32)
- */
-TEST (test_tensor_transform, typecast_5)
-{
- const guint num_buffers = 3;
- const guint array_size = 5;
-
- GstHarness *h;
- GstBuffer *in_buf, *out_buf;
- GstTensorConfig config;
- GstMemory *mem;
- GstMapInfo info;
- guint i, b;
- gsize data_in_size, data_out_size;
-
- h = gst_harness_new ("tensor_transform");
-
- g_object_set (h->element, "mode", GTT_TYPECAST, "option", "float32", NULL);
- g_object_set (h->element, "acceleration", (gboolean) FALSE, NULL);
-
- /* input tensor info */
- config.info.type = _NNS_UINT8;
- gst_tensor_parse_dimension ("5", config.info.dimension);
- config.rate_n = 0;
- config.rate_d = 1;
-
- gst_harness_set_src_caps (h, gst_tensor_caps_from_config (&config));
- data_in_size = gst_tensor_info_get_size (&config.info);
-
- config.info.type = _NNS_FLOAT32;
- data_out_size = gst_tensor_info_get_size (&config.info);
-
- /* push buffers */
- for (b = 0; b < num_buffers; b++) {
- /* set input buffer */
- in_buf = gst_harness_create_buffer (h, data_in_size);
-
- mem = gst_buffer_peek_memory (in_buf, 0);
- ASSERT_TRUE (gst_memory_map (mem, &info, GST_MAP_WRITE));
-
- for (i = 0; i < array_size; i++) {
- uint8_t value = (i + 1) * (b + 1);
- ((uint8_t *) info.data)[i] = value;
- }
-
- gst_memory_unmap (mem, &info);
-
- EXPECT_EQ (gst_harness_push (h, in_buf), GST_FLOW_OK);
-
- /* get output buffer */
- out_buf = gst_harness_pull (h);
-
- ASSERT_TRUE (out_buf != NULL);
- ASSERT_EQ (gst_buffer_n_memory (out_buf), 1);
- ASSERT_EQ (gst_buffer_get_size (out_buf), data_out_size);
-
- mem = gst_buffer_peek_memory (out_buf, 0);
- ASSERT_TRUE (gst_memory_map (mem, &info, GST_MAP_READ));
-
- for (i = 0; i < array_size; i++) {
- float expected = (i + 1) * (b + 1);
- EXPECT_FLOAT_EQ (((float *) info.data)[i], expected);
- }
-
- gst_memory_unmap (mem, &info);
- gst_buffer_unref (out_buf);
- }
-
- EXPECT_EQ (gst_harness_buffers_received (h), num_buffers);
- gst_harness_teardown (h);
-}
-
-/**
- * @brief Test for tensor_transform typecast (acceleration, uint8 > float32)
- */
-TEST (test_tensor_transform, typecast_5_accel)
-{
- const guint num_buffers = 3;
- const guint array_size = 5;
-
- GstHarness *h;
- GstBuffer *in_buf, *out_buf;
- GstTensorConfig config;
- GstMemory *mem;
- GstMapInfo info;
- guint i, b;
- gsize data_in_size, data_out_size;
-
- h = gst_harness_new ("tensor_transform");
-
- g_object_set (h->element, "mode", GTT_TYPECAST, "option", "float32", NULL);
- g_object_set (h->element, "acceleration", (gboolean) TRUE, NULL);
-
- /* input tensor info */
- config.info.type = _NNS_UINT8;
- gst_tensor_parse_dimension ("5", config.info.dimension);
- config.rate_n = 0;
- config.rate_d = 1;
-
- gst_harness_set_src_caps (h, gst_tensor_caps_from_config (&config));
- data_in_size = gst_tensor_info_get_size (&config.info);
-
- config.info.type = _NNS_FLOAT32;
- data_out_size = gst_tensor_info_get_size (&config.info);
-
- /* push buffers */
- for (b = 0; b < num_buffers; b++) {
- /* set input buffer */
- in_buf = gst_harness_create_buffer (h, data_in_size);
-
- mem = gst_buffer_peek_memory (in_buf, 0);
- ASSERT_TRUE (gst_memory_map (mem, &info, GST_MAP_WRITE));
-
- for (i = 0; i < array_size; i++) {
- uint8_t value = (i + 1) * (b + 1);
- ((uint8_t *) info.data)[i] = value;
- }
-
- gst_memory_unmap (mem, &info);
-
- EXPECT_EQ (gst_harness_push (h, in_buf), GST_FLOW_OK);
-
- /* get output buffer */
- out_buf = gst_harness_pull (h);
-
- ASSERT_TRUE (out_buf != NULL);
- ASSERT_EQ (gst_buffer_n_memory (out_buf), 1);
- ASSERT_EQ (gst_buffer_get_size (out_buf), data_out_size);
-
- mem = gst_buffer_peek_memory (out_buf, 0);
- ASSERT_TRUE (gst_memory_map (mem, &info, GST_MAP_READ));
-
- for (i = 0; i < array_size; i++) {
- float expected = (i + 1) * (b + 1);
- EXPECT_FLOAT_EQ (((float *) info.data)[i], expected);
- }
-
- gst_memory_unmap (mem, &info);
- gst_buffer_unref (out_buf);
- }
-
- EXPECT_EQ (gst_harness_buffers_received (h), num_buffers);
- gst_harness_teardown (h);
-}
-
-/**
- * @brief Test for tensor_transform typecast (int16 > float32)
- */
-TEST (test_tensor_transform, typecast_6)
-{
- const guint num_buffers = 3;
- const guint array_size = 5;
-
- GstHarness *h;
- GstBuffer *in_buf, *out_buf;
- GstTensorConfig config;
- GstMemory *mem;
- GstMapInfo info;
- guint i, b;
- gsize data_in_size, data_out_size;
-
- h = gst_harness_new ("tensor_transform");
-
- g_object_set (h->element, "mode", GTT_TYPECAST, "option", "float32", NULL);
- g_object_set (h->element, "acceleration", (gboolean) FALSE, NULL);
-
- /* input tensor info */
- config.info.type = _NNS_INT16;
- gst_tensor_parse_dimension ("5", config.info.dimension);
- config.rate_n = 0;
- config.rate_d = 1;
-
- gst_harness_set_src_caps (h, gst_tensor_caps_from_config (&config));
- data_in_size = gst_tensor_info_get_size (&config.info);
-
- config.info.type = _NNS_FLOAT32;
- data_out_size = gst_tensor_info_get_size (&config.info);
-
- /* push buffers */
- for (b = 0; b < num_buffers; b++) {
- /* set input buffer */
- in_buf = gst_harness_create_buffer (h, data_in_size);
+TEST_TRANSFORM_TYPECAST (typecast_1, 3, 5, uint8_t, _NNS_UINT8, uint32_t, "uint32", _NNS_UINT32, FALSE)
- mem = gst_buffer_peek_memory (in_buf, 0);
- ASSERT_TRUE (gst_memory_map (mem, &info, GST_MAP_WRITE));
+/**
+ * @brief Test for tensor_transform typecast (acceleration, uint8 > uint32)
+ */
+TEST_TRANSFORM_TYPECAST (typecast_1_accel, 3, 5, uint8_t, _NNS_UINT8, uint32_t, "uint32", _NNS_UINT32, TRUE)
- for (i = 0; i < array_size; i++) {
- int16_t value = (i + 1) * (b + 1) * (-1);
- ((int16_t *) info.data)[i] = value;
- }
+/**
+ * @brief Test for tensor_transform typecast (uint32 > float64)
+ */
+TEST_TRANSFORM_TYPECAST (typecast_2, 3, 5, uint32_t, _NNS_UINT32, double, "float64", _NNS_FLOAT64, FALSE)
- gst_memory_unmap (mem, &info);
+/**
+ * @brief Test for tensor_transform typecast (acceleration, uint32 > float64)
+ */
+TEST_TRANSFORM_TYPECAST (typecast_2_accel, 3, 5, uint32_t, _NNS_UINT32, double, "float64", _NNS_FLOAT64, TRUE)
- EXPECT_EQ (gst_harness_push (h, in_buf), GST_FLOW_OK);
+/**
+ * @brief Test for tensor_transform typecast (int32 > float32)
+ */
+TEST_TRANSFORM_TYPECAST (typecast_3, 3, 5, int32_t, _NNS_INT32, float, "float32", _NNS_FLOAT32, FALSE)
- /* get output buffer */
- out_buf = gst_harness_pull (h);
+/**
+ * @brief Test for tensor_transform typecast (acceleration, int32 > float32)
+ */
+TEST_TRANSFORM_TYPECAST (typecast_3_accel, 3, 5, int32_t, _NNS_INT32, float, "float32", _NNS_FLOAT32, TRUE)
- ASSERT_TRUE (out_buf != NULL);
- ASSERT_EQ (gst_buffer_n_memory (out_buf), 1);
- ASSERT_EQ (gst_buffer_get_size (out_buf), data_out_size);
+/**
+ * @brief Test for tensor_transform typecast (int8 > float32)
+ */
+TEST_TRANSFORM_TYPECAST (typecast_4, 3, 5, int8_t, _NNS_INT8, float, "float32", _NNS_FLOAT32, FALSE)
- mem = gst_buffer_peek_memory (out_buf, 0);
- ASSERT_TRUE (gst_memory_map (mem, &info, GST_MAP_READ));
+/**
+ * @brief Test for tensor_transform typecast (acceleration, int8 > float32)
+ */
+TEST_TRANSFORM_TYPECAST (typecast_4_accel, 3, 5, int8_t, _NNS_INT8, float, "float32", _NNS_FLOAT32, TRUE)
- for (i = 0; i < array_size; i++) {
- float expected = (i + 1) * (b + 1) * (-1.);
- EXPECT_FLOAT_EQ (((float *) info.data)[i], expected);
- }
+/**
+ * @brief Test for tensor_transform typecast (uint8 > float32)
+ */
+TEST_TRANSFORM_TYPECAST (typecast_5, 3, 5, uint8_t, _NNS_UINT8, float, "float32", _NNS_FLOAT32, FALSE)
- gst_memory_unmap (mem, &info);
- gst_buffer_unref (out_buf);
- }
+/**
+ * @brief Test for tensor_transform typecast (acceleration, uint8 > float32)
+ */
+TEST_TRANSFORM_TYPECAST (typecast_5_accel, 3, 5, uint8_t, _NNS_UINT8, float, "float32", _NNS_FLOAT32, TRUE)
- EXPECT_EQ (gst_harness_buffers_received (h), num_buffers);
- gst_harness_teardown (h);
-}
+/**
+ * @brief Test for tensor_transform typecast (int16 > float32)
+ */
+TEST_TRANSFORM_TYPECAST (typecast_6, 3, 5, int16_t, _NNS_INT16, float, "float32", _NNS_FLOAT32, FALSE)
/**
* @brief Test for tensor_transform typecast (acceleration, int16 > float32)
*/
-TEST (test_tensor_transform, typecast_6_accel)
-{
- const guint num_buffers = 3;
- const guint array_size = 5;
-
- GstHarness *h;
- GstBuffer *in_buf, *out_buf;
- GstTensorConfig config;
- GstMemory *mem;
- GstMapInfo info;
- guint i, b;
- gsize data_in_size, data_out_size;
-
- h = gst_harness_new ("tensor_transform");
-
- g_object_set (h->element, "mode", GTT_TYPECAST, "option", "float32", NULL);
- g_object_set (h->element, "acceleration", (gboolean) TRUE, NULL);
-
- /* input tensor info */
- config.info.type = _NNS_INT16;
- gst_tensor_parse_dimension ("5", config.info.dimension);
- config.rate_n = 0;
- config.rate_d = 1;
-
- gst_harness_set_src_caps (h, gst_tensor_caps_from_config (&config));
- data_in_size = gst_tensor_info_get_size (&config.info);
-
- config.info.type = _NNS_FLOAT32;
- data_out_size = gst_tensor_info_get_size (&config.info);
-
- /* push buffers */
- for (b = 0; b < num_buffers; b++) {
- /* set input buffer */
- in_buf = gst_harness_create_buffer (h, data_in_size);
-
- mem = gst_buffer_peek_memory (in_buf, 0);
- ASSERT_TRUE (gst_memory_map (mem, &info, GST_MAP_WRITE));
-
- for (i = 0; i < array_size; i++) {
- int16_t value = (i + 1) * (b + 1) * (-1);
- ((int16_t *) info.data)[i] = value;
- }
-
- gst_memory_unmap (mem, &info);
-
- EXPECT_EQ (gst_harness_push (h, in_buf), GST_FLOW_OK);
-
- /* get output buffer */
- out_buf = gst_harness_pull (h);
-
- ASSERT_TRUE (out_buf != NULL);
- ASSERT_EQ (gst_buffer_n_memory (out_buf), 1);
- ASSERT_EQ (gst_buffer_get_size (out_buf), data_out_size);
-
- mem = gst_buffer_peek_memory (out_buf, 0);
- ASSERT_TRUE (gst_memory_map (mem, &info, GST_MAP_READ));
-
- for (i = 0; i < array_size; i++) {
- float expected = (i + 1) * (b + 1) * (-1.);
- EXPECT_FLOAT_EQ (((float *) info.data)[i], expected);
- }
-
- gst_memory_unmap (mem, &info);
- gst_buffer_unref (out_buf);
- }
-
- EXPECT_EQ (gst_harness_buffers_received (h), num_buffers);
- gst_harness_teardown (h);
-}
+TEST_TRANSFORM_TYPECAST (typecast_6_accel, 3, 5, int16_t, _NNS_INT16, float, "float32", _NNS_FLOAT32, TRUE)
/**
* @brief Test for tensor_transform typecast (uint16 > float32)
*/
-TEST (test_tensor_transform, typecast_7)
-{
- const guint num_buffers = 3;
- const guint array_size = 5;
-
- GstHarness *h;
- GstBuffer *in_buf, *out_buf;
- GstTensorConfig config;
- GstMemory *mem;
- GstMapInfo info;
- guint i, b;
- gsize data_in_size, data_out_size;
-
- h = gst_harness_new ("tensor_transform");
-
- g_object_set (h->element, "mode", GTT_TYPECAST, "option", "float32", NULL);
- g_object_set (h->element, "acceleration", (gboolean) FALSE, NULL);
-
- /* input tensor info */
- config.info.type = _NNS_UINT16;
- gst_tensor_parse_dimension ("5", config.info.dimension);
- config.rate_n = 0;
- config.rate_d = 1;
-
- gst_harness_set_src_caps (h, gst_tensor_caps_from_config (&config));
- data_in_size = gst_tensor_info_get_size (&config.info);
-
- config.info.type = _NNS_FLOAT32;
- data_out_size = gst_tensor_info_get_size (&config.info);
-
- /* push buffers */
- for (b = 0; b < num_buffers; b++) {
- /* set input buffer */
- in_buf = gst_harness_create_buffer (h, data_in_size);
-
- mem = gst_buffer_peek_memory (in_buf, 0);
- ASSERT_TRUE (gst_memory_map (mem, &info, GST_MAP_WRITE));
-
- for (i = 0; i < array_size; i++) {
- uint16_t value = (i + 1) * (b + 1);
- ((uint16_t *) info.data)[i] = value;
- }
-
- gst_memory_unmap (mem, &info);
-
- EXPECT_EQ (gst_harness_push (h, in_buf), GST_FLOW_OK);
-
- /* get output buffer */
- out_buf = gst_harness_pull (h);
-
- ASSERT_TRUE (out_buf != NULL);
- ASSERT_EQ (gst_buffer_n_memory (out_buf), 1);
- ASSERT_EQ (gst_buffer_get_size (out_buf), data_out_size);
-
- mem = gst_buffer_peek_memory (out_buf, 0);
- ASSERT_TRUE (gst_memory_map (mem, &info, GST_MAP_READ));
-
- for (i = 0; i < array_size; i++) {
- float expected = (i + 1) * (b + 1);
- EXPECT_FLOAT_EQ (((float *) info.data)[i], expected);
- }
-
- gst_memory_unmap (mem, &info);
- gst_buffer_unref (out_buf);
- }
-
- EXPECT_EQ (gst_harness_buffers_received (h), num_buffers);
- gst_harness_teardown (h);
-}
+TEST_TRANSFORM_TYPECAST (typecast_7, 3, 5, uint16_t, _NNS_UINT16, float, "float32", _NNS_FLOAT32, FALSE)
/**
* @brief Test for tensor_transform typecast (acceleration, uint16 > float32)
*/
-TEST (test_tensor_transform, typecast_7_accel)
-{
- const guint num_buffers = 3;
- const guint array_size = 5;
-
- GstHarness *h;
- GstBuffer *in_buf, *out_buf;
- GstTensorConfig config;
- GstMemory *mem;
- GstMapInfo info;
- guint i, b;
- gsize data_in_size, data_out_size;
-
- h = gst_harness_new ("tensor_transform");
-
- g_object_set (h->element, "mode", GTT_TYPECAST, "option", "float32", NULL);
- g_object_set (h->element, "acceleration", (gboolean) TRUE, NULL);
-
- /* input tensor info */
- config.info.type = _NNS_UINT16;
- gst_tensor_parse_dimension ("5", config.info.dimension);
- config.rate_n = 0;
- config.rate_d = 1;
-
- gst_harness_set_src_caps (h, gst_tensor_caps_from_config (&config));
- data_in_size = gst_tensor_info_get_size (&config.info);
-
- config.info.type = _NNS_FLOAT32;
- data_out_size = gst_tensor_info_get_size (&config.info);
-
- /* push buffers */
- for (b = 0; b < num_buffers; b++) {
- /* set input buffer */
- in_buf = gst_harness_create_buffer (h, data_in_size);
-
- mem = gst_buffer_peek_memory (in_buf, 0);
- ASSERT_TRUE (gst_memory_map (mem, &info, GST_MAP_WRITE));
-
- for (i = 0; i < array_size; i++) {
- uint16_t value = (i + 1) * (b + 1);
- ((uint16_t *) info.data)[i] = value;
- }
-
- gst_memory_unmap (mem, &info);
-
- EXPECT_EQ (gst_harness_push (h, in_buf), GST_FLOW_OK);
-
- /* get output buffer */
- out_buf = gst_harness_pull (h);
-
- ASSERT_TRUE (out_buf != NULL);
- ASSERT_EQ (gst_buffer_n_memory (out_buf), 1);
- ASSERT_EQ (gst_buffer_get_size (out_buf), data_out_size);
-
- mem = gst_buffer_peek_memory (out_buf, 0);
- ASSERT_TRUE (gst_memory_map (mem, &info, GST_MAP_READ));
-
- for (i = 0; i < array_size; i++) {
- float expected = (i + 1) * (b + 1);
- EXPECT_FLOAT_EQ (((float *) info.data)[i], expected);
- }
-
- gst_memory_unmap (mem, &info);
- gst_buffer_unref (out_buf);
- }
-
- EXPECT_EQ (gst_harness_buffers_received (h), num_buffers);
- gst_harness_teardown (h);
-}
+TEST_TRANSFORM_TYPECAST (typecast_7_accel, 3, 5, uint16_t, _NNS_UINT16, float, "float32", _NNS_FLOAT32, TRUE)
/**
* @brief Test for tensor_transform typecast (uint64 -> int64)