Skip to contentSkip to conversation

Use Google Test as DPDK unit test framework

RFC In review Declan Doherty 8 participants 19 messages Aug 2, 2016 – Aug 5, 2016

lore
Share & tools
lore
#0 lore raw

cover Use Google Test as DPDK unit test framework

I've been trying out using google test as a possible replacement for our unit test framework and have put to together this series of patches with help from Anatoly as RFC to get peoples thoughts on migrating to google test.

To facilitate google test this rfc patch set contains build system changes to allow C++ to built within the DPDK framework, this intended for unit test code only, and to support google test which is a C++ framework. Don't worry, I'm not advocating making DPDK a C++ project :)

A new EAL option to allow the user to silence logging to stdout while still logging to syslog. This was to facilitate a eclipse plugin I was using which parses googe test output, so it is not strictly necessary.

A example application which uses the C++ build changes.

And finally a google test application which some mempool tests ported from the current test app to give a feel of what google test is like to use for testing C.

Some of the major advantages of google test that I see over continuing to use the current test include giving a consist feel to all tests, a powerful test execution framework which allow individual test suites or tests to be specified from the command line, support for a standard xunit output which can be integrated into a continuous build systems, and a very powerful mocking library which allows much more control over testing failure conditions.

Have a look at the patch set keeping in mind that this isn't intended to be production code, I imagine that build systems changes for C++ would require some refinement etc

Regards
Declan

Anatoly Burakov (2):
mk: Add support for C++ compilation
examples: add c++ example application

Declan Doherty (2):
eal: add command line option to log output to stdout app/test-gtest: example google test application

 app/Makefile                               |   1 +
 app/test-gtest/Makefile                    |  67 +++++++
 app/test-gtest/main.cpp                    |  20 ++
 app/test-gtest/test_mempool.cpp            | 281 +++++++++++++++++++++++++++++
 config/common_base                         |   5 +
 examples/Makefile                          |   1 +
 examples/helloworld-cpp/Makefile           |  51 ++++++
 examples/helloworld-cpp/c_code.c           |   5 +
 examples/helloworld-cpp/c_header.h         |   6 +
 examples/helloworld-cpp/cpp_code.cpp       |  89 +++++++++
 lib/librte_eal/common/eal_common_log.c     |  14 ++
 lib/librte_eal/common/eal_common_options.c |   8 +
 lib/librte_eal/common/eal_options.h        |   2 +
 lib/librte_eal/common/include/rte_log.h    |  15 ++
 lib/librte_eal/linuxapp/eal/eal.c          |   1 +
 lib/librte_eal/linuxapp/eal/eal_log.c      |  23 ++-
 mk/internal/rte.compile-pre.mk             |  52 +++++-
 mk/target/generic/rte.vars.mk              |   3 +
 mk/toolchain/clang/rte.vars.mk             |  14 +-
 mk/toolchain/gcc/rte.vars.mk               |  14 +-
 mk/toolchain/icc/rte.vars.mk               |  10 +-
 21 files changed, 660 insertions(+), 22 deletions(-)
 create mode 100644 app/test-gtest/Makefile
 create mode 100644 app/test-gtest/main.cpp
 create mode 100644 app/test-gtest/test_mempool.cpp
 create mode 100644 examples/helloworld-cpp/Makefile
 create mode 100644 examples/helloworld-cpp/c_code.c
 create mode 100644 examples/helloworld-cpp/c_header.h
 create mode 100644 examples/helloworld-cpp/cpp_code.cpp
Signature · 1 line
2.5.5
#1 lore raw

RFC 1/4 mk: Add support for C++ compilation

From: Anatoly Burakov <[email protected]>

Adding support for compiling C++ files as part of the build system

---
 mk/internal/rte.compile-pre.mk | 52 ++++++++++++++++++++++++++++++++++++++----
 mk/target/generic/rte.vars.mk  |  3 +++
 mk/toolchain/clang/rte.vars.mk | 14 +++++++++---
 mk/toolchain/gcc/rte.vars.mk   | 14 +++++++++---
 mk/toolchain/icc/rte.vars.mk   | 10 +++++---
 5 files changed, 80 insertions(+), 13 deletions(-)
mk/internal/rte.compile-pre.mk +48 -4
index f740179..2342942 100644
@@ -32,12 +32,12 @@
 #
 # Common to rte.lib.mk, rte.app.mk, rte.obj.mk
 #
-
 SRCS-all := $(SRCS-y) $(SRCS-n) $(SRCS-)
 
 # convert source to obj file
 src2obj = $(strip $(patsubst %.c,%.o,\
-	$(patsubst %.S,%_s.o,$(1))))
+	$(patsubst %.S,%_s.o,\
+	$(patsubst %.cpp,%_cpp.o,$(1)))))
 
 # add a dot in front of the file name
 dotfile = $(strip $(foreach f,$(1),\
@@ -46,12 +46,14 @@ dotfile = $(strip $(foreach f,$(1),\
 # convert source/obj files into dot-dep filename (does not
 # include .S files)
 src2dep = $(strip $(call dotfile,$(patsubst %.c,%.o.d, \
-		$(patsubst %.S,,$(1)))))
+		$(patsubst %.cpp,%_cpp.o.d, \
+		$(patsubst %.S,,$(1))))))
 obj2dep = $(strip $(call dotfile,$(patsubst %.o,%.o.d,$(1))))
 
 # convert source/obj files into dot-cmd filename
 src2cmd = $(strip $(call dotfile,$(patsubst %.c,%.o.cmd, \
-		$(patsubst %.S,%_s.o.cmd,$(1)))))
+		$(patsubst %.cpp,%_cpp.o.cmd, \
+		$(patsubst %.S,%_s.o.cmd,$(1))))))
 obj2cmd = $(strip $(call dotfile,$(patsubst %.o,%.o.cmd,$(1))))
 
 OBJS-y := $(call src2obj,$(SRCS-y))
@@ -186,3 +188,45 @@ S_TO_O_DO = @set -e; \
 		$(depfile_missing),\
 		$(depfile_newer)),\
 		$(S_TO_O_DO))
