Re: [Qemu-devel] [PATCH v2 4/4] qemu-iotests: Check common namespace for id and node-name

2014-04-21 Thread Fam Zheng
On Thu, 04/17 17:48, Kevin Wolf wrote:
> A name that is taken by an ID can't be taken by a node-name at the same
> time. Check that conflicts are correctly detected.
> 
> Signed-off-by: Kevin Wolf 
> ---
>  tests/qemu-iotests/087 | 52 
> ++
>  tests/qemu-iotests/087.out |  5 +
>  2 files changed, 57 insertions(+)
> 
>  
> diff --git a/tests/qemu-iotests/087.out b/tests/qemu-iotests/087.out
> index 479bf86..7fbee3f 100644
> --- a/tests/qemu-iotests/087.out
> +++ b/tests/qemu-iotests/087.out
> @@ -20,6 +20,11 @@ QMP_VERSION
>  {"return": {}}
>  {"return": {}}
>  {"error": {"class": "GenericError", "desc": "Device with id 'disk' already 
> exists"}}
> +{"error": {"class": "GenericError", "desc": "Device with node-name 
> 'test-node' already exists"}}
> +main-loop: WARNING: I/O thread spun for 1000 iterations

Is this warning message deterministic? I think we could avoid the guest code by
'-machine accel=qtest'.

BTW I intended to write a patch for this but it would have some overlap with
Jeff's qemu-iotests common.qemu series:

https://lists.gnu.org/archive/html/qemu-devel/2014-04/msg01733.html

Fam

> +{"error": {"class": "GenericError", "desc": "could not open disk image 
> disk2: node-name=disk is conflicting with a device id"}}
> +{"error": {"class": "GenericError", "desc": "could not open disk image 
> disk2: Duplicate node name"}}
> +{"error": {"class": "GenericError", "desc": "could not open disk image 
> disk3: node-name=disk3 is conflicting with a device id"}}
>  {"return": {}}
>  {"timestamp": {"seconds":  TIMESTAMP, "microseconds":  TIMESTAMP}, "event": 
> "SHUTDOWN"}
>  {"timestamp": {"seconds":  TIMESTAMP, "microseconds":  TIMESTAMP}, "event": 
> "DEVICE_TRAY_MOVED", "data": {"device": "ide1-cd0", "tray-open": true}}
> -- 
> 1.8.3.1
> 
> 



Re: [Qemu-devel] [PATCH v5] target-ppc: ppc64 target's virtio can be either endian

2014-04-21 Thread Alexander Graf


> Am 21.04.2014 um 06:16 schrieb Bharata B Rao :
> 
>> On Mon, Apr 14, 2014 at 5:42 PM, Greg Kurz  wrote:
>> 
>> +
>> +#if !defined(CONFIG_USER_ONLY)
>> +bool virtio_is_big_endian(void)
>> +{
>> +PowerPCCPU *cp = POWERPC_CPU(first_cpu);
>> +CPUPPCState *env = &cp->env;
>> +
>> +/* NOTE: booke uses the same number for another unrelated spr.
>> + */
>> +if (strcmp(env->spr_cb[SPR_LPCR].name, "LPCR")) {
>> +return TARGET_WORDS_BIGENDIAN;
>> +} else {
>> +return !(env->spr[SPR_LPCR] & LPCR_ILE);
>> +}
>> +}
>> +#endif
> 
> I am adding crash support for little endian ppc64 guests and I realized that 
> the above code needs to be re-used in 
> target-ppc/arch_dump.c:cpu_get_dump_info() to set the endianness.

Wouldn't it make more sense to treat dumps like gdb and set the endianness 
depending on MSR_LE?

Alex

> 
> Do you think it is worth to have this routine as a generic routine to 
> determine endianness so that subsystems other than virtio can reuse the same ?
> 
> Regards,
> Bharata.


Re: [Qemu-devel] [PATCH v5] target-ppc: ppc64 target's virtio can be either endian

2014-04-21 Thread Bharata B Rao
On Mon, Apr 21, 2014 at 1:26 PM, Alexander Graf  wrote:

>
>
> Am 21.04.2014 um 06:16 schrieb Bharata B Rao :
>
> On Mon, Apr 14, 2014 at 5:42 PM, Greg Kurz wrote:
>
>>
>> +
>> +#if !defined(CONFIG_USER_ONLY)
>> +bool virtio_is_big_endian(void)
>> +{
>> +PowerPCCPU *cp = POWERPC_CPU(first_cpu);
>> +CPUPPCState *env = &cp->env;
>> +
>> +/* NOTE: booke uses the same number for another unrelated spr.
>> + */
>> +if (strcmp(env->spr_cb[SPR_LPCR].name, "LPCR")) {
>> +return TARGET_WORDS_BIGENDIAN;
>> +} else {
>> +return !(env->spr[SPR_LPCR] & LPCR_ILE);
>> +}
>> +}
>> +#endif
>>
>
> I am adding crash support for little endian ppc64 guests and I realized
> that the above code needs to be re-used in
> target-ppc/arch_dump.c:cpu_get_dump_info() to set the endianness.
>
>
> Wouldn't it make more sense to treat dumps like gdb and set the endianness
> depending on MSR_LE?
>

Since we are talking about guest system dumps here and going by what Ben
says here (http://article.gmane.org/gmane.comp.emulators.qemu/227201), it
appears that using LPCR_ILE would be appropriate.

Regards,
Bharata.


[Qemu-devel] [PATCH] libcacard: actually use the symbols file

2014-04-21 Thread Michael Tokarev
libtool has an argument for .syms file, which is -export-symbols.
There's no argument `-export-syms', and it looks like at least on
linux, -export-syms is just ignored.  Use the correct argument,
-export-symbols, to actually get the right export list.

Signed-off-by: Michael Tokarev 
---
 libcacard/Makefile |2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libcacard/Makefile b/libcacard/Makefile
index 6b06448..ca08991 100644
--- a/libcacard/Makefile
+++ b/libcacard/Makefile
@@ -24,7 +24,7 @@ vscclient$(EXESUF): libcacard/vscclient.o libcacard.la
 # Rules for building libcacard standalone library
 
 libcacard.la: LDFLAGS += -rpath $(libdir) -no-undefined \
-   -export-syms $(SRC_PATH)/libcacard/libcacard.syms
+   -export-symbols $(SRC_PATH)/libcacard/libcacard.syms
 libcacard.la: LIBS = $(libcacard_libs)
 libcacard.la: $(libcacard-lobj-y)
$(call LINK,$^)
-- 
1.7.10.4




Re: [Qemu-devel] [PATCH] libcacard: actually use the symbols file

2014-04-21 Thread Michael Tokarev
21.04.2014 13:01, Michael Tokarev wrote:
> libtool has an argument for .syms file, which is -export-symbols.
> There's no argument `-export-syms', and it looks like at least on
> linux, -export-syms is just ignored.  Use the correct argument,
> -export-symbols, to actually get the right export list.

Note: with this patch applied, linking vscclient fails due to the
following symbols missing:

qemu_mutex_lock
qemu_mutex_unlock
qemu_cond_wait
qemu_cond_signal
qemu_thread_create
socket_init
qemu_socket
qemu_mutex_init
qemu_cond_init

So it looks like a preparation patch is needed before this one, to
ensure bisectability.

Should those symbols be exported by libcacard (hence listed in the
.syms file), or should vscclient link line use more objects?

Thanks,

/mjt

> Signed-off-by: Michael Tokarev 
> ---
>  libcacard/Makefile |2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/libcacard/Makefile b/libcacard/Makefile
> index 6b06448..ca08991 100644
> --- a/libcacard/Makefile
> +++ b/libcacard/Makefile
> @@ -24,7 +24,7 @@ vscclient$(EXESUF): libcacard/vscclient.o libcacard.la
>  # Rules for building libcacard standalone library
>  
>  libcacard.la: LDFLAGS += -rpath $(libdir) -no-undefined \
> - -export-syms $(SRC_PATH)/libcacard/libcacard.syms
> + -export-symbols $(SRC_PATH)/libcacard/libcacard.syms
>  libcacard.la: LIBS = $(libcacard_libs)
>  libcacard.la: $(libcacard-lobj-y)
>   $(call LINK,$^)
> 




Re: [Qemu-devel] [PATCH v5] target-ppc: ppc64 target's virtio can be either endian

2014-04-21 Thread Greg Kurz
On Mon, 21 Apr 2014 09:46:59 +0530
Bharata B Rao  wrote:
> On Mon, Apr 14, 2014 at 5:42 PM, Greg Kurz  wrote:
> 
> >
> > +
> > +#if !defined(CONFIG_USER_ONLY)
> > +bool virtio_is_big_endian(void)
> > +{
> > +PowerPCCPU *cp = POWERPC_CPU(first_cpu);
> > +CPUPPCState *env = &cp->env;
> > +
> > +/* NOTE: booke uses the same number for another unrelated spr.
> > + */
> > +if (strcmp(env->spr_cb[SPR_LPCR].name, "LPCR")) {
> > +return TARGET_WORDS_BIGENDIAN;
> > +} else {
> > +return !(env->spr[SPR_LPCR] & LPCR_ILE);
> > +}
> > +}
> > +#endif
> >
> 
> I am adding crash support for little endian ppc64 guests and I realized
> that the above code needs to be re-used in
> target-ppc/arch_dump.c:cpu_get_dump_info() to set the endianness.
> 
> Do you think it is worth to have this routine as a generic routine to
> determine endianness so that subsystems other than virtio can reuse the
> same ?
> 

Hi Bharata,

I had comments on this patch that I have addressed, I shall send an update
shortly (function will be a CPU object method and, most important,
we will rely on current_cpu). So I guess you should not use the code
above.

> Regards,
> Bharata.
> 

Regards.

-- 
Gregory Kurz kurzg...@fr.ibm.com
 gk...@linux.vnet.ibm.com
Software Engineer @ IBM/Meiosys  http://www.ibm.com
Tel +33 (0)562 165 496

"Anarchy is about taking complete responsibility for yourself."
Alan Moore.




Re: [Qemu-devel] [PATCH v5] target-ppc: ppc64 target's virtio can be either endian

2014-04-21 Thread Alexander Graf


> Am 21.04.2014 um 10:55 schrieb Bharata B Rao :
> 
>> On Mon, Apr 21, 2014 at 1:26 PM, Alexander Graf  wrote:
>> 
>> 
>>> Am 21.04.2014 um 06:16 schrieb Bharata B Rao :
>>> 
>> 
 On Mon, Apr 14, 2014 at 5:42 PM, Greg Kurz  
 wrote:
 
 +
 +#if !defined(CONFIG_USER_ONLY)
 +bool virtio_is_big_endian(void)
 +{
 +PowerPCCPU *cp = POWERPC_CPU(first_cpu);
 +CPUPPCState *env = &cp->env;
 +
 +/* NOTE: booke uses the same number for another unrelated spr.
 + */
 +if (strcmp(env->spr_cb[SPR_LPCR].name, "LPCR")) {
 +return TARGET_WORDS_BIGENDIAN;
 +} else {
 +return !(env->spr[SPR_LPCR] & LPCR_ILE);
 +}
 +}
 +#endif
>>> 
>>> I am adding crash support for little endian ppc64 guests and I realized 
>>> that the above code needs to be re-used in 
>>> target-ppc/arch_dump.c:cpu_get_dump_info() to set the endianness.
>> 
>> Wouldn't it make more sense to treat dumps like gdb and set the endianness 
>> depending on MSR_LE?
> 
> Since we are talking about guest system dumps here and going by what Ben says 
> here (http://article.gmane.org/gmane.comp.emulators.qemu/227201), it appears 
> that using LPCR_ILE would be appropriate.

Take the example that Ben raised - lx86 on be. When you create a dump, do you 
want to analyze lx86 or Linux beneath? For virtio the answer is easy. For crash 
dumps not so much.

I think the most sensible thing to do is to base on msr_le and allow the user 
to override our clever decision. If you feel strongly for the ILE approach, I 
won't refuse that either though.

That said, in case you do want to go with the ILE approach, make sure you don't 
call the *virtio specific* cpu callback and that you stay compatible with 
non-ibm cpus.


Alex



Re: [Qemu-devel] [PATCH RFC] ps2: set the keybord output buffer size as the same as kernel

2014-04-21 Thread Gonglei (Arei)
Hi,

> -Original Message-
> From: Gonglei (Arei)
> Sent: Thursday, April 17, 2014 9:16 PM
> To: qemu-devel@nongnu.org
> Cc: kra...@redhat.com; aligu...@amazon.com; Huangweidong (C); Gonglei
> (Arei)
> Subject: [PATCH RFC] ps2: set the keybord output buffer size as the same as
> kernel
> 
> From: Gonglei 
> 
> According to the PS/2 Mouse/Keyboard Protocol, the keyboard outupt buffer
> size
> is 16 bytes. And the PS2_QUEUE_SIZE 256 was introduced in Qemu from the
> very
> beginning.
> 
> When I started a  redhat5.6 32bit guest, meanwhile tapped the keyboard as
> quickly as
> possible, the screen would show me "i8042.c: No controller found". As a 
> result,
> I couldn't use the keyboard in the VNC client.
> 
> Previous discussion about the issue in maillist:
> http://thread.gmane.org/gmane.comp.emulators.qemu/43294/focus=47180
> 
> This patch has been tested on redhat5.6 32-bit/suse11sp3 64-bit guests.
> More easy meathod to reproduce:
> 1.boot a guest with libvirt.
> 2.connect to VNC client.
> 3.as you see the BIOS, bootloader, Linux booting, run the follow simply shell
> script:
> for((i=0;i<1000;i++)) do virsh send-key redhat5.6 KEY_A; done
> 
> Actual results:
> dmesg show "i8042.c: No controller found." And the keyboard is out of work.
> 
> Signed-off-by: Gonglei 
> ---
>  hw/input/ps2.c |6 +++---
>  1 files changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/hw/input/ps2.c b/hw/input/ps2.c
> index 3412079..a754fef 100644
> --- a/hw/input/ps2.c
> +++ b/hw/input/ps2.c
> @@ -71,7 +71,7 @@
>  #define MOUSE_STATUS_ENABLED0x20
>  #define MOUSE_STATUS_SCALE210x10
> 
> -#define PS2_QUEUE_SIZE 256
> +#define PS2_QUEUE_SIZE 16 /* Keyboard output buffer size */
> 
>  typedef struct {
>  uint8_t data[PS2_QUEUE_SIZE];
> @@ -137,7 +137,7 @@ void ps2_queue(void *opaque, int b)
>  PS2State *s = (PS2State *)opaque;
>  PS2Queue *q = &s->queue;
> 
> -if (q->count >= PS2_QUEUE_SIZE)
> +if (q->count >= PS2_QUEUE_SIZE - 1)
>  return;
>  q->data[q->wptr] = b;
>  if (++q->wptr == PS2_QUEUE_SIZE)
> @@ -375,7 +375,7 @@ static void ps2_mouse_event(void *opaque,
>  }
> 
>  if (!(s->mouse_status & MOUSE_STATUS_REMOTE) &&
> -(s->common.queue.count < (PS2_QUEUE_SIZE - 16))) {
> +(s->common.queue.count < PS2_QUEUE_SIZE)) {
>  for(;;) {
>  /* if not remote, send event. Multiple events are sent if
> too big deltas */
> --
> 1.6.0.2
> 

Ping...
Any comments will be appreciated.


Best regards,
-Gonglei



Re: [Qemu-devel] [PATCH v5] target-ppc: ppc64 target's virtio can be either endian

2014-04-21 Thread Greg Kurz
On Mon, 21 Apr 2014 09:56:48 +0200
Alexander Graf  wrote:

> 
> 
> > Am 21.04.2014 um 06:16 schrieb Bharata B Rao :
> > 
> >> On Mon, Apr 14, 2014 at 5:42 PM, Greg Kurz  
> >> wrote:
> >> 
> >> +
> >> +#if !defined(CONFIG_USER_ONLY)
> >> +bool virtio_is_big_endian(void)
> >> +{
> >> +PowerPCCPU *cp = POWERPC_CPU(first_cpu);
> >> +CPUPPCState *env = &cp->env;
> >> +
> >> +/* NOTE: booke uses the same number for another unrelated spr.
> >> + */
> >> +if (strcmp(env->spr_cb[SPR_LPCR].name, "LPCR")) {
> >> +return TARGET_WORDS_BIGENDIAN;
> >> +} else {
> >> +return !(env->spr[SPR_LPCR] & LPCR_ILE);
> >> +}
> >> +}
> >> +#endif
> > 
> > I am adding crash support for little endian ppc64 guests and I realized 
> > that the above code needs to be re-used in 
> > target-ppc/arch_dump.c:cpu_get_dump_info() to set the endianness.
> 
> Wouldn't it make more sense to treat dumps like gdb and set the endianness 
> depending on MSR_LE?
> 
> Alex
> 

It makes sense to behave the same as gdb... and BTW, since the guest may
change endianness, we could possibly have MSB and LSB data in the dump. The
important thing is to have the possibility to adapt endianness to what we are
looking (like set target endian in gdb).

> > 
> > Do you think it is worth to have this routine as a generic routine to 
> > determine endianness so that subsystems other than virtio can reuse the 
> > same ?
> > 
> > Regards,
> > Bharata.



-- 
Gregory Kurz kurzg...@fr.ibm.com
 gk...@linux.vnet.ibm.com
Software Engineer @ IBM/Meiosys  http://www.ibm.com
Tel +33 (0)562 165 496

"Anarchy is about taking complete responsibility for yourself."
Alan Moore.




Re: [Qemu-devel] [PATCH v3 3/4] pc & q35: Add new object pc-memory-layout.

2014-04-21 Thread Paolo Bonzini

Il 24/03/2014 19:55, Don Slutz ha scritto:

This new object has the property max-ram-below-4g.

If you add enough PCI devices then all mmio for them will not fit
below 4G which may not be the layout the user wanted. This allows
you to increase the below 4G address space that PCI devices can use
(aka decrease ram below 4G) and therefore in more cases not have any
mmio that is above 4G.

For example adding "-global pc-memory-layout.max-ram-below-4g=2G" to
the command line will limit the amount of ram that is below 4G to
2G.


Does Xen's firmware allow 64-bit BARs?  I'm wondering why this is not a 
problem on KVM.


Also, overloading -global like this isn't the best long term choice.  We 
should get custom -machine properties in 2.1, we should use them.


Paolo



[Qemu-devel] [Bug 1308542] Re: hang in qemu_gluster_init

2014-04-21 Thread John Eckersberg
Also I should add a note to this related bug I filed against gluster -
https://bugzilla.redhat.com/show_bug.cgi?id=1088589

This bug is what causes the glfs_set_logging call to fail, and fall into
the hang case.

** Bug watch added: Red Hat Bugzilla #1088589
   https://bugzilla.redhat.com/show_bug.cgi?id=1088589

-- 
You received this bug notification because you are a member of qemu-
devel-ml, which is subscribed to QEMU.
https://bugs.launchpad.net/bugs/1308542

Title:
  hang in qemu_gluster_init

Status in QEMU:
  New

Bug description:
  In qemu_gluster_init, if the call to either glfs_set_volfile_server or
  glfs_set_logging fails into the "out" case, glfs_fini is called
  without having first calling glfs_init.  This causes glfs_lock to spin
  forever on this bit:

while (!fs->init)
pthread_cond_wait (&fs->cond, &fs->mutex);

  And here's the bottom part of the backtrace when hung:

  #0  pthread_cond_wait@@GLIBC_2.3.2 () at 
../nptl/sysdeps/unix/sysv/linux/x86_64/pthread_cond_wait.S:183
  #1  0x7feceebf58c3 in glfs_lock (fs=0x7fecf15660b0) at glfs-internal.h:156
  #2  glfs_active_subvol (fs=0x7fecf15660b0) at glfs-resolve.c:799
  #3  0x7feceebeb5b4 in glfs_fini (fs=0x7fecf15660b0) at glfs.c:652
  #4  0x7fecf0043c73 in qemu_gluster_init (gconf=, 
filename=) at 
/usr/src/debug/qemu-kvm-0.12.1.2/block/gluster.c:229

  I believe this can be fixed by simply moving the call to glfs_init
  after the call to glfs_new but before the calls to
  glfs_set_volfile_server or glfs_set_logging.

To manage notifications about this bug go to:
https://bugs.launchpad.net/qemu/+bug/1308542/+subscriptions



Re: [Qemu-devel] [Bug 1310324] [NEW] Commit 0f842f8a introduces regression when using tcg-interpreter

2014-04-21 Thread Stefan Weil
Am 20.04.2014 19:19, schrieb Giovanni Mascellani:
> Public bug reported:
> 
> Hi.
> 
> Commit 0f842f8a246f2b5b51a11c13f933bf7a90ae8e96 apparently introduces a
> regression when using --enable-tcg-interpreter. The regression is
> manifested as follows:
> 

That commit changed the use of the GETPC macro. I just tried to debug
the tci.c code and noticed that cputlb.c no longer works as expected:

That file redefines GETPC before including exec/softmmu_template.h. This
redefinition is no longer used because the included file now uses
GETPC_ADJ und GETRA.

This is not specific for the TCG interpreter, but I don't know how the
normal TCG is affected.

I also noticed that other code like target-i386/seg_helper.c which
includes exec/softmmu_template.h also results in undefined usage of the
GETRA macro.

Richard, I used the appended patch to debug this problem. It raises an
assertion whenever GETRA is used outside of tcg_qemu_tb_exec loop.

Regards
Stefan


diff --git a/cputlb.c b/cputlb.c
index 7bd3573..98ccc86 100644
--- a/cputlb.c
+++ b/cputlb.c
@@ -331,8 +331,8 @@ tb_page_addr_t get_page_addr_code(CPUArchState *env1, 
target_ulong addr)
 }
 
 #define MMUSUFFIX _cmmu
-#undef GETPC
-#define GETPC() ((uintptr_t)0)
+#undef GETRA
+#define GETRA() ((uintptr_t)0)
 #define SOFTMMU_CODE_ACCESS
 
 #define SHIFT 0
diff --git a/include/exec/exec-all.h b/include/exec/exec-all.h
index f9ac332..9a806a0 100644
--- a/include/exec/exec-all.h
+++ b/include/exec/exec-all.h
@@ -301,7 +301,8 @@ static inline void tb_add_jump(TranslationBlock *tb, int n,
defined here for simplicity of defining the follow-up macros.  */
 #if defined(CONFIG_TCG_INTERPRETER)
 extern uintptr_t tci_tb_ptr;
-# define GETRA() tci_tb_ptr
+extern uintptr_t GETRA(void);
+//~ # define GETRA() tci_tb_ptr
 #else
 # define GETRA() \
 ((uintptr_t)__builtin_extract_return_addr(__builtin_return_address(0)))
@@ -314,11 +315,7 @@ extern uintptr_t tci_tb_ptr;
to indicate the compressed mode; subtracting two works around that.  It
is also the case that there are no host isas that contain a call insn
smaller than 4 bytes, so we don't worry about special-casing this.  */
-#if defined(CONFIG_TCG_INTERPRETER)
-# define GETPC_ADJ   0
-#else
-# define GETPC_ADJ   2
-#endif
+#define GETPC_ADJ   2
 
 #define GETPC()  (GETRA() - GETPC_ADJ)
 
diff --git a/tci.c b/tci.c
index 0202ed9..2637cc8 100644
--- a/tci.c
+++ b/tci.c
@@ -53,9 +53,19 @@ typedef uint64_t (*helper_function)(tcg_target_ulong, 
tcg_target_ulong,
 
 /* Targets which don't use GETPC also don't need tci_tb_ptr
which makes them a little faster. */
-#if defined(GETPC)
 uintptr_t tci_tb_ptr;
+uintptr_t GETRA(void)
+{
+  assert(tci_tb_ptr != 0);
+  return tci_tb_ptr;
+}
+
+static inline void savepc(void *tb_ptr)
+{
+#ifdef CONFIG_SOFTMMU
+tci_tb_ptr = (uintptr_t)tb_ptr;
 #endif
+}
 
 static tcg_target_ulong tci_reg[TCG_TARGET_NB_REGS];
 
@@ -467,9 +477,7 @@ uintptr_t tcg_qemu_tb_exec(CPUArchState *env, uint8_t 
*tb_ptr)
 uint64_t v64;
 #endif
 
-#if defined(GETPC)
-tci_tb_ptr = (uintptr_t)tb_ptr;
-#endif
+tci_tb_ptr = 0;
 
 /* Skip opcode and size entry. */
 tb_ptr += 2;
@@ -489,6 +497,7 @@ uintptr_t tcg_qemu_tb_exec(CPUArchState *env, uint8_t 
*tb_ptr)
 TODO();
 break;
 case INDEX_op_call:
+tci_tb_ptr = (uintptr_t)tb_ptr;
 t0 = tci_read_ri(&tb_ptr);
 #if TCG_TARGET_REG_BITS == 32
 tmp64 = ((helper_function)t0)(tci_read_reg(TCG_REG_R0),
@@ -1087,6 +1096,7 @@ uintptr_t tcg_qemu_tb_exec(CPUArchState *env, uint8_t 
*tb_ptr)
 tb_ptr += (int32_t)t0;
 continue;
 case INDEX_op_qemu_ld8u:
+savepc(tb_ptr);
 t0 = *tb_ptr++;
 taddr = tci_read_ulong(&tb_ptr);
 #ifdef CONFIG_SOFTMMU
@@ -1098,6 +1108,7 @@ uintptr_t tcg_qemu_tb_exec(CPUArchState *env, uint8_t 
*tb_ptr)
 tci_write_reg8(t0, tmp8);
 break;
 case INDEX_op_qemu_ld8s:
+savepc(tb_ptr);
 t0 = *tb_ptr++;
 taddr = tci_read_ulong(&tb_ptr);
 #ifdef CONFIG_SOFTMMU
@@ -1109,6 +1120,7 @@ uintptr_t tcg_qemu_tb_exec(CPUArchState *env, uint8_t 
*tb_ptr)
 tci_write_reg8s(t0, tmp8);
 break;
 case INDEX_op_qemu_ld16u:
+savepc(tb_ptr);
 t0 = *tb_ptr++;
 taddr = tci_read_ulong(&tb_ptr);
 #ifdef CONFIG_SOFTMMU
@@ -1120,6 +1132,7 @@ uintptr_t tcg_qemu_tb_exec(CPUArchState *env, uint8_t 
*tb_ptr)
 tci_write_reg16(t0, tmp16);
 break;
 case INDEX_op_qemu_ld16s:
+savepc(tb_ptr);
 t0 = *tb_ptr++;
 taddr = tci_read_ulong(&tb_ptr);
 #ifdef CONFIG_SOFTMMU
@@ -1132,6 +1145,7 @@ uintptr_t tcg_qemu_tb_exec(CPUArchState *env, uint8_t 
*tb_ptr)
 break;
 #if TCG_TARGET_REG_BITS == 64
 case INDEX_op_qemu_ld32u:
+savepc(tb_ptr);
 t0 = *tb_ptr++;
 taddr =

[Qemu-devel] [PATCH 013/124] vmstate: Remove VMSTATE_UINTL_EQUAL_V

2014-04-21 Thread Juan Quintela
It was not used anywhere.

Signed-off-by: Juan Quintela 
---
 include/hw/hw.h | 10 --
 1 file changed, 4 insertions(+), 6 deletions(-)

diff --git a/include/hw/hw.h b/include/hw/hw.h
index 33bdb92..2b68ac3 100644
--- a/include/hw/hw.h
+++ b/include/hw/hw.h
@@ -51,22 +51,20 @@ int qemu_boot_set(const char *boot_order);
 #if TARGET_LONG_BITS == 64
 #define VMSTATE_UINTTL_V(_f, _s, _v)  \
 VMSTATE_UINT64_V(_f, _s, _v)
-#define VMSTATE_UINTTL_EQUAL_V(_f, _s, _v)\
-VMSTATE_UINT64_EQUAL_V(_f, _s, _v)
+#define VMSTATE_UINTTL_EQUAL(_f, _s)  \
+VMSTATE_UINT64_EQUAL(_f, _s)
 #define VMSTATE_UINTTL_ARRAY_V(_f, _s, _n, _v)\
 VMSTATE_UINT64_ARRAY_V(_f, _s, _n, _v)
 #else
 #define VMSTATE_UINTTL_V(_f, _s, _v)  \
 VMSTATE_UINT32_V(_f, _s, _v)
-#define VMSTATE_UINTTL_EQUAL_V(_f, _s, _v)\
-VMSTATE_UINT32_EQUAL_V(_f, _s, _v)
+#define VMSTATE_UINTTL_EQUAL(_f, _s)  \
+VMSTATE_UINT32_EQUAL(_f, _s)
 #define VMSTATE_UINTTL_ARRAY_V(_f, _s, _n, _v)\
 VMSTATE_UINT32_ARRAY_V(_f, _s, _n, _v)
 #endif
 #define VMSTATE_UINTTL(_f, _s)\
 VMSTATE_UINTTL_V(_f, _s, 0)
-#define VMSTATE_UINTTL_EQUAL(_f, _s)  \
-VMSTATE_UINTTL_EQUAL_V(_f, _s, 0)
 #define VMSTATE_UINTTL_ARRAY(_f, _s, _n)  \
 VMSTATE_UINTTL_ARRAY_V(_f, _s, _n, 0)

-- 
1.9.0




[Qemu-devel] [PATCH 001/124] savevm: Ignore minimum_version_id_old if there is no load_state_old

2014-04-21 Thread Juan Quintela
From: Peter Maydell 

At the moment we require vmstate definitions to set minimum_version_id_old
to the same value as minimum_version_id if they do not provide a
load_state_old handler. Since the load_state_old functionality is
required only for a handful of devices that need to retain migration
compatibility with a pre-vmstate implementation, this means the bulk
of devices have pointless boilerplate. Relax the definition so that
minimum_version_id_old is ignored if there is no load_state_old handler.

Note that under the old scheme we would segfault if the vmstate
specified a minimum_version_id_old that was less than minimum_version_id
but did not provide a load_state_old function, and the incoming state
specified a version number between minimum_version_id_old and
minimum_version_id. Under the new scheme this will just result in
our failing the migration.

Signed-off-by: Peter Maydell 
Reviewed-by: Michael S. Tsirkin 
Signed-off-by: Michael S. Tsirkin 
Signed-off-by: Juan Quintela 
---
 docs/migration.txt | 12 +---
 vmstate.c  |  9 +
 2 files changed, 10 insertions(+), 11 deletions(-)

diff --git a/docs/migration.txt b/docs/migration.txt
index 0e0a1d4..fe1f2bb 100644
--- a/docs/migration.txt
+++ b/docs/migration.txt
@@ -139,7 +139,6 @@ static const VMStateDescription vmstate_kbd = {
 .name = "pckbd",
 .version_id = 3,
 .minimum_version_id = 3,
-.minimum_version_id_old = 3,
 .fields  = (VMStateField []) {
 VMSTATE_UINT8(write_cmd, KBDState),
 VMSTATE_UINT8(status, KBDState),
@@ -168,12 +167,13 @@ You can see that there are several version fields:
 - minimum_version_id: the minimum version_id that VMState is able to understand
   for that device.
 - minimum_version_id_old: For devices that were not able to port to vmstate, 
we can
-  assign a function that knows how to read this old state.
+  assign a function that knows how to read this old state. This field is
+  ignored if there is no load_state_old handler.

 So, VMState is able to read versions from minimum_version_id to
-version_id.  And the function load_state_old() is able to load state
-from minimum_version_id_old to minimum_version_id.  This function is
-deprecated and will be removed when no more users are left.
+version_id.  And the function load_state_old() (if present) is able to
+load state from minimum_version_id_old to minimum_version_id.  This
+function is deprecated and will be removed when no more users are left.

 ===  Massaging functions ===

@@ -255,7 +255,6 @@ const VMStateDescription vmstate_ide_drive_pio_state = {
 .name = "ide_drive/pio_state",
 .version_id = 1,
 .minimum_version_id = 1,
-.minimum_version_id_old = 1,
 .pre_save = ide_drive_pio_pre_save,
 .post_load = ide_drive_pio_post_load,
 .fields  = (VMStateField []) {
@@ -275,7 +274,6 @@ const VMStateDescription vmstate_ide_drive = {
 .name = "ide_drive",
 .version_id = 3,
 .minimum_version_id = 0,
-.minimum_version_id_old = 0,
 .post_load = ide_drive_post_load,
 .fields  = (VMStateField []) {
  several fields 
diff --git a/vmstate.c b/vmstate.c
index b689f2f..bfa34cc 100644
--- a/vmstate.c
+++ b/vmstate.c
@@ -19,11 +19,12 @@ int vmstate_load_state(QEMUFile *f, const 
VMStateDescription *vmsd,
 if (version_id > vmsd->version_id) {
 return -EINVAL;
 }
-if (version_id < vmsd->minimum_version_id_old) {
-return -EINVAL;
-}
 if  (version_id < vmsd->minimum_version_id) {
-return vmsd->load_state_old(f, opaque, version_id);
+if (vmsd->load_state_old &&
+version_id >= vmsd->minimum_version_id_old) {
+return vmsd->load_state_old(f, opaque, version_id);
+}
+return -EINVAL;
 }
 if (vmsd->pre_load) {
 int ret = vmsd->pre_load(opaque);
-- 
1.9.0




[Qemu-devel] [PATCH v2 000/124] VMState Simplification (Massive)

2014-04-21 Thread Juan Quintela
Merge remote-tracking branch 
'remotes/pmaydell/tags/pull-target-arm-20140417-1' into staging (2014-04-17 
21:37:26 +0100)

are available in the git repository at:


  git://github.com/juanquintela/qemu.git tags/vmstate-simplification/20140421

for you to fetch changes up to d587ef5f4657c9c6ba26fe27fc2d78a0d051e30f:

  vmstate: Test for VMSTATE_ARRAY_OF_POINTER (2014-04-21 16:31:22 +0200)

----
vmstate-simplification/next for 20140421


Juan Quintela (121):
  savevm: Remove all the unneded version_minimum_id_old (usb)
  savevm: Remove all the unneded version_minimum_id_old (ppc)
  savevm: Remove all the unneded version_minimum_id_old (arm)
  savevm: Remove all the unneded version_minimum_id_old (x86)
  savevm: Remove all the unneded version_minimum_id_old (rest)
  vmstate: Return error in case of error
  vmstate: Refactor opening of files
  vmstate: Refactor & increase tests for primitive types
  vmstate: Port versioned tests to new format
  vmstate: Create test functions for versions until 15
  vmstate: Remove VMSTATE_UINTL_EQUAL_V
  vmstate: Change VMSTATE_INTTL_V to VMSTATE_INTTL_TEST
  vmstate: Remove unused VMSTATE_UINTTL_ARRAY_V
  vmstate: Test for VMSTATE_BOOL_TEST
  vmstate: Test for VMSTATE_INT8_TEST
  vmstate: Test for VMSTATE_INT16_TEST
  vmstate: Test for VMSTATE_INT32_TEST
  vmstate: test for VMSTATE_INT64_TEST
  vmstate: Test for VMSTATE_UINT8_TEST
  vmstate: Test for VMSTATE_UINT16_TEST
  vmstate: Test for VMSTATE_UINT32_TEST
  vmstate: Test for VMSTATE_UINT64_TEST
  vmstate: Test for VMSTATE_FLOAT64
  vmstate: Test for VMSTATE_UNUSED
  vmstate: Test for VMSTATE_BITMAP
  vmstate: Test for VMSTATE_UINT8_EQUAL
  vmstate: Test for VMSTATE_UINT16_EQUAL
  vmstate: Test for VMSTATE_UINT32_EQUAL
  vmstate: Test for VMSTATE_UINT64_EQUAL
  vmstate: Test for VMSTATE_INT32_EQUAL
  vmstate: Test for VMSTATE_INT32_LE
  vmstate: Move VMSTATE_TIMER_V to VMSTATE_TIMER_TEST
  vmstate: Test for VMSTATE_ARRAY_BOOL_TEST
  vmstate: Test for VMSTATE_UINT8_ARRAY
  vmstate: Test for VMSTATE_UINT16_ARRAY
  vmstate: Test for VMSTATE_UINT32_ARRAY{_TEST}
  vmstate: Test for VMSTATE_UINT64_ARRAY{_TEST}
  vmstate: Test for VMSTATE_INT16_ARRAY
  vmstate: Test for VMSTATE_INT32_ARRAY{_TEST}
  vmstate: Test for VMSTATE_INT64_ARRAY
  vmstate: Test for VMSTATE_FLOAT64_ARRAY
  vmstate: Test for VMSTATE_UINT8_2DARRAY
  vmstate: Test for VMSTATE_UINT16_2DARRAY.
  vmstate: Test for VMSTATE_UINT32_2DARRAY
  vmstate: Remove unused VMSTATE_BUFFER_V
  vmstate: Remove version from VMSTATE_BUFFER_UNSAFE
  vmstate: Remove unused version fields from ARM
  vmstate: All ptimers users were at least at version 1 or more
  vmstate: Remove version from all variants of VMSTATE_STRUCT_POINTER*
  vmstate: Port last 3 users of VMSTATE_ARRAY to VMSTATE_ARRAY_TEST
  vmstate: Port last user of VMSTATE_SINGLE to VMSTATE_SINGLE_TEST
  vmstate: Remove unused VMSTATE_POINTER
  vmstate: Rename VMSTATE_SINGLE_TEST to VMSTATE_SINGLE
  vmstate: Move VMSTATE_2DARRAY to use _test
  vmstate: Rename VMSTATE_POINTER_TEST without _TEST
  vmstate: Rename VMSTATE_ARRAY_TEST to VMSTATE_ARRAY
  vmstate: Remove version_id from VMSTATE_VBUFFER
  vmstate: Remove version_id fields that were not used
  vmstate: Remove version_id from VMSTATE_SUB_ARRAY
  vmstate: Remove version parameter from VMSTATE_VARRAY_INT32
  vmstate: Remove version_id from VMSTATE_VARRAY_UINT16_UNSAFE
  vmstate: Remove unused version_id from VMSTATE_ARRAY_OF_POINTER
  vmstate: remove version parameter from VMSTATE_BUFFER_POINTER_UNSAFE
  vmstate: Remove version, test and start parameter from 
VMSTATE_VBUFFER_UINT32
  vmstate: Remove version paramenter from VMSTATE_ARRAY_OF_POINTER_TO_STRUCT
  vmstate: Remove VMSTATE_BUFFER_MULTIPLY
  vmstate: Remove version parameter from VMSTATE_STATIC_BUFFER
  vmstate: Remove version field from VMSTATE_STRUCT_VARRAY_UINT32
  vmstate: Move all users of versioning of VMSTATE_STRUCT_ARRAY to _TEST
  vmstate: Remove version parameter from VMSTATE_STRUCT_ARRAY
  vmstate: Remove version parameter from VMSTATE_STRUCT_ARRAY_TEST
  vmstate: Remove unused version parameter from VMSTATE_STRUCT_VARRAY_INT32
  vmstate: Remove unused version parameter from VMSTATE_STRUCT_VARRAY_UINT8
  vmstate: Introduce VMSTATE_VARRAY_UINT32_TEST
  vmstate: Remove version parameter from VMSTATE_VARRAY_UINT32
  vmstate: Remove version parameter from VMSTATE_STRUCT_TEST
  vmstate: Move all users of versioning to VMSTATE_STRUCT_TEST
  vmstate: Remove version from all VMSTATE_STRUCT calls
  vmstate: Create VMSTATE_VARRAY macro
  vmstate: Create VM

[Qemu-devel] [PATCH 006/124] savevm: Remove all the unneded version_minimum_id_old (rest)

2014-04-21 Thread Juan Quintela
After previous Peter patch, they are redundant.  This way we don't asign them
except when needed.  Once there, there were lots of case where the ".fields"
indentation was wrong:

 .fields = (VMStateField []) {
and
 .fields =  (VMStateField []) {

Change all the combinations to:

 .fields = (VMStateField[]){

The biggest problem (appart of aesthetics) was that checkpatch complained
when we copy&pasted the code from one place to another.

Signed-off-by: Juan Quintela 
---
 audio/audio.c|  3 +--
 cpus.c   |  3 +--
 docs/migration.txt   |  6 +++---
 exec.c   |  3 +--
 hw/audio/milkymist-ac97.c|  3 +--
 hw/block/m25p80.c|  1 -
 hw/char/ipoctal232.c |  9 +++--
 hw/char/lm32_juart.c |  3 +--
 hw/char/lm32_uart.c  |  3 +--
 hw/char/milkymist-uart.c |  3 +--
 hw/char/sclpconsole-lm.c |  3 +--
 hw/char/sclpconsole.c|  3 +--
 hw/core/ptimer.c |  3 +--
 hw/display/cg3.c |  2 +-
 hw/display/g364fb.c  |  1 -
 hw/display/jazz_led.c|  1 -
 hw/display/milkymist-tmu2.c  |  3 +--
 hw/display/milkymist-vgafb.c |  3 +--
 hw/display/tcx.c |  3 +--
 hw/dma/sparc32_dma.c |  3 +--
 hw/dma/sun4m_iommu.c |  3 +--
 hw/i2c/core.c|  6 ++
 hw/i2c/smbus_ich9.c  |  1 -
 hw/ide/core.c| 16 +---
 hw/ide/macio.c   |  3 +--
 hw/ide/microdrive.c  |  3 +--
 hw/ide/mmio.c|  3 +--
 hw/input/adb.c   |  6 ++
 hw/input/milkymist-softusb.c |  3 +--
 hw/intc/lm32_pic.c   |  3 +--
 hw/intc/slavio_intctl.c  |  6 ++
 hw/ipack/ipack.c |  3 +--
 hw/ipack/tpci200.c   |  3 +--
 hw/misc/eccmemctl.c  |  3 +--
 hw/misc/lm32_sys.c   |  3 +--
 hw/misc/macio/cuda.c |  6 ++
 hw/misc/macio/mac_dbdma.c|  6 ++
 hw/misc/milkymist-hpdmc.c|  3 +--
 hw/misc/milkymist-pfpu.c |  3 +--
 hw/misc/slavio_misc.c|  3 +--
 hw/net/lance.c   |  3 +--
 hw/net/milkymist-minimac2.c  |  6 ++
 hw/net/mipsnet.c |  3 +--
 hw/nvram/ds1225y.c   |  1 -
 hw/nvram/mac_nvram.c |  3 +--
 hw/pci-host/bonito.c |  3 +--
 hw/s390x/event-facility.c|  3 +--
 hw/s390x/sclpquiesce.c   |  3 +--
 hw/scsi/esp-pci.c|  1 -
 hw/scsi/esp.c|  4 +---
 hw/sd/milkymist-memcard.c|  3 +--
 hw/sd/sdhci.c|  2 +-
 hw/timer/lm32_timer.c|  3 +--
 hw/timer/milkymist-sysctl.c  |  3 +--
 hw/timer/slavio_timer.c  |  6 ++
 target-alpha/machine.c   |  2 --
 target-lm32/machine.c|  6 ++
 target-moxie/machine.c   |  3 +--
 target-openrisc/machine.c|  2 --
 tests/test-vmstate.c |  9 +++--
 60 files changed, 70 insertions(+), 147 deletions(-)

diff --git a/audio/audio.c b/audio/audio.c
index fc77511..9d018e9 100644
--- a/audio/audio.c
+++ b/audio/audio.c
@@ -1812,8 +1812,7 @@ static const VMStateDescription vmstate_audio = {
 .name = "audio",
 .version_id = 1,
 .minimum_version_id = 1,
-.minimum_version_id_old = 1,
-.fields  = (VMStateField []) {
+.fields = (VMStateField[]) {
 VMSTATE_END_OF_LIST()
 }
 };
diff --git a/cpus.c b/cpus.c
index 1104d61..c510052 100644
--- a/cpus.c
+++ b/cpus.c
@@ -430,8 +430,7 @@ static const VMStateDescription vmstate_timers = {
 .name = "timer",
 .version_id = 2,
 .minimum_version_id = 1,
-.minimum_version_id_old = 1,
-.fields  = (VMStateField[]) {
+.fields = (VMStateField[]) {
 VMSTATE_INT64(cpu_ticks_offset, TimersState),
 VMSTATE_INT64(dummy, TimersState),
 VMSTATE_INT64_V(cpu_clock_offset, TimersState, 2),
diff --git a/docs/migration.txt b/docs/migration.txt
index fe1f2bb..0492a45 100644
--- a/docs/migration.txt
+++ b/docs/migration.txt
@@ -139,7 +139,7 @@ static const VMStateDescription vmstate_kbd = {
 .name = "pckbd",
 .version_id = 3,
 .minimum_version_id = 3,
-.fields  = (VMStateField []) {
+.fields = (VMStateField[]) {
 VMSTATE_UINT8(write_cmd, KBDState),
 VMSTATE_UINT8(status, KBDState),
 VMSTATE_UINT8(mode, KBDState),
@@ -257,7 +257,7 @@ const VMStateDescription vmstate_ide_drive_pio_state = {
 .minimum_version_id = 1,
 .pre_save = ide_drive_pio_pre_save,
 .post_load = ide_drive_pio_post_load,
-.fields  = (VMStateField []) {
+.fields = (VMStateField[]) {
 VMSTATE_INT32(req_nb_sectors, IDEState),
 VMSTATE_VARRAY_INT32(io_buffer, IDEState, io_buffer_total_len, 1,
  vmstate_info_uint8, uint8_t),
@@ -275,7 +275,7 @@ const VMStateDescription vmstate_ide_drive = {
 .version_id = 3,
 .minimum_version_id = 0,
 .post_load = ide_drive_post_load,
-.fields  = (VMStateField []) {
+.fields = (VMStateField[]) {
 

[Qemu-devel] [PATCH 020/124] vmstate: test for VMSTATE_INT64_TEST

2014-04-21 Thread Juan Quintela
Remove VMSTATE_INT64_V, we are removing versioning.
Move all users to VMSTATE_INT64_TEST.

Signed-off-by: Juan Quintela 
---
 cpus.c  | 2 +-
 hw/timer/mc146818rtc.c  | 2 +-
 hw/usb/hcd-uhci.c   | 2 +-
 include/migration/vmstate.h | 6 +++---
 tests/test-vmstate.c| 4 
 5 files changed, 10 insertions(+), 6 deletions(-)

diff --git a/cpus.c b/cpus.c
index c510052..83aa302 100644
--- a/cpus.c
+++ b/cpus.c
@@ -433,7 +433,7 @@ static const VMStateDescription vmstate_timers = {
 .fields = (VMStateField[]) {
 VMSTATE_INT64(cpu_ticks_offset, TimersState),
 VMSTATE_INT64(dummy, TimersState),
-VMSTATE_INT64_V(cpu_clock_offset, TimersState, 2),
+VMSTATE_INT64_TEST(cpu_clock_offset, TimersState, vmstate_2_plus),
 VMSTATE_END_OF_LIST()
 }
 };
diff --git a/hw/timer/mc146818rtc.c b/hw/timer/mc146818rtc.c
index 1822af2..8342749 100644
--- a/hw/timer/mc146818rtc.c
+++ b/hw/timer/mc146818rtc.c
@@ -732,7 +732,7 @@ static const VMStateDescription vmstate_rtc = {
 VMSTATE_UINT32_V(period, RTCState, 2),
 VMSTATE_UINT64_V(base_rtc, RTCState, 3),
 VMSTATE_UINT64_V(last_update, RTCState, 3),
-VMSTATE_INT64_V(offset, RTCState, 3),
+VMSTATE_INT64_TEST(offset, RTCState, vmstate_3_plus),
 VMSTATE_TIMER_V(update_timer, RTCState, 3),
 VMSTATE_UINT64_V(next_alarm_time, RTCState, 3),
 VMSTATE_END_OF_LIST()
diff --git a/hw/usb/hcd-uhci.c b/hw/usb/hcd-uhci.c
index 9b1166b..5590e18 100644
--- a/hw/usb/hcd-uhci.c
+++ b/hw/usb/hcd-uhci.c
@@ -457,7 +457,7 @@ static const VMStateDescription vmstate_uhci = {
 VMSTATE_UINT8(sof_timing, UHCIState),
 VMSTATE_UINT8(status2, UHCIState),
 VMSTATE_TIMER(frame_timer, UHCIState),
-VMSTATE_INT64_V(expire_time, UHCIState, 2),
+VMSTATE_INT64_TEST(expire_time, UHCIState, vmstate_3_plus),
 VMSTATE_UINT32_V(pending_int_mask, UHCIState, 3),
 VMSTATE_END_OF_LIST()
 }
diff --git a/include/migration/vmstate.h b/include/migration/vmstate.h
index 036b800..453be1a 100644
--- a/include/migration/vmstate.h
+++ b/include/migration/vmstate.h
@@ -535,8 +535,8 @@ extern const VMStateInfo vmstate_info_bitmap;
 VMSTATE_SINGLE_TEST(_f, _s, _t, 0, vmstate_info_int16, int16_t)
 #define VMSTATE_INT32_TEST(_f, _s, _t)\
 VMSTATE_SINGLE_TEST(_f, _s, _t, 0, vmstate_info_int32, int32_t)
-#define VMSTATE_INT64_V(_f, _s, _v)   \
-VMSTATE_SINGLE(_f, _s, _v, vmstate_info_int64, int64_t)
+#define VMSTATE_INT64_TEST(_f, _s, _t)\
+VMSTATE_SINGLE_TEST(_f, _s, _t, 0, vmstate_info_int64, int64_t)

 #define VMSTATE_UINT8_V(_f, _s, _v)   \
 VMSTATE_SINGLE(_f, _s, _v, vmstate_info_uint8, uint8_t)
@@ -557,7 +557,7 @@ extern const VMStateInfo vmstate_info_bitmap;
 #define VMSTATE_INT32(_f, _s) \
 VMSTATE_INT32_TEST(_f, _s, NULL)
 #define VMSTATE_INT64(_f, _s) \
-VMSTATE_INT64_V(_f, _s, 0)
+VMSTATE_INT64_TEST(_f, _s, NULL)

 #define VMSTATE_UINT8(_f, _s) \
 VMSTATE_UINT8_V(_f, _s, 0)
diff --git a/tests/test-vmstate.c b/tests/test-vmstate.c
index e8e6468..fd763e1 100644
--- a/tests/test-vmstate.c
+++ b/tests/test-vmstate.c
@@ -299,6 +299,8 @@ static const VMStateDescription vmstate_simple_test = {
 VMSTATE_INT16_TEST(i16_2, TestSimple, test_false),
 VMSTATE_INT32_TEST(i32_1, TestSimple, test_true),
 VMSTATE_INT32_TEST(i32_2, TestSimple, test_false),
+VMSTATE_INT64_TEST(i64_1, TestSimple, test_true),
+VMSTATE_INT64_TEST(i64_2, TestSimple, test_false),
 VMSTATE_END_OF_LIST()
 }
 };
@@ -308,6 +310,7 @@ uint8_t wire_simple_test[] = {
 /* i8_1 */  0x41,
 /* i16_1 */ 0x02, 0x00,
 /* i32_1 */ 0x00, 0x01, 0x11, 0x70,
+/* i64_1 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0xb8, 0xf4, 0x7c,
 QEMU_VM_EOF, /* just to ensure we won't get EOF reported prematurely */
 };

@@ -328,6 +331,7 @@ static void test_simple_test(void)
 FIELD_EQUAL(i8_1);
 FIELD_EQUAL(i16_1);
 FIELD_EQUAL(i32_1);
+FIELD_EQUAL(i64_1);
 }
 #undef FIELD_EQUAL

-- 
1.9.0




[Qemu-devel] [PATCH 004/124] savevm: Remove all the unneded version_minimum_id_old (arm)

2014-04-21 Thread Juan Quintela
After previous Peter patch, they are redundant.  This way we don't asign them
except when needed.  Once there, there were lots of case where the ".fields"
indentation was wrong:

 .fields = (VMStateField []) {
and
 .fields =  (VMStateField []) {

Change all the combinations to:

 .fields = (VMStateField[]){

The biggest problem (appart of aesthetics) was that checkpatch complained
when we copy&pasted the code from one place to another.

Signed-off-by: Juan Quintela 
---
 hw/arm/highbank.c |  1 -
 hw/arm/musicpal.c |  8 
 hw/arm/pxa2xx.c   | 19 ++-
 hw/arm/pxa2xx_gpio.c  |  3 +--
 hw/arm/pxa2xx_pic.c   |  1 -
 hw/arm/spitz.c| 12 
 hw/arm/stellaris.c| 12 
 hw/arm/strongarm.c|  6 --
 hw/arm/z2.c   |  2 --
 hw/audio/lm4549.c |  5 ++---
 hw/audio/marvell_88w8618.c|  1 -
 hw/audio/pl041.c  |  9 +++--
 hw/audio/wm8750.c |  3 +--
 hw/block/ecc.c|  3 +--
 hw/block/nand.c   |  3 +--
 hw/block/onenand.c|  1 -
 hw/char/cadence_uart.c|  1 -
 hw/char/digic-uart.c  |  1 -
 hw/char/exynos4210_uart.c |  2 --
 hw/char/imx_serial.c  |  1 -
 hw/char/pl011.c   |  3 +--
 hw/display/ads7846.c  |  3 +--
 hw/display/exynos4210_fimd.c  |  4 ++--
 hw/display/pxa2xx_lcd.c   |  6 ++
 hw/display/ssd0303.c  |  3 +--
 hw/dma/pl330.c|  5 -
 hw/dma/pxa2xx_dma.c   |  2 --
 hw/gpio/max7310.c |  3 +--
 hw/gpio/zaurus.c  |  3 +--
 hw/input/lm832x.c |  3 +--
 hw/input/pxa2xx_keypad.c  |  3 +--
 hw/input/stellaris_input.c|  6 ++
 hw/intc/allwinner-a10-pic.c   |  1 -
 hw/intc/armv7m_nvic.c |  3 +--
 hw/intc/exynos4210_combiner.c |  2 --
 hw/intc/exynos4210_gic.c  |  1 -
 hw/intc/imx_avic.c|  1 -
 hw/misc/exynos4210_pmu.c  |  2 +-
 hw/misc/imx_ccm.c |  1 -
 hw/misc/max111x.c |  3 +--
 hw/misc/mst_fpga.c| 11 +--
 hw/misc/tmp105.c  |  3 +--
 hw/misc/zynq_slcr.c   |  3 +--
 hw/net/cadence_gem.c  |  3 +--
 hw/net/smc91c111.c|  2 +-
 hw/net/xgmac.c|  2 +-
 hw/ssi/pl022.c|  3 +--
 hw/ssi/ssi.c  |  3 +--
 hw/ssi/xilinx_spi.c   |  1 -
 hw/ssi/xilinx_spips.c |  1 -
 hw/timer/allwinner-a10-pit.c  |  1 -
 hw/timer/arm_timer.c  |  6 ++
 hw/timer/cadence_ttc.c|  2 --
 hw/timer/digic-timer.c|  1 -
 hw/timer/ds1338.c |  1 -
 hw/timer/exynos4210_mct.c |  6 --
 hw/timer/exynos4210_pwm.c |  2 --
 hw/timer/exynos4210_rtc.c |  1 -
 hw/timer/imx_epit.c   |  3 +--
 hw/timer/imx_gpt.c|  3 +--
 hw/timer/pxa2xx_timer.c   |  3 ---
 hw/timer/twl92230.c   |  6 ++
 target-arm/machine.c  |  5 -
 util/fifo8.c  |  3 +--
 64 files changed, 58 insertions(+), 169 deletions(-)

diff --git a/hw/arm/highbank.c b/hw/arm/highbank.c
index 46b9f1e..24231e5 100644
--- a/hw/arm/highbank.c
+++ b/hw/arm/highbank.c
@@ -134,7 +134,6 @@ static VMStateDescription vmstate_highbank_regs = {
 .name = "highbank-regs",
 .version_id = 0,
 .minimum_version_id = 0,
-.minimum_version_id_old = 0,
 .fields = (VMStateField[]) {
 VMSTATE_UINT32_ARRAY(regs, HighbankRegsState, NUM_REGS),
 VMSTATE_END_OF_LIST(),
diff --git a/hw/arm/musicpal.c b/hw/arm/musicpal.c
index de54201..2a27a19 100644
--- a/hw/arm/musicpal.c
+++ b/hw/arm/musicpal.c
@@ -405,7 +405,6 @@ static const VMStateDescription mv88w8618_eth_vmsd = {
 .name = "mv88w8618_eth",
 .version_id = 1,
 .minimum_version_id = 1,
-.minimum_version_id_old = 1,
 .fields = (VMStateField[]) {
 VMSTATE_UINT32(smir, mv88w8618_eth_state),
 VMSTATE_UINT32(icr, mv88w8618_eth_state),
@@ -642,7 +641,6 @@ static const VMStateDescription musicpal_lcd_vmsd = {
 .name = "musicpal_lcd",
 .version_id = 1,
 .minimum_version_id = 1,
-.minimum_version_id_old = 1,
 .fields = (VMStateField[]) {
 VMSTATE_UINT32(brightness, musicpal_lcd_state),
 VMSTATE_UINT32(mode, musicpal_lcd_state),
@@ -769,7 +767,6 @@ static const VMStateDescription mv88w8618_pic_vmsd = {
 .name = "mv88w8618_pic",
 .version_id = 1,
 .minimum_version_id = 1,
-.minimum_version_id_old = 1,
 .fields = (VMStateField[]) {
 VMSTATE_UINT32(level, mv88w8618_pic_state),
 VMSTATE_UINT32(enabled, mv88w8618_pic_state),
@@ -940,7 +937,6 @@ static const VMStateDescription mv88w8618_timer_vmsd = {
 .name = "timer",
 .version_id = 1,
 .minimum_version_id = 1,
-.minimum_version_id_old = 1,
 .fields = (VMStateField[]) {
 VMSTATE_PTIMER(ptimer, mv88w8618_timer_state),
 VMST

[Qemu-devel] [PATCH 012/124] vmstate: Create test functions for versions until 15

2014-04-21 Thread Juan Quintela
Using macros, just to avoid repeating code.

Signed-off-by: Juan Quintela 
---
 include/migration/vmstate.h | 16 
 vmstate.c   | 22 ++
 2 files changed, 38 insertions(+)

diff --git a/include/migration/vmstate.h b/include/migration/vmstate.h
index e7e1705..55d7fe6 100644
--- a/include/migration/vmstate.h
+++ b/include/migration/vmstate.h
@@ -769,4 +769,20 @@ void vmstate_register_ram(struct MemoryRegion *memory, 
DeviceState *dev);
 void vmstate_unregister_ram(struct MemoryRegion *memory, DeviceState *dev);
 void vmstate_register_ram_global(struct MemoryRegion *memory);

+/* Return true if version_id > X */
+bool vmstate_2_plus(void *opaque, int version_id);
+bool vmstate_3_plus(void *opaque, int version_id);
+bool vmstate_4_plus(void *opaque, int version_id);
+bool vmstate_5_plus(void *opaque, int version_id);
+bool vmstate_6_plus(void *opaque, int version_id);
+bool vmstate_7_plus(void *opaque, int version_id);
+bool vmstate_8_plus(void *opaque, int version_id);
+bool vmstate_9_plus(void *opaque, int version_id);
+bool vmstate_10_plus(void *opaque, int version_id);
+bool vmstate_11_plus(void *opaque, int version_id);
+bool vmstate_12_plus(void *opaque, int version_id);
+bool vmstate_13_plus(void *opaque, int version_id);
+bool vmstate_14_plus(void *opaque, int version_id);
+bool vmstate_15_plus(void *opaque, int version_id);
+
 #endif
diff --git a/vmstate.c b/vmstate.c
index e0debfa..abade3f 100644
--- a/vmstate.c
+++ b/vmstate.c
@@ -662,3 +662,25 @@ const VMStateInfo vmstate_info_bitmap = {
 .get = get_bitmap,
 .put = put_bitmap,
 };
+
+/* version is X or bigger */
+#define VMSTATE_X_PLUS(X)\
+bool vmstate_##X##_plus(void *opaque, int version_id)\
+{\
+return version_id >= X;\
+}
+
+VMSTATE_X_PLUS(2)
+VMSTATE_X_PLUS(3)
+VMSTATE_X_PLUS(4)
+VMSTATE_X_PLUS(5)
+VMSTATE_X_PLUS(6)
+VMSTATE_X_PLUS(7)
+VMSTATE_X_PLUS(8)
+VMSTATE_X_PLUS(9)
+VMSTATE_X_PLUS(10)
+VMSTATE_X_PLUS(11)
+VMSTATE_X_PLUS(12)
+VMSTATE_X_PLUS(13)
+VMSTATE_X_PLUS(14)
+VMSTATE_X_PLUS(15)
-- 
1.9.0




[Qemu-devel] [PATCH 008/124] vmstate: Reduce code duplication

2014-04-21 Thread Juan Quintela
From: "Michael S. Tsirkin" 

Move size offset and number of elements math out
to functions, to reduce code duplication.

Signed-off-by: Michael S. Tsirkin 
Cc: "Dr. David Alan Gilbert" 
Signed-off-by: Juan Quintela 
---
 vmstate.c | 100 --
 1 file changed, 52 insertions(+), 48 deletions(-)

diff --git a/vmstate.c b/vmstate.c
index bcf1cde..e0debfa 100644
--- a/vmstate.c
+++ b/vmstate.c
@@ -10,6 +10,50 @@ static void vmstate_subsection_save(QEMUFile *f, const 
VMStateDescription *vmsd,
 static int vmstate_subsection_load(QEMUFile *f, const VMStateDescription *vmsd,
void *opaque);

+static int vmstate_n_elems(void *opaque, VMStateField *field)
+{
+int n_elems = 1;
+
+if (field->flags & VMS_ARRAY) {
+n_elems = field->num;
+} else if (field->flags & VMS_VARRAY_INT32) {
+n_elems = *(int32_t *)(opaque+field->num_offset);
+} else if (field->flags & VMS_VARRAY_UINT32) {
+n_elems = *(uint32_t *)(opaque+field->num_offset);
+} else if (field->flags & VMS_VARRAY_UINT16) {
+n_elems = *(uint16_t *)(opaque+field->num_offset);
+} else if (field->flags & VMS_VARRAY_UINT8) {
+n_elems = *(uint8_t *)(opaque+field->num_offset);
+}
+
+return n_elems;
+}
+
+static int vmstate_size(void *opaque, VMStateField *field)
+{
+int size = field->size;
+
+if (field->flags & VMS_VBUFFER) {
+size = *(int32_t *)(opaque+field->size_offset);
+if (field->flags & VMS_MULTIPLY) {
+size *= field->size;
+}
+}
+
+return size;
+}
+
+static void *vmstate_base_addr(void *opaque, VMStateField *field)
+{
+void *base_addr = opaque + field->offset;
+
+if (field->flags & VMS_POINTER) {
+base_addr = *(void **)base_addr + field->start;
+}
+
+return base_addr;
+}
+
 int vmstate_load_state(QEMUFile *f, const VMStateDescription *vmsd,
void *opaque, int version_id)
 {
@@ -37,30 +81,10 @@ int vmstate_load_state(QEMUFile *f, const 
VMStateDescription *vmsd,
  field->field_exists(opaque, version_id)) ||
 (!field->field_exists &&
  field->version_id <= version_id)) {
-void *base_addr = opaque + field->offset;
-int i, n_elems = 1;
-int size = field->size;
-
-if (field->flags & VMS_VBUFFER) {
-size = *(int32_t *)(opaque+field->size_offset);
-if (field->flags & VMS_MULTIPLY) {
-size *= field->size;
-}
-}
-if (field->flags & VMS_ARRAY) {
-n_elems = field->num;
-} else if (field->flags & VMS_VARRAY_INT32) {
-n_elems = *(int32_t *)(opaque+field->num_offset);
-} else if (field->flags & VMS_VARRAY_UINT32) {
-n_elems = *(uint32_t *)(opaque+field->num_offset);
-} else if (field->flags & VMS_VARRAY_UINT16) {
-n_elems = *(uint16_t *)(opaque+field->num_offset);
-} else if (field->flags & VMS_VARRAY_UINT8) {
-n_elems = *(uint8_t *)(opaque+field->num_offset);
-}
-if (field->flags & VMS_POINTER) {
-base_addr = *(void **)base_addr + field->start;
-}
+void *base_addr = vmstate_base_addr(opaque, field);
+int i, n_elems = vmstate_n_elems(opaque, field);
+int size = vmstate_size(opaque, field);
+
 for (i = 0; i < n_elems; i++) {
 void *addr = base_addr + size * i;

@@ -109,30 +133,10 @@ void vmstate_save_state(QEMUFile *f, const 
VMStateDescription *vmsd,
 while (field->name) {
 if (!field->field_exists ||
 field->field_exists(opaque, vmsd->version_id)) {
-void *base_addr = opaque + field->offset;
-int i, n_elems = 1;
-int size = field->size;
-
-if (field->flags & VMS_VBUFFER) {
-size = *(int32_t *)(opaque+field->size_offset);
-if (field->flags & VMS_MULTIPLY) {
-size *= field->size;
-}
-}
-if (field->flags & VMS_ARRAY) {
-n_elems = field->num;
-} else if (field->flags & VMS_VARRAY_INT32) {
-n_elems = *(int32_t *)(opaque+field->num_offset);
-} else if (field->flags & VMS_VARRAY_UINT32) {
-n_elems = *(uint32_t *)(opaque+field->num_offset);
-} else if (field->flags & VMS_VARRAY_UINT16) {
-n_elems = *(uint16_t *)(opaque+field->num_offset);
-} else if (field->flags & VMS_VARRAY_UINT8) {
-n_elems = *(uint8_t *)(opaque+field->num_offset);
-}
-if (field->flags & VMS_POINTER) {
-base_addr = *(void **)base_addr + field->start;
-}
+void *base_addr = vmstate_base_addr(opaque

[Qemu-devel] [PATCH 031/124] vmstate: Test for VMSTATE_UINT64_EQUAL

2014-04-21 Thread Juan Quintela
Remove unused VMSTATE_UINT64_EQUAL_V.

Signed-off-by: Juan Quintela 
---
 include/migration/vmstate.h | 9 +++--
 tests/test-vmstate.c| 2 ++
 2 files changed, 5 insertions(+), 6 deletions(-)

diff --git a/include/migration/vmstate.h b/include/migration/vmstate.h
index c0b823d..3d55344 100644
--- a/include/migration/vmstate.h
+++ b/include/migration/vmstate.h
@@ -579,15 +579,12 @@ extern const VMStateInfo vmstate_info_bitmap;
 #define VMSTATE_UINT32_EQUAL(_f, _s)  \
 VMSTATE_SINGLE_TEST(_f, _s, NULL, 0, vmstate_info_uint32_equal, uint32_t)

+#define VMSTATE_UINT64_EQUAL(_f, _s)  \
+VMSTATE_SINGLE_TEST(_f, _s, NULL, 0, vmstate_info_uint64_equal, uint64_t)
+
 #define VMSTATE_INT32_EQUAL(_f, _s)   \
 VMSTATE_SINGLE(_f, _s, 0, vmstate_info_int32_equal, int32_t)

-#define VMSTATE_UINT64_EQUAL_V(_f, _s, _v)\
-VMSTATE_SINGLE(_f, _s, _v, vmstate_info_uint64_equal, uint64_t)
-
-#define VMSTATE_UINT64_EQUAL(_f, _s)  \
-VMSTATE_UINT64_EQUAL_V(_f, _s, 0)
-
 #define VMSTATE_INT32_LE(_f, _s)   \
 VMSTATE_SINGLE(_f, _s, 0, vmstate_info_int32_le, int32_t)

diff --git a/tests/test-vmstate.c b/tests/test-vmstate.c
index 68345a8..9c8a40e 100644
--- a/tests/test-vmstate.c
+++ b/tests/test-vmstate.c
@@ -373,6 +373,7 @@ static const VMStateDescription vmstate_simple_compare = {
 VMSTATE_UINT16_EQUAL_TEST(u16_2, TestSimple, test_false),
 VMSTATE_UINT16_EQUAL_TEST(u16_3, TestSimple, test_true),
 VMSTATE_UINT32_EQUAL(u32_1, TestSimple),
+VMSTATE_UINT64_EQUAL(u64_1, TestSimple),
 VMSTATE_END_OF_LIST()
 }
 };
@@ -382,6 +383,7 @@ uint8_t wire_simple_compare[] = {
 /* u16_1 */ 0x02, 0x00,
 /* u16_3 */ 0x02, 0x00,
 /* u32_1 */ 0x00, 0x01, 0x11, 0x70,
+/* u64_1 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0xb8, 0xf4, 0x7c,
 QEMU_VM_EOF, /* just to ensure we won't get EOF reported prematurely */
 };

-- 
1.9.0




[Qemu-devel] [PATCH 009/124] vmstate: Refactor opening of files

2014-04-21 Thread Juan Quintela
Signed-off-by: Juan Quintela 
---
 tests/test-vmstate.c | 38 +++---
 1 file changed, 19 insertions(+), 19 deletions(-)

diff --git a/tests/test-vmstate.c b/tests/test-vmstate.c
index 30cc721..8b242c4 100644
--- a/tests/test-vmstate.c
+++ b/tests/test-vmstate.c
@@ -44,14 +44,14 @@ void yield_until_fd_readable(int fd)
 }

 /* Duplicate temp_fd and seek to the beginning of the file */
-static int dup_temp_fd(bool truncate)
+static QEMUFile *open_test_file(bool write)
 {
 int fd = dup(temp_fd);
 lseek(fd, 0, SEEK_SET);
-if (truncate) {
+if (write) {
 g_assert_cmpint(ftruncate(fd, 0), ==, 0);
 }
-return fd;
+return qemu_fdopen(fd, write ? "wb" : "rb");
 }

 typedef struct TestSruct {
@@ -76,13 +76,13 @@ static const VMStateDescription vmstate_simple = {

 static void test_simple_save(void)
 {
-QEMUFile *fsave = qemu_fdopen(dup_temp_fd(true), "wb");
+QEMUFile *fsave = open_test_file(true);
 TestStruct obj = { .a = 1, .b = 2, .c = 3, .d = 4 };
 vmstate_save_state(fsave, &vmstate_simple, &obj);
 g_assert(!qemu_file_get_error(fsave));
 qemu_fclose(fsave);

-QEMUFile *loading = qemu_fdopen(dup_temp_fd(false), "rb");
+QEMUFile *loading = open_test_file(false);
 uint8_t expected[] = {
 0, 0, 0, 1, /* a */
 0, 0, 0, 2, /* b */
@@ -104,7 +104,7 @@ static void test_simple_save(void)

 static void test_simple_load(void)
 {
-QEMUFile *fsave = qemu_fdopen(dup_temp_fd(true), "wb");
+QEMUFile *fsave = open_test_file(true);
 uint8_t buf[] = {
 0, 0, 0, 10, /* a */
 0, 0, 0, 20, /* b */
@@ -115,7 +115,7 @@ static void test_simple_load(void)
 qemu_put_buffer(fsave, buf, sizeof(buf));
 qemu_fclose(fsave);

-QEMUFile *loading = qemu_fdopen(dup_temp_fd(false), "rb");
+QEMUFile *loading = open_test_file(false);
 TestStruct obj;
 vmstate_load_state(loading, &vmstate_simple, &obj, 1);
 g_assert(!qemu_file_get_error(loading));
@@ -145,7 +145,7 @@ static const VMStateDescription vmstate_versioned = {

 static void test_load_v1(void)
 {
-QEMUFile *fsave = qemu_fdopen(dup_temp_fd(true), "wb");
+QEMUFile *fsave = open_test_file(true);
 uint8_t buf[] = {
 0, 0, 0, 10, /* a */
 0, 0, 0, 30, /* c */
@@ -155,7 +155,7 @@ static void test_load_v1(void)
 qemu_put_buffer(fsave, buf, sizeof(buf));
 qemu_fclose(fsave);

-QEMUFile *loading = qemu_fdopen(dup_temp_fd(false), "rb");
+QEMUFile *loading = open_test_file(false);
 TestStruct obj = { .b = 200, .e = 500, .f = 600 };
 vmstate_load_state(loading, &vmstate_versioned, &obj, 1);
 g_assert(!qemu_file_get_error(loading));
@@ -170,7 +170,7 @@ static void test_load_v1(void)

 static void test_load_v2(void)
 {
-QEMUFile *fsave = qemu_fdopen(dup_temp_fd(true), "wb");
+QEMUFile *fsave = open_test_file(true);
 uint8_t buf[] = {
 0, 0, 0, 10, /* a */
 0, 0, 0, 20, /* b */
@@ -183,7 +183,7 @@ static void test_load_v2(void)
 qemu_put_buffer(fsave, buf, sizeof(buf));
 qemu_fclose(fsave);

-QEMUFile *loading = qemu_fdopen(dup_temp_fd(false), "rb");
+QEMUFile *loading = open_test_file(false);
 TestStruct obj;
 vmstate_load_state(loading, &vmstate_versioned, &obj, 2);
 g_assert_cmpint(obj.a, ==, 10);
@@ -219,14 +219,14 @@ static const VMStateDescription vmstate_skipping = {

 static void test_save_noskip(void)
 {
-QEMUFile *fsave = qemu_fdopen(dup_temp_fd(true), "wb");
+QEMUFile *fsave = open_test_file(true);
 TestStruct obj = { .a = 1, .b = 2, .c = 3, .d = 4, .e = 5, .f = 6,
.skip_c_e = false };
 vmstate_save_state(fsave, &vmstate_skipping, &obj);
 g_assert(!qemu_file_get_error(fsave));
 qemu_fclose(fsave);

-QEMUFile *loading = qemu_fdopen(dup_temp_fd(false), "rb");
+QEMUFile *loading = open_test_file(false);
 uint8_t expected[] = {
 0, 0, 0, 1, /* a */
 0, 0, 0, 2, /* b */
@@ -250,14 +250,14 @@ static void test_save_noskip(void)

 static void test_save_skip(void)
 {
-QEMUFile *fsave = qemu_fdopen(dup_temp_fd(true), "wb");
+QEMUFile *fsave = open_test_file(true);
 TestStruct obj = { .a = 1, .b = 2, .c = 3, .d = 4, .e = 5, .f = 6,
.skip_c_e = true };
 vmstate_save_state(fsave, &vmstate_skipping, &obj);
 g_assert(!qemu_file_get_error(fsave));
 qemu_fclose(fsave);

-QEMUFile *loading = qemu_fdopen(dup_temp_fd(false), "rb");
+QEMUFile *loading = open_test_file(false);
 uint8_t expected[] = {
 0, 0, 0, 1, /* a */
 0, 0, 0, 2, /* b */
@@ -280,7 +280,7 @@ static void test_save_skip(void)

 static void test_load_noskip(void)
 {
-QEMUFile *fsave = qemu_fdopen(dup_temp_fd(true), "wb");
+QEMUFile *fsave = open_test_file(true);
 uint8_t buf[] = {
 0, 0,

[Qemu-devel] [PATCH 015/124] vmstate: Remove unused VMSTATE_UINTTL_ARRAY_V

2014-04-21 Thread Juan Quintela
Signed-off-by: Juan Quintela 
---
 include/hw/hw.h | 11 ---
 1 file changed, 4 insertions(+), 7 deletions(-)

diff --git a/include/hw/hw.h b/include/hw/hw.h
index 211eb8b..2c19297 100644
--- a/include/hw/hw.h
+++ b/include/hw/hw.h
@@ -53,21 +53,18 @@ int qemu_boot_set(const char *boot_order);
 VMSTATE_UINT64_TEST(_f, _s, _t)
 #define VMSTATE_UINTTL_EQUAL(_f, _s)  \
 VMSTATE_UINT64_EQUAL(_f, _s)
-#define VMSTATE_UINTTL_ARRAY_V(_f, _s, _n, _v)\
-VMSTATE_UINT64_ARRAY_V(_f, _s, _n, _v)
+#define VMSTATE_UINTTL_ARRAY(_f, _s, _n)  \
+VMSTATE_UINT64_ARRAY(_f, _s, _n)
 #else
 #define VMSTATE_UINTTL_TEST(_f, _s, _t)   \
 VMSTATE_UINT32_TEST(_f, _s, _t)
 #define VMSTATE_UINTTL_EQUAL(_f, _s)  \
 VMSTATE_UINT32_EQUAL(_f, _s)
-#define VMSTATE_UINTTL_ARRAY_V(_f, _s, _n, _v)\
-VMSTATE_UINT32_ARRAY_V(_f, _s, _n, _v)
+#define VMSTATE_UINTTL_ARRAY(_f, _s, _n)  \
+VMSTATE_UINT32_ARRAY(_f, _s, _n)
 #endif
 #define VMSTATE_UINTTL(_f, _s)\
 VMSTATE_UINTTL_TEST(_f, _s, NULL)
-#define VMSTATE_UINTTL_ARRAY(_f, _s, _n)  \
-VMSTATE_UINTTL_ARRAY_V(_f, _s, _n, 0)
-
 #endif

 #endif
-- 
1.9.0




[Qemu-devel] [PATCH 032/124] vmstate: Test for VMSTATE_INT32_EQUAL

2014-04-21 Thread Juan Quintela
Signed-off-by: Juan Quintela 
---
 include/migration/vmstate.h | 2 +-
 tests/test-vmstate.c| 2 ++
 2 files changed, 3 insertions(+), 1 deletion(-)

diff --git a/include/migration/vmstate.h b/include/migration/vmstate.h
index 3d55344..9765973 100644
--- a/include/migration/vmstate.h
+++ b/include/migration/vmstate.h
@@ -583,7 +583,7 @@ extern const VMStateInfo vmstate_info_bitmap;
 VMSTATE_SINGLE_TEST(_f, _s, NULL, 0, vmstate_info_uint64_equal, uint64_t)

 #define VMSTATE_INT32_EQUAL(_f, _s)   \
-VMSTATE_SINGLE(_f, _s, 0, vmstate_info_int32_equal, int32_t)
+VMSTATE_SINGLE_TEST(_f, _s, NULL, 0, vmstate_info_int32_equal, int32_t)

 #define VMSTATE_INT32_LE(_f, _s)   \
 VMSTATE_SINGLE(_f, _s, 0, vmstate_info_int32_le, int32_t)
diff --git a/tests/test-vmstate.c b/tests/test-vmstate.c
index 9c8a40e..3fc8f5e 100644
--- a/tests/test-vmstate.c
+++ b/tests/test-vmstate.c
@@ -374,6 +374,7 @@ static const VMStateDescription vmstate_simple_compare = {
 VMSTATE_UINT16_EQUAL_TEST(u16_3, TestSimple, test_true),
 VMSTATE_UINT32_EQUAL(u32_1, TestSimple),
 VMSTATE_UINT64_EQUAL(u64_1, TestSimple),
+VMSTATE_INT32_EQUAL(i32_1, TestSimple),
 VMSTATE_END_OF_LIST()
 }
 };
@@ -384,6 +385,7 @@ uint8_t wire_simple_compare[] = {
 /* u16_3 */ 0x02, 0x00,
 /* u32_1 */ 0x00, 0x01, 0x11, 0x70,
 /* u64_1 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0xb8, 0xf4, 0x7c,
+/* i32_1 */ 0x00, 0x01, 0x11, 0x70,
 QEMU_VM_EOF, /* just to ensure we won't get EOF reported prematurely */
 };

-- 
1.9.0




[Qemu-devel] [PATCH 010/124] vmstate: Refactor & increase tests for primitive types

2014-04-21 Thread Juan Quintela
This commit refactor the simple tests to test all integer types. We
move to hex because it is easier to read values of different types.

Signed-off-by: Juan Quintela 
---
 tests/test-vmstate.c | 277 +++
 1 file changed, 216 insertions(+), 61 deletions(-)

diff --git a/tests/test-vmstate.c b/tests/test-vmstate.c
index 8b242c4..caf90ec 100644
--- a/tests/test-vmstate.c
+++ b/tests/test-vmstate.c
@@ -54,80 +54,236 @@ static QEMUFile *open_test_file(bool write)
 return qemu_fdopen(fd, write ? "wb" : "rb");
 }

-typedef struct TestSruct {
-uint32_t a, b, c, e;
-uint64_t d, f;
-bool skip_c_e;
-} TestStruct;
+#define SUCCESS(val) \
+g_assert_cmpint((val), ==, 0)

+#define FAILURE(val) \
+g_assert_cmpint((val), !=, 0)

-static const VMStateDescription vmstate_simple = {
-.name = "test",
-.version_id = 1,
-.minimum_version_id = 1,
-.fields = (VMStateField[]) {
-VMSTATE_UINT32(a, TestStruct),
-VMSTATE_UINT32(b, TestStruct),
-VMSTATE_UINT32(c, TestStruct),
-VMSTATE_UINT64(d, TestStruct),
-VMSTATE_END_OF_LIST()
-}
-};
+static void save_vmstate(const VMStateDescription *desc, void *obj)
+{
+QEMUFile *f = open_test_file(true);
+
+/* Save file with vmstate */
+vmstate_save_state(f, desc, obj);
+qemu_put_byte(f, QEMU_VM_EOF);
+g_assert(!qemu_file_get_error(f));
+qemu_fclose(f);
+}

-static void test_simple_save(void)
+static void compare_vmstate(uint8_t *wire, size_t size)
 {
-QEMUFile *fsave = open_test_file(true);
-TestStruct obj = { .a = 1, .b = 2, .c = 3, .d = 4 };
-vmstate_save_state(fsave, &vmstate_simple, &obj);
-g_assert(!qemu_file_get_error(fsave));
-qemu_fclose(fsave);
+QEMUFile *f = open_test_file(false);
+uint8_t result[size];

-QEMUFile *loading = open_test_file(false);
-uint8_t expected[] = {
-0, 0, 0, 1, /* a */
-0, 0, 0, 2, /* b */
-0, 0, 0, 3, /* c */
-0, 0, 0, 0, 0, 0, 0, 4, /* d */
-};
-uint8_t result[sizeof(expected)];
-g_assert_cmpint(qemu_get_buffer(loading, result, sizeof(result)), ==,
+/* read back as binary */
+
+g_assert_cmpint(qemu_get_buffer(f, result, sizeof(result)), ==,
 sizeof(result));
-g_assert(!qemu_file_get_error(loading));
-g_assert_cmpint(memcmp(result, expected, sizeof(result)), ==, 0);
+g_assert(!qemu_file_get_error(f));
+
+/* Compare that what is on the file is the same that what we
+   expected to be there */
+SUCCESS(memcmp(result, wire, sizeof(result)));

 /* Must reach EOF */
-qemu_get_byte(loading);
-g_assert_cmpint(qemu_file_get_error(loading), ==, -EIO);
+qemu_get_byte(f);
+g_assert_cmpint(qemu_file_get_error(f), ==, -EIO);

-qemu_fclose(loading);
+qemu_fclose(f);
 }

-static void test_simple_load(void)
+static int load_vmstate_one(const VMStateDescription *desc, void *obj,
+int version, uint8_t *wire, size_t size)
 {
-QEMUFile *fsave = open_test_file(true);
-uint8_t buf[] = {
-0, 0, 0, 10, /* a */
-0, 0, 0, 20, /* b */
-0, 0, 0, 30, /* c */
-0, 0, 0, 0, 0, 0, 0, 40, /* d */
-QEMU_VM_EOF, /* just to ensure we won't get EOF reported prematurely */
-};
-qemu_put_buffer(fsave, buf, sizeof(buf));
-qemu_fclose(fsave);
+QEMUFile *f;
+int ret;
+
+f = open_test_file(true);
+qemu_put_buffer(f, wire, size);
+qemu_fclose(f);
+
+f = open_test_file(false);
+ret = vmstate_load_state(f, desc, obj, version);
+if (ret) {
+g_assert(qemu_file_get_error(f));
+} else{
+g_assert(!qemu_file_get_error(f));
+}
+qemu_fclose(f);
+return ret;
+}

-QEMUFile *loading = open_test_file(false);
-TestStruct obj;
-vmstate_load_state(loading, &vmstate_simple, &obj, 1);
-g_assert(!qemu_file_get_error(loading));
-g_assert_cmpint(obj.a, ==, 10);
-g_assert_cmpint(obj.b, ==, 20);
-g_assert_cmpint(obj.c, ==, 30);
-g_assert_cmpint(obj.d, ==, 40);
-qemu_fclose(loading);
+
+static int load_vmstate(const VMStateDescription *desc,
+void *obj, void *obj_clone,
+void (*obj_copy)(void *, void*),
+int version, uint8_t *wire, size_t size)
+{
+/* We test with zero size */
+obj_copy(obj_clone, obj);
+FAILURE(load_vmstate_one(desc, obj, version, wire, 0));
+
+/* Stream ends with QEMU_EOF, so we need at least 3 bytes to be
+ * able to test in the middle */
+
+if (size > 3) {
+
+/* We test with size - 2. We can't test size - 1 due to EOF tricks */
+obj_copy(obj, obj_clone);
+FAILURE(load_vmstate_one(desc, obj, version, wire, size - 2));
+
+/* Test with size/2, first half of real state */
+obj_copy(obj, obj_clone);
+FAILURE(load_vmstate_one(desc, obj, version, 

[Qemu-devel] [PATCH 016/124] vmstate: Test for VMSTATE_BOOL_TEST

2014-04-21 Thread Juan Quintela
Remove VMSTATE_BOOL_V, we are removing versioning, would use only tests.

Signed-off-by: Juan Quintela 
---
 include/migration/vmstate.h |  6 +++---
 tests/test-vmstate.c| 44 
 2 files changed, 47 insertions(+), 3 deletions(-)

diff --git a/include/migration/vmstate.h b/include/migration/vmstate.h
index cb253b8..c807417 100644
--- a/include/migration/vmstate.h
+++ b/include/migration/vmstate.h
@@ -526,8 +526,8 @@ extern const VMStateInfo vmstate_info_bitmap;
 VMSTATE_STRUCT_ARRAY_TEST(_field, _state, _num, NULL, _version,   \
 _vmsd, _type)

-#define VMSTATE_BOOL_V(_f, _s, _v)\
-VMSTATE_SINGLE(_f, _s, _v, vmstate_info_bool, bool)
+#define VMSTATE_BOOL_TEST(_f, _s, _t) \
+VMSTATE_SINGLE_TEST(_f, _s, _t, 0, vmstate_info_bool, bool)

 #define VMSTATE_INT8_V(_f, _s, _v)\
 VMSTATE_SINGLE(_f, _s, _v, vmstate_info_int8, int8_t)
@@ -548,7 +548,7 @@ extern const VMStateInfo vmstate_info_bitmap;
 VMSTATE_SINGLE(_f, _s, _v, vmstate_info_uint64, uint64_t)

 #define VMSTATE_BOOL(_f, _s)  \
-VMSTATE_BOOL_V(_f, _s, 0)
+VMSTATE_BOOL_TEST(_f, _s, NULL)

 #define VMSTATE_INT8(_f, _s)  \
 VMSTATE_INT8_V(_f, _s, 0)
diff --git a/tests/test-vmstate.c b/tests/test-vmstate.c
index 9743039..7de9e66 100644
--- a/tests/test-vmstate.c
+++ b/tests/test-vmstate.c
@@ -274,6 +274,49 @@ static void test_simple_primitive(void)
 FIELD_EQUAL(i64_1);
 FIELD_EQUAL(i64_2);
 }
+
+static bool test_true(void *opaque, int version_id)
+{
+return true;
+}
+
+static bool test_false(void *opaque, int version_id)
+{
+return false;
+}
+
+static const VMStateDescription vmstate_simple_test = {
+.name = "simple/test",
+.version_id = 1,
+.minimum_version_id = 1,
+.minimum_version_id_old = 1,
+.fields = (VMStateField[]) {
+VMSTATE_BOOL_TEST(b_1, TestSimple, test_true),
+VMSTATE_BOOL_TEST(b_2, TestSimple, test_false),
+VMSTATE_END_OF_LIST()
+}
+};
+
+uint8_t wire_simple_test[] = {
+/* b_1 */   0x01,
+QEMU_VM_EOF, /* just to ensure we won't get EOF reported prematurely */
+};
+
+static void test_simple_test(void)
+{
+TestSimple obj, obj_clone;
+
+memset(&obj, 0, sizeof(obj));
+save_vmstate(&vmstate_simple_test, &obj_simple);
+
+compare_vmstate(wire_simple_test, sizeof(wire_simple_test));
+
+SUCCESS(load_vmstate(&vmstate_simple_test, &obj, &obj_clone,
+ obj_simple_copy, 1, wire_simple_test,
+ sizeof(wire_simple_test)));
+
+FIELD_EQUAL(b_1);
+}
 #undef FIELD_EQUAL

 typedef struct TestVersioned {
@@ -507,6 +550,7 @@ int main(int argc, char **argv)
 g_test_add_func("/vmstate/simple/v2", test_simple_v2);
 g_test_add_func("/vmstate/simple/skip", test_simple_skip);
 g_test_add_func("/vmstate/simple/no_skip", test_simple_no_skip);
+g_test_add_func("/vmstate/simple/test", test_simple_test);
 g_test_run();

 close(temp_fd);
-- 
1.9.0




[Qemu-devel] [PATCH 027/124] vmstate: Test for VMSTATE_BITMAP

2014-04-21 Thread Juan Quintela
Remove the unused version field (was unused).

Signed-off-by: Juan Quintela 
---
 hw/sd/sd.c  |  2 +-
 include/migration/vmstate.h |  4 +--
 tests/test-vmstate.c| 75 +
 3 files changed, 78 insertions(+), 3 deletions(-)

diff --git a/hw/sd/sd.c b/hw/sd/sd.c
index 4502ad1..7ee8c24 100644
--- a/hw/sd/sd.c
+++ b/hw/sd/sd.c
@@ -467,7 +467,7 @@ static const VMStateDescription sd_vmstate = {
 VMSTATE_UINT32(card_status, SDState),
 VMSTATE_PARTIAL_BUFFER(sd_status, SDState, 1),
 VMSTATE_UINT32(vhs, SDState),
-VMSTATE_BITMAP(wp_groups, SDState, 0, wpgrps_size),
+VMSTATE_BITMAP(wp_groups, SDState, wpgrps_size),
 VMSTATE_UINT32(blk_len, SDState),
 VMSTATE_UINT32(erase_start, SDState),
 VMSTATE_UINT32(erase_end, SDState),
diff --git a/include/migration/vmstate.h b/include/migration/vmstate.h
index 553cc0a..52b0cc8 100644
--- a/include/migration/vmstate.h
+++ b/include/migration/vmstate.h
@@ -493,9 +493,9 @@ extern const VMStateInfo vmstate_info_bitmap;
 /* _field_size should be a int32_t field in the _state struct giving the
  * size of the bitmap _field in bits.
  */
-#define VMSTATE_BITMAP(_field, _state, _version, _field_size) {  \
+#define VMSTATE_BITMAP(_field, _state, _field_size) {\
 .name = (stringify(_field)), \
-.version_id   = (_version),  \
+.version_id   = 0,   \
 .size_offset  = vmstate_offset_value(_state, _field_size, int32_t),\
 .info = &vmstate_info_bitmap,\
 .flags= VMS_VBUFFER|VMS_POINTER, \
diff --git a/tests/test-vmstate.c b/tests/test-vmstate.c
index 2aa6d8b..f105e2c 100644
--- a/tests/test-vmstate.c
+++ b/tests/test-vmstate.c
@@ -28,6 +28,7 @@
 #include "migration/migration.h"
 #include "migration/vmstate.h"
 #include "block/coroutine.h"
+#include "qemu/bitmap.h"

 char temp_file[] = "/tmp/vmst.test.XX";
 int temp_fd;
@@ -361,6 +362,79 @@ static void test_simple_test(void)
 }
 #undef FIELD_EQUAL

+typedef struct TestBitmap {
+int32_t bitmap_size;
+unsigned long *bitmap;
+} TestBitmap;
+
+static const VMStateDescription vmstate_simple_bitmap = {
+.name = "simple/bitmap",
+.version_id = 1,
+.minimum_version_id = 1,
+.minimum_version_id_old = 1,
+.fields = (VMStateField[]) {
+VMSTATE_INT32_EQUAL(bitmap_size, TestBitmap),
+VMSTATE_BITMAP(bitmap, TestBitmap, bitmap_size),
+VMSTATE_END_OF_LIST()
+}
+};
+
+/* This is the binary representation on the wire of that struct */
+uint8_t wire_simple_bitmap[] = {
+0x00,  0x00,  0x00,  0x40,  /* size */
+0x40,  0x00,  0x00,  0x00,  /* bitmap */
+0x40,  0x40,  0x00,  0x01,
+QEMU_VM_EOF, /* just to ensure we won't get EOF reported prematurely */
+};
+
+#define VMSTATE_BITMAP_SIZE 64
+
+static void obj_bitmap_copy(void *arg1, void *arg2)
+{
+TestBitmap *target = arg1;
+TestBitmap *source = arg2;
+
+target->bitmap_size = source->bitmap_size;
+memcpy(target->bitmap, source->bitmap, VMSTATE_BITMAP_SIZE / sizeof(long));
+}
+
+static TestBitmap *create_bitmap(void)
+{
+TestBitmap *obj = g_malloc0(sizeof(*obj));
+obj->bitmap_size = VMSTATE_BITMAP_SIZE;
+obj->bitmap = bitmap_new(VMSTATE_BITMAP_SIZE);
+
+return obj;
+}
+
+static void test_simple_bitmap(void)
+{
+TestBitmap *obj_bitmap, *obj, *obj_clone;
+
+obj_bitmap = create_bitmap();
+obj = create_bitmap();
+obj_clone = create_bitmap();
+
+set_bit(0, obj_bitmap->bitmap);
+set_bit(22, obj_bitmap->bitmap);
+set_bit(30, obj_bitmap->bitmap);
+set_bit(62, obj_bitmap->bitmap);
+
+save_vmstate(&vmstate_simple_bitmap, obj_bitmap);
+
+compare_vmstate(wire_simple_bitmap, sizeof(wire_simple_bitmap));
+
+SUCCESS(load_vmstate(&vmstate_simple_bitmap, obj, obj_clone,
+ obj_bitmap_copy, 1, wire_simple_bitmap,
+ sizeof(wire_simple_bitmap)));
+
+#define FIELD_EQUAL(name)   g_assert_cmpint(obj->name, ==, obj_bitmap->name)
+FIELD_EQUAL(bitmap_size);
+g_assert_cmpint(bitmap_equal(obj->bitmap, obj_bitmap->bitmap,
+ VMSTATE_BITMAP_SIZE), ==, 1);
+#undef FIELD_EQUAL
+}
+
 typedef struct TestVersioned {
 uint32_t a, b, c, e;
 uint64_t d, f;
@@ -592,6 +666,7 @@ int main(int argc, char **argv)
 g_test_add_func("/vmstate/simple/skip", test_simple_skip);
 g_test_add_func("/vmstate/simple/no_skip", test_simple_no_skip);
 g_test_add_func("/vmstate/simple/test", test_simple_test);
+g_test_add_func("/vmstate/simple/bitmap", test_simple_bitmap);
 g_test_run();

 close(temp_fd);
-- 
1.9.0




[Qemu-devel] [PATCH 039/124] vmstate: Test for VMSTATE_UINT32_ARRAY{_TEST}

2014-04-21 Thread Juan Quintela
Once there, change only user of VMSTATE_UInT32_ARRAY_V.

Signed-off-by: Juan Quintela 
---
 hw/misc/arm_sysctl.c|  3 ++-
 include/migration/vmstate.h | 15 ++-
 tests/test-vmstate.c| 20 
 3 files changed, 28 insertions(+), 10 deletions(-)

diff --git a/hw/misc/arm_sysctl.c b/hw/misc/arm_sysctl.c
index 807d48e..0f61241 100644
--- a/hw/misc/arm_sysctl.c
+++ b/hw/misc/arm_sysctl.c
@@ -65,7 +65,8 @@ static const VMStateDescription vmstate_arm_sysctl = {
 VMSTATE_UINT32_TEST(sys_cfgctrl, arm_sysctl_state, vmstate_2_plus),
 VMSTATE_UINT32_TEST(sys_cfgstat, arm_sysctl_state, vmstate_2_plus),
 VMSTATE_UINT32_TEST(sys_clcd, arm_sysctl_state, vmstate_3_plus),
-VMSTATE_UINT32_ARRAY_V(mb_clock, arm_sysctl_state, 6, 4),
+VMSTATE_UINT32_ARRAY_TEST(mb_clock, arm_sysctl_state, 6,
+  vmstate_4_plus),
 VMSTATE_VARRAY_UINT32(db_clock, arm_sysctl_state, db_num_clocks,
   4, vmstate_info_uint32, uint32_t),
 VMSTATE_END_OF_LIST()
diff --git a/include/migration/vmstate.h b/include/migration/vmstate.h
index 5935d60..8f4a1a3 100644
--- a/include/migration/vmstate.h
+++ b/include/migration/vmstate.h
@@ -612,6 +612,12 @@ extern const VMStateInfo vmstate_info_bitmap;
 #define VMSTATE_UINT16_ARRAY(_f, _s, _n)  \
 VMSTATE_ARRAY_TEST(_f, _s, _n, NULL, vmstate_info_uint16, uint16_t)

+#define VMSTATE_UINT32_ARRAY_TEST(_f, _s, _n, _t) \
+VMSTATE_ARRAY_TEST(_f, _s, _n, _t, vmstate_info_uint32, uint32_t)
+
+#define VMSTATE_UINT32_ARRAY(_f, _s, _n)  \
+VMSTATE_UINT32_ARRAY_TEST(_f, _s, _n, NULL)
+
 #define VMSTATE_UINT16_2DARRAY_V(_f, _s, _n1, _n2, _v)\
 VMSTATE_2DARRAY(_f, _s, _n1, _n2, _v, vmstate_info_uint16, uint16_t)

@@ -627,15 +633,9 @@ extern const VMStateInfo vmstate_info_bitmap;
 #define VMSTATE_UINT8_2DARRAY(_f, _s, _n1, _n2)   \
 VMSTATE_UINT8_2DARRAY_V(_f, _s, _n1, _n2, 0)

-#define VMSTATE_UINT32_ARRAY_V(_f, _s, _n, _v)\
-VMSTATE_ARRAY(_f, _s, _n, _v, vmstate_info_uint32, uint32_t)
-
 #define VMSTATE_UINT32_2DARRAY_V(_f, _s, _n1, _n2, _v)\
 VMSTATE_2DARRAY(_f, _s, _n1, _n2, _v, vmstate_info_uint32, uint32_t)

-#define VMSTATE_UINT32_ARRAY(_f, _s, _n)  \
-VMSTATE_UINT32_ARRAY_V(_f, _s, _n, 0)
-
 #define VMSTATE_UINT32_2DARRAY(_f, _s, _n1, _n2)  \
 VMSTATE_UINT32_2DARRAY_V(_f, _s, _n1, _n2, 0)

@@ -660,9 +660,6 @@ extern const VMStateInfo vmstate_info_bitmap;
 #define VMSTATE_UINT32_SUB_ARRAY(_f, _s, _start, _num)\
 VMSTATE_SUB_ARRAY(_f, _s, _start, _num, 0, vmstate_info_uint32, uint32_t)

-#define VMSTATE_UINT32_ARRAY(_f, _s, _n)  \
-VMSTATE_UINT32_ARRAY_V(_f, _s, _n, 0)
-
 #define VMSTATE_INT64_ARRAY_V(_f, _s, _n, _v) \
 VMSTATE_ARRAY(_f, _s, _n, _v, vmstate_info_int64, int64_t)

diff --git a/tests/test-vmstate.c b/tests/test-vmstate.c
index baf9046..f81d470 100644
--- a/tests/test-vmstate.c
+++ b/tests/test-vmstate.c
@@ -515,6 +515,8 @@ typedef struct TestArray {
 uint8_t  u8_1[VMSTATE_ARRAY_SIZE];
 uint8_t  u8_2[VMSTATE_ARRAY_SIZE];
 uint16_t u16_1[VMSTATE_ARRAY_SIZE];
+uint32_t u32_1[VMSTATE_ARRAY_SIZE];
+uint32_t u32_2[VMSTATE_ARRAY_SIZE];
 } TestArray;

 TestArray obj_array = {
@@ -524,6 +526,8 @@ TestArray obj_array = {
 .u8_1 = { 1, 2, 3, 4, 5},
 .u8_2 = { 5, 4, 3, 2, 1},
 .u16_1 = {11, 12, 13, 14, 15},
+.u32_1 = {21, 22, 23, 24, 25},
+.u32_2 = {25, 24, 23, 22, 21},
 };

 static const VMStateDescription vmstate_array_primitive = {
@@ -536,6 +540,7 @@ static const VMStateDescription vmstate_array_primitive = {
 VMSTATE_BOOL_ARRAY(b_1, TestArray, VMSTATE_ARRAY_SIZE),
 VMSTATE_UINT8_ARRAY(u8_1, TestArray, VMSTATE_ARRAY_SIZE),
 VMSTATE_UINT16_ARRAY(u16_1, TestArray, VMSTATE_ARRAY_SIZE),
+VMSTATE_UINT32_ARRAY(u32_1, TestArray, VMSTATE_ARRAY_SIZE),
 VMSTATE_END_OF_LIST()
 }
 };
@@ -545,6 +550,9 @@ uint8_t wire_array_primitive[] = {
 /* b_1 */   0x00, 0x01, 0x00, 0x01, 0x00,
 /* u8_1 */  0x01, 0x02, 0x03, 0x04, 0x05,
 /* u16_1 */ 0x00, 0x0b, 0x00, 0x0c, 0x00, 0x0d, 0x00, 0x0e, 0x00, 0x0f,
+/* u32_1 */ 0x00, 0x00, 0x00, 0x15, 0x00, 0x00, 0x00, 0x16,
+0x00, 0x00, 0x00, 0x17, 0x00, 0x00, 0x00, 0x18,
+0x00, 0x00, 0x00, 0x19,
 QEMU_VM_EOF, /* just to ensure we won't get EOF reported prematurely */
 };

@@ -562,6 +570,8 @@ static void obj_array_copy(void *arg1, void *arg2)
 target->u8_1[i] = source->u8_1[i];
 target->u8_2[i] = source->u8_2[i];
 target->u16_1[i] = source->u16_1[i];
+target->u32_1[i] = source->u32_1[i];
+target->u32_2[i] = source->u32_2[i];
 }
 }

@@ -593,6 +603,7 @@ stati

[Qemu-devel] [PATCH 018/124] vmstate: Test for VMSTATE_INT16_TEST

2014-04-21 Thread Juan Quintela
Remove VMSTATES_INT16_V, we are removing versioning, would use only tests.

Signed-off-by: Juan Quintela 
---
 include/migration/vmstate.h | 6 +++---
 tests/test-vmstate.c| 4 
 2 files changed, 7 insertions(+), 3 deletions(-)

diff --git a/include/migration/vmstate.h b/include/migration/vmstate.h
index 211ea46..1c07f95 100644
--- a/include/migration/vmstate.h
+++ b/include/migration/vmstate.h
@@ -531,8 +531,8 @@ extern const VMStateInfo vmstate_info_bitmap;

 #define VMSTATE_INT8_TEST(_f, _s, _t) \
 VMSTATE_SINGLE_TEST(_f, _s, _t, 0, vmstate_info_int8, int8_t)
-#define VMSTATE_INT16_V(_f, _s, _v)   \
-VMSTATE_SINGLE(_f, _s, _v, vmstate_info_int16, int16_t)
+#define VMSTATE_INT16_TEST(_f, _s, _t)\
+VMSTATE_SINGLE_TEST(_f, _s, _t, 0, vmstate_info_int16, int16_t)
 #define VMSTATE_INT32_V(_f, _s, _v)   \
 VMSTATE_SINGLE(_f, _s, _v, vmstate_info_int32, int32_t)
 #define VMSTATE_INT64_V(_f, _s, _v)   \
@@ -553,7 +553,7 @@ extern const VMStateInfo vmstate_info_bitmap;
 #define VMSTATE_INT8(_f, _s)  \
 VMSTATE_INT8_TEST(_f, _s, NULL)
 #define VMSTATE_INT16(_f, _s) \
-VMSTATE_INT16_V(_f, _s, 0)
+VMSTATE_INT16_TEST(_f, _s, NULL)
 #define VMSTATE_INT32(_f, _s) \
 VMSTATE_INT32_V(_f, _s, 0)
 #define VMSTATE_INT64(_f, _s) \
diff --git a/tests/test-vmstate.c b/tests/test-vmstate.c
index d62ca44..8929129 100644
--- a/tests/test-vmstate.c
+++ b/tests/test-vmstate.c
@@ -295,6 +295,8 @@ static const VMStateDescription vmstate_simple_test = {
 VMSTATE_BOOL_TEST(b_2, TestSimple, test_false),
 VMSTATE_INT8_TEST(i8_1, TestSimple, test_true),
 VMSTATE_INT8_TEST(i8_2, TestSimple, test_false),
+VMSTATE_INT16_TEST(i16_1, TestSimple, test_true),
+VMSTATE_INT16_TEST(i16_2, TestSimple, test_false),
 VMSTATE_END_OF_LIST()
 }
 };
@@ -302,6 +304,7 @@ static const VMStateDescription vmstate_simple_test = {
 uint8_t wire_simple_test[] = {
 /* b_1 */   0x01,
 /* i8_1 */  0x41,
+/* i16_1 */ 0x02, 0x00,
 QEMU_VM_EOF, /* just to ensure we won't get EOF reported prematurely */
 };

@@ -320,6 +323,7 @@ static void test_simple_test(void)

 FIELD_EQUAL(b_1);
 FIELD_EQUAL(i8_1);
+FIELD_EQUAL(i16_1);
 }
 #undef FIELD_EQUAL

-- 
1.9.0




[Qemu-devel] [PATCH 017/124] vmstate: Test for VMSTATE_INT8_TEST

2014-04-21 Thread Juan Quintela
Remove VMSTATE_INT8_V, we are removing versioning, would use only tests.

Signed-off-by: Juan Quintela 
---
 include/migration/vmstate.h | 6 +++---
 tests/test-vmstate.c| 4 
 2 files changed, 7 insertions(+), 3 deletions(-)

diff --git a/include/migration/vmstate.h b/include/migration/vmstate.h
index c807417..211ea46 100644
--- a/include/migration/vmstate.h
+++ b/include/migration/vmstate.h
@@ -529,8 +529,8 @@ extern const VMStateInfo vmstate_info_bitmap;
 #define VMSTATE_BOOL_TEST(_f, _s, _t) \
 VMSTATE_SINGLE_TEST(_f, _s, _t, 0, vmstate_info_bool, bool)

-#define VMSTATE_INT8_V(_f, _s, _v)\
-VMSTATE_SINGLE(_f, _s, _v, vmstate_info_int8, int8_t)
+#define VMSTATE_INT8_TEST(_f, _s, _t) \
+VMSTATE_SINGLE_TEST(_f, _s, _t, 0, vmstate_info_int8, int8_t)
 #define VMSTATE_INT16_V(_f, _s, _v)   \
 VMSTATE_SINGLE(_f, _s, _v, vmstate_info_int16, int16_t)
 #define VMSTATE_INT32_V(_f, _s, _v)   \
@@ -551,7 +551,7 @@ extern const VMStateInfo vmstate_info_bitmap;
 VMSTATE_BOOL_TEST(_f, _s, NULL)

 #define VMSTATE_INT8(_f, _s)  \
-VMSTATE_INT8_V(_f, _s, 0)
+VMSTATE_INT8_TEST(_f, _s, NULL)
 #define VMSTATE_INT16(_f, _s) \
 VMSTATE_INT16_V(_f, _s, 0)
 #define VMSTATE_INT32(_f, _s) \
diff --git a/tests/test-vmstate.c b/tests/test-vmstate.c
index 7de9e66..d62ca44 100644
--- a/tests/test-vmstate.c
+++ b/tests/test-vmstate.c
@@ -293,12 +293,15 @@ static const VMStateDescription vmstate_simple_test = {
 .fields = (VMStateField[]) {
 VMSTATE_BOOL_TEST(b_1, TestSimple, test_true),
 VMSTATE_BOOL_TEST(b_2, TestSimple, test_false),
+VMSTATE_INT8_TEST(i8_1, TestSimple, test_true),
+VMSTATE_INT8_TEST(i8_2, TestSimple, test_false),
 VMSTATE_END_OF_LIST()
 }
 };

 uint8_t wire_simple_test[] = {
 /* b_1 */   0x01,
+/* i8_1 */  0x41,
 QEMU_VM_EOF, /* just to ensure we won't get EOF reported prematurely */
 };

@@ -316,6 +319,7 @@ static void test_simple_test(void)
  sizeof(wire_simple_test)));

 FIELD_EQUAL(b_1);
+FIELD_EQUAL(i8_1);
 }
 #undef FIELD_EQUAL

-- 
1.9.0




[Qemu-devel] [PATCH 040/124] vmstate: Test for VMSTATE_UINT64_ARRAY{_TEST}

2014-04-21 Thread Juan Quintela
CHange users of _V to _TEST.

Signed-off-by: Juan Quintela 
---
 include/migration/vmstate.h | 12 ++--
 target-i386/machine.c   |  5 +++--
 tests/test-vmstate.c| 24 
 3 files changed, 33 insertions(+), 8 deletions(-)

diff --git a/include/migration/vmstate.h b/include/migration/vmstate.h
index 8f4a1a3..7c8bc54 100644
--- a/include/migration/vmstate.h
+++ b/include/migration/vmstate.h
@@ -618,6 +618,12 @@ extern const VMStateInfo vmstate_info_bitmap;
 #define VMSTATE_UINT32_ARRAY(_f, _s, _n)  \
 VMSTATE_UINT32_ARRAY_TEST(_f, _s, _n, NULL)

+#define VMSTATE_UINT64_ARRAY_TEST(_f, _s, _n, _t) \
+VMSTATE_ARRAY_TEST(_f, _s, _n, _t, vmstate_info_uint64, uint64_t)
+
+#define VMSTATE_UINT64_ARRAY(_f, _s, _n)  \
+VMSTATE_UINT64_ARRAY_TEST(_f, _s, _n, NULL)
+
 #define VMSTATE_UINT16_2DARRAY_V(_f, _s, _n1, _n2, _v)\
 VMSTATE_2DARRAY(_f, _s, _n1, _n2, _v, vmstate_info_uint16, uint16_t)

@@ -639,12 +645,6 @@ extern const VMStateInfo vmstate_info_bitmap;
 #define VMSTATE_UINT32_2DARRAY(_f, _s, _n1, _n2)  \
 VMSTATE_UINT32_2DARRAY_V(_f, _s, _n1, _n2, 0)

-#define VMSTATE_UINT64_ARRAY_V(_f, _s, _n, _v)\
-VMSTATE_ARRAY(_f, _s, _n, _v, vmstate_info_uint64, uint64_t)
-
-#define VMSTATE_UINT64_ARRAY(_f, _s, _n)  \
-VMSTATE_UINT64_ARRAY_V(_f, _s, _n, 0)
-
 #define VMSTATE_INT16_ARRAY_V(_f, _s, _n, _v) \
 VMSTATE_ARRAY(_f, _s, _n, _v, vmstate_info_int16, int16_t)

diff --git a/target-i386/machine.c b/target-i386/machine.c
index d4ffe8e..1b8e3c4 100644
--- a/target-i386/machine.c
+++ b/target-i386/machine.c
@@ -667,7 +667,7 @@ const VMStateDescription vmstate_x86_cpu = {
 VMSTATE_UINT32_TEST(env.intercept_exceptions, X86CPU, vmstate_5_plus),
 VMSTATE_UINT8_TEST(env.v_tpr, X86CPU, vmstate_5_plus),
 /* MTRRs */
-VMSTATE_UINT64_ARRAY_V(env.mtrr_fixed, X86CPU, 11, 8),
+VMSTATE_UINT64_ARRAY_TEST(env.mtrr_fixed, X86CPU, 11, vmstate_8_plus),
 VMSTATE_UINT64_TEST(env.mtrr_deftype, X86CPU, vmstate_8_plus),
 VMSTATE_MTRR_VARS(env.mtrr_var, X86CPU, 8, 8),
 /* KVM-related states */
@@ -684,7 +684,8 @@ const VMStateDescription vmstate_x86_cpu = {
 VMSTATE_UINT64_TEST(env.mcg_cap, X86CPU, vmstate_10_plus),
 VMSTATE_UINT64_TEST(env.mcg_status, X86CPU, vmstate_10_plus),
 VMSTATE_UINT64_TEST(env.mcg_ctl, X86CPU, vmstate_10_plus),
-VMSTATE_UINT64_ARRAY_V(env.mce_banks, X86CPU, MCE_BANKS_DEF * 4, 10),
+VMSTATE_UINT64_ARRAY_TEST(env.mce_banks, X86CPU, MCE_BANKS_DEF * 4,
+  vmstate_10_plus),
 /* rdtscp */
 VMSTATE_UINT64_TEST(env.tsc_aux, X86CPU, vmstate_11_plus),
 /* KVM pvclock msr */
diff --git a/tests/test-vmstate.c b/tests/test-vmstate.c
index f81d470..d4c15a2 100644
--- a/tests/test-vmstate.c
+++ b/tests/test-vmstate.c
@@ -517,6 +517,8 @@ typedef struct TestArray {
 uint16_t u16_1[VMSTATE_ARRAY_SIZE];
 uint32_t u32_1[VMSTATE_ARRAY_SIZE];
 uint32_t u32_2[VMSTATE_ARRAY_SIZE];
+uint64_t u64_1[VMSTATE_ARRAY_SIZE];
+uint64_t u64_2[VMSTATE_ARRAY_SIZE];
 } TestArray;

 TestArray obj_array = {
@@ -528,6 +530,8 @@ TestArray obj_array = {
 .u16_1 = {11, 12, 13, 14, 15},
 .u32_1 = {21, 22, 23, 24, 25},
 .u32_2 = {25, 24, 23, 22, 21},
+.u64_1 = {31, 32, 33, 34, 35},
+.u64_2 = {35, 34, 33, 32, 31},
 };

 static const VMStateDescription vmstate_array_primitive = {
@@ -541,6 +545,7 @@ static const VMStateDescription vmstate_array_primitive = {
 VMSTATE_UINT8_ARRAY(u8_1, TestArray, VMSTATE_ARRAY_SIZE),
 VMSTATE_UINT16_ARRAY(u16_1, TestArray, VMSTATE_ARRAY_SIZE),
 VMSTATE_UINT32_ARRAY(u32_1, TestArray, VMSTATE_ARRAY_SIZE),
+VMSTATE_UINT64_ARRAY(u64_1, TestArray, VMSTATE_ARRAY_SIZE),
 VMSTATE_END_OF_LIST()
 }
 };
@@ -553,6 +558,11 @@ uint8_t wire_array_primitive[] = {
 /* u32_1 */ 0x00, 0x00, 0x00, 0x15, 0x00, 0x00, 0x00, 0x16,
 0x00, 0x00, 0x00, 0x17, 0x00, 0x00, 0x00, 0x18,
 0x00, 0x00, 0x00, 0x19,
+/* u64_1 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1f,
+0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20,
+0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x21,
+0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x22,
+0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x23,
 QEMU_VM_EOF, /* just to ensure we won't get EOF reported prematurely */
 };

@@ -572,6 +582,8 @@ static void obj_array_copy(void *arg1, void *arg2)
 target->u16_1[i] = source->u16_1[i];
 target->u32_1[i] = source->u32_1[i];
 target->u32_2[i] = source->u32_2[i];
+target->u64_1[i] = source->u64_1[i];
+target->u64_2[i] = source->u64_2[i];
 }
 }

@@ -604,6 +616,7 @@ sta

[Qemu-devel] [PATCH 019/124] vmstate: Test for VMSTATE_INT32_TEST

2014-04-21 Thread Juan Quintela
Remove VMSTATE_INT32_V, we are removing versioning.
Move all users to use tests.

Signed-off-by: Juan Quintela 
---
 hw/input/ps2.c  | 2 +-
 include/migration/vmstate.h | 6 +++---
 target-i386/machine.c   | 4 ++--
 tests/test-vmstate.c| 4 
 4 files changed, 10 insertions(+), 6 deletions(-)

diff --git a/hw/input/ps2.c b/hw/input/ps2.c
index 0a0bd80..e05ff0d 100644
--- a/hw/input/ps2.c
+++ b/hw/input/ps2.c
@@ -613,7 +613,7 @@ static const VMStateDescription vmstate_ps2_keyboard = {
 VMSTATE_STRUCT(common, PS2KbdState, 0, vmstate_ps2_common, PS2State),
 VMSTATE_INT32(scan_enabled, PS2KbdState),
 VMSTATE_INT32(translate, PS2KbdState),
-VMSTATE_INT32_V(scancode_set, PS2KbdState,3),
+VMSTATE_INT32_TEST(scancode_set, PS2KbdState, vmstate_3_plus),
 VMSTATE_END_OF_LIST()
 },
 .subsections = (VMStateSubsection []) {
diff --git a/include/migration/vmstate.h b/include/migration/vmstate.h
index 1c07f95..036b800 100644
--- a/include/migration/vmstate.h
+++ b/include/migration/vmstate.h
@@ -533,8 +533,8 @@ extern const VMStateInfo vmstate_info_bitmap;
 VMSTATE_SINGLE_TEST(_f, _s, _t, 0, vmstate_info_int8, int8_t)
 #define VMSTATE_INT16_TEST(_f, _s, _t)\
 VMSTATE_SINGLE_TEST(_f, _s, _t, 0, vmstate_info_int16, int16_t)
-#define VMSTATE_INT32_V(_f, _s, _v)   \
-VMSTATE_SINGLE(_f, _s, _v, vmstate_info_int32, int32_t)
+#define VMSTATE_INT32_TEST(_f, _s, _t)\
+VMSTATE_SINGLE_TEST(_f, _s, _t, 0, vmstate_info_int32, int32_t)
 #define VMSTATE_INT64_V(_f, _s, _v)   \
 VMSTATE_SINGLE(_f, _s, _v, vmstate_info_int64, int64_t)

@@ -555,7 +555,7 @@ extern const VMStateInfo vmstate_info_bitmap;
 #define VMSTATE_INT16(_f, _s) \
 VMSTATE_INT16_TEST(_f, _s, NULL)
 #define VMSTATE_INT32(_f, _s) \
-VMSTATE_INT32_V(_f, _s, 0)
+VMSTATE_INT32_TEST(_f, _s, NULL)
 #define VMSTATE_INT64(_f, _s) \
 VMSTATE_INT64_V(_f, _s, 0)

diff --git a/target-i386/machine.c b/target-i386/machine.c
index 838a5b0..2aecf5f 100644
--- a/target-i386/machine.c
+++ b/target-i386/machine.c
@@ -671,10 +671,10 @@ const VMStateDescription vmstate_x86_cpu = {
 VMSTATE_UINT64_V(env.mtrr_deftype, X86CPU, 8),
 VMSTATE_MTRR_VARS(env.mtrr_var, X86CPU, 8, 8),
 /* KVM-related states */
-VMSTATE_INT32_V(env.interrupt_injected, X86CPU, 9),
+VMSTATE_INT32_TEST(env.interrupt_injected, X86CPU, vmstate_9_plus),
 VMSTATE_UINT32_V(env.mp_state, X86CPU, 9),
 VMSTATE_UINT64_V(env.tsc, X86CPU, 9),
-VMSTATE_INT32_V(env.exception_injected, X86CPU, 11),
+VMSTATE_INT32_TEST(env.exception_injected, X86CPU, vmstate_11_plus),
 VMSTATE_UINT8_V(env.soft_interrupt, X86CPU, 11),
 VMSTATE_UINT8_V(env.nmi_injected, X86CPU, 11),
 VMSTATE_UINT8_V(env.nmi_pending, X86CPU, 11),
diff --git a/tests/test-vmstate.c b/tests/test-vmstate.c
index 8929129..e8e6468 100644
--- a/tests/test-vmstate.c
+++ b/tests/test-vmstate.c
@@ -297,6 +297,8 @@ static const VMStateDescription vmstate_simple_test = {
 VMSTATE_INT8_TEST(i8_2, TestSimple, test_false),
 VMSTATE_INT16_TEST(i16_1, TestSimple, test_true),
 VMSTATE_INT16_TEST(i16_2, TestSimple, test_false),
+VMSTATE_INT32_TEST(i32_1, TestSimple, test_true),
+VMSTATE_INT32_TEST(i32_2, TestSimple, test_false),
 VMSTATE_END_OF_LIST()
 }
 };
@@ -305,6 +307,7 @@ uint8_t wire_simple_test[] = {
 /* b_1 */   0x01,
 /* i8_1 */  0x41,
 /* i16_1 */ 0x02, 0x00,
+/* i32_1 */ 0x00, 0x01, 0x11, 0x70,
 QEMU_VM_EOF, /* just to ensure we won't get EOF reported prematurely */
 };

@@ -324,6 +327,7 @@ static void test_simple_test(void)
 FIELD_EQUAL(b_1);
 FIELD_EQUAL(i8_1);
 FIELD_EQUAL(i16_1);
+FIELD_EQUAL(i32_1);
 }
 #undef FIELD_EQUAL

-- 
1.9.0




[Qemu-devel] [PATCH 043/124] vmstate: Test for VMSTATE_INT64_ARRAY

2014-04-21 Thread Juan Quintela
Remove unused VMSTATE_INT64_ARRAY_V.

Signed-off-by: Juan Quintela 
---
 include/migration/vmstate.h |  9 +++--
 tests/test-vmstate.c| 10 ++
 2 files changed, 13 insertions(+), 6 deletions(-)

diff --git a/include/migration/vmstate.h b/include/migration/vmstate.h
index 49446a8..0a562aa 100644
--- a/include/migration/vmstate.h
+++ b/include/migration/vmstate.h
@@ -633,6 +633,9 @@ extern const VMStateInfo vmstate_info_bitmap;
 #define VMSTATE_INT32_ARRAY(_f, _s, _n)   \
 VMSTATE_INT32_ARRAY_TEST(_f, _s, _n, NULL)

+#define VMSTATE_INT64_ARRAY(_f, _s, _n)   \
+VMSTATE_ARRAY_TEST(_f, _s, _n, NULL, vmstate_info_int64, int64_t)
+
 #define VMSTATE_UINT16_2DARRAY_V(_f, _s, _n1, _n2, _v)\
 VMSTATE_2DARRAY(_f, _s, _n1, _n2, _v, vmstate_info_uint16, uint16_t)

@@ -657,12 +660,6 @@ extern const VMStateInfo vmstate_info_bitmap;
 #define VMSTATE_UINT32_SUB_ARRAY(_f, _s, _start, _num)\
 VMSTATE_SUB_ARRAY(_f, _s, _start, _num, 0, vmstate_info_uint32, uint32_t)

-#define VMSTATE_INT64_ARRAY_V(_f, _s, _n, _v) \
-VMSTATE_ARRAY(_f, _s, _n, _v, vmstate_info_int64, int64_t)
-
-#define VMSTATE_INT64_ARRAY(_f, _s, _n)   \
-VMSTATE_INT64_ARRAY_V(_f, _s, _n, 0)
-
 #define VMSTATE_FLOAT64_ARRAY_V(_f, _s, _n, _v)   \
 VMSTATE_ARRAY(_f, _s, _n, _v, vmstate_info_float64, float64)

diff --git a/tests/test-vmstate.c b/tests/test-vmstate.c
index d7f2223..a930bde 100644
--- a/tests/test-vmstate.c
+++ b/tests/test-vmstate.c
@@ -522,6 +522,7 @@ typedef struct TestArray {
 int16_t i16_1[VMSTATE_ARRAY_SIZE];
 int32_t i32_1[VMSTATE_ARRAY_SIZE];
 int32_t i32_2[VMSTATE_ARRAY_SIZE];
+int64_t i64_1[VMSTATE_ARRAY_SIZE];
 } TestArray;

 TestArray obj_array = {
@@ -538,6 +539,7 @@ TestArray obj_array = {
 .i16_1 = {41, 42, 43, 44, 45},
 .i32_1 = {51, 52, 53, 54, 55},
 .i32_2 = {55, 54, 53, 52, 51},
+.i64_1 = {61, 62, 63, 64, 65},
 };

 static const VMStateDescription vmstate_array_primitive = {
@@ -554,6 +556,7 @@ static const VMStateDescription vmstate_array_primitive = {
 VMSTATE_UINT64_ARRAY(u64_1, TestArray, VMSTATE_ARRAY_SIZE),
 VMSTATE_INT16_ARRAY(i16_1, TestArray, VMSTATE_ARRAY_SIZE),
 VMSTATE_INT32_ARRAY(i32_1, TestArray, VMSTATE_ARRAY_SIZE),
+VMSTATE_INT64_ARRAY(i64_1, TestArray, VMSTATE_ARRAY_SIZE),
 VMSTATE_END_OF_LIST()
 }
 };
@@ -575,6 +578,11 @@ uint8_t wire_array_primitive[] = {
 /* i32_1 */ 0x00, 0x00, 0x00, 0x33, 0x00, 0x00, 0x00, 0x34,
 0x00, 0x00, 0x00, 0x35, 0x00, 0x00, 0x00, 0x36,
 0x00, 0x00, 0x00, 0x37,
+/* i64_1 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3d,
+0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3e,
+0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3f,
+0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40,
+0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x41,
 QEMU_VM_EOF, /* just to ensure we won't get EOF reported prematurely */
 };

@@ -599,6 +607,7 @@ static void obj_array_copy(void *arg1, void *arg2)
 target->i16_1[i] = source->i16_1[i];
 target->i32_1[i] = source->i32_1[i];
 target->i32_2[i] = source->i32_2[i];
+target->i64_1[i] = source->i64_1[i];
 }
 }

@@ -634,6 +643,7 @@ static void test_array_primitive(void)
 ELEM_EQUAL(u64_1, i);
 ELEM_EQUAL(i16_1, i);
 ELEM_EQUAL(i32_1, i);
+ELEM_EQUAL(i64_1, i);
 }
 }

-- 
1.9.0




[Qemu-devel] [PATCH 021/124] vmstate: Test for VMSTATE_UINT8_TEST

2014-04-21 Thread Juan Quintela
Remove VMSTATE_UINT8_V, we are removing versioning.
Move all users to VMSTATE_UINT8_TEST.

Signed-off-by: Juan Quintela 
---
 hw/char/serial.c|  2 +-
 hw/ide/core.c   |  2 +-
 hw/net/ne2000.c |  2 +-
 hw/timer/ds1338.c   |  2 +-
 hw/timer/hpet.c |  2 +-
 include/migration/vmstate.h |  9 +++--
 target-i386/machine.c   | 10 +-
 tests/test-vmstate.c|  4 
 8 files changed, 17 insertions(+), 16 deletions(-)

diff --git a/hw/char/serial.c b/hw/char/serial.c
index d17da16..4ec0164 100644
--- a/hw/char/serial.c
+++ b/hw/char/serial.c
@@ -612,7 +612,7 @@ const VMStateDescription vmstate_serial = {
 VMSTATE_UINT8(lsr, SerialState),
 VMSTATE_UINT8(msr, SerialState),
 VMSTATE_UINT8(scr, SerialState),
-VMSTATE_UINT8_V(fcr_vmstate, SerialState, 3),
+VMSTATE_UINT8_TEST(fcr_vmstate, SerialState, vmstate_3_plus),
 VMSTATE_END_OF_LIST()
 }
 };
diff --git a/hw/ide/core.c b/hw/ide/core.c
index 1cac5f5..2441e33 100644
--- a/hw/ide/core.c
+++ b/hw/ide/core.c
@@ -2404,7 +2404,7 @@ const VMStateDescription vmstate_ide_drive = {
 VMSTATE_UINT8(lba48, IDEState),
 VMSTATE_UINT8(sense_key, IDEState),
 VMSTATE_UINT8(asc, IDEState),
-VMSTATE_UINT8_V(cdrom_changed, IDEState, 3),
+VMSTATE_UINT8_TEST(cdrom_changed, IDEState, vmstate_3_plus),
 VMSTATE_END_OF_LIST()
 },
 .subsections = (VMStateSubsection []) {
diff --git a/hw/net/ne2000.c b/hw/net/ne2000.c
index d558b8c..84745d64 100644
--- a/hw/net/ne2000.c
+++ b/hw/net/ne2000.c
@@ -617,7 +617,7 @@ const VMStateDescription vmstate_ne2000 = {
 .minimum_version_id = 0,
 .post_load = ne2000_post_load,
 .fields = (VMStateField[]) {
-VMSTATE_UINT8_V(rxcr, NE2000State, 2),
+VMSTATE_UINT8_TEST(rxcr, NE2000State, vmstate_2_plus),
 VMSTATE_UINT8(cmd, NE2000State),
 VMSTATE_UINT32(start, NE2000State),
 VMSTATE_UINT32(stop, NE2000State),
diff --git a/hw/timer/ds1338.c b/hw/timer/ds1338.c
index ec6dbee..78b8e7b 100644
--- a/hw/timer/ds1338.c
+++ b/hw/timer/ds1338.c
@@ -43,7 +43,7 @@ static const VMStateDescription vmstate_ds1338 = {
 .fields = (VMStateField[]) {
 VMSTATE_I2C_SLAVE(parent_obj, DS1338State),
 VMSTATE_INT64(offset, DS1338State),
-VMSTATE_UINT8_V(wday_offset, DS1338State, 2),
+VMSTATE_UINT8_TEST(wday_offset, DS1338State, vmstate_2_plus),
 VMSTATE_UINT8_ARRAY(nvram, DS1338State, NVRAM_SIZE),
 VMSTATE_INT32(ptr, DS1338State),
 VMSTATE_BOOL(addr_byte, DS1338State),
diff --git a/hw/timer/hpet.c b/hw/timer/hpet.c
index fa590e3..2148568 100644
--- a/hw/timer/hpet.c
+++ b/hw/timer/hpet.c
@@ -303,7 +303,7 @@ static const VMStateDescription vmstate_hpet = {
 VMSTATE_UINT64(config, HPETState),
 VMSTATE_UINT64(isr, HPETState),
 VMSTATE_UINT64(hpet_counter, HPETState),
-VMSTATE_UINT8_V(num_timers, HPETState, 2),
+VMSTATE_UINT8_TEST(num_timers, HPETState, vmstate_2_plus),
 VMSTATE_STRUCT_VARRAY_UINT8(timer, HPETState, num_timers, 0,
 vmstate_hpet_timer, HPETTimer),
 VMSTATE_END_OF_LIST()
diff --git a/include/migration/vmstate.h b/include/migration/vmstate.h
index 453be1a..3f1931e 100644
--- a/include/migration/vmstate.h
+++ b/include/migration/vmstate.h
@@ -538,8 +538,8 @@ extern const VMStateInfo vmstate_info_bitmap;
 #define VMSTATE_INT64_TEST(_f, _s, _t)\
 VMSTATE_SINGLE_TEST(_f, _s, _t, 0, vmstate_info_int64, int64_t)

-#define VMSTATE_UINT8_V(_f, _s, _v)   \
-VMSTATE_SINGLE(_f, _s, _v, vmstate_info_uint8, uint8_t)
+#define VMSTATE_UINT8_TEST(_f, _s, _t)\
+VMSTATE_SINGLE_TEST(_f, _s, _t, 0, vmstate_info_uint8, uint8_t)
 #define VMSTATE_UINT16_V(_f, _s, _v)  \
 VMSTATE_SINGLE(_f, _s, _v, vmstate_info_uint16, uint16_t)
 #define VMSTATE_UINT32_V(_f, _s, _v)  \
@@ -560,7 +560,7 @@ extern const VMStateInfo vmstate_info_bitmap;
 VMSTATE_INT64_TEST(_f, _s, NULL)

 #define VMSTATE_UINT8(_f, _s) \
-VMSTATE_UINT8_V(_f, _s, 0)
+VMSTATE_UINT8_TEST(_f, _s, NULL)
 #define VMSTATE_UINT16(_f, _s)\
 VMSTATE_UINT16_V(_f, _s, 0)
 #define VMSTATE_UINT32(_f, _s)\
@@ -595,9 +595,6 @@ extern const VMStateInfo vmstate_info_bitmap;
 #define VMSTATE_INT32_LE(_f, _s)   \
 VMSTATE_SINGLE(_f, _s, 0, vmstate_info_int32_le, int32_t)

-#define VMSTATE_UINT8_TEST(_f, _s, _t)   \
-VMSTATE_SINGLE_TEST(_f, _s, _t, 0, vmstate_info_uint8, uint8_t)
-
 #define VMSTATE_UINT16_TEST(_f, _s, _t)   \
 VMSTATE_SINGLE_TEST(_f, _s, _t, 0, vmstate_info_

[Qemu-devel] [PATCH 028/124] vmstate: Test for VMSTATE_UINT8_EQUAL

2014-04-21 Thread Juan Quintela
We intruduce another full test.

Signed-off-by: Juan Quintela 
---
 include/migration/vmstate.h |  2 +-
 tests/test-vmstate.c| 42 ++
 2 files changed, 43 insertions(+), 1 deletion(-)

diff --git a/include/migration/vmstate.h b/include/migration/vmstate.h
index 52b0cc8..8d6230d 100644
--- a/include/migration/vmstate.h
+++ b/include/migration/vmstate.h
@@ -568,7 +568,7 @@ extern const VMStateInfo vmstate_info_bitmap;
 VMSTATE_UINT64_TEST(_f, _s, NULL)

 #define VMSTATE_UINT8_EQUAL(_f, _s)   \
-VMSTATE_SINGLE(_f, _s, 0, vmstate_info_uint8_equal, uint8_t)
+VMSTATE_SINGLE_TEST(_f, _s, NULL, 0, vmstate_info_uint8_equal, uint8_t)

 #define VMSTATE_UINT16_EQUAL(_f, _s)  \
 VMSTATE_SINGLE(_f, _s, 0, vmstate_info_uint16_equal, uint16_t)
diff --git a/tests/test-vmstate.c b/tests/test-vmstate.c
index f105e2c..7bc8422 100644
--- a/tests/test-vmstate.c
+++ b/tests/test-vmstate.c
@@ -360,6 +360,47 @@ static void test_simple_test(void)
 FIELD_EQUAL(u32_1);
 FIELD_EQUAL(u64_1);
 }
+
+static const VMStateDescription vmstate_simple_compare = {
+.name = "simple/compare",
+.version_id = 1,
+.minimum_version_id = 1,
+.minimum_version_id_old = 1,
+.fields = (VMStateField[]) {
+VMSTATE_UINT8_EQUAL(u8_1, TestSimple),
+VMSTATE_END_OF_LIST()
+}
+};
+
+uint8_t wire_simple_compare[] = {
+/* u8_1 */  0x82,
+QEMU_VM_EOF, /* just to ensure we won't get EOF reported prematurely */
+};
+
+static void test_simple_compare(void)
+{
+TestSimple obj, obj_clone;
+
+memset(&obj, 0, sizeof(obj));
+save_vmstate(&vmstate_simple_compare, &obj_simple);
+
+compare_vmstate(wire_simple_compare, sizeof(wire_simple_compare));
+
+
+/* we are testing that values are the same, we need to
+   have the same value */
+memcpy(&obj, &obj_simple, sizeof(obj));
+SUCCESS(load_vmstate(&vmstate_simple_compare, &obj, &obj_clone,
+ obj_simple_copy, 1, wire_simple_compare,
+ sizeof(wire_simple_compare)));
+
+/* we change the value, so it is not equal anymore */
+memcpy(&obj, &obj_simple, sizeof(obj));
+obj.u8_1 = 27;
+FAILURE(load_vmstate(&vmstate_simple_compare, &obj, &obj_clone,
+ obj_simple_copy, 1, wire_simple_compare,
+ sizeof(wire_simple_compare)));
+}
 #undef FIELD_EQUAL

 typedef struct TestBitmap {
@@ -666,6 +707,7 @@ int main(int argc, char **argv)
 g_test_add_func("/vmstate/simple/skip", test_simple_skip);
 g_test_add_func("/vmstate/simple/no_skip", test_simple_no_skip);
 g_test_add_func("/vmstate/simple/test", test_simple_test);
+g_test_add_func("/vmstate/simple/compare", test_simple_compare);
 g_test_add_func("/vmstate/simple/bitmap", test_simple_bitmap);
 g_test_run();

-- 
1.9.0




[Qemu-devel] [PATCH 022/124] vmstate: Test for VMSTATE_UINT16_TEST

2014-04-21 Thread Juan Quintela
Remove VMSTATE_UINT16_V, we are removing versioning.
Move all users to VMSTATE_UINT16_TEST.
Signed-off-by: Juan Quintela 
---
 hw/char/serial.c| 2 +-
 hw/net/lan9118.c| 4 ++--
 include/migration/vmstate.h | 9 +++--
 target-i386/machine.c   | 8 
 tests/test-vmstate.c| 4 
 5 files changed, 14 insertions(+), 13 deletions(-)

diff --git a/hw/char/serial.c b/hw/char/serial.c
index 4ec0164..681ab46 100644
--- a/hw/char/serial.c
+++ b/hw/char/serial.c
@@ -603,7 +603,7 @@ const VMStateDescription vmstate_serial = {
 .pre_save = serial_pre_save,
 .post_load = serial_post_load,
 .fields = (VMStateField[]) {
-VMSTATE_UINT16_V(divider, SerialState, 2),
+VMSTATE_UINT16_TEST(divider, SerialState, vmstate_2_plus),
 VMSTATE_UINT8(rbr, SerialState),
 VMSTATE_UINT8(ier, SerialState),
 VMSTATE_UINT8(iir, SerialState),
diff --git a/hw/net/lan9118.c b/hw/net/lan9118.c
index e528290..fecbf8d 100644
--- a/hw/net/lan9118.c
+++ b/hw/net/lan9118.c
@@ -310,8 +310,8 @@ static const VMStateDescription vmstate_lan9118 = {
 VMSTATE_INT32(rxp_pad, lan9118_state),
 VMSTATE_UINT32_V(write_word_prev_offset, lan9118_state, 2),
 VMSTATE_UINT32_V(write_word_n, lan9118_state, 2),
-VMSTATE_UINT16_V(write_word_l, lan9118_state, 2),
-VMSTATE_UINT16_V(write_word_h, lan9118_state, 2),
+VMSTATE_UINT16_TEST(write_word_l, lan9118_state, vmstate_2_plus),
+VMSTATE_UINT16_TEST(write_word_h, lan9118_state, vmstate_2_plus),
 VMSTATE_UINT32_V(read_word_prev_offset, lan9118_state, 2),
 VMSTATE_UINT32_V(read_word_n, lan9118_state, 2),
 VMSTATE_UINT32_V(read_long, lan9118_state, 2),
diff --git a/include/migration/vmstate.h b/include/migration/vmstate.h
index 3f1931e..a975602 100644
--- a/include/migration/vmstate.h
+++ b/include/migration/vmstate.h
@@ -540,8 +540,8 @@ extern const VMStateInfo vmstate_info_bitmap;

 #define VMSTATE_UINT8_TEST(_f, _s, _t)\
 VMSTATE_SINGLE_TEST(_f, _s, _t, 0, vmstate_info_uint8, uint8_t)
-#define VMSTATE_UINT16_V(_f, _s, _v)  \
-VMSTATE_SINGLE(_f, _s, _v, vmstate_info_uint16, uint16_t)
+#define VMSTATE_UINT16_TEST(_f, _s, _t)   \
+VMSTATE_SINGLE_TEST(_f, _s, _t, 0, vmstate_info_uint16, uint16_t)
 #define VMSTATE_UINT32_V(_f, _s, _v)  \
 VMSTATE_SINGLE(_f, _s, _v, vmstate_info_uint32, uint32_t)
 #define VMSTATE_UINT64_V(_f, _s, _v)  \
@@ -562,7 +562,7 @@ extern const VMStateInfo vmstate_info_bitmap;
 #define VMSTATE_UINT8(_f, _s) \
 VMSTATE_UINT8_TEST(_f, _s, NULL)
 #define VMSTATE_UINT16(_f, _s)\
-VMSTATE_UINT16_V(_f, _s, 0)
+VMSTATE_UINT16_TEST(_f, _s, NULL)
 #define VMSTATE_UINT32(_f, _s)\
 VMSTATE_UINT32_V(_f, _s, 0)
 #define VMSTATE_UINT64(_f, _s)\
@@ -595,9 +595,6 @@ extern const VMStateInfo vmstate_info_bitmap;
 #define VMSTATE_INT32_LE(_f, _s)   \
 VMSTATE_SINGLE(_f, _s, 0, vmstate_info_int32_le, int32_t)

-#define VMSTATE_UINT16_TEST(_f, _s, _t)   \
-VMSTATE_SINGLE_TEST(_f, _s, _t, 0, vmstate_info_uint16, uint16_t)
-
 #define VMSTATE_UINT32_TEST(_f, _s, _t)  \
 VMSTATE_SINGLE_TEST(_f, _s, _t, 0, vmstate_info_uint32, uint32_t)

diff --git a/target-i386/machine.c b/target-i386/machine.c
index e4fd27c..c05dc5a 100644
--- a/target-i386/machine.c
+++ b/target-i386/machine.c
@@ -660,10 +660,10 @@ const VMStateDescription vmstate_x86_cpu = {
 VMSTATE_UINT64_V(env.vm_vmcb, X86CPU, 5),
 VMSTATE_UINT64_V(env.tsc_offset, X86CPU, 5),
 VMSTATE_UINT64_V(env.intercept, X86CPU, 5),
-VMSTATE_UINT16_V(env.intercept_cr_read, X86CPU, 5),
-VMSTATE_UINT16_V(env.intercept_cr_write, X86CPU, 5),
-VMSTATE_UINT16_V(env.intercept_dr_read, X86CPU, 5),
-VMSTATE_UINT16_V(env.intercept_dr_write, X86CPU, 5),
+VMSTATE_UINT16_TEST(env.intercept_cr_read, X86CPU, vmstate_5_plus),
+VMSTATE_UINT16_TEST(env.intercept_cr_write, X86CPU, vmstate_5_plus),
+VMSTATE_UINT16_TEST(env.intercept_dr_read, X86CPU, vmstate_5_plus),
+VMSTATE_UINT16_TEST(env.intercept_dr_write, X86CPU, vmstate_5_plus),
 VMSTATE_UINT32_V(env.intercept_exceptions, X86CPU, 5),
 VMSTATE_UINT8_TEST(env.v_tpr, X86CPU, vmstate_5_plus),
 /* MTRRs */
diff --git a/tests/test-vmstate.c b/tests/test-vmstate.c
index 460665a..4e75c87 100644
--- a/tests/test-vmstate.c
+++ b/tests/test-vmstate.c
@@ -303,6 +303,8 @@ static const VMStateDescription vmstate_simple_test = {
 VMSTATE_INT64_TEST(i64_2, TestSimple, test_false),
 VMSTATE_UINT8_TEST(u8_1, TestSimple, t

[Qemu-devel] [PATCH 042/124] vmstate: Test for VMSTATE_INT32_ARRAY{_TEST}

2014-04-21 Thread Juan Quintela
Change only user of _V to _TEST.

Signed-off-by: Juan Quintela 
---
 hw/pci-host/piix.c  |  4 ++--
 include/migration/vmstate.h | 12 ++--
 tests/test-vmstate.c| 20 
 3 files changed, 28 insertions(+), 8 deletions(-)

diff --git a/hw/pci-host/piix.c b/hw/pci-host/piix.c
index e0e0946..a6c6834 100644
--- a/hw/pci-host/piix.c
+++ b/hw/pci-host/piix.c
@@ -567,8 +567,8 @@ static const VMStateDescription vmstate_piix3 = {
 .pre_save = piix3_pre_save,
 .fields = (VMStateField[]) {
 VMSTATE_PCI_DEVICE(dev, PIIX3State),
-VMSTATE_INT32_ARRAY_V(pci_irq_levels_vmstate, PIIX3State,
-  PIIX_NUM_PIRQS, 3),
+VMSTATE_INT32_ARRAY_TEST(pci_irq_levels_vmstate, PIIX3State,
+ PIIX_NUM_PIRQS, vmstate_3_plus),
 VMSTATE_END_OF_LIST()
 },
 .subsections = (VMStateSubsection[]) {
diff --git a/include/migration/vmstate.h b/include/migration/vmstate.h
index db8f295..49446a8 100644
--- a/include/migration/vmstate.h
+++ b/include/migration/vmstate.h
@@ -627,6 +627,12 @@ extern const VMStateInfo vmstate_info_bitmap;
 #define VMSTATE_INT16_ARRAY(_f, _s, _n)   \
 VMSTATE_ARRAY_TEST(_f, _s, _n, NULL, vmstate_info_int16, int16_t)

+#define VMSTATE_INT32_ARRAY_TEST(_f, _s, _n, _t)  \
+VMSTATE_ARRAY_TEST(_f, _s, _n, _t, vmstate_info_int32, int32_t)
+
+#define VMSTATE_INT32_ARRAY(_f, _s, _n)   \
+VMSTATE_INT32_ARRAY_TEST(_f, _s, _n, NULL)
+
 #define VMSTATE_UINT16_2DARRAY_V(_f, _s, _n1, _n2, _v)\
 VMSTATE_2DARRAY(_f, _s, _n1, _n2, _v, vmstate_info_uint16, uint16_t)

@@ -648,12 +654,6 @@ extern const VMStateInfo vmstate_info_bitmap;
 #define VMSTATE_UINT32_2DARRAY(_f, _s, _n1, _n2)  \
 VMSTATE_UINT32_2DARRAY_V(_f, _s, _n1, _n2, 0)

-#define VMSTATE_INT32_ARRAY_V(_f, _s, _n, _v) \
-VMSTATE_ARRAY(_f, _s, _n, _v, vmstate_info_int32, int32_t)
-
-#define VMSTATE_INT32_ARRAY(_f, _s, _n)   \
-VMSTATE_INT32_ARRAY_V(_f, _s, _n, 0)
-
 #define VMSTATE_UINT32_SUB_ARRAY(_f, _s, _start, _num)\
 VMSTATE_SUB_ARRAY(_f, _s, _start, _num, 0, vmstate_info_uint32, uint32_t)

diff --git a/tests/test-vmstate.c b/tests/test-vmstate.c
index c31d85f..d7f2223 100644
--- a/tests/test-vmstate.c
+++ b/tests/test-vmstate.c
@@ -520,6 +520,8 @@ typedef struct TestArray {
 uint64_t u64_1[VMSTATE_ARRAY_SIZE];
 uint64_t u64_2[VMSTATE_ARRAY_SIZE];
 int16_t i16_1[VMSTATE_ARRAY_SIZE];
+int32_t i32_1[VMSTATE_ARRAY_SIZE];
+int32_t i32_2[VMSTATE_ARRAY_SIZE];
 } TestArray;

 TestArray obj_array = {
@@ -534,6 +536,8 @@ TestArray obj_array = {
 .u64_1 = {31, 32, 33, 34, 35},
 .u64_2 = {35, 34, 33, 32, 31},
 .i16_1 = {41, 42, 43, 44, 45},
+.i32_1 = {51, 52, 53, 54, 55},
+.i32_2 = {55, 54, 53, 52, 51},
 };

 static const VMStateDescription vmstate_array_primitive = {
@@ -549,6 +553,7 @@ static const VMStateDescription vmstate_array_primitive = {
 VMSTATE_UINT32_ARRAY(u32_1, TestArray, VMSTATE_ARRAY_SIZE),
 VMSTATE_UINT64_ARRAY(u64_1, TestArray, VMSTATE_ARRAY_SIZE),
 VMSTATE_INT16_ARRAY(i16_1, TestArray, VMSTATE_ARRAY_SIZE),
+VMSTATE_INT32_ARRAY(i32_1, TestArray, VMSTATE_ARRAY_SIZE),
 VMSTATE_END_OF_LIST()
 }
 };
@@ -567,6 +572,9 @@ uint8_t wire_array_primitive[] = {
 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x22,
 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x23,
 /* i16_1 */ 0x00, 0x29, 0x00, 0x2a, 0x00, 0x2b, 0x00, 0x2c, 0x00, 0x2d,
+/* i32_1 */ 0x00, 0x00, 0x00, 0x33, 0x00, 0x00, 0x00, 0x34,
+0x00, 0x00, 0x00, 0x35, 0x00, 0x00, 0x00, 0x36,
+0x00, 0x00, 0x00, 0x37,
 QEMU_VM_EOF, /* just to ensure we won't get EOF reported prematurely */
 };

@@ -589,6 +597,8 @@ static void obj_array_copy(void *arg1, void *arg2)
 target->u64_1[i] = source->u64_1[i];
 target->u64_2[i] = source->u64_2[i];
 target->i16_1[i] = source->i16_1[i];
+target->i32_1[i] = source->i32_1[i];
+target->i32_2[i] = source->i32_2[i];
 }
 }

@@ -623,6 +633,7 @@ static void test_array_primitive(void)
 ELEM_EQUAL(u32_1, i);
 ELEM_EQUAL(u64_1, i);
 ELEM_EQUAL(i16_1, i);
+ELEM_EQUAL(i32_1, i);
 }
 }

@@ -643,6 +654,10 @@ static const VMStateDescription vmstate_array_test = {
   test_true),
 VMSTATE_UINT64_ARRAY_TEST(u64_2, TestArray, VMSTATE_ARRAY_SIZE,
   test_false),
+VMSTATE_INT32_ARRAY_TEST(i32_1, TestArray, VMSTATE_ARRAY_SIZE,
+ test_true),
+VMSTATE_INT32_ARRAY_TEST(i32_2, TestArray, VMSTATE_ARRAY_SIZE,
+ test_false),
 VMSTATE_END_OF_LIST()
 }
 };
@@ -658,6 +673,9 @@ uint8_t

[Qemu-devel] [PATCH 025/124] vmstate: Test for VMSTATE_FLOAT64

2014-04-21 Thread Juan Quintela
Remove unused VMSTATE_FLOAT64_V.

Signed-off-by: Juan Quintela 
---
 include/migration/vmstate.h | 5 +
 tests/test-vmstate.c| 5 +
 2 files changed, 6 insertions(+), 4 deletions(-)

diff --git a/include/migration/vmstate.h b/include/migration/vmstate.h
index 0940340..717c7fb 100644
--- a/include/migration/vmstate.h
+++ b/include/migration/vmstate.h
@@ -596,11 +596,8 @@ extern const VMStateInfo vmstate_info_bitmap;
 VMSTATE_SINGLE(_f, _s, 0, vmstate_info_int32_le, int32_t)


-#define VMSTATE_FLOAT64_V(_f, _s, _v) \
-VMSTATE_SINGLE(_f, _s, _v, vmstate_info_float64, float64)
-
 #define VMSTATE_FLOAT64(_f, _s)   \
-VMSTATE_FLOAT64_V(_f, _s, 0)
+VMSTATE_SINGLE_TEST(_f, _s, NULL, 0, vmstate_info_float64, float64)

 #define VMSTATE_TIMER_TEST(_f, _s, _test) \
 VMSTATE_POINTER_TEST(_f, _s, _test, vmstate_info_timer, QEMUTimer *)
diff --git a/tests/test-vmstate.c b/tests/test-vmstate.c
index 4a6a56d..c6ceec6 100644
--- a/tests/test-vmstate.c
+++ b/tests/test-vmstate.c
@@ -158,6 +158,7 @@ typedef struct TestSimple {
 int16_t  i16_1, i16_2;
 int32_t  i32_1, i32_2;
 int64_t  i64_1, i64_2;
+float64 f64;
 } TestSimple;

 /* Object instantiation, we are going to use it in more than one test */
@@ -181,6 +182,7 @@ TestSimple obj_simple = {
 .i32_2 = -7,
 .i64_1 = 12121212,
 .i64_2 = -12121212,
+.f64 = float64_pi,
 };

 /* Description of the values.  If you add a primitive type
@@ -205,6 +207,7 @@ static const VMStateDescription vmstate_simple_primitive = {
 VMSTATE_INT32(i32_2, TestSimple),
 VMSTATE_INT64(i64_1, TestSimple),
 VMSTATE_INT64(i64_2, TestSimple),
+VMSTATE_FLOAT64(f64, TestSimple),
 VMSTATE_END_OF_LIST()
 }
 };
@@ -236,6 +239,7 @@ uint8_t wire_simple_primitive[] = {
 /* i32_2 */ 0xff, 0xfe, 0xee, 0x90,
 /* i64_1 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0xb8, 0xf4, 0x7c,
 /* i64_2 */ 0xff, 0xff, 0xff, 0xff, 0xff, 0x47, 0x0b, 0x84,
+/* f64 */   0x40, 0x09, 0x21, 0xfb, 0x54, 0x44, 0x2d, 0x18,
 QEMU_VM_EOF, /* just to ensure we won't get EOF reported prematurely */
 };

@@ -273,6 +277,7 @@ static void test_simple_primitive(void)
 FIELD_EQUAL(i32_2);
 FIELD_EQUAL(i64_1);
 FIELD_EQUAL(i64_2);
+FIELD_EQUAL(f64);
 }

 static bool test_true(void *opaque, int version_id)
-- 
1.9.0




[Qemu-devel] [PATCH 051/124] vmstate: All ptimers users were at least at version 1 or more

2014-04-21 Thread Juan Quintela
So we can remove the version field.

Signed-off-by: Juan Quintela 
---
 include/hw/ptimer.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/include/hw/ptimer.h b/include/hw/ptimer.h
index 8ebacbb..ef852bf 100644
--- a/include/hw/ptimer.h
+++ b/include/hw/ptimer.h
@@ -28,7 +28,7 @@ void ptimer_stop(ptimer_state *s);
 extern const VMStateDescription vmstate_ptimer;

 #define VMSTATE_PTIMER(_field, _state) \
-VMSTATE_STRUCT_POINTER_V(_field, _state, 1, vmstate_ptimer, ptimer_state)
+VMSTATE_STRUCT_POINTER(_field, _state, vmstate_ptimer, ptimer_state)

 #define VMSTATE_PTIMER_ARRAY(_f, _s, _n)\
 VMSTATE_ARRAY_OF_POINTER_TO_STRUCT(_f, _s, _n, 0,   \
-- 
1.9.0




[Qemu-devel] [PATCH 050/124] vmstate: Remove unused version fields from ARM

2014-04-21 Thread Juan Quintela
Signed-off-by: Juan Quintela 
---
 target-ppc/machine.c | 14 --
 1 file changed, 4 insertions(+), 10 deletions(-)

diff --git a/target-ppc/machine.c b/target-ppc/machine.c
index d7807f8..4540fe2 100644
--- a/target-ppc/machine.c
+++ b/target-ppc/machine.c
@@ -120,11 +120,8 @@ static const VMStateInfo vmstate_info_avr = {
 .put  = put_avr,
 };

-#define VMSTATE_AVR_ARRAY_V(_f, _s, _n, _v)   \
-VMSTATE_ARRAY(_f, _s, _n, _v, vmstate_info_avr, ppc_avr_t)
-
-#define VMSTATE_AVR_ARRAY(_f, _s, _n) \
-VMSTATE_AVR_ARRAY_V(_f, _s, _n, 0)
+#define VMSTATE_AVR_ARRAY(_f, _s, _n) \
+VMSTATE_ARRAY_TEST(_f, _s, _n, NULL, vmstate_info_avr, ppc_avr_t)

 static void cpu_pre_save(void *opaque)
 {
@@ -290,11 +287,8 @@ static const VMStateInfo vmstate_info_slbe = {
 .put  = put_slbe,
 };

-#define VMSTATE_SLB_ARRAY_V(_f, _s, _n, _v)   \
-VMSTATE_ARRAY(_f, _s, _n, _v, vmstate_info_slbe, ppc_slb_t)
-
-#define VMSTATE_SLB_ARRAY(_f, _s, _n) \
-VMSTATE_SLB_ARRAY_V(_f, _s, _n, 0)
+#define VMSTATE_SLB_ARRAY(_f, _s, _n) \
+VMSTATE_ARRAY_TEST(_f, _s, _n, NULL, vmstate_info_slbe, ppc_slb_t)

 static bool slb_needed(void *opaque)
 {
-- 
1.9.0




[Qemu-devel] [PATCH 029/124] vmstate: Test for VMSTATE_UINT16_EQUAL

2014-04-21 Thread Juan Quintela
We change only user of VMSTATE_UINT16_EQUAL_V to VMSTATE_UINT16_EQUAL_TEST.

Signed-off-by: Juan Quintela 
---
 hw/nvram/eeprom93xx.c   | 7 ++-
 include/migration/vmstate.h | 8 
 tests/test-vmstate.c| 8 +++-
 3 files changed, 17 insertions(+), 6 deletions(-)

diff --git a/hw/nvram/eeprom93xx.c b/hw/nvram/eeprom93xx.c
index 0af4d67..d07bafb 100644
--- a/hw/nvram/eeprom93xx.c
+++ b/hw/nvram/eeprom93xx.c
@@ -121,6 +121,11 @@ static bool is_old_eeprom_version(void *opaque, int 
version_id)
 return version_id == OLD_EEPROM_VERSION;
 }

+static bool is_eeprom_version(void *opaque, int version_id)
+{
+return version_id == EEPROM_VERSION;
+}
+
 static const VMStateDescription vmstate_eeprom = {
 .name = "eeprom",
 .version_id = EEPROM_VERSION,
@@ -138,7 +143,7 @@ static const VMStateDescription vmstate_eeprom = {
 VMSTATE_UINT8(addrbits, eeprom_t),
 VMSTATE_UINT16_HACK_TEST(size, eeprom_t, is_old_eeprom_version),
 VMSTATE_UNUSED_TEST(is_old_eeprom_version, 1),
-VMSTATE_UINT16_EQUAL_V(size, eeprom_t, EEPROM_VERSION),
+VMSTATE_UINT16_EQUAL_TEST(size, eeprom_t, is_eeprom_version),
 VMSTATE_UINT16(data, eeprom_t),
 VMSTATE_VARRAY_UINT16_UNSAFE(contents, eeprom_t, size, 0,
  vmstate_info_uint16, uint16_t),
diff --git a/include/migration/vmstate.h b/include/migration/vmstate.h
index 8d6230d..9a64315 100644
--- a/include/migration/vmstate.h
+++ b/include/migration/vmstate.h
@@ -570,11 +570,11 @@ extern const VMStateInfo vmstate_info_bitmap;
 #define VMSTATE_UINT8_EQUAL(_f, _s)   \
 VMSTATE_SINGLE_TEST(_f, _s, NULL, 0, vmstate_info_uint8_equal, uint8_t)

-#define VMSTATE_UINT16_EQUAL(_f, _s)  \
-VMSTATE_SINGLE(_f, _s, 0, vmstate_info_uint16_equal, uint16_t)
+#define VMSTATE_UINT16_EQUAL_TEST(_f, _s, _t) \
+VMSTATE_SINGLE_TEST(_f, _s, _t, 0, vmstate_info_uint16_equal, uint16_t)

-#define VMSTATE_UINT16_EQUAL_V(_f, _s, _v)\
-VMSTATE_SINGLE(_f, _s, _v, vmstate_info_uint16_equal, uint16_t)
+#define VMSTATE_UINT16_EQUAL(_f, _s)  \
+VMSTATE_UINT16_EQUAL_TEST(_f, _s, NULL)

 #define VMSTATE_INT32_EQUAL(_f, _s)   \
 VMSTATE_SINGLE(_f, _s, 0, vmstate_info_int32_equal, int32_t)
diff --git a/tests/test-vmstate.c b/tests/test-vmstate.c
index 7bc8422..1e28985 100644
--- a/tests/test-vmstate.c
+++ b/tests/test-vmstate.c
@@ -152,7 +152,7 @@ static int load_vmstate(const VMStateDescription *desc,
 typedef struct TestSimple {
 bool b_1,   b_2;
 uint8_t  u8_1,  u8_2;
-uint16_t u16_1, u16_2;
+uint16_t u16_1, u16_2, u16_3;
 uint32_t u32_1, u32_2;
 uint64_t u64_1, u64_2;
 int8_t   i8_1,  i8_2;
@@ -171,6 +171,7 @@ TestSimple obj_simple = {
 .u8_1 = 130,
 .u16_1 = 512,
 .u16_2 = 45000,
+.u16_3 = 512,
 .u32_1 = 7,
 .u32_2 = 10,
 .u64_1 = 12121212,
@@ -368,12 +369,17 @@ static const VMStateDescription vmstate_simple_compare = {
 .minimum_version_id_old = 1,
 .fields = (VMStateField[]) {
 VMSTATE_UINT8_EQUAL(u8_1, TestSimple),
+VMSTATE_UINT16_EQUAL(u16_1, TestSimple),
+VMSTATE_UINT16_EQUAL_TEST(u16_2, TestSimple, test_false),
+VMSTATE_UINT16_EQUAL_TEST(u16_3, TestSimple, test_true),
 VMSTATE_END_OF_LIST()
 }
 };

 uint8_t wire_simple_compare[] = {
 /* u8_1 */  0x82,
+/* u16_1 */ 0x02, 0x00,
+/* u16_3 */ 0x02, 0x00,
 QEMU_VM_EOF, /* just to ensure we won't get EOF reported prematurely */
 };

-- 
1.9.0




[Qemu-devel] [PATCH 052/124] vmstate: Remove version from all variants of VMSTATE_STRUCT_POINTER*

2014-04-21 Thread Juan Quintela
There were no more users of them.

Signed-off-by: Juan Quintela 
---
 include/migration/vmstate.h | 17 ++---
 1 file changed, 2 insertions(+), 15 deletions(-)

diff --git a/include/migration/vmstate.h b/include/migration/vmstate.h
index a715904..f0c99d9 100644
--- a/include/migration/vmstate.h
+++ b/include/migration/vmstate.h
@@ -310,18 +310,8 @@ extern const VMStateInfo vmstate_info_bitmap;
 .offset   = vmstate_offset_value(_state, _field, _type), \
 }

-#define VMSTATE_STRUCT_POINTER_V(_field, _state, _version, _vmsd, _type) { \
+#define VMSTATE_STRUCT_POINTER_TEST(_field, _state, _test, _vmsd, _type) { \
 .name = (stringify(_field)), \
-.version_id   = (_version),\
-.vmsd = &(_vmsd),\
-.size = sizeof(_type *), \
-.flags= VMS_STRUCT|VMS_POINTER,  \
-.offset   = vmstate_offset_pointer(_state, _field, _type),   \
-}
-
-#define VMSTATE_STRUCT_POINTER_TEST_V(_field, _state, _test, _version, _vmsd, 
_type) { \
-.name = (stringify(_field)), \
-.version_id   = (_version),\
 .field_exists = (_test), \
 .vmsd = &(_vmsd),\
 .size = sizeof(_type *), \
@@ -516,10 +506,7 @@ extern const VMStateInfo vmstate_info_bitmap;
 VMSTATE_STRUCT_TEST(_field, _state, NULL, _version, _vmsd, _type)

 #define VMSTATE_STRUCT_POINTER(_field, _state, _vmsd, _type)  \
-VMSTATE_STRUCT_POINTER_V(_field, _state, 0, _vmsd, _type)
-
-#define VMSTATE_STRUCT_POINTER_TEST(_field, _state, _test, _vmsd, _type) \
-VMSTATE_STRUCT_POINTER_TEST_V(_field, _state, _test, 0, _vmsd, _type)
+VMSTATE_STRUCT_POINTER_TEST(_field, _state, NULL, _vmsd, _type)

 #define VMSTATE_STRUCT_ARRAY(_field, _state, _num, _version, _vmsd, _type) \
 VMSTATE_STRUCT_ARRAY_TEST(_field, _state, _num, NULL, _version,   \
-- 
1.9.0




[Qemu-devel] [PATCH 033/124] vmstate: Test for VMSTATE_INT32_LE

2014-04-21 Thread Juan Quintela
Add tests for less/more than the value on destination.

Signed-off-by: Juan Quintela 
---
 include/migration/vmstate.h |  4 ++--
 tests/test-vmstate.c| 20 +++-
 2 files changed, 21 insertions(+), 3 deletions(-)

diff --git a/include/migration/vmstate.h b/include/migration/vmstate.h
index 9765973..397fa1d 100644
--- a/include/migration/vmstate.h
+++ b/include/migration/vmstate.h
@@ -585,8 +585,8 @@ extern const VMStateInfo vmstate_info_bitmap;
 #define VMSTATE_INT32_EQUAL(_f, _s)   \
 VMSTATE_SINGLE_TEST(_f, _s, NULL, 0, vmstate_info_int32_equal, int32_t)

-#define VMSTATE_INT32_LE(_f, _s)   \
-VMSTATE_SINGLE(_f, _s, 0, vmstate_info_int32_le, int32_t)
+#define VMSTATE_INT32_LE(_f, _s)  \
+VMSTATE_SINGLE_TEST(_f, _s, NULL, 0, vmstate_info_int32_le, int32_t)


 #define VMSTATE_FLOAT64(_f, _s)   \
diff --git a/tests/test-vmstate.c b/tests/test-vmstate.c
index 3fc8f5e..3e871c3 100644
--- a/tests/test-vmstate.c
+++ b/tests/test-vmstate.c
@@ -374,7 +374,8 @@ static const VMStateDescription vmstate_simple_compare = {
 VMSTATE_UINT16_EQUAL_TEST(u16_3, TestSimple, test_true),
 VMSTATE_UINT32_EQUAL(u32_1, TestSimple),
 VMSTATE_UINT64_EQUAL(u64_1, TestSimple),
-VMSTATE_INT32_EQUAL(i32_1, TestSimple),
+VMSTATE_INT32_EQUAL(i32_2, TestSimple),
+VMSTATE_INT32_LE(i32_1, TestSimple),
 VMSTATE_END_OF_LIST()
 }
 };
@@ -385,6 +386,7 @@ uint8_t wire_simple_compare[] = {
 /* u16_3 */ 0x02, 0x00,
 /* u32_1 */ 0x00, 0x01, 0x11, 0x70,
 /* u64_1 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0xb8, 0xf4, 0x7c,
+/* i32_2 */ 0xff, 0xfe, 0xee, 0x90,
 /* i32_1 */ 0x00, 0x01, 0x11, 0x70,
 QEMU_VM_EOF, /* just to ensure we won't get EOF reported prematurely */
 };
@@ -412,6 +414,22 @@ static void test_simple_compare(void)
 FAILURE(load_vmstate(&vmstate_simple_compare, &obj, &obj_clone,
  obj_simple_copy, 1, wire_simple_compare,
  sizeof(wire_simple_compare)));
+
+/* testing less equal */
+
+/* we change the value, so it is not equal anymore */
+memcpy(&obj, &obj_simple, sizeof(obj));
+obj.i32_1 = 8000;
+FAILURE(load_vmstate(&vmstate_simple_compare, &obj, &obj_clone,
+ obj_simple_copy, 1, wire_simple_compare,
+ sizeof(wire_simple_compare)));
+
+/* we change the value, so it is not equal anymore */
+memcpy(&obj, &obj_simple, sizeof(obj));
+obj.i32_1 = 8;
+SUCCESS(load_vmstate(&vmstate_simple_compare, &obj, &obj_clone,
+ obj_simple_copy, 1, wire_simple_compare,
+ sizeof(wire_simple_compare)));
 }
 #undef FIELD_EQUAL

-- 
1.9.0




[Qemu-devel] [PATCH 053/124] vmstate: Port last 3 users of VMSTATE_ARRAY to VMSTATE_ARRAY_TEST

2014-04-21 Thread Juan Quintela
And then remove VMSTATE_ARRAY.

Signed-off-by: Juan Quintela 
---
 hw/net/vmxnet3.c| 13 +++--
 include/migration/vmstate.h | 10 --
 2 files changed, 7 insertions(+), 16 deletions(-)

diff --git a/hw/net/vmxnet3.c b/hw/net/vmxnet3.c
index d8e8d59..1faf58d 100644
--- a/hw/net/vmxnet3.c
+++ b/hw/net/vmxnet3.c
@@ -2457,14 +2457,15 @@ static const VMStateDescription vmstate_vmxnet3 = {
 VMSTATE_UINT64(drv_shmem, VMXNET3State),
 VMSTATE_UINT64(temp_shared_guest_driver_memory, VMXNET3State),

-VMSTATE_ARRAY(txq_descr, VMXNET3State,
-VMXNET3_DEVICE_MAX_TX_QUEUES, 0, txq_descr_info,
+VMSTATE_ARRAY_TEST(txq_descr, VMXNET3State,
+VMXNET3_DEVICE_MAX_TX_QUEUES, NULL, txq_descr_info,
 Vmxnet3TxqDescr),
-VMSTATE_ARRAY(rxq_descr, VMXNET3State,
-VMXNET3_DEVICE_MAX_RX_QUEUES, 0, rxq_descr_info,
+VMSTATE_ARRAY_TEST(rxq_descr, VMXNET3State,
+VMXNET3_DEVICE_MAX_RX_QUEUES, NULL, rxq_descr_info,
 Vmxnet3RxqDescr),
-VMSTATE_ARRAY(interrupt_states, VMXNET3State, VMXNET3_MAX_INTRS,
-0, int_state_info, Vmxnet3IntState),
+VMSTATE_ARRAY_TEST(interrupt_states, VMXNET3State,
+VMXNET3_MAX_INTRS, NULL, int_state_info,
+Vmxnet3IntState),

 VMSTATE_END_OF_LIST()
 },
diff --git a/include/migration/vmstate.h b/include/migration/vmstate.h
index f0c99d9..60b67dc 100644
--- a/include/migration/vmstate.h
+++ b/include/migration/vmstate.h
@@ -221,16 +221,6 @@ extern const VMStateInfo vmstate_info_bitmap;
 .offset = vmstate_offset_value(_state, _field, _type),   \
 }

-#define VMSTATE_ARRAY(_field, _state, _num, _version, _info, _type) {\
-.name   = (stringify(_field)),   \
-.version_id = (_version),\
-.num= (_num),\
-.info   = &(_info),  \
-.size   = sizeof(_type), \
-.flags  = VMS_ARRAY, \
-.offset = vmstate_offset_array(_state, _field, _type, _num), \
-}
-
 #define VMSTATE_2DARRAY(_field, _state, _n1, _n2, _version, _info, _type) { \
 .name   = (stringify(_field)),  \
 .version_id = (_version),   \
-- 
1.9.0




[Qemu-devel] [PATCH 034/124] vmstate: s/VMSTATE_INT32_LE/VMSTATE_INT32_POSITIVE_LE/

2014-04-21 Thread Juan Quintela
From: "Michael S. Tsirkin" 

As the macro verifies the value is positive, rename it
to make the function clearer.

Signed-off-by: Michael S. Tsirkin 
Signed-off-by: Juan Quintela 
---
 hw/pci/pci.c| 4 ++--
 include/migration/vmstate.h | 3 +--
 target-arm/machine.c| 2 +-
 tests/test-vmstate.c| 2 +-
 4 files changed, 5 insertions(+), 6 deletions(-)

diff --git a/hw/pci/pci.c b/hw/pci/pci.c
index d4375b6..2ba6b30 100644
--- a/hw/pci/pci.c
+++ b/hw/pci/pci.c
@@ -473,7 +473,7 @@ const VMStateDescription vmstate_pci_device = {
 .version_id = 2,
 .minimum_version_id = 1,
 .fields = (VMStateField[]) {
-VMSTATE_INT32_LE(version_id, PCIDevice),
+VMSTATE_INT32_POSITIVE_LE(version_id, PCIDevice),
 VMSTATE_BUFFER_UNSAFE_INFO(config, PCIDevice, 0,
vmstate_info_pci_config,
PCI_CONFIG_SPACE_SIZE),
@@ -489,7 +489,7 @@ const VMStateDescription vmstate_pcie_device = {
 .version_id = 2,
 .minimum_version_id = 1,
 .fields = (VMStateField[]) {
-VMSTATE_INT32_LE(version_id, PCIDevice),
+VMSTATE_INT32_POSITIVE_LE(version_id, PCIDevice),
 VMSTATE_BUFFER_UNSAFE_INFO(config, PCIDevice, 0,
vmstate_info_pci_config,
PCIE_CONFIG_SPACE_SIZE),
diff --git a/include/migration/vmstate.h b/include/migration/vmstate.h
index 397fa1d..132757f 100644
--- a/include/migration/vmstate.h
+++ b/include/migration/vmstate.h
@@ -585,10 +585,9 @@ extern const VMStateInfo vmstate_info_bitmap;
 #define VMSTATE_INT32_EQUAL(_f, _s)   \
 VMSTATE_SINGLE_TEST(_f, _s, NULL, 0, vmstate_info_int32_equal, int32_t)

-#define VMSTATE_INT32_LE(_f, _s)  \
+#define VMSTATE_INT32_POSITIVE_LE(_f, _s) \
 VMSTATE_SINGLE_TEST(_f, _s, NULL, 0, vmstate_info_int32_le, int32_t)

-
 #define VMSTATE_FLOAT64(_f, _s)   \
 VMSTATE_SINGLE_TEST(_f, _s, NULL, 0, vmstate_info_float64, float64)

diff --git a/target-arm/machine.c b/target-arm/machine.c
index cb11b2b..5092dcd 100644
--- a/target-arm/machine.c
+++ b/target-arm/machine.c
@@ -243,7 +243,7 @@ const VMStateDescription vmstate_arm_cpu = {
 /* The length-check must come before the arrays to avoid
  * incoming data possibly overflowing the array.
  */
-VMSTATE_INT32_LE(cpreg_vmstate_array_len, ARMCPU),
+VMSTATE_INT32_POSITIVE_LE(cpreg_vmstate_array_len, ARMCPU),
 VMSTATE_VARRAY_INT32(cpreg_vmstate_indexes, ARMCPU,
  cpreg_vmstate_array_len,
  0, vmstate_info_uint64, uint64_t),
diff --git a/tests/test-vmstate.c b/tests/test-vmstate.c
index 3e871c3..3b93ab9 100644
--- a/tests/test-vmstate.c
+++ b/tests/test-vmstate.c
@@ -375,7 +375,7 @@ static const VMStateDescription vmstate_simple_compare = {
 VMSTATE_UINT32_EQUAL(u32_1, TestSimple),
 VMSTATE_UINT64_EQUAL(u64_1, TestSimple),
 VMSTATE_INT32_EQUAL(i32_2, TestSimple),
-VMSTATE_INT32_LE(i32_1, TestSimple),
+VMSTATE_INT32_POSITIVE_LE(i32_1, TestSimple),
 VMSTATE_END_OF_LIST()
 }
 };
-- 
1.9.0




[Qemu-devel] [PATCH 036/124] vmstate: Test for VMSTATE_ARRAY_BOOL_TEST

2014-04-21 Thread Juan Quintela
We add all the boilerplate code for testing arrays.
We change only user of VMSTATE_ARRAY_BOOL_V to VMSTATE_ARRAY_BOOL_TEST.

Signed-off-by: Juan Quintela 
---
 hw/audio/hda-codec.c|   3 +-
 include/migration/vmstate.h |   8 +--
 tests/test-vmstate.c| 117 
 3 files changed, 123 insertions(+), 5 deletions(-)

diff --git a/hw/audio/hda-codec.c b/hw/audio/hda-codec.c
index 09559ef..1c1a138 100644
--- a/hw/audio/hda-codec.c
+++ b/hw/audio/hda-codec.c
@@ -603,7 +603,8 @@ static const VMStateDescription vmstate_hda_audio = {
  vmstate_hda_audio_stream,
  HDAAudioStream),
 VMSTATE_BOOL_ARRAY(running_compat, HDAAudioState, 16),
-VMSTATE_BOOL_ARRAY_V(running_real, HDAAudioState, 2 * 16, 2),
+VMSTATE_BOOL_ARRAY_TEST(running_real, HDAAudioState, 2 * 16,
+vmstate_2_plus),
 VMSTATE_END_OF_LIST()
 }
 };
diff --git a/include/migration/vmstate.h b/include/migration/vmstate.h
index e86d9bd..490f0f4 100644
--- a/include/migration/vmstate.h
+++ b/include/migration/vmstate.h
@@ -600,11 +600,11 @@ extern const VMStateInfo vmstate_info_bitmap;
 #define VMSTATE_TIMER_ARRAY(_f, _s, _n)   \
 VMSTATE_ARRAY_OF_POINTER(_f, _s, _n, 0, vmstate_info_timer, QEMUTimer *)

-#define VMSTATE_BOOL_ARRAY_V(_f, _s, _n, _v) \
-VMSTATE_ARRAY(_f, _s, _n, _v, vmstate_info_bool, bool)
+#define VMSTATE_BOOL_ARRAY_TEST(_f, _s, _n, _t)   \
+VMSTATE_ARRAY_TEST(_f, _s, _n, _t, vmstate_info_bool, bool)

-#define VMSTATE_BOOL_ARRAY(_f, _s, _n)   \
-VMSTATE_BOOL_ARRAY_V(_f, _s, _n, 0)
+#define VMSTATE_BOOL_ARRAY(_f, _s, _n)\
+VMSTATE_BOOL_ARRAY_TEST(_f, _s, _n, NULL)

 #define VMSTATE_UINT16_ARRAY_V(_f, _s, _n, _v) \
 VMSTATE_ARRAY(_f, _s, _n, _v, vmstate_info_uint16, uint16_t)
diff --git a/tests/test-vmstate.c b/tests/test-vmstate.c
index 3b93ab9..5cc5706 100644
--- a/tests/test-vmstate.c
+++ b/tests/test-vmstate.c
@@ -506,6 +506,121 @@ static void test_simple_bitmap(void)
 #undef FIELD_EQUAL
 }

+#define VMSTATE_ARRAY_SIZE 5
+
+typedef struct TestArray {
+int32_t  size;
+bool b_1[VMSTATE_ARRAY_SIZE];
+bool b_2[VMSTATE_ARRAY_SIZE];
+} TestArray;
+
+TestArray obj_array = {
+.size = VMSTATE_ARRAY_SIZE,
+.b_1 = { false, true, false, true, false},
+.b_2 = { true, false, true, false, true},
+};
+
+static const VMStateDescription vmstate_array_primitive = {
+.name = "array/primitive",
+.version_id = 1,
+.minimum_version_id = 1,
+.minimum_version_id_old = 1,
+.fields = (VMStateField[]) {
+VMSTATE_INT32_EQUAL(size, TestArray),
+VMSTATE_BOOL_ARRAY(b_1, TestArray, VMSTATE_ARRAY_SIZE),
+VMSTATE_END_OF_LIST()
+}
+};
+
+uint8_t wire_array_primitive[] = {
+/* size */  0x00, 0x00, 0x00, 0x05,
+/* b_1 */   0x00, 0x01, 0x00, 0x01, 0x00,
+QEMU_VM_EOF, /* just to ensure we won't get EOF reported prematurely */
+};
+
+static void obj_array_copy(void *arg1, void *arg2)
+{
+TestArray *target = arg1;
+TestArray *source = arg2;
+int i;
+
+target->size = source->size;
+
+for (i = 0; i < VMSTATE_ARRAY_SIZE; i++) {
+target->b_1[i] = source->b_1[i];
+target->b_2[i] = source->b_2[i];
+}
+}
+
+static void test_array_primitive(void)
+{
+TestArray obj, obj_clone;
+int i;
+
+memset(&obj, 0, sizeof(obj));
+obj.size = VMSTATE_ARRAY_SIZE;
+
+save_vmstate(&vmstate_array_primitive, &obj_array);
+
+compare_vmstate(wire_array_primitive, sizeof(wire_array_primitive));
+
+SUCCESS(load_vmstate(&vmstate_array_primitive, &obj, &obj_clone,
+ obj_array_copy, 1, wire_array_primitive,
+ sizeof(wire_array_primitive)));
+
+#define FIELD_EQUAL(name)   g_assert_cmpint(obj.name, ==, obj_array.name)
+#define ELEM_EQUAL(name, i) \
+g_assert_cmpint(obj.name[i], ==, obj_array.name[i])
+
+FIELD_EQUAL(size);
+for (i = 0; i < VMSTATE_ARRAY_SIZE; i++) {
+ELEM_EQUAL(b_1, i);
+}
+}
+
+static const VMStateDescription vmstate_array_test = {
+.name = "array/test",
+.version_id = 1,
+.minimum_version_id = 1,
+.minimum_version_id_old = 1,
+.fields = (VMStateField[]) {
+VMSTATE_INT32_EQUAL(size, TestArray),
+VMSTATE_BOOL_ARRAY_TEST(b_1, TestArray, VMSTATE_ARRAY_SIZE, test_true),
+VMSTATE_BOOL_ARRAY_TEST(b_2, TestArray, VMSTATE_ARRAY_SIZE, 
test_false),
+VMSTATE_END_OF_LIST()
+}
+};
+
+uint8_t wire_array_test[] = {
+/* size */  0x00, 0x00, 0x00, 0x05,
+/* b_1 */   0x00, 0x01, 0x00, 0x01, 0x00,
+QEMU_VM_EOF, /* just to ensure we won't get EOF reported prematurely */
+};
+
+static void test_array_test(void)
+{
+TestArray obj, obj_clone;
+int i;
+
+memset(&obj, 0, si

[Qemu-devel] [PATCH 038/124] vmstate: Test for VMSTATE_UINT16_ARRAY

2014-04-21 Thread Juan Quintela
Remove unused VMSTATE_UINT16_ARRAY_V.

Signed-off-by: Juan Quintela 
---
 include/migration/vmstate.h | 7 ++-
 tests/test-vmstate.c| 6 ++
 2 files changed, 8 insertions(+), 5 deletions(-)

diff --git a/include/migration/vmstate.h b/include/migration/vmstate.h
index 19789c4..5935d60 100644
--- a/include/migration/vmstate.h
+++ b/include/migration/vmstate.h
@@ -609,15 +609,12 @@ extern const VMStateInfo vmstate_info_bitmap;
 #define VMSTATE_UINT8_ARRAY(_f, _s, _n)   \
 VMSTATE_ARRAY_TEST(_f, _s, _n, NULL, vmstate_info_uint8, uint8_t)

-#define VMSTATE_UINT16_ARRAY_V(_f, _s, _n, _v) \
-VMSTATE_ARRAY(_f, _s, _n, _v, vmstate_info_uint16, uint16_t)
+#define VMSTATE_UINT16_ARRAY(_f, _s, _n)  \
+VMSTATE_ARRAY_TEST(_f, _s, _n, NULL, vmstate_info_uint16, uint16_t)

 #define VMSTATE_UINT16_2DARRAY_V(_f, _s, _n1, _n2, _v)\
 VMSTATE_2DARRAY(_f, _s, _n1, _n2, _v, vmstate_info_uint16, uint16_t)

-#define VMSTATE_UINT16_ARRAY(_f, _s, _n)   \
-VMSTATE_UINT16_ARRAY_V(_f, _s, _n, 0)
-
 #define VMSTATE_UINT16_2DARRAY(_f, _s, _n1, _n2)  \
 VMSTATE_UINT16_2DARRAY_V(_f, _s, _n1, _n2, 0)

diff --git a/tests/test-vmstate.c b/tests/test-vmstate.c
index b2590e3..baf9046 100644
--- a/tests/test-vmstate.c
+++ b/tests/test-vmstate.c
@@ -514,6 +514,7 @@ typedef struct TestArray {
 bool b_2[VMSTATE_ARRAY_SIZE];
 uint8_t  u8_1[VMSTATE_ARRAY_SIZE];
 uint8_t  u8_2[VMSTATE_ARRAY_SIZE];
+uint16_t u16_1[VMSTATE_ARRAY_SIZE];
 } TestArray;

 TestArray obj_array = {
@@ -522,6 +523,7 @@ TestArray obj_array = {
 .b_2 = { true, false, true, false, true},
 .u8_1 = { 1, 2, 3, 4, 5},
 .u8_2 = { 5, 4, 3, 2, 1},
+.u16_1 = {11, 12, 13, 14, 15},
 };

 static const VMStateDescription vmstate_array_primitive = {
@@ -533,6 +535,7 @@ static const VMStateDescription vmstate_array_primitive = {
 VMSTATE_INT32_EQUAL(size, TestArray),
 VMSTATE_BOOL_ARRAY(b_1, TestArray, VMSTATE_ARRAY_SIZE),
 VMSTATE_UINT8_ARRAY(u8_1, TestArray, VMSTATE_ARRAY_SIZE),
+VMSTATE_UINT16_ARRAY(u16_1, TestArray, VMSTATE_ARRAY_SIZE),
 VMSTATE_END_OF_LIST()
 }
 };
@@ -541,6 +544,7 @@ uint8_t wire_array_primitive[] = {
 /* size */  0x00, 0x00, 0x00, 0x05,
 /* b_1 */   0x00, 0x01, 0x00, 0x01, 0x00,
 /* u8_1 */  0x01, 0x02, 0x03, 0x04, 0x05,
+/* u16_1 */ 0x00, 0x0b, 0x00, 0x0c, 0x00, 0x0d, 0x00, 0x0e, 0x00, 0x0f,
 QEMU_VM_EOF, /* just to ensure we won't get EOF reported prematurely */
 };

@@ -557,6 +561,7 @@ static void obj_array_copy(void *arg1, void *arg2)
 target->b_2[i] = source->b_2[i];
 target->u8_1[i] = source->u8_1[i];
 target->u8_2[i] = source->u8_2[i];
+target->u16_1[i] = source->u16_1[i];
 }
 }

@@ -587,6 +592,7 @@ static void test_array_primitive(void)
 ELEM_EQUAL(b_1, i);
 ELEM_EQUAL(u8_1, i);
 ELEM_NOT_EQUAL(u8_2, i);
+ELEM_EQUAL(u16_1, i);
 }
 }

-- 
1.9.0




[Qemu-devel] [PATCH 056/124] vmstate: Rename VMSTATE_SINGLE_TEST to VMSTATE_SINGLE

2014-04-21 Thread Juan Quintela
And as no user used the version_id, just remove the parameter.

Signed-off-by: Juan Quintela 
---
 hw/nvram/eeprom93xx.c   |  2 +-
 hw/nvram/fw_cfg.c   |  2 +-
 hw/timer/twl92230.c |  2 +-
 include/migration/vmstate.h | 36 +---
 target-i386/machine.c   |  2 +-
 5 files changed, 21 insertions(+), 23 deletions(-)

diff --git a/hw/nvram/eeprom93xx.c b/hw/nvram/eeprom93xx.c
index d07bafb..7e09037 100644
--- a/hw/nvram/eeprom93xx.c
+++ b/hw/nvram/eeprom93xx.c
@@ -114,7 +114,7 @@ static const VMStateInfo vmstate_hack_uint16_from_uint8 = {
 };

 #define VMSTATE_UINT16_HACK_TEST(_f, _s, _t)   \
-VMSTATE_SINGLE_TEST(_f, _s, _t, 0, vmstate_hack_uint16_from_uint8, 
uint16_t)
+VMSTATE_SINGLE(_f, _s, _t, vmstate_hack_uint16_from_uint8, uint16_t)

 static bool is_old_eeprom_version(void *opaque, int version_id)
 {
diff --git a/hw/nvram/fw_cfg.c b/hw/nvram/fw_cfg.c
index 8ea3ac8..97218c7 100644
--- a/hw/nvram/fw_cfg.c
+++ b/hw/nvram/fw_cfg.c
@@ -365,7 +365,7 @@ static const VMStateInfo vmstate_hack_uint32_as_uint16 = {
 };

 #define VMSTATE_UINT16_HACK(_f, _s, _t)\
-VMSTATE_SINGLE_TEST(_f, _s, _t, 0, vmstate_hack_uint32_as_uint16, uint32_t)
+VMSTATE_SINGLE(_f, _s, _t, vmstate_hack_uint32_as_uint16, uint32_t)


 static bool is_version_1(void *opaque, int version_id)
diff --git a/hw/timer/twl92230.c b/hw/timer/twl92230.c
index 3aacaeb..26c6001 100644
--- a/hw/timer/twl92230.c
+++ b/hw/timer/twl92230.c
@@ -765,7 +765,7 @@ static const VMStateInfo vmstate_hack_int32_as_uint16 = {
 };

 #define VMSTATE_UINT16_HACK(_f, _s)  \
-VMSTATE_SINGLE_TEST(_f, _s, NULL, 0, vmstate_hack_int32_as_uint16, int32_t)
+VMSTATE_SINGLE(_f, _s, NULL, vmstate_hack_int32_as_uint16, int32_t)


 static const VMStateDescription vmstate_menelaus_tm = {
diff --git a/include/migration/vmstate.h b/include/migration/vmstate.h
index f64ad8c..977a35a 100644
--- a/include/migration/vmstate.h
+++ b/include/migration/vmstate.h
@@ -193,9 +193,8 @@ extern const VMStateInfo vmstate_info_bitmap;
 vmstate_offset_array(_state, _field, uint8_t,\
  sizeof(typeof_field(_state, _field)))

-#define VMSTATE_SINGLE_TEST(_field, _state, _test, _version, _info, _type) { \
+#define VMSTATE_SINGLE(_field, _state, _test, _info, _type) {\
 .name = (stringify(_field)), \
-.version_id   = (_version),  \
 .field_exists = (_test), \
 .size = sizeof(_type),   \
 .info = &(_info),\
@@ -491,25 +490,24 @@ extern const VMStateInfo vmstate_info_bitmap;
 _vmsd, _type)

 #define VMSTATE_BOOL_TEST(_f, _s, _t) \
-VMSTATE_SINGLE_TEST(_f, _s, _t, 0, vmstate_info_bool, bool)
+VMSTATE_SINGLE(_f, _s, _t, vmstate_info_bool, bool)

 #define VMSTATE_INT8_TEST(_f, _s, _t) \
-VMSTATE_SINGLE_TEST(_f, _s, _t, 0, vmstate_info_int8, int8_t)
+VMSTATE_SINGLE(_f, _s, _t, vmstate_info_int8, int8_t)
 #define VMSTATE_INT16_TEST(_f, _s, _t)\
-VMSTATE_SINGLE_TEST(_f, _s, _t, 0, vmstate_info_int16, int16_t)
+VMSTATE_SINGLE(_f, _s, _t, vmstate_info_int16, int16_t)
 #define VMSTATE_INT32_TEST(_f, _s, _t)\
-VMSTATE_SINGLE_TEST(_f, _s, _t, 0, vmstate_info_int32, int32_t)
+VMSTATE_SINGLE(_f, _s, _t, vmstate_info_int32, int32_t)
 #define VMSTATE_INT64_TEST(_f, _s, _t)\
-VMSTATE_SINGLE_TEST(_f, _s, _t, 0, vmstate_info_int64, int64_t)
-
+VMSTATE_SINGLE(_f, _s, _t, vmstate_info_int64, int64_t)
 #define VMSTATE_UINT8_TEST(_f, _s, _t)\
-VMSTATE_SINGLE_TEST(_f, _s, _t, 0, vmstate_info_uint8, uint8_t)
+VMSTATE_SINGLE(_f, _s, _t, vmstate_info_uint8, uint8_t)
 #define VMSTATE_UINT16_TEST(_f, _s, _t)   \
-VMSTATE_SINGLE_TEST(_f, _s, _t, 0, vmstate_info_uint16, uint16_t)
+VMSTATE_SINGLE(_f, _s, _t, vmstate_info_uint16, uint16_t)
 #define VMSTATE_UINT32_TEST(_f, _s, _t)   \
-VMSTATE_SINGLE_TEST(_f, _s, _t, 0, vmstate_info_uint32, uint32_t)
+VMSTATE_SINGLE(_f, _s, _t, vmstate_info_uint32, uint32_t)
 #define VMSTATE_UINT64_TEST(_f, _s, _t)   \
-VMSTATE_SINGLE_TEST(_f, _s, _t, 0, vmstate_info_uint64, uint64_t)
+VMSTATE_SINGLE(_f, _s, _t, vmstate_info_uint64, uint64_t)

 #define VMSTATE_BOOL(_f, _s)  \
 VMSTATE_BOOL_TEST(_f, _s, NULL)
@@ -533,28 +531,28 @@ extern const VMStateInfo vmstate_info_bitmap;
 VMSTATE_UINT64_TEST(_f, _s, NULL)

 #define VMSTATE_UINT8_EQUAL(_f, _s)  

[Qemu-devel] [PATCH 069/124] vmstate: Remove VMSTATE_BUFFER_MULTIPLY

2014-04-21 Thread Juan Quintela
It was unused.

Signed-off-by: Juan Quintela 
---
 include/migration/vmstate.h | 13 -
 vmstate.c   |  3 ---
 2 files changed, 16 deletions(-)

diff --git a/include/migration/vmstate.h b/include/migration/vmstate.h
index f5687b7..7e3877d 100644
--- a/include/migration/vmstate.h
+++ b/include/migration/vmstate.h
@@ -97,7 +97,6 @@ enum VMStateFlags {
 VMS_ARRAY_OF_POINTER = 0x040,
 VMS_VARRAY_UINT16= 0x080,  /* Array with size in uint16_t field */
 VMS_VBUFFER  = 0x100,  /* Buffer with size in int32_t field */
-VMS_MULTIPLY = 0x200,  /* multiply "size" field by field_size */
 VMS_VARRAY_UINT8 = 0x400,  /* Array with size in uint8_t field*/
 VMS_VARRAY_UINT32= 0x800,  /* Array with size in uint32_t field*/
 };
@@ -392,18 +391,6 @@ extern const VMStateInfo vmstate_info_bitmap;
 .offset   = vmstate_offset_buffer(_state, _field) + _start,  \
 }

-#define VMSTATE_VBUFFER_MULTIPLY(_field, _state, _version, _test, _start, 
_field_size, _multiply) { \
-.name = (stringify(_field)), \
-.version_id   = (_version),  \
-.field_exists = (_test), \
-.size_offset  = vmstate_offset_value(_state, _field_size, uint32_t),\
-.size = (_multiply),  \
-.info = &vmstate_info_buffer,\
-.flags= VMS_VBUFFER|VMS_POINTER|VMS_MULTIPLY,\
-.offset   = offsetof(_state, _field),\
-.start= (_start),\
-}
-
 #define VMSTATE_VBUFFER(_field, _state, _test, _start, _field_size) { \
 .name = (stringify(_field)), \
 .field_exists = (_test), \
diff --git a/vmstate.c b/vmstate.c
index abade3f..dd74730 100644
--- a/vmstate.c
+++ b/vmstate.c
@@ -35,9 +35,6 @@ static int vmstate_size(void *opaque, VMStateField *field)

 if (field->flags & VMS_VBUFFER) {
 size = *(int32_t *)(opaque+field->size_offset);
-if (field->flags & VMS_MULTIPLY) {
-size *= field->size;
-}
 }

 return size;
-- 
1.9.0




[Qemu-devel] [PATCH 061/124] vmstate: Remove version_id fields that were not used

2014-04-21 Thread Juan Quintela
Signed-off-by: Juan Quintela 
---
 include/migration/vmstate.h | 4 
 1 file changed, 4 deletions(-)

diff --git a/include/migration/vmstate.h b/include/migration/vmstate.h
index dfb59e2..e84da16 100644
--- a/include/migration/vmstate.h
+++ b/include/migration/vmstate.h
@@ -342,7 +342,6 @@ extern const VMStateInfo vmstate_info_bitmap;

 #define VMSTATE_STRUCT_VARRAY_POINTER_INT32(_field, _state, _field_num, _vmsd, 
_type) { \
 .name   = (stringify(_field)),   \
-.version_id = 0, \
 .num_offset = vmstate_offset_value(_state, _field_num, int32_t), \
 .size   = sizeof(_type), \
 .vmsd   = &(_vmsd),  \
@@ -352,7 +351,6 @@ extern const VMStateInfo vmstate_info_bitmap;

 #define VMSTATE_STRUCT_VARRAY_POINTER_UINT32(_field, _state, _field_num, 
_vmsd, _type) { \
 .name   = (stringify(_field)),   \
-.version_id = 0, \
 .num_offset = vmstate_offset_value(_state, _field_num, uint32_t),\
 .size   = sizeof(_type), \
 .vmsd   = &(_vmsd),  \
@@ -362,7 +360,6 @@ extern const VMStateInfo vmstate_info_bitmap;

 #define VMSTATE_STRUCT_VARRAY_POINTER_UINT16(_field, _state, _field_num, 
_vmsd, _type) { \
 .name   = (stringify(_field)),   \
-.version_id = 0, \
 .num_offset = vmstate_offset_value(_state, _field_num, uint16_t),\
 .size   = sizeof(_type), \
 .vmsd   = &(_vmsd),  \
@@ -464,7 +461,6 @@ extern const VMStateInfo vmstate_info_bitmap;
  */
 #define VMSTATE_BITMAP(_field, _state, _field_size) {\
 .name = (stringify(_field)), \
-.version_id   = 0,   \
 .size_offset  = vmstate_offset_value(_state, _field_size, int32_t),\
 .info = &vmstate_info_bitmap,\
 .flags= VMS_VBUFFER|VMS_POINTER, \
-- 
1.9.0




[Qemu-devel] [PATCH 045/124] vmstate: Test for VMSTATE_UINT8_2DARRAY

2014-04-21 Thread Juan Quintela
Remove unused _V version.

Signed-off-by: Juan Quintela 
---
 include/migration/vmstate.h |  9 +++--
 tests/test-vmstate.c| 28 ++--
 2 files changed, 29 insertions(+), 8 deletions(-)

diff --git a/include/migration/vmstate.h b/include/migration/vmstate.h
index 378dbc9..eeff224 100644
--- a/include/migration/vmstate.h
+++ b/include/migration/vmstate.h
@@ -639,21 +639,18 @@ extern const VMStateInfo vmstate_info_bitmap;
 #define VMSTATE_FLOAT64_ARRAY(_f, _s, _n) \
 VMSTATE_ARRAY_TEST(_f, _s, _n, NULL, vmstate_info_float64, float64)

+#define VMSTATE_UINT8_2DARRAY(_f, _s, _n1, _n2)   \
+VMSTATE_2DARRAY(_f, _s, _n1, _n2, 0, vmstate_info_uint8, uint8_t)
+
 #define VMSTATE_UINT16_2DARRAY_V(_f, _s, _n1, _n2, _v)\
 VMSTATE_2DARRAY(_f, _s, _n1, _n2, _v, vmstate_info_uint16, uint16_t)

 #define VMSTATE_UINT16_2DARRAY(_f, _s, _n1, _n2)  \
 VMSTATE_UINT16_2DARRAY_V(_f, _s, _n1, _n2, 0)

-#define VMSTATE_UINT8_2DARRAY_V(_f, _s, _n1, _n2, _v) \
-VMSTATE_2DARRAY(_f, _s, _n1, _n2, _v, vmstate_info_uint8, uint8_t)
-
 #define VMSTATE_UINT8_SUB_ARRAY(_f, _s, _start, _num)\
 VMSTATE_SUB_ARRAY(_f, _s, _start, _num, 0, vmstate_info_uint8, uint8_t)

-#define VMSTATE_UINT8_2DARRAY(_f, _s, _n1, _n2)   \
-VMSTATE_UINT8_2DARRAY_V(_f, _s, _n1, _n2, 0)
-
 #define VMSTATE_UINT32_2DARRAY_V(_f, _s, _n1, _n2, _v)\
 VMSTATE_2DARRAY(_f, _s, _n1, _n2, _v, vmstate_info_uint32, uint32_t)

diff --git a/tests/test-vmstate.c b/tests/test-vmstate.c
index 9addb60..6c01832 100644
--- a/tests/test-vmstate.c
+++ b/tests/test-vmstate.c
@@ -507,6 +507,7 @@ static void test_simple_bitmap(void)
 }

 #define VMSTATE_ARRAY_SIZE 5
+#define VMSTATE_2D_SIZE 3

 typedef struct TestArray {
 int32_t  size;
@@ -524,6 +525,7 @@ typedef struct TestArray {
 int32_t i32_2[VMSTATE_ARRAY_SIZE];
 int64_t i64_1[VMSTATE_ARRAY_SIZE];
 float64 f64_1[VMSTATE_ARRAY_SIZE];
+uint8_t u8_1d[VMSTATE_2D_SIZE][VMSTATE_2D_SIZE];
 } TestArray;

 TestArray obj_array = {
@@ -543,6 +545,9 @@ TestArray obj_array = {
 .i64_1 = {61, 62, 63, 64, 65},
 .f64_1 = {float64_zero, float64_one, float64_ln2, float64_pi,
   float64_infinity},
+.u8_1d = { {71, 72, 73},
+   {74, 75, 76},
+   {77, 78, 79} },
 };

 static const VMStateDescription vmstate_array_primitive = {
@@ -561,6 +566,8 @@ static const VMStateDescription vmstate_array_primitive = {
 VMSTATE_INT32_ARRAY(i32_1, TestArray, VMSTATE_ARRAY_SIZE),
 VMSTATE_INT64_ARRAY(i64_1, TestArray, VMSTATE_ARRAY_SIZE),
 VMSTATE_FLOAT64_ARRAY(f64_1, TestArray, VMSTATE_ARRAY_SIZE),
+VMSTATE_UINT8_2DARRAY(u8_1d, TestArray, VMSTATE_2D_SIZE,
+  VMSTATE_2D_SIZE),
 VMSTATE_END_OF_LIST()
 }
 };
@@ -592,6 +599,9 @@ uint8_t wire_array_primitive[] = {
 0x3f, 0xe6, 0x2e, 0x42, 0xfe, 0xfa, 0x39, 0xef,
 0x40, 0x09, 0x21, 0xfb, 0x54, 0x44, 0x2d, 0x18,
 0x7f, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+/* u8_1d */ 0x47, 0x48, 0x49,
+0x4a, 0x4b, 0x4c,
+0x4d, 0x4e, 0x4f,
 QEMU_VM_EOF, /* just to ensure we won't get EOF reported prematurely */
 };

@@ -599,7 +609,7 @@ static void obj_array_copy(void *arg1, void *arg2)
 {
 TestArray *target = arg1;
 TestArray *source = arg2;
-int i;
+int i, j;

 target->size = source->size;

@@ -619,12 +629,18 @@ static void obj_array_copy(void *arg1, void *arg2)
 target->i64_1[i] = source->i64_1[i];
 target->f64_1[i] = source->f64_1[i];
 }
+
+for (i = 0; i < VMSTATE_2D_SIZE; i++) {
+for (j = 0; j < VMSTATE_2D_SIZE; j++) {
+target->u8_1d[i][j] = source->u8_1d[i][j];
+}
+}
 }

 static void test_array_primitive(void)
 {
 TestArray obj, obj_clone;
-int i;
+int i, j;

 memset(&obj, 0, sizeof(obj));
 obj.size = VMSTATE_ARRAY_SIZE;
@@ -640,6 +656,8 @@ static void test_array_primitive(void)
 #define FIELD_EQUAL(name)   g_assert_cmpint(obj.name, ==, obj_array.name)
 #define ELEM_EQUAL(name, i) \
 g_assert_cmpint(obj.name[i], ==, obj_array.name[i])
+#define ELEM_EQUAL_2D(name, i, j)\
+g_assert_cmpint(obj.name[i][j], ==, obj_array.name[i][j])
 #define ELEM_NOT_EQUAL(name, i) \
 g_assert_cmpint(obj.name[i], !=, obj_array.name[i])

@@ -656,6 +674,11 @@ static void test_array_primitive(void)
 ELEM_EQUAL(i64_1, i);
 ELEM_EQUAL(f64_1, i);
 }
+for (i = 0; i < VMSTATE_2D_SIZE; i++) {
+for (j = 0; j < VMSTATE_2D_SIZE; j++) {
+ELEM_EQUAL_2D(u8_1d, i, j);
+}
+}
 }

 static const VMStateDescription vmstate_array_test = {
@@ -729,6 +752,7 @@ static void test_array_test(void)
 }
 #undef FIELD_EQUAL
 #undef ELEM_EQUAL
+#undef ELEM_EQUAL_2D
 #

[Qemu-devel] [PATCH 072/124] vmstate: Move all users of versioning of VMSTATE_STRUCT_ARRAY to _TEST

2014-04-21 Thread Juan Quintela
Signed-off-by: Juan Quintela 
---
 hw/char/escc.c  |  4 ++--
 hw/ide/internal.h   |  3 ++-
 hw/timer/i8254_common.c |  5 +++--
 target-i386/machine.c   | 15 +--
 4 files changed, 16 insertions(+), 11 deletions(-)

diff --git a/hw/char/escc.c b/hw/char/escc.c
index 4875a2b..dc5768f 100644
--- a/hw/char/escc.c
+++ b/hw/char/escc.c
@@ -678,8 +678,8 @@ static const VMStateDescription vmstate_escc = {
 .version_id = 2,
 .minimum_version_id = 1,
 .fields = (VMStateField[]) {
-VMSTATE_STRUCT_ARRAY(chn, ESCCState, 2, 2, vmstate_escc_chn,
- ChannelState),
+VMSTATE_STRUCT_ARRAY_TEST(chn, ESCCState, 2, vmstate_2_plus, 0,
+  vmstate_escc_chn, ChannelState),
 VMSTATE_END_OF_LIST()
 }
 };
diff --git a/hw/ide/internal.h b/hw/ide/internal.h
index 0567a52..d771308 100644
--- a/hw/ide/internal.h
+++ b/hw/ide/internal.h
@@ -526,7 +526,8 @@ extern const VMStateDescription vmstate_ide_bus;
 extern const VMStateDescription vmstate_ide_drive;

 #define VMSTATE_IDE_DRIVES(_field, _state) \
-VMSTATE_STRUCT_ARRAY(_field, _state, 2, 3, vmstate_ide_drive, IDEState)
+VMSTATE_STRUCT_ARRAY_TEST(_field, _state, 2, vmstate_3_plus, 0,\
+  vmstate_ide_drive, IDEState)

 void ide_bus_reset(IDEBus *bus);
 int64_t ide_get_sector(IDEState *s);
diff --git a/hw/timer/i8254_common.c b/hw/timer/i8254_common.c
index f519864..b7bd908 100644
--- a/hw/timer/i8254_common.c
+++ b/hw/timer/i8254_common.c
@@ -268,8 +268,9 @@ static const VMStateDescription vmstate_pit_common = {
 .fields = (VMStateField[]) {
 VMSTATE_UINT32_TEST(channels[0].irq_disabled, PITCommonState,
 vmstate_3_plus),
-VMSTATE_STRUCT_ARRAY(channels, PITCommonState, 3, 2,
- vmstate_pit_channel, PITChannelState),
+VMSTATE_STRUCT_ARRAY_TEST(channels, PITCommonState, 3,
+  vmstate_2_plus, 0, vmstate_pit_channel,
+  PITChannelState),
 VMSTATE_INT64(channels[0].next_transition_time,
   PITCommonState), /* formerly irq_timer */
 VMSTATE_END_OF_LIST()
diff --git a/target-i386/machine.c b/target-i386/machine.c
index 2686390..7bb3c14 100644
--- a/target-i386/machine.c
+++ b/target-i386/machine.c
@@ -57,8 +57,9 @@ static const VMStateDescription vmstate_ymmh_reg = {
 }
 };

-#define VMSTATE_YMMH_REGS_VARS(_field, _state, _n, _v) 
\
-VMSTATE_STRUCT_ARRAY(_field, _state, _n, _v, vmstate_ymmh_reg, XMMReg)
+#define VMSTATE_YMMH_REGS_VARS(_field, _state, _n, _t) 
\
+VMSTATE_STRUCT_ARRAY_TEST(_field, _state, _n, _t, 0,\
+  vmstate_ymmh_reg, XMMReg)

 static const VMStateDescription vmstate_bnd_regs = {
 .name = "bnd_regs",
@@ -85,8 +86,9 @@ static const VMStateDescription vmstate_mtrr_var = {
 }
 };

-#define VMSTATE_MTRR_VARS(_field, _state, _n, _v)\
-VMSTATE_STRUCT_ARRAY(_field, _state, _n, _v, vmstate_mtrr_var, MTRRVar)
+#define VMSTATE_MTRR_VARS(_field, _state, _n, _t)\
+VMSTATE_STRUCT_ARRAY_TEST(_field, _state, _n, _t, 0,\
+  vmstate_mtrr_var, MTRRVar)

 static void put_fpreg_error(QEMUFile *f, void *opaque, size_t size)
 {
@@ -672,7 +674,7 @@ const VMStateDescription vmstate_x86_cpu = {
 /* MTRRs */
 VMSTATE_UINT64_ARRAY_TEST(env.mtrr_fixed, X86CPU, 11, vmstate_8_plus),
 VMSTATE_UINT64_TEST(env.mtrr_deftype, X86CPU, vmstate_8_plus),
-VMSTATE_MTRR_VARS(env.mtrr_var, X86CPU, 8, 8),
+VMSTATE_MTRR_VARS(env.mtrr_var, X86CPU, 8, vmstate_8_plus),
 /* KVM-related states */
 VMSTATE_INT32_TEST(env.interrupt_injected, X86CPU, vmstate_9_plus),
 VMSTATE_UINT32_TEST(env.mp_state, X86CPU, vmstate_9_plus),
@@ -697,7 +699,8 @@ const VMStateDescription vmstate_x86_cpu = {
 /* XSAVE related fields */
 VMSTATE_UINT64_TEST(env.xcr0, X86CPU, vmstate_12_plus),
 VMSTATE_UINT64_TEST(env.xstate_bv, X86CPU, vmstate_12_plus),
-VMSTATE_YMMH_REGS_VARS(env.ymmh_regs, X86CPU, CPU_NB_REGS, 12),
+VMSTATE_YMMH_REGS_VARS(env.ymmh_regs, X86CPU, CPU_NB_REGS,
+   vmstate_12_plus),
 VMSTATE_END_OF_LIST()
 /* The above list is not sorted /wrt version numbers, watch out! */
 },
-- 
1.9.0




[Qemu-devel] [PATCH 073/124] vmstate: Remove version parameter from VMSTATE_STRUCT_ARRAY

2014-04-21 Thread Juan Quintela
No users of that field left.

Signed-off-by: Juan Quintela 
---
 hw/arm/musicpal.c |  2 +-
 hw/audio/ac97.c   |  2 +-
 hw/audio/es1370.c |  2 +-
 hw/audio/hda-codec.c  |  3 +--
 hw/audio/intel-hda.c  |  3 +--
 hw/block/fdc.c|  2 +-
 hw/char/ipoctal232.c  |  4 ++--
 hw/char/serial-pci.c  |  2 +-
 hw/display/exynos4210_fimd.c  |  2 +-
 hw/display/pxa2xx_lcd.c   |  2 +-
 hw/display/qxl.c  |  2 +-
 hw/dma/i8257.c|  3 ++-
 hw/dma/pl080.c|  2 +-
 hw/ide/internal.h |  2 +-
 hw/ide/pci.c  |  3 +--
 hw/input/hid.c|  2 +-
 hw/intc/arm_gic_common.c  |  2 +-
 hw/intc/exynos4210_combiner.c |  2 +-
 hw/intc/heathrow_pic.c|  2 +-
 hw/intc/slavio_intctl.c   |  2 +-
 hw/misc/macio/cuda.c  |  2 +-
 hw/misc/macio/mac_dbdma.c |  2 +-
 hw/net/allwinner_emac.c   |  2 +-
 hw/pci-host/ppce500.c |  4 ++--
 hw/ppc/ppc4xx_pci.c   | 10 --
 hw/ppc/spapr_pci.c|  4 ++--
 hw/timer/cadence_ttc.c|  3 +--
 hw/timer/exynos4210_mct.c |  2 +-
 hw/timer/exynos4210_pwm.c |  4 ++--
 hw/timer/pxa2xx_timer.c   |  4 ++--
 hw/timer/slavio_timer.c   |  2 +-
 hw/usb/dev-hub.c  |  2 +-
 hw/usb/dev-smartcard-reader.c |  4 ++--
 hw/usb/hcd-uhci.c |  2 +-
 hw/usb/redirect.c |  2 +-
 include/migration/vmstate.h   |  5 ++---
 target-i386/machine.c |  6 +++---
 37 files changed, 50 insertions(+), 56 deletions(-)

diff --git a/hw/arm/musicpal.c b/hw/arm/musicpal.c
index 2a27a19..9ac05d8 100644
--- a/hw/arm/musicpal.c
+++ b/hw/arm/musicpal.c
@@ -949,7 +949,7 @@ static const VMStateDescription mv88w8618_pit_vmsd = {
 .version_id = 1,
 .minimum_version_id = 1,
 .fields = (VMStateField[]) {
-VMSTATE_STRUCT_ARRAY(timer, mv88w8618_pit_state, 4, 1,
+VMSTATE_STRUCT_ARRAY(timer, mv88w8618_pit_state, 4,
  mv88w8618_timer_vmsd, mv88w8618_timer_state),
 VMSTATE_END_OF_LIST()
 }
diff --git a/hw/audio/ac97.c b/hw/audio/ac97.c
index 45cb118..af00545 100644
--- a/hw/audio/ac97.c
+++ b/hw/audio/ac97.c
@@ -1216,7 +1216,7 @@ static const VMStateDescription vmstate_ac97 = {
 VMSTATE_UINT32 (glob_cnt, AC97LinkState),
 VMSTATE_UINT32 (glob_sta, AC97LinkState),
 VMSTATE_UINT32 (cas, AC97LinkState),
-VMSTATE_STRUCT_ARRAY (bm_regs, AC97LinkState, 3, 1,
+VMSTATE_STRUCT_ARRAY (bm_regs, AC97LinkState, 3,
   vmstate_ac97_bm_regs, AC97BusMasterRegs),
 VMSTATE_BUFFER (mixer_data, AC97LinkState),
 VMSTATE_UNUSED_TEST (is_version_2, 3),
diff --git a/hw/audio/es1370.c b/hw/audio/es1370.c
index 5dbf803..b4cfe5d 100644
--- a/hw/audio/es1370.c
+++ b/hw/audio/es1370.c
@@ -999,7 +999,7 @@ static const VMStateDescription vmstate_es1370 = {
 .post_load = es1370_post_load,
 .fields = (VMStateField[]) {
 VMSTATE_PCI_DEVICE (dev, ES1370State),
-VMSTATE_STRUCT_ARRAY (chan, ES1370State, NB_CHANNELS, 2,
+VMSTATE_STRUCT_ARRAY (chan, ES1370State, NB_CHANNELS,
   vmstate_es1370_channel, struct chan),
 VMSTATE_UINT32 (ctl, ES1370State),
 VMSTATE_UINT32 (status, ES1370State),
diff --git a/hw/audio/hda-codec.c b/hw/audio/hda-codec.c
index 1c1a138..76f4d3c 100644
--- a/hw/audio/hda-codec.c
+++ b/hw/audio/hda-codec.c
@@ -599,8 +599,7 @@ static const VMStateDescription vmstate_hda_audio = {
 .version_id = 2,
 .post_load = hda_audio_post_load,
 .fields = (VMStateField[]) {
-VMSTATE_STRUCT_ARRAY(st, HDAAudioState, 4, 0,
- vmstate_hda_audio_stream,
+VMSTATE_STRUCT_ARRAY(st, HDAAudioState, 4, vmstate_hda_audio_stream,
  HDAAudioStream),
 VMSTATE_BOOL_ARRAY(running_compat, HDAAudioState, 16),
 VMSTATE_BOOL_ARRAY_TEST(running_real, HDAAudioState, 2 * 16,
diff --git a/hw/audio/intel-hda.c b/hw/audio/intel-hda.c
index 1c660a4..426d178 100644
--- a/hw/audio/intel-hda.c
+++ b/hw/audio/intel-hda.c
@@ -1220,8 +1220,7 @@ static const VMStateDescription vmstate_intel_hda = {
 VMSTATE_UINT32(icw, IntelHDAState),
 VMSTATE_UINT32(irr, IntelHDAState),
 VMSTATE_UINT32(ics, IntelHDAState),
-VMSTATE_STRUCT_ARRAY(st, IntelHDAState, 8, 0,
- vmstate_intel_hda_stream,
+VMSTATE_STRUCT_ARRAY(st, IntelHDAState, 8, vmstate_intel_hda_stream,
  IntelHDAStream),

 /* additional state info */
diff --git a/hw/block/fdc.c b/hw/block/fdc.c
index ca973f4..9d8d5d5 100644
--- a/hw/block/fdc.c
+++ b/hw/block/fdc.c
@@ -767,7 +767,7 @@ static const VMStateDescription vmstate_fdc = {
 VMSTATE_UINT8(lock, FDCtrl),
 VMSTATE_UINT8(pwrd, FDCtrl),
 VMSTATE_UINT8_EQUAL(num_floppies, FDCtrl),
-VMSTATE_S

[Qemu-devel] [PATCH 014/124] vmstate: Change VMSTATE_INTTL_V to VMSTATE_INTTL_TEST

2014-04-21 Thread Juan Quintela
And fix all users.
VMSTATE_UINT64_TEST don't exist.  Create it.

Signed-off-by: Juan Quintela 
---
 include/hw/hw.h | 10 +-
 include/migration/vmstate.h |  3 +++
 target-i386/machine.c   |  4 ++--
 3 files changed, 10 insertions(+), 7 deletions(-)

diff --git a/include/hw/hw.h b/include/hw/hw.h
index 2b68ac3..211eb8b 100644
--- a/include/hw/hw.h
+++ b/include/hw/hw.h
@@ -49,22 +49,22 @@ int qemu_boot_set(const char *boot_order);

 #ifdef NEED_CPU_H
 #if TARGET_LONG_BITS == 64
-#define VMSTATE_UINTTL_V(_f, _s, _v)  \
-VMSTATE_UINT64_V(_f, _s, _v)
+#define VMSTATE_UINTTL_TEST(_f, _s, _t)   \
+VMSTATE_UINT64_TEST(_f, _s, _t)
 #define VMSTATE_UINTTL_EQUAL(_f, _s)  \
 VMSTATE_UINT64_EQUAL(_f, _s)
 #define VMSTATE_UINTTL_ARRAY_V(_f, _s, _n, _v)\
 VMSTATE_UINT64_ARRAY_V(_f, _s, _n, _v)
 #else
-#define VMSTATE_UINTTL_V(_f, _s, _v)  \
-VMSTATE_UINT32_V(_f, _s, _v)
+#define VMSTATE_UINTTL_TEST(_f, _s, _t)   \
+VMSTATE_UINT32_TEST(_f, _s, _t)
 #define VMSTATE_UINTTL_EQUAL(_f, _s)  \
 VMSTATE_UINT32_EQUAL(_f, _s)
 #define VMSTATE_UINTTL_ARRAY_V(_f, _s, _n, _v)\
 VMSTATE_UINT32_ARRAY_V(_f, _s, _n, _v)
 #endif
 #define VMSTATE_UINTTL(_f, _s)\
-VMSTATE_UINTTL_V(_f, _s, 0)
+VMSTATE_UINTTL_TEST(_f, _s, NULL)
 #define VMSTATE_UINTTL_ARRAY(_f, _s, _n)  \
 VMSTATE_UINTTL_ARRAY_V(_f, _s, _n, 0)

diff --git a/include/migration/vmstate.h b/include/migration/vmstate.h
index 55d7fe6..cb253b8 100644
--- a/include/migration/vmstate.h
+++ b/include/migration/vmstate.h
@@ -604,6 +604,9 @@ extern const VMStateInfo vmstate_info_bitmap;
 #define VMSTATE_UINT32_TEST(_f, _s, _t)  \
 VMSTATE_SINGLE_TEST(_f, _s, _t, 0, vmstate_info_uint32, uint32_t)

+#define VMSTATE_UINT64_TEST(_f, _s, _t)  \
+VMSTATE_SINGLE_TEST(_f, _s, _t, 0, vmstate_info_uint64, uint64_t)
+

 #define VMSTATE_FLOAT64_V(_f, _s, _v) \
 VMSTATE_SINGLE(_f, _s, _v, vmstate_info_float64, float64)
diff --git a/target-i386/machine.c b/target-i386/machine.c
index fe3f024..838a5b0 100644
--- a/target-i386/machine.c
+++ b/target-i386/machine.c
@@ -624,8 +624,8 @@ const VMStateDescription vmstate_x86_cpu = {
 /* Hack: In v7 size changed from 32 to 64 bits on x86_64 */
 VMSTATE_HACK_UINT32(env.sysenter_esp, X86CPU, less_than_7),
 VMSTATE_HACK_UINT32(env.sysenter_eip, X86CPU, less_than_7),
-VMSTATE_UINTTL_V(env.sysenter_esp, X86CPU, 7),
-VMSTATE_UINTTL_V(env.sysenter_eip, X86CPU, 7),
+VMSTATE_UINTTL_TEST(env.sysenter_esp, X86CPU, vmstate_7_plus),
+VMSTATE_UINTTL_TEST(env.sysenter_eip, X86CPU, vmstate_7_plus),
 #else
 VMSTATE_UINTTL(env.sysenter_esp, X86CPU),
 VMSTATE_UINTTL(env.sysenter_eip, X86CPU),
-- 
1.9.0




[Qemu-devel] [PATCH 044/124] vmstate: Test for VMSTATE_FLOAT64_ARRAY

2014-04-21 Thread Juan Quintela
Remove unused VMSTATE_FLOAT64_ARRAY_V.

Signed-off-by: Juan Quintela 
---
 include/migration/vmstate.h |  9 +++--
 tests/test-vmstate.c| 11 +++
 2 files changed, 14 insertions(+), 6 deletions(-)

diff --git a/include/migration/vmstate.h b/include/migration/vmstate.h
index 0a562aa..378dbc9 100644
--- a/include/migration/vmstate.h
+++ b/include/migration/vmstate.h
@@ -636,6 +636,9 @@ extern const VMStateInfo vmstate_info_bitmap;
 #define VMSTATE_INT64_ARRAY(_f, _s, _n)   \
 VMSTATE_ARRAY_TEST(_f, _s, _n, NULL, vmstate_info_int64, int64_t)

+#define VMSTATE_FLOAT64_ARRAY(_f, _s, _n) \
+VMSTATE_ARRAY_TEST(_f, _s, _n, NULL, vmstate_info_float64, float64)
+
 #define VMSTATE_UINT16_2DARRAY_V(_f, _s, _n1, _n2, _v)\
 VMSTATE_2DARRAY(_f, _s, _n1, _n2, _v, vmstate_info_uint16, uint16_t)

@@ -660,12 +663,6 @@ extern const VMStateInfo vmstate_info_bitmap;
 #define VMSTATE_UINT32_SUB_ARRAY(_f, _s, _start, _num)\
 VMSTATE_SUB_ARRAY(_f, _s, _start, _num, 0, vmstate_info_uint32, uint32_t)

-#define VMSTATE_FLOAT64_ARRAY_V(_f, _s, _n, _v)   \
-VMSTATE_ARRAY(_f, _s, _n, _v, vmstate_info_float64, float64)
-
-#define VMSTATE_FLOAT64_ARRAY(_f, _s, _n) \
-VMSTATE_FLOAT64_ARRAY_V(_f, _s, _n, 0)
-
 #define VMSTATE_BUFFER_V(_f, _s, _v)  \
 VMSTATE_STATIC_BUFFER(_f, _s, _v, NULL, 0, sizeof(typeof_field(_s, _f)))

diff --git a/tests/test-vmstate.c b/tests/test-vmstate.c
index a930bde..9addb60 100644
--- a/tests/test-vmstate.c
+++ b/tests/test-vmstate.c
@@ -523,6 +523,7 @@ typedef struct TestArray {
 int32_t i32_1[VMSTATE_ARRAY_SIZE];
 int32_t i32_2[VMSTATE_ARRAY_SIZE];
 int64_t i64_1[VMSTATE_ARRAY_SIZE];
+float64 f64_1[VMSTATE_ARRAY_SIZE];
 } TestArray;

 TestArray obj_array = {
@@ -540,6 +541,8 @@ TestArray obj_array = {
 .i32_1 = {51, 52, 53, 54, 55},
 .i32_2 = {55, 54, 53, 52, 51},
 .i64_1 = {61, 62, 63, 64, 65},
+.f64_1 = {float64_zero, float64_one, float64_ln2, float64_pi,
+  float64_infinity},
 };

 static const VMStateDescription vmstate_array_primitive = {
@@ -557,6 +560,7 @@ static const VMStateDescription vmstate_array_primitive = {
 VMSTATE_INT16_ARRAY(i16_1, TestArray, VMSTATE_ARRAY_SIZE),
 VMSTATE_INT32_ARRAY(i32_1, TestArray, VMSTATE_ARRAY_SIZE),
 VMSTATE_INT64_ARRAY(i64_1, TestArray, VMSTATE_ARRAY_SIZE),
+VMSTATE_FLOAT64_ARRAY(f64_1, TestArray, VMSTATE_ARRAY_SIZE),
 VMSTATE_END_OF_LIST()
 }
 };
@@ -583,6 +587,11 @@ uint8_t wire_array_primitive[] = {
 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3f,
 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40,
 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x41,
+/* f64_1 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+0x3f, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+0x3f, 0xe6, 0x2e, 0x42, 0xfe, 0xfa, 0x39, 0xef,
+0x40, 0x09, 0x21, 0xfb, 0x54, 0x44, 0x2d, 0x18,
+0x7f, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
 QEMU_VM_EOF, /* just to ensure we won't get EOF reported prematurely */
 };

@@ -608,6 +617,7 @@ static void obj_array_copy(void *arg1, void *arg2)
 target->i32_1[i] = source->i32_1[i];
 target->i32_2[i] = source->i32_2[i];
 target->i64_1[i] = source->i64_1[i];
+target->f64_1[i] = source->f64_1[i];
 }
 }

@@ -644,6 +654,7 @@ static void test_array_primitive(void)
 ELEM_EQUAL(i16_1, i);
 ELEM_EQUAL(i32_1, i);
 ELEM_EQUAL(i64_1, i);
+ELEM_EQUAL(f64_1, i);
 }
 }

-- 
1.9.0




[Qemu-devel] [PATCH 074/124] vmstate: Remove version parameter from VMSTATE_STRUCT_ARRAY_TEST

2014-04-21 Thread Juan Quintela
No users left.

Signed-off-by: Juan Quintela 
---
 hw/char/escc.c  | 2 +-
 hw/ide/internal.h   | 2 +-
 hw/timer/i8254_common.c | 2 +-
 hw/timer/pxa2xx_timer.c | 2 +-
 hw/usb/hcd-xhci.c   | 2 +-
 include/hw/acpi/pcihp.h | 2 +-
 include/migration/vmstate.h | 5 ++---
 target-i386/machine.c   | 6 ++
 8 files changed, 10 insertions(+), 13 deletions(-)

diff --git a/hw/char/escc.c b/hw/char/escc.c
index dc5768f..99dcb04 100644
--- a/hw/char/escc.c
+++ b/hw/char/escc.c
@@ -678,7 +678,7 @@ static const VMStateDescription vmstate_escc = {
 .version_id = 2,
 .minimum_version_id = 1,
 .fields = (VMStateField[]) {
-VMSTATE_STRUCT_ARRAY_TEST(chn, ESCCState, 2, vmstate_2_plus, 0,
+VMSTATE_STRUCT_ARRAY_TEST(chn, ESCCState, 2, vmstate_2_plus,
   vmstate_escc_chn, ChannelState),
 VMSTATE_END_OF_LIST()
 }
diff --git a/hw/ide/internal.h b/hw/ide/internal.h
index 23330be..a75e524 100644
--- a/hw/ide/internal.h
+++ b/hw/ide/internal.h
@@ -526,7 +526,7 @@ extern const VMStateDescription vmstate_ide_bus;
 extern const VMStateDescription vmstate_ide_drive;

 #define VMSTATE_IDE_DRIVES(_field, _state) \
-VMSTATE_STRUCT_ARRAY_TEST(_field, _state, 2, vmstate_3_plus, 0,\
+VMSTATE_STRUCT_ARRAY_TEST(_field, _state, 2, vmstate_3_plus,\
   vmstate_ide_drive, IDEState)

 void ide_bus_reset(IDEBus *bus);
diff --git a/hw/timer/i8254_common.c b/hw/timer/i8254_common.c
index b7bd908..9e36a93 100644
--- a/hw/timer/i8254_common.c
+++ b/hw/timer/i8254_common.c
@@ -269,7 +269,7 @@ static const VMStateDescription vmstate_pit_common = {
 VMSTATE_UINT32_TEST(channels[0].irq_disabled, PITCommonState,
 vmstate_3_plus),
 VMSTATE_STRUCT_ARRAY_TEST(channels, PITCommonState, 3,
-  vmstate_2_plus, 0, vmstate_pit_channel,
+  vmstate_2_plus, vmstate_pit_channel,
   PITChannelState),
 VMSTATE_INT64(channels[0].next_transition_time,
   PITCommonState), /* formerly irq_timer */
diff --git a/hw/timer/pxa2xx_timer.c b/hw/timer/pxa2xx_timer.c
index 393a792..a8af5a0 100644
--- a/hw/timer/pxa2xx_timer.c
+++ b/hw/timer/pxa2xx_timer.c
@@ -519,7 +519,7 @@ static const VMStateDescription vmstate_pxa2xx_timer_regs = 
{
 VMSTATE_UINT32(reset3, PXA2xxTimerInfo),
 VMSTATE_UINT32(snapshot, PXA2xxTimerInfo),
 VMSTATE_STRUCT_ARRAY_TEST(tm4, PXA2xxTimerInfo, 8,
-pxa2xx_timer_has_tm4_test, 0,
+pxa2xx_timer_has_tm4_test,
 vmstate_pxa2xx_timer4_regs, PXA2xxTimer4),
 VMSTATE_END_OF_LIST(),
 }
diff --git a/hw/usb/hcd-xhci.c b/hw/usb/hcd-xhci.c
index a95bd30..d1e4bd0 100644
--- a/hw/usb/hcd-xhci.c
+++ b/hw/usb/hcd-xhci.c
@@ -3737,7 +3737,7 @@ static const VMStateDescription vmstate_xhci_intr = {
 VMSTATE_UINT32_TEST(ev_buffer_put, XHCIInterrupter, xhci_er_full),
 VMSTATE_UINT32_TEST(ev_buffer_get, XHCIInterrupter, xhci_er_full),
 VMSTATE_STRUCT_ARRAY_TEST(ev_buffer, XHCIInterrupter, EV_QUEUE,
-  xhci_er_full, 1,
+  xhci_er_full,
   vmstate_xhci_event, XHCIEvent),

 VMSTATE_END_OF_LIST()
diff --git a/include/hw/acpi/pcihp.h b/include/hw/acpi/pcihp.h
index 9323838..ac80832 100644
--- a/include/hw/acpi/pcihp.h
+++ b/include/hw/acpi/pcihp.h
@@ -68,7 +68,7 @@ extern const VMStateDescription vmstate_acpi_pcihp_pci_status;
 test_pcihp), \
 VMSTATE_STRUCT_ARRAY_TEST(pcihp.acpi_pcihp_pci_status, state, \
   ACPI_PCIHP_MAX_HOTPLUG_BUS, \
-  test_pcihp, 1, \
+  test_pcihp, \
   vmstate_acpi_pcihp_pci_status, \
   AcpiPciHpPciStatus)

diff --git a/include/migration/vmstate.h b/include/migration/vmstate.h
index e540804..46d46fb 100644
--- a/include/migration/vmstate.h
+++ b/include/migration/vmstate.h
@@ -313,11 +313,10 @@ extern const VMStateInfo vmstate_info_bitmap;
 .offset = vmstate_offset_array(_s, _f, _type*, _n),  \
 }

-#define VMSTATE_STRUCT_ARRAY_TEST(_field, _state, _num, _test, _version, 
_vmsd, _type) { \
+#define VMSTATE_STRUCT_ARRAY_TEST(_field, _state, _num, _test, _vmsd, _type) { 
\
 .name = (stringify(_field)), \
 .num  = (_num),  \
 .field_exists = (_test), \
-.version_id   = (_version),  \
 .vmsd = &(_vmsd),\
 .size = sizeof(_type),   \
 .flags= VMS_STRUCT|

[Qemu-devel] [PATCH 067/124] vmstate: Remove version, test and start parameter from VMSTATE_VBUFFER_UINT32

2014-04-21 Thread Juan Quintela
None of its users use them.

Signed-off-by: Juan Quintela 
---
 hw/char/exynos4210_uart.c   | 2 +-
 hw/display/g364fb.c | 2 +-
 hw/dma/pl330.c  | 8 
 hw/intc/exynos4210_gic.c| 2 +-
 hw/net/vmxnet3.c| 3 +--
 hw/nvram/mac_nvram.c| 2 +-
 hw/sd/sdhci.c   | 2 +-
 hw/timer/m48t59.c   | 2 +-
 include/migration/vmstate.h | 7 ++-
 util/fifo8.c| 2 +-
 10 files changed, 14 insertions(+), 18 deletions(-)

diff --git a/hw/char/exynos4210_uart.c b/hw/char/exynos4210_uart.c
index 7614e58..872bc99 100644
--- a/hw/char/exynos4210_uart.c
+++ b/hw/char/exynos4210_uart.c
@@ -563,7 +563,7 @@ static const VMStateDescription 
vmstate_exynos4210_uart_fifo = {
 .fields = (VMStateField[]) {
 VMSTATE_UINT32(sp, Exynos4210UartFIFO),
 VMSTATE_UINT32(rp, Exynos4210UartFIFO),
-VMSTATE_VBUFFER_UINT32(data, Exynos4210UartFIFO, 1, NULL, 0, size),
+VMSTATE_VBUFFER_UINT32(data, Exynos4210UartFIFO, size),
 VMSTATE_END_OF_LIST()
 }
 };
diff --git a/hw/display/g364fb.c b/hw/display/g364fb.c
index 9f6717e..b1a7985 100644
--- a/hw/display/g364fb.c
+++ b/hw/display/g364fb.c
@@ -461,7 +461,7 @@ static const VMStateDescription vmstate_g364fb = {
 .minimum_version_id = 1,
 .post_load = g364fb_post_load,
 .fields = (VMStateField[]) {
-VMSTATE_VBUFFER_UINT32(vram, G364State, 1, NULL, 0, vram_size),
+VMSTATE_VBUFFER_UINT32(vram, G364State, vram_size),
 VMSTATE_BUFFER_UNSAFE(color_palette, G364State, 256 * 3),
 VMSTATE_BUFFER_UNSAFE(cursor_palette, G364State, 9),
 VMSTATE_UINT16_ARRAY(cursor, G364State, 512),
diff --git a/hw/dma/pl330.c b/hw/dma/pl330.c
index 6b6eaae..e4f8993 100644
--- a/hw/dma/pl330.c
+++ b/hw/dma/pl330.c
@@ -170,8 +170,8 @@ static const VMStateDescription vmstate_pl330_fifo = {
 .version_id = 1,
 .minimum_version_id = 1,
 .fields = (VMStateField[]) {
-VMSTATE_VBUFFER_UINT32(buf, PL330Fifo, 1, NULL, 0, buf_size),
-VMSTATE_VBUFFER_UINT32(tag, PL330Fifo, 1, NULL, 0, buf_size),
+VMSTATE_VBUFFER_UINT32(buf, PL330Fifo, buf_size),
+VMSTATE_VBUFFER_UINT32(tag, PL330Fifo, buf_size),
 VMSTATE_UINT32(head, PL330Fifo),
 VMSTATE_UINT32(num, PL330Fifo),
 VMSTATE_UINT32(buf_size, PL330Fifo),
@@ -279,8 +279,8 @@ static const VMStateDescription vmstate_pl330 = {
 VMSTATE_STRUCT(manager, PL330State, 0, vmstate_pl330_chan, PL330Chan),
 VMSTATE_STRUCT_VARRAY_UINT32(chan, PL330State, num_chnls, 0,
  vmstate_pl330_chan, PL330Chan),
-VMSTATE_VBUFFER_UINT32(lo_seqn, PL330State, 1, NULL, 0, num_chnls),
-VMSTATE_VBUFFER_UINT32(hi_seqn, PL330State, 1, NULL, 0, num_chnls),
+VMSTATE_VBUFFER_UINT32(lo_seqn, PL330State, num_chnls),
+VMSTATE_VBUFFER_UINT32(hi_seqn, PL330State, num_chnls),
 VMSTATE_STRUCT(fifo, PL330State, 0, vmstate_pl330_fifo, PL330Fifo),
 VMSTATE_STRUCT(read_queue, PL330State, 0, vmstate_pl330_queue,
PL330Queue),
diff --git a/hw/intc/exynos4210_gic.c b/hw/intc/exynos4210_gic.c
index 0590d5d..4c1f095 100644
--- a/hw/intc/exynos4210_gic.c
+++ b/hw/intc/exynos4210_gic.c
@@ -395,7 +395,7 @@ static const VMStateDescription vmstate_exynos4210_irq_gate 
= {
 .version_id = 2,
 .minimum_version_id = 2,
 .fields = (VMStateField[]) {
-VMSTATE_VBUFFER_UINT32(level, Exynos4210IRQGateState, 1, NULL, 0, 
n_in),
+VMSTATE_VBUFFER_UINT32(level, Exynos4210IRQGateState, n_in),
 VMSTATE_END_OF_LIST()
 }
 };
diff --git a/hw/net/vmxnet3.c b/hw/net/vmxnet3.c
index 88a99ca..d6f419f 100644
--- a/hw/net/vmxnet3.c
+++ b/hw/net/vmxnet3.c
@@ -2225,8 +2225,7 @@ static const VMStateDescription 
vmxstate_vmxnet3_mcast_list = {
 .minimum_version_id = 1,
 .pre_load = vmxnet3_mcast_list_pre_load,
 .fields = (VMStateField[]) {
-VMSTATE_VBUFFER_UINT32(mcast_list, VMXNET3State, 0, NULL, 0,
-mcast_list_buff_size),
+VMSTATE_VBUFFER_UINT32(mcast_list, VMXNET3State, mcast_list_buff_size),
 VMSTATE_END_OF_LIST()
 }
 };
diff --git a/hw/nvram/mac_nvram.c b/hw/nvram/mac_nvram.c
index 170b10b..c4b4a4e 100644
--- a/hw/nvram/mac_nvram.c
+++ b/hw/nvram/mac_nvram.c
@@ -97,7 +97,7 @@ static const VMStateDescription vmstate_macio_nvram = {
 .version_id = 1,
 .minimum_version_id = 1,
 .fields = (VMStateField[]) {
-VMSTATE_VBUFFER_UINT32(data, MacIONVRAMState, 0, NULL, 0, size),
+VMSTATE_VBUFFER_UINT32(data, MacIONVRAMState, size),
 VMSTATE_END_OF_LIST()
 }
 };
diff --git a/hw/sd/sdhci.c b/hw/sd/sdhci.c
index e2951e6..d9c67a6 100644
--- a/hw/sd/sdhci.c
+++ b/hw/sd/sdhci.c
@@ -1223,7 +1223,7 @@ const VMStateDescription sdhci_vmstate = {
 VMSTATE_UINT16(data_count, SDHCIState),
 VMSTATE_UINT64(admasysaddr, SDHCIState),
 VMSTATE_UINT8(stopped_state, SDHCIState),
-VMST

[Qemu-devel] [PATCH 059/124] vmstate: Rename VMSTATE_ARRAY_TEST to VMSTATE_ARRAY

2014-04-21 Thread Juan Quintela
VMSTATE_ARRAY is not being used anymore.

Signed-off-by: Juan Quintela 
---
 hw/net/vmxnet3.c|  9 -
 include/migration/vmstate.h | 20 ++--
 target-i386/machine.c   | 11 +++
 target-ppc/machine.c|  4 ++--
 4 files changed, 23 insertions(+), 21 deletions(-)

diff --git a/hw/net/vmxnet3.c b/hw/net/vmxnet3.c
index 1faf58d..88a99ca 100644
--- a/hw/net/vmxnet3.c
+++ b/hw/net/vmxnet3.c
@@ -2457,15 +2457,14 @@ static const VMStateDescription vmstate_vmxnet3 = {
 VMSTATE_UINT64(drv_shmem, VMXNET3State),
 VMSTATE_UINT64(temp_shared_guest_driver_memory, VMXNET3State),

-VMSTATE_ARRAY_TEST(txq_descr, VMXNET3State,
+VMSTATE_ARRAY(txq_descr, VMXNET3State,
 VMXNET3_DEVICE_MAX_TX_QUEUES, NULL, txq_descr_info,
 Vmxnet3TxqDescr),
-VMSTATE_ARRAY_TEST(rxq_descr, VMXNET3State,
+VMSTATE_ARRAY(rxq_descr, VMXNET3State,
 VMXNET3_DEVICE_MAX_RX_QUEUES, NULL, rxq_descr_info,
 Vmxnet3RxqDescr),
-VMSTATE_ARRAY_TEST(interrupt_states, VMXNET3State,
-VMXNET3_MAX_INTRS, NULL, int_state_info,
-Vmxnet3IntState),
+VMSTATE_ARRAY(interrupt_states, VMXNET3State, VMXNET3_MAX_INTRS,
+NULL, int_state_info, Vmxnet3IntState),

 VMSTATE_END_OF_LIST()
 },
diff --git a/include/migration/vmstate.h b/include/migration/vmstate.h
index cde875e..e4839a2 100644
--- a/include/migration/vmstate.h
+++ b/include/migration/vmstate.h
@@ -221,7 +221,7 @@ extern const VMStateInfo vmstate_info_bitmap;
 .offset   = vmstate_offset_2darray(_state, _field, _type, _n1, _n2),  \
 }

-#define VMSTATE_ARRAY_TEST(_field, _state, _num, _test, _info, _type) {\
+#define VMSTATE_ARRAY(_field, _state, _num, _test, _info, _type) {\
 .name = (stringify(_field)),  \
 .field_exists = (_test),  \
 .num  = (_num),   \
@@ -564,43 +564,43 @@ extern const VMStateInfo vmstate_info_bitmap;
 VMSTATE_ARRAY_OF_POINTER(_f, _s, _n, 0, vmstate_info_timer, QEMUTimer *)

 #define VMSTATE_BOOL_ARRAY_TEST(_f, _s, _n, _t)   \
-VMSTATE_ARRAY_TEST(_f, _s, _n, _t, vmstate_info_bool, bool)
+VMSTATE_ARRAY(_f, _s, _n, _t, vmstate_info_bool, bool)

 #define VMSTATE_BOOL_ARRAY(_f, _s, _n)\
 VMSTATE_BOOL_ARRAY_TEST(_f, _s, _n, NULL)

 #define VMSTATE_UINT8_ARRAY(_f, _s, _n)   \
-VMSTATE_ARRAY_TEST(_f, _s, _n, NULL, vmstate_info_uint8, uint8_t)
+VMSTATE_ARRAY(_f, _s, _n, NULL, vmstate_info_uint8, uint8_t)

 #define VMSTATE_UINT16_ARRAY(_f, _s, _n)  \
-VMSTATE_ARRAY_TEST(_f, _s, _n, NULL, vmstate_info_uint16, uint16_t)
+VMSTATE_ARRAY(_f, _s, _n, NULL, vmstate_info_uint16, uint16_t)

 #define VMSTATE_UINT32_ARRAY_TEST(_f, _s, _n, _t) \
-VMSTATE_ARRAY_TEST(_f, _s, _n, _t, vmstate_info_uint32, uint32_t)
+VMSTATE_ARRAY(_f, _s, _n, _t, vmstate_info_uint32, uint32_t)

 #define VMSTATE_UINT32_ARRAY(_f, _s, _n)  \
 VMSTATE_UINT32_ARRAY_TEST(_f, _s, _n, NULL)

 #define VMSTATE_UINT64_ARRAY_TEST(_f, _s, _n, _t) \
-VMSTATE_ARRAY_TEST(_f, _s, _n, _t, vmstate_info_uint64, uint64_t)
+VMSTATE_ARRAY(_f, _s, _n, _t, vmstate_info_uint64, uint64_t)

 #define VMSTATE_UINT64_ARRAY(_f, _s, _n)  \
 VMSTATE_UINT64_ARRAY_TEST(_f, _s, _n, NULL)

 #define VMSTATE_INT16_ARRAY(_f, _s, _n)   \
-VMSTATE_ARRAY_TEST(_f, _s, _n, NULL, vmstate_info_int16, int16_t)
+VMSTATE_ARRAY(_f, _s, _n, NULL, vmstate_info_int16, int16_t)

 #define VMSTATE_INT32_ARRAY_TEST(_f, _s, _n, _t)  \
-VMSTATE_ARRAY_TEST(_f, _s, _n, _t, vmstate_info_int32, int32_t)
+VMSTATE_ARRAY(_f, _s, _n, _t, vmstate_info_int32, int32_t)

 #define VMSTATE_INT32_ARRAY(_f, _s, _n)   \
 VMSTATE_INT32_ARRAY_TEST(_f, _s, _n, NULL)

 #define VMSTATE_INT64_ARRAY(_f, _s, _n)   \
-VMSTATE_ARRAY_TEST(_f, _s, _n, NULL, vmstate_info_int64, int64_t)
+VMSTATE_ARRAY(_f, _s, _n, NULL, vmstate_info_int64, int64_t)

 #define VMSTATE_FLOAT64_ARRAY(_f, _s, _n) \
-VMSTATE_ARRAY_TEST(_f, _s, _n, NULL, vmstate_info_float64, float64)
+VMSTATE_ARRAY(_f, _s, _n, NULL, vmstate_info_float64, float64)

 #define VMSTATE_UINT8_2DARRAY(_f, _s, _n1, _n2)   \
 VMSTATE_2DARRAY(_f, _s, _n1, _n2, NULL, vmstate_info_uint8, uint8_t)
diff --git a/target-i386/machine.c b/target-i386/machine.c
index 8e4a518..2686390 100644
--- a/target-i386/machine.c
+++ b/target-i386/machine.c
@@ -209,10 +209,13 @@ static bool fpregs_is_1_no_mmx(void *opaque, int 
version_id)
 re

[Qemu-devel] [PATCH 078/124] vmstate: Remove version parameter from VMSTATE_VARRAY_UINT32

2014-04-21 Thread Juan Quintela
Signed-off-by: Juan Quintela 
---
 hw/nvram/ds1225y.c  | 2 +-
 hw/ppc/spapr_iommu.c| 3 ++-
 include/migration/vmstate.h | 2 +-
 3 files changed, 4 insertions(+), 3 deletions(-)

diff --git a/hw/nvram/ds1225y.c b/hw/nvram/ds1225y.c
index 332598b..cfedfa8 100644
--- a/hw/nvram/ds1225y.c
+++ b/hw/nvram/ds1225y.c
@@ -97,7 +97,7 @@ static const VMStateDescription vmstate_nvram = {
 .minimum_version_id = 0,
 .post_load = nvram_post_load,
 .fields = (VMStateField[]) {
-VMSTATE_VARRAY_UINT32(contents, NvRamState, chip_size, 0,
+VMSTATE_VARRAY_UINT32(contents, NvRamState, chip_size,
   vmstate_info_uint8, uint8_t),
 VMSTATE_END_OF_LIST()
 }
diff --git a/hw/ppc/spapr_iommu.c b/hw/ppc/spapr_iommu.c
index ce15751..9fda2b3 100644
--- a/hw/ppc/spapr_iommu.c
+++ b/hw/ppc/spapr_iommu.c
@@ -105,7 +105,8 @@ static const VMStateDescription vmstate_spapr_tce_table = {

 /* IOMMU state */
 VMSTATE_BOOL(bypass, sPAPRTCETable),
-VMSTATE_VARRAY_UINT32(table, sPAPRTCETable, nb_table, 0, 
vmstate_info_uint64, uint64_t),
+VMSTATE_VARRAY_UINT32(table, sPAPRTCETable, nb_table,
+  vmstate_info_uint64, uint64_t),

 VMSTATE_END_OF_LIST()
 },
diff --git a/include/migration/vmstate.h b/include/migration/vmstate.h
index e1c9680..4293377 100644
--- a/include/migration/vmstate.h
+++ b/include/migration/vmstate.h
@@ -611,7 +611,7 @@ extern const VMStateInfo vmstate_info_bitmap;
 #define VMSTATE_UNUSED(_size) \
 VMSTATE_UNUSED_TEST(NULL, _size)

-#define VMSTATE_VARRAY_UINT32(_field, _state, _field_num, _version, _info, 
_type) \
+#define VMSTATE_VARRAY_UINT32(_field, _state, _field_num, _info, _type) \
 VMSTATE_VARRAY_UINT32_TEST(_field, _state, _field_num, NULL, _info, _type)

 #define VMSTATE_END_OF_LIST() \
-- 
1.9.0




[Qemu-devel] [PATCH 060/124] vmstate: Remove version_id from VMSTATE_VBUFFER

2014-04-21 Thread Juan Quintela
None of its two users use it.

Signed-off-by: Juan Quintela 
---
 include/migration/vmstate.h | 7 +++
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/include/migration/vmstate.h b/include/migration/vmstate.h
index e4839a2..dfb59e2 100644
--- a/include/migration/vmstate.h
+++ b/include/migration/vmstate.h
@@ -412,9 +412,8 @@ extern const VMStateInfo vmstate_info_bitmap;
 .start= (_start),\
 }

-#define VMSTATE_VBUFFER(_field, _state, _version, _test, _start, _field_size) 
{ \
+#define VMSTATE_VBUFFER(_field, _state, _test, _start, _field_size) { \
 .name = (stringify(_field)), \
-.version_id   = (_version),  \
 .field_exists = (_test), \
 .size_offset  = vmstate_offset_value(_state, _field_size, int32_t),\
 .info = &vmstate_info_buffer,\
@@ -627,13 +626,13 @@ extern const VMStateInfo vmstate_info_bitmap;
 VMSTATE_STATIC_BUFFER(_f, _s, 0, NULL, _start, sizeof(typeof_field(_s, 
_f)))

 #define VMSTATE_PARTIAL_VBUFFER(_f, _s, _size)\
-VMSTATE_VBUFFER(_f, _s, 0, NULL, 0, _size)
+VMSTATE_VBUFFER(_f, _s, NULL, 0, _size)

 #define VMSTATE_PARTIAL_VBUFFER_UINT32(_f, _s, _size)\
 VMSTATE_VBUFFER_UINT32(_f, _s, 0, NULL, 0, _size)

 #define VMSTATE_SUB_VBUFFER(_f, _s, _start, _size)\
-VMSTATE_VBUFFER(_f, _s, 0, NULL, _start, _size)
+VMSTATE_VBUFFER(_f, _s, NULL, _start, _size)

 #define VMSTATE_BUFFER_TEST(_f, _s, _test)\
 VMSTATE_STATIC_BUFFER(_f, _s, 0, _test, 0, sizeof(typeof_field(_s, _f)))
-- 
1.9.0




[Qemu-devel] [PATCH 064/124] vmstate: Remove version_id from VMSTATE_VARRAY_UINT16_UNSAFE

2014-04-21 Thread Juan Quintela
Signed-off-by: Juan Quintela 
---
 hw/nvram/eeprom93xx.c   | 2 +-
 include/migration/vmstate.h | 3 +--
 2 files changed, 2 insertions(+), 3 deletions(-)

diff --git a/hw/nvram/eeprom93xx.c b/hw/nvram/eeprom93xx.c
index 7e09037..8f59509 100644
--- a/hw/nvram/eeprom93xx.c
+++ b/hw/nvram/eeprom93xx.c
@@ -145,7 +145,7 @@ static const VMStateDescription vmstate_eeprom = {
 VMSTATE_UNUSED_TEST(is_old_eeprom_version, 1),
 VMSTATE_UINT16_EQUAL_TEST(size, eeprom_t, is_eeprom_version),
 VMSTATE_UINT16(data, eeprom_t),
-VMSTATE_VARRAY_UINT16_UNSAFE(contents, eeprom_t, size, 0,
+VMSTATE_VARRAY_UINT16_UNSAFE(contents, eeprom_t, size,
  vmstate_info_uint16, uint16_t),
 VMSTATE_END_OF_LIST()
 }
diff --git a/include/migration/vmstate.h b/include/migration/vmstate.h
index a26eb20..031c117 100644
--- a/include/migration/vmstate.h
+++ b/include/migration/vmstate.h
@@ -268,9 +268,8 @@ extern const VMStateInfo vmstate_info_bitmap;
 .offset = vmstate_offset_pointer(_state, _field, _type), \
 }

-#define VMSTATE_VARRAY_UINT16_UNSAFE(_field, _state, _field_num, _version, 
_info, _type) {\
+#define VMSTATE_VARRAY_UINT16_UNSAFE(_field, _state, _field_num, _info, _type) 
{\
 .name   = (stringify(_field)),   \
-.version_id = (_version),\
 .num_offset = vmstate_offset_value(_state, _field_num, uint16_t),\
 .info   = &(_info),  \
 .size   = sizeof(_type), \
-- 
1.9.0




[Qemu-devel] [PATCH 054/124] vmstate: Port last user of VMSTATE_SINGLE to VMSTATE_SINGLE_TEST

2014-04-21 Thread Juan Quintela
Signed-off-by: Juan Quintela 
---
 hw/timer/twl92230.c | 2 +-
 include/migration/vmstate.h | 3 ---
 2 files changed, 1 insertion(+), 4 deletions(-)

diff --git a/hw/timer/twl92230.c b/hw/timer/twl92230.c
index 7ded4ba..3aacaeb 100644
--- a/hw/timer/twl92230.c
+++ b/hw/timer/twl92230.c
@@ -765,7 +765,7 @@ static const VMStateInfo vmstate_hack_int32_as_uint16 = {
 };

 #define VMSTATE_UINT16_HACK(_f, _s)  \
-VMSTATE_SINGLE(_f, _s, 0, vmstate_hack_int32_as_uint16, int32_t)
+VMSTATE_SINGLE_TEST(_f, _s, NULL, 0, vmstate_hack_int32_as_uint16, int32_t)


 static const VMStateDescription vmstate_menelaus_tm = {
diff --git a/include/migration/vmstate.h b/include/migration/vmstate.h
index 60b67dc..e223758 100644
--- a/include/migration/vmstate.h
+++ b/include/migration/vmstate.h
@@ -489,9 +489,6 @@ extern const VMStateInfo vmstate_info_bitmap;
_v : version
 */

-#define VMSTATE_SINGLE(_field, _state, _version, _info, _type)\
-VMSTATE_SINGLE_TEST(_field, _state, NULL, _version, _info, _type)
-
 #define VMSTATE_STRUCT(_field, _state, _version, _vmsd, _type)\
 VMSTATE_STRUCT_TEST(_field, _state, NULL, _version, _vmsd, _type)

-- 
1.9.0




[Qemu-devel] [PATCH 070/124] vmstate: Remove version parameter from VMSTATE_STATIC_BUFFER

2014-04-21 Thread Juan Quintela
No user for it.

Signed-off-by: Juan Quintela 
---
 include/migration/vmstate.h | 11 +--
 1 file changed, 5 insertions(+), 6 deletions(-)

diff --git a/include/migration/vmstate.h b/include/migration/vmstate.h
index 7e3877d..1afbf5a 100644
--- a/include/migration/vmstate.h
+++ b/include/migration/vmstate.h
@@ -381,9 +381,8 @@ extern const VMStateInfo vmstate_info_bitmap;
 .offset = offsetof(_state, _field),  \
 }

-#define VMSTATE_STATIC_BUFFER(_field, _state, _version, _test, _start, _size) 
{ \
+#define VMSTATE_STATIC_BUFFER(_field, _state, _test, _start, _size) { \
 .name = (stringify(_field)), \
-.version_id   = (_version),  \
 .field_exists = (_test), \
 .size = (_size - _start),\
 .info = &vmstate_info_buffer,\
@@ -591,13 +590,13 @@ extern const VMStateInfo vmstate_info_bitmap;
 VMSTATE_SUB_ARRAY(_f, _s, _start, _num, vmstate_info_uint32, uint32_t)

 #define VMSTATE_BUFFER(_f, _s)\
-VMSTATE_STATIC_BUFFER(_f, _s, 0, NULL, 0, sizeof(typeof_field(_s, _f)))
+VMSTATE_STATIC_BUFFER(_f, _s, NULL, 0, sizeof(typeof_field(_s, _f)))

 #define VMSTATE_PARTIAL_BUFFER(_f, _s, _size) \
-VMSTATE_STATIC_BUFFER(_f, _s, 0, NULL, 0, _size)
+VMSTATE_STATIC_BUFFER(_f, _s, NULL, 0, _size)

 #define VMSTATE_BUFFER_START_MIDDLE(_f, _s, _start) \
-VMSTATE_STATIC_BUFFER(_f, _s, 0, NULL, _start, sizeof(typeof_field(_s, 
_f)))
+VMSTATE_STATIC_BUFFER(_f, _s, NULL, _start, sizeof(typeof_field(_s, _f)))

 #define VMSTATE_PARTIAL_VBUFFER(_f, _s, _size)\
 VMSTATE_VBUFFER(_f, _s, NULL, 0, _size)
@@ -609,7 +608,7 @@ extern const VMStateInfo vmstate_info_bitmap;
 VMSTATE_VBUFFER(_f, _s, NULL, _start, _size)

 #define VMSTATE_BUFFER_TEST(_f, _s, _test)\
-VMSTATE_STATIC_BUFFER(_f, _s, 0, _test, 0, sizeof(typeof_field(_s, _f)))
+VMSTATE_STATIC_BUFFER(_f, _s, _test, 0, sizeof(typeof_field(_s, _f)))

 #define VMSTATE_BUFFER_UNSAFE(_field, _state,  _size) \
 VMSTATE_BUFFER_UNSAFE_TEST(_field, _state, NULL, vmstate_info_buffer, 
_size)
-- 
1.9.0




[Qemu-devel] [PATCH 062/124] vmstate: Remove version_id from VMSTATE_SUB_ARRAY

2014-04-21 Thread Juan Quintela
None of its two users used it.

Signed-off-by: Juan Quintela 
---
 include/migration/vmstate.h | 7 +++
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/include/migration/vmstate.h b/include/migration/vmstate.h
index e84da16..1acba4b 100644
--- a/include/migration/vmstate.h
+++ b/include/migration/vmstate.h
@@ -231,9 +231,8 @@ extern const VMStateInfo vmstate_info_bitmap;
 .offset   = vmstate_offset_array(_state, _field, _type, _num),\
 }

-#define VMSTATE_SUB_ARRAY(_field, _state, _start, _num, _version, _info, 
_type) { \
+#define VMSTATE_SUB_ARRAY(_field, _state, _start, _num, _info, _type) { \
 .name   = (stringify(_field)),   \
-.version_id = (_version),\
 .num= (_num),\
 .info   = &(_info),  \
 .size   = sizeof(_type), \
@@ -607,10 +606,10 @@ extern const VMStateInfo vmstate_info_bitmap;
 VMSTATE_2DARRAY(_f, _s, _n1, _n2, NULL, vmstate_info_uint32, uint32_t)

 #define VMSTATE_UINT8_SUB_ARRAY(_f, _s, _start, _num)\
-VMSTATE_SUB_ARRAY(_f, _s, _start, _num, 0, vmstate_info_uint8, uint8_t)
+VMSTATE_SUB_ARRAY(_f, _s, _start, _num, vmstate_info_uint8, uint8_t)

 #define VMSTATE_UINT32_SUB_ARRAY(_f, _s, _start, _num)\
-VMSTATE_SUB_ARRAY(_f, _s, _start, _num, 0, vmstate_info_uint32, uint32_t)
+VMSTATE_SUB_ARRAY(_f, _s, _start, _num, vmstate_info_uint32, uint32_t)

 #define VMSTATE_BUFFER(_f, _s)\
 VMSTATE_STATIC_BUFFER(_f, _s, 0, NULL, 0, sizeof(typeof_field(_s, _f)))
-- 
1.9.0




[Qemu-devel] [PATCH 080/124] vmstate: Move all users of versioning to VMSTATE_STRUCT_TEST

2014-04-21 Thread Juan Quintela
Signed-off-by: Juan Quintela 
---
 hw/usb/hcd-ehci-pci.c| 3 ++-
 hw/usb/hcd-ehci-sysbus.c | 3 ++-
 2 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/hw/usb/hcd-ehci-pci.c b/hw/usb/hcd-ehci-pci.c
index 505741a..6ada623 100644
--- a/hw/usb/hcd-ehci-pci.c
+++ b/hw/usb/hcd-ehci-pci.c
@@ -110,7 +110,8 @@ static const VMStateDescription vmstate_ehci_pci = {
 .minimum_version_id  = 1,
 .fields = (VMStateField[]) {
 VMSTATE_PCI_DEVICE(pcidev, EHCIPCIState),
-VMSTATE_STRUCT(ehci, EHCIPCIState, 2, vmstate_ehci, EHCIState),
+VMSTATE_STRUCT_TEST(ehci, EHCIPCIState, vmstate_2_plus,
+vmstate_ehci, EHCIState),
 VMSTATE_END_OF_LIST()
 }
 };
diff --git a/hw/usb/hcd-ehci-sysbus.c b/hw/usb/hcd-ehci-sysbus.c
index 19ed2c2..2c28555 100644
--- a/hw/usb/hcd-ehci-sysbus.c
+++ b/hw/usb/hcd-ehci-sysbus.c
@@ -22,7 +22,8 @@ static const VMStateDescription vmstate_ehci_sysbus = {
 .version_id  = 2,
 .minimum_version_id  = 1,
 .fields = (VMStateField[]) {
-VMSTATE_STRUCT(ehci, EHCISysBusState, 2, vmstate_ehci, EHCIState),
+VMSTATE_STRUCT_TEST(ehci, EHCISysBusState, vmstate_2_plus,
+vmstate_ehci, EHCIState),
 VMSTATE_END_OF_LIST()
 }
 };
-- 
1.9.0




[Qemu-devel] [PATCH 026/124] vmstate: Test for VMSTATE_UNUSED

2014-04-21 Thread Juan Quintela
Remove VMSTATE_UNUSED_V and fix only user.

Signed-off-by: Juan Quintela 
---
 hw/intc/ioapic_common.c |  3 ++-
 include/migration/vmstate.h | 11 ++-
 tests/test-vmstate.c|  5 +
 3 files changed, 9 insertions(+), 10 deletions(-)

diff --git a/hw/intc/ioapic_common.c b/hw/intc/ioapic_common.c
index d4c0c8e..ae81d3f 100644
--- a/hw/intc/ioapic_common.c
+++ b/hw/intc/ioapic_common.c
@@ -91,7 +91,8 @@ static const VMStateDescription vmstate_ioapic_common = {
 .fields = (VMStateField[]) {
 VMSTATE_UINT8(id, IOAPICCommonState),
 VMSTATE_UINT8(ioregsel, IOAPICCommonState),
-VMSTATE_UNUSED_V(2, 8), /* to account for qemu-kvm's v2 format */
+/* to account for qemu-kvm's v2 format */
+VMSTATE_UNUSED_TEST(vmstate_2_plus, 8),
 VMSTATE_UINT32_TEST(irr, IOAPICCommonState, vmstate_2_plus),
 VMSTATE_UINT64_ARRAY(ioredtbl, IOAPICCommonState, IOAPIC_NUM_PINS),
 VMSTATE_END_OF_LIST()
diff --git a/include/migration/vmstate.h b/include/migration/vmstate.h
index 717c7fb..553cc0a 100644
--- a/include/migration/vmstate.h
+++ b/include/migration/vmstate.h
@@ -482,10 +482,9 @@ extern const VMStateInfo vmstate_info_bitmap;
 .offset = offsetof(_state, _field),  \
 }

-#define VMSTATE_UNUSED_BUFFER(_test, _version, _size) {  \
+#define VMSTATE_UNUSED_TEST(_test, _size) {  \
 .name = "unused",\
 .field_exists = (_test), \
-.version_id   = (_version),  \
 .size = (_size), \
 .info = &vmstate_info_unused_buffer, \
 .flags= VMS_BUFFER,  \
@@ -719,14 +718,8 @@ extern const VMStateInfo vmstate_info_bitmap;
 #define VMSTATE_BUFFER_UNSAFE(_field, _state, _version, _size)\
 VMSTATE_BUFFER_UNSAFE_INFO(_field, _state, _version, vmstate_info_buffer, 
_size)

-#define VMSTATE_UNUSED_V(_v, _size)   \
-VMSTATE_UNUSED_BUFFER(NULL, _v, _size)
-
 #define VMSTATE_UNUSED(_size) \
-VMSTATE_UNUSED_V(0, _size)
-
-#define VMSTATE_UNUSED_TEST(_test, _size) \
-VMSTATE_UNUSED_BUFFER(_test, 0, _size)
+VMSTATE_UNUSED_TEST(NULL, _size)

 #define VMSTATE_END_OF_LIST() \
 {}
diff --git a/tests/test-vmstate.c b/tests/test-vmstate.c
index c6ceec6..2aa6d8b 100644
--- a/tests/test-vmstate.c
+++ b/tests/test-vmstate.c
@@ -208,6 +208,7 @@ static const VMStateDescription vmstate_simple_primitive = {
 VMSTATE_INT64(i64_1, TestSimple),
 VMSTATE_INT64(i64_2, TestSimple),
 VMSTATE_FLOAT64(f64, TestSimple),
+VMSTATE_UNUSED(5),
 VMSTATE_END_OF_LIST()
 }
 };
@@ -240,6 +241,7 @@ uint8_t wire_simple_primitive[] = {
 /* i64_1 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0xb8, 0xf4, 0x7c,
 /* i64_2 */ 0xff, 0xff, 0xff, 0xff, 0xff, 0x47, 0x0b, 0x84,
 /* f64 */   0x40, 0x09, 0x21, 0xfb, 0x54, 0x44, 0x2d, 0x18,
+/* unused */0x00, 0x00, 0x00, 0x00, 0x00,
 QEMU_VM_EOF, /* just to ensure we won't get EOF reported prematurely */
 };

@@ -314,6 +316,8 @@ static const VMStateDescription vmstate_simple_test = {
 VMSTATE_UINT32_TEST(u32_2, TestSimple, test_false),
 VMSTATE_UINT64_TEST(u64_1, TestSimple, test_true),
 VMSTATE_UINT64_TEST(u64_2, TestSimple, test_false),
+VMSTATE_UNUSED_TEST(test_true, 5),
+VMSTATE_UNUSED_TEST(test_false, 5),
 VMSTATE_END_OF_LIST()
 }
 };
@@ -328,6 +332,7 @@ uint8_t wire_simple_test[] = {
 /* u16_1 */ 0x02, 0x00,
 /* u32_1 */ 0x00, 0x01, 0x11, 0x70,
 /* u64_1 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0xb8, 0xf4, 0x7c,
+/* unused */0x00, 0x00, 0x00, 0x00, 0x00,
 QEMU_VM_EOF, /* just to ensure we won't get EOF reported prematurely */
 };

-- 
1.9.0




[Qemu-devel] [PATCH 066/124] vmstate: remove version parameter from VMSTATE_BUFFER_POINTER_UNSAFE

2014-04-21 Thread Juan Quintela
Signed-off-by: Juan Quintela 
---
 hw/block/onenand.c  | 2 +-
 hw/sd/sd.c  | 2 +-
 include/migration/vmstate.h | 3 +--
 3 files changed, 3 insertions(+), 4 deletions(-)

diff --git a/hw/block/onenand.c b/hw/block/onenand.c
index 60d5311..87fbf00 100644
--- a/hw/block/onenand.c
+++ b/hw/block/onenand.c
@@ -189,7 +189,7 @@ static const VMStateDescription vmstate_onenand = {
 VMSTATE_UINT8(ecc.cp, OneNANDState),
 VMSTATE_UINT16_ARRAY(ecc.lp, OneNANDState, 2),
 VMSTATE_UINT16(ecc.count, OneNANDState),
-VMSTATE_BUFFER_POINTER_UNSAFE(otp, OneNANDState, 0,
+VMSTATE_BUFFER_POINTER_UNSAFE(otp, OneNANDState,
 ((64 + 2) << PAGE_SHIFT)),
 VMSTATE_END_OF_LIST()
 }
diff --git a/hw/sd/sd.c b/hw/sd/sd.c
index 7ee8c24..ac909f3 100644
--- a/hw/sd/sd.c
+++ b/hw/sd/sd.c
@@ -480,7 +480,7 @@ static const VMStateDescription sd_vmstate = {
 VMSTATE_UINT64(data_start, SDState),
 VMSTATE_UINT32(data_offset, SDState),
 VMSTATE_UINT8_ARRAY(data, SDState, 512),
-VMSTATE_BUFFER_POINTER_UNSAFE(buf, SDState, 1, 512),
+VMSTATE_BUFFER_POINTER_UNSAFE(buf, SDState, 512),
 VMSTATE_BOOL(enable, SDState),
 VMSTATE_END_OF_LIST()
 }
diff --git a/include/migration/vmstate.h b/include/migration/vmstate.h
index fcd2c8a..b3db632 100644
--- a/include/migration/vmstate.h
+++ b/include/migration/vmstate.h
@@ -435,9 +435,8 @@ extern const VMStateInfo vmstate_info_bitmap;
 .offset   = offsetof(_state, _field),\
 }

-#define VMSTATE_BUFFER_POINTER_UNSAFE(_field, _state, _version, _size) { \
+#define VMSTATE_BUFFER_POINTER_UNSAFE(_field, _state, _size) { \
 .name   = (stringify(_field)),   \
-.version_id = (_version),\
 .size   = (_size),   \
 .info   = &vmstate_info_buffer,  \
 .flags  = VMS_BUFFER|VMS_POINTER,\
-- 
1.9.0




[Qemu-devel] [PATCH 089/124] vmstate: Test for VMSTATE_UINT32_SUB_ARRAY

2014-04-21 Thread Juan Quintela
Signed-off-by: Juan Quintela 
---
 tests/test-vmstate.c | 10 ++
 1 file changed, 10 insertions(+)

diff --git a/tests/test-vmstate.c b/tests/test-vmstate.c
index 0a4f81a..8b45ea5 100644
--- a/tests/test-vmstate.c
+++ b/tests/test-vmstate.c
@@ -811,6 +811,8 @@ static const VMStateDescription vmstate_array_sub = {
 .fields = (VMStateField[]) {
 VMSTATE_UINT8_SUB_ARRAY(u8_1, TestArray, 0, VMSTATE_ARRAY_SIZE),
 VMSTATE_UINT8_SUB_ARRAY(u8_2, TestArray, 2 , 2),
+VMSTATE_UINT32_SUB_ARRAY(u32_1, TestArray, 0, VMSTATE_ARRAY_SIZE),
+VMSTATE_UINT32_SUB_ARRAY(u32_2, TestArray, 2 , 2),
 VMSTATE_END_OF_LIST()
 }
 };
@@ -818,6 +820,10 @@ static const VMStateDescription vmstate_array_sub = {
 uint8_t wire_array_sub[] = {
 /* u8_1 */ 0x01, 0x02, 0x03, 0x04, 0x05,
 /* u8_2 {3,4} */   0x03, 0x02,
+/* u32_1 */0x00, 0x00, 0x00, 0x15, 0x00, 0x00, 0x00, 0x16,
+   0x00, 0x00, 0x00, 0x17, 0x00, 0x00, 0x00, 0x18,
+   0x00, 0x00, 0x00, 0x19,
+/* u32_2 {3,4}*/   0x00, 0x00, 0x00, 0x17, 0x00, 0x00, 0x00, 0x16,
 QEMU_VM_EOF, /* just to ensure we won't get EOF reported prematurely */
 };

@@ -839,15 +845,19 @@ static void test_array_sub(void)

 for (i = 0; i < VMSTATE_ARRAY_SIZE; i++) {
 ELEM_EQUAL(u8_1, i);
+ELEM_EQUAL(u32_1, i);
 }
 for (i = 0; i < 2; i++) {
 ELEM_NOT_EQUAL(u8_2, i);
+ELEM_NOT_EQUAL(u32_2, i);
 }
 for (i = 2; i < 4; i++) {
 ELEM_EQUAL(u8_2, i);
+ELEM_EQUAL(u32_2, i);
 }
 for (i = 4; i < VMSTATE_ARRAY_SIZE; i++) {
 ELEM_NOT_EQUAL(u8_2, i);
+ELEM_NOT_EQUAL(u32_2, i);
 }
 }
 #undef FIELD_EQUAL
-- 
1.9.0




[Qemu-devel] [PATCH 081/124] vmstate: Remove version from all VMSTATE_STRUCT calls

2014-04-21 Thread Juan Quintela
It has no users at this point.

Signed-off-by: Juan Quintela 
---
 hw/acpi/piix4.c|  4 ++--
 hw/arm/spitz.c |  2 +-
 hw/audio/pl041.c   | 16 ++--
 hw/block/fdc.c |  4 ++--
 hw/char/exynos4210_uart.c  |  2 +-
 hw/char/serial-isa.c   |  2 +-
 hw/char/serial-pci.c   |  2 +-
 hw/display/cirrus_vga.c|  2 +-
 hw/display/qxl.c   |  4 ++--
 hw/display/vga-pci.c   |  2 +-
 hw/display/vmware_vga.c|  2 +-
 hw/dma/i82374.c|  2 +-
 hw/dma/pl330.c |  8 
 hw/i386/kvmvapic.c |  6 +++---
 hw/ide/internal.h  |  2 +-
 hw/input/pckbd.c   |  2 +-
 hw/input/ps2.c |  4 ++--
 hw/isa/lpc_ich9.c  |  4 ++--
 hw/isa/vt82c686.c  |  2 +-
 hw/net/allwinner_emac.c|  2 +-
 hw/net/lan9118.c   |  2 +-
 hw/net/lance.c |  2 +-
 hw/net/milkymist-minimac2.c|  2 +-
 hw/net/ne2000-isa.c|  2 +-
 hw/net/ne2000.c|  2 +-
 hw/net/pcnet-pci.c |  2 +-
 hw/net/rtl8139.c   |  2 +-
 hw/net/xgmac.c |  2 +-
 hw/pci-bridge/ioh3420.c|  2 +-
 hw/pci-bridge/xio3130_downstream.c |  2 +-
 hw/pci-bridge/xio3130_upstream.c   |  2 +-
 hw/scsi/esp-pci.c  |  2 +-
 hw/scsi/esp.c  |  2 +-
 hw/timer/exynos4210_mct.c  | 11 ---
 hw/timer/pxa2xx_timer.c|  4 ++--
 hw/timer/twl92230.c|  6 ++
 hw/usb/dev-smartcard-reader.c  |  2 +-
 hw/usb/hcd-xhci.c  |  2 +-
 hw/usb/redirect.c  |  8 
 include/hw/ipack/ipack.h   |  2 +-
 include/hw/ppc/spapr_vio.h |  2 +-
 include/migration/vmstate.h| 10 +++---
 target-alpha/machine.c |  2 +-
 target-lm32/machine.c  |  2 +-
 target-openrisc/machine.c  |  2 +-
 45 files changed, 70 insertions(+), 83 deletions(-)

diff --git a/hw/acpi/piix4.c b/hw/acpi/piix4.c
index 091dca3..527a5c8 100644
--- a/hw/acpi/piix4.c
+++ b/hw/acpi/piix4.c
@@ -262,10 +262,10 @@ static const VMStateDescription vmstate_acpi = {
 VMSTATE_UINT16(ar.pm1.evt.sts, PIIX4PMState),
 VMSTATE_UINT16(ar.pm1.evt.en, PIIX4PMState),
 VMSTATE_UINT16(ar.pm1.cnt.cnt, PIIX4PMState),
-VMSTATE_STRUCT(apm, PIIX4PMState, 0, vmstate_apm, APMState),
+VMSTATE_STRUCT(apm, PIIX4PMState, vmstate_apm, APMState),
 VMSTATE_TIMER(ar.tmr.timer, PIIX4PMState),
 VMSTATE_INT64(ar.tmr.overflow_time, PIIX4PMState),
-VMSTATE_STRUCT(ar.gpe, PIIX4PMState, 2, vmstate_gpe, ACPIGPE),
+VMSTATE_STRUCT(ar.gpe, PIIX4PMState, vmstate_gpe, ACPIGPE),
 VMSTATE_STRUCT_TEST(
 acpi_pci_hotplug.acpi_pcihp_pci_status[ACPI_PCIHP_BSEL_DEFAULT],
 PIIX4PMState,
diff --git a/hw/arm/spitz.c b/hw/arm/spitz.c
index a179c1d..cff3a9e 100644
--- a/hw/arm/spitz.c
+++ b/hw/arm/spitz.c
@@ -1008,7 +1008,7 @@ static VMStateDescription vmstate_sl_nand_info = {
 .minimum_version_id = 0,
 .fields = (VMStateField[]) {
 VMSTATE_UINT8(ctl, SLNANDState),
-VMSTATE_STRUCT(ecc, SLNANDState, 0, vmstate_ecc_state, ECCState),
+VMSTATE_STRUCT(ecc, SLNANDState, vmstate_ecc_state, ECCState),
 VMSTATE_END_OF_LIST(),
 },
 };
diff --git a/hw/audio/pl041.c b/hw/audio/pl041.c
index 19982f2..9b850c5 100644
--- a/hw/audio/pl041.c
+++ b/hw/audio/pl041.c
@@ -585,13 +585,11 @@ static const VMStateDescription vmstate_pl041_channel = {
 .version_id = 1,
 .minimum_version_id = 1,
 .fields = (VMStateField[]) {
-VMSTATE_STRUCT(tx_fifo, pl041_channel, 0,
-   vmstate_pl041_fifo, pl041_fifo),
+VMSTATE_STRUCT(tx_fifo, pl041_channel, vmstate_pl041_fifo, pl041_fifo),
 VMSTATE_UINT8(tx_enabled, pl041_channel),
 VMSTATE_UINT8(tx_compact_mode, pl041_channel),
 VMSTATE_UINT8(tx_sample_size, pl041_channel),
-VMSTATE_STRUCT(rx_fifo, pl041_channel, 0,
-   vmstate_pl041_fifo, pl041_fifo),
+VMSTATE_STRUCT(rx_fifo, pl041_channel, vmstate_pl041_fifo, pl041_fifo),
 VMSTATE_UINT8(rx_enabled, pl041_channel),
 VMSTATE_UINT8(rx_compact_mode, pl041_channel),
 VMSTATE_UINT8(rx_sample_size, pl041_channel),
@@ -605,12 +603,10 @@ static const VMStateDescription vmstate_pl041 = {
 .minimum_version_id = 1,
 .fields = (VMStateField[]) {
 VMSTATE_UINT32(fifo_depth, PL041State),
-VMSTATE_STRUCT(regs, PL041State, 0,
-   vmstate_pl041_regfile, pl041_regfile),
-VMSTATE_STRUCT(fifo1, PL041State, 0,
-   vmstate_pl041_channel, pl041_channel),
-VMSTATE_STRUCT(codec, PL041State, 0,
-   vms

[Qemu-devel] [PATCH 002/124] savevm: Remove all the unneded version_minimum_id_old (usb)

2014-04-21 Thread Juan Quintela
After previous Peter patch, they are redundant.  This way we don't asign them
except when needed.  Once there, there were lots of case where the ".fields"
indentation was wrong:

 .fields = (VMStateField []) {
and
 .fields =  (VMStateField []) {

Change all the combinations to:

 .fields = (VMStateField[]){

The biggest problem (appart of aesthetics) was that checkpatch complained
when we copy&pasted the code from one place to another.

Signed-off-by: Juan Quintela 
---
 hw/usb/bus.c | 2 +-
 hw/usb/dev-hid.c | 4 ++--
 hw/usb/dev-hub.c | 4 ++--
 hw/usb/dev-storage.c | 2 +-
 hw/usb/hcd-ehci-pci.c| 2 +-
 hw/usb/hcd-ehci-sysbus.c | 2 +-
 hw/usb/hcd-ehci.c| 2 +-
 hw/usb/hcd-uhci.c| 6 ++
 8 files changed, 11 insertions(+), 13 deletions(-)

diff --git a/hw/usb/bus.c b/hw/usb/bus.c
index fe70429..5f201cb 100644
--- a/hw/usb/bus.c
+++ b/hw/usb/bus.c
@@ -61,7 +61,7 @@ const VMStateDescription vmstate_usb_device = {
 .version_id = 1,
 .minimum_version_id = 1,
 .post_load = usb_device_post_load,
-.fields = (VMStateField []) {
+.fields = (VMStateField[]) {
 VMSTATE_UINT8(addr, USBDevice),
 VMSTATE_INT32(state, USBDevice),
 VMSTATE_INT32(remote_wakeup, USBDevice),
diff --git a/hw/usb/dev-hid.c b/hw/usb/dev-hid.c
index f36e617..d097d93 100644
--- a/hw/usb/dev-hid.c
+++ b/hw/usb/dev-hid.c
@@ -622,7 +622,7 @@ static const VMStateDescription vmstate_usb_ptr = {
 .version_id = 1,
 .minimum_version_id = 1,
 .post_load = usb_ptr_post_load,
-.fields = (VMStateField []) {
+.fields = (VMStateField[]) {
 VMSTATE_USB_DEVICE(dev, USBHIDState),
 VMSTATE_HID_POINTER_DEVICE(hid, USBHIDState),
 VMSTATE_END_OF_LIST()
@@ -633,7 +633,7 @@ static const VMStateDescription vmstate_usb_kbd = {
 .name = "usb-kbd",
 .version_id = 1,
 .minimum_version_id = 1,
-.fields = (VMStateField []) {
+.fields = (VMStateField[]) {
 VMSTATE_USB_DEVICE(dev, USBHIDState),
 VMSTATE_HID_KEYBOARD_DEVICE(hid, USBHIDState),
 VMSTATE_END_OF_LIST()
diff --git a/hw/usb/dev-hub.c b/hw/usb/dev-hub.c
index bc03531..7492174 100644
--- a/hw/usb/dev-hub.c
+++ b/hw/usb/dev-hub.c
@@ -540,7 +540,7 @@ static const VMStateDescription vmstate_usb_hub_port = {
 .name = "usb-hub-port",
 .version_id = 1,
 .minimum_version_id = 1,
-.fields = (VMStateField []) {
+.fields = (VMStateField[]) {
 VMSTATE_UINT16(wPortStatus, USBHubPort),
 VMSTATE_UINT16(wPortChange, USBHubPort),
 VMSTATE_END_OF_LIST()
@@ -551,7 +551,7 @@ static const VMStateDescription vmstate_usb_hub = {
 .name = "usb-hub",
 .version_id = 1,
 .minimum_version_id = 1,
-.fields = (VMStateField []) {
+.fields = (VMStateField[]) {
 VMSTATE_USB_DEVICE(dev, USBHubState),
 VMSTATE_STRUCT_ARRAY(ports, USBHubState, NUM_PORTS, 0,
  vmstate_usb_hub_port, USBHubPort),
diff --git a/hw/usb/dev-storage.c b/hw/usb/dev-storage.c
index 2852669..e919100 100644
--- a/hw/usb/dev-storage.c
+++ b/hw/usb/dev-storage.c
@@ -716,7 +716,7 @@ static const VMStateDescription vmstate_usb_msd = {
 .name = "usb-storage",
 .version_id = 1,
 .minimum_version_id = 1,
-.fields = (VMStateField []) {
+.fields = (VMStateField[]) {
 VMSTATE_USB_DEVICE(dev, MSDState),
 VMSTATE_UINT32(mode, MSDState),
 VMSTATE_UINT32(scsi_len, MSDState),
diff --git a/hw/usb/hcd-ehci-pci.c b/hw/usb/hcd-ehci-pci.c
index 484a9bd..505741a 100644
--- a/hw/usb/hcd-ehci-pci.c
+++ b/hw/usb/hcd-ehci-pci.c
@@ -108,7 +108,7 @@ static const VMStateDescription vmstate_ehci_pci = {
 .name= "ehci",
 .version_id  = 2,
 .minimum_version_id  = 1,
-.fields  = (VMStateField[]) {
+.fields = (VMStateField[]) {
 VMSTATE_PCI_DEVICE(pcidev, EHCIPCIState),
 VMSTATE_STRUCT(ehci, EHCIPCIState, 2, vmstate_ehci, EHCIState),
 VMSTATE_END_OF_LIST()
diff --git a/hw/usb/hcd-ehci-sysbus.c b/hw/usb/hcd-ehci-sysbus.c
index fe6eea5..19ed2c2 100644
--- a/hw/usb/hcd-ehci-sysbus.c
+++ b/hw/usb/hcd-ehci-sysbus.c
@@ -21,7 +21,7 @@ static const VMStateDescription vmstate_ehci_sysbus = {
 .name= "ehci-sysbus",
 .version_id  = 2,
 .minimum_version_id  = 1,
-.fields  = (VMStateField[]) {
+.fields = (VMStateField[]) {
 VMSTATE_STRUCT(ehci, EHCISysBusState, 2, vmstate_ehci, EHCIState),
 VMSTATE_END_OF_LIST()
 }
diff --git a/hw/usb/hcd-ehci.c b/hw/usb/hcd-ehci.c
index 355bbd6..a3ae9f2 100644
--- a/hw/usb/hcd-ehci.c
+++ b/hw/usb/hcd-ehci.c
@@ -2492,7 +2492,7 @@ const VMStateDescription vmstate_ehci = {
 .minimum_version_id  = 1,
 .pre_save= usb_ehci_pre_save,
 .post_load   = usb_ehci_post_load,
-.fields  = (VMStateField[]) {
+.fields = (VMStateField[]) {
 /* mmio registers */
 VMSTATE_UINT32(usbcmd, EHCIState),
 VMSTATE_UINT3

[Qemu-devel] [PATCH 093/124] vmstate: Test for VMSTATE_BUFFER_TEST

2014-04-21 Thread Juan Quintela
Signed-off-by: Juan Quintela 
---
 tests/test-vmstate.c | 36 
 1 file changed, 36 insertions(+)

diff --git a/tests/test-vmstate.c b/tests/test-vmstate.c
index 8b114fa..3c4c0f8 100644
--- a/tests/test-vmstate.c
+++ b/tests/test-vmstate.c
@@ -928,6 +928,41 @@ static void test_buffer_simple(void)
 SUCCESS(memcmp(obj.middle+6, obj_buffer.middle+6, sizeof(obj.middle)-6));
 }

+static const VMStateDescription vmstate_buffer_test = {
+.name = "buffer/test",
+.version_id = 1,
+.minimum_version_id = 1,
+.minimum_version_id_old = 1,
+.fields = (VMStateField[]) {
+VMSTATE_BUFFER_TEST(buffer, TestBuffer, test_true),
+VMSTATE_BUFFER_TEST(partial, TestBuffer, test_false),
+VMSTATE_END_OF_LIST()
+}
+};
+
+uint8_t wire_buffer_test[] = {
+/* buffer */   0x68, 0x65, 0x6c, 0x6c, 0x6f, 0x00,
+QEMU_VM_EOF, /* just to ensure we won't get EOF reported prematurely */
+};
+
+static void test_buffer_test(void)
+{
+TestBuffer obj, obj_clone;
+
+memset(&obj, 0, sizeof(obj));
+
+save_vmstate(&vmstate_buffer_test, &obj_buffer);
+
+compare_vmstate(wire_buffer_test, sizeof(wire_buffer_test));
+
+SUCCESS(load_vmstate(&vmstate_buffer_test, &obj, &obj_clone,
+ obj_buffer_copy, 1, wire_buffer_test,
+ sizeof(wire_buffer_test)));
+
+SUCCESS(memcmp(obj.buffer, obj_buffer.buffer, sizeof(obj.buffer)));
+FAILURE(memcmp(obj.partial, obj_buffer.partial, sizeof(obj.partial)));
+}
+
 typedef struct TestVersioned {
 uint32_t a, b, c, e;
 uint64_t d, f;
@@ -1165,6 +1200,7 @@ int main(int argc, char **argv)
 g_test_add_func("/vmstate/array/test", test_array_test);
 g_test_add_func("/vmstate/array/sub", test_array_sub);
 g_test_add_func("/vmstate/buffer/simple", test_buffer_simple);
+g_test_add_func("/vmstate/buffer/test", test_buffer_test);
 g_test_run();

 close(temp_fd);
-- 
1.9.0




[Qemu-devel] [PATCH 024/124] vmstate: Test for VMSTATE_UINT64_TEST

2014-04-21 Thread Juan Quintela
Remove VMSTATE_UINT64_V, we are removing versioning.
Move all users to VMSTATE_UINT64_TEST.

Signed-off-by: Juan Quintela 
---
 hw/timer/mc146818rtc.c  |  6 +++---
 include/migration/vmstate.h |  9 +++--
 target-i386/machine.c   | 30 +++---
 tests/test-vmstate.c|  8 ++--
 4 files changed, 27 insertions(+), 26 deletions(-)

diff --git a/hw/timer/mc146818rtc.c b/hw/timer/mc146818rtc.c
index 079ae93..8446d48 100644
--- a/hw/timer/mc146818rtc.c
+++ b/hw/timer/mc146818rtc.c
@@ -730,11 +730,11 @@ static const VMStateDescription vmstate_rtc = {
 VMSTATE_UNUSED(3*8),
 VMSTATE_UINT32_TEST(irq_coalesced, RTCState, vmstate_2_plus),
 VMSTATE_UINT32_TEST(period, RTCState, vmstate_2_plus),
-VMSTATE_UINT64_V(base_rtc, RTCState, 3),
-VMSTATE_UINT64_V(last_update, RTCState, 3),
+VMSTATE_UINT64_TEST(base_rtc, RTCState, vmstate_3_plus),
+VMSTATE_UINT64_TEST(last_update, RTCState, vmstate_3_plus),
 VMSTATE_INT64_TEST(offset, RTCState, vmstate_3_plus),
 VMSTATE_TIMER_V(update_timer, RTCState, 3),
-VMSTATE_UINT64_V(next_alarm_time, RTCState, 3),
+VMSTATE_UINT64_TEST(next_alarm_time, RTCState, vmstate_3_plus),
 VMSTATE_END_OF_LIST()
 }
 };
diff --git a/include/migration/vmstate.h b/include/migration/vmstate.h
index aea8d23..0940340 100644
--- a/include/migration/vmstate.h
+++ b/include/migration/vmstate.h
@@ -544,8 +544,8 @@ extern const VMStateInfo vmstate_info_bitmap;
 VMSTATE_SINGLE_TEST(_f, _s, _t, 0, vmstate_info_uint16, uint16_t)
 #define VMSTATE_UINT32_TEST(_f, _s, _t)   \
 VMSTATE_SINGLE_TEST(_f, _s, _t, 0, vmstate_info_uint32, uint32_t)
-#define VMSTATE_UINT64_V(_f, _s, _v)  \
-VMSTATE_SINGLE(_f, _s, _v, vmstate_info_uint64, uint64_t)
+#define VMSTATE_UINT64_TEST(_f, _s, _t)   \
+VMSTATE_SINGLE_TEST(_f, _s, _t, 0, vmstate_info_uint64, uint64_t)

 #define VMSTATE_BOOL(_f, _s)  \
 VMSTATE_BOOL_TEST(_f, _s, NULL)
@@ -566,7 +566,7 @@ extern const VMStateInfo vmstate_info_bitmap;
 #define VMSTATE_UINT32(_f, _s)\
 VMSTATE_UINT32_TEST(_f, _s, NULL)
 #define VMSTATE_UINT64(_f, _s)\
-VMSTATE_UINT64_V(_f, _s, 0)
+VMSTATE_UINT64_TEST(_f, _s, NULL)

 #define VMSTATE_UINT8_EQUAL(_f, _s)   \
 VMSTATE_SINGLE(_f, _s, 0, vmstate_info_uint8_equal, uint8_t)
@@ -595,9 +595,6 @@ extern const VMStateInfo vmstate_info_bitmap;
 #define VMSTATE_INT32_LE(_f, _s)   \
 VMSTATE_SINGLE(_f, _s, 0, vmstate_info_int32_le, int32_t)

-#define VMSTATE_UINT64_TEST(_f, _s, _t)  \
-VMSTATE_SINGLE_TEST(_f, _s, _t, 0, vmstate_info_uint64, uint64_t)
-

 #define VMSTATE_FLOAT64_V(_f, _s, _v) \
 VMSTATE_SINGLE(_f, _s, _v, vmstate_info_float64, float64)
diff --git a/target-i386/machine.c b/target-i386/machine.c
index 42c9de0..d4ffe8e 100644
--- a/target-i386/machine.c
+++ b/target-i386/machine.c
@@ -652,14 +652,14 @@ const VMStateDescription vmstate_x86_cpu = {
 #endif
 VMSTATE_UINT32_TEST(env.smbase, X86CPU, vmstate_4_plus),

-VMSTATE_UINT64_V(env.pat, X86CPU, 5),
+VMSTATE_UINT64_TEST(env.pat, X86CPU, vmstate_5_plus),
 VMSTATE_UINT32_TEST(env.hflags2, X86CPU, vmstate_5_plus),

 VMSTATE_UINT32_TEST(parent_obj.halted, X86CPU, version_is_5),
-VMSTATE_UINT64_V(env.vm_hsave, X86CPU, 5),
-VMSTATE_UINT64_V(env.vm_vmcb, X86CPU, 5),
-VMSTATE_UINT64_V(env.tsc_offset, X86CPU, 5),
-VMSTATE_UINT64_V(env.intercept, X86CPU, 5),
+VMSTATE_UINT64_TEST(env.vm_hsave, X86CPU, vmstate_5_plus),
+VMSTATE_UINT64_TEST(env.vm_vmcb, X86CPU, vmstate_5_plus),
+VMSTATE_UINT64_TEST(env.tsc_offset, X86CPU, vmstate_5_plus),
+VMSTATE_UINT64_TEST(env.intercept, X86CPU, vmstate_5_plus),
 VMSTATE_UINT16_TEST(env.intercept_cr_read, X86CPU, vmstate_5_plus),
 VMSTATE_UINT16_TEST(env.intercept_cr_write, X86CPU, vmstate_5_plus),
 VMSTATE_UINT16_TEST(env.intercept_dr_read, X86CPU, vmstate_5_plus),
@@ -668,12 +668,12 @@ const VMStateDescription vmstate_x86_cpu = {
 VMSTATE_UINT8_TEST(env.v_tpr, X86CPU, vmstate_5_plus),
 /* MTRRs */
 VMSTATE_UINT64_ARRAY_V(env.mtrr_fixed, X86CPU, 11, 8),
-VMSTATE_UINT64_V(env.mtrr_deftype, X86CPU, 8),
+VMSTATE_UINT64_TEST(env.mtrr_deftype, X86CPU, vmstate_8_plus),
 VMSTATE_MTRR_VARS(env.mtrr_var, X86CPU, 8, 8),
 /* KVM-related states */
 VMSTATE_INT32_TEST(env.interrupt_injected, X86CPU, vmstate_9_plus),
 VMSTATE_UINT32_TEST(env.mp_state, X86CPU, vmstate_9_plus),
-VMSTATE_UINT64_V(env.tsc, X86CPU, 9),
+VMSTATE_UINT64_TEST(env.tsc, X86CPU, vm

[Qemu-devel] [PATCH 076/124] vmstate: Remove unused version parameter from VMSTATE_STRUCT_VARRAY_UINT8

2014-04-21 Thread Juan Quintela
Signed-off-by: Juan Quintela 
---
 hw/timer/hpet.c | 2 +-
 include/migration/vmstate.h | 3 +--
 2 files changed, 2 insertions(+), 3 deletions(-)

diff --git a/hw/timer/hpet.c b/hw/timer/hpet.c
index 2148568..0fd2eb0 100644
--- a/hw/timer/hpet.c
+++ b/hw/timer/hpet.c
@@ -304,7 +304,7 @@ static const VMStateDescription vmstate_hpet = {
 VMSTATE_UINT64(isr, HPETState),
 VMSTATE_UINT64(hpet_counter, HPETState),
 VMSTATE_UINT8_TEST(num_timers, HPETState, vmstate_2_plus),
-VMSTATE_STRUCT_VARRAY_UINT8(timer, HPETState, num_timers, 0,
+VMSTATE_STRUCT_VARRAY_UINT8(timer, HPETState, num_timers,
 vmstate_hpet_timer, HPETTimer),
 VMSTATE_END_OF_LIST()
 },
diff --git a/include/migration/vmstate.h b/include/migration/vmstate.h
index 68565ce..be80717 100644
--- a/include/migration/vmstate.h
+++ b/include/migration/vmstate.h
@@ -323,10 +323,9 @@ extern const VMStateInfo vmstate_info_bitmap;
 .offset   = vmstate_offset_array(_state, _field, _type, _num),\
 }

-#define VMSTATE_STRUCT_VARRAY_UINT8(_field, _state, _field_num, _version, 
_vmsd, _type) { \
+#define VMSTATE_STRUCT_VARRAY_UINT8(_field, _state, _field_num, _vmsd, _type) 
{ \
 .name   = (stringify(_field)),   \
 .num_offset = vmstate_offset_value(_state, _field_num, uint8_t), \
-.version_id = (_version),\
 .vmsd   = &(_vmsd),  \
 .size   = sizeof(_type), \
 .flags  = VMS_STRUCT|VMS_VARRAY_UINT8,   \
-- 
1.9.0




[Qemu-devel] [PATCH 075/124] vmstate: Remove unused version parameter from VMSTATE_STRUCT_VARRAY_INT32

2014-04-21 Thread Juan Quintela
Signed-off-by: Juan Quintela 
---
 hw/input/stellaris_input.c  | 2 +-
 include/migration/vmstate.h | 3 +--
 2 files changed, 2 insertions(+), 3 deletions(-)

diff --git a/hw/input/stellaris_input.c b/hw/input/stellaris_input.c
index 0609e80..07e7856 100644
--- a/hw/input/stellaris_input.c
+++ b/hw/input/stellaris_input.c
@@ -63,7 +63,7 @@ static const VMStateDescription vmstate_stellaris_gamepad = {
 .minimum_version_id = 1,
 .fields = (VMStateField[]) {
 VMSTATE_INT32(extension, gamepad_state),
-VMSTATE_STRUCT_VARRAY_INT32(buttons, gamepad_state, num_buttons, 0,
+VMSTATE_STRUCT_VARRAY_INT32(buttons, gamepad_state, num_buttons,
   vmstate_stellaris_button, gamepad_button),
 VMSTATE_END_OF_LIST()
 }
diff --git a/include/migration/vmstate.h b/include/migration/vmstate.h
index 46d46fb..68565ce 100644
--- a/include/migration/vmstate.h
+++ b/include/migration/vmstate.h
@@ -360,10 +360,9 @@ extern const VMStateInfo vmstate_info_bitmap;
 .offset = vmstate_offset_pointer(_state, _field, _type), \
 }

-#define VMSTATE_STRUCT_VARRAY_INT32(_field, _state, _field_num, _version, 
_vmsd, _type) { \
+#define VMSTATE_STRUCT_VARRAY_INT32(_field, _state, _field_num, _vmsd, _type) 
{ \
 .name   = (stringify(_field)),   \
 .num_offset = vmstate_offset_value(_state, _field_num, int32_t), \
-.version_id = (_version),\
 .vmsd   = &(_vmsd),  \
 .size   = sizeof(_type), \
 .flags  = VMS_STRUCT|VMS_VARRAY_INT32,   \
-- 
1.9.0




[Qemu-devel] [PATCH 096/124] vmstate: Remove unused VMSTATE_SUB_VBUFFER

2014-04-21 Thread Juan Quintela
Signed-off-by: Juan Quintela 
---
 include/migration/vmstate.h | 3 ---
 1 file changed, 3 deletions(-)

diff --git a/include/migration/vmstate.h b/include/migration/vmstate.h
index b363eca..98c5602 100644
--- a/include/migration/vmstate.h
+++ b/include/migration/vmstate.h
@@ -644,9 +644,6 @@ extern const VMStateInfo vmstate_info_bitmap;
 #define VMSTATE_PARTIAL_VBUFFER_UINT32(_f, _s, _size)\
 VMSTATE_VBUFFER_UINT32(_f, _s, _size)

-#define VMSTATE_SUB_VBUFFER(_f, _s, _start, _size)\
-VMSTATE_VBUFFER(_f, _s, NULL, _start, _size)
-
 #define VMSTATE_BUFFER_TEST(_f, _s, _test)\
 VMSTATE_STATIC_BUFFER(_f, _s, _test, 0, sizeof(typeof_field(_s, _f)))

-- 
1.9.0




[Qemu-devel] [PATCH 087/124] vmstate: Test for VMSTATE_SYNTHETIC

2014-04-21 Thread Juan Quintela
Signed-off-by: Juan Quintela 
---
 tests/test-vmstate.c | 24 
 1 file changed, 24 insertions(+)

diff --git a/tests/test-vmstate.c b/tests/test-vmstate.c
index a56c5cc..308f94d 100644
--- a/tests/test-vmstate.c
+++ b/tests/test-vmstate.c
@@ -187,6 +187,28 @@ TestSimple obj_simple = {
 .f64 = float64_pi,
 };

+static int get_42_as_uint32(QEMUFile *f, void *pv, size_t size)
+{
+uint64_t v;
+v = qemu_get_be32(f);
+if (v != 42) {
+return -1;
+}
+return 0;
+}
+
+static void put_42_as_uint32(QEMUFile *f, void *pv, size_t size)
+{
+uint64_t v = 42;
+qemu_put_be32(f, v);
+}
+
+static const VMStateInfo vmstate_42_as_uint32 = {
+.name = "42_as_uint32",
+.get  = get_42_as_uint32,
+.put  = put_42_as_uint32,
+};
+
 /* Description of the values.  If you add a primitive type
you are expected to add a test here */

@@ -211,6 +233,7 @@ static const VMStateDescription vmstate_simple_primitive = {
 VMSTATE_INT64(i64_2, TestSimple),
 VMSTATE_FLOAT64(f64, TestSimple),
 VMSTATE_UNUSED(5),
+VMSTATE_SYNTHETIC("synthetic", vmstate_42_as_uint32, sizeof(uint32)),
 VMSTATE_END_OF_LIST()
 }
 };
@@ -244,6 +267,7 @@ uint8_t wire_simple_primitive[] = {
 /* i64_2 */ 0xff, 0xff, 0xff, 0xff, 0xff, 0x47, 0x0b, 0x84,
 /* f64 */   0x40, 0x09, 0x21, 0xfb, 0x54, 0x44, 0x2d, 0x18,
 /* unused */0x00, 0x00, 0x00, 0x00, 0x00,
+/* synthe */0x00, 0x00, 0x00, 0x2a,
 QEMU_VM_EOF, /* just to ensure we won't get EOF reported prematurely */
 };

-- 
1.9.0




[Qemu-devel] [PATCH 077/124] vmstate: Introduce VMSTATE_VARRAY_UINT32_TEST

2014-04-21 Thread Juan Quintela
Use it on the only case were a version was used.

Signed-off-by: Juan Quintela 
---
 hw/misc/arm_sysctl.c| 5 +++--
 include/migration/vmstate.h | 7 +--
 2 files changed, 8 insertions(+), 4 deletions(-)

diff --git a/hw/misc/arm_sysctl.c b/hw/misc/arm_sysctl.c
index 0f61241..668681f 100644
--- a/hw/misc/arm_sysctl.c
+++ b/hw/misc/arm_sysctl.c
@@ -67,8 +67,9 @@ static const VMStateDescription vmstate_arm_sysctl = {
 VMSTATE_UINT32_TEST(sys_clcd, arm_sysctl_state, vmstate_3_plus),
 VMSTATE_UINT32_ARRAY_TEST(mb_clock, arm_sysctl_state, 6,
   vmstate_4_plus),
-VMSTATE_VARRAY_UINT32(db_clock, arm_sysctl_state, db_num_clocks,
-  4, vmstate_info_uint32, uint32_t),
+VMSTATE_VARRAY_UINT32_TEST(db_clock, arm_sysctl_state, db_num_clocks,
+   vmstate_4_plus, vmstate_info_uint32,
+   uint32_t),
 VMSTATE_END_OF_LIST()
 }
 };
diff --git a/include/migration/vmstate.h b/include/migration/vmstate.h
index be80717..e1c9680 100644
--- a/include/migration/vmstate.h
+++ b/include/migration/vmstate.h
@@ -257,9 +257,9 @@ extern const VMStateInfo vmstate_info_bitmap;
 .offset = vmstate_offset_pointer(_state, _field, _type), \
 }

-#define VMSTATE_VARRAY_UINT32(_field, _state, _field_num, _version, _info, 
_type) {\
+#define VMSTATE_VARRAY_UINT32_TEST(_field, _state, _field_num, _test, _info, 
_type) {\
 .name   = (stringify(_field)),   \
-.version_id = (_version),\
+.field_exists = (_test), \
 .num_offset = vmstate_offset_value(_state, _field_num, uint32_t),\
 .info   = &(_info),  \
 .size   = sizeof(_type), \
@@ -611,6 +611,9 @@ extern const VMStateInfo vmstate_info_bitmap;
 #define VMSTATE_UNUSED(_size) \
 VMSTATE_UNUSED_TEST(NULL, _size)

+#define VMSTATE_VARRAY_UINT32(_field, _state, _field_num, _version, _info, 
_type) \
+VMSTATE_VARRAY_UINT32_TEST(_field, _state, _field_num, NULL, _info, _type)
+
 #define VMSTATE_END_OF_LIST() \
 {}

-- 
1.9.0




[Qemu-devel] [PATCH 097/124] vmstate: Remove unused VMSTATE_PARTIAL_VBUFFER_UINT32

2014-04-21 Thread Juan Quintela
Signed-off-by: Juan Quintela 
---
 include/migration/vmstate.h | 3 ---
 1 file changed, 3 deletions(-)

diff --git a/include/migration/vmstate.h b/include/migration/vmstate.h
index 98c5602..7117239 100644
--- a/include/migration/vmstate.h
+++ b/include/migration/vmstate.h
@@ -641,9 +641,6 @@ extern const VMStateInfo vmstate_info_bitmap;
 #define VMSTATE_PARTIAL_VBUFFER(_f, _s, _size)\
 VMSTATE_VBUFFER(_f, _s, NULL, 0, _size)

-#define VMSTATE_PARTIAL_VBUFFER_UINT32(_f, _s, _size)\
-VMSTATE_VBUFFER_UINT32(_f, _s, _size)
-
 #define VMSTATE_BUFFER_TEST(_f, _s, _test)\
 VMSTATE_STATIC_BUFFER(_f, _s, _test, 0, sizeof(typeof_field(_s, _f)))

-- 
1.9.0




[Qemu-devel] [PATCH 090/124] vmstate: Test for VMSTATE_BUFFER

2014-04-21 Thread Juan Quintela
Signed-off-by: Juan Quintela 
---
 tests/test-vmstate.c | 50 ++
 1 file changed, 50 insertions(+)

diff --git a/tests/test-vmstate.c b/tests/test-vmstate.c
index 8b45ea5..cea5984 100644
--- a/tests/test-vmstate.c
+++ b/tests/test-vmstate.c
@@ -865,6 +865,55 @@ static void test_array_sub(void)
 #undef ELEM_EQUAL_2D
 #undef ELEM_NOT_EQUAL

+typedef struct TestBuffer {
+uint8_t  buffer[6];
+} TestBuffer;
+
+TestBuffer obj_buffer = {
+.buffer = "hello",
+};
+
+static const VMStateDescription vmstate_buffer_simple = {
+.name = "buffer/simple",
+.version_id = 1,
+.minimum_version_id = 1,
+.minimum_version_id_old = 1,
+.fields = (VMStateField[]) {
+VMSTATE_BUFFER(buffer, TestBuffer),
+VMSTATE_END_OF_LIST()
+}
+};
+
+uint8_t wire_buffer_simple[] = {
+/* buffer */   0x68, 0x65, 0x6c, 0x6c, 0x6f, 0x00,
+QEMU_VM_EOF, /* just to ensure we won't get EOF reported prematurely */
+};
+
+static void obj_buffer_copy(void *arg1, void *arg2)
+{
+TestBuffer *target = arg1;
+TestBuffer *source = arg2;
+
+memcpy(target->buffer, source->buffer, 6);
+}
+
+static void test_buffer_simple(void)
+{
+TestBuffer obj, obj_clone;
+
+memset(&obj, 0, sizeof(obj));
+
+save_vmstate(&vmstate_buffer_simple, &obj_buffer);
+
+compare_vmstate(wire_buffer_simple, sizeof(wire_buffer_simple));
+
+SUCCESS(load_vmstate(&vmstate_buffer_simple, &obj, &obj_clone,
+ obj_buffer_copy, 1, wire_buffer_simple,
+ sizeof(wire_buffer_simple)));
+
+SUCCESS(memcmp(obj.buffer, obj_buffer.buffer, sizeof(obj.buffer)));
+}
+
 typedef struct TestVersioned {
 uint32_t a, b, c, e;
 uint64_t d, f;
@@ -1101,6 +1150,7 @@ int main(int argc, char **argv)
 g_test_add_func("/vmstate/array/primitive", test_array_primitive);
 g_test_add_func("/vmstate/array/test", test_array_test);
 g_test_add_func("/vmstate/array/sub", test_array_sub);
+g_test_add_func("/vmstate/buffer/simple", test_buffer_simple);
 g_test_run();

 close(temp_fd);
-- 
1.9.0




[Qemu-devel] [PATCH 082/124] vmstate: Create VMSTATE_VARRAY macro

2014-04-21 Thread Juan Quintela
Use it instead of hard-ecoding it on ich9 for GPE.

Signed-off-by: Juan Quintela 
---
 hw/acpi/ich9.c  | 11 ++-
 include/migration/vmstate.h | 10 ++
 2 files changed, 12 insertions(+), 9 deletions(-)

diff --git a/hw/acpi/ich9.c b/hw/acpi/ich9.c
index 407ae89..f4801d1 100644
--- a/hw/acpi/ich9.c
+++ b/hw/acpi/ich9.c
@@ -129,15 +129,8 @@ static int ich9_pm_post_load(void *opaque, int version_id)
 }

 #define VMSTATE_GPE_ARRAY(_field, _state)\
- {   \
- .name   = (stringify(_field)),  \
- .version_id = 0,\
- .num= ICH9_PMIO_GPE0_LEN,   \
- .info   = &vmstate_info_uint8,  \
- .size   = sizeof(uint8_t),  \
- .flags  = VMS_ARRAY | VMS_POINTER,  \
- .offset = vmstate_offset_pointer(_state, _field, uint8_t),  \
- }
+VMSTATE_VARRAY(_field, _state, ICH9_PMIO_GPE0_LEN, NULL, \
+   vmstate_info_uint8, uint8)

 const VMStateDescription vmstate_ich9_pm = {
 .name = "ich9_pm",
diff --git a/include/migration/vmstate.h b/include/migration/vmstate.h
index 81268c6..8de6988 100644
--- a/include/migration/vmstate.h
+++ b/include/migration/vmstate.h
@@ -230,6 +230,16 @@ extern const VMStateInfo vmstate_info_bitmap;
 .offset   = vmstate_offset_array(_state, _field, _type, _num),\
 }

+#define VMSTATE_VARRAY(_field, _state, _num, _test, _info, _type) {   \
+.name = (stringify(_field)),  \
+.field_exists = (_test),  \
+.num  = (_num),   \
+.info = &(_info), \
+.size = sizeof(_type),\
+.flags= VMS_ARRAY | VMS_POINTER,  \
+.offset   = vmstate_offset_pointer(_state, _field, _type),\
+}
+
 #define VMSTATE_SUB_ARRAY(_field, _state, _start, _num, _info, _type) { \
 .name   = (stringify(_field)),   \
 .num= (_num),\
-- 
1.9.0




[Qemu-devel] [PATCH 104/124] vmstate: Test for VMSTATE_POINTER

2014-04-21 Thread Juan Quintela
Signed-off-by: Juan Quintela 
---
 tests/test-vmstate.c | 61 
 1 file changed, 61 insertions(+)

diff --git a/tests/test-vmstate.c b/tests/test-vmstate.c
index 79bdf9d..c284bfc 100644
--- a/tests/test-vmstate.c
+++ b/tests/test-vmstate.c
@@ -1057,6 +1057,66 @@ static void test_vbuffer_simple(void)
 SUCCESS(memcmp(obj->buffer2, obj_vbuffer->buffer2, VMSTATE_ARRAY_SIZE));
 }

+typedef struct TestPointer {
+uint8_t  *u8_1p;
+} TestPointer;
+
+static const VMStateDescription vmstate_pointer_simple = {
+.name = "pointer/simple",
+.version_id = 1,
+.minimum_version_id = 1,
+.minimum_version_id_old = 1,
+.fields = (VMStateField[]) {
+VMSTATE_POINTER(u8_1p, TestPointer, NULL, vmstate_info_uint8, uint8_t),
+VMSTATE_END_OF_LIST()
+}
+};
+
+uint8_t wire_pointer_simple[] = {
+/* u8_1p */   0x11,
+QEMU_VM_EOF, /* just to ensure we won't get EOF reported prematurely */
+};
+
+static void obj_pointer_copy(void *arg1, void *arg2)
+{
+TestPointer *target = arg1;
+TestPointer *source = arg2;
+
+*target->u8_1p = *source->u8_1p;
+}
+
+static TestPointer *create_pointer(void)
+{
+TestPointer *obj = g_malloc0(sizeof(*obj));
+obj->u8_1p = g_malloc0(sizeof(*obj->u8_1p));
+
+return obj;
+}
+
+static void test_pointer_simple(void)
+{
+TestPointer *obj, *obj_clone, *obj_pointer;
+
+obj_pointer = create_pointer();
+obj = create_pointer();
+obj_clone = create_pointer();
+
+*obj_pointer->u8_1p = 17;
+*obj->u8_1p = 22;
+
+save_vmstate(&vmstate_pointer_simple, obj_pointer);
+
+compare_vmstate(wire_pointer_simple, sizeof(wire_pointer_simple));
+
+SUCCESS(load_vmstate(&vmstate_pointer_simple, obj, obj_clone,
+ obj_pointer_copy, 1, wire_pointer_simple,
+ sizeof(wire_pointer_simple)));
+
+#define FIELD_EQUAL(name)   g_assert_cmpint(*obj->name, ==, *obj_pointer->name)
+FIELD_EQUAL(u8_1p);
+}
+#undef FIELD_EQUAL
+
 typedef struct TestVersioned {
 uint32_t a, b, c, e;
 uint64_t d, f;
@@ -1296,6 +1356,7 @@ int main(int argc, char **argv)
 g_test_add_func("/vmstate/buffer/simple", test_buffer_simple);
 g_test_add_func("/vmstate/buffer/test", test_buffer_test);
 g_test_add_func("/vmstate/vbuffer/simple", test_vbuffer_simple);
+g_test_add_func("/vmstate/pointer/simple", test_pointer_simple);
 g_test_run();

 close(temp_fd);
-- 
1.9.0




[Qemu-devel] [PATCH 101/124] vmstate: Rename VMS_VBUFFER to VMST_VBUFFER_INT32 for consintency

2014-04-21 Thread Juan Quintela
Signed-off-by: Juan Quintela 
---
 include/migration/vmstate.h | 6 +++---
 vmstate.c   | 2 +-
 2 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/include/migration/vmstate.h b/include/migration/vmstate.h
index a2d1aae..cf27366 100644
--- a/include/migration/vmstate.h
+++ b/include/migration/vmstate.h
@@ -96,7 +96,7 @@ enum VMStateFlags {
 VMS_BUFFER   = 0x020,  /* static sized buffer */
 VMS_ARRAY_OF_POINTER = 0x040,
 VMS_VARRAY_UINT16= 0x080,  /* Array with size in uint16_t field */
-VMS_VBUFFER  = 0x100,  /* Buffer with size in int32_t field */
+VMS_VBUFFER_INT32= 0x100,  /* Buffer with size in int32_t field */
 VMS_VBUFFER_UINT32   = 0x200,  /* Buffer with size in uint32_t field */
 VMS_VARRAY_UINT8 = 0x400,  /* Array with size in uint8_t field*/
 VMS_VARRAY_UINT32= 0x800,  /* Array with size in uint32_t field*/
@@ -436,7 +436,7 @@ extern const VMStateInfo vmstate_info_bitmap;
 .name = (stringify(_field)), \
 .size_offset  = vmstate_offset_value(_state, _field_size, int32_t),\
 .info = &vmstate_info_buffer,\
-.flags= VMS_VBUFFER|VMS_POINTER, \
+.flags= VMS_VBUFFER_INT32|VMS_POINTER,   \
 .offset   = offsetof(_state, _field),\
 }

@@ -480,7 +480,7 @@ extern const VMStateInfo vmstate_info_bitmap;
 .name = (stringify(_field)), \
 .size_offset  = vmstate_offset_value(_state, _field_size, int32_t),\
 .info = &vmstate_info_bitmap,\
-.flags= VMS_VBUFFER|VMS_POINTER, \
+.flags= VMS_VBUFFER_INT32|VMS_POINTER,   \
 .offset   = offsetof(_state, _field),\
 }

diff --git a/vmstate.c b/vmstate.c
index c2e79b9..8f28518 100644
--- a/vmstate.c
+++ b/vmstate.c
@@ -33,7 +33,7 @@ static int vmstate_size(void *opaque, VMStateField *field)
 {
 int size = field->size;

-if (field->flags & VMS_VBUFFER) {
+if (field->flags & VMS_VBUFFER_INT32) {
 size = *(int32_t *)(opaque+field->size_offset);
 } else if (field->flags & VMS_VBUFFER_UINT32) {
 size = *(uint32_t *)(opaque+field->size_offset);
-- 
1.9.0




[Qemu-devel] [PATCH 091/124] vmstate: Test for VMSTATE_PARTIAL_BUFFER

2014-04-21 Thread Juan Quintela
Signed-off-by: Juan Quintela 
---
 tests/test-vmstate.c | 7 +++
 1 file changed, 7 insertions(+)

diff --git a/tests/test-vmstate.c b/tests/test-vmstate.c
index cea5984..ddfa017 100644
--- a/tests/test-vmstate.c
+++ b/tests/test-vmstate.c
@@ -867,10 +867,12 @@ static void test_array_sub(void)

 typedef struct TestBuffer {
 uint8_t  buffer[6];
+uint8_t  partial[13];
 } TestBuffer;

 TestBuffer obj_buffer = {
 .buffer = "hello",
+.partial = "This is Juan",
 };

 static const VMStateDescription vmstate_buffer_simple = {
@@ -880,12 +882,14 @@ static const VMStateDescription vmstate_buffer_simple = {
 .minimum_version_id_old = 1,
 .fields = (VMStateField[]) {
 VMSTATE_BUFFER(buffer, TestBuffer),
+VMSTATE_PARTIAL_BUFFER(partial, TestBuffer, 4),
 VMSTATE_END_OF_LIST()
 }
 };

 uint8_t wire_buffer_simple[] = {
 /* buffer */   0x68, 0x65, 0x6c, 0x6c, 0x6f, 0x00,
+/* partial */  0x54, 0x68, 0x69, 0x73,
 QEMU_VM_EOF, /* just to ensure we won't get EOF reported prematurely */
 };

@@ -895,6 +899,7 @@ static void obj_buffer_copy(void *arg1, void *arg2)
 TestBuffer *source = arg2;

 memcpy(target->buffer, source->buffer, 6);
+memcpy(target->partial, source->partial, 13);
 }

 static void test_buffer_simple(void)
@@ -912,6 +917,8 @@ static void test_buffer_simple(void)
  sizeof(wire_buffer_simple)));

 SUCCESS(memcmp(obj.buffer, obj_buffer.buffer, sizeof(obj.buffer)));
+SUCCESS(memcmp(obj.partial, obj_buffer.partial, 4));
+FAILURE(memcmp(obj.partial+4, obj_buffer.partial+4, 
sizeof(obj.partial)-4));
 }

 typedef struct TestVersioned {
-- 
1.9.0




[Qemu-devel] [PATCH 102/124] vmstate: Test for VMSTATE_VBUFFER_UINT32

2014-04-21 Thread Juan Quintela
Signed-off-by: Juan Quintela 
---
 tests/test-vmstate.c | 12 
 1 file changed, 12 insertions(+)

diff --git a/tests/test-vmstate.c b/tests/test-vmstate.c
index ae27679..79bdf9d 100644
--- a/tests/test-vmstate.c
+++ b/tests/test-vmstate.c
@@ -974,6 +974,8 @@ static void test_buffer_test(void)
 typedef struct TestVBuffer {
 int32_t size;
 uint8_t  *buffer;
+uint32_t size2;
+uint8_t  *buffer2;
 } TestVBuffer;

 static const VMStateDescription vmstate_vbuffer_simple = {
@@ -983,14 +985,18 @@ static const VMStateDescription vmstate_vbuffer_simple = {
 .minimum_version_id_old = 1,
 .fields = (VMStateField[]) {
 VMSTATE_INT32_EQUAL(size, TestVBuffer),
+VMSTATE_UINT32_EQUAL(size2, TestVBuffer),
 VMSTATE_VBUFFER_INT32(buffer, TestVBuffer, size),
+VMSTATE_VBUFFER_UINT32(buffer2, TestVBuffer, size2),
 VMSTATE_END_OF_LIST()
 }
 };

 uint8_t wire_vbuffer_simple[] = {
 /* size */0x00, 0x00, 0x00, 0x05,
+/* size2 */   0x00, 0x00, 0x00, 0x05,
 /* buffer */  0x01, 0x02, 0x03, 0x04, 0x05,
+/* buffer2 */ 0x06, 0x07, 0x08, 0x09, 0x0a,
 QEMU_VM_EOF, /* just to ensure we won't get EOF reported prematurely */
 };

@@ -1001,8 +1007,10 @@ static void obj_vbuffer_copy(void *arg1, void *arg2)
 int i;

 target->size = source->size;
+target->size2 = source->size2;
 for (i = 0; i < VMSTATE_ARRAY_SIZE; i++) {
 target->buffer[i] = source->buffer[i];
+target->buffer2[i] = source->buffer2[i];
 }
 }

@@ -1011,6 +1019,8 @@ static TestVBuffer *create_vbuffer(void)
 TestVBuffer *obj = g_malloc0(sizeof(*obj));
 obj->size = VMSTATE_ARRAY_SIZE;
 obj->buffer = g_malloc0(VMSTATE_ARRAY_SIZE);
+obj->size2 = VMSTATE_ARRAY_SIZE;
+obj->buffer2 = g_malloc0(VMSTATE_ARRAY_SIZE);

 return obj;
 }
@@ -1022,6 +1032,7 @@ static TestVBuffer *create_vbuffer_init(void)

 for (i = 0; i < VMSTATE_ARRAY_SIZE; i++) {
 obj->buffer[i] = i + 1;
+obj->buffer2[i] = i + 6;
 }
 return obj;
 }
@@ -1043,6 +1054,7 @@ static void test_vbuffer_simple(void)
  sizeof(wire_vbuffer_simple)));

 SUCCESS(memcmp(obj->buffer, obj_vbuffer->buffer, VMSTATE_ARRAY_SIZE));
+SUCCESS(memcmp(obj->buffer2, obj_vbuffer->buffer2, VMSTATE_ARRAY_SIZE));
 }

 typedef struct TestVersioned {
-- 
1.9.0




[Qemu-devel] [PATCH 098/124] vmstate: Test for VMSTATE_PARTIAL_VBUFFER

2014-04-21 Thread Juan Quintela
Signed-off-by: Juan Quintela 
---
 tests/test-vmstate.c | 75 
 1 file changed, 75 insertions(+)

diff --git a/tests/test-vmstate.c b/tests/test-vmstate.c
index c16b0f0..31acb15 100644
--- a/tests/test-vmstate.c
+++ b/tests/test-vmstate.c
@@ -971,6 +971,80 @@ static void test_buffer_test(void)
 FAILURE(memcmp(obj.partial, obj_buffer.partial, sizeof(obj.partial)));
 }

+typedef struct TestVBuffer {
+int32_t size;
+uint8_t  *buffer;
+} TestVBuffer;
+
+static const VMStateDescription vmstate_vbuffer_simple = {
+.name = "vbuffer/simple",
+.version_id = 1,
+.minimum_version_id = 1,
+.minimum_version_id_old = 1,
+.fields = (VMStateField[]) {
+VMSTATE_INT32_EQUAL(size, TestVBuffer),
+VMSTATE_PARTIAL_VBUFFER(buffer, TestVBuffer, size),
+VMSTATE_END_OF_LIST()
+}
+};
+
+uint8_t wire_vbuffer_simple[] = {
+/* size */0x00, 0x00, 0x00, 0x05,
+/* buffer */  0x01, 0x02, 0x03, 0x04, 0x05,
+QEMU_VM_EOF, /* just to ensure we won't get EOF reported prematurely */
+};
+
+static void obj_vbuffer_copy(void *arg1, void *arg2)
+{
+TestVBuffer *target = arg1;
+TestVBuffer *source = arg2;
+int i;
+
+target->size = source->size;
+for (i = 0; i < VMSTATE_ARRAY_SIZE; i++) {
+target->buffer[i] = source->buffer[i];
+}
+}
+
+static TestVBuffer *create_vbuffer(void)
+{
+TestVBuffer *obj = g_malloc0(sizeof(*obj));
+obj->size = VMSTATE_ARRAY_SIZE;
+obj->buffer = g_malloc0(VMSTATE_ARRAY_SIZE);
+
+return obj;
+}
+
+static TestVBuffer *create_vbuffer_init(void)
+{
+TestVBuffer *obj = create_vbuffer();
+int i;
+
+for (i = 0; i < VMSTATE_ARRAY_SIZE; i++) {
+obj->buffer[i] = i + 1;
+}
+return obj;
+}
+
+static void test_vbuffer_simple(void)
+{
+TestVBuffer *obj, *obj_clone, *obj_vbuffer;
+
+obj_vbuffer = create_vbuffer_init();
+obj = create_vbuffer();
+obj_clone = create_vbuffer();
+
+save_vmstate(&vmstate_vbuffer_simple, obj_vbuffer);
+
+compare_vmstate(wire_vbuffer_simple, sizeof(wire_vbuffer_simple));
+
+SUCCESS(load_vmstate(&vmstate_vbuffer_simple, obj, obj_clone,
+ obj_vbuffer_copy, 1, wire_vbuffer_simple,
+ sizeof(wire_vbuffer_simple)));
+
+SUCCESS(memcmp(obj->buffer, obj_vbuffer->buffer, VMSTATE_ARRAY_SIZE));
+}
+
 typedef struct TestVersioned {
 uint32_t a, b, c, e;
 uint64_t d, f;
@@ -1209,6 +1283,7 @@ int main(int argc, char **argv)
 g_test_add_func("/vmstate/array/sub", test_array_sub);
 g_test_add_func("/vmstate/buffer/simple", test_buffer_simple);
 g_test_add_func("/vmstate/buffer/test", test_buffer_test);
+g_test_add_func("/vmstate/vbuffer/simple", test_vbuffer_simple);
 g_test_run();

 close(temp_fd);
-- 
1.9.0




[Qemu-devel] [PATCH 108/124] vmstate: Test for VMSTATE_ARRAY_INT32_UNSAFE

2014-04-21 Thread Juan Quintela
Signed-off-by: Juan Quintela 
---
 tests/test-vmstate.c | 19 +++
 1 file changed, 19 insertions(+)

diff --git a/tests/test-vmstate.c b/tests/test-vmstate.c
index a8a1dfe..f7fd3e2 100644
--- a/tests/test-vmstate.c
+++ b/tests/test-vmstate.c
@@ -535,11 +535,13 @@ static void test_simple_bitmap(void)

 typedef struct TestArray {
 int32_t  size;
+int32_t  size2;
 bool b_1[VMSTATE_ARRAY_SIZE];
 bool b_2[VMSTATE_ARRAY_SIZE];
 uint8_t  u8_1[VMSTATE_ARRAY_SIZE];
 uint8_t  u8_2[VMSTATE_ARRAY_SIZE];
 uint16_t u16_1[VMSTATE_ARRAY_SIZE];
+uint16_t u16_2[VMSTATE_ARRAY_SIZE];
 uint32_t u32_1[VMSTATE_ARRAY_SIZE];
 uint32_t u32_2[VMSTATE_ARRAY_SIZE];
 uint64_t u64_1[VMSTATE_ARRAY_SIZE];
@@ -556,11 +558,13 @@ typedef struct TestArray {

 TestArray obj_array = {
 .size = VMSTATE_ARRAY_SIZE,
+.size2 = VMSTATE_ARRAY_SIZE - 1,
 .b_1 = { false, true, false, true, false},
 .b_2 = { true, false, true, false, true},
 .u8_1 = { 1, 2, 3, 4, 5},
 .u8_2 = { 5, 4, 3, 2, 1},
 .u16_1 = {11, 12, 13, 14, 15},
+.u16_2 = {11, 12, 13, 14, 15},
 .u32_1 = {21, 22, 23, 24, 25},
 .u32_2 = {25, 24, 23, 22, 21},
 .u64_1 = {31, 32, 33, 34, 35},
@@ -604,6 +608,9 @@ static const VMStateDescription vmstate_array_primitive = {
VMSTATE_2D_SIZE),
 VMSTATE_UINT32_2DARRAY(u32_1d, TestArray, VMSTATE_2D_SIZE,
VMSTATE_2D_SIZE),
+VMSTATE_INT32_EQUAL(size2, TestArray),
+VMSTATE_ARRAY_INT32_UNSAFE(u16_2, TestArray, size2,
+   vmstate_info_uint16, uint16_t),
 VMSTATE_END_OF_LIST()
 }
 };
@@ -650,6 +657,8 @@ uint8_t wire_array_primitive[] = {
 0x00, 0x00, 0x00, 0x61,
 0x00, 0x00, 0x00, 0x62,
 0x00, 0x00, 0x00, 0x63,
+/* size2 */ 0x00, 0x00, 0x00, 0x04,
+/* u16_2 */ 0x00, 0x0b, 0x00, 0x0c, 0x00, 0x0d, 0x00, 0x0e,
 QEMU_VM_EOF, /* just to ensure we won't get EOF reported prematurely */
 };

@@ -660,6 +669,7 @@ static void obj_array_copy(void *arg1, void *arg2)
 int i, j;

 target->size = source->size;
+target->size2 = source->size2;

 for (i = 0; i < VMSTATE_ARRAY_SIZE; i++) {
 target->b_1[i] = source->b_1[i];
@@ -667,6 +677,7 @@ static void obj_array_copy(void *arg1, void *arg2)
 target->u8_1[i] = source->u8_1[i];
 target->u8_2[i] = source->u8_2[i];
 target->u16_1[i] = source->u16_1[i];
+target->u16_2[i] = source->u16_2[i];
 target->u32_1[i] = source->u32_1[i];
 target->u32_2[i] = source->u32_2[i];
 target->u64_1[i] = source->u64_1[i];
@@ -694,6 +705,7 @@ static void test_array_primitive(void)

 memset(&obj, 0, sizeof(obj));
 obj.size = VMSTATE_ARRAY_SIZE;
+obj.size2 = VMSTATE_ARRAY_SIZE - 1;

 save_vmstate(&vmstate_array_primitive, &obj_array);

@@ -731,6 +743,12 @@ static void test_array_primitive(void)
 ELEM_EQUAL_2D(u32_1d, i, j);
 }
 }
+
+FIELD_EQUAL(size2);
+for (i = 0; i < VMSTATE_ARRAY_SIZE-1; i++) {
+ELEM_EQUAL(u16_2, i);
+}
+ELEM_NOT_EQUAL(u16_2, VMSTATE_ARRAY_SIZE-1);
 }

 static const VMStateDescription vmstate_array_test = {
@@ -782,6 +800,7 @@ static void test_array_test(void)

 memset(&obj, 0, sizeof(obj));
 obj.size = VMSTATE_ARRAY_SIZE;
+obj.size2 = VMSTATE_ARRAY_SIZE - 1;

 save_vmstate(&vmstate_array_test, &obj_array);

-- 
1.9.0




[Qemu-devel] [PATCH 123/124] vmstate: Test for VMSTATE_ARRAY_OF_POINTER_TO_STRUCT

2014-04-21 Thread Juan Quintela
Signed-off-by: Juan Quintela 
---
 tests/test-vmstate.c | 105 +++
 1 file changed, 105 insertions(+)

diff --git a/tests/test-vmstate.c b/tests/test-vmstate.c
index fa69209..ca1f6e2 100644
--- a/tests/test-vmstate.c
+++ b/tests/test-vmstate.c
@@ -1916,6 +1916,110 @@ static void test_struct_varray(void)
 }
 }
 }
+
+typedef struct TestStruct3 {
+SubStruct *p_1[3];
+} TestStruct3;
+
+/*
+ * size: needs to be the 1st field
+ * a: needs to be the last field
+ * We use that fact to load with different sizes
+ */
+
+static const VMStateDescription vmstate_struct_pointer = {
+.name = "struct/pointer",
+.version_id = 1,
+.minimum_version_id = 1,
+.minimum_version_id_old = 1,
+.fields = (VMStateField[]) {
+VMSTATE_ARRAY_OF_POINTER_TO_STRUCT(p_1, TestStruct3, 3,
+   vmstate_sub_struct, SubStruct),
+VMSTATE_END_OF_LIST()
+}
+};
+
+/* This is the binary representation on the wire of that struct */
+/* We need to change the first byte for load to work */
+uint8_t wire_struct_pointer[] = {
+/* p_1[0] */
+/* i32 */   0x00, 0x00, 0x00, 0x15,
+/* i64 */   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1f,
+/* buffer */0x62, 0x79, 0x65, 0x30, 0x20, 0x20, 0x77, 0x6f,
+0x72, 0x6c, 0x64, 0x21, 0x00,
+/* p_1[1] */
+/* i32 */   0x00, 0x00, 0x00, 0x16,
+/* i64 */   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20,
+/* buffer */0x62, 0x79, 0x65, 0x31, 0x20, 0x20, 0x77, 0x6f,
+0x72, 0x6c, 0x64, 0x21, 0x00,
+/* p_1[2] */
+/* i32 */   0x00, 0x00, 0x00, 0x17,
+/* i64 */   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x21,
+/* buffer */0x62, 0x79, 0x65, 0x32, 0x20, 0x20, 0x77, 0x6f,
+0x72, 0x6c, 0x64, 0x21, 0x00,
+QEMU_VM_EOF, /* just to ensure we won't get EOF reported prematurely */
+};
+
+static void obj_struct3_copy(void *arg1, void *arg2)
+{
+TestStruct3 *target = arg1;
+TestStruct3 *source = arg2;
+int i;
+
+for (i = 0; i < 3; i++) {
+target->p_1[i]->i32 = source->p_1[i]->i32;
+target->p_1[i]->i64 = source->p_1[i]->i64;
+memcpy(target->p_1[i]->buffer, source->p_1[i]->buffer, 13);
+}
+}
+
+static TestStruct3 *create_struct3(void)
+{
+TestStruct3 *obj = g_malloc0(sizeof(*obj));
+int i;
+
+for (i = 0; i < 3; i++) {
+obj->p_1[i] = g_malloc0(sizeof(SubStruct));
+}
+
+return obj;
+}
+
+static TestStruct3 *create_struct3_init(void)
+{
+TestStruct3 *obj = create_struct3();
+int i;
+
+for (i = 0; i < 3; i++) {
+obj->p_1[i]->i32 = i + 21;
+obj->p_1[i]->i64 = i + 31;
+snprintf((char *)obj->p_1[i]->buffer, 13, "bye%d  world!", i);
+}
+
+return obj;
+}
+
+static void test_struct_pointer(void)
+{
+TestStruct3 *obj, *obj_clone, *obj_struct3;
+int i;
+
+obj_struct3 = create_struct3_init();
+obj = create_struct3();
+obj_clone = create_struct3();
+
+save_vmstate(&vmstate_struct_pointer, obj_struct3);
+
+compare_vmstate(wire_struct_pointer, sizeof(wire_struct_pointer));
+
+SUCCESS(load_vmstate(&vmstate_struct_pointer, obj, obj_clone,
+ obj_struct3_copy, 1, wire_struct_pointer,
+ sizeof(wire_struct_pointer)));
+
+for (i = 0; i < 3; i++) {
+STRUCT_EQUAL(obj->p_1[i], obj_struct3->p_1[i]);
+}
+}
 #undef STRUCT_EQUAL
 #undef STRUCT_NOT_EQUAL

@@ -2164,6 +2268,7 @@ int main(int argc, char **argv)
 g_test_add_func("/vmstate/struct/simple", test_struct_simple);
 g_test_add_func("/vmstate/struct/test", test_struct_test);
 g_test_add_func("/vmstate/struct/varray", test_struct_varray);
+g_test_add_func("/vmstate/struct/pointer", test_struct_pointer);
 g_test_run();

 close(temp_fd);
-- 
1.9.0




[Qemu-devel] [PATCH 105/124] vmstate: Test for VMSTATE_POINTER_UNSAFE

2014-04-21 Thread Juan Quintela
Signed-off-by: Juan Quintela 
---
 tests/test-vmstate.c | 13 +++--
 1 file changed, 11 insertions(+), 2 deletions(-)

diff --git a/tests/test-vmstate.c b/tests/test-vmstate.c
index c284bfc..e1e2523 100644
--- a/tests/test-vmstate.c
+++ b/tests/test-vmstate.c
@@ -1059,6 +1059,7 @@ static void test_vbuffer_simple(void)

 typedef struct TestPointer {
 uint8_t  *u8_1p;
+uint8_t  *u8_2p;
 } TestPointer;

 static const VMStateDescription vmstate_pointer_simple = {
@@ -1068,12 +1069,15 @@ static const VMStateDescription vmstate_pointer_simple 
= {
 .minimum_version_id_old = 1,
 .fields = (VMStateField[]) {
 VMSTATE_POINTER(u8_1p, TestPointer, NULL, vmstate_info_uint8, uint8_t),
+VMSTATE_POINTER_UNSAFE(u8_2p, TestPointer,
+   vmstate_info_uint16, uint16_t),
 VMSTATE_END_OF_LIST()
 }
 };

 uint8_t wire_pointer_simple[] = {
 /* u8_1p */   0x11,
+/* u8_2p */   0x02, 0x2b,
 QEMU_VM_EOF, /* just to ensure we won't get EOF reported prematurely */
 };

@@ -1083,12 +1087,14 @@ static void obj_pointer_copy(void *arg1, void *arg2)
 TestPointer *source = arg2;

 *target->u8_1p = *source->u8_1p;
+*((uint16_t *)target->u8_2p) = *((uint16_t *)source->u8_2p);
 }

 static TestPointer *create_pointer(void)
 {
 TestPointer *obj = g_malloc0(sizeof(*obj));
 obj->u8_1p = g_malloc0(sizeof(*obj->u8_1p));
+obj->u8_2p = g_malloc0(sizeof(uint16_t));

 return obj;
 }
@@ -1102,7 +1108,9 @@ static void test_pointer_simple(void)
 obj_clone = create_pointer();

 *obj_pointer->u8_1p = 17;
+*((uint16_t *)obj_pointer->u8_2p) = 555;
 *obj->u8_1p = 22;
+*((uint16_t *)obj->u8_2p) = 777;

 save_vmstate(&vmstate_pointer_simple, obj_pointer);

@@ -1112,8 +1120,9 @@ static void test_pointer_simple(void)
  obj_pointer_copy, 1, wire_pointer_simple,
  sizeof(wire_pointer_simple)));

-#define FIELD_EQUAL(name)   g_assert_cmpint(*obj->name, ==, *obj_pointer->name)
-FIELD_EQUAL(u8_1p);
+g_assert_cmpint(*obj->u8_1p, ==, *obj_pointer->u8_1p);
+g_assert_cmpint(*((uint16_t *)obj->u8_2p), ==,
+*((uint16_t *)obj_pointer->u8_2p));
 }
 #undef FIELD_EQUAL

-- 
1.9.0




[Qemu-devel] [PATCH 092/124] vmstate: Test for VMSTATE_BUFFER_START_MIDDLE

2014-04-21 Thread Juan Quintela
Signed-off-by: Juan Quintela 
---
 tests/test-vmstate.c | 7 +++
 1 file changed, 7 insertions(+)

diff --git a/tests/test-vmstate.c b/tests/test-vmstate.c
index ddfa017..8b114fa 100644
--- a/tests/test-vmstate.c
+++ b/tests/test-vmstate.c
@@ -868,11 +868,13 @@ static void test_array_sub(void)
 typedef struct TestBuffer {
 uint8_t  buffer[6];
 uint8_t  partial[13];
+uint8_t  middle[13];
 } TestBuffer;

 TestBuffer obj_buffer = {
 .buffer = "hello",
 .partial = "This is Juan",
+.middle = "hello world!"
 };

 static const VMStateDescription vmstate_buffer_simple = {
@@ -883,6 +885,7 @@ static const VMStateDescription vmstate_buffer_simple = {
 .fields = (VMStateField[]) {
 VMSTATE_BUFFER(buffer, TestBuffer),
 VMSTATE_PARTIAL_BUFFER(partial, TestBuffer, 4),
+VMSTATE_BUFFER_START_MIDDLE(middle, TestBuffer, 6),
 VMSTATE_END_OF_LIST()
 }
 };
@@ -890,6 +893,7 @@ static const VMStateDescription vmstate_buffer_simple = {
 uint8_t wire_buffer_simple[] = {
 /* buffer */   0x68, 0x65, 0x6c, 0x6c, 0x6f, 0x00,
 /* partial */  0x54, 0x68, 0x69, 0x73,
+/* middle */   0x77, 0x6f, 0x72, 0x6c, 0x64, 0x21, 0x00,
 QEMU_VM_EOF, /* just to ensure we won't get EOF reported prematurely */
 };

@@ -900,6 +904,7 @@ static void obj_buffer_copy(void *arg1, void *arg2)

 memcpy(target->buffer, source->buffer, 6);
 memcpy(target->partial, source->partial, 13);
+memcpy(target->middle, source->middle, 13);
 }

 static void test_buffer_simple(void)
@@ -919,6 +924,8 @@ static void test_buffer_simple(void)
 SUCCESS(memcmp(obj.buffer, obj_buffer.buffer, sizeof(obj.buffer)));
 SUCCESS(memcmp(obj.partial, obj_buffer.partial, 4));
 FAILURE(memcmp(obj.partial+4, obj_buffer.partial+4, 
sizeof(obj.partial)-4));
+FAILURE(memcmp(obj.middle, obj_buffer.middle, 6));
+SUCCESS(memcmp(obj.middle+6, obj_buffer.middle+6, sizeof(obj.middle)-6));
 }

 typedef struct TestVersioned {
-- 
1.9.0




[Qemu-devel] [PATCH 109/124] vmstate: Test for VMSTATE_VARRAY

2014-04-21 Thread Juan Quintela
Signed-off-by: Juan Quintela 
---
 tests/test-vmstate.c | 127 +++
 1 file changed, 127 insertions(+)

diff --git a/tests/test-vmstate.c b/tests/test-vmstate.c
index f7fd3e2..1fa2899 100644
--- a/tests/test-vmstate.c
+++ b/tests/test-vmstate.c
@@ -1208,6 +1208,131 @@ static void test_pointer_simple(void)
 }
 #undef FIELD_EQUAL

+typedef struct TestVarray {
+uint8_t  *u8_1p;
+uint8_t  *u8_2p;
+} TestVArray;
+
+static const VMStateDescription vmstate_varray_simple = {
+.name = "varray/simple",
+.version_id = 1,
+.minimum_version_id = 1,
+.minimum_version_id_old = 1,
+.fields = (VMStateField[]) {
+VMSTATE_VARRAY(u8_1p, TestVArray, VMSTATE_ARRAY_SIZE,
+   NULL, vmstate_info_uint8, uint8_t),
+VMSTATE_END_OF_LIST()
+}
+};
+
+uint8_t wire_varray_simple[] = {
+/* u8_1p */ 0x01, 0x02, 0x03, 0x04, 0x05,
+QEMU_VM_EOF, /* just to ensure we won't get EOF reported prematurely */
+};
+
+static void obj_varray_copy(void *arg1, void *arg2)
+{
+TestVArray *target = arg1;
+TestVArray *source = arg2;
+int i;
+
+for (i = 0; i < VMSTATE_ARRAY_SIZE; i++) {
+target->u8_1p[i] = source->u8_1p[i];
+target->u8_2p[i] = source->u8_2p[i];
+}
+}
+
+static TestVArray *create_varray(void)
+{
+TestVArray *obj = g_malloc0(sizeof(*obj));
+obj->u8_1p = g_malloc0(VMSTATE_ARRAY_SIZE);
+obj->u8_2p = g_malloc0(VMSTATE_ARRAY_SIZE);
+
+return obj;
+}
+
+static TestVArray *create_varray_init(void)
+{
+TestVArray *obj = create_varray();
+int i;
+
+for (i = 0; i < VMSTATE_ARRAY_SIZE; i++) {
+obj->u8_1p[i] = i + 1;
+obj->u8_2p[i] = i + 11;
+}
+return obj;
+}
+
+static void test_varray_simple(void)
+{
+TestVArray *obj, *obj_clone, *obj_varray;
+int i;
+
+obj_varray = create_varray_init();
+obj = create_varray();
+obj_clone = create_varray();
+
+save_vmstate(&vmstate_varray_simple, obj_varray);
+
+compare_vmstate(wire_varray_simple, sizeof(wire_varray_simple));
+
+SUCCESS(load_vmstate(&vmstate_varray_simple, obj, obj_clone,
+ obj_varray_copy, 1, wire_varray_simple,
+ sizeof(wire_varray_simple)));
+#define ELEM_EQUAL(name, i) \
+g_assert_cmpint(obj->name[i], ==, obj_varray->name[i])
+#define ELEM_NOT_EQUAL(name, i) \
+g_assert_cmpint(obj->name[i], !=, obj_varray->name[i])
+
+for (i = 0; i < VMSTATE_ARRAY_SIZE; i++) {
+ELEM_EQUAL(u8_1p, i);
+ELEM_NOT_EQUAL(u8_2p, i);
+}
+}
+static const VMStateDescription vmstate_varray_test = {
+.name = "varray/test",
+.version_id = 1,
+.minimum_version_id = 1,
+.minimum_version_id_old = 1,
+.fields = (VMStateField[]) {
+VMSTATE_VARRAY(u8_1p, TestVArray, VMSTATE_ARRAY_SIZE,
+   test_true, vmstate_info_uint8, uint8_t),
+VMSTATE_VARRAY(u8_2p, TestVArray, VMSTATE_ARRAY_SIZE,
+   test_false, vmstate_info_uint8, uint8_t),
+VMSTATE_END_OF_LIST()
+}
+};
+
+uint8_t wire_varray_test[] = {
+/* u8_1p */ 0x01, 0x02, 0x03, 0x04, 0x05,
+QEMU_VM_EOF, /* just to ensure we won't get EOF reported prematurely */
+};
+
+static void test_varray_test(void)
+{
+TestVArray *obj, *obj_clone, *obj_varray;
+int i;
+
+obj_varray = create_varray_init();
+obj = create_varray();
+obj_clone = create_varray();
+
+save_vmstate(&vmstate_varray_test, obj_varray);
+
+compare_vmstate(wire_varray_test, sizeof(wire_varray_test));
+
+SUCCESS(load_vmstate(&vmstate_varray_test, obj, obj_clone,
+ obj_varray_copy, 1, wire_varray_test,
+ sizeof(wire_varray_test)));
+
+for (i = 0; i < VMSTATE_ARRAY_SIZE; i++) {
+ELEM_EQUAL(u8_1p, i);
+ELEM_NOT_EQUAL(u8_2p, i);
+}
+}
+#undef ELEM_EQUAL
+#undef ELEM_NOTEQUAL
+
 typedef struct TestVersioned {
 uint32_t a, b, c, e;
 uint64_t d, f;
@@ -1448,6 +1573,8 @@ int main(int argc, char **argv)
 g_test_add_func("/vmstate/buffer/test", test_buffer_test);
 g_test_add_func("/vmstate/vbuffer/simple", test_vbuffer_simple);
 g_test_add_func("/vmstate/pointer/simple", test_pointer_simple);
+g_test_add_func("/vmstate/varray/simple", test_varray_simple);
+g_test_add_func("/vmstate/varray/test", test_varray_test);
 g_test_run();

 close(temp_fd);
-- 
1.9.0




[Qemu-devel] [PATCH 103/124] vmstate: VMSTATE_POINTER() used the wrong type to calculate the size

2014-04-21 Thread Juan Quintela
We need the the pointer to foo for the type of the field, but not for the size.
Fix its only user.

Signed-off-by: Juan Quintela 
---
 include/migration/vmstate.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/include/migration/vmstate.h b/include/migration/vmstate.h
index cf27366..3fd13e7 100644
--- a/include/migration/vmstate.h
+++ b/include/migration/vmstate.h
@@ -221,7 +221,7 @@ extern const VMStateInfo vmstate_info_bitmap;
 .field_exists = (_test), \
 .size = sizeof(_type),   \
 .flags= VMS_SINGLE|VMS_POINTER,  \
-.offset   = vmstate_offset_value(_state, _field, _type), \
+.offset   = vmstate_offset_value(_state, _field, _type*),\
 }

 #define VMSTATE_POINTER_UNSAFE(_field, _state, _info, _type) {   \
@@ -566,7 +566,7 @@ extern const VMStateInfo vmstate_info_bitmap;
 VMSTATE_SINGLE(_f, _s, NULL, vmstate_info_float64, float64)

 #define VMSTATE_TIMER_TEST(_f, _s, _test) \
-VMSTATE_POINTER(_f, _s, _test, vmstate_info_timer, QEMUTimer*)
+VMSTATE_POINTER(_f, _s, _test, vmstate_info_timer, QEMUTimer)

 #define VMSTATE_TIMER(_f, _s) \
 VMSTATE_TIMER_TEST(_f, _s, NULL)
-- 
1.9.0




[Qemu-devel] [PATCH 007/124] vmstate: Return error in case of error

2014-04-21 Thread Juan Quintela
If there is an error while loading a field, we should stop reading and
not continue with the rest of fields.  And we should also set an error
in qemu_file.

Signed-off-by: Juan Quintela 
---
 vmstate.c | 6 ++
 1 file changed, 6 insertions(+)

diff --git a/vmstate.c b/vmstate.c
index bfa34cc..bcf1cde 100644
--- a/vmstate.c
+++ b/vmstate.c
@@ -74,7 +74,13 @@ int vmstate_load_state(QEMUFile *f, const VMStateDescription 
*vmsd,
 ret = field->info->get(f, addr, size);

 }
+if (ret >= 0) {
+ret = qemu_file_get_error(f);
+}
 if (ret < 0) {
+if (!qemu_file_get_error(f)) {
+qemu_file_set_error(f, ret);
+}
 trace_vmstate_load_field_error(field->name, ret);
 return ret;
 }
-- 
1.9.0




[Qemu-devel] [PATCH 100/124] vmstate: Create VMS_VBUFFER_UINT32

2014-04-21 Thread Juan Quintela
We were dereferencing an uint32_t as int32_t.

Signed-off-by: Juan Quintela 
---
 include/migration/vmstate.h | 3 ++-
 vmstate.c   | 2 ++
 2 files changed, 4 insertions(+), 1 deletion(-)

diff --git a/include/migration/vmstate.h b/include/migration/vmstate.h
index 84efec5..a2d1aae 100644
--- a/include/migration/vmstate.h
+++ b/include/migration/vmstate.h
@@ -97,6 +97,7 @@ enum VMStateFlags {
 VMS_ARRAY_OF_POINTER = 0x040,
 VMS_VARRAY_UINT16= 0x080,  /* Array with size in uint16_t field */
 VMS_VBUFFER  = 0x100,  /* Buffer with size in int32_t field */
+VMS_VBUFFER_UINT32   = 0x200,  /* Buffer with size in uint32_t field */
 VMS_VARRAY_UINT8 = 0x400,  /* Array with size in uint8_t field*/
 VMS_VARRAY_UINT32= 0x800,  /* Array with size in uint32_t field*/
 };
@@ -443,7 +444,7 @@ extern const VMStateInfo vmstate_info_bitmap;
 .name = (stringify(_field)), \
 .size_offset  = vmstate_offset_value(_state, _field_size, uint32_t),\
 .info = &vmstate_info_buffer,\
-.flags= VMS_VBUFFER|VMS_POINTER, \
+.flags= VMS_VBUFFER_UINT32|VMS_POINTER,  \
 .offset   = offsetof(_state, _field),\
 }

diff --git a/vmstate.c b/vmstate.c
index bd52c79..c2e79b9 100644
--- a/vmstate.c
+++ b/vmstate.c
@@ -35,6 +35,8 @@ static int vmstate_size(void *opaque, VMStateField *field)

 if (field->flags & VMS_VBUFFER) {
 size = *(int32_t *)(opaque+field->size_offset);
+} else if (field->flags & VMS_VBUFFER_UINT32) {
+size = *(uint32_t *)(opaque+field->size_offset);
 }

 return size;
-- 
1.9.0




[Qemu-devel] [PATCH 112/124] vmstate: Test for VMSTATE_VARRAY_INT32{_TEST}

2014-04-21 Thread Juan Quintela
Signed-off-by: Juan Quintela 
---
 tests/test-vmstate.c | 31 +++
 1 file changed, 31 insertions(+)

diff --git a/tests/test-vmstate.c b/tests/test-vmstate.c
index edceaee..7e69b14 100644
--- a/tests/test-vmstate.c
+++ b/tests/test-vmstate.c
@@ -1213,6 +1213,9 @@ typedef struct TestVarray {
 uint8_t  *u8_2p;
 int32_t size;
 uint32_t *u32_1p;
+uint32_t size3;
+int32_t *i32_1p;
+int32_t *i32_2p;
 uint16_t size2;
 uint16_t u16_1[0];
 } TestVArray;
@@ -1228,6 +1231,9 @@ static const VMStateDescription vmstate_varray_simple = {
 VMSTATE_INT32(size, TestVArray),
 VMSTATE_VARRAY_INT32(u32_1p, TestVArray, size,
  vmstate_info_uint32, uint32_t),
+VMSTATE_UINT32_EQUAL(size3, TestVArray),
+VMSTATE_VARRAY_UINT32(i32_1p, TestVArray, size3,
+  vmstate_info_int32, int32_t),
 VMSTATE_UINT16_EQUAL(size2, TestVArray),
 VMSTATE_VARRAY_UINT16_UNSAFE(u16_1, TestVArray, size2,
  vmstate_info_uint16, uint16_t),
@@ -1241,6 +1247,10 @@ uint8_t wire_varray_simple[] = {
 /* u32_1p */0x00, 0x00, 0x00, 0x15, 0x00, 0x00, 0x00, 0x16,
 0x00, 0x00, 0x00, 0x17, 0x00, 0x00, 0x00, 0x18,
 0x00, 0x00, 0x00, 0x19,
+/* size3 */ 0x00, 0x00, 0x00, 0x05,
+/* i32_1 */ 0x00, 0x00, 0x00, 0x33, 0x00, 0x00, 0x00, 0x34,
+0x00, 0x00, 0x00, 0x35, 0x00, 0x00, 0x00, 0x36,
+0x00, 0x00, 0x00, 0x37,
 /* size2 */ 0x00, 0x05,
 /* u16_1 */ 0x00, 0x0b, 0x00, 0x0c, 0x00, 0x0d,
 0x00, 0x0e, 0x00, 0x0f,
@@ -1255,11 +1265,14 @@ static void obj_varray_copy(void *arg1, void *arg2)

 target->size = source->size;
 target->size2 = source->size2;
+target->size3 = source->size3;
 for (i = 0; i < VMSTATE_ARRAY_SIZE; i++) {
 target->u8_1p[i] = source->u8_1p[i];
 target->u8_2p[i] = source->u8_2p[i];
 target->u32_1p[i] = source->u32_1p[i];
 target->u16_1[i] = source->u16_1[i];
+target->i32_1p[i] = source->i32_1p[i];
+target->i32_2p[i] = source->i32_2p[i];
 }
 }

@@ -1269,9 +1282,12 @@ static TestVArray *create_varray(void)
 VMSTATE_ARRAY_SIZE * sizeof(uint16_t));
 obj->size = VMSTATE_ARRAY_SIZE;
 obj->size2 = VMSTATE_ARRAY_SIZE;
+obj->size3 = VMSTATE_ARRAY_SIZE;
 obj->u8_1p = g_malloc0(VMSTATE_ARRAY_SIZE);
 obj->u8_2p = g_malloc0(VMSTATE_ARRAY_SIZE);
 obj->u32_1p = g_malloc0(VMSTATE_ARRAY_SIZE * sizeof(uint32_t));
+obj->i32_1p = g_malloc0(VMSTATE_ARRAY_SIZE * sizeof(int32_t));
+obj->i32_2p = g_malloc0(VMSTATE_ARRAY_SIZE * sizeof(int32_t));

 return obj;
 }
@@ -1286,6 +1302,8 @@ static TestVArray *create_varray_init(void)
 obj->u8_2p[i] = i + 11;
 obj->u32_1p[i] = i + 21;
 obj->u16_1[i] = i + 11;
+obj->i32_1p[i] = i + 51;
+obj->i32_2p[i] = 55 - i;
 }
 return obj;
 }
@@ -1316,6 +1334,8 @@ static void test_varray_simple(void)
 ELEM_NOT_EQUAL(u8_2p, i);
 ELEM_EQUAL(u32_1p, i);
 ELEM_EQUAL(u16_1, i);
+ELEM_EQUAL(i32_1p, i);
+ELEM_NOT_EQUAL(i32_2p, i);
 }
 }
 static const VMStateDescription vmstate_varray_test = {
@@ -1328,12 +1348,21 @@ static const VMStateDescription vmstate_varray_test = {
test_true, vmstate_info_uint8, uint8_t),
 VMSTATE_VARRAY(u8_2p, TestVArray, VMSTATE_ARRAY_SIZE,
test_false, vmstate_info_uint8, uint8_t),
+VMSTATE_UINT32_EQUAL(size3, TestVArray),
+VMSTATE_VARRAY_UINT32_TEST(i32_1p, TestVArray, size3, test_true,
+   vmstate_info_int32, int32_t),
+VMSTATE_VARRAY_UINT32_TEST(i32_2p, TestVArray, size3, test_false,
+   vmstate_info_int32, int32_t),
 VMSTATE_END_OF_LIST()
 }
 };

 uint8_t wire_varray_test[] = {
 /* u8_1p */ 0x01, 0x02, 0x03, 0x04, 0x05,
+/* size3 */ 0x00, 0x00, 0x00, 0x05,
+/* i32_1 */ 0x00, 0x00, 0x00, 0x33, 0x00, 0x00, 0x00, 0x34,
+0x00, 0x00, 0x00, 0x35, 0x00, 0x00, 0x00, 0x36,
+0x00, 0x00, 0x00, 0x37,
 QEMU_VM_EOF, /* just to ensure we won't get EOF reported prematurely */
 };

@@ -1357,6 +1386,8 @@ static void test_varray_test(void)
 for (i = 0; i < VMSTATE_ARRAY_SIZE; i++) {
 ELEM_EQUAL(u8_1p, i);
 ELEM_NOT_EQUAL(u8_2p, i);
+ELEM_EQUAL(i32_1p, i);
+ELEM_NOT_EQUAL(i32_2p, i);
 }
 }
 #undef ELEM_EQUAL
-- 
1.9.0




[Qemu-devel] [PATCH 118/124] vmstate: Test for VMSTATE_STRUCT_VARRAY_UINT32

2014-04-21 Thread Juan Quintela
Signed-off-by: Juan Quintela 
---
 tests/test-vmstate.c | 33 +
 1 file changed, 33 insertions(+)

diff --git a/tests/test-vmstate.c b/tests/test-vmstate.c
index f4ff93d..25e162f 100644
--- a/tests/test-vmstate.c
+++ b/tests/test-vmstate.c
@@ -1653,6 +1653,8 @@ static void test_struct_test(void)
 typedef struct TestStruct2 {
 uint8_t size;
 SubStruct a[3];
+uint32_t size2;
+SubStruct b[3];
 } TestStruct2;

 /*
@@ -1668,6 +1670,9 @@ static const VMStateDescription vmstate_struct_varray = {
 .minimum_version_id_old = 1,
 .fields = (VMStateField[]) {
 VMSTATE_UINT8_EQUAL(size, TestStruct2),
+VMSTATE_UINT32_EQUAL(size2, TestStruct2),
+VMSTATE_STRUCT_VARRAY_UINT32(b, TestStruct2, size2,
+ vmstate_sub_struct, SubStruct),
 VMSTATE_STRUCT_VARRAY_UINT8(a, TestStruct2, size,
 vmstate_sub_struct, SubStruct),
 VMSTATE_END_OF_LIST()
@@ -1678,6 +1683,22 @@ static const VMStateDescription vmstate_struct_varray = {
 /* We need to change the first byte for load to work */
 uint8_t wire_struct_varray[] = {
 /* size */  0x03,
+/* size2 */ 0x00, 0x00, 0x00, 0x03,
+/* b[0] */
+/* i32 */   0x00, 0x00, 0x00, 0x29,
+/* i64 */   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x33,
+/* buffer */0x62, 0x79, 0x65, 0x33, 0x20, 0x20, 0x77, 0x6f,
+0x72, 0x6c, 0x64, 0x21, 0x00,
+/* b[1] */
+/* i32 */   0x00, 0x00, 0x00, 0x2a,
+/* i64 */   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x34,
+/* buffer */0x62, 0x79, 0x65, 0x34, 0x20, 0x20, 0x77, 0x6f,
+0x72, 0x6c, 0x64, 0x21, 0x00,
+/* b[2] */
+/* i32 */   0x00, 0x00, 0x00, 0x2b,
+/* i64 */   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x35,
+/* buffer */0x62, 0x79, 0x65, 0x35, 0x20, 0x20, 0x77, 0x6f,
+0x72, 0x6c, 0x64, 0x21, 0x00,
 /* a[0] */
 /* i32 */   0x00, 0x00, 0x00, 0x15,
 /* i64 */   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1f,
@@ -1703,10 +1724,14 @@ static void obj_struct2_copy(void *arg1, void *arg2)
 int i;

 target->size = source->size;
+target->size2 = source->size2;
 for (i = 0; i < 3; i++) {
 target->a[i].i32 = source->a[i].i32;
 target->a[i].i64 = source->a[i].i64;
 memcpy(target->a[i].buffer, source->a[i].buffer, 13);
+target->b[i].i32 = source->b[i].i32;
+target->b[i].i64 = source->b[i].i64;
+memcpy(target->b[i].buffer, source->b[i].buffer, 13);
 }
 }

@@ -1714,6 +1739,7 @@ static TestStruct2 *create_struct2(void)
 {
 TestStruct2 *obj = g_malloc0(sizeof(*obj));
 obj->size = 3;
+obj->size2 = 3;

 return obj;
 }
@@ -1727,6 +1753,9 @@ static TestStruct2 *create_struct2_init(void)
 obj->a[i].i32 = i + 21;
 obj->a[i].i64 = i + 31;
 snprintf((char *)obj->a[i].buffer, 13, "bye%d  world!", i);
+obj->b[i].i32 = i + 41;
+obj->b[i].i64 = i + 51;
+snprintf((char *)obj->b[i].buffer, 13, "bye%d  world!", i + 3);
 }

 return obj;
@@ -1750,6 +1779,7 @@ static void test_struct_varray(void)

 sub_struct_size = sizeof(uint32_t) + sizeof(uint64_t) + 13;
 memset(obj->a, 0, sizeof(obj->a));
+memset(obj->b, 0, sizeof(obj->b));
 obj->size = j;
 obj_struct2->size = j;
 wire_struct_varray[0] = j;
@@ -1764,6 +1794,9 @@ static void test_struct_varray(void)
 for (i = j; i < 3; i++) {
 STRUCT_NOT_EQUAL((&obj->a[i]), (&obj_struct2->a[i]));
 }
+for (i = 0; i < 3; i++) {
+STRUCT_EQUAL((&obj->b[i]), (&obj_struct2->b[i]));
+}
 }
 }
 #undef STRUCT_EQUAL
-- 
1.9.0




[Qemu-devel] [PATCH 107/124] vmstate: Test for VMSTATE_BUFFER_POINTER_UNSAFE

2014-04-21 Thread Juan Quintela
Signed-off-by: Juan Quintela 
---
 tests/test-vmstate.c | 19 +++
 1 file changed, 19 insertions(+)

diff --git a/tests/test-vmstate.c b/tests/test-vmstate.c
index 9f7256c..a8a1dfe 100644
--- a/tests/test-vmstate.c
+++ b/tests/test-vmstate.c
@@ -865,12 +865,15 @@ static void test_array_sub(void)
 #undef ELEM_EQUAL_2D
 #undef ELEM_NOT_EQUAL

+uint32_t test_scratch3[5] =  {41, 42, 43, 44, 45};
+
 typedef struct TestBuffer {
 uint8_t  buffer[6];
 uint8_t  partial[13];
 uint8_t  middle[13];
 uint32_t scratch[5];
 uint32_t scratch2[5];
+uint32_t *scratch3;
 } TestBuffer;

 TestBuffer obj_buffer = {
@@ -879,6 +882,7 @@ TestBuffer obj_buffer = {
 .middle = "hello world!",
 .scratch = {21, 22, 23, 24, 25},
 .scratch2 = {31, 32, 33, 34, 35},
+.scratch3 = test_scratch3,
 };

 static const VMStateDescription vmstate_buffer_simple = {
@@ -891,6 +895,8 @@ static const VMStateDescription vmstate_buffer_simple = {
 VMSTATE_PARTIAL_BUFFER(partial, TestBuffer, 4),
 VMSTATE_BUFFER_START_MIDDLE(middle, TestBuffer, 6),
 VMSTATE_BUFFER_UNSAFE(scratch, TestBuffer, 5 * sizeof(uint32_t)),
+VMSTATE_BUFFER_POINTER_UNSAFE(scratch3,
+  TestBuffer, 5 * sizeof(uint32_t)),
 VMSTATE_END_OF_LIST()
 }
 };
@@ -902,6 +908,9 @@ uint8_t wire_buffer_simple[] = {
 /* scratch */  0x15, 0x00, 0x00, 0x00, 0x16, 0x00, 0x00, 0x00,
0x17, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x00,
0x19, 0x00, 0x00, 0x00,
+/* scratch3 */ 0x29, 0x00, 0x00, 0x00, 0x2a, 0x00, 0x00, 0x00,
+   0x2b, 0x00, 0x00, 0x00, 0x2c, 0x00, 0x00, 0x00,
+   0x2d, 0x00, 0x00, 0x00,
 QEMU_VM_EOF, /* just to ensure we won't get EOF reported prematurely */
 };

@@ -917,14 +926,19 @@ static void obj_buffer_copy(void *arg1, void *arg2)
 for (i = 0; i < 5; i++) {
 target->scratch[0] = source->scratch[0];
 target->scratch2[0] = source->scratch2[0];
+target->scratch3[0] = source->scratch3[0];
 }
 }

 static void test_buffer_simple(void)
 {
 TestBuffer obj, obj_clone;
+uint32_t local_scratch[5];
+uint32_t local_scratch_clone[5];

 memset(&obj, 0, sizeof(obj));
+obj.scratch3 = local_scratch;
+obj_clone.scratch3 = local_scratch_clone;

 save_vmstate(&vmstate_buffer_simple, &obj_buffer);

@@ -940,6 +954,7 @@ static void test_buffer_simple(void)
 FAILURE(memcmp(obj.middle, obj_buffer.middle, 6));
 SUCCESS(memcmp(obj.middle+6, obj_buffer.middle+6, sizeof(obj.middle)-6));
 SUCCESS(memcmp(obj.scratch, obj_buffer.scratch, sizeof(obj.scratch)));
+SUCCESS(memcmp(obj.scratch3, obj_buffer.scratch3, 5 * sizeof(uint32_t)));
 }

 /* just sent the fields in the reverse order that are stored */
@@ -998,8 +1013,12 @@ uint8_t wire_buffer_test[] = {
 static void test_buffer_test(void)
 {
 TestBuffer obj, obj_clone;
+uint32_t local_scratch[5];
+uint32_t local_scratch_clone[5];

 memset(&obj, 0, sizeof(obj));
+obj.scratch3 = local_scratch;
+obj_clone.scratch3 = local_scratch_clone;

 save_vmstate(&vmstate_buffer_test, &obj_buffer);

-- 
1.9.0




[Qemu-devel] [PATCH 113/124] vmstate: Test for VMSTATE_STRUCT{_TEST}

2014-04-21 Thread Juan Quintela
Signed-off-by: Juan Quintela 
---
 tests/test-vmstate.c | 148 +++
 1 file changed, 148 insertions(+)

diff --git a/tests/test-vmstate.c b/tests/test-vmstate.c
index 7e69b14..93537f7 100644
--- a/tests/test-vmstate.c
+++ b/tests/test-vmstate.c
@@ -1393,6 +1393,152 @@ static void test_varray_test(void)
 #undef ELEM_EQUAL
 #undef ELEM_NOTEQUAL

+typedef struct SubStruct {
+int32_t i32;
+int64_t i64;
+uint8_t buffer[13];
+} SubStruct;
+
+static const VMStateDescription vmstate_sub_struct = {
+.name = "struct/substruct",
+.version_id = 1,
+.minimum_version_id = 1,
+.minimum_version_id_old = 1,
+.fields = (VMStateField[]) {
+VMSTATE_INT32(i32, SubStruct),
+VMSTATE_INT64(i64, SubStruct),
+VMSTATE_BUFFER(buffer, SubStruct),
+VMSTATE_END_OF_LIST()
+}
+};
+
+typedef struct TestStruct {
+SubStruct sub;
+SubStruct sub2;
+} TestStruct;
+
+static const VMStateDescription vmstate_struct_simple = {
+.name = "struct/simple",
+.version_id = 1,
+.minimum_version_id = 1,
+.minimum_version_id_old = 1,
+.fields = (VMStateField[]) {
+VMSTATE_STRUCT(sub, TestStruct, vmstate_sub_struct, SubStruct),
+VMSTATE_END_OF_LIST()
+}
+};
+
+TestStruct obj_struct = {
+.sub = {
+.i32 = 33,
+.i64 = 77,
+.buffer = "hello world!",
+},
+.sub2 = {
+.i32 = 66,
+.i64 = 99,
+.buffer = "bye   world!",
+},
+};
+
+/* This is the binary representation on the wire of that struct */
+uint8_t wire_struct_simple[] = {
+/* i32 */   0x00, 0x00, 0x00, 0x21,
+/* i64 */   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x4d,
+/* buffer */0x68, 0x65, 0x6c, 0x6c, 0x6f, 0x20, 0x77, 0x6f,
+0x72, 0x6c, 0x64, 0x21, 0x00,
+QEMU_VM_EOF, /* just to ensure we won't get EOF reported prematurely */
+};
+
+static void obj_struct_copy(void *arg1, void *arg2)
+{
+TestStruct *target = arg1;
+TestStruct *source = arg2;
+
+target->sub.i32 = source->sub.i32;
+target->sub.i64 = source->sub.i64;
+memcpy(target->sub.buffer, source->sub.buffer, 13);
+
+target->sub2.i32 = source->sub2.i32;
+target->sub2.i64 = source->sub2.i64;
+memcpy(target->sub2.buffer, source->sub2.buffer, 13);
+}
+
+static void test_struct_simple(void)
+{
+TestStruct obj, obj_clone;
+
+
+memset(&obj, 0, sizeof(obj));
+
+save_vmstate(&vmstate_struct_simple, &obj_struct);
+
+compare_vmstate(wire_struct_simple, sizeof(wire_struct_simple));
+
+SUCCESS(load_vmstate(&vmstate_struct_simple, &obj, &obj_clone,
+ obj_struct_copy, 1, wire_struct_simple,
+ sizeof(wire_struct_simple)));
+
+#define STRUCT_EQUAL(s1, s2)\
+do {\
+g_assert_cmpint(s1->i32, ==, s2->i32);  \
+g_assert_cmpint(s1->i64, ==, s2->i64);  \
+SUCCESS(memcmp(s1->buffer, s2->buffer,  \
+   sizeof(s1->buffer)));\
+} while (0)
+
+#define STRUCT_NOT_EQUAL(s1, s2)\
+do {\
+g_assert_cmpint(s1->i32, !=, s2->i32);  \
+g_assert_cmpint(s1->i64, !=, s2->i64);  \
+FAILURE(memcmp(s1->buffer, s2->buffer,  \
+   sizeof(s1->buffer)));\
+} while (0)
+
+STRUCT_EQUAL((&obj.sub), (&obj_struct.sub));
+STRUCT_NOT_EQUAL((&obj.sub2), (&obj_struct.sub2));
+}
+
+static const VMStateDescription vmstate_struct_test = {
+.name = "struct/test",
+.version_id = 1,
+.minimum_version_id = 1,
+.minimum_version_id_old = 1,
+.fields = (VMStateField[]) {
+VMSTATE_STRUCT(sub, TestStruct, vmstate_sub_struct, SubStruct),
+VMSTATE_END_OF_LIST()
+}
+};
+
+/* This is the binary representation on the wire of that struct */
+uint8_t wire_struct_test[] = {
+/* i32 */   0x00, 0x00, 0x00, 0x21,
+/* i64 */   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x4d,
+/* buffer */0x68, 0x65, 0x6c, 0x6c, 0x6f, 0x20, 0x77, 0x6f,
+0x72, 0x6c, 0x64, 0x21, 0x00,
+QEMU_VM_EOF, /* just to ensure we won't get EOF reported prematurely */
+};
+
+static void test_struct_test(void)
+{
+TestStruct obj, obj_clone;
+
+memset(&obj, 0, sizeof(obj));
+
+save_vmstate(&vmstate_struct_test, &obj_struct);
+
+compare_vmstate(wire_struct_test, sizeof(wire_struct_test));
+
+SUCCESS(load_vmstate(&vmstate_struct_test, &obj, &obj_clone,
+ obj_struct_copy, 1, wire_struct_test,
+ sizeof(wire_struct_test)));
+
+STRUCT_EQUAL((&obj.sub), (&obj_struct.sub));
+STRUCT_NOT_EQUAL((&obj.sub2), (&obj_struct.sub2));
+}
+#undef STRUCT_EQUAL
+#undef STRUCT_NOT_EQUAL
+
 typedef struct TestVersioned {
 uint32_t a, b, c, e;
 uint64_t d, f;
@@ -1635,6 +1781,8 @@ int main(int argc, char **argv)
 g_test

Re: [Qemu-devel] [PATCH] qemu-img: Improve error messages

2014-04-21 Thread Eric Blake
On 04/21/2014 12:23 AM, Fam Zheng wrote:
> Previously, when there is an user error in argv parsing, qemu-img prints

s/an user/a user/

(The rule of thumb for selecting which article to use for a leading 'u'
is pronunciation: anything starting with "you" uses "a", anything with
"uh" uses "an" [e.g. a unicorn under an umbrella].  Similar confusion
for 'h': hard h uses "a", silent h uses "an" [e.g. an hour and a half])

> help text and exits.
> 
> Add an error_exit function to print a helpful error message and a hint
> to run 'qemu-img --help' for more information.
> 
> As a bonus, "qemu-img  --help" now has a more reasonable exit code
> 0.
> 
> In the future the help text should be split by sub command, and only
> print the information for the specified command.
> 
> Signed-off-by: Fam Zheng 
> ---
>  qemu-img.c | 71 
> +++---
>  1 file changed, 45 insertions(+), 26 deletions(-)

>  
> +static void GCC_FMT_ATTR(1, 2) error_exit(const char *fmt, ...)

Should you also mark this QEMU_NORETURN?

> +{
> +va_list ap;
> +
> +error_printf("qemu-img: ");
> +
> +va_start(ap, fmt);
> +error_vprintf(fmt, ap);
> +va_end(ap);
> +
> +error_printf("\nTry 'qemu-img --help' for more information\n");
> +exit(1);

Worth using EXIT_FAILURE?

> @@ -129,7 +143,7 @@ static void help(void)
>  printf("%s\nSupported formats:", help_msg);
>  bdrv_iterate_format(format_print, NULL);
>  printf("\n");
> -exit(1);
> +exit(0);

Worth using EXIT_SUCCESS?

> @@ -2046,10 +2061,10 @@ static int img_map(int argc, char **argv)
>  break;
>  }
>  }
> -if (optind >= argc) {
> -help();
> +if (optind != argc - 1) {
> +error_exit("Expecting one image file name");
>  }
> -filename = argv[optind++];
> +filename = argv[optind];

I had to look at context to see that the increment of optind was indeed
dead code worth removing.

> @@ -2788,6 +2807,6 @@ int main(int argc, char **argv)
>  }
>  
>  /* not found */
> -help();
> +error_exit("Command not found: %s", cmdname);
>  return 0;

This return is now dead code; using QEMU_NORETURN would have helped the
compiler flag it.

-- 
Eric Blake   eblake redhat com+1-919-301-3266
Libvirt virtualization library http://libvirt.org



signature.asc
Description: OpenPGP digital signature


Re: [Qemu-devel] [PATCH v2 1/4] block: Add errp to bdrv_new()

2014-04-21 Thread Eric Blake
On 04/17/2014 09:48 AM, Kevin Wolf wrote:
> This patch adds an errp parameter to bdrv_new() and updates all its
> callers. The next patches will make use of this in order to check for
> duplicate IDs. Most of the callers know that their ID is fine, so they
> can simply assert that there is no error.
> 
> Behaviour doesn't change with this patch yet as bdrv_new() doesn't
> actually assign errors to errp.
> 
> Signed-off-by: Kevin Wolf 
> ---
>  block.c   | 6 +++---
>  block/iscsi.c | 2 +-
>  block/vvfat.c | 2 +-
>  blockdev.c| 9 +++--
>  hw/block/xen_disk.c   | 7 +--
>  include/block/block.h | 2 +-
>  qemu-img.c| 6 +++---
>  qemu-io.c | 2 +-
>  qemu-nbd.c| 3 ++-
>  9 files changed, 24 insertions(+), 15 deletions(-)
> 

Reviewed-by: Eric Blake 

-- 
Eric Blake   eblake redhat com+1-919-301-3266
Libvirt virtualization library http://libvirt.org



signature.asc
Description: OpenPGP digital signature


[Qemu-devel] [PATCH 120/124] vmstate: Test for VMSTATE_STRUCT_VARRAY_POINTER_UINT16

2014-04-21 Thread Juan Quintela
Signed-off-by: Juan Quintela 
---
 tests/test-vmstate.c | 32 
 1 file changed, 32 insertions(+)

diff --git a/tests/test-vmstate.c b/tests/test-vmstate.c
index 8ccf07d..eef5484 100644
--- a/tests/test-vmstate.c
+++ b/tests/test-vmstate.c
@@ -1657,6 +1657,8 @@ typedef struct TestStruct2 {
 SubStruct b[3];
 int32_t size3;
 SubStruct c[3];
+uint16_t size4;
+SubStruct *p_1;
 } TestStruct2;

 /*
@@ -1678,6 +1680,9 @@ static const VMStateDescription vmstate_struct_varray = {
 VMSTATE_INT32_EQUAL(size3, TestStruct2),
 VMSTATE_STRUCT_VARRAY_INT32(c, TestStruct2, size3,
 vmstate_sub_struct, SubStruct),
+VMSTATE_UINT16_EQUAL(size4, TestStruct2),
+VMSTATE_STRUCT_VARRAY_POINTER_UINT16(p_1, TestStruct2, size4,
+ vmstate_sub_struct, SubStruct),
 VMSTATE_STRUCT_VARRAY_UINT8(a, TestStruct2, size,
 vmstate_sub_struct, SubStruct),
 VMSTATE_END_OF_LIST()
@@ -1720,6 +1725,22 @@ uint8_t wire_struct_varray[] = {
 /* i64 */   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x49,
 /* buffer */0x62, 0x79, 0x65, 0x38, 0x20, 0x20, 0x77, 0x6f,
 0x72, 0x6c, 0x64, 0x21, 0x00,
+/* size4 */ 0x00, 0x03,
+/* p_1[0] */
+/* i32 */   0x00, 0x00, 0x00, 0x51,
+/* i64 */   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x5b,
+/* buffer */0x62, 0x79, 0x65, 0x30, 0x20, 0x20, 0x77, 0x6f,
+0x72, 0x6c, 0x64, 0x21, 0x00,
+/* p_1[1] */
+/* i32 */   0x00, 0x00, 0x00, 0x52,
+/* i64 */   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x5c,
+/* buffer */0x62, 0x79, 0x65, 0x31, 0x20, 0x20, 0x77, 0x6f,
+0x72, 0x6c, 0x64, 0x21, 0x00,
+/* p_1[2] */
+/* i32 */   0x00, 0x00, 0x00, 0x53,
+/* i64 */   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x5d,
+/* buffer */0x62, 0x79, 0x65, 0x32, 0x20, 0x20, 0x77, 0x6f,
+0x72, 0x6c, 0x64, 0x21, 0x00,
 /* a[0] */
 /* i32 */   0x00, 0x00, 0x00, 0x15,
 /* i64 */   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1f,
@@ -1747,6 +1768,7 @@ static void obj_struct2_copy(void *arg1, void *arg2)
 target->size = source->size;
 target->size2 = source->size2;
 target->size3 = source->size3;
+target->size4 = source->size4;
 for (i = 0; i < 3; i++) {
 target->a[i].i32 = source->a[i].i32;
 target->a[i].i64 = source->a[i].i64;
@@ -1757,6 +1779,9 @@ static void obj_struct2_copy(void *arg1, void *arg2)
 target->c[i].i32 = source->c[i].i32;
 target->c[i].i64 = source->c[i].i64;
 memcpy(target->c[i].buffer, source->c[i].buffer, 13);
+target->p_1[i].i32 = source->p_1[i].i32;
+target->p_1[i].i64 = source->p_1[i].i64;
+memcpy(target->p_1[i].buffer, source->p_1[i].buffer, 13);
 }
 }

@@ -1766,6 +1791,8 @@ static TestStruct2 *create_struct2(void)
 obj->size = 3;
 obj->size2 = 3;
 obj->size3 = 3;
+obj->size4 = 3;
+obj->p_1 = g_malloc0(sizeof(SubStruct) * 3);

 return obj;
 }
@@ -1785,6 +1812,9 @@ static TestStruct2 *create_struct2_init(void)
 obj->c[i].i32 = i + 61;
 obj->c[i].i64 = i + 71;
 snprintf((char *)obj->c[i].buffer, 13, "bye%d  world!", i + 6);
+obj->p_1[i].i32 = i + 81;
+obj->p_1[i].i64 = i + 91;
+snprintf((char *)obj->p_1[i].buffer, 13, "bye%d  world!", i);
 }

 return obj;
@@ -1810,6 +1840,7 @@ static void test_struct_varray(void)
 memset(obj->a, 0, sizeof(obj->a));
 memset(obj->b, 0, sizeof(obj->b));
 memset(obj->c, 0, sizeof(obj->c));
+memset(obj->p_1, 0, sizeof(*obj->p_1) * 3);
 obj->size = j;
 obj_struct2->size = j;
 wire_struct_varray[0] = j;
@@ -1827,6 +1858,7 @@ static void test_struct_varray(void)
 for (i = 0; i < 3; i++) {
 STRUCT_EQUAL((&obj->b[i]), (&obj_struct2->b[i]));
 STRUCT_EQUAL((&obj->c[i]), (&obj_struct2->c[i]));
+STRUCT_EQUAL((&obj->p_1[i]), (&obj_struct2->p_1[i]));
 }
 }
 }
-- 
1.9.0




  1   2   3   >