SET(TTRACE_TIZEN_VERSION_MAJOR "2")
ENDIF()
-IF("${COVERAGE}" STREQUAL "on")
- ADD_DEFINITIONS("-DTTRACE_COVERAGE")
-ENDIF()
-
CONFIGURE_FILE(${TTRACE_H_IN} "include/ttrace.h")
SET(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/cmake/Modules/")
%if 0%{?gcov:1}
BuildRequires: lcov
-%define TTRACE_COVERAGE on
-%else
-%define TTRACE_COVERAGE off
%endif
%define keepstatic 1
%cmake . -DCMAKE_INSTALL_PREFIX=%{_prefix} -DLIBDIR=%{_libdir} -DINCLUDEDIR=%{_includedir} \
-DTTRACE_PROFILE=%{TTRACE_PROFILE} -DTTRACE_TIZEN_VERSION_MAJOR=%{TTRACE_TIZEN_VERSION_MAJOR} \
-DMAJORVER=${MAJORVER} -DFULLVER=%{version} \
- -DATRACE_VERSION=%{ATRACE_VERSION} -DATRACE_HELPER_VERSION=%{ATRACE_HELPER_VERSION} \
- -DCOVERAGE=%{TTRACE_COVERAGE}
+ -DATRACE_VERSION=%{ATRACE_VERSION} -DATRACE_HELPER_VERSION=%{ATRACE_HELPER_VERSION}
make %{?jobs:-j%jobs}
%if 0%{?gcov:1}
}
sm_for_enabled_tag = mmap(NULL, sizeof(uint64_t), PROT_READ, MAP_SHARED, g_enabled_tag_fd, 0);
if (sm_for_enabled_tag == MAP_FAILED) {
+/* LCOV_EXCL_START */
TTRACE_LOG("error: mmap() failed(%s)\n", strerror(errno));
close(g_enabled_tag_fd);
return 0;
+/* LCOV_EXCL_STOP */
}
cur_enabled_tag = sm_for_enabled_tag;
}
if(g_trace_handle_fd == FD_INITIAL_VALUE) {
g_trace_handle_fd = open(TRACE_FILE, O_WRONLY);
if (g_trace_handle_fd < 0) {
+/* LCOV_EXCL_START */
TTRACE_LOG("Fail to open trace file: %s(%d)", strerror(errno), errno);
/*
* If ftrace debugfs is not mounted, ttrace does not call traceInit() anymore.
set_last_result(TRACE_ERROR_IO_ERROR);
return 0;
+/* LCOV_EXCL_STOP */
}
}
TTRACE_LOG("traceInit:: cur_enabled_tag >> %u", *cur_enabled_tag);
static inline uint64_t isTagEnabled(uint64_t cur_tag)
{
-#ifdef TTRACE_COVERAGE
- return 1;
-#endif
-
if (g_trace_handle_fd == TRACE_FILE_NOT_EXIST)
return 0;
/* if no tag is enabled, trace all tags. */
int check_params(int fd, char* buf, int len, const char* func)
{
if (fd <= 0 || buf == NULL || len < 0) {
+/* LCOV_EXCL_START */
TTRACE_LOG("Currupted arguments, fd: %d, buf: %p, len: %d at %s.\n",
fd, buf, len, func);
return -1;
+/* LCOV_EXCL_STOP */
}
return 0;
}
ret = write(g_trace_handle_fd, buf, len);
if (ret < 0)
+/* LCOV_EXCL_START */
TTRACE_LOG("error writing, len: %d, ret: %d, errno: %d at traceBegin.\n",
len, ret, errno);
+/* LCOV_EXCL_STOP */
}
else
TTRACE_LOG("traceBegin:: disabled tag >> tag: %u tag_bit: %u", tag, *cur_enabled_tag);
ENABLE_TESTING()
AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/src UNIT_TESTS_SRCS)
+AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/../src TTRACE_SRCS)
-ADD_EXECUTABLE(${TARGET_TTRACE_UNIT_TEST} ${UNIT_TESTS_SRCS})
+ADD_EXECUTABLE(${TARGET_TTRACE_UNIT_TEST} ${TTRACE_SRCS} ${UNIT_TESTS_SRCS})
TARGET_INCLUDE_DIRECTORIES(${TARGET_TTRACE_UNIT_TEST} PUBLIC
"${CMAKE_CURRENT_SOURCE_DIR}/../include"
+ "${CMAKE_CURRENT_SOURCE_DIR}/src"
)
APPLY_PKG_CONFIG(${TARGET_TTRACE_UNIT_TEST} PUBLIC
GMOCK_DEPS
+ DLOG_DEPS
+ CAPI_BASE_COMMON_DEPS
)
-TARGET_LINK_LIBRARIES(${TARGET_TTRACE_UNIT_TEST} PUBLIC ${TARGET_TTRACE})
-SET_TARGET_PROPERTIES(${TARGET_TTRACE_UNIT_TEST} PROPERTIES COMPILE_FLAGS "-fPIE -fvisibility=default")
-SET_TARGET_PROPERTIES(${TARGET_TTRACE_UNIT_TEST} PROPERTIES LINK_FLAGS "-pie")
+SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${EXTRA_CFLAGS} -fpic -fPIE -std=c++11")
+
+#TARGET_LINK_LIBRARIES(${TARGET_TTRACE_UNIT_TEST} PUBLIC ${TARGET_TTRACE})
+SET_TARGET_PROPERTIES(${TARGET_TTRACE_UNIT_TEST} PROPERTIES COMPILE_FLAGS ${CFLAGS} "-fPIE -fvisibility=default")
+SET_TARGET_PROPERTIES(${TARGET_TTRACE_UNIT_TEST} PROPERTIES LINK_FLAGS "-pie -Wl,--wrap=open -Wl,--wrap=open64 -Wl,--wrap=write -Wl,--wrap=mmap -Wl,--wrap=mmap64 -Wl,--wrap=close")
ADD_TEST(
NAME ${TARGET_TTRACE_UNIT_TEST}
--- /dev/null
+#include <stdlib.h>
+#include <stdbool.h>
+#include <stdint.h>
+
+#include <sys/mman.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+#include <unistd.h>
+
+#include "file_mock.h"
+
+int __real_open(const char *pathname, int flags, mode_t mode);
+int __real_open64(const char *pathname, int flags, mode_t mode);
+ssize_t __real_write(int fd, const void* buf, size_t count);
+void *__real_mmap(void *addr, size_t length, int prot, int flags, int fd, off_t offset);
+void *__real_mmap64(void *addr, size_t length, int prot, int flags, int fd, off_t offset);
+int __real_close(int fd);
+
+static uint64_t enabled_tag_ = 1 << 20; // TTRACE_TAG_APP
+static bool mock_enabled_flag_ = false;
+
+void file_mock_setup(bool flag) {
+ mock_enabled_flag_ = flag;
+}
+
+int __wrap_open(const char *pathname, int flags, mode_t mode) {
+ if (!mock_enabled_flag_)
+ return __real_open(pathname, flags, mode);
+
+ return 2;
+}
+
+int __wrap_open64(const char *pathname, int flags, mode_t mode) {
+ if (!mock_enabled_flag_)
+ return __real_open64(pathname, flags, mode);
+
+ return 2;
+}
+
+ssize_t __wrap_write(int fd, const void* buf, size_t count) {
+ if (!mock_enabled_flag_)
+ return __real_write(fd, buf, count);
+
+ return count;
+}
+
+void *__wrap_mmap(void *addr, size_t length, int prot, int flags, int fd, off_t offset)
+{
+ if (!mock_enabled_flag_)
+ return __real_mmap(addr, length, prot, flags, fd, offset);
+
+ return &enabled_tag_;
+}
+
+void *__wrap_mmap64(void *addr, size_t length, int prot, int flags, int fd, off_t offset)
+{
+ if (!mock_enabled_flag_)
+ return __real_mmap64(addr, length, prot, flags, fd, offset);
+
+ return &enabled_tag_;
+}
+
+int __wrap_close(int fd) {
+ if (!mock_enabled_flag_)
+ return __real_close(fd);
+
+ return 0;
+}
--- /dev/null
+/*
+ * Copyright (c) 2021 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.
+ */
+
+#ifndef __TTRACE_FILE_MOCK_H__
+#define __TTRACE_FILE_MOCK_H__
+
+#include <stdbool.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+void file_mock_setup(bool flag);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __TTRACE_FILE_MOCK_H__ */
#include <gtest/gtest.h>
+#include <stdio.h>
+
#include <trace.h>
#include <string>
#include <vector>
#include <memory>
+#include "file_mock.h"
+
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+
class TtraceTest : public testing::Test {
public:
TtraceTest() {}
virtual ~TtraceTest() {}
- virtual void SetUp() {}
+ virtual void SetUp() { file_mock_setup(true); }
- virtual void TearDown() {}
+ virtual void TearDown() { file_mock_setup(false); }
};
-TEST(TtraceTest, trace_begin) {
+TEST_F(TtraceTest, trace_begin) {
int ret = -1;
trace_begin("fmt");
EXPECT_EQ(ret, 0);
}
-TEST(TtraceTest, trace_end) {
+TEST_F(TtraceTest, trace_end) {
int ret = -1;
trace_end();
EXPECT_EQ(ret, 0);
}
-TEST(TtraceTest, trace_async_begin) {
+TEST_F(TtraceTest, trace_async_begin) {
int ret = -1;
trace_async_begin(1, "fmt");
EXPECT_EQ(ret, 0);
}
-TEST(TtraceTest, trace_async_end) {
+TEST_F(TtraceTest, trace_async_end) {
int ret = -1;
trace_async_end(1, "fmt");
EXPECT_EQ(ret, 0);
}
-TEST(TtraceTest, trace_update_counter) {
+TEST_F(TtraceTest, trace_update_counter) {
int ret = -1;
trace_update_counter(1, "fmt");