Re: 2/3 testsuite formatting bugs [was: [PATCH] Skip some xen tests if xend is not running]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



2011/7/9 Eric Blake <eblake@xxxxxxxxxx>:
> On 07/08/2011 05:28 PM, Matthias Bolte wrote:
>>
>> From a1508239af921289cd6e357e8521ff42faf535bd Mon Sep 17 00:00:00 2001
>> From: Matthias Bolte <matthias.bolte@xxxxxxxxxxxxxx>
>> Date: Sat, 9 Jul 2011 01:24:16 +0200
>> Subject: [PATCH] tests: Add the logic to skip the statstest to the right place
>>
>> ---
>>  tests/statstest.c |   31 ++++++++++++++++++++-----------
>>  1 files changed, 20 insertions(+), 11 deletions(-)
>>
>>
>> -VIRT_TEST_MAIN(mymain)
>> +/* Skipping the test in mymain is too late, it results in broken output.
>> + * Therefore, expand VIRT_TEST_MAIN here manually to be able to skip at
>> + * the right place. */
>> +int main(int argc, char **argv)
>
> This seems fishy.  Why did tests/reconnect.c not need the same
> treatment?  Oh, because it didn't use VIRT_TEST_MAIN.
>
> Wouldn't it be better to teach VIRT_TEST_MAIN to behave better on a skip?
>
> diff --git i/tests/testutils.c w/tests/testutils.c
> index b433204..f732fdd 100644
> --- i/tests/testutils.c
> +++ w/tests/testutils.c
> @@ -688,7 +688,7 @@ cleanup:
>     if (abs_srcdir_cleanup)
>         VIR_FREE(abs_srcdir);
>     virResetLastError();
> -    if (!virTestGetVerbose()) {
> +    if (!virTestGetVerbose() && ret != EXIT_AM_SKIP) {
>         int i;
>         for (i = (testCounter % 40) ; i > 0 && i < 40 ; i++)
>             fprintf(stderr, " ");

This can still be improved in the look of the output. This results in

TEST: statstest
          SKIP: statstest

Other tests that decide to be skipped at compile time just result in

SKIP: <testname>

Problem with the runtime skip decision is that we need to setup stuff
before and want to print the TEST: <testname> before doing that to get
error messages probably assigned to this test in the output. So we
cannot achieve SKIP: <testname> only here. In order to get rid of the
indentation of SKIP: <testname> we need to defer the output of the
indentation until we know that the test isn't skipped and is actually
running test cases.

Here's a v2 that does this.

-- 
Matthias Bolte
http://photron.blogspot.com
From 43b8e22bcd0bb1c9cd480f23001c30da33fd124e Mon Sep 17 00:00:00 2001
From: Matthias Bolte <matthias.bolte@xxxxxxxxxxxxxx>
Date: Sat, 9 Jul 2011 11:50:38 +0200
Subject: [PATCH] tests: Improve output of tests that decide to skip at runtime

Don't print OK/FAIL for test that decide to be skipped after
calling virtTestMain. Delay printing of the indentation before
the first test until we know that the test didn't decide to be
skipped.

Also make the reconnect test use VIRT_TEST_MAIN.
---
 tests/Makefile.am |    2 +-
 tests/reconnect.c |   17 ++++++++++-------
 tests/testutils.c |   10 +++++++---
 3 files changed, 18 insertions(+), 11 deletions(-)

diff --git a/tests/Makefile.am b/tests/Makefile.am
index 528b88e..e9a445e 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -300,7 +300,7 @@ xencapstest_SOURCES = \
 xencapstest_LDADD = ../src/libvirt_driver_xen.la $(LDADDS)
 
 reconnect_SOURCES = \
-	reconnect.c
+	reconnect.c testutils.h testutils.c
 reconnect_LDADD = $(LDADDS)
 
 statstest_SOURCES = \
diff --git a/tests/reconnect.c b/tests/reconnect.c
index e5553b5..d4aa9f3 100644
--- a/tests/reconnect.c
+++ b/tests/reconnect.c
@@ -11,7 +11,9 @@ static void errorHandler(void *userData ATTRIBUTE_UNUSED,
                          virErrorPtr error ATTRIBUTE_UNUSED) {
 }
 
-int main(void) {
+static int
+mymain(void)
+{
     int id = 0;
     int ro = 0;
     virConnectPtr conn;
@@ -36,12 +38,12 @@ int main(void) {
     }
     if (conn == NULL) {
         fprintf(stderr, "First virConnectOpen() failed\n");
-        exit(EXIT_FAILURE);
+        return EXIT_FAILURE;
     }
     dom = virDomainLookupByID(conn, id);
     if (dom == NULL) {
         fprintf(stderr, "First lookup for domain %d failed\n", id);
-        exit(EXIT_FAILURE);
+        return EXIT_FAILURE;
     }
     virDomainFree(dom);
     virConnectClose(conn);
@@ -51,16 +53,17 @@ int main(void) {
         conn = virConnectOpen(NULL);
     if (conn == NULL) {
         fprintf(stderr, "Second virConnectOpen() failed\n");
-        exit(EXIT_FAILURE);
+        return EXIT_FAILURE;
     }
     dom = virDomainLookupByID(conn, id);
     if (dom == NULL) {
         fprintf(stderr, "Second lookup for domain %d failed\n", id);
-        exit(EXIT_FAILURE);
+        return EXIT_FAILURE;
     }
     virDomainFree(dom);
     virConnectClose(conn);
-    printf("OK\n");
-    exit(EXIT_SUCCESS);
 
+    return EXIT_SUCCESS;
 }
+
+VIRT_TEST_MAIN(mymain)
diff --git a/tests/testutils.c b/tests/testutils.c
index b433204..c89f70f 100644
--- a/tests/testutils.c
+++ b/tests/testutils.c
@@ -76,6 +76,9 @@ void virtTestResult(const char *name, int ret, const char *msg, ...)
     va_list vargs;
     va_start(vargs, msg);
 
+    if (testCounter == 0 && !virTestGetVerbose())
+        fprintf(stderr, "      ");
+
     testCounter++;
     if (virTestGetVerbose()) {
         fprintf(stderr, "%3d) %-60s ", testCounter, name);
@@ -113,6 +116,9 @@ virtTestRun(const char *title, int nloops, int (*body)(const void *data), const
     int i, ret = 0;
     double *ts = NULL;
 
+    if (testCounter == 0 && !virTestGetVerbose())
+        fprintf(stderr, "      ");
+
     testCounter++;
 
     if (testOOM < 2) {
@@ -562,8 +568,6 @@ int virtTestMain(int argc,
         return EXIT_FAILURE;
     }
     fprintf(stderr, "TEST: %s\n", progname);
-    if (!virTestGetVerbose())
-        fprintf(stderr, "      ");
 
     if (virThreadInitialize() < 0 ||
         virErrorInitialize() < 0 ||
@@ -688,7 +692,7 @@ cleanup:
     if (abs_srcdir_cleanup)
         VIR_FREE(abs_srcdir);
     virResetLastError();
-    if (!virTestGetVerbose()) {
+    if (!virTestGetVerbose() && ret != EXIT_AM_SKIP) {
         int i;
         for (i = (testCounter % 40) ; i > 0 && i < 40 ; i++)
             fprintf(stderr, " ");
-- 
1.7.4.1

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list

[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]