From 3292a32e4d3621fc117920f5a4aa40c547a980fd Mon Sep 17 00:00:00 2001 From: hyunuktak Date: Wed, 24 Jan 2018 09:55:02 +0900 Subject: [PATCH] Add initial source codes for gtest Change-Id: I41574b7e13b99c1a1fb14ee32b27d4352bbc933a Signed-off-by: hyunuktak --- CMakeLists.txt | 6 +- include/stc-manager-gdbus.h | 5 +- include/stc-manager.h | 4 +- interfaces/stcmanager-iface-manager.xml | 7 + interfaces/stcmanager-iface-restriction.xml | 4 + packaging/stc-manager.spec | 14 +- src/CMakeLists.txt | 10 +- src/database/db-common.c | 40 +-- src/database/db-guard.c | 8 +- src/database/include/stc-db.h | 9 - src/database/include/table-statistics.h | 3 - src/database/tables/table-counters.c | 26 +- src/database/tables/table-restrictions.c | 68 ++--- src/database/tables/table-statistics.c | 66 ++--- src/helper/helper-cgroup.c | 24 +- src/helper/helper-iptables.c | 122 ++++----- src/helper/helper-net-cls.c | 32 +-- src/helper/helper-nfacct-rule.c | 34 ++- src/helper/helper-nl.c | 16 +- src/helper/helper-procfs.c | 12 +- src/monitor/stc-app-lifecycle.c | 120 ++++----- src/monitor/stc-default-connection.c | 73 +++--- src/monitor/stc-emulator.c | 12 +- src/monitor/stc-exception.c | 26 +- src/monitor/stc-monitor.c | 225 ++++++++++------- src/stc-manager-gdbus.c | 91 +++++-- src/stc-manager-plugin.c | 2 + src/stc-manager-util.c | 22 +- src/stc-manager.c | 23 +- src/stc-restriction.c | 74 +++--- src/stc-statistics.c | 86 +++---- unittest/CMakeLists.txt | 32 +++ unittest/gdbus.cpp | 185 ++++++++++++++ unittest/gdbus.h | 70 ++++++ unittest/manager.cpp | 58 +++++ unittest/manager.h | 31 +++ unittest/restriction.cpp | 343 +++++++++++++++++++++++++ unittest/restriction.h | 78 ++++++ unittest/statistics.cpp | 317 +++++++++++++++++++++++ unittest/statistics.h | 66 +++++ unittest/stcmgr.cpp | 17 ++ unittest/stcmgr.h | 72 ++++++ unittest/unittest.cpp | 377 ++++++++++++++++++++++++++++ unittest/unittest.h | 29 +++ 44 files changed, 2382 insertions(+), 557 deletions(-) create mode 100644 interfaces/stcmanager-iface-manager.xml create mode 100755 unittest/CMakeLists.txt create mode 100755 unittest/gdbus.cpp create mode 100755 unittest/gdbus.h create mode 100755 unittest/manager.cpp create mode 100755 unittest/manager.h create mode 100755 unittest/restriction.cpp create mode 100755 unittest/restriction.h create mode 100755 unittest/statistics.cpp create mode 100755 unittest/statistics.h create mode 100755 unittest/stcmgr.cpp create mode 100755 unittest/stcmgr.h create mode 100755 unittest/unittest.cpp create mode 100755 unittest/unittest.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 4dfaf15..1e7fe23 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,5 +1,5 @@ CMAKE_MINIMUM_REQUIRED(VERSION 2.6) -PROJECT(stc-manager C) +PROJECT(stc-manager C CXX) SET(PACKAGE ${PROJECT_NAME}) SET(INTERFACES "${CMAKE_SOURCE_DIR}/interfaces") SET(PREFIX ${CMAKE_INSTALL_PREFIX}) @@ -9,3 +9,7 @@ SET(DATA_DIR ${CMAKE_SOURCE_DIR}/data) ADD_SUBDIRECTORY(src) ADD_SUBDIRECTORY(plugin) + +IF(BUILD_GTESTS) + ADD_SUBDIRECTORY(unittest) +ENDIF(BUILD_GTESTS) diff --git a/include/stc-manager-gdbus.h b/include/stc-manager-gdbus.h index 045a70c..7803c6b 100755 --- a/include/stc-manager-gdbus.h +++ b/include/stc-manager-gdbus.h @@ -25,7 +25,7 @@ #define STC_DBUS_SERVICE_PATH "/net/stc" #define STC_DBUS_SERVICE_STATISTICS_PATH "/net/stc/statistics" #define STC_DBUS_SERVICE_RESTRICTION_PATH "/net/stc/restriction" -#define STC_DBUS_SERVICE_QUOTA_PATH "/net/stc/quota" +#define STC_DBUS_SERVICE_MANAGER_PATH "/net/stc/manager" #define STC_DBUS_REPLY_ERROR_NONE(invocation) \ g_dbus_method_invocation_return_value((invocation), \ @@ -79,4 +79,7 @@ gboolean stc_manager_dbus_emit_signal(GDBusConnection *connection, const gchar *signal_name, GVariant *parameters); +gboolean handle_manager_stop(StcManager *object, + GDBusMethodInvocation *invocation); + #endif /* __STC_MANAGER_GDBUS_H__ */ diff --git a/include/stc-manager.h b/include/stc-manager.h index 2766a60..f2b9c97 100755 --- a/include/stc-manager.h +++ b/include/stc-manager.h @@ -137,7 +137,6 @@ typedef enum { /** * @desc Set of the options. - * version - contains structure version * wifi - enable/disable wifi, STC_DB_OPTION_UNDEF to leave option as is * datacall - enable/disable datacall, STC_DB_OPTION_UNDEF to leave option as is * datausage_timer - set period of the updating data from the kernel, @@ -146,7 +145,6 @@ typedef enum { * STC_DB_OPTION_UNDEF to leave option as is */ typedef struct { - unsigned char version; stc_option_state_e wifi; stc_option_state_e datacall; time_t datausage_timer; @@ -166,6 +164,7 @@ typedef struct { gpointer statistics_obj; gpointer restriction_obj; + gpointer manager_obj; GDBusObjectManagerServer *obj_mgr; GDBusConnection *connection; @@ -176,5 +175,6 @@ typedef struct { } stc_s; stc_s *stc_get_manager(void); +void stc_stop_manager(void); #endif /* __STC_MANAGER__ */ diff --git a/interfaces/stcmanager-iface-manager.xml b/interfaces/stcmanager-iface-manager.xml new file mode 100644 index 0000000..f5a9167 --- /dev/null +++ b/interfaces/stcmanager-iface-manager.xml @@ -0,0 +1,7 @@ + + + + + + + diff --git a/interfaces/stcmanager-iface-restriction.xml b/interfaces/stcmanager-iface-restriction.xml index f4baf76..93b81af 100644 --- a/interfaces/stcmanager-iface-restriction.xml +++ b/interfaces/stcmanager-iface-restriction.xml @@ -33,6 +33,10 @@ + + + + diff --git a/packaging/stc-manager.spec b/packaging/stc-manager.spec index bd37172..ea01601 100644 --- a/packaging/stc-manager.spec +++ b/packaging/stc-manager.spec @@ -1,6 +1,6 @@ Name: stc-manager Summary: STC(Smart Traffic Control) manager -Version: 0.0.42 +Version: 0.0.43 Release: 0 Group: Network & Connectivity/Other License: Apache-2.0 @@ -30,6 +30,10 @@ BuildRequires: pkgconfig(sqlite3) BuildRequires: python BuildRequires: python-xml +%if 0%{?gtests:1} +BuildRequires: pkgconfig(gmock) +%endif + %description A smart traffic control manager to manage traffic counting and bandwidth limitation @@ -57,7 +61,9 @@ export FFLAGS="$FFLAGS -DTIZEN_DEBUG_ENABLE" -DENABLE_DATABASE=%{enable_database} \ -DDATABASE_FULL_PATH=%{database_full_path} \ -DENABLE_STATISTICS=%{enable_statistics} \ - -DENABLE_RESTRICTION=%{enable_restriction} + -DENABLE_RESTRICTION=%{enable_restriction} \ + -DBUILD_GTESTS=%{?gtests:1}%{!?gtests:0} \ + -DBUILD_GCOV=%{?gcov:1}%{!?gcov:0} make %{?_smp_mflags} @@ -108,6 +114,10 @@ cp resources/dbus/stc-manager.conf %{buildroot}%{_sysconfdir}/dbus-1/system.d/st %config(noreplace) %attr(660, root, root) %{database_full_path}-journal %endif +%if 0%{?gtests:1} +%{_bindir}/gtest* +%endif + %files plugin %manifest %{name}.manifest %attr(644, -,-) %{_datadir}/icons/*.png diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 23fd943..d8bc359 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -64,14 +64,21 @@ IF("${ENABLE_DATABASE}" STREQUAL "YES") INSTALL(FILES ${DATA_DIR}/traffic_db.sql DESTINATION /usr/share) ENDIF() +IF(BUILD_GTESTS) +SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -fpic -Wall -Werror-implicit-function-declaration") +SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS} -fprofile-arcs -ftest-coverage") +ELSE(BUILD_GTESTS) SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -fpic -Wall -Werror-implicit-function-declaration -fvisibility=hidden") -SET(ARM_CFLAGS "${ARM_CFLAGS} -mapcs -mabi=aapcs-linux -msoft-float -Uarm -fpic") SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS}") +ENDIF(BUILD_GTESTS) SET(CMAKE_EXE_LINKER_FLAGS "-Wl,--as-needed -pie") ADD_DEFINITIONS("-DUSE_DLOG") ADD_DEFINITIONS("-DDATABASE_FULL_PATH=\"${DATABASE_FULL_PATH}\"") +IF(BUILD_GTESTS) + ADD_DEFINITIONS(-DTIZEN_GTESTS) +ENDIF(BUILD_GTESTS) ADD_CUSTOM_COMMAND( WORKING_DIRECTORY @@ -81,6 +88,7 @@ ADD_CUSTOM_COMMAND( --c-namespace Stc --c-generate-object-manager --generate-docbook generated-code-docs + ${INTERFACES}/stcmanager-iface-manager.xml ${INTERFACES}/stcmanager-iface-restriction.xml ${INTERFACES}/stcmanager-iface-statistics.xml COMMENT "Generating GDBus .c/.h") diff --git a/src/database/db-common.c b/src/database/db-common.c index 3895e12..f5f1770 100755 --- a/src/database/db-common.c +++ b/src/database/db-common.c @@ -28,6 +28,7 @@ static sqlite3 *database; +//LCOV_EXCL_START static int __stc_db_busy(void *user, int attempts) { __STC_LOG_FUNC_ENTER__; @@ -38,6 +39,7 @@ static int __stc_db_busy(void *user, int attempts) __STC_LOG_FUNC_EXIT__; return 1; } +//LCOV_EXCL_STOP stc_error_e stc_db_initialize_once(void) { @@ -45,16 +47,16 @@ stc_error_e stc_db_initialize_once(void) int res = 0; int retry_count = 0; if (database != NULL) { - __STC_LOG_FUNC_EXIT__; - return STC_ERROR_NONE; + __STC_LOG_FUNC_EXIT__; //LCOV_EXCL_LINE + return STC_ERROR_NONE; //LCOV_EXCL_LINE } do { res = sqlite3_open(DATABASE_FULL_PATH, &database); if (res != SQLITE_OK) { - STC_LOGD("Retry[%d] opening database %s: %s\n", + STC_LOGD("Retry[%d] opening database %s: %s\n", //LCOV_EXCL_LINE ++retry_count, DATABASE_FULL_PATH, - sqlite3_errmsg(database)); + sqlite3_errmsg(database)); //LCOV_EXCL_LINE } else { break; } @@ -62,33 +64,34 @@ stc_error_e stc_db_initialize_once(void) } while (retry_count <= MAX_DB_RETRY_COUNT); if (res != SQLITE_OK) { - STC_LOGE("Can't open database %s: %s\n", DATABASE_FULL_PATH, + STC_LOGE("Can't open database %s: %s\n", DATABASE_FULL_PATH, //LCOV_EXCL_LINE sqlite3_errmsg(database)); - __STC_LOG_FUNC_EXIT__; - return STC_ERROR_DB_FAILED; + __STC_LOG_FUNC_EXIT__; //LCOV_EXCL_LINE + return STC_ERROR_DB_FAILED; //LCOV_EXCL_LINE } STC_LOGD("Successfully opened database"); res = sqlite3_exec(database, "PRAGMA locking_mode = NORMAL", 0, 0, 0); if (res != SQLITE_OK) { - STC_LOGE("Can't set locking mode %s, skip set busy handler.", + STC_LOGE("Can't set locking mode %s, skip set busy handler.", //LCOV_EXCL_LINE sqlite3_errmsg(database)); - sqlite3_close(database); - database = NULL; - __STC_LOG_FUNC_EXIT__; - return STC_ERROR_DB_FAILED; + sqlite3_close(database); //LCOV_EXCL_LINE + database = NULL; //LCOV_EXCL_LINE + __STC_LOG_FUNC_EXIT__; //LCOV_EXCL_LINE + return STC_ERROR_DB_FAILED; //LCOV_EXCL_LINE } /* Set how many times we'll repeat our attempts for sqlite_step */ if (sqlite3_busy_handler(database, __stc_db_busy, NULL) != SQLITE_OK) - STC_LOGE("Couldn't set busy handler!"); + STC_LOGE("Couldn't set busy handler!"); //LCOV_EXCL_LINE __STC_LOG_FUNC_EXIT__; return STC_ERROR_NONE; } +//LCOV_EXCL_START sqlite3 *stc_db_get_database(void) { if (database == NULL) @@ -96,6 +99,7 @@ sqlite3 *stc_db_get_database(void) return database; } +//LCOV_EXCL_STOP stc_error_e stc_db_initialize(void) { @@ -113,17 +117,17 @@ stc_error_e stc_db_initialize(void) return STC_ERROR_NONE; handle_error: - stc_db_deinitialize(); - __STC_LOG_FUNC_EXIT__; - return STC_ERROR_DB_FAILED; + stc_db_deinitialize(); //LCOV_EXCL_LINE + __STC_LOG_FUNC_EXIT__; //LCOV_EXCL_LINE + return STC_ERROR_DB_FAILED; //LCOV_EXCL_LINE } gboolean stc_db_deinitialize(void) { __STC_LOG_FUNC_ENTER__; if (database == NULL) { - __STC_LOG_FUNC_EXIT__; - return TRUE; + __STC_LOG_FUNC_EXIT__; //LCOV_EXCL_LINE + return TRUE; //LCOV_EXCL_LINE } table_statistics_finalize(); diff --git a/src/database/db-guard.c b/src/database/db-guard.c index 5d03183..54b7fc5 100755 --- a/src/database/db-guard.c +++ b/src/database/db-guard.c @@ -33,6 +33,7 @@ static guint erase_timer = 0; static int db_entries = 0; +//LCOV_EXCL_START static void __change_db_entries_num_num(int num) { __STC_LOG_FUNC_ENTER__; @@ -115,6 +116,7 @@ static gboolean __erase_func_cb(void *user_data) __STC_LOG_FUNC_EXIT__; return TRUE; } +//LCOV_EXCL_STOP stc_error_e stc_init_db_guard(void) { @@ -123,9 +125,9 @@ stc_error_e stc_init_db_guard(void) erase_timer = g_timeout_add_seconds(ERASE_TIMER_INTERVAL, __erase_func_cb, NULL); if (erase_timer == 0) { - STC_LOGE("Failed to create timer"); - __STC_LOG_FUNC_EXIT__; - return STC_ERROR_FAIL; + STC_LOGE("Failed to create timer"); //LCOV_EXCL_LINE + __STC_LOG_FUNC_EXIT__; //LCOV_EXCL_LINE + return STC_ERROR_FAIL; //LCOV_EXCL_LINE } __STC_LOG_FUNC_EXIT__; diff --git a/src/database/include/stc-db.h b/src/database/include/stc-db.h index 689cb1f..6255433 100755 --- a/src/database/include/stc-db.h +++ b/src/database/include/stc-db.h @@ -37,15 +37,6 @@ typedef struct { time_t to; } stc_db_tm_interval_s; -typedef enum { - STC_DB_CON_PERIOD_UNKNOWN, /**< Undefined period */ - STC_DB_CON_PERIOD_LAST_RECEIVED_DATA, /**< Last received data */ - STC_DB_CON_PERIOD_LAST_SENT_DATA, /**< Last sent data */ - STC_DB_CON_PERIOD_TOTAL_RECEIVED_DATA, /**< Total received data */ - STC_DB_CON_PERIOD_TOTAL_SENT_DATA, /**< Total sent data */ - STC_DB_CON_PERIOD_LAST_ELEM -} stc_db_connection_period_type; - /* * General structure containing information for storing * app_id - package name as unique application identifier diff --git a/src/database/include/table-statistics.h b/src/database/include/table-statistics.h index ec88f5a..284fb48 100755 --- a/src/database/include/table-statistics.h +++ b/src/database/include/table-statistics.h @@ -30,16 +30,13 @@ typedef struct { } table_statistics_info; typedef struct { - unsigned char version; char *app_id; char *subscriber_id; stc_iface_type_e iftype; stc_db_tm_interval_s *interval; - stc_db_connection_period_type connection_state; } table_statistics_reset_rule; typedef struct { - unsigned char version; time_t from; time_t to; stc_iface_type_e iftype; diff --git a/src/database/tables/table-counters.c b/src/database/tables/table-counters.c index f8946f7..11c99a4 100755 --- a/src/database/tables/table-counters.c +++ b/src/database/tables/table-counters.c @@ -91,8 +91,8 @@ static int __prepare_delete(sqlite3 *db) static int initialized; if (initialized) { - __STC_LOG_FUNC_EXIT__; - return SQLITE_OK; + __STC_LOG_FUNC_EXIT__; //LCOV_EXCL_LINE + return SQLITE_OK; //LCOV_EXCL_LINE } PREPARE_DELETE(delete_counter, DELETE_COUNTER); @@ -118,8 +118,8 @@ static int __prepare_select(sqlite3 *db) static int initialized; if (initialized) { - __STC_LOG_FUNC_EXIT__; - return SQLITE_OK; + __STC_LOG_FUNC_EXIT__; //LCOV_EXCL_LINE + return SQLITE_OK; //LCOV_EXCL_LINE } PREPARE_SELECT(select_counter, SELECT_COUNTER); @@ -145,8 +145,8 @@ static int __prepare_update(sqlite3 *db) static int initialized; if (initialized) { - __STC_LOG_FUNC_EXIT__; - return SQLITE_OK; + __STC_LOG_FUNC_EXIT__; //LCOV_EXCL_LINE + return SQLITE_OK; //LCOV_EXCL_LINE } PREPARE_UPDATE(update_counter, UPDATE_COUNTER); @@ -182,6 +182,7 @@ stc_error_e table_counters_get(uint64_t restriction_id, do { rc = sqlite3_step(stmt); + //LCOV_EXCL_START switch (rc) { case SQLITE_DONE: break; @@ -198,6 +199,7 @@ stc_error_e table_counters_get(uint64_t restriction_id, error_code = STC_ERROR_DB_FAILED; } + //LCOV_EXCL_STOP } while (rc == SQLITE_ROW); handle_error: @@ -205,6 +207,7 @@ handle_error: return error_code; } +//LCOV_EXCL_START stc_error_e table_counters_update_counters(const table_counters_info *info) { stc_error_e error_code = STC_ERROR_NONE; @@ -233,6 +236,7 @@ handle_error: sqlite3_reset(stmt); return error_code; } +//LCOV_EXCL_STOP stc_error_e table_counters_delete(uint64_t restriction_id) { @@ -242,10 +246,10 @@ stc_error_e table_counters_delete(uint64_t restriction_id) DB_ACTION(sqlite3_bind_int64(stmt, 1, restriction_id)); if (sqlite3_step(stmt) != SQLITE_DONE) { - STC_LOGE("Failed to delete counter: %s\n", + STC_LOGE("Failed to delete counter: %s\n", //LCOV_EXCL_LINE sqlite3_errmsg(stc_db_get_database())); - error_code = STC_ERROR_DB_FAILED; - goto handle_error; + error_code = STC_ERROR_DB_FAILED; //LCOV_EXCL_LINE + goto handle_error; //LCOV_EXCL_LINE } STC_LOGD("Counter deleted for restriction_id [%llu]", restriction_id); @@ -262,8 +266,8 @@ stc_error_e table_counters_prepare(sqlite3 *db) stc_error_e error_code = STC_ERROR_NONE; if (db == NULL) { - __STC_LOG_FUNC_EXIT__; - return STC_ERROR_FAIL; + __STC_LOG_FUNC_EXIT__; //LCOV_EXCL_LINE + return STC_ERROR_FAIL; //LCOV_EXCL_LINE } DB_ACTION(__prepare_delete(db)); diff --git a/src/database/tables/table-restrictions.c b/src/database/tables/table-restrictions.c index 9324887..1c717e4 100755 --- a/src/database/tables/table-restrictions.c +++ b/src/database/tables/table-restrictions.c @@ -145,8 +145,8 @@ static int __prepare_delete(sqlite3 *db) static int initialized; if (initialized) { - __STC_LOG_FUNC_EXIT__; - return SQLITE_OK; + __STC_LOG_FUNC_EXIT__; //LCOV_EXCL_LINE + return SQLITE_OK; //LCOV_EXCL_LINE } PREPARE_DELETE(delete_restrictions, DELETE_RESTRICTIONS); @@ -172,8 +172,8 @@ static int __prepare_select(sqlite3 *db) static int initialized; if (initialized) { - __STC_LOG_FUNC_EXIT__; - return SQLITE_OK; + __STC_LOG_FUNC_EXIT__; //LCOV_EXCL_LINE + return SQLITE_OK; //LCOV_EXCL_LINE } PREPARE_SELECT(select_restriction, SELECT_RESTRICTIONS); @@ -207,8 +207,8 @@ static int __prepare_replace(sqlite3 *db) static int initialized; if (initialized) { - __STC_LOG_FUNC_EXIT__; - return SQLITE_OK; + __STC_LOG_FUNC_EXIT__; //LCOV_EXCL_LINE + return SQLITE_OK; //LCOV_EXCL_LINE } PREPARE_UPDATE(update_net_restrictions, UPDATE_NET_RESTRICTIONS); @@ -234,8 +234,8 @@ static int __prepare_insert(sqlite3 *db) static int initialized; if (initialized) { - __STC_LOG_FUNC_EXIT__; - return SQLITE_OK; + __STC_LOG_FUNC_EXIT__; //LCOV_EXCL_LINE + return SQLITE_OK; //LCOV_EXCL_LINE } PREPARE_UPDATE(insert_net_restrictions, INSERT_NET_RESTRICTIONS); @@ -265,8 +265,8 @@ stc_error_e table_restrictions_per_app(const gchar* app_id, sqlite3_stmt *stmt = select_restriction_per_app; if (!app_id) { - __STC_LOG_FUNC_EXIT__; - return STC_ERROR_DB_FAILED; + __STC_LOG_FUNC_EXIT__; //LCOV_EXCL_LINE + return STC_ERROR_DB_FAILED; //LCOV_EXCL_LINE } DB_ACTION(sqlite3_bind_text(stmt, 1, app_id, -1, @@ -294,15 +294,15 @@ stc_error_e table_restrictions_per_app(const gchar* app_id, data.restriction_id = sqlite3_column_int64(stmt, 8); if (restriction_cb(&data, user_data) == STC_CANCEL) - rc = SQLITE_DONE; + rc = SQLITE_DONE; //LCOV_EXCL_LINE break; case SQLITE_ERROR: default: - STC_LOGE("Failed to enumerate restrictions: %s\n", + STC_LOGE("Failed to enumerate restrictions: %s\n", //LCOV_EXCL_LINE sqlite3_errmsg(stc_db_get_database())); - __STC_LOG_FUNC_EXIT__; - error_code = STC_ERROR_DB_FAILED; + __STC_LOG_FUNC_EXIT__; //LCOV_EXCL_LINE + error_code = STC_ERROR_DB_FAILED; //LCOV_EXCL_LINE } } while (rc == SQLITE_ROW); @@ -342,15 +342,15 @@ stc_error_e table_restrictions_foreach(const table_restrictions_info_cb restrict data.restriction_id = sqlite3_column_int64(stmt, 8); if (restriction_cb(&data, user_data) == STC_CANCEL) - rc = SQLITE_DONE; + rc = SQLITE_DONE; //LCOV_EXCL_LINE break; case SQLITE_ERROR: default: - STC_LOGE("Failed to enumerate restrictions: %s\n", + STC_LOGE("Failed to enumerate restrictions: %s\n", //LCOV_EXCL_LINE sqlite3_errmsg(stc_db_get_database())); - __STC_LOG_FUNC_EXIT__; - error_code = STC_ERROR_DB_FAILED; + __STC_LOG_FUNC_EXIT__; //LCOV_EXCL_LINE + error_code = STC_ERROR_DB_FAILED; //LCOV_EXCL_LINE } } while (rc == SQLITE_ROW); @@ -370,9 +370,9 @@ stc_error_e table_restrictions_get_restriction_state_subscriber_id(const char *a bool state_subscriber_id = 0; if (state == NULL) { - STC_LOGE("Please provide valid argument!"); - __STC_LOG_FUNC_EXIT__; - return STC_ERROR_INVALID_PARAMETER; + STC_LOGE("Please provide valid argument!"); //LCOV_EXCL_LINE + __STC_LOG_FUNC_EXIT__; //LCOV_EXCL_LINE + return STC_ERROR_INVALID_PARAMETER; //LCOV_EXCL_LINE } *state = STC_RESTRICTION_UNKNOWN; @@ -410,10 +410,10 @@ stc_error_e table_restrictions_get_restriction_state_subscriber_id(const char *a break; case SQLITE_ERROR: default: - STC_LOGE("Can't perform sql query: %s \n%s", + STC_LOGE("Can't perform sql query: %s \n%s", //LCOV_EXCL_LINE SELECT_RESTRICTION_STATE, sqlite3_errmsg(stc_db_get_database())); - error_code = STC_ERROR_DB_FAILED; + error_code = STC_ERROR_DB_FAILED; //LCOV_EXCL_LINE } handle_error: @@ -449,10 +449,10 @@ stc_error_e table_restrictions_delete(const char *app_id, SQLITE_TRANSIENT)); if (sqlite3_step(stmt) != SQLITE_DONE) { - STC_LOGE("Failed to remove restrictions by network interface %s\n", + STC_LOGE("Failed to remove restrictions by network interface %s\n", //LCOV_EXCL_LINE sqlite3_errmsg(stc_db_get_database())); - error_code = STC_ERROR_DB_FAILED; - goto handle_error; + error_code = STC_ERROR_DB_FAILED; //LCOV_EXCL_LINE + goto handle_error; //LCOV_EXCL_LINE } STC_LOGD("Restriction deleted for app_id [%s]", app_id); @@ -491,7 +491,7 @@ stc_error_e __get_restriction_id(table_restrictions_info *info) break; case SQLITE_ERROR: default: - STC_LOGE("Failed to get restriction id: %s\n", + STC_LOGE("Failed to get restriction id: %s\n", //LCOV_EXCL_LINE sqlite3_errmsg(stc_db_get_database())); } @@ -507,8 +507,8 @@ stc_error_e table_restrictions_update(table_restrictions_info *info) sqlite3_stmt *stmt = insert_net_restrictions; if (!info) { - error_code = STC_ERROR_INVALID_PARAMETER; - goto handle_error; + error_code = STC_ERROR_INVALID_PARAMETER; //LCOV_EXCL_LINE + goto handle_error; //LCOV_EXCL_LINE } __get_restriction_id(info); @@ -531,10 +531,10 @@ stc_error_e table_restrictions_update(table_restrictions_info *info) DB_ACTION(sqlite3_bind_int64(stmt, 9, info->restriction_id)); if (sqlite3_step(stmt) != SQLITE_DONE) { - STC_LOGE("Failed to set network restriction: %s\n", + STC_LOGE("Failed to set network restriction: %s\n", //LCOV_EXCL_LINE sqlite3_errmsg(stc_db_get_database())); - error_code = STC_ERROR_DB_FAILED; - goto handle_error; + error_code = STC_ERROR_DB_FAILED; //LCOV_EXCL_LINE + goto handle_error; //LCOV_EXCL_LINE } if (info->restriction_id) { @@ -556,8 +556,8 @@ stc_error_e table_restrictions_prepare(sqlite3 *db) stc_error_e error_code = STC_ERROR_NONE; if (db == NULL) { - __STC_LOG_FUNC_EXIT__; - return STC_ERROR_FAIL; + __STC_LOG_FUNC_EXIT__; //LCOV_EXCL_LINE + return STC_ERROR_FAIL; //LCOV_EXCL_LINE } DB_ACTION(__prepare_delete(db)); diff --git a/src/database/tables/table-statistics.c b/src/database/tables/table-statistics.c index c14fdb6..49856b4 100755 --- a/src/database/tables/table-statistics.c +++ b/src/database/tables/table-statistics.c @@ -223,8 +223,8 @@ static int __prepare_delete(sqlite3 *db) static int initialized; if (initialized) { - __STC_LOG_FUNC_EXIT__; - return SQLITE_OK; + __STC_LOG_FUNC_EXIT__; //LCOV_EXCL_LINE + return SQLITE_OK; //LCOV_EXCL_LINE } PREPARE_DELETE(delete_query[0], DELETE_ALL); @@ -256,8 +256,8 @@ static int __prepare_select(sqlite3 *db) static int initialized; if (initialized) { - __STC_LOG_FUNC_EXIT__; - return SQLITE_OK; + __STC_LOG_FUNC_EXIT__; //LCOV_EXCL_LINE + return SQLITE_OK; //LCOV_EXCL_LINE } PREPARE_SELECT(select_for_period, SELECT_FOR_PERIOD); @@ -305,8 +305,8 @@ static int __prepare_insert(sqlite3 *db) static int initialized; if (initialized) { - __STC_LOG_FUNC_EXIT__; - return SQLITE_OK; + __STC_LOG_FUNC_EXIT__; //LCOV_EXCL_LINE + return SQLITE_OK; //LCOV_EXCL_LINE } PREPARE_INSERT(update_statistics_query, INSERT_VALUES); @@ -360,6 +360,7 @@ static sqlite3_stmt *__select_statement(const char *app_id, return *details_stms[stm_index]; } +//LCOV_EXCL_START stc_error_e table_statistics_reset_first_n_entries(int num) { __STC_LOG_FUNC_ENTER__; @@ -381,18 +382,19 @@ handle_error: sqlite3_reset(delete_query[4]); return error_code; } +//LCOV_EXCL_STOP stc_error_e table_statistics_reset(const table_statistics_reset_rule *rule) { __STC_LOG_FUNC_ENTER__; sqlite3_stmt *stmt; stc_error_e error_code = STC_ERROR_NONE; - int pos = 1;/* running through positions where to + int pos = 1; /* running through positions where to bind parameters in the query */ if (!rule || !rule->interval) { - __STC_LOG_FUNC_EXIT__; - return STC_ERROR_INVALID_PARAMETER; + __STC_LOG_FUNC_EXIT__; //LCOV_EXCL_LINE + return STC_ERROR_INVALID_PARAMETER; //LCOV_EXCL_LINE } /* pick a statement depending on parameters. @@ -413,10 +415,10 @@ stc_error_e table_statistics_reset(const table_statistics_reset_rule *rule) DB_ACTION(sqlite3_bind_int64(stmt, pos++, rule->interval->to)); if (sqlite3_step(stmt) != SQLITE_DONE) { - STC_LOGE("Failed to drop collected statistics."); - error_code = STC_ERROR_DB_FAILED; - __STC_LOG_FUNC_EXIT__; - goto handle_error; + STC_LOGE("Failed to drop collected statistics."); //LCOV_EXCL_LINE + error_code = STC_ERROR_DB_FAILED; //LCOV_EXCL_LINE + __STC_LOG_FUNC_EXIT__; //LCOV_EXCL_LINE + goto handle_error; //LCOV_EXCL_LINE } STC_LOGD("Entry deleted successfully."); @@ -441,8 +443,8 @@ stc_error_e table_statistics_foreach_app(const table_statistics_select_rule *rul memset(&data, 0, sizeof(data)); if (!rule || !info_cb) { - __STC_LOG_FUNC_EXIT__; - return STC_ERROR_INVALID_PARAMETER; + __STC_LOG_FUNC_EXIT__; //LCOV_EXCL_LINE + return STC_ERROR_INVALID_PARAMETER; //LCOV_EXCL_LINE } /* pick a statement depending on parameters */ @@ -485,7 +487,7 @@ stc_error_e table_statistics_foreach_app(const table_statistics_select_rule *rul } if (info_cb(&data, user_data) == STC_CANCEL) - rc = SQLITE_DONE;/* emulate end of data */ + rc = SQLITE_DONE; //LCOV_EXCL_LINE __STC_LOG_FUNC_EXIT__; break; case SQLITE_DONE: @@ -493,9 +495,9 @@ stc_error_e table_statistics_foreach_app(const table_statistics_select_rule *rul break; case SQLITE_ERROR: default: - error_code = STC_ERROR_DB_FAILED; - __STC_LOG_FUNC_EXIT__; - break; + error_code = STC_ERROR_DB_FAILED; //LCOV_EXCL_LINE + __STC_LOG_FUNC_EXIT__; //LCOV_EXCL_LINE + break; //LCOV_EXCL_LINE } } while (rc == SQLITE_ROW); @@ -515,15 +517,15 @@ stc_error_e table_statistics_per_app(const char *app_id, sqlite3_stmt *stmt; stc_error_e error_code = STC_ERROR_NONE; int rc; - int pos = 1;/* running through positions + int pos = 1; /* running through positions where to bind parameters in the query */ stc_db_tm_interval_s interval; memset(&data, 0, sizeof(data)); if (!rule || !info_cb) { - __STC_LOG_FUNC_EXIT__; - return STC_ERROR_INVALID_PARAMETER; + __STC_LOG_FUNC_EXIT__; //LCOV_EXCL_LINE + return STC_ERROR_INVALID_PARAMETER; //LCOV_EXCL_LINE } /* pick a statement depending on parameters. @@ -566,7 +568,7 @@ stc_error_e table_statistics_per_app(const char *app_id, } if (info_cb(&data, user_data) == STC_CANCEL) - rc = SQLITE_DONE; /* emulate end of data */ + rc = SQLITE_DONE; //LCOV_EXCL_LINE __STC_LOG_FUNC_EXIT__; break; case SQLITE_DONE: @@ -574,9 +576,9 @@ stc_error_e table_statistics_per_app(const char *app_id, break; case SQLITE_ERROR: default: - error_code = STC_ERROR_DB_FAILED; - __STC_LOG_FUNC_EXIT__; - break; + error_code = STC_ERROR_DB_FAILED; //LCOV_EXCL_LINE + __STC_LOG_FUNC_EXIT__; //LCOV_EXCL_LINE + break; //LCOV_EXCL_LINE } } while (rc == SQLITE_ROW); @@ -619,11 +621,11 @@ stc_error_e table_statistics_insert(stc_db_classid_iftype_key *stat_key, stat->rcv_count = 0; stat->snd_count = 0; if (sqlite3_step(stmt) != SQLITE_DONE) { - STC_LOGE("Failed to record appstat. %s", + STC_LOGE("Failed to record appstat. %s", //LCOV_EXCL_LINE sqlite3_errmsg(stc_db_get_database())); - error_code = STC_ERROR_DB_FAILED; - __STC_LOG_FUNC_EXIT__; - goto handle_error; + error_code = STC_ERROR_DB_FAILED; //LCOV_EXCL_LINE + __STC_LOG_FUNC_EXIT__; //LCOV_EXCL_LINE + goto handle_error; //LCOV_EXCL_LINE } STC_LOGD("App stat recorded [%s]", stat->app_id); @@ -669,8 +671,8 @@ stc_error_e table_statistics_prepare(sqlite3 *db) stc_error_e error_code = STC_ERROR_NONE; if (db == NULL) { - __STC_LOG_FUNC_EXIT__; - return STC_ERROR_DB_FAILED; + __STC_LOG_FUNC_EXIT__; //LCOV_EXCL_LINE + return STC_ERROR_DB_FAILED; //LCOV_EXCL_LINE } DB_ACTION(__prepare_delete(db)); diff --git a/src/helper/helper-cgroup.c b/src/helper/helper-cgroup.c index 8c258a5..dc51231 100755 --- a/src/helper/helper-cgroup.c +++ b/src/helper/helper-cgroup.c @@ -34,7 +34,7 @@ static int cgroup_create(const char *cgroup_full_path) { if (mkdir(cgroup_full_path, S_IRUSR | S_IWUSR | S_IRGRP) < 0) - return -errno; + return -errno; //LCOV_EXCL_LINE return 0; } @@ -49,8 +49,8 @@ stc_error_e cgroup_write_pid_fullpath(const char *cgroup_full_path, int ret; if (pid <= 0) { - STC_LOGE("try to write empty pid to %s", cgroup_full_path); - return STC_ERROR_NO_DATA; + STC_LOGE("try to write empty pid to %s", cgroup_full_path); //LCOV_EXCL_LINE + return STC_ERROR_NO_DATA; //LCOV_EXCL_LINE } ret = cgroup_write_node_uint32(cgroup_full_path, CGROUP_FILE_NAME, @@ -69,6 +69,7 @@ stc_error_e cgroup_write_pid(const char *cgroup_subsystem, return cgroup_write_pid_fullpath(buf, pid); } +//LCOV_EXCL_START stc_error_e cgroup_write_pidtree(const char *cgroup_subsystem, const char *cgroup_name, const int pid) { @@ -110,6 +111,7 @@ stc_error_e cgroup_write_pidtree(const char *cgroup_subsystem, fclose(f); return STC_ERROR_NONE; } +//LCOV_EXCL_STOP int cgroup_write_node_uint32(const char *cgroup_name, const char *file_name, uint32_t value) @@ -118,7 +120,7 @@ int cgroup_write_node_uint32(const char *cgroup_name, snprintf(buf, sizeof(buf), "%s/%s", cgroup_name, file_name); if (STC_DEBUG_LOG) - STC_LOGD("cgroup_buf %s, value %d\n", buf, value); + STC_LOGD("cgroup_buf %s, value %d\n", buf, value); //LCOV_EXCL_LINE return fwrite_uint(buf, value); } @@ -130,7 +132,7 @@ int cgroup_write_node_str(const char *cgroup_name, snprintf(buf, sizeof(buf), "%s/%s", cgroup_name, file_name); if (STC_DEBUG_LOG) - STC_LOGD("cgroup_buf %s, string %s\n", buf, string); + STC_LOGD("cgroup_buf %s, string %s\n", buf, string); //LCOV_EXCL_LINE return fwrite_str(buf, string); } @@ -144,7 +146,7 @@ int cgroup_read_node_uint32(const char *cgroup_name, ret = fread_uint(buf, value); if (STC_DEBUG_LOG) - STC_LOGD("cgroup_buf %s, value %d\n", buf, *value); + STC_LOGD("cgroup_buf %s, value %d\n", buf, *value); //LCOV_EXCL_LINE return ret; } @@ -173,12 +175,12 @@ int cgroup_make_subdir(const char *parentdir, const char *cgroup_name, if (parentdir && !strncmp(parentdir, DEFAULT_CGROUP, sizeof(DEFAULT_CGROUP))) { - ret = mount("tmpfs", DEFAULT_CGROUP, "tmpfs", + ret = mount("tmpfs", DEFAULT_CGROUP, "tmpfs", //LCOV_EXCL_LINE MS_REMOUNT|MS_NOSUID|MS_NOEXEC|MS_NODEV|MS_STRICTATIME, "mode=755"); if (ret < 0) { - STC_LOGE("Fail to RW mount cgroup directory. Can't make %s cgroup", cgroup_name); - return STC_ERROR_FAIL; + STC_LOGE("Fail to RW mount cgroup directory. Can't make %s cgroup", cgroup_name); //LCOV_EXCL_LINE + return STC_ERROR_FAIL; //LCOV_EXCL_LINE } cgroup_remount = true; } @@ -189,11 +191,11 @@ int cgroup_make_subdir(const char *parentdir, const char *cgroup_name, cgroup_name, errno); if (cgroup_remount) { - ret = mount("tmpfs", DEFAULT_CGROUP, "tmpfs", + ret = mount("tmpfs", DEFAULT_CGROUP, "tmpfs", //LCOV_EXCL_LINE MS_REMOUNT|MS_NOSUID|MS_NOEXEC|MS_NODEV|MS_STRICTATIME|MS_RDONLY, "mode=755"); if (ret < 0) - STC_LOGD("Fail to RO mount"); + STC_LOGD("Fail to RO mount"); //LCOV_EXCL_LINE } } diff --git a/src/helper/helper-iptables.c b/src/helper/helper-iptables.c index 96eacb8..06b9378 100755 --- a/src/helper/helper-iptables.c +++ b/src/helper/helper-iptables.c @@ -44,7 +44,7 @@ static void __add_rule_info_to_builder(GVariantBuilder *builder, iptables_rule_s *rule) { if (builder == NULL || rule == NULL) - return; + return; //LCOV_EXCL_LINE g_variant_builder_add(builder, "{sv}", RULE_CHAIN, g_variant_new_string(rule->chain)); @@ -91,8 +91,8 @@ static int __iptables_rule_add(GDBusConnection *connection, params); if (message == NULL) { - STC_LOGE("Failed to invoke dbus method"); - return STC_ERROR_FAIL; + STC_LOGE("Failed to invoke dbus method"); //LCOV_EXCL_LINE + return STC_ERROR_FAIL; //LCOV_EXCL_LINE } g_variant_get(message, "(i)", &result); @@ -123,8 +123,8 @@ static int __iptables_rule_remove(GDBusConnection *connection, params); if (message == NULL) { - STC_LOGE("Failed to invoke dbus method"); - return STC_ERROR_FAIL; + STC_LOGE("Failed to invoke dbus method"); //LCOV_EXCL_LINE + return STC_ERROR_FAIL; //LCOV_EXCL_LINE } g_variant_get(message, "(i)", &result); @@ -155,8 +155,8 @@ static int __ip6tables_rule_add(GDBusConnection *connection, params); if (message == NULL) { - STC_LOGE("Failed to invoke dbus method"); - return STC_ERROR_FAIL; + STC_LOGE("Failed to invoke dbus method"); //LCOV_EXCL_LINE + return STC_ERROR_FAIL; //LCOV_EXCL_LINE } g_variant_get(message, "(i)", &result); @@ -187,8 +187,8 @@ static int __ip6tables_rule_remove(GDBusConnection *connection, params); if (message == NULL) { - STC_LOGE("Failed to invoke dbus method"); - return STC_ERROR_FAIL; + STC_LOGE("Failed to invoke dbus method"); //LCOV_EXCL_LINE + return STC_ERROR_FAIL; //LCOV_EXCL_LINE } g_variant_get(message, "(i)", &result); @@ -212,8 +212,8 @@ static int __iptables_add_chain(GDBusConnection *connection, g_variant_new("(s)", chain)); if (message == NULL) { - STC_LOGE("Failed to invoke dbus method"); - return STC_ERROR_FAIL; + STC_LOGE("Failed to invoke dbus method"); //LCOV_EXCL_LINE + return STC_ERROR_FAIL; //LCOV_EXCL_LINE } g_variant_get(message, "(i)", &result); @@ -237,8 +237,8 @@ static int __ip6tables_add_chain(GDBusConnection *connection, g_variant_new("(s)", chain)); if (message == NULL) { - STC_LOGE("Failed to invoke dbus method"); - return STC_ERROR_FAIL; + STC_LOGE("Failed to invoke dbus method"); //LCOV_EXCL_LINE + return STC_ERROR_FAIL; //LCOV_EXCL_LINE } g_variant_get(message, "(i)", &result); @@ -262,8 +262,8 @@ static int __iptables_remove_chain(GDBusConnection *connection, g_variant_new("(s)", chain)); if (message == NULL) { - STC_LOGE("Failed to invoke dbus method"); - return STC_ERROR_FAIL; + STC_LOGE("Failed to invoke dbus method"); //LCOV_EXCL_LINE + return STC_ERROR_FAIL; //LCOV_EXCL_LINE } g_variant_get(message, "(i)", &result); @@ -287,8 +287,8 @@ static int __ip6tables_remove_chain(GDBusConnection *connection, g_variant_new("(s)", chain)); if (message == NULL) { - STC_LOGE("Failed to invoke dbus method"); - return STC_ERROR_FAIL; + STC_LOGE("Failed to invoke dbus method"); //LCOV_EXCL_LINE + return STC_ERROR_FAIL; //LCOV_EXCL_LINE } g_variant_get(message, "(i)", &result); @@ -312,8 +312,8 @@ static int __iptables_flush_chain(GDBusConnection *connection, g_variant_new("(s)", chain)); if (message == NULL) { - STC_LOGE("Failed to invoke dbus method"); - return STC_ERROR_FAIL; + STC_LOGE("Failed to invoke dbus method"); //LCOV_EXCL_LINE + return STC_ERROR_FAIL; //LCOV_EXCL_LINE } g_variant_get(message, "(i)", &result); @@ -337,8 +337,8 @@ static int __ip6tables_flush_chain(GDBusConnection *connection, g_variant_new("(s)", chain)); if (message == NULL) { - STC_LOGE("Failed to invoke dbus method"); - return STC_ERROR_FAIL; + STC_LOGE("Failed to invoke dbus method"); //LCOV_EXCL_LINE + return STC_ERROR_FAIL; //LCOV_EXCL_LINE } g_variant_get(message, "(i)", &result); @@ -372,11 +372,11 @@ stc_error_e iptables_add(iptables_rule_s *rule) stc_s *stc = stc_get_manager(); if (!stc || !stc->connection) - return STC_ERROR_INVALID_PARAMETER; + return STC_ERROR_INVALID_PARAMETER; //LCOV_EXCL_LINE ret = __iptables_rule_add(stc->connection, rule); if (ret != STC_ERROR_NONE) - goto done; + goto done; //LCOV_EXCL_LINE ret = __ip6tables_rule_add(stc->connection, rule); done: @@ -389,11 +389,11 @@ stc_error_e iptables_remove(iptables_rule_s *rule) stc_s *stc = stc_get_manager(); if (!stc || !stc->connection) - return STC_ERROR_INVALID_PARAMETER; + return STC_ERROR_INVALID_PARAMETER; //LCOV_EXCL_LINE ret = __iptables_rule_remove(stc->connection, rule); if (ret != STC_ERROR_NONE) - goto done; + goto done; //LCOV_EXCL_LINE ret = __ip6tables_rule_remove(stc->connection, rule); done: @@ -406,27 +406,27 @@ stc_error_e iptables_flush_chains(void) stc_s *stc = stc_get_manager(); if (!stc || !stc->connection) - return STC_ERROR_INVALID_PARAMETER; + return STC_ERROR_INVALID_PARAMETER; //LCOV_EXCL_LINE ret = __iptables_flush_chain(stc->connection, STC_IN_CHAIN); if (ret != STC_ERROR_NONE) - goto done; + goto done; //LCOV_EXCL_LINE ret = __iptables_flush_chain(stc->connection, STC_OUT_CHAIN); if (ret != STC_ERROR_NONE) - goto done; + goto done; //LCOV_EXCL_LINE ret = __iptables_flush_chain(stc->connection, STC_FRWD_CHAIN); if (ret != STC_ERROR_NONE) - goto done; + goto done; //LCOV_EXCL_LINE ret = __ip6tables_flush_chain(stc->connection, STC_IN_CHAIN); if (ret != STC_ERROR_NONE) - goto done; + goto done; //LCOV_EXCL_LINE ret = __ip6tables_flush_chain(stc->connection, STC_OUT_CHAIN); if (ret != STC_ERROR_NONE) - goto done; + goto done; //LCOV_EXCL_LINE ret = __ip6tables_flush_chain(stc->connection, STC_FRWD_CHAIN); done: @@ -441,56 +441,56 @@ stc_error_e iptables_init(void) stc_s *stc = stc_get_manager(); if (!stc || !stc->connection) { - __STC_LOG_FUNC_EXIT__; - return STC_ERROR_INVALID_PARAMETER; + __STC_LOG_FUNC_EXIT__; //LCOV_EXCL_LINE + return STC_ERROR_INVALID_PARAMETER; //LCOV_EXCL_LINE } ret = __iptables_add_chain(stc->connection, STC_IN_CHAIN); if (ret != STC_ERROR_NONE) { - __STC_LOG_FUNC_EXIT__; - goto done; + __STC_LOG_FUNC_EXIT__; //LCOV_EXCL_LINE + goto done; //LCOV_EXCL_LINE } ret = __iptables_add_chain(stc->connection, STC_OUT_CHAIN); if (ret != STC_ERROR_NONE) { - __STC_LOG_FUNC_EXIT__; - goto done; + __STC_LOG_FUNC_EXIT__; //LCOV_EXCL_LINE + goto done; //LCOV_EXCL_LINE } ret = __iptables_add_chain(stc->connection, STC_FRWD_CHAIN); if (ret != STC_ERROR_NONE) { - __STC_LOG_FUNC_EXIT__; - goto done; + __STC_LOG_FUNC_EXIT__; //LCOV_EXCL_LINE + goto done; //LCOV_EXCL_LINE } ret = __ip6tables_add_chain(stc->connection, STC_IN_CHAIN); if (ret != STC_ERROR_NONE) { - __STC_LOG_FUNC_EXIT__; - goto done; + __STC_LOG_FUNC_EXIT__; //LCOV_EXCL_LINE + goto done; //LCOV_EXCL_LINE } ret = __ip6tables_add_chain(stc->connection, STC_OUT_CHAIN); if (ret != STC_ERROR_NONE) { - __STC_LOG_FUNC_EXIT__; - goto done; + __STC_LOG_FUNC_EXIT__; //LCOV_EXCL_LINE + goto done; //LCOV_EXCL_LINE } ret = __ip6tables_add_chain(stc->connection, STC_FRWD_CHAIN); if (ret != STC_ERROR_NONE) { - __STC_LOG_FUNC_EXIT__; - goto done; + __STC_LOG_FUNC_EXIT__; //LCOV_EXCL_LINE + goto done; //LCOV_EXCL_LINE } ret = __iptables_add_chain_jump_rule("INPUT", STC_IN_CHAIN); if (ret != STC_ERROR_NONE) { - __STC_LOG_FUNC_EXIT__; - goto done; + __STC_LOG_FUNC_EXIT__; //LCOV_EXCL_LINE + goto done; //LCOV_EXCL_LINE } ret = __iptables_add_chain_jump_rule("OUTPUT", STC_OUT_CHAIN); if (ret != STC_ERROR_NONE) { - __STC_LOG_FUNC_EXIT__; - goto done; + __STC_LOG_FUNC_EXIT__; //LCOV_EXCL_LINE + goto done; //LCOV_EXCL_LINE } ret = __iptables_add_chain_jump_rule("FORWARD", STC_FRWD_CHAIN); @@ -506,38 +506,38 @@ stc_error_e iptables_deinit(void) stc_s *stc = stc_get_manager(); if (!stc || !stc->connection) { - __STC_LOG_FUNC_EXIT__; - return STC_ERROR_INVALID_PARAMETER; + __STC_LOG_FUNC_EXIT__; //LCOV_EXCL_LINE + return STC_ERROR_INVALID_PARAMETER; //LCOV_EXCL_LINE } ret = __iptables_remove_chain(stc->connection, STC_IN_CHAIN); if (ret != STC_ERROR_NONE) { - __STC_LOG_FUNC_EXIT__; - goto done; + __STC_LOG_FUNC_EXIT__; //LCOV_EXCL_LINE + goto done; //LCOV_EXCL_LINE } ret = __iptables_remove_chain(stc->connection, STC_OUT_CHAIN); if (ret != STC_ERROR_NONE) { - __STC_LOG_FUNC_EXIT__; - goto done; + __STC_LOG_FUNC_EXIT__; //LCOV_EXCL_LINE + goto done; //LCOV_EXCL_LINE } ret = __iptables_remove_chain(stc->connection, STC_FRWD_CHAIN); if (ret != STC_ERROR_NONE) { - __STC_LOG_FUNC_EXIT__; - goto done; + __STC_LOG_FUNC_EXIT__; //LCOV_EXCL_LINE + goto done; //LCOV_EXCL_LINE } ret = __ip6tables_remove_chain(stc->connection, STC_IN_CHAIN); if (ret != STC_ERROR_NONE) { - __STC_LOG_FUNC_EXIT__; - goto done; + __STC_LOG_FUNC_EXIT__; //LCOV_EXCL_LINE + goto done; //LCOV_EXCL_LINE } ret = __ip6tables_remove_chain(stc->connection, STC_OUT_CHAIN); if (ret != STC_ERROR_NONE) { - __STC_LOG_FUNC_EXIT__; - goto done; + __STC_LOG_FUNC_EXIT__; //LCOV_EXCL_LINE + goto done; //LCOV_EXCL_LINE } ret = __ip6tables_remove_chain(stc->connection, STC_FRWD_CHAIN); diff --git a/src/helper/helper-net-cls.c b/src/helper/helper-net-cls.c index 6be717a..c1460dc 100755 --- a/src/helper/helper-net-cls.c +++ b/src/helper/helper-net-cls.c @@ -36,7 +36,7 @@ static uint32_t __produce_classid(check_classid_used_cb check_classid_cb) uint32_t classid = STC_RESERVED_CLASSID_MAX; int ret = fread_uint(CUR_CLASSID_PATH, &classid); if (ret < 0) - STC_LOGI("Can not read current classid"); + STC_LOGI("Can not read current classid"); //LCOV_EXCL_LINE classid += 1; @@ -51,7 +51,7 @@ static uint32_t __produce_classid(check_classid_used_cb check_classid_cb) ret = fwrite_uint(CUR_CLASSID_PATH, ++classid); if (ret < 0) - STC_LOGE("Can not write classid"); + STC_LOGE("Can not write classid"); //LCOV_EXCL_LINE return classid; } @@ -81,7 +81,7 @@ static uint32_t __get_classid_from_cgroup(const char *cgroup, int ret = cgroup_read_node_uint32(buf, CLASSID_FILE_NAME, &classid); if (ret < 0) - STC_LOGE("Can't read classid from cgroup %s", buf); + STC_LOGE("Can't read classid from cgroup %s", buf); //LCOV_EXCL_LINE return classid; } @@ -94,8 +94,8 @@ stc_error_e init_current_classid(void) uint32_t classid = STC_RESERVED_CLASSID_MAX; ret = fwrite_uint(CUR_CLASSID_PATH, classid); if (ret < 0) { - STC_LOGE("Can not init current classid"); - return STC_ERROR_FAIL; + STC_LOGE("Can not init current classid"); //LCOV_EXCL_LINE + return STC_ERROR_FAIL; //LCOV_EXCL_LINE } } @@ -110,8 +110,8 @@ uint32_t get_classid_by_app_id(const char *app_id, int create) const char *path_to_net_cgroup_dir = NULL; if (app_id == NULL) { - STC_LOGE("app_id must be not empty"); - return STC_UNKNOWN_CLASSID; + STC_LOGE("app_id must be not empty"); //LCOV_EXCL_LINE + return STC_UNKNOWN_CLASSID; //LCOV_EXCL_LINE } if (!strcmp(app_id, STC_BACKGROUND_APP_ID)) @@ -139,7 +139,7 @@ uint32_t get_classid_by_app_id(const char *app_id, int create) /* just read */ if (!create) - classid = __get_classid_from_cgroup(path_to_net_cgroup_dir, + classid = __get_classid_from_cgroup(path_to_net_cgroup_dir, //LCOV_EXCL_LINE app_id); if (classid != STC_UNKNOWN_CLASSID) @@ -157,14 +157,14 @@ uint32_t get_classid_by_app_id(const char *app_id, int create) ret = __place_classid_to_cgroup(path_to_net_cgroup_dir, (char *)app_id, &classid, NULL); if (ret) - goto handle_error; + goto handle_error; //LCOV_EXCL_LINE return classid; handle_error: - STC_LOGE("error_code: [%d]", ret); - return STC_UNKNOWN_CLASSID; + STC_LOGE("error_code: [%d]", ret); //LCOV_EXCL_LINE + return STC_UNKNOWN_CLASSID; //LCOV_EXCL_LINE } stc_error_e place_pids_to_net_cgroup(const int pid, const char *app_id) @@ -175,8 +175,8 @@ stc_error_e place_pids_to_net_cgroup(const int pid, const char *app_id) snprintf(child_buf, sizeof(child_buf), PROC_TASK_CHILDREN, pid, pid); if (app_id == NULL) { - STC_LOGE("package name must be not empty"); - return STC_ERROR_INVALID_PARAMETER; + STC_LOGE("package name must be not empty"); //LCOV_EXCL_LINE + return STC_ERROR_INVALID_PARAMETER; //LCOV_EXCL_LINE } if (!strcmp(app_id, STC_BACKGROUND_APP_ID)) @@ -184,13 +184,13 @@ stc_error_e place_pids_to_net_cgroup(const int pid, const char *app_id) else if (strstr(app_id, STC_BACKGROUND_APP_SUFFIX)) path_to_net_cgroup_dir = BACKGROUND_CGROUP_NETWORK; else - path_to_net_cgroup_dir = FOREGROUND_CGROUP_NETWORK; + path_to_net_cgroup_dir = FOREGROUND_CGROUP_NETWORK; //LCOV_EXCL_LINE if (access(child_buf, F_OK)) { if (STC_DEBUG_LOG) - STC_LOGD("%s of %s is not existed", child_buf, app_id); + STC_LOGD("%s of %s is not existed", child_buf, app_id); //LCOV_EXCL_LINE return cgroup_write_pid(path_to_net_cgroup_dir, app_id, pid); } - return cgroup_write_pidtree(path_to_net_cgroup_dir, app_id, pid); + return cgroup_write_pidtree(path_to_net_cgroup_dir, app_id, pid); //LCOV_EXCL_LINE } diff --git a/src/helper/helper-nfacct-rule.c b/src/helper/helper-nfacct-rule.c index 374090a..8f5dfee 100755 --- a/src/helper/helper-nfacct-rule.c +++ b/src/helper/helper-nfacct-rule.c @@ -135,19 +135,20 @@ static stc_error_e nfacct_send_new(nfacct_rule_s *counter) int ret = STC_ERROR_NONE; struct genl *req = MALLOC0(struct genl, 1); if (req == NULL) { - STC_LOGE("Failed allocate memory to genl request message"); - return STC_ERROR_OUT_OF_MEMORY; + STC_LOGE("Failed allocate memory to genl request message"); //LCOV_EXCL_LINE + return STC_ERROR_OUT_OF_MEMORY; //LCOV_EXCL_LINE } prepare_netlink_msg(req, NFNL_MSG_ACCT_NEW, NLM_F_CREATE | NLM_F_ACK); add_string_attr(req, counter->name, NFACCT_NAME); if (STC_DEBUG_LOG) - STC_LOGD("counter name %s", counter->name); + STC_LOGD("counter name %s", counter->name); //LCOV_EXCL_LINE /* padding */ add_uint64_attr(req, 0, NFACCT_PKTS); add_uint64_attr(req, 0, NFACCT_BYTES); + //LCOV_EXCL_START if (counter->quota) { STC_LOGD("quota bytes %"PRId64, counter->quota); @@ -155,6 +156,7 @@ static stc_error_e nfacct_send_new(nfacct_rule_s *counter) NFACCT_FLAGS); add_uint64_attr(req, htobe64(counter->quota), NFACCT_QUOTA); } + //LCOV_EXCL_STOP ret = send_nfacct_request(counter->carg->sock, req); FREE(req); @@ -166,12 +168,12 @@ stc_error_e nfacct_send_del(nfacct_rule_s *counter) int ret = STC_ERROR_NONE; struct genl *req = MALLOC0(struct genl, 1); if (req == NULL) { - STC_LOGE("Failed allocate memory to genl request message"); - return STC_ERROR_OUT_OF_MEMORY; + STC_LOGE("Failed allocate memory to genl request message"); //LCOV_EXCL_LINE + return STC_ERROR_OUT_OF_MEMORY; //LCOV_EXCL_LINE } if (STC_DEBUG_LOG) - STC_LOGD("send remove request for %s", counter->name); + STC_LOGD("send remove request for %s", counter->name); //LCOV_EXCL_LINE prepare_netlink_msg(req, NFNL_MSG_ACCT_DEL, NLM_F_ACK); add_string_attr(req, counter->name, NFACCT_NAME); @@ -192,8 +194,8 @@ static stc_error_e internal_nfacct_send_get(struct counter_arg *carg, int flag = !name ? NLM_F_DUMP : 0; struct genl *req = MALLOC0(struct genl, 1); if (req == NULL) { - STC_LOGE("Failed allocate memory to genl request message"); - return STC_ERROR_OUT_OF_MEMORY; + STC_LOGE("Failed allocate memory to genl request message"); //LCOV_EXCL_LINE + return STC_ERROR_OUT_OF_MEMORY; //LCOV_EXCL_LINE } prepare_netlink_msg(req, get_type, flag); @@ -278,14 +280,15 @@ bool recreate_counter_by_name(char *cnt_name, nfacct_rule_s *cnt) cnt->intend = NFACCT_BLOCK; break; case 't': - cnt->intend = NFACCT_TETH_COUNTER; - break; + cnt->intend = NFACCT_TETH_COUNTER; //LCOV_EXCL_LINE + break; //LCOV_EXCL_LINE default: return false; } STRING_SAVE_COPY(cnt->name, cnt_name); + //LCOV_EXCL_START if (cnt->intend == NFACCT_TETH_COUNTER) { char ifname_buf[MAX_IFACE_LENGTH]; int ifname_len; @@ -321,6 +324,7 @@ bool recreate_counter_by_name(char *cnt_name, nfacct_rule_s *cnt) cnt->classid = STC_TETHERING_APP_CLASSID; return true; } + //LCOV_EXCL_STOP io_part = strtok_r(name, "_", &save_ptr); if (io_part != NULL) @@ -413,8 +417,8 @@ static char *get_iptables_chain(const nfacct_rule_direction iotype) return STC_IN_CHAIN; else if (iotype == NFACCT_COUNTER_OUT) return STC_OUT_CHAIN; - else if (iotype == NFACCT_COUNTER_FORWARD) - return STC_FRWD_CHAIN; + else if (iotype == NFACCT_COUNTER_FORWARD) //LCOV_EXCL_LINE + return STC_FRWD_CHAIN; //LCOV_EXCL_LINE return ""; } @@ -429,11 +433,13 @@ static char *get_iptables_jump(const nfacct_rule_jump jump) return ""; } +/* static char *choose_iftype_name(nfacct_rule_s *rule) { return strlen(rule->ifname) != 0 ? rule->ifname : get_iftype_name(rule->iftype); } +*/ static stc_error_e exec_iptables_cmd(nfacct_rule_s *rule) { @@ -611,6 +617,7 @@ static stc_error_e produce_iface_rule(nfacct_rule_s *rule) " traffic, for iftype %d, cmd %s, j %s", rule->iftype, set_cmd, jump_cmd); + //LCOV_EXCL_START /* for tethering */ if (rule->intend == NFACCT_WARN || rule->intend == NFACCT_BLOCK) { @@ -635,6 +642,7 @@ static stc_error_e produce_iface_rule(nfacct_rule_s *rule) ret_value_msg_if(ret != STC_ERROR_NONE, ret, "can't del quota counter"); } + //LCOV_EXCL_STOP } if (rule->iotype & NFACCT_COUNTER_OUT) { @@ -668,6 +676,7 @@ static stc_error_e produce_iface_rule(nfacct_rule_s *rule) "engress traffic, for iftype %d, cmd %s, j %s", rule->iftype, set_cmd, jump_cmd); + //LCOV_EXCL_START /* for tethering */ if (rule->intend == NFACCT_WARN || rule->intend == NFACCT_BLOCK) { @@ -691,6 +700,7 @@ static stc_error_e produce_iface_rule(nfacct_rule_s *rule) ret_value_msg_if(ret != STC_ERROR_NONE, ret, "can't del quota counter"); } + //LCOV_EXCL_STOP } return STC_ERROR_NONE; } diff --git a/src/helper/helper-nl.c b/src/helper/helper-nl.c index b43ff2f..a42e565 100755 --- a/src/helper/helper-nl.c +++ b/src/helper/helper-nl.c @@ -34,7 +34,7 @@ int create_netlink(int protocol, uint32_t groups) int sock; sock = socket(PF_NETLINK, SOCK_RAW, protocol); if (sock < 0) - return -EINVAL; + return -EINVAL; //LCOV_EXCL_LINE struct sockaddr_nl src_addr = { 0, }; @@ -42,8 +42,8 @@ int create_netlink(int protocol, uint32_t groups) src_addr.nl_groups = groups; if (bind(sock, (struct sockaddr *)&src_addr, sizeof(src_addr)) < 0) { - close(sock); - return -1; + close(sock); //LCOV_EXCL_LINE + return -1; //LCOV_EXCL_LINE } return sock; @@ -86,16 +86,16 @@ int read_netlink(int sock, void *buf, size_t len) }; ret = recvmsg(sock, &msg, 0); if (ret == -1) - return ret; + return ret; //LCOV_EXCL_LINE if (msg.msg_flags & MSG_TRUNC) { - errno = ENOSPC; - return -1; + errno = ENOSPC; //LCOV_EXCL_LINE + return -1; //LCOV_EXCL_LINE } if (msg.msg_namelen != sizeof(struct sockaddr_nl)) { - errno = EINVAL; - return -1; + errno = EINVAL; //LCOV_EXCL_LINE + return -1; //LCOV_EXCL_LINE } return ret; diff --git a/src/helper/helper-procfs.c b/src/helper/helper-procfs.c index 8710fa2..4cf1bb2 100755 --- a/src/helper/helper-procfs.c +++ b/src/helper/helper-procfs.c @@ -52,11 +52,11 @@ int proc_get_cmdline(pid_t pid, char *cmdline) snprintf(buf, sizeof(buf), "/proc/%d/cmdline", pid); fp = fopen(buf, "r"); if (fp == NULL) - return STC_ERROR_FAIL; + return STC_ERROR_FAIL; //LCOV_EXCL_LINE if (fgets(cmdline_buf, PROC_NAME_MAX-1, fp) == NULL) { - fclose(fp); - return STC_ERROR_FAIL; + fclose(fp); //LCOV_EXCL_LINE + return STC_ERROR_FAIL; //LCOV_EXCL_LINE } fclose(fp); @@ -84,6 +84,7 @@ int proc_get_cmdline(pid_t pid, char *cmdline) return STC_ERROR_NONE; } +//LCOV_EXCL_START pid_t find_pid_from_cmdline(char *cmdline) { pid_t pid = -1, foundpid = -1; @@ -173,6 +174,7 @@ int proc_get_raw_cmdline(pid_t pid, char *buf, int len) snprintf(path, sizeof(path), "/proc/%d/cmdline", pid); return proc_get_data(path, buf, len); } +//LCOV_EXCL_STOP int proc_get_status(pid_t pid, char status[][PROC_BUF_MAX]) { @@ -193,8 +195,8 @@ int proc_get_status(pid_t pid, char status[][PROC_BUF_MAX]) char *saveptr = NULL; if (fgets(status_buf, sizeof(status_buf), fp) == NULL) { - fclose(fp); - return STC_ERROR_FAIL; + fclose(fp); //LCOV_EXCL_LINE + return STC_ERROR_FAIL; //LCOV_EXCL_LINE } if (!updated[PROC_STATUS_NAME] && strstr(status_buf, diff --git a/src/monitor/stc-app-lifecycle.c b/src/monitor/stc-app-lifecycle.c index 1cd8e9d..d02667f 100755 --- a/src/monitor/stc-app-lifecycle.c +++ b/src/monitor/stc-app-lifecycle.c @@ -93,14 +93,15 @@ static proc_value_s * __proc_tree_lookup(const proc_key_s *key) proc_value_s *lookup; if (proc_tree == NULL) { - STC_LOGE("tree is null"); - return NULL; + STC_LOGE("tree is null"); //LCOV_EXCL_LINE + return NULL; //LCOV_EXCL_LINE } lookup = g_tree_lookup(proc_tree, key); return lookup; } +//LCOV_EXCL_START static gboolean __proc_tree_foreach_print(gpointer key, gpointer value, gpointer data) { @@ -113,10 +114,11 @@ static gboolean __proc_tree_foreach_print(gpointer key, gpointer value, return FALSE; } +//LCOV_EXCL_STOP static void __proc_tree_printall(void) { - g_tree_foreach(proc_tree, __proc_tree_foreach_print, NULL); + g_tree_foreach(proc_tree, __proc_tree_foreach_print, NULL); //LCOV_EXCL_LINE } static proc_value_s * __proc_tree_find_parent(proc_value_s *value) @@ -133,8 +135,8 @@ static proc_value_s * __proc_tree_find_parent(proc_value_s *value) } while (lookup); if (STC_DEBUG_LOG) { - if (parent != NULL) - STC_LOGD("\033[0;35mPARENT\033[0;m: tgid[\033[1;33m%s\033[0;m] pid[%s] " + if (parent != NULL) //LCOV_EXCL_LINE + STC_LOGD("\033[0;35mPARENT\033[0;m: tgid[\033[1;33m%s\033[0;m] pid[%s] " //LCOV_EXCL_LINE "ppid[\033[1;35m%s\033[0;m] cmdline[\033[0;34m%s\033[0;m] name[%s]", parent->status[PROC_STATUS_TGID], parent->status[PROC_STATUS_PID], parent->status[PROC_STATUS_PPID], parent->cmdline, @@ -151,14 +153,14 @@ static void __proc_tree_add(proc_key_s *key, proc_value_s *parent; if (proc_tree == NULL) { - STC_LOGE("tree is null"); - return; + STC_LOGE("tree is null"); //LCOV_EXCL_LINE + return; //LCOV_EXCL_LINE } lookup = g_tree_lookup(proc_tree, key); if (lookup) { if (STC_DEBUG_LOG) - STC_LOGD("LOOKUP: tgid[\033[1;33m%s\033[0;m] pid[%s] ppid[\033[1;35m%s\033[0;m] " + STC_LOGD("LOOKUP: tgid[\033[1;33m%s\033[0;m] pid[%s] ppid[\033[1;35m%s\033[0;m] " //LCOV_EXCL_LINE "cmdline[\033[0;34m%s\033[0;m] name[%s]", lookup->status[PROC_STATUS_TGID], lookup->status[PROC_STATUS_PID], lookup->status[PROC_STATUS_PPID], lookup->cmdline, lookup->status[PROC_STATUS_NAME]); @@ -185,8 +187,8 @@ static void __proc_tree_add(proc_key_s *key, static void __proc_tree_remove(const proc_key_s *key) { if (proc_tree == NULL) { - STC_LOGE("tree is null"); - return; + STC_LOGE("tree is null"); //LCOV_EXCL_LINE + return; //LCOV_EXCL_LINE } stc_manager_app_status_changed(STC_CMD_SET_TERMINATED, key->pid, NULL, @@ -195,7 +197,7 @@ static void __proc_tree_remove(const proc_key_s *key) g_tree_remove(proc_tree, key); if (STC_DEBUG_LOG) - __proc_tree_printall(); + __proc_tree_printall(); //LCOV_EXCL_LINE } static gboolean __check_excn(char *cmdline) @@ -218,26 +220,26 @@ static void __open_nl_connector_sock(void) GIOChannel *gio = NULL; if (nl_connector_sock != -1 && - nl_connector_gsource_id != 0) { - STC_LOGE("Socket is already open"); - __STC_LOG_FUNC_EXIT__; - return; + nl_connector_gsource_id != 0) { //LCOV_EXCL_LINE + STC_LOGE("Socket is already open"); //LCOV_EXCL_LINE + __STC_LOG_FUNC_EXIT__; //LCOV_EXCL_LINE + return; //LCOV_EXCL_LINE } if (nl_connector_sock != -1) { - close(nl_connector_sock); - nl_connector_sock = -1; + close(nl_connector_sock); //LCOV_EXCL_LINE + nl_connector_sock = -1; //LCOV_EXCL_LINE } if (nl_connector_gsource_id != 0) { - g_source_remove(nl_connector_gsource_id); - nl_connector_gsource_id = 0; + g_source_remove(nl_connector_gsource_id); //LCOV_EXCL_LINE + nl_connector_gsource_id = 0; //LCOV_EXCL_LINE } nl_connector_sock = create_netlink(NETLINK_CONNECTOR, CN_IDX_PROC); if (nl_connector_sock == -1) { - __STC_LOG_FUNC_EXIT__; - return; + __STC_LOG_FUNC_EXIT__; //LCOV_EXCL_LINE + return; //LCOV_EXCL_LINE } gio = g_io_channel_unix_new(nl_connector_sock); @@ -266,10 +268,11 @@ static void __close_nl_connector_sock(void) static void __reopen_nl_connector_sock(void) { - __close_nl_connector_sock(); - __open_nl_connector_sock(); + __close_nl_connector_sock(); //LCOV_EXCL_LINE + __open_nl_connector_sock(); //LCOV_EXCL_LINE } +//LCOV_EXCL_START stc_error_e stc_manager_app_status_changed(stc_cmd_type_e cmd, pid_t pid, const gchar *app_id, @@ -389,6 +392,7 @@ stc_error_e stc_manager_app_status_changed(stc_cmd_type_e cmd, return ret; } +//LCOV_EXCL_STOP static void __process_event_fork(int tgid, int pid) { @@ -402,7 +406,7 @@ static void __process_event_fork(int tgid, int pid) if (__check_excn(cmdline)) { if (STC_DEBUG_LOG) - STC_LOGD("[%s] monitoring is excepted", cmdline); + STC_LOGD("[%s] monitoring is excepted", cmdline); //LCOV_EXCL_LINE return; } @@ -412,15 +416,15 @@ static void __process_event_fork(int tgid, int pid) key = MALLOC0(proc_key_s, 1); if (key == NULL) { - STC_LOGE("memory allocation failed"); - return; + STC_LOGE("memory allocation failed"); //LCOV_EXCL_LINE + return; //LCOV_EXCL_LINE } value = MALLOC0(proc_value_s, 1); if (value == NULL) { - STC_LOGE("memory allocation failed"); - FREE(key); - return; + STC_LOGE("memory allocation failed"); //LCOV_EXCL_LINE + FREE(key); //LCOV_EXCL_LINE + return; //LCOV_EXCL_LINE } key->pid = tgid; @@ -429,9 +433,9 @@ static void __process_event_fork(int tgid, int pid) g_strlcpy(value->cmdline, cmdline, sizeof(value->cmdline)); if (STC_DEBUG_LOG) { - STC_LOGD("\033[1;34mFORK\033[0;m: tgid[\033[1;33m%d\033[0;m] ppid=[\033[1;35m%s\033[0;m] " + STC_LOGD("\033[1;34mFORK\033[0;m: tgid[\033[1;33m%d\033[0;m] ppid=[\033[1;35m%s\033[0;m] " //LCOV_EXCL_LINE "cmdline[\033[0;34m%s\033[0;m] pid[%d]", tgid, status[PROC_STATUS_PPID], cmdline, pid); - STC_LOGD("STATUS: tgid[%s] pid[%s] ppid[%s] name[%s] state[%s] tracerpid[%s]", + STC_LOGD("STATUS: tgid[%s] pid[%s] ppid[%s] name[%s] state[%s] tracerpid[%s]", //LCOV_EXCL_LINE status[PROC_STATUS_TGID], status[PROC_STATUS_PID], status[PROC_STATUS_PPID], status[PROC_STATUS_NAME], status[PROC_STATUS_STATE], status[PROC_STATUS_TRACERPID]); } @@ -452,7 +456,7 @@ static void __process_event_exec(int tgid, int pid) if (__check_excn(cmdline)) { if (STC_DEBUG_LOG) - STC_LOGD("[%s] monitoring is excepted", cmdline); + STC_LOGD("[%s] monitoring is excepted", cmdline); //LCOV_EXCL_LINE return; } @@ -462,15 +466,15 @@ static void __process_event_exec(int tgid, int pid) key = MALLOC0(proc_key_s, 1); if (key == NULL) { - STC_LOGE("memory allocation failed"); - return; + STC_LOGE("memory allocation failed"); //LCOV_EXCL_LINE + return; //LCOV_EXCL_LINE } value = MALLOC0(proc_value_s, 1); if (value == NULL) { - STC_LOGE("memory allocation failed"); - FREE(key); - return; + STC_LOGE("memory allocation failed"); //LCOV_EXCL_LINE + FREE(key); //LCOV_EXCL_LINE + return; //LCOV_EXCL_LINE } key->pid = tgid; @@ -479,9 +483,9 @@ static void __process_event_exec(int tgid, int pid) g_strlcpy(value->cmdline, cmdline, sizeof(value->cmdline)); if (STC_DEBUG_LOG) { - STC_LOGD("\033[1;32mEXEC\033[0;m: tgid[\033[1;33m%d\033[0;m] ppid=[\033[1;35m%s\033[0;m] " + STC_LOGD("\033[1;32mEXEC\033[0;m: tgid[\033[1;33m%d\033[0;m] ppid=[\033[1;35m%s\033[0;m] " //LCOV_EXCL_LINE "cmdline[\033[0;34m%s\033[0;m] pid[%d]", tgid, status[PROC_STATUS_PPID], cmdline, pid); - STC_LOGD("STATUS: tgid[%s] pid[%s] ppid[%s] name[%s] state[%s] tracerpid[%s]", + STC_LOGD("STATUS: tgid[%s] pid[%s] ppid[%s] name[%s] state[%s] tracerpid[%s]", //LCOV_EXCL_LINE status[PROC_STATUS_TGID], status[PROC_STATUS_PID], status[PROC_STATUS_PPID], status[PROC_STATUS_NAME], status[PROC_STATUS_STATE], status[PROC_STATUS_TRACERPID]); } @@ -504,7 +508,7 @@ static void __process_event_exit(int tgid, int pid, int exit_code) return; if (STC_DEBUG_LOG) - STC_LOGD("\033[1;31mEXIT\033[0;m: tgid[\033[1;33m%d\033[0;m] " + STC_LOGD("\033[1;31mEXIT\033[0;m: tgid[\033[1;33m%d\033[0;m] " //LCOV_EXCL_LINE "pid[%d] exitcode[\033[0;31m%d\033[0;m]", tgid, pid, exit_code); __proc_tree_remove(&key); @@ -522,21 +526,21 @@ static gboolean __process_nl_connector_message(GIOChannel *source, (condition & G_IO_NVAL)) { /* G_IO_ERR/G_IO_HUP/G_IO_NVAL received */ - STC_LOGE("Netlink Connector socket received G_IO event, closing" + STC_LOGE("Netlink Connector socket received G_IO event, closing" //LCOV_EXCL_LINE " socket. G_IO_ERR [%d], G_IO_HUP [%d], G_IO_NVAL [%s]", (condition & G_IO_ERR), (condition & G_IO_HUP), (condition & G_IO_NVAL)); - __reopen_nl_connector_sock(); - __STC_LOG_FUNC_EXIT__; - return FALSE; + __reopen_nl_connector_sock(); //LCOV_EXCL_LINE + __STC_LOG_FUNC_EXIT__; //LCOV_EXCL_LINE + return FALSE; //LCOV_EXCL_LINE } memset(&msg, 0, sizeof(nl_connector_proc_event_s)); ret = read(sock, &msg, sizeof(nl_connector_proc_event_s)); if (ret == 0) { - __STC_LOG_FUNC_EXIT__; - return TRUE; + __STC_LOG_FUNC_EXIT__; //LCOV_EXCL_LINE + return TRUE; //LCOV_EXCL_LINE } switch (msg.proc_ev.what) { @@ -568,8 +572,8 @@ static int __subscribe_proc_events(void) int sock = nl_connector_sock; if (sock == -1) { - __STC_LOG_FUNC_EXIT__; - return -1; + __STC_LOG_FUNC_EXIT__; //LCOV_EXCL_LINE + return -1; //LCOV_EXCL_LINE } memset(&msg, 0, sizeof(nl_connector_msg_s)); @@ -586,9 +590,9 @@ static int __subscribe_proc_events(void) ret = send(sock, &msg, sizeof(nl_connector_msg_s), 0); if (ret == -1) { - STC_LOGE("Error sending netlink connector message"); - __STC_LOG_FUNC_EXIT__; - return -1; + STC_LOGE("Error sending netlink connector message"); //LCOV_EXCL_LINE + __STC_LOG_FUNC_EXIT__; //LCOV_EXCL_LINE + return -1; //LCOV_EXCL_LINE } __STC_LOG_FUNC_EXIT__; @@ -603,8 +607,8 @@ static int __unsubscribe_proc_events(void) int sock = nl_connector_sock; if (sock == -1) { - __STC_LOG_FUNC_EXIT__; - return -1; + __STC_LOG_FUNC_EXIT__; //LCOV_EXCL_LINE + return -1; //LCOV_EXCL_LINE } memset(&msg, 0, sizeof(nl_connector_msg_s)); @@ -621,9 +625,9 @@ static int __unsubscribe_proc_events(void) ret = send(sock, &msg, sizeof(nl_connector_msg_s), 0); if (ret == -1) { - STC_LOGE("Error sending netlink connector message"); - __STC_LOG_FUNC_EXIT__; - return -1; + STC_LOGE("Error sending netlink connector message"); //LCOV_EXCL_LINE + __STC_LOG_FUNC_EXIT__; //LCOV_EXCL_LINE + return -1; //LCOV_EXCL_LINE } __STC_LOG_FUNC_EXIT__; @@ -650,8 +654,8 @@ void stc_app_lifecycle_monitor_deinit(void) __STC_LOG_FUNC_ENTER__; if (nl_connector_sock == -1) { - STC_LOGE("socket already closed"); - return; + STC_LOGE("socket already closed"); //LCOV_EXCL_LINE + return; //LCOV_EXCL_LINE } __unsubscribe_proc_events(); diff --git a/src/monitor/stc-default-connection.c b/src/monitor/stc-default-connection.c index aa8e1e6..9a43408 100755 --- a/src/monitor/stc-default-connection.c +++ b/src/monitor/stc-default-connection.c @@ -59,19 +59,19 @@ static int __telephony_get_current_sim(void) int current_sim = 0; if (vconf_get_int(VCONFKEY_TELEPHONY_SIM_SLOT_COUNT, &sim_slot_count) != 0) { - STC_LOGD("failed to get sim slot count"); - return -1; + STC_LOGD("failed to get sim slot count"); //LCOV_EXCL_LINE + return -1; //LCOV_EXCL_LINE } if (sim_slot_count == SIM_SLOT_SINGLE) { - STC_LOGD("It's single sim model"); - return current_sim; + STC_LOGD("It's single sim model"); //LCOV_EXCL_LINE + return current_sim; //LCOV_EXCL_LINE } if (vconf_get_int(VCONF_TELEPHONY_DEFAULT_DATA_SERVICE, ¤t_sim) != 0) { - STC_LOGD("failed to get default data service = %d\n", + STC_LOGD("failed to get default data service = %d\n", //LCOV_EXCL_LINE current_sim); - return -1; + return -1; //LCOV_EXCL_LINE } return current_sim; @@ -111,8 +111,8 @@ static void __telephony_get_modem_subscriber_id(GDBusConnection *connection, TELEPHONY_GET_IMSI, NULL); if (message == NULL) { - STC_LOGE("Failed to get services informations"); - goto done; + STC_LOGE("Failed to get services informations"); //LCOV_EXCL_LINE + goto done; //LCOV_EXCL_LINE } DEBUG_PARAMS(message); @@ -122,8 +122,8 @@ static void __telephony_get_modem_subscriber_id(GDBusConnection *connection, msin_len = strlen(msin); if (msin_len + plmn_len >= IMSI_LENGTH) { - STC_LOGD("Incorrect length of mobile subscriber identifier + net id"); - goto done; + STC_LOGD("Incorrect length of mobile subscriber identifier + net id"); //LCOV_EXCL_LINE + goto done; //LCOV_EXCL_LINE } snprintf(imsi, IMSI_LENGTH, "%s%s", plmn, msin); @@ -143,8 +143,8 @@ static void __telephony_update_default_modem_subscriber_id(GDBusConnection *conn int current_sim = __telephony_get_current_sim(); if (current_sim < 0) { - STC_LOGI("Sim not found"); - return; + STC_LOGI("Sim not found"); //LCOV_EXCL_LINE + return; //LCOV_EXCL_LINE } message = stc_manager_gdbus_call_sync(connection, @@ -154,8 +154,8 @@ static void __telephony_update_default_modem_subscriber_id(GDBusConnection *conn TELEPHONY_GET_MODEMS, NULL); if (message == NULL) { - STC_LOGE("Failed to get services informations"); - return; + STC_LOGE("Failed to get services informations"); //LCOV_EXCL_LINE + return; //LCOV_EXCL_LINE } g_variant_get(message, "(as)", &iter); @@ -167,7 +167,7 @@ static void __telephony_update_default_modem_subscriber_id(GDBusConnection *conn FREE(modem_name); break; } - current_sim--; + current_sim--; //LCOV_EXCL_LINE } __telephony_get_modem_subscriber_id(connection, default_modem_name); @@ -220,7 +220,7 @@ static gboolean __is_cellular_profile(const char *profile) if (profile == NULL) return FALSE; - return g_str_has_prefix(profile, + return g_str_has_prefix(profile, //LCOV_EXCL_LINE CONNMAN_CELLULAR_SERVICE_PROFILE_PREFIX); } @@ -229,7 +229,8 @@ static gboolean __is_wifi_profile(const char *profile) if (profile == NULL) return FALSE; - return g_str_has_prefix(profile, CONNMAN_WIFI_SERVICE_PROFILE_PREFIX); + return g_str_has_prefix(profile, //LCOV_EXCL_LINE + CONNMAN_WIFI_SERVICE_PROFILE_PREFIX); } static gboolean __is_ethernet_profile(const char *profile) @@ -237,7 +238,7 @@ static gboolean __is_ethernet_profile(const char *profile) if (profile == NULL) return FALSE; - return g_str_has_prefix(profile, + return g_str_has_prefix(profile, //LCOV_EXCL_LINE CONNMAN_ETHERNET_SERVICE_PROFILE_PREFIX); } @@ -246,7 +247,7 @@ static gboolean __is_bluetooth_profile(const char *profile) if (profile == NULL) return FALSE; - return g_str_has_prefix(profile, + return g_str_has_prefix(profile, //LCOV_EXCL_LINE CONNMAN_BLUETOOTH_SERVICE_PROFILE_PREFIX); } @@ -296,14 +297,14 @@ static void __get_default_connection_info(GDBusConnection *connection, CONNMAN_SERVICE_INTERFACE, "GetProperties", NULL); if (message == NULL) { - STC_LOGE("Failed to get services informations"); - goto done; + STC_LOGE("Failed to get services informations"); //LCOV_EXCL_LINE + goto done; //LCOV_EXCL_LINE } g_variant_get(message, "(a{sv})", &iter); if (iter == NULL) { - STC_LOGE("Profile %s doesn't exist", object_path); - goto done; + STC_LOGE("Profile %s doesn't exist", object_path); //LCOV_EXCL_LINE + goto done; //LCOV_EXCL_LINE } while (g_variant_iter_loop(iter, "{sv}", &key, &variant)) { @@ -314,7 +315,7 @@ static void __get_default_connection_info(GDBusConnection *connection, g_variant_get(variant, "a{sv}", &iter1); if (iter1 == NULL) - continue; + continue; //LCOV_EXCL_LINE while (g_variant_iter_loop(iter1, "{sv}", &key1, &variant1)) { @@ -363,14 +364,14 @@ static stc_error_e __get_default_profile(GDBusConnection *connection) CONNMAN_MANAGER_INTERFACE, "GetServices", NULL); if (message == NULL) { - STC_LOGE("Failed to get profiles"); - return STC_ERROR_FAIL; + STC_LOGE("Failed to get profiles"); //LCOV_EXCL_LINE + return STC_ERROR_FAIL; //LCOV_EXCL_LINE } g_variant_get(message, "(a(oa{sv}))", &iter); while (g_variant_iter_loop(iter, "(oa{sv})", &object_path, &next)) { if (object_path == NULL) - continue; + continue; //LCOV_EXCL_LINE if (__is_cellular_profile(object_path) && !__is_cellular_internet_profile(object_path)) @@ -394,16 +395,16 @@ static stc_error_e __get_default_profile(GDBusConnection *connection) g_variant_unref(message); if (__is_cellular_profile(g_default_connection.path)) { - g_default_connection.type = STC_IFACE_DATACALL; - __telephony_update_default_modem_subscriber_id(connection); + g_default_connection.type = STC_IFACE_DATACALL; //LCOV_EXCL_LINE + __telephony_update_default_modem_subscriber_id(connection); //LCOV_EXCL_LINE } else if (__is_wifi_profile(g_default_connection.path)) { - g_default_connection.type = STC_IFACE_WIFI; + g_default_connection.type = STC_IFACE_WIFI; //LCOV_EXCL_LINE } else if (__is_ethernet_profile(g_default_connection.path)) { - g_default_connection.type = STC_IFACE_WIRED; + g_default_connection.type = STC_IFACE_WIRED; //LCOV_EXCL_LINE } else if (__is_bluetooth_profile(g_default_connection.path)) { - g_default_connection.type = STC_IFACE_BLUETOOTH; + g_default_connection.type = STC_IFACE_BLUETOOTH; //LCOV_EXCL_LINE } else { - g_default_connection.type = STC_IFACE_UNKNOWN; + g_default_connection.type = STC_IFACE_UNKNOWN; //LCOV_EXCL_LINE } __get_default_connection_info(connection, g_default_connection.path); @@ -448,11 +449,12 @@ static void _service_signal_cb(GDBusConnection *conn, } } else { if (g_strcmp0(g_default_connection.path, path) == 0) { - __reset_default_connection_data(); - __get_default_profile(stc->connection); + __reset_default_connection_data(); //LCOV_EXCL_LINE + __get_default_profile(stc->connection); //LCOV_EXCL_LINE } } } else if (g_strcmp0(sigvalue, "Roaming") == 0) { + //LCOV_EXCL_START if (g_strcmp0(g_default_connection.path, path) == 0) { gboolean roaming = 0; @@ -462,6 +464,7 @@ static void _service_signal_cb(GDBusConnection *conn, g_default_connection.roaming = roaming; } } + //LCOV_EXCL_STOP } else { ;//Do nothing } diff --git a/src/monitor/stc-emulator.c b/src/monitor/stc-emulator.c index 80bc170..6ccbe4f 100755 --- a/src/monitor/stc-emulator.c +++ b/src/monitor/stc-emulator.c @@ -29,17 +29,17 @@ static gboolean __stc_emulator_check_env(void) ret = system_info_get_platform_string("tizen.org/system/model_name", &model); if (ret != SYSTEM_INFO_ERROR_NONE) { - STC_LOGE("Failed to get system information(%d)", ret); - return FALSE; + STC_LOGE("Failed to get system information(%d)", ret); //LCOV_EXCL_LINE + return FALSE; //LCOV_EXCL_LINE } if (model && strncmp(model, "Emulator", strlen("Emulator")) == 0) { - g_free(model); - return TRUE; + g_free(model); //LCOV_EXCL_LINE + return TRUE; //LCOV_EXCL_LINE } - g_free(model); - return FALSE; + g_free(model); //LCOV_EXCL_LINE + return FALSE; //LCOV_EXCL_LINE } gboolean stc_emulator_is_emulated(void) diff --git a/src/monitor/stc-exception.c b/src/monitor/stc-exception.c index 30579fc..a9e3523 100755 --- a/src/monitor/stc-exception.c +++ b/src/monitor/stc-exception.c @@ -54,13 +54,13 @@ stc_error_e table_exceptions_foreach(const stc_exceptions_info_cb exception_cb, if (process_name != NULL) data.process_name = process_name; else - data.process_name = "none"; + data.process_name = "none"; //LCOV_EXCL_LINE exe_type = strtok_r(NULL, "\n", &save_ptr); if (exe_type != NULL) data.exe_type = exe_type; else - data.exe_type = "none"; + data.exe_type = "none"; //LCOV_EXCL_LINE if (exception_cb(&data, user_data) == STC_CANCEL) break; @@ -80,7 +80,7 @@ static int __pkginfo_filter_list_cb(pkgmgrinfo_pkginfo_h handle, void *user_data if (ret == PMINFO_R_OK) { if (g_hash_table_insert(g_pkginfo_filter_hash, g_strdup(pkgname), g_strdup(EXE_TYPE_APPLICATION)) != TRUE) - STC_LOGE("Failed to insert hash table"); + STC_LOGE("Failed to insert hash table"); //LCOV_EXCL_LINE } return STC_CONTINUE; @@ -104,7 +104,7 @@ static int __pkginfo_pkg_list_cb(pkgmgrinfo_pkginfo_h handle, void *user_data) data.exe_type = EXE_TYPE_APPLICATION; if (excn_cb(&data, NULL) == STC_CANCEL) - STC_LOGE("Failed to insert hash table"); + STC_LOGE("Failed to insert hash table"); //LCOV_EXCL_LINE } return STC_CONTINUE; @@ -130,24 +130,24 @@ stc_error_e pkginfo_exceptions_foreach(const stc_exceptions_info_cb exception_cb PMINFO_PKGINFO_PROP_PACKAGE_PRIVILEGE, INTERNET_PRIVILEGE); if (ret != PMINFO_R_OK) { - STC_LOGE("Failed to add pkginfo filter string"); - err = STC_ERROR_FAIL; - goto out; + STC_LOGE("Failed to add pkginfo filter string"); //LCOV_EXCL_LINE + err = STC_ERROR_FAIL; //LCOV_EXCL_LINE + goto out; //LCOV_EXCL_LINE } ret = pkgmgrinfo_pkginfo_filter_foreach_pkginfo(handle, __pkginfo_filter_list_cb, NULL); if (ret != PMINFO_R_OK) { - STC_LOGE("Failed to foreach pkginfo filter"); - err = STC_ERROR_FAIL; - goto out; + STC_LOGE("Failed to foreach pkginfo filter"); //LCOV_EXCL_LINE + err = STC_ERROR_FAIL; //LCOV_EXCL_LINE + goto out; //LCOV_EXCL_LINE } ret = pkgmgrinfo_pkginfo_get_list(__pkginfo_pkg_list_cb, exception_cb); if (ret != PMINFO_R_OK) { - STC_LOGE("Failed to get pkginfo list"); - err = STC_ERROR_FAIL; - goto out; + STC_LOGE("Failed to get pkginfo list"); //LCOV_EXCL_LINE + err = STC_ERROR_FAIL; //LCOV_EXCL_LINE + goto out; //LCOV_EXCL_LINE } out: diff --git a/src/monitor/stc-monitor.c b/src/monitor/stc-monitor.c index 268c5cf..62a2c5c 100755 --- a/src/monitor/stc-monitor.c +++ b/src/monitor/stc-monitor.c @@ -277,6 +277,7 @@ static void __rstns_tree_key_free(gpointer data) FREE(key); } +//LCOV_EXCL_START static gboolean __processes_tree_foreach_print(gpointer key, gpointer value, gpointer data) { @@ -314,6 +315,7 @@ static void __apps_tree_printall(void) { g_tree_foreach(g_system->apps, __apps_tree_foreach_print, NULL); } +//LCOV_EXCL_STOP static gboolean __apps_tree_foreach_remove_pid(gpointer key, gpointer value, gpointer data) @@ -323,7 +325,7 @@ static gboolean __apps_tree_foreach_remove_pid(gpointer key, gpointer value, if (!g_tree_remove(app_value->processes, context->proc_key)) { if (STC_DEBUG_LOG) - STC_LOGD("key not found"); + STC_LOGD("key not found"); //LCOV_EXCL_LINE return FALSE; } @@ -357,6 +359,7 @@ static stc_process_value_s * __process_lookup(GTree *processes, return lookup; } +//LCOV_EXCL_START static gboolean __processes_tree_check_empty(gpointer key, gpointer value, gpointer data) { @@ -364,6 +367,7 @@ static gboolean __processes_tree_check_empty(gpointer key, gpointer value, (*pid_count)++; return TRUE; } +//LCOV_EXCL_STOP static gboolean __add_application_monitor(gpointer key, gpointer value, gpointer data) @@ -381,11 +385,11 @@ static gboolean __add_application_monitor(gpointer key, gpointer value, struct nfacct_rule counter; if (!stc->carg) { - stc->carg = MALLOC0(counter_arg_s, 1); - if (stc->carg == NULL) - return FALSE; + stc->carg = MALLOC0(counter_arg_s, 1); //LCOV_EXCL_LINE + if (stc->carg == NULL) //LCOV_EXCL_LINE + return FALSE; //LCOV_EXCL_LINE - stc->carg->sock = stc_monitor_get_counter_socket(); + stc->carg->sock = stc_monitor_get_counter_socket(); //LCOV_EXCL_LINE } memset(&counter, 0, sizeof(struct nfacct_rule)); @@ -424,11 +428,11 @@ static gboolean __remove_application_monitor(gpointer key, gpointer value, struct nfacct_rule counter; if (!stc->carg) { - stc->carg = MALLOC0(counter_arg_s, 1); - if (stc->carg == NULL) - return FALSE; + stc->carg = MALLOC0(counter_arg_s, 1); //LCOV_EXCL_LINE + if (stc->carg == NULL) //LCOV_EXCL_LINE + return FALSE; //LCOV_EXCL_LINE - stc->carg->sock = stc_monitor_get_counter_socket(); + stc->carg->sock = stc_monitor_get_counter_socket(); //LCOV_EXCL_LINE } memset(&counter, 0, sizeof(struct nfacct_rule)); @@ -506,12 +510,12 @@ static void __process_restriction(enum traffic_restriction_type rst_type, effective_data_warn_limit -= info.data_counter; if (effective_data_limit < 0) { - effective_data_limit = 0; - rstn_value->data_limit_reached = TRUE; + effective_data_limit = 0; //LCOV_EXCL_LINE + rstn_value->data_limit_reached = TRUE; //LCOV_EXCL_LINE } if (effective_data_warn_limit < 0) - effective_data_warn_limit = 0; + effective_data_warn_limit = 0; //LCOV_EXCL_LINE STC_LOGD("datausage [%lld] bytes", info.data_counter); } @@ -528,19 +532,18 @@ static void __process_restriction(enum traffic_restriction_type rst_type, struct nfacct_rule counter; stc_s *stc = stc_get_manager(); if (!stc) { - g_free(default_ifname); - return; + g_free(default_ifname); //LCOV_EXCL_LINE + return; //LCOV_EXCL_LINE } if (!stc->carg) { - stc->carg = MALLOC0(counter_arg_s, 1); - if (stc->carg == NULL) { - g_free(default_ifname); - return; + stc->carg = MALLOC0(counter_arg_s, 1); //LCOV_EXCL_LINE + if (stc->carg == NULL) { //LCOV_EXCL_LINE + g_free(default_ifname); //LCOV_EXCL_LINE + return; //LCOV_EXCL_LINE } - stc->carg->sock = - stc_monitor_get_counter_socket(); + stc->carg->sock = stc_monitor_get_counter_socket(); //LCOV_EXCL_LINE } counter.carg = stc->carg; @@ -574,19 +577,18 @@ static void __process_restriction(enum traffic_restriction_type rst_type, struct nfacct_rule counter; stc_s *stc = stc_get_manager(); if (!stc) { - g_free(default_ifname); - return; + g_free(default_ifname); //LCOV_EXCL_LINE + return; //LCOV_EXCL_LINE } if (!stc->carg) { - stc->carg = MALLOC0(counter_arg_s, 1); - if (stc->carg == NULL) { - g_free(default_ifname); - return; + stc->carg = MALLOC0(counter_arg_s, 1); //LCOV_EXCL_LINE + if (stc->carg == NULL) { //LCOV_EXCL_LINE + g_free(default_ifname); //LCOV_EXCL_LINE + return; //LCOV_EXCL_LINE } - stc->carg->sock = - stc_monitor_get_counter_socket(); + stc->carg->sock = stc_monitor_get_counter_socket(); //LCOV_EXCL_LINE } counter.carg = stc->carg; @@ -616,6 +618,7 @@ static void __process_restriction(enum traffic_restriction_type rst_type, } } +//LCOV_EXCL_START static gboolean __remove_rstns_foreach_application(gpointer key, gpointer value, gpointer data) @@ -643,6 +646,7 @@ static gboolean __remove_rstns_foreach_application(gpointer key, out: return FALSE; } +//LCOV_EXCL_STOP static void __remove_rstns_for_application(gchar *app_id) { @@ -660,8 +664,8 @@ static stc_error_e __application_remove_if_empty(const stc_app_key_s *app_key) lookup = __application_lookup(g_system->apps, app_key); if (!lookup) { - STC_LOGE("app_key not found"); - return STC_ERROR_NO_DATA; + STC_LOGE("app_key not found"); //LCOV_EXCL_LINE + return STC_ERROR_NO_DATA; //LCOV_EXCL_LINE } g_tree_foreach(lookup->processes, __processes_tree_check_empty, @@ -675,8 +679,8 @@ static stc_error_e __application_remove_if_empty(const stc_app_key_s *app_key) } if (!g_tree_remove(g_system->apps, app_key)) { - ret = STC_ERROR_NO_DATA; - STC_LOGE("key not found"); + ret = STC_ERROR_NO_DATA; //LCOV_EXCL_LINE + STC_LOGE("key not found"); //LCOV_EXCL_LINE } return ret; @@ -704,6 +708,7 @@ static gboolean __process_contr_reply(GIOChannel *source, GIOCondition condition, gpointer user_data); +//LCOV_EXCL_START static stc_error_e __close_and_reopen_contr_sock(stc_system_s *system) { GIOChannel *gio = NULL; @@ -854,8 +859,8 @@ static gboolean __rstn_counter_update_foreach_classid(gpointer key, goto try_next_callback; if (rstn_value->data_limit_reached == TRUE) { - context->data_limit_reached = TRUE; - goto try_next_callback; + context->data_limit_reached = TRUE; //LCOV_EXCL_LINE + goto try_next_callback; //LCOV_EXCL_LINE } classid = context->counter->classid; @@ -870,6 +875,7 @@ static gboolean __rstn_counter_update_foreach_classid(gpointer key, try_next_callback: return rv; } +//LCOV_EXCL_STOP static gboolean __update_app_statistics(gpointer key, gpointer value, gpointer data) @@ -890,7 +896,7 @@ static gboolean __update_app_statistics(gpointer key, gpointer value, if (STC_IFACE_DATACALL == stat_key.iftype) stat_key.subscriber_id = g_strdup(default_connection->subscriber_id); else - stat_key.subscriber_id = g_strdup("none_subid"); + stat_key.subscriber_id = g_strdup("none_subid"); //LCOV_EXCL_LINE g_strlcpy(stat_key.ifname, default_connection->ifname, MAX_IFACE_LENGTH); @@ -938,6 +944,7 @@ static gboolean __flush_apps_stats_to_database(gpointer user_data) return G_SOURCE_REMOVE; } +//LCOV_EXCL_START static gboolean __update_counter_statistics(gpointer key, gpointer value, gpointer data) { @@ -969,6 +976,7 @@ static gboolean __flush_rstns_counter_to_database(gpointer user_data) STC_LOGI("Flushed rstns counters to database"); return G_SOURCE_REMOVE; } +//LCOV_EXCL_STOP static void __app_counter_update(stc_app_key_s *app_key, stc_app_value_s *app_value, @@ -981,7 +989,7 @@ static void __app_counter_update(stc_app_key_s *app_key, g_system->apps_tree_updated = TRUE; if (STC_DEBUG_LOG) - __apps_tree_foreach_print(app_key, app_value, NULL); + __apps_tree_foreach_print(app_key, app_value, NULL); //LCOV_EXCL_LINE break; case NFACCT_COUNTER_OUT: app_value->data_usage.out_bytes += context->bytes; @@ -989,10 +997,10 @@ static void __app_counter_update(stc_app_key_s *app_key, g_system->apps_tree_updated = TRUE; if (STC_DEBUG_LOG) - __apps_tree_foreach_print(app_key, app_value, NULL); + __apps_tree_foreach_print(app_key, app_value, NULL); //LCOV_EXCL_LINE break; default: - STC_LOGE("unknown iotype"); + STC_LOGE("unknown iotype"); //LCOV_EXCL_LINE } } @@ -1049,11 +1057,11 @@ static void __fill_nfacct_result(char *cnt_name, int64_t bytes, }; if (STC_DEBUG_LOG) - STC_LOGD("cnt_name %s", cnt_name); + STC_LOGD("cnt_name %s", cnt_name); //LCOV_EXCL_LINE if (!recreate_counter_by_name(cnt_name, &counter)) { - STC_LOGE("Can't parse counter name %s", cnt_name); - return; + STC_LOGE("Can't parse counter name %s", cnt_name); //LCOV_EXCL_LINE + return; //LCOV_EXCL_LINE } STC_LOGI("classid %lu, iftype %u, iotype %d, intend %d, ifname %s, bytes %lld", @@ -1120,8 +1128,8 @@ static void __process_network_counter(struct genl *ans, netlink_serialization_command *netlink = netlink_create_command(&ser_params); if (!netlink) { - STC_LOGE("Can not create command"); - return; + STC_LOGE("Can not create command"); //LCOV_EXCL_LINE + return; //LCOV_EXCL_LINE } netlink->deserialize_answer(&(netlink->params)); @@ -1136,27 +1144,32 @@ static gboolean __process_contr_reply(GIOChannel *source, int ret; stc_s *stc = stc_get_manager(); +#ifdef TIZEN_GTESTS + void __gcov_flush(void); + __gcov_flush(); +#endif + if ((condition & G_IO_ERR) || (condition & G_IO_HUP) || (condition & G_IO_NVAL)) { /* G_IO_ERR/G_IO_HUP/G_IO_NVAL received */ - STC_LOGE("Counter socket received G_IO event, closing socket." + STC_LOGE("Counter socket received G_IO event, closing socket." //LCOV_EXCL_LINE "G_IO_ERR [%d], G_IO_HUP [%d], G_IO_NVAL [%s]", (condition & G_IO_ERR), (condition & G_IO_HUP), (condition & G_IO_NVAL)); - __close_and_reopen_contr_sock(g_system); - return FALSE; + __close_and_reopen_contr_sock(g_system); //LCOV_EXCL_LINE + return FALSE; //LCOV_EXCL_LINE } ans = MALLOC0(struct genl, 1); if (ans == NULL) { - STC_LOGE("Failed allocate memory to genl reply message"); - return TRUE; + STC_LOGE("Failed allocate memory to genl reply message"); //LCOV_EXCL_LINE + return TRUE; //LCOV_EXCL_LINE } if (stc == NULL) { - STC_LOGE("Can't get stc data"); - goto out; + STC_LOGE("Can't get stc data"); //LCOV_EXCL_LINE + goto out; //LCOV_EXCL_LINE } ret = read_netlink(sock, ans, sizeof(struct genl)); @@ -1170,6 +1183,7 @@ static gboolean __process_contr_reply(GIOChannel *source, g_idle_add(__flush_apps_stats_to_database, NULL); g_idle_add(__flush_rstns_counter_to_database, NULL); out: + FREE(ans); return TRUE; } @@ -1187,6 +1201,11 @@ static gboolean __update_contr_cb(void *user_data) stc->carg->sock = stc_monitor_get_counter_socket(); } +#ifdef TIZEN_GTESTS + void __gcov_flush(void); + __gcov_flush(); +#endif + /* STC_LOGD("Get all counters"); */ nfacct_send_get_all(stc->carg); @@ -1256,6 +1275,7 @@ static gboolean __add_restriction_debug(gpointer key, gpointer value, return FALSE; } +//LCOV_EXCL_START static gboolean __add_restriction(gpointer key, gpointer value, gpointer data) { stc_rstn_key_s *rstn_key = (stc_rstn_key_s *)key; @@ -1272,6 +1292,7 @@ static gboolean __add_restriction(gpointer key, gpointer value, gpointer data) return FALSE; } +//LCOV_EXCL_STOP static stc_error_e __rstn_tree_remove(stc_rstn_key_s *key) { @@ -1281,8 +1302,8 @@ static stc_error_e __rstn_tree_remove(stc_rstn_key_s *key) lookup_value = __rstn_lookup(g_system->rstns, key); if (!lookup_value) { - STC_LOGE("key not found"); - return STC_ERROR_NO_DATA; + STC_LOGE("key not found"); //LCOV_EXCL_LINE + return STC_ERROR_NO_DATA; //LCOV_EXCL_LINE } __remove_restriction(key, lookup_value, NULL); @@ -1291,8 +1312,8 @@ static stc_error_e __rstn_tree_remove(stc_rstn_key_s *key) table_counters_delete(lookup_value->restriction_id); if (!g_tree_remove(g_system->rstns, key)) { - STC_LOGD("key not found"); - return STC_ERROR_NO_DATA; + STC_LOGD("key not found"); //LCOV_EXCL_LINE + return STC_ERROR_NO_DATA; //LCOV_EXCL_LINE } return STC_ERROR_NONE; @@ -1309,15 +1330,15 @@ static stc_error_e __rstn_tree_add(stc_rstn_key_s *key, if (!rstn_value) { stc_rstn_key_s *rstn_key = MALLOC0(stc_rstn_key_s, 1); if (!rstn_key) { - STC_LOGE("rstn_key allocation failed"); - return STC_ERROR_OUT_OF_MEMORY; + STC_LOGE("rstn_key allocation failed"); //LCOV_EXCL_LINE + return STC_ERROR_OUT_OF_MEMORY; //LCOV_EXCL_LINE } rstn_value = MALLOC0(stc_rstn_value_s, 1); if (!rstn_value) { - STC_LOGE("rstn_value allocation failed"); - FREE(rstn_key); - return STC_ERROR_OUT_OF_MEMORY; + STC_LOGE("rstn_value allocation failed"); //LCOV_EXCL_LINE + FREE(rstn_key); //LCOV_EXCL_LINE + return STC_ERROR_OUT_OF_MEMORY; //LCOV_EXCL_LINE } rstn_key->app_id = g_strdup(key->app_id); @@ -1346,6 +1367,7 @@ static stc_error_e __rstn_tree_add(stc_rstn_key_s *key, return STC_ERROR_NONE; } +//LCOV_EXCL_START static stc_cb_ret_e __insert_restriction_cb(const table_restrictions_info *info, void *user_data) { @@ -1419,6 +1441,7 @@ static gboolean __add_rstn_foreach_application(gpointer key, out: return FALSE; } +//LCOV_EXCL_STOP static void __add_rstns_for_application(gchar *app_id) { @@ -1432,7 +1455,7 @@ static void __add_application_by_interface(const char *app_id) stc_app_value_s app_value; if (app_id == NULL) - return; + return; //LCOV_EXCL_LINE memset(&app_key, 0, sizeof(stc_app_key_s)); memset(&app_value, 0, sizeof(stc_app_value_s)); @@ -1457,21 +1480,22 @@ static int __vconf_get_int(const char *key, int *value) ret = vconf_get_int(key, value); if (ret != VCONF_OK) { - STC_LOGE("Failed to get vconfkey [%s] value", key); - return -1; + STC_LOGE("Failed to get vconfkey [%s] value", key); //LCOV_EXCL_LINE + return -1; //LCOV_EXCL_LINE } return 0; } +//LCOV_EXCL_START static int __vconf_set_int(const char *key, int value) { int ret = 0; ret = vconf_set_int(key, value); if (ret != VCONF_OK) { - STC_LOGE("Failed to set vconfkey [%s] value", key); - return -1; + STC_LOGE("Failed to set vconfkey [%s] value", key); //LCOV_EXCL_LINE + return -1; //LCOV_EXCL_LINE } return 0; @@ -1523,6 +1547,7 @@ static stc_error_e __process_update_background(void) return STC_ERROR_NONE; } +//LCOV_EXCL_STOP #if 0 static void __excn_hash_foreach_print(gpointer key, gpointer value, @@ -1542,6 +1567,7 @@ static void __excn_hash_printall(void) } #endif +//LCOV_EXCL_START static gboolean __remove_exception_app(gpointer key, gpointer value, gpointer data) { @@ -1552,10 +1578,11 @@ static gboolean __remove_exception_app(gpointer key, gpointer value, return FALSE; } +//LCOV_EXCL_STOP static void __remove_exception_appall(void) { - g_hash_table_foreach_remove(g_system->excns_hash, + g_hash_table_foreach_remove(g_system->excns_hash, //LCOV_EXCL_LINE __remove_exception_app, NULL); } @@ -1567,7 +1594,7 @@ static stc_cb_ret_e __insert_exception_cb(const stc_exceptions_info *info, if (g_hash_table_insert(g_system->excns_hash, g_strdup(info->process_name), g_strdup(info->exe_type)) != TRUE) - ret = STC_CANCEL; + ret = STC_CANCEL; //LCOV_EXCL_LINE return ret; } @@ -1580,6 +1607,7 @@ static void __fill_exceptions_list(void) /* __excn_hash_printall(); */ } +//LCOV_EXCL_START static gboolean __update_exceptions_app_list(void *user_data) { __remove_exception_appall(); @@ -1589,6 +1617,7 @@ static gboolean __update_exceptions_app_list(void *user_data) return TRUE; } +//LCOV_EXCL_STOP stc_error_e stc_monitor_init(void) { @@ -1618,9 +1647,9 @@ stc_error_e stc_monitor_init(void) /* create netlink socket for updating kernel counters */ system->contr_sock = create_netlink(NETLINK_NETFILTER, 0); if (system->contr_sock < 0) { - STC_LOGE("failed to open socket"); - FREE(system); - return STC_ERROR_FAIL; + STC_LOGE("failed to open socket"); //LCOV_EXCL_LINE + FREE(system); //LCOV_EXCL_LINE + return STC_ERROR_FAIL; //LCOV_EXCL_LINE } gio = g_io_channel_unix_new(system->contr_sock); @@ -1646,9 +1675,9 @@ stc_error_e stc_monitor_init(void) __update_contr_cb, NULL); if (g_system->contr_timer_id == 0) { - STC_LOGE("Failed to register kernel counters update timer"); - __close_contr_sock(g_system); - return STC_ERROR_FAIL; + STC_LOGE("Failed to register kernel counters update timer"); //LCOV_EXCL_LINE + __close_contr_sock(g_system); //LCOV_EXCL_LINE + return STC_ERROR_FAIL; //LCOV_EXCL_LINE } __vconf_get_int(VCONFKEY_STC_BACKGROUND_STATE, @@ -1712,21 +1741,21 @@ stc_error_e stc_monitor_application_add(const stc_app_key_s app_key, lookup = __application_lookup(g_system->apps, &app_key); if (lookup) { - STC_LOGD("app_key already present"); - return STC_ERROR_NONE; + STC_LOGD("app_key already present"); //LCOV_EXCL_LINE + return STC_ERROR_NONE; //LCOV_EXCL_LINE } key = MALLOC0(stc_app_key_s, 1); if (!key) { - STC_LOGE("key allocation failed"); - return STC_ERROR_OUT_OF_MEMORY; + STC_LOGE("key allocation failed"); //LCOV_EXCL_LINE + return STC_ERROR_OUT_OF_MEMORY; //LCOV_EXCL_LINE } value = MALLOC0(stc_app_value_s, 1); if (!value) { - STC_LOGE("value allocation failed"); - FREE(key); - return STC_ERROR_OUT_OF_MEMORY; + STC_LOGE("value allocation failed"); //LCOV_EXCL_LINE + FREE(key); //LCOV_EXCL_LINE + return STC_ERROR_OUT_OF_MEMORY; //LCOV_EXCL_LINE } key->app_id = g_strdup(app_key.app_id); @@ -1766,27 +1795,27 @@ stc_error_e stc_monitor_process_add(const stc_app_key_s app_key, app_lookup = __application_lookup(g_system->apps, &app_key); if (!app_lookup) { - STC_LOGD("app_key not found"); - return STC_ERROR_FAIL; + STC_LOGD("app_key not found"); //LCOV_EXCL_LINE + return STC_ERROR_FAIL; //LCOV_EXCL_LINE } proc_lookup = __process_lookup(app_lookup->processes, &proc_key); if (proc_lookup) { - STC_LOGD("proc_key already present"); - return STC_ERROR_NONE; + STC_LOGD("proc_key already present"); //LCOV_EXCL_LINE + return STC_ERROR_NONE; //LCOV_EXCL_LINE } key = MALLOC0(stc_process_key_s, 1); if (!key) { - STC_LOGE("key allocation failed"); - return STC_ERROR_OUT_OF_MEMORY; + STC_LOGE("key allocation failed"); //LCOV_EXCL_LINE + return STC_ERROR_OUT_OF_MEMORY; //LCOV_EXCL_LINE } value = MALLOC0(stc_process_value_s, 1); if (!value) { - STC_LOGE("value allocation failed"); - FREE(key); - return STC_ERROR_OUT_OF_MEMORY; + STC_LOGE("value allocation failed"); //LCOV_EXCL_LINE + FREE(key); //LCOV_EXCL_LINE + return STC_ERROR_OUT_OF_MEMORY; //LCOV_EXCL_LINE } key->pid = proc_key.pid; @@ -1799,7 +1828,7 @@ stc_error_e stc_monitor_process_add(const stc_app_key_s app_key, place_pids_to_net_cgroup(proc_key.pid, app_key.app_id); if (STC_DEBUG_LOG) - __apps_tree_printall(); + __apps_tree_printall(); //LCOV_EXCL_LINE return ret; } @@ -1826,11 +1855,12 @@ stc_error_e stc_monitor_process_remove(pid_t pid) __application_remove_if_empty(context.app_key); if (STC_DEBUG_LOG) - __apps_tree_printall(); + __apps_tree_printall(); //LCOV_EXCL_LINE return ret; } +//LCOV_EXCL_START stc_error_e stc_monitor_process_update_ground(const stc_app_key_s app_key, const stc_process_key_s proc_key, stc_app_state_e ground) @@ -1863,6 +1893,7 @@ stc_error_e stc_monitor_process_update_ground(const stc_app_key_s app_key, return ret; } +//LCOV_EXCL_STOP void stc_monitor_update_rstn_by_default_connection(void *data) { @@ -1870,6 +1901,7 @@ void stc_monitor_update_rstn_by_default_connection(void *data) default_connection_s *new_connection = (default_connection_s *)data; if (old_connection.path != NULL) { + //LCOV_EXCL_START if (g_system->apps) g_tree_foreach(g_system->apps, __remove_application_monitor, @@ -1881,6 +1913,7 @@ void stc_monitor_update_rstn_by_default_connection(void *data) (gpointer)&old_connection); iptables_flush_chains(); + //LCOV_EXCL_STOP } FREE(old_connection.path); @@ -1930,9 +1963,9 @@ stc_error_e stc_monitor_rstns_tree_add(const table_restrictions_info *info) value.classid = STC_UNKNOWN_CLASSID; if (value.classid == STC_BACKGROUND_APP_CLASSID) { - __set_background_state(TRUE); - __vconf_set_int(VCONFKEY_STC_BACKGROUND_STATE, g_system->background_state); - __process_update_background(); + __set_background_state(TRUE); //LCOV_EXCL_LINE + __vconf_set_int(VCONFKEY_STC_BACKGROUND_STATE, g_system->background_state); //LCOV_EXCL_LINE + __process_update_background(); //LCOV_EXCL_LINE } value.data_limit = info->data_limit; @@ -1959,9 +1992,9 @@ stc_error_e stc_monitor_rstns_tree_remove(const table_restrictions_info *info) }; if (!strcmp(key.app_id, STC_BACKGROUND_APP_ID)) { - __set_background_state(FALSE); - __vconf_set_int(VCONFKEY_STC_BACKGROUND_STATE, g_system->background_state); - __process_update_background(); + __set_background_state(FALSE); //LCOV_EXCL_LINE + __vconf_set_int(VCONFKEY_STC_BACKGROUND_STATE, g_system->background_state); //LCOV_EXCL_LINE + __process_update_background(); //LCOV_EXCL_LINE } ret = __rstn_tree_remove(&key); diff --git a/src/stc-manager-gdbus.c b/src/stc-manager-gdbus.c index bf556e6..df53f9b 100755 --- a/src/stc-manager-gdbus.c +++ b/src/stc-manager-gdbus.c @@ -15,6 +15,7 @@ */ #include "stc-manager-gdbus.h" +#include "stc-manager.h" #include "stc-statistics.h" #include "stc-restriction.h" #include "stc-default-connection.h" @@ -129,6 +130,37 @@ static gboolean __stc_manager_gdbus_restriction_init(stc_s *stc) return ret; } +static gboolean __stc_manager_gdbus_manager_init(stc_s *stc) +{ + __STC_LOG_FUNC_ENTER__; + gboolean ret = TRUE; + gchar *s = NULL; + + StcObjectSkeleton *object = NULL; + StcManager *manager = NULL; + s = g_strdup_printf(STC_DBUS_SERVICE_MANAGER_PATH); + + object = stc_object_skeleton_new(s); + g_free(s); + + manager = stc_manager_skeleton_new(); + stc_object_skeleton_set_manager(object, manager); + g_object_unref(manager); + + g_signal_connect(manager, "handle-stop", + G_CALLBACK(handle_manager_stop), stc); + + g_dbus_object_manager_server_export(stc->obj_mgr, + G_DBUS_OBJECT_SKELETON(object)); + g_object_unref(object); + + stc->manager_obj = (gpointer)manager; + + __STC_LOG_FUNC_EXIT__; + return ret; +} + + static void __stc_manager_gdbus_on_bus_acquired(GDBusConnection *connection, const gchar *name, gpointer user_data) @@ -143,12 +175,17 @@ static void __stc_manager_gdbus_on_bus_acquired(GDBusConnection *connection, stc->connection = connection; if (__stc_manager_gdbus_statistics_init(stc) == FALSE) { - STC_LOGE("Can not signal connect to statistics"); + STC_LOGE("Can not signal connect to statistics"); //LCOV_EXCL_LINE /* Deinitialize and quit manager */ } if (__stc_manager_gdbus_restriction_init(stc) == FALSE) { - STC_LOGE("Cannot signal connect to restriction"); + STC_LOGE("Cannot signal connect to restriction"); //LCOV_EXCL_LINE + /* Deinitialize and quit manager */ + } + + if (__stc_manager_gdbus_manager_init(stc) == FALSE) { + STC_LOGE("Cannot signal connect to manager"); //LCOV_EXCL_LINE /* Deinitialize and quit manager */ } @@ -169,12 +206,14 @@ static void __stc_manager_gdbus_on_name_acquired(GDBusConnection *connection, STC_LOGD("name : %s", name); } +//LCOV_EXCL_START static void __stc_manager_gdbus_on_name_lost(GDBusConnection *connection, const gchar *name, gpointer user_data) { STC_LOGD("name : %s", name); } +//LCOV_EXCL_STOP void stc_manager_gdbus_init(gpointer stc_data) { @@ -205,6 +244,7 @@ void stc_manager_gdbus_deinit(gpointer stc_data) stc->statistics_obj = NULL; stc->restriction_obj = NULL; + stc->manager_obj = NULL; __STC_LOG_FUNC_EXIT__; } @@ -217,8 +257,8 @@ GVariant *stc_manager_gdbus_call_sync(GDBusConnection *connection, GVariant *reply = NULL; if (connection == NULL) { - STC_LOGE("Failed to get GDBusconnection"); - return reply; + STC_LOGE("Failed to get GDBusconnection"); //LCOV_EXCL_LINE + return reply; //LCOV_EXCL_LINE } reply = g_dbus_connection_call_sync(connection, @@ -235,11 +275,11 @@ GVariant *stc_manager_gdbus_call_sync(GDBusConnection *connection, if (reply == NULL) { if (error != NULL) { - STC_LOGE("g_dbus_connection_call_sync() failed" + STC_LOGE("g_dbus_connection_call_sync() failed" //LCOV_EXCL_LINE "error [%d: %s]", error->code, error->message); - g_error_free(error); + g_error_free(error); //LCOV_EXCL_LINE } else { - STC_LOGE("g_dbus_connection_call_sync() failed"); + STC_LOGE("g_dbus_connection_call_sync() failed"); //LCOV_EXCL_LINE } return NULL; @@ -260,8 +300,8 @@ guint stc_manager_gdbus_subscribe_signal(GDBusConnection *connection, GDestroyNotify user_data_free_func) { if (connection == NULL) { - STC_LOGE("Failed to get GDBusconnection"); - return 0; + STC_LOGE("Failed to get GDBusconnection"); //LCOV_EXCL_LINE + return 0; //LCOV_EXCL_LINE } return g_dbus_connection_signal_subscribe(connection, @@ -280,8 +320,8 @@ void stc_manager_gdbus_unsubscribe_signal(GDBusConnection *connection, guint subscription_id) { if (connection == NULL) { - STC_LOGE("Failed to get GDBusconnection"); - return; + STC_LOGE("Failed to get GDBusconnection"); //LCOV_EXCL_LINE + return; //LCOV_EXCL_LINE } g_dbus_connection_signal_unsubscribe(connection, subscription_id); @@ -296,8 +336,8 @@ void stc_manager_gdbus_dict_foreach(GVariantIter *iter, dbus_dict_cb cb, GVariant *value = NULL; if (!cb) { - __STC_LOG_FUNC_EXIT__; - return; + __STC_LOG_FUNC_EXIT__; //LCOV_EXCL_LINE + return; //LCOV_EXCL_LINE } while (g_variant_iter_loop(iter, "{sv}", &key, &value)) { @@ -319,7 +359,7 @@ gboolean stc_manager_dbus_emit_signal(GDBusConnection *connection, GError *error = NULL; if (connection == NULL) { - STC_LOGE("GDBusconnection is NULL"); + STC_LOGE("GDBusconnection is NULL"); //LCOV_EXCL_LINE return 0; } @@ -333,9 +373,9 @@ gboolean stc_manager_dbus_emit_signal(GDBusConnection *connection, parameters, &error); if (rv != TRUE) { - STC_LOGE("Failed to emit signal [%s] interface [%s] Error [%s]", + STC_LOGE("Failed to emit signal [%s] interface [%s] Error [%s]", //LCOV_EXCL_LINE signal_name, interface_name, error->message); - g_error_free(error); + g_error_free(error); //LCOV_EXCL_LINE } else { STC_LOGD("[%s] signal sent on [%s] interface", signal_name, interface_name); @@ -343,3 +383,22 @@ gboolean stc_manager_dbus_emit_signal(GDBusConnection *connection, return rv; } + +gboolean handle_manager_stop(StcManager *object, + GDBusMethodInvocation *invocation) +{ + __STC_LOG_FUNC_ENTER__; + GVariant *return_parameters = NULL; + + STC_LOGI("stc manager stop"); + + return_parameters = g_variant_new("(i)", STC_ERROR_NONE); + + DEBUG_GDBUS_VARIANT("Return parameters: ", return_parameters); + STC_DBUS_REPLY(invocation, return_parameters); + + stc_stop_manager(); + + __STC_LOG_FUNC_EXIT__; + return TRUE; +} diff --git a/src/stc-manager-plugin.c b/src/stc-manager-plugin.c index d1e6d30..a97ae73 100755 --- a/src/stc-manager-plugin.c +++ b/src/stc-manager-plugin.c @@ -24,6 +24,7 @@ static gboolean stc_plugin_enabled = FALSE; static void *handle_plugin; static stc_plugin_s *stc_plugin; +//LCOV_EXCL_START void stc_manager_plugin_init(void) { __STC_LOG_FUNC_ENTER__; @@ -150,3 +151,4 @@ int stc_deregister_state_changed_cb(stc_s *stc) __STC_LOG_FUNC_EXIT__; return stc_plugin->deregister_state_changed_cb(stc); } +//LCOV_EXCL_STOP diff --git a/src/stc-manager-util.c b/src/stc-manager-util.c index 17f9d83..b929427 100755 --- a/src/stc-manager-util.c +++ b/src/stc-manager-util.c @@ -40,10 +40,10 @@ static GKeyFile *__load_key_file(const char *path) keyfile = g_key_file_new(); if (!g_key_file_load_from_file(keyfile, path, 0, &error)) { - STC_LOGD("Unable to load [%s] : %s", path, error->message); - g_clear_error(&error); - g_key_file_free(keyfile); - keyfile = NULL; + STC_LOGD("Unable to load [%s] : %s", path, error->message); //LCOV_EXCL_LINE + g_clear_error(&error); //LCOV_EXCL_LINE + g_key_file_free(keyfile); //LCOV_EXCL_LINE + keyfile = NULL; //LCOV_EXCL_LINE } return keyfile; @@ -59,9 +59,9 @@ static int __save_key_file(GKeyFile *keyfile, char *path) data = g_key_file_to_data(keyfile, &length, NULL); if (!g_file_set_contents(path, data, length, &error)) { - STC_LOGD("Failed to save information : %s", error->message); - g_error_free(error); - ret = -EIO; + STC_LOGD("Failed to save information : %s", error->message); //LCOV_EXCL_LINE + g_error_free(error); //LCOV_EXCL_LINE + ret = -EIO; //LCOV_EXCL_LINE } __sync_file_to_disk(path); @@ -70,6 +70,7 @@ static int __save_key_file(GKeyFile *keyfile, char *path) return ret; } +//LCOV_EXCL_START gboolean stc_util_get_config_bool(char *key) { char path[MAX_PATH_LENGTH]; @@ -105,6 +106,7 @@ gchar * stc_util_get_config_str(char *key) return value; } +//LCOV_EXCL_STOP int stc_util_get_config_int(char *key) { @@ -116,7 +118,7 @@ int stc_util_get_config_int(char *key) keyfile = __load_key_file(path); if (!keyfile) - keyfile = g_key_file_new(); + keyfile = g_key_file_new(); //LCOV_EXCL_LINE value = g_key_file_get_integer(keyfile, path, key, NULL); @@ -125,10 +127,12 @@ int stc_util_get_config_int(char *key) return value; } +//LCOV_EXCL_START API void stc_util_set_debuglog(int debuglog) { g_debuglog = debuglog; } +//LCOV_EXCL_STOP API int stc_util_get_debuglog(void) { @@ -147,7 +151,7 @@ void stc_util_initialize_config(void) keyfile = __load_key_file(path); if (!keyfile) - keyfile = g_key_file_new(); + keyfile = g_key_file_new(); //LCOV_EXCL_LINE g_key_file_set_integer(keyfile, path, INFO_DEBUGLOG, 0); diff --git a/src/stc-manager.c b/src/stc-manager.c index 5e7ddd6..d9a4d80 100755 --- a/src/stc-manager.c +++ b/src/stc-manager.c @@ -59,6 +59,7 @@ static void __stc_manager_deinit(void) stc_deinit_db_guard(); stc_db_deinitialize(); + iptables_flush_chains(); iptables_deinit(); stc_manager_gdbus_deinit((gpointer)g_stc); stc_app_lifecycle_monitor_deinit(); @@ -77,8 +78,8 @@ static stc_s *__stc_manager_init(void) stc = MALLOC0(stc_s, 1); if (!stc) { - STC_LOGE("Failed to allocate memory for manager structure"); - return NULL; + STC_LOGE("Failed to allocate memory for manager structure"); //LCOV_EXCL_LINE + return NULL; //LCOV_EXCL_LINE } g_stc = stc; @@ -101,9 +102,9 @@ static stc_s *__stc_manager_init(void) return stc; handle_error: - STC_LOGD("Failed to initialize stc manager"); - __stc_manager_deinit(); - return NULL; + STC_LOGD("Failed to initialize stc manager"); //LCOV_EXCL_LINE + __stc_manager_deinit(); //LCOV_EXCL_LINE + return NULL; //LCOV_EXCL_LINE } stc_s *stc_get_manager(void) @@ -111,6 +112,12 @@ stc_s *stc_get_manager(void) return g_stc; } +void stc_stop_manager(void) +{ + if (g_stc && g_stc->main_loop) + g_main_loop_quit(g_stc->main_loop); +} + gint32 main(gint32 argc, gchar *argv[]) { GMainLoop *main_loop = NULL; @@ -118,8 +125,12 @@ gint32 main(gint32 argc, gchar *argv[]) STC_LOGI("Smart Traffic Control Manager"); +#ifdef TIZEN_GTESTS + setenv("GCOV_PREFIX", "/tmp/daemon", 1); +#endif + if (daemon(0, 0) != 0) - STC_LOGE("Can't start daemon"); + STC_LOGE("Can't start daemon"); //LCOV_EXCL_LINE /* Initialize required subsystems */ #if !GLIB_CHECK_VERSION(2, 35, 0) diff --git a/src/stc-restriction.c b/src/stc-restriction.c index ab3d350..e8a8a7d 100755 --- a/src/stc-restriction.c +++ b/src/stc-restriction.c @@ -56,34 +56,34 @@ gboolean __validate_rstn_rule(table_restrictions_info *rule, __STC_LOG_FUNC_ENTER__; if (rule == NULL) { - __STC_LOG_FUNC_EXIT__; - return FALSE; + __STC_LOG_FUNC_EXIT__; //LCOV_EXCL_LINE + return FALSE; //LCOV_EXCL_LINE } if (rst_type <= RST_UNDEFINDED || rst_type >= RST_MAX_VALUE) { - __STC_LOG_FUNC_EXIT__; - return FALSE; + __STC_LOG_FUNC_EXIT__; //LCOV_EXCL_LINE + return FALSE; //LCOV_EXCL_LINE } if (rule->iftype <= STC_IFACE_UNKNOWN || rule->iftype >= STC_IFACE_LAST_ELEM) { - __STC_LOG_FUNC_EXIT__; - return FALSE; + __STC_LOG_FUNC_EXIT__; //LCOV_EXCL_LINE + return FALSE; //LCOV_EXCL_LINE } if (rule->roaming >= STC_ROAMING_LAST_ELEM) { - __STC_LOG_FUNC_EXIT__; - return FALSE; + __STC_LOG_FUNC_EXIT__; //LCOV_EXCL_LINE + return FALSE; //LCOV_EXCL_LINE } if (rule->subscriber_id == NULL) { - __STC_LOG_FUNC_EXIT__; - return FALSE; + __STC_LOG_FUNC_EXIT__; //LCOV_EXCL_LINE + return FALSE; //LCOV_EXCL_LINE } if (rule->app_id == NULL) { - __STC_LOG_FUNC_EXIT__; - return FALSE; + __STC_LOG_FUNC_EXIT__; //LCOV_EXCL_LINE + return FALSE; //LCOV_EXCL_LINE } __STC_LOG_FUNC_EXIT__; @@ -96,8 +96,8 @@ void __stc_restriction_app_info_builder_add(GVariantBuilder *builder, __STC_LOG_FUNC_ENTER__; if (!builder || !info) { - __STC_LOG_FUNC_EXIT__; - return; + __STC_LOG_FUNC_EXIT__; //LCOV_EXCL_LINE + return; //LCOV_EXCL_LINE } g_variant_builder_add(builder, "{sv}", "app_id", @@ -135,8 +135,8 @@ stc_cb_ret_e __table_restrictions_foreach_app_cb(const table_restrictions_info * GVariantBuilder sub_builder; if (!info || !builder) { - __STC_LOG_FUNC_EXIT__; - return STC_CANCEL; + __STC_LOG_FUNC_EXIT__; //LCOV_EXCL_LINE + return STC_CANCEL; //LCOV_EXCL_LINE } g_variant_builder_init(&sub_builder, G_VARIANT_TYPE("a{sv}")); @@ -156,8 +156,8 @@ stc_cb_ret_e __table_restrictions_per_app_cb(const table_restrictions_info *info GVariantBuilder *builder = (GVariantBuilder *)user_data; if (!info || !builder) { - __STC_LOG_FUNC_EXIT__; - return STC_CANCEL; + __STC_LOG_FUNC_EXIT__; //LCOV_EXCL_LINE + return STC_CANCEL; //LCOV_EXCL_LINE } __stc_restriction_app_info_builder_add(builder, info); @@ -174,8 +174,8 @@ static void __stc_extract_restriction_rule(const char *key, GVariant *value, table_restrictions_info *rule = (table_restrictions_info *) user_data; if (rule == NULL) { - __STC_LOG_FUNC_EXIT__; - return; + __STC_LOG_FUNC_EXIT__; //LCOV_EXCL_LINE + return; //LCOV_EXCL_LINE } if (!g_strcmp0(key, "app_id")) { @@ -213,7 +213,7 @@ static void __stc_extract_restriction_rule(const char *key, GVariant *value, STC_LOGD("subscriber_id: [%s]", rule->subscriber_id); } else { - STC_LOGD("Unknown select rule"); + STC_LOGD("Unknown select rule"); //LCOV_EXCL_LINE } __STC_LOG_FUNC_EXIT__; @@ -242,9 +242,9 @@ gboolean handle_restriction_set(StcRestriction *object, rule.rst_state = STC_RESTRICTION_REMOVED; if (__validate_rstn_rule(&rule, RST_SET) == FALSE) { - STC_RESTRICTION_DBUS_REPLY_ERROR(invocation, + STC_RESTRICTION_DBUS_REPLY_ERROR(invocation, //LCOV_EXCL_LINE STC_ERROR_INVALID_PARAMETER); - __STC_LOG_FUNC_EXIT__; + __STC_LOG_FUNC_EXIT__; //LCOV_EXCL_LINE return TRUE; } @@ -280,9 +280,9 @@ gboolean handle_restriction_exclude(StcRestriction *object, rule.rst_state = STC_RESTRICTION_EXCLUDED; if (__validate_rstn_rule(&rule, RST_EXCLUDE) == FALSE) { - STC_RESTRICTION_DBUS_REPLY_ERROR(invocation, + STC_RESTRICTION_DBUS_REPLY_ERROR(invocation, //LCOV_EXCL_LINE STC_ERROR_INVALID_PARAMETER); - __STC_LOG_FUNC_EXIT__; + __STC_LOG_FUNC_EXIT__; //LCOV_EXCL_LINE return TRUE; } @@ -316,9 +316,9 @@ gboolean handle_restriction_unset(StcRestriction *object, } if (__validate_rstn_rule(&rule, RST_UNSET) == FALSE) { - STC_RESTRICTION_DBUS_REPLY_ERROR(invocation, + STC_RESTRICTION_DBUS_REPLY_ERROR(invocation, //LCOV_EXCL_LINE STC_ERROR_INVALID_PARAMETER); - __STC_LOG_FUNC_EXIT__; + __STC_LOG_FUNC_EXIT__; //LCOV_EXCL_LINE return TRUE; } @@ -347,10 +347,10 @@ gboolean handle_restriction_get(StcRestriction *object, __table_restrictions_per_app_cb, builder); if (ret < STC_ERROR_NONE) { - g_variant_builder_unref(builder); - STC_RESTRICTION_DBUS_REPLY_ERROR(invocation, ret); - __STC_LOG_FUNC_EXIT__; - return TRUE; + g_variant_builder_unref(builder); //LCOV_EXCL_LINE + STC_RESTRICTION_DBUS_REPLY_ERROR(invocation, ret); //LCOV_EXCL_LINE + __STC_LOG_FUNC_EXIT__; //LCOV_EXCL_LINE + return TRUE; //LCOV_EXCL_LINE } return_parameters = g_variant_new("(ia{sv})", STC_ERROR_NONE, builder); @@ -376,10 +376,10 @@ gboolean handle_restriction_get_all(StcRestriction *object, ret = table_restrictions_foreach(__table_restrictions_foreach_app_cb, builder); if (ret < STC_ERROR_NONE) { - g_variant_builder_unref(builder); - STC_RESTRICTION_DBUS_REPLY_ERROR(invocation, ret); - __STC_LOG_FUNC_EXIT__; - return TRUE; + g_variant_builder_unref(builder); //LCOV_EXCL_LINE + STC_RESTRICTION_DBUS_REPLY_ERROR(invocation, ret); //LCOV_EXCL_LINE + __STC_LOG_FUNC_EXIT__; //LCOV_EXCL_LINE + return TRUE; //LCOV_EXCL_LINE } return_parameters = g_variant_new("(iaa{sv})", STC_ERROR_NONE, builder); @@ -404,8 +404,8 @@ gboolean handle_restriction_get_state(StcRestriction *object, ret = table_restrictions_get_restriction_state(app_id, iftype, &state); if (ret < STC_ERROR_NONE) { - STC_RESTRICTION_DBUS_REPLY_ERROR(invocation, ret); - __STC_LOG_FUNC_EXIT__; + STC_RESTRICTION_DBUS_REPLY_ERROR(invocation, ret); //LCOV_EXCL_LINE + __STC_LOG_FUNC_EXIT__; //LCOV_EXCL_LINE return TRUE; } diff --git a/src/stc-statistics.c b/src/stc-statistics.c index fd4544d..70cf48c 100755 --- a/src/stc-statistics.c +++ b/src/stc-statistics.c @@ -61,15 +61,11 @@ void __stc_extract_select_rule(const char *key, GVariant *value, table_statistics_select_rule *rule = (table_statistics_select_rule *) user_data; if (rule == NULL) { - __STC_LOG_FUNC_EXIT__; - return; + __STC_LOG_FUNC_EXIT__; //LCOV_EXCL_LINE + return; //LCOV_EXCL_LINE } - if (!g_strcmp0(key, "version")) { - rule->version = g_variant_get_byte(value); - STC_LOGD("version: [%u]", (unsigned int) rule->version); - - } else if (!g_strcmp0(key, "from")) { + if (!g_strcmp0(key, "from")) { rule->from = g_variant_get_uint64(value); STC_LOGD("from: [%lu]", rule->from); @@ -81,12 +77,8 @@ void __stc_extract_select_rule(const char *key, GVariant *value, rule->iftype = g_variant_get_uint16(value); STC_LOGD("iftype: [%u]", (unsigned int) rule->iftype); - } else if (!g_strcmp0(key, "granularity")) { - rule->granularity = g_variant_get_int32(value); - STC_LOGD("granularity: [%d]", rule->granularity); - } else { - STC_LOGD("Unknown select rule"); + STC_LOGD("Unknown select rule"); //LCOV_EXCL_LINE } __STC_LOG_FUNC_EXIT__; @@ -100,15 +92,11 @@ void __stc_extract_reset_rule(const char *key, GVariant *value, table_statistics_reset_rule *rule = (table_statistics_reset_rule *) user_data; if (rule == NULL) { - __STC_LOG_FUNC_EXIT__; - return; + __STC_LOG_FUNC_EXIT__; //LCOV_EXCL_LINE + return; //LCOV_EXCL_LINE } - if (!g_strcmp0(key, "version")) { - rule->version = g_variant_get_byte(value); - STC_LOGD("version: [%u]", (unsigned int) rule->version); - - } else if (!g_strcmp0(key, "app_id")) { + if (!g_strcmp0(key, "app_id")) { gsize len = 0; rule->app_id = g_variant_dup_string(value, &len); STC_LOGD("app_id: [%s]", rule->app_id); @@ -124,10 +112,10 @@ void __stc_extract_reset_rule(const char *key, GVariant *value, } else if (!g_strcmp0(key, "from")) { if (!(rule->interval)) { - rule->interval = MALLOC0(stc_db_tm_interval_s, 1); - if (!(rule->interval)) { - __STC_LOG_FUNC_EXIT__; - return; + rule->interval = MALLOC0(stc_db_tm_interval_s, 1); //LCOV_EXCL_LINE + if (!(rule->interval)) { //LCOV_EXCL_LINE + __STC_LOG_FUNC_EXIT__; //LCOV_EXCL_LINE + return; //LCOV_EXCL_LINE } } @@ -136,22 +124,18 @@ void __stc_extract_reset_rule(const char *key, GVariant *value, } else if (!g_strcmp0(key, "to")) { if (!(rule->interval)) { - rule->interval = MALLOC0(stc_db_tm_interval_s, 1); - if (!(rule->interval)) { - __STC_LOG_FUNC_EXIT__; - return; + rule->interval = MALLOC0(stc_db_tm_interval_s, 1); //LCOV_EXCL_LINE + if (!(rule->interval)) { //LCOV_EXCL_LINE + __STC_LOG_FUNC_EXIT__; //LCOV_EXCL_LINE + return; //LCOV_EXCL_LINE } } rule->interval->to = g_variant_get_uint64(value); STC_LOGD("to: [%lu]", rule->interval->to); - } else if (!g_strcmp0(key, "connection_state")) { - rule->connection_state = g_variant_get_int32(value); - STC_LOGD("connection_state: [%d]", rule->connection_state); - } else { - STC_LOGD("Unknown reset rule"); + STC_LOGD("Unknown reset rule"); //LCOV_EXCL_LINE } __STC_LOG_FUNC_EXIT__; @@ -163,8 +147,8 @@ void __stc_statistics_app_info_builder_add(GVariantBuilder *builder, __STC_LOG_FUNC_ENTER__; if (!builder || !info) { - __STC_LOG_FUNC_EXIT__; - return; + __STC_LOG_FUNC_EXIT__; //LCOV_EXCL_LINE + return; //LCOV_EXCL_LINE } if (info->app_id) @@ -215,8 +199,8 @@ stc_cb_ret_e __table_statistics_foreach_app_cb(const table_statistics_info *info GVariantBuilder sub_builder; if (!info || !builder) { - __STC_LOG_FUNC_EXIT__; - return STC_CANCEL; + __STC_LOG_FUNC_EXIT__; //LCOV_EXCL_LINE + return STC_CANCEL; //LCOV_EXCL_LINE } g_variant_builder_init(&sub_builder, G_VARIANT_TYPE("a{sv}")); @@ -237,8 +221,8 @@ stc_cb_ret_e __table_statistics_per_app_cb(const table_statistics_info *info, GVariantBuilder sub_builder; if (!info || !builder) { - __STC_LOG_FUNC_EXIT__; - return STC_CANCEL; + __STC_LOG_FUNC_EXIT__; //LCOV_EXCL_LINE + return STC_CANCEL; //LCOV_EXCL_LINE } g_variant_builder_init(&sub_builder, G_VARIANT_TYPE("a{sv}")); @@ -281,7 +265,7 @@ gboolean handle_statistics_get_all(StcStatistics *object, g_variant_iter_free(iter); } } else { - STC_LOGD("No selection rule, using default selection rule."); + STC_LOGD("No selection rule, using default selection rule."); //LCOV_EXCL_LINE } builder = g_variant_builder_new(G_VARIANT_TYPE("aa{sv}")); @@ -290,10 +274,10 @@ gboolean handle_statistics_get_all(StcStatistics *object, __table_statistics_foreach_app_cb, builder); if (ret < STC_ERROR_NONE) { - g_variant_builder_unref(builder); - STC_STATISTICS_DBUS_REPLY_ERROR(invocation, ret); - __STC_LOG_FUNC_EXIT__; - return TRUE; + g_variant_builder_unref(builder); //LCOV_EXCL_LINE + STC_STATISTICS_DBUS_REPLY_ERROR(invocation, ret); //LCOV_EXCL_LINE + __STC_LOG_FUNC_EXIT__; //LCOV_EXCL_LINE + return TRUE; //LCOV_EXCL_LINE } return_parameters = g_variant_new("(iaa{sv})", STC_ERROR_NONE, builder); @@ -349,7 +333,7 @@ gboolean handle_statistics_get(StcStatistics *object, g_variant_iter_free(iter); } } else { - STC_LOGD("No selection rule, using default selection rule."); + STC_LOGD("No selection rule, using default selection rule."); //LCOV_EXCL_LINE } builder = g_variant_builder_new(G_VARIANT_TYPE("aa{sv}")); @@ -358,10 +342,10 @@ gboolean handle_statistics_get(StcStatistics *object, __table_statistics_per_app_cb, builder); if (ret < STC_ERROR_NONE) { - g_variant_builder_unref(builder); - STC_STATISTICS_DBUS_REPLY_ERROR(invocation, ret); - __STC_LOG_FUNC_EXIT__; - return TRUE; + g_variant_builder_unref(builder); //LCOV_EXCL_LINE + STC_STATISTICS_DBUS_REPLY_ERROR(invocation, ret); //LCOV_EXCL_LINE + __STC_LOG_FUNC_EXIT__; //LCOV_EXCL_LINE + return TRUE; //LCOV_EXCL_LINE } return_parameters = g_variant_new("(iaa{sv})", STC_ERROR_NONE, builder); @@ -396,13 +380,13 @@ gboolean handle_statistics_reset(StcStatistics *object, g_variant_iter_free(iter); } } else { - STC_LOGD("No selection rule, using default selection rule."); + STC_LOGD("No selection rule, using default selection rule."); //LCOV_EXCL_LINE } ret = table_statistics_reset(&rule); if (ret < STC_ERROR_NONE) { - STC_STATISTICS_DBUS_REPLY_ERROR(invocation, ret); - goto handle_error; + STC_STATISTICS_DBUS_REPLY_ERROR(invocation, ret); //LCOV_EXCL_LINE + goto handle_error; //LCOV_EXCL_LINE } return_parameters = g_variant_new("(i)", STC_ERROR_NONE); diff --git a/unittest/CMakeLists.txt b/unittest/CMakeLists.txt new file mode 100755 index 0000000..7cb1f4f --- /dev/null +++ b/unittest/CMakeLists.txt @@ -0,0 +1,32 @@ +CMAKE_MINIMUM_REQUIRED(VERSION 2.6) +PROJECT(gtest-stc-manager C CXX) + +SET(GTEST_TEST "gtest-stc-manager") +ADD_DEFINITIONS("-DUSE_DLOG") + +SET(REQUIRES_LIST ${REQUIRES_LIST} + glib-2.0 + gio-2.0 + gmock + dlog +) + +INCLUDE(FindPkgConfig) +PKG_CHECK_MODULES(GTEST_TEST_PKG REQUIRED ${REQUIRES_LIST}) + +FOREACH(flag ${GTEST_TEST_PKG_CFLAGS}) + SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}") +ENDFOREACH(flag) + +SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -Wall -fPIE") +SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS}") +SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${EXTRA_CFLAGS}") +SET(CMAKE_EXE_LINKER_FLAGS "-Wl,--as-needed -pie") + +FILE(GLOB GTEST_TEST_SRCS *.cpp) +SET(GTEST_TEST_SRCS ${GTEST_TEST_SRCS}) + +ADD_EXECUTABLE(${GTEST_TEST} ${GTEST_TEST_SRCS}) +TARGET_LINK_LIBRARIES(${GTEST_TEST} ${GTEST_TEST_LDFLAGS} ${GTEST_TEST_PKG_LDFLAGS} -ldl -lgcov) + +INSTALL(TARGETS ${GTEST_TEST} RUNTIME DESTINATION ${BIN_DIR}) diff --git a/unittest/gdbus.cpp b/unittest/gdbus.cpp new file mode 100755 index 0000000..e882fea --- /dev/null +++ b/unittest/gdbus.cpp @@ -0,0 +1,185 @@ +/* + * Copyright (c) 2017 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include + +#include "gdbus.h" + +GDbus::GDbus() +{ + this->m_pConnection = NULL; + this->m_pCancellable = NULL; +} + +GDbus::~GDbus() +{ + GDBusConnection *conn = this->m_pConnection; + GCancellable *cancel = this->m_pCancellable; + + if (cancel) { + g_cancellable_cancel(cancel); + g_object_unref(cancel); + cancel = NULL; + } + + if (conn) { + g_object_unref(conn); + conn = NULL; + } +} + +error_e GDbus::Create(void) +{ + GError *err = NULL; + +#if !GLIB_CHECK_VERSION(2, 36, 0) + g_type_init(); +#endif + + this->m_pConnection = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &err); + if (this->m_pConnection == NULL) { + if (err != NULL) { + GLOGD("Failed to connect to the D-BUS daemon [%s]", err->message); + g_error_free(err); + } + + return ERROR_OPERATION_FAILED; + } + + this->m_pCancellable = g_cancellable_new(); + + return ERROR_NONE; +} + +error_e GDbus::Destroy(void) +{ + g_cancellable_cancel(this->m_pCancellable); + g_object_unref(this->m_pCancellable); + this->m_pCancellable = NULL; + + g_object_unref(this->m_pConnection); + this->m_pConnection = NULL; + + return ERROR_NONE; +} + +GDBusConnection *GDbus::GetConnection(void) +{ + return this->m_pConnection; +} + +GCancellable *GDbus::GetCancellable(void) +{ + return this->m_pCancellable; +} + +error_e GDbus::ConvertErrorStringToEnum(const char *error) +{ + if (NULL != strstr(error, "NoReply")) + return ERROR_INVALID_OPERATION; + else if (NULL != strstr(error, "Failed")) + return ERROR_OPERATION_FAILED; + else if (NULL != strstr(error, "UnknownMethod")) + return ERROR_INVALID_OPERATION; + else if (NULL != strstr(error, "InvalidArguments")) + return ERROR_INVALID_PARAMETER; + else if (NULL != strstr(error, "AccessDenied")) + return ERROR_PERMISSION_DENIED; + else if (NULL != strstr(error, "PermissionDenied")) + return ERROR_PERMISSION_DENIED; + else if (NULL != strstr(error, "NotSupported")) + return ERROR_NOT_SUPPORTED; + else if (NULL != strstr(error, "InProgress")) + return ERROR_IN_PROGRESS; + + return ERROR_OPERATION_FAILED; +} + +GVariant *GDbus::InvokeMethod(const char *dest, const char *path, + const char *iface_name, const char *method, GVariant *params, error_e *dbus_error) +{ + GError *error = NULL; + GVariant *reply = NULL; + GDBusConnection *connection = NULL; + *dbus_error = ERROR_NONE; + + connection = GetConnection(); + if (connection == NULL) { + GLOGD("GDBusconnection is NULL"); + *dbus_error = ERROR_NOT_INITIALIZED; + return reply; + } + + reply = g_dbus_connection_call_sync(connection, + dest, + path, + iface_name, + method, + params, + NULL, + G_DBUS_CALL_FLAGS_NONE, + DBUS_REPLY_TIMEOUT, + GetCancellable(), + &error); + + if (reply == NULL) { + if (error != NULL) { + GLOGD("g_dbus_connection_call_sync() failed " + "error [%d: %s]", error->code, error->message); + *dbus_error = ConvertErrorStringToEnum(error->message); + g_error_free(error); + } else { + GLOGD("g_dbus_connection_call_sync() failed"); + *dbus_error = ERROR_OPERATION_FAILED; + } + + return NULL; + } + + return reply; +} + +error_e GDbus::InvokeMethodNonblock(const char *dest, const char *path, + const char *iface_name, const char *method, GVariant *params, int timeout, + GAsyncReadyCallback notify_func, void *user_data) +{ + GDBusConnection *connection = NULL; + + connection = GetConnection(); + if (connection == NULL) { + GLOGD("GDBusconnection is NULL"); + return ERROR_NOT_INITIALIZED; + } + + g_dbus_connection_call(connection, + dest, + path, + iface_name, + method, + params, + NULL, + G_DBUS_CALL_FLAGS_NONE, + timeout, + GetCancellable(), + (GAsyncReadyCallback) notify_func, + (gpointer)user_data); + + return ERROR_NONE; +} diff --git a/unittest/gdbus.h b/unittest/gdbus.h new file mode 100755 index 0000000..91596a9 --- /dev/null +++ b/unittest/gdbus.h @@ -0,0 +1,70 @@ +/* + * Copyright (c) 2017 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#ifndef __STC_MGR_GDBUS_H__ +#define __STC_MGR_GDBUS_H__ + +#include +#include + +#include "stcmgr.h" + +#define GMAINTIMEOUT 10000 +#define DBUS_REPLY_TIMEOUT (120 * 1000) + +#define STC_MGR_SERVICE "net.stc" +#define STC_MGR_STATISTICS_INTERFACE STC_MGR_SERVICE ".statistics" +#define STC_MGR_RESTRICTION_INTERFACE STC_MGR_SERVICE ".restriction" +#define STC_MGR_MANAGER_INTERFACE STC_MGR_SERVICE ".manager" + +#define STC_MGR_STATISTICS_PATH "/net/stc/statistics" +#define STC_MGR_RESTRICTION_PATH "/net/stc/restriction" +#define STC_MGR_MANAGER_PATH "/net/stc/manager" + +#define STC_MGR_METHOD_STATISTICS_INIT "Init" +#define STC_MGR_METHOD_STATISTICS_GET_PER_APP_ID "Get" +#define STC_MGR_METHOD_STATISTICS_GET_ALL "GetAll" +#define STC_MGR_METHOD_STATISTICS_GET_TOTAL "Get" +#define STC_MGR_METHOD_STATISTICS_RESET "Reset" + +#define STC_MGR_METHOD_RESTRICTION_SET "Set" +#define STC_MGR_METHOD_RESTRICTION_GET_STATUS "GetState" +#define STC_MGR_METHOD_RESTRICTION_GET_PER_APP_ID "Get" +#define STC_MGR_METHOD_RESTRICTION_GET_ALL "GetAll" +#define STC_MGR_METHOD_RESTRICTION_UNSET "Unset" +#define STC_MGR_METHOD_RESTRICTION_EXCLUDE "Exclude" + +#define STC_MGR_METHOD_MANAGER_STOP "Stop" + +class GDbus { +private: + GDBusConnection *m_pConnection; + GCancellable *m_pCancellable; +public: + GDbus(); + ~GDbus(); + error_e Create(void); + error_e Destroy(void); + GDBusConnection *GetConnection(void); + GCancellable *GetCancellable(void); + error_e ConvertErrorStringToEnum(const char *error); + GVariant *InvokeMethod(const char *dest, const char *path, + const char *iface_name, const char *method, GVariant *params, error_e *dbus_error); + error_e InvokeMethodNonblock(const char *dest, const char *path, + const char *iface_name, const char *method, GVariant *params, int timeout, + GAsyncReadyCallback notify_func, void *user_data); +}; + +#endif /* __STC_MGR_GDBUS_H__ */ diff --git a/unittest/manager.cpp b/unittest/manager.cpp new file mode 100755 index 0000000..a99149c --- /dev/null +++ b/unittest/manager.cpp @@ -0,0 +1,58 @@ +/* + * Copyright (c) 2017 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include + +#include "manager.h" + +Manager::Manager() +{ + Create(); +} + +Manager::~Manager() +{ + Destroy(); +} + +error_e Manager::StopManager(void) +{ + GVariant *message = NULL; + error_e error = ERROR_NONE; + int result = 0; + + message = InvokeMethod(STC_MGR_SERVICE, + STC_MGR_MANAGER_PATH, + STC_MGR_MANAGER_INTERFACE, + STC_MGR_METHOD_MANAGER_STOP, + NULL, + &error); + + if (message == NULL) { + GLOGD("Failed to invoke dbus method"); + return error; + } + + g_variant_get(message, "(i)", &result); + GLOGD("Successfully stop manager [%d]", result); + g_variant_unref(message); + + return ERROR_NONE; +} diff --git a/unittest/manager.h b/unittest/manager.h new file mode 100755 index 0000000..61b31ca --- /dev/null +++ b/unittest/manager.h @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2017 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#ifndef __STC_MGR_MANAGER_H__ +#define __STC_MGR_MANAGER_H__ + +#include "stcmgr.h" +#include "gdbus.h" + +class Manager : public GDbus { +private: +public: + Manager(); + ~Manager(); + error_e StopManager(void); +}; + + +#endif /* __STC_MGR_MANAGER_H__ */ diff --git a/unittest/restriction.cpp b/unittest/restriction.cpp new file mode 100755 index 0000000..0c09ddc --- /dev/null +++ b/unittest/restriction.cpp @@ -0,0 +1,343 @@ +/* + * Copyright (c) 2017 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include + +#include "restriction.h" + +static GMainLoop *g_pMainLoop = NULL; +static guint g_nTimeoutId = 0; + +static gboolean CallbackTimeut(gpointer data) +{ + if (g_pMainLoop) + g_main_loop_quit(g_pMainLoop); + + return false; +} + +static void RunMainLoop(void) +{ + g_pMainLoop = g_main_loop_new(NULL, false); + g_nTimeoutId = g_timeout_add(GMAINTIMEOUT, CallbackTimeut, g_pMainLoop); + g_main_loop_run(g_pMainLoop); + + g_source_remove(g_nTimeoutId); + g_pMainLoop = NULL; +} + +static void QuitMainLoop(void) +{ + if (g_pMainLoop) + g_main_loop_quit(g_pMainLoop); +} + +static void AsyncReadyCallback(GObject *source_object, + GAsyncResult *res, gpointer user_data) +{ + GLOGD("Succeeded to response async callback"); + QuitMainLoop(); +} + +RRule::RRule() +{ + this->m_AppID[0] = '\0'; + this->m_IfaceName[0] = '\0'; + this->m_IfaceType = IFACE_ALL; + this->m_DataLimit = 0; + this->m_DataWarnLimit = 0; + this->m_RoamingType = ROAMING_DISABLED; + this->m_SubscriberID[0] = '\0'; +} + +RRule::~RRule() +{ +} + +Restriction::Restriction() +{ + Create(); +} + +Restriction::~Restriction() +{ + Destroy(); +} + +error_e Restriction::SetRule(const char *app_id, const char *iface_name, + const char *subscriber_id, iface_type_e iface_type, + int64_t data_limit, int64_t data_warn_limit, + roaming_type_e roaming_type) +{ + if (app_id == NULL || strlen(app_id) == 0) + this->m_Rule.m_AppID[0] = '\0'; + else + g_strlcpy(this->m_Rule.m_AppID, app_id, APP_ID_LEN); + + if (iface_name == NULL || strlen(iface_name) == 0) + this->m_Rule.m_IfaceName[0] = '\0'; + else + g_strlcpy(this->m_Rule.m_IfaceName, iface_name, IFNAME_LEN); + + if (subscriber_id == NULL || strlen(subscriber_id) == 0) + this->m_Rule.m_SubscriberID[0] = '\0'; + else + g_strlcpy(this->m_Rule.m_SubscriberID, subscriber_id, SUBSCRIBER_ID_LEN); + + switch(iface_type) { + case IFACE_UNKNOWN: + case IFACE_DATACALL: + case IFACE_WIFI: + case IFACE_WIRED: + case IFACE_BLUETOOTH: + case IFACE_ALL: + this->m_Rule.m_IfaceType = iface_type; + break; + default: + return ERROR_INVALID_PARAMETER; + } + + switch(roaming_type) { + case ROAMING_UNKNOWN: + case ROAMING_ENABLED: + case ROAMING_DISABLED: + this->m_Rule.m_RoamingType = roaming_type; + break; + default: + return ERROR_INVALID_PARAMETER; + } + + this->m_Rule.m_DataLimit = data_limit; + this->m_Rule.m_DataWarnLimit = data_warn_limit; + + return ERROR_NONE; +} + +void Restriction::MakeRuleParams(GVariant **params) +{ + GVariantBuilder *builder; + + builder = g_variant_builder_new(G_VARIANT_TYPE("a{sv}")); + + g_variant_builder_add(builder, "{sv}", + RESTRICTION_RULE_APP_ID, + g_variant_new_string(this->m_Rule.m_AppID)); + + g_variant_builder_add(builder, "{sv}", + RESTRICTION_RULE_IFNAME, + g_variant_new_string(this->m_Rule.m_IfaceName)); + + g_variant_builder_add(builder, "{sv}", + RESTRICTION_RULE_IFTYPE, + g_variant_new_uint16(this->m_Rule.m_IfaceType)); + + g_variant_builder_add(builder, "{sv}", + RESTRICTION_RULE_ROAMING, + g_variant_new_uint16(this->m_Rule.m_RoamingType)); + + g_variant_builder_add(builder, "{sv}", + RESTRICTION_RULE_SUBSCRIBER_ID, + g_variant_new_string(this->m_Rule.m_SubscriberID)); + + g_variant_builder_add(builder, "{sv}", + RESTRICTION_RULE_DATA_LIMIT, + g_variant_new_int64(this->m_Rule.m_DataLimit)); + + g_variant_builder_add(builder, "{sv}", + RESTRICTION_RULE_DATA_WARN_LIMIT, + g_variant_new_int64(this->m_Rule.m_DataWarnLimit)); + + *params = g_variant_new("(@a{sv})", g_variant_builder_end(builder)); + g_variant_builder_unref(builder); +} + +void Restriction::MakeGetParams(GVariant **params) +{ + *params = g_variant_new("(s)", this->m_Rule.m_AppID); +} + +void Restriction::MakeStatusParams(GVariant **params) +{ + *params = g_variant_new("(si)", + this->m_Rule.m_AppID, this->m_Rule.m_IfaceType); +} + +error_e Restriction::SetRstriction(void) +{ + GVariant *message = NULL; + GVariant *params = NULL; + error_e error = ERROR_NONE; + int result = 0; + + MakeRuleParams(¶ms); + + message = InvokeMethod(STC_MGR_SERVICE, + STC_MGR_RESTRICTION_PATH, + STC_MGR_RESTRICTION_INTERFACE, + STC_MGR_METHOD_RESTRICTION_SET, + params, + &error); + + if (message == NULL) { + GLOGD("Failed to invoke dbus method"); + return error; + } + + g_variant_get(message, "(i)", &result); + GLOGD("Succeeded to set restriction [%d]", result); + g_variant_unref(message); + + return ERROR_NONE; +} + +error_e Restriction::ExcludeRstriction(void) +{ + GVariant *message = NULL; + GVariant *params = NULL; + error_e error = ERROR_NONE; + int result = 0; + + MakeRuleParams(¶ms); + + message = InvokeMethod(STC_MGR_SERVICE, + STC_MGR_RESTRICTION_PATH, + STC_MGR_RESTRICTION_INTERFACE, + STC_MGR_METHOD_RESTRICTION_EXCLUDE, + params, + &error); + + if (message == NULL) { + GLOGD("Failed to invoke dbus method"); + return error; + } + + g_variant_get(message, "(i)", &result); + GLOGD("Succeeded to exclude restriction [%d]", result); + g_variant_unref(message); + + return ERROR_NONE; +} + +error_e Restriction::UnsetRstriction(void) +{ + GVariant *message = NULL; + GVariant *params = NULL; + error_e error = ERROR_NONE; + int result = 0; + + MakeRuleParams(¶ms); + + message = InvokeMethod(STC_MGR_SERVICE, + STC_MGR_RESTRICTION_PATH, + STC_MGR_RESTRICTION_INTERFACE, + STC_MGR_METHOD_RESTRICTION_UNSET, + params, + &error); + + if (message == NULL) { + GLOGD("Failed to invoke dbus method"); + return error; + } + + g_variant_get(message, "(i)", &result); + GLOGD("Succeeded to unset restriction [%d]", result); + g_variant_unref(message); + + return ERROR_NONE; +} + +error_e Restriction::GetRstrictionStatus(restriction_status_e *status) +{ + GVariant *message = NULL; + GVariant *params = NULL; + error_e error = ERROR_NONE; + int result = 0; + + MakeStatusParams(¶ms); + + message = InvokeMethod(STC_MGR_SERVICE, + STC_MGR_RESTRICTION_PATH, + STC_MGR_RESTRICTION_INTERFACE, + STC_MGR_METHOD_RESTRICTION_GET_STATUS, + params, + &error); + + if (message == NULL) { + GLOGD("Failed to invoke dbus method"); + return error; + } + + g_variant_get(message, "(ii)", &result, status); + GLOGD("Succeeded to get restriction status [%d:%d]", result, *status); + g_variant_unref(message); + + return ERROR_NONE; +} + +error_e Restriction::GetRstriction(void) +{ + GVariant *params = NULL; + error_e error = ERROR_NONE; + + MakeGetParams(¶ms); + + error = InvokeMethodNonblock(STC_MGR_SERVICE, + STC_MGR_RESTRICTION_PATH, + STC_MGR_RESTRICTION_INTERFACE, + STC_MGR_METHOD_RESTRICTION_GET_PER_APP_ID, + params, + DBUS_REPLY_TIMEOUT, + AsyncReadyCallback, + NULL); + + if (error != ERROR_NONE) { + GLOGD("Failed to invoke dbus method nonblock"); + return error; + } + + GLOGD("Succeeded to get restriction per app ID"); + + RunMainLoop(); + return ERROR_NONE; +} + +error_e Restriction::GetAllRstriction(void) +{ + error_e error = ERROR_NONE; + + error = InvokeMethodNonblock(STC_MGR_SERVICE, + STC_MGR_RESTRICTION_PATH, + STC_MGR_RESTRICTION_INTERFACE, + STC_MGR_METHOD_RESTRICTION_GET_ALL, + NULL, + DBUS_REPLY_TIMEOUT, + AsyncReadyCallback, + NULL); + + if (error != ERROR_NONE) { + GLOGD("Failed to invoke dbus method nonblock"); + return error; + } + + GLOGD("Succeeded to get all restriction"); + + RunMainLoop(); + return ERROR_NONE; +} \ No newline at end of file diff --git a/unittest/restriction.h b/unittest/restriction.h new file mode 100755 index 0000000..c0b0f2d --- /dev/null +++ b/unittest/restriction.h @@ -0,0 +1,78 @@ +/* + * Copyright (c) 2017 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#ifndef __STC_MGR_RESTRICTION_H__ +#define __STC_MGR_RESTRICTION_H__ + +#include +#include + +#include "stcmgr.h" +#include "gdbus.h" + +#define RESTRICTION_RULE_APP_ID "app_id" +#define RESTRICTION_RULE_IFNAME "ifname" +#define RESTRICTION_RULE_IFTYPE "iftype" +#define RESTRICTION_RULE_ROAMING "roaming" +#define RESTRICTION_RULE_SUBSCRIBER_ID "subscriber_id" +#define RESTRICTION_RULE_DATA_LIMIT "data_limit" +#define RESTRICTION_RULE_DATA_WARN_LIMIT "data_warn_limit" + +typedef enum { + RESTRICTION_UNKNOWN, + RESTRICTION_ACTIVATED, + RESTRICTION_REMOVED, + RESTRICTION_EXCLUDED, + RESTRICTION_BACKGROUND, + RESTRICTION_LAST_ELEM, +} restriction_status_e; + +class RRule { +private: +public: + char m_AppID[APP_ID_LEN]; + char m_IfaceName[IFNAME_LEN]; + char m_SubscriberID[SUBSCRIBER_ID_LEN]; + iface_type_e m_IfaceType; + int64_t m_DataLimit; + int64_t m_DataWarnLimit; + roaming_type_e m_RoamingType; + + RRule(); + ~RRule(); +}; + +class Restriction : public GDbus { +private: + RRule m_Rule; +public: + Restriction(); + ~Restriction(); + error_e SetRule(const char *app_id, const char *iface_name, + const char *subscriber_id, iface_type_e iface_type, + int64_t data_limit, int64_t data_warn_limit, + roaming_type_e roaming_type); + void MakeRuleParams(GVariant **params); + void MakeGetParams(GVariant **params); + void MakeStatusParams(GVariant **params); + error_e SetRstriction(void); + error_e ExcludeRstriction(void); + error_e UnsetRstriction(void); + error_e GetRstrictionStatus(restriction_status_e *status); + error_e GetRstriction(void); + error_e GetAllRstriction(void); +}; + +#endif /* __STC_MGR_RESTRICTION_H__ */ diff --git a/unittest/statistics.cpp b/unittest/statistics.cpp new file mode 100755 index 0000000..49ebd6a --- /dev/null +++ b/unittest/statistics.cpp @@ -0,0 +1,317 @@ +/* + * Copyright (c) 2017 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include + +#include "statistics.h" + +static GMainLoop *g_pMainLoop = NULL; +static guint g_nTimeoutId = 0; + +static gboolean CallbackTimeut(gpointer data) +{ + if (g_pMainLoop) + g_main_loop_quit(g_pMainLoop); + + return false; +} + +static void RunMainLoop(void) +{ + g_pMainLoop = g_main_loop_new(NULL, false); + g_nTimeoutId = g_timeout_add(GMAINTIMEOUT, CallbackTimeut, g_pMainLoop); + g_main_loop_run(g_pMainLoop); + + g_source_remove(g_nTimeoutId); + g_pMainLoop = NULL; +} + +static void QuitMainLoop(void) +{ + if (g_pMainLoop) + g_main_loop_quit(g_pMainLoop); +} + +static void AsyncReadyCallback(GObject *source_object, + GAsyncResult *res, gpointer user_data) +{ + GLOGD("Succeeded to response async callback"); + QuitMainLoop(); +} + +SRule::SRule() +{ + this->m_IfaceType = IFACE_UNKNOWN; + this->m_TimePeriod = TIME_PERIOD_UNKNOWN; + this->m_Interval.from = 0; + this->m_Interval.to = 0; +} + +SRule::~SRule() +{ +} + +Statistics::Statistics() +{ + Create(); +} + +Statistics::~Statistics() +{ + Destroy(); +} + +error_e Statistics::SetRule(const char *app_id, const char *subscriber_id, + iface_type_e iface_type, time_t from, time_t to, time_period_e time_period) +{ + if (app_id == NULL || strlen(app_id) == 0) + this->m_Rule.m_AppID[0] = '\0'; + else + g_strlcpy(this->m_Rule.m_AppID, app_id, APP_ID_LEN); + + if (subscriber_id == NULL || strlen(subscriber_id) == 0) + this->m_Rule.m_SubscriberID[0] = '\0'; + else + g_strlcpy(this->m_Rule.m_SubscriberID, subscriber_id, SUBSCRIBER_ID_LEN); + + switch(iface_type) { + case IFACE_UNKNOWN: + case IFACE_DATACALL: + case IFACE_WIFI: + case IFACE_WIRED: + case IFACE_BLUETOOTH: + case IFACE_ALL: + this->m_Rule.m_IfaceType = iface_type; + break; + default: + return ERROR_INVALID_PARAMETER; + } + + if (from < 0 || to < 0) + return ERROR_INVALID_PARAMETER; + + this->m_Rule.m_Interval.from = from; + this->m_Rule.m_Interval.to = to; + + switch(time_period) { + case TIME_PERIOD_UNKNOWN: + case TIME_PERIOD_HOUR: + case TIME_PERIOD_DAY: + case TIME_PERIOD_WEEK: + case TIME_PERIOD_MONTH: + this->m_Rule.m_TimePeriod = time_period; + break; + default: + return ERROR_INVALID_PARAMETER; + } + + return ERROR_NONE; +} + +time_t Statistics::MakeTime(int year, int mon, int day, int hour, int min) +{ + struct tm curr = { 0, }; + curr.tm_year = year - 1900; + curr.tm_mon = mon - 1; + curr.tm_mday = day; + curr.tm_hour = hour; + curr.tm_min = min; + return mktime(&curr); +} + +void Statistics::MakeRuleParams(GVariant **params, int mode) +{ + GVariantBuilder *builder; + + builder = g_variant_builder_new(G_VARIANT_TYPE("a{sv}")); + + g_variant_builder_add(builder, "{sv}", + STATISTICS_RULE_INTERVAL_FROM, + g_variant_new_uint64(this->m_Rule.m_Interval.from)); + + g_variant_builder_add(builder, "{sv}", + STATISTICS_RULE_INTERVAL_TO, + g_variant_new_uint64(this->m_Rule.m_Interval.to)); + + g_variant_builder_add(builder, "{sv}", + STATISTICS_RULE_IFTYPE, + g_variant_new_uint16(this->m_Rule.m_IfaceType)); + + g_variant_builder_add(builder, "{sv}", + STATISTICS_RULE_TIME_PERIOD, + g_variant_new_int32(this->m_Rule.m_TimePeriod)); + + switch (mode) { + case 0: /* reset */ + g_variant_builder_add(builder, "{sv}", + STATISTICS_RULE_APP_ID, + g_variant_new_string(this->m_Rule.m_AppID)); + + g_variant_builder_add(builder, "{sv}", + RESET_RULE_SUBSCRIBER_ID, + g_variant_new_string(this->m_Rule.m_SubscriberID)); + + *params = g_variant_new("(@a{sv})", g_variant_builder_end(builder)); + break; + case 1: /* get app */ + *params = g_variant_new("(s@a{sv})", this->m_Rule.m_AppID, g_variant_builder_end(builder)); + break; + case 2: /* get total */ + *params = g_variant_new("(s@a{sv})", "", g_variant_builder_end(builder)); + break; + case 3: /* get all */ + default: + *params = g_variant_new("(@a{sv})", g_variant_builder_end(builder)); + break; + } + + g_variant_builder_unref(builder); +} + +error_e Statistics::InitStatistics(void) +{ + GVariant *message = NULL; + error_e error = ERROR_NONE; + + message = InvokeMethod(STC_MGR_SERVICE, + STC_MGR_STATISTICS_PATH, + STC_MGR_STATISTICS_INTERFACE, + STC_MGR_METHOD_STATISTICS_INIT, + NULL, + &error); + + if (message == NULL) { + GLOGD("Failed to invoke dbus method"); + return error; + } + + GLOGD("Succeeded to init statistics"); + + return ERROR_NONE; +} + +error_e Statistics::GetStatistics(void) +{ + GVariant *params = NULL; + error_e error = ERROR_NONE; + + MakeRuleParams(¶ms, 1); + + error = InvokeMethodNonblock(STC_MGR_SERVICE, + STC_MGR_STATISTICS_PATH, + STC_MGR_STATISTICS_INTERFACE, + STC_MGR_METHOD_STATISTICS_GET_PER_APP_ID, + params, + DBUS_REPLY_TIMEOUT, + AsyncReadyCallback, + NULL); + + if (error != ERROR_NONE) { + GLOGD("Failed to invoke dbus method nonblock"); + return error; + } + + RunMainLoop(); + GLOGD("Succeeded to get statistics per app ID"); + + return ERROR_NONE; +} + +error_e Statistics::GetTotalStatistics(void) +{ + GVariant *params = NULL; + error_e error = ERROR_NONE; + + MakeRuleParams(¶ms, 2); + + error = InvokeMethodNonblock(STC_MGR_SERVICE, + STC_MGR_STATISTICS_PATH, + STC_MGR_STATISTICS_INTERFACE, + STC_MGR_METHOD_STATISTICS_GET_TOTAL, + params, + DBUS_REPLY_TIMEOUT, + AsyncReadyCallback, + NULL); + + if (error != ERROR_NONE) { + GLOGD("Failed to invoke dbus method nonblock"); + return error; + } + + RunMainLoop(); + GLOGD("Succeeded to get total statistics"); + + return ERROR_NONE; +} + +error_e Statistics::GetAllStatistics(void) +{ + GVariant *params = NULL; + error_e error = ERROR_NONE; + + MakeRuleParams(¶ms, 3); + + error = InvokeMethodNonblock(STC_MGR_SERVICE, + STC_MGR_STATISTICS_PATH, + STC_MGR_STATISTICS_INTERFACE, + STC_MGR_METHOD_STATISTICS_GET_ALL, + params, + DBUS_REPLY_TIMEOUT, + AsyncReadyCallback, + NULL); + + if (error != ERROR_NONE) { + GLOGD("Failed to invoke dbus method nonblock"); + return error; + } + + RunMainLoop(); + GLOGD("Succeeded to get all statistics"); + + return ERROR_NONE; +} + +error_e Statistics::ResetStatistics(void) +{ + GVariant *message = NULL; + GVariant *params = NULL; + error_e error = ERROR_NONE; + int result = 0; + + MakeRuleParams(¶ms, 0); + + message = InvokeMethod(STC_MGR_SERVICE, + STC_MGR_STATISTICS_PATH, + STC_MGR_STATISTICS_INTERFACE, + STC_MGR_METHOD_STATISTICS_RESET, + params, + &error); + + if (message == NULL) { + GLOGD("Failed to invoke dbus method"); + return error; + } + + g_variant_get(message, "(i)", &result); + GLOGD("Succeeded to reset statistics", result); + g_variant_unref(message); + + return ERROR_NONE; +} diff --git a/unittest/statistics.h b/unittest/statistics.h new file mode 100755 index 0000000..5f3ebcc --- /dev/null +++ b/unittest/statistics.h @@ -0,0 +1,66 @@ +/* + * Copyright (c) 2017 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#ifndef __STC_MGR_STATISTICS_H__ +#define __STC_MGR_STATISTICS_H__ + +#include "stcmgr.h" +#include "gdbus.h" + +#define STATISTICS_RULE_APP_ID "app_id" +#define STATISTICS_RULE_INTERVAL_FROM "from" +#define STATISTICS_RULE_INTERVAL_TO "to" +#define STATISTICS_RULE_IFTYPE "iftype" +#define STATISTICS_RULE_TIME_PERIOD "granularity" + +#define RESET_RULE_SUBSCRIBER_ID "subscriber_id" + +typedef struct { + time_t from; + time_t to; +} time_interval_s; + +class SRule { +private: +public: + char m_AppID[APP_ID_LEN]; + char m_SubscriberID[SUBSCRIBER_ID_LEN]; + iface_type_e m_IfaceType; + time_period_e m_TimePeriod; + time_interval_s m_Interval; + + SRule(); + ~SRule(); +}; + +class Statistics : public GDbus { +private: + SRule m_Rule; +public: + Statistics(); + ~Statistics(); + error_e SetRule(const char *app_id, const char *subscriber_id, + iface_type_e iface_type, time_t from, time_t to, time_period_e time_period); + time_t MakeTime(int year, int mon, int day, int hour, int min); + void MakeRuleParams(GVariant **params, int mode); + error_e InitStatistics(void); + error_e GetStatistics(void); + error_e GetTotalStatistics(void); + error_e GetAllStatistics(void); + error_e ResetStatistics(void); +}; + + +#endif /* __STC_MGR_STATISTICS_H__ */ diff --git a/unittest/stcmgr.cpp b/unittest/stcmgr.cpp new file mode 100755 index 0000000..c3f401f --- /dev/null +++ b/unittest/stcmgr.cpp @@ -0,0 +1,17 @@ +/* + * Copyright (c) 2017 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "stcmgr.h" diff --git a/unittest/stcmgr.h b/unittest/stcmgr.h new file mode 100755 index 0000000..79f9c2c --- /dev/null +++ b/unittest/stcmgr.h @@ -0,0 +1,72 @@ +/* + * Copyright (c) 2017 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#ifndef __STC_MGR_H__ +#define __STC_MGR_H__ + +#include + +#define APP_ID_LEN 128 +#define IFNAME_LEN 16 +#define SUBSCRIBER_ID_LEN 128 + +#ifdef USE_DLOG +#include +#undef LOG_TAG +#define LOG_TAG "STC_GTEST" +#define GLOGD(format, args...) LOGD(format, ##args) +#else +#define GLOGD(format, args...) +#endif + +typedef enum { + ERROR_NONE = 0, + ERROR_NOT_PERMITTED = -1, + ERROR_OUT_OF_MEMORY = -2, + ERROR_PERMISSION_DENIED = -3, + ERROR_RESOURCE_BUSY = -4, + ERROR_INVALID_OPERATION = -5, + ERROR_INVALID_PARAMETER = -6, + ERROR_NOT_SUPPORTED = -7, + ERROR_OPERATION_FAILED = -8, + ERROR_NOT_INITIALIZED = -9, + ERROR_ALREADY_INITIALIZED = -10, + ERROR_IN_PROGRESS = -11, +} error_e; + +typedef enum { + IFACE_UNKNOWN, + IFACE_DATACALL, + IFACE_WIFI, + IFACE_WIRED, + IFACE_BLUETOOTH, + IFACE_ALL, +} iface_type_e; + +typedef enum { + ROAMING_UNKNOWN, + ROAMING_ENABLED, + ROAMING_DISABLED, +} roaming_type_e; + +typedef enum { + TIME_PERIOD_UNKNOWN = 0, + TIME_PERIOD_HOUR = 3600, + TIME_PERIOD_DAY = 86400, + TIME_PERIOD_WEEK = 604800, + TIME_PERIOD_MONTH = 2419200, +} time_period_e; + +#endif /* __STC_MGR_H__ */ diff --git a/unittest/unittest.cpp b/unittest/unittest.cpp new file mode 100755 index 0000000..1141021 --- /dev/null +++ b/unittest/unittest.cpp @@ -0,0 +1,377 @@ +/* + * Copyright (c) 2017 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include +#include + +#include "unittest.h" +#include "restriction.h" +#include "statistics.h" +#include "manager.h" + +using ::testing::InitGoogleTest; +using ::testing::Test; +using ::testing::TestCase; + +TEST(StcManager_Statistics, Init_p) +{ + error_e ret = ERROR_NONE; + Statistics stat; + + ret = stat.InitStatistics(); + EXPECT_EQ(ERROR_NONE, ret); +} + +TEST(StcManager_Statistics, Get_p) +{ + error_e ret = ERROR_NONE; + Statistics stat; + time_t from = 0; + time_t to = 0; + + from = stat.MakeTime(2000, 1, 1, 1, 1); + time(&to); + + ret = stat.SetRule("TOTAL_DATACALL", + NULL, + IFACE_DATACALL, + from, + to, + TIME_PERIOD_DAY); + EXPECT_EQ(ERROR_NONE, ret); + + ret = stat.GetStatistics(); + EXPECT_EQ(ERROR_NONE, ret); + + ret = stat.SetRule("TOTAL_WIFI", + NULL, + IFACE_WIFI, + from, + to, + TIME_PERIOD_UNKNOWN); + EXPECT_EQ(ERROR_NONE, ret); + + ret = stat.GetStatistics(); + EXPECT_EQ(ERROR_NONE, ret); +} + +TEST(StcManager_Statistics, GetAll_p) +{ + error_e ret = ERROR_NONE; + Statistics stat; + time_t from = 0; + time_t to = 0; + + from = stat.MakeTime(2000, 1, 1, 1, 1); + time(&to); + + ret = stat.SetRule(NULL, + NULL, + IFACE_UNKNOWN, + from, + to, + TIME_PERIOD_UNKNOWN); + EXPECT_EQ(ERROR_NONE, ret); + + ret = stat.GetAllStatistics(); + EXPECT_EQ(ERROR_NONE, ret); +} + +TEST(StcManager_Statistics, GetTotal_p) +{ + error_e ret = ERROR_NONE; + Statistics stat; + time_t from = 0; + time_t to = 0; + + from = stat.MakeTime(2000, 1, 1, 1, 1); + time(&to); + + ret = stat.SetRule(NULL, + NULL, + IFACE_DATACALL, + from, + to, + TIME_PERIOD_UNKNOWN); + EXPECT_EQ(ERROR_NONE, ret); + + ret = stat.GetTotalStatistics(); + EXPECT_EQ(ERROR_NONE, ret); + + ret = stat.SetRule(NULL, + NULL, + IFACE_WIFI, + from, + to, + TIME_PERIOD_UNKNOWN); + EXPECT_EQ(ERROR_NONE, ret); + + ret = stat.GetTotalStatistics(); + EXPECT_EQ(ERROR_NONE, ret); +} + +TEST(StcManager_Restriction, Set_p) +{ + error_e ret = ERROR_NONE; + Restriction rest; + + ret = rest.SetRule("Test_tel", + "seth_w0", + "1234567890abcdefg", + IFACE_DATACALL, + 0, + 0, + ROAMING_UNKNOWN); + EXPECT_EQ(ERROR_NONE, ret); + + ret = rest.SetRstriction(); + EXPECT_EQ(ERROR_NONE, ret); + + ret = rest.SetRule("TOTAL_WIFI", + "wlan0", + NULL, + IFACE_WIFI, + 2, + 1, + ROAMING_UNKNOWN); + EXPECT_EQ(ERROR_NONE, ret); + + ret = rest.SetRstriction(); + EXPECT_EQ(ERROR_NONE, ret); + + ret = rest.SetRule("Test_eth", + "eth0", + NULL, + IFACE_WIRED, + 100000, + 80000, + ROAMING_UNKNOWN); + EXPECT_EQ(ERROR_NONE, ret); + + ret = rest.SetRstriction(); + EXPECT_EQ(ERROR_NONE, ret); +} + +TEST(StcManager_Restriction, Exclude_p) + +{ + error_e ret = ERROR_NONE; + Restriction rest; + + ret = rest.SetRule("TOTAL_DATACALL", + "seth_w0", + NULL, + IFACE_DATACALL, + 0, + 0, + ROAMING_UNKNOWN); + EXPECT_EQ(ERROR_NONE, ret); + + ret = rest.ExcludeRstriction(); + EXPECT_EQ(ERROR_NONE, ret); +} + +TEST(StcManager_Restriction, Get_p) +{ + error_e ret = ERROR_NONE; + Restriction rest; + + ret = rest.SetRule("Test_tel", + "seth_w0", + "1234567890abcdefg", + IFACE_DATACALL, + 0, + 0, + ROAMING_UNKNOWN); + EXPECT_EQ(ERROR_NONE, ret); + + ret = rest.GetRstriction(); + EXPECT_EQ(ERROR_NONE, ret); + + ret = rest.SetRule("TOTAL_WIFI", + "wlan0", + NULL, + IFACE_WIFI, + 0, + 0, + ROAMING_UNKNOWN); + EXPECT_EQ(ERROR_NONE, ret); + + ret = rest.GetRstriction(); + EXPECT_EQ(ERROR_NONE, ret); + + ret = rest.SetRule("TOTAL_IPV4", + "seth_w0", + NULL, + IFACE_DATACALL, + 0, + 0, + ROAMING_UNKNOWN); + EXPECT_EQ(ERROR_NONE, ret); + + ret = rest.GetRstriction(); + EXPECT_EQ(ERROR_NONE, ret); +} + +TEST(StcManager_Restriction, GetAll_p) +{ + error_e ret = ERROR_NONE; + Restriction rest; + + ret = rest.GetAllRstriction(); + EXPECT_EQ(ERROR_NONE, ret); +} + +TEST(StcManager_Restriction, GetRst_p) +{ + error_e ret = ERROR_NONE; + Restriction rest; + restriction_status_e status = RESTRICTION_UNKNOWN; + + ret = rest.SetRule("Test_tel", + "seth_w0", + NULL, + IFACE_DATACALL, + 0, + 0, + ROAMING_UNKNOWN); + EXPECT_EQ(ERROR_NONE, ret); + + ret = rest.GetRstrictionStatus(&status); + EXPECT_EQ(ERROR_NONE, ret); + EXPECT_LE(RESTRICTION_UNKNOWN, status); + EXPECT_GE(RESTRICTION_LAST_ELEM, status); + + ret = rest.SetRule("Test_eth", + "eth0", + NULL, + IFACE_WIRED, + 100000, + 80000, + ROAMING_UNKNOWN); + EXPECT_EQ(ERROR_NONE, ret); + + ret = rest.GetRstrictionStatus(&status); + EXPECT_EQ(ERROR_NONE, ret); + EXPECT_LE(RESTRICTION_UNKNOWN, status); + EXPECT_GE(RESTRICTION_LAST_ELEM, status); +} + +TEST(StcManager_Restriction, Unset_p) +{ + error_e ret = ERROR_NONE; + Restriction rest; + + ret = rest.SetRule("Test_tel", + "seth_w0", + "1234567890abcdefg", + IFACE_DATACALL, + 0, + 0, + ROAMING_UNKNOWN); + EXPECT_EQ(ERROR_NONE, ret); + + ret = rest.UnsetRstriction(); + EXPECT_EQ(ERROR_NONE, ret); + + ret = rest.SetRule("TOTAL_WIFI", + "wlan0", + NULL, + IFACE_WIFI, + 2, + 1, + ROAMING_UNKNOWN); + EXPECT_EQ(ERROR_NONE, ret); + + ret = rest.UnsetRstriction(); + EXPECT_EQ(ERROR_NONE, ret); + + ret = rest.SetRule("Test_eth", + "eth0", + NULL, + IFACE_WIRED, + 100000, + 80000, + ROAMING_UNKNOWN); + EXPECT_EQ(ERROR_NONE, ret); + + ret = rest.UnsetRstriction(); + EXPECT_EQ(ERROR_NONE, ret); + + ret = rest.SetRule("TOTAL_DATACALL", + "seth_w0", + NULL, + IFACE_DATACALL, + 0, + 0, + ROAMING_UNKNOWN); + EXPECT_EQ(ERROR_NONE, ret); + + ret = rest.UnsetRstriction(); + EXPECT_EQ(ERROR_NONE, ret); +} + +TEST(StcManager_Statistics, Reset_p) +{ + error_e ret = ERROR_NONE; + Statistics stat; + time_t from = 0; + time_t to = 0; + + from = stat.MakeTime(2000, 1, 1, 1, 1); + time(&to); + + ret = stat.SetRule("TOTAL_DATACALL", + "1234567890abcdefg", + IFACE_DATACALL, + from, + to, + TIME_PERIOD_UNKNOWN); + EXPECT_EQ(ERROR_NONE, ret); + + ret = stat.ResetStatistics(); + EXPECT_EQ(ERROR_NONE, ret); + + ret = stat.SetRule(NULL, + NULL, + IFACE_UNKNOWN, + from, + to, + TIME_PERIOD_UNKNOWN); + EXPECT_EQ(ERROR_NONE, ret); + + ret = stat.ResetStatistics(); + EXPECT_EQ(ERROR_NONE, ret); +} + +TEST(StcManager_Manager, Stop_p) +{ + error_e ret = ERROR_NONE; + Manager mgr; + + ret = mgr.StopManager(); + EXPECT_EQ(ERROR_NONE, ret); +} + +int main(int argc, char **argv) +{ + InitGoogleTest(&argc, argv); + return RUN_ALL_TESTS(); +} diff --git a/unittest/unittest.h b/unittest/unittest.h new file mode 100755 index 0000000..2ad100d --- /dev/null +++ b/unittest/unittest.h @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2017 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#ifndef __STC_MGR_UNITTEST_H__ +#define __STC_MGR_UNITTEST_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include + +#ifdef __cplusplus +} +#endif + +#endif /* __STC_MGR_UNITTEST_H__ */ \ No newline at end of file -- 2.7.4