From: Seungha Son Date: Mon, 5 Oct 2020 09:30:34 +0000 (+0900) Subject: Adjust gtest skeleton X-Git-Tag: submit/tizen/20201109.044826~2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Fchanges%2F01%2F245201%2F2;p=tools%2Fttrace.git Adjust gtest skeleton Change-Id: I6fdc2ce6ac49700395d0758ab2b93c76e11069c6 Signed-off-by: Seungha Son --- diff --git a/CMakeLists.txt b/CMakeLists.txt index 8141fc7..349621f 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -86,3 +86,5 @@ ENDFOREACH(hfile) # ------------------------------ ADD_SUBDIRECTORY(atrace) ADD_SUBDIRECTORY(atrace-helper) + +ADD_SUBDIRECTORY(test) diff --git a/atrace-helper/CMakeLists.txt b/atrace-helper/CMakeLists.txt index b4ee937..746d91a 100644 --- a/atrace-helper/CMakeLists.txt +++ b/atrace-helper/CMakeLists.txt @@ -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) diff --git a/atrace/CMakeLists.txt b/atrace/CMakeLists.txt index 378aa08..c5c7e7f 100644 --- a/atrace/CMakeLists.txt +++ b/atrace/CMakeLists.txt @@ -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") diff --git a/packaging/ttrace.spec b/packaging/ttrace.spec index 75f0adb..ecb0913 100644 --- a/packaging/ttrace.spec +++ b/packaging/ttrace.spec @@ -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 index 0000000..405c263 --- /dev/null +++ b/test/CMakeLists.txt @@ -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 index 0000000..a1a8508 --- /dev/null +++ b/test/src/test_main.cc @@ -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 + +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 index 0000000..4df0109 --- /dev/null +++ b/test/src/test_ttrace.cc @@ -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 + +#include + +#include +#include +#include + +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); +}