]> xenbits.xensource.com Git - libvirt.git/commitdiff
tests: uniformly report test failures
authorEric Blake <eblake@redhat.com>
Fri, 22 Feb 2013 22:42:39 +0000 (15:42 -0700)
committerEric Blake <eblake@redhat.com>
Tue, 26 Feb 2013 00:38:11 +0000 (17:38 -0700)
testutils.c likes to print summaries after a test completes,
including if it failed.  But if the test outright exit()s,
this summary is skipped.  Enforce that we return instead of exit.

* cfg.mk (sc_prohibit_exit_in_tests): New syntax check.
* tests/commandhelper.c (main): Fix offenders.
* tests/qemumonitorjsontest.c (mymain): Likewise.
* tests/seclabeltest.c (main): Likewise.
* tests/securityselinuxlabeltest.c (mymain): Likewise.
* tests/securityselinuxtest.c (mymain): Likewise.
* tests/testutils.h (VIRT_TEST_MAIN_PRELOAD): Likewise.
* tests/testutils.c (virtTestMain): Likewise.
(virtTestCaptureProgramOutput): Use symbolic name.

cfg.mk
tests/commandhelper.c
tests/qemumonitorjsontest.c
tests/seclabeltest.c
tests/securityselinuxlabeltest.c
tests/securityselinuxtest.c
tests/testutils.c
tests/testutils.h

diff --git a/cfg.mk b/cfg.mk
index d56f7e37c54b6d66fc3f1b264880d3dc3baf082e..b95a90b1ec5be8163935ad6a9088d0cdf446bd97 100644 (file)
--- a/cfg.mk
+++ b/cfg.mk
@@ -709,6 +709,13 @@ sc_prohibit_semicolon_at_eol_in_python:
        halt="Don't use semicolon at eol in python files"               \
          $(_sc_search_regexp)
 
+# mymain() in test files should use return, not exit, for nicer output
+sc_prohibit_exit_in_tests:
+       @prohibit='\<exit *\('                                          \
+       in_vc_files='^tests/'                                           \
+       halt='use return, not exit(), in tests'                         \
+         $(_sc_search_regexp)
+
 # We don't use this feature of maint.mk.
 prev_version_file = /dev/null
 
index 39f3c53ae052ff3d894926fafb7a3172107676d0..92f031fd41d4ff73ed017be504b613b53880504d 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * commandhelper.c: Auxiliary program for commandtest
  *
- * Copyright (C) 2010-2012 Red Hat, Inc.
+ * Copyright (C) 2010-2013 Red Hat, Inc.
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -71,9 +71,8 @@ int main(int argc, char **argv) {
         origenv++;
     }
 
-    if (VIR_ALLOC_N(newenv, n) < 0) {
-        exit(EXIT_FAILURE);
-    }
+    if (VIR_ALLOC_N(newenv, n) < 0)
+        return EXIT_FAILURE;
 
     origenv = environ;
     n = i = 0;
index 107653e2de88a4210f27a5732540d2a812e83af7..16e1f98a6fbfb7a6b615d49ad4b454417946a4e1 100644 (file)
@@ -449,11 +449,9 @@ mymain(void)
     return EXIT_AM_SKIP;
 #endif
 
-    if (virThreadInitialize() < 0)
-        exit(EXIT_FAILURE);
-
-    if (!(caps = testQemuCapsInit()))
-        exit(EXIT_FAILURE);
+    if (virThreadInitialize() < 0 ||
+        !(caps = testQemuCapsInit()))
+        return EXIT_FAILURE;
 
     virEventRegisterDefaultImpl();
 
index 93b4902da38b69c9d1451ca5266307aa96423abe..cd34b6b57c869a383eccd7901864ab471f384111 100644 (file)
@@ -15,12 +15,12 @@ main(int argc ATTRIBUTE_UNUSED, char **argv ATTRIBUTE_UNUSED)
     const char *doi, *model;
 
     if (virThreadInitialize() < 0)
-        exit(EXIT_FAILURE);
+        return EXIT_FAILURE;
 
     mgr = virSecurityManagerNew(NULL, "QEMU", false, true, false);
     if (mgr == NULL) {
         fprintf(stderr, "Failed to start security driver");
-        exit(EXIT_FAILURE);
+        return EXIT_FAILURE;
     }
 
     model = virSecurityManagerGetModel(mgr);
@@ -28,7 +28,7 @@ main(int argc ATTRIBUTE_UNUSED, char **argv ATTRIBUTE_UNUSED)
     {
         fprintf(stderr, "Failed to copy secModel model: %s",
                 strerror(errno));
-        exit(EXIT_FAILURE);
+        return EXIT_FAILURE;
     }
 
     doi = virSecurityManagerGetDOI(mgr);
