]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
test: fix build errors with gcc 4.7.0 and -O0
authorLaine Stump <laine@laine.org>
Thu, 5 Apr 2012 20:31:36 +0000 (16:31 -0400)
committerEric Blake <eblake@redhat.com>
Fri, 6 Apr 2012 04:07:41 +0000 (22:07 -0600)
When building on Fedora 17 (which uses gcc 4.7.0) with -O0 in CFLAGS,
three of the tests failed to compile.

cputest.c and qemuxml2argvtest.c had non-static structs defined
inside the macro that was being repeatedly invoked. Due to some so-far
unidentified change in gcc, the stack space used by variables defined
inside { } is not recovered/re-used when the block ends, so all these
structs have become additive (this is the same problem worked around
in commit cf57d345b). Fortunately, these two files could be fixed with
a single line addition of "static" to the struct definition in the
macro.

virnettlscontexttest.c was a bit different, though. The problem structs
in the do/while loop of macros had non-constant initializers, so it
took a bit more work and piecemeal initialization instead of member
initialization to get things to be happy.

In an ideal world, none of these changes should be necessary, but not
knowing how long it will be until the gcc regressions are fixed, and
since the code is just as correct after this patch as before, it makes
sense to fix libvirt's build for -O0 while also reporting the gcc
problem.

tests/cputest.c
tests/qemuxml2argvtest.c
tests/virnettlscontexttest.c

index 9928e5d64e292a18e1a231d463d67324ac09d8e7..01db8f146184afebcb6ee3bce96e0f90241d50de 100644 (file)
@@ -512,7 +512,7 @@ mymain(void)
 #define DO_TEST(arch, api, name, host, cpu,                             \
                 models, nmodels, preferred, result)                     \
     do {                                                                \
-        struct data data = {                                            \
+        static struct data data = {                                     \
             arch, api, host, cpu, models,                               \
             models == NULL ? NULL : #models,                            \
             nmodels, preferred, result    \
index 637ca5041584e4db4bb7b352efcc2e1cbfaf257c..fdbe95ac8fd703a08bfd274b07a06f3975d35fda 100644 (file)
@@ -314,7 +314,7 @@ mymain(void)
 # define DO_TEST_FULL(name, migrateFrom, migrateFd,                     \
                       expectError, expectFailure, ...)                  \
     do {                                                                \
-        struct testInfo info = {                                        \
+        static struct testInfo info = {                                 \
             name, NULL, migrateFrom, migrateFd,                         \
             expectError, expectFailure                                  \
         };                                                              \
index 8e805d8cf50197e3253acb79026947cc7891aee4..e745487db4590f032ed0f689f5ae4006ca8e2768 100644 (file)
@@ -749,31 +749,47 @@ mymain(void)
     if (virFileWriteStr(keyfile, PRIVATE_KEY, 0600) < 0)
         return EXIT_FAILURE;
 
-# define DO_CTX_TEST(isServer, caReq, certReq, expectFail)              \
+# define DO_CTX_TEST(_isServer, _caReq, _certReq, _expectFail)          \
     do {                                                                \
-        struct testTLSContextData data = {                              \
-            isServer, caReq, certReq, expectFail,                       \
-        };                                                              \
+        static struct testTLSContextData data;                          \
+        data.isServer = _isServer;                                      \
+        data.careq = _caReq;                                            \
+        data.certreq = _certReq;                                        \
+        data.expectFail = _expectFail;                                  \
         if (virtTestRun("TLS Context", 1, testTLSContextInit, &data) < 0) \
             ret = -1;                                                   \
     } while (0)
 
-# define DO_SESS_TEST(caReq, serverReq, clientReq, expectServerFail, expectClientFail, hostname, wildcards) \
+# define DO_SESS_TEST(_caReq, _serverReq, _clientReq, _expectServerFail,\
+                      _expectClientFail, _hostname, _wildcards)         \
     do {                                                                \
-        struct testTLSSessionData data = {                              \
-            caReq, { 0 }, serverReq, clientReq,                         \
-            expectServerFail, expectClientFail, hostname, wildcards     \
-        };                                                              \
+        static struct testTLSSessionData data;                          \
+        static struct testTLSCertReq other;                             \
+        data.careq = _caReq;                                            \
+        data.othercareq = other;                                        \
+        data.serverreq = _serverReq;                                    \
+        data.clientreq = _clientReq;                                    \
+        data.expectServerFail = _expectServerFail;                      \
+        data.expectClientFail = _expectClientFail;                      \
+        data.hostname = _hostname;                                      \
+        data.wildcards = _wildcards;                                    \
         if (virtTestRun("TLS Session", 1, testTLSSessionInit, &data) < 0) \
             ret = -1;                                                   \
     } while (0)
 
-# define DO_SESS_TEST_EXT(caReq, othercaReq, serverReq, clientReq, expectServerFail, expectClientFail, hostname, wildcards) \
+# define DO_SESS_TEST_EXT(_caReq, _othercaReq, _serverReq, _clientReq,  \
+                          _expectServerFail, _expectClientFail,         \
+                          _hostname, _wildcards)                        \
     do {                                                                \
-        struct testTLSSessionData data = {                              \
-            caReq, othercaReq, serverReq, clientReq,                    \
-            expectServerFail, expectClientFail, hostname, wildcards     \
-        };                                                              \
+        static struct testTLSSessionData data;                          \
+        data.careq = _caReq;                                            \
+        data.othercareq = _othercaReq;                                  \
+        data.serverreq = _serverReq;                                    \
+        data.clientreq = _clientReq;                                    \
+        data.expectServerFail = _expectServerFail;                      \
+        data.expectClientFail = _expectClientFail;                      \
+        data.hostname = _hostname;                                      \
+        data.wildcards = _wildcards;                                    \
         if (virtTestRun("TLS Session", 1, testTLSSessionInit, &data) < 0) \
             ret = -1;                                                   \
     } while (0)