Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unittest: add a test folder v1 #150

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ add_subdirectory(ivi-layermanagement-examples)
add_subdirectory(ivi-layermanagement-api/ilmInput)
add_subdirectory(ivi-input-modules/ivi-input-controller)
add_subdirectory(ivi-id-agent-modules/ivi-id-agent)
add_subdirectory(unittest)


#=============================================================================================
Expand Down
10 changes: 9 additions & 1 deletion README
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,18 @@ EGLWLMockNavigation:
Syntax: [wayland_display_to_connect_to] <your installation path>/bin/EGLWLMockNavigation
Example: WAYLAND_DISPLAY=wayland-1 $HOME/bin/EGLWLMockNavigation

How to test
How to test functional testing
====================================
1. Build the testsuite by setting BUILD_ILM_API_TESTS option.
Example: cmake -DBUILD_ILM_API_TESTS
2. After starting up Weston run the testsuite.
Syntax: [wayland_display_to_connect_to] <your installation path>/bin/ivi-layermanagement-api-test
Example: WAYLAND_DISPLAY=wayland-1 $HOME/bin/ivi-layermanagement-api-test

How to test unit testing
====================================
1. Build the testsuite by setting BUILD_ILM_UNIT_TESTS option.
Example: cmake -DBUILD_ILM_UNIT_TESTS=ON
2. After build successfully, just run the testsuite right away.
Syntax: <your installation path>/bin/unittest*
Example: $HOME/install/bin/unittest-ivi-controller
33 changes: 33 additions & 0 deletions unittest/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
############################################################################
#
# Copyright (C) 2023 Advanced Driver Information Technology Joint Venture GmbH
#
#
# 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.
#
############################################################################

CMAKE_MINIMUM_REQUIRED(VERSION 2.6)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The warning messages when configuring of cmake.
change to: 65fa39b

find_package(gtest REQUIRED)

IF(NOT gtest_FOUND)
MESSAGE(STATUS "gtest not found, disabling unit tests (BUILD_ILM_UNIT_TESTS=OFF)")
SET(BUILD_ILM_UNIT_TESTS FALSE CACHE BOOL "Build unit tests for IVI LayerManagement API" FORCE)
ENDIF()

IF(BUILD_ILM_UNIT_TESTS)
enable_testing()
add_subdirectory(client)
add_subdirectory(server)
ENDIF()
95 changes: 95 additions & 0 deletions unittest/client/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
############################################################################
#
# Copyright (C) 2023 Advanced Driver Information Technology Joint Venture GmbH
#
#
# 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.
#
############################################################################

CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
cmake_policy(SET CMP0046 OLD)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The warning messages when configuring of cmake.
65fa39b

PROJECT(ilm_client_unittest)

INCLUDE_DIRECTORIES(
${CMAKE_CURRENT_SOURCE_DIR}/../../ivi-layermanagement-api/ilmControl/src
${CMAKE_CURRENT_SOURCE_DIR}/../../ivi-layermanagement-api/ilmCommon/include
${CMAKE_CURRENT_SOURCE_DIR}/../../ivi-layermanagement-api/ilmControl/include
${CMAKE_CURRENT_SOURCE_DIR}/../../ivi-layermanagement-api/ilmInput/include
${CMAKE_CURRENT_BINARY_DIR}/../../ivi-layermanagement-api/ilmControl
${CMAKE_CURRENT_BINARY_DIR}/../../protocol
${CMAKE_CURRENT_SOURCE_DIR}/include
${CMAKE_CURRENT_SOURCE_DIR}/../common
${WAYLAND_CLIENT_INCLUDE_DIRS}
${WESTON_INCLUDE_DIRS}
${gtest_INCLUDE_DIRS}
)

LINK_DIRECTORIES(
${WAYLAND_CLIENT_LIBRARY_DIRS}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no binaries link to libwayland-client.so, don't need to keep this link

)

SET(LIBS
${gtest_LIBRARIES}
)

