Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CodeClean] dependency to ml-agent #435

Merged
merged 2 commits into from
Jan 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions c/src/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -102,28 +102,29 @@ nns_capi_dep = declare_dependency(link_with: nns_capi_lib,

# Service API
if get_option('enable-ml-service')
ml_service_deps = [nns_capi_dep, ml_agent_deps]
ml_service_deps = [nns_capi_dep, ml_agent_dep, gio_dep, json_glib_dep]
if support_remote_service
ml_service_deps += [nnstreamer_edge_dep, curl_dep]
endif
if get_option('enable-tizen')
ml_service_deps += dependency('capi-appfw-app-common')
endif

nns_capi_service_shared_lib = shared_library ('capi-ml-service',
nns_capi_service_srcs,
dependencies: ml_service_deps,
include_directories: [nns_capi_include, ml_agent_incs],
include_directories: nns_capi_include,
install: true,
install_dir: api_install_libdir,
link_with: ml_agent_lib,
version: api_version,
version: api_version
)

nns_capi_service_static_lib = static_library ('capi-ml-service',
nns_capi_service_srcs,
dependencies: ml_service_deps,
include_directories: [nns_capi_include, ml_agent_incs],
include_directories: nns_capi_include,
install: true,
link_with: ml_agent_lib,
install_dir: api_install_libdir,
install_dir: api_install_libdir
)

nns_capi_service_lib = nns_capi_service_shared_lib
Expand Down
5 changes: 0 additions & 5 deletions c/src/ml-api-service-private.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,6 @@
#include <ml-api-service.h>
#include <ml-api-inference-internal.h>

#include "pipeline-dbus.h"
#include "model-dbus.h"
#include "resource-dbus.h"
#include "nnstreamer-tizen-internal.h"

#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
Expand Down
26 changes: 12 additions & 14 deletions c/src/ml-api-service-remote.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

#include <glib.h>
#include <glib/gstdio.h>
#include <gio/gio.h>
#include <gst/gst.h>
#include <gst/gstbuffer.h>
#include <gst/app/app.h>
Expand All @@ -23,6 +24,9 @@
#include "ml-api-service.h"
#include "ml-api-service-private.h"

/** @todo remove this header after ACR for ml-remote API is done. */
#include "nnstreamer-tizen-internal.h"

#define MAX_PORT_NUM_LEN 6U

/**
Expand Down Expand Up @@ -64,7 +68,7 @@ typedef struct

ml_service_event_cb event_cb;
void *user_data;
gchar *path; /** A path to save the received model file */
gchar *path; /**< A path to save the received model file */
} _ml_remote_service_s;

/**
Expand Down Expand Up @@ -207,15 +211,9 @@ _mlrs_get_service_type (gchar * service_str)
* @brief Get ml remote service activation type.
*/
static gboolean
_mlrs_parse_activate (gchar * activate)
_mlrs_parse_activate (const gchar * activate)
{
gboolean ret = TRUE;

if (g_ascii_strcasecmp (activate, "false") == 0) {
ret = FALSE;
}

return ret;
return (activate && g_ascii_strcasecmp (activate, "true") == 0);
}

/**
Expand Down Expand Up @@ -559,10 +557,10 @@ ml_service_remote_release_internal (void *priv)
return ML_ERROR_INVALID_PARAMETER;

nns_edge_release_handle (mlrs->edge_h);
g_free (mlrs->path);

/** Wait some time until release the edge handle. */
/* Wait some time until release the edge handle. */
g_usleep (1000000);
g_free (mlrs->path);
g_free (mlrs);

return ML_ERROR_NONE;
Expand Down Expand Up @@ -635,12 +633,12 @@ ml_service_remote_create (ml_option_h option, ml_service_event_cb cb,

_mlrs_release_edge_info (edge_info);

return ret;
return ML_ERROR_NONE;
}