@@ -36,7 +36,7 @@ main(int argc ATTRIBUTE_UNUSED, char **argv ATTRIBUTE_UNUSED)
     {
         fprintf(stderr, "Failed to copy secModel DOI: %s",
                 strerror(errno));
-        exit(EXIT_FAILURE);
+        return EXIT_FAILURE;
     }
 
     virObjectUnref(mgr);
index 7445ab680fa50a1fef60465e0f534d310623dad8..24547726834ac9dea481d1dc9b68e17dea6dc9d9 100644 (file)
@@ -317,15 +317,15 @@ mymain(void)
     if (!(mgr = virSecurityManagerNew("selinux", "QEMU", false, true, false))) {
         virErrorPtr err = virGetLastError();
         if (err->code == VIR_ERR_CONFIG_UNSUPPORTED)
-            exit(EXIT_AM_SKIP);
+            return EXIT_AM_SKIP;
 
         fprintf(stderr, "Unable to initialize security driver: %s\n",
                 err->message);
-        exit(EXIT_FAILURE);
+        return EXIT_FAILURE;
     }
 
     if ((caps = testQemuCapsInit()) == NULL)
-        exit(EXIT_FAILURE);
+        return EXIT_FAILURE;
 
 #define DO_TEST_LABELING(name) \
     if (virtTestRun("Labelling " # name, 1, testSELinuxLabeling, name) < 0) \
index 0dff8721e7ed146a82962d701780dd87614c3995..ba00010490c2f4226296ff03bd68a0ddb4979fd4 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2011-2012 Red Hat, Inc.
+ * Copyright (C) 2011-2013 Red Hat, Inc.
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -274,11 +274,11 @@ mymain(void)
     if (!(mgr = virSecurityManagerNew("selinux", "QEMU", false, true, false))) {
         virErrorPtr err = virGetLastError();
         if (err->code == VIR_ERR_CONFIG_UNSUPPORTED)
-            exit(EXIT_AM_SKIP);
+            return EXIT_AM_SKIP;
 
         fprintf(stderr, "Unable to initialize security driver: %s\n",
                 err->message);
-        exit(EXIT_FAILURE);
+        return EXIT_FAILURE;
     }
 
 #define DO_TEST_GEN_LABEL(desc, pidcon,                                 \
index 7b2ea5122ec6649c5228ed36a8122b854e0f620f..ea46c095cb82d34fe5b93de9a70e60064904df47 100644 (file)
@@ -317,7 +317,7 @@ virtTestCaptureProgramOutput(const char *const argv[], char **buf, int maxlen)
         virtTestCaptureProgramExecChild(argv, pipefd[1]);
 
         VIR_FORCE_CLOSE(pipefd[1]);
-        _exit(1);
+        _exit(EXIT_FAILURE);
 
     case -1:
         return -1;
@@ -586,7 +586,7 @@ int virtTestMain(int argc,
         abs_srcdir_cleanup = true;
     }
     if (!abs_srcdir)
-        exit(EXIT_AM_HARDFAIL);
+        return EXIT_AM_HARDFAIL;
 
     progname = last_component(argv[0]);
     if (STRPREFIX(progname, "lt-"))
@@ -603,13 +603,13 @@ int virtTestMain(int argc,
 
     if (virThreadInitialize() < 0 ||
         virErrorInitialize() < 0)
-        return 1;
+        return EXIT_FAILURE;
 
     virLogSetFromEnv();
     if (!getenv("LIBVIRT_DEBUG") && !virLogGetNbOutputs()) {
         if (virLogDefineOutput(virtTestLogOutput, virtTestLogClose, &testLog,
                                VIR_LOG_DEBUG, VIR_LOG_TO_STDERR, NULL, 0) < 0)
-            return 1;
+            return EXIT_FAILURE;
     }
 
 #if TEST_OOM
index 581bd3e3caedb7fb4e3e2c6323a74f775138086e..546c9aed43939c4d7bdfbef99f8e8f7df41522a7 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * utils.c: test utils
  *
- * Copyright (C) 2005, 2008-2012 Red Hat, Inc.
+ * Copyright (C) 2005, 2008-2013 Red Hat, Inc.
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -78,7 +78,7 @@ int virtTestMain(int argc,
             if (virAsprintf(&newenv, "%s%s%s", preload ? preload : "",  \
                             preload ? ":" : "", lib) < 0) {             \
                 perror("virAsprintf");                                  \
-                exit(EXIT_FAILURE);                                     \
+                return EXIT_FAILURE;                                    \
             }                                                           \
             setenv("LD_PRELOAD", newenv, 1);                            \
             execv(argv[0], argv);                                       \