+
+
+# command to compile a .cpp file to generate an object
+ifeq ($(USE_HOST),1)
+CXX_TO_O = $(HOSTCXX) -Wp,-MD,$(call obj2dep,$(@)).tmp $(HOST_CXXFLAGS) \
+	$(CXXFLAGS_$(@)) $(HOST_EXTRA_CXXFLAGS) -o $@ -c $<
+CXX_TO_O_STR = $(subst ','\'',$(CXX_TO_O)) #'# fix syntax highlight
+CXX_TO_O_DISP = $(if $(V),"$(CXX_TO_O_STR)","  HOSTCXX $(@)")
+else
+CXX_TO_O = $(CXX) -Wp,-MD,$(call obj2dep,$(@)).tmp $(CXXFLAGS) \
+	$(CXXFLAGS_$(@)) $(EXTRA_CXXFLAGS) -o $@ -c $<
+CXX_TO_O_STR = $(subst ','\'',$(CXX_TO_O)) #'# fix syntax highlight
+CXX_TO_O_DISP = $(if $(V),"$(CXX_TO_O_STR)","  CXX $(@)")
+endif
+CXX_TO_O_CMD = 'cmd_$@ = $(CXX_TO_O_STR)'
+CXX_TO_O_DO = @set -e; \
+	echo $(CXX_TO_O_DISP); \
+	$(CXX_TO_O) && \
+	echo $(CXX_TO_O_CMD) > $(call obj2cmd,$(@)) && \
+	sed 's,'$@':,dep_'$@' =,' $(call obj2dep,$(@)).tmp > $(call obj2dep,$(@)) && \
+	rm -f $(call obj2dep,$(@)).tmp
+
+#
+# Compile .cpp file if needed
+# Note: dep_$$@ is from the .d file and DEP_$$@ can be specified by
+# user (by default it is empty)
+#
+.SECONDEXPANSION:
+%_cpp.o: %.cpp $$(wildcard $$(dep_$$@)) $$(DEP_$$(@)) FORCE
+	@[ -d $(dir $@) ] || mkdir -p $(dir $@)
+	$(if $(D),\
+		@echo -n "$< -> $@ " ; \
+		echo -n "file_missing=$(call boolean,$(file_missing)) " ; \
+		echo -n "cmdline_changed=$(call boolean,$(call cmdline_changed,$(CXX_TO_O))) " ; \
+		echo -n "depfile_missing=$(call boolean,$(depfile_missing)) " ; \
+		echo "depfile_newer=$(call boolean,$(depfile_newer))")
+	$(if $(or \
+		$(file_missing),\
+		$(call cmdline_changed,$(CXX_TO_O)),\
+		$(depfile_missing),\
+		$(depfile_newer)),\
+		$(CXX_TO_O_DO))
\ No newline at end of file
mk/target/generic/rte.vars.mk +3 -0
index 75a616a..128d4e2 100644
@@ -138,7 +138,10 @@ endif
 LDFLAGS += -L$(RTE_SDK_BIN)/lib
 endif
 
+CXXFLAGS := $(CFLAGS)
+
 export CFLAGS
+export CXXFLAGS
 export LDFLAGS
 
 endif
mk/toolchain/clang/rte.vars.mk +11 -3
index 7749b99..2a7105e 100644
@@ -32,8 +32,9 @@
 #
 # toolchain:
 #
-#   - define CC, LD, AR, AS, ... (overriden by cmdline value)
+#   - define CC, CXX, LD, AR, AS, ... (overriden by cmdline value)
 #   - define TOOLCHAIN_CFLAGS variable (overriden by cmdline value)
+#   - define TOOLCHAIN_CXXFLAGS variable (overriden by cmdline value)
 #   - define TOOLCHAIN_LDFLAGS variable (overriden by cmdline value)
 #   - define TOOLCHAIN_ASFLAGS variable (overriden by cmdline value)
 #
@@ -41,6 +42,7 @@
 CC        = $(CROSS)clang
 KERNELCC  = $(CROSS)gcc
 CPP       = $(CROSS)cpp
+CXX       = $(CROSS)clang++
 # for now, we don't use as but nasm.
 # AS      = $(CROSS)as
 AS        = nasm
@@ -57,10 +59,16 @@ HOSTCC    = $(CC)
 else
 HOSTCC    = clang
 endif
+ifeq ("$(origin CXX)", "command line")
+HOSTCXX    = $(CXX)
+else
+HOSTCXX    = clang++
+endif
 HOSTAS    = as
 
 TOOLCHAIN_ASFLAGS =
 TOOLCHAIN_CFLAGS =
+TOOLCHAIN_CXXFLAGS =
 TOOLCHAIN_LDFLAGS =
 
 WERROR_FLAGS := -W -Wall -Wstrict-prototypes -Wmissing-prototypes
@@ -79,5 +87,5 @@ include $(RTE_SDK)/mk/toolchain/$(RTE_TOOLCHAIN)/rte.toolchain-compat.mk
 # workaround clang bug with warning "missing field initializer" for "= {0}"
 WERROR_FLAGS += -Wno-missing-field-initializers
 
-export CC AS AR LD OBJCOPY OBJDUMP STRIP READELF
-export TOOLCHAIN_CFLAGS TOOLCHAIN_LDFLAGS TOOLCHAIN_ASFLAGS
+export CC CXX AS AR LD OBJCOPY OBJDUMP STRIP READELF
+export TOOLCHAIN_CFLAGS TOOLCHAIN_CXXFLAGS TOOLCHAIN_LDFLAGS TOOLCHAIN_ASFLAGS
mk/toolchain/gcc/rte.vars.mk +11 -3
index ff70f3d..1961f6c 100644
@@ -32,8 +32,9 @@
 #
 # toolchain:
 #
-#   - define CC, LD, AR, AS, ... (overriden by cmdline value)
+#   - define CC, CXX, LD, AR, AS, ... (overriden by cmdline value)
 #   - define TOOLCHAIN_CFLAGS variable (overriden by cmdline value)
+#   - define TOOLCHAIN_CXXFLAGS variable (overriden by cmdline value)
 #   - define TOOLCHAIN_LDFLAGS variable (overriden by cmdline value)
 #   - define TOOLCHAIN_ASFLAGS variable (overriden by cmdline value)
 #
@@ -41,6 +42,7 @@
 CC        = $(CROSS)gcc
 KERNELCC  = $(CROSS)gcc
 CPP       = $(CROSS)cpp
+CXX       = $(CROSS)g++
 # for now, we don't use as but nasm.
 # AS      = $(CROSS)as
 AS        = nasm
