From patchwork Tue Sep 29 23:56:46 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cole Robinson X-Patchwork-Id: 54287 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wi0-f198.google.com (mail-wi0-f198.google.com [209.85.212.198]) by patches.linaro.org (Postfix) with ESMTPS id 3730F23009 for ; Tue, 29 Sep 2015 23:59:48 +0000 (UTC) Received: by wicmn1 with SMTP id mn1sf13678639wic.1 for ; Tue, 29 Sep 2015 16:59:47 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:delivered-to:from:to:date:message-id:in-reply-to :references:in-reply-to:references:subject:precedence:list-id :list-unsubscribe:list-archive:list-post:list-help:list-subscribe :mime-version:content-type:content-transfer-encoding:sender :errors-to:x-original-sender:x-original-authentication-results :mailing-list; bh=Q9VfZXmCKGWvgND86Z+l9qrosLiBdvvpDh2+D1EJkyE=; b=VNAHUhkc+ZdUizoCQ49MT6F7JfyK1g4VuNOX6Z/sTpoLKwq2n64ZPxdpCZ4lVkXmwh XkT0Y55DKUEo/Yiil2q+Z9DA/CAnZOi7cMfqvenVXgb9OQrTtGXfWeh94iH6Vu/PlSgF 7lZ3kxHj+4K7z4cNnJv2LHS87JFwA57JMJkPB4L4om7Zh083z26NGo334gvsfptJ5vnu 1IE9fgaCg/VJo1utAyVFGXmrOr1S8p4c5uQfwZUbMiviOwHnE3h+Xpr1HdrJavHwi9wu Erw6uTnCIDgxn71fi2aFOIPDUvS4spMhp7lBHU6VTR3mLNcFc0chOgjoRAJxVbLLcfzz v2SQ== X-Gm-Message-State: ALoCoQni0P2k11p5nbVAP2Y9oVlfLuOzffl79A00xS4Do990nc3GcLI6cntuWwAQvDeg96ygM5OU X-Received: by 10.180.188.211 with SMTP id gc19mr4297958wic.6.1443571187478; Tue, 29 Sep 2015 16:59:47 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.27.106 with SMTP id s10ls7169lag.98.gmail; Tue, 29 Sep 2015 16:59:47 -0700 (PDT) X-Received: by 10.152.7.10 with SMTP id f10mr199558laa.84.1443571187176; Tue, 29 Sep 2015 16:59:47 -0700 (PDT) Received: from mail-la0-f50.google.com (mail-la0-f50.google.com. [209.85.215.50]) by mx.google.com with ESMTPS id as1si12107059lbc.94.2015.09.29.16.59.47 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 29 Sep 2015 16:59:47 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.50 as permitted sender) client-ip=209.85.215.50; Received: by laer8 with SMTP id r8so27123131lae.2 for ; Tue, 29 Sep 2015 16:59:47 -0700 (PDT) X-Received: by 10.25.207.82 with SMTP id f79mr129460lfg.73.1443571187058; Tue, 29 Sep 2015 16:59:47 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.112.59.35 with SMTP id w3csp2430709lbq; Tue, 29 Sep 2015 16:59:46 -0700 (PDT) X-Received: by 10.194.176.6 with SMTP id ce6mr653881wjc.101.1443571186356; Tue, 29 Sep 2015 16:59:46 -0700 (PDT) Received: from mx3-phx2.redhat.com (mx3-phx2.redhat.com. [209.132.183.24]) by mx.google.com with ESMTPS id co1si32607073wib.65.2015.09.29.16.59.45 (version=TLSv1 cipher=AES128-SHA bits=128/128); Tue, 29 Sep 2015 16:59:46 -0700 (PDT) Received-SPF: pass (google.com: domain of libvir-list-bounces@redhat.com designates 209.132.183.24 as permitted sender) client-ip=209.132.183.24; Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by mx3-phx2.redhat.com (8.13.8/8.13.8) with ESMTP id t8TNvE4H032094; Tue, 29 Sep 2015 19:57:14 -0400 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id t8TNusSl032257 for ; Tue, 29 Sep 2015 19:56:54 -0400 Received: from colepc.redhat.com (ovpn-113-60.phx2.redhat.com [10.3.113.60]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id t8TNuo7S015888; Tue, 29 Sep 2015 19:56:53 -0400 From: Cole Robinson To: libvirt-list@redhat.com Date: Tue, 29 Sep 2015 19:56:46 -0400 Message-Id: <36363a3385c25563f2aee28e2e134698593e64b5.1443570876.git.crobinso@redhat.com> In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.68 on 10.5.11.22 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 2/3] tests: eventtest: Open code virtTestResult X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: , List-Help: , List-Subscribe: , MIME-Version: 1.0 Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: crobinso@redhat.com X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.50 as permitted sender) smtp.mailfrom=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 These event tests aren't run synchronously, so there isn't an obvious function to pass to virtTestRun. Instead, open code roughly what virtTestResult did before: printing an error message if a test failed. --- tests/eventtest.c | 57 +++++++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 47 insertions(+), 10 deletions(-) diff --git a/tests/eventtest.c b/tests/eventtest.c index 13adbf6..ab08181 100644 --- a/tests/eventtest.c +++ b/tests/eventtest.c @@ -63,6 +63,43 @@ enum { EV_ERROR_DATA, }; +struct testEventResultData { + bool failed; + const char *msg; +}; + +static int +testEventResultCallback(const void *opaque) +{ + const struct testEventResultData *data = opaque; + + if (data->failed && data->msg) { + fprintf(stderr, "%s", data->msg); + } + return data->failed; +} + +static void +ATTRIBUTE_FMT_PRINTF(3,4) +testEventReport(const char *name, bool failed, const char *msg, ...) +{ + va_list vargs; + va_start(vargs, msg); + char *str = NULL; + struct testEventResultData data; + + if (msg && virVasprintfQuiet(&str, msg, vargs) != 0) { + failed = true; + } + + data.failed = failed; + data.msg = msg; + virtTestRun(name, testEventResultCallback, &data); + + va_end(vargs); + VIR_FREE(str); +} + static void testPipeReader(int watch, int fd, int events, void *data) { @@ -148,13 +185,13 @@ verifyFired(const char *name, int handle, int timer) for (i = 0; i < NUM_FDS; i++) { if (handles[i].fired) { if (i != handle) { - virtTestResult(name, 1, + testEventReport(name, 1, "Handle %zu fired, but expected %d\n", i, handle); return EXIT_FAILURE; } else { if (handles[i].error != EV_ERROR_NONE) { - virtTestResult(name, 1, + testEventReport(name, 1, "Handle %zu fired, but had error %d\n", i, handles[i].error); return EXIT_FAILURE; @@ -163,7 +200,7 @@ verifyFired(const char *name, int handle, int timer) } } else { if (i == handle) { - virtTestResult(name, 1, + testEventReport(name, 1, "Handle %d should have fired, but didn't\n", handle); return EXIT_FAILURE; @@ -171,7 +208,7 @@ verifyFired(const char *name, int handle, int timer) } } if (handleFired != 1 && handle != -1) { - virtTestResult(name, 1, + testEventReport(name, 1, "Something weird happened, expecting handle %d\n", handle); return EXIT_FAILURE; @@ -181,12 +218,12 @@ verifyFired(const char *name, int handle, int timer) for (i = 0; i < NUM_TIME; i++) { if (timers[i].fired) { if (i != timer) { - virtTestResult(name, 1, + testEventReport(name, 1, "Timer %zu fired, but expected %d\n", i, timer); return EXIT_FAILURE; } else { if (timers[i].error != EV_ERROR_NONE) { - virtTestResult(name, 1, + testEventReport(name, 1, "Timer %zu fired, but had error %d\n", i, timers[i].error); return EXIT_FAILURE; @@ -195,7 +232,7 @@ verifyFired(const char *name, int handle, int timer) } } else { if (i == timer) { - virtTestResult(name, 1, + testEventReport(name, 1, "Timer %d should have fired, but didn't\n", timer); return EXIT_FAILURE; @@ -203,7 +240,7 @@ verifyFired(const char *name, int handle, int timer) } } if (timerFired != 1 && timer != -1) { - virtTestResult(name, 1, + testEventReport(name, 1, "Something weird happened, expecting timer %d\n", timer); return EXIT_FAILURE; @@ -234,14 +271,14 @@ finishJob(const char *name, int handle, int timer) rc = pthread_cond_timedwait(&eventThreadJobCond, &eventThreadMutex, &waitTime); if (rc != 0) { - virtTestResult(name, 1, "Timed out waiting for pipe event\n"); + testEventReport(name, 1, "Timed out waiting for pipe event\n"); return EXIT_FAILURE; } if (verifyFired(name, handle, timer) != EXIT_SUCCESS) return EXIT_FAILURE; - virtTestResult(name, 0, NULL); + testEventReport(name, 0, NULL); return EXIT_SUCCESS; }