[ovs-dev] [ovs-assert 4/4] Makefile.am: add check that <assert.h> is not used from unexpected files.

Ethan Jackson ethan at nicira.com
Tue Jan 15 19:27:58 UTC 2013


Acked-by: Ethan Jackson <ethan at nicira.com>

On Wed, Nov 7, 2012 at 10:48 AM, Ben Pfaff <blp at nicira.com> wrote:
> In general, with a few specific exceptions, ovs_assert is now preferred
> over assert, so this commit adds a check for that in the top-level
> Makefile.
>
> Signed-off-by: Ben Pfaff <blp at nicira.com>
> ---
>  Makefile.am  |   13 +++++++++++++
>  configure.ac |    1 +
>  lib/vlog.c   |    5 +++++
>  lib/worker.c |    5 +++++
>  4 files changed, 24 insertions(+), 0 deletions(-)
>
> diff --git a/Makefile.am b/Makefile.am
> index b71ca1f..56fe3bb 100644
> --- a/Makefile.am
> +++ b/Makefile.am
> @@ -180,6 +180,19 @@ rate-limit-check:
>          fi
>  .PHONY: rate-limit-check
>
> +# Check that assert.h is not used outside a whitelist of files.
> +ALL_LOCAL += check-assert-h-usage
> +check-assert-h-usage:
> +       @if test -e $(srcdir)/.git && (git --version) >/dev/null 2>&1 && \
> +           (cd $(srcdir) && git --no-pager grep -l -E '[<]assert.h[>]') | \
> +           $(EGREP) -v '^lib/(sflow_receiver|vlog|worker).c$$|^tests/'; \
> +         then \
> +           echo "Files listed above unexpectedly #include <""assert.h"">."; \
> +           echo "Please use ovs_assert (from util.h) instead of assert."; \
> +           exit 1; \
> +        fi
> +.PHONY: check-assert-h-usage
> +
>  if HAVE_GROFF
>  ALL_LOCAL += manpage-check
>  manpage-check: $(man_MANS) $(dist_man_MANS) $(noinst_man_MANS)
> diff --git a/configure.ac b/configure.ac
> index 32940a5..b85cf06 100644
> --- a/configure.ac
> +++ b/configure.ac
> @@ -27,6 +27,7 @@ AC_PROG_CPP
>  AC_PROG_RANLIB
>  AC_PROG_MKDIR_P
>  AC_PROG_FGREP
> +AC_PROG_EGREP
>
>  AC_ARG_VAR([PERL], [path to Perl interpreter])
>  AC_PATH_PROG([PERL], perl, no)
> diff --git a/lib/vlog.c b/lib/vlog.c
> index 0bd9bd1..600c4b6 100644
> --- a/lib/vlog.c
> +++ b/lib/vlog.c
> @@ -40,6 +40,11 @@
>
>  VLOG_DEFINE_THIS_MODULE(vlog);
>
> +/* ovs_assert() logs the assertion message, so using ovs_assert() in this
> + * source file could cause recursion. */
> +#undef ovs_assert
> +#define ovs_assert use_assert_instead_of_ovs_assert_in_this_module
> +
>  /* Name for each logging level. */
>  static const char *level_names[VLL_N_LEVELS] = {
>  #define VLOG_LEVEL(NAME, SYSLOG_LEVEL) #NAME,
> diff --git a/lib/worker.c b/lib/worker.c
> index f2b896e..58ee85b 100644
> --- a/lib/worker.c
> +++ b/lib/worker.c
> @@ -37,6 +37,11 @@
>
>  VLOG_DEFINE_THIS_MODULE(worker);
>
> +/* ovs_assert() logs the assertion message and logging sometimes goes through a
> + * worker, so using ovs_assert() in this source file could cause recursion. */
> +#undef ovs_assert
> +#define ovs_assert use_assert_instead_of_ovs_assert_in_this_module
> +
>  /* Header for an RPC request. */
>  struct worker_request {
>      size_t request_len;              /* Length of the payload in bytes. */
> --
> 1.7.2.5
>
> _______________________________________________
> dev mailing list
> dev at openvswitch.org
> http://openvswitch.org/mailman/listinfo/dev



More information about the dev mailing list