diff mbox

[v2] tests: Fix broken tcg test compilation

Message ID aee4e0cc17d97b27e57b5dc656d87eb4c12f9a44.1472816827.git.mprivozn@redhat.com
State New
Headers show

Commit Message

Michal Prívozník Sept. 2, 2016, 11:49 a.m. UTC
The first build error to be seen is that linux-test.c fails to
include cutils.h:

linux-test.c:42:25: fatal error: qemu/cutils.h: No such file or directory

This is because toplevel include/ dir is not put onto compiler's
command line. After that:

qemu.git/include/qemu/cutils.h:171:1: error: unknown type name ‘bool’

So we need to include "qemu/osdep.h" which will define bool type
for us. However, osdep.h eventually includes glib.h from system,
therefore we need to put GLIB_CFLAGS onto compiler's command line
too.

Lastly, getrusage is used in linux-test.c. This function and a
struct it uses are defined in sys/resource.h:

linux-test.c:247:5: warning: implicit declaration of function ‘getrusage’

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
---

Comments

Peter Maydell Sept. 2, 2016, 11:56 a.m. UTC | #1
On 2 September 2016 at 12:49, Michal Privoznik <mprivozn@redhat.com> wrote:
> The first build error to be seen is that linux-test.c fails to
> include cutils.h:
>
> linux-test.c:42:25: fatal error: qemu/cutils.h: No such file or directory
>
> This is because toplevel include/ dir is not put onto compiler's
> command line. After that:
>
> qemu.git/include/qemu/cutils.h:171:1: error: unknown type name ‘bool’
>
> So we need to include "qemu/osdep.h" which will define bool type
> for us. However, osdep.h eventually includes glib.h from system,
> therefore we need to put GLIB_CFLAGS onto compiler's command line
> too.

Why are we including qemu/cutils.h anyway? As far as I can see
we don't use it for anything and removing the #include doesn't
cause any problems...

thanks
-- PMM
Pranith Kumar Sept. 2, 2016, 12:04 p.m. UTC | #2
Hi Michal,

On Fri, Sep 2, 2016 at 7:49 AM, Michal Privoznik <mprivozn@redhat.com> wrote:
> The first build error to be seen is that linux-test.c fails to
> include cutils.h:
>
> linux-test.c:42:25: fatal error: qemu/cutils.h: No such file or directory
>
> This is because toplevel include/ dir is not put onto compiler's
> command line. After that:
>
> qemu.git/include/qemu/cutils.h:171:1: error: unknown type name ‘bool’
>
> So we need to include "qemu/osdep.h" which will define bool type
> for us. However, osdep.h eventually includes glib.h from system,
> therefore we need to put GLIB_CFLAGS onto compiler's command line
> too.
>
> Lastly, getrusage is used in linux-test.c. This function and a
> struct it uses are defined in sys/resource.h:
>
> linux-test.c:247:5: warning: implicit declaration of function ‘getrusage’
>

I recently posted a patch series cleaning up tests/tcg. While doing
that I fixed the build issues I came across.

Please see: https://www.mail-archive.com/qemu-devel@nongnu.org/msg393764.html

Thanks,
--
Pranith
diff mbox

Patch

diff to v1:
- Move include of osdep.h in linux-test.c at the beginning of the file as
  suggested by Eric in review

 tests/tcg/Makefile     | 6 +++---
 tests/tcg/linux-test.c | 4 ++++
 2 files changed, 7 insertions(+), 3 deletions(-)

diff --git a/tests/tcg/Makefile b/tests/tcg/Makefile
index 89e3342..5eadd8b 100644
--- a/tests/tcg/Makefile
+++ b/tests/tcg/Makefile
@@ -89,7 +89,7 @@  hello-i386: hello-i386.c
 	strip $@
 
 testthread: testthread.c
-	$(CC_I386) $(CFLAGS) $(LDFLAGS) -o $@ $< -lpthread
+	$(CC_I386) $(QEMU_INCLUDES) $(CFLAGS) $(LDFLAGS) -o $@ $< -lpthread
 
 # i386/x86_64 emulation test (test various opcodes) */
 test-i386: test-i386.c test-i386-code16.S test-i386-vm86.S \
@@ -98,7 +98,7 @@  test-i386: test-i386.c test-i386-code16.S test-i386-vm86.S \
               $(<D)/test-i386.c $(<D)/test-i386-code16.S $(<D)/test-i386-vm86.S -lm
 
 test-i386-fprem: test-i386-fprem.c
-	$(CC_I386) $(QEMU_INCLUDES) $(CFLAGS) $(LDFLAGS) -o $@ $^
+	$(CC_I386) $(QEMU_INCLUDES) $(GLIB_CFLAGS) $(CFLAGS) $(LDFLAGS) -o $@ $^
 
 test-x86_64: test-i386.c \
            test-i386.h test-i386-shift.h test-i386-muldiv.h
@@ -106,7 +106,7 @@  test-x86_64: test-i386.c \
 
 # generic Linux and CPU test
 linux-test: linux-test.c
-	$(CC_I386) $(CFLAGS) $(LDFLAGS) -o $@ $< -lm
+	$(CC_I386) $(QEMU_INCLUDES) $(GLIB_CFLAGS) $(CFLAGS) $(LDFLAGS) -o $@ $< -lm
 
 # vm86 test
 runcom: runcom.c
diff --git a/tests/tcg/linux-test.c b/tests/tcg/linux-test.c
index 5070d31..173214d 100644
--- a/tests/tcg/linux-test.c
+++ b/tests/tcg/linux-test.c
@@ -16,6 +16,9 @@ 
  *  You should have received a copy of the GNU General Public License
  *  along with this program; if not, see <http://www.gnu.org/licenses/>.
  */
+
+#include "qemu/osdep.h"
+
 #define _GNU_SOURCE
 #include <stdarg.h>
 #include <stdlib.h>
@@ -31,6 +34,7 @@ 
 #include <utime.h>
 #include <time.h>
 #include <sys/time.h>
+#include <sys/resource.h>
 #include <sys/uio.h>
 #include <sys/socket.h>
 #include <netinet/in.h>