@@ -57,10 +59,16 @@ HOSTCC    = $(CC)
 else
 HOSTCC    = gcc
 endif
+ifeq ("$(origin CXX)", "command line")
+HOSTCXX    = $(CXX)
+else
+HOSTCXX    = g++
+endif
 HOSTAS    = as
 
 TOOLCHAIN_ASFLAGS =
 TOOLCHAIN_CFLAGS =
+TOOLCHAIN_CXXFLAGS =
 TOOLCHAIN_LDFLAGS =
 
 ifeq ($(CONFIG_RTE_LIBRTE_GCOV),y)
@@ -99,5 +107,5 @@ ifeq ($(shell test $(GCC_VERSION) -lt 47 && echo 1), 1)
 WERROR_FLAGS += -Wno-uninitialized
 endif
 
-export CC AS AR LD OBJCOPY OBJDUMP STRIP READELF
-export TOOLCHAIN_CFLAGS TOOLCHAIN_LDFLAGS TOOLCHAIN_ASFLAGS
+export CC CXX AS AR LD OBJCOPY OBJDUMP STRIP READELF
+export TOOLCHAIN_CFLAGS TOOLCHAIN_CXXFLAGS TOOLCHAIN_LDFLAGS TOOLCHAIN_ASFLAGS
mk/toolchain/icc/rte.vars.mk +7 -3
index ba69f1f..e9d6721 100644
@@ -32,8 +32,9 @@
 #
 # toolchain:
 #
-#   - define CC, LD, AR, AS, ... (overriden by cmdline value)
+#   - define CC, CXX, LD, AR, AS, ... (overriden by cmdline value)
 #   - define TOOLCHAIN_CFLAGS variable (overriden by cmdline value)
+#   - define TOOLCHAIN_CXXFLAGS variable (overriden by cmdline value)
 #   - define TOOLCHAIN_LDFLAGS variable (overriden by cmdline value)
 #   - define TOOLCHAIN_ASFLAGS variable (overriden by cmdline value)
 #
@@ -42,6 +43,7 @@
 # x86->x86 compiler
 
 CC        = icc
+CXX       = icc
 KERNELCC  = gcc
 CPP       = cpp
 AS        = nasm
@@ -57,9 +59,11 @@ HOSTCC    = icc
 else
 HOSTCC    = gcc
 endif
+HOSTCXX   = icc
 HOSTAS    = as
 
 TOOLCHAIN_CFLAGS =
+TOOLCHAIN_CXXFLAGS =
 TOOLCHAIN_LDFLAGS =
 TOOLCHAIN_ASFLAGS =
 
@@ -83,5 +87,5 @@ ifeq ($(shell test $(ICC_MAJOR_VERSION) -ge 14 && echo 1), 1)
 	TOOLCHAIN_CFLAGS += -no-inline-max-size -no-inline-max-total-size
 endif
 
-export CC AS AR LD OBJCOPY OBJDUMP STRIP READELF
-export TOOLCHAIN_CFLAGS TOOLCHAIN_LDFLAGS TOOLCHAIN_ASFLAGS
+export CC CXX AS AR LD OBJCOPY OBJDUMP STRIP READELF
+export TOOLCHAIN_CFLAGS TOOLCHAIN_CXXFLAGS TOOLCHAIN_LDFLAGS TOOLCHAIN_ASFLAGS
Signature · 1 line
2.5.5
#2 lore raw

RFC 2/4 examples: add c++ example application

In reply to Declan Doherty

From: Anatoly Burakov <[email protected]>

Example application for C++ compilation

---
 examples/Makefile                    |  1 +
 examples/helloworld-cpp/Makefile     | 51 +++++++++++++++++++++
 examples/helloworld-cpp/c_code.c     |  5 ++
 examples/helloworld-cpp/c_header.h   |  6 +++
 examples/helloworld-cpp/cpp_code.cpp | 89 ++++++++++++++++++++++++++++++++++++
 5 files changed, 152 insertions(+)
 create mode 100644 examples/helloworld-cpp/Makefile
 create mode 100644 examples/helloworld-cpp/c_code.c
 create mode 100644 examples/helloworld-cpp/c_header.h
 create mode 100644 examples/helloworld-cpp/cpp_code.cpp
examples/Makefile +1 -0
index 18b41b9..cb81c6c 100644
@@ -46,6 +46,7 @@ endif
 DIRS-y += ethtool
 DIRS-y += exception_path
 DIRS-y += helloworld
+DIRS-y += helloworld-cpp
 DIRS-$(CONFIG_RTE_LIBRTE_PIPELINE) += ip_pipeline
 ifeq ($(CONFIG_RTE_LIBRTE_LPM),y)
 DIRS-$(CONFIG_RTE_IP_FRAG) += ip_reassembly
examples/helloworld-cpp/Makefile new file +51 -0

51 lines not on this page · raw message

examples/helloworld-cpp/c_code.c new file +5 -0
new file mode 100644
index 0000000..d349a3b
@@ -0,0 +1,5 @@
+#include "c_header.h"
+
+int func(void) {
+	return 100500;
+}
examples/helloworld-cpp/c_header.h new file +6 -0
new file mode 100644
index 0000000..3668b60
@@ -0,0 +1,6 @@
+#ifndef HEADER_H
+#define HEADER_H
+
+int func(void);
+
+#endif
examples/helloworld-cpp/cpp_code.cpp new file +89 -0

89 lines not on this page · raw message

Signature · 1 line
2.5.5
#3 lore raw

RFC 3/4 eal: add command line option to log output to stdout

In reply to Declan Doherty

Adds new command line options which allows the user to stop application echoing log output to stdout, logs are still written to syslog.

---
 lib/librte_eal/common/eal_common_log.c     | 14 ++++++++++++++
 lib/librte_eal/common/eal_common_options.c |  8 ++++++++
 lib/librte_eal/common/eal_options.h        |  2 ++
 lib/librte_eal/common/include/rte_log.h    | 15 +++++++++++++++
 lib/librte_eal/linuxapp/eal/eal.c          |  1 +
 lib/librte_eal/linuxapp/eal/eal_log.c      | 23 ++++++++++++++---------
 6 files changed, 54 insertions(+), 9 deletions(-)
