From 9d3f131ae448a1194495268819d9cfa77002c437 Mon Sep 17 00:00:00 2001 From: lokilee73 Date: Mon, 22 Feb 2021 13:10:12 +0900 Subject: [PATCH] Implement HAL test for display Change-Id: I67bcfa3713c41a054c898898ad538d92d767def7 Signed-off-by: lokilee73 --- CMakeLists.txt | 8 +- haltest/CMakeLists.txt | 40 ++++++ haltest/display.cpp | 310 ++++++++++++++++++++++++++++++++++++++++++ haltest/haltest.h | 31 +++++ haltest/main.cpp | 24 ++++ packaging/hal-api-device.spec | 19 ++- 6 files changed, 429 insertions(+), 3 deletions(-) create mode 100644 haltest/CMakeLists.txt create mode 100644 haltest/display.cpp create mode 100644 haltest/haltest.h create mode 100644 haltest/main.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index adfe2b8..2cec322 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -70,14 +70,18 @@ CONFIGURE_FILE( ) INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/${fw_name}.pc DESTINATION ${LIB_INSTALL_DIR}/pkgconfig) +IF(HALTEST STREQUAL on) + ADD_SUBDIRECTORY(haltest) +ENDIF() + IF(UNIX) ADD_CUSTOM_TARGET (distclean @echo cleaning for source distribution) ADD_CUSTOM_COMMAND( - DEPENDS clean + DEPENDS clean COMMENT "distribution clean" COMMAND find - ARGS . + ARGS . -not -name config.cmake -and \( -name tester.c -or -name Testing -or diff --git a/haltest/CMakeLists.txt b/haltest/CMakeLists.txt new file mode 100644 index 0000000..37313df --- /dev/null +++ b/haltest/CMakeLists.txt @@ -0,0 +1,40 @@ +CMAKE_MINIMUM_REQUIRED(VERSION 2.6) +PROJECT(device-haltests C CXX) + +SET(HALAPI_LIBRARY "hal-api-device") + +INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}) +INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/${INC_DIR}) + +SET(REQUIRES_LIST ${REQUIRES_LIST} + capi-system-info + hal-api-common + glib-2.0 + gio-2.0 + gmock + dlog +) + +FIND_LIBRARY( + HALAPI_LIBRARY + NAMES libhal-api-device.so + HINTS /usr/lib/hal /usr/lib64/hal + REQUIRED) + +INCLUDE(FindPkgConfig) +PKG_CHECK_MODULES(gtest_pkgs REQUIRED ${REQUIRES_LIST}) + +FOREACH(flag ${gtest_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}") +SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${EXTRA_CFLAGS}") +SET(CMAKE_EXE_LINKER_FLAGS "-Wl,--as-needed -pie") + +SET(src ${CMAKE_SOURCE_DIR}/haltest/main.cpp + ${CMAKE_SOURCE_DIR}/haltest/display.cpp) +ADD_EXECUTABLE(${PROJECT_NAME} ${src}) +TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${gtest_LDFLAGS} ${gtest_pkgs_LDFLAGS} -ldl ${HALAPI_LIBRARY}) +INSTALL(TARGETS ${PROJECT_NAME} DESTINATION /usr/bin/hal) diff --git a/haltest/display.cpp b/haltest/display.cpp new file mode 100644 index 0000000..9f85a53 --- /dev/null +++ b/haltest/display.cpp @@ -0,0 +1,310 @@ + +#include +#include +#include +#include "haltest.h" +#include "hal-display.h" + +using namespace std; + +/* Define Classes */ +class DISPLAY : public testing::Test +{ + public: + virtual void SetUp() + { + int ret; + + ret = system_info_get_platform_bool(FEATURE_DISPLAY, &supported); + EXPECT_EQ(SYSTEM_INFO_ERROR_NONE, ret) << "system_info_get_platform_bool failed"; + + } + + virtual void TearDown() + { + + } +}; + +/* + * Testcase for Display + */ +TEST_F(DISPLAY, GetBackendP) +{ + int ret; + + if (!supported) + return; + + ret = hal_device_display_get_backend(); + EXPECT_EQ(ret, 0) << "Fail to get display device (" << ret << ")"; +} + +TEST_F(DISPLAY, GetMaxBrightnessP) +{ + int ret; + int max; + + if (!supported) + return; + + ret = hal_device_display_get_max_brightness(&max); + if (ret == -ENODEV) + return; + + EXPECT_EQ(ret, 0) << "Fail to get max brightness (" << ret << ")"; +} + +TEST_F(DISPLAY, GetBrightnessP) +{ + int ret; + int brt; + + if (!supported) + return; + + ret = hal_device_display_get_brightness(&brt); + if (ret == -ENODEV) + return; + + EXPECT_EQ(ret, 0) << "Fail to get brightness (" << ret << ")"; +} + +TEST_F(DISPLAY, SetBrightnessP) +{ + int ret; + int max = 100; + + if (!supported) + return; + + ret = hal_device_display_set_brightness(max); + if (ret == -ENODEV) + return; + + EXPECT_EQ(ret, 0) << "Fail to set_brightness (" << ret << ")"; +} + +TEST_F(DISPLAY, SetMultiBrightnessP) +{ + int ret; + int brt = 50, step = 5, delay = 10000; + + if (!supported) + return; + + ret = hal_device_display_set_multi_brightness(brt, step, delay); + if (ret == -ENODEV) + return; + + EXPECT_EQ(ret, 0) << "Fail to set multi brightness (" << ret << ")"; +} + +TEST_F(DISPLAY, GetAutoBrightnessP) +{ + int ret; + int brt; + float lmax = 0, lmin = 0, light = 0; + + if (!supported) + return; + + ret = hal_device_display_get_auto_brightness(lmax, lmin, light, &brt); + if (ret == -ENODEV) + return; + + EXPECT_EQ(ret, 0) << "Fail to get auto brightness (" << ret << ")"; +} + +TEST_F(DISPLAY, GetStateP) +{ + int ret; + enum display_state state; + + if (!supported) + return; + + ret = hal_device_display_get_state(&state); + if (ret == -ENODEV) + return; + + EXPECT_EQ(ret, 0) << "Fail to get state (" << ret << ")"; +} + +TEST_F(DISPLAY, SetStateP) +{ + int ret; + + if (!supported) + return; + + ret = hal_device_display_set_state(DISPLAY_ON); + if (ret == -ENODEV) + return; + + EXPECT_EQ(ret, 0) << "Fail to set state (" << ret << ")"; +} + +TEST_F(DISPLAY, GetImageEffectP) +{ + enum display_image_effect effect; + int ret; + + if (!supported) + return; + + ret = hal_device_display_get_image_effect(&effect); + if (ret == -ENODEV) + return; + + EXPECT_EQ(ret, 0) << "Fail to get image effect (" << ret << ")"; +} + +TEST_F(DISPLAY, SetImageEffectP) +{ + int ret; + + if (!supported) + return; + + ret = hal_device_display_set_image_effect(DISPLAY_IMAGE_EFFECT_GREY); + if (ret == -ENODEV) + return; + + EXPECT_EQ(ret, 0) << "Fail to set image effect (" << ret << ")"; +} + +TEST_F(DISPLAY, GetPanelModeP) +{ + enum display_panel_mode mode; + int ret; + + if (!supported) + return; + + ret = hal_device_display_get_panel_mode(&mode); + if (ret == -ENODEV) + return; + + EXPECT_EQ(ret, 0) << "Fail to get panel mode (" << ret << ")"; +} + +TEST_F(DISPLAY, SetPanelModeP) +{ + int ret; + + if (!supported) + return; + + ret = hal_device_display_set_panel_mode(DISPLAY_PANEL_MODE_LOWPOWER); + if (ret == -ENODEV) + return; + + EXPECT_EQ(ret, 0) << "Fail to set panel mode (" << ret << ")"; +} + +TEST_F(DISPLAY, GetAodModeP) +{ + enum display_aod_mode mode; + int ret; + + if (!supported) + return; + + ret = hal_device_display_get_aod_mode(&mode); + if (ret == -ENODEV) + return; + + EXPECT_EQ(ret, 0) << "Fail to get aod mode (" << ret << ")"; +} + +TEST_F(DISPLAY, GetAodBrightnessP) +{ + int max, normal, min, charging; + int ret; + + if (!supported) + return; + + ret = hal_device_display_get_aod_brightness(&max, &normal, &min, &charging); + if (ret == -ENODEV) + return; + + EXPECT_EQ(ret, 0) << "Fail to get aod brightness (" << ret << ")"; +} + + +TEST_F(DISPLAY, GetMaxFrameRateP) +{ + int ret; + int max; + + if (!supported) + return; + + ret = hal_device_display_get_max_frame_rate(&max); + if (ret == -ENODEV) + return; + + EXPECT_GE(ret, 0) << "Fail to get max frame_rate (" << ret << ")"; +} + +TEST_F(DISPLAY, GetMinFrameRateP) +{ + int ret; + int min; + + if (!supported) + return; + + ret = hal_device_display_get_min_frame_rate(&min); + if (ret == -ENODEV) + return; + + EXPECT_GE(ret, 0) << "Fail to get min frame rate (" << ret << ")"; +} + +TEST_F(DISPLAY, GetFrameRateP) +{ + int ret, rate; + + if (!supported) + return; + + ret = hal_device_display_get_frame_rate(&rate); + if (ret == -ENODEV) + return; + + EXPECT_GE(ret, 0) << "Fail to get frame rate (" << ret << ")"; +} + +TEST_F(DISPLAY, SetFrameRateP) +{ + int ret, fmax; + + if (!supported) + return; + + ret = hal_device_display_get_max_frame_rate(&fmax); + if (ret == -ENODEV) + return; + + EXPECT_GE(ret, 0) << "Fail to get max frame rate (" << ret << ")"; + + ret = hal_device_display_set_frame_rate(fmax); + if (ret == -ENODEV) + return; + + EXPECT_GE(ret, 0) << "Fail to set frame rate (" << ret << ")"; +} + +TEST_F(DISPLAY, DeinitP) +{ + int ret; + + if (!supported) + return; + + ret = hal_device_display_put_backend(); + EXPECT_GE(ret, 0) << "Fail to close display device (" << ret << ")"; +} diff --git a/haltest/haltest.h b/haltest/haltest.h new file mode 100644 index 0000000..2ddc558 --- /dev/null +++ b/haltest/haltest.h @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2021 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. + */ +#ifndef __HALTEST_H__ +#define __HALTEST_H__ + +#include + +#define FEATURE_BATTERY "http://tizen.org/feature/battery" +#define FEATURE_DISPLAY "http://tizen.org/feature/display" +#define FEATURE_LED "http://tizen.org/feature/led" +#define FEATURE_IR "http://tizen.org/feature/consumer_ir" +#define FEATURE_THERMISTOR "http://tizen.org/feature/thermistor.ap" +#define FEATURE_BEZEL "http://tizen.org/feature/input.rotating_bezel" + + +bool supported; + +#endif /* __HALTEST_H__ */ diff --git a/haltest/main.cpp b/haltest/main.cpp new file mode 100644 index 0000000..137f574 --- /dev/null +++ b/haltest/main.cpp @@ -0,0 +1,24 @@ +#include +#include + +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/packaging/hal-api-device.spec b/packaging/hal-api-device.spec index ceecfaa..d88da16 100644 --- a/packaging/hal-api-device.spec +++ b/packaging/hal-api-device.spec @@ -8,7 +8,11 @@ Source0: %{name}-%{version}.tar.gz Source1: hal-api-device.manifest BuildRequires: cmake BuildRequires: pkgconfig(dlog) +BuildRequires: pkgconfig(glib-2.0) +BuildRequires: pkgconfig(gio-2.0) +BuildRequires: pkgconfig(gmock) BuildRequires: pkgconfig(hal-api-common) +BuildRequires: pkgconfig(capi-system-info) %description API library for HAL device modules @@ -21,6 +25,13 @@ Requires: %{name} = %{version}-%{release} %description devel API library for HAL device modules (Development package) +%package -n device-haltests +Summary: Device HAL(Hardware Abstraction Layer) Test Cases +Requires: %{name} = %{version}-%{release} + +%description -n device-haltests +Device HAL(Hardware Abstraction Layer) Test Cases + %prep %setup -q @@ -28,7 +39,8 @@ API library for HAL device modules (Development package) cp %{SOURCE1} . MAJORVER=`echo %{version} | awk 'BEGIN {FS="."}{print $1}'` %cmake . -DFULLVER=%{version} \ - -DMAJORVER=${MAJORVER} + -DMAJORVER=${MAJORVER} \ + -DHALTEST=on %__make %{?jobs:-j%jobs} @@ -50,3 +62,8 @@ MAJORVER=`echo %{version} | awk 'BEGIN {FS="."}{print $1}'` %{_includedir}/hal/device/hal-*.h %{_libdir}/pkgconfig/*.pc %{_libdir}/hal/libhal-api-device.so + +%files -n device-haltests +%manifest %{name}.manifest +%license LICENSE.Apache-2.0 +%{_bindir}/hal/device-haltests -- 2.7.4