syscommon-plugin-test: Add plugin battery module test code 56/312856/1
authorYunhee Seo <yuni.seo@samsung.com>
Mon, 3 Jun 2024 10:11:14 +0000 (19:11 +0900)
committerYunhee Seo <yuni.seo@samsung.com>
Mon, 17 Jun 2024 04:45:13 +0000 (13:45 +0900)
From the tizen 8.0 image, plugins could be separated into plugin-backend
through libsyscommon plugin api and interface implementation.
However, there was no place where the plugin backend module was installed and used,
so it was unable to test it.
Therefore, test code is added that can test the installed plugin backend
regardless of the type of plugin backend and feature support.
If there is a plugin backend module .so file, you can test the module function
with gtest unit.

Also, there are still many plugin functions that have not been separated,
but it will be helpful with this test code.

Change-Id: Iddf34a0074dfbe42a076f47636949a33217792d6
Signed-off-by: Yunhee Seo <yuni.seo@samsung.com>
CMakeLists.txt
packaging/deviced.spec
tests/syscommon-plugin-test/CMakeLists.txt [new file with mode: 0644]
tests/syscommon-plugin-test/battery.cc [new file with mode: 0644]
tests/syscommon-plugin-test/main.cc [new file with mode: 0644]
tests/syscommon-plugin-test/syscommon-plugin-test.h [new file with mode: 0644]

index ef277b0c365cf560d3b835054f2ad03df2eed5e1..f36ea414550a80d6daba55eedd07eb14c815decf 100644 (file)
@@ -362,3 +362,4 @@ INSTALL_CONF(conf display-profile-tv)
 # Tests
 ADD_SUBDIRECTORY(tests/deviced-common-private-test)
 ADD_SUBDIRECTORY(tests/auto-test)
+ADD_SUBDIRECTORY(tests/syscommon-plugin-test)
index 666a9a195b3d2bec89fc3fdeb70a8969d75ef2fe..830d875e223db6444f33a84b4ef9d921587ca13e 100644 (file)
@@ -45,6 +45,8 @@ BuildRequires:  pkgconfig(tizen-dpms-client)
 BuildRequires:  pkgconfig(zlib)
 BuildRequires:  pkgconfig(argos_watchdog)
 BuildRequires:  pkgconfig(cmocka)
+BuildRequires:  pkgconfig(gtest)
+BuildRequires:  pkgconfig(gmock)
 
 Requires: %{name}-tools = %{version}-%{release}
 %{?systemd_requires}
@@ -125,6 +127,14 @@ Requires:   %{name} = %{version}-%{release}
 %description isu
 Configuration files to generate the ISU (Individual Service Upgrade) package
 
+%package syscommon-plugin-test
+Summary:    libsyscommon function test tool related to deviced
+Group:      System/Utilities
+
+%description syscommon-plugin-test
+This package can be installed optional for syscommon-plugin test.
+It can test resource-driver and plugin backend call test for deviced.
+
 %prep
 %setup -q
 
