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

Adds the ability to run tests under performance profiling. #416

Merged
merged 2 commits into from
Aug 9, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
15 changes: 13 additions & 2 deletions etc/cov.mk
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,12 @@ HOST_TARGET := 1
STARTGROUP := -Wl,--start-group
ENDGROUP := -Wl,--end-group

TESTOPTIMIZATION=-O0

ifdef SKIP_COVERAGE
ARCHOPTIMIZATION = -g -O0
ARCHOPTIMIZATION = -g $(TESTOPTIMIZATION)
else
ARCHOPTIMIZATION = -g -O0 -fprofile-arcs -ftest-coverage
ARCHOPTIMIZATION = -g $(TESTOPTIMIZATION) -fprofile-arcs -ftest-coverage
endif

CSHAREDFLAGS = -c -frandom-seed=$(shell echo $(abspath $<) | md5sum | sed 's/\(.*\) .*/\1/') $(ARCHOPTIMIZATION) $(INCLUDES) -Wall -Werror -Wno-unknown-pragmas -MD -MP -fno-stack-protector -D_GNU_SOURCE -DGTEST
Expand All @@ -36,6 +38,15 @@ LDFLAGS = $(ARCHOPTIMIZATION) -Wl,-Map="$(@:%=%.map)"
SYSLIB_SUBDIRS +=
SYSLIBRARIES = -lrt -lpthread -lavahi-client -lavahi-common $(SYSLIBRARIESEXTRA)

ifdef RUN_GPERF
CXXFLAGS += -DWITHGPERFTOOLS
LDFLAGS += -DWITHGPERFTOOLS
SYSLIBRARIES += -lprofiler
TESTOPTIMIZATION = -O3
SKIP_COVERAGE = 1
endif


ifndef SKIP_COVERAGE
LDFLAGS += -pg
SYSLIBRARIES += -lgcov
Expand Down
8 changes: 5 additions & 3 deletions etc/test.mk
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,13 @@ LIBS = $(STARTGROUP) \
$(ENDGROUP) \
$(LINKCORELIBS)

TESTOPTIMIZATION=-O0

INCLUDES += -I$(GTESTPATH)/include -I$(GMOCKPATH)/include -I$(GMOCKPATH) \
-I$(OPENMRNPATH)/src -I$(OPENMRNPATH)/include
CFLAGS += -DGTEST $(INCLUDES) -Wno-unused-but-set-variable -fprofile-arcs -ftest-coverage -O0
CXXFLAGS += -DGTEST $(INCLUDES) -Wno-unused-but-set-variable -fprofile-arcs -ftest-coverage -O0
SYSLIBRARIES += -lgcov -fprofile-arcs -ftest-coverage -O0
CFLAGS += -DGTEST $(INCLUDES) -Wno-unused-but-set-variable -fprofile-arcs -ftest-coverage $(TESTOPTIMIZATION)
CXXFLAGS += -DGTEST $(INCLUDES) -Wno-unused-but-set-variable -fprofile-arcs -ftest-coverage $(TESTOPTIMIZATION)
SYSLIBRARIES += -lgcov -fprofile-arcs -ftest-coverage $(TESTOPTIMIZATION)
LDFLAGS += -L$(LIBDIR)

.SUFFIXES:
Expand Down
8 changes: 8 additions & 0 deletions src/utils/test_main.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
#include <stdarg.h>
#include <memory>
#include <string>
#include <functional>
#include "gtest/gtest.h"
#include "gmock/gmock.h"

Expand All @@ -54,6 +55,13 @@
#include "os/os.h"
#include "utils/StringPrintf.hxx"

#ifdef WITHGPERFTOOLS
#include <gperftools/profiler.h>

std::function<void()> profiler_enable{&ProfilerEnable};
std::function<void()> profiler_disable{&ProfilerDisable};
#endif

int appl_main(int argc, char *argv[])
{
testing::InitGoogleMock(&argc, argv);
Expand Down