From 89fcb5d273fcdafdaae7f3695eae748cf7e25022 Mon Sep 17 00:00:00 2001 From: Changgyu Choi Date: Tue, 7 Feb 2023 18:37:48 +0900 Subject: [PATCH 01/16] Add unittest Unittest adds: - DebuggerInfo - LauncherInfo - LoaderInfo Change-Id: If2a8bf0ea367eb071713d951ba6117f83a5765bd Signed-off-by: Changgyu Choi --- CMakeLists.txt | 9 +- packaging/launchpad.spec | 13 +- tests/CMakeLists.txt | 1 + .../launchpad-process-pool-unittest/CMakeLists.txt | 51 +++++ .../src/test_launchpad.cc | 236 +++++++++++++++++++++ .../src/test_main.cc | 42 ++++ 6 files changed, 350 insertions(+), 2 deletions(-) create mode 100644 tests/CMakeLists.txt create mode 100644 tests/launchpad-process-pool-unittest/CMakeLists.txt create mode 100644 tests/launchpad-process-pool-unittest/src/test_launchpad.cc create mode 100644 tests/launchpad-process-pool-unittest/src/test_main.cc diff --git a/CMakeLists.txt b/CMakeLists.txt index 7c79e5f..02e8130 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,4 +1,4 @@ -CMAKE_MINIMUM_REQUIRED(VERSION 2.8) +CMAKE_MINIMUM_REQUIRED(VERSION 2.8.12) PROJECT(launchpad) IF(_TIZEN_FEATURE_PRIORITY_CHANGE) @@ -68,5 +68,12 @@ PKG_CHECK_MODULES(SECURITY_MANAGER_DEPS REQUIRED security-manager) PKG_CHECK_MODULES(TANCHOR_DEPS REQUIRED tanchor) PKG_CHECK_MODULES(TTRACE_DEPS REQUIRED ttrace) PKG_CHECK_MODULES(VCONF_DEPS REQUIRED vconf) +PKG_CHECK_MODULES(GMOCK_DEPS REQUIRED gmock) + +ENABLE_TESTING() +SET(LAUNCHPAD_PROCESS_POOL_UNITTEST launchpad-process-pool-unittest) +ADD_TEST(NAME ${LAUNCHPAD_PROCESS_POOL_UNITTEST} COMMAND ${LAUNCHPAD_PROCESS_POOL_UNITTEST} + WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/tests/launchpad-process-pool-unittest) ADD_SUBDIRECTORY(src) +ADD_SUBDIRECTORY(tests) diff --git a/packaging/launchpad.spec b/packaging/launchpad.spec index 070f3d7..413133e 100644 --- a/packaging/launchpad.spec +++ b/packaging/launchpad.spec @@ -33,6 +33,7 @@ BuildRequires: pkgconfig(iniparser) BuildRequires: pkgconfig(libxml-2.0) BuildRequires: pkgconfig(libsmack) BuildRequires: pkgconfig(pkgmgr-installer) +BuildRequires: pkgconfig(gmock) Requires(post): /sbin/ldconfig Requires(post): /usr/bin/systemctl @@ -41,7 +42,6 @@ Requires(postun): /usr/bin/systemctl Requires(preun): /usr/bin/systemctl Provides: app-launchpad -Obsoletes: amd-mod-launchpad %define tizen_feature_priority_change 0 %ifarch armv7l i686 i586 @@ -102,6 +102,12 @@ Requires: liblaunchpad = %{version}-%{release} %description -n liblaunchpad-devel Launchpad library (devel) +%package unittests +Summary: %{name} unittests binary + +%description unittests +unittests binary + %prep %setup -q cp %{SOURCE1001} . @@ -144,6 +150,9 @@ MAJORVER=`echo %{version} | awk 'BEGIN {FS="."}{print $1}'` . %__make %{?_smp_mflags} +%check +ctest --verbose %{?_smp_mflags} + %install rm -rf %{buildroot} @@ -200,3 +209,5 @@ ln -sf ../launchpad-process-pool.service %{buildroot}%{_unitdir_user}/basic.targ %{_libdir}/pkgconfig/liblaunchpad.pc %{_libdir}/pkgconfig/liblaunchpad-hydra.pc +%files unittests +%{_bindir}/launchpad-process-pool-unittest diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt new file mode 100644 index 0000000..adf695a --- /dev/null +++ b/tests/CMakeLists.txt @@ -0,0 +1 @@ +ADD_SUBDIRECTORY(launchpad-process-pool-unittest) diff --git a/tests/launchpad-process-pool-unittest/CMakeLists.txt b/tests/launchpad-process-pool-unittest/CMakeLists.txt new file mode 100644 index 0000000..c79c682 --- /dev/null +++ b/tests/launchpad-process-pool-unittest/CMakeLists.txt @@ -0,0 +1,51 @@ +CMAKE_MINIMUM_REQUIRED(VERSION 2.8.12) +PROJECT(launchpad-process-pool-unittest C CXX) + +INCLUDE(FindPkgConfig) + +SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -fvisibility=hidden -Wall -Winline") + +SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${EXTRA_CFLAGS} -std=c++17 -DUNIT_TEST") +SET(CMAKE_CXX_FLAGS_DEBUG "-O0 -g") +SET(CMAKE_CXX_FLAGS_RELEASE "-O2") + +INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/../) +INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/../../) +INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/../../src/lib/common/inc) +INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/../../src/launchpad-process-pool/inc) + +AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/src UNITTESTS_SOURCES) +AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/../../src/lib/common/src LAUNCHPAD_COMMON_SOURCES) +AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/../../src/launchpad-process-pool/src LAUNCHPAD_PROCESS_POOL_SOURCES) +LIST(REMOVE_ITEM LAUNCHPAD_PROCESS_POOL_SOURCES + "${CMAKE_CURRENT_SOURCE_DIR}/../../src/launchpad-process-pool/src/launchpad.cc" +) + +ADD_EXECUTABLE(${PROJECT_NAME} + ${LAUNCHPAD_PROCESS_POOL_SOURCES} + ${LAUNCHPAD_COMMON_SOURCES} + ${UNITTESTS_SOURCES} +) + +APPLY_PKG_CONFIG(${PROJECT_NAME} PUBLIC + BUNDLE_DEPS + DBUS_DEPS + DLOG_DEPS + DLOG_REDIRECT_STDOUT_DEPS + GIO_DEPS + INIPARSER_DEPS + LIBCAP_DEPS + LIBSMACK_DEPS + LIBSYSTEMD_DEPS + LIBTZPLATFORM_CONFIG_DEPS + SECURITY_MANAGER_DEPS + TANCHOR_DEPS + TTRACE_DEPS + VCONF_DEPS + GMOCK_DEPS +) + +SET_TARGET_PROPERTIES(${PROJECT_NAME} PROPERTIES COMPILE_FLAGS "${EXTRA_CFLAGS}") +TARGET_LINK_LIBRARIES(${PROJECT_NAME} PRIVATE "-ldl") + +INSTALL(TARGETS ${PROJECT_NAME} DESTINATION /usr/bin/) diff --git a/tests/launchpad-process-pool-unittest/src/test_launchpad.cc b/tests/launchpad-process-pool-unittest/src/test_launchpad.cc new file mode 100644 index 0000000..ad9e83e --- /dev/null +++ b/tests/launchpad-process-pool-unittest/src/test_launchpad.cc @@ -0,0 +1,236 @@ +/* + * Copyright (c) 2023 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include + +#include +#include + +#include "debugger_info.hh" +#include "launcher_info.hh" +#include "loader_info.hh" + +using ::testing::AtLeast; +using namespace launchpad; + +class LaunchpadTest : public ::testing::Test { + public: + virtual void SetUp() { + std::ofstream of; + of.open(test_debugger); + of << test_debugger; + of.close(); + + of.open(test_launcher); + of << test_launcher; + of.close(); + + of.open(test_loader); + of << test_loader; + of.close(); + + of.open(test_debugger_info_file); + of << R"__test( +[DEBUGGER] +NAME DEBUG +EXE test_debugger +APP_TYPE capp|c++app +EXTRA_KEY __DLP_DEBUG_ARG__ +DEFAULT_OPT --wrapper +DEFAULT_OPT env +DEFAULT_OPT OPENSSL_armcap=0 +DEFAULT_OPT -- +)__test"; + of.close(); + + of.open(test_launcher_info_file); + of << R"__test( +[LAUNCHER] +NAME dotnet-launcher +EXE test_launcher +APP_TYPE dotnet +EXTRA_ARG --PADDING_TO_CHANGE_CMDLINE_PADDING_TO_CHANGE_CMDLINE_PADDING_TO_CHANGE_CMDLINE_PADDING_TO_CHANGE_CMDLINE +EXTRA_ARG --profile +EXTRA_ARG --appType +EXTRA_ARG dotnet +EXTRA_ARG TIZEN_UIFW +EXTRA_ARG ElmSharp +EXTRA_ARG --standalone +)__test"; + of.close(); + + of.open(test_loader_info_file); + of << R"__test( +[LOADER] +NAME hw-loader1 +EXE /usr/bin/launchpad-loader +APP_TYPE capp|c++app +HW_ACC ON +DETECTION_METHOD TIMEOUT|VISIBILITY +TIMEOUT 5000 +EXTRA loader_type hw-loader +EXTRA_ARRAY preload +EXTRA_ARRAY_VAL /usr/lib/libappcore-efl.so.1 +EXTRA_ARRAY_VAL /usr/lib/libappcore-common.so.1 +EXTRA_ARRAY_VAL /usr/lib/libcapi-appfw-application.so.0 +EXTRA_ARRAY_VAL /usr/lib/ecore_imf/modules/wayland/v-1.25/module.so +EXTRA_ARRAY_VAL /usr/lib/libdali-toolkit.so +EXTRA_ARRAY_VAL /usr/lib/libcairo.so.2 +EXTRA_ARRAY_VAL /usr/lib/libcapi-media-player.so.0 +EXTRA_ARRAY_VAL /usr/lib/libcapi-media-camera.so.0 +EXTRA_ARRAY_VAL /usr/lib/ecore_evas/engines/extn/v-1.25/module.so +ALTERNATIVE_LOADER common-loader1 +EXTRA threads 7 + +)__test"; + of.close(); + } + + virtual void TearDown() {} + + private: + const std::string test_debugger = "test_debugger"; + const std::string test_launcher = "test_launcher"; + const std::string test_loader = "test_loader"; + const std::string test_debugger_info_file = "test.debugger"; + const std::string test_launcher_info_file = "test.launcher"; + const std::string test_loader_info_file = "test.loader"; +}; + +TEST_F(LaunchpadTest, DebuggerInfoTest) { + /* Test debugger info file + [DEBUGGER] + NAME DEBUG + EXE test_debugger + APP_TYPE capp|c++app + EXTRA_KEY __DLP_DEBUG_ARG__ + DEFAULT_OPT --wrapper + DEFAULT_OPT env + DEFAULT_OPT OPENSSL_armcap=0 + DEFAULT_OPT -- + */ + + DebuggerInfoInflator inflator; + auto list = inflator.Inflate("."); + EXPECT_EQ(list.size(), 1); + auto info = std::move(list.front()); + EXPECT_EQ(info->GetName(), "DEBUG"); + EXPECT_EQ(info->GetExe(), "test_debugger"); + EXPECT_EQ(info->GetAppTypes().size(), 2); + EXPECT_EQ(info->GetAppTypes()[0], "capp"); + EXPECT_EQ(info->GetAppTypes()[1], "c++app"); + EXPECT_EQ(info->GetExtraKeyList().size(), 1); + EXPECT_EQ(info->GetExtraKeyList()[0], "__DLP_DEBUG_ARG__"); + EXPECT_EQ(info->GetDefaultOptList().size(), 4); + EXPECT_EQ(info->GetDefaultOptList()[0], "--wrapper"); + EXPECT_EQ(info->GetDefaultOptList()[1], "env"); + EXPECT_EQ(info->GetDefaultOptList()[2], "OPENSSL_armcap=0"); + EXPECT_EQ(info->GetDefaultOptList()[3], "--"); +} + +TEST_F(LaunchpadTest, LauncherInfoTest) { + /* Test launcher info file + [LAUNCHER] + NAME dotnet-launcher + EXE test_launcher + APP_TYPE dotnet + EXTRA_ARG + --PADDING_TO_CHANGE_CMDLINE_PADDING_TO_CHANGE_CMDLINE_PADDING_TO_CHANGE_CMDLINE_PADDING_TO_CHANGE_CMDLINE + EXTRA_ARG --profile + EXTRA_ARG --appType + EXTRA_ARG dotnet + EXTRA_ARG TIZEN_UIFW + EXTRA_ARG ElmSharp + EXTRA_ARG --standalone + */ + + LauncherInfoInflator inflator; + auto list = inflator.Inflate("."); + EXPECT_EQ(list.size(), 1); + auto info = std::move(list.front()); + EXPECT_EQ(info->GetName(), "dotnet-launcher"); + EXPECT_EQ(info->GetExe(), "test_launcher"); + EXPECT_EQ(info->GetAppTypes().size(), 1); + EXPECT_EQ(info->GetAppTypes()[0], "dotnet"); + EXPECT_EQ(info->GetExtraArgs().size(), 7); + EXPECT_EQ(info->GetExtraArgs()[0], + "--PADDING_TO_CHANGE_CMDLINE_PADDING_TO_CHANGE_CMDLINE_PADDING_TO_" + "CHANGE_CMDLINE_PADDING_TO_CHANGE_CMDLINE"); + EXPECT_EQ(info->GetExtraArgs()[1], "--profile"); + EXPECT_EQ(info->GetExtraArgs()[2], "--appType"); + EXPECT_EQ(info->GetExtraArgs()[3], "dotnet"); + EXPECT_EQ(info->GetExtraArgs()[4], "TIZEN_UIFW"); + EXPECT_EQ(info->GetExtraArgs()[5], "ElmSharp"); + EXPECT_EQ(info->GetExtraArgs()[6], "--standalone"); +} + +TEST_F(LaunchpadTest, LoaderInfoTest) { +/* Test loader info file +[LOADER] +NAME hw-loader1 +EXE /usr/bin/launchpad-loader +APP_TYPE capp|c++app +HW_ACC ON +DETECTION_METHOD TIMEOUT|VISIBILITY +TIMEOUT 5000 +EXTRA loader_type hw-loader +EXTRA_ARRAY preload +EXTRA_ARRAY_VAL /usr/lib/libappcore-efl.so.1 +EXTRA_ARRAY_VAL /usr/lib/libappcore-common.so.1 +EXTRA_ARRAY_VAL /usr/lib/libcapi-appfw-application.so.0 +EXTRA_ARRAY_VAL /usr/lib/ecore_imf/modules/wayland/v-1.25/module.so +EXTRA_ARRAY_VAL /usr/lib/libdali-toolkit.so +EXTRA_ARRAY_VAL /usr/lib/libcairo.so.2 +EXTRA_ARRAY_VAL /usr/lib/libcapi-media-player.so.0 +EXTRA_ARRAY_VAL /usr/lib/libcapi-media-camera.so.0 +EXTRA_ARRAY_VAL /usr/lib/ecore_evas/engines/extn/v-1.25/module.so +ALTERNATIVE_LOADER common-loader1 +EXTRA threads 7 +*/ + + LoaderInfoInflator inflator; + auto list = inflator.Inflate("."); + EXPECT_EQ(list.size(), 1); + auto info = std::move(list.front()); + EXPECT_EQ(info->GetName(), "hw-loader1"); + EXPECT_EQ(info->GetExe(), "/usr/bin/launchpad-loader"); + EXPECT_EQ(info->GetAppTypes().size(), 2); + EXPECT_EQ(info->GetAppTypes()[0], "capp"); + EXPECT_EQ(info->GetAppTypes()[1], "c++app"); + EXPECT_EQ(info->GetHwAcc(), "ON"); + EXPECT_EQ(info->GetDetectionMethod(), LoaderMethod::Timeout | + LoaderMethod::Visibility | + LoaderMethod::Install); + EXPECT_EQ(info->GetTimeoutVal(), 5000); + auto& b = info->GetExtra(); + EXPECT_EQ(b.GetString("loader_type"), "hw-loader"); + EXPECT_EQ(b.GetString("threads"), "7"); + auto arr = b.GetStringArray("preload"); + EXPECT_EQ(arr.size(), 9); + EXPECT_EQ(arr[0], "/usr/lib/libappcore-efl.so.1"); + EXPECT_EQ(arr[1], "/usr/lib/libappcore-common.so.1"); + EXPECT_EQ(arr[2], "/usr/lib/libcapi-appfw-application.so.0"); + EXPECT_EQ(arr[3], "/usr/lib/ecore_imf/modules/wayland/v-1.25/module.so"); + EXPECT_EQ(arr[4], "/usr/lib/libdali-toolkit.so"); + EXPECT_EQ(arr[5], "/usr/lib/libcairo.so.2"); + EXPECT_EQ(arr[6], "/usr/lib/libcapi-media-player.so.0"); + EXPECT_EQ(arr[7], "/usr/lib/libcapi-media-camera.so.0"); + EXPECT_EQ(arr[8], "/usr/lib/ecore_evas/engines/extn/v-1.25/module.so"); +} diff --git a/tests/launchpad-process-pool-unittest/src/test_main.cc b/tests/launchpad-process-pool-unittest/src/test_main.cc new file mode 100644 index 0000000..3822224 --- /dev/null +++ b/tests/launchpad-process-pool-unittest/src/test_main.cc @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2023 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include + +#include + +extern "C" int __dlog_print(log_id_t log_id, int prio, const char* tag, + const char* fmt, ...) { + printf("%s:", tag); + va_list ap; + va_start(ap, fmt); + vprintf(fmt, ap); + va_end(ap); + printf("\n"); + return 0; +} + +int main(int argc, char** argv) { + try { + testing::InitGoogleTest(&argc, argv); + return RUN_ALL_TESTS(); + } catch (std::exception const &e) { + std::cout << "test_main caught exception: " << e.what() << std::endl; + return -1; + } +} -- 2.7.4 From c1440580ea9009b99556b94d1ea6664d5030a1d4 Mon Sep 17 00:00:00 2001 From: Changgyu Choi Date: Mon, 13 Feb 2023 11:11:24 +0900 Subject: [PATCH 02/16] Modify launchpad-process-pool directory structure launchpad-process-pool directory structure is modified as follow. launchpad-process-pool | *.cc | *.hh Change-Id: I30c244da4b5fe20db85ea7ad00209cb5bd8cc84c Signed-off-by: Changgyu Choi --- src/launchpad-process-pool/CMakeLists.txt | 6 +- .../{src => }/debugger_info.cc | 7 +- .../{inc => }/debugger_info.hh | 0 .../{src => }/launcher_info.cc | 7 +- .../{inc => }/launcher_info.hh | 0 src/launchpad-process-pool/{src => }/launchpad.cc | 36 +-- src/launchpad-process-pool/launchpad_config.cc | 303 +++++++++++++++++++ .../{inc => }/launchpad_config.h | 0 .../{src => }/launchpad_dbus.cc | 5 +- .../{inc => }/launchpad_dbus.h | 0 .../{src => }/launchpad_debug.cc | 11 +- .../{inc => }/launchpad_debug.h | 0 .../{src => }/launchpad_inotify.cc | 5 +- .../{inc => }/launchpad_inotify.h | 0 .../{src => }/launchpad_io_channel.cc | 5 +- .../{inc => }/launchpad_io_channel.h | 0 .../{src => }/launchpad_log.cc | 9 +- .../{inc => }/launchpad_log.h | 0 .../{src => }/launchpad_logger.cc | 7 +- .../{inc => }/launchpad_logger.h | 0 .../{src => }/launchpad_memory_monitor.cc | 9 +- .../{inc => }/launchpad_memory_monitor.h | 0 .../{src => }/launchpad_signal.cc | 15 +- .../{inc => }/launchpad_signal.h | 0 .../{src => }/launchpad_worker.cc | 5 +- .../{inc => }/launchpad_worker.h | 0 .../{src => }/loader_info.cc | 7 +- .../{inc => }/loader_info.hh | 2 +- src/launchpad-process-pool/{inc => }/slot_info.h | 0 src/launchpad-process-pool/src/launchpad_config.cc | 332 --------------------- src/launchpad-process-pool/{src => }/util.cc | 0 src/launchpad-process-pool/{inc => }/util.hh | 0 .../launchpad-process-pool-unittest/CMakeLists.txt | 8 +- .../src/test_launchpad.cc | 8 +- 34 files changed, 386 insertions(+), 401 deletions(-) rename src/launchpad-process-pool/{src => }/debugger_info.cc (97%) rename src/launchpad-process-pool/{inc => }/debugger_info.hh (100%) rename src/launchpad-process-pool/{src => }/launcher_info.cc (96%) rename src/launchpad-process-pool/{inc => }/launcher_info.hh (100%) rename src/launchpad-process-pool/{src => }/launchpad.cc (99%) create mode 100644 src/launchpad-process-pool/launchpad_config.cc rename src/launchpad-process-pool/{inc => }/launchpad_config.h (100%) rename src/launchpad-process-pool/{src => }/launchpad_dbus.cc (98%) rename src/launchpad-process-pool/{inc => }/launchpad_dbus.h (100%) rename src/launchpad-process-pool/{src => }/launchpad_debug.cc (97%) rename src/launchpad-process-pool/{inc => }/launchpad_debug.h (100%) rename src/launchpad-process-pool/{src => }/launchpad_inotify.cc (97%) rename src/launchpad-process-pool/{inc => }/launchpad_inotify.h (100%) rename src/launchpad-process-pool/{src => }/launchpad_io_channel.cc (97%) rename src/launchpad-process-pool/{inc => }/launchpad_io_channel.h (100%) rename src/launchpad-process-pool/{src => }/launchpad_log.cc (89%) rename src/launchpad-process-pool/{inc => }/launchpad_log.h (100%) rename src/launchpad-process-pool/{src => }/launchpad_logger.cc (97%) rename src/launchpad-process-pool/{inc => }/launchpad_logger.h (100%) rename src/launchpad-process-pool/{src => }/launchpad_memory_monitor.cc (94%) rename src/launchpad-process-pool/{inc => }/launchpad_memory_monitor.h (100%) rename src/launchpad-process-pool/{src => }/launchpad_signal.cc (96%) rename src/launchpad-process-pool/{inc => }/launchpad_signal.h (100%) rename src/launchpad-process-pool/{src => }/launchpad_worker.cc (97%) rename src/launchpad-process-pool/{inc => }/launchpad_worker.h (100%) rename src/launchpad-process-pool/{src => }/loader_info.cc (99%) rename src/launchpad-process-pool/{inc => }/loader_info.hh (99%) rename src/launchpad-process-pool/{inc => }/slot_info.h (100%) delete mode 100644 src/launchpad-process-pool/src/launchpad_config.cc rename src/launchpad-process-pool/{src => }/util.cc (100%) rename src/launchpad-process-pool/{inc => }/util.hh (100%) diff --git a/src/launchpad-process-pool/CMakeLists.txt b/src/launchpad-process-pool/CMakeLists.txt index 3175dac..e619fe3 100644 --- a/src/launchpad-process-pool/CMakeLists.txt +++ b/src/launchpad-process-pool/CMakeLists.txt @@ -1,8 +1,8 @@ -AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/src +AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR} LAUNCHPAD_PROCESS_POOL_SRCS) AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/../lib/common/src LIB_COMMON_SRCS) -INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/inc) +INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/..) ADD_EXECUTABLE(${TARGET_LAUNCHPAD_PROCESS_POOL} ${LAUNCHPAD_PROCESS_POOL_SRCS} @@ -11,7 +11,7 @@ SET_TARGET_PROPERTIES(${TARGET_LAUNCHPAD_PROCESS_POOL} PROPERTIES SKIP_BUILD_RPATH TRUE) TARGET_INCLUDE_DIRECTORIES(${TARGET_LAUNCHPAD_PROCESS_POOL} PUBLIC - ${CMAKE_CURRENT_SOURCE_DIR}/inc) + ${CMAKE_CURRENT_SOURCE_DIR}/..) TARGET_INCLUDE_DIRECTORIES(${TARGET_LAUNCHPAD_PROCESS_POOL} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/../lib/common/inc) diff --git a/src/launchpad-process-pool/src/debugger_info.cc b/src/launchpad-process-pool/debugger_info.cc similarity index 97% rename from src/launchpad-process-pool/src/debugger_info.cc rename to src/launchpad-process-pool/debugger_info.cc index 8cbeaf7..5ae58bd 100644 --- a/src/launchpad-process-pool/src/debugger_info.cc +++ b/src/launchpad-process-pool/debugger_info.cc @@ -14,6 +14,8 @@ * limitations under the License. */ +#include "launchpad-process-pool/debugger_info.hh" + #include #include #include @@ -27,9 +29,8 @@ #include #include -#include "debugger_info.hh" -#include "launchpad_common.h" -#include "util.hh" +#include "launchpad-process-pool/util.hh" +#include "lib/common/inc/launchpad_common.h" namespace launchpad { namespace { diff --git a/src/launchpad-process-pool/inc/debugger_info.hh b/src/launchpad-process-pool/debugger_info.hh similarity index 100% rename from src/launchpad-process-pool/inc/debugger_info.hh rename to src/launchpad-process-pool/debugger_info.hh diff --git a/src/launchpad-process-pool/src/launcher_info.cc b/src/launchpad-process-pool/launcher_info.cc similarity index 96% rename from src/launchpad-process-pool/src/launcher_info.cc rename to src/launchpad-process-pool/launcher_info.cc index 7387323..a8baacd 100644 --- a/src/launchpad-process-pool/src/launcher_info.cc +++ b/src/launchpad-process-pool/launcher_info.cc @@ -14,6 +14,8 @@ * limitations under the License. */ +#include "launchpad-process-pool/launcher_info.hh" + #include #include #include @@ -27,9 +29,8 @@ #include #include -#include "launcher_info.hh" -#include "launchpad_common.h" -#include "util.hh" +#include "launchpad-process-pool/util.hh" +#include "lib/common/inc/launchpad_common.h" namespace launchpad { namespace { diff --git a/src/launchpad-process-pool/inc/launcher_info.hh b/src/launchpad-process-pool/launcher_info.hh similarity index 100% rename from src/launchpad-process-pool/inc/launcher_info.hh rename to src/launchpad-process-pool/launcher_info.hh diff --git a/src/launchpad-process-pool/src/launchpad.cc b/src/launchpad-process-pool/launchpad.cc similarity index 99% rename from src/launchpad-process-pool/src/launchpad.cc rename to src/launchpad-process-pool/launchpad.cc index a71168f..6fd6ef4 100644 --- a/src/launchpad-process-pool/src/launchpad.cc +++ b/src/launchpad-process-pool/launchpad.cc @@ -40,24 +40,24 @@ #include -#include "key.h" -#include "launcher_info.hh" -#include "launchpad_common.h" -#include "launchpad_config.h" -#include "launchpad_dbus.h" -#include "launchpad_debug.h" -#include "launchpad_inotify.h" -#include "launchpad_io_channel.h" -#include "launchpad_log.h" -#include "launchpad_memory_monitor.h" -#include "launchpad_plugin.h" -#include "launchpad_proc.h" -#include "launchpad_signal.h" -#include "launchpad_types.h" -#include "launchpad_worker.h" -#include "loader_info.hh" -#include "perf.h" -#include "slot_info.h" +#include "launchpad-process-pool/launcher_info.hh" +#include "launchpad-process-pool/launchpad_config.h" +#include "launchpad-process-pool/launchpad_dbus.h" +#include "launchpad-process-pool/launchpad_debug.h" +#include "launchpad-process-pool/launchpad_inotify.h" +#include "launchpad-process-pool/launchpad_io_channel.h" +#include "launchpad-process-pool/launchpad_log.h" +#include "launchpad-process-pool/launchpad_memory_monitor.h" +#include "launchpad-process-pool/launchpad_signal.h" +#include "launchpad-process-pool/launchpad_worker.h" +#include "launchpad-process-pool/loader_info.hh" +#include "launchpad-process-pool/slot_info.h" +#include "lib/common/inc/key.h" +#include "lib/common/inc/launchpad_common.h" +#include "lib/common/inc/launchpad_plugin.h" +#include "lib/common/inc/launchpad_proc.h" +#include "lib/common/inc/launchpad_types.h" +#include "lib/common/inc/perf.h" #define AUL_PR_NAME 16 #define EXEC_CANDIDATE_EXPIRED 5 diff --git a/src/launchpad-process-pool/launchpad_config.cc b/src/launchpad-process-pool/launchpad_config.cc new file mode 100644 index 0000000..434973d --- /dev/null +++ b/src/launchpad-process-pool/launchpad_config.cc @@ -0,0 +1,303 @@ +/* + * Copyright (c) 2019 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "launchpad-process-pool/launchpad_config.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "lib/common/inc/launchpad_common.h" + +#define PATH_LAUNCHPAD_CONF "/usr/share/aul/launchpad.conf" +#define TAG_MEMORY_STATUS "MemoryStatus" +#define KEY_MEMORY_STATUS_LOW_KEY "LowKey" +#define KEY_MEMORY_STATUS_LOW_VALUE "LowValue" +#define KEY_MEMORY_STATUS_NORMAL_KEY "NormalKey" +#define KEY_MEMORY_STATUS_NORMAL_VALUE "NormalValue" + +#define TAG_MEMORY_MONITOR "MemoryMonitor" +#define KEY_MEMORY_MONITOR_THRESHOLD "Threshold" +#define KEY_MEMORY_MONITOR_INTERVAL "Interval" + +#define TAG_CPU_CHECKER "CpuChecker" +#define KEY_CPU_CHECKER_MAX_COUNT "MaxCount" + +#define TAG_LOGGER "Logger" +#define KEY_LOGGER_PATH "Path" +#define KEY_LOGGER_ENABLE "Enable" + +struct memory_status_s { + char* low_key; + int low_value; + char* normal_key; + int normal_value; +}; + +struct memory_monitor_s { + int threshold; + int interval; +}; + +struct cpu_checker_s { + int max_count; +}; + +struct logger_s { + char* path; + int enable; +}; + +static struct memory_status_s __memory_status; +static struct memory_monitor_s __memory_monitor; +static struct cpu_checker_s __cpu_checker; +static struct logger_s __logger; + +const char* _config_get_string_value(config_type_e type) { + const char* value; + + switch (type) { + case CONFIG_TYPE_MEMORY_STATUS_LOW_KEY: + value = __memory_status.low_key; + break; + case CONFIG_TYPE_MEMORY_STATUS_NORMAL_KEY: + value = __memory_status.normal_key; + break; + case CONFIG_TYPE_LOGGER_PATH: + value = __logger.path; + break; + default: + _E("Unknown type"); + value = NULL; + break; + } + + return value; +} + +int _config_get_int_value(config_type_e type) { + int value; + + switch (type) { + case CONFIG_TYPE_MEMORY_STATUS_LOW_VALUE: + value = __memory_status.low_value; + break; + case CONFIG_TYPE_MEMORY_STATUS_NORMAL_VALUE: + value = __memory_status.normal_value; + break; + case CONFIG_TYPE_MEMORY_MONITOR_THRESHOLD: + value = __memory_monitor.threshold; + break; + case CONFIG_TYPE_MEMORY_MONITOR_INTERVAL: + value = __memory_monitor.interval; + break; + case CONFIG_TYPE_CPU_CHECKER_MAX_COUNT: + value = __cpu_checker.max_count; + break; + case CONFIG_TYPE_LOGGER_ENABLE: + value = __logger.enable; + break; + default: + _E("Unknown type"); + value = INT_MIN; + } + + return value; +} + +static const char* __get_string_value(dictionary* d, + const char* tag, + const char* key) { + char buf[128]; + + snprintf(buf, sizeof(buf), "%s:%s", tag, key); + return iniparser_getstring(d, buf, NULL); +} + +static int __get_int_value(dictionary* d, const char* tag, const char* key) { + char buf[128]; + + snprintf(buf, sizeof(buf), "%s:%s", tag, key); + return iniparser_getint(d, buf, INT_MIN); +} + +static void __memory_status_init(void) { + __memory_status.low_key = strdup(VCONFKEY_SYSMAN_LOW_MEMORY); + __memory_status.low_value = VCONFKEY_SYSMAN_LOW_MEMORY_SOFT_WARNING; + __memory_status.normal_key = strdup(VCONFKEY_SYSMAN_LOW_MEMORY); + __memory_status.normal_value = VCONFKEY_SYSMAN_LOW_MEMORY_NORMAL; +} + +static void __memory_status_fini(void) { + __memory_status.normal_value = 0; + free(__memory_status.normal_key); + __memory_status.low_value = 0; + free(__memory_status.low_key); +} + +static void __memory_status_set(dictionary* d) { + const char* str; + char* val; + int ret; + + str = __get_string_value(d, TAG_MEMORY_STATUS, KEY_MEMORY_STATUS_LOW_KEY); + if (str) { + val = strdup(str); + if (val) { + free(__memory_status.low_key); + __memory_status.low_key = val; + } + } + + ret = __get_int_value(d, TAG_MEMORY_STATUS, KEY_MEMORY_STATUS_LOW_VALUE); + if (ret != INT_MIN) + __memory_status.low_value = ret; + + str = __get_string_value(d, TAG_MEMORY_STATUS, KEY_MEMORY_STATUS_NORMAL_KEY); + if (str) { + val = strdup(str); + if (val) { + free(__memory_status.normal_key); + __memory_status.normal_key = val; + } + } + + ret = __get_int_value(d, TAG_MEMORY_STATUS, KEY_MEMORY_STATUS_NORMAL_VALUE); + if (ret != INT_MIN) + __memory_status.normal_value = ret; + + _W("Memory Status Low(%s:%d), Normal(%s:%d)", __memory_status.low_key, + __memory_status.low_value, __memory_status.normal_key, + __memory_status.normal_value); +} + +static void __memory_monitor_init(void) { + __memory_monitor.threshold = 80; /* 80 % */ + __memory_monitor.interval = 5000; /* 5 seconds */ +} + +static void __memory_monitor_fini(void) { + __memory_monitor.threshold = 0; + __memory_monitor.interval = 0; +} + +static void __memory_monitor_set(dictionary* d) { + int ret; + + ret = __get_int_value(d, TAG_MEMORY_MONITOR, KEY_MEMORY_MONITOR_THRESHOLD); + if (ret != INT_MIN) + __memory_monitor.threshold = ret; + + ret = __get_int_value(d, TAG_MEMORY_MONITOR, KEY_MEMORY_MONITOR_INTERVAL); + if (ret != INT_MIN) + __memory_monitor.interval = ret; + + _W("Memory Monitor Threshold(%d), Interval(%d)", __memory_monitor.threshold, + __memory_monitor.interval); +} + +static void __cpu_checker_init(void) { + __cpu_checker.max_count = 10; +} + +static void __cpu_checker_fini(void) { + __cpu_checker.max_count = 0; +} + +static void __cpu_checker_set(dictionary* d) { + int ret; + + ret = __get_int_value(d, TAG_CPU_CHECKER, KEY_CPU_CHECKER_MAX_COUNT); + if (ret != INT_MIN) + __cpu_checker.max_count = ret; + + _W("CPU Checker MaxCount(%d)", __cpu_checker.max_count); +} + +static void __logger_init(void) { + __logger.path = strdup("/var/log/appfw"); + __logger.enable = false; +} + +static void __logger_fini(void) { + free(__logger.path); +} + +static void __logger_set(dictionary* d) { + const char* str; + int val; + + str = __get_string_value(d, TAG_LOGGER, KEY_LOGGER_PATH); + if (str) { + free(__logger.path); + __logger.path = strdup(str); + } + _W("Logger path(%s)", __logger.path); + + val = __get_int_value(d, TAG_LOGGER, KEY_LOGGER_ENABLE); + if (val >= 0) + __logger.enable = val; + _W("Logger enable(%d)", __logger.enable); +} + +int _config_init(void) { + dictionary* d; + int ret; + + _D("config init"); + + __memory_status_init(); + __memory_monitor_init(); + __cpu_checker_init(); + __logger_init(); + + ret = access(PATH_LAUNCHPAD_CONF, F_OK); + if (ret != 0) { + _W("The file doesn't exist. errno(%d)", errno); + return 0; + } + + d = iniparser_load(PATH_LAUNCHPAD_CONF); + if (!d) { + _E("Failed to load the config file"); + return -1; + } + + __memory_status_set(d); + __memory_monitor_set(d); + __cpu_checker_set(d); + __logger_set(d); + + iniparser_freedict(d); + + return 0; +} + +void _config_fini(void) { + _D("config fini"); + + __logger_fini(); + __cpu_checker_fini(); + __memory_monitor_fini(); + __memory_status_fini(); +} diff --git a/src/launchpad-process-pool/inc/launchpad_config.h b/src/launchpad-process-pool/launchpad_config.h similarity index 100% rename from src/launchpad-process-pool/inc/launchpad_config.h rename to src/launchpad-process-pool/launchpad_config.h diff --git a/src/launchpad-process-pool/src/launchpad_dbus.cc b/src/launchpad-process-pool/launchpad_dbus.cc similarity index 98% rename from src/launchpad-process-pool/src/launchpad_dbus.cc rename to src/launchpad-process-pool/launchpad_dbus.cc index 7beff3d..231b8e4 100644 --- a/src/launchpad-process-pool/src/launchpad_dbus.cc +++ b/src/launchpad-process-pool/launchpad_dbus.cc @@ -14,13 +14,14 @@ * limitations under the License. */ +#include "launchpad-process-pool/launchpad_dbus.h" + #include #include #include #include -#include "launchpad_dbus.h" -#include "log_private.h" +#include "lib/common/inc/log_private.h" #define AUL_DBUS_PATH "/aul/dbus_handler" #define AUL_DBUS_SIGNAL_INTERFACE "org.tizen.aul.signal" diff --git a/src/launchpad-process-pool/inc/launchpad_dbus.h b/src/launchpad-process-pool/launchpad_dbus.h similarity index 100% rename from src/launchpad-process-pool/inc/launchpad_dbus.h rename to src/launchpad-process-pool/launchpad_dbus.h diff --git a/src/launchpad-process-pool/src/launchpad_debug.cc b/src/launchpad-process-pool/launchpad_debug.cc similarity index 97% rename from src/launchpad-process-pool/src/launchpad_debug.cc rename to src/launchpad-process-pool/launchpad_debug.cc index 12f8bdc..d94c194 100644 --- a/src/launchpad-process-pool/src/launchpad_debug.cc +++ b/src/launchpad-process-pool/launchpad_debug.cc @@ -14,6 +14,8 @@ * limitations under the License. */ +#include "launchpad-process-pool/launchpad_debug.h" + #include #include #include @@ -27,11 +29,10 @@ #include -#include "debugger_info.hh" -#include "key.h" -#include "launchpad_common.h" -#include "launchpad_debug.h" -#include "launchpad_types.h" +#include "launchpad-process-pool/debugger_info.hh" +#include "lib/common/inc/key.h" +#include "lib/common/inc/launchpad_common.h" +#include "lib/common/inc/launchpad_types.h" #define DEBUGGER_INFO_PATH "/usr/share/aul" diff --git a/src/launchpad-process-pool/inc/launchpad_debug.h b/src/launchpad-process-pool/launchpad_debug.h similarity index 100% rename from src/launchpad-process-pool/inc/launchpad_debug.h rename to src/launchpad-process-pool/launchpad_debug.h diff --git a/src/launchpad-process-pool/src/launchpad_inotify.cc b/src/launchpad-process-pool/launchpad_inotify.cc similarity index 97% rename from src/launchpad-process-pool/src/launchpad_inotify.cc rename to src/launchpad-process-pool/launchpad_inotify.cc index 2afc91a..82ffcdc 100644 --- a/src/launchpad-process-pool/src/launchpad_inotify.cc +++ b/src/launchpad-process-pool/launchpad_inotify.cc @@ -14,6 +14,8 @@ * limitations under the License. */ +#include "launchpad-process-pool/launchpad_inotify.h" + #include #include #include @@ -21,8 +23,7 @@ #include #include -#include "launchpad_inotify.h" -#include "log_private.h" +#include "lib/common/inc/log_private.h" struct inotify_watch_info_s { int fd; diff --git a/src/launchpad-process-pool/inc/launchpad_inotify.h b/src/launchpad-process-pool/launchpad_inotify.h similarity index 100% rename from src/launchpad-process-pool/inc/launchpad_inotify.h rename to src/launchpad-process-pool/launchpad_inotify.h diff --git a/src/launchpad-process-pool/src/launchpad_io_channel.cc b/src/launchpad-process-pool/launchpad_io_channel.cc similarity index 97% rename from src/launchpad-process-pool/src/launchpad_io_channel.cc rename to src/launchpad-process-pool/launchpad_io_channel.cc index 5987793..9fded4e 100644 --- a/src/launchpad-process-pool/src/launchpad_io_channel.cc +++ b/src/launchpad-process-pool/launchpad_io_channel.cc @@ -14,13 +14,14 @@ * limitations under the License. */ +#include "launchpad-process-pool/launchpad_io_channel.h" + #include #include #include #include -#include "launchpad_io_channel.h" -#include "log_private.h" +#include "lib/common/inc/log_private.h" #define ARRAY_SIZE(x) (sizeof(x) / sizeof(x[0])) diff --git a/src/launchpad-process-pool/inc/launchpad_io_channel.h b/src/launchpad-process-pool/launchpad_io_channel.h similarity index 100% rename from src/launchpad-process-pool/inc/launchpad_io_channel.h rename to src/launchpad-process-pool/launchpad_io_channel.h diff --git a/src/launchpad-process-pool/src/launchpad_log.cc b/src/launchpad-process-pool/launchpad_log.cc similarity index 89% rename from src/launchpad-process-pool/src/launchpad_log.cc rename to src/launchpad-process-pool/launchpad_log.cc index 59128ab..21ade94 100644 --- a/src/launchpad-process-pool/src/launchpad_log.cc +++ b/src/launchpad-process-pool/launchpad_log.cc @@ -14,14 +14,15 @@ * limitations under the License. */ +#include "launchpad-process-pool/launchpad_logger.h" + #include #include #include -#include "launchpad_config.h" -#include "launchpad_log.h" -#include "launchpad_logger.h" -#include "log_private.h" +#include "launchpad-process-pool/launchpad_config.h" +#include "launchpad-process-pool/launchpad_log.h" +#include "lib/common/inc/log_private.h" #define LOG_FILE "launchpad.log" #define PATH_LAUNCHPAD_LOG "/var/log/appfw/launchpad/launchpad.log" diff --git a/src/launchpad-process-pool/inc/launchpad_log.h b/src/launchpad-process-pool/launchpad_log.h similarity index 100% rename from src/launchpad-process-pool/inc/launchpad_log.h rename to src/launchpad-process-pool/launchpad_log.h diff --git a/src/launchpad-process-pool/src/launchpad_logger.cc b/src/launchpad-process-pool/launchpad_logger.cc similarity index 97% rename from src/launchpad-process-pool/src/launchpad_logger.cc rename to src/launchpad-process-pool/launchpad_logger.cc index 592d73e..0de93d1 100644 --- a/src/launchpad-process-pool/src/launchpad_logger.cc +++ b/src/launchpad-process-pool/launchpad_logger.cc @@ -14,6 +14,8 @@ * limitations under the License. */ +#include "launchpad-process-pool/launchpad_logger.h" + #include #include #include @@ -28,9 +30,8 @@ #include #include -#include "launchpad_config.h" -#include "launchpad_logger.h" -#include "log_private.h" +#include "launchpad-process-pool/launchpad_config.h" +#include "lib/common/inc/log_private.h" #define LAUNCHPAD_LOG_APPFW_PATH "/var/log/appfw" #define LAUNCHPAD_LOG_PATH "/var/log/appfw/launchpad" diff --git a/src/launchpad-process-pool/inc/launchpad_logger.h b/src/launchpad-process-pool/launchpad_logger.h similarity index 100% rename from src/launchpad-process-pool/inc/launchpad_logger.h rename to src/launchpad-process-pool/launchpad_logger.h diff --git a/src/launchpad-process-pool/src/launchpad_memory_monitor.cc b/src/launchpad-process-pool/launchpad_memory_monitor.cc similarity index 94% rename from src/launchpad-process-pool/src/launchpad_memory_monitor.cc rename to src/launchpad-process-pool/launchpad_memory_monitor.cc index d2b60ca..c69fe73 100644 --- a/src/launchpad-process-pool/src/launchpad_memory_monitor.cc +++ b/src/launchpad-process-pool/launchpad_memory_monitor.cc @@ -14,16 +14,17 @@ * limitations under the License. */ +#include "launchpad-process-pool/launchpad_memory_monitor.h" + #include #include #include #include #include -#include "launchpad_config.h" -#include "launchpad_memory_monitor.h" -#include "launchpad_proc.h" -#include "log_private.h" +#include "launchpad-process-pool/launchpad_config.h" +#include "lib/common/inc/launchpad_proc.h" +#include "lib/common/inc/log_private.h" #define INTERVAL_BASE_RATE 0.15f diff --git a/src/launchpad-process-pool/inc/launchpad_memory_monitor.h b/src/launchpad-process-pool/launchpad_memory_monitor.h similarity index 100% rename from src/launchpad-process-pool/inc/launchpad_memory_monitor.h rename to src/launchpad-process-pool/launchpad_memory_monitor.h diff --git a/src/launchpad-process-pool/src/launchpad_signal.cc b/src/launchpad-process-pool/launchpad_signal.cc similarity index 96% rename from src/launchpad-process-pool/src/launchpad_signal.cc rename to src/launchpad-process-pool/launchpad_signal.cc index ca305b0..be233a0 100644 --- a/src/launchpad-process-pool/src/launchpad_signal.cc +++ b/src/launchpad-process-pool/launchpad_signal.cc @@ -14,6 +14,8 @@ * limitations under the License. */ +#include "launchpad-process-pool/launchpad_signal.h" + #include #include #include @@ -24,13 +26,12 @@ #include #include -#include "launchpad_common.h" -#include "launchpad_dbus.h" -#include "launchpad_io_channel.h" -#include "launchpad_proc.h" -#include "launchpad_signal.h" -#include "launchpad_socket.h" -#include "log_private.h" +#include "launchpad-process-pool/launchpad_dbus.h" +#include "launchpad-process-pool/launchpad_io_channel.h" +#include "lib/common/inc/launchpad_common.h" +#include "lib/common/inc/launchpad_proc.h" +#include "lib/common/inc/launchpad_socket.h" +#include "lib/common/inc/log_private.h" #define HYDRA_SIGCHLD_SOCK ".hydra-sigchld-sock" diff --git a/src/launchpad-process-pool/inc/launchpad_signal.h b/src/launchpad-process-pool/launchpad_signal.h similarity index 100% rename from src/launchpad-process-pool/inc/launchpad_signal.h rename to src/launchpad-process-pool/launchpad_signal.h diff --git a/src/launchpad-process-pool/src/launchpad_worker.cc b/src/launchpad-process-pool/launchpad_worker.cc similarity index 97% rename from src/launchpad-process-pool/src/launchpad_worker.cc rename to src/launchpad-process-pool/launchpad_worker.cc index 15b53a5..4729e48 100644 --- a/src/launchpad-process-pool/src/launchpad_worker.cc +++ b/src/launchpad-process-pool/launchpad_worker.cc @@ -14,6 +14,8 @@ * limitations under the License. */ +#include "launchpad-process-pool/launchpad_worker.h" + #include #include #include @@ -25,8 +27,7 @@ #include #include -#include "launchpad_worker.h" -#include "log_private.h" +#include "lib/common/inc/log_private.h" struct job_s { worker_job_cb callback; diff --git a/src/launchpad-process-pool/inc/launchpad_worker.h b/src/launchpad-process-pool/launchpad_worker.h similarity index 100% rename from src/launchpad-process-pool/inc/launchpad_worker.h rename to src/launchpad-process-pool/launchpad_worker.h diff --git a/src/launchpad-process-pool/src/loader_info.cc b/src/launchpad-process-pool/loader_info.cc similarity index 99% rename from src/launchpad-process-pool/src/loader_info.cc rename to src/launchpad-process-pool/loader_info.cc index 548dfe1..28e2934 100644 --- a/src/launchpad-process-pool/src/loader_info.cc +++ b/src/launchpad-process-pool/loader_info.cc @@ -14,6 +14,8 @@ * limitations under the License. */ +#include "launchpad-process-pool/loader_info.hh" + #include #include #include @@ -25,9 +27,8 @@ #include #include -#include "launchpad_common.h" -#include "loader_info.hh" -#include "util.hh" +#include "launchpad-process-pool/util.hh" +#include "lib/common/inc/launchpad_common.h" namespace launchpad { namespace { diff --git a/src/launchpad-process-pool/inc/loader_info.hh b/src/launchpad-process-pool/loader_info.hh similarity index 99% rename from src/launchpad-process-pool/inc/loader_info.hh rename to src/launchpad-process-pool/loader_info.hh index d96e029..105aecb 100644 --- a/src/launchpad-process-pool/inc/loader_info.hh +++ b/src/launchpad-process-pool/loader_info.hh @@ -25,7 +25,7 @@ #include #include -#include "util.hh" +#include "launchpad-process-pool/util.hh" namespace launchpad { diff --git a/src/launchpad-process-pool/inc/slot_info.h b/src/launchpad-process-pool/slot_info.h similarity index 100% rename from src/launchpad-process-pool/inc/slot_info.h rename to src/launchpad-process-pool/slot_info.h diff --git a/src/launchpad-process-pool/src/launchpad_config.cc b/src/launchpad-process-pool/src/launchpad_config.cc deleted file mode 100644 index 33a448f..0000000 --- a/src/launchpad-process-pool/src/launchpad_config.cc +++ /dev/null @@ -1,332 +0,0 @@ -/* - * Copyright (c) 2019 Samsung Electronics Co., Ltd All Rights Reserved - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "launchpad_common.h" -#include "launchpad_config.h" - -#define PATH_LAUNCHPAD_CONF "/usr/share/aul/launchpad.conf" -#define TAG_MEMORY_STATUS "MemoryStatus" -#define KEY_MEMORY_STATUS_LOW_KEY "LowKey" -#define KEY_MEMORY_STATUS_LOW_VALUE "LowValue" -#define KEY_MEMORY_STATUS_NORMAL_KEY "NormalKey" -#define KEY_MEMORY_STATUS_NORMAL_VALUE "NormalValue" - -#define TAG_MEMORY_MONITOR "MemoryMonitor" -#define KEY_MEMORY_MONITOR_THRESHOLD "Threshold" -#define KEY_MEMORY_MONITOR_INTERVAL "Interval" - -#define TAG_CPU_CHECKER "CpuChecker" -#define KEY_CPU_CHECKER_MAX_COUNT "MaxCount" - -#define TAG_LOGGER "Logger" -#define KEY_LOGGER_PATH "Path" -#define KEY_LOGGER_ENABLE "Enable" - -struct memory_status_s { - char *low_key; - int low_value; - char *normal_key; - int normal_value; -}; - -struct memory_monitor_s { - int threshold; - int interval; -}; - -struct cpu_checker_s { - int max_count; -}; - -struct logger_s { - char *path; - int enable; -}; - -static struct memory_status_s __memory_status; -static struct memory_monitor_s __memory_monitor; -static struct cpu_checker_s __cpu_checker; -static struct logger_s __logger; - -const char *_config_get_string_value(config_type_e type) -{ - const char *value; - - switch (type) { - case CONFIG_TYPE_MEMORY_STATUS_LOW_KEY: - value = __memory_status.low_key; - break; - case CONFIG_TYPE_MEMORY_STATUS_NORMAL_KEY: - value = __memory_status.normal_key; - break; - case CONFIG_TYPE_LOGGER_PATH: - value = __logger.path; - break; - default: - _E("Unknown type"); - value = NULL; - break; - } - - return value; -} - -int _config_get_int_value(config_type_e type) -{ - int value; - - switch (type) { - case CONFIG_TYPE_MEMORY_STATUS_LOW_VALUE: - value = __memory_status.low_value; - break; - case CONFIG_TYPE_MEMORY_STATUS_NORMAL_VALUE: - value = __memory_status.normal_value; - break; - case CONFIG_TYPE_MEMORY_MONITOR_THRESHOLD: - value = __memory_monitor.threshold; - break; - case CONFIG_TYPE_MEMORY_MONITOR_INTERVAL: - value = __memory_monitor.interval; - break; - case CONFIG_TYPE_CPU_CHECKER_MAX_COUNT: - value = __cpu_checker.max_count; - break; - case CONFIG_TYPE_LOGGER_ENABLE: - value = __logger.enable; - break; - default: - _E("Unknown type"); - value = INT_MIN; - } - - return value; -} - -static const char *__get_string_value(dictionary *d, const char *tag, - const char *key) -{ - char buf[128]; - - snprintf(buf, sizeof(buf), "%s:%s", tag, key); - return iniparser_getstring(d, buf, NULL); -} - -static int __get_int_value(dictionary *d, const char *tag, - const char *key) -{ - char buf[128]; - - snprintf(buf, sizeof(buf), "%s:%s", tag, key); - return iniparser_getint(d, buf, INT_MIN); -} - -static void __memory_status_init(void) -{ - __memory_status.low_key = strdup(VCONFKEY_SYSMAN_LOW_MEMORY); - __memory_status.low_value = VCONFKEY_SYSMAN_LOW_MEMORY_SOFT_WARNING; - __memory_status.normal_key = strdup(VCONFKEY_SYSMAN_LOW_MEMORY); - __memory_status.normal_value = VCONFKEY_SYSMAN_LOW_MEMORY_NORMAL; -} - -static void __memory_status_fini(void) -{ - __memory_status.normal_value = 0; - free(__memory_status.normal_key); - __memory_status.low_value = 0; - free(__memory_status.low_key); -} - -static void __memory_status_set(dictionary *d) -{ - const char *str; - char *val; - int ret; - - str = __get_string_value(d, TAG_MEMORY_STATUS, - KEY_MEMORY_STATUS_LOW_KEY); - if (str) { - val = strdup(str); - if (val) { - free(__memory_status.low_key); - __memory_status.low_key = val; - } - } - - ret = __get_int_value(d, TAG_MEMORY_STATUS, - KEY_MEMORY_STATUS_LOW_VALUE); - if (ret != INT_MIN) - __memory_status.low_value = ret; - - str = __get_string_value(d, TAG_MEMORY_STATUS, - KEY_MEMORY_STATUS_NORMAL_KEY); - if (str) { - val = strdup(str); - if (val) { - free(__memory_status.normal_key); - __memory_status.normal_key = val; - } - } - - ret = __get_int_value(d, TAG_MEMORY_STATUS, - KEY_MEMORY_STATUS_NORMAL_VALUE); - if (ret != INT_MIN) - __memory_status.normal_value = ret; - - _W("Memory Status Low(%s:%d), Normal(%s:%d)", - __memory_status.low_key, - __memory_status.low_value, - __memory_status.normal_key, - __memory_status.normal_value); -} - -static void __memory_monitor_init(void) -{ - __memory_monitor.threshold = 80; /* 80 % */ - __memory_monitor.interval = 5000; /* 5 seconds */ -} - -static void __memory_monitor_fini(void) -{ - __memory_monitor.threshold = 0; - __memory_monitor.interval = 0; -} - -static void __memory_monitor_set(dictionary *d) -{ - int ret; - - ret = __get_int_value(d, TAG_MEMORY_MONITOR, - KEY_MEMORY_MONITOR_THRESHOLD); - if (ret != INT_MIN) - __memory_monitor.threshold = ret; - - ret = __get_int_value(d, TAG_MEMORY_MONITOR, - KEY_MEMORY_MONITOR_INTERVAL); - if (ret != INT_MIN) - __memory_monitor.interval = ret; - - _W("Memory Monitor Threshold(%d), Interval(%d)", - __memory_monitor.threshold, - __memory_monitor.interval); -} - -static void __cpu_checker_init(void) -{ - __cpu_checker.max_count = 10; -} - -static void __cpu_checker_fini(void) -{ - __cpu_checker.max_count = 0; -} - -static void __cpu_checker_set(dictionary *d) -{ - int ret; - - ret = __get_int_value(d, TAG_CPU_CHECKER, - KEY_CPU_CHECKER_MAX_COUNT); - if (ret != INT_MIN) - __cpu_checker.max_count = ret; - - _W("CPU Checker MaxCount(%d)", __cpu_checker.max_count); -} - -static void __logger_init(void) -{ - __logger.path = strdup("/var/log/appfw"); - __logger.enable = false; -} - -static void __logger_fini(void) -{ - free(__logger.path); -} - -static void __logger_set(dictionary *d) -{ - const char *str; - int val; - - str = __get_string_value(d, TAG_LOGGER, - KEY_LOGGER_PATH); - if (str) { - free(__logger.path); - __logger.path = strdup(str); - } - _W("Logger path(%s)", __logger.path); - - val = __get_int_value(d, TAG_LOGGER, - KEY_LOGGER_ENABLE); - if (val >= 0) - __logger.enable = val; - _W("Logger enable(%d)", __logger.enable); -} - -int _config_init(void) -{ - dictionary *d; - int ret; - - _D("config init"); - - __memory_status_init(); - __memory_monitor_init(); - __cpu_checker_init(); - __logger_init(); - - ret = access(PATH_LAUNCHPAD_CONF, F_OK); - if (ret != 0) { - _W("The file doesn't exist. errno(%d)", errno); - return 0; - } - - d = iniparser_load(PATH_LAUNCHPAD_CONF); - if (!d) { - _E("Failed to load the config file"); - return -1; - } - - __memory_status_set(d); - __memory_monitor_set(d); - __cpu_checker_set(d); - __logger_set(d); - - iniparser_freedict(d); - - return 0; -} - -void _config_fini(void) -{ - _D("config fini"); - - __logger_fini(); - __cpu_checker_fini(); - __memory_monitor_fini(); - __memory_status_fini(); -} diff --git a/src/launchpad-process-pool/src/util.cc b/src/launchpad-process-pool/util.cc similarity index 100% rename from src/launchpad-process-pool/src/util.cc rename to src/launchpad-process-pool/util.cc diff --git a/src/launchpad-process-pool/inc/util.hh b/src/launchpad-process-pool/util.hh similarity index 100% rename from src/launchpad-process-pool/inc/util.hh rename to src/launchpad-process-pool/util.hh diff --git a/tests/launchpad-process-pool-unittest/CMakeLists.txt b/tests/launchpad-process-pool-unittest/CMakeLists.txt index c79c682..0fee590 100644 --- a/tests/launchpad-process-pool-unittest/CMakeLists.txt +++ b/tests/launchpad-process-pool-unittest/CMakeLists.txt @@ -5,20 +5,20 @@ INCLUDE(FindPkgConfig) SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -fvisibility=hidden -Wall -Winline") -SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${EXTRA_CFLAGS} -std=c++17 -DUNIT_TEST") +SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${EXTRA_CFLAGS} -std=c++17") SET(CMAKE_CXX_FLAGS_DEBUG "-O0 -g") SET(CMAKE_CXX_FLAGS_RELEASE "-O2") INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/../) INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/../../) INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/../../src/lib/common/inc) -INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/../../src/launchpad-process-pool/inc) +INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/../../src/) AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/src UNITTESTS_SOURCES) AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/../../src/lib/common/src LAUNCHPAD_COMMON_SOURCES) -AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/../../src/launchpad-process-pool/src LAUNCHPAD_PROCESS_POOL_SOURCES) +AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/../../src/launchpad-process-pool LAUNCHPAD_PROCESS_POOL_SOURCES) LIST(REMOVE_ITEM LAUNCHPAD_PROCESS_POOL_SOURCES - "${CMAKE_CURRENT_SOURCE_DIR}/../../src/launchpad-process-pool/src/launchpad.cc" + "${CMAKE_CURRENT_SOURCE_DIR}/../../src/launchpad-process-pool/launchpad.cc" ) ADD_EXECUTABLE(${PROJECT_NAME} diff --git a/tests/launchpad-process-pool-unittest/src/test_launchpad.cc b/tests/launchpad-process-pool-unittest/src/test_launchpad.cc index ad9e83e..5f604bb 100644 --- a/tests/launchpad-process-pool-unittest/src/test_launchpad.cc +++ b/tests/launchpad-process-pool-unittest/src/test_launchpad.cc @@ -23,15 +23,17 @@ #include #include -#include "debugger_info.hh" -#include "launcher_info.hh" -#include "loader_info.hh" +#include "launchpad-process-pool/debugger_info.hh" +#include "launchpad-process-pool/launcher_info.hh" +#include "launchpad-process-pool/loader_info.hh" using ::testing::AtLeast; using namespace launchpad; class LaunchpadTest : public ::testing::Test { public: + LaunchpadTest() = default; + virtual void SetUp() { std::ofstream of; of.open(test_debugger); -- 2.7.4 From df945d328f8e3fd2c90a6a023c606bf6ff49a122 Mon Sep 17 00:00:00 2001 From: Changgyu Choi Date: Thu, 16 Feb 2023 14:04:33 +0900 Subject: [PATCH 03/16] Fix library path for aarch64 Change-Id: I8aa04dccb3d66aadccd31f6571fbab1ad048736e Signed-off-by: Changgyu Choi --- src/lib/launchpad-hydra/src/launchpad_hydra.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib/launchpad-hydra/src/launchpad_hydra.c b/src/lib/launchpad-hydra/src/launchpad_hydra.c index ba385db..e4a2eda 100644 --- a/src/lib/launchpad-hydra/src/launchpad_hydra.c +++ b/src/lib/launchpad-hydra/src/launchpad_hydra.c @@ -100,7 +100,7 @@ static void __fini_signal(void) static int (*__security_manager_prepare_app_candidate)(void); static int __load_security_manager_func(void) { -#define PATH_SECURITY_MANAGER_CLIENT "/usr/lib/libsecurity-manager-client.so.3" +#define PATH_SECURITY_MANAGER_CLIENT LIBDIR"/libsecurity-manager-client.so.3" void *handle; handle = dlopen(PATH_SECURITY_MANAGER_CLIENT, RTLD_LAZY | RTLD_LOCAL); -- 2.7.4 From 100678dd3dd282881f51f4407701edad5b1f157e Mon Sep 17 00:00:00 2001 From: Changgyu Choi Date: Thu, 16 Feb 2023 14:04:33 +0900 Subject: [PATCH 04/16] Rename sample loader lib path args to /test Change-Id: I8aa04dccb3d66aadccd31f6571fbab1ad048736e Signed-off-by: Changgyu Choi --- .../src/test_launchpad.cc | 54 +++++++++++----------- 1 file changed, 27 insertions(+), 27 deletions(-) diff --git a/tests/launchpad-process-pool-unittest/src/test_launchpad.cc b/tests/launchpad-process-pool-unittest/src/test_launchpad.cc index 5f604bb..0133f12 100644 --- a/tests/launchpad-process-pool-unittest/src/test_launchpad.cc +++ b/tests/launchpad-process-pool-unittest/src/test_launchpad.cc @@ -89,15 +89,15 @@ DETECTION_METHOD TIMEOUT|VISIBILITY TIMEOUT 5000 EXTRA loader_type hw-loader EXTRA_ARRAY preload -EXTRA_ARRAY_VAL /usr/lib/libappcore-efl.so.1 -EXTRA_ARRAY_VAL /usr/lib/libappcore-common.so.1 -EXTRA_ARRAY_VAL /usr/lib/libcapi-appfw-application.so.0 -EXTRA_ARRAY_VAL /usr/lib/ecore_imf/modules/wayland/v-1.25/module.so -EXTRA_ARRAY_VAL /usr/lib/libdali-toolkit.so -EXTRA_ARRAY_VAL /usr/lib/libcairo.so.2 -EXTRA_ARRAY_VAL /usr/lib/libcapi-media-player.so.0 -EXTRA_ARRAY_VAL /usr/lib/libcapi-media-camera.so.0 -EXTRA_ARRAY_VAL /usr/lib/ecore_evas/engines/extn/v-1.25/module.so +EXTRA_ARRAY_VAL /test/libappcore-efl.so.1 +EXTRA_ARRAY_VAL /test/libappcore-common.so.1 +EXTRA_ARRAY_VAL /test/libcapi-appfw-application.so.0 +EXTRA_ARRAY_VAL /test/ecore_imf/modules/wayland/v-1.25/module.so +EXTRA_ARRAY_VAL /test/libdali-toolkit.so +EXTRA_ARRAY_VAL /test/libcairo.so.2 +EXTRA_ARRAY_VAL /test/libcapi-media-player.so.0 +EXTRA_ARRAY_VAL /test/libcapi-media-camera.so.0 +EXTRA_ARRAY_VAL /test/ecore_evas/engines/extn/v-1.25/module.so ALTERNATIVE_LOADER common-loader1 EXTRA threads 7 @@ -194,15 +194,15 @@ DETECTION_METHOD TIMEOUT|VISIBILITY TIMEOUT 5000 EXTRA loader_type hw-loader EXTRA_ARRAY preload -EXTRA_ARRAY_VAL /usr/lib/libappcore-efl.so.1 -EXTRA_ARRAY_VAL /usr/lib/libappcore-common.so.1 -EXTRA_ARRAY_VAL /usr/lib/libcapi-appfw-application.so.0 -EXTRA_ARRAY_VAL /usr/lib/ecore_imf/modules/wayland/v-1.25/module.so -EXTRA_ARRAY_VAL /usr/lib/libdali-toolkit.so -EXTRA_ARRAY_VAL /usr/lib/libcairo.so.2 -EXTRA_ARRAY_VAL /usr/lib/libcapi-media-player.so.0 -EXTRA_ARRAY_VAL /usr/lib/libcapi-media-camera.so.0 -EXTRA_ARRAY_VAL /usr/lib/ecore_evas/engines/extn/v-1.25/module.so +EXTRA_ARRAY_VAL /test/libappcore-efl.so.1 +EXTRA_ARRAY_VAL /test/libappcore-common.so.1 +EXTRA_ARRAY_VAL /test/libcapi-appfw-application.so.0 +EXTRA_ARRAY_VAL /test/ecore_imf/modules/wayland/v-1.25/module.so +EXTRA_ARRAY_VAL /test/libdali-toolkit.so +EXTRA_ARRAY_VAL /test/libcairo.so.2 +EXTRA_ARRAY_VAL /test/libcapi-media-player.so.0 +EXTRA_ARRAY_VAL /test/libcapi-media-camera.so.0 +EXTRA_ARRAY_VAL /test/ecore_evas/engines/extn/v-1.25/module.so ALTERNATIVE_LOADER common-loader1 EXTRA threads 7 */ @@ -226,13 +226,13 @@ EXTRA threads 7 EXPECT_EQ(b.GetString("threads"), "7"); auto arr = b.GetStringArray("preload"); EXPECT_EQ(arr.size(), 9); - EXPECT_EQ(arr[0], "/usr/lib/libappcore-efl.so.1"); - EXPECT_EQ(arr[1], "/usr/lib/libappcore-common.so.1"); - EXPECT_EQ(arr[2], "/usr/lib/libcapi-appfw-application.so.0"); - EXPECT_EQ(arr[3], "/usr/lib/ecore_imf/modules/wayland/v-1.25/module.so"); - EXPECT_EQ(arr[4], "/usr/lib/libdali-toolkit.so"); - EXPECT_EQ(arr[5], "/usr/lib/libcairo.so.2"); - EXPECT_EQ(arr[6], "/usr/lib/libcapi-media-player.so.0"); - EXPECT_EQ(arr[7], "/usr/lib/libcapi-media-camera.so.0"); - EXPECT_EQ(arr[8], "/usr/lib/ecore_evas/engines/extn/v-1.25/module.so"); + EXPECT_EQ(arr[0], "/test/libappcore-efl.so.1"); + EXPECT_EQ(arr[1], "/test/libappcore-common.so.1"); + EXPECT_EQ(arr[2], "/test/libcapi-appfw-application.so.0"); + EXPECT_EQ(arr[3], "/test/ecore_imf/modules/wayland/v-1.25/module.so"); + EXPECT_EQ(arr[4], "/test/libdali-toolkit.so"); + EXPECT_EQ(arr[5], "/test/libcairo.so.2"); + EXPECT_EQ(arr[6], "/test/libcapi-media-player.so.0"); + EXPECT_EQ(arr[7], "/test/libcapi-media-camera.so.0"); + EXPECT_EQ(arr[8], "/test/ecore_evas/engines/extn/v-1.25/module.so"); } -- 2.7.4 From 86016df1eb169520491f11cc17d492798b03f0e1 Mon Sep 17 00:00:00 2001 From: Changgyu Choi Date: Thu, 16 Feb 2023 14:20:16 +0900 Subject: [PATCH 05/16] Release version 0.24.0 Changes: - Refactor launchpad to c++ - Add unittest - Modify launchpad-process-pool directory structure - Fix library path for aarch64 - Rename sample loader lib path args to /test Change-Id: I846cd507e348b330bea0ae5d3eb44d2cfc231f49 Signed-off-by: Changgyu Choi --- packaging/launchpad.spec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packaging/launchpad.spec b/packaging/launchpad.spec index 413133e..bee045b 100644 --- a/packaging/launchpad.spec +++ b/packaging/launchpad.spec @@ -1,6 +1,6 @@ Name: launchpad Summary: Launchpad for launching applications -Version: 0.23.2 +Version: 0.24.0 Release: 1 Group: Application Framework/Daemons License: Apache-2.0 -- 2.7.4 From 5cbc42a2864441f9c20978031fa35d8df0903cd2 Mon Sep 17 00:00:00 2001 From: "jh9216.park" Date: Mon, 27 Feb 2023 01:14:05 -0500 Subject: [PATCH 06/16] Fix lib dir Change-Id: I8c44ae1304579b250937d5568ae751b36e9854b2 Signed-off-by: jh9216.park --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 02e8130..fb3253d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -12,7 +12,7 @@ ADD_DEFINITIONS("-DSHARE_PREFIX=\"/usr/share/aul\"") ADD_DEFINITIONS("-DLAUNCHPAD_LOG") ADD_DEFINITIONS("-DPRELOAD_ACTIVATE") ADD_DEFINITIONS("-DPREEXEC_ACTIVATE") -ADD_DEFINITIONS("-DLIBDIR=\"${LIBDIR}\"") +ADD_DEFINITIONS("-DLIBDIR=\"${CMAKE_INSTALL_LIBDIR}\"") ## Compile flags SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall") -- 2.7.4 From 6cfdbba4a3a2dd835eda824a2c26dd9b8d546fcf Mon Sep 17 00:00:00 2001 From: "jh9216.park" Date: Mon, 27 Feb 2023 02:53:38 -0500 Subject: [PATCH 07/16] Release version 0.24.1 Changes: - Fix lib dir Signed-off-by: jh9216.park Change-Id: I47ebc7a50bb2b6454e24316b2bfe7d409da723de --- packaging/launchpad.spec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packaging/launchpad.spec b/packaging/launchpad.spec index bee045b..75c1184 100644 --- a/packaging/launchpad.spec +++ b/packaging/launchpad.spec @@ -1,6 +1,6 @@ Name: launchpad Summary: Launchpad for launching applications -Version: 0.24.0 +Version: 0.24.1 Release: 1 Group: Application Framework/Daemons License: Apache-2.0 -- 2.7.4 From ead07566d0cef544849d541733d7decd3a53be81 Mon Sep 17 00:00:00 2001 From: Hwankyu Jhun Date: Thu, 2 Mar 2023 23:34:02 +0000 Subject: [PATCH 08/16] Fix wrong initialization The memory monitor initialization should be called before adding default slots. If the threshold is greater than 100, the memory monitor should be disabled. Change-Id: I64ce56d5d73c3a61bccec425827567ad37c2c640 Signed-off-by: Hwankyu Jhun --- src/launchpad-process-pool/launchpad.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/launchpad-process-pool/launchpad.cc b/src/launchpad-process-pool/launchpad.cc index 6fd6ef4..88d0f39 100644 --- a/src/launchpad-process-pool/launchpad.cc +++ b/src/launchpad-process-pool/launchpad.cc @@ -3351,6 +3351,8 @@ static int __before_loop(int argc, char** argv) { _W("Failed to initialize dbus"); _inotify_init(); + _memory_monitor_init(); + _memory_monitor_set_event_cb(__memory_monitor_cb, nullptr); MAX_CPU_CHECK_COUNT = _config_get_int_value(CONFIG_TYPE_CPU_CHECKER_MAX_COUNT); @@ -3378,8 +3380,6 @@ static int __before_loop(int argc, char** argv) { __register_vconf_events(); __init_app_defined_loader_monitor(); - _memory_monitor_init(); - _memory_monitor_set_event_cb(__memory_monitor_cb, nullptr); _log_init(); _print_hwc_log("%s(%d): END", __FUNCTION__, __LINE__); -- 2.7.4 From 3060248ac37c5760aac53a1360d3d2967c86a637 Mon Sep 17 00:00:00 2001 From: Hwankyu Jhun Date: Fri, 3 Mar 2023 00:00:36 +0000 Subject: [PATCH 09/16] Release version 0.24.2 Changes: - Fix wrong initialization Change-Id: I4a33cefab8c9ededaa69459aa1b004f26152f8d2 Signed-off-by: Hwankyu Jhun --- packaging/launchpad.spec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packaging/launchpad.spec b/packaging/launchpad.spec index 75c1184..2f6809d 100644 --- a/packaging/launchpad.spec +++ b/packaging/launchpad.spec @@ -1,6 +1,6 @@ Name: launchpad Summary: Launchpad for launching applications -Version: 0.24.1 +Version: 0.24.2 Release: 1 Group: Application Framework/Daemons License: Apache-2.0 -- 2.7.4 From 27662bc8d8303f5d2e32f3610bf2d494cddce66c Mon Sep 17 00:00:00 2001 From: Hwankyu Jhun Date: Fri, 3 Mar 2023 05:35:22 +0000 Subject: [PATCH 10/16] Remove build warning messages This patch fixes build warnings. Change-Id: If38a108c401b91bc429dd2b5e59efd494c88ec1f Signed-off-by: Hwankyu Jhun --- src/launchpad-process-pool/launchpad.cc | 5 +- src/launchpad-process-pool/launchpad_io_channel.cc | 6 +- src/launchpad-process-pool/launchpad_log.cc | 2 +- src/launchpad-process-pool/launchpad_logger.cc | 2 +- .../launchpad-process-pool-unittest/CMakeLists.txt | 2 +- .../src/test_launchpad.cc | 112 +++++++-------------- 6 files changed, 43 insertions(+), 86 deletions(-) diff --git a/src/launchpad-process-pool/launchpad.cc b/src/launchpad-process-pool/launchpad.cc index 88d0f39..71a67df 100644 --- a/src/launchpad-process-pool/launchpad.cc +++ b/src/launchpad-process-pool/launchpad.cc @@ -1253,7 +1253,7 @@ static void __real_launch(const char* app_path, int ret; if (bundle_get_val(kb, AUL_K_DEBUG) != nullptr) - putenv("TIZEN_DEBUGGING_PORT=1"); + setenv("TIZEN_DEBUGGING_PORT", "1", 1); ret = __create_app_argv(&app_argc, &app_argv, app_path, kb, menu_info->app_type); @@ -2155,7 +2155,6 @@ static void __foreach_loader_info(const launchpad::LoaderInfoPtr& info, } static int __dispatch_cmd_update_app_type(bundle* b) { - int r; struct app_info info; const char* is_installed; @@ -2924,7 +2923,7 @@ static int __verify_loader_caps(const char* loader) { } static void __get_app_type_string(const launchpad::LoaderInfoPtr& info, - char buf[], int size) { + char buf[], size_t size) { char* ptr = buf; for (auto& app_type : info->GetAppTypes()) { diff --git a/src/launchpad-process-pool/launchpad_io_channel.cc b/src/launchpad-process-pool/launchpad_io_channel.cc index 9fded4e..e74bc0c 100644 --- a/src/launchpad-process-pool/launchpad_io_channel.cc +++ b/src/launchpad-process-pool/launchpad_io_channel.cc @@ -52,9 +52,8 @@ static struct io_condition_s __cond_map[] = { static io_condition_e __convert_g_io_condition(GIOCondition cond) { int condition = 0; - int i; - for (i = 0; i < ARRAY_SIZE(__cond_map); i++) { + for (unsigned int i = 0; i < ARRAY_SIZE(__cond_map); i++) { if (__cond_map[i].g_io_cond & cond) condition |= __cond_map[i].io_cond; } @@ -64,9 +63,8 @@ static io_condition_e __convert_g_io_condition(GIOCondition cond) { static GIOCondition __convert_io_condition(io_condition_e cond) { int condition = 0; - int i; - for (i = 0; i < ARRAY_SIZE(__cond_map); i++) { + for (unsigned int i = 0; i < ARRAY_SIZE(__cond_map); i++) { if (__cond_map[i].io_cond & cond) condition |= __cond_map[i].g_io_cond; } diff --git a/src/launchpad-process-pool/launchpad_log.cc b/src/launchpad-process-pool/launchpad_log.cc index 21ade94..ebe7323 100644 --- a/src/launchpad-process-pool/launchpad_log.cc +++ b/src/launchpad-process-pool/launchpad_log.cc @@ -40,7 +40,7 @@ int _log_print(const char* tag, const char* format, ...) { va_start(ap, format); ret = vsnprintf(formatted_buf, sizeof(formatted_buf), format, ap); va_end(ap); - if (ret < 0 || ret >= sizeof(formatted_buf)) { + if (ret < 0 || static_cast(ret) >= sizeof(formatted_buf)) { _E("vsnprintf() is failed. result(%d)", ret); return -1; } diff --git a/src/launchpad-process-pool/launchpad_logger.cc b/src/launchpad-process-pool/launchpad_logger.cc index 0de93d1..91c9c7d 100644 --- a/src/launchpad-process-pool/launchpad_logger.cc +++ b/src/launchpad-process-pool/launchpad_logger.cc @@ -204,7 +204,7 @@ int _logger_print(logger_h handle, const char* tag, const char* format, ...) { va_start(ap, format); bytes = vsnprintf(format_buf, sizeof(format_buf), format, ap); va_end(ap); - if (bytes < 0 || bytes >= sizeof(format_buf)) { + if (bytes < 0 || static_cast(bytes) >= sizeof(format_buf)) { _E("vsnprintf() is failed. result(%d)", bytes); return -1; } diff --git a/tests/launchpad-process-pool-unittest/CMakeLists.txt b/tests/launchpad-process-pool-unittest/CMakeLists.txt index 0fee590..2f77f1a 100644 --- a/tests/launchpad-process-pool-unittest/CMakeLists.txt +++ b/tests/launchpad-process-pool-unittest/CMakeLists.txt @@ -3,7 +3,7 @@ PROJECT(launchpad-process-pool-unittest C CXX) INCLUDE(FindPkgConfig) -SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -fvisibility=hidden -Wall -Winline") +SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -fvisibility=hidden -Wall") SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${EXTRA_CFLAGS} -std=c++17") SET(CMAKE_CXX_FLAGS_DEBUG "-O0 -g") diff --git a/tests/launchpad-process-pool-unittest/src/test_launchpad.cc b/tests/launchpad-process-pool-unittest/src/test_launchpad.cc index 0133f12..d332ebb 100644 --- a/tests/launchpad-process-pool-unittest/src/test_launchpad.cc +++ b/tests/launchpad-process-pool-unittest/src/test_launchpad.cc @@ -30,26 +30,10 @@ using ::testing::AtLeast; using namespace launchpad; -class LaunchpadTest : public ::testing::Test { - public: - LaunchpadTest() = default; - - virtual void SetUp() { - std::ofstream of; - of.open(test_debugger); - of << test_debugger; - of.close(); - - of.open(test_launcher); - of << test_launcher; - of.close(); +namespace { - of.open(test_loader); - of << test_loader; - of.close(); - - of.open(test_debugger_info_file); - of << R"__test( +constexpr const char TEST_DEBUGGER[] = +R"__test( [DEBUGGER] NAME DEBUG EXE test_debugger @@ -60,10 +44,9 @@ DEFAULT_OPT env DEFAULT_OPT OPENSSL_armcap=0 DEFAULT_OPT -- )__test"; - of.close(); - of.open(test_launcher_info_file); - of << R"__test( +constexpr const char TEST_LAUNCHER[] = +R"__test( [LAUNCHER] NAME dotnet-launcher EXE test_launcher @@ -76,10 +59,9 @@ EXTRA_ARG TIZEN_UIFW EXTRA_ARG ElmSharp EXTRA_ARG --standalone )__test"; - of.close(); - of.open(test_loader_info_file); - of << R"__test( +constexpr const char TEST_LOADER[] = +R"__test( [LOADER] NAME hw-loader1 EXE /usr/bin/launchpad-loader @@ -100,8 +82,36 @@ EXTRA_ARRAY_VAL /test/libcapi-media-camera.so.0 EXTRA_ARRAY_VAL /test/ecore_evas/engines/extn/v-1.25/module.so ALTERNATIVE_LOADER common-loader1 EXTRA threads 7 - )__test"; + +} // namespace + +class LaunchpadTest : public ::testing::Test { + public: + virtual void SetUp() { + std::ofstream of; + of.open(test_debugger); + of << test_debugger; + of.close(); + + of.open(test_launcher); + of << test_launcher; + of.close(); + + of.open(test_loader); + of << test_loader; + of.close(); + + of.open(test_debugger_info_file); + of << TEST_DEBUGGER; + of.close(); + + of.open(test_launcher_info_file); + of << TEST_LAUNCHER; + of.close(); + + of.open(test_loader_info_file); + of << TEST_LOADER; of.close(); } @@ -117,18 +127,6 @@ EXTRA threads 7 }; TEST_F(LaunchpadTest, DebuggerInfoTest) { - /* Test debugger info file - [DEBUGGER] - NAME DEBUG - EXE test_debugger - APP_TYPE capp|c++app - EXTRA_KEY __DLP_DEBUG_ARG__ - DEFAULT_OPT --wrapper - DEFAULT_OPT env - DEFAULT_OPT OPENSSL_armcap=0 - DEFAULT_OPT -- - */ - DebuggerInfoInflator inflator; auto list = inflator.Inflate("."); EXPECT_EQ(list.size(), 1); @@ -148,21 +146,6 @@ TEST_F(LaunchpadTest, DebuggerInfoTest) { } TEST_F(LaunchpadTest, LauncherInfoTest) { - /* Test launcher info file - [LAUNCHER] - NAME dotnet-launcher - EXE test_launcher - APP_TYPE dotnet - EXTRA_ARG - --PADDING_TO_CHANGE_CMDLINE_PADDING_TO_CHANGE_CMDLINE_PADDING_TO_CHANGE_CMDLINE_PADDING_TO_CHANGE_CMDLINE - EXTRA_ARG --profile - EXTRA_ARG --appType - EXTRA_ARG dotnet - EXTRA_ARG TIZEN_UIFW - EXTRA_ARG ElmSharp - EXTRA_ARG --standalone - */ - LauncherInfoInflator inflator; auto list = inflator.Inflate("."); EXPECT_EQ(list.size(), 1); @@ -184,29 +167,6 @@ TEST_F(LaunchpadTest, LauncherInfoTest) { } TEST_F(LaunchpadTest, LoaderInfoTest) { -/* Test loader info file -[LOADER] -NAME hw-loader1 -EXE /usr/bin/launchpad-loader -APP_TYPE capp|c++app -HW_ACC ON -DETECTION_METHOD TIMEOUT|VISIBILITY -TIMEOUT 5000 -EXTRA loader_type hw-loader -EXTRA_ARRAY preload -EXTRA_ARRAY_VAL /test/libappcore-efl.so.1 -EXTRA_ARRAY_VAL /test/libappcore-common.so.1 -EXTRA_ARRAY_VAL /test/libcapi-appfw-application.so.0 -EXTRA_ARRAY_VAL /test/ecore_imf/modules/wayland/v-1.25/module.so -EXTRA_ARRAY_VAL /test/libdali-toolkit.so -EXTRA_ARRAY_VAL /test/libcairo.so.2 -EXTRA_ARRAY_VAL /test/libcapi-media-player.so.0 -EXTRA_ARRAY_VAL /test/libcapi-media-camera.so.0 -EXTRA_ARRAY_VAL /test/ecore_evas/engines/extn/v-1.25/module.so -ALTERNATIVE_LOADER common-loader1 -EXTRA threads 7 -*/ - LoaderInfoInflator inflator; auto list = inflator.Inflate("."); EXPECT_EQ(list.size(), 1); -- 2.7.4 From 7c182aa6d7f981fc3894fb0c39618e6beb27de3f Mon Sep 17 00:00:00 2001 From: Hwankyu Jhun Date: Fri, 3 Mar 2023 04:49:55 +0000 Subject: [PATCH 11/16] Delete unused files after process shutdown After the process is terminated, the launchpad deletes unnecessary files. To debug & profile dotnet applications, the coreclr creates "clr-debug-pipe-" and "dotnet-diagnostic-" files. The launchpad deletes the files if the files exists. To avoid blocking the main thread of the launchpad, this patch creates a new worker thread that is "RecycleBin+". Change-Id: I68e02359ed2ec79801b46da2f45ef54b5c35f4b9 Signed-off-by: Hwankyu Jhun --- src/launchpad-process-pool/launchpad_signal.cc | 84 ++++++++++++++++++++++---- 1 file changed, 72 insertions(+), 12 deletions(-) diff --git a/src/launchpad-process-pool/launchpad_signal.cc b/src/launchpad-process-pool/launchpad_signal.cc index be233a0..0082b84 100644 --- a/src/launchpad-process-pool/launchpad_signal.cc +++ b/src/launchpad-process-pool/launchpad_signal.cc @@ -26,24 +26,34 @@ #include #include +#include +#include + #include "launchpad-process-pool/launchpad_dbus.h" #include "launchpad-process-pool/launchpad_io_channel.h" +#include "launchpad-process-pool/launchpad_worker.h" #include "lib/common/inc/launchpad_common.h" #include "lib/common/inc/launchpad_proc.h" #include "lib/common/inc/launchpad_socket.h" #include "lib/common/inc/log_private.h" -#define HYDRA_SIGCHLD_SOCK ".hydra-sigchld-sock" +namespace { + +constexpr const char HYDRA_SIGCHLD_SOCK[] = ".hydra-sigchld-sock"; + +pid_t __pid; +sigset_t __mask; +sigset_t __old_mask; +socket_h __sigchld_socket; +io_channel_h __sigchld_channel; +socket_h __hydra_sigchld_socket; +io_channel_h __hydra_sigchld_channel; +signal_sigchld_cb __callback; +void* __user_data; + +worker_h recycle_bin; -static pid_t __pid; -static sigset_t __mask; -static sigset_t __old_mask; -static socket_h __sigchld_socket; -static io_channel_h __sigchld_channel; -static socket_h __hydra_sigchld_socket; -static io_channel_h __hydra_sigchld_channel; -static signal_sigchld_cb __callback; -static void* __user_data; +} // namespace static gboolean __hydra_sigchld_recovery_cb(gpointer data); static gboolean __sigchld_recovery_cb(gpointer data); @@ -69,10 +79,51 @@ static void __socket_garbage_collector(void) { closedir(dp); } -static void __sigchld_action(int pid) { - _dbus_send_app_dead_signal(pid); +static void __delete_unused_files(pid_t pid) { + std::vector files = { + "clr-debug-pipe-" + std::to_string(pid) + "-", + "dotnet-diagnostic-" + std::to_string(pid) + "-" + }; + + DIR* dp = opendir("/tmp"); + if (dp == nullptr) { + _E("opendir() is failed"); + return; + } + + struct dirent* dentry = nullptr; + while ((dentry = readdir(dp)) != nullptr) { + if (dentry->d_name[0] == '.') + continue; + + if (dentry->d_name[0] != 'c' && dentry->d_name[0] != 'd') + continue; + + for (size_t i = 0; i < files.size(); ++i) { + if (files[i].compare(0, files[i].length(), dentry->d_name, 0, + files[i].length()) == 0) { + std::string path = std::string("/tmp/") + dentry->d_name; + unlink(path.c_str()); + _W("unlink(%s)", path.c_str()); + } + } + } + closedir(dp); +} + +static bool __garbage_collector(void *user_data) { + pid_t pid = GPOINTER_TO_INT( + reinterpret_cast(user_data) & UINT32_MAX); + _W("pid(%d)", pid); _delete_sock_path(pid, getuid()); + __delete_unused_files(pid); __socket_garbage_collector(); + return false; +} + +static void __sigchld_action(int pid) { + _dbus_send_app_dead_signal(pid); + _worker_add_job(recycle_bin, __garbage_collector, GINT_TO_POINTER(pid)); } static int __check_permission(int pid) { @@ -377,6 +428,12 @@ int _signal_init(void) { } } + ret = _worker_create("RecycleBin+", &recycle_bin); + if (ret < 0) { + _E("_worker_create() is failed"); + return ret; + } + return 0; } @@ -389,6 +446,9 @@ void _signal_fini(void) { #endif _D("SIGNAL_FINI"); + if (getpid() == __pid) + _worker_destroy(recycle_bin); + _signal_set_sigchld_cb(nullptr, nullptr); __hydra_sigchld_fini(); __sigchld_fini(); -- 2.7.4 From bfe47de98b22be28f1f7db06d242207549eb60f5 Mon Sep 17 00:00:00 2001 From: Hwankyu Jhun Date: Mon, 6 Mar 2023 01:13:15 +0000 Subject: [PATCH 12/16] Release version 0.24.3 Changes: - Remove build warning messages - Delete unused files after process shutdown Change-Id: Ic1d2e4fd755130f98597cde93354584518b33c23 Signed-off-by: Hwankyu Jhun --- packaging/launchpad.spec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packaging/launchpad.spec b/packaging/launchpad.spec index 2f6809d..e4081d1 100644 --- a/packaging/launchpad.spec +++ b/packaging/launchpad.spec @@ -1,6 +1,6 @@ Name: launchpad Summary: Launchpad for launching applications -Version: 0.24.2 +Version: 0.24.3 Release: 1 Group: Application Framework/Daemons License: Apache-2.0 -- 2.7.4 From 5a81d05e9f6fb8e332b651e2beee5bafb7a43c93 Mon Sep 17 00:00:00 2001 From: Hwankyu Jhun Date: Mon, 6 Mar 2023 04:01:23 +0000 Subject: [PATCH 13/16] Add a new option to the loader configuration The "CONDITION_PATH_EXISTS" option is added to the loader configuration. The option is for the "ON_BOOT_TIMEOUT" option. If the path does not exist, the launchpad does not prepare the candidate process. And, the launchpad adds a timer to wait until the path exists. The interval of the timer is 100 ms. Change-Id: I626b25ef8448079bd7fba90f76e7815a2934574b Signed-off-by: Hwankyu Jhun --- src/launchpad-process-pool/launchpad.cc | 28 ++++++++++++++++++---- src/launchpad-process-pool/loader_info.cc | 17 +++++++++++++ src/launchpad-process-pool/loader_info.hh | 4 ++++ src/launchpad-process-pool/slot_info.h | 4 ++++ .../src/test_launchpad.cc | 11 ++++++--- 5 files changed, 56 insertions(+), 8 deletions(-) diff --git a/src/launchpad-process-pool/launchpad.cc b/src/launchpad-process-pool/launchpad.cc index 71a67df..9a7b293 100644 --- a/src/launchpad-process-pool/launchpad.cc +++ b/src/launchpad-process-pool/launchpad.cc @@ -132,6 +132,7 @@ typedef struct { int on_boot_timeout; guint on_boot_timer; int sched_priority; + std::vector condition_path_exists; } candidate_process_context_t; typedef struct { @@ -1830,6 +1831,19 @@ static gboolean __on_boot_timeout_cb(gpointer user_data) { _E("Candidate process is already running. %d:%s:%d", context->type, context->loader_name, context->pid); } else { + auto iter = context->condition_path_exists.begin(); + while (iter != context->condition_path_exists.end()) { + auto& path = *iter; + if (access(path.c_str(), F_OK) != 0) { + _D("%s does not exist", path.c_str()); + context->on_boot_timer = g_timeout_add(100, __on_boot_timeout_cb, + context); + return G_SOURCE_REMOVE; + } + + iter = context->condition_path_exists.erase(iter); + } + __prepare_candidate_process(context->type, context->loader_id); context->touched = true; } @@ -2585,14 +2599,13 @@ static void __destroy_slot(candidate_process_context_t* cpc) { if (cpc->loader_name) free(cpc->loader_name); - free(cpc); + delete cpc; } static candidate_process_context_t* __create_slot(slot_info_t* info) { candidate_process_context_t* cpc; - cpc = static_cast( - calloc(1, sizeof(candidate_process_context_t))); + cpc = new candidate_process_context_t(); if (cpc == nullptr) { _E("Out of memory"); return nullptr; @@ -2647,11 +2660,16 @@ static candidate_process_context_t* __create_slot(slot_info_t* info) { cpc->live_timer = 0; cpc->is_hydra = info->is_hydra; cpc->app_check = info->app_check; + cpc->client_channel = nullptr; + cpc->channel = nullptr; + cpc->hydra_channel = nullptr; cpc->score = WIN_SCORE; cpc->pss = 0; cpc->cpu_check_count = 0; cpc->on_boot_timeout = info->on_boot_timeout; + cpc->on_boot_timer = 0; cpc->sched_priority = info->sched_priority; + cpc->condition_path_exists = info->condition_path_exists; if ((cpc->deactivation_method & static_cast(launchpad::LoaderMethod::OutOfMemory)) && __is_low_memory()) cpc->state = CANDIDATE_PROCESS_STATE_PAUSED; @@ -2946,7 +2964,6 @@ static void __add_slot_from_info(const launchpad::LoaderInfoPtr& info) { 0, }; - // TODO(changyu.choi): slot_info will be implemented to refer to loader_info slot_info_t slot_info = { .type = LAUNCHPAD_LOADER_TYPE_USER + user_slot_offset, .loader_name = info->GetName().c_str(), @@ -2957,7 +2974,8 @@ static void __add_slot_from_info(const launchpad::LoaderInfoPtr& info) { .is_hydra = info->IsHydraEnabled(), .app_check = info->IsNeededAppCheck(), .on_boot_timeout = info->GetOnbootTimeout(), - .sched_priority = info->GetSchedPriority() + .sched_priority = info->GetSchedPriority(), + .condition_path_exists = info->GetConditionPathExists() }; if (info->GetExe() == "null") { diff --git a/src/launchpad-process-pool/loader_info.cc b/src/launchpad-process-pool/loader_info.cc index 28e2934..465c8a1 100644 --- a/src/launchpad-process-pool/loader_info.cc +++ b/src/launchpad-process-pool/loader_info.cc @@ -54,6 +54,7 @@ constexpr const char kTagHydra[] = "HYDRA"; constexpr const char kTagAppCheck[] = "APP_CHECK"; constexpr const char kTagOnBootTimeout[] = "ON_BOOT_TIMEOUT"; constexpr const char kTagSchedPriority[] = "SCHED_PRIORITY"; +constexpr const char kTagConditionPathExists[] = "CONDITION_PATH_EXISTS"; constexpr const char kValOn[] = "ON"; constexpr const char kValOff[] = "OFF"; @@ -144,6 +145,16 @@ void LoaderInfoInflator::ParseAppTypes(const LoaderInfoPtr& info, } while (std::getline(ss, line)); } +void LoaderInfoInflator::ParseConditionPathExists(const LoaderInfoPtr& info, + const std::string& tok_start, std::istringstream& stream) { + std::string line = tok_start; + do { + auto tokens = Split(line, " |\t\r\n"); + for (auto& token : tokens) + info->condition_path_exists_.push_back(std::move(token)); + } while (std::getline(stream, line)); +} + void LoaderInfoInflator::Parse(std::vector& loader_info_list, const fs::path& path) { std::ifstream fp; @@ -234,6 +245,8 @@ void LoaderInfoInflator::Parse(std::vector& loader_info_list, info->on_boot_timeout_ = std::stoi(tok2); } else if (kTagSchedPriority == key) { info->sched_priority_ = std::min(std::max(std::stoi(tok2), -20), 19); + } else if (key == kTagConditionPathExists) { + ParseConditionPathExists(info, tok2, ss); } } @@ -330,6 +343,10 @@ void LoaderInfo::SetAppExists(bool exists) { app_exists_ = exists; } +const std::vector& LoaderInfo::GetConditionPathExists() const { + return condition_path_exists_; +} + std::vector LoaderInfoInflator::Inflate( const std::string_view path) { fs::path p(path); diff --git a/src/launchpad-process-pool/loader_info.hh b/src/launchpad-process-pool/loader_info.hh index 105aecb..af12572 100644 --- a/src/launchpad-process-pool/loader_info.hh +++ b/src/launchpad-process-pool/loader_info.hh @@ -74,6 +74,7 @@ class LoaderInfo { tizen_base::Bundle& GetExtra(); void SetType(LoaderType type); void SetAppExists(bool exsits); + const std::vector& GetConditionPathExists() const; private: LoaderType type_ = LoaderType::Unsupported; @@ -98,6 +99,7 @@ class LoaderInfo { bool app_check_ = true; int on_boot_timeout_ = 0; int sched_priority_ = 0; + std::vector condition_path_exists_; friend class LoaderInfoManager; friend class LoaderInfoInflator; @@ -124,6 +126,8 @@ class LoaderInfoInflator { void ParseAppTypes(const LoaderInfoPtr& info, std::string& tok_start, std::istringstream& ss); + void ParseConditionPathExists(const LoaderInfoPtr& info, + const std::string& tok_start, std::istringstream& stream); }; class LoaderInfoManager { diff --git a/src/launchpad-process-pool/slot_info.h b/src/launchpad-process-pool/slot_info.h index 58de327..9597fa1 100644 --- a/src/launchpad-process-pool/slot_info.h +++ b/src/launchpad-process-pool/slot_info.h @@ -19,6 +19,9 @@ #include +#include +#include + typedef struct slot_info_s { int type; int loader_id; @@ -39,6 +42,7 @@ typedef struct slot_info_s { bool app_check; int on_boot_timeout; int sched_priority; + std::vector condition_path_exists; } slot_info_t; #endif /* __SLOT_INFO_H__ */ diff --git a/tests/launchpad-process-pool-unittest/src/test_launchpad.cc b/tests/launchpad-process-pool-unittest/src/test_launchpad.cc index d332ebb..10086da 100644 --- a/tests/launchpad-process-pool-unittest/src/test_launchpad.cc +++ b/tests/launchpad-process-pool-unittest/src/test_launchpad.cc @@ -82,6 +82,8 @@ EXTRA_ARRAY_VAL /test/libcapi-media-camera.so.0 EXTRA_ARRAY_VAL /test/ecore_evas/engines/extn/v-1.25/module.so ALTERNATIVE_LOADER common-loader1 EXTRA threads 7 +ON_BOOT_TIMEOUT 10000 +CONDITION_PATH_EXISTS /run/.wm_ready )__test"; } // namespace @@ -177,9 +179,9 @@ TEST_F(LaunchpadTest, LoaderInfoTest) { EXPECT_EQ(info->GetAppTypes()[0], "capp"); EXPECT_EQ(info->GetAppTypes()[1], "c++app"); EXPECT_EQ(info->GetHwAcc(), "ON"); - EXPECT_EQ(info->GetDetectionMethod(), LoaderMethod::Timeout | - LoaderMethod::Visibility | - LoaderMethod::Install); + EXPECT_EQ(info->GetDetectionMethod(), + (LoaderMethod::Timeout | LoaderMethod::Visibility | + LoaderMethod::Install)); EXPECT_EQ(info->GetTimeoutVal(), 5000); auto& b = info->GetExtra(); EXPECT_EQ(b.GetString("loader_type"), "hw-loader"); @@ -195,4 +197,7 @@ TEST_F(LaunchpadTest, LoaderInfoTest) { EXPECT_EQ(arr[6], "/test/libcapi-media-player.so.0"); EXPECT_EQ(arr[7], "/test/libcapi-media-camera.so.0"); EXPECT_EQ(arr[8], "/test/ecore_evas/engines/extn/v-1.25/module.so"); + + EXPECT_EQ(info->GetOnbootTimeout(), 10000); + EXPECT_EQ(info->GetConditionPathExists()[0], "/run/.wm_ready"); } -- 2.7.4 From 7533b46bb00c510de35c0833f0415f59cf6cfac8 Mon Sep 17 00:00:00 2001 From: Hwankyu Jhun Date: Mon, 6 Mar 2023 05:57:14 +0000 Subject: [PATCH 14/16] Release version 0.25.0 Changes: - Add a new option to the loader configuration Change-Id: I9df5bff98dc9a8c49c9e1226581070ee80e7b90f Signed-off-by: Hwankyu Jhun --- packaging/launchpad.spec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packaging/launchpad.spec b/packaging/launchpad.spec index e4081d1..8542abd 100644 --- a/packaging/launchpad.spec +++ b/packaging/launchpad.spec @@ -1,6 +1,6 @@ Name: launchpad Summary: Launchpad for launching applications -Version: 0.24.3 +Version: 0.25.0 Release: 1 Group: Application Framework/Daemons License: Apache-2.0 -- 2.7.4 From eeb036c11ad74c122086cf1ca83a8e659d566e26 Mon Sep 17 00:00:00 2001 From: Hwankyu Jhun Date: Tue, 7 Mar 2023 05:57:08 +0000 Subject: [PATCH 15/16] Add logs for debugging loader creation To debug loader creation, new logs are added. Change-Id: I1ca9c480ba7f11d4321639df8a0dc7f07cbfd87f Signed-off-by: Hwankyu Jhun --- src/launchpad-process-pool/launchpad.cc | 42 +++++++++++++++++++++++++-------- 1 file changed, 32 insertions(+), 10 deletions(-) diff --git a/src/launchpad-process-pool/launchpad.cc b/src/launchpad-process-pool/launchpad.cc index 9a7b293..ed0a39a 100644 --- a/src/launchpad-process-pool/launchpad.cc +++ b/src/launchpad-process-pool/launchpad.cc @@ -811,7 +811,8 @@ static gboolean __handle_deactivate_event(gpointer user_data) { cpc = (candidate_process_context_t*)user_data; __update_slot_state(cpc, launchpad::LoaderMethod::Ttl, false); - _D("Deactivate event: type(%d)", cpc->type); + _D("Deactivate event: type(%d), loader_name(%s)", + cpc->type, cpc->loader_name); return G_SOURCE_REMOVE; } @@ -969,6 +970,8 @@ static gboolean __handle_timeout_event(gpointer user_data) { cpc = (candidate_process_context_t*)user_data; cpc->timer = 0; + _W("type(%d), loader_name(%s), state(%d)", + cpc->type, cpc->loader_name, cpc->state); if (cpc->pid != CANDIDATE_NONE) { _W("Candidate(%d) process(%d) is running", cpc->type, cpc->pid); return G_SOURCE_REMOVE; @@ -980,12 +983,22 @@ static gboolean __handle_timeout_event(gpointer user_data) { } static void __set_timer(candidate_process_context_t* cpc) { - if (cpc == nullptr || cpc->timer > 0) + if (cpc == nullptr || cpc->timer > 0) { + _E("Invalid parameter"); return; + } - if ((cpc->detection_method & static_cast(launchpad::LoaderMethod::Timeout)) && + _W("type(%d), loader_name(%s), state(%d)", + cpc->type, cpc->loader_name, cpc->state); + if ((cpc->detection_method & + static_cast(launchpad::LoaderMethod::Timeout)) && cpc->state == CANDIDATE_PROCESS_STATE_RUNNING) { cpc->timer = g_timeout_add(cpc->timeout_val, __handle_timeout_event, cpc); + if (cpc->timer == 0) + _E("g_timeout_add() is failed. %d:%s", cpc->type, cpc->loader_name); + } else { + _E("Skip adding timer. detection_method(%d), state(%d)", + cpc->detection_method, cpc->state); } } @@ -1006,7 +1019,7 @@ static void __dispose_candidate_process(candidate_process_context_t* cpc) { if (!cpc) return; - _D("Dispose candidate process %d", cpc->type); + _D("Dispose candidate process %d:%s", cpc->type, cpc->loader_name); if (cpc->pid > 0) { _D("kill process %d", cpc->pid); __kill_process(cpc->pid); @@ -1030,7 +1043,7 @@ static void __dispose_hydra_process(candidate_process_context_t* cpc) { __dispose_candidate_process(cpc); - _D("Dispose hydra process %d", cpc->type); + _D("Dispose hydra process %d:%s", cpc->type, cpc->loader_name); if (cpc->hydra_pid > 0) { _D("kill process %d", cpc->hydra_pid); __kill_process(cpc->hydra_pid); @@ -1055,7 +1068,7 @@ static int __send_launchpad_loader(candidate_process_context_t* cpc, return -1; __candidate_process_real_launch(cpc->send_fd, pkt); - SECURE_LOGD("Request to candidate process, pid: %d, bin path: %s", cpc->pid, + _W("Request to candidate process, pid: %d, bin path: %s", cpc->pid, app_path); pid = cpc->pid; @@ -2129,6 +2142,8 @@ static void __update_slot(int type, bool app_exists) { return; cpc->app_exists = app_exists; + _W("type(%d), loader_name(%s), app_check(%d), app_exists(%d)", + cpc->type, cpc->loader_name, cpc->app_check, cpc->app_exists); if (cpc->app_check && !cpc->app_exists) { if (cpc->pid > 0) __dispose_candidate_process(cpc); @@ -2192,6 +2207,8 @@ static int __dispatch_cmd_update_app_type(bundle* b) { } static void __deactivate_slot(candidate_process_context_t* cpc) { + _W("type(%d), loader_name(%s), state(%d)", + cpc->type, cpc->loader_name, cpc->state); if (cpc->state == CANDIDATE_PROCESS_STATE_PAUSED) return; @@ -2203,6 +2220,8 @@ static void __deactivate_slot(candidate_process_context_t* cpc) { } static void __activate_slot(candidate_process_context_t* cpc) { + _W("type(%d), loader_name(%s), state(%d)", + cpc->type, cpc->loader_name, cpc->state); if (cpc->state == CANDIDATE_PROCESS_STATE_RUNNING) return; @@ -2213,16 +2232,19 @@ static void __activate_slot(candidate_process_context_t* cpc) { if ((cpc->app_check && !cpc->app_exists) || cpc->pid > CANDIDATE_NONE) return; - if (cpc->detection_method & static_cast(launchpad::LoaderMethod::Timeout)) + if (cpc->detection_method & + static_cast(launchpad::LoaderMethod::Timeout)) __set_timer(cpc); } static void __update_slot_state(candidate_process_context_t* cpc, - launchpad::LoaderMethod method, - bool force) { + launchpad::LoaderMethod method, bool force) { + _W("type(%d), loader_name(%s), state(%d), method(%d), force(%d)", + cpc->type, cpc->loader_name, cpc->state, static_cast(method), force); switch (method) { case launchpad::LoaderMethod::OutOfMemory: - if ((force || cpc->deactivation_method & static_cast(method)) && __is_low_memory()) { + if ((force || cpc->deactivation_method & static_cast(method)) && + __is_low_memory()) { _W("Low memory, deactivate slot %d", cpc->type); __deactivate_slot(cpc); } else { -- 2.7.4 From 31cb4c7041db397458e864ac1abec84c548d6792 Mon Sep 17 00:00:00 2001 From: Hwankyu Jhun Date: Tue, 7 Mar 2023 06:03:52 +0000 Subject: [PATCH 16/16] Release version 0.25.1 Changes: - Add logs for debugging loader creation Change-Id: I446868898d85d6b3ce30a6fa6f8f2f6fb415be52 Signed-off-by: Hwankyu Jhun --- packaging/launchpad.spec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packaging/launchpad.spec b/packaging/launchpad.spec index 8542abd..13dcb12 100644 --- a/packaging/launchpad.spec +++ b/packaging/launchpad.spec @@ -1,6 +1,6 @@ Name: launchpad Summary: Launchpad for launching applications -Version: 0.25.0 +Version: 0.25.1 Release: 1 Group: Application Framework/Daemons License: Apache-2.0 -- 2.7.4