From patchwork Wed Sep 30 00:30:00 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cole Robinson X-Patchwork-Id: 54288 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-la0-f70.google.com (mail-la0-f70.google.com [209.85.215.70]) by patches.linaro.org (Postfix) with ESMTPS id 948D823009 for ; Wed, 30 Sep 2015 00:32:54 +0000 (UTC) Received: by labjk1 with SMTP id jk1sf13078818lab.0 for ; Tue, 29 Sep 2015 17:32:53 -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:to:references:from:message-id:date :user-agent:mime-version:in-reply-to:subject:precedence:list-id :list-unsubscribe:list-archive:list-post:list-help:list-subscribe :content-type:content-transfer-encoding:sender:errors-to :x-original-sender:x-original-authentication-results:mailing-list; bh=zQufzrzK9x5AgvyyTSedgcBE+VG+jJA9m1zts0mJagQ=; b=Mv/BJorUJJwjt6Efn61NXzsnFRg4hWvGKjTcgku82wAcTEmu5BOa11o5ZNXdcaUZZ4 5pEboB7ChVFKLqN8x8flFgO9w8b5ogiqODkVKu8tbC974OUBHIvORPvydrW4QEzZs9Zt rKvaUuxPC2ceC1VYvXqldCAE1OiNKhgsrysg3KmInEaNtW6Q57VN3bJJn9jP57oilJao yP8yoGTvZ/MlOd13v1W+HS7NhADWc32MOW7YE9XFFJBaXSdTBgzpg/UD6vrS13PvkUjR RLDVhmc/ZZw8YA5bkeGubZCotFxIlINNUCl92wANM6IcgkeVUvSN0csEixZTaJa0C5jE xdUQ== X-Gm-Message-State: ALoCoQlC0nmjFeVtS/s8jbO/tawIoUezzpwopWDO5WBsTL1wPmQ8B+zdKGBHOm2ImnVU510JJE55 X-Received: by 10.180.10.202 with SMTP id k10mr4310524wib.2.1443573172787; Tue, 29 Sep 2015 17:32:52 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.43.198 with SMTP id y6ls10597lal.8.gmail; Tue, 29 Sep 2015 17:32:52 -0700 (PDT) X-Received: by 10.152.6.162 with SMTP id c2mr222566laa.26.1443573172446; Tue, 29 Sep 2015 17:32:52 -0700 (PDT) Received: from mail-la0-f43.google.com (mail-la0-f43.google.com. [209.85.215.43]) by mx.google.com with ESMTPS id u3si12195232lau.101.2015.09.29.17.32.52 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 29 Sep 2015 17:32:52 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.43 as permitted sender) client-ip=209.85.215.43; Received: by laclj5 with SMTP id lj5so27806806lac.3 for ; Tue, 29 Sep 2015 17:32:52 -0700 (PDT) X-Received: by 10.112.51.142 with SMTP id k14mr183393lbo.76.1443573172279; Tue, 29 Sep 2015 17:32:52 -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 w3csp2441304lbq; Tue, 29 Sep 2015 17:32:51 -0700 (PDT) X-Received: by 10.180.198.180 with SMTP id jd20mr1572510wic.70.1443573171276; Tue, 29 Sep 2015 17:32:51 -0700 (PDT) Received: from mx4-phx2.redhat.com (mx4-phx2.redhat.com. [209.132.183.25]) by mx.google.com with ESMTPS id gg6si19616293wic.69.2015.09.29.17.32.50 (version=TLSv1 cipher=AES128-SHA bits=128/128); Tue, 29 Sep 2015 17:32:51 -0700 (PDT) Received-SPF: pass (google.com: domain of libvir-list-bounces@redhat.com designates 209.132.183.25 as permitted sender) client-ip=209.132.183.25; Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by mx4-phx2.redhat.com (8.13.8/8.13.8) with ESMTP id t8U0U34u002582; Tue, 29 Sep 2015 20:30:03 -0400 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id t8U0U1dk008335 for ; Tue, 29 Sep 2015 20:30:02 -0400 Received: from [10.3.113.60] (ovpn-113-60.phx2.redhat.com [10.3.113.60]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id t8U0U1dd023999 for ; Tue, 29 Sep 2015 20:30:01 -0400 To: libvirt-list@redhat.com References: <36363a3385c25563f2aee28e2e134698593e64b5.1443570876.git.crobinso@redhat.com> From: Cole Robinson Message-ID: <560B2D08.3030704@redhat.com> Date: Tue, 29 Sep 2015 20:30:00 -0400 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.2.0 MIME-Version: 1.0 In-Reply-To: <36363a3385c25563f2aee28e2e134698593e64b5.1443570876.git.crobinso@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.23 X-loop: libvir-list@redhat.com Subject: Re: [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: , 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.43 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 On 09/29/2015 07:56 PM, Cole Robinson wrote: > 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; > } > > I squashed this in locally to appease syntax-check: data.msg = msg; - Cole --- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list diff --git a/tests/eventtest.c b/tests/eventtest.c index ab08181..d0faf27 100644 --- a/tests/eventtest.c +++ b/tests/eventtest.c @@ -73,14 +73,13 @@ testEventResultCallback(const void *opaque) { const struct testEventResultData *data = opaque; - if (data->failed && data->msg) { + if (data->failed && data->msg) fprintf(stderr, "%s", data->msg); - } return data->failed; } static void -ATTRIBUTE_FMT_PRINTF(3,4) +ATTRIBUTE_FMT_PRINTF(3, 4) testEventReport(const char *name, bool failed, const char *msg, ...) { va_list vargs; @@ -88,9 +87,8 @@ testEventReport(const char *name, bool failed, const char *msg, ...) char *str = NULL; struct testEventResultData data; - if (msg && virVasprintfQuiet(&str, msg, vargs) != 0) { + if (msg && virVasprintfQuiet(&str, msg, vargs) != 0) failed = true; - } data.failed = failed;