Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce gcovpreload repo to support code coverage report generation for swss and sairedis #11323

Open
wants to merge 36 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
ab433a1
introduce gcovpreload repo
pettershao-ragilenetworks Jul 1, 2022
e2fbf90
Create gcov_preload.c
pettershao-ragilenetworks Jul 1, 2022
685fa8f
Create Makefile
pettershao-ragilenetworks Jul 1, 2022
3957337
Create changelog
pettershao-ragilenetworks Jul 1, 2022
ba21501
Create control
pettershao-ragilenetworks Jul 1, 2022
2b9eaea
Create copyright
pettershao-ragilenetworks Jul 1, 2022
e9a3e6b
Create debhelper-build-stamp
pettershao-ragilenetworks Jul 1, 2022
b28e173
Create rules
pettershao-ragilenetworks Jul 1, 2022
f858d26
Merge branch 'Azure:master' into introduce-gcovpreload-repo
pettershao-ragilenetworks Jul 2, 2022
f0dabfd
Create gcov_preload.mk
pettershao-ragilenetworks Jul 2, 2022
d507796
Update docker-init.j2
pettershao-ragilenetworks Jul 18, 2022
928f04d
Update sairedis.mk
pettershao-ragilenetworks Jul 18, 2022
446e6f6
Update docker-orchagent.mk
pettershao-ragilenetworks Jul 18, 2022
710da0c
Update Dockerfile.j2
pettershao-ragilenetworks Jul 18, 2022
f868eb6
Update swss.mk
pettershao-ragilenetworks Jul 18, 2022
7d158d0
Update docker-orchagent.mk
pettershao-ragilenetworks Jul 18, 2022
88cdfe3
Update Dockerfile.j2
pettershao-ragilenetworks Jul 18, 2022
45bbeb5
Update Dockerfile.j2
pettershao-ragilenetworks Jul 18, 2022
ccdb1e2
Update gcov_preload.mk
pettershao-ragilenetworks Aug 1, 2022
465c9ad
Update .gitignore
pettershao-ragilenetworks Aug 5, 2022
3a00844
change permission of rules
pettershao-ragilenetworks Aug 17, 2022
932ded8
triggle rebuild
pettershao-ragilenetworks Aug 18, 2022
a429f44
triggle rebuild
pettershao-ragilenetworks Aug 23, 2022
1173bb2
triggle rebuild
pettershao-ragilenetworks Aug 23, 2022
0525e1f
triggle rebuild
pettershao-ragilenetworks Aug 25, 2022
733ceae
Update docker-sonic-vs.mk
pettershao-ragilenetworks Aug 31, 2022
39f4256
Create .gitignore
pettershao-ragilenetworks Sep 13, 2022
d3eef75
Update .gitignore
pettershao-ragilenetworks Sep 13, 2022
6cde260
Create libgcovpreload.postinst
pettershao-ragilenetworks Sep 13, 2022
b0bbc1d
Update .gitignore
pettershao-ragilenetworks Sep 13, 2022
0828cce
Update docker-init.j2
pettershao-ragilenetworks Sep 13, 2022
fc04151
Update Dockerfile.j2
pettershao-ragilenetworks Sep 13, 2022
a6d97d0
Update Dockerfile.j2
pettershao-ragilenetworks Sep 13, 2022
e9c60ab
Update Dockerfile.j2
pettershao-ragilenetworks Sep 13, 2022
59af7a2
Update libgcovpreload.postinst
pettershao-ragilenetworks Sep 14, 2022
c306750
Update libgcovpreload.postinst
pettershao-ragilenetworks Sep 18, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion platform/vs/docker-sonic-vs.mk
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ $(DOCKER_SONIC_VS)_DEPENDS += $(SWSS) \
$(LIBYANG_PY3) \
$(SONIC_UTILITIES_DATA) \
$(SONIC_HOST_SERVICES_DATA) \
$(IPROUTE2)
$(IPROUTE2) \
$(LIBGCOV_PRELOAD)

# swsssdk is a dependency of sonic-py-common
# TODO: sonic-py-common should depend on swsscommon instead
Expand Down
2 changes: 1 addition & 1 deletion rules/docker-orchagent.mk
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ endif
$(DOCKER_ORCHAGENT)_DBG_DEPENDS = $($(DOCKER_SWSS_LAYER_BULLSEYE)_DBG_DEPENDS)
$(DOCKER_ORCHAGENT)_DBG_DEPENDS += $(SWSS_DBG) \
$(LIBSWSSCOMMON_DBG) \
$(LIBSAIREDIS_DBG)
$(LIBSAIREDIS_DBG) \
Copy link
Collaborator

