From 4b985b6a8a86ec9289f38d07e95d784dde4b82c5 Mon Sep 17 00:00:00 2001 From: Yunmi Ha Date: Mon, 5 Apr 2021 20:10:04 +0900 Subject: [PATCH 01/16] Load HAL module before running API Change-Id: Ibe74a9b72c30ea96f61efb7110a8c897eeffd5c7 Signed-off-by: Yunmi Ha --- src/hal-api-sensor.cpp | 67 ++++++++++++++++++++++++++++++-------------------- 1 file changed, 41 insertions(+), 26 deletions(-) diff --git a/src/hal-api-sensor.cpp b/src/hal-api-sensor.cpp index e4b535a..01683b7 100644 --- a/src/hal-api-sensor.cpp +++ b/src/hal-api-sensor.cpp @@ -25,43 +25,58 @@ #define EXPORT __attribute__((visibility("default"))) #endif -static hal_backend_sensor_funcs *g_sensor_funcs = NULL; +static hal_backend_sensor_funcs *hal_sensor_funcs = NULL; +/* +-1 : failed to initialize +0 : not initialized +1 : succeeded to initialize +*/ +static int hal_initialized = 0; EXPORT -int hal_sensor_get_backend(void) { - int ret; +int hal_sensor_get_backend(void) +{ + int ret; - if (g_sensor_funcs) return 0; + if (hal_sensor_funcs) + return 0; - ret = hal_common_get_backend(HAL_MODULE_SENSOR, (void **)&g_sensor_funcs); - if (ret < 0) { - _E("Failed to get backend\n"); - return -EINVAL; - } + ret = hal_common_get_backend(HAL_MODULE_SENSOR, (void **)&hal_sensor_funcs); + if (ret < 0) { + _E("Failed to get backend"); + hal_initialized = -1; + return -ENODEV; + } - return 0; + hal_initialized = 1; + return 0; } EXPORT -int hal_sensor_put_backend(void) { - int ret; - - if (!g_sensor_funcs) return -EINVAL; +int hal_sensor_put_backend(void) +{ + if (!hal_sensor_funcs) + return -ENODEV; - ret = hal_common_put_backend(HAL_MODULE_SENSOR, (void *)g_sensor_funcs); - if (ret < 0) { - _E("Failed to put backend\n"); - return -EINVAL; - } - g_sensor_funcs = NULL; + hal_common_put_backend(HAL_MODULE_SENSOR, (void *)hal_sensor_funcs); + hal_sensor_funcs = NULL; + hal_initialized = 0; - return 0; + return 0; } EXPORT -int hal_sensor_create(sensor_device_t **devices) { - if (!g_sensor_funcs) { - return -ENOTSUP; - } - return g_sensor_funcs->create(devices); +int hal_sensor_create(sensor_device_t **devices) +{ + int ret; + + if (!hal_sensor_funcs && !hal_initialized) { + if ((ret = hal_sensor_get_backend()) < 0) + return ret; + } + + if (!hal_sensor_funcs || !hal_sensor_funcs->create) + return -ENODEV; + + return hal_sensor_funcs->create(devices); } -- 2.7.4 From 49335ba517dd035fd3438834f46094583a4c8099 Mon Sep 17 00:00:00 2001 From: Yunmi Ha Date: Tue, 13 Apr 2021 15:34:55 +0900 Subject: [PATCH 02/16] Add haltest Change-Id: I71919c82656d07c14990795a2b6f099cb4104150 Signed-off-by: Yunmi Ha --- CMakeLists.txt | 4 + haltest/CMakeLists.txt | 46 +++++++++++ haltest/main.cpp | 60 +++++++++++++++ haltest/sensor-device.cpp | 173 ++++++++++++++++++++++++++++++++++++++++++ haltest/sensor-haltest.h | 80 +++++++++++++++++++ include/hal-sensor-types.h | 20 +++++ packaging/hal-api-sensor.spec | 19 ++++- 7 files changed, 400 insertions(+), 2 deletions(-) create mode 100644 haltest/CMakeLists.txt create mode 100644 haltest/main.cpp create mode 100644 haltest/sensor-device.cpp create mode 100644 haltest/sensor-haltest.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 697f63e..1b3e104 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -56,3 +56,7 @@ INSTALL( FILES_MATCHING PATTERN "*.h" ) INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/${PROJECT_NAME}.pc DESTINATION ${LIBDIR}/pkgconfig) + +IF(HALTEST STREQUAL on) + ADD_SUBDIRECTORY(haltest) +ENDIF() diff --git a/haltest/CMakeLists.txt b/haltest/CMakeLists.txt new file mode 100644 index 0000000..97c237c --- /dev/null +++ b/haltest/CMakeLists.txt @@ -0,0 +1,46 @@ +CMAKE_MINIMUM_REQUIRED(VERSION 2.6) +PROJECT(sensor-haltests CXX) + +SET(HALAPI_LIBRARY "hal-api-sensor") + +INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}) +INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/${INC_DIR}) + +SET(REQUIRES_LIST ${REQUIRES_LIST} + hal-api-common + glib-2.0 + gio-2.0 + gmock + dlog +) + +FIND_LIBRARY( + HALAPI_LIBRARY + NAMES libhal-api-sensor.so + HINTS /usr/lib/hal /usr/lib64/hal + REQUIRED) + +INCLUDE(FindPkgConfig) +PKG_CHECK_MODULES(gtest_pkgs REQUIRED ${REQUIRES_LIST}) + +SET(GTEST_VERSION ${gtest_pkgs_gmock_VERSION}) +STRING(REPLACE "." ";" GTEST_VERSION ${GTEST_VERSION}) +LIST(GET GTEST_VERSION 0 GTEST_VERSION_MAJOR) +LIST(GET GTEST_VERSION 1 GTEST_VERSION_MINOR) +ADD_DEFINITIONS("-DGTEST_VERSION_MAJOR=${GTEST_VERSION_MAJOR}") +ADD_DEFINITIONS("-DGTEST_VERSION_MINOR=${GTEST_VERSION_MINOR}") + +FOREACH(flag ${gtest_pkgs_CFLAGS}) + SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}") +ENDFOREACH(flag) + +SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${EXTRA_CFLAGS} -std=gnu++0x") +SET(CMAKE_EXE_LINKER_FLAGS "-Wl,--as-needed -Wl,--gc-sections -pie") + +FILE(GLOB HALTESTS "*.cpp") + +SET(SRCS ${CMAKE_SOURCE_DIR}/haltest/main.cpp ${HALTESTS}) +ADD_EXECUTABLE(${PROJECT_NAME} ${SRCS}) + +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/main.cpp b/haltest/main.cpp new file mode 100644 index 0000000..287c9f4 --- /dev/null +++ b/haltest/main.cpp @@ -0,0 +1,60 @@ +#include "sensor-haltest.h" +#include "hal-sensor.h" + +#define CHECK_NODEV(ret_val) \ + if (ret_val == -ENODEV) { \ + SKIP_MESSAGE("Not supported HAL."); \ + return ; \ + } + +class SENSOR_API : public testing::Test { +protected: + static void SetUpHalTestSuite() { + } + + void SetUp() override {} + void TearDown() override {} +}; + +TEST_F(SENSOR_API, GetBackendP) +{ + int ret_val; + + ret_val = hal_sensor_get_backend(); + EXPECT_EQ(ret_val, 0) << strerr("Failed to get sensor device", ret_val); +} + +TEST_F(SENSOR_API, CreateP) +{ + int ret_val; + + void **devices; + ret_val = hal_sensor_create(&devices); + if (ret_val == -ENODEV) { + SKIP_MESSAGE("Not supported HAL"); + return ; + } + ASSERT_GT(ret_val, 0) << strerr("Failed to call create", ret_val); + ASSERT_NE(devices[0], nullptr) << "Opened devices are invalid."; +} + +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/haltest/sensor-device.cpp b/haltest/sensor-device.cpp new file mode 100644 index 0000000..93089e4 --- /dev/null +++ b/haltest/sensor-device.cpp @@ -0,0 +1,173 @@ +#include + +#include "sensor-haltest.h" +#include "hal-sensor.h" +#include "hal-sensor-types.h" + +typedef std::vector> device_registry_t; + +class SENSOR_DEV : public testing::Test { +public: + static int device_count; + static device_registry_t devices; + + static void SetUpHalTestSuite() { + void **sensors = nullptr; + + device_count = hal_sensor_create(&sensors); + ASSERT_GT(device_count, 0) << "Failed to get sensor devices"; + + DEBUG_MESSAGE("Setup test suite : Create %d sensor devices", device_count); + for (int i = 0; i < device_count; i++) { + devices.emplace_back(static_cast(sensors[i])); + } + } + + void SetUp() override{} + void TearDown() override{} +}; + +int SENSOR_DEV::device_count = 0; +device_registry_t SENSOR_DEV::devices; + +#define SKIP_NO_DEV() \ + if (device_count <= 0) { \ + SKIP_MESSAGE("There is no sensor devices."); \ + return; \ + } + +TEST_F(SENSOR_DEV, get_poll_fdP) +{ + SKIP_NO_DEV() + + for (auto it = devices.begin(); it != devices.end(); ++it) { + EXPECT_NE((*it)->get_poll_fd(), 0); + } +} + +TEST_F(SENSOR_DEV, get_sensorsP) +{ + const sensor_info_t *sensors = nullptr; + int ret_func; + + SKIP_NO_DEV() + + for (auto it = devices.begin(); it != devices.end(); ++it) { + ret_func = (*it)->get_sensors(&sensors); + EXPECT_GE(ret_func, 1); + EXPECT_NE(sensors, nullptr); + } +} + +TEST_F(SENSOR_DEV, get_sensorsN) +{ + SKIP_NO_DEV() + + for (auto it = devices.begin(); it != devices.end(); ++it) { + EXPECT_EQ((*it)->get_sensors(nullptr), SENSOR_ERROR_INVALID_PARAMETER); + } +} +/* +TEST_F(SENSOR_DEV, enableP) +{ + const sensor_info_t *sensors = nullptr; + + SKIP_NO_DEV() + + for (auto it = devices.begin(); it != devices.end(); ++it) { + EXPECT_GE((*it)->get_sensors(&sensors), 1); + (*it)->disable(sensors[0].id); + EXPECT_EQ((*it)->enable(sensors[0].id), true); + } +} + +TEST_F(SENSOR_DEV, enableN) +{ + SKIP_NO_DEV() + + for (auto it = devices.begin(); it != devices.end(); ++it) { + EXPECT_EQ((*it)->enable(0), false); + EXPECT_EQ((*it)->enable(10), false); + } +} + +TEST_F(SENSOR_DEV, disableP) +{ + const sensor_info_t *sensors = nullptr; + + SKIP_NO_DEV() + + for (auto it = devices.begin(); it != devices.end(); ++it) { + EXPECT_GE((*it)->get_sensors(&sensors), 1); + EXPECT_EQ((*it)->disable(sensors[0].id), true); + } + +} + +TEST_F(SENSOR_DEV, disableN) +{ + SKIP_NO_DEV() + + for (auto it = devices.begin(); it != devices.end(); ++it) { + EXPECT_EQ((*it)->disable(0), false); + EXPECT_EQ((*it)->disable(10), false); + } +} +*/ +/* +TEST_F(SENSOR_DEV, read_fdP) +{ + uint32_t *id = nullptr; + int ret_func = 0; + + SKIP_NO_DEV(); + + for (auto it = devices.begin(); it != devices.end(); ++it) { + EXPECT_EQ((*it)->enable(1), true); + + ret_func = (*it)->read_fd(&id); + EXPECT_NE(id, nullptr); + EXPECT_NE(ret_func, 0); + } +} + +TEST_F(SENSOR_DEV, read_fdN) +{ + + SKIP_NO_DEV(); + + for (auto it = devices.begin(); it != devices.end(); ++it) { + EXPECT_EQ((*it)->read_fd(nullptr), SENSOR_ERROR_INVALID_PARAMETER); + } +} +*/ +TEST_F(SENSOR_DEV, get_dataP) +{ + int length = 0; + int ret_func = 0; + sensor_data_t *data = NULL; + const sensor_info_t *sensors = nullptr; + + SKIP_NO_DEV() + + for (auto it = devices.begin(); it != devices.end(); ++it) { + EXPECT_GE((*it)->get_sensors(&sensors), 1); + + ret_func = (*it)->get_data(sensors[0].id, &data, &length); + EXPECT_EQ(ret_func, 0); + } +} + +TEST_F(SENSOR_DEV, get_dataN) +{ + int length = 0; + sensor_data_t *data = NULL; + + SKIP_NO_DEV() + + for (auto it = devices.begin(); it != devices.end(); ++it) { + EXPECT_EQ((*it)->get_data(0, &data, &length), SENSOR_ERROR_INVALID_PARAMETER); + EXPECT_EQ((*it)->get_data(1, nullptr, &length), SENSOR_ERROR_INVALID_PARAMETER); + EXPECT_EQ((*it)->get_data(1, &data, nullptr), SENSOR_ERROR_INVALID_PARAMETER); + } +} diff --git a/haltest/sensor-haltest.h b/haltest/sensor-haltest.h new file mode 100644 index 0000000..033fb75 --- /dev/null +++ b/haltest/sensor-haltest.h @@ -0,0 +1,80 @@ +/* + * 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 __SENSOR_HALTEST_H__ +#define __SENSOR_HALTEST_H__ + +#include +#include + +// hack gtest internal for print message +namespace testing +{ + namespace internal + { + enum GTestColor { + COLOR_DEFAULT, + COLOR_RED, + COLOR_GREEN, + COLOR_YELLOW + }; + + extern void ColoredPrintf(GTestColor color, const char* fmt, ...); + } +} + +#define SKIP_MESSAGE(fmt, args...) \ +do { \ + testing::internal::ColoredPrintf(testing::internal::COLOR_YELLOW, "[ SKIPPED ] "); \ + testing::internal::ColoredPrintf(testing::internal::COLOR_YELLOW, fmt, ##args); \ + testing::internal::ColoredPrintf(testing::internal::COLOR_YELLOW, "\n"); \ +} while (0) + +#define DEBUG_MESSAGE(fmt, args...) \ +do { \ + testing::internal::ColoredPrintf(testing::internal::COLOR_GREEN, "[ DEBUG ] "); \ + testing::internal::ColoredPrintf(testing::internal::COLOR_DEFAULT, fmt, ##args); \ + testing::internal::ColoredPrintf(testing::internal::COLOR_DEFAULT, "\n"); \ +} while (0) + +// SetUp/TearDown function for a testsuite differ by gtest version +#if (GTEST_VERSION_MAJOR >= 2 || (GTEST_VERSION_MAJOR == 1 && GTEST_VERSION_MINOR >= 10)) +#define SetUpHalTestSuite SetUpTestSuite +#define TearDownHalTestSuite TearDownTestSuite +#else +#define SetUpHalTestSuite SetUpTestCase +#define TearDownHalTestSuite TearDownTestCase +#endif + +#define BUFMAX 256 +static char errbuf1[BUFMAX]; + +static inline const char* strerr(const char* message, int eno) +{ + if (eno == 0) + return message; + + if (eno < 0) + eno = -eno; + + if (message) + snprintf(errbuf1, BUFMAX, "%s (%s)", message, strerror(eno)); + else + snprintf(errbuf1, BUFMAX, "%s", strerror(eno)); + + return errbuf1; +} + +#endif /* __SENSOR_HALTEST_H__ */ diff --git a/include/hal-sensor-types.h b/include/hal-sensor-types.h index fcba0cd..d373f6f 100644 --- a/include/hal-sensor-types.h +++ b/include/hal-sensor-types.h @@ -20,6 +20,7 @@ #include #include #include +#include #define SENSOR_HAL_VERSION(maj, min) ((((maj)&0xFFFF) << 24) | ((min)&0xFFFF)) @@ -155,6 +156,25 @@ typedef enum { SENSOR_DEVICE_PPG, } sensor_device_type; +/** + * @brief Enumeration for errors. + * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif + */ +typedef enum { + SENSOR_ERROR_NONE = TIZEN_ERROR_NONE, /**< Successful */ + SENSOR_ERROR_IO_ERROR = TIZEN_ERROR_IO_ERROR, /**< I/O error */ + SENSOR_ERROR_INVALID_PARAMETER = TIZEN_ERROR_INVALID_PARAMETER, /**< Invalid parameter */ + SENSOR_ERROR_NOT_SUPPORTED = TIZEN_ERROR_NOT_SUPPORTED, /**< Not supported */ + SENSOR_ERROR_PERMISSION_DENIED = TIZEN_ERROR_PERMISSION_DENIED, /**< Permission denied */ + SENSOR_ERROR_OUT_OF_MEMORY = TIZEN_ERROR_OUT_OF_MEMORY, /**< Out of memory */ + SENSOR_ERROR_NO_DATA = TIZEN_ERROR_NO_DATA, /**< No data available + @if MOBILE (Since 3.0) @elseif WEARABLE (Since 2.3.2) @endif */ + SENSOR_ERROR_NOT_NEED_CALIBRATION = TIZEN_ERROR_SENSOR | 0x03, /**< Sensor doesn't need calibration */ + SENSOR_ERROR_OPERATION_FAILED = TIZEN_ERROR_SENSOR | 0x06, /**< Operation failed */ + SENSOR_ERROR_NOT_AVAILABLE = TIZEN_ERROR_SENSOR | 0x07, /**< The sensor is supported, but currently not available + @if MOBILE (Since 3.0) @elseif WEARABLE (Since 2.3.2) @endif */ +} sensor_error_e; + /* * A platform sensor handler is generated based on this handle * This id can be assigned from HAL developer. so it has to be unique in 1 diff --git a/packaging/hal-api-sensor.spec b/packaging/hal-api-sensor.spec index a06a530..c86626f 100644 --- a/packaging/hal-api-sensor.spec +++ b/packaging/hal-api-sensor.spec @@ -7,7 +7,7 @@ Name: %{name} Summary: %{name} interface Version: 0.0.1 Release: 1 -Group: Development/Libraries +Group: System/API License: Apache-2.0 Source0: %{name}-%{version}.tar.gz Source1: %{name}.manifest @@ -34,6 +34,14 @@ Requires: %{name} = %{version}-%{release} %description -n %{devel_name} %{name} Interface for product vendor developer +### hal test package ######## +%package -n sensor-haltests +Summary: Sensor HAL(Hardware Abstraction Layer) Test Cases +Requires: %{name} = %{version}-%{release} + +%description -n sensor-haltests +Sensor HAL(Hardware Abstraction Layer) Test Cases + ### build and install ######### %prep %setup -q @@ -42,7 +50,9 @@ Requires: %{name} = %{version}-%{release} %build cp %{SOURCE1} . cp %{SOURCE2} . -cmake . -DCMAKE_INSTALL_PREFIX=%{_prefix} -DCMAKE_LIBDIR_PREFIX=%{_libdir} +cmake . -DCMAKE_INSTALL_PREFIX=%{_prefix} \ + -DCMAKE_LIBDIR_PREFIX=%{_libdir} \ + -DHALTEST=on make %{?jobs:-j%jobs} %install @@ -71,3 +81,8 @@ rm -rf %{buildroot} %license LICENSE %{_includedir}/hal/*.h %{_libdir}/pkgconfig/%{name}.pc + +%files -n sensor-haltests +%manifest %{name}.manifest +%license LICENSE +%{_bindir}/hal/sensor-haltests -- 2.7.4 From 94c68e97f9ac6d0b5357c5e41e9b522fa17c0b78 Mon Sep 17 00:00:00 2001 From: Yunmi Ha Date: Tue, 20 Apr 2021 14:12:58 +0900 Subject: [PATCH 03/16] Use system error instaed of sensor_error_e Change-Id: Ibea2e23204e1186533ee997bbf2509eae319b19b Signed-off-by: Yunmi Ha --- haltest/sensor-device.cpp | 10 +++++----- include/hal-sensor-types.h | 20 -------------------- 2 files changed, 5 insertions(+), 25 deletions(-) diff --git a/haltest/sensor-device.cpp b/haltest/sensor-device.cpp index 93089e4..58bd034 100644 --- a/haltest/sensor-device.cpp +++ b/haltest/sensor-device.cpp @@ -64,7 +64,7 @@ TEST_F(SENSOR_DEV, get_sensorsN) SKIP_NO_DEV() for (auto it = devices.begin(); it != devices.end(); ++it) { - EXPECT_EQ((*it)->get_sensors(nullptr), SENSOR_ERROR_INVALID_PARAMETER); + EXPECT_EQ((*it)->get_sensors(nullptr), -EINVAL); } } /* @@ -137,7 +137,7 @@ TEST_F(SENSOR_DEV, read_fdN) SKIP_NO_DEV(); for (auto it = devices.begin(); it != devices.end(); ++it) { - EXPECT_EQ((*it)->read_fd(nullptr), SENSOR_ERROR_INVALID_PARAMETER); + EXPECT_EQ((*it)->read_fd(nullptr), -EINVAL); } } */ @@ -166,8 +166,8 @@ TEST_F(SENSOR_DEV, get_dataN) SKIP_NO_DEV() for (auto it = devices.begin(); it != devices.end(); ++it) { - EXPECT_EQ((*it)->get_data(0, &data, &length), SENSOR_ERROR_INVALID_PARAMETER); - EXPECT_EQ((*it)->get_data(1, nullptr, &length), SENSOR_ERROR_INVALID_PARAMETER); - EXPECT_EQ((*it)->get_data(1, &data, nullptr), SENSOR_ERROR_INVALID_PARAMETER); + EXPECT_EQ((*it)->get_data(0, &data, &length), -EINVAL); + EXPECT_EQ((*it)->get_data(1, nullptr, &length), -EINVAL); + EXPECT_EQ((*it)->get_data(1, &data, nullptr), -EINVAL); } } diff --git a/include/hal-sensor-types.h b/include/hal-sensor-types.h index d373f6f..fcba0cd 100644 --- a/include/hal-sensor-types.h +++ b/include/hal-sensor-types.h @@ -20,7 +20,6 @@ #include #include #include -#include #define SENSOR_HAL_VERSION(maj, min) ((((maj)&0xFFFF) << 24) | ((min)&0xFFFF)) @@ -156,25 +155,6 @@ typedef enum { SENSOR_DEVICE_PPG, } sensor_device_type; -/** - * @brief Enumeration for errors. - * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif - */ -typedef enum { - SENSOR_ERROR_NONE = TIZEN_ERROR_NONE, /**< Successful */ - SENSOR_ERROR_IO_ERROR = TIZEN_ERROR_IO_ERROR, /**< I/O error */ - SENSOR_ERROR_INVALID_PARAMETER = TIZEN_ERROR_INVALID_PARAMETER, /**< Invalid parameter */ - SENSOR_ERROR_NOT_SUPPORTED = TIZEN_ERROR_NOT_SUPPORTED, /**< Not supported */ - SENSOR_ERROR_PERMISSION_DENIED = TIZEN_ERROR_PERMISSION_DENIED, /**< Permission denied */ - SENSOR_ERROR_OUT_OF_MEMORY = TIZEN_ERROR_OUT_OF_MEMORY, /**< Out of memory */ - SENSOR_ERROR_NO_DATA = TIZEN_ERROR_NO_DATA, /**< No data available - @if MOBILE (Since 3.0) @elseif WEARABLE (Since 2.3.2) @endif */ - SENSOR_ERROR_NOT_NEED_CALIBRATION = TIZEN_ERROR_SENSOR | 0x03, /**< Sensor doesn't need calibration */ - SENSOR_ERROR_OPERATION_FAILED = TIZEN_ERROR_SENSOR | 0x06, /**< Operation failed */ - SENSOR_ERROR_NOT_AVAILABLE = TIZEN_ERROR_SENSOR | 0x07, /**< The sensor is supported, but currently not available - @if MOBILE (Since 3.0) @elseif WEARABLE (Since 2.3.2) @endif */ -} sensor_error_e; - /* * A platform sensor handler is generated based on this handle * This id can be assigned from HAL developer. so it has to be unique in 1 -- 2.7.4 From 6f0d90cea3cef30da5de4dcb1c58280a881fdc15 Mon Sep 17 00:00:00 2001 From: Chanwoo Choi Date: Thu, 22 Apr 2021 14:50:16 +0900 Subject: [PATCH 04/16] Remove unneeded fPIE gcc option The fPIE option is for the executable binary. It is not proper for shared library files. So that remove unneeded fPIE gcc option. Change-Id: I800016e2bb30b8a02d2170b9c87df4cd334dfa02 Signed-off-by: Chanwoo Choi --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 1b3e104..8e2f855 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -33,7 +33,7 @@ FOREACH(flag ${pkgs_CFLAGS}) SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}") ENDFOREACH(flag) -SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -fvisibility=hidden -fPIE -fPIC") +SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -fvisibility=hidden -fPIC") SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -g -fno-omit-frame-pointer -finstrument-functions") SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${EXTRA_CFLAGS} -lrt") SET(CMAKE_EXE_LINKER_FLAGS "-pie") -- 2.7.4 From 0813c0b54e38beb0f84d1b5d1f0a455bdb12474f Mon Sep 17 00:00:00 2001 From: Yunmi Ha Date: Mon, 26 Apr 2021 17:19:16 +0900 Subject: [PATCH 05/16] Add get_attribute interface Change-Id: I588887f1fdc17dbd079d97d646b1b88b932a940a Signed-off-by: Yunmi Ha --- include/hal-sensor-types.h | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/include/hal-sensor-types.h b/include/hal-sensor-types.h index fcba0cd..d7b78d1 100644 --- a/include/hal-sensor-types.h +++ b/include/hal-sensor-types.h @@ -570,6 +570,15 @@ class sensor_device { int len) { return true; } + virtual bool get_attribute_int(uint32_t id, int32_t attribute, + int32_t *value) { + return true; + } + virtual bool set_attribute_str(uint32_t id, int32_t attribute, char **value, + int *len) { + return true; + } + virtual bool flush(uint32_t id) { return true; } }; -- 2.7.4 From 452278d1f20aebc46f4dc7a78a190d6e0baaf618 Mon Sep 17 00:00:00 2001 From: "taemin.yeom" Date: Tue, 11 May 2021 16:04:32 +0900 Subject: [PATCH 06/16] Add conditional compile directive to avoid build error Change-Id: I4e6d3bda7bcea0af59793344b0787b9aa89114b0 Signed-off-by: taemin.yeom --- haltest/sensor-haltest.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/haltest/sensor-haltest.h b/haltest/sensor-haltest.h index 033fb75..3e030f1 100644 --- a/haltest/sensor-haltest.h +++ b/haltest/sensor-haltest.h @@ -19,6 +19,7 @@ #include #include +#if (GTEST_VERSION_MAJOR < 1 || (GTEST_VERSION_MAJOR == 1 && GTEST_VERSION_MINOR < 10)) // hack gtest internal for print message namespace testing { @@ -34,6 +35,7 @@ namespace testing extern void ColoredPrintf(GTestColor color, const char* fmt, ...); } } +#endif #define SKIP_MESSAGE(fmt, args...) \ do { \ -- 2.7.4 From d8f8d0c6004ec5cf821c891a19b5d8fb690aaa17 Mon Sep 17 00:00:00 2001 From: Hyotaek Shim Date: Mon, 21 Jun 2021 20:51:21 +0900 Subject: [PATCH 07/16] Fix get_attribute interface Change-Id: I22e5145fbb8a11f32a0eba96d9dfbf335cf2e0ba Signed-off-by: Hyotaek Shim --- include/hal-sensor-types.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/hal-sensor-types.h b/include/hal-sensor-types.h index d7b78d1..07d89d3 100644 --- a/include/hal-sensor-types.h +++ b/include/hal-sensor-types.h @@ -574,7 +574,7 @@ class sensor_device { int32_t *value) { return true; } - virtual bool set_attribute_str(uint32_t id, int32_t attribute, char **value, + virtual bool get_attribute_str(uint32_t id, int32_t attribute, char **value, int *len) { return true; } -- 2.7.4 From ed1d69136415abe6c2f74eaac3eed67485108679 Mon Sep 17 00:00:00 2001 From: Hyotaek Shim Date: Mon, 21 Jun 2021 20:58:12 +0900 Subject: [PATCH 08/16] Add file cases to .gitignore Change-Id: I2bb317443cd46fbff28c369c92081dafe3422f26 Signed-off-by: Hyotaek Shim --- .gitignore | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 623211c..43c5f5b 100644 --- a/.gitignore +++ b/.gitignore @@ -9,4 +9,7 @@ build.ninja rules.ninja #ETC -.vscode/ \ No newline at end of file +.vscode/ +cscope.files +cscope.out +tags -- 2.7.4 From a1f3041dd445b01942e5b7bad512398a60798df3 Mon Sep 17 00:00:00 2001 From: "taemin.yeom" Date: Tue, 22 Jun 2021 10:51:05 +0900 Subject: [PATCH 09/16] Add const keyword to char* argument Change-Id: I84d417a5c4e17c1eeeb03c6c66654a8ef78b35b2 Signed-off-by: taemin.yeom --- include/hal-sensor-types.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/hal-sensor-types.h b/include/hal-sensor-types.h index 07d89d3..d4ee3fe 100644 --- a/include/hal-sensor-types.h +++ b/include/hal-sensor-types.h @@ -566,7 +566,7 @@ class sensor_device { int32_t value) { return true; } - virtual bool set_attribute_str(uint32_t id, int32_t attribute, char *value, + virtual bool set_attribute_str(uint32_t id, int32_t attribute, const char *value, int len) { return true; } -- 2.7.4 From e06b5066452e0967f04d278cce00ebc4e5ba635f Mon Sep 17 00:00:00 2001 From: Yunmi Ha Date: Fri, 9 Jul 2021 15:23:21 +0900 Subject: [PATCH 10/16] Divide HAL so file by each sensor Change-Id: I13af2315223a2730876983b587153bd4d75de346 Signed-off-by: Yunmi Ha --- src/hal-api-sensor.cpp | 111 +++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 99 insertions(+), 12 deletions(-) diff --git a/src/hal-api-sensor.cpp b/src/hal-api-sensor.cpp index 01683b7..7dbbd99 100644 --- a/src/hal-api-sensor.cpp +++ b/src/hal-api-sensor.cpp @@ -13,19 +13,23 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - +#include +#include #include #include #include "hal-api-sensor-log.h" #include "hal-sensor-interface.h" +#include "hal-sensor-types.h" #include "hal-sensor.h" #ifndef EXPORT #define EXPORT __attribute__((visibility("default"))) #endif -static hal_backend_sensor_funcs *hal_sensor_funcs = NULL; +static hal_backend_sensor_funcs **hal_sensor_funcs = NULL; +static char **hal_sensor_names = NULL; +static int hal_sensor_count = 0; /* -1 : failed to initialize 0 : not initialized @@ -33,33 +37,100 @@ static hal_backend_sensor_funcs *hal_sensor_funcs = NULL; */ static int hal_initialized = 0; +static std::vector hal_backend_devs; + +#define FREE(x) \ + do { if (x) { free(x); x = NULL; } } while(0) + EXPORT int hal_sensor_get_backend(void) { - int ret; + int ret_getnames, ret_getbackend; + int i; + int loaded_backend = 0; if (hal_sensor_funcs) return 0; - ret = hal_common_get_backend(HAL_MODULE_SENSOR, (void **)&hal_sensor_funcs); - if (ret < 0) { - _E("Failed to get backend"); - hal_initialized = -1; + hal_sensor_count = hal_common_get_backend_count(HAL_MODULE_SENSOR); + if (hal_sensor_count < 0) { + _E("Failed to get backend count."); + return -ENODEV; + } else if (hal_sensor_count == 0) { + _E("There is no hal-backend-sensor library."); + return -ENODEV; + } + + hal_sensor_names = (char **)malloc(sizeof(char *) * hal_sensor_count); + if (!hal_sensor_names) { + _E("Failed to allocate memory."); + hal_sensor_count = 0; return -ENODEV; } + for (i = 0; i < hal_sensor_count; i++) { + hal_sensor_names[i] = (char *)malloc(sizeof(char) * 256); + if (!hal_sensor_names[i]) { + _E("Failed to allocate memory."); + goto FREE_MEMORY; + } + } + + ret_getnames = hal_common_get_backend_library_names(HAL_MODULE_SENSOR, hal_sensor_names, hal_sensor_count); + if (ret_getnames < 0) { + _E("Failed to get backend library names."); + goto FREE_MEMORY; + } + + hal_sensor_funcs = (hal_backend_sensor_funcs **)malloc(sizeof(hal_backend_sensor_funcs *) * hal_sensor_count); + if (!hal_sensor_funcs) { + _E("Failed to allocate memory."); + goto FREE_MEMORY; + } + + for(i = 0; i < hal_sensor_count; i++) { + ret_getbackend = hal_common_get_backend_with_library_name(HAL_MODULE_SENSOR, (void **)&hal_sensor_funcs[i], hal_sensor_names[i]); + if (ret_getbackend < 0) { + _E("Failed to get backend (%s)", hal_sensor_names[i]); + } else + loaded_backend++; + } + + if (loaded_backend == 0) { + FREE(hal_sensor_funcs); + goto FREE_MEMORY; + } + hal_initialized = 1; return 0; + +FREE_MEMORY: + for(i = 0; i < hal_sensor_count; i++) + FREE(hal_sensor_names[i]); + + FREE(hal_sensor_names); + + hal_sensor_count = 0; + hal_initialized = -1; + return -ENODEV; } EXPORT int hal_sensor_put_backend(void) { + int i = 0; if (!hal_sensor_funcs) return -ENODEV; - hal_common_put_backend(HAL_MODULE_SENSOR, (void *)hal_sensor_funcs); - hal_sensor_funcs = NULL; + for (i = 0; i < hal_sensor_count; i++) { + if (hal_sensor_funcs[i]) { + hal_common_put_backend_with_library_name(HAL_MODULE_SENSOR, (void *)hal_sensor_funcs[i], hal_sensor_names[i]); + } + FREE(hal_sensor_names[i]); + } + FREE(hal_sensor_names); + FREE(hal_sensor_funcs); + hal_initialized = 0; return 0; @@ -68,15 +139,31 @@ int hal_sensor_put_backend(void) EXPORT int hal_sensor_create(sensor_device_t **devices) { - int ret; + int ret, ret_create; + int i, j; + sensor_device_t *device; if (!hal_sensor_funcs && !hal_initialized) { if ((ret = hal_sensor_get_backend()) < 0) return ret; } - if (!hal_sensor_funcs || !hal_sensor_funcs->create) + if (!hal_sensor_funcs || (hal_sensor_count == 0)) return -ENODEV; - return hal_sensor_funcs->create(devices); + if (hal_backend_devs.empty()) { + for (i = 0; i < hal_sensor_count; i++) { + if (!hal_sensor_funcs[i] || !hal_sensor_funcs[i]->create) + continue; + + ret_create = hal_sensor_funcs[i]->create(&device); + for (j = 0; j < ret_create; j++) + { + hal_backend_devs.push_back(device[j]); + } + } + } + + *devices = &hal_backend_devs[0]; + return hal_backend_devs.size(); } -- 2.7.4 From f0f58a0bff4126e122af6676e6ada40f60e2781a Mon Sep 17 00:00:00 2001 From: Yunmi Ha Date: Tue, 13 Jul 2021 11:35:15 +0900 Subject: [PATCH 11/16] Change hal_common_get_backend_library_names API parameter. Change-Id: I1bca6851b6a8b2704622ebf44fbf4bfa6b413ce5 Signed-off-by: Yunmi Ha --- src/hal-api-sensor.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/hal-api-sensor.cpp b/src/hal-api-sensor.cpp index 7dbbd99..02a88b5 100644 --- a/src/hal-api-sensor.cpp +++ b/src/hal-api-sensor.cpp @@ -42,6 +42,8 @@ static std::vector hal_backend_devs; #define FREE(x) \ do { if (x) { free(x); x = NULL; } } while(0) +#define MAX_LIB_NAME 256 + EXPORT int hal_sensor_get_backend(void) { @@ -69,14 +71,14 @@ int hal_sensor_get_backend(void) } for (i = 0; i < hal_sensor_count; i++) { - hal_sensor_names[i] = (char *)malloc(sizeof(char) * 256); + hal_sensor_names[i] = (char *)malloc(sizeof(char) * MAX_LIB_NAME); if (!hal_sensor_names[i]) { _E("Failed to allocate memory."); goto FREE_MEMORY; } } - ret_getnames = hal_common_get_backend_library_names(HAL_MODULE_SENSOR, hal_sensor_names, hal_sensor_count); + ret_getnames = hal_common_get_backend_library_names(HAL_MODULE_SENSOR, hal_sensor_names, hal_sensor_count, MAX_LIB_NAME); if (ret_getnames < 0) { _E("Failed to get backend library names."); goto FREE_MEMORY; -- 2.7.4 From 721d9b70d9d1be8e6390e8034b79e1139447e2c0 Mon Sep 17 00:00:00 2001 From: Hyotaek Shim Date: Wed, 14 Jul 2021 10:58:39 +0900 Subject: [PATCH 12/16] Change sensor-haltests rpm to hal-api-sensor-haltests Change-Id: I76fae2d91e5e65e8ec7c06eb24bf93cb5cb7ab90 Signed-off-by: Hyotaek Shim --- packaging/hal-api-sensor.spec | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packaging/hal-api-sensor.spec b/packaging/hal-api-sensor.spec index c86626f..8c7ac36 100644 --- a/packaging/hal-api-sensor.spec +++ b/packaging/hal-api-sensor.spec @@ -35,11 +35,11 @@ Requires: %{name} = %{version}-%{release} %{name} Interface for product vendor developer ### hal test package ######## -%package -n sensor-haltests +%package haltests Summary: Sensor HAL(Hardware Abstraction Layer) Test Cases Requires: %{name} = %{version}-%{release} -%description -n sensor-haltests +%description haltests Sensor HAL(Hardware Abstraction Layer) Test Cases ### build and install ######### @@ -82,7 +82,7 @@ rm -rf %{buildroot} %{_includedir}/hal/*.h %{_libdir}/pkgconfig/%{name}.pc -%files -n sensor-haltests +%files haltests %manifest %{name}.manifest %license LICENSE %{_bindir}/hal/sensor-haltests -- 2.7.4 From f22456cf0cf1e054d62b4847d28610c03a28c997 Mon Sep 17 00:00:00 2001 From: "taemin.yeom" Date: Mon, 27 Sep 2021 18:45:08 +0900 Subject: [PATCH 13/16] Add checking features in sensor haltest Change-Id: I0d0086eb401d835a0520a94156d5f4512bbda625 Signed-off-by: taemin.yeom --- haltest/CMakeLists.txt | 1 + haltest/main.cpp | 13 +++++++---- haltest/sensor-device.cpp | 10 +++++++-- haltest/sensor-haltest.h | 52 +++++++++++++++++++++++++++++++++++++++++++ packaging/hal-api-sensor.spec | 1 + 5 files changed, 71 insertions(+), 6 deletions(-) diff --git a/haltest/CMakeLists.txt b/haltest/CMakeLists.txt index 97c237c..6cccd68 100644 --- a/haltest/CMakeLists.txt +++ b/haltest/CMakeLists.txt @@ -12,6 +12,7 @@ SET(REQUIRES_LIST ${REQUIRES_LIST} gio-2.0 gmock dlog + capi-system-info ) FIND_LIBRARY( diff --git a/haltest/main.cpp b/haltest/main.cpp index 287c9f4..1a20fef 100644 --- a/haltest/main.cpp +++ b/haltest/main.cpp @@ -12,14 +12,20 @@ protected: static void SetUpHalTestSuite() { } - void SetUp() override {} + void SetUp() override { + int ret_val = check_feature_all(); + if (!ret_val) { + SKIP_MESSAGE("All sensor features are false"); + GTEST_SKIP(); + return; + } + } void TearDown() override {} }; TEST_F(SENSOR_API, GetBackendP) { int ret_val; - ret_val = hal_sensor_get_backend(); EXPECT_EQ(ret_val, 0) << strerr("Failed to get sensor device", ret_val); } @@ -27,12 +33,11 @@ TEST_F(SENSOR_API, GetBackendP) TEST_F(SENSOR_API, CreateP) { int ret_val; - void **devices; ret_val = hal_sensor_create(&devices); if (ret_val == -ENODEV) { SKIP_MESSAGE("Not supported HAL"); - return ; + return; } ASSERT_GT(ret_val, 0) << strerr("Failed to call create", ret_val); ASSERT_NE(devices[0], nullptr) << "Opened devices are invalid."; diff --git a/haltest/sensor-device.cpp b/haltest/sensor-device.cpp index 58bd034..3b87482 100644 --- a/haltest/sensor-device.cpp +++ b/haltest/sensor-device.cpp @@ -13,7 +13,6 @@ public: static void SetUpHalTestSuite() { void **sensors = nullptr; - device_count = hal_sensor_create(&sensors); ASSERT_GT(device_count, 0) << "Failed to get sensor devices"; @@ -23,7 +22,14 @@ public: } } - void SetUp() override{} + void SetUp() override { + int ret_val = check_feature_all(); + if (!ret_val) { + SKIP_MESSAGE("All sensor features are false"); + GTEST_SKIP(); + return; + } + } void TearDown() override{} }; diff --git a/haltest/sensor-haltest.h b/haltest/sensor-haltest.h index 3e030f1..88ef284 100644 --- a/haltest/sensor-haltest.h +++ b/haltest/sensor-haltest.h @@ -16,6 +16,7 @@ #ifndef __SENSOR_HALTEST_H__ #define __SENSOR_HALTEST_H__ +#include #include #include @@ -63,6 +64,57 @@ do { \ #define BUFMAX 256 static char errbuf1[BUFMAX]; +#define FEATURE_NUM 37 +static const char *feature[FEATURE_NUM] = { + "http://tizen.org/feature/sensor.accelerometer", + "http://tizen.org/feature/sensor.accelerometer.wakeup", + "http://tizen.org/feature/sensor.activity_recognition", + "http://tizen.org/feature/sensor.barometer", + "http://tizen.org/feature/sensor.barometer.wakeup", + "http://tizen.org/feature/sensor.geomagnetic_rotation_vector", + "http://tizen.org/feature/sensor.gesture_recognition", + "http://tizen.org/feature/sensor.gravity", + "http://tizen.org/feature/sensor.gyroscope", + "http://tizen.org/feature/sensor.gyroscope_rotation_vector", + "http://tizen.org/feature/sensor.gyroscope.uncalibrated", + "http://tizen.org/feature/sensor.gyroscope.wakeup", + "http://tizen.org/feature/sensor.heart_rate_monitor", + "http://tizen.org/feature/sensor.heart_rate_monitor.batch", + "http://tizen.org/feature/sensor.heart_rate_monitor.led_green", + "http://tizen.org/feature/sensor.heart_rate_monitor.led_green.batch", + "http://tizen.org/feature/sensor.heart_rate_monitor.led_ir", + "http://tizen.org/feature/sensor.heart_rate_monitor.led_red", + "http://tizen.org/feature/sensor.humidity", + "http://tizen.org/feature/sensor.linear_acceleration", + "http://tizen.org/feature/sensor.magnetometer", + "http://tizen.org/feature/sensor.magnetometer.uncalibrated", + "http://tizen.org/feature/sensor.magnetometer.wakeup", + "http://tizen.org/feature/sensor.pedometer", + "http://tizen.org/feature/sensor.photometer", + "http://tizen.org/feature/sensor.photometer.wakeup", + "http://tizen.org/feature/sensor.proximity", + "http://tizen.org/feature/sensor.proximity.wakeup", + "http://tizen.org/feature/sensor.rotation_vector", + "http://tizen.org/feature/sensor.significant_motion", + "http://tizen.org/feature/sensor.sleep_monitor", + "http://tizen.org/feature/sensor.stress_monitor", + "http://tizen.org/feature/sensor.temperature", + "http://tizen.org/feature/sensor.tiltmeter", + "http://tizen.org/feature/sensor.tiltmeter.wakeup", + "http://tizen.org/feature/sensor.ultraviolet", + "http://tizen.org/feature/sensor.wrist_up" +}; + +static bool check_feature_all() { + bool ret, val; + for (int i = 0; i < FEATURE_NUM; ++i) { + ret = system_info_get_platform_bool(feature[i], &val); + if (!ret && val) + return true; + } + return false; +} + static inline const char* strerr(const char* message, int eno) { if (eno == 0) diff --git a/packaging/hal-api-sensor.spec b/packaging/hal-api-sensor.spec index 8c7ac36..ca81eea 100644 --- a/packaging/hal-api-sensor.spec +++ b/packaging/hal-api-sensor.spec @@ -21,6 +21,7 @@ BuildRequires: pkgconfig(gio-2.0) BuildRequires: pkgconfig(glib-2.0) BuildRequires: pkgconfig(gmock) BuildRequires: pkgconfig(hal-api-common) +BuildRequires: pkgconfig(capi-system-info) %description %{name} interface -- 2.7.4 From ddb260cd112300bb0be27f0b7e1e857afaae719b Mon Sep 17 00:00:00 2001 From: "taemin.yeom" Date: Wed, 29 Sep 2021 13:22:42 +0900 Subject: [PATCH 14/16] Support lower gtest version "GTEST_SKIP()" is supported from gtest 1.10 so in lower version, it has to been ignored. Change-Id: Ic2a64eb5005ec177dfb6bc04d2dbf55133cfd453 Signed-off-by: taemin.yeom --- haltest/main.cpp | 4 ++++ haltest/sensor-device.cpp | 10 ++++++++++ haltest/sensor-haltest.h | 6 ++++++ 3 files changed, 20 insertions(+) diff --git a/haltest/main.cpp b/haltest/main.cpp index 1a20fef..a142e3e 100644 --- a/haltest/main.cpp +++ b/haltest/main.cpp @@ -25,6 +25,8 @@ protected: TEST_F(SENSOR_API, GetBackendP) { + SKIP_NO_FEATURE(); + int ret_val; ret_val = hal_sensor_get_backend(); EXPECT_EQ(ret_val, 0) << strerr("Failed to get sensor device", ret_val); @@ -32,6 +34,8 @@ TEST_F(SENSOR_API, GetBackendP) TEST_F(SENSOR_API, CreateP) { + SKIP_NO_FEATURE(); + int ret_val; void **devices; ret_val = hal_sensor_create(&devices); diff --git a/haltest/sensor-device.cpp b/haltest/sensor-device.cpp index 3b87482..ed28660 100644 --- a/haltest/sensor-device.cpp +++ b/haltest/sensor-device.cpp @@ -36,6 +36,11 @@ public: int SENSOR_DEV::device_count = 0; device_registry_t SENSOR_DEV::devices; +#define SKIP_NO_FEATURE() \ + if (!check_feature_all()) { \ + return; \ + } + #define SKIP_NO_DEV() \ if (device_count <= 0) { \ SKIP_MESSAGE("There is no sensor devices."); \ @@ -44,6 +49,7 @@ device_registry_t SENSOR_DEV::devices; TEST_F(SENSOR_DEV, get_poll_fdP) { + SKIP_NO_FEATURE() SKIP_NO_DEV() for (auto it = devices.begin(); it != devices.end(); ++it) { @@ -56,6 +62,7 @@ TEST_F(SENSOR_DEV, get_sensorsP) const sensor_info_t *sensors = nullptr; int ret_func; + SKIP_NO_FEATURE() SKIP_NO_DEV() for (auto it = devices.begin(); it != devices.end(); ++it) { @@ -67,6 +74,7 @@ TEST_F(SENSOR_DEV, get_sensorsP) TEST_F(SENSOR_DEV, get_sensorsN) { + SKIP_NO_FEATURE() SKIP_NO_DEV() for (auto it = devices.begin(); it != devices.end(); ++it) { @@ -154,6 +162,7 @@ TEST_F(SENSOR_DEV, get_dataP) sensor_data_t *data = NULL; const sensor_info_t *sensors = nullptr; + SKIP_NO_FEATURE() SKIP_NO_DEV() for (auto it = devices.begin(); it != devices.end(); ++it) { @@ -169,6 +178,7 @@ TEST_F(SENSOR_DEV, get_dataN) int length = 0; sensor_data_t *data = NULL; + SKIP_NO_FEATURE() SKIP_NO_DEV() for (auto it = devices.begin(); it != devices.end(); ++it) { diff --git a/haltest/sensor-haltest.h b/haltest/sensor-haltest.h index 88ef284..bd4ec43 100644 --- a/haltest/sensor-haltest.h +++ b/haltest/sensor-haltest.h @@ -21,6 +21,7 @@ #include #if (GTEST_VERSION_MAJOR < 1 || (GTEST_VERSION_MAJOR == 1 && GTEST_VERSION_MINOR < 10)) +#define GTEST_SKIP() ; // hack gtest internal for print message namespace testing { @@ -52,6 +53,11 @@ do { \ testing::internal::ColoredPrintf(testing::internal::COLOR_DEFAULT, "\n"); \ } while (0) +#define SKIP_NO_FEATURE() \ + if (!check_feature_all()) { \ + return; \ + } + // SetUp/TearDown function for a testsuite differ by gtest version #if (GTEST_VERSION_MAJOR >= 2 || (GTEST_VERSION_MAJOR == 1 && GTEST_VERSION_MINOR >= 10)) #define SetUpHalTestSuite SetUpTestSuite -- 2.7.4 From 87f764d7d0448a658ec37fabde9d662593e915f8 Mon Sep 17 00:00:00 2001 From: "taemin.yeom" Date: Wed, 29 Sep 2021 13:50:27 +0900 Subject: [PATCH 15/16] Fix redefinition and expression of macro Change-Id: I7c4fe6eaf34371fd00f4520bd02f466cbe549c34 Signed-off-by: taemin.yeom --- haltest/main.cpp | 6 ------ haltest/sensor-device.cpp | 35 +++++++++++++---------------------- haltest/sensor-haltest.h | 8 ++++++-- 3 files changed, 19 insertions(+), 30 deletions(-) diff --git a/haltest/main.cpp b/haltest/main.cpp index a142e3e..a0da52b 100644 --- a/haltest/main.cpp +++ b/haltest/main.cpp @@ -13,12 +13,6 @@ protected: } void SetUp() override { - int ret_val = check_feature_all(); - if (!ret_val) { - SKIP_MESSAGE("All sensor features are false"); - GTEST_SKIP(); - return; - } } void TearDown() override {} }; diff --git a/haltest/sensor-device.cpp b/haltest/sensor-device.cpp index ed28660..2856c8f 100644 --- a/haltest/sensor-device.cpp +++ b/haltest/sensor-device.cpp @@ -23,12 +23,6 @@ public: } void SetUp() override { - int ret_val = check_feature_all(); - if (!ret_val) { - SKIP_MESSAGE("All sensor features are false"); - GTEST_SKIP(); - return; - } } void TearDown() override{} }; @@ -36,21 +30,18 @@ public: int SENSOR_DEV::device_count = 0; device_registry_t SENSOR_DEV::devices; -#define SKIP_NO_FEATURE() \ - if (!check_feature_all()) { \ - return; \ - } - #define SKIP_NO_DEV() \ +do { \ if (device_count <= 0) { \ SKIP_MESSAGE("There is no sensor devices."); \ return; \ - } + } \ +} while (0) TEST_F(SENSOR_DEV, get_poll_fdP) { - SKIP_NO_FEATURE() - SKIP_NO_DEV() + SKIP_NO_FEATURE(); + SKIP_NO_DEV(); for (auto it = devices.begin(); it != devices.end(); ++it) { EXPECT_NE((*it)->get_poll_fd(), 0); @@ -62,8 +53,8 @@ TEST_F(SENSOR_DEV, get_sensorsP) const sensor_info_t *sensors = nullptr; int ret_func; - SKIP_NO_FEATURE() - SKIP_NO_DEV() + SKIP_NO_FEATURE(); + SKIP_NO_DEV(); for (auto it = devices.begin(); it != devices.end(); ++it) { ret_func = (*it)->get_sensors(&sensors); @@ -74,8 +65,8 @@ TEST_F(SENSOR_DEV, get_sensorsP) TEST_F(SENSOR_DEV, get_sensorsN) { - SKIP_NO_FEATURE() - SKIP_NO_DEV() + SKIP_NO_FEATURE(); + SKIP_NO_DEV(); for (auto it = devices.begin(); it != devices.end(); ++it) { EXPECT_EQ((*it)->get_sensors(nullptr), -EINVAL); @@ -162,8 +153,8 @@ TEST_F(SENSOR_DEV, get_dataP) sensor_data_t *data = NULL; const sensor_info_t *sensors = nullptr; - SKIP_NO_FEATURE() - SKIP_NO_DEV() + SKIP_NO_FEATURE(); + SKIP_NO_DEV(); for (auto it = devices.begin(); it != devices.end(); ++it) { EXPECT_GE((*it)->get_sensors(&sensors), 1); @@ -178,8 +169,8 @@ TEST_F(SENSOR_DEV, get_dataN) int length = 0; sensor_data_t *data = NULL; - SKIP_NO_FEATURE() - SKIP_NO_DEV() + SKIP_NO_FEATURE(); + SKIP_NO_DEV(); for (auto it = devices.begin(); it != devices.end(); ++it) { EXPECT_EQ((*it)->get_data(0, &data, &length), -EINVAL); diff --git a/haltest/sensor-haltest.h b/haltest/sensor-haltest.h index bd4ec43..a1f2e9f 100644 --- a/haltest/sensor-haltest.h +++ b/haltest/sensor-haltest.h @@ -21,7 +21,7 @@ #include #if (GTEST_VERSION_MAJOR < 1 || (GTEST_VERSION_MAJOR == 1 && GTEST_VERSION_MINOR < 10)) -#define GTEST_SKIP() ; +#define GTEST_SKIP() // hack gtest internal for print message namespace testing { @@ -54,9 +54,13 @@ do { \ } while (0) #define SKIP_NO_FEATURE() \ +do { \ if (!check_feature_all()) { \ + SKIP_MESSAGE("All sensor features are false"); \ + GTEST_SKIP(); \ return; \ - } + } \ +} while (0) // SetUp/TearDown function for a testsuite differ by gtest version #if (GTEST_VERSION_MAJOR >= 2 || (GTEST_VERSION_MAJOR == 1 && GTEST_VERSION_MINOR >= 10)) -- 2.7.4 From 985dd0ad44c2180d33ca2fea986819a6e4b3ddcc Mon Sep 17 00:00:00 2001 From: "taemin.yeom" Date: Fri, 17 Dec 2021 19:25:03 +0900 Subject: [PATCH 16/16] Add Lidar HAL sensor type Change-Id: I41fcb83fbb4a320d4025b3acf328d6278cd36821 Signed-off-by: taemin.yeom (cherry picked from commit 32d51134f5c50a6b56965ba3a05ecc5212f83ba7) --- include/hal-sensor-types.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/include/hal-sensor-types.h b/include/hal-sensor-types.h index d4ee3fe..2c1949c 100644 --- a/include/hal-sensor-types.h +++ b/include/hal-sensor-types.h @@ -153,6 +153,8 @@ typedef enum { SENSOR_DEVICE_GSR, SENSOR_DEVICE_SIMSENSE, SENSOR_DEVICE_PPG, + + SENSOR_DEVICE_LIDAR = 0x8000, } sensor_device_type; /* -- 2.7.4