linux-arch.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jiri Slaby <jirislaby@gmail.com>
To: David Howells <dhowells@redhat.com>
Cc: linux-arch@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH 2/7] Add assertion checking macros
Date: Wed, 12 Oct 2011 19:43:19 +0200	[thread overview]
Message-ID: <4E95D1B7.4050603@gmail.com> (raw)
In-Reply-To: <20111012164728.539.29820.stgit@warthog.procyon.org.uk>

On 10/12/2011 06:47 PM, David Howells wrote:
> Add a range of ASSERT* macros to linux/assert.h for performing runtime
> assertions.  These will use assertion_failure() to cause an annotated oops if
> the check fails.
> 
> The checks are only enabled under two circumstances:
> 
>  (1) CONFIG_DEBUG_ENABLE_ASSERTIONS=y
> 
>  (2) ENABLE_ASSERTIONS is defined prior to the #inclusion of <linux/assert.h>
> 
> There are five macros provided:
> 
>  (a) ASSERT(X)
> 
>      Issue an assertion failure error if X is false.  In other words, require
>      the expression X to be true.  For example:
> 
> 	ASSERT(val != 0);
> 
>      There is no need to display val here in the case the expression fails
>      since it can only be 0.  If this fails, it produces an error like the
>      following:
> 
> 	------------[ cut here ]------------
> 	ASSERTION FAILED at fs/fscache/main.c:109!
> 	invalid opcode: 0000 [#1] SMP
> 
>  (b) ASSERTCMP(X, OP, Y)
> 
>      Issue an assertion failure error if the expression X OP Y is false.  For
>      example:
> 
> 	ASSERTCMP(x, >, 12)
> 
> 
>      If an oops is produced, then the values of X and Y will be displayed in
>      hex, along with OP:
> 
> 	------------[ cut here ]------------
> 	ASSERTION FAILED at fs/fscache/main.c:109!
> 	Check 2 > c is false
> 	invalid opcode: 0000 [#1] SMP
> 
>  (c) ASSERTRANGE(X, OP, Y, OP2, Z)
> 
>      Issue an assertion failure error if the expression X OP Y or if the
>      expression Y OP2 Z is false.  Typically OP and OP2 would be < or <=,
>      looking something like:
> 
> 	ASSERTRANGE(11, <, x, <=, 13);
> 
>      and giving the following error:
> 
> 	------------[ cut here ]------------
> 	ASSERTION FAILED at fs/fscache/main.c:109!
> 	Check b < 2 <= d is false
> 	invalid opcode: 0000 [#1] SMP

Hmm, but why not have a single something-like-"ASSERT" doing the same as
in userspace:
#define ASSERT(X) do {                                   \
  if (unlikely(!(X)))                                    \
    cond_assertion_failed("Assertion '" #X "' failed");  \
} while (0)

You would not need zillion of sub-macros then.

thanks,
-- 
js

  parent reply	other threads:[~2011-10-12 17:45 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-10-12 16:47 [PATCH 1/7] Add assertion support with annotated oopsing David Howells
2011-10-12 16:47 ` [PATCH 2/7] Add assertion checking macros David Howells
2011-10-12 16:47   ` David Howells
2011-10-12 17:43   ` Jiri Slaby [this message]
2011-10-12 20:36   ` David Howells
2011-10-12 16:47 ` [PATCH 3/7] Make shrink_dcache_for_umount_subtree() use the core assertion code David Howells
2011-10-12 16:47   ` David Howells
2011-10-12 16:47 ` [PATCH 4/7] FS-Cache: Use new core assertion macros David Howells
2011-10-12 16:47   ` David Howells
2011-10-12 16:47 ` [PATCH 5/7] CacheFiles: " David Howells
2011-10-12 16:47   ` David Howells
2011-10-12 16:48 ` [PATCH 6/7] AFS: " David Howells
2011-10-12 16:48   ` David Howells
2011-10-12 16:48 ` [PATCH 7/7] RxRPC: " David Howells
2011-10-12 16:48   ` David Howells
2011-10-12 16:57 ` [PATCH 1/7] Add assertion support with annotated oopsing Ingo Molnar
2011-10-12 16:57   ` Ingo Molnar
2011-10-12 17:23 ` David Howells
2011-10-12 17:23   ` David Howells

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4E95D1B7.4050603@gmail.com \
    --to=jirislaby@gmail.com \
    --cc=dhowells@redhat.com \
    --cc=linux-arch@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).