# ------------------------------
ADD_SUBDIRECTORY(atrace)
ADD_SUBDIRECTORY(atrace-helper)
+
+ADD_SUBDIRECTORY(test)
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)
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")
BuildRequires: pkgconfig(zlib)
BuildRequires: pkgconfig(capi-base-common)
BuildRequires: pkgconfig(libsmack)
+BuildRequires: pkgconfig(gmock)
BuildRequires: cmake
%define keepstatic 1
%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} \
find . -name '*.gcno' -exec cp '{}' gcov-obj ';'
%endif
+%check
+(cd test && LD_LIBRARY_PATH=../ ctest -V)
+
%install
rm -rf %{buildroot}
%make_install
--- /dev/null
+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}
+)
--- /dev/null
+/*
+ * 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;
+}
--- /dev/null
+/*
+ * 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);
+}