ml_tensors_info_destroy (in_res);
ml_tensors_info_destroy (out_res);
}
+
+/**
+ * @brief Test NNStreamer single shot (tensorflow-lite)
+ * @detail Update property 'layout' for input tensor
+ */
+TEST (nnstreamer_capi_singleshot, property_01_p)
+{
+ ml_single_h single;
+ ml_tensors_info_h in_info;
+ ml_tensors_data_h input, output;
+ int status;
+ char *prop_value;
+ void *data;
+ size_t data_size;
+
+ const gchar *root_path = g_getenv ("NNSTREAMER_BUILD_ROOT_PATH");
+ gchar *test_model;
+
+ /* supposed to run test in build directory */
+ if (root_path == NULL)
+ root_path = "..";
+
+ test_model = g_build_filename (root_path, "tests", "test_models", "models",
+ "mobilenet_v1_1.0_224_quant.tflite", NULL);
+ ASSERT_TRUE (g_file_test (test_model, G_FILE_TEST_EXISTS));
+
+ status = ml_single_open (&single, test_model, NULL, NULL,
+ ML_NNFW_TYPE_TENSORFLOW_LITE, ML_NNFW_HW_ANY);
+ EXPECT_EQ (status, ML_ERROR_NONE);
+
+ /* get layout */
+ status = ml_single_get_property (single, "inputlayout", &prop_value);
+ EXPECT_EQ (status, ML_ERROR_NONE);
+
+ EXPECT_STREQ (prop_value, "ANY");
+ g_free (prop_value);
+
+ /* get updatable */
+ status = ml_single_get_property (single, "is-updatable", &prop_value);
+ EXPECT_EQ (status, ML_ERROR_NONE);
+
+ EXPECT_STREQ (prop_value, "false");
+ g_free (prop_value);
+
+ /* set layout (tf-lite does not require the layout) */
+ status = ml_single_set_property (single, "inputlayout", "NHWC");
+ EXPECT_EQ (status, ML_ERROR_NONE);
+
+ status = ml_single_get_property (single, "inputlayout", &prop_value);
+ EXPECT_EQ (status, ML_ERROR_NONE);
+
+ EXPECT_STREQ (prop_value, "NHWC");
+ g_free (prop_value);
+
+ /* get input info */
+ status = ml_single_get_input_info (single, &in_info);
+ EXPECT_EQ (status, ML_ERROR_NONE);
+
+ /* invoke */
+ input = output = NULL;
+
+ /* generate dummy data */
+ status = ml_tensors_data_create (in_info, &input);
+ EXPECT_EQ (status, ML_ERROR_NONE);
+ EXPECT_TRUE (input != NULL);
+
+ status = ml_single_set_timeout (single, SINGLE_DEF_TIMEOUT_MSEC);
+ EXPECT_TRUE (status == ML_ERROR_NOT_SUPPORTED || status == ML_ERROR_NONE);
+
+ status = ml_single_invoke (single, input, &output);
+ EXPECT_EQ (status, ML_ERROR_NONE);
+ EXPECT_TRUE (output != NULL);
+
+ status = ml_tensors_data_get_tensor_data (output, 0, (void **) &data, &data_size);
+ EXPECT_EQ (status, ML_ERROR_NONE);
+ EXPECT_EQ (data_size, 1001U);
+
+ ml_tensors_data_destroy (output);
+ ml_tensors_data_destroy (input);
+ ml_tensors_info_destroy (in_info);
+
+ status = ml_single_close (single);
+ EXPECT_EQ (status, ML_ERROR_NONE);
+
+ g_free (test_model);
+}
+
+/**
+ * @brief Test NNStreamer single shot (tensorflow-lite)
+ * @detail Failure case to set invalid property
+ */
+TEST (nnstreamer_capi_singleshot, property_02_n)
+{
+ ml_single_h single;
+ int status;
+ char *prop_value = NULL;
+
+ const gchar *root_path = g_getenv ("NNSTREAMER_BUILD_ROOT_PATH");
+ gchar *test_model;
+
+ /* supposed to run test in build directory */
+ if (root_path == NULL)
+ root_path = "..";
+
+ test_model = g_build_filename (root_path, "tests", "test_models", "models",
+ "mobilenet_v1_1.0_224_quant.tflite", NULL);
+ ASSERT_TRUE (g_file_test (test_model, G_FILE_TEST_EXISTS));
+
+ status = ml_single_open (&single, test_model, NULL, NULL,
+ ML_NNFW_TYPE_TENSORFLOW_LITE, ML_NNFW_HW_ANY);
+ EXPECT_EQ (status, ML_ERROR_NONE);
+
+ /* get invalid property */
+ status = ml_single_get_property (single, "unknown_prop", &prop_value);
+ EXPECT_NE (status, ML_ERROR_NONE);
+ g_free (prop_value);
+
+ /* set invalid property */
+ status = ml_single_set_property (single, "unknown_prop", "INVALID");
+ EXPECT_NE (status, ML_ERROR_NONE);
+
+ status = ml_single_close (single);
+ EXPECT_EQ (status, ML_ERROR_NONE);
+
+ g_free (test_model);
+}
+
+/**
+ * @brief Test NNStreamer single shot (tensorflow-lite)
+ * @detail Failure case to set meta property
+ */
+TEST (nnstreamer_capi_singleshot, property_03_n)
+{
+ ml_single_h single;
+ ml_tensors_info_h in_info, out_info;
+ ml_tensor_dimension in_dim, out_dim;
+ ml_tensors_data_h input, output;
+ ml_tensor_type_e type = ML_TENSOR_TYPE_UNKNOWN;
+ int status;
+ unsigned int count = 0;
+ char *name = NULL;
+ char *prop_value = NULL;
+ void *data;
+ size_t data_size;
+
+ const gchar *root_path = g_getenv ("NNSTREAMER_BUILD_ROOT_PATH");
+ gchar *test_model;
+
+ /* supposed to run test in build directory */
+ if (root_path == NULL)
+ root_path = "..";
+
+ test_model = g_build_filename (root_path, "tests", "test_models", "models",
+ "mobilenet_v1_1.0_224_quant.tflite", NULL);
+ ASSERT_TRUE (g_file_test (test_model, G_FILE_TEST_EXISTS));
+
+ status = ml_single_open (&single, test_model, NULL, NULL,
+ ML_NNFW_TYPE_TENSORFLOW_LITE, ML_NNFW_HW_ANY);
+ EXPECT_EQ (status, ML_ERROR_NONE);
+
+ /* failed to set dimension */
+ status = ml_single_set_property (single, "input", "3:4:4:1");
+ EXPECT_NE (status, ML_ERROR_NONE);
+
+ status = ml_single_get_property (single, "input", &prop_value);
+ EXPECT_EQ (status, ML_ERROR_NONE);
+
+ EXPECT_STREQ (prop_value, "3:224:224:1");
+ g_free (prop_value);
+
+ /* input tensor in filter */
+ status = ml_single_get_input_info (single, &in_info);
+ EXPECT_EQ (status, ML_ERROR_NONE);
+
+ status = ml_tensors_info_get_count (in_info, &count);
+ EXPECT_EQ (status, ML_ERROR_NONE);
+ EXPECT_EQ (count, 1U);
+
+ status = ml_tensors_info_get_tensor_name (in_info, 0, &name);
+ EXPECT_EQ (status, ML_ERROR_NONE);
+ EXPECT_TRUE (name == NULL);
+
+ status = ml_tensors_info_get_tensor_type (in_info, 0, &type);
+ EXPECT_EQ (status, ML_ERROR_NONE);
+ EXPECT_EQ (type, ML_TENSOR_TYPE_UINT8);
+
+ ml_tensors_info_get_tensor_dimension (in_info, 0, in_dim);
+ EXPECT_EQ (in_dim[0], 3U);
+ EXPECT_EQ (in_dim[1], 224U);
+ EXPECT_EQ (in_dim[2], 224U);
+ EXPECT_EQ (in_dim[3], 1U);
+
+ /* output tensor in filter */
+ status = ml_single_get_output_info (single, &out_info);
+ EXPECT_EQ (status, ML_ERROR_NONE);
+
+ status = ml_tensors_info_get_count (out_info, &count);
+ EXPECT_EQ (status, ML_ERROR_NONE);
+ EXPECT_EQ (count, 1U);
+
+ status = ml_tensors_info_get_tensor_name (out_info, 0, &name);
+ EXPECT_EQ (status, ML_ERROR_NONE);
+ EXPECT_TRUE (name == NULL);
+
+ status = ml_tensors_info_get_tensor_type (out_info, 0, &type);
+ EXPECT_EQ (status, ML_ERROR_NONE);
+ EXPECT_EQ (type, ML_TENSOR_TYPE_UINT8);
+
+ ml_tensors_info_get_tensor_dimension (out_info, 0, out_dim);
+ EXPECT_EQ (out_dim[0], 1001U);
+ EXPECT_EQ (out_dim[1], 1U);
+ EXPECT_EQ (out_dim[2], 1U);
+ EXPECT_EQ (out_dim[3], 1U);
+
+ /* invoke */
+ input = output = NULL;
+
+ /* generate dummy data */
+ status = ml_tensors_data_create (in_info, &input);
+ EXPECT_EQ (status, ML_ERROR_NONE);
+ EXPECT_TRUE (input != NULL);
+
+ status = ml_single_set_timeout (single, SINGLE_DEF_TIMEOUT_MSEC);
+ EXPECT_TRUE (status == ML_ERROR_NOT_SUPPORTED || status == ML_ERROR_NONE);
+
+ status = ml_single_invoke (single, input, &output);
+ EXPECT_EQ (status, ML_ERROR_NONE);
+ EXPECT_TRUE (output != NULL);
+
+ status = ml_tensors_data_get_tensor_data (output, 0, (void **) &data, &data_size);
+ EXPECT_EQ (status, ML_ERROR_NONE);
+ EXPECT_EQ (data_size, 1001U);
+
+ ml_tensors_data_destroy (input);
+ ml_tensors_data_destroy (output);
+ ml_tensors_info_destroy (in_info);
+ ml_tensors_info_destroy (out_info);
+
+ status = ml_single_close (single);
+ EXPECT_EQ (status, ML_ERROR_NONE);
+
+ g_free (test_model);
+}
+
+/**
+ * @brief Test NNStreamer single shot (tensorflow-lite)
+ * @detail Update dimension for input tensor
+ */
+TEST (nnstreamer_capi_singleshot, property_04_p)
+{
+ ml_single_h single;
+ ml_tensors_info_h in_info, out_info;
+ ml_tensors_data_h input, output;
+ ml_tensor_dimension in_dim, out_dim;
+ char *prop_value;
+ int status;
+ size_t data_size;
+ float *data;
+
+ const gchar *root_path = g_getenv ("NNSTREAMER_BUILD_ROOT_PATH");
+ gchar *test_model;
+
+ /* supposed to run test in build directory */
+ if (root_path == NULL)
+ root_path = "..";
+
+ /** add.tflite adds value 2 to all the values in the input */
+ test_model = g_build_filename (root_path, "tests", "test_models", "models",
+ "add.tflite", NULL);
+ ASSERT_TRUE (g_file_test (test_model, G_FILE_TEST_EXISTS));
+
+ status = ml_single_open (&single, test_model, NULL, NULL,
+ ML_NNFW_TYPE_TENSORFLOW_LITE, ML_NNFW_HW_ANY);
+ EXPECT_EQ (status, ML_ERROR_NONE);
+
+ status = ml_single_set_property (single, "input", "5:1:1:1");
+ EXPECT_EQ (status, ML_ERROR_NONE);
+
+ status = ml_single_get_property (single, "input", &prop_value);
+ EXPECT_EQ (status, ML_ERROR_NONE);
+
+ EXPECT_STREQ (prop_value, "5:1:1:1");
+ g_free (prop_value);
+
+ /* validate in/out info */
+ status = ml_single_get_input_info (single, &in_info);
+ EXPECT_EQ (status, ML_ERROR_NONE);
+
+ ml_tensors_info_get_tensor_dimension (in_info, 0, in_dim);
+ EXPECT_EQ (in_dim[0], 5U);
+ EXPECT_EQ (in_dim[1], 1U);
+ EXPECT_EQ (in_dim[2], 1U);
+ EXPECT_EQ (in_dim[3], 1U);
+
+ status = ml_single_get_output_info (single, &out_info);
+ EXPECT_EQ (status, ML_ERROR_NONE);
+
+ ml_tensors_info_get_tensor_dimension (out_info, 0, out_dim);
+ EXPECT_EQ (out_dim[0], 5U);
+ EXPECT_EQ (out_dim[1], 1U);
+ EXPECT_EQ (out_dim[2], 1U);
+ EXPECT_EQ (out_dim[3], 1U);
+
+ /* invoke */
+ input = output = NULL;
+
+ /* generate dummy data */
+ status = ml_tensors_data_create (in_info, &input);
+ EXPECT_EQ (status, ML_ERROR_NONE);
+ EXPECT_TRUE (input != NULL);
+
+ status = ml_tensors_data_get_tensor_data (input, 0, (void **) &data, &data_size);
+ EXPECT_EQ (status, ML_ERROR_NONE);
+ EXPECT_EQ (data_size, 5 * sizeof (float));
+ for (int idx = 0; idx < 5; idx++)
+ data[idx] = idx;
+
+ status = ml_single_invoke (single, input, &output);
+ EXPECT_EQ (status, ML_ERROR_NONE);
+ EXPECT_TRUE (output != NULL);
+
+ status = ml_tensors_data_get_tensor_data (output, 0, (void **) &data, &data_size);
+ EXPECT_EQ (status, ML_ERROR_NONE);
+ EXPECT_EQ (data_size, 5 * sizeof (float));
+ for (int idx = 0; idx < 5; idx++)
+ EXPECT_EQ (data[idx], idx + 2);
+
+ ml_tensors_data_destroy (input);
+ ml_tensors_data_destroy (output);
+ ml_tensors_info_destroy (in_info);
+ ml_tensors_info_destroy (out_info);
+
+ status = ml_single_close (single);
+ EXPECT_EQ (status, ML_ERROR_NONE);
+
+ g_free (test_model);
+}
#endif /* ENABLE_TENSORFLOW_LITE */
#ifdef ENABLE_NNFW_RUNTIME