SET(SRC_COMMON_FILES
${CMAKE_CURRENT_SOURCE_DIR}/src/client_api_fake.c
${CMAKE_CURRENT_SOURCE_DIR}/../common/common_fake_api.c
)

SET(SRC_IVI_COMMON_FILES
${CMAKE_CURRENT_SOURCE_DIR}/src/ilm_common_unittests.cpp
${CMAKE_CURRENT_SOURCE_DIR}/../../ivi-layermanagement-api/ilmCommon/src/ilm_common.c
${CMAKE_CURRENT_SOURCE_DIR}/../../ivi-layermanagement-api/ilmCommon/src/ilm_common_wayland_platform.c
)

SET(SRC_IVI_CONTROL_FILES
${CMAKE_CURRENT_SOURCE_DIR}/src/ilm_control_unittests.cpp
)

SET(SRC_IVI_INPUT_FILES
${CMAKE_CURRENT_SOURCE_DIR}/src/ilm_input_uinttests.cpp
${CMAKE_CURRENT_SOURCE_DIR}/../../ivi-layermanagement-api/ilmInput/src/ilm_input.c
)

SET(GCC_SANITIZER_COMPILE_FLAGS "-fsanitize=address -fsanitize=undefined -fno-sanitize-recover -fstack-protector-all -fpermissive")
IF(BUILD_CODE_COVERAGE)
SET(COVERAGE_COMPILER_FLAGS "-g --coverage")
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${COVERAGE_COMPILER_FLAGS}")
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${GCC_SANITIZER_COMPILE_FLAGS} -pthread ${COVERAGE_COMPILER_FLAGS}")
SET(CMAKE_CXX_LINK_FLAGS "${CMAKE_CXX_LINK_FLAGS} -static-libasan -static-libubsan ${COVERAGE_COMPILER_FLAGS}")
ELSE()
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${GCC_SANITIZER_COMPILE_FLAGS} -pthread")
SET(CMAKE_CXX_LINK_FLAGS "${CMAKE_CXX_LINK_FLAGS} -static-libasan -static-libubsan")
ENDIF()

ADD_EXECUTABLE(unittest-ilm-common ${SRC_COMMON_FILES} ${SRC_IVI_COMMON_FILES})
TARGET_LINK_LIBRARIES(unittest-ilm-common ${LIBS})
ADD_DEPENDENCIES(unittest-ilm-common ${LIBS})
INSTALL(TARGETS unittest-ilm-common DESTINATION bin)

ADD_EXECUTABLE(unittest-ilm-input ${SRC_COMMON_FILES} ${SRC_IVI_INPUT_FILES})
TARGET_LINK_LIBRARIES(unittest-ilm-input ${LIBS})
ADD_DEPENDENCIES(unittest-ilm-input ${LIBS})
INSTALL(TARGETS unittest-ilm-input DESTINATION bin)

ADD_EXECUTABLE(unittest-ilm-control ${SRC_COMMON_FILES} ${SRC_IVI_CONTROL_FILES})
TARGET_LINK_LIBRARIES(unittest-ilm-control ${LIBS})
ADD_DEPENDENCIES(unittest-ilm-control ${LIBS})
INSTALL(TARGETS unittest-ilm-control DESTINATION bin)