@@ -367,3 +377,8 @@ mv %{_libdir}/tv-display.so %{_libdir}/deviced/display.so
 
 %files isu
 /etc/isu/deviced/*
+
+%files syscommon-plugin-test
+%manifest deviced.manifest
+%license LICENSE.Apache-2.0
+%{_bindir}/syscommon-plugin-test
diff --git a/tests/syscommon-plugin-test/CMakeLists.txt b/tests/syscommon-plugin-test/CMakeLists.txt
new file mode 100644 (file)
index 0000000..c3991b1
--- /dev/null
@@ -0,0 +1,37 @@
+CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
+PROJECT(syscommon-plugin-test C CXX)
+
+INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/tests/syscommon-plugin-test)
+
+SET(SRCS
+       main.cc
+       battery.cc
+       syscommon-plugin-test.h)
+
+INCLUDE(FindPkgConfig)
+PKG_CHECK_MODULES(pkgs REQUIRED
+       capi-system-info
+       dlog
+       gio-2.0
+       glib-2.0
+       gmock
+       gtest
+       libsyscommon
+       libsyscommon-plugin-api-deviced
+)
+
+FOREACH(flag ${pkgs_CFLAGS})
+       SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}")
+ENDFOREACH(flag)
+
+SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -Wall -fPIE")
+SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS} -g -fno-omit-frame-pointer -Wall -fPIE")
+SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${EXTRA_CFLAGS} -std=c++14 -Wall")
+SET(CMAKE_EXE_LINKER_FLAGS "-Wl,--as-needed -pie")
+
+ADD_DEFINITIONS("-DENABLE_TEST_DEVICED_RESOURCE_DRIVER")
+
+ADD_EXECUTABLE(${PROJECT_NAME} ${SRCS})
+
+TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${pkgs_LDFLAGS})
+INSTALL(TARGETS ${PROJECT_NAME} DESTINATION /usr/bin/)
\ No newline at end of file
diff --git a/tests/syscommon-plugin-test/battery.cc b/tests/syscommon-plugin-test/battery.cc
new file mode 100644 (file)
index 0000000..0e14c57
--- /dev/null
@@ -0,0 +1,45 @@
+#include <system_info.h>
+#include <system/syscommon-plugin-deviced-battery.h>
+
+#include "syscommon-plugin-test.h"
+
+class BatteryTest : public testing::Test {
+       protected:
+               void SetUp() override {
+                       int ret_val;
+
+                       ret_val = syscommon_plugin_deviced_battery_get_backend();
+                       if (ret_val == 0) {
+                               battery_plugin_backend_supported = true;
+                       } else {
+                               DEBUG_MESSAGE("Battery plugin backend is not supported");
+                               battery_plugin_backend_supported = false;
+                       }
+               }
+               ~BatteryTest() {}
+               void TearDown() override {}
+               bool battery_plugin_backend_supported;
+};
+
+TEST_F(BatteryTest, IsPossibleToNotifyBatteryFull)
+{
+       int ret_val = -1;
+       bool possible_notify;
+
+       if (!battery_plugin_backend_supported)
+               return;
+
+       ret_val = syscommon_plugin_deviced_battery_is_possible_to_notify_battery_full(&possible_notify);
+       EXPECT_TRUE(ret_val == 0 || ret_val == -ENOTSUP || ret_val == -EOPNOTSUPP);
+}
+
+TEST_F(BatteryTest, UpdateHealthOvpState)
+{
+       int ret_val = 0;
+
+       if (!battery_plugin_backend_supported)
+               return;
+
+       ret_val = syscommon_plugin_deviced_battery_update_health_ovp_state(DEVICED_BATTERY_NOTI_ON);
+       EXPECT_TRUE(ret_val == 0 || ret_val == -ENOTSUP || ret_val == -EOPNOTSUPP);
+}
diff --git a/tests/syscommon-plugin-test/main.cc b/tests/syscommon-plugin-test/main.cc
new file mode 100644 (file)
index 0000000..137f574
--- /dev/null
@@ -0,0 +1,24 @@
+#include <iostream>
+#include <gtest/gtest.h>
+
+using namespace std;
+
+int main(int argc, char **argv)
+{
+       int ret = -1;
+
+       try {
+               testing::InitGoogleTest(&argc, argv);
+       } catch(...) {
+               std::cout << "Exception occurred." << std::endl;
+       }
+
+       try {
+               ret = RUN_ALL_TESTS();
+       } catch (const ::testing::internal::GoogleTestFailureException& e) {
+               ret = -1;
+               std::cout << "GoogleTestFailureException was thrown:" << e.what() << std::endl;
+       }
+
+       return ret;
+}
diff --git a/tests/syscommon-plugin-test/syscommon-plugin-test.h b/tests/syscommon-plugin-test/syscommon-plugin-test.h
new file mode 100644 (file)
index 0000000..16f1166
--- /dev/null
@@ -0,0 +1,55 @@
+/*
+ * syscommon-test
+ * Copyright (c) 2024 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the License);
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#ifndef __SYSCOMMON_PLUGIN_TEST_H__
+#define __SYSCOMMON_PLUGIN_TEST_H__
+
+#include <gtest/gtest.h>
+#include <stdio.h>
+#include <stdbool.h>
+#include <string.h>
+
+#ifdef ENABLE_TEST_DEVICED_SYSCOMMON_PLUGIN
+       #define LOG_TAG "DEVICED_SYSCOMMON_TEST"
+       #include <dlog.h>
+       #define _D(fmt, args...)        SLOGD(fmt, ##args)
+       #define _W(fmt, args...)        SLOGW(fmt, ##args)
+       #define _E(fmt, args...)        SLOGE(fmt, ##args)
+#else
+       #define _D(x, ...)
+    #define _W(x, ...)
+    #define _E(x, ...)
+#endif
+
+#define SKIP_MESSAGE(fmt, args...) \
+do { \
+       printf("[  SKIPPED ] "); \
+       printf(fmt, ##args); \
+       printf("\n"); \
+} while (0)
+
+#define DEBUG_MESSAGE(fmt, args...) \
+do { \
+       printf("[    DEBUG ] "); \
+       printf(fmt, ##args); \
+       printf("\n"); \
+} while (0)
+
+/**
+ * @}
+ */
+
+#endif //__SYSCOMMON_PLUGIN_TEST_H__