From patchwork Wed Apr 28 15:47:55 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Avi Kivity X-Patchwork-Id: 95713 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter.kernel.org (8.14.3/8.14.3) with ESMTP id o3SFm4N9024861 for ; Wed, 28 Apr 2010 15:48:04 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753438Ab0D1PsA (ORCPT ); Wed, 28 Apr 2010 11:48:00 -0400 Received: from mx1.redhat.com ([209.132.183.28]:31343 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751581Ab0D1Pr7 (ORCPT ); Wed, 28 Apr 2010 11:47:59 -0400 Received: from int-mx02.intmail.prod.int.phx2.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id o3SFlx03009782 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Wed, 28 Apr 2010 11:47:59 -0400 Received: from cleopatra.tlv.redhat.com (cleopatra.tlv.redhat.com [10.35.255.11]) by int-mx02.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id o3SFlwuS007866 for ; Wed, 28 Apr 2010 11:47:59 -0400 Received: from localhost.localdomain (file.tlv.redhat.com [10.35.255.8]) by cleopatra.tlv.redhat.com (Postfix) with ESMTP id 52C2B250AD8; Wed, 28 Apr 2010 18:47:58 +0300 (IDT) From: Avi Kivity To: Marcelo Tosatti Cc: kvm@vger.kernel.org Subject: [PATCH 2/5] test: access: consolidate test failure reporting into a function Date: Wed, 28 Apr 2010 18:47:55 +0300 Message-Id: <1272469678-10728-3-git-send-email-avi@redhat.com> In-Reply-To: <1272469678-10728-1-git-send-email-avi@redhat.com> References: <1272469678-10728-1-git-send-email-avi@redhat.com> X-Scanned-By: MIMEDefang 2.67 on 10.5.11.12 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.3 (demeter.kernel.org [140.211.167.41]); Wed, 28 Apr 2010 15:48:04 +0000 (UTC) diff --git a/kvm/user/test/x86/access.c b/kvm/user/test/x86/access.c index dbc1213..0906691 100644 --- a/kvm/user/test/x86/access.c +++ b/kvm/user/test/x86/access.c @@ -453,6 +453,28 @@ fault: ; } +static void ac_test_check(ac_test_t *at, _Bool *success_ret, _Bool cond, + const char *fmt, ...) +{ + va_list ap; + char buf[500]; + + if (!*success_ret) { + return; + } + + if (!cond) { + return; + } + + *success_ret = false; + + va_start(ap, fmt); + vsnprintf(buf, sizeof(buf), fmt, ap); + va_end(ap); + printf("FAIL: %s\n", buf); +} + int ac_test_do_access(ac_test_t *at) { static unsigned unique = 42; @@ -460,6 +482,7 @@ int ac_test_do_access(ac_test_t *at) unsigned e; static unsigned char user_stack[4096]; unsigned long rsp; + _Bool success = true; ++unique; @@ -531,30 +554,21 @@ int ac_test_do_access(ac_test_t *at) "jmp back_to_kernel \n\t" ".section .text"); - if (fault && !at->expected_fault) { - printf("FAIL: unexpected fault\n"); - return 0; - } - if (!fault && at->expected_fault) { - printf("FAIL: unexpected access\n"); - return 0; - } - if (fault && e != at->expected_error) { - printf("FAIL: error code %x expected %x\n", e, at->expected_error); - return 0; - } - if (at->ptep && *at->ptep != at->expected_pte) { - printf("FAIL: pte %x expected %x\n", *at->ptep, at->expected_pte); - return 0; + ac_test_check(at, &success, fault && !at->expected_fault, + "unexpected fault"); + ac_test_check(at, &success, !fault && at->expected_fault, + "unexpected access"); + ac_test_check(at, &success, fault && e != at->expected_error, + "error code %x expected %x", e, at->expected_error); + ac_test_check(at, &success, at->ptep && *at->ptep != at->expected_pte, + "pte %x expected %x", *at->ptep, at->expected_pte); + ac_test_check(at, &success, *at->pdep != at->expected_pde, + "pde %x expected %x", *at->pdep, at->expected_pde); + + if (success) { + printf("PASS\n"); } - - if (*at->pdep != at->expected_pde) { - printf("FAIL: pde %x expected %x\n", *at->pdep, at->expected_pde); - return 0; - } - - printf("PASS\n"); - return 1; + return success; } static void ac_test_show(ac_test_t *at)