From a2b9e042d7c07281d4ecfd85add4995b3278fa97 Mon Sep 17 00:00:00 2001 From: Chanwoo Choi Date: Mon, 20 Jun 2022 13:38:01 +0900 Subject: [PATCH] tests: unittest: Add pass-unittest skeleton for testing pass module PASS daemon contains the modules such as pass-parser, pass-hal, pass-rescon, pass-resmon and son on. It requires the testing on building time. In order to support the unittest of pass module, add pass-unittest skeleton code. Change-Id: Ie4c8637b4c0b5045b59eb3a92495f132aeb0c6e3 Signed-off-by: Chanwoo Choi --- CMakeLists.txt | 2 ++ packaging/pass.spec | 3 +++ tests/unittest/CMakeLists.txt | 39 +++++++++++++++++++++++++++++++++++++++ tests/unittest/pass-unittests.cc | 32 ++++++++++++++++++++++++++++++++ 4 files changed, 76 insertions(+) create mode 100644 tests/unittest/CMakeLists.txt create mode 100644 tests/unittest/pass-unittests.cc diff --git a/CMakeLists.txt b/CMakeLists.txt index 6116b46..71ab2c3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -132,4 +132,6 @@ INSTALL(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/systemd/ DESTINATION lib/systemd/s ADD_SUBDIRECTORY(tests/integration-test) ADD_SUBDIRECTORY(tests/haltest) +ADD_SUBDIRECTORY(tests/unittest) + ADD_SUBDIRECTORY(lib) diff --git a/packaging/pass.spec b/packaging/pass.spec index 29a506e..74c735a 100644 --- a/packaging/pass.spec +++ b/packaging/pass.spec @@ -84,6 +84,9 @@ cp %{SOURCE1} . cp %{SOURCE2} . make %{?jobs:-j%jobs} +%check +(cd tests/unittest && LD_LIBRARY_PATH=../../ ctest -V) + %install rm -rf %{buildroot} %make_install diff --git a/tests/unittest/CMakeLists.txt b/tests/unittest/CMakeLists.txt new file mode 100644 index 0000000..25b89aa --- /dev/null +++ b/tests/unittest/CMakeLists.txt @@ -0,0 +1,39 @@ +ENABLE_TESTING() +SET(PASS_UNITTEST "pass-unittests") + +SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -g -Wall -Werror") +SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${EXTRA_CFLAGS} -Wall -Werror") + +AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/ PASS_UNITTEST_SRCS) +ADD_EXECUTABLE(${PASS_UNITTEST} ${PASS_UNITTEST_SRCS}) + +TARGET_INCLUDE_DIRECTORIES(${PASS_UNITTEST} PUBLIC + "${CMAKE_CURRENT_SOURCE_DIR}/../../include" + "${CMAKE_SOURCE_DIR}" + "${CMAKE_SOURCE_DIR}/src" + "${CMAKE_SOURCE_DIR}/src/pass" + "${CMAKE_SOURCE_DIR}/include" +) + +INCLUDE(FindPkgConfig) +pkg_check_modules(pass_unittest_pkgs REQUIRED + glib-2.0 + gio-2.0 + gmock + dlog + json-c + hal-api-power +) + +FOREACH(flag ${pass_unittest_pkgs_CFLAGS}) + SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}") +ENDFOREACH(flag) + +TARGET_LINK_LIBRARIES(${PASS_UNITTEST} ${pass_unittest_pkgs_LDFLAGS}) +SET_TARGET_PROPERTIES(${PASS_UNITTEST} PROPERTIES COMPILE_FLAGS "-fPIE -fvisibility=default") +SET_TARGET_PROPERTIES(${PASS_UNITTEST} PROPERTIES LINK_FLAGS "-pie") + +ADD_TEST( + NAME ${PASS_UNITTEST} + COMMAND ${PASS_UNITTEST} +) diff --git a/tests/unittest/pass-unittests.cc b/tests/unittest/pass-unittests.cc new file mode 100644 index 0000000..14748d2 --- /dev/null +++ b/tests/unittest/pass-unittests.cc @@ -0,0 +1,32 @@ +/* + * Copyright (C) 2022 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. + */ + +#include +#include + +#include +#include +#include + +int main(int argc, char *argv[]) +{ + try { + testing::InitGoogleTest(&argc, argv); + return RUN_ALL_TESTS(); + } catch (...) { + return EXIT_FAILURE; + } +} -- 2.7.4