diff options
author | Ickhee Woo <ickhee.woo@samsung.com> | 2017-07-10 20:00:58 +0900 |
---|---|---|
committer | Ickhee Woo <ickhee.woo@samsung.com> | 2017-07-25 13:56:28 +0900 |
commit | 1e0e047f26981bb91f70b7ca8ff2166637b4cbc7 (patch) | |
tree | 778b915afd1648cb336818d5c4ff3137b73d9c62 | |
parent | e80eedacd63d698eb6971687a1d0eb5523f80ea7 (diff) | |
download | sync-manager-sync_test.tar.gz sync-manager-sync_test.tar.bz2 sync-manager-sync_test.zip |
added first implement of synctest daemonsync_test
Change-Id: I9a73f2ce9e41891cd5235db908fe99c3b0201331
Signed-off-by: Ickhee Woo <ickhee.woo@samsung.com>
-rw-r--r-- | CMakeLists.txt | 47 | ||||
-rw-r--r-- | packaging/synctest.service | 15 | ||||
-rw-r--r-- | packaging/synctest.spec | 54 | ||||
-rw-r--r-- | src/CMakeLists.txt | 38 | ||||
-rw-r--r-- | src/main.c | 377 | ||||
-rw-r--r-- | src/util.h | 56 | ||||
-rw-r--r-- | sync-test.manifest | 5 |
7 files changed, 592 insertions, 0 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..b7721ab --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,47 @@ +# Copyright (c) 2013 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. +# + +# SyncManager test build script +MESSAGE("===== SYNCTEST BUILD START =====") + +CMAKE_MINIMUM_REQUIRED(VERSION 2.6) +PROJECT(synctest C) + +INCLUDE(FindPkgConfig) + +SET(LIBNAME "${PROJECT_NAME}") +SET(EXENAME "${PROJECT_NAME}") +SET(PREFIX ${CMAKE_INSTALL_PREFIX}) +SET(BINDIR "${PREFIX}/bin") +SET(LIBDIR "${PREFIX}/%{_libdir}") +SET(PIDDIR "/var/run") +SET(TMPDIR "/tmp") + +FOREACH(flag ${service_pkgs_CFLAGS}) + SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}") +ENDFOREACH(flag) + +SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS} -Werror -Wno-deprecated-declarations") +SET(CMAKE_CXX_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS} -Werror -Wno-deprecated-declarations") + +ADD_DEFINITIONS("-DPREFIX=\"${PREFIX}\"") +ADD_DEFINITIONS("-DPIDDIR=\"${PIDDIR}\"") +ADD_DEFINITIONS("-DTMPDIR=\"${TMPDIR}\"") + +# SyncManager test daemon +ADD_SUBDIRECTORY(src) + +MESSAGE("===== SYNCTEST BUILD END =====") + diff --git a/packaging/synctest.service b/packaging/synctest.service new file mode 100644 index 0000000..9acd6b2 --- /dev/null +++ b/packaging/synctest.service @@ -0,0 +1,15 @@ +[Unit] +Description=SyncManager Test daemon +After=dbus.service + +[Service] +Type=simple +ExecStart=/usr/bin/synctest +Restart=always +RestartSec=1 +MemoryLimit=10M +User=system +Group=system + +[Install] +WantedBy=default.target diff --git a/packaging/synctest.spec b/packaging/synctest.spec new file mode 100644 index 0000000..4c14a03 --- /dev/null +++ b/packaging/synctest.spec @@ -0,0 +1,54 @@ +Name: synctest +Summary: SyncManager test services +Version: 0.0.1 +Release: 1 +Group: Application Framework/Service +License: Apache-2.0 +Source0: %{name}-%{version}.tar.gz +Source1: synctest.service +Requires(post): /sbin/ldconfig +Requires(postun): /sbin/ldconfig +BuildRequires: pkgconfig(glib-2.0) +BuildRequires: pkgconfig(gthread-2.0) +BuildRequires: pkgconfig(accounts-svc) +BuildRequires: pkgconfig(bundle) +BuildRequires: pkgconfig(core-sync-client) +BuildRequires: pkgconfig(dlog) + +BuildRequires: cmake + +%description +SyncManager test daemon + +%package bin +Summary: SyncManager test daemon +Group: Application Framework/Service + +%description bin +SyncManager test daemon + +%prep +%setup -q + +%build + +cmake . -DCMAKE_INSTALL_PREFIX="/usr" -DVERSION=%{version} +make %{?jobs:-j%jobs} + +%install +rm -rf %{buildroot} + +%make_install +mkdir -p %{buildroot}%{_unitdir}/default.target.wants +install -m 0644 %{SOURCE1} %{buildroot}%{_unitdir}/synctest.service +ln -s ../synctest.service %{buildroot}%{_unitdir}/default.target.wants/synctest.service + +%post bin + +%files +%manifest sync-test.manifest +%{_bindir}/synctest + +%{_unitdir}/synctest.service +%{_unitdir}/default.target.wants/synctest.service + diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt new file mode 100644 index 0000000..05f6ab5 --- /dev/null +++ b/src/CMakeLists.txt @@ -0,0 +1,38 @@ +# Copyright (c) 2013 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. +# + +# SyncManager test daemon build script +MESSAGE("===== DAEMON =====") + +pkg_check_modules(EPKGS REQUIRED glib-2.0 dlog gthread-2.0 accounts-svc bundle core-sync-client dlog) + +SET(SRCS main.c) + +SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIE") +SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -pthread -pie") + +INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}) + +STRING(REPLACE ";" " " EXTRA_CFLAGS "${EPKGS_CFLAGS}") + +ADD_DEFINITIONS("-DIS_LITTLE_ENDIAN=1") + +ADD_EXECUTABLE(${EXENAME} ${SRCS}) +TARGET_LINK_LIBRARIES(${EXENAME} ${EPKGS_LIBRARIES}) +SET_TARGET_PROPERTIES(${EXENAME} PROPERTIES COMPILE_FLAGS ${EXTRA_CFLAGS}) + +INSTALL(TARGETS ${EXENAME} DESTINATION ${BINDIR}) +MESSAGE("===== DAEMON END =====") + diff --git a/src/main.c b/src/main.c new file mode 100644 index 0000000..93bd11c --- /dev/null +++ b/src/main.c @@ -0,0 +1,377 @@ +/* + * Copyright (c) 2013 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 <stdio.h> +#include <glib.h> +#include <glib-object.h> +#include <glib-unix.h> +#include <stdlib.h> +#include <string.h> +#include <fcntl.h> +#include <unistd.h> +#include <time.h> +#include <sys/time.h> +#include "util.h" + +#include <account.h> +#include <sync_adapter.h> +#include <sync_manager.h> + +bool bRequestSent = FALSE; + +int jobId[3] = {0, 0, 0}; + +int cbSet = 0; + +GMainLoop *global_loop = NULL; + + +void print_menu() +{ + while (bRequestSent) + sleep(1); + + printf(_BOLDRED"\nSyncManager Test Menu\n"_RESET + _GREEN"1.Set Sync Callbacks\n"_RESET + "2.Unset Sync Callbacks\n" + "3.OnDemand Sync\n" + _GREEN"4.Periodic Sync\n"_RESET + _GREEN"5.DataChange Sync\n"_RESET + "6.Foreach Sync\n" + _GREEN"7.Remove All Sync\n"_RESET + "q.Exit :\n"); +} + + +/* + * Callback for receiving the result of sync start operation + * It is invoked in the following cases + * - sync_manager_on_demand_sync_job() which was called in Sync Adapter is complete + * - In the case of using sync_manager_add_periodic_sync_job() in Sync Adapter, + * it is called after some times which is set as period interval later + * - In the case of using sync_manager_add_data_change_sync_job() in Sync Adapter, + * it is called when status change is detected in DB for specific capability + */ +static bool +handle_start_sync_cb(account_h account, const char *sync_job_name, const char *sync_capability, bundle *sync_job_user_data) +{ + if (sync_job_name) { + _D("Sync Job Name [%s]", sync_job_name); + if (!strcmp(sync_job_name, "OnDemandSyncJob")) { + _D("OnDemand Sync Job Name [%s]", sync_job_name); + printf(_BOLDWHITE"OnDemandSyncJob callback is invoked.\n"_RESET); + jobId[0] = 0; + } else { + _D("Periodic Sync Job Name [%s]", sync_job_name); + printf(_BOLDWHITE"PeriodicSyncJob callback is invoked.\n"_RESET); + } + } else { + _D("Data Change Sync Job Capability [%s]", sync_capability); + printf(_BOLDWHITE"DataChangeSyncJob callback is invoked. [SYNC_SUPPORTS_CAPABILITY_IMAGE]\n"_RESET); + } + + printf(_BOLDWHITE"Sync start operation is complete.\n"_RESET); + + return true; +} + + +/* + * Callback for receiving the result of sync stop operation + */ +static void +handle_stop_sync_cb(account_h account, const char *sync_job_name, const char *sync_capability, bundle *sync_job_user_data) +{ + if (sync_job_name) { + _D("Sync Job Name [%s]", sync_job_name); + if (!strcmp(sync_job_name, "OnDemandSyncJob")) { + _D("OnDemand Sync Job Name [%s]", sync_job_name); + printf(_BOLDWHITE"OnDemandSyncJob callback is invoked.\n"_RESET); + jobId[0] = 0; + } else { + _D("Periodic Sync Job Name [%s]", sync_job_name); + printf(_BOLDWHITE"PeriodicSyncJob callback is invoked.\n"_RESET); + } + } else { + _D("Data Change Sync Job Capability [%s]", sync_capability); + printf(_BOLDWHITE"DataChangeSyncJob callback is invoked. [SYNC_SUPPORTS_CAPABILITY_IMAGE]\n"_RESET); + } + + printf(_BOLDWHITE"Sync stop operation is complete.\n"_RESET); +} + + +bool +foreach_sync_job_cb(account_h account, const char *sync_job_name, const char *sync_capability, int sync_job_id, bundle* sync_job_user_data, void *user_data) +{ + if (sync_job_name) { + _D("Sync Job Name [%s]", sync_job_name); + if (!strcmp(sync_job_name, "OnDemandSyncJob")) { + printf(_BOLDCYAN"OnDemandSyncJob is pended.\n"_RESET); + jobId[0] = sync_job_id; + } else { + printf(_BOLDCYAN"PeriodicSyncJob is registered.\n"_RESET); + jobId[1] = sync_job_id; + } + } else { + _D("Data Change Sync Job Capability [%s]", sync_capability); + printf(_BOLDCYAN"DataChangeSyncJob is registered. [SYNC_SUPPORTS_CAPABILITY_IMAGE]\n"_RESET); + jobId[2] = sync_job_id; + } + + return true; +} + + +void stop_api_test() +{ + int idx, ret; + + /* whether it is exist */ + for (idx = 0; idx < 3; idx++) { + if (jobId[idx] != 0) { + ret = sync_manager_remove_sync_job(jobId[idx]); + if (ret != SYNC_ERROR_NONE) { + if (idx == 0) + printf(_RED"Failed to remove pended OnDemand Sync.\n"_RESET); + else if (idx == 1) + printf(_RED"Failed to remove Periodic Sync.\n"_RESET); + else if (idx == 2) + printf(_RED"Failed to remove DataChange Sync.\n"_RESET); + } else { + jobId[idx] = 0; + } + } + } + + /* remove and unset */ + ret = sync_adapter_unset_callbacks(); + if (ret == SYNC_ERROR_NONE) + printf(_BOLDCYAN"Callbacks are unset.\n"_RESET); + else + printf(_RED"Failed to unset Callbacks.\n"_RESET); +} + + +int sync_manager_api_receive_test(void) +{ + int ret = SYNC_ERROR_NONE; + char a[10]; + int id = 0; + int idx; + + while (1) { + print_menu(); + + ret = read(0, a, 10); + switch (a[0]) { + case '1': + /* Set Sync Callbacks */ + if (cbSet == 0) { + ret = sync_adapter_set_callbacks(handle_start_sync_cb, handle_stop_sync_cb); + if (ret == SYNC_ERROR_NONE) { + printf(_BOLDCYAN"Callbacks are set.\n"_RESET); + cbSet = 1; + } else { + printf(_RED"Failed to set Callbacks.\n"_RESET); + } + } else { + printf(_RED"Callbacks are already set.\n"_RESET); + } + break; + case '2': + if (cbSet == 0) { + printf(_RED"Callbacks are already unset.\n"_RESET); + break; + } + /* check remained sync jobs */ + for (idx = 0; idx < 3; idx++) { + if (jobId[idx] != 0) { + ret = sync_manager_remove_sync_job(jobId[idx]); + if (ret != SYNC_ERROR_NONE) { + if (idx == 0) + printf(_RED"Failed to remove pended OnDemand Sync.\n"_RESET); + else if (idx == 1) + printf(_RED"Failed to remove Periodic Sync.\n"_RESET); + else if (idx == 2) + printf(_RED"Failed to remove DataChange Sync.\n"_RESET); + } + } + } + /* Unset Sync Callbacks */ + ret = sync_adapter_unset_callbacks(); + if (ret == SYNC_ERROR_NONE) { + printf(_BOLDCYAN"Callbacks are unset.\n"_RESET); + cbSet = 0; + } else { + printf(_RED"Failed to unset Callbacks.\n"_RESET); + } + break; + case '3': + if (cbSet == 0) { + printf(_RED"Callbacks should be set first.\n"_RESET + _BOLDCYAN"Please try select 1.Set Sync Callbacks\n"); + break; + } + /* OnDemand Sync */ + ret = sync_manager_on_demand_sync_job(NULL, "OnDemandSyncJob", SYNC_OPTION_NONE, NULL, &id); + if (ret == SYNC_ERROR_NONE) { + printf(_BOLDCYAN"Request OnDemand Sync.\n"_RESET); + jobId[0] = id; + sleep(2); + } else { + printf(_RED"Failed to request OnDemand Sync.\n"_RESET); + } + break; + case '4': + if (cbSet == 0) { + printf(_RED"Callbacks should be set first.\n"_RESET + _BOLDCYAN"Please try select 1.Set Sync Callbacks\n"); + break; + } + /* Periodic Sync */ + ret = sync_manager_add_periodic_sync_job(NULL, "PeriodicSyncJob", SYNC_PERIOD_INTERVAL_30MIN, SYNC_OPTION_EXPEDITED, NULL, &id); + if (ret == SYNC_ERROR_NONE) { + printf(_BOLDCYAN"Request Periodic Sync with Priority [30mins].\n"_RESET); + jobId[1] = id; + sleep(2); + } else { + printf(_RED"Failed to request Periodic Sync.\n"_RESET); + } + break; + case '5': + if (cbSet == 0) { + printf(_RED"Callbacks should be set first.\n"_RESET + _BOLDCYAN"Please try select 1.Set Sync Callbacks\n"); + break; + } + /* DataChange Sync */ + ret = sync_manager_add_data_change_sync_job(NULL, SYNC_SUPPORTS_CAPABILITY_IMAGE, SYNC_OPTION_EXPEDITED, NULL, &id); + if (ret == SYNC_ERROR_NONE) { + printf(_BOLDCYAN"Request DataChange Sync with Priority [image].\n"_RESET); + jobId[2] = id; + sleep(2); + } else { + printf(_RED"Failed to request DataChange Sync.\n"_RESET); + } + break; + case '6': + if (cbSet == 0) { + printf(_RED"Callbacks should be set first.\n"_RESET + _BOLDCYAN"Please try select 1.Set Sync Callbacks\n"); + break; + } + /* Foreach Sync */ + ret = sync_manager_foreach_sync_job(foreach_sync_job_cb, NULL); + if (ret == SYNC_ERROR_NONE) { + printf(_BOLDWHITE"Request Foreach Sync.\n"_RESET); + sleep(2); + } else { + printf(_RED"Failed to request Foreach Sync.\n"_RESET); + } + break; + case '7': + /* whether it is exist */ + printf(_BOLDWHITE"Remove All Sync jobs.\n"_RESET); + /* Remove All Sync */ + for (idx = 0; idx < 3; idx++) { + if (jobId[idx] != 0) { + ret = sync_manager_remove_sync_job(jobId[idx]); + if (ret != SYNC_ERROR_NONE) { + if (idx == 0) + printf(_RED"Failed to remove pended OnDemand Sync.\n"_RESET); + else if (idx == 1) + printf(_RED"Failed to remove Periodic Sync.\n"_RESET); + else if (idx == 2) + printf(_RED"Failed to remove DataChange Sync.\n"_RESET); + } else { + jobId[idx] = 0; + } + } + } + break; + case 'q': + stop_api_test(); + return 0; + default: + break; + } + } +} + + +void* start_api_test() +{ + bRequestSent = FALSE; + + cbSet = 0; + + int ret = sync_manager_api_receive_test(); + if (ret) + printf(_BOLDCYAN"Test Finished\n"_RESET); + + printf(_BOLDCYAN"Bye\n"_RESET); + + g_main_loop_quit(global_loop); + + return NULL; +} + + +static gint sigterm_cb(void *data) +{ + stop_api_test(); + + printf(_BOLDCYAN"signal terminated callback\n"_RESET); + printf(_BOLDCYAN"Farewell\n"_RESET); + + g_main_loop_quit((GMainLoop*)data); + + return FALSE; +} + + +int main(int argc, char **argv) +{ + GMainLoop *loop; + + pthread_t thd; + + printf("\n"); + printf(_YELLOW"##################################\n"); + printf(_YELLOW"######## SyncManager Test ########\n"); + printf(_YELLOW"##################################\n"_RESET); + + /* start transaction manager */ + if (pthread_create(&thd, NULL, start_api_test, NULL) != 0) + return -1; + + /* mainloop of main thread */ + global_loop = loop = g_main_loop_new(NULL, FALSE); + + /* installing signal handlers */ + g_unix_signal_add_full(G_PRIORITY_HIGH, SIGINT, sigterm_cb, loop, NULL); + g_unix_signal_add_full(G_PRIORITY_HIGH, SIGTERM, sigterm_cb, loop, NULL); + + /* start application's main loop */ + g_main_loop_run(loop); + + /* cleanup after mainloop */ + g_main_loop_unref(loop); + + return 0; +} + diff --git a/src/util.h b/src/util.h new file mode 100644 index 0000000..e83afd5 --- /dev/null +++ b/src/util.h @@ -0,0 +1,56 @@ +/* + * Copyright (c) 2013 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 __TIZEN_SYNCTEST_UTIL_H__ +#define __TIZEN_SYNCTEST_UTIL_H__ + +#include <dlog.h> + +#undef LOG_TAG +#define LOG_TAG "SYNCTEST" + +#define _RESET "\033[0m" +#define _BLACK "\033[30m" /* Black */ +#define _RED "\033[31m" /* Red */ +#define _GREEN "\033[32m" /* Green */ +#define _YELLOW "\033[33m" /* Yellow */ +#define _BLUE "\033[34m" /* Blue */ +#define _PURPLE "\033[35m" /* Purple */ +#define _CYAN "\033[36m" /* Cyan */ +#define _WHITE "\033[37m" /* White */ +#define _BOLDBLACK "\033[1m\033[30m" /* Bold Black */ +#define _BOLDRED "\033[1m\033[31m" /* Bold Red */ +#define _BOLDGREEN "\033[1m\033[32m" /* Bold Green */ +#define _BOLDYELLOW "\033[1m\033[33m" /* Bold Yellow */ +#define _BOLDBLUE "\033[1m\033[34m" /* Bold Blue */ +#define _BOLDPURPLE "\033[1m\033[35m" /* Bold Purple */ +#define _BOLDCYAN "\033[1m\033[36m" /* Bold Cyan */ +#define _BOLDWHITE "\033[1m\033[37m" /* Bold White */ + +#define _I(fmt, arg...) do { LOGI(fmt, ##arg); } while (0) +#define _W(fmt, arg...) do { LOGW(fmt, ##arg); } while (0) +#define _E(fmt, arg...) do { LOGE(fmt, ##arg); } while (0) +#define _D(fmt, arg...) do { LOGD(fmt, ##arg); } while (0) +#define _SE(fmt, arg...) do { LOGE(fmt, ##arg); } while (0) +#define _SD(fmt, arg...) do { LOGD(fmt, ##arg); } while (0) +#define _SW(fmt, arg...) do { LOGW(fmt, ##arg); } while (0) + +#define _free(p) do { if (p) { free(p); p = NULL; } } while (0) +#define _FUNC_ENTER do { LOGD("start"); } while (0) +#define _FUNC_LEAVE do { LOGD("end"); } while (0) + +#endif /* __TIZEN_SYNCTEST_UTIL_H__ */ + diff --git a/sync-test.manifest b/sync-test.manifest new file mode 100644 index 0000000..97e8c31 --- /dev/null +++ b/sync-test.manifest @@ -0,0 +1,5 @@ +<manifest> + <request> + <domain name="_"/> + </request> +</manifest> |