summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile.am20
-rwxr-xr-xconfigure.ac16
-rw-r--r--doc/user/installation.rst9
-rw-r--r--docker/alpine/Dockerfile-coverage12
-rw-r--r--lib/if.c12
-rw-r--r--zebra/rt_netlink.c9
-rw-r--r--zebra/zapi_msg.c4
-rw-r--r--zebra/zebra_mpls.c12
-rw-r--r--zebra/zserv.c4
9 files changed, 76 insertions, 22 deletions
diff --git a/Makefile.am b/Makefile.am
index 5dc80b4983..ed22c60e7c 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -115,3 +115,23 @@ noinst_HEADERS += defaults.h
indent:
tools/indent.py `find sharpd bgpd eigrpd include isisd lib nhrpd ospf6d ospfd pimd qpb ripd vtysh zebra -name '*.[ch]' | grep -v include/linux`
+
+if HAVE_GCOV
+
+coverage: check
+ @ find . -name '*.o' -exec gcov {} \;
+
+yorn:
+ @ echo "OK to upload coverage to https://coverage.io [y/N]:"
+ @ read yn; test "$$yn" = "y"
+
+upload-check-coverage:
+ @ if [ "x${COMMIT}" = "x" ]; then echo "COMMIT required"; exit 1; fi
+ @ if [ "x${TOKEN}" = "x" ]; then echo "TOKEN required"; exit 1; fi
+ curl -s https://codecov.io/bash | bash -s - -C ${COMMIT} -t ${TOKEN}
+
+force-check-coverage: coverage upload-check-coverage
+
+check-coverage: coverage yorn upload-check-coverage
+
+endif
diff --git a/configure.ac b/configure.ac
index 3ec29cc38f..8846fcdf71 100755
--- a/configure.ac
+++ b/configure.ac
@@ -226,7 +226,14 @@ AC_ARG_ENABLE([memory-sanitizer], AS_HELP_STRING([--enable-memory-sanitizer], \
])
dnl if the user has specified any CFLAGS, override our settings
-if test "x${enable_dev_build}" = "xyes"; then
+if test "x${enable_gcov}" = "xyes"; then
+ if test "z$orig_cflags" = "z"; then
+ AC_C_FLAG([-coverage])
+ AC_C_FLAG([-O0])
+ fi
+
+ LDFLAGS="${LDFLAGS} -lgcov"
+elif test "x${enable_dev_build}" = "xyes"; then
AC_DEFINE(DEV_BUILD,,Build for development)
if test "z$orig_cflags" = "z"; then
AC_C_FLAG([-g3])
@@ -441,6 +448,8 @@ AC_ARG_ENABLE([clippy-only],
AS_HELP_STRING([--enable-clippy-only], [Only build clippy]))
AC_ARG_ENABLE([numeric_version],
AS_HELP_STRING([--enable-numeric-version], [Only numeric digits allowed in version (for Alpine)]))
+AC_ARG_ENABLE([gcov],
+ AS_HELP_STRING([--enable-gcov], [Add code coverage information]))
AS_IF([test "${enable_clippy_only}" != "yes"], [
AC_CHECK_HEADERS(json-c/json.h)
@@ -692,6 +701,11 @@ AC_DEFINE_UNQUOTED(MULTIPATH_NUM, $MPATH_NUM, Maximum number of paths for a rout
AC_DEFINE_UNQUOTED(VTYSH_PAGER, "$VTYSH_PAGER", [What pager to use])
+dnl --------------------
+dnl Enable code coverage
+dnl --------------------
+AM_CONDITIONAL([HAVE_GCOV],[test '!' "$enable_gcov" = no])
+
dnl ------------------------------------
dnl Alpine only accepts numeric versions
dnl ------------------------------------
diff --git a/doc/user/installation.rst b/doc/user/installation.rst
index 26d30f1e10..158e2c8595 100644
--- a/doc/user/installation.rst
+++ b/doc/user/installation.rst
@@ -205,6 +205,15 @@ options from the list below.
hardcoded arrays that FRR builds towards, so we need to know how big to
make these arrays at build time.
+.. option:: --enable-gcov
+
+ Code coverage reports from gcov require adjustments to the C and LD flags.
+ With this option, gcov instrumentation is added to the build and coverage
+ reports are created during execution. The check-coverage make target is
+ also created to ease report uploading to codecov.io. The upload requires
+ the COMMIT (git hash) and TOKEN (codecov upload token) environment variables
+ be set.
+
You may specify any combination of the above options to the configure
script. By default, the executables are placed in :file:`/usr/local/sbin`
and the configuration files in :file:`/usr/local/etc`. The :file:`/usr/local/`
diff --git a/docker/alpine/Dockerfile-coverage b/docker/alpine/Dockerfile-coverage
new file mode 100644
index 0000000000..5fdb1179b0
--- /dev/null
+++ b/docker/alpine/Dockerfile-coverage
@@ -0,0 +1,12 @@
+FROM alpine:3.7
+ARG commit
+ARG token
+ENV COMMIT=${commit}
+ENV TOKEN=${token}
+ADD . /src
+RUN cd /src && \
+ source alpine/APKBUILD.in && \
+ apk add --no-cache alpine-sdk $makedepends $checkdepends && \
+ ./bootstrap.sh && \
+ ./configure --enable-gcov
+ENTRYPOINT [ "/bin/sh", "-c", "cd /src && make && make -j 1 check-coverage" ]
diff --git a/lib/if.c b/lib/if.c
index 2541e6e45a..2320093a15 100644
--- a/lib/if.c
+++ b/lib/if.c
@@ -222,18 +222,6 @@ struct interface *if_lookup_by_index(ifindex_t ifindex, vrf_id_t vrf_id)
struct vrf *vrf;
struct interface if_tmp;
- if (vrf_id == VRF_UNKNOWN) {
- struct interface *ifp;
-
- RB_FOREACH (vrf, vrf_id_head, &vrfs_by_id) {
- ifp = if_lookup_by_index(ifindex, vrf->vrf_id);
- if (ifp)
- return ifp;
- }
-
- return NULL;
- }
-
vrf = vrf_lookup_by_id(vrf_id);
if (!vrf)
return NULL;
diff --git a/zebra/rt_netlink.c b/zebra/rt_netlink.c
index 06211d5a43..485abc3f12 100644
--- a/zebra/rt_netlink.c
+++ b/zebra/rt_netlink.c
@@ -483,7 +483,9 @@ static int netlink_route_change_read_unicast(struct nlmsghdr *h, ns_id_t ns_id,
memcpy(&nh.gate, gate, sz);
if (index) {
- ifp = if_lookup_by_index(index, VRF_UNKNOWN);
+ ifp = if_lookup_by_index_per_ns(
+ zebra_ns_lookup(ns_id),
+ index);
if (ifp)
nh_vrf_id = ifp->vrf_id;
}
@@ -526,8 +528,9 @@ static int netlink_route_change_read_unicast(struct nlmsghdr *h, ns_id_t ns_id,
* using the last one looked
* up right now
*/
- ifp = if_lookup_by_index(index,
- VRF_UNKNOWN);
+ ifp = if_lookup_by_index_per_ns(
+ zebra_ns_lookup(ns_id),
+ index);
if (ifp)
nh_vrf_id = ifp->vrf_id;
else {
diff --git a/zebra/zapi_msg.c b/zebra/zapi_msg.c
index dcccb3e321..c16fa70857 100644
--- a/zebra/zapi_msg.c
+++ b/zebra/zapi_msg.c
@@ -2834,7 +2834,9 @@ static inline void zread_rule(ZAPI_HANDLER_ARGS)
STREAM_GETL(s, ifindex);
if (ifindex) {
- zpr.ifp = if_lookup_by_index(ifindex, VRF_UNKNOWN);
+ zpr.ifp = if_lookup_by_index_per_ns(
+ zvrf->zns,
+ ifindex);
if (!zpr.ifp) {
zlog_debug("Failed to lookup ifindex: %u",
ifindex);
diff --git a/zebra/zebra_mpls.c b/zebra/zebra_mpls.c
index fe0837a63a..cfe208d35b 100644
--- a/zebra/zebra_mpls.c
+++ b/zebra/zebra_mpls.c
@@ -38,6 +38,7 @@
#include "zebra/rib.h"
#include "zebra/rt.h"
+#include "zebra/interface.h"
#include "zebra/zserv.h"
#include "zebra/redistribute.h"
#include "zebra/debug.h"
@@ -704,6 +705,7 @@ static int nhlfe_nexthop_active(zebra_nhlfe_t *nhlfe)
{
struct nexthop *nexthop;
struct interface *ifp;
+ struct zebra_ns *zns;
nexthop = nhlfe->nexthop;
if (!nexthop) // unexpected
@@ -721,7 +723,8 @@ static int nhlfe_nexthop_active(zebra_nhlfe_t *nhlfe)
* which will not be in the default
* VRF. So let's look in all of them
*/
- ifp = if_lookup_by_index(nexthop->ifindex, VRF_UNKNOWN);
+ zns = zebra_ns_lookup(NS_DEFAULT);
+ ifp = if_lookup_by_index_per_ns(zns, nexthop->ifindex);
if (ifp && if_is_operative(ifp))
SET_FLAG(nexthop->flags, NEXTHOP_FLAG_ACTIVE);
else
@@ -2752,10 +2755,13 @@ void zebra_mpls_print_lsp_table(struct vty *vty, struct zebra_vrf *zvrf,
switch (nexthop->type) {
case NEXTHOP_TYPE_IFINDEX: {
+ struct zebra_ns *zns;
struct interface *ifp;
- ifp = if_lookup_by_index(
- nexthop->ifindex, VRF_UNKNOWN);
+ zns = zebra_ns_lookup(NS_DEFAULT);
+ ifp = if_lookup_by_index_per_ns(
+ zns,
+ nexthop->ifindex);
vty_out(vty, "%15s", ifp->name);
break;
}
diff --git a/zebra/zserv.c b/zebra/zserv.c
index 434a1507ae..b08da9cebd 100644
--- a/zebra/zserv.c
+++ b/zebra/zserv.c
@@ -69,7 +69,7 @@ extern struct zebra_privs_t zserv_privs;
* Client thread events.
*
* These are used almost exclusively by client threads to drive their own event
- * loops. The only exception is in zebra_client_create(), which pushes an
+ * loops. The only exception is in zserv_client_create(), which pushes an
* initial ZSERV_CLIENT_READ event to start the API handler loop.
*/
enum zserv_client_event {
@@ -1025,7 +1025,7 @@ void zserv_read_file(char *input)
struct zserv *client = NULL;
struct thread t;
- zebra_client_create(-1);
+ zserv_client_create(-1);
frr_pthread_stop(client->pthread, NULL);
frr_pthread_destroy(client->pthread);