lib/librte_eal/common/eal_common_log.c +14 -0
index 7916c78..8319823 100644
@@ -45,6 +45,7 @@
 struct rte_logs rte_logs = {
 	.type = ~0,
 	.level = RTE_LOG_DEBUG,
+	.silent = 1,
 	.file = NULL,
 };
 
@@ -102,6 +103,18 @@ rte_get_log_level(void)
 	return rte_logs.level;
 }
 
+void
+rte_log_silence_stdout(void)
+{
+	rte_logs.silent = 0;
+}
+
+int
+rte_log_stdout(void)
+{
+	return rte_logs.silent;
+}
+
 /* Set global log type */
 void
 rte_set_log_type(uint32_t type, int enable)
@@ -125,6 +138,7 @@ int rte_log_cur_msg_loglevel(void)
 	return RTE_PER_LCORE(log_cur_msg).loglevel;
 }
 
+
 /* get the current logtype for the message beeing processed */
 int rte_log_cur_msg_logtype(void)
 {
lib/librte_eal/common/eal_common_options.c +8 -0
index 1a1bab3..186cfeb 100644
@@ -69,6 +69,7 @@ eal_short_options[] =
 	"r:" /* memory ranks */
 	"v"  /* version */
 	"w:" /* pci-whitelist */
+	"s"  /* silence log output to stdout */
 	;
 
 const struct option
@@ -95,6 +96,7 @@ eal_long_options[] = {
 	{OPT_VFIO_INTR,         1, NULL, OPT_VFIO_INTR_NUM        },
 	{OPT_VMWARE_TSC_MAP,    0, NULL, OPT_VMWARE_TSC_MAP_NUM   },
 	{OPT_XEN_DOM0,          0, NULL, OPT_XEN_DOM0_NUM         },
+	{OPT_SILENT_STDOUT,     0, NULL, OPT_SILENT_STDOUT_NUM    },
 	{0,                     0, NULL, 0                        }
 };
 
@@ -842,6 +844,10 @@ eal_parse_common_option(int opt, const char *optarg,
 		RTE_LOG(CRIT, EAL, "RTE Version: '%s'\n", rte_version());
 		break;
 
+	case OPT_SILENT_STDOUT_NUM:
+		rte_log_silence_stdout();
+		break;
+
 	/* long options */
 	case OPT_HUGE_UNLINK_NUM:
 		conf->hugepage_unlink = 1;
@@ -906,6 +912,7 @@ eal_parse_common_option(int opt, const char *optarg,
 		conf->log_level = log;
 		break;
 	}
+
 	case OPT_LCORES_NUM:
 		if (eal_parse_lcores(optarg) < 0) {
 			RTE_LOG(ERR, EAL, "invalid parameter for --"
@@ -1028,6 +1035,7 @@ eal_common_usage(void)
 	       "  --"OPT_PROC_TYPE"         Type of this process (primary|secondary|auto)\n"
 	       "  --"OPT_SYSLOG"            Set syslog facility\n"
 	       "  --"OPT_LOG_LEVEL"         Set default log level\n"
+	       "  -s, --"OPT_SILENT_STDOUT" Silent mode, supress output to STDOUT\n"
 	       "  -v                  Display version information on startup\n"
 	       "  -h, --help          This help\n"
 	       "\nEAL options for DEBUG use only:\n"
lib/librte_eal/common/eal_options.h +2 -0
index a881c62..ce6547c 100644
@@ -41,6 +41,8 @@ enum {
 	OPT_PCI_BLACKLIST_NUM   = 'b',
 #define OPT_PCI_WHITELIST     "pci-whitelist"
 	OPT_PCI_WHITELIST_NUM   = 'w',
+#define OPT_SILENT_STDOUT     "log-stdout-silent"
+	OPT_SILENT_STDOUT_NUM   = 's',
 
 	/* first long only option value must be >= 256, so that we won't
 	 * conflict with short options */
lib/librte_eal/common/include/rte_log.h +15 -0
index b1add04..74acb91 100644
@@ -56,6 +56,7 @@ extern "C" {
 struct rte_logs {
 	uint32_t type;  /**< Bitfield with enabled logs. */
 	uint32_t level; /**< Log level. */
+	uint32_t silent:1; /**< Silent mode - Don't print to STDOUT */
 	FILE *file;     /**< Pointer to current FILE* for logs. */
 };
 
@@ -181,6 +182,20 @@ int rte_log_cur_msg_loglevel(void);
 int rte_log_cur_msg_logtype(void);
 
 /**
+ * Silence output to stdout by logging facilities
+ */
+void rte_log_silence_stdout(void);
+
+/**
+ * Check if echoing log output to stdout is enabled.
+ *
+ * @return
+ * - Returns 1 if echoing to stdout is enabled
+ * - Returns 0 if logging is in silent mode
+ */
+int rte_log_stdout(void);
+
+/**
  * @deprecated
  * Enable or disable the history (enabled by default)
  *
lib/librte_eal/linuxapp/eal/eal.c +1 -0
index 3fb2188..8f8ed42 100644
@@ -748,6 +748,7 @@ rte_eal_init(int argc, char **argv)
 
 	thread_id = pthread_self();
 
+
 	if (rte_eal_log_early_init() < 0)
 		rte_panic("Cannot init early logs\n");
 
lib/librte_eal/linuxapp/eal/eal_log.c +14 -9
index d391100..5387e5a 100644
@@ -56,12 +56,14 @@ static ssize_t
 console_log_write(__attribute__((unused)) void *c, const char *buf, size_t size)
 {
 	char copybuf[BUFSIZ + 1];
-	ssize_t ret;
+	ssize_t ret = 0;
 	uint32_t loglevel;
-
+ 
 	/* write on stdout */
-	ret = fwrite(buf, 1, size, stdout);
-	fflush(stdout);
+	if (rte_log_stdout()) {
+		ret = fwrite(buf, 1, size, stdout);
+		fflush(stdout);
+	}
 
 	/* truncate message if too big (should not happen) */
 	if (size > BUFSIZ)
@@ -111,11 +113,14 @@ rte_eal_log_init(const char *id, int facility)
 static ssize_t
 early_log_write(__attribute__((unused)) void *c, const char *buf, size_t size)
 {
-	ssize_t ret;
-	ret = fwrite(buf, size, 1, stdout);
-	fflush(stdout);
-	if (ret == 0)
-		return -1;
+	ssize_t ret = 0;
+
+	if (rte_log_stdout()) {
+		ret = fwrite(buf, size, 1, stdout);
+		fflush(stdout);
+		if (ret == 0)
+			return -1;
+	}
 	return ret;
 }
 
Signature · 1 line
2.5.5
#4 lore raw

Re: [RFC 3/4] eal: add command line option to log output to stdout

Quoted 30 lines · Declan Doherty

Adds new command line options which allows the user to stop application echoing log output to stdout, logs are still written to syslog.

---
 lib/librte_eal/common/eal_common_log.c     | 14 ++++++++++++++
 lib/librte_eal/common/eal_common_options.c |  8 ++++++++
 lib/librte_eal/common/eal_options.h        |  2 ++
 lib/librte_eal/common/include/rte_log.h    | 15 +++++++++++++++
 lib/librte_eal/linuxapp/eal/eal.c          |  1 +
 lib/librte_eal/linuxapp/eal/eal_log.c      | 23 ++++++++++++++---------
 6 files changed, 54 insertions(+), 9 deletions(-)
lib/librte_eal/common/eal_common_log.c +1 -0
index 7916c78..8319823 100644
@@ -45,6 +45,7 @@
 struct rte_logs rte_logs = {
 	.type = ~0,
 	.level = RTE_LOG_DEBUG,
+	.silent = 1,
 	.file = NULL,
 };
 
@@ -102,6 +103,18 @@ rte_get_log_level(void)
 	return rte_logs.level;
 }
 

lib/librte_eal/common/eal_common_log.c rte_get_log_level(void) · line 115

Quoted 10 lines
lib/librte_eal/common/eal_common_log.c +10 -0
+void
+rte_log_silence_stdout(void)
+{
+	rte_logs.silent = 0;
+}
+
+int
+rte_log_stdout(void)
+{
+	return rte_logs.silent;

Maybe you want to return !rte_logs.silent? That way the sense of the actual variable makes human readable sense. i.e. currently rte_logs.silent is set to 1 if you want to print to stdout, which seems backwards

Neil

#5 lore raw

RFC 4/4 app/test-gtest: example google test application

In reply to Declan Doherty

Adds a new application to demonstrate how google test could be used as a new unit test framework.

To compile both ${GTEST_DIR} and ${GMOCK_DIR} the install paths to google test and google mock directories respectively must be defined/exported.

---
 app/Makefile                    |   1 +
 app/test-gtest/Makefile         |  67 ++++++++++
 app/test-gtest/main.cpp         |  20 +++
 app/test-gtest/test_mempool.cpp | 281 ++++++++++++++++++++++++++++++++++++++++
 config/common_base              |   5 +
 5 files changed, 374 insertions(+)
 create mode 100644 app/test-gtest/Makefile
 create mode 100644 app/test-gtest/main.cpp
 create mode 100644 app/test-gtest/test_mempool.cpp
app/Makefile +1 -0
index 30ec292..71cf31e 100644
@@ -38,5 +38,6 @@ DIRS-$(CONFIG_RTE_TEST_PMD) += test-pmd
 DIRS-$(CONFIG_RTE_LIBRTE_CMDLINE) += cmdline_test
 DIRS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += proc_info
 DIRS-$(CONFIG_RTE_LIBRTE_PDUMP) += pdump
+DIRS-$(CONFIG_RTE_TEST_GTEST) += test-gtest
 
 include $(RTE_SDK)/mk/rte.subdir.mk
app/test-gtest/Makefile new file +67 -0

67 lines not on this page · raw message

app/test-gtest/main.cpp new file +20 -0
new file mode 100644
index 0000000..a221823
@@ -0,0 +1,20 @@
+#include <gtest/gtest.h>
+#include <gmock/gmock.h>
+
+#include <stdio.h>
+
+#include <rte_common.h>
+#include <rte_eal.h>
+
+int main(int argc, char *argv[])
+{
+	/* Initialise DPDK EAL */
+	int ret = rte_eal_init(argc, argv);
+	if (ret < 0)
+		rte_exit(EXIT_FAILURE, "Invalid EAL arguments\n");
+	argc -= ret;
+	argv += ret;
+
+	testing::InitGoogleMock(&argc, argv);
+	return RUN_ALL_TESTS();
+}	
app/test-gtest/test_mempool.cpp new file +281 -0

281 lines not on this page · raw message

config/common_base +5 -0
index 7830535..6ef4de6 100644
@@ -579,6 +579,11 @@ CONFIG_RTE_APP_TEST=y
 CONFIG_RTE_APP_TEST_RESOURCE_TAR=n
 
 #
+# Compile the google test unit tests
+#
+CONFIG_RTE_TEST_GTEST=y
+
+#
 # Compile the PMD test application
 #
 CONFIG_RTE_TEST_PMD=y
Signature · 1 line
2.5.5
#6 lore raw
In reply to Declan Doherty

2016-08-02 21:37, Declan Doherty:

Quoted 3 lines

I've been trying out using google test as a possible replacement for our unit test framework and have put to together this series of patches with help from Anatoly as RFC to get peoples thoughts on migrating to google test.

Thanks for exploring new possibilities.

Quoted 4 lines

To facilitate google test this rfc patch set contains build system changes to allow C++ to built within the DPDK framework, this intended for unit test code only, and to support google test which is a C++ framework. Don't worry, I'm not advocating making DPDK a C++ project :)

You are not advocating but the unit test must be written in C++.
I don't think it is a good idea to force people to write and maintain the tests in a different language than the code it tests.

Quoted 6 lines

Some of the major advantages of google test that I see over continuing to use the current test include giving a consist feel to all tests, a powerful test execution framework which allow individual test suites or tests to be specified from the command line, support for a standard xunit output which can be integrated into a continuous build systems, and a very powerful mocking library which allows much more control over testing failure conditions.

It would be interesting to better describe in details what is missing currently and what such a framework can bring.
(I agree there is a huge room for improvements on unit tests)

#7 lore raw
Quoted 1 line · Thomas Monjalon

2016-08-02 21:37, Declan Doherty:

[..]

Quoted 3 lines

You are not advocating but the unit test must be written in C++.
I don't think it is a good idea to force people to write and maintain the tests in a different language than the code it tests.

In principle I agree, but in practice I don't see any alternative. All the purely C-based frameworks I've (independently of Declan) tried don't have the same flexibility as the C++ ones.

Quoted 3 lines

It would be interesting to better describe in details what is missing currently and what such a framework can bring.
(I agree there is a huge room for improvements on unit tests)

From my own perspective, mocking of functions is the main thing that is missing. When testing KeepAlive this allowed me to reroute rte_malloc() calls to the OS malloc() rather than having to startup/teardown the hugepage subsystem.

..Remy

#8 lore raw
In reply to Thomas Monjalon
Quoted 3 lines

-----Original Message-----

...

Quoted 3 lines

You are not advocating but the unit test must be written in C++.
I don't think it is a good idea to force people to write and maintain the tests in a different language than the code it tests.

I know where you are coming from on this point, and I general would agree if
it were not for the advantages you get from C++ test framework. Having worked with multiple C and C++ frameworks, I've found that one of the biggest advantages of the C++ frameworks is the amount of boilerplate code they can save you from writing. Also nearly all of C frameworks I've used make use macros to the point that they look more like objective C than C. In general I feel that even if the test code is written in C++ the code itself should be simple enough that someone with even a passing knowledge of C++ could easily understand the intent of the test code.

Quoted 5 lines
Quoted 1 line

Some of the major advantages of google test that I see over continuing to use

the

Quoted 3 lines

current test include giving a consist feel to all tests, a powerful test execution framework which allow individual test suites or tests to be specified from the command line, support for a standard xunit output which can be

Quoted 7 lines

integrated

Quoted 2 lines

into a continuous build systems, and a very powerful mocking library which allows much more control over testing failure conditions.

It would be interesting to better describe in details what is missing currently and what such a framework can bring.
(I agree there is a huge room for improvements on unit tests)

Some of the things I've come across include:
No standard output format to integrated with continuous regression systems No ability to specify specific unit tests or groups of tests to run from the command line No standard set of test assertions used across the test suites.
No standard setup and teardown functions across test suites, state from previous test suite can break current
Requirement to use a python script to orchestrate test runs.
No support for mocking functionality.

I know that none of the above couldn't be fixed in our current test application, but I would question if it is effort worthwhile when we take an off the shelf framework, which does all those things and a whole lot more, which has been test and used in a huge variety of projects.

I certainly willing to look at other frameworks both C and C++ but I yet to find a C framework which come close to the usability and flexibility of the popular C++ ones.

#9 lore raw
Quoted 30 lines · Declan
Quoted 3 lines

-----Original Message-----

...

Quoted 3 lines

You are not advocating but the unit test must be written in C++.
I don't think it is a good idea to force people to write and maintain the tests in a different language than the code it tests.

I know where you are coming from on this point, and I general would agree if
it were not for the advantages you get from C++ test framework. Having worked with multiple C and C++ frameworks, I've found that one of the biggest advantages of the C++ frameworks is the amount of boilerplate code they can save you from writing. Also nearly all of C frameworks I've used make use macros to the point that they look more like objective C than C. In general I feel that even if the test code is written in C++ the code itself should be simple enough that someone with even a passing knowledge of C++ could easily understand the intent of the test code.

Quoted 5 lines
Quoted 1 line

Some of the major advantages of google test that I see over continuing to use

the

Quoted 3 lines

current test include giving a consist feel to all tests, a powerful test execution framework which allow individual test suites or tests to be specified from the command line, support for a standard xunit output which can be

Quoted 7 lines

integrated

Quoted 2 lines

into a continuous build systems, and a very powerful mocking library which allows much more control over testing failure conditions.

It would be interesting to better describe in details what is missing currently and what such a framework can bring.
(I agree there is a huge room for improvements on unit tests)

Quoted 9 lines

Some of the things I've come across include:
No standard output format to integrated with continuous regression systems No ability to specify specific unit tests or groups of tests to run from the command line No standard set of test assertions used across the test suites.
No standard setup and teardown functions across test suites, state from previous test suite can break current
Requirement to use a python script to orchestrate test runs.
No support for mocking functionality.

I think libcheck:
https://libcheck.github.io/check/

Ticks most of those boxes, or can have the missing functionality added fairly easily.

Quoted 11 lines

I know that none of the above couldn't be fixed in our current test application, but I would question if it is effort worthwhile when we take an off the shelf framework, which does all those things and a whole lot more, which has been test and used in a huge variety of projects.

I certainly willing to look at other frameworks both C and C++ but I yet to find a C framework which come close to the usability and flexibility of the popular C++ ones.

#10 lore raw
In reply to Doherty, Declan

googletest is a very nice test framework and we use it very extensively in our company(Luminate Wireless), together with gmock.

I understand the resistance from the maintainers that are concerned about introducing a C++ dependency to a pure C code base. The approach we take doesn't require any change to the dpdk core, instead we just use things like a mock PMD(through gmock framework) to allow mocking the RX/TX code path, disabling huge page usage in test so that the test can be easily launched without worrying about huge page collision, etc.

Personally I highly recommend using googletest plus some basic test cases, which removes a lot of boilerplate and let the developers focus the test itself.

Quoted 49 lines · Declan
Quoted 3 lines

-----Original Message-----

...

Quoted 3 lines

You are not advocating but the unit test must be written in C++.
I don't think it is a good idea to force people to write and maintain the tests in a different language than the code it tests.

I know where you are coming from on this point, and I general would agree if
it were not for the advantages you get from C++ test framework. Having worked with multiple C and C++ frameworks, I've found that one of the biggest advantages of the C++ frameworks is the amount of boilerplate code they can save you from writing. Also nearly all of C frameworks I've used make use macros to the point that they look more like objective C than C. In general I feel that even if the test code is written in C++ the code itself should be simple enough that someone with even a passing knowledge of C++ could easily understand the intent of the test code.

Quoted 5 lines
Quoted 1 line

Some of the major advantages of google test that I see over continuing to use

the

Quoted 3 lines

current test include giving a consist feel to all tests, a powerful test execution framework which allow individual test suites or tests to be specified from the command line, support for a standard xunit output which can be

Quoted 7 lines

integrated

Quoted 2 lines

into a continuous build systems, and a very powerful mocking library which allows much more control over testing failure conditions.

It would be interesting to better describe in details what is missing currently and what such a framework can bring.
(I agree there is a huge room for improvements on unit tests)

Some of the things I've come across include:
No standard output format to integrated with continuous regression systems No ability to specify specific unit tests or groups of tests to run from the command line No standard set of test assertions used across the test suites.
No standard setup and teardown functions across test suites, state from previous test suite can break current
Requirement to use a python script to orchestrate test runs.
No support for mocking functionality.

I know that none of the above couldn't be fixed in our current test application, but I would question if it is effort worthwhile when we take an off the shelf framework, which does all those things and a whole lot more, which has been test and used in a huge variety of projects.

I certainly willing to look at other frameworks both C and C++ but I yet to find a C framework which come close to the usability and flexibility of the popular C++ ones.

#11 lore raw

Hi,

We are looking at using our existing test environment for our DPDK applications that will run on our build servers. Hughpages therefore is an issue. What is involved in running DPDK without hugepages?

Thanks,

Jim

Quoted 88 lines · Ming Zhao(赵明)

googletest is a very nice test framework and we use it very extensively in our company(Luminate Wireless), together with gmock.

I understand the resistance from the maintainers that are concerned about introducing a C++ dependency to a pure C code base. The approach we take doesn't require any change to the dpdk core, instead we just use things like a mock PMD(through gmock framework) to allow mocking the RX/TX code path, disabling huge page usage in test so that the test can be easily launched without worrying about huge page collision, etc.

Personally I highly recommend using googletest plus some basic test cases, which removes a lot of boilerplate and let the developers focus the test itself.

Quoted 6 lines · Declan
Quoted 3 lines

-----Original Message-----

...

Quoted 2 lines

You are not advocating but the unit test must be written in C++. I don't think it is a good idea to force people to write and maintain

the tests

Quoted 3 lines
Quoted 1 line

in a different language than the code it tests.

I know where you are coming from on this point, and I general would

agree if

Quoted 1 line

it were not for the advantages you get from C++ test framework. Having

worked with

Quoted 1 line

multiple C and C++ frameworks, I've found that one of the biggest

advantages of the

Quoted 1 line

C++ frameworks is the amount of boilerplate code they can save you from

writing. Also

Quoted 1 line

nearly all of C frameworks I've used make use macros to the point that

they look more like

Quoted 1 line

objective C than C. In general I feel that even if the test code is

written in C++ the code itself

Quoted 1 line

should be simple enough that someone with even a passing knowledge of

C++ could easily

Quoted 3 lines

understand the intent of the test code.

Quoted 1 line
Quoted 1 line

Some of the major advantages of google test that I see over

continuing to use

Quoted 2 lines
Quoted 2 lines

the

Quoted 1 line

current test include giving a consist feel to all tests, a powerful

test

Quoted 1 line
Quoted 1 line
Quoted 1 line

execution framework which allow individual test suites or tests to be

specified

Quoted 1 line
Quoted 1 line
Quoted 1 line

from the command line, support for a standard xunit output which can

be

Quoted 5 lines
Quoted 5 lines

integrated

Quoted 2 lines

into a continuous build systems, and a very powerful mocking library which allows much more control over testing failure conditions.

It would be interesting to better describe in details what is missing

currently

Quoted 5 lines
Quoted 2 lines

and what such a framework can bring.
(I agree there is a huge room for improvements on unit tests)

Some of the things I've come across include:
No standard output format to integrated with continuous regression

systems

Quoted 1 line

No ability to specify specific unit tests or groups of tests to run from

the command line

Quoted 2 lines

No standard set of test assertions used across the test suites. No standard setup and teardown functions across test suites, state from

previous test

Quoted 5 lines

suite can break current
Requirement to use a python script to orchestrate test runs. No support for mocking functionality.

I know that none of the above couldn't be fixed in our current test

application, but I would

Quoted 1 line

question if it is effort worthwhile when we take an off the shelf

framework, which does all

Quoted 1 line

those things and a whole lot more, which has been test and used in a

huge variety of

Quoted 3 lines

projects.

I certainly willing to look at other frameworks both C and C++ but I yet

to find a C framework

Quoted 1 line

which come close to the usability and flexibility of the popular C++

ones.

Quoted 3 lines
#12 lore raw
Quoted 8 lines · Jim Murphy

Hi,

We are looking at using our existing test environment for our DPDK applications that will run on our build servers. Hughpages therefore is an issue. What is involved in running DPDK without huge pages?

Command line option —no-huge should work. Note two dashs in front.

Quoted 97 lines

Thanks,

Jim

Quoted 88 lines · Ming Zhao(赵明)

googletest is a very nice test framework and we use it very extensively in our company(Luminate Wireless), together with gmock.

I understand the resistance from the maintainers that are concerned about introducing a C++ dependency to a pure C code base. The approach we take doesn't require any change to the dpdk core, instead we just use things like a mock PMD(through gmock framework) to allow mocking the RX/TX code path, disabling huge page usage in test so that the test can be easily launched without worrying about huge page collision, etc.

Personally I highly recommend using googletest plus some basic test cases, which removes a lot of boilerplate and let the developers focus the test itself.

Quoted 6 lines · Declan
Quoted 3 lines

-----Original Message-----

...

Quoted 2 lines

You are not advocating but the unit test must be written in C++. I don't think it is a good idea to force people to write and maintain

the tests

Quoted 3 lines
Quoted 1 line

in a different language than the code it tests.

I know where you are coming from on this point, and I general would

agree if

Quoted 1 line

it were not for the advantages you get from C++ test framework. Having

worked with

Quoted 1 line

multiple C and C++ frameworks, I've found that one of the biggest

advantages of the

Quoted 1 line

C++ frameworks is the amount of boilerplate code they can save you from

writing. Also

Quoted 1 line

nearly all of C frameworks I've used make use macros to the point that

they look more like

Quoted 1 line

objective C than C. In general I feel that even if the test code is

written in C++ the code itself

Quoted 1 line

should be simple enough that someone with even a passing knowledge of

C++ could easily

Quoted 3 lines

understand the intent of the test code.

Quoted 1 line
Quoted 1 line

Some of the major advantages of google test that I see over

continuing to use

Quoted 2 lines
Quoted 2 lines

the

Quoted 1 line

current test include giving a consist feel to all tests, a powerful

test

Quoted 1 line
Quoted 1 line
Quoted 1 line

execution framework which allow individual test suites or tests to be

specified

Quoted 1 line
Quoted 1 line
Quoted 1 line

from the command line, support for a standard xunit output which can

be

Quoted 5 lines
Quoted 5 lines

integrated

Quoted 2 lines

into a continuous build systems, and a very powerful mocking library which allows much more control over testing failure conditions.

It would be interesting to better describe in details what is missing

currently

Quoted 5 lines
Quoted 2 lines

and what such a framework can bring.
(I agree there is a huge room for improvements on unit tests)

Some of the things I've come across include:
No standard output format to integrated with continuous regression

systems

Quoted 1 line

No ability to specify specific unit tests or groups of tests to run from

the command line

Quoted 2 lines

No standard set of test assertions used across the test suites. No standard setup and teardown functions across test suites, state from

previous test

Quoted 5 lines

suite can break current
Requirement to use a python script to orchestrate test runs. No support for mocking functionality.

I know that none of the above couldn't be fixed in our current test

application, but I would

Quoted 1 line

question if it is effort worthwhile when we take an off the shelf

framework, which does all

Quoted 1 line

those things and a whole lot more, which has been test and used in a

huge variety of

Quoted 3 lines

projects.

I certainly willing to look at other frameworks both C and C++ but I yet

to find a C framework

Quoted 1 line

which come close to the usability and flexibility of the popular C++

ones.

Quoted 3 lines
#13 lore raw

2016-08-04 19:55, Wiles, Keith:

Quoted 10 lines
Quoted 8 lines · Jim Murphy

Hi,

We are looking at using our existing test environment for our DPDK applications that will run on our build servers. Hughpages therefore is an issue. What is involved in running DPDK without huge pages?

Command line option —no-huge should work. Note two dashs in front.

Most of drivers still require hugepages.
A big rework would be needed to make them work without hugepages.

#14 lore raw
In reply to Doherty, Declan
Quoted 9 lines · Declan

Some of the things I've come across include:
No standard output format to integrated with continuous regression systems No ability to specify specific unit tests or groups of tests to run from the command line No standard set of test assertions used across the test suites.
No standard setup and teardown functions across test suites, state from previous test suite can break current
Requirement to use a python script to orchestrate test runs.
No support for mocking functionality.

Quoted 7 lines

I know that none of the above couldn't be fixed in our current test application, but I would question if it is effort worthwhile when we take an off the shelf framework, which does all those things and a whole lot more, which has been test and used in a huge variety of projects.

I certainly willing to look at other frameworks both C and C++ but I yet to find a C framework which come close to the usability and flexibility of the popular C++ ones.

We use cmocka.org for tests. Written in C. It has support for:
* mocking;
* setup/teardown;
* asserts;
* test groups.

Output is nicely formatted.

#15 lore raw

On 05/08/2016 08:41, Yerden Zhumabekov wrote:
[..]

Quoted 7 lines

We use cmocka.org for tests. Written in C. It has support for:
* mocking;
* setup/teardown;
* asserts;
* test groups.

Output is nicely formatted.

Cmocka's mocking relies on Gnu ld's --wrap feature, which has problems if the function being mocked is defined in the same compilation unit that it is used. Pity really as otherwise it looked quite good to me.

..Remy

#16 lore raw
Quoted 9 lines · Remy Horton

On 05/08/2016 08:41, Yerden Zhumabekov wrote:
[..]

Quoted 6 lines

We use cmocka.org for tests. Written in C. It has support for:
* mocking;
* setup/teardown;
* asserts;
* test groups.

Quoted 6 lines
Quoted 1 line

Output is nicely formatted.

Cmocka's mocking relies on Gnu ld's --wrap feature, which has problems if the function being mocked is defined in the same compilation unit that it is used. Pity really as otherwise it looked quite good to me.

Can't you use ld's --undefined option to get the correct behavior? I thought that was specifically what it was there for.

Neil

Quoted 2 lines

..Remy

#17 lore raw
Quoted 1 line · Neil Horman

On Fri, Aug 05, 2016 at 10:11:56AM +0100, Remy Horton wrote:

[..]

Quoted 6 lines
Quoted 4 lines

Cmocka's mocking relies on Gnu ld's --wrap feature, which has problems if the function being mocked is defined in the same compilation unit that it is used. Pity really as otherwise it looked quite good to me.

Can't you use ld's --undefined option to get the correct behavior? I thought that was specifically what it was there for.

Not sure - I'll try playing around with it when I next have some spare time.. :)

The C-Mock extension (https://github.com/hjagodzinski/C-Mock) for GMock uses some dynamic linker trickery which I'm guessing is probably not C++ specific, and I quite like that approach as it avoids the need to pre-specify in makefiles which functions are to be mocked.

..Remy

#18 lore raw
In reply to Thomas Monjalon
Quoted 7 lines · Thomas Monjalon

2016-08-02 21:37, Declan Doherty:

Quoted 3 lines

I've been trying out using google test as a possible replacement for our unit test framework and have put to together this series of patches with help from Anatoly as RFC to get peoples thoughts on migrating to google test.

Thanks for exploring new possibilities.

Quoted 9 lines
Quoted 4 lines

To facilitate google test this rfc patch set contains build system changes to allow C++ to built within the DPDK framework, this intended for unit test code only, and to support google test which is a C++ framework. Don't worry, I'm not advocating making DPDK a C++ project :)

You are not advocating but the unit test must be written in C++.
I don't think it is a good idea to force people to write and maintain the tests in a different language than the code it tests.

I agree, there are lots of xunit based integration tests that are available as pure C frameworks. Jenkins might also be a good candidate here.

Quoted 11 lines
Quoted 6 lines

Some of the major advantages of google test that I see over continuing to use the current test include giving a consist feel to all tests, a powerful test execution framework which allow individual test suites or tests to be specified from the command line, support for a standard xunit output which can be integrated into a continuous build systems, and a very powerful mocking library which allows much more control over testing failure conditions.

It would be interesting to better describe in details what is missing currently and what such a framework can bring.
(I agree there is a huge room for improvements on unit tests)

I agree that a test framework gives a consistent look and feel to all tests, but it seems to me that would be the case with any framework worth its salt. While I'm not opposed to google test per-se, the fact that it requires C++ to build makes me wonder if there isn't a better option available.

Neil