[devel] [PATCH for apt 38/38] Add code coverage support
Aleksei Nikiforov
darktemplar на altlinux.org
Вт Дек 10 18:23:43 MSK 2019
---
apt.spec | 28 +++++++++++++++++++++++++++-
apt/apt-pkg/Makefile.am | 10 +++++++---
apt/apt-pkg/acquire-method.cc | 9 +++++++--
apt/apt-pkg/acquire.cc | 5 ++++-
apt/apt-pkg/contrib/cdromutl.cc | 15 ++++++++++++---
apt/apt-pkg/defs.h | 18 ++++++++++++++++++
apt/apt-pkg/rpm/rpmlistparser.cc | 2 ++
apt/apt-pkg/rpm/rpmpm.cc | 21 ++++++++++++++++-----
apt/cmdline/Makefile.am | 9 +++++++--
apt/cmdline/apt-get.cc | 6 ++++++
apt/configure.in | 2 ++
apt/methods/Makefile.am | 7 ++++++-
apt/methods/ftp.cc | 6 +++++-
apt/methods/http.cc | 10 ++++++++--
apt/methods/rsh.cc | 6 +++++-
apt/methods/rsync.cc | 2 ++
apt/tools/Makefile.am | 8 ++++++--
17 files changed, 140 insertions(+), 24 deletions(-)
create mode 100644 apt/apt-pkg/defs.h
diff --git a/apt.spec b/apt.spec
index 7c91f70..e3e3384 100644
--- a/apt.spec
+++ b/apt.spec
@@ -1,4 +1,5 @@
%def_enable check
+%def_disable coverage
Name: apt
Version: 0.5.15lorg2
@@ -57,6 +58,11 @@ BuildPreReq: liblua5.3-devel
BuildRequires: bzlib-devel cvs docbook-utils gcc-c++ libreadline-devel librpm-devel setproctitle-devel zlib-devel
BuildRequires: libgnutls-devel
+BuildRequires: autoconf-archive
+
+%if_enabled coverage
+BuildRequires: lcov
+%endif
# dependencies of tests
%if_enabled check
@@ -246,12 +252,21 @@ sed -i 's, > /dev/null 2>&1,,' buildlib/tools.m4
# Add trivial arch translation.
printf '%_target_cpu\t%_target_cpu' >> buildlib/archtable
+%if_enabled coverage
+%remove_optflags -O2
+%add_optflags -DENABLE_COVERAGE_GCOV
+%endif
+
%autoreconf
%add_optflags -DAPTRPM_ID=\\\"%name-%{?epoch:%epoch:}%version-%release%{?disttag::%disttag}.%_target_cpu\\\"
%ifarch %e2k
%add_optflags -std=c++14
%endif
-%configure --includedir=%_includedir/apt-pkg %{subst_enable static}
+%configure \
+ --includedir=%_includedir/apt-pkg \
+ %{subst_enable static} \
+ %{?_enable_coverage: --enable-code-coverage} \
+ %nil
# Probably this obsolete now?
find -type f -print0 |
@@ -308,6 +323,12 @@ LD_LIBRARY_PATH=%buildroot%_libdir PATH=$PATH:%buildroot%_bindir METHODSDIR=%bui
done
popd
+%if_enabled coverage
+find . -name '*.cc' -o -name '*.h' -o -name '*.c' | while read file ; do gcov $file ; done
+lcov --capture --directory . --exclude '/usr/include/*' --output-file %name.info
+genhtml %name.info --output-directory %name-coverage-output
+%endif
+
%files -f %name.lang
%_bindir/apt-*
%_libdir/%name
@@ -351,6 +372,11 @@ popd
%_libdir/%name/methods/https
%files tests
+%if_enabled coverage
+%if_enabled check
+%doc %name-coverage-output
+%endif
+%endif
%_libdir/%name/tests
%changelog
diff --git a/apt/apt-pkg/Makefile.am b/apt/apt-pkg/Makefile.am
index 4c0d234..bc6b717 100644
--- a/apt/apt-pkg/Makefile.am
+++ b/apt/apt-pkg/Makefile.am
@@ -1,10 +1,13 @@
+include $(top_srcdir)/aminclude_static.am
lib_LTLIBRARIES = libapt-pkg.la
-libapt_pkg_la_LIBADD = @RPMLIBS@
+libapt_pkg_la_LIBADD = @RPMLIBS@ $(CODE_COVERAGE_LIBS)
libapt_pkg_la_LDFLAGS = -version-info 9:0:1 -release @GLIBC_VER на -@LIBSTDCPP_VER@@NO_CXX11ABI_SUFFIX@@FILE_OFFSET_BITS_SUFFIX@
-AM_CPPFLAGS = -DLIBDIR=\"$(libdir)\" -D_RPM_4_4_COMPAT
+AM_CFLAGS = $(CODE_COVERAGE_CFLAGS)
+AM_CXXFLAGS = $(CODE_COVERAGE_CXXFLAGS)
+AM_CPPFLAGS = -DLIBDIR=\"$(libdir)\" -D_RPM_4_4_COMPAT $(CODE_COVERAGE_CPPFLAGS)
if WITH_LUA
libapt_pkg_la_LIBADD += -llua
@@ -72,6 +75,7 @@ libapt_pkg_la_SOURCES = \
cacheiterators.h \
clean.cc \
clean.h \
+ defs.h \
depcache.cc \
depcache.h \
indexfile.cc \
@@ -152,7 +156,7 @@ $(top_builddir)/include/%: rpm/%
@$(mkinstalldirs) $(top_builddir)/include/apt-pkg
cp -f -p $< $@
-clean-local:
+clean-local: code-coverage-clean
rm -f $(PRIVCOPYHEADERS)
rm -rf $(top_builddir)/include/apt-pkg
diff --git a/apt/apt-pkg/acquire-method.cc b/apt/apt-pkg/acquire-method.cc
index 3b5c580..9296e62 100644
--- a/apt/apt-pkg/acquire-method.cc
+++ b/apt/apt-pkg/acquire-method.cc
@@ -18,6 +18,7 @@
#pragma implementation "apt-pkg/acquire-method.h"
#endif
#include <config.h>
+#include <apt-pkg/defs.h>
#include <apt-pkg/acquire-method.h>
#include <apt-pkg/error.h>
@@ -140,8 +141,10 @@ void pkgAcqMethod::Fail(const char *Why, bool Transient)
/* */
void pkgAcqMethod::URIStart(FetchResult &Res)
{
- if (Queue == 0)
+ if (Queue == 0) {
+ GCOV_DUMP;
abort();
+ }
ostringstream s;
@@ -169,8 +172,10 @@ void pkgAcqMethod::URIStart(FetchResult &Res)
/* */
void pkgAcqMethod::URIDone(FetchResult &Res, FetchResult *Alt)
{
- if (Queue == 0)
+ if (Queue == 0) {
+ GCOV_DUMP;
abort();
+ }
ostringstream s;
diff --git a/apt/apt-pkg/acquire.cc b/apt/apt-pkg/acquire.cc
index 79784af..dec9ee7 100644
--- a/apt/apt-pkg/acquire.cc
+++ b/apt/apt-pkg/acquire.cc
@@ -16,6 +16,7 @@
#pragma implementation "apt-pkg/acquire.h"
#endif
#include <config.h>
+#include <apt-pkg/defs.h>
#include <apt-pkg/acquire.h>
#include <apt-pkg/acquire-item.h>
@@ -143,8 +144,10 @@ void pkgAcquire::Add(Worker *Work)
it cant.. */
void pkgAcquire::Remove(Worker *Work)
{
- if (Running == true)
+ if (Running == true) {
+ GCOV_DUMP;
abort();
+ }
Worker **I = &Workers;
for (; *I != 0;)
diff --git a/apt/apt-pkg/contrib/cdromutl.cc b/apt/apt-pkg/contrib/cdromutl.cc
index 139be84..bd10e02 100644
--- a/apt/apt-pkg/contrib/cdromutl.cc
+++ b/apt/apt-pkg/contrib/cdromutl.cc
@@ -15,6 +15,7 @@
// CNC:2004-03-19
#include <config.h>
+#include <apt-pkg/defs.h>
#include <apt-pkg/luaiface.h>
#include <apt-pkg/cdromutl.h>
@@ -95,8 +96,11 @@ bool UnmountCdrom(string Path)
if (_config->Exists("Acquire::cdrom::"+Path+"::UMount") == true)
{
- if (system(_config->Find("Acquire::cdrom::"+Path+"::UMount").c_str()) != 0)
+ if (system(_config->Find("Acquire::cdrom::"+Path+"::UMount").c_str()) != 0) {
+ GCOV_DUMP;
_exit(100);
+ }
+ GCOV_DUMP;
_exit(0);
}
else
@@ -111,8 +115,10 @@ bool UnmountCdrom(string Path)
if (MntDir[MntDir.length() - 1] != '/')
MntDir += '/';
if ( Path == MntDir )
- if ((strcmp ("subfs", mnt->mnt_type) == 0) || (strcmp ("supermount", mnt->mnt_type) == 0))
+ if ((strcmp ("subfs", mnt->mnt_type) == 0) || (strcmp ("supermount", mnt->mnt_type) == 0)) {
+ GCOV_DUMP;
_exit(0);
+ }
}
endmntent (f);
}
@@ -159,8 +165,11 @@ bool MountCdrom(string Path)
if (_config->Exists("Acquire::cdrom::"+Path+"::Mount") == true)
{
- if (system(_config->Find("Acquire::cdrom::"+Path+"::Mount").c_str()) != 0)
+ if (system(_config->Find("Acquire::cdrom::"+Path+"::Mount").c_str()) != 0) {
+ GCOV_DUMP;
_exit(100);
+ }
+ GCOV_DUMP;
_exit(0);
}
else
diff --git a/apt/apt-pkg/defs.h b/apt/apt-pkg/defs.h
new file mode 100644
index 0000000..33ed490
--- /dev/null
+++ b/apt/apt-pkg/defs.h
@@ -0,0 +1,18 @@
+#ifndef APT_DEFS_H
+#define APT_DEFS_H
+
+/* coverage support */
+#ifdef ENABLE_COVERAGE_GCOV
+#ifdef __cplusplus
+extern "C" {
+#endif
+extern void __gcov_dump(void);
+#ifdef __cplusplus
+}
+#endif
+#define GCOV_DUMP __gcov_dump()
+#else
+#define GCOV_DUMP
+#endif
+
+#endif /* APT_DEFS_H */
diff --git a/apt/apt-pkg/rpm/rpmlistparser.cc b/apt/apt-pkg/rpm/rpmlistparser.cc
index 9b2e9ad..6029520 100644
--- a/apt/apt-pkg/rpm/rpmlistparser.cc
+++ b/apt/apt-pkg/rpm/rpmlistparser.cc
@@ -12,6 +12,7 @@
// Include Files
#include <config.h>
+#include <apt-pkg/defs.h>
#ifdef HAVE_RPM
@@ -98,6 +99,7 @@ std::experimental::optional<map_ptrloc> rpmListParser::UniqFindTagWrite(int Tag)
Stop = Start + strlen(Start);
} else {
cout << "oh shit, not handled:"<<type<<" Package:"<<Package()<<endl;
+ GCOV_DUMP;
abort();
}
diff --git a/apt/apt-pkg/rpm/rpmpm.cc b/apt/apt-pkg/rpm/rpmpm.cc
index d2d3120..e2be6b9 100644
--- a/apt/apt-pkg/rpm/rpmpm.cc
+++ b/apt/apt-pkg/rpm/rpmpm.cc
@@ -12,6 +12,7 @@
#endif
#include <config.h>
+#include <apt-pkg/defs.h>
#ifdef HAVE_RPM
@@ -164,8 +165,10 @@ bool pkgRPMPM::RunScripts(const char *Cnf)
pid_t Process = ExecFork();
if (Process == 0)
{
- if (chdir("/tmp") != 0)
+ if (chdir("/tmp") != 0) {
+ GCOV_DUMP;
_exit(100);
+ }
const char *Args[4];
Args[0] = "/bin/sh";
@@ -627,23 +630,31 @@ bool pkgRPMExtPM::ExecRPM(Item::RPMOps op, const std::vector<apt_item> &files)
// This is the child
if (Child == 0)
{
- if (chdir(_config->FindDir("RPM::Run-Directory","/").c_str()) != 0)
+ if (chdir(_config->FindDir("RPM::Run-Directory","/").c_str()) != 0) {
+ GCOV_DUMP;
_exit(100);
+ }
if (_config->FindB("RPM::FlushSTDIN",true) == true)
{
int Flags,dummy;
- if ((Flags = fcntl(STDIN_FILENO,F_GETFL)) < 0)
+ if ((Flags = fcntl(STDIN_FILENO,F_GETFL)) < 0) {
+ GCOV_DUMP;
_exit(100);
+ }
// Discard everything in stdin before forking dpkg
- if (fcntl(STDIN_FILENO,F_SETFL,Flags | O_NONBLOCK) < 0)
+ if (fcntl(STDIN_FILENO,F_SETFL,Flags | O_NONBLOCK) < 0) {
+ GCOV_DUMP;
_exit(100);
+ }
while (read(STDIN_FILENO,&dummy,1) == 1);
- if (fcntl(STDIN_FILENO,F_SETFL,Flags & (~(long)O_NONBLOCK)) < 0)
+ if (fcntl(STDIN_FILENO,F_SETFL,Flags & (~(long)O_NONBLOCK)) < 0) {
+ GCOV_DUMP;
_exit(100);
+ }
}
execvp(Args[0],(char **)Args);
diff --git a/apt/cmdline/Makefile.am b/apt/cmdline/Makefile.am
index ad9b761..c030d90 100644
--- a/apt/cmdline/Makefile.am
+++ b/apt/cmdline/Makefile.am
@@ -1,3 +1,8 @@
+include $(top_srcdir)/aminclude_static.am
+
+AM_CFLAGS = $(CODE_COVERAGE_CFLAGS)
+AM_CXXFLAGS = $(CODE_COVERAGE_CXXFLAGS)
+AM_CPPFLAGS = $(CODE_COVERAGE_CPPFLAGS)
EXTRA_DIST = indexcopy.cc indexcopy.h
@@ -10,14 +15,14 @@ if COMPILE_STATIC
bin_PROGRAMS += apt-get-static apt-cache-static apt-cdrom-static
endif
-LDADD = ../apt-pkg/libapt-pkg.la $(RPMLIBS)
+LDADD = ../apt-pkg/libapt-pkg.la $(RPMLIBS) $(CODE_COVERAGE_LIBS)
apt_get_SOURCES = apt-get.cc acqprogress.cc acqprogress.h
apt_cache_SOURCES = apt-cache.cc
apt_shell_SOURCES = apt-shell.cc acqprogress.cc acqprogress.h
apt_shell_LDADD = $(LDADD) -lreadline
apt_pipe_SOURCES = $(apt_shell_SOURCES) apt-pipe.c
-apt_pipe_CPPFLAGS = -DAPT_PIPE
+apt_pipe_CPPFLAGS = -DAPT_PIPE $(CODE_COVERAGE_CPPFLAGS)
apt_pipe_LDADD = $(LDADD) -lsetproctitle
apt_config_SOURCES = apt-config.cc
apt_cdrom_SOURCES = apt-cdrom.cc rpmindexcopy.cc rpmindexcopy.h
diff --git a/apt/cmdline/apt-get.cc b/apt/cmdline/apt-get.cc
index 5484b95..5675973 100644
--- a/apt/cmdline/apt-get.cc
+++ b/apt/cmdline/apt-get.cc
@@ -28,6 +28,7 @@
/*}}}*/
// Include Files /*{{{*/
#include <config.h>
+#include <apt-pkg/defs.h>
#include <apt-pkg/error.h>
#include <apt-pkg/cmndline.h>
@@ -2090,6 +2091,7 @@ bool DoSource(CommandLine &CmdL)
if (system(S) != 0)
{
fprintf(stderr,_("Build command '%s' failed.\n"),S);
+ GCOV_DUMP;
_exit(1);
}
}
@@ -2102,6 +2104,7 @@ bool DoSource(CommandLine &CmdL)
if (system(S) != 0)
{
fprintf(stderr,_("Unpack command '%s' failed.\n"),S);
+ GCOV_DUMP;
_exit(1);
}
}
@@ -2124,6 +2127,7 @@ bool DoSource(CommandLine &CmdL)
if (system(S) != 0)
{
fprintf(stderr,_("Unpack command '%s' failed.\n"),S);
+ GCOV_DUMP;
_exit(1);
}
}
@@ -2141,12 +2145,14 @@ bool DoSource(CommandLine &CmdL)
if (system(S) != 0)
{
fprintf(stderr,_("Build command '%s' failed.\n"),S);
+ GCOV_DUMP;
_exit(1);
}
}
#endif
}
+ GCOV_DUMP;
_exit(0);
}
diff --git a/apt/configure.in b/apt/configure.in
index 10178c3..c8848b3 100644
--- a/apt/configure.in
+++ b/apt/configure.in
@@ -9,6 +9,8 @@ AC_CONFIG_SRCDIR([configure.in])
AM_INIT_AUTOMAKE([foreign subdir-objects dist-bzip2 1.7])
AM_MAINTAINER_MODE
+AX_CODE_COVERAGE
+
AC_CONFIG_HEADER([include/config.h:buildlib/config.h.in])
dnl Check our C compiler
diff --git a/apt/methods/Makefile.am b/apt/methods/Makefile.am
index 2d3510c..d29097f 100644
--- a/apt/methods/Makefile.am
+++ b/apt/methods/Makefile.am
@@ -1,8 +1,13 @@
+include $(top_srcdir)/aminclude_static.am
+
+AM_CFLAGS = $(CODE_COVERAGE_CFLAGS)
+AM_CXXFLAGS = $(CODE_COVERAGE_CXXFLAGS)
+AM_CPPFLAGS = $(CODE_COVERAGE_CPPFLAGS)
methodsdir=${libdir}/apt/methods
methods_PROGRAMS = cdrom copy file ftp gpg gzip bzip2 http https rsh ssh rsync
-LDADD = ../apt-pkg/libapt-pkg.la
+LDADD = ../apt-pkg/libapt-pkg.la $(CODE_COVERAGE_LIBS)
cdrom_SOURCES = cdrom.cc
copy_SOURCES = copy.cc
diff --git a/apt/methods/ftp.cc b/apt/methods/ftp.cc
index e79e70d..268f8d3 100644
--- a/apt/methods/ftp.cc
+++ b/apt/methods/ftp.cc
@@ -15,6 +15,7 @@
/*}}}*/
// Include Files /*{{{*/
#include <config.h>
+#include <apt-pkg/defs.h>
#include <apt-pkg/fileutl.h>
#include <apt-pkg/acquire-method.h>
@@ -936,8 +937,10 @@ FtpMethod::FtpMethod() : pkgAcqMethod("1.0",SendConfig)
resume behavoir on user abort */
void FtpMethod::SigTerm(int)
{
- if (FailFd == -1)
+ if (FailFd == -1) {
+ GCOV_DUMP;
_exit(100);
+ }
close(FailFd);
// Timestamp
@@ -946,6 +949,7 @@ void FtpMethod::SigTerm(int)
UBuf.modtime = FailTime;
utime(FailFile.c_str(),&UBuf);
+ GCOV_DUMP;
_exit(100);
}
/*}}}*/
diff --git a/apt/methods/http.cc b/apt/methods/http.cc
index 9302495..5c6f2e2 100644
--- a/apt/methods/http.cc
+++ b/apt/methods/http.cc
@@ -25,6 +25,7 @@
/*}}}*/
// Include Files /*{{{*/
#include <config.h>
+#include <apt-pkg/defs.h>
#include <apt-pkg/fileutl.h>
#include <apt-pkg/acquire-method.h>
@@ -628,8 +629,10 @@ void HttpMethod::SendReq(FetchItem *Itm,CircleBuf &Out)
string ProperHost = Uri.Address.to_string();
// Just in case.
- if (Itm->Uri.length() >= sizeof(Buf))
+ if (Itm->Uri.length() >= sizeof(Buf)) {
+ GCOV_DUMP;
abort();
+ }
/* Build the request. We include a keep-alive header only for non-proxy
requests. This is to tweak old http/1.0 servers that do support keep-alive
@@ -1034,8 +1037,10 @@ int HttpMethod::DealWithHeaders(FetchResult &Res,ServerState *Srv)
resume behavoir on user abort */
void HttpMethod::SigTerm(int)
{
- if (FailFd == -1)
+ if (FailFd == -1) {
+ GCOV_DUMP;
_exit(100);
+ }
close(FailFd);
// Timestamp
@@ -1044,6 +1049,7 @@ void HttpMethod::SigTerm(int)
UBuf.modtime = FailTime;
utime(FailFile.c_str(),&UBuf);
+ GCOV_DUMP;
_exit(100);
}
/*}}}*/
diff --git a/apt/methods/rsh.cc b/apt/methods/rsh.cc
index 2371e4a..0acb3d8 100644
--- a/apt/methods/rsh.cc
+++ b/apt/methods/rsh.cc
@@ -11,6 +11,7 @@
/*}}}*/
// Include Files /*{{{*/
#include <config.h>
+#include <apt-pkg/defs.h>
#include "rsh.h"
#include <apt-pkg/error.h>
@@ -389,8 +390,10 @@ bool RSHMethod::Configuration(const string &Message)
/* */
void RSHMethod::SigTerm(int sig)
{
- if (FailFd == -1)
+ if (FailFd == -1) {
+ GCOV_DUMP;
_exit(100);
+ }
close(FailFd);
// Timestamp
@@ -399,6 +402,7 @@ void RSHMethod::SigTerm(int sig)
UBuf.modtime = FailTime;
utime(FailFile.c_str(),&UBuf);
+ GCOV_DUMP;
_exit(100);
}
/*}}}*/
diff --git a/apt/methods/rsync.cc b/apt/methods/rsync.cc
index f28bb5a..0b974ea 100644
--- a/apt/methods/rsync.cc
+++ b/apt/methods/rsync.cc
@@ -8,6 +8,7 @@ RSYNC Aquire Method - This is the RSYNC aquire method for APT.
/*}}}*/
// Include Files /*{{{*/
#include <config.h>
+#include <apt-pkg/defs.h>
#include <apt-pkg/fileutl.h>
#include <apt-pkg/acquire-method.h>
@@ -482,6 +483,7 @@ RsyncMethod::RsyncMethod() : pkgAcqMethod("1.0",SendConfig),
void RsyncMethod::SigTerm(int)
{
delete server;
+ GCOV_DUMP;
_exit(100);
}
/*}}}*/
diff --git a/apt/tools/Makefile.am b/apt/tools/Makefile.am
index b0eab54..e661c8a 100644
--- a/apt/tools/Makefile.am
+++ b/apt/tools/Makefile.am
@@ -1,11 +1,15 @@
+include $(top_srcdir)/aminclude_static.am
+
+AM_CFLAGS = $(CODE_COVERAGE_CFLAGS)
+AM_CXXFLAGS = $(CODE_COVERAGE_CXXFLAGS)
bin_PROGRAMS = genpkglist gensrclist countpkglist
bin_SCRIPTS = genbasedir
EXTRA_DIST = genbasedir
-AM_CPPFLAGS = -D_RPM_4_4_COMPAT
-LDADD = ../apt-pkg/libapt-pkg.la $(RPMLIBS)
+AM_CPPFLAGS = -D_RPM_4_4_COMPAT $(CODE_COVERAGE_CPPFLAGS)
+LDADD = ../apt-pkg/libapt-pkg.la $(RPMLIBS) $(CODE_COVERAGE_LIBS)
genpkglist_SOURCES = genpkglist.cc cached_md5.cc cached_md5.h
gensrclist_SOURCES = gensrclist.cc cached_md5.cc cached_md5.h
--
2.24.0
Подробная информация о списке рассылки Devel