ADD_TEST(Unittest-ilm-common unittest-ilm-common)
ADD_TEST(Unittest-ilm-input unittest-ilm-input)
ADD_TEST(Unittest-ilm-control unittest-ilm-control)
96 changes: 96 additions & 0 deletions unittest/client/include/client_api_fake.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
/***************************************************************************
*
* Copyright (C) 2023 Advanced Driver Information Technology Joint Venture GmbH
*
*
* 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 CLIENT_API_FAKE
#define CLIENT_API_FAKE

#include "stdint.h"
#include <pthread.h>
#include "fff.h"
#include "common_fake_api.h"

#ifdef __cplusplus
extern "C" {
#endif

typedef void (**registerHandler) (void);
typedef void *(*threadEntry) (void *);

DECLARE_FAKE_VALUE_FUNC(struct wl_display *, wl_display_connect, const char *);
DECLARE_FAKE_VALUE_FUNC(struct wl_event_queue *, wl_display_create_queue, struct wl_display *);
DECLARE_FAKE_VALUE_FUNC(int, wl_display_roundtrip, struct wl_display *);
DECLARE_FAKE_VALUE_FUNC(int, wl_proxy_add_listener, struct wl_proxy *, registerHandler, void *);
DECLARE_FAKE_VALUE_FUNC(int, wl_display_roundtrip_queue, struct wl_display *, struct wl_event_queue *);
DECLARE_FAKE_VALUE_FUNC(int, pthread_create, pthread_t *, const pthread_attr_t *, threadEntry, void *);
DECLARE_FAKE_VALUE_FUNC(int, wl_display_flush, struct wl_display *);
DECLARE_FAKE_VALUE_FUNC(int, wl_display_dispatch_queue, struct wl_display *, struct wl_event_queue *);
DECLARE_FAKE_VALUE_FUNC(int, wl_display_dispatch_queue_pending, struct wl_display *, struct wl_event_queue *);
DECLARE_FAKE_VALUE_FUNC(int, wl_display_get_error, struct wl_display *);
DECLARE_FAKE_VALUE_FUNC(int, wl_display_get_fd, struct wl_display *);
DECLARE_FAKE_VALUE_FUNC(int, wl_display_prepare_read_queue, struct wl_display *, struct wl_event_queue *);
DECLARE_FAKE_VALUE_FUNC(int, wl_display_read_events, struct wl_display *);
DECLARE_FAKE_VALUE_FUNC(uint32_t, wl_proxy_get_version, struct wl_proxy *);
DECLARE_FAKE_VOID_FUNC(wl_display_disconnect, struct wl_display *);
DECLARE_FAKE_VOID_FUNC(wl_event_queue_destroy, struct wl_event_queue *);
DECLARE_FAKE_VOID_FUNC(wl_proxy_set_queue, struct wl_proxy *, struct wl_event_queue *);
DECLARE_FAKE_VOID_FUNC(wl_proxy_destroy, struct wl_proxy *);
DECLARE_FAKE_VOID_FUNC(wl_display_cancel_read, struct wl_display *);
DECLARE_FAKE_VOID_FUNC(wl_list_insert, struct wl_list *, struct wl_list *);
DECLARE_FAKE_VALUE_FUNC(void *, wl_array_add, struct wl_array *, size_t);
DECLARE_FAKE_VALUE_FUNC_VARARG(struct wl_proxy *, wl_proxy_marshal_flags, struct wl_proxy *, uint32_t, const struct wl_interface *, uint32_t, uint32_t, ...);
DECLARE_FAKE_VOID_FUNC(wl_array_init, struct wl_array *);
DECLARE_FAKE_VOID_FUNC(wl_array_release, struct wl_array *);
DECLARE_FAKE_VOID_FUNC(wl_list_init, struct wl_list *);
DECLARE_FAKE_VOID_FUNC(wl_list_remove, struct wl_list *);
DECLARE_FAKE_VALUE_FUNC(int, wl_list_length, const struct wl_list *);

#define CLIENT_API_FAKE_LIST(FAKE) \
FAKE(wl_display_connect) \
FAKE(wl_display_create_queue) \
FAKE(wl_display_roundtrip) \
FAKE(wl_proxy_add_listener) \
FAKE(wl_display_roundtrip_queue) \
FAKE(pthread_create) \
FAKE(wl_display_flush) \
FAKE(wl_display_dispatch_queue) \
FAKE(wl_display_dispatch_queue_pending) \
FAKE(wl_display_get_error) \
FAKE(wl_display_get_fd) \
FAKE(wl_display_prepare_read_queue) \
FAKE(wl_display_read_events) \
FAKE(wl_proxy_get_version) \
FAKE(wl_display_disconnect) \
FAKE(wl_event_queue_destroy) \
FAKE(wl_proxy_set_queue) \
FAKE(wl_proxy_destroy) \
FAKE(wl_display_cancel_read) \
FAKE(wl_list_insert) \
FAKE(wl_array_add) \
FAKE(wl_proxy_marshal_flags) \
FAKE(wl_array_init) \
FAKE(wl_array_release) \
FAKE(wl_list_init) \
FAKE(wl_list_remove) \
FAKE(wl_list_length) \
FFF_RESET_HISTORY()

#ifdef __cplusplus
}
#endif
#endif // CLIENT_API_FAKE
52 changes: 52 additions & 0 deletions unittest/client/src/client_api_fake.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/***************************************************************************
*
* Copyright (C) 2023 Advanced Driver Information Technology Joint Venture GmbH
*
*
* 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 "client_api_fake.h"
#include "ilm_control_platform.h"
#include "wayland-client-protocol.h"

DEFINE_FFF_GLOBALS;

DEFINE_FAKE_VALUE_FUNC(struct wl_display *, wl_display_connect, const char *);
DEFINE_FAKE_VALUE_FUNC(struct wl_event_queue *, wl_display_create_queue, struct wl_display *);
DEFINE_FAKE_VALUE_FUNC(int, wl_display_roundtrip, struct wl_display *);
DEFINE_FAKE_VALUE_FUNC(int, wl_proxy_add_listener, struct wl_proxy *, registerHandler, void *);
DEFINE_FAKE_VALUE_FUNC(int, wl_display_roundtrip_queue, struct wl_display *, struct wl_event_queue *);
DEFINE_FAKE_VALUE_FUNC(int, pthread_create, pthread_t *, const pthread_attr_t *, threadEntry, void *);
DEFINE_FAKE_VALUE_FUNC(int, wl_display_flush, struct wl_display *);
DEFINE_FAKE_VALUE_FUNC(int, wl_display_dispatch_queue, struct wl_display *, struct wl_event_queue *);
DEFINE_FAKE_VALUE_FUNC(int, wl_display_dispatch_queue_pending, struct wl_display *, struct wl_event_queue *);
DEFINE_FAKE_VALUE_FUNC(int, wl_display_get_error, struct wl_display *);
DEFINE_FAKE_VALUE_FUNC(int, wl_display_get_fd, struct wl_display *);
DEFINE_FAKE_VALUE_FUNC(int, wl_display_prepare_read_queue, struct wl_display *, struct wl_event_queue *);
DEFINE_FAKE_VALUE_FUNC(int, wl_display_read_events, struct wl_display *);
DEFINE_FAKE_VOID_FUNC(wl_display_cancel_read, struct wl_display *);
DEFINE_FAKE_VALUE_FUNC(uint32_t, wl_proxy_get_version, struct wl_proxy *);
DEFINE_FAKE_VOID_FUNC(wl_display_disconnect, struct wl_display *);
DEFINE_FAKE_VOID_FUNC(wl_event_queue_destroy, struct wl_event_queue *);
DEFINE_FAKE_VOID_FUNC(wl_proxy_set_queue, struct wl_proxy *, struct wl_event_queue *);
DEFINE_FAKE_VOID_FUNC(wl_proxy_destroy, struct wl_proxy *);
DEFINE_FAKE_VALUE_FUNC(void *, wl_array_add, struct wl_array *, size_t);
DEFINE_FAKE_VOID_FUNC(wl_list_insert, struct wl_list *, struct wl_list *);
DEFINE_FAKE_VALUE_FUNC_VARARG(struct wl_proxy *, wl_proxy_marshal_flags, struct wl_proxy *, uint32_t, const struct wl_interface *, uint32_t, uint32_t, ...);
DEFINE_FAKE_VOID_FUNC(wl_list_remove, struct wl_list *);
DEFINE_FAKE_VOID_FUNC(wl_list_init, struct wl_list *);
DEFINE_FAKE_VOID_FUNC(wl_array_init, struct wl_array *);
DEFINE_FAKE_VOID_FUNC(wl_array_release, struct wl_array *);
DEFINE_FAKE_VALUE_FUNC(int, wl_list_length, const struct wl_list *);
Loading