# Tests
ADD_SUBDIRECTORY(tests/deviced-common-private-test)
ADD_SUBDIRECTORY(tests/auto-test)
+ADD_SUBDIRECTORY(tests/syscommon-plugin-test)
BuildRequires: pkgconfig(zlib)
BuildRequires: pkgconfig(argos_watchdog)
BuildRequires: pkgconfig(cmocka)
+BuildRequires: pkgconfig(gtest)
+BuildRequires: pkgconfig(gmock)
Requires: %{name}-tools = %{version}-%{release}
%{?systemd_requires}
%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
%files isu
/etc/isu/deviced/*
+
+%files syscommon-plugin-test
+%manifest deviced.manifest
+%license LICENSE.Apache-2.0
+%{_bindir}/syscommon-plugin-test
--- /dev/null
+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
--- /dev/null
+#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);
+}
--- /dev/null
+#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;
+}
--- /dev/null
+/*
+ * 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__