From patchwork Fri Jul 11 08:19:34 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Jones X-Patchwork-Id: 4531621 Return-Path: X-Original-To: patchwork-kvm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 83D629F36A for ; Fri, 11 Jul 2014 08:22:10 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id AB298201EC for ; Fri, 11 Jul 2014 08:22:09 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 97608201C7 for ; Fri, 11 Jul 2014 08:22:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752227AbaGKIUP (ORCPT ); Fri, 11 Jul 2014 04:20:15 -0400 Received: from mx1.redhat.com ([209.132.183.28]:1699 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752172AbaGKIUC (ORCPT ); Fri, 11 Jul 2014 04:20:02 -0400 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id s6B8K00F019799 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 11 Jul 2014 04:20:00 -0400 Received: from hawk.usersys.redhat.com (ovpn-116-34.ams2.redhat.com [10.36.116.34]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id s6B8Jmil010067; Fri, 11 Jul 2014 04:19:58 -0400 From: Andrew Jones To: kvmarm@lists.cs.columbia.edu, kvm@vger.kernel.org Cc: christoffer.dall@linaro.org, pbonzini@redhat.com Subject: [PATCH v6 04/17] libcflat: add abort() and assert() Date: Fri, 11 Jul 2014 10:19:34 +0200 Message-Id: <1405066787-5793-5-git-send-email-drjones@redhat.com> In-Reply-To: <1405066787-5793-1-git-send-email-drjones@redhat.com> References: <1405066787-5793-1-git-send-email-drjones@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.22 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Spam-Status: No, score=-7.5 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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 --- v6: change abort() from macro to function [Paolo Bonzini] don't use signal ambiguous status codes [Paolo Bonzini] --- Makefile | 1 + lib/abort.c | 20 ++++++++++++++++++++ lib/libcflat.h | 9 +++++++++ 3 files changed, 30 insertions(+) create mode 100644 lib/abort.c diff --git a/Makefile b/Makefile index fba58e36f272f..180189ecd6d8c 100644 --- a/Makefile +++ b/Makefile @@ -19,6 +19,7 @@ cflatobjs := \ lib/argv.o \ lib/printf.o \ lib/string.o \ + lib/abort.o \ lib/report.o # libfdt paths diff --git a/lib/abort.c b/lib/abort.c new file mode 100644 index 0000000000000..61f7f924aba4b --- /dev/null +++ b/lib/abort.c @@ -0,0 +1,20 @@ +/* + * Copyright (C) 2014, Red Hat Inc, Andrew Jones + * + * This work is licensed under the terms of the GNU LGPL, version 2. + */ +#include "libcflat.h" + +/* + * When exit(code) is invoked, qemu will exit with ((code << 1) | 1), + * leaving us 128 exit status codes. To avoid confusion with signal + * status, we further limit exit codes to those resulting in qemu + * exiting with a status < 128. We give abort() the highest (127), + * leaving the lower status codes for unit tests. + */ +#define ABORT_EXIT_STATUS 63 /* 127 exit status from qemu */ + +void abort(void) +{ + exit(ABORT_EXIT_STATUS); +} diff --git a/lib/libcflat.h b/lib/libcflat.h index c9754695326df..9f76d6741344d 100644 --- a/lib/libcflat.h +++ b/lib/libcflat.h @@ -44,6 +44,7 @@ typedef _Bool bool; #define false 0 extern void exit(int code); +extern void abort(void); extern int printf(const char *fmt, ...); extern int snprintf(char *buf, int size, const char *fmt, ...); @@ -61,4 +62,12 @@ extern long atol(const char *ptr); void report(const char *msg_fmt, bool pass, ...); void report_xfail(const char *msg_fmt, bool xfail, bool pass, ...); int report_summary(void); + +#define assert(cond) \ +do { \ + if (!(cond)) \ + printf("%s:%d: assert failed\n", __FILE__, __LINE__), \ + abort(); \ +} while (0) + #endif