From 89fcb5d273fcdafdaae7f3695eae748cf7e25022 Mon Sep 17 00:00:00 2001 From: Changgyu Choi Date: Tue, 7 Feb 2023 18:37:48 +0900 Subject: [PATCH] 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