}
/**
+ * @brief Test for tensor dimension.
+ */
+TEST (commonGetTensorDimension, case5)
+{
+ tensor_dim dim;
+ gchar *dim_str;
+ guint rank;
+
+ rank = gst_tensor_parse_dimension ("345:123:433:177:851", dim);
+ EXPECT_EQ (rank, 5U);
+ EXPECT_EQ (dim[0], 345U);
+ EXPECT_EQ (dim[1], 123U);
+ EXPECT_EQ (dim[2], 433U);
+ EXPECT_EQ (dim[3], 177U);
+ EXPECT_EQ (dim[4], 851U);
+
+ dim_str = gst_tensor_get_dimension_string (dim);
+ EXPECT_TRUE (gst_tensor_dimension_string_is_equal (dim_str, "345:123:433:177:851"));
+ g_free (dim_str);
+}
+
+/**
+ * @brief Test for tensor dimension.
+ */
+TEST (commonGetTensorDimension, case6)
+{
+ tensor_dim dim;
+ gchar *dim_str;
+ guint rank;
+
+ rank = gst_tensor_parse_dimension ("345:123:433:177:851:369", dim);
+ EXPECT_EQ (rank, 6U);
+ EXPECT_EQ (dim[0], 345U);
+ EXPECT_EQ (dim[1], 123U);
+ EXPECT_EQ (dim[2], 433U);
+ EXPECT_EQ (dim[3], 177U);
+ EXPECT_EQ (dim[4], 851U);
+ EXPECT_EQ (dim[5], 369U);
+
+ dim_str = gst_tensor_get_dimension_string (dim);
+ EXPECT_TRUE (gst_tensor_dimension_string_is_equal (dim_str, "345:123:433:177:851:369"));
+ g_free (dim_str);
+}
+
+/**
+ * @brief Test for tensor dimension.
+ */
+TEST (commonGetTensorDimension, case7)
+{
+ tensor_dim dim;
+ gchar *dim_str;
+ guint rank;
+
+ rank = gst_tensor_parse_dimension ("345:123:433:177:851:369:456", dim);
+ EXPECT_EQ (rank, 7U);
+ EXPECT_EQ (dim[0], 345U);
+ EXPECT_EQ (dim[1], 123U);
+ EXPECT_EQ (dim[2], 433U);
+ EXPECT_EQ (dim[3], 177U);
+ EXPECT_EQ (dim[4], 851U);
+ EXPECT_EQ (dim[5], 369U);
+ EXPECT_EQ (dim[6], 456U);
+
+ dim_str = gst_tensor_get_dimension_string (dim);
+ EXPECT_TRUE (gst_tensor_dimension_string_is_equal (dim_str, "345:123:433:177:851:369:456"));
+ g_free (dim_str);
+}
+
+/**
+ * @brief Test for tensor dimension.
+ */
+TEST (commonGetTensorDimension, case8)
+{
+ tensor_dim dim;
+ gchar *dim_str;
+ guint rank;
+
+ rank = gst_tensor_parse_dimension ("345:123:433:177:851:369:456:91", dim);
+ EXPECT_EQ (rank, 8U);
+ EXPECT_EQ (dim[0], 345U);
+ EXPECT_EQ (dim[1], 123U);
+ EXPECT_EQ (dim[2], 433U);
+ EXPECT_EQ (dim[3], 177U);
+ EXPECT_EQ (dim[4], 851U);
+ EXPECT_EQ (dim[5], 369U);
+ EXPECT_EQ (dim[6], 456U);
+ EXPECT_EQ (dim[7], 91U);
+
+ dim_str = gst_tensor_get_dimension_string (dim);
+ EXPECT_TRUE (gst_tensor_dimension_string_is_equal (dim_str, "345:123:433:177:851:369:456:91"));
+ g_free (dim_str);
+}
+
+/**
* @brief Test to copy tensor info.
*/
TEST (commonTensorInfo, copyTensor)
info1->info[0].dimension[1] = info2->info[0].dimension[1] = 3;
info1->info[0].dimension[2] = info2->info[0].dimension[2] = 1;
info1->info[0].dimension[3] = info2->info[0].dimension[3] = 1;
+ info1->info[0].dimension[4] = info2->info[0].dimension[4] = 2;
+ info1->info[0].dimension[5] = info2->info[0].dimension[5] = 3;
+ info1->info[0].dimension[6] = info2->info[0].dimension[6] = 1;
+ info1->info[0].dimension[7] = info2->info[0].dimension[7] = 1;
info1->info[1].dimension[0] = info2->info[1].dimension[0] = 5;
info1->info[1].dimension[1] = info2->info[1].dimension[1] = 5;
info1->info[1].dimension[2] = info2->info[1].dimension[2] = 1;
info1->info[1].dimension[3] = info2->info[1].dimension[3] = 1;
+ info1->info[1].dimension[4] = info2->info[1].dimension[4] = 5;
+ info1->info[1].dimension[5] = info2->info[1].dimension[5] = 5;
+ info1->info[1].dimension[6] = info2->info[1].dimension[6] = 1;
+ info1->info[1].dimension[7] = info2->info[1].dimension[7] = 1;
}
/**
}
#endif /* ENABLE_TENSORFLOW_LITE */
+#ifdef ENABLE_TENSORFLOW2_LITE
+/**
+ * @brief Test Fixture class for a tensor-filter single functionality with high rank.
+ */
+class NNSFilterSingleTestExtended : public::testing::Test
+{
+protected:
+ GTensorFilterSingle *single;
+ GTensorFilterSingleClass *klass;
+ GstTensorMemory input[2];
+ GstTensorMemory output;
+ gboolean loaded;
+
+public:
+ /**
+ * @brief Construct a new NNSFilterSingleTestExtended object
+ */
+ NNSFilterSingleTestExtended ()
+ : single (nullptr), klass (nullptr), loaded (FALSE)
+ {
+ input[0].data = input[1].data = output.data = nullptr;
+ input[0].size = input[1].size = output.size = 0;
+ }
+
+ /**
+ * @brief SetUp method for each test case
+ */
+ void SetUp () override
+ {
+ g_autofree gchar *model_file = nullptr;
+ gsize length = 4 * 4 * 4 * 4 * 4;
+ guint i;
+ const gchar *root_path = g_getenv ("NNSTREAMER_SOURCE_ROOT_PATH");
+
+ input[0].size = length * 4;
+ input[1].size = length * 4;
+ output.size = length * 4;
+
+ single = (GTensorFilterSingle *) g_object_new (G_TYPE_TENSOR_FILTER_SINGLE, NULL);
+ klass = (GTensorFilterSingleClass *) g_type_class_ref (G_TYPE_TENSOR_FILTER_SINGLE);
+
+ /* supposed to run test in build directory */
+ if (root_path == NULL)
+ root_path = "..";
+
+ model_file = g_build_filename (root_path, "tests", "test_models", "models",
+ "sample_4x4x4x4x4_two_input_one_output.tflite", NULL);
+ ASSERT_TRUE (g_file_test (model_file, G_FILE_TEST_EXISTS));
+
+ input[0].data = g_malloc0(sizeof(gfloat)*length);
+ input[1].data = g_malloc0(sizeof(gfloat)*length);
+
+ for (i = 0; i < length ; i++) {
+ ((gfloat*)input[0].data)[i] = i;
+ ((gfloat*)input[1].data)[i] = i + 1;
+ }
+
+ g_object_set (G_OBJECT (single), "framework", "tensorflow-lite",
+ "model", model_file, NULL);
+ loaded = TRUE;
+ }
+
+ /**
+ * @brief TearDown method for each test case
+ */
+ void TearDown () override
+ {
+ g_type_class_unref (klass);
+ g_object_unref (single);
+ g_free (input[0].data);
+ g_free (input[1].data);
+ g_free (output.data);
+ }
+};
+
+/**
+ * @brief Test to invoke tf-lite model.
+ */
+TEST_F (NNSFilterSingleTestExtended, invoke_p)
+{
+ guint i, length = 4 * 4 * 4 * 4 * 4;
+ ASSERT_TRUE (this->loaded);
+
+ /* invoke the model and check output result */
+ EXPECT_TRUE (klass->invoke (single, input, &output, TRUE));
+
+ for (i = 0 ; i < length ; i++)
+ EXPECT_EQ (((gfloat *)output.data)[i], (((gfloat*)input[0].data)[i] + ((gfloat*)input[1].data)[i]));
+
+ EXPECT_TRUE (klass->input_configured (single));
+ EXPECT_TRUE (klass->output_configured (single));
+ EXPECT_FALSE (klass->allocate_in_invoke (single));
+
+ klass->destroy_notify (single, &output);
+}
+
+/**
+ * @brief Test to set invalid info.
+ */
+TEST_F (NNSFilterSingleTestExtended, setInvalidInfo_n)
+{
+ GstTensorsInfo in_info, out_info;
+ gst_tensors_info_init (&in_info);
+ gst_tensors_info_init (&out_info);
+
+ ASSERT_TRUE (this->loaded);
+ EXPECT_TRUE (klass->start (single));
+
+ /* valid tensor info */
+ in_info.num_tensors = 2U;
+ in_info.info[0].type = _NNS_FLOAT32;
+ gst_tensor_parse_dimension ("4:4:4:4:4", in_info.info[0].dimension);
+ in_info.info[1].type = _NNS_FLOAT32;
+ gst_tensor_parse_dimension ("4:4:4:4:4", in_info.info[1].dimension);
+ EXPECT_TRUE (klass->set_input_info (single, &in_info, &out_info) == 0);
+
+ /* request to set invalid tensor info */
+ in_info.num_tensors = 1U;
+ EXPECT_FALSE (klass->set_input_info (single, &in_info, &out_info) == 0);
+
+ EXPECT_TRUE (klass->stop (single));
+ gst_tensors_info_free (&in_info);
+ gst_tensors_info_free (&out_info);
+}
+
+#endif /* ENABLE_TENSORFLOW2_LITE */
+
/**
* @brief Test to start before initializing.
*/
}
/**
- * @brief Test data for tensor_aggregator (2 frames with dimension 3:4:2:2)
+ * @brief Test data for tensor_aggregator (2 frames with dimension 3:4:2:2 or 3:2:2:2:2)
*/
const gint aggr_test_frames[2][48]
= { { 1101, 1102, 1103, 1104, 1105, 1106, 1107, 1108, 1109, 1110, 1111, 1112,
}
/**
+ * @brief Test for tensor_aggregator (concatenate 2 frames with frames-dim 4, out-dimension 3:2:2:2:4)
+ */
+TEST (testTensorAggregator, aggregate6)
+{
+ GstHarness *h;
+ GstTensorsConfig config;
+ guint i;
+ gsize data_in_size;
+
+ h = gst_harness_new ("tensor_aggregator");
+
+ g_object_set (h->element, "frames-out", 2, "frames-dim", 4, NULL);
+
+ /* input tensor info */
+ gst_tensors_config_init (&config);
+ config.info.num_tensors = 1;
+ config.info.info[0].type = _NNS_INT32;
+ gst_tensor_parse_dimension ("3:2:2:2:2", config.info.info[0].dimension);
+ config.rate_n = 0;
+ config.rate_d = 1;
+
+ gst_harness_set_src_caps (h, gst_tensors_caps_from_config (&config));
+ data_in_size = gst_tensors_info_get_size (&config.info, 0);
+
+ /* push buffers */
+ for (i = 0; i < 2; i++) {
+ _aggregator_test_push_buffer (h, aggr_test_frames[i], data_in_size);
+ }
+
+ /* get output buffer */
+ const gint expected[96] = { 1101, 1102, 1103, 1104, 1105, 1106, 1107, 1108,
+ 1109, 1110, 1111, 1112, 1113, 1114, 1115, 1116, 1117, 1118, 1119, 1120,
+ 1121, 1122, 1123, 1124, 1201, 1202, 1203, 1204, 1205, 1206, 1207, 1208,
+ 1209, 1210, 1211, 1212, 1213, 1214, 1215, 1216, 1217, 1218, 1219, 1220, 1221,
+ 1222, 1223, 1224, 2101, 2102, 2103, 2104, 2105, 2106, 2107, 2108, 2109, 2110,
+ 2111, 2112, 2113, 2114, 2115, 2116, 2117, 2118, 2119, 2120, 2121, 2122, 2123,
+ 2124, 2201, 2202, 2203, 2204, 2205, 2206, 2207, 2208, 2209, 2210, 2211, 2212,
+ 2213, 2214, 2215, 2216, 2217, 2218, 2219, 2220, 2221, 2222, 2223, 2224 };
+
+ _aggregator_test_check_output (h, expected, 96);
+
+ EXPECT_EQ (gst_harness_buffers_received (h), 1U);
+ gst_harness_teardown (h);
+}
+
+/**
+ * @brief Test for tensor_aggregator (concatenate 2 frames with frames-dim 3, out-dimension 3:2:2:4:2)
+ */
+TEST (testTensorAggregator, aggregate7)
+{
+ GstHarness *h;
+ GstTensorsConfig config;
+ guint i;
+ gsize data_in_size;
+
+ h = gst_harness_new ("tensor_aggregator");
+
+ g_object_set (h->element, "frames-out", 2, "frames-dim", 3, NULL);
+
+ /* input tensor info */
+ gst_tensors_config_init (&config);
+ config.info.num_tensors = 1;
+ config.info.info[0].type = _NNS_INT32;
+ gst_tensor_parse_dimension ("3:2:2:2:2", config.info.info[0].dimension);
+ config.rate_n = 0;
+ config.rate_d = 1;
+
+ gst_harness_set_src_caps (h, gst_tensors_caps_from_config (&config));
+ data_in_size = gst_tensors_info_get_size (&config.info, 0);
+
+ /* push buffers */
+ for (i = 0; i < 2; i++) {
+ _aggregator_test_push_buffer (h, aggr_test_frames[i], data_in_size);
+ }
+
+ /* get output buffer */
+ const gint expected[96] = { 1101, 1102, 1103, 1104, 1105, 1106, 1107, 1108,
+ 1109, 1110, 1111, 1112, 1113, 1114, 1115, 1116, 1117, 1118, 1119, 1120,
+ 1121, 1122, 1123, 1124, 2101, 2102, 2103, 2104, 2105, 2106, 2107, 2108,
+ 2109, 2110, 2111, 2112, 2113, 2114, 2115, 2116, 2117, 2118, 2119, 2120, 2121,
+ 2122, 2123, 2124, 1201, 1202, 1203, 1204, 1205, 1206, 1207, 1208, 1209, 1210,
+ 1211, 1212, 1213, 1214, 1215, 1216, 1217, 1218, 1219, 1220, 1221, 1222, 1223,
+ 1224, 2201, 2202, 2203, 2204, 2205, 2206, 2207, 2208, 2209, 2210, 2211, 2212,
+ 2213, 2214, 2215, 2216, 2217, 2218, 2219, 2220, 2221, 2222, 2223, 2224 };
+
+ _aggregator_test_check_output (h, expected, 96);
+
+ EXPECT_EQ (gst_harness_buffers_received (h), 1U);
+ gst_harness_teardown (h);
+}
+
+/**
+ * @brief Test for tensor_aggregator (concatenate 2 frames with frames-dim 2, out-dimension 3:2:4:2:2)
+ */
+TEST (testTensorAggregator, aggregate8)
+{
+ GstHarness *h;
+ GstTensorsConfig config;
+ guint i;
+ gsize data_in_size;
+
+ h = gst_harness_new ("tensor_aggregator");
+
+ g_object_set (h->element, "frames-out", 2, "frames-dim", 2, NULL);
+
+ /* input tensor info */
+ gst_tensors_config_init (&config);
+ config.info.num_tensors = 1;
+ config.info.info[0].type = _NNS_INT32;
+ gst_tensor_parse_dimension ("3:2:2:2:2", config.info.info[0].dimension);
+ config.rate_n = 0;
+ config.rate_d = 1;
+
+ gst_harness_set_src_caps (h, gst_tensors_caps_from_config (&config));
+ data_in_size = gst_tensors_info_get_size (&config.info, 0);
+
+ /* push buffers */
+ for (i = 0; i < 2; i++) {
+ _aggregator_test_push_buffer (h, aggr_test_frames[i], data_in_size);
+ }
+
+ /* get output buffer */
+ const gint expected[96] = { 1101, 1102, 1103, 1104, 1105, 1106, 1107, 1108,
+ 1109, 1110, 1111, 1112, 2101, 2102, 2103, 2104, 2105, 2106, 2107, 2108,
+ 2109, 2110, 2111, 2112, 1113, 1114, 1115, 1116, 1117, 1118, 1119, 1120,
+ 1121, 1122, 1123, 1124, 2113, 2114, 2115, 2116, 2117, 2118, 2119, 2120, 2121,
+ 2122, 2123, 2124, 1201, 1202, 1203, 1204, 1205, 1206, 1207, 1208, 1209, 1210,
+ 1211, 1212, 2201, 2202, 2203, 2204, 2205, 2206, 2207, 2208, 2209, 2210, 2211,
+ 2212, 1213, 1214, 1215, 1216, 1217, 1218, 1219, 1220, 1221, 1222, 1223, 1224,
+ 2213, 2214, 2215, 2216, 2217, 2218, 2219, 2220, 2221, 2222, 2223, 2224 };
+
+ _aggregator_test_check_output (h, expected, 96);
+
+ EXPECT_EQ (gst_harness_buffers_received (h), 1U);
+ gst_harness_teardown (h);
+}
+
+/**
+ * @brief Test for tensor_aggregator (concatenate 2 frames with frames-dim 1, out-dimension 3:4:2:2:2)
+ */
+TEST (testTensorAggregator, aggregate9)
+{
+ GstHarness *h;
+ GstTensorsConfig config;
+ guint i;
+ gsize data_in_size;
+
+ h = gst_harness_new ("tensor_aggregator");
+
+ g_object_set (h->element, "frames-out", 2, "frames-dim", 1, NULL);
+
+ /* input tensor info */
+ gst_tensors_config_init (&config);
+ config.info.num_tensors = 1;
+ config.info.info[0].type = _NNS_INT32;
+ gst_tensor_parse_dimension ("3:2:2:2:2", config.info.info[0].dimension);
+ config.rate_n = 0;
+ config.rate_d = 1;
+
+ gst_harness_set_src_caps (h, gst_tensors_caps_from_config (&config));
+ data_in_size = gst_tensors_info_get_size (&config.info, 0);
+
+ /* push buffers */
+ for (i = 0; i < 2; i++) {
+ _aggregator_test_push_buffer (h, aggr_test_frames[i], data_in_size);
+ }
+
+ /* get output buffer */
+ const gint expected[96] = { 1101, 1102, 1103, 1104, 1105, 1106, 2101, 2102,
+ 2103, 2104, 2105, 2106, 1107, 1108, 1109, 1110, 1111, 1112, 2107, 2108,
+ 2109, 2110, 2111, 2112, 1113, 1114, 1115, 1116, 1117, 1118, 2113, 2114,
+ 2115, 2116, 2117, 2118, 1119, 1120, 1121, 1122, 1123, 1124, 2119, 2120, 2121,
+ 2122, 2123, 2124, 1201, 1202, 1203, 1204, 1205, 1206, 2201, 2202, 2203, 2204,
+ 2205, 2206, 1207, 1208, 1209, 1210, 1211, 1212, 2207, 2208, 2209, 2210, 2211,
+ 2212, 1213, 1214, 1215, 1216, 1217, 1218, 2213, 2214, 2215, 2216, 2217, 2218,
+ 1219, 1220, 1221, 1222, 1223, 1224, 2219, 2220, 2221, 2222, 2223, 2224 };
+
+ _aggregator_test_check_output (h, expected, 96);
+
+ EXPECT_EQ (gst_harness_buffers_received (h), 1U);
+ gst_harness_teardown (h);
+}
+
+/**
+ * @brief Test for tensor_aggregator (concatenate 2 frames with frames-dim 0, out-dimension 6:2:2:2:2)
+ */
+TEST (testTensorAggregator, aggregate10)
+{
+ GstHarness *h;
+ GstTensorsConfig config;
+ guint i;
+ gsize data_in_size;
+
+ h = gst_harness_new ("tensor_aggregator");
+
+ g_object_set (h->element, "frames-out", 2, "frames-dim", 0, NULL);
+
+ /* input tensor info */
+ gst_tensors_config_init (&config);
+ config.info.num_tensors = 1;
+ config.info.info[0].type = _NNS_INT32;
+ gst_tensor_parse_dimension ("3:2:2:2:2", config.info.info[0].dimension);
+ config.rate_n = 0;
+ config.rate_d = 1;
+
+ gst_harness_set_src_caps (h, gst_tensors_caps_from_config (&config));
+ data_in_size = gst_tensors_info_get_size (&config.info, 0);
+
+ /* push buffers */
+ for (i = 0; i < 2; i++) {
+ _aggregator_test_push_buffer (h, aggr_test_frames[i], data_in_size);
+ }
+
+ /* get output buffer */
+ const gint expected[96] = { 1101, 1102, 1103, 2101, 2102, 2103, 1104, 1105,
+ 1106, 2104, 2105, 2106, 1107, 1108, 1109, 2107, 2108, 2109, 1110, 1111,
+ 1112, 2110, 2111, 2112, 1113, 1114, 1115, 2113, 2114, 2115, 1116, 1117,
+ 1118, 2116, 2117, 2118, 1119, 1120, 1121, 2119, 2120, 2121, 1122, 1123, 1124,
+ 2122, 2123, 2124, 1201, 1202, 1203, 2201, 2202, 2203, 1204, 1205, 1206, 2204,
+ 2205, 2206, 1207, 1208, 1209, 2207, 2208, 2209, 1210, 1211, 1212, 2210, 2211,
+ 2212, 1213, 1214, 1215, 2213, 2214, 2215, 1216, 1217, 1218, 2216, 2217, 2218,
+ 1219, 1220, 1221, 2219, 2220, 2221, 1222, 1223, 1224, 2222, 2223, 2224 };
+
+ _aggregator_test_check_output (h, expected, 96);
+
+ EXPECT_EQ (gst_harness_buffers_received (h), 1U);
+ gst_harness_teardown (h);
+}
+
+/**
* @brief Test for tensor_aggregator (flush old data in aggregator)
*/
TEST (testTensorAggregator, flushData)