@xumia xumia Sep 21, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like the change is not necessary, may need to remove the last character "\", or miss a dependent target name.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have the same concern.

$(DOCKER_ORCHAGENT)_PYTHON_WHEELS += $(SCAPY)

$(DOCKER_ORCHAGENT)_DBG_IMAGE_PACKAGES = $($(DOCKER_SWSS_LAYER_BULLSEYE)_DBG_IMAGE_PACKAGES)
Expand Down
12 changes: 12 additions & 0 deletions rules/gcov_preload.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# libgcovpreload package
# Created for gcda files generations

GCOV_PRELOAD_VERSION = 0.0.1
GCOV_PRELOAD_VERSION_FULL = $(GCOV_PRELOAD_VERSION)-1

export GCOV_PRELOAD_VERSION GCOV_PRELOAD_VERSION_FULL

LIBGCOV_PRELOAD = libgcovpreload_$(GCOV_PRELOAD_VERSION_FULL)_$(CONFIGURED_ARCH).deb
$(LIBGCOV_PRELOAD)_SRC_PATH = $(SRC_PATH)/preload

SONIC_MAKE_DEBS += $(LIBGCOV_PRELOAD)
15 changes: 9 additions & 6 deletions rules/sairedis.mk
Original file line number Diff line number Diff line change
Expand Up @@ -8,40 +8,43 @@ $(LIBSAIREDIS)_DPKG_TARGET = binary-sairedis
$(LIBSAIREDIS)_SRC_PATH = $(SRC_PATH)/sonic-sairedis
$(LIBSAIREDIS)_VERSION = $(LIBSAIREDIS_VERSION)
$(LIBSAIREDIS)_NAME = $(LIBSAIREDIS_NAME)
$(LIBSAIREDIS)_DEPENDS += $(LIBSWSSCOMMON_DEV)
$(LIBSAIREDIS)_DEPENDS += $(LIBSWSSCOMMON_DEV) $(LIBGCOV_PRELOAD)
Copy link
Collaborator

