]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
tests: diagnose more open failures
authorJim Meyering <meyering@redhat.com>
Mon, 2 Feb 2009 20:35:14 +0000 (20:35 +0000)
committerJim Meyering <meyering@redhat.com>
Mon, 2 Feb 2009 20:35:14 +0000 (20:35 +0000)
* tests/qemuxml2argvtest.c: Revert the change,
"tests: diagnose open failure" of 2009-01-30.
* tests/testutils.c (virtTestLoadFile): Diagnose failure here.

ChangeLog
tests/qemuxml2argvtest.c
tests/testutils.c

index dc88e66326e12f4fda374428e2a1f208c9541f0d..6c0fedbfde8f922f9da363fca589f71161fb2665 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+Mon, 2 Feb 2009 21:33:57 +0100 Jim Meyering <meyering@redhat.com>
+
+       tests: diagnose more open failures
+       * tests/qemuxml2argvtest.c: Revert the change,
+       "tests: diagnose open failure" of 2009-01-30.
+       * tests/testutils.c (virtTestLoadFile): Diagnose failure here.
+
 Mon Feb  2 18:33:19 GMT 2009 John Levon <john.levon@sun.com>
 
        * src/libvirt.c: fix more printf("%s", NULL) cases
index 1d7aeb9d7a30734c50a358660b059064bff6cfad..90b474018c16ea7268c74ca76c60ec6f17a70142 100644 (file)
@@ -36,10 +36,8 @@ static int testCompareXMLToArgvFiles(const char *xml,
     virDomainDefPtr vmdef = NULL;
     virDomainObj vm;
 
-    if (virtTestLoadFile(cmd, &expectargv, MAX_FILE) < 0) {
-        fprintf(stderr, "failed to open %s: %s\n", cmd, strerror (errno));
+    if (virtTestLoadFile(cmd, &expectargv, MAX_FILE) < 0)
         goto fail;
-    }
 
     if (!(vmdef = virDomainDefParseFile(NULL, driver.caps, xml,
                                         VIR_DOMAIN_XML_INACTIVE)))
index e8b07fc609f1918e79ea5191c85e6e649609933e..8d8f82d119f2088da62a5d9eded7208bcece8b22 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * testutils.c: basic test utils
  *
- * Copyright (C) 2005-2008 Red Hat, Inc.
+ * Copyright (C) 2005-2009 Red Hat, Inc.
  *
  * See COPYING.LIB for the License of this software
  *
@@ -106,27 +106,36 @@ virtTestRun(const char *title, int nloops, int (*body)(const void *data), const
     return ret;
 }
 
-int virtTestLoadFile(const char *name,
+/* Read FILE into buffer BUF of length BUFLEN.
+   Upon any failure, or if FILE appears to contain more than BUFLEN bytes,
+   diagnose it and return -1, but don't bother trying to preserve errno.
+   Otherwise, return the number of bytes read (and copied into BUF).  */
+int virtTestLoadFile(const char *file,
                      char **buf,
                      int buflen) {
-    FILE *fp = fopen(name, "r");
+    FILE *fp = fopen(file, "r");
     struct stat st;
 
-    if (!fp)
+    if (!fp) {
+        fprintf (stderr, "%s: failed to open: %s\n", file, strerror(errno));
         return -1;
+    }
 
     if (fstat(fileno(fp), &st) < 0) {
+        fprintf (stderr, "%s: failed to fstat: %s\n", file, strerror(errno));
         fclose(fp);
         return -1;
     }
 
     if (st.st_size > (buflen-1)) {
+        fprintf (stderr, "%s: larger than buffer (> %d)\n", file, buflen-1);
         fclose(fp);
         return -1;
     }
 
     if (st.st_size) {
         if (fread(*buf, st.st_size, 1, fp) != 1) {
+            fprintf (stderr, "%s: read failed: %s\n", file, strerror(errno));
             fclose(fp);
             return -1;
         }