Adjust gtest skeleton 01/245201/2
authorSeungha Son <seungha.son@samsung.com>
Mon, 5 Oct 2020 09:30:34 +0000 (18:30 +0900)
committerSeungha Son <seungha.son@samsung.com>
Tue, 6 Oct 2020 03:35:56 +0000 (12:35 +0900)
Change-Id: I6fdc2ce6ac49700395d0758ab2b93c76e11069c6
Signed-off-by: Seungha Son <seungha.son@samsung.com>
CMakeLists.txt
atrace-helper/CMakeLists.txt
atrace/CMakeLists.txt
packaging/ttrace.spec
test/CMakeLists.txt [new file with mode: 0644]
test/src/test_main.cc [new file with mode: 0644]
test/src/test_ttrace.cc [new file with mode: 0644]

index 8141fc7f0a90d698c76abf778299aacc9f8fe57f..349621f11f2b493b1681826d14238c81ca893be8 100755 (executable)
@@ -86,3 +86,5 @@ ENDFOREACH(hfile)
 # ------------------------------
 ADD_SUBDIRECTORY(atrace)
 ADD_SUBDIRECTORY(atrace-helper)
+
+ADD_SUBDIRECTORY(test)
index b4ee9374cdc9725941c878db8727c9248ba7dcbc..746d91aa8b0a38ee77991498403688bf356a5e35 100644 (file)
@@ -4,10 +4,6 @@ PROJECT(atrace-helper CXX)
 SET(PREFIX ${CMAKE_INSTALL_PREFIX})
 SET(EXEC_PREFIX "\${prefix}")
 
-SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${EXTRA_CFLAGS} -std=c++11")
-SET(CMAKE_CXX_FLAGS_DEBUG "-O0 -g")
-SET(CMAKE_CXX_FLAGS_RELEASE "-O2")
-
 INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR})
 AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR} SOURCES)
 
index 378aa086ed526c548cbcbb77535e545524f6db7b..c5c7e7f7500aa43984cc15d0d0585d4c7adc3a29 100644 (file)
@@ -4,7 +4,7 @@ PROJECT(atrace C)
 SET(PREFIX ${CMAKE_INSTALL_PREFIX})
 SET(EXEC_PREFIX "\${prefix}")
 
-SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${EXTRA_CFLAGS} -std=c++11")
+SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${EXTRA_CFLAGS} -std=c++11 -fPIE")
 SET(CMAKE_CXX_FLAGS_DEBUG "-O0 -g")
 SET(CMAKE_CXX_FLAGS_RELEASE "-O2")
 
index 75f0adbb5e1addfe557bd4841da12ac7183f8069..ecb09130db0753186a6d38b0c9dc9567ad0b8987 100644 (file)
@@ -14,6 +14,7 @@ BuildRequires: pkgconfig(dlog)
 BuildRequires: pkgconfig(zlib)
 BuildRequires: pkgconfig(capi-base-common)
 BuildRequires: pkgconfig(libsmack)
+BuildRequires: pkgconfig(gmock)
 BuildRequires: cmake
 
 %define keepstatic 1
@@ -71,7 +72,7 @@ export LDFLAGS+=" -lgcov"
 %endif
 
 export CFLAGS="$CFLAGS -g -Wall -std=gnu99"
-export CXXFLAGS="$CXXFLAGS -std=c++0x -fPIE -pie -fno-exceptions"
+export CXXFLAGS="$CXXFLAGS -std=c++11 -fPIE -pie"
 
 MAJORVER=`echo %{version} | awk 'BEGIN {FS="."}{print $1}'`
 %cmake . -DCMAKE_INSTALL_PREFIX=%{_prefix} -DLIBDIR=%{_libdir} -DINCLUDEDIR=%{_includedir} \
@@ -85,6 +86,9 @@ mkdir -p gcov-obj
 find . -name '*.gcno' -exec cp '{}' gcov-obj ';'
 %endif
 
+%check
+(cd test && LD_LIBRARY_PATH=../ ctest -V)
+
 %install
 rm -rf %{buildroot}
 %make_install
diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt
new file mode 100644 (file)
index 0000000..405c263
--- /dev/null
@@ -0,0 +1,23 @@
+ENABLE_TESTING()
+SET(TARGET_TTRACE_UNIT_TEST "ttrace-unit-test")
+
+AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/src UNIT_TESTS_SRCS)
+
+ADD_EXECUTABLE(${TARGET_TTRACE_UNIT_TEST} ${UNIT_TESTS_SRCS})
+
+TARGET_INCLUDE_DIRECTORIES(${TARGET_TTRACE_UNIT_TEST} PUBLIC
+  "${CMAKE_CURRENT_SOURCE_DIR}/../include"
+)
+
+INCLUDE(FindPkgConfig)
+PKG_CHECK_MODULES(gtest_pkgs REQUIRED gmock)
+
+TARGET_LINK_LIBRARIES(${TARGET_TTRACE_UNIT_TEST} PUBLIC ${gtest_pkgs_LDFLAGS} ${PROJECT_NAME})
+
+SET_TARGET_PROPERTIES(${TARGET_TTRACE_UNIT_TEST} PROPERTIES COMPILE_FLAGS "-fPIE -fvisibility=default")
+SET_TARGET_PROPERTIES(${TARGET_TTRACE_UNIT_TEST} PROPERTIES LINK_FLAGS "-pie")
+
+ADD_TEST(
+  NAME ${TARGET_TTRACE_UNIT_TEST}
+  COMMAND ${TARGET_TTRACE_UNIT_TEST}
+)
diff --git a/test/src/test_main.cc b/test/src/test_main.cc
new file mode 100644 (file)
index 0000000..a1a8508
--- /dev/null
@@ -0,0 +1,36 @@
+/*
+ * Copyright (c) 2020 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 <gtest/gtest.h>
+
+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/test/src/test_ttrace.cc b/test/src/test_ttrace.cc
new file mode 100644 (file)
index 0000000..4df0109
--- /dev/null
@@ -0,0 +1,84 @@
+/*
+ * Copyright (c) 2020 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 <gtest/gtest.h>
+
+#include <trace.h>
+
+#include <string>
+#include <vector>
+#include <memory>
+
+class TtraceTest : public testing::Test {
+ public:
+  TtraceTest() {}
+
+  virtual ~TtraceTest() {}
+
+  virtual void SetUp() {}
+
+  virtual void TearDown() {}
+};
+
+TEST(TtraceTest, trace_begin) {
+  int ret = -1;
+
+  trace_begin("fmt");
+
+  ret = get_last_result();
+
+  EXPECT_EQ(ret, 0);
+}
+
+TEST(TtraceTest, trace_end) {
+  int ret = -1;
+
+  trace_end();
+
+  ret = get_last_result();
+
+  EXPECT_EQ(ret, 0);
+}
+
+TEST(TtraceTest, trace_async_begin) {
+  int ret = -1;
+
+  trace_async_begin(1, "fmt");
+
+  ret = get_last_result();
+
+  EXPECT_EQ(ret, 0);
+}
+
+TEST(TtraceTest, trace_async_end) {
+  int ret = -1;
+
+  trace_async_end(1, "fmt");
+
+  ret = get_last_result();
+
+  EXPECT_EQ(ret, 0);
+}
+
+TEST(TtraceTest, trace_update_counter) {
+  int ret = -1;
+
+  trace_update_counter(1, "fmt");
+
+  ret = get_last_result();
+
+  EXPECT_EQ(ret, 0);
+}