/**
* @brief Register new information, such as neural network models or pipeline descriptions, on a remote server.
*/
* @brief Register new information, such as neural network models or pipeline descriptions, on a remote server.
*/
int
ml_service_remote_register (ml_service_h handle, ml_option_h option, void *data,
size_t data_len)
Expand Down
9 changes: 7 additions & 2 deletions daemon/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,14 @@ ml_agent_static_lib = static_library('ml-agent',

ml_agent_lib = ml_agent_shared_lib
if get_option('default_library') == 'static'
ml_agent_lib = ml_agent_static_lib
ml_agent_lib = ml_agent_static_lib
endif

ml_agent_dep = declare_dependency(link_with: ml_agent_lib,
dependencies: ml_agent_deps,
include_directories: ml_agent_incs
)

ml_agent_lib_common_objs = ml_agent_shared_lib.extract_objects(ml_agent_lib_common_srcs)
ml_agent_test_both_lib = both_libraries('ml-agent-test',
ml_agent_lib_service_db_srcs,
Expand All @@ -102,7 +107,7 @@ ml_agent_test_both_lib = both_libraries('ml-agent-test',

ml_agent_test_lib = ml_agent_test_both_lib.get_shared_lib()
if get_option('default_library') == 'static'
ml_agent_test_lib = ml_agent_test_both_lib.get_static_lib()
ml_agent_test_lib = ml_agent_test_both_lib.get_static_lib()
endif

lib_ml_agent_test_dep = declare_dependency(
Expand Down
2 changes: 1 addition & 1 deletion meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ if get_option('enable-tizen')
endif

if get_option('enable-gcov')
add_project_arguments('-DENABLE_GCOV=1', language: ['c', 'cpp'])
add_project_arguments('-DENABLE_GCOV=1', language: ['c', 'cpp'])
endif

serviceDBPath = get_option('service-db-path')
Expand Down
9 changes: 3 additions & 6 deletions tests/capi/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ unittest_capi_inference_single = executable('unittest_capi_inference_single',
'unittest_capi_inference_single.cc',
dependencies: [nns_capi_single_dep, gtest_dep],
install: get_option('install-test'),
install_dir: unittest_install_dir,
include_directories: nns_capi_include,
install_dir: unittest_install_dir
)
test('unittest_capi_inference_single', unittest_capi_inference_single, env: testenv, timeout: 100)

Expand Down Expand Up @@ -36,8 +35,7 @@ if get_option('enable-ml-service')
'unittest_capi_service_agent_client.cc',
dependencies: [unittest_common_dep, nns_capi_service_dep, gdbus_gen_test_dep, lib_ml_agent_test_dep],
install: get_option('install-test'),
install_dir: unittest_install_dir,
include_directories: nns_capi_include,
install_dir: unittest_install_dir
)
test('unittest_capi_service_agent_client', unittest_capi_service_agent_client, env: testenv, timeout: 100)

Expand All @@ -46,8 +44,7 @@ if get_option('enable-ml-service')
'unittest_capi_remote_service.cc',
dependencies: [unittest_common_dep, nns_capi_service_dep, gdbus_gen_test_dep, lib_ml_agent_test_dep],
install: get_option('install-test'),
install_dir: unittest_install_dir,
include_directories: nns_capi_include,
install_dir: unittest_install_dir
)
test('unittest_capi_remote_service', unittest_capi_remote_service, env: testenv, timeout: 100)
endif
Expand Down
4 changes: 3 additions & 1 deletion tests/capi/unittest_capi_remote_service.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
*/

#include <gtest/gtest.h>
#include <gdbus-util.h>
#include <gio/gio.h>
#include <glib/gstdio.h>
#include <ml-api-inference-pipeline-internal.h>
Expand All @@ -19,6 +18,9 @@
#include <netinet/in.h>
#include <netinet/tcp.h>

/** @todo remove this header after ACR for ml-remote API is done. */
#include "nnstreamer-tizen-internal.h"

/**
* @brief Test base class for Database of ML Service API.
*/
Expand Down
110 changes: 2 additions & 108 deletions tests/capi/unittest_capi_service_agent_client.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
*/

#include <gtest/gtest.h>
#include <gdbus-util.h>
#include <gio/gio.h>
#include <ml-api-inference-pipeline-internal.h>
#include <ml-api-internal.h>
Expand All @@ -18,7 +17,8 @@
#include <netinet/in.h>
#include <netinet/tcp.h>

#include "dbus-interface.h"
/** @todo remove below header after deleting ml-agent from api repo. */
#include "gdbus-util.h"

/**
* @brief Test base class for Database of ML Service API.
Expand Down Expand Up @@ -1280,112 +1280,6 @@ TEST_F (MLServiceAgentTest, model_scenario)
g_free (test_model2);
}

/**
* @brief Negative testcase of pipeline gdbus call.
*/
TEST_F (MLServiceAgentTest, pipeline_gdbus_call_n)
{
int ret;
GError *error = NULL;

MachinelearningServicePipeline *proxy_for_pipeline
= machinelearning_service_pipeline_proxy_new_for_bus_sync (bus_type,
G_DBUS_PROXY_FLAGS_NONE, DBUS_ML_BUS_NAME, DBUS_PIPELINE_PATH, NULL, &error);

if (!proxy_for_pipeline || error) {
g_critical ("Failed to create proxy_for_pipeline for machinelearning service pipeline");
if (error) {
g_critical ("Error Message : %s", error->message);
g_clear_error (&error);
}
ASSERT_TRUE (false);
}

/* gdbus call with empty string */
machinelearning_service_pipeline_call_set_pipeline_sync (
proxy_for_pipeline, "", "", &ret, nullptr, nullptr);
EXPECT_EQ (ML_ERROR_INVALID_PARAMETER, ret);
}

/**
* @brief Negative testcase of model gdbus call.
*/
TEST_F (MLServiceAgentTest, model_gdbus_call_n)
{
int ret;
GError *error = NULL;

MachinelearningServiceModel *proxy_for_model
= machinelearning_service_model_proxy_new_for_bus_sync (bus_type,
G_DBUS_PROXY_FLAGS_NONE, DBUS_ML_BUS_NAME, DBUS_MODEL_PATH, NULL, &error);

if (!proxy_for_model || error) {
g_critical ("Failed to create proxy_for_model for machinelearning service model");
if (error) {
g_critical ("Error Message : %s", error->message);
g_clear_error (&error);
}
ASSERT_TRUE (false);
}

/* empty string */
machinelearning_service_model_call_register_sync (
proxy_for_model, "", "", false, "test", "", NULL, &ret, nullptr, nullptr);
EXPECT_EQ (ML_ERROR_INVALID_PARAMETER, ret);

/* empty string */
machinelearning_service_model_call_get_all_sync (
proxy_for_model, "", NULL, &ret, nullptr, nullptr);
EXPECT_EQ (ML_ERROR_INVALID_PARAMETER, ret);

g_object_unref (proxy_for_model);
}

/**
* @brief Negative testcase of resource gdbus call.
*/
TEST_F (MLServiceAgentTest, resource_gdbus_call_n)
{
int ret;
gchar *res_info = NULL;
GError *error = NULL;

MachinelearningServiceResource *proxy_for_resource
= machinelearning_service_resource_proxy_new_for_bus_sync (bus_type,
G_DBUS_PROXY_FLAGS_NONE, DBUS_ML_BUS_NAME, DBUS_RESOURCE_PATH, NULL, &error);

if (!proxy_for_resource || error) {
g_critical ("Failed to create proxy_for_resource for machinelearning service resource");
if (error) {
g_critical ("Error Message : %s", error->message);
g_clear_error (&error);
}
ASSERT_TRUE (false);
}

machinelearning_service_resource_call_add_sync (
proxy_for_resource, "", "path", "description", "", &ret, nullptr, nullptr);
EXPECT_EQ (ML_ERROR_INVALID_PARAMETER, ret);

machinelearning_service_resource_call_add_sync (
proxy_for_resource, "name", "", "description", "", &ret, nullptr, nullptr);
EXPECT_EQ (ML_ERROR_INVALID_PARAMETER, ret);

machinelearning_service_resource_call_get_sync (
proxy_for_resource, "", &res_info, &ret, nullptr, nullptr);
EXPECT_EQ (ML_ERROR_INVALID_PARAMETER, ret);

machinelearning_service_resource_call_get_sync (
proxy_for_resource, "unknown", &res_info, &ret, nullptr, nullptr);
EXPECT_EQ (ML_ERROR_INVALID_PARAMETER, ret);

machinelearning_service_resource_call_delete_sync (
proxy_for_resource, "", &ret, nullptr, nullptr);
EXPECT_EQ (ML_ERROR_INVALID_PARAMETER, ret);

g_object_unref (proxy_for_resource);
}

/**
* @brief Test the usecase of ml_service for resource.
*/
Expand Down
Loading