From mboxrd@z Thu Jan 1 00:00:00 1970 From: Paolo Bonzini Subject: Re: [PATCH v5 09/19] libcflat: add abort() and assert() Date: Thu, 12 Jun 2014 13:09:32 +0200 Message-ID: <53998A6C.5010906@redhat.com> References: <1402495294-30737-1-git-send-email-drjones@redhat.com> <1402495294-30737-10-git-send-email-drjones@redhat.com> <53998570.1070900@redhat.com> <20140612110723.GD6646@dhcp-27-201.brq.redhat.com> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Cc: kvmarm@lists.cs.columbia.edu, kvm@vger.kernel.org, christoffer.dall@linaro.org To: Andrew Jones Return-path: Received: from mx1.redhat.com ([209.132.183.28]:49348 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752682AbaFLLJi (ORCPT ); Thu, 12 Jun 2014 07:09:38 -0400 In-Reply-To: <20140612110723.GD6646@dhcp-27-201.brq.redhat.com> Sender: kvm-owner@vger.kernel.org List-ID: Il 12/06/2014 13:07, Andrew Jones ha scritto: > On Thu, Jun 12, 2014 at 12:48:16PM +0200, Paolo Bonzini wrote: >> Il 11/06/2014 16:01, Andrew Jones ha scritto: >>> The test framework may have external dependencies. assert() provides >>> the ability to abort when those dependencies aren't met. However, >>> assert() should only be used for unlikely conditions. We can provide >>> more informative messages with printf() for the more likely problems. >>> >>> Signed-off-by: Andrew Jones >>> Acked-by: Christoffer Dall >>> --- >>> lib/libcflat.h | 9 +++++++++ >>> 1 file changed, 9 insertions(+) >>> >>> diff --git a/lib/libcflat.h b/lib/libcflat.h >>> index 024c834630d63..8886885766ddc 100644 >>> --- a/lib/libcflat.h >>> +++ b/lib/libcflat.h >>> @@ -70,4 +70,13 @@ extern long atol(const char *ptr); >>> >>> void report(const char *msg_fmt, bool pass, ...); >>> int report_summary(void); >>> + >>> +#define abort() exit(64) /* 129 exit status from qemu */ >> >> This can be confused with a SIGHUP. We can change it to exit(44) aka 99 >> exit status. >> >> Also, please make it a function rather than a macro. > > OK > >> >>> +#define assert(cond) \ >>> +do { \ >>> + if (!(cond)) \ >>> + printf("%s:%d: assert failed\n", __FILE__, __LINE__), \ >>> + abort(); \ >>> +} while (0) >> >> Here you could also put the printf/abort into a function; as you prefer. >> > > Might as well. If I'm moving abort() into a general lib function, then > I'll need to find a home for it. I can use the same home for assert(). > The best existing home is probably lib/report.c, or I should create a > new .c file. A new lib/abort.c file sounds better. Paolo