tests: unittest: Add pass-unittest skeleton for testing pass module 72/276572/4
authorChanwoo Choi <cw00.choi@samsung.com>
Mon, 20 Jun 2022 04:38:01 +0000 (13:38 +0900)
committerChanwoo Choi <cw00.choi@samsung.com>
Thu, 23 Jun 2022 06:08:12 +0000 (15:08 +0900)
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 <cw00.choi@samsung.com>
CMakeLists.txt
packaging/pass.spec
tests/unittest/CMakeLists.txt [new file with mode: 0644]
tests/unittest/pass-unittests.cc [new file with mode: 0644]

index 6116b46..71ab2c3 100644 (file)
@@ -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)
index 29a506e..74c735a 100644 (file)
@@ -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 (file)
index 0000000..25b89aa
--- /dev/null
@@ -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 (file)
index 0000000..14748d2
--- /dev/null
@@ -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 <iostream>
+#include <unistd.h>
+
+#include <gio/gio.h>
+#include <gtest/gtest.h>
+#include <gmock/gmock.h>
+
+int main(int argc, char *argv[])
+{
+       try {
+               testing::InitGoogleTest(&argc, argv);
+               return RUN_ALL_TESTS();
+       } catch (...) {
+               return EXIT_FAILURE;
+       }
+}