Skip to content

Commit

Permalink
Adds the ability to run tests under performance profiling. (#416)
Browse files Browse the repository at this point in the history
* Adds the ability to run tests under performance profiling.
For this apt-get install libgoogle-perftools-dev needs to be installed.

* removes unnecessary whitespace
  • Loading branch information
balazsracz authored Aug 9, 2020
1 parent 95b30e2 commit 6920d7e
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 5 deletions.
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

0 comments on commit 6920d7e

Please sign in to comment.