nnfw_tensorinfo i_in;
nnfw_tensorinfo i_out;
nnfw_session *session;
- gchar *model_path;
+ gchar *model_file;
} nnfw_pdata;
static void nnfw_close (const GstTensorFilterProperties * prop,
NNFW_STATUS status;
int err = 0;
nnfw_pdata *pdata;
+ char *model_path = NULL;
+ char *meta_file = NULL;
if (*private_data != NULL) {
pdata = *private_data;
- if (g_strcmp0 (prop->model_files[0], pdata->model_path) != 0) {
+ if (g_strcmp0 (prop->model_files[0], pdata->model_file) != 0) {
nnfw_close (prop, private_data); /* "reopen" */
} else {
return 1;
goto unalloc_exit;
}
- status = nnfw_load_model_from_file (pdata->session, prop->model_files[0]);
+ /** @note nnfw opens the first model listed in the MANIFEST file */
+ model_path = g_path_get_dirname (prop->model_files[0]);
+ meta_file = g_build_filename (model_path, "metadata", "MANIFEST", NULL);
+
+ if (!g_file_test (prop->model_files[0], G_FILE_TEST_IS_REGULAR) ||
+ !g_file_test (meta_file, G_FILE_TEST_IS_REGULAR)) {
+ err = -EINVAL;
+ g_printerr ("Model file (%s) or its metadata is not valid (not regular).",
+ prop->model_files[0]);
+ goto session_exit;
+ }
+
+ /* @todo open using model_file once nnfw works with it */
+ status = nnfw_load_model_from_file (pdata->session, model_path);
if (status != NNFW_STATUS_NO_ERROR) {
err = -EINVAL;
g_printerr ("Cannot load the model file: %s", prop->model_files[0]);
goto session_exit;
}
- pdata->model_path = g_strdup (prop->model_files[0]);
+ pdata->model_file = g_strdup (prop->model_files[0]);
+ g_free (meta_file);
+ g_free (model_path);
+
return 0;
session_exit:
status = nnfw_close_session(pdata->session);
if (status != NNFW_STATUS_NO_ERROR)
g_printerr ("Closing the session just opened by %s has failed", __func__);
+ g_free (meta_file);
+ g_free (model_path);
unalloc_exit:
g_free (pdata);
*private_data = NULL;
if (status != NNFW_STATUS_NO_ERROR) {
g_printerr ("cannot close nnfw-runtime session for %s",
- pdata->model_path);
+ pdata->model_file);
}
} else {
g_printerr ("nnfw_close called without proper nnfw_open");
}
pdata->session = NULL;
- g_free (pdata->model_path);
- pdata->model_path = NULL;
+ g_free (pdata->model_file);
+ pdata->model_file = NULL;
g_free (pdata);
*private_data = NULL;
EXPECT_NE (ret, 0);
}
-/**
- * @brief Test nnfw subplugin with successful open/close
- */
-TEST (nnstreamer_nnfw_runtime_raw_functions, open_close_01_n)
+static
+gboolean gen_tf_prop (GstTensorFilterProperties *prop)
{
- int ret;
- void *data = NULL;
- gchar *test_model;
+ gchar *model_file;
+ gchar *meta_file;
gchar *model_path;
const gchar *root_path = g_getenv ("NNSTREAMER_BUILD_ROOT_PATH");
- ASSERT_NE (root_path, nullptr);
+ g_return_val_if_fail (root_path != nullptr, FALSE);
/** nnfw needs a directory with model file and metadata in that directory */
model_path = g_build_filename (root_path, "tests", "test_models", "models",
NULL);
+
+ meta_file = g_build_filename (model_path, "metadata", "MANIFEST", NULL);
+ g_return_val_if_fail (g_file_test (meta_file, G_FILE_TEST_EXISTS), FALSE);
+ g_free (meta_file);
+
+ model_file = g_build_filename (model_path, "add.tflite", NULL);
+ g_return_val_if_fail (g_file_test (model_file, G_FILE_TEST_EXISTS), FALSE);
+ g_free (model_path);
+
+ prop->fwname = "nnfw";
+ prop->fw_opened = 0;
+
const gchar *model_files[] = {
model_path, NULL,
};
- GstTensorFilterProperties prop = {
- .fwname = "nnfw",
- .fw_opened = 0,
- .model_files = model_files,
- .num_models = 1,
- };
+ prop->model_files = model_files;
+ prop->num_models = 1;
+
+ return TRUE;
+}
- test_model = g_build_filename (model_path, "add.tflite", NULL);
- ASSERT_TRUE (g_file_test (test_model, G_FILE_TEST_EXISTS));
- g_free (test_model);
+/**
+ * @brief Test nnfw subplugin with successful open/close
+ */
+TEST (nnstreamer_nnfw_runtime_raw_functions, open_close_01_n)
+{
+ int ret;
+ void *data = NULL;
+ GstTensorFilterProperties prop;
- test_model = g_build_filename (model_path, "metadata", "MANIFEST", NULL);
- ASSERT_TRUE (g_file_test (test_model, G_FILE_TEST_EXISTS));
- g_free (test_model);
+ ASSERT_TRUE (gen_tf_prop (&prop));
const GstTensorFilterFramework *sp = nnstreamer_filter_find ("nnfw");
EXPECT_NE (sp, (void *) NULL);
{
int ret;
void *data = NULL;
- gchar *test_model;
- gchar *model_path;
- const gchar *root_path = g_getenv ("NNSTREAMER_BUILD_ROOT_PATH");
GstTensorsInfo info, res;
+ GstTensorFilterProperties prop;
- ASSERT_NE (root_path, nullptr);
-
- /** nnfw needs a directory with model file and metadata in that directory */
- model_path = g_build_filename (root_path, "tests", "test_models", "models",
- NULL);
- const gchar *model_files[] = {
- model_path, NULL,
- };
- GstTensorFilterProperties prop = {
- .fwname = "nnfw",
- .fw_opened = 0,
- .model_files = model_files,
- .num_models = 1,
- };
-
- test_model = g_build_filename (model_path, "add.tflite", NULL);
- ASSERT_TRUE (g_file_test (test_model, G_FILE_TEST_EXISTS));
- g_free (test_model);
-
- test_model = g_build_filename (model_path, "metadata", "MANIFEST", NULL);
- ASSERT_TRUE (g_file_test (test_model, G_FILE_TEST_EXISTS));
- g_free (test_model);
+ ASSERT_TRUE (gen_tf_prop (&prop));
const GstTensorFilterFramework *sp = nnstreamer_filter_find ("nnfw");
EXPECT_NE (sp, (void *) NULL);
{
int ret;
void *data = NULL;
- gchar *test_model;
- gchar *model_path;
- const gchar *root_path = g_getenv ("NNSTREAMER_BUILD_ROOT_PATH");
GstTensorMemory input, output;
- ASSERT_NE (root_path, nullptr);
-
- /** nnfw needs a directory with model file and metadata in that directory */
- model_path = g_build_filename (root_path, "tests", "test_models", "models",
- NULL);
- const gchar *model_files[] = {
- model_path, NULL,
- };
- GstTensorFilterProperties prop = {
- .fwname = "nnfw",
- .fw_opened = 0,
- .model_files = model_files,
- .num_models = 1,
- };
-
- /** this model adds 2 to the input data passed in float format */
- test_model = g_build_filename (model_path, "add.tflite", NULL);
- ASSERT_TRUE (g_file_test (test_model, G_FILE_TEST_EXISTS));
- g_free (test_model);
+ GstTensorFilterProperties prop;
- test_model = g_build_filename (model_path, "metadata", "MANIFEST", NULL);
- ASSERT_TRUE (g_file_test (test_model, G_FILE_TEST_EXISTS));
- g_free (test_model);
+ ASSERT_TRUE (gen_tf_prop (&prop));
const GstTensorFilterFramework *sp = nnstreamer_filter_find ("nnfw");
EXPECT_NE (sp, (void *) NULL);