tool: add code coverage tool

N/A

Signed-off-by: yinshengkai <yinshengkai@xiaomi.com>
Change-Id: I9388a08565508383e53b418696c14ae286b172ce
This commit is contained in:
yinshengkai
2021-09-08 17:37:25 +08:00
parent 959f5496de
commit c40a7eb930
7 changed files with 83 additions and 0 deletions
+2
View File
@@ -7,6 +7,8 @@
*.dSYM *.dSYM
*.elf *.elf
*.exe *.exe
*.gcno
*.gcda
*.hex *.hex
*.i *.i
*.ihx *.ihx
+8
View File
@@ -217,6 +217,14 @@ config ARCH_SIZET_LONG
C++ library routines because the NuttX size_t might not have C++ library routines because the NuttX size_t might not have
the same underlying type as your toolchain's size_t. the same underlying type as your toolchain's size_t.
config ARCH_COVERAGE
bool "arch coverage"
select HAVE_CXX
select HAVE_CXXINITIALIZE
default n
---help---
Generate code coverage
comment "Architecture Options" comment "Architecture Options"
config ARCH_NOINTC config ARCH_NOINTC
+4
View File
@@ -88,6 +88,10 @@ ifeq ($(CONFIG_STACK_COLORATION),y)
CSRCS += up_checkstack.c CSRCS += up_checkstack.c
endif endif
ifeq ($(CONFIG_ARCH_COVERAGE),y)
STDLIBS += -lgcov
endif
ifeq ($(CONFIG_SPINLOCK),y) ifeq ($(CONFIG_SPINLOCK),y)
HOSTSRCS += up_testset.c HOSTSRCS += up_testset.c
endif endif
+19
View File
@@ -31,7 +31,9 @@
#endif #endif
NXSYMBOLS(__cxa_atexit) NXSYMBOLS(__cxa_atexit)
NXSYMBOLS(abort)
NXSYMBOLS(accept) NXSYMBOLS(accept)
NXSYMBOLS(access)
NXSYMBOLS(atexit) NXSYMBOLS(atexit)
NXSYMBOLS(bind) NXSYMBOLS(bind)
NXSYMBOLS(calloc) NXSYMBOLS(calloc)
@@ -46,14 +48,24 @@ NXSYMBOLS(dup)
NXSYMBOLS(exit) NXSYMBOLS(exit)
NXSYMBOLS(fchmod) NXSYMBOLS(fchmod)
NXSYMBOLS(fchown) NXSYMBOLS(fchown)
NXSYMBOLS(fclose)
NXSYMBOLS(fcntl) NXSYMBOLS(fcntl)
NXSYMBOLS(fdopen)
NXSYMBOLS(fopen)
NXSYMBOLS(fprintf)
NXSYMBOLS(fread)
NXSYMBOLS(free) NXSYMBOLS(free)
NXSYMBOLS(fseek)
NXSYMBOLS(fstat) NXSYMBOLS(fstat)
NXSYMBOLS(fsync) NXSYMBOLS(fsync)
NXSYMBOLS(ftell)
NXSYMBOLS(ftruncate) NXSYMBOLS(ftruncate)
NXSYMBOLS(futimens) NXSYMBOLS(futimens)
NXSYMBOLS(fwrite)
NXSYMBOLS(getpeername) NXSYMBOLS(getpeername)
NXSYMBOLS(getsockname) NXSYMBOLS(getsockname)
NXSYMBOLS(getenv)
NXSYMBOLS(getpid)
NXSYMBOLS(getsockopt) NXSYMBOLS(getsockopt)
NXSYMBOLS(if_nametoindex) NXSYMBOLS(if_nametoindex)
NXSYMBOLS(ioctl) NXSYMBOLS(ioctl)
@@ -86,6 +98,7 @@ NXSYMBOLS(pthread_mutex_lock)
NXSYMBOLS(pthread_mutex_unlock) NXSYMBOLS(pthread_mutex_unlock)
NXSYMBOLS(pthread_setspecific) NXSYMBOLS(pthread_setspecific)
NXSYMBOLS(pthread_sigmask) NXSYMBOLS(pthread_sigmask)
NXSYMBOLS(puts)
NXSYMBOLS(read) NXSYMBOLS(read)
NXSYMBOLS(readdir) NXSYMBOLS(readdir)
NXSYMBOLS(readv) NXSYMBOLS(readv)
@@ -99,6 +112,7 @@ NXSYMBOLS(select)
NXSYMBOLS(sendmsg) NXSYMBOLS(sendmsg)
NXSYMBOLS(sendto) NXSYMBOLS(sendto)
NXSYMBOLS(setitimer) NXSYMBOLS(setitimer)
NXSYMBOLS(setbuf)
NXSYMBOLS(setjmp) NXSYMBOLS(setjmp)
NXSYMBOLS(setsockopt) NXSYMBOLS(setsockopt)
NXSYMBOLS(shutdown) NXSYMBOLS(shutdown)
@@ -110,7 +124,12 @@ NXSYMBOLS(sleep)
NXSYMBOLS(socket) NXSYMBOLS(socket)
NXSYMBOLS(stat) NXSYMBOLS(stat)
NXSYMBOLS(statvfs) NXSYMBOLS(statvfs)
NXSYMBOLS(stderr)
NXSYMBOLS(strcat)
NXSYMBOLS(strchr)
NXSYMBOLS(strerror) NXSYMBOLS(strerror)
NXSYMBOLS(strlen)
NXSYMBOLS(strtol)
NXSYMBOLS(syslog) NXSYMBOLS(syslog)
NXSYMBOLS(tcgetattr) NXSYMBOLS(tcgetattr)
NXSYMBOLS(tcsetattr) NXSYMBOLS(tcsetattr)
+4
View File
@@ -55,6 +55,10 @@ ifeq ($(CONFIG_SIM_SANITIZE),y)
ARCHOPTIMIZATION += -fsanitize=address -fno-omit-frame-pointer ARCHOPTIMIZATION += -fsanitize=address -fno-omit-frame-pointer
endif endif
ifeq ($(CONFIG_ARCH_COVERAGE),y)
ARCHOPTIMIZATION += -fprofile-arcs -ftest-coverage
endif
ARCHCPUFLAGS = -fno-builtin ARCHCPUFLAGS = -fno-builtin
ARCHCPUFLAGSXX = -fno-builtin -nostdinc++ ARCHCPUFLAGSXX = -fno-builtin -nostdinc++
ifeq ($(CONFIG_CXX_EXCEPTION),) ifeq ($(CONFIG_CXX_EXCEPTION),)
+4
View File
@@ -459,6 +459,10 @@ endef
# CLEAN - Default clean target # CLEAN - Default clean target
ifeq ($(CONFIG_ARCH_COVERAGE),y)
OBJS += *.gcno *.gcda
endif
ifeq ($(CONFIG_WINDOWS_NATIVE),y) ifeq ($(CONFIG_WINDOWS_NATIVE),y)
define CLEAN define CLEAN
$(Q) if exist *$(OBJEXT) (del /f /q *$(OBJEXT)) $(Q) if exist *$(OBJEXT) (del /f /q *$(OBJEXT))
Executable
+42
View File
@@ -0,0 +1,42 @@
#!/usr/bin/env bash
# tools/gcov.sh
#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to you 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.
#
ROOT_DIR=$(cd $(dirname $0)/../../; pwd)
if [ $# == 1 ]; then
GCOV_DIR=$1
else
GCOV_DIR=${ROOT_DIR}/gcov
fi
mkdir -p ${GCOV_DIR}
cd ${GCOV_DIR}
# Generate coverage text report
lcov -c -d ${ROOT_DIR} -o coverage.info --rc lcov_branch_coverage=1
# Generate coverage page report
genhtml --branch-coverage -o result coverage.info
if [ $? -ne 0 ]; then
echo "Failed to generate coverage file"
exit 1
fi
echo -e "Copy the following link and open it in the browser to view the coverage report"
echo "file://${GCOV_DIR}/result/index.html"