From e617ba16782dacdac6f807cdfd620be1b39c6ead Mon Sep 17 00:00:00 2001 From: Changgyu Choi Date: Wed, 22 Mar 2023 09:19:07 +0900 Subject: [PATCH 01/16] Release version 1.14.3 Changes: - Fix static analysis issues Change-Id: If66e5c982c92a20ae7c1e57b306a392c37bbb9d1 Signed-off-by: Changgyu Choi --- packaging/rpc-port.spec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packaging/rpc-port.spec b/packaging/rpc-port.spec index 3256d04..2702f16 100644 --- a/packaging/rpc-port.spec +++ b/packaging/rpc-port.spec @@ -1,6 +1,6 @@ Name: rpc-port Summary: RPC Port library -Version: 1.14.2 +Version: 1.14.3 Release: 0 Group: Application Framework/Libraries License: Apache-2.0 -- 2.7.4 From 2c12bd804204a02bce1b3601a4454a3086f9711f Mon Sep 17 00:00:00 2001 From: Hwankyu Jhun Date: Fri, 12 May 2023 01:42:06 +0000 Subject: [PATCH 02/16] Add nodelete option for destroying handles If the process unloads the rpc-port library, the process will be crashed by the glib source. While calling elm_shutdown(), the glib source will be dispatched. In that case, the process has crashed if the rpc-port library is unloaded. Change-Id: I67354c0d7bc8d2ef51b363cb762f5c8132940783 Signed-off-by: Hwankyu Jhun --- src/CMakeLists.txt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 46b286d..a783f49 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -25,6 +25,8 @@ APPLY_PKG_CONFIG(${TARGET_RPC_PORT} PUBLIC UUID_DEPS ) +TARGET_LINK_LIBRARIES(${TARGET_RPC_PORT} PUBLIC "-Wl,-z,nodelete") + INSTALL(TARGETS ${TARGET_RPC_PORT} DESTINATION ${LIB_INSTALL_DIR}) INSTALL(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/../include/ DESTINATION include/rpc-port -- 2.7.4 From f50fb93fb27145e249b3d5714a9f506293dfa930 Mon Sep 17 00:00:00 2001 From: Hwankyu Jhun Date: Fri, 12 May 2023 02:08:36 +0000 Subject: [PATCH 03/16] Release version 1.14.4 Changes: - Add nodelete option for destroying handles Change-Id: I349b3acef2b9cf024c5e631be46480809b43bc23 Signed-off-by: Hwankyu Jhun --- packaging/rpc-port.spec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packaging/rpc-port.spec b/packaging/rpc-port.spec index 2702f16..ad9b669 100644 --- a/packaging/rpc-port.spec +++ b/packaging/rpc-port.spec @@ -1,6 +1,6 @@ Name: rpc-port Summary: RPC Port library -Version: 1.14.3 +Version: 1.14.4 Release: 0 Group: Application Framework/Libraries License: Apache-2.0 -- 2.7.4 From 318b00f0a9a569000f44c8fa4b1ce061f02f5091 Mon Sep 17 00:00:00 2001 From: Hwankyu Jhun Date: Mon, 15 May 2023 22:31:59 +0000 Subject: [PATCH 04/16] Change tizen version from 7.5 to 8.0 Platform version policy has been changed from 7.5 to 8.0. This patch modifies the description of the API added in 7.5 to 8.0. Change-Id: I6a506b9202cd166c6398feb673fef8e84804df0c Signed-off-by: Hwankyu Jhun --- include/rpc-port-parcel.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/rpc-port-parcel.h b/include/rpc-port-parcel.h index 02c5aa3..48c6a8d 100644 --- a/include/rpc-port-parcel.h +++ b/include/rpc-port-parcel.h @@ -543,7 +543,7 @@ int rpc_port_parcel_create_from_raw(rpc_port_parcel_h *h, const void *raw, unsig /** * @brief Creates the rpc port parcel handle without the header. - * @since_tizen 7.5 + * @since_tizen 8.0 * @remarks You must release @a h using rpc_port_parcel_destroy(). * @param[out] h The rpc port parcel handle * @return @c 0 on success, -- 2.7.4 From 9d8e077de45348a545f3fcb3b26981378fff8262 Mon Sep 17 00:00:00 2001 From: Hwankyu Jhun Date: Wed, 31 May 2023 08:02:16 +0000 Subject: [PATCH 05/16] Release version 1.14.5 Changes: - Change tizen version from 7.5 to 8.0 Change-Id: I9a699694d24b9e46ce28ad4039196b5dafd79f5f Signed-off-by: Hwankyu Jhun --- packaging/rpc-port.spec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packaging/rpc-port.spec b/packaging/rpc-port.spec index ad9b669..5195a11 100644 --- a/packaging/rpc-port.spec +++ b/packaging/rpc-port.spec @@ -1,6 +1,6 @@ Name: rpc-port Summary: RPC Port library -Version: 1.14.4 +Version: 1.14.5 Release: 0 Group: Application Framework/Libraries License: Apache-2.0 -- 2.7.4 From 9d6ccd46b6479dace85616391190b3c1b07491a0 Mon Sep 17 00:00:00 2001 From: Hwankyu Jhun Date: Mon, 3 Jul 2023 07:27:22 +0000 Subject: [PATCH 06/16] Fixed the build error using gcc 13 - Fix wrong indentation - Remove unnecessary std::move call Change-Id: I903fa85df87fccb7b0aa74aeccd4c888d26e48c1 Signed-off-by: Hwankyu Jhun --- src/cynara_thread.cc | 2 +- src/debug-port-internal.hh | 1 + src/port-internal.cc | 6 +++--- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/cynara_thread.cc b/src/cynara_thread.cc index 7e5b84b..15ccf15 100644 --- a/src/cynara_thread.cc +++ b/src/cynara_thread.cc @@ -47,7 +47,7 @@ CynaraThread::~CynaraThread() { void CynaraThread::ThreadRun() { while (true) { - Job job = std::move(queue_.WaitAndPop()); + Job job = queue_.WaitAndPop(); Job::Type ret = job.Do(); if (ret == Job::Type::Finish) return; diff --git a/src/debug-port-internal.hh b/src/debug-port-internal.hh index 1fb2285..9b68c65 100644 --- a/src/debug-port-internal.hh +++ b/src/debug-port-internal.hh @@ -17,6 +17,7 @@ #ifndef DEBUG_PORT_INTERNAL_HH_ #define DEBUG_PORT_INTERNAL_HH_ +#include #include namespace rpc_port { diff --git a/src/port-internal.cc b/src/port-internal.cc index a937278..5c7d66c 100644 --- a/src/port-internal.cc +++ b/src/port-internal.cc @@ -266,10 +266,10 @@ int Port::Write(const void* buf, unsigned int size, int* sent_bytes) { continue; } - if (errno == EAGAIN || errno == EWOULDBLOCK) - return PORT_STATUS_ERROR_RESOURCE_UNAVAILABLE; + if (errno == EAGAIN || errno == EWOULDBLOCK) + return PORT_STATUS_ERROR_RESOURCE_UNAVAILABLE; - _E("write_socket: ...error fd %d: errno %d\n", fd_, errno); + _E("write_socket: ...error fd: %d, errno: %d", fd_, errno); return PORT_STATUS_ERROR_IO_ERROR; } -- 2.7.4 From 343cc3a50701e295eb65a923df206529922d5856 Mon Sep 17 00:00:00 2001 From: Hwankyu Jhun Date: Mon, 3 Jul 2023 08:38:39 +0000 Subject: [PATCH 07/16] Release version 1.14.6 Changes: - Fixed the build error using gcc 13 Change-Id: If1be7db5a87f2badacf3dcec95a7fa617d6c7dec Signed-off-by: Hwankyu Jhun --- packaging/rpc-port.spec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packaging/rpc-port.spec b/packaging/rpc-port.spec index 5195a11..60430f7 100644 --- a/packaging/rpc-port.spec +++ b/packaging/rpc-port.spec @@ -1,6 +1,6 @@ Name: rpc-port Summary: RPC Port library -Version: 1.14.5 +Version: 1.14.6 Release: 0 Group: Application Framework/Libraries License: Apache-2.0 -- 2.7.4 From e3b245ce14500169bf109fccbc6b48e9cd442c41 Mon Sep 17 00:00:00 2001 From: jusung son Date: Wed, 19 Jul 2023 09:39:32 +0900 Subject: [PATCH 08/16] Add a new internal API for gettting peer info - rpc_port_get_peer_info() Change-Id: I8516e79389fe89d391ea1b30999ba253e811d22e Signed-off-by: jusung son --- include/rpc-port-internal.h | 11 +++++++++++ src/rpc-port-internal.cc | 22 ++++++++++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/include/rpc-port-internal.h b/include/rpc-port-internal.h index 999f73f..636306a 100644 --- a/include/rpc-port-internal.h +++ b/include/rpc-port-internal.h @@ -64,6 +64,17 @@ int rpc_port_register_proc_info(const char *proc_name, bundle *extra); */ int rpc_port_deregister_proc_info(void); +/** + * @brief Gets the pid and uid of the connected rpc port. + * @since_tizen 8.0 + * @param[in] h The rpc port handle + * @param[out] pid Process ID + * @param[out] uid User ID + * @return @c 0 on success, + * otherwise a negative error value + */ +int rpc_port_get_peer_info(rpc_port_h h, pid_t *pid, uid_t *uid); + #ifdef __cplusplus } #endif diff --git a/src/rpc-port-internal.cc b/src/rpc-port-internal.cc index 36682dd..1a8c0b1 100644 --- a/src/rpc-port-internal.cc +++ b/src/rpc-port-internal.cc @@ -23,11 +23,14 @@ #include "include/rpc-port-internal.h" #include "include/rpc-port.h" +#include "peer-cred-internal.hh" +#include "port-internal.hh" #undef RPC_API #define RPC_API extern "C" __attribute__((visibility("default"))) namespace { +using namespace rpc_port::internal; constexpr uid_t kRegularUidMin = 5000; std::atomic __target_uid { getuid() }; @@ -63,3 +66,22 @@ RPC_API int rpc_port_deregister_proc_info(void) { return RPC_PORT_ERROR_NONE; } + +RPC_API int rpc_port_get_peer_info(rpc_port_h h, pid_t* pid, uid_t* uid) { + if (h == nullptr) + return RPC_PORT_ERROR_INVALID_PARAMETER; + + auto port = static_cast(h); + std::shared_ptr cred(PeerCred::Get(port->GetFd())); + if (cred.get() == nullptr) + return RPC_PORT_ERROR_IO_ERROR; + + if (pid) + *pid = cred->GetPid(); + + if (uid) + *uid = cred->GetUid(); + + return RPC_PORT_ERROR_NONE; +} + -- 2.7.4 From fa87e1d5debce55c02c1fcbca35acfd5ee9d78ee Mon Sep 17 00:00:00 2001 From: jusung son Date: Wed, 19 Jul 2023 10:00:08 +0900 Subject: [PATCH 09/16] Release version 1.14.7 Changes: - Add a new internal API for gettting peer info Change-Id: Ib3ef3ada76b401924d5d20480f1c929581f9618a Signed-off-by: jusung son --- packaging/rpc-port.spec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packaging/rpc-port.spec b/packaging/rpc-port.spec index 60430f7..1db372f 100644 --- a/packaging/rpc-port.spec +++ b/packaging/rpc-port.spec @@ -1,6 +1,6 @@ Name: rpc-port Summary: RPC Port library -Version: 1.14.6 +Version: 1.14.7 Release: 0 Group: Application Framework/Libraries License: Apache-2.0 -- 2.7.4 From 136c27ddc0331dd848bf6a7f3907ef669be2ec32 Mon Sep 17 00:00:00 2001 From: Changgyu Choi Date: Fri, 4 Aug 2023 11:17:08 +0900 Subject: [PATCH 10/16] Protect to access released handle Change-Id: Ib228d1991930e220226e83b2d7ed87155589e595 Signed-off-by: Changgyu Choi --- src/ac-internal.cc | 8 ++++++++ src/ac-internal.hh | 2 +- src/cynara_thread.cc | 7 +++---- src/cynara_thread.hh | 2 ++ src/stub-internal.cc | 6 +++--- src/stub-internal.hh | 3 ++- 6 files changed, 19 insertions(+), 9 deletions(-) diff --git a/src/ac-internal.cc b/src/ac-internal.cc index 70821d6..9f44608 100644 --- a/src/ac-internal.cc +++ b/src/ac-internal.cc @@ -96,7 +96,14 @@ int AccessController::Check(int fd, const std::string& sender_appid) { void AccessController::CheckAsync(int fd, std::string sender_appid, CompleteCallback callback) { + /* This is for handle freed issue */ + auto tmp_handle = new std::shared_ptr(shared_from_this()); Job job([=]() -> Job::Type { + if ((*tmp_handle).use_count() == 1) { + delete tmp_handle; + return Job::Type::Continue; + } + int res = Check(fd, sender_appid); auto* cbdata = new std::pair(callback, res); guint sid = g_idle_add( @@ -112,6 +119,7 @@ void AccessController::CheckAsync(int fd, std::string sender_appid, delete cbdata; } + delete tmp_handle; return Job::Type::Continue; }); diff --git a/src/ac-internal.hh b/src/ac-internal.hh index a2309ee..daefbd7 100644 --- a/src/ac-internal.hh +++ b/src/ac-internal.hh @@ -33,7 +33,7 @@ namespace internal { using CompleteCallback = std::function; -class AccessController { +class AccessController : public std::enable_shared_from_this { public: explicit AccessController(bool trusted = false) : trusted_(trusted) {} diff --git a/src/cynara_thread.cc b/src/cynara_thread.cc index 15ccf15..fb86761 100644 --- a/src/cynara_thread.cc +++ b/src/cynara_thread.cc @@ -40,17 +40,16 @@ CynaraThread::CynaraThread() { } CynaraThread::~CynaraThread() { - Job finish_job; - Push(finish_job); + finished_ = true; thread_.join(); } void CynaraThread::ThreadRun() { while (true) { Job job = queue_.WaitAndPop(); - Job::Type ret = job.Do(); - if (ret == Job::Type::Finish) + if (finished_) return; + Job::Type ret = job.Do(); } } diff --git a/src/cynara_thread.hh b/src/cynara_thread.hh index 3babdd3..04d76cd 100644 --- a/src/cynara_thread.hh +++ b/src/cynara_thread.hh @@ -17,6 +17,7 @@ #ifndef CYNARA_THREAD_HH_ #define CYNARA_THREAD_HH_ +#include #include #include #include @@ -58,6 +59,7 @@ class CynaraThread { Job Pop(); std::thread thread_; + std::atomic finished_ = false; mutable tizen_base::SharedQueue queue_; }; diff --git a/src/stub-internal.cc b/src/stub-internal.cc index 72b59b2..b0bc883 100644 --- a/src/stub-internal.cc +++ b/src/stub-internal.cc @@ -129,12 +129,12 @@ void Stub::Ignore() { void Stub::AddPrivilege(const std::string& privilege) { std::lock_guard lock(GetMutex()); - access_controller_.AddPrivilege(privilege); + access_controller_->AddPrivilege(privilege); } void Stub::SetTrusted(const bool trusted) { std::lock_guard lock(GetMutex()); - access_controller_.SetTrusted(trusted); + access_controller_->SetTrusted(trusted); } std::shared_ptr Stub::FindPort(const std::string& instance) const { @@ -412,7 +412,7 @@ gboolean Stub::Server::OnRequestReceived(GIOChannel* channel, GIOCondition cond, _E("Reject request. %u:%u", cred->GetUid(), getuid()); res = -1; } else { - stub->access_controller_.CheckAsync(client->GetFd(), app_id, + stub->access_controller_->CheckAsync(client->GetFd(), app_id, response_func); return G_SOURCE_CONTINUE; } diff --git a/src/stub-internal.hh b/src/stub-internal.hh index 0f2723c..f58413f 100644 --- a/src/stub-internal.hh +++ b/src/stub-internal.hh @@ -108,7 +108,8 @@ class Stub { std::recursive_mutex& GetMutex() const; private: - AccessController access_controller_; + std::shared_ptr access_controller_ = + std::make_shared(); std::string port_name_; std::list> ports_; IEventListener* listener_ = nullptr; -- 2.7.4 From 56171d9e4c0153d359f19ecaafdb3a55b5c373f7 Mon Sep 17 00:00:00 2001 From: Changgyu Choi Date: Mon, 7 Aug 2023 10:34:13 +0900 Subject: [PATCH 11/16] Release version 1.14.8 Changes: - Protect to access released handle Change-Id: Iaece9994d3e626f6f851ed6f160de0a051d28110 Signed-off-by: Changgyu Choi --- packaging/rpc-port.spec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packaging/rpc-port.spec b/packaging/rpc-port.spec index 1db372f..ed1402e 100644 --- a/packaging/rpc-port.spec +++ b/packaging/rpc-port.spec @@ -1,6 +1,6 @@ Name: rpc-port Summary: RPC Port library -Version: 1.14.7 +Version: 1.14.8 Release: 0 Group: Application Framework/Libraries License: Apache-2.0 -- 2.7.4 From 1c30b7798dfc159cfa2e8a8f66ba78fed4fcea15 Mon Sep 17 00:00:00 2001 From: Hwankyu Jhun Date: Mon, 28 Aug 2023 10:21:59 +0900 Subject: [PATCH 12/16] Remove build warning message - Removes unused variable Change-Id: I9a50268f0f7e0b4b73825204b704175fe712254d Signed-off-by: Hwankyu Jhun --- src/cynara_thread.cc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/cynara_thread.cc b/src/cynara_thread.cc index fb86761..9e84564 100644 --- a/src/cynara_thread.cc +++ b/src/cynara_thread.cc @@ -49,7 +49,8 @@ void CynaraThread::ThreadRun() { Job job = queue_.WaitAndPop(); if (finished_) return; - Job::Type ret = job.Do(); + + job.Do(); } } -- 2.7.4 From a2b29184faa2b4c3ea5c05a01bd82c3b80029c2b Mon Sep 17 00:00:00 2001 From: Hwankyu Jhun Date: Mon, 28 Aug 2023 15:33:11 +0900 Subject: [PATCH 13/16] Improve code coverage - Adds unit tests - Excludes some lines Change-Id: I2e3e64252fb48eecd4130323151c6fb892832a39 Signed-off-by: Hwankyu Jhun --- packaging/rpc-port.spec | 2 + src/ac-internal.cc | 18 +++- src/aul-internal.cc | 10 +- src/client-socket-internal.cc | 83 +++----------- src/client-socket-internal.hh | 5 - src/cynara_thread.cc | 4 +- src/exception-internal.cc | 2 + src/exception-internal.hh | 2 +- src/message-sending-thread-internal.cc | 2 + src/parcel-internal.cc | 12 ++- src/peer-cred-internal.cc | 7 +- src/port-internal.cc | 41 ++++--- src/port-internal.hh | 2 + src/proxy-internal.cc | 172 +++++++++++++++-------------- src/rpc-port-internal.cc | 1 + src/rpc-port-parcel.cc | 47 ++++---- src/rpc-port.cc | 16 +-- src/server-socket-internal.cc | 6 +- src/stub-internal.cc | 82 +++++++------- test/unit_tests/mock/aul_mock.cc | 8 ++ test/unit_tests/mock/aul_mock.hh | 36 +++---- test/unit_tests/rpc_port_parcel_test.cc | 185 ++++++++------------------------ test/unit_tests/rpc_port_test.cc | 128 ++++++++++++---------- 23 files changed, 404 insertions(+), 467 deletions(-) diff --git a/packaging/rpc-port.spec b/packaging/rpc-port.spec index ed1402e..5c4562a 100644 --- a/packaging/rpc-port.spec +++ b/packaging/rpc-port.spec @@ -125,12 +125,14 @@ setup() { test_main() { echo "test_main start" export "GCOV_PREFIX=/tmp" + /usr/bin/rpc-port-util -n test_port & /usr/bin/rpc-port_unittests } teardown() { echo "teardown start" set_perm + killall rpc-port-util } main() { diff --git a/src/ac-internal.cc b/src/ac-internal.cc index 9f44608..9fea7ca 100644 --- a/src/ac-internal.cc +++ b/src/ac-internal.cc @@ -53,6 +53,7 @@ int AccessController::CheckPrivilege(const Cynara& c) { return 0; } +// LCOV_EXCL_START int AccessController::CheckTrusted(const std::string& sender_appid) { if (getuid() < kRegularUidMin) return 0; @@ -75,6 +76,7 @@ int AccessController::CheckTrusted(const std::string& sender_appid) { return 0; } +// LCOV_EXCL_STOP int AccessController::Check(int fd, const std::string& sender_appid) { Cynara cynara; @@ -100,8 +102,8 @@ void AccessController::CheckAsync(int fd, std::string sender_appid, auto tmp_handle = new std::shared_ptr(shared_from_this()); Job job([=]() -> Job::Type { if ((*tmp_handle).use_count() == 1) { - delete tmp_handle; - return Job::Type::Continue; + delete tmp_handle; // LCOV_EXCL_LINE + return Job::Type::Continue; // LCOV_EXCL_LINE } int res = Check(fd, sender_appid); @@ -115,8 +117,8 @@ void AccessController::CheckAsync(int fd, std::string sender_appid, return G_SOURCE_REMOVE; }, cbdata); if (sid == 0) { - _E("Failed to call g_idle_add"); - delete cbdata; + _E("Failed to call g_idle_add"); // LCOV_EXCL_LINE + delete cbdata; // LCOV_EXCL_LINE } delete tmp_handle; @@ -132,7 +134,7 @@ AccessController::Cynara::Cynara() cynara* cynara_inst = nullptr; if (cynara_initialize(&cynara_inst, NULL) != CYNARA_API_SUCCESS) { - _E("cynara_initialize() is failed"); // LCOV_EXL_LINE + _E("cynara_initialize() is failed"); // LCOV_EXCL_LINE } else { cynara_.reset(cynara_inst); } @@ -144,22 +146,26 @@ int AccessController::Cynara::FetchCredsFromSocket(int fd) { char* user = nullptr; int ret = cynara_creds_socket_get_user(fd, USER_METHOD_DEFAULT, &user); if (ret != CYNARA_API_SUCCESS) { + // LCOV_EXCL_START char buf[128] = { 0, }; cynara_strerror(ret, buf, sizeof(buf)); _E("cynara_creds_socket_get_user() is failed. fd(%d), error(%d:%s)", fd, ret, buf); return -1; + // LCOV_EXCL_STOP } user_.reset(user); char* client = nullptr; ret = cynara_creds_socket_get_client(fd, CLIENT_METHOD_DEFAULT, &client); if (ret != CYNARA_API_SUCCESS) { + // LCOV_EXCL_START char buf[128] = { 0, }; cynara_strerror(ret, buf, sizeof(buf)); _E("cynara_creds_socket_get_client() is failed. fd(%d), error(%d:%s)", fd, ret, buf); return -1; + // LCOV_EXCL_STOP } client_.reset(client); @@ -167,6 +173,7 @@ int AccessController::Cynara::FetchCredsFromSocket(int fd) { return 0; } +// LCOV_EXCL_START int AccessController::Cynara::Check(const std::string& privilege) const { _D("check privilege %s", privilege.c_str()); if (cynara_check(cynara_.get(), client_.get(), "", user_.get(), @@ -177,6 +184,7 @@ int AccessController::Cynara::Check(const std::string& privilege) const { return 0; } +// LCOV_EXCL_STOP } // namespace internal } // namespace rpc_port diff --git a/src/aul-internal.cc b/src/aul-internal.cc index 67a5838..f77b6d3 100644 --- a/src/aul-internal.cc +++ b/src/aul-internal.cc @@ -31,6 +31,7 @@ std::string Aul::GetAppId(int pid) { char app_id[256] = { 0, }; int ret = aul_app_get_appid_bypid(pid, app_id, sizeof(app_id)); if (ret != AUL_R_OK) { + // LCOV_EXCL_START _E("aul_app_get_appid_bypid() is failed. pid(%d), error(%d)", pid, ret); char* name = nullptr; ret = aul_proc_get_name(pid, &name); @@ -39,6 +40,7 @@ std::string Aul::GetAppId(int pid) { std::unique_ptr name_auto(name, std::free); return std::string(name); + // LCOV_EXCL_STOP } return std::string(app_id); @@ -50,8 +52,8 @@ std::string Aul::GetPortPath(const std::string& app_id, int ret = aul_rpc_port_usr_get_path(app_id.c_str(), port_name.c_str(), uid, &port_path); if (ret != AUL_R_OK) { - _E("aul_rpc_port_usr_get_path() is failed. error(%d)", ret); - return {}; + _E("aul_rpc_port_usr_get_path() is failed. error(%d)", ret); // LCOV_EXCL_LINE + return {}; // LCOV_EXCL_LINE } std::unique_ptr ptr(port_path, std::free); @@ -79,7 +81,7 @@ bool Aul::ExistPort(const std::string& app_id, const std::string& port_name, int ret = aul_rpc_port_usr_exist(app_id.c_str(), port_name.c_str(), uid, &exist); if (ret != AUL_R_OK) - _W("aul_rpc_port_usr_exist() is failed. error(%d)", ret); + _W("aul_rpc_port_usr_exist() is failed. error(%d)", ret); // LCOV_EXCL_LINE return exist; } @@ -87,7 +89,7 @@ bool Aul::ExistPort(const std::string& app_id, const std::string& port_name, void Aul::NotifyRpcFinished() { int ret = aul_rpc_port_notify_rpc_finished(); if (ret != AUL_R_OK) - _W("aul_rpc_port_notify_rpc_finished() is failed. error(%d)", ret); + _W("aul_rpc_port_notify_rpc_finished() is failed. error(%d)", ret); // LCOV_EXCL_LINE } } // namespace internal diff --git a/src/client-socket-internal.cc b/src/client-socket-internal.cc index c932342..295d172 100644 --- a/src/client-socket-internal.cc +++ b/src/client-socket-internal.cc @@ -32,9 +32,11 @@ namespace internal { ClientSocket::ClientSocket() { fd_ = socket(AF_UNIX, SOCK_STREAM | SOCK_CLOEXEC, 0); if (fd_ < 0) { + // LCOV_EXCL_START fd_ = -errno; _E("socket() is failed. errno(%d)", errno); THROW(fd_); + // LCOV_EXCL_STOP } } @@ -66,9 +68,11 @@ int ClientSocket::Connect(const std::string& endpoint) { int ret = connect(GetFd(), sockaddr_ptr, len); fcntl(GetFd(), F_SETFL, flag); if (ret < 0) { + // LCOV_EXCL_START ret = -errno; _E("connect() is failed. errno(%d)", errno); return ret; + // LCOV_EXCL_STOP } return 0; @@ -80,9 +84,11 @@ int ClientSocket::Send(const void* buf, unsigned int size) { while (len) { ssize_t bytes = send(GetFd(), buffer, len, MSG_NOSIGNAL); if (bytes < 0) { + // LCOV_EXCL_START int ret = -errno; _E("send() is failed. fd(%d), errno(%d)", GetFd(), errno); return ret; + // LCOV_EXCL_STOP } len -= bytes; @@ -98,12 +104,12 @@ int ClientSocket::Receive(void* buf, unsigned int size) { while (len) { ssize_t bytes = read(GetFd(), buffer, len); if (bytes == 0) { - _W("EOF. fd(%d)", GetFd()); - return -EIO; + _W("EOF. fd(%d)", GetFd()); // LCOV_EXCL_START + return -EIO; // LCOV_EXCL_STOP } if (bytes < 0) - return -errno; + return -errno; // LCOV_EXCL_LINE len -= bytes; buffer += bytes; @@ -112,79 +118,16 @@ int ClientSocket::Receive(void* buf, unsigned int size) { return 0; } -int ClientSocket::GetReceiveBufferSize() { - int value; - socklen_t len = sizeof(int); - int ret = getsockopt(GetFd(), SOL_SOCKET, SO_RCVBUF, - reinterpret_cast(&value), &len); - if (ret < 0) { - ret = -errno; - _E("getsockopt() is failed. errno(%d)", errno); - return ret; - } - - return value; -} - -int ClientSocket::GetSendBufferSize() { - int value; - socklen_t len = sizeof(int); - int ret = getsockopt(GetFd(), SOL_SOCKET, SO_SNDBUF, - reinterpret_cast(&value), &len); - if (ret < 0) { - ret = -errno; - _E("getsockopt() is failed. errno(%d)", errno); - return ret; - } - - return value; -} - -int ClientSocket::GetReceiveTimeout() { - struct timeval timeout = { 0, }; - socklen_t len = static_cast(sizeof(struct timeval)); - int ret = getsockopt(GetFd(), SOL_SOCKET, SO_RCVTIMEO, - reinterpret_cast(&timeout), &len); - if (ret < 0) { - ret = -errno; - _E("getsockopt() is failed. errno(%d)", errno); - return ret; - } - - int value = timeout.tv_sec * 1000 + timeout.tv_usec / 1000; - return value; -} - -void ClientSocket::SetReceiveBufferSize(int size) { - socklen_t len = static_cast(sizeof(size)); - int ret = setsockopt(GetFd(), SOL_SOCKET, SO_RCVBUF, &size, len); - if (ret < 0) { - ret = -errno; - _E("setsockopt() is failed. errno(%d)", errno); - THROW(ret); - } -} - -void ClientSocket::SetSendBufferSize(int size) { - socklen_t len = sizeof(size); - int ret = setsockopt(GetFd(), SOL_SOCKET, SO_SNDBUF, &size, len); - if (ret < 0) { - ret = -errno; - _E("setsockopt() is failed. errno(%d)", errno); - THROW(ret); - } -} - void ClientSocket::SetReceiveTimeout(int timeout) { if (timeout == INT_MAX) - return; + return; // LCOV_EXCL_LINE if (timeout == -1) timeout = 5000; if (timeout < 0) { - _E("Invalid parameter"); - THROW(-EINVAL); + _E("Invalid parameter"); // LCOV_EXCL_LINE + THROW(-EINVAL); // LCOV_EXCL_LINE } struct timeval tv = { @@ -194,9 +137,11 @@ void ClientSocket::SetReceiveTimeout(int timeout) { socklen_t len = static_cast(sizeof(struct timeval)); int ret = setsockopt(GetFd(), SOL_SOCKET, SO_RCVTIMEO, &tv, len); if (ret < 0) { + // LCOV_EXCL_START ret = -errno; _E("setsockopt() is failed. errno(%d)", errno); THROW(ret); + // LCOV_EXCL_STOP } } diff --git a/src/client-socket-internal.hh b/src/client-socket-internal.hh index 2446e38..9b02047 100644 --- a/src/client-socket-internal.hh +++ b/src/client-socket-internal.hh @@ -32,11 +32,6 @@ class ClientSocket { int Connect(const std::string& endpoint); int Send(const void* buf, unsigned int size); int Receive(void* buf, unsigned int size); - int GetReceiveBufferSize(); - int GetSendBufferSize(); - int GetReceiveTimeout(); - void SetReceiveBufferSize(int size); - void SetSendBufferSize(int size); void SetReceiveTimeout(int timeout); bool IsClosed(); int GetFd() const; diff --git a/src/cynara_thread.cc b/src/cynara_thread.cc index 9e84564..17b7ee3 100644 --- a/src/cynara_thread.cc +++ b/src/cynara_thread.cc @@ -39,16 +39,18 @@ CynaraThread::CynaraThread() { thread_ = std::thread([this]() { ThreadRun(); }); } +// LCOV_EXCL_START CynaraThread::~CynaraThread() { finished_ = true; thread_.join(); } +// LCOV_EXCL_STOP void CynaraThread::ThreadRun() { while (true) { Job job = queue_.WaitAndPop(); if (finished_) - return; + return; // LCOV_EXCL_LINE job.Do(); } diff --git a/src/exception-internal.cc b/src/exception-internal.cc index 2af6bfb..51a7bb9 100644 --- a/src/exception-internal.cc +++ b/src/exception-internal.cc @@ -21,6 +21,7 @@ namespace rpc_port { namespace internal { +// LCOV_EXCL_START Exception::Exception(int error_code, const std::string& file, int line) : error_code_(error_code), message_(std::move(GetErrorMessage(error_code_, file, line))) { @@ -39,6 +40,7 @@ std::string Exception::GetErrorMessage(int error_code, const std::string& file, return file.substr(file.find_last_of("/") + 1) + ":" + std::to_string(line) + " error_code: " + std::to_string(error_code); } +// LCOV_EXCL_STOP } // namespace internal } // namespace rpc_port diff --git a/src/exception-internal.hh b/src/exception-internal.hh index 655fbae..226c909 100644 --- a/src/exception-internal.hh +++ b/src/exception-internal.hh @@ -28,7 +28,7 @@ namespace internal { class Exception : public std::exception { public: explicit Exception(int error_code, const std::string& file, int line); - virtual ~Exception() = default; + virtual ~Exception() = default; // LCOV_EXCL_LINE virtual const char* what() const noexcept; int GetErrorCode(); diff --git a/src/message-sending-thread-internal.cc b/src/message-sending-thread-internal.cc index e74c895..b21eddd 100644 --- a/src/message-sending-thread-internal.cc +++ b/src/message-sending-thread-internal.cc @@ -20,6 +20,7 @@ namespace rpc_port { namespace internal { +// LCOV_EXCL_START MessageSendingThread& MessageSendingThread::GetInst() { static MessageSendingThread inst; return inst; @@ -88,6 +89,7 @@ void MessageSendingThread::Dispose() { GMainContext* MessageSendingThread::GetContext() { return context_; } +// LCOV_EXCL_STOP } // namespace internal } // namespace rpc_port diff --git a/src/parcel-internal.cc b/src/parcel-internal.cc index 75f4302..932569c 100644 --- a/src/parcel-internal.cc +++ b/src/parcel-internal.cc @@ -14,10 +14,12 @@ * limitations under the License. */ +#include "parcel-internal.hh" + #include +#include #include "log-private.hh" -#include "parcel-internal.hh" namespace rpc_port { namespace internal { @@ -46,16 +48,18 @@ void Parcel::ReadFromParcel(tizen_base::Parcel* parcel) { if (size > 0) { auto* buf = static_cast(malloc(size)); if (buf == nullptr) { - _E("Out of memory"); - return; + _E("Out of memory"); // LCOV_EXEC_LINE + return; // LCOV_EXCL_LINE } parcel->Read(buf, size); handle_ = std::move(tizen_base::Parcel(buf, size, false)); } } else { + // LCOV_EXCL_START handle_ = std::move( tizen_base::Parcel(parcel->GetData(), parcel->GetDataSize())); + // LCOV_EXCL_STOP } } @@ -71,9 +75,11 @@ void Parcel::SetRawParcel(tizen_base::Parcel* raw_parcel) { raw_parcel_.reset(raw_parcel); } +// LCOV_EXCL_START tizen_base::Parcel* Parcel::GetRawParcel() const { return raw_parcel_.get(); } +// LCOV_EXCL_STOP } // namespace internal } // namespace rpc_port diff --git a/src/peer-cred-internal.cc b/src/peer-cred-internal.cc index e978e0f..150d3ab 100644 --- a/src/peer-cred-internal.cc +++ b/src/peer-cred-internal.cc @@ -35,8 +35,8 @@ PeerCred* PeerCred::Get(int fd) { int ret = getsockopt(fd, SOL_SOCKET, SO_PEERCRED, static_cast(&cred), &len); if (ret != 0) { - _E("getsockopt() is failed. fd(%d), errno(%d)", fd, errno); - return nullptr; + _E("getsockopt() is failed. fd(%d), errno(%d)", fd, errno); // LCOV_EXCL_LINE + return nullptr; // LCOV_EXCL_LINE } return new (std::nothrow) PeerCred(cred.pid, cred.uid, cred.gid); @@ -50,9 +50,12 @@ uid_t PeerCred::GetUid() const { return uid_; } + +// LCOV_EXCL_START gid_t PeerCred::GetGid() const { return gid_; } +// LCOV_EXCL_STOP } // namespace internal } // namespace rpc_port diff --git a/src/port-internal.cc b/src/port-internal.cc index 5c7d66c..ecb6aea 100644 --- a/src/port-internal.cc +++ b/src/port-internal.cc @@ -42,6 +42,7 @@ constexpr const int MIN_TIMEOUT = 50; } // namespace +// LCOV_EXCL_START Port::DelayMessage::DelayMessage(const char* msg, int index, int size) : message_(msg, msg + size), index_(index), size_(size) { } @@ -63,6 +64,7 @@ char* Port::DelayMessage::GetMessage() { ptr += index_; return ptr; } +// LCOV_EXCL_STOP Port::Port(int fd, std::string id) : fd_(fd), id_(std::move(id)), instance_(""), seq_(0) { @@ -96,7 +98,8 @@ void Port::Disconnect() { int Port::SetPrivateSharing(const char* paths[], unsigned int size) { int ret = aul_rpc_port_set_private_sharing(id_.c_str(), paths, size); if (ret != 0) - return RPC_PORT_ERROR_IO_ERROR; + return RPC_PORT_ERROR_IO_ERROR; // LCOV_EXCL_LINE + return RPC_PORT_ERROR_NONE; } @@ -104,14 +107,14 @@ int Port::SetPrivateSharing(const char* path) { const char* file_list[1] = {path}; int ret = aul_rpc_port_set_private_sharing(id_.c_str(), file_list, 1); if (ret != 0) - return RPC_PORT_ERROR_IO_ERROR; + return RPC_PORT_ERROR_IO_ERROR; // LCOV_EXCL_LINE return RPC_PORT_ERROR_NONE; } int Port::UnsetPrivateSharing() { int ret = aul_rpc_port_unset_private_sharing(id_.c_str()); if (ret != 0) - return RPC_PORT_ERROR_IO_ERROR; + return RPC_PORT_ERROR_IO_ERROR; // LCOV_EXCL_LINE return RPC_PORT_ERROR_NONE; } @@ -130,8 +133,8 @@ int Port::Read(void* buf, unsigned int size) { } if (fd < 0 || fd >= sysconf(_SC_OPEN_MAX)) { - _E("Invalid fd(%d)", fd); - return RPC_PORT_ERROR_IO_ERROR; + _E("Invalid fd(%d)", fd); // LCOV_EXCL_LINE + return RPC_PORT_ERROR_IO_ERROR; // LCOV_EXCL_LINE } while (left) { @@ -162,8 +165,8 @@ int Port::Read(void* buf, unsigned int size) { } if (!can_read) { - _E("read_socket: ...timed out fd %d: errno %d", fd, errno); - return RPC_PORT_ERROR_IO_ERROR; + _E("read_socket: ...timed out fd %d: errno %d", fd, errno); // LCOV_EXCL_LINE + return RPC_PORT_ERROR_IO_ERROR; // LCOV_EXCL_LINE } continue; @@ -197,6 +200,7 @@ bool Port::CanRead(int timeout) { return true; } +// LCOV_EXCL_START bool Port::CanWrite() { struct pollfd fds[1]; fds[0].fd = fd_; @@ -211,6 +215,7 @@ bool Port::CanWrite() { return true; } +// LCOV_EXCL_STOP int Port::Write(const void* buf, unsigned int size) { int sent_bytes = 0; @@ -223,7 +228,8 @@ int Port::Write(const void* buf, unsigned int size) { return RPC_PORT_ERROR_NONE; else if (ret == PORT_STATUS_ERROR_IO_ERROR) return RPC_PORT_ERROR_IO_ERROR; - } else if (CanWrite()) { + } else if (CanWrite()) { // LCOV_EXCL_LINE + // LCOV_EXCL_START while (!queue_.empty()) { int port_status = PopDelayedMessage(); if (port_status != PORT_STATUS_ERROR_NONE) { @@ -233,8 +239,10 @@ int Port::Write(const void* buf, unsigned int size) { break; } } + // LCOV_EXCL_STOP } + // LCOV_EXCL_START if (delayed_message_size_ > QUEUE_SIZE_MAX) { _E("cache fail : delayed_message_size (%d), count(%zu)", delayed_message_size_, queue_.size()); @@ -244,6 +252,7 @@ int Port::Write(const void* buf, unsigned int size) { return PushDelayedMessage( std::make_shared( static_cast(buf), sent_bytes, size)); + // LCOV_EXCL_STOP } int Port::Write(const void* buf, unsigned int size, int* sent_bytes) { @@ -253,17 +262,19 @@ int Port::Write(const void* buf, unsigned int size, int* sent_bytes) { const char* buffer = static_cast(buf); if (fd_ < 0 || fd_ >= sysconf(_SC_OPEN_MAX)) { - _E("Invalid fd(%d)", fd_); - return PORT_STATUS_ERROR_IO_ERROR; + _E("Invalid fd(%d)", fd_); // LCOV_EXCL_LINE + return PORT_STATUS_ERROR_IO_ERROR; // LCOV_EXCL_LINE } while (left && (retry_cnt < MAX_RETRY_CNT)) { nb = send(fd_, buffer, left, MSG_NOSIGNAL); if (nb == -1) { if (errno == EINTR) { + // LCOV_EXCL_START LOGI("write_socket: EINTR continue ..."); retry_cnt++; continue; + // LCOV_EXCL_STOP } if (errno == EAGAIN || errno == EWOULDBLOCK) @@ -286,6 +297,7 @@ int Port::Write(const void* buf, unsigned int size, int* sent_bytes) { return PORT_STATUS_ERROR_NONE; } +// LCOV_EXCL_START gboolean Port::OnEventReceived(GIOChannel* io, GIOCondition condition, gpointer data) { auto* ptr = static_cast*>(data); @@ -311,6 +323,7 @@ gboolean Port::OnEventReceived(GIOChannel* io, GIOCondition condition, port->PopDelayedMessage(); return G_SOURCE_CONTINUE; } +// LCOV_EXCL_STOP void Port::ClearQueue() { std::lock_guard lock(rw_mutex_); @@ -325,20 +338,23 @@ void Port::ClearQueue() { void Port::IgnoreIOEvent() { std::lock_guard lock(rw_mutex_); if (source_id_ != 0) { + // LCOV_EXCL_START GSource* source = g_main_context_find_source_by_id( MessageSendingThread::GetInst().GetContext(), source_id_); if (source != nullptr && !g_source_is_destroyed(source)) g_source_destroy(source); source_id_ = 0; + // LCOV_EXCL_STOP } if (channel_ != nullptr) { - g_io_channel_unref(channel_); - channel_ = nullptr; + g_io_channel_unref(channel_); // LCOV_EXCL_LINE + channel_ = nullptr; // LCOV_EXCL_LINE } } +// LCOV_EXCL_START int Port::ListenIOEvent() { std::lock_guard lock(rw_mutex_); channel_ = g_io_channel_unix_new(fd_); @@ -404,6 +420,7 @@ int Port::PushDelayedMessage(std::shared_ptr dm) { queue_.size(), delayed_message_size_); return RPC_PORT_ERROR_NONE; } +// LCOV_EXCL_STOP } // namespace internal } // namespace rpc_port diff --git a/src/port-internal.hh b/src/port-internal.hh index f9aba93..ee25d78 100644 --- a/src/port-internal.hh +++ b/src/port-internal.hh @@ -67,6 +67,7 @@ class Port : public std::enable_shared_from_this { } private: + // LCOV_EXCL_START bool CanRead(int timeout); bool CanWrite(); void IgnoreIOEvent(); @@ -98,6 +99,7 @@ class Port : public std::enable_shared_from_this { static gboolean OnEventReceived(GIOChannel* io, GIOCondition condition, gpointer data); void ClearQueue(); + // LCOV_EXCL_STOP int fd_; std::string id_; diff --git a/src/proxy-internal.cc b/src/proxy-internal.cc index 67fd462..4cf650d 100644 --- a/src/proxy-internal.cc +++ b/src/proxy-internal.cc @@ -56,14 +56,14 @@ int SendRequest(ClientSocket* client, const Request& request) { size_t size = parcel.GetDataSize(); int ret = client->Send(reinterpret_cast(&size), sizeof(size)); if (ret != 0) { - _E("Send() is failed. error(%d)", ret); - return -1; + _E("Send() is failed. error(%d)", ret); // LCOV_EXCL_LINE + return -1; // LCOV_EXCL_LINE } ret = client->Send(parcel.GetData(), size); if (ret != 0) { - _E("Send() is failed. error(%d)", ret); - return -1; + _E("Send() is failed. error(%d)", ret); // LCOV_EXCL_LINE + return -1; // LCOV_EXCL_LINE } return 0; @@ -73,28 +73,30 @@ int ReceiveResponse(ClientSocket* client, Response** response) { size_t size = 0; int ret = client->Receive(reinterpret_cast(&size), sizeof(size)); if (ret != 0) { - _E("Receive() is failed. error(%d)", ret); - return -1; + _E("Receive() is failed. error(%d)", ret); // LCOV_EXCL_LINE + return -1; // LCOV_EXCL_LINE } uint8_t* buf = static_cast(malloc(size)); if (buf == nullptr) { - _E("Out of memory"); - return -1; + _E("Out of memory"); // LCOV_EXCL_LINE + return -1; // LCOV_EXCL_LINE } ret = client->Receive(buf, size); if (ret != 0) { + // LCOV_EXCL_START _E("Receive() is failed. error(%d)", ret); free(buf); return -1; + // LCOV_EXCL_STOP } tizen_base::Parcel parcel(buf, size, false); *response = new (std::nothrow) Response(); if (*response == nullptr) { - _E("Out of memory"); - return -1; + _E("Out of memory"); // LCOV_EXCL_LINE + return -1; // LCOV_EXCL_LINE } parcel.ReadParcelable(*response); @@ -111,7 +113,7 @@ Proxy::~Proxy() { std::lock_guard lock(GetMutex()); _D("Proxy::~Proxy()"); if (main_port_.get() != nullptr) - DebugPort::RemoveSession(main_port_->GetFd()); + DebugPort::RemoveSession(main_port_->GetFd()); // LCOV_EXCL_LINE listener_ = nullptr; UnsetIdler(); @@ -131,23 +133,23 @@ int Proxy::Connect(bool sync) { // Main Port main_client_.reset(Client::Create(this, port_path)); if (main_client_.get() == nullptr) - return RPC_PORT_ERROR_IO_ERROR; + return RPC_PORT_ERROR_IO_ERROR; // LCOV_EXCL_LINE Request request(instance.c_str(), kPortTypeMain); int ret = SendRequest(main_client_.get(), request); if (ret != 0) - return RPC_PORT_ERROR_IO_ERROR; + return RPC_PORT_ERROR_IO_ERROR; // LCOV_EXCL_LINE if (sync) { Response* response = nullptr; ret = ReceiveResponse(main_client_.get(), &response); if (ret != 0) - return RPC_PORT_ERROR_IO_ERROR; + return RPC_PORT_ERROR_IO_ERROR; // LCOV_EXCL_LINE std::unique_ptr response_auto(response); if (response->GetResult() != 0) { - _E("Permission denied"); - return RPC_PORT_ERROR_PERMISSION_DENIED; + _E("Permission denied"); // LCOV_EXCL_LINE + return RPC_PORT_ERROR_PERMISSION_DENIED; // LCOV_EXCL_LINE } main_client_->SetNonblock(); @@ -155,29 +157,29 @@ int Proxy::Connect(bool sync) { } else { ret = main_client_->Watch(); if (ret != 0) - return RPC_PORT_ERROR_IO_ERROR; + return RPC_PORT_ERROR_IO_ERROR; // LCOV_EXCL_LINE } // Delegate Port delegate_client_.reset(Client::Create(this, port_path)); if (delegate_client_.get() == nullptr) - return RPC_PORT_ERROR_IO_ERROR; + return RPC_PORT_ERROR_IO_ERROR; // LCOV_EXCL_LINE request.SetPortType(kPortTypeDelegate); ret = SendRequest(delegate_client_.get(), request); if (ret != 0) - return RPC_PORT_ERROR_IO_ERROR; + return RPC_PORT_ERROR_IO_ERROR; // LCOV_EXCL_LINE if (sync) { Response* response = nullptr; ret = ReceiveResponse(delegate_client_.get(), &response); if (ret != 0) - return RPC_PORT_ERROR_IO_ERROR; + return RPC_PORT_ERROR_IO_ERROR; // LCOV_EXCL_LINE std::unique_ptr response_auto(response); if (response->GetResult() != 0) { - _E("Permission denied"); - return RPC_PORT_ERROR_PERMISSION_DENIED; + _E("Permission denied"); // LCOV_EXCL_LINE + return RPC_PORT_ERROR_PERMISSION_DENIED; // LCOV_EXCL_LINE } delegate_client_->SetNonblock(); @@ -185,7 +187,7 @@ int Proxy::Connect(bool sync) { } else { ret = delegate_client_->Watch(); if (ret != 0) - return RPC_PORT_ERROR_IO_ERROR; + return RPC_PORT_ERROR_IO_ERROR; // LCOV_EXCL_LINE } return RPC_PORT_ERROR_NONE; @@ -198,8 +200,8 @@ int Proxy::Connect(std::string appid, std::string port_name, std::lock_guard lock(GetMutex()); if (HasRequested()) { - _D("Already requested"); - return RPC_PORT_ERROR_INVALID_PARAMETER; + _D("Already requested"); // LCOV_EXCL_LINE + return RPC_PORT_ERROR_INVALID_PARAMETER; // LCOV_EXCL_LINE } listener_ = listener; @@ -220,8 +222,8 @@ int Proxy::Connect(std::string appid, std::string port_name, ret = Watch(); if (ret != 0) { - listener_ = nullptr; - return RPC_PORT_ERROR_IO_ERROR; + listener_ = nullptr; // LCOV_EXCL_LINE + return RPC_PORT_ERROR_IO_ERROR; // LCOV_EXCL_LINE } return RPC_PORT_ERROR_NONE; @@ -262,15 +264,17 @@ int Proxy::ConnectSync(std::string appid, std::string port_name, } while (retry_count > 0); if (!exist) { + // LCOV_EXCL_START _E("%s:%s is not ready", real_appid_.c_str(), port_name_.c_str()); listener_ = nullptr; return RPC_PORT_ERROR_IO_ERROR; + // LCOV_EXCL_STOP } ret = Connect(true); if (ret != RPC_PORT_ERROR_NONE) { - listener_ = nullptr; - return ret; + listener_ = nullptr; // LCOV_EXCL_LINE + return ret; // LCOV_EXCL_LINE } main_port_.reset(new ProxyPort(this, fds_[0], target_appid_, false)); @@ -294,8 +298,8 @@ int Proxy::Watch() { OnPortAppeared, OnPortVanished, this, rpc_port_get_target_uid(), &watch_handle_); if (ret != AUL_R_OK) { - _E("aul_rpc_port_usr_add_watch() is failed. error(%d)", ret); - return -1; + _E("aul_rpc_port_usr_add_watch() is failed. error(%d)", ret); // LCOV_EXCL_LINE + return -1; // LCOV_EXCL_LINE } port_exist_ = Aul::ExistPort(real_appid_, port_name_, @@ -326,9 +330,11 @@ void Proxy::SetRealAppId(const std::string& alias_appid) { return; } + // LCOV_EXCL_START std::unique_ptr appid_ptr(appid, std::free); real_appid_ = std::string(appid); _W("alias_appid(%s), real_appid(%s)", alias_appid.c_str(), appid); + // LCOV_EXCL_STOP } std::recursive_mutex& Proxy::GetMutex() const { @@ -337,14 +343,14 @@ std::recursive_mutex& Proxy::GetMutex() const { void Proxy::SetConnTimer() { if (conn_timer_data_) { - _W("Already exists"); - return; + _W("Already exists"); // LCOV_EXCL_START + return; // LCOV_EXCL_START } conn_timer_data_ = CreateWeakPtr(); if (conn_timer_data_ == nullptr) { - _E("Out of memory"); - return; + _E("Out of memory"); // LCOV_EXCL_START + return; // LCOV_EXCL_START } g_timeout_add_seconds(10, OnTimedOut, conn_timer_data_); @@ -365,14 +371,14 @@ void Proxy::UnsetConnTimer() { void Proxy::SetIdler() { if (idler_data_) { - _W("Already exists"); - return; + _W("Already exists"); // LCOV_EXCL_START + return; // LCOV_EXCL_START } idler_data_ = CreateWeakPtr(); if (idler_data_ == nullptr) { - _E("Out of memory"); - return; + _E("Out of memory"); // LCOV_EXCL_START + return; // LCOV_EXCL_START } g_idle_add(OnIdle, idler_data_); @@ -405,20 +411,22 @@ void Proxy::OnPortAppeared(const char* app_id, const char* port_name, int pid, auto* listener = proxy->listener_; if (listener == nullptr) { - _E("Invalid context"); - return; + _E("Invalid context"); // LCOV_EXCL_START + return; // LCOV_EXCL_START } proxy->Cancel(); int ret = proxy->Connect(false); if (ret != RPC_PORT_ERROR_NONE) { + // LCOV_EXCL_START proxy->UnsetConnTimer(); proxy->listener_ = nullptr; if (ret == RPC_PORT_ERROR_PERMISSION_DENIED) listener->OnRejected(proxy->target_appid_, ret); else listener->OnDisconnected(proxy->target_appid_); + // LCOV_EXCL_STOP } } @@ -435,14 +443,14 @@ gboolean Proxy::OnTimedOut(gpointer user_data) { auto* ptr = static_cast*>(user_data); auto proxy = ptr->lock(); if (proxy == nullptr) { - _E("Proxy is nullptr"); - return G_SOURCE_REMOVE; + _E("Proxy is nullptr"); // LCOV_EXCL_LINE + return G_SOURCE_REMOVE; // LCOV_EXCL_LINE } std::lock_guard lock(proxy->GetMutex()); if (proxy->conn_timer_data_ == nullptr) { - _E("Invalid context. proxy(%p)", proxy.get()); - return G_SOURCE_REMOVE; + _E("Invalid context. proxy(%p)", proxy.get()); // LCOV_EXCL_LINE + return G_SOURCE_REMOVE; // LCOV_EXCL_LINE } proxy->Cancel(); @@ -453,8 +461,8 @@ gboolean Proxy::OnTimedOut(gpointer user_data) { auto* listener = proxy->listener_; if (listener == nullptr) { - _E("Invalid context"); - return G_SOURCE_REMOVE; + _E("Invalid context"); // LCOV_EXCL_LINE + return G_SOURCE_REMOVE; // LCOV_EXCL_LINE } proxy->listener_ = nullptr; @@ -466,14 +474,14 @@ gboolean Proxy::OnIdle(gpointer user_data) { auto* ptr = static_cast*>(user_data); auto proxy = ptr->lock(); if (proxy == nullptr) { - _E("Proxy is nullptr"); - return G_SOURCE_REMOVE; + _E("Proxy is nullptr"); // LCOV_EXCL_LINE + return G_SOURCE_REMOVE; // LCOV_EXCL_LINE } std::lock_guard lock(proxy->GetMutex()); if (proxy->idler_data_ == nullptr) { - _E("Invalid context. proxy(%p)", proxy.get()); - return G_SOURCE_REMOVE; + _E("Invalid context. proxy(%p)", proxy.get()); // LCOV_EXCL_LINE + return G_SOURCE_REMOVE; // LCOV_EXCL_LINE } DestroyWeakPtr(proxy->idler_data_); @@ -510,16 +518,16 @@ Proxy::ProxyPort::~ProxyPort() { int Proxy::ProxyPort::Watch(bool receive) { channel_ = g_io_channel_unix_new(GetFd()); if (channel_ == nullptr) { - _E("g_io_channel_unix_new() is failed"); - return -1; + _E("g_io_channel_unix_new() is failed"); // LCOV_EXCL_LINE + return -1; // LCOV_EXCL_LINE } disconn_source_ = g_io_add_watch(channel_, static_cast(G_IO_ERR | G_IO_HUP | G_IO_NVAL), Proxy::ProxyPort::OnSocketDisconnected, parent_); if (disconn_source_ == 0) { - _E("g_io_add_watch() is failed"); - return -1; + _E("g_io_add_watch() is failed"); // LCOV_EXCL_LINE + return -1; // LCOV_EXCL_LINE } if (!receive) @@ -528,8 +536,8 @@ int Proxy::ProxyPort::Watch(bool receive) { source_ = g_io_add_watch(channel_, static_cast(G_IO_IN), Proxy::ProxyPort::OnDataReceived, parent_); if (source_ == 0) { - _E("g_io_add_watch() is failed"); - return -1; + _E("g_io_add_watch() is failed"); // LCOV_EXCL_LINE + return -1; // LCOV_EXCL_LINE } return 0; @@ -549,8 +557,8 @@ gboolean Proxy::ProxyPort::OnSocketDisconnected(GIOChannel* channel, std::lock_guard lock(proxy->GetMutex()); auto* listener = proxy->listener_; if (listener == nullptr) { - _E("Invalid context"); - return G_SOURCE_REMOVE; + _E("Invalid context"); // LCOV_EXCL_LINE + return G_SOURCE_REMOVE; // LCOV_EXCL_LINE } int fd = g_io_channel_unix_get_fd(channel); @@ -568,7 +576,7 @@ gboolean Proxy::ProxyPort::OnSocketDisconnected(GIOChannel* channel, proxy->listener_ = nullptr; listener->OnDisconnected(proxy->target_appid_); DebugPort::RemoveSession(fd); - return G_SOURCE_REMOVE;; + return G_SOURCE_REMOVE; } gboolean Proxy::ProxyPort::OnDataReceived(GIOChannel* channel, @@ -577,8 +585,8 @@ gboolean Proxy::ProxyPort::OnDataReceived(GIOChannel* channel, std::lock_guard lock(proxy->GetMutex()); auto* listener = proxy->listener_; if (listener == nullptr) { - _E("Invalid context"); - return G_SOURCE_REMOVE; + _E("Invalid context"); // LCOV_EXCL_LINE + return G_SOURCE_REMOVE; // LCOV_EXCL_LINE } int fd = g_io_channel_unix_get_fd(channel); @@ -623,8 +631,8 @@ Proxy::Client* Proxy::Client::Create(Proxy* parent, try { client.reset(new (std::nothrow) Proxy::Client(parent)); } catch (const Exception& e) { - _E("Exception(%s) occurs", e.what()); - return nullptr; + _E("Exception(%s) occurs", e.what()); // LCOV_EXCL_LINE + return nullptr; // LCOV_EXCL_LINE } int ret; @@ -634,22 +642,24 @@ Proxy::Client* Proxy::Client::Create(Proxy* parent, if (ret == 0) { break; } else if (ret < 0) { + // LCOV_EXCL_START _D("Connect() is failed"); usleep(100 * 1000); retry_count--; + // LCOV_EXCL_STOP } } while (retry_count > 0); if (ret != 0) { - _E("Connect() is failed"); - return nullptr; + _E("Connect() is failed"); // LCOV_EXCL_LINE + return nullptr; // LCOV_EXCL_LINE } try { client->SetReceiveTimeout(5000); } catch (const Exception& e) { - _E("Exception occurs. error(%s)", e.what()); - return nullptr; + _E("Exception occurs. error(%s)", e.what()); // LCOV_EXCL_LINE + return nullptr; // LCOV_EXCL_LINE } _W("endpoint(%s), fd(%d)", endpoint.c_str(), client->GetFd()); @@ -659,36 +669,39 @@ Proxy::Client* Proxy::Client::Create(Proxy* parent, int Proxy::Client::Watch() { channel_ = g_io_channel_unix_new(GetFd()); if (channel_ == nullptr) { - _E("g_io_channel_unix_new() is failed"); - return -1; + _E("g_io_channel_unix_new() is failed"); // LCOV_EXCL_LINE + return -1; // LCOV_EXCL_LINE } source_ = g_io_add_watch(channel_, static_cast(G_IO_IN), Proxy::Client::OnResponseReceived, parent_); if (source_ == 0) { - _E("g_io_add_watch() is failed"); - return -1; + _E("g_io_add_watch() is failed"); // LCOV_EXCL_LINE + return -1; // LCOV_EXCL_LINE } disconn_source_ = g_io_add_watch(channel_, static_cast(G_IO_ERR | G_IO_HUP | G_IO_NVAL), Proxy::Client::OnSocketDisconnected, parent_); if (disconn_source_ == 0) { - _E("g_io_add_watch() is failed"); - return -1; + _E("g_io_add_watch() is failed"); // LCOV_EXCL_LINE + return -1; // LCOV_EXCL_LINE } return 0; } +// LCOV_EXCL_START void Proxy::Client::SetDisconnectedSource(guint source) { disconn_source_ = source; } +// LCOV_EXCL_STOP void Proxy::Client::SetSource(guint source) { source_ = source; } +// LCOV_EXCL_START gboolean Proxy::Client::OnSocketDisconnected(GIOChannel* channel, GIOCondition cond, gpointer user_data) { auto* proxy = static_cast(user_data); @@ -716,6 +729,7 @@ gboolean Proxy::Client::OnSocketDisconnected(GIOChannel* channel, listener->OnDisconnected(proxy->target_appid_); return G_SOURCE_REMOVE; } +// LCOV_EXCL_STOP gboolean Proxy::Client::OnResponseReceived(GIOChannel* channel, GIOCondition cond, gpointer user_data) { @@ -724,8 +738,8 @@ gboolean Proxy::Client::OnResponseReceived(GIOChannel* channel, proxy->UnsetConnTimer(); auto* listener = proxy->listener_; if (listener == nullptr) { - _E("Invalid context"); - return G_SOURCE_REMOVE; + _E("Invalid context"); // LCOV_EXCL_LINE + return G_SOURCE_REMOVE; // LCOV_EXCL_LINE } bool is_delegate = false; @@ -741,8 +755,8 @@ gboolean Proxy::Client::OnResponseReceived(GIOChannel* channel, } if (client.get() == nullptr) { - _E("Unknown fd(%d)", fd); - return G_SOURCE_REMOVE; + _E("Unknown fd(%d)", fd); // LCOV_EXCL_LINE + return G_SOURCE_REMOVE; // LCOV_EXCL_LINE } client->SetSource(0); @@ -750,11 +764,13 @@ gboolean Proxy::Client::OnResponseReceived(GIOChannel* channel, Response* response = nullptr; int ret = ReceiveResponse(client.get(), &response); if (ret != 0) { + // LCOV_EXCL_START proxy->listener_ = nullptr; proxy->main_client_.reset(); proxy->delegate_client_.reset(); listener->OnRejected(proxy->target_appid_, RPC_PORT_ERROR_IO_ERROR); return G_SOURCE_REMOVE; + // LCOV_EXCL_STOP } std::unique_ptr response_auto(response); diff --git a/src/rpc-port-internal.cc b/src/rpc-port-internal.cc index 1a8c0b1..ba78616 100644 --- a/src/rpc-port-internal.cc +++ b/src/rpc-port-internal.cc @@ -39,6 +39,7 @@ std::atomic __target_uid { getuid() }; RPC_API void rpc_port_set_target_uid(uid_t target_uid) { __target_uid.exchange(target_uid); + set_last_result(RPC_PORT_ERROR_NONE); } RPC_API uid_t rpc_port_get_target_uid(void) { diff --git a/src/rpc-port-parcel.cc b/src/rpc-port-parcel.cc index e665b5e..e78b6da 100644 --- a/src/rpc-port-parcel.cc +++ b/src/rpc-port-parcel.cc @@ -14,13 +14,14 @@ * limitations under the License. */ +#include "include/rpc-port-parcel.h" + #include #include #include #include -#include "include/rpc-port-parcel.h" #include "log-private.hh" #include "parcel-internal.hh" #include "port-internal.hh" @@ -64,22 +65,24 @@ RPC_API int rpc_port_parcel_create_from_port(rpc_port_parcel_h* h, buf = static_cast(malloc(len)); if (buf == nullptr) { - _E("Out of memory"); - return RPC_PORT_ERROR_IO_ERROR; + _E("Out of memory"); // LCOV_EXCL_LINE + return RPC_PORT_ERROR_IO_ERROR; // LCOV_EXCL_LINE } ret = rpc_port_read(port, buf, len); if (ret != 0) { - free(buf); - return ret; + free(buf); // LCOV_EXCL_LINE + return ret; // LCOV_EXCL_LINE } } auto* parcel = new (std::nothrow) internal::Parcel(); if (parcel == nullptr) { + // LCOV_EXCL_START _E("Out of memory"); free(buf); return RPC_PORT_ERROR_IO_ERROR; + // LCOV_EXCL_STOP } tizen_base::Parcel raw_parcel(buf, len, false); @@ -238,7 +241,7 @@ RPC_API int rpc_port_parcel_read_byte(rpc_port_parcel_h h, char* b) { auto* parcel = static_cast(h); int ret = parcel_read_byte(parcel->GetHandle(), b); if (ret != PARCEL_ERROR_NONE) - _E("parcel_read_byte() is failed. error(%d)", ret); + _E("parcel_read_byte() is failed. error(%d)", ret); // LCOV_EXCL_LINE return RPC_PORT_ERROR_NONE; } @@ -250,7 +253,7 @@ RPC_API int rpc_port_parcel_read_int16(rpc_port_parcel_h h, short* i) { auto* parcel = static_cast(h); int ret = parcel_read_int16(parcel->GetHandle(), i); if (ret != PARCEL_ERROR_NONE) - _E("parcel_read_int16() is failed. error(%d)", ret); + _E("parcel_read_int16() is failed. error(%d)", ret); // LCOV_EXCL_LINE return RPC_PORT_ERROR_NONE; } @@ -262,7 +265,7 @@ RPC_API int rpc_port_parcel_read_int32(rpc_port_parcel_h h, int* i) { auto* parcel = static_cast(h); int ret = parcel_read_int32(parcel->GetHandle(), i); if (ret != PARCEL_ERROR_NONE) - _E("parcel_read_int32() is failed. error(%d)", ret); + _E("parcel_read_int32() is failed. error(%d)", ret); // LCOV_EXCL_LINE return RPC_PORT_ERROR_NONE; } @@ -275,7 +278,7 @@ RPC_API int rpc_port_parcel_read_int64(rpc_port_parcel_h h, long long* i) { int64_t val = 0; int ret = parcel_read_int64(parcel->GetHandle(), &val); if (ret != PARCEL_ERROR_NONE) - _E("parcel_read_int64() is failed. error(%d)", ret); + _E("parcel_read_int64() is failed. error(%d)", ret); // LCOV_EXCL_LINE *i = static_cast(val); return RPC_PORT_ERROR_NONE; @@ -288,7 +291,7 @@ RPC_API int rpc_port_parcel_read_float(rpc_port_parcel_h h, float* f) { auto* parcel = static_cast(h); int ret = parcel_read_float(parcel->GetHandle(), f); if (ret != PARCEL_ERROR_NONE) - _E("parcel_read_float() is failed. error(%d)", ret); + _E("parcel_read_float() is failed. error(%d)", ret); // LCOV_EXCL_LINE return RPC_PORT_ERROR_NONE; } @@ -300,7 +303,7 @@ RPC_API int rpc_port_parcel_read_double(rpc_port_parcel_h h, double* d) { auto* parcel = static_cast(h); int ret = parcel_read_double(parcel->GetHandle(), d); if (ret != PARCEL_ERROR_NONE) - _E("parcel_read_double() is failed. error(%d)", ret); + _E("parcel_read_double() is failed. error(%d)", ret); // LCOV_EXCL_LINE return RPC_PORT_ERROR_NONE; } @@ -312,8 +315,8 @@ RPC_API int rpc_port_parcel_read_string(rpc_port_parcel_h h, char** str) { auto* parcel = static_cast(h); int ret = parcel_read_string(parcel->GetHandle(), str); if (ret != PARCEL_ERROR_NONE) { - _E("parcel_read_string() is failed. error(%d)", ret); - *str = strdup(""); + _E("parcel_read_string() is failed. error(%d)", ret); // LCOV_EXCL_LINE + *str = strdup(""); // LCOV_EXCL_LINE } return RPC_PORT_ERROR_NONE; @@ -326,7 +329,7 @@ RPC_API int rpc_port_parcel_read_bool(rpc_port_parcel_h h, bool* b) { auto* parcel = static_cast(h); int ret = parcel_read_bool(parcel->GetHandle(), b); if (ret != 0) - _E("parcel_read_bool() is failed. error(%d)", ret); + _E("parcel_read_bool() is failed. error(%d)", ret); // LCOV_EXCL_LINE return RPC_PORT_ERROR_NONE; } @@ -339,8 +342,8 @@ RPC_API int rpc_port_parcel_read_bundle(rpc_port_parcel_h h, bundle** b) { char* raw = nullptr; int ret = parcel_read_string(parcel->GetHandle(), &raw); if (ret != 0) { - _E("parcel_read_string() is failed. error(%d)", ret); - *b = bundle_create(); + _E("parcel_read_string() is failed. error(%d)", ret); // LCOV_EXCL_LINE + *b = bundle_create(); // LCOV_EXCL_LINE } else { *b = bundle_decode(reinterpret_cast(raw), strlen(raw)); std::free(raw); @@ -356,7 +359,7 @@ RPC_API int rpc_port_parcel_read_array_count(rpc_port_parcel_h h, int* count) { auto* parcel = static_cast(h); int ret = parcel_read_int32(parcel->GetHandle(), count); if (ret != 0) - _E("parcel_read_int32() is failed. error(%d)", ret); + _E("parcel_read_int32() is failed. error(%d)", ret); // LCOV_EXCL_LINE return RPC_PORT_ERROR_NONE; } @@ -383,7 +386,7 @@ RPC_API int rpc_port_parcel_burst_read(rpc_port_parcel_h h, unsigned char *buf, int ret = parcel_burst_read(parcel->GetHandle(), static_cast(buf), valid_size); if (ret != PARCEL_ERROR_NONE) - _E("parcel_read() is failed. error(%d)", ret); + _E("parcel_read() is failed. error(%d)", ret); // LCOV_EXCL_LINE return RPC_PORT_ERROR_NONE; } @@ -481,7 +484,7 @@ RPC_API int rpc_port_parcel_header_get_tag(rpc_port_parcel_header_h header, *tag = strdup(raw_tag.c_str()); if (*tag == nullptr) - return RPC_PORT_ERROR_OUT_OF_MEMORY; + return RPC_PORT_ERROR_OUT_OF_MEMORY; // LCOV_EXCL_LINE return RPC_PORT_ERROR_NONE; } @@ -529,9 +532,11 @@ RPC_API int rpc_port_parcel_get_raw(rpc_port_parcel_h h, void** raw, *raw = raw_parcel->GetData(); *size = static_cast(raw_parcel->GetDataSize()); } else { + // LCOV_EXCL_START _E("Out of memory"); *raw = nullptr; *size = 0; + // LCOV_EXCL_STOP } return RPC_PORT_ERROR_NONE; @@ -549,8 +554,8 @@ RPC_API int rpc_port_parcel_create_from_raw(rpc_port_parcel_h* h, ret = rpc_port_parcel_from_array(parcel, raw, size); if (ret != RPC_PORT_ERROR_NONE) { - rpc_port_parcel_destroy(parcel); - return ret; + rpc_port_parcel_destroy(parcel); // LCOV_EXCL_LINE + return ret; // LCOV_EXCL_LINE } *h = parcel; diff --git a/src/rpc-port.cc b/src/rpc-port.cc index 1a09c2c..b9d04cd 100644 --- a/src/rpc-port.cc +++ b/src/rpc-port.cc @@ -276,11 +276,13 @@ RPC_API int rpc_port_proxy_create(rpc_port_proxy_h* h) { auto p = new (std::nothrow) std::shared_ptr<::ProxyExt>( new (std::nothrow) ::ProxyExt()); if (p == nullptr) { - _E("Out of memory"); + _E("Out of memory"); // LCOV_EXCL_LINE } else if (p->get() == nullptr) { + // LCOV_EXCL_START _E("Out of memory"); delete p; p = nullptr; + // LCOV_EXCL_STOP } else { _W("rpc_port_proxy_create(%p)", p->get()); } @@ -296,8 +298,8 @@ RPC_API int rpc_port_proxy_destroy(rpc_port_proxy_h h) { auto p = static_cast*>(h); auto* proxy = p->get(); if (proxy->IsDestroying()) { - _E("already destroyed. handle(%p)", proxy); - abort(); + _E("already destroyed. handle(%p)", proxy); // LCOV_EXCL_LINE + abort(); // LCOV_EXCL_LINE } _W("rpc_port_proxy_destroy(%p)", proxy); @@ -433,8 +435,8 @@ RPC_API int rpc_port_stub_destroy(rpc_port_stub_h h) { _W("rpc_port_stub_destroy(%p)", h); auto p = static_cast<::StubExt*>(h); if (p->IsDestroying()) { - _E("already destroyed. handle(%p)", h); - abort(); + _E("already destroyed. handle(%p)", h); // LCOV_EXCL_LINE + abort(); // LCOV_EXCL_LINE } p->SetDestroying(true); @@ -462,8 +464,8 @@ RPC_API int rpc_port_stub_listen(rpc_port_stub_h h) { int ret = aul_rpc_port_usr_create(p->GetPortName().c_str(), rpc_port_get_target_uid(), &fd); if (ret != AUL_R_OK) { - _E("aul_rpc_port_usr_create() is failed. error(%d)", ret); - return RPC_PORT_ERROR_IO_ERROR; + _E("aul_rpc_port_usr_create() is failed. error(%d)", ret); // LCOV_EXCL_LINE + return RPC_PORT_ERROR_IO_ERROR; // LCOV_EXCL_LINE } return p->Listen(p, fd); diff --git a/src/server-socket-internal.cc b/src/server-socket-internal.cc index 4f60c20..d117faa 100644 --- a/src/server-socket-internal.cc +++ b/src/server-socket-internal.cc @@ -46,8 +46,8 @@ ClientSocket* ServerSocket::Accept() { auto* addr_ptr = reinterpret_cast(&addr); int client_fd = accept(GetFd(), addr_ptr, &len); if (client_fd == -1) { - _E("accept() is failed. errno(%d)", errno); - return nullptr; + _E("accept() is failed. errno(%d)", errno); // LCOV_EXCL_LINE + return nullptr; // LCOV_EXCL_LINE } return new (std::nothrow) ClientSocket(client_fd); @@ -57,6 +57,7 @@ int ServerSocket::GetFd() const { return fd_; } +// LCOV_EXCL_START int ServerSocket::Listen(int backlog) { int ret = listen(GetFd(), backlog); if (ret < 0) { @@ -66,6 +67,7 @@ int ServerSocket::Listen(int backlog) { return 0; } +// LCOV_EXCL_STOP void ServerSocket::Close() { if (fd_ > -1) { diff --git a/src/stub-internal.cc b/src/stub-internal.cc index b0bc883..0abc27d 100644 --- a/src/stub-internal.cc +++ b/src/stub-internal.cc @@ -44,22 +44,22 @@ int ReceiveRequest(ClientSocket* client, Request** request) { size_t size = 0; int ret = client->Receive(reinterpret_cast(&size), sizeof(size)); if (ret != 0) { - _E("Receive() is failed. error(%d)", ret); - return -1; + _E("Receive() is failed. error(%d)", ret); // LCOV_EXCL_LINE + return -1; // LCOV_EXCL_LINE } std::vector buf(size); ret = client->Receive(buf.data(), size); if (ret != 0) { - _E("Receive() is failed. error(%d)", ret); - return -1; + _E("Receive() is failed. error(%d)", ret); // LCOV_EXCL_LINE + return -1; // LCOV_EXCL_LINE } tizen_base::Parcel parcel(buf.data(), buf.size()); *request = new (std::nothrow) Request(); if (*request == nullptr) { - _E("Out of memory"); - return -1; + _E("Out of memory"); // LCOV_EXCL_LINE + return -1; // LCOV_EXCL_LINE } parcel.ReadParcelable(*request); @@ -72,14 +72,14 @@ int SendResponse(ClientSocket* client, const Response& response) { size_t size = parcel.GetDataSize(); int ret = client->Send(reinterpret_cast(&size), sizeof(size)); if (ret != 0) { - _E("Send() is failed. error(%d)", ret); - return -1; + _E("Send() is failed. error(%d)", ret); // LCOV_EXCL_LINE + return -1; // LCOV_EXCL_LINE } ret = client->Send(parcel.GetData(), size); if (ret != 0) { - _E("Send() is failed. error(%d)", ret); - return -1; + _E("Send() is failed. error(%d)", ret); // LCOV_EXCL_LINE + return -1; // LCOV_EXCL_LINE } return 0; @@ -112,8 +112,8 @@ int Stub::Listen(IEventListener* ev, int fd) { return RPC_PORT_ERROR_INVALID_PARAMETER; if (listener_ != nullptr) { - _E("Already listening!"); - return RPC_PORT_ERROR_INVALID_PARAMETER; + _E("Already listening!"); // LCOV_EXCL_LINE + return RPC_PORT_ERROR_INVALID_PARAMETER; // LCOV_EXCL_LINE } std::lock_guard lock(GetMutex()); @@ -137,6 +137,7 @@ void Stub::SetTrusted(const bool trusted) { access_controller_->SetTrusted(trusted); } +// LCOV_EXCL_START std::shared_ptr Stub::FindPort(const std::string& instance) const { std::lock_guard lock(GetMutex()); for (auto& p : ports_) { @@ -147,6 +148,7 @@ std::shared_ptr Stub::FindPort(const std::string& instance) const { return {}; } +// LCOV_EXCL_STOP std::shared_ptr Stub::FindDelegatePort( const std::string& instance) const { @@ -184,8 +186,8 @@ gboolean Stub::AcceptedPort::OnDataReceived(GIOChannel* channel, std::lock_guard lock(stub->GetMutex()); auto* listener = stub->listener_; if (listener == nullptr) { - _E("Invalid context"); - return G_SOURCE_REMOVE; + _E("Invalid context"); // LCOV_EXCL_LINE + return G_SOURCE_REMOVE; // LCOV_EXCL_LINE } int fd = g_io_channel_unix_get_fd(channel); @@ -223,8 +225,8 @@ gboolean Stub::AcceptedPort::OnSocketDisconnected(GIOChannel* channel, std::lock_guard lock(stub->GetMutex()); auto* listener = stub->listener_; if (listener == nullptr) { - _E("Invalid context"); - return G_SOURCE_REMOVE; + _E("Invalid context"); // LCOV_EXCL_LINE + return G_SOURCE_REMOVE; // LCOV_EXCL_LINE } int fd = g_io_channel_unix_get_fd(channel); @@ -282,12 +284,14 @@ Stub::AcceptedPort::AcceptedPort(Stub* parent, bool isDelegate, int fd, Watch(watch); } +// LCOV_EXCL_START Stub::AcceptedPort::AcceptedPort(Stub* parent, bool isDelegate, int fd, std::string id, bool watch) : Port(fd, std::move(id)), parent_(parent), is_delegate_(isDelegate) { Watch(watch); } +// LCOV_EXCL_STOP Stub::AcceptedPort::~AcceptedPort() { if (disconn_source_ > 0) @@ -303,16 +307,16 @@ Stub::AcceptedPort::~AcceptedPort() { int Stub::AcceptedPort::Watch(bool receive) { channel_ = g_io_channel_unix_new(GetFd()); if (channel_ == nullptr) { - _E("g_io_channel_unix_new() is failed"); - return -1; + _E("g_io_channel_unix_new() is failed"); // LCOV_EXCL_LINE + return -1; // LCOV_EXCL_LINE } disconn_source_ = g_io_add_watch(channel_, static_cast(G_IO_ERR | G_IO_HUP | G_IO_NVAL), OnSocketDisconnected, parent_); if (disconn_source_ == 0) { - _E("g_io_add_watch() is failed"); - return -1; + _E("g_io_add_watch() is failed"); // LCOV_EXCL_LINE + return -1; // LCOV_EXCL_LINE } if (!receive) @@ -321,8 +325,8 @@ int Stub::AcceptedPort::Watch(bool receive) { source_ = g_io_add_watch(channel_, static_cast(G_IO_IN), OnDataReceived, parent_); if (source_ == 0) { - _E("g_io_add_watch() is failed"); - return -1; + _E("g_io_add_watch() is failed"); // LCOV_EXCL_LINE + return -1; // LCOV_EXCL_LINE } return 0; @@ -344,15 +348,15 @@ Stub::Server::~Server() { int Stub::Server::Listen() { channel_ = g_io_channel_unix_new(GetFd()); if (channel_ == nullptr) { - _E("g_io_channel_unix_new() is failed"); - return -1; + _E("g_io_channel_unix_new() is failed"); // LCOV_EXCL_LINE + return -1; // LCOV_EXCL_LINE } source_ = g_io_add_watch(channel_, static_cast(G_IO_IN), OnRequestReceived, parent_); if (source_ == 0) { - _E("g_io_add_watch() is failed"); - return -1; + _E("g_io_add_watch() is failed"); // LCOV_EXCL_LINE + return -1; // LCOV_EXCL_LINE } return 0; @@ -363,41 +367,41 @@ gboolean Stub::Server::OnRequestReceived(GIOChannel* channel, GIOCondition cond, auto* stub = static_cast(user_data); std::lock_guard lock(stub->GetMutex()); if (stub->listener_ == nullptr) { - _E("Invalid context"); - return G_SOURCE_REMOVE; + _E("Invalid context"); // LCOV_EXCL_LINE + return G_SOURCE_REMOVE; // LCOV_EXCL_LINE } std::shared_ptr client(stub->server_->Accept()); if (client.get() == nullptr) { - _E("Out of memory"); - return G_SOURCE_CONTINUE; + _E("Out of memory"); // LCOV_EXCL_LINE + return G_SOURCE_CONTINUE; // LCOV_EXCL_LINE } Request* request = nullptr; int ret = ReceiveRequest(client.get(), &request); if (ret != 0) - return G_SOURCE_CONTINUE; + return G_SOURCE_CONTINUE; // LCOV_EXCL_LINE std::shared_ptr request_auto(request); std::shared_ptr cred(PeerCred::Get(client->GetFd())); if (cred.get() == nullptr) { - _E("Failed to create peer credentials"); - return G_SOURCE_CONTINUE; + _E("Failed to create peer credentials"); // LCOV_EXCL_LINE + return G_SOURCE_CONTINUE; // LCOV_EXCL_LINE } std::string app_id = Aul::GetAppId(cred->GetPid()); auto response_func = [=](int res) -> void { if (freed_stubs_.find(stub) != freed_stubs_.end()) - return; + return; // LCOV_EXCL_LINE Response response(res); int ret = SendResponse(client.get(), response); if (ret != 0) - return; + return; // LCOV_EXCL_LINE if (res != 0) { - _E("Access denied. fd(%d), pid(%d)", client->GetFd(), cred->GetPid()); - return; + _E("Access denied. fd(%d), pid(%d)", client->GetFd(), cred->GetPid()); // LCOV_EXCL_LINE + return; // LCOV_EXCL_LINE } client->SetNonblock(); @@ -409,8 +413,8 @@ gboolean Stub::Server::OnRequestReceived(GIOChannel* channel, GIOCondition cond, int res; if (cred->GetUid() >= kRegularUidMin) { if (cred->GetUid() != getuid() && getuid() >= kRegularUidMin) { - _E("Reject request. %u:%u", cred->GetUid(), getuid()); - res = -1; + _E("Reject request. %u:%u", cred->GetUid(), getuid()); // LCOV_EXCL_LINE + res = -1; // LCOV_EXCL_LINE } else { stub->access_controller_->CheckAsync(client->GetFd(), app_id, response_func); diff --git a/test/unit_tests/mock/aul_mock.cc b/test/unit_tests/mock/aul_mock.cc index 2fce77b..f32043c 100644 --- a/test/unit_tests/mock/aul_mock.cc +++ b/test/unit_tests/mock/aul_mock.cc @@ -80,3 +80,11 @@ extern "C" int aul_rpc_port_usr_create(const char* port_name, uid_t uid, extern "C" int aul_rpc_port_usr_destroy(const char* port_name, uid_t uid) { return MOCK_HOOK_P2(AulMock, aul_rpc_port_usr_destroy, port_name, uid); } + +extern "C" int aul_proc_register(const char* proc_name, bundle* extra) { + return MOCK_HOOK_P2(AulMock, aul_proc_register, proc_name, extra); +} + +extern "C" int aul_proc_deregister() { + return MOCK_HOOK_P0(AulMock, aul_proc_deregister); +} diff --git a/test/unit_tests/mock/aul_mock.hh b/test/unit_tests/mock/aul_mock.hh index 33a26b4..fcf40ca 100644 --- a/test/unit_tests/mock/aul_mock.hh +++ b/test/unit_tests/mock/aul_mock.hh @@ -30,31 +30,27 @@ class AulMock : public virtual ModuleMock { public: virtual ~AulMock() {} - MOCK_METHOD3(aul_app_get_appid_bypid, - int (int, char*, int)); + MOCK_METHOD3(aul_app_get_appid_bypid, int(int, char*, int)); MOCK_METHOD4(aul_rpc_port_usr_get_path, - int (const char*, const char*, uid_t, char**)); + int(const char*, const char*, uid_t, char**)); MOCK_METHOD3(aul_rpc_port_usr_prepare_stub, - int (const char*, const char*, uid_t)); + int(const char*, const char*, uid_t)); MOCK_METHOD4(aul_rpc_port_usr_exist, - int (const char*, const char*, uid_t, bool*)); - MOCK_METHOD0(aul_rpc_port_notify_rpc_finished, - int ()); + int(const char*, const char*, uid_t, bool*)); + MOCK_METHOD0(aul_rpc_port_notify_rpc_finished, int()); MOCK_METHOD3(aul_rpc_port_set_private_sharing, - int (const char*, const char**, unsigned int)); - MOCK_METHOD1(aul_rpc_port_unset_private_sharing, - int (const char*)); + int(const char*, const char**, unsigned int)); + MOCK_METHOD1(aul_rpc_port_unset_private_sharing, int(const char*)); MOCK_METHOD7(aul_rpc_port_usr_add_watch, - int (const char*, const char*, aul_rpc_port_appeared_cb, - aul_rpc_port_vanished_cb, void*, uid_t, aul_rpc_port_watch_h*)); - MOCK_METHOD1(aul_rpc_port_remove_watch, - int (aul_rpc_port_watch_h)); - MOCK_METHOD2(aul_svc_get_appid_by_alias_appid, - int (const char*, char**)); - MOCK_METHOD3(aul_rpc_port_usr_create, - int (const char*, uid_t, int*)); - MOCK_METHOD2(aul_rpc_port_usr_destroy, - int (const char*, uid_t)); + int(const char*, const char*, aul_rpc_port_appeared_cb, + aul_rpc_port_vanished_cb, void*, uid_t, + aul_rpc_port_watch_h*)); + MOCK_METHOD1(aul_rpc_port_remove_watch, int(aul_rpc_port_watch_h)); + MOCK_METHOD2(aul_svc_get_appid_by_alias_appid, int(const char*, char**)); + MOCK_METHOD3(aul_rpc_port_usr_create, int(const char*, uid_t, int*)); + MOCK_METHOD2(aul_rpc_port_usr_destroy, int(const char*, uid_t)); + MOCK_METHOD2(aul_proc_register, int(const char*, bundle*)); + MOCK_METHOD0(aul_proc_deregister, int()); }; #endif // UNIT_TESTS_MOCK_AUL_MOCK_HH_ diff --git a/test/unit_tests/rpc_port_parcel_test.cc b/test/unit_tests/rpc_port_parcel_test.cc index 07de128..0d09583 100644 --- a/test/unit_tests/rpc_port_parcel_test.cc +++ b/test/unit_tests/rpc_port_parcel_test.cc @@ -22,6 +22,7 @@ #include #include "rpc-port-parcel.h" +#include "rpc-port-parcel-internal.h" using ::testing::AtLeast; @@ -101,11 +102,6 @@ class ParcelTest : public ::testing::Test { bool touch_to_ = false; }; -/* - * @testcase rpc_port_parcel_create_destroy_P - * @description Creates and destroys the rpc-port parcel handle - * @apicovered rpc_port_parcel_create, rpc_port_parcel_destroy - */ TEST(rpc_port_parcel, rpc_port_parcel_create_destroy_P) { rpc_port_parcel_h handle; @@ -118,11 +114,6 @@ TEST(rpc_port_parcel, rpc_port_parcel_create_destroy_P) { ASSERT_EQ(ret, 0); } -/* - * @testcase rpc_port_parcel_read_write_byte_P - * @description Writes and reads the byte data to the rpc-port parcel handle - * @apicovered rpc_port_parcel_write_byte, rpc_port_parcel_read_byte - */ TEST_F(ParcelTest, rpc_port_parcel_write_read_byte_P) { int ret = rpc_port_parcel_write_byte(handle_, 'k'); ASSERT_EQ(ret, 0); @@ -133,11 +124,6 @@ TEST_F(ParcelTest, rpc_port_parcel_write_read_byte_P) { ASSERT_EQ(b, 'k'); } -/* - * @testcase rpc_port_parcel_read_write_int16_P - * @description Writes and reads the int16 data to the rpc-port parcel handle - * @apicovered rpc_port_parcel_write_int16, rpc_port_parcel_read_int16 - */ TEST_F(ParcelTest, rpc_port_parcel_read_write_in16_P) { int ret = rpc_port_parcel_write_int16(handle_, 123); ASSERT_EQ(ret, 0); @@ -148,11 +134,6 @@ TEST_F(ParcelTest, rpc_port_parcel_read_write_in16_P) { ASSERT_EQ(b, 123); } -/* - * @testcase rpc_port_parcel_read_write_int32_P - * @description Writes and reads the int32 data to the rpc-port parcel handle - * @apicovered rpc_port_parcel_write_int32, rpc_port_parcel_read_int32 - */ TEST_F(ParcelTest, rpc_port_parcel_read_write_int32_P) { int ret = rpc_port_parcel_write_int32(handle_, 123456); ASSERT_EQ(ret, 0); @@ -163,11 +144,6 @@ TEST_F(ParcelTest, rpc_port_parcel_read_write_int32_P) { ASSERT_EQ(b, 123456); } -/* - * @testcase rpc_port_parcel_read_write_int64_P - * @description Writes and reads the int64 data to the rpc-port parcel handle - * @apicovered rpc_port_parcel_write_int64, rpc_port_parcel_read_int64 - */ TEST_F(ParcelTest, rpc_port_parcel_read_write_int64_P) { int ret = rpc_port_parcel_write_int64(handle_, 12345678); ASSERT_EQ(ret, 0); @@ -178,11 +154,6 @@ TEST_F(ParcelTest, rpc_port_parcel_read_write_int64_P) { ASSERT_EQ(b, 12345678); } -/* - * @testcase rpc_port_parcel_read_write_float_P - * @description Writes and reads the float data to the rpc-port parcel handle - * @apicovered rpc_port_parcel_write_float, rpc_port_parcel_read_float - */ TEST_F(ParcelTest, rpc_port_parcel_read_write_float_P) { int ret = rpc_port_parcel_write_float(handle_, 123.456f); ASSERT_EQ(ret, 0); @@ -193,11 +164,6 @@ TEST_F(ParcelTest, rpc_port_parcel_read_write_float_P) { ASSERT_EQ(b, 123.456f); } -/* - * @testcase rpc_port_parcel_read_write_double_P - * @description Writes and reads the double data to the rpc-port parcel handle - * @apicovered rpc_port_parcel_write_double, rpc_port_parcel_read_double - */ TEST_F(ParcelTest, rpc_port_parcel_read_write_double_P) { int ret = rpc_port_parcel_write_double(handle_, 123.456f); ASSERT_EQ(ret, 0); @@ -208,11 +174,6 @@ TEST_F(ParcelTest, rpc_port_parcel_read_write_double_P) { ASSERT_EQ(b, 123.456f); } -/* - * @testcase rpc_port_parcel_read_write_string_P - * @description Writes and reads the string data to the rpc-port parcel handle - * @apicovered rpc_port_parcel_write_string, rpc_port_parcel_read_string - */ TEST_F(ParcelTest, rpc_port_parcel_read_write_string_P) { const char str[] = "abcdef"; int ret = rpc_port_parcel_write_string(handle_, str); @@ -225,11 +186,6 @@ TEST_F(ParcelTest, rpc_port_parcel_read_write_string_P) { ASSERT_STREQ(s1.Get(), str); } -/* - * @testcase rpc_port_parcel_read_write_bool_P - * @description Writes and reads the boolean data to the rpc-port parcel handle - * @apicovered rpc_port_parcel_write_bool, rpc_port_parcel_read_bool - */ TEST_F(ParcelTest, rpc_port_parcel_read_write_bool_P) { int ret = rpc_port_parcel_write_bool(handle_, true); ASSERT_EQ(ret, 0); @@ -240,11 +196,6 @@ TEST_F(ParcelTest, rpc_port_parcel_read_write_bool_P) { ASSERT_TRUE(b); } -/* - * @testcase rpc_port_parcel_read_write_bundle_P - * @description Writes and reads the bundle data to the rpc-port parcel handle - * @apicovered rpc_port_parcel_write_bundle, rpc_port_parcel_read_bundle - */ TEST_F(ParcelTest, rpc_port_parcel_read_write_bundle_P) { bundle* b = bundle_create(); ASSERT_NE(b, nullptr); @@ -268,11 +219,6 @@ TEST_F(ParcelTest, rpc_port_parcel_read_write_bundle_P) { ASSERT_STREQ("Value", str); } -/* - * @testcase rpc_port_parcel_read_write_array_count_P - * @description Writes and reads the array count data to the rpc-port parcel handle - * @apicovered rpc_port_parcel_write_array_count, rpc_port_parcel_read_array_count - */ TEST_F(ParcelTest, rpc_port_parcle_read_write_array_count_P) { int ret = rpc_port_parcel_write_array_count(handle_, 123); ASSERT_EQ(ret, 0); @@ -283,11 +229,6 @@ TEST_F(ParcelTest, rpc_port_parcle_read_write_array_count_P) { ASSERT_EQ(c, 123); } -/* - * @testcase rpc_port_parcel_read_write_P - * @description Writes and reads the data to the rpc-port parcel handle - * @apicovered rpc_port_parcel_write, rpc_port_parcel_read - */ TEST_F(ParcelTest, rpc_port_parcel_read_write_P) { rpc_port_parcelable_t p = { .to = WriteParcelable, @@ -303,11 +244,6 @@ TEST_F(ParcelTest, rpc_port_parcel_read_write_P) { ASSERT_TRUE(touch_from_); } -/* - * @testcase rpc_port_parcel_burst_read_write_P - * @description Writes and reads the data by burst mode to the rpc-port parcel handle - * @apicovered rpc_port_parcel_burst_write, rpc_port_parcel_burst_read - */ TEST_F(ParcelTest, rpc_port_parcel_burst_read_write_P) { unsigned char buf[] = { 0, 1, 2, 3, 4 }; int ret = rpc_port_parcel_burst_write(handle_, buf, sizeof(buf)); @@ -321,11 +257,6 @@ TEST_F(ParcelTest, rpc_port_parcel_burst_read_write_P) { } } -/* - * @testcase rpc_port_parcel_get_header_P - * @description Gets the header handle from the rpc port parcel handle - * @apicovered rpc_port_parcel_get_header - */ TEST_F(ParcelTest, rpc_port_parcel_get_header_P) { rpc_port_parcel_header_h header = nullptr; int ret = rpc_port_parcel_get_header(handle_, &header); @@ -333,21 +264,11 @@ TEST_F(ParcelTest, rpc_port_parcel_get_header_P) { ASSERT_NE(header, nullptr); } -/* - * @testcase rpc_port_parcel_get_header_N - * @description Gets the header handle from the rpc port parcel handle - * @apicovered rpc_port_parcel_get_header - */ TEST_F(ParcelTest, rpc_port_parcel_get_header_N) { int ret = rpc_port_parcel_get_header(nullptr, nullptr); ASSERT_EQ(ret, RPC_PORT_ERROR_INVALID_PARAMETER); } -/* - * @testcase rpc_port_parcel_header_set_get_tag_P - * @description Sets and gets the tag - * @apicovered rpc_port_parcel_header_set_tag, rpc_port_parcel_header_get_tag - */ TEST_F(ParcelTest, rpc_port_parcel_header_set_get_tag_P) { rpc_port_parcel_header_h header = nullptr; int ret = rpc_port_parcel_get_header(handle_, &header); @@ -364,11 +285,6 @@ TEST_F(ParcelTest, rpc_port_parcel_header_set_get_tag_P) { ASSERT_STREQ(tag, out_tag); } -/* - * @testcase rpc_port_parcel_header_set_get_tag_without_set_tag_P - * @description gets the tag without set tag. - * @apicovered rpc_port_parcel_header_get_tag - */ TEST_F(ParcelTest, rpc_port_parcel_header_set_get_tag_without_set_tag_P) { rpc_port_parcel_header_h header = nullptr; int ret = rpc_port_parcel_get_header(handle_, &header); @@ -381,11 +297,6 @@ TEST_F(ParcelTest, rpc_port_parcel_header_set_get_tag_without_set_tag_P) { ASSERT_STREQ(out_tag, ""); } -/* - * @testcase rpc_port_parcel_header_set_get_tag_N - * @description Sets and gets the tag - * @apicovered rpc_port_parcel_header_set_tag, rpc_port_parcel_header_get_tag - */ TEST_F(ParcelTest, rpc_port_parcel_header_set_get_tag_N) { rpc_port_parcel_header_h header = nullptr; int ret = rpc_port_parcel_get_header(handle_, &header); @@ -406,11 +317,6 @@ TEST_F(ParcelTest, rpc_port_parcel_header_set_get_tag_N) { ASSERT_EQ(ret, RPC_PORT_ERROR_INVALID_PARAMETER); } -/* - * @testcase rpc_port_parcel_header_set_get_seq_num_P - * @description Sets and gets the sequence number - * @apicovered rpc_port_parcel_header_set_seq_num, rpc_port_parcel_header_get_seq_num - */ TEST_F(ParcelTest, rpc_port_parcel_header_set_get_seq_num_P) { rpc_port_parcel_header_h header = nullptr; int ret = rpc_port_parcel_get_header(handle_, &header); @@ -425,11 +331,6 @@ TEST_F(ParcelTest, rpc_port_parcel_header_set_get_seq_num_P) { ASSERT_EQ(seq_num, 100); } -/* - * @testcase rpc_port_parcel_header_set_get_seq_num_N - * @description Sets and gets the sequence number - * @apicovered rpc_port_parcel_header_set_seq_num, rpc_port_parcel_header_get_seq_num - */ TEST_F(ParcelTest, rpc_port_parcel_header_set_get_seq_num_N) { int ret = rpc_port_parcel_header_set_seq_num(nullptr, -1); ASSERT_EQ(ret, RPC_PORT_ERROR_INVALID_PARAMETER); @@ -438,11 +339,6 @@ TEST_F(ParcelTest, rpc_port_parcel_header_set_get_seq_num_N) { ASSERT_EQ(ret, RPC_PORT_ERROR_INVALID_PARAMETER); } -/* - * @testcase rpc_port_parcel_header_get_timestamp_P - * @description Gets the timestamp from the header handle of the rpc port parcel - * @apicovered rpc_port_parcel_header_get_timestamp - */ TEST_F(ParcelTest, rpc_port_parcel_header_get_timestamp_P) { rpc_port_parcel_header_h header = nullptr; int ret = rpc_port_parcel_get_header(handle_, &header); @@ -456,21 +352,11 @@ TEST_F(ParcelTest, rpc_port_parcel_header_get_timestamp_P) { ASSERT_NE(timestamp.tv_nsec, 0); } -/* - * @testcase rpc_port_parcel_header_get_timestamp_N - * @description Gets the timestamp from the header handle of the rpc port parcel - * @apicovered rpc_port_parcel_header_get_timestamp - */ TEST_F(ParcelTest, rpc_port_parcel_header_get_timestamp_N) { int ret = rpc_port_parcel_header_get_timestamp(nullptr, nullptr); ASSERT_EQ(ret, RPC_PORT_ERROR_INVALID_PARAMETER); } -/* - * @testcase rpc_port_parcel_get_raw_P - * @description Gets the raw data from the rpc port parcel handle - * @apicovered rpc_port_parcel_get_raw - */ TEST_F(ParcelTest, rpc_port_parcel_get_raw_P) { int ret = rpc_port_parcel_write_string(handle_, "test"); ASSERT_EQ(ret, RPC_PORT_ERROR_NONE); @@ -483,21 +369,11 @@ TEST_F(ParcelTest, rpc_port_parcel_get_raw_P) { ASSERT_NE(raw_size, 0); } -/* - * @testcase rpc_port_parcel_get_raw_N - * @description Gets the raw data from the rpc port parcel handle - * @apicovered rpc_port_parcel_get_raw - */ TEST_F(ParcelTest, rpc_port_parcel_get_raw_N) { int ret = rpc_port_parcel_get_raw(nullptr, nullptr, nullptr); ASSERT_EQ(ret, RPC_PORT_ERROR_INVALID_PARAMETER); } -/* - * @testcase rpc_port_parcel_create_from_raw_P - * @description Creates the rpc parcel handle with given the raw data. - * @apicovered rpc_port_parcel_create_from_raw - */ TEST_F(ParcelTest, rpc_port_parcel_create_from_raw_P) { int ret = rpc_port_parcel_write_string(handle_, "test"); ASSERT_EQ(ret, RPC_PORT_ERROR_NONE); @@ -523,21 +399,11 @@ TEST_F(ParcelTest, rpc_port_parcel_create_from_raw_P) { ASSERT_EQ(std::string(str), "test"); } -/* - * @testcase rpc_port_parcel_create_from_raw_N - * @description Creates the rpc parcel handle with given the raw data. - * @apicovered rpc_port_parcel_create_from_raw - */ TEST_F(ParcelTest, rpc_port_parcel_create_from_raw_N) { int ret = rpc_port_parcel_create_from_raw(nullptr, nullptr, 0); ASSERT_EQ(ret, RPC_PORT_ERROR_INVALID_PARAMETER); } -/* - * @testcase rpc_port_parcel_create_without_header_P - * @description Creates the rpc parcel handle without the header. - * @apicovered rpc_port_parcel_create_without_header - */ TEST_F(ParcelTest, rpc_port_parcel_create_without_header_P) { rpc_port_parcel_h parcel = nullptr; int ret = rpc_port_parcel_create_without_header(&parcel); @@ -554,12 +420,51 @@ TEST_F(ParcelTest, rpc_port_parcel_create_without_header_P) { ASSERT_EQ(header, nullptr); } -/* - * @testcase rpc_port_parcel_create_without_header_N - * @description Creates the rpc parcel handle without the header. - * @apicovered rpc_port_parcel_create_without_header - */ TEST_F(ParcelTest, rpc_port_parcel_create_without_header_N) { int ret = rpc_port_parcel_create_without_header(nullptr); ASSERT_EQ(ret, RPC_PORT_ERROR_INVALID_PARAMETER); } + +TEST_F(ParcelTest, rpc_port_parcel_reset_reader_P) { + int ret = rpc_port_parcel_write_string(handle_, "test"); + ASSERT_EQ(ret, RPC_PORT_ERROR_NONE); + + char* value = nullptr; + ret = rpc_port_parcel_read_string(handle_, &value); + ASSERT_EQ(ret, RPC_PORT_ERROR_NONE); + std::unique_ptr value_auto(value, std::free); + ASSERT_EQ(std::string(value), "test"); + + ret = rpc_port_parcel_reset_reader(handle_); + ASSERT_EQ(ret, RPC_PORT_ERROR_NONE); + + value = nullptr; + ret = rpc_port_parcel_read_string(handle_, &value); + ASSERT_EQ(ret, RPC_PORT_ERROR_NONE); + value_auto = std::unique_ptr(value, std::free); + ASSERT_EQ(std::string(value), "test"); +} + +TEST_F(ParcelTest, rpc_port_parcel_reset_reader_N) { + int ret = rpc_port_parcel_reset_reader(nullptr); + ASSERT_EQ(ret, RPC_PORT_ERROR_INVALID_PARAMETER); +} + +TEST_F(ParcelTest, rpc_port_parcel_to_array_P) { + int ret = rpc_port_parcel_write_string(handle_, "test"); + ASSERT_EQ(ret, RPC_PORT_ERROR_NONE); + + char* array = nullptr; + unsigned int size = 0; + ret = rpc_port_parcel_to_array(handle_, reinterpret_cast(&array), + &size); + std::unique_ptr array_auto(array, std::free); + ASSERT_EQ(ret, RPC_PORT_ERROR_NONE); + ASSERT_NE(array, nullptr); + ASSERT_NE(size, 0); +} + +TEST_F(ParcelTest, rpc_port_parcel_to_array_N) { + int ret = rpc_port_parcel_to_array(nullptr, nullptr, nullptr); + ASSERT_EQ(ret, RPC_PORT_ERROR_INVALID_PARAMETER); +} diff --git a/test/unit_tests/rpc_port_test.cc b/test/unit_tests/rpc_port_test.cc index e738121..9dd7b2c 100644 --- a/test/unit_tests/rpc_port_test.cc +++ b/test/unit_tests/rpc_port_test.cc @@ -66,7 +66,6 @@ class WatchInfo { void Vanish() { if (vanished_cb_) vanished_cb_(app_id_.c_str(), port_name_.c_str(), -1, user_data_); - } private: @@ -217,6 +216,17 @@ int FakeAulRpcPortUsrDestroy(const char* port_name, uid_t uid) { return 0; } +int FakeAulProcRegister(const char* proc_name, bundle* extra) { + if (proc_name == nullptr) + return -1; + + return 0; +} + +int FakeAulProcDeregister() { + return 0; +} + } // namespace class Mocks : public ::testing::NiceMock {}; @@ -286,6 +296,12 @@ class RpcPortBase : public TestFixture { EXPECT_CALL(GetMock(), aul_rpc_port_usr_destroy(_, _)) .WillRepeatedly(Invoke(FakeAulRpcPortUsrDestroy)); + EXPECT_CALL(GetMock(), + aul_proc_register(_, _)) + .WillRepeatedly(Invoke(FakeAulProcRegister)); + EXPECT_CALL(GetMock(), + aul_proc_deregister()) + .WillRepeatedly(Invoke(FakeAulProcDeregister)); } void RunMainLoop() { @@ -341,14 +357,27 @@ class RpcPortConnection : public RpcPortBase { rpc_port_h port, void *data) -> int { RpcPortConnection* p = static_cast(data); p->stub_port_ = port; - int ret = rpc_port_stub_get_port(p->stub_handle_, + pid_t pid = -1; + uid_t uid = 0; + int ret = rpc_port_get_peer_info(port, &pid, &uid); + if (ret != RPC_PORT_ERROR_NONE) + std::cerr << "Failed to get peer info" << std::endl; + + rpc_port_h main_port = nullptr; + ret = rpc_port_stub_get_port(p->stub_handle_, RPC_PORT_PORT_MAIN, + instance, &main_port); + if (ret != RPC_PORT_ERROR_NONE) + std::cerr << "Failed to get main port" << std::endl; + + ret = rpc_port_stub_get_port(p->stub_handle_, RPC_PORT_PORT_CALLBACK, instance, &p->stub_callback_port_); p->Finish(); - if (ret != 0) + if (ret != RPC_PORT_ERROR_NONE) return -1; - return 0; + + return RPC_PORT_ERROR_NONE; }, this); - ASSERT_EQ(ret, 0); + ASSERT_EQ(ret, RPC_PORT_ERROR_NONE); ret = rpc_port_stub_add_disconnected_event_cb(stub_handle_, [](const char* sender, const char* instance, void *data) { @@ -361,14 +390,17 @@ class RpcPortConnection : public RpcPortBase { }, p); }, this); - ASSERT_EQ(ret, 0); + ASSERT_EQ(ret, RPC_PORT_ERROR_NONE); ret = rpc_port_stub_add_privilege(stub_handle_, "http://tizen.org/privilege/appmanager.launch"); - ASSERT_EQ(ret, 0); + ASSERT_EQ(ret, RPC_PORT_ERROR_NONE); + + ret = rpc_port_stub_set_trusted(stub_handle_, true); + ASSERT_EQ(ret, RPC_PORT_ERROR_NONE); ret = rpc_port_stub_listen(stub_handle_); - ASSERT_EQ(ret, 0); + ASSERT_EQ(ret, RPC_PORT_ERROR_NONE); } void ProxySetup() { @@ -416,13 +448,6 @@ class RpcPortConnection : public RpcPortBase { bool touch_proxy_received_event_cb_ = false; }; -/* - * @testcase rpc_port_event_connect_P - * @description After the rpc_port_proxy_connect() is called, - * the rambda function is called by connected events. - * @apicovered rpc_port_stub_add_connected_event_cb, rpc_port_stub_listen, - * rpc_port_proxy_add_connected_event_cb, rpc_port_proxy_connect, - */ TEST_F(RpcPortBase, rpc_port_event_connect) { int ret = rpc_port_stub_add_connected_event_cb(stub_handle_, [](const char *sender, const char* instance, void *data) { @@ -452,13 +477,6 @@ TEST_F(RpcPortBase, rpc_port_event_connect) { ASSERT_TRUE(touch_stub_connected_event_cb_); } -/* - * @testcase rpc_port_event_connect_sync_P - * @description After the rpc_port_proxy_connect_sync() is called, - * the rambda function is called by connected events. - * @apicovered rpc_port_stub_add_connected_event_cb, rpc_port_stub_listen, - * rpc_port_proxy_add_connected_event_cb, rpc_port_proxy_connect_sync, - */ TEST_F(RpcPortBase, rpc_port_event_connect_sync) { int ret = rpc_port_stub_add_connected_event_cb(stub_handle_, [](const char *sender, const char* instance, void *data) { @@ -491,13 +509,36 @@ TEST_F(RpcPortBase, rpc_port_event_connect_sync) { ASSERT_TRUE(touch_stub_connected_event_cb_); } -/* - * @testcase rpc_port_proxy_event_reject_n - * @description After the rpc_port_proxy_connect() is called, - * the rambda function is called by the rejected event. - * @apicovered rpc_port_proxy_add_connected_event_cb, - * rpc_port_proxy_connect, - */ +TEST_F(RpcPortBase, rpc_port_set_target_uid_P) { + rpc_port_set_target_uid(5001); + ASSERT_EQ(get_last_result(), RPC_PORT_ERROR_NONE); +} + +TEST_F(RpcPortBase, rpc_port_get_target_uid_P) { + uid_t uid = rpc_port_get_target_uid(); + ASSERT_EQ(uid, 5001); +} + +TEST_F(RpcPortBase, rpc_port_register_proc_info_P) { + int ret = rpc_port_register_proc_info("UnitTest", nullptr); + ASSERT_EQ(ret, RPC_PORT_ERROR_NONE); +} + +TEST_F(RpcPortBase, rpc_port_register_proc_info_N) { + int ret = rpc_port_register_proc_info(nullptr, nullptr); + ASSERT_EQ(ret, RPC_PORT_ERROR_INVALID_PARAMETER); +} + +TEST_F(RpcPortBase, rpc_port_deregister_proc_info_P) { + int ret = rpc_port_deregister_proc_info(); + ASSERT_EQ(ret, RPC_PORT_ERROR_NONE); +} + +TEST_F(RpcPortBase, rpc_port_get_peer_info_N) { + int ret = rpc_port_get_peer_info(nullptr, nullptr, nullptr); + ASSERT_EQ(ret, RPC_PORT_ERROR_INVALID_PARAMETER); +} + TEST_F(RpcPortBase, rpc_port_proxy_event_reject_N) { int ret = rpc_port_proxy_add_rejected_event_cb(proxy_handle_, [](const char *ep, const char *port_name, void *data) { @@ -522,12 +563,6 @@ TEST_F(RpcPortBase, rpc_port_proxy_event_reject_N) { g_source_remove(tag); } -/* - * @testcase rpc_port_proxy_event_receive_P - * @description Writes and reads the data to the port handles. - * And then, checks the data in callback functions. - * @apicovered rpc_port_write, rpc_port_read - */ TEST_F(RpcPortConnection, rpc_port_proxy_event_receive_p) { char res[] = "OK"; char r_buf[256]; @@ -567,11 +602,6 @@ TEST_F(RpcPortConnection, rpc_port_proxy_event_receive_p) { ASSERT_STREQ(res, r_buf); } -/* - * @testcase rpc_port_read_write_P - * @description Writes and reads the data to the port handles. - * @apicovered rpc_port_write, rpc_port_read - */ TEST_F(RpcPortConnection, rpc_port_read_write) { char buf[] = "test message"; char res[] = "OK"; @@ -601,12 +631,6 @@ TEST_F(RpcPortConnection, rpc_port_read_write) { ASSERT_STREQ("OK", r_buf); } -/* - * @testcase rpc_port_proxy_disconnected_N - * @description Kills the stub port. - * And then, checks whether the disconnected event callback is invoked or not. - * @apicovered rpc_port_stub_add_disconnected_event_cb - */ TEST_F(RpcPortConnection, rpc_port_proxy_disconnected_N) { KillStub(); RunMainLoop(); @@ -614,12 +638,6 @@ TEST_F(RpcPortConnection, rpc_port_proxy_disconnected_N) { ASSERT_TRUE(touch_proxy_disconnected_event_cb_); } -/* - * @testcase rpc_port_stub_disconnected_N - * @description Kills the proxy port. - * And then, checks whether the disconnected event callback is invoked or not. - * @apicovered rpc_port_proxy_add_disconnected_event_cb - */ TEST_F(RpcPortConnection, rpc_port_stub_disconnected_N) { KillProxy(); RunMainLoop(); @@ -627,12 +645,6 @@ TEST_F(RpcPortConnection, rpc_port_stub_disconnected_N) { ASSERT_TRUE(touch_stub_disconnected_event_cb_); } -/* - * @testcase rpc_port_disconnect_P - * @description disconnect the port. - * And then, checks whether the disconnected event callback is invoked or not. - * @apicovered rpc_port_disconnect - */ TEST_F(RpcPortConnection, rpc_port_disconnect_P) { char res[] = "test"; if (proxy_port_ == nullptr) -- 2.7.4 From fac51e5821a844abf8bb74269d3cd714e195f9b0 Mon Sep 17 00:00:00 2001 From: Hwankyu Jhun Date: Mon, 28 Aug 2023 16:33:00 +0900 Subject: [PATCH 14/16] Release version 1.14.9 Changes: - Remove build warning message - Improve code coverage Change-Id: I94f98f02e9c5bea7476cfed66e3e4e250a47d948 Signed-off-by: Hwankyu Jhun --- packaging/rpc-port.spec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packaging/rpc-port.spec b/packaging/rpc-port.spec index 5c4562a..1f0fc2b 100644 --- a/packaging/rpc-port.spec +++ b/packaging/rpc-port.spec @@ -1,6 +1,6 @@ Name: rpc-port Summary: RPC Port library -Version: 1.14.8 +Version: 1.14.9 Release: 0 Group: Application Framework/Libraries License: Apache-2.0 -- 2.7.4 From abcefd49f48aaa5d6c7929c3124bae1bd951ef1a Mon Sep 17 00:00:00 2001 From: Hwankyu Jhun Date: Thu, 7 Sep 2023 08:56:03 +0900 Subject: [PATCH 15/16] Modify log message To debug the issues, the file descriptor number is needed. This patch changes the log format and the log level. Change-Id: Ie1d90c6c87f5009b92bf086aa2a71f983709be40 Signed-off-by: Hwankyu Jhun --- src/ac-internal.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ac-internal.cc b/src/ac-internal.cc index 9fea7ca..20b8974 100644 --- a/src/ac-internal.cc +++ b/src/ac-internal.cc @@ -169,7 +169,7 @@ int AccessController::Cynara::FetchCredsFromSocket(int fd) { } client_.reset(client); - _D("Cred client(%s), user(%s)", client_.get(), user_.get()); + _W("Cred client(%s), user(%s), fd(%d)", client_.get(), user_.get(), fd); return 0; } -- 2.7.4 From 9c89b330a0a76bff8a76bbe34d13d8d7d53bcb1c Mon Sep 17 00:00:00 2001 From: Hwankyu Jhun Date: Thu, 7 Sep 2023 10:08:28 +0900 Subject: [PATCH 16/16] Release version 1.14.10 Changes: - Modify log message Change-Id: I811bc99da9292bece5a0a93b42553cdf649f1c78 Signed-off-by: Hwankyu Jhun --- packaging/rpc-port.spec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packaging/rpc-port.spec b/packaging/rpc-port.spec index 1f0fc2b..d27345d 100644 --- a/packaging/rpc-port.spec +++ b/packaging/rpc-port.spec @@ -1,6 +1,6 @@ Name: rpc-port Summary: RPC Port library -Version: 1.14.9 +Version: 1.14.10 Release: 0 Group: Application Framework/Libraries License: Apache-2.0 -- 2.7.4