@xumia xumia Sep 21, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure my understanding is correct. Is it for code coverage? Is it possible to install it on demand, we can enable it in PR build, for official build to install in devices, looks like it is not necessary. We may need to clean some tools for build/test only in the image.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Currently, I have raised a sairedis PR to support GCOV, but need preload lib(the reason why can't build with sairedis repo together has mentioned in PR: sonic-net/sonic-sairedis#972). As I know, pipeline framework will download vs docker and install sairedis deb into it, and then do testing. So i need to make sure that the downloaded docker encompass preload lib.
Is it possible to install it on demand -> I think a MACRO "ENABLE_GCOV" defined in rules/config will be fine. I will add it soon, default value set to 'y'.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We do not want LIBGCOV_PRELOAD in the sonic image. You only need it in test.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are there other ways to solve this problem? to make sure that vs docker downloaded by pipeline framework when testing encompass gcov preload lib and this lib will not in sonic image ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We do not want LIBGCOV_PRELOAD in the sonic image. You only need it in test.

Do you have any idea about how to solve this problem?

$(LIBSAIREDIS)_RDEPENDS += $(LIBSWSSCOMMON)
$(LIBSAIREDIS)_DEB_BUILD_OPTIONS = nocheck
SONIC_DPKG_DEBS += $(LIBSAIREDIS)

LIBSAIREDIS_DEV = $(LIBSAIREDIS_NAME)-dev_$(LIBSAIREDIS_VERSION)_$(CONFIGURED_ARCH).deb
$(LIBSAIREDIS_DEV)_DEPENDS += $(LIBGCOV_PRELOAD)
$(eval $(call add_derived_package,$(LIBSAIREDIS),$(LIBSAIREDIS_DEV)))

LIBSAIVS = libsaivs_$(LIBSAIREDIS_VERSION)_$(CONFIGURED_ARCH).deb
$(LIBSAIVS)_DEPENDS += $(LIBGCOV_PRELOAD)
$(eval $(call add_derived_package,$(LIBSAIREDIS),$(LIBSAIVS)))

LIBSAIVS_DEV = libsaivs-dev_$(LIBSAIREDIS_VERSION)_$(CONFIGURED_ARCH).deb
$(eval $(call add_derived_package,$(LIBSAIREDIS),$(LIBSAIVS_DEV)))
$(LIBSAIVS_DEV)_DEPENDS += $(LIBSAIVS)
$(LIBSAIVS_DEV)_DEPENDS += $(LIBSAIVS) $(LIBGCOV_PRELOAD)

LIBSAIMETADATA = libsaimetadata_$(LIBSAIREDIS_VERSION)_$(CONFIGURED_ARCH).deb
$(LIBSAIMETADATA)_DEPENDS += $(LIBGCOV_PRELOAD)
$(eval $(call add_derived_package,$(LIBSAIREDIS),$(LIBSAIMETADATA)))

LIBSAIMETADATA_DEV = libsaimetadata-dev_$(LIBSAIREDIS_VERSION)_$(CONFIGURED_ARCH).deb
$(LIBSAIMETADATA_DEV)_DEPENDS += $(LIBSAIMETADATA)
$(LIBSAIMETADATA_DEV)_DEPENDS += $(LIBSAIMETADATA) $(LIBGCOV_PRELOAD)
$(eval $(call add_derived_package,$(LIBSAIREDIS),$(LIBSAIMETADATA_DEV)))

LIBSAIREDIS_DBG = $(LIBSAIREDIS_NAME)-dbg_$(LIBSAIREDIS_VERSION)_$(CONFIGURED_ARCH).deb
$(LIBSAIREDIS_DBG)_DEPENDS += $(LIBSAIREDIS)
$(LIBSAIREDIS_DBG)_DEPENDS += $(LIBSAIREDIS) $(LIBGCOV_PRELOAD)
$(LIBSAIREDIS_DBG)_RDEPENDS += $(LIBSAIREDIS)
$(eval $(call add_derived_package,$(LIBSAIREDIS),$(LIBSAIREDIS_DBG)))

LIBSAIVS_DBG = libsaivs-dbg_$(LIBSAIREDIS_VERSION)_$(CONFIGURED_ARCH).deb
$(LIBSAIVS_DBG)_DEPENDS += $(LIBSAIVS)
$(LIBSAIVS_DBG)_DEPENDS += $(LIBSAIVS) $(LIBGCOV_PRELOAD)
$(LIBSAIVS_DBG)_RDEPENDS += $(LIBSAIVS)
$(eval $(call add_derived_package,$(LIBSAIREDIS),$(LIBSAIVS_DBG)))

LIBSAIMETADATA_DBG = libsaimetadata-dbg_$(LIBSAIREDIS_VERSION)_$(CONFIGURED_ARCH).deb
$(LIBSAIMETADATA_DBG)_DEPENDS += $(LIBSAIMETADATA)
$(LIBSAIMETADATA_DBG)_DEPENDS += $(LIBSAIMETADATA) $(LIBGCOV_PRELOAD)
$(LIBSAIMETADATA_DBG)_RDEPENDS += $(LIBSAIMETADATA)
$(eval $(call add_derived_package,$(LIBSAIREDIS),$(LIBSAIMETADATA_DBG)))

Expand Down
5 changes: 3 additions & 2 deletions rules/swss.mk
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,16 @@ SWSS = swss_1.0.0_$(CONFIGURED_ARCH).deb
$(SWSS)_SRC_PATH = $(SRC_PATH)/sonic-swss
$(SWSS)_DEPENDS += $(LIBSAIREDIS_DEV) $(LIBSAIMETADATA_DEV) $(LIBTEAM_DEV) \
$(LIBTEAMDCTL) $(LIBTEAM_UTILS) $(LIBSWSSCOMMON_DEV) \
$(LIBSAIVS) $(LIBSAIVS_DEV)
$(LIBSAIVS) $(LIBSAIVS_DEV) \
$(LIBGCOV_PRELOAD)
$(SWSS)_UNINSTALLS = $(LIBSAIVS_DEV)

$(SWSS)_RDEPENDS += $(LIBSAIREDIS) $(LIBSAIMETADATA) $(LIBTEAM) \
$(LIBTEAMDCTL) $(LIBSWSSCOMMON) $(PYTHON3_SWSSCOMMON)
SONIC_DPKG_DEBS += $(SWSS)

SWSS_DBG = swss-dbg_1.0.0_$(CONFIGURED_ARCH).deb
$(SWSS_DBG)_DEPENDS += $(SWSS)
$(SWSS_DBG)_DEPENDS += $(SWSS) $(LIBGCOV_PRELOAD)
$(SWSS_DBG)_RDEPENDS += $(SWSS)
$(eval $(call add_derived_package,$(SWSS),$(SWSS_DBG)))

Expand Down
5 changes: 5 additions & 0 deletions src/preload/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
gcovpreload/debian/*
!gcovpreload/debian/changelog
!gcovpreload/debian/control
!gcovpreload/debian/rules
!gcovpreload/debian/libgcovpreload.postinst
11 changes: 11 additions & 0 deletions src/preload/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
.ONESHELL:
SHELL = /bin/bash
.SHELLFLAGS += -e

MAIN_TARGET = libgcovpreload_$(GCOV_PRELOAD_VERSION_FULL)_$(CONFIGURED_ARCH).deb

$(addprefix $(DEST)/, $(MAIN_TARGET)): $(DEST)/% :
pushd gcov_preload
dpkg-buildpackage -rfakeroot -d -b -us -uc -j$(SONIC_CONFIG_MAKE_JOBS)
popd
mv $* $(DEST)/
22 changes: 22 additions & 0 deletions src/preload/gcov_preload/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#gcov Makefile

MKDIR := mkdir
MV := mv
#OBJ=gcov_preload.o
LIBNAME=libgcovpreload

# Fallback to gcc when $CC is not in $PATH.
CC:=$(shell sh -c 'type $${CC%% *} >/dev/null 2>/dev/null && echo $(CC) || echo gcc')
CXX:=$(shell sh -c 'type $${CXX%% *} >/dev/null 2>/dev/null && echo $(CXX) || echo g++')

DYLIBSUFFIX=so
DYLIBNAME=$(LIBNAME).$(DYLIBSUFFIX)
DYLIB_MAKE_CMD=$(CC) -shared -fpic gcov_preload.c -o ${DYLIBNAME}

$(DYLIBNAME):
$(DYLIB_MAKE_CMD)

# Other Targets
install:
$(MKDIR) -p $(DESTDIR)/usr/lib
$(MV) $(DYLIBNAME) $(DESTDIR)/usr/lib
5 changes: 5 additions & 0 deletions src/preload/gcov_preload/debian/changelog
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
gcovpreload (0.0.1-1) stretch-backports; urgency=medium

* Rebuild for stretch-backports. (Closes: #911732)

--Petter Shao <pettershao@ragilenetworks> Wed, 07 Nov 2021 11:26:50 +0000
22 changes: 22 additions & 0 deletions src/preload/gcov_preload/debian/control
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
Source: gcovpreload
Priority: optional
Maintainer: Petter Shao <pettershao@ragilenetworks>
Build-Depends:
debhelper-compat (= 11),
procps <!nocheck>,
redis-server (>= 2:2.4.2-2) [linux-any kfreebsd-any] <!nocheck>,
Standards-Version: 4.2.1
Section: libs
Homepage:
Vcs-Git:
Vcs-Browser:

Package: libgcovpreload
Architecture: any
Depends:
${misc:Depends},
${shlibs:Depends},
Pre-Depends:
${misc:Pre-Depends},
Multi-Arch: same
Description: minimalistic C client library for Redis
8 changes: 8 additions & 0 deletions src/preload/gcov_preload/debian/copyright
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
Format: https://www.debian.org/doc/packaging-manuals/copyright-format/1.0/
Upstream-Name: gcovpreload
Upstream-Contact: Petter Shao <pettershao@ragilenetworks>
Source:

Files: *
Copyright:
License: BSD-3-Clause
1 change: 1 addition & 0 deletions src/preload/gcov_preload/debian/debhelper-build-stamp
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
libgcovpreload
4 changes: 4 additions & 0 deletions src/preload/gcov_preload/debian/libgcovpreload.postinst
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# !/bin/sh
# postinst
echo /usr/lib/libgcovpreload.so > /etc/ld.so.preload

8 changes: 8 additions & 0 deletions src/preload/gcov_preload/debian/rules
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/usr/bin/make -f

%:
dh $@

override_dh_auto_install:
dh_auto_install -- LIBRARY_PATH="lib/" \
PREFIX=/usr
43 changes: 43 additions & 0 deletions src/preload/gcov_preload/gcov_preload.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#include <stdio.h>
#include <stdlib.h>
#include <signal.h>
#include <signal.h>
#define SIMPLE_WAY

void sighandler(int signo)
{
#ifdef SIMPLE_WAY
exit(signo);
#else
extern void __gcov_flush(); /* flush*/
__gcov_flush(); /* flush out gcov stats data */
raise(signo); /* raise the signal again to crash process */
#endif
}

/**
* The code for cracking the preloaded dynamic library gcov_preload.so is as follows, where __attribute__((constructor)) is the symbol of gcc,
* The modified function will be called before the main function is executed. We use it to intercept the exception signal to our own function, and then call __gcov_flush() to output the error message
*/

__attribute__ ((constructor))

void ctor()
{
int sigs[] = {
SIGILL, SIGFPE, SIGABRT, SIGBUS,
SIGSEGV, SIGHUP, SIGINT, SIGQUIT,
SIGTERM
};
int i;
struct sigaction sa;
sa.sa_handler = sighandler;
sigemptyset(&sa.sa_mask);
sa.sa_flags = SA_RESETHAND;

for(i = 0; i < sizeof(sigs)/sizeof(sigs[0]); ++i) {
if (sigaction(sigs[i], &sa, NULL) == -1) {
perror("Could not set signal handler");
}
}
}