github.com/v21neolink/libvirt-go-xml@v1.0.5/domain_test.go (about)

     1  /*
     2   * This file is part of the libvirt-go-xml project
     3   *
     4   * Permission is hereby granted, free of charge, to any person obtaining a copy
     5   * of this software and associated documentation files (the "Software"), to deal
     6   * in the Software without restriction, including without limitation the rights
     7   * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
     8   * copies of the Software, and to permit persons to whom the Software is
     9   * furnished to do so, subject to the following conditions:
    10   *
    11   * The above copyright notice and this permission notice shall be included in
    12   * all copies or substantial portions of the Software.
    13   *
    14   * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
    15   * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
    16   * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
    17   * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
    18   * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
    19   * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
    20   * THE SOFTWARE.
    21   *
    22   * Copyright (C) 2016 Red Hat, Inc.
    23   *
    24   */
    25  
    26  package libvirtxml
    27  
    28  import (
    29  	"reflect"
    30  	"strings"
    31  	"testing"
    32  )
    33  
    34  type PCIAddress struct {
    35  	Domain   uint
    36  	Bus      uint
    37  	Slot     uint
    38  	Function uint
    39  }
    40  
    41  type DriveAddress struct {
    42  	Controller uint
    43  	Bus        uint
    44  	Target     uint
    45  	Unit       uint
    46  }
    47  
    48  type ISAAddress struct {
    49  	IOBase uint
    50  }
    51  
    52  var domainID int = 3
    53  
    54  var uhciIndex uint = 0
    55  var uhciAddr = PCIAddress{0, 0, 1, 2}
    56  var nvmeAddr = PCIAddress{0, 1, 3, 0}
    57  var pciIndex uint = 0
    58  var pciTargetChassisNr uint = 7
    59  var pciTargetChassis uint = 23
    60  var pciTargetPort uint = 78
    61  var pciTargetBusNr uint = 2
    62  var pciTargetIndex uint = 3
    63  var pciTargetNUMANode uint = 2
    64  var scsiIndex uint = 0
    65  var scsiQueues uint = 3
    66  var scsiCmdPerLUN uint = 8
    67  var scsiMaxSectors uint = 512
    68  
    69  var usbHostBus uint = 14
    70  var usbHostDevice uint = 6
    71  
    72  var pciHostDomain uint = 0
    73  var pciHostBus uint = 3
    74  var pciHostSlot uint = 14
    75  var pciHostFunction uint = 5
    76  
    77  var diskAddr = PCIAddress{0, 0, 3, 0}
    78  var ifaceAddr = PCIAddress{0, 0, 4, 0}
    79  var videoAddr = PCIAddress{0, 0, 5, 0}
    80  var fsAddr = PCIAddress{0, 0, 6, 0}
    81  var balloonAddr = PCIAddress{0, 0, 7, 0}
    82  var panicAddr = ISAAddress{0x505}
    83  var duplexAddr = PCIAddress{0, 0, 8, 0}
    84  var watchdogAddr = PCIAddress{0, 0, 8, 0}
    85  var rngAddr = PCIAddress{0, 0, 9, 0}
    86  var hostdevSCSI = DriveAddress{0, 0, 3, 0}
    87  
    88  var serialPort uint = 0
    89  var parallelPort uint = 0
    90  var tabletBus uint = 0
    91  var tabletPort string = "1.1"
    92  
    93  var nicAverage int = 1000
    94  var nicBurst int = 10000
    95  
    96  var vcpuId0 uint = 0
    97  var vcpuOrder0 uint = 1
    98  var vcpuId1 uint = 1
    99  
   100  var memorydevAddressSlot uint = 0
   101  var memorydevAddressBase uint64 = 4294967296
   102  
   103  var rebootTimeout int = 0
   104  var cellID0 uint = 0
   105  var cellID1 uint = 1
   106  
   107  var ipv6Prefix uint = 24
   108  
   109  var iothreadPriority int = -3
   110  var vcpuPriority int = -5
   111  
   112  var vepaManagerID uint = 5
   113  var vepaTypeID uint = 3
   114  var vepaTypeIDVersion uint = 12
   115  var vepaInstanceID = "c7bb5ab2-d42f-4690-89d6-f590eb199d0f"
   116  
   117  var vntagProfileID = "c7bb5ab2-d42f-4690-89d6-f590eb199d0f"
   118  
   119  var ovsProfileID = "c7bb5ab2-d42f-4690-89d6-f590eb199d0f"
   120  var ovsInterfaceID = "73728ac4-53d9-44de-8438-8d8f90beca00"
   121  
   122  var midoInterfaceID = "73728ac4-53d9-44de-8438-8d8f90beca00"
   123  
   124  var nvramReg uint64 = 0x4000
   125  
   126  var smartcardController uint = 0
   127  var smartcardSlot uint = 7
   128  
   129  var redirBus uint = 0
   130  var redirPort string = "3"
   131  
   132  var redirfilterClass uint = 0x08
   133  var redirfilterProduct uint = 0x2007
   134  var redirfilterVendor uint = 0x15e1
   135  
   136  var domainTestData = []struct {
   137  	Object   Document
   138  	Expected []string
   139  }{
   140  	{
   141  		Object: &Domain{
   142  			Type: "kvm",
   143  			Name: "test",
   144  			ID:   &domainID,
   145  		},
   146  		Expected: []string{
   147  			`<domain type="kvm" id="3">`,
   148  			`  <name>test</name>`,
   149  			`</domain>`,
   150  		},
   151  	},
   152  	{
   153  		Object: &Domain{
   154  			Type:        "kvm",
   155  			Name:        "test",
   156  			Title:       "Test",
   157  			Description: "A test guest config",
   158  			Metadata: &DomainMetadata{
   159  				XML: "<myvalue xmlns='http://myapp.com/schemeas/my/1.0'><widget name='foo'/></myvalue>" +
   160  					"<myothervalue xmlns='http://myotherapp.com/schemeas/my/1.0'><gizmo name='foo'/></myothervalue>",
   161  			},
   162  			Devices: &DomainDeviceList{
   163  				Disks: []DomainDisk{
   164  					DomainDisk{
   165  						Device: "cdrom",
   166  						Driver: &DomainDiskDriver{
   167  							Name: "qemu",
   168  							Type: "qcow2",
   169  						},
   170  						Source: &DomainDiskSource{
   171  							File: &DomainDiskSourceFile{
   172  								File: "/var/lib/libvirt/images/demo.qcow2",
   173  							},
   174  						},
   175  						Target: &DomainDiskTarget{
   176  							Dev: "vda",
   177  							Bus: "virtio",
   178  						},
   179  						Serial: "fishfood",
   180  						Boot: &DomainDeviceBoot{
   181  							Order: 1,
   182  						},
   183  					},
   184  					DomainDisk{
   185  						Device: "disk",
   186  						Driver: &DomainDiskDriver{
   187  							Name: "qemu",
   188  							Type: "raw",
   189  						},
   190  						Source: &DomainDiskSource{
   191  							Block: &DomainDiskSourceBlock{
   192  								Dev: "/dev/sda1",
   193  							},
   194  						},
   195  						Target: &DomainDiskTarget{
   196  							Dev: "vdb",
   197  							Bus: "virtio",
   198  						},
   199  						Address: &DomainAddress{
   200  							PCI: &DomainAddressPCI{
   201  								Domain:   &diskAddr.Domain,
   202  								Bus:      &diskAddr.Bus,
   203  								Slot:     &diskAddr.Slot,
   204  								Function: &diskAddr.Function,
   205  							},
   206  						},
   207  					},
   208  					DomainDisk{
   209  						Device: "disk",
   210  						Auth: &DomainDiskAuth{
   211  							Username: "fred",
   212  							Secret: &DomainDiskSecret{
   213  								Type: "ceph",
   214  								UUID: "e49f09c9-119e-43fd-b5a9-000d41e65493",
   215  							},
   216  						},
   217  						Source: &DomainDiskSource{
   218  							Network: &DomainDiskSourceNetwork{
   219  								Protocol: "rbd",
   220  								Name:     "somepool/somevol",
   221  								Hosts: []DomainDiskSourceHost{
   222  									DomainDiskSourceHost{
   223  										Transport: "tcp",
   224  										Name:      "rbd1.example.com",
   225  										Port:      "3000",
   226  									},
   227  									DomainDiskSourceHost{
   228  										Transport: "tcp",
   229  										Name:      "rbd2.example.com",
   230  										Port:      "3000",
   231  									},
   232  								},
   233  							},
   234  						},
   235  						Target: &DomainDiskTarget{
   236  							Dev: "vdc",
   237  							Bus: "virtio",
   238  						},
   239  					},
   240  					DomainDisk{
   241  						Device: "disk",
   242  						Source: &DomainDiskSource{
   243  							Network: &DomainDiskSourceNetwork{
   244  								Protocol: "nbd",
   245  								Hosts: []DomainDiskSourceHost{
   246  									DomainDiskSourceHost{
   247  										Transport: "unix",
   248  										Socket:    "/var/run/nbd.sock",
   249  									},
   250  								},
   251  							},
   252  						},
   253  						Target: &DomainDiskTarget{
   254  							Dev: "vdd",
   255  							Bus: "virtio",
   256  						},
   257  						Shareable: &DomainDiskShareable{},
   258  					},
   259  					DomainDisk{
   260  						Device: "cdrom",
   261  						Driver: &DomainDiskDriver{
   262  							Cache:       "none",
   263  							IO:          "native",
   264  							ErrorPolicy: "stop",
   265  						},
   266  						Source: &DomainDiskSource{
   267  							Volume: &DomainDiskSourceVolume{
   268  								Pool:   "default",
   269  								Volume: "myvolume",
   270  							},
   271  						},
   272  						Target: &DomainDiskTarget{
   273  							Dev: "vde",
   274  							Bus: "virtio",
   275  						},
   276  						ReadOnly: &DomainDiskReadOnly{},
   277  					},
   278  				},
   279  			},
   280  		},
   281  		Expected: []string{
   282  			`<domain type="kvm">`,
   283  			`  <name>test</name>`,
   284  			`  <title>Test</title>`,
   285  			`  <description>A test guest config</description>`,
   286  			`  <metadata>` +
   287  				`<myvalue xmlns='http://myapp.com/schemeas/my/1.0'><widget name='foo'/></myvalue>` +
   288  				`<myothervalue xmlns='http://myotherapp.com/schemeas/my/1.0'><gizmo name='foo'/></myothervalue>` +
   289  				`</metadata>`,
   290  			`  <devices>`,
   291  			`    <disk type="file" device="cdrom">`,
   292  			`      <driver name="qemu" type="qcow2"></driver>`,
   293  			`      <source file="/var/lib/libvirt/images/demo.qcow2"></source>`,
   294  			`      <target dev="vda" bus="virtio"></target>`,
   295  			`      <serial>fishfood</serial>`,
   296  			`      <boot order="1"></boot>`,
   297  			`    </disk>`,
   298  			`    <disk type="block" device="disk">`,
   299  			`      <driver name="qemu" type="raw"></driver>`,
   300  			`      <source dev="/dev/sda1"></source>`,
   301  			`      <target dev="vdb" bus="virtio"></target>`,
   302  			`      <address type="pci" domain="0x0000" bus="0x00" slot="0x03" function="0x0"></address>`,
   303  			`    </disk>`,
   304  			`    <disk type="network" device="disk">`,
   305  			`      <auth username="fred">`,
   306  			`        <secret type="ceph" uuid="e49f09c9-119e-43fd-b5a9-000d41e65493"></secret>`,
   307  			`      </auth>`,
   308  			`      <source protocol="rbd" name="somepool/somevol">`,
   309  			`        <host transport="tcp" name="rbd1.example.com" port="3000"></host>`,
   310  			`        <host transport="tcp" name="rbd2.example.com" port="3000"></host>`,
   311  			`      </source>`,
   312  			`      <target dev="vdc" bus="virtio"></target>`,
   313  			`    </disk>`,
   314  			`    <disk type="network" device="disk">`,
   315  			`      <source protocol="nbd">`,
   316  			`        <host transport="unix" socket="/var/run/nbd.sock"></host>`,
   317  			`      </source>`,
   318  			`      <target dev="vdd" bus="virtio"></target>`,
   319  			`      <shareable></shareable>`,
   320  			`    </disk>`,
   321  			`    <disk type="volume" device="cdrom">`,
   322  			`      <driver cache="none" error_policy="stop" io="native"></driver>`,
   323  			`      <source pool="default" volume="myvolume"></source>`,
   324  			`      <target dev="vde" bus="virtio"></target>`,
   325  			`      <readonly></readonly>`,
   326  			`    </disk>`,
   327  			`  </devices>`,
   328  			`</domain>`,
   329  		},
   330  	},
   331  	{
   332  		Object: &Domain{
   333  			Type: "kvm",
   334  			Name: "test",
   335  			Devices: &DomainDeviceList{
   336  				Inputs: []DomainInput{
   337  					DomainInput{
   338  						Type: "tablet",
   339  						Bus:  "usb",
   340  						Address: &DomainAddress{
   341  							USB: &DomainAddressUSB{
   342  								Bus:  &tabletBus,
   343  								Port: tabletPort,
   344  							},
   345  						},
   346  					},
   347  					DomainInput{
   348  						Type: "keyboard",
   349  						Bus:  "ps2",
   350  					},
   351  				},
   352  				Videos: []DomainVideo{
   353  					DomainVideo{
   354  						Model: DomainVideoModel{
   355  							Type:   "cirrus",
   356  							Heads:  1,
   357  							Ram:    4096,
   358  							VRam:   8192,
   359  							VGAMem: 256,
   360  						},
   361  						Address: &DomainAddress{
   362  							PCI: &DomainAddressPCI{
   363  								Domain:   &videoAddr.Domain,
   364  								Bus:      &videoAddr.Bus,
   365  								Slot:     &videoAddr.Slot,
   366  								Function: &videoAddr.Function,
   367  							},
   368  						},
   369  					},
   370  				},
   371  				TPMs: []DomainTPM{
   372  					DomainTPM{
   373  						Model: "tpm-tis",
   374  						Backend: &DomainTPMBackend{
   375  							Passthrough: &DomainTPMBackendPassthrough{
   376  								Device: &DomainTPMBackendDevice{
   377  									Path: "/dev/tpm0",
   378  								},
   379  							},
   380  						},
   381  					},
   382  				},
   383  				Graphics: []DomainGraphic{
   384  					DomainGraphic{
   385  						VNC: &DomainGraphicVNC{},
   386  					},
   387  				},
   388  				MemBalloon: &DomainMemBalloon{
   389  					Model: "virtio",
   390  					Address: &DomainAddress{
   391  						PCI: &DomainAddressPCI{
   392  							Domain:   &balloonAddr.Domain,
   393  							Bus:      &balloonAddr.Bus,
   394  							Slot:     &balloonAddr.Slot,
   395  							Function: &balloonAddr.Function,
   396  						},
   397  					},
   398  				},
   399  				Panics: []DomainPanic{
   400  					DomainPanic{
   401  						Model: "hyperv",
   402  					},
   403  					DomainPanic{
   404  						Model: "isa",
   405  						Address: &DomainAddress{
   406  							ISA: &DomainAddressISA{
   407  								IOBase: &panicAddr.IOBase,
   408  							},
   409  						},
   410  					},
   411  				},
   412  				Consoles: []DomainConsole{
   413  					DomainConsole{
   414  						Source: &DomainChardevSource{
   415  							Pty: &DomainChardevSourcePty{},
   416  						},
   417  						Target: &DomainConsoleTarget{
   418  							Type: "virtio",
   419  							Port: &serialPort,
   420  						},
   421  					},
   422  				},
   423  				Serials: []DomainSerial{
   424  					DomainSerial{
   425  						Source: &DomainChardevSource{
   426  							Pty: &DomainChardevSourcePty{},
   427  						},
   428  						Target: &DomainSerialTarget{
   429  							Type: "isa",
   430  							Port: &serialPort,
   431  						},
   432  					},
   433  					DomainSerial{
   434  						Source: &DomainChardevSource{
   435  							File: &DomainChardevSourceFile{
   436  								Path:   "/tmp/serial.log",
   437  								Append: "off",
   438  							},
   439  						},
   440  						Target: &DomainSerialTarget{
   441  							Port: &serialPort,
   442  						},
   443  					},
   444  					DomainSerial{
   445  						Source: &DomainChardevSource{
   446  							TCP: &DomainChardevSourceTCP{
   447  								Mode:    "bind",
   448  								Host:    "127.0.0.1",
   449  								Service: "1234",
   450  								TLS:     "yes",
   451  							},
   452  						},
   453  						Protocol: &DomainChardevProtocol{
   454  							Type: "telnet",
   455  						},
   456  						Target: &DomainSerialTarget{
   457  							Port: &serialPort,
   458  						},
   459  					},
   460  				},
   461  				Channels: []DomainChannel{
   462  					DomainChannel{
   463  						Source: &DomainChardevSource{
   464  							Pty: &DomainChardevSourcePty{},
   465  						},
   466  						Target: &DomainChannelTarget{
   467  							VirtIO: &DomainChannelTargetVirtIO{
   468  								Name:  "org.redhat.spice",
   469  								State: "connected",
   470  							},
   471  						},
   472  					},
   473  				},
   474  				Sounds: []DomainSound{
   475  					DomainSound{
   476  						Model: "ich6",
   477  						Codec: []DomainSoundCodec{
   478  							DomainSoundCodec{
   479  								Type: "duplex",
   480  							},
   481  						},
   482  						Address: &DomainAddress{
   483  							PCI: &DomainAddressPCI{
   484  								Domain:   &duplexAddr.Domain,
   485  								Bus:      &duplexAddr.Bus,
   486  								Slot:     &duplexAddr.Slot,
   487  								Function: &duplexAddr.Function,
   488  							},
   489  						},
   490  					},
   491  				},
   492  				RedirDevs: []DomainRedirDev{
   493  					DomainRedirDev{
   494  						Bus: "usb",
   495  						Source: &DomainChardevSource{
   496  							SpiceVMC: &DomainChardevSourceSpiceVMC{},
   497  						},
   498  						Address: &DomainAddress{
   499  							USB: &DomainAddressUSB{
   500  								Bus:  &redirBus,
   501  								Port: redirPort,
   502  							},
   503  						},
   504  					},
   505  				},
   506  				RedirFilters: []DomainRedirFilter{
   507  					DomainRedirFilter{
   508  						USB: []DomainRedirFilterUSB{
   509  							DomainRedirFilterUSB{
   510  								Class:   &redirfilterClass,
   511  								Product: &redirfilterProduct,
   512  								Vendor:  &redirfilterVendor,
   513  								Version: "1.10",
   514  								Allow:   "yes",
   515  							},
   516  							DomainRedirFilterUSB{
   517  								Version: "1.10",
   518  								Allow:   "no",
   519  							},
   520  							DomainRedirFilterUSB{
   521  								Allow: "yes",
   522  							},
   523  						},
   524  					},
   525  				},
   526  				RNGs: []DomainRNG{
   527  					DomainRNG{
   528  						Model: "virtio",
   529  						Rate: &DomainRNGRate{
   530  							Period: 2000,
   531  							Bytes:  1234,
   532  						},
   533  						Backend: &DomainRNGBackend{
   534  							EGD: &DomainRNGBackendEGD{
   535  								Source: &DomainChardevSource{
   536  									Dev: &DomainChardevSourceDev{
   537  										Path: "/dev/ttyS0",
   538  									},
   539  								},
   540  								Protocol: &DomainChardevProtocol{
   541  									Type: "raw",
   542  								},
   543  							},
   544  						},
   545  					},
   546  				},
   547  				Memorydevs: []DomainMemorydev{
   548  					DomainMemorydev{
   549  						Model:  "dimm",
   550  						Access: "private",
   551  						Target: &DomainMemorydevTarget{
   552  							Size: &DomainMemorydevTargetSize{
   553  								Value: 1,
   554  								Unit:  "GiB",
   555  							},
   556  							Node: &DomainMemorydevTargetNode{
   557  								Value: 0,
   558  							},
   559  						},
   560  						Address: &DomainAddress{
   561  							DIMM: &DomainAddressDIMM{
   562  								Slot: &memorydevAddressSlot,
   563  								Base: &memorydevAddressBase,
   564  							},
   565  						},
   566  					},
   567  				},
   568  			},
   569  		},
   570  		Expected: []string{
   571  			`<domain type="kvm">`,
   572  			`  <name>test</name>`,
   573  			`  <devices>`,
   574  			`    <serial type="pty">`,
   575  			`      <target type="isa" port="0"></target>`,
   576  			`    </serial>`,
   577  			`    <serial type="file">`,
   578  			`      <source path="/tmp/serial.log" append="off"></source>`,
   579  			`      <target port="0"></target>`,
   580  			`    </serial>`,
   581  			`    <serial type="tcp">`,
   582  			`      <source mode="bind" host="127.0.0.1" service="1234" tls="yes"></source>`,
   583  			`      <protocol type="telnet"></protocol>`,
   584  			`      <target port="0"></target>`,
   585  			`    </serial>`,
   586  			`    <console type="pty">`,
   587  			`      <target type="virtio" port="0"></target>`,
   588  			`    </console>`,
   589  			`    <channel type="pty">`,
   590  			`      <target type="virtio" name="org.redhat.spice" state="connected"></target>`,
   591  			`    </channel>`,
   592  			`    <input type="tablet" bus="usb">`,
   593  			`      <address type="usb" bus="0" port="1.1"></address>`,
   594  			`    </input>`,
   595  			`    <input type="keyboard" bus="ps2"></input>`,
   596  			`    <tpm model="tpm-tis">`,
   597  			`      <backend type="passthrough">`,
   598  			`        <device path="/dev/tpm0"></device>`,
   599  			`      </backend>`,
   600  			`    </tpm>`,
   601  			`    <graphics type="vnc"></graphics>`,
   602  			`    <sound model="ich6">`,
   603  			`      <codec type="duplex"></codec>`,
   604  			`      <address type="pci" domain="0x0000" bus="0x00" slot="0x08" function="0x0"></address>`,
   605  			`    </sound>`,
   606  			`    <video>`,
   607  			`      <model type="cirrus" heads="1" ram="4096" vram="8192" vgamem="256"></model>`,
   608  			`      <address type="pci" domain="0x0000" bus="0x00" slot="0x05" function="0x0"></address>`,
   609  			`    </video>`,
   610  			`    <redirdev type="spicevmc" bus="usb">`,
   611  			`      <address type="usb" bus="0" port="3"></address>`,
   612  			`    </redirdev>`,
   613  			`    <redirfilter>`,
   614  			`      <usbdev class="0x08" vendor="0x15e1" product="0x2007" version="1.10" allow="yes"></usbdev>`,
   615  			`      <usbdev version="1.10" allow="no"></usbdev>`,
   616  			`      <usbdev allow="yes"></usbdev>`,
   617  			`    </redirfilter>`,
   618  			`    <memballoon model="virtio">`,
   619  			`      <address type="pci" domain="0x0000" bus="0x00" slot="0x07" function="0x0"></address>`,
   620  			`    </memballoon>`,
   621  			`    <rng model="virtio">`,
   622  			`      <rate bytes="1234" period="2000"></rate>`,
   623  			`      <backend model="egd" type="dev">`,
   624  			`        <source path="/dev/ttyS0"></source>`,
   625  			`        <protocol type="raw"></protocol>`,
   626  			`      </backend>`,
   627  			`    </rng>`,
   628  			`    <panic model="hyperv"></panic>`,
   629  			`    <panic model="isa">`,
   630  			`      <address type="isa" iobase="0x505"></address>`,
   631  			`    </panic>`,
   632  			`    <memory model="dimm" access="private">`,
   633  			`      <target>`,
   634  			`        <size unit="GiB">1</size>`,
   635  			`        <node>0</node>`,
   636  			`      </target>`,
   637  			`      <address type="dimm" slot="0" base="0x100000000"></address>`,
   638  			`    </memory>`,
   639  			`  </devices>`,
   640  			`</domain>`,
   641  		},
   642  	},
   643  	{
   644  		Object: &Domain{
   645  			Type: "kvm",
   646  			Name: "test",
   647  			Memory: &DomainMemory{
   648  				Unit:     "KiB",
   649  				Value:    8192,
   650  				DumpCore: "yes",
   651  			},
   652  			CurrentMemory: &DomainCurrentMemory{
   653  				Unit:  "KiB",
   654  				Value: 4096,
   655  			},
   656  			MaximumMemory: &DomainMaxMemory{
   657  				Unit:  "KiB",
   658  				Value: 16384,
   659  				Slots: 2,
   660  			},
   661  			MemoryBacking: &DomainMemoryBacking{
   662  				MemoryHugePages: &DomainMemoryHugepages{
   663  					Hugepages: []DomainMemoryHugepage{
   664  						{
   665  							Size:    1,
   666  							Unit:    "G",
   667  							Nodeset: "0-3,5",
   668  						},
   669  						{
   670  							Size:    2,
   671  							Unit:    "M",
   672  							Nodeset: "4",
   673  						},
   674  					},
   675  				},
   676  				MemoryNosharepages: &DomainMemoryNosharepages{},
   677  				MemoryLocked:       &DomainMemoryLocked{},
   678  				MemorySource: &DomainMemorySource{
   679  					Type: "file",
   680  				},
   681  				MemoryAccess: &DomainMemoryAccess{
   682  					Mode: "shared",
   683  				},
   684  				MemoryAllocation: &DomainMemoryAllocation{
   685  					Mode: "immediate",
   686  				},
   687  			},
   688  			OS: &DomainOS{
   689  				Type: &DomainOSType{
   690  					Arch:    "x86_64",
   691  					Machine: "pc",
   692  					Type:    "hvm",
   693  				},
   694  				BootDevices: []DomainBootDevice{
   695  					DomainBootDevice{
   696  						Dev: "hd",
   697  					},
   698  				},
   699  				Loader: &DomainLoader{
   700  					Readonly: "yes",
   701  					Secure:   "no",
   702  					Type:     "rom",
   703  					Path:     "/loader",
   704  				},
   705  				DTB: "/some/path",
   706  				ACPI: &DomainACPI{
   707  					Tables: []DomainACPITable{
   708  						DomainACPITable{
   709  							Type: "slic",
   710  							Path: "/some/data",
   711  						},
   712  					},
   713  				},
   714  				SMBios: &DomainSMBios{
   715  					Mode: "sysinfo",
   716  				},
   717  				BIOS: &DomainBIOS{
   718  					UseSerial:     "yes",
   719  					RebootTimeout: &rebootTimeout,
   720  				},
   721  				Init: "/bin/systemd",
   722  				InitArgs: []string{
   723  					"--unit",
   724  					"emergency.service",
   725  				},
   726  				InitEnv: []DomainOSInitEnv{
   727  					DomainOSInitEnv{
   728  						Name:  "HOME",
   729  						Value: "/home/fred",
   730  					},
   731  					DomainOSInitEnv{
   732  						Name:  "USER",
   733  						Value: "fred",
   734  					},
   735  				},
   736  				InitUser:  "fred",
   737  				InitGroup: "fred",
   738  				InitDir:   "/home/fred",
   739  			},
   740  			SysInfo: []DomainSysInfo{
   741  				DomainSysInfo{
   742  					SMBIOS: &DomainSysInfoSMBIOS{
   743  						BIOS: &DomainSysInfoBIOS{
   744  							Entry: []DomainSysInfoEntry{
   745  								DomainSysInfoEntry{
   746  									Name:  "vendor",
   747  									Value: "vendor",
   748  								},
   749  							},
   750  						},
   751  						System: &DomainSysInfoSystem{
   752  							Entry: []DomainSysInfoEntry{
   753  								DomainSysInfoEntry{
   754  									Name:  "manufacturer",
   755  									Value: "manufacturer",
   756  								},
   757  								DomainSysInfoEntry{
   758  									Name:  "product",
   759  									Value: "product",
   760  								},
   761  								DomainSysInfoEntry{
   762  									Name:  "version",
   763  									Value: "version",
   764  								},
   765  							},
   766  						},
   767  						BaseBoard: []DomainSysInfoBaseBoard{
   768  							DomainSysInfoBaseBoard{
   769  								Entry: []DomainSysInfoEntry{
   770  									DomainSysInfoEntry{
   771  										Name:  "manufacturer",
   772  										Value: "manufacturer",
   773  									},
   774  									DomainSysInfoEntry{
   775  										Name:  "product",
   776  										Value: "product",
   777  									},
   778  									DomainSysInfoEntry{
   779  										Name:  "version",
   780  										Value: "version",
   781  									},
   782  									DomainSysInfoEntry{
   783  										Name:  "serial",
   784  										Value: "serial",
   785  									},
   786  								},
   787  							},
   788  						},
   789  					},
   790  				},
   791  				DomainSysInfo{
   792  					FWCfg: &DomainSysInfoFWCfg{
   793  						Entry: []DomainSysInfoEntry{
   794  							DomainSysInfoEntry{
   795  								Name:  "vendor",
   796  								Value: "vendor",
   797  							},
   798  							DomainSysInfoEntry{
   799  								Name: "installer",
   800  								File: "/some/path.cfg",
   801  							},
   802  						},
   803  					},
   804  				},
   805  			},
   806  			Clock: &DomainClock{
   807  				Offset:     "variable",
   808  				Basis:      "utc",
   809  				Adjustment: "28794",
   810  				TimeZone:   "Europe/Paris",
   811  				Timer: []DomainTimer{
   812  					DomainTimer{
   813  						Name:       "rtc",
   814  						Track:      "boot",
   815  						TickPolicy: "catchup",
   816  						CatchUp: &DomainTimerCatchUp{
   817  							Threshold: 123,
   818  							Slew:      120,
   819  							Limit:     10000,
   820  						},
   821  						Frequency: 120,
   822  						Mode:      "auto",
   823  					},
   824  				},
   825  			},
   826  		},
   827  		Expected: []string{
   828  			`<domain type="kvm">`,
   829  			`  <name>test</name>`,
   830  			`  <maxMemory unit="KiB" slots="2">16384</maxMemory>`,
   831  			`  <memory unit="KiB" dumpCore="yes">8192</memory>`,
   832  			`  <currentMemory unit="KiB">4096</currentMemory>`,
   833  			`  <memoryBacking>`,
   834  			`    <hugepages>`,
   835  			`      <page size="1" unit="G" nodeset="0-3,5"></page>`,
   836  			`      <page size="2" unit="M" nodeset="4"></page>`,
   837  			`    </hugepages>`,
   838  			`    <nosharepages></nosharepages>`,
   839  			`    <locked></locked>`,
   840  			`    <source type="file"></source>`,
   841  			`    <access mode="shared"></access>`,
   842  			`    <allocation mode="immediate"></allocation>`,
   843  			`  </memoryBacking>`,
   844  			`  <sysinfo type="smbios">`,
   845  			`    <bios>`,
   846  			`      <entry name="vendor">vendor</entry>`,
   847  			`    </bios>`,
   848  			`    <system>`,
   849  			`      <entry name="manufacturer">manufacturer</entry>`,
   850  			`      <entry name="product">product</entry>`,
   851  			`      <entry name="version">version</entry>`,
   852  			`    </system>`,
   853  			`    <baseBoard>`,
   854  			`      <entry name="manufacturer">manufacturer</entry>`,
   855  			`      <entry name="product">product</entry>`,
   856  			`      <entry name="version">version</entry>`,
   857  			`      <entry name="serial">serial</entry>`,
   858  			`    </baseBoard>`,
   859  			`  </sysinfo>`,
   860  			`  <sysinfo type="fwcfg">`,
   861  			`    <entry name="vendor">vendor</entry>`,
   862  			`    <entry name="installer" file="/some/path.cfg"></entry>`,
   863  			`  </sysinfo>`,
   864  			`  <os>`,
   865  			`    <type arch="x86_64" machine="pc">hvm</type>`,
   866  			`    <init>/bin/systemd</init>`,
   867  			`    <initarg>--unit</initarg>`,
   868  			`    <initarg>emergency.service</initarg>`,
   869  			`    <initenv name="HOME">/home/fred</initenv>`,
   870  			`    <initenv name="USER">fred</initenv>`,
   871  			`    <initdir>/home/fred</initdir>`,
   872  			`    <inituser>fred</inituser>`,
   873  			`    <initgroup>fred</initgroup>`,
   874  			`    <loader readonly="yes" secure="no" type="rom">/loader</loader>`,
   875  			`    <dtb>/some/path</dtb>`,
   876  			`    <acpi>`,
   877  			`      <table type="slic">/some/data</table>`,
   878  			`    </acpi>`,
   879  			`    <boot dev="hd"></boot>`,
   880  			`    <bios useserial="yes" rebootTimeout="0"></bios>`,
   881  			`    <smbios mode="sysinfo"></smbios>`,
   882  			`  </os>`,
   883  			`  <clock offset="variable" basis="utc" adjustment="28794" timezone="Europe/Paris">`,
   884  			`    <timer name="rtc" track="boot" tickpolicy="catchup" frequency="120" mode="auto">`,
   885  			`      <catchup threshold="123" slew="120" limit="10000"></catchup>`,
   886  			`    </timer>`,
   887  			`  </clock>`,
   888  			`</domain>`,
   889  		},
   890  	},
   891  	{
   892  		Object: &Domain{
   893  			Type: "kvm",
   894  			Name: "test",
   895  			Clock: &DomainClock{
   896  				Offset:     "variable",
   897  				Basis:      "utc",
   898  				Adjustment: "reset",
   899  			},
   900  		},
   901  		Expected: []string{
   902  			`<domain type="kvm">`,
   903  			`  <name>test</name>`,
   904  			`  <clock offset="variable" basis="utc" adjustment="reset"></clock>`,
   905  			`</domain>`,
   906  		},
   907  	},
   908  	{
   909  		Object: &Domain{
   910  			Type: "kvm",
   911  			Name: "test",
   912  			OS: &DomainOS{
   913  				NVRam: &DomainNVRam{
   914  					Template: "/t.fd",
   915  					NVRam:    "/vars.fd",
   916  				},
   917  				BootMenu: &DomainBootMenu{
   918  					Enable:  "yes",
   919  					Timeout: "3000",
   920  				},
   921  			},
   922  		},
   923  		Expected: []string{
   924  			`<domain type="kvm">`,
   925  			`  <name>test</name>`,
   926  			`  <os>`,
   927  			`    <nvram template="/t.fd">/vars.fd</nvram>`,
   928  			`    <bootmenu enable="yes" timeout="3000"></bootmenu>`,
   929  			`  </os>`,
   930  			`</domain>`,
   931  		},
   932  	},
   933  	{
   934  		Object: &Domain{
   935  			Type: "kvm",
   936  			Name: "test",
   937  			BlockIOTune: &DomainBlockIOTune{
   938  				Weight: 900,
   939  				Device: []DomainBlockIOTuneDevice{
   940  					DomainBlockIOTuneDevice{
   941  						Path:          "/dev/sda",
   942  						Weight:        500,
   943  						ReadIopsSec:   300,
   944  						WriteIopsSec:  200,
   945  						ReadBytesSec:  3000,
   946  						WriteBytesSec: 2000,
   947  					},
   948  					DomainBlockIOTuneDevice{
   949  						Path:          "/dev/sdb",
   950  						Weight:        600,
   951  						ReadIopsSec:   100,
   952  						WriteIopsSec:  40,
   953  						ReadBytesSec:  1000,
   954  						WriteBytesSec: 400,
   955  					},
   956  				},
   957  			},
   958  		},
   959  		Expected: []string{
   960  			`<domain type="kvm">`,
   961  			`  <name>test</name>`,
   962  			`  <blkiotune>`,
   963  			`    <weight>900</weight>`,
   964  			`    <device>`,
   965  			`      <path>/dev/sda</path>`,
   966  			`      <weight>500</weight>`,
   967  			`      <read_iops_sec>300</read_iops_sec>`,
   968  			`      <write_iops_sec>200</write_iops_sec>`,
   969  			`      <read_bytes_sec>3000</read_bytes_sec>`,
   970  			`      <write_bytes_sec>2000</write_bytes_sec>`,
   971  			`    </device>`,
   972  			`    <device>`,
   973  			`      <path>/dev/sdb</path>`,
   974  			`      <weight>600</weight>`,
   975  			`      <read_iops_sec>100</read_iops_sec>`,
   976  			`      <write_iops_sec>40</write_iops_sec>`,
   977  			`      <read_bytes_sec>1000</read_bytes_sec>`,
   978  			`      <write_bytes_sec>400</write_bytes_sec>`,
   979  			`    </device>`,
   980  			`  </blkiotune>`,
   981  			`</domain>`,
   982  		},
   983  	},
   984  	{
   985  		Object: &Domain{
   986  			Type: "kvm",
   987  			Name: "test",
   988  			MemoryTune: &DomainMemoryTune{
   989  				HardLimit: &DomainMemoryTuneLimit{
   990  					Value: 1024,
   991  					Unit:  "MiB",
   992  				},
   993  				SoftLimit: &DomainMemoryTuneLimit{
   994  					Value: 1024,
   995  				},
   996  				MinGuarantee: &DomainMemoryTuneLimit{
   997  					Value: 1024,
   998  				},
   999  				SwapHardLimit: &DomainMemoryTuneLimit{
  1000  					Value: 1024,
  1001  				},
  1002  			},
  1003  		},
  1004  		Expected: []string{
  1005  			`<domain type="kvm">`,
  1006  			`  <name>test</name>`,
  1007  			`  <memtune>`,
  1008  			`    <hard_limit unit="MiB">1024</hard_limit>`,
  1009  			`    <soft_limit>1024</soft_limit>`,
  1010  			`    <min_guarantee>1024</min_guarantee>`,
  1011  			`    <swap_hard_limit>1024</swap_hard_limit>`,
  1012  			`  </memtune>`,
  1013  			`</domain>`,
  1014  		},
  1015  	},
  1016  	{
  1017  		Object: &Domain{
  1018  			Type: "kvm",
  1019  			Name: "test",
  1020  			PM: &DomainPM{
  1021  				SuspendToMem: &DomainPMPolicy{
  1022  					Enabled: "no",
  1023  				},
  1024  				SuspendToDisk: &DomainPMPolicy{
  1025  					Enabled: "yes",
  1026  				},
  1027  			},
  1028  		},
  1029  		Expected: []string{
  1030  			`<domain type="kvm">`,
  1031  			`  <name>test</name>`,
  1032  			`  <pm>`,
  1033  			`    <suspend-to-mem enabled="no"></suspend-to-mem>`,
  1034  			`    <suspend-to-disk enabled="yes"></suspend-to-disk>`,
  1035  			`  </pm>`,
  1036  			`</domain>`,
  1037  		},
  1038  	},
  1039  	{
  1040  		Object: &Domain{
  1041  			Type: "kvm",
  1042  			Name: "test",
  1043  			SecLabel: []DomainSecLabel{
  1044  				DomainSecLabel{
  1045  					Type:       "dynamic",
  1046  					Model:      "selinux",
  1047  					Relabel:    "yes",
  1048  					Label:      "system_u:system_r:svirt_t:s0:c143,c762",
  1049  					ImageLabel: "system_u:object_r:svirt_image_t:s0:c143,c762",
  1050  					BaseLabel:  "system_u:system_r:svirt_t:s0",
  1051  				},
  1052  				DomainSecLabel{
  1053  					Type:    "dynamic",
  1054  					Model:   "dac",
  1055  					Relabel: "no",
  1056  				},
  1057  			},
  1058  		},
  1059  		Expected: []string{
  1060  			`<domain type="kvm">`,
  1061  			`  <name>test</name>`,
  1062  			`  <seclabel type="dynamic" model="selinux" relabel="yes">`,
  1063  			`    <label>system_u:system_r:svirt_t:s0:c143,c762</label>`,
  1064  			`    <imagelabel>system_u:object_r:svirt_image_t:s0:c143,c762</imagelabel>`,
  1065  			`    <baselabel>system_u:system_r:svirt_t:s0</baselabel>`,
  1066  			`  </seclabel>`,
  1067  			`  <seclabel type="dynamic" model="dac" relabel="no"></seclabel>`,
  1068  			`</domain>`,
  1069  		},
  1070  	},
  1071  	{
  1072  		Object: &Domain{
  1073  			Type: "kvm",
  1074  			Name: "test",
  1075  			OS: &DomainOS{
  1076  				Kernel:  "/vmlinuz",
  1077  				Initrd:  "/initrd",
  1078  				Cmdline: "arg",
  1079  			},
  1080  		},
  1081  		Expected: []string{
  1082  			`<domain type="kvm">`,
  1083  			`  <name>test</name>`,
  1084  			`  <os>`,
  1085  			`    <kernel>/vmlinuz</kernel>`,
  1086  			`    <initrd>/initrd</initrd>`,
  1087  			`    <cmdline>arg</cmdline>`,
  1088  			`  </os>`,
  1089  			`</domain>`,
  1090  		},
  1091  	},
  1092  	{
  1093  		Object: &Domain{
  1094  			Type: "kvm",
  1095  			Name: "test",
  1096  			Resource: &DomainResource{
  1097  				Partition: "/machines/production",
  1098  			},
  1099  		},
  1100  		Expected: []string{
  1101  			`<domain type="kvm">`,
  1102  			`  <name>test</name>`,
  1103  			`  <resource>`,
  1104  			`    <partition>/machines/production</partition>`,
  1105  			`  </resource>`,
  1106  			`</domain>`,
  1107  		},
  1108  	},
  1109  	{
  1110  		Object: &Domain{
  1111  			Type: "kvm",
  1112  			Name: "test",
  1113  			VCPU: &DomainVCPU{
  1114  				Placement: "static",
  1115  				CPUSet:    "1-4,^3,6",
  1116  				Current:   1,
  1117  				Value:     2,
  1118  			},
  1119  			VCPUs: &DomainVCPUs{
  1120  				VCPU: []DomainVCPUsVCPU{
  1121  					DomainVCPUsVCPU{
  1122  						Id:           &vcpuId0,
  1123  						Enabled:      "yes",
  1124  						Hotpluggable: "no",
  1125  						Order:        &vcpuOrder0,
  1126  					},
  1127  					DomainVCPUsVCPU{
  1128  						Id:           &vcpuId1,
  1129  						Enabled:      "no",
  1130  						Hotpluggable: "yes",
  1131  						Order:        nil,
  1132  					},
  1133  				},
  1134  			},
  1135  			Devices: &DomainDeviceList{
  1136  				Interfaces: []DomainInterface{
  1137  					DomainInterface{
  1138  						MAC: &DomainInterfaceMAC{
  1139  							Address: "00:11:22:33:44:55",
  1140  						},
  1141  						Model: &DomainInterfaceModel{
  1142  							Type: "virtio",
  1143  						},
  1144  						Source: &DomainInterfaceSource{
  1145  							Network: &DomainInterfaceSourceNetwork{
  1146  								Network: "default",
  1147  							},
  1148  						},
  1149  					},
  1150  				},
  1151  			},
  1152  		},
  1153  		Expected: []string{
  1154  			`<domain type="kvm">`,
  1155  			`  <name>test</name>`,
  1156  			`  <vcpu placement="static" cpuset="1-4,^3,6" current="1">2</vcpu>`,
  1157  			`  <vcpus>`,
  1158  			`    <vcpu id="0" enabled="yes" hotpluggable="no" order="1"></vcpu>`,
  1159  			`    <vcpu id="1" enabled="no" hotpluggable="yes"></vcpu>`,
  1160  			`  </vcpus>`,
  1161  			`  <devices>`,
  1162  			`    <interface type="network">`,
  1163  			`      <mac address="00:11:22:33:44:55"></mac>`,
  1164  			`      <source network="default"></source>`,
  1165  			`      <model type="virtio"></model>`,
  1166  			`    </interface>`,
  1167  			`  </devices>`,
  1168  			`</domain>`,
  1169  		},
  1170  	},
  1171  	{
  1172  		Object: &Domain{
  1173  			Type: "kvm",
  1174  			Name: "test",
  1175  			CPU: &DomainCPU{
  1176  				Match: "exact",
  1177  				Check: "none",
  1178  				Model: &DomainCPUModel{
  1179  					Fallback: "allow",
  1180  					Value:    "core2duo",
  1181  					VendorID: "LibvirtQEMU",
  1182  				},
  1183  				Vendor: "Intel",
  1184  				Topology: &DomainCPUTopology{
  1185  					Sockets: 1,
  1186  					Cores:   2,
  1187  					Threads: 1,
  1188  				},
  1189  				Features: []DomainCPUFeature{
  1190  					DomainCPUFeature{Policy: "disable", Name: "lahf_lm"},
  1191  				},
  1192  				Cache: &DomainCPUCache{
  1193  					Level: 1,
  1194  					Mode:  "emulate",
  1195  				},
  1196  				Numa: &DomainNuma{
  1197  					[]DomainCell{
  1198  						{
  1199  							ID:        &cellID0,
  1200  							CPUs:      "0-1",
  1201  							Memory:    512000,
  1202  							Unit:      "KiB",
  1203  							MemAccess: "private",
  1204  							Distances: &DomainCellDistances{
  1205  								Siblings: []DomainCellSibling{
  1206  									DomainCellSibling{
  1207  										ID:    1,
  1208  										Value: 20,
  1209  									},
  1210  								},
  1211  							},
  1212  						},
  1213  						{
  1214  							ID:        &cellID1,
  1215  							CPUs:      "2-3",
  1216  							Memory:    512000,
  1217  							Unit:      "KiB",
  1218  							MemAccess: "private",
  1219  							Distances: &DomainCellDistances{
  1220  								Siblings: []DomainCellSibling{
  1221  									DomainCellSibling{
  1222  										ID:    0,
  1223  										Value: 20,
  1224  									},
  1225  								},
  1226  							},
  1227  						},
  1228  					},
  1229  					nil,
  1230  				},
  1231  			},
  1232  			Devices: &DomainDeviceList{
  1233  				Emulator: "/bin/qemu-kvm",
  1234  			},
  1235  		},
  1236  		Expected: []string{
  1237  			`<domain type="kvm">`,
  1238  			`  <name>test</name>`,
  1239  			`  <cpu match="exact" check="none">`,
  1240  			`    <model fallback="allow" vendor_id="LibvirtQEMU">core2duo</model>`,
  1241  			`    <vendor>Intel</vendor>`,
  1242  			`    <topology sockets="1" cores="2" threads="1"></topology>`,
  1243  			`    <cache level="1" mode="emulate"></cache>`,
  1244  			`    <feature policy="disable" name="lahf_lm"></feature>`,
  1245  			`    <numa>`,
  1246  			`      <cell id="0" cpus="0-1" memory="512000" unit="KiB" memAccess="private">`,
  1247  			`        <distances>`,
  1248  			`          <sibling id="1" value="20"></sibling>`,
  1249  			`        </distances>`,
  1250  			`      </cell>`,
  1251  			`      <cell id="1" cpus="2-3" memory="512000" unit="KiB" memAccess="private">`,
  1252  			`        <distances>`,
  1253  			`          <sibling id="0" value="20"></sibling>`,
  1254  			`        </distances>`,
  1255  			`      </cell>`,
  1256  			`    </numa>`,
  1257  			`  </cpu>`,
  1258  			`  <devices>`,
  1259  			`    <emulator>/bin/qemu-kvm</emulator>`,
  1260  			`  </devices>`,
  1261  			`</domain>`,
  1262  		},
  1263  	},
  1264  	{
  1265  		Object: &Domain{
  1266  			Type: "kvm",
  1267  			Name: "test",
  1268  			Devices: &DomainDeviceList{
  1269  				Interfaces: []DomainInterface{
  1270  					DomainInterface{
  1271  						MAC: &DomainInterfaceMAC{
  1272  							Address: "06:39:b4:00:00:46",
  1273  						},
  1274  						Model: &DomainInterfaceModel{
  1275  							Type: "virtio",
  1276  						},
  1277  						Source: &DomainInterfaceSource{
  1278  							Bridge: &DomainInterfaceSourceBridge{
  1279  								Bridge: "private",
  1280  							},
  1281  						},
  1282  						Target: &DomainInterfaceTarget{
  1283  							Dev: "vnet3",
  1284  						},
  1285  						Alias: &DomainAlias{
  1286  							Name: "net1",
  1287  						},
  1288  					},
  1289  				},
  1290  			},
  1291  		},
  1292  		Expected: []string{
  1293  			`<domain type="kvm">`,
  1294  			`  <name>test</name>`,
  1295  			`  <devices>`,
  1296  			`    <interface type="bridge">`,
  1297  			`      <mac address="06:39:b4:00:00:46"></mac>`,
  1298  			`      <source bridge="private"></source>`,
  1299  			`      <target dev="vnet3"></target>`,
  1300  			`      <model type="virtio"></model>`,
  1301  			`      <alias name="net1"></alias>`,
  1302  			`    </interface>`,
  1303  			`  </devices>`,
  1304  			`</domain>`,
  1305  		},
  1306  	},
  1307  	{
  1308  		Object: &Domain{
  1309  			Type: "vmware",
  1310  			Name: "test",
  1311  			Devices: &DomainDeviceList{
  1312  				Interfaces: []DomainInterface{
  1313  					DomainInterface{
  1314  						MAC: &DomainInterfaceMAC{
  1315  							Address: "06:39:b4:00:00:46",
  1316  						},
  1317  						Model: &DomainInterfaceModel{
  1318  							Type: "e1000",
  1319  						},
  1320  						Source: &DomainInterfaceSource{
  1321  							Bridge: &DomainInterfaceSourceBridge{
  1322  								Bridge: "",
  1323  							},
  1324  						},
  1325  					},
  1326  				},
  1327  			},
  1328  		},
  1329  		Expected: []string{
  1330  			`<domain type="vmware">`,
  1331  			`  <name>test</name>`,
  1332  			`  <devices>`,
  1333  			`    <interface type="bridge">`,
  1334  			`      <mac address="06:39:b4:00:00:46"></mac>`,
  1335  			`      <source bridge=""></source>`,
  1336  			`      <model type="e1000"></model>`,
  1337  			`    </interface>`,
  1338  			`  </devices>`,
  1339  			`</domain>`,
  1340  		},
  1341  	},
  1342  	{
  1343  		Object: &Domain{
  1344  			Type: "kvm",
  1345  			Name: "test",
  1346  			Devices: &DomainDeviceList{
  1347  				Interfaces: []DomainInterface{
  1348  					DomainInterface{
  1349  						MAC: &DomainInterfaceMAC{
  1350  							Address: "52:54:00:39:97:ac",
  1351  						},
  1352  						Model: &DomainInterfaceModel{
  1353  							Type: "e1000",
  1354  						},
  1355  						Source: &DomainInterfaceSource{
  1356  							Network: &DomainInterfaceSourceNetwork{
  1357  								Network: "default",
  1358  							},
  1359  						},
  1360  					},
  1361  				},
  1362  			},
  1363  		},
  1364  		Expected: []string{
  1365  			`<domain type="kvm">`,
  1366  			`  <name>test</name>`,
  1367  			`  <devices>`,
  1368  			`    <interface type="network">`,
  1369  			`      <mac address="52:54:00:39:97:ac"></mac>`,
  1370  			`      <source network="default"></source>`,
  1371  			`      <model type="e1000"></model>`,
  1372  			`    </interface>`,
  1373  			`  </devices>`,
  1374  			`</domain>`,
  1375  		},
  1376  	},
  1377  	{
  1378  		Object: &Domain{
  1379  			Type: "kvm",
  1380  			Name: "test",
  1381  			Devices: &DomainDeviceList{
  1382  				Interfaces: []DomainInterface{
  1383  					DomainInterface{
  1384  						MAC: &DomainInterfaceMAC{
  1385  							Address: "52:54:00:39:97:ac",
  1386  						},
  1387  						Model: &DomainInterfaceModel{
  1388  							Type: "virtio",
  1389  						},
  1390  						Source: &DomainInterfaceSource{
  1391  							UDP: &DomainInterfaceSourceUDP{
  1392  								Address: "127.0.0.1",
  1393  								Port:    1234,
  1394  								Local: &DomainInterfaceSourceLocal{
  1395  									Address: "127.0.0.1",
  1396  									Port:    1235,
  1397  								},
  1398  							},
  1399  						},
  1400  					},
  1401  				},
  1402  			},
  1403  		},
  1404  		Expected: []string{
  1405  			`<domain type="kvm">`,
  1406  			`  <name>test</name>`,
  1407  			`  <devices>`,
  1408  			`    <interface type="udp">`,
  1409  			`      <mac address="52:54:00:39:97:ac"></mac>`,
  1410  			`      <source address="127.0.0.1" port="1234">`,
  1411  			`        <local address="127.0.0.1" port="1235"></local>`,
  1412  			`      </source>`,
  1413  			`      <model type="virtio"></model>`,
  1414  			`    </interface>`,
  1415  			`  </devices>`,
  1416  			`</domain>`,
  1417  		},
  1418  	},
  1419  	{
  1420  		Object: &Domain{
  1421  			Type: "kvm",
  1422  			Name: "test",
  1423  			Devices: &DomainDeviceList{
  1424  				Interfaces: []DomainInterface{
  1425  					DomainInterface{
  1426  						Source: &DomainInterfaceSource{
  1427  							Direct: &DomainInterfaceSourceDirect{
  1428  								Dev:  "eth0",
  1429  								Mode: "bridge",
  1430  							},
  1431  						},
  1432  						VirtualPort: &DomainInterfaceVirtualPort{
  1433  							Params: &DomainInterfaceVirtualPortParams{
  1434  								VEPA8021QBG: &DomainInterfaceVirtualPortParamsVEPA8021QBG{
  1435  									ManagerID:     &vepaManagerID,
  1436  									TypeID:        &vepaTypeID,
  1437  									TypeIDVersion: &vepaTypeIDVersion,
  1438  									InstanceID:    vepaInstanceID,
  1439  								},
  1440  							},
  1441  						},
  1442  					},
  1443  				},
  1444  			},
  1445  		},
  1446  		Expected: []string{
  1447  			`<domain type="kvm">`,
  1448  			`  <name>test</name>`,
  1449  			`  <devices>`,
  1450  			`    <interface type="direct">`,
  1451  			`      <source dev="eth0" mode="bridge"></source>`,
  1452  			`      <virtualport type="802.1Qbg">`,
  1453  			`        <parameters managerid="5" typeid="3" typeidversion="12" instanceid="c7bb5ab2-d42f-4690-89d6-f590eb199d0f"></parameters>`,
  1454  			`      </virtualport>`,
  1455  			`    </interface>`,
  1456  			`  </devices>`,
  1457  			`</domain>`,
  1458  		},
  1459  	},
  1460  	{
  1461  		Object: &Domain{
  1462  			Type: "kvm",
  1463  			Name: "test",
  1464  			Devices: &DomainDeviceList{
  1465  				Interfaces: []DomainInterface{
  1466  					DomainInterface{
  1467  						Source: &DomainInterfaceSource{
  1468  							Direct: &DomainInterfaceSourceDirect{
  1469  								Dev:  "eth0",
  1470  								Mode: "bridge",
  1471  							},
  1472  						},
  1473  						VirtualPort: &DomainInterfaceVirtualPort{
  1474  							Params: &DomainInterfaceVirtualPortParams{
  1475  								VNTag8011QBH: &DomainInterfaceVirtualPortParamsVNTag8021QBH{
  1476  									ProfileID: vntagProfileID,
  1477  								},
  1478  							},
  1479  						},
  1480  					},
  1481  				},
  1482  			},
  1483  		},
  1484  		Expected: []string{
  1485  			`<domain type="kvm">`,
  1486  			`  <name>test</name>`,
  1487  			`  <devices>`,
  1488  			`    <interface type="direct">`,
  1489  			`      <source dev="eth0" mode="bridge"></source>`,
  1490  			`      <virtualport type="802.1Qbh">`,
  1491  			`        <parameters profileid="c7bb5ab2-d42f-4690-89d6-f590eb199d0f"></parameters>`,
  1492  			`      </virtualport>`,
  1493  			`    </interface>`,
  1494  			`  </devices>`,
  1495  			`</domain>`,
  1496  		},
  1497  	},
  1498  	{
  1499  		Object: &Domain{
  1500  			Type: "kvm",
  1501  			Name: "test",
  1502  			Devices: &DomainDeviceList{
  1503  				Interfaces: []DomainInterface{
  1504  					DomainInterface{
  1505  						Source: &DomainInterfaceSource{
  1506  							Direct: &DomainInterfaceSourceDirect{
  1507  								Dev:  "eth0",
  1508  								Mode: "bridge",
  1509  							},
  1510  						},
  1511  						VirtualPort: &DomainInterfaceVirtualPort{
  1512  							Params: &DomainInterfaceVirtualPortParams{
  1513  								OpenVSwitch: &DomainInterfaceVirtualPortParamsOpenVSwitch{
  1514  									ProfileID:   ovsProfileID,
  1515  									InterfaceID: ovsInterfaceID,
  1516  								},
  1517  							},
  1518  						},
  1519  					},
  1520  				},
  1521  			},
  1522  		},
  1523  		Expected: []string{
  1524  			`<domain type="kvm">`,
  1525  			`  <name>test</name>`,
  1526  			`  <devices>`,
  1527  			`    <interface type="direct">`,
  1528  			`      <source dev="eth0" mode="bridge"></source>`,
  1529  			`      <virtualport type="openvswitch">`,
  1530  			`        <parameters interfaceid="73728ac4-53d9-44de-8438-8d8f90beca00" profileid="c7bb5ab2-d42f-4690-89d6-f590eb199d0f"></parameters>`,
  1531  			`      </virtualport>`,
  1532  			`    </interface>`,
  1533  			`  </devices>`,
  1534  			`</domain>`,
  1535  		},
  1536  	},
  1537  	{
  1538  		Object: &Domain{
  1539  			Type: "kvm",
  1540  			Name: "test",
  1541  			Devices: &DomainDeviceList{
  1542  				Interfaces: []DomainInterface{
  1543  					DomainInterface{
  1544  						Source: &DomainInterfaceSource{
  1545  							Direct: &DomainInterfaceSourceDirect{
  1546  								Dev:  "eth0",
  1547  								Mode: "bridge",
  1548  							},
  1549  						},
  1550  						VirtualPort: &DomainInterfaceVirtualPort{
  1551  							Params: &DomainInterfaceVirtualPortParams{
  1552  								MidoNet: &DomainInterfaceVirtualPortParamsMidoNet{
  1553  									InterfaceID: midoInterfaceID,
  1554  								},
  1555  							},
  1556  						},
  1557  					},
  1558  				},
  1559  			},
  1560  		},
  1561  		Expected: []string{
  1562  			`<domain type="kvm">`,
  1563  			`  <name>test</name>`,
  1564  			`  <devices>`,
  1565  			`    <interface type="direct">`,
  1566  			`      <source dev="eth0" mode="bridge"></source>`,
  1567  			`      <virtualport type="midonet">`,
  1568  			`        <parameters interfaceid="73728ac4-53d9-44de-8438-8d8f90beca00"></parameters>`,
  1569  			`      </virtualport>`,
  1570  			`    </interface>`,
  1571  			`  </devices>`,
  1572  			`</domain>`,
  1573  		},
  1574  	},
  1575  	{
  1576  		Object: &Domain{
  1577  			Type: "kvm",
  1578  			Name: "test",
  1579  			Devices: &DomainDeviceList{
  1580  				Interfaces: []DomainInterface{
  1581  					DomainInterface{
  1582  						MAC: &DomainInterfaceMAC{
  1583  							Address: "52:54:00:39:97:ac",
  1584  						},
  1585  						Model: &DomainInterfaceModel{
  1586  							Type: "virtio",
  1587  						},
  1588  						Source: &DomainInterfaceSource{
  1589  							User: &DomainInterfaceSourceUser{},
  1590  						},
  1591  						Link: &DomainInterfaceLink{
  1592  							State: "up",
  1593  						},
  1594  						Boot: &DomainDeviceBoot{
  1595  							Order: 1,
  1596  						},
  1597  						Driver: &DomainInterfaceDriver{
  1598  							Name:   "vhost",
  1599  							Queues: 5,
  1600  						},
  1601  					},
  1602  				},
  1603  			},
  1604  		},
  1605  		Expected: []string{
  1606  			`<domain type="kvm">`,
  1607  			`  <name>test</name>`,
  1608  			`  <devices>`,
  1609  			`    <interface type="user">`,
  1610  			`      <mac address="52:54:00:39:97:ac"></mac>`,
  1611  			`      <boot order="1"></boot>`,
  1612  			`      <model type="virtio"></model>`,
  1613  			`      <driver name="vhost" queues="5"></driver>`,
  1614  			`      <link state="up"></link>`,
  1615  			`    </interface>`,
  1616  			`  </devices>`,
  1617  			`</domain>`,
  1618  		},
  1619  	},
  1620  	{
  1621  		Object: &Domain{
  1622  			Type: "kvm",
  1623  			Name: "test",
  1624  			Devices: &DomainDeviceList{
  1625  				Interfaces: []DomainInterface{
  1626  					DomainInterface{
  1627  						MAC: &DomainInterfaceMAC{
  1628  							Address: "52:54:00:39:97:ac",
  1629  						},
  1630  						Model: &DomainInterfaceModel{
  1631  							Type: "virtio",
  1632  						},
  1633  						Source: &DomainInterfaceSource{
  1634  							Server: &DomainInterfaceSourceServer{
  1635  								Address: "127.0.0.1",
  1636  								Port:    1234,
  1637  							},
  1638  						},
  1639  					},
  1640  				},
  1641  			},
  1642  		},
  1643  		Expected: []string{
  1644  			`<domain type="kvm">`,
  1645  			`  <name>test</name>`,
  1646  			`  <devices>`,
  1647  			`    <interface type="server">`,
  1648  			`      <mac address="52:54:00:39:97:ac"></mac>`,
  1649  			`      <source address="127.0.0.1" port="1234"></source>`,
  1650  			`      <model type="virtio"></model>`,
  1651  			`    </interface>`,
  1652  			`  </devices>`,
  1653  			`</domain>`,
  1654  		},
  1655  	},
  1656  	{
  1657  		Object: &Domain{
  1658  			Type: "kvm",
  1659  			Name: "test",
  1660  			Devices: &DomainDeviceList{
  1661  				Interfaces: []DomainInterface{
  1662  					DomainInterface{
  1663  						MAC: &DomainInterfaceMAC{
  1664  							Address: "52:54:00:39:97:ac",
  1665  						},
  1666  						Model: &DomainInterfaceModel{
  1667  							Type: "virtio",
  1668  						},
  1669  						Source: &DomainInterfaceSource{
  1670  							Ethernet: &DomainInterfaceSourceEthernet{},
  1671  						},
  1672  						Script: &DomainInterfaceScript{
  1673  							Path: "/etc/qemu-ifup",
  1674  						},
  1675  						Address: &DomainAddress{
  1676  							PCI: &DomainAddressPCI{
  1677  								Domain:   &ifaceAddr.Domain,
  1678  								Bus:      &ifaceAddr.Bus,
  1679  								Slot:     &ifaceAddr.Slot,
  1680  								Function: &ifaceAddr.Function,
  1681  							},
  1682  						},
  1683  					},
  1684  				},
  1685  			},
  1686  		},
  1687  		Expected: []string{
  1688  			`<domain type="kvm">`,
  1689  			`  <name>test</name>`,
  1690  			`  <devices>`,
  1691  			`    <interface type="ethernet">`,
  1692  			`      <mac address="52:54:00:39:97:ac"></mac>`,
  1693  			`      <script path="/etc/qemu-ifup"></script>`,
  1694  			`      <model type="virtio"></model>`,
  1695  			`      <address type="pci" domain="0x0000" bus="0x00" slot="0x04" function="0x0"></address>`,
  1696  			`    </interface>`,
  1697  			`  </devices>`,
  1698  			`</domain>`,
  1699  		},
  1700  	},
  1701  	{
  1702  		Object: &Domain{
  1703  			Type: "kvm",
  1704  			Name: "test",
  1705  			Devices: &DomainDeviceList{
  1706  				Interfaces: []DomainInterface{
  1707  					DomainInterface{
  1708  						MAC: &DomainInterfaceMAC{
  1709  							Address: "52:54:00:39:97:ac",
  1710  						},
  1711  						Model: &DomainInterfaceModel{
  1712  							Type: "virtio",
  1713  						},
  1714  						Source: &DomainInterfaceSource{
  1715  							VHostUser: &DomainChardevSource{
  1716  								UNIX: &DomainChardevSourceUNIX{
  1717  									Path: "/tmp/vhost0.sock",
  1718  									Mode: "server",
  1719  								},
  1720  							},
  1721  						},
  1722  					},
  1723  				},
  1724  			},
  1725  		},
  1726  		Expected: []string{
  1727  			`<domain type="kvm">`,
  1728  			`  <name>test</name>`,
  1729  			`  <devices>`,
  1730  			`    <interface type="vhostuser">`,
  1731  			`      <mac address="52:54:00:39:97:ac"></mac>`,
  1732  			`      <source type="unix" mode="server" path="/tmp/vhost0.sock"></source>`,
  1733  			`      <model type="virtio"></model>`,
  1734  			`    </interface>`,
  1735  			`  </devices>`,
  1736  			`</domain>`,
  1737  		},
  1738  	},
  1739  	{
  1740  		Object: &Domain{
  1741  			Type: "kvm",
  1742  			Name: "test",
  1743  			Devices: &DomainDeviceList{
  1744  				Interfaces: []DomainInterface{
  1745  					DomainInterface{
  1746  						MAC: &DomainInterfaceMAC{
  1747  							Address: "52:54:00:39:97:ac",
  1748  						},
  1749  						Model: &DomainInterfaceModel{
  1750  							Type: "virtio",
  1751  						},
  1752  						Source: &DomainInterfaceSource{
  1753  							VHostUser: &DomainChardevSource{
  1754  								UNIX: &DomainChardevSourceUNIX{
  1755  									Path: "/tmp/vhost0.sock",
  1756  									Mode: "server",
  1757  								},
  1758  							},
  1759  						},
  1760  						Bandwidth: &DomainInterfaceBandwidth{
  1761  							Inbound: &DomainInterfaceBandwidthParams{
  1762  								Average: &nicAverage,
  1763  								Burst:   &nicBurst,
  1764  							},
  1765  							Outbound: &DomainInterfaceBandwidthParams{
  1766  								Average: new(int),
  1767  								Burst:   new(int),
  1768  							},
  1769  						},
  1770  					},
  1771  				},
  1772  			},
  1773  		},
  1774  		Expected: []string{
  1775  			`<domain type="kvm">`,
  1776  			`  <name>test</name>`,
  1777  			`  <devices>`,
  1778  			`    <interface type="vhostuser">`,
  1779  			`      <mac address="52:54:00:39:97:ac"></mac>`,
  1780  			`      <source type="unix" mode="server" path="/tmp/vhost0.sock"></source>`,
  1781  			`      <model type="virtio"></model>`,
  1782  			`      <bandwidth>`,
  1783  			`        <inbound average="1000" burst="10000"></inbound>`,
  1784  			`        <outbound average="0" burst="0"></outbound>`,
  1785  			`      </bandwidth>`,
  1786  			`    </interface>`,
  1787  			`  </devices>`,
  1788  			`</domain>`,
  1789  		},
  1790  	},
  1791  	{
  1792  		Object: &Domain{
  1793  			Type: "kvm",
  1794  			Name: "test",
  1795  			Devices: &DomainDeviceList{
  1796  				Interfaces: []DomainInterface{
  1797  					DomainInterface{
  1798  						MAC: &DomainInterfaceMAC{
  1799  							Address: "52:54:00:39:97:ac",
  1800  						},
  1801  						Source: &DomainInterfaceSource{
  1802  							Hostdev: &DomainInterfaceSourceHostdev{
  1803  								PCI: &DomainHostdevSubsysPCISource{
  1804  									Address: &DomainAddressPCI{
  1805  										Domain:   &pciHostDomain,
  1806  										Bus:      &pciHostBus,
  1807  										Slot:     &pciHostSlot,
  1808  										Function: &pciHostFunction,
  1809  									},
  1810  								},
  1811  							},
  1812  						},
  1813  					},
  1814  				},
  1815  			},
  1816  		},
  1817  		Expected: []string{
  1818  			`<domain type="kvm">`,
  1819  			`  <name>test</name>`,
  1820  			`  <devices>`,
  1821  			`    <interface type="hostdev">`,
  1822  			`      <mac address="52:54:00:39:97:ac"></mac>`,
  1823  			`      <source>`,
  1824  			`        <address type="pci" domain="0x0000" bus="0x03" slot="0x0e" function="0x5"></address>`,
  1825  			`      </source>`,
  1826  			`    </interface>`,
  1827  			`  </devices>`,
  1828  			`</domain>`,
  1829  		},
  1830  	},
  1831  	{
  1832  		Object: &Domain{
  1833  			Type: "kvm",
  1834  			Name: "test",
  1835  			Devices: &DomainDeviceList{
  1836  				Filesystems: []DomainFilesystem{
  1837  					DomainFilesystem{
  1838  						AccessMode: "mapped",
  1839  						Driver: &DomainFilesystemDriver{
  1840  							Type:     "path",
  1841  							WRPolicy: "immediate",
  1842  						},
  1843  						Source: &DomainFilesystemSource{
  1844  							Mount: &DomainFilesystemSourceMount{
  1845  								Dir: "/home/user/test",
  1846  							},
  1847  						},
  1848  						Target: &DomainFilesystemTarget{
  1849  							Dir: "user-test-mount",
  1850  						},
  1851  						Address: &DomainAddress{
  1852  							PCI: &DomainAddressPCI{
  1853  								Domain:   &fsAddr.Domain,
  1854  								Bus:      &fsAddr.Bus,
  1855  								Slot:     &fsAddr.Slot,
  1856  								Function: &fsAddr.Function,
  1857  							},
  1858  						},
  1859  					},
  1860  					DomainFilesystem{
  1861  						AccessMode: "passthrough",
  1862  						Driver: &DomainFilesystemDriver{
  1863  							Name: "loop",
  1864  							Type: "raw",
  1865  						},
  1866  						Source: &DomainFilesystemSource{
  1867  							File: &DomainFilesystemSourceFile{
  1868  								File: "/home/user/test.img",
  1869  							},
  1870  						},
  1871  						Target: &DomainFilesystemTarget{
  1872  							Dir: "user-file-test-mount",
  1873  						},
  1874  					},
  1875  				},
  1876  			},
  1877  		},
  1878  		Expected: []string{
  1879  			`<domain type="kvm">`,
  1880  			`  <name>test</name>`,
  1881  			`  <devices>`,
  1882  			`    <filesystem type="mount" accessmode="mapped">`,
  1883  			`      <driver type="path" wrpolicy="immediate"></driver>`,
  1884  			`      <source dir="/home/user/test"></source>`,
  1885  			`      <target dir="user-test-mount"></target>`,
  1886  			`      <address type="pci" domain="0x0000" bus="0x00" slot="0x06" function="0x0"></address>`,
  1887  			`    </filesystem>`,
  1888  			`    <filesystem type="file" accessmode="passthrough">`,
  1889  			`      <driver type="raw" name="loop"></driver>`,
  1890  			`      <source file="/home/user/test.img"></source>`,
  1891  			`      <target dir="user-file-test-mount"></target>`,
  1892  			`    </filesystem>`,
  1893  			`  </devices>`,
  1894  			`</domain>`,
  1895  		},
  1896  	},
  1897  	{
  1898  		Object: &Domain{
  1899  			Type: "kvm",
  1900  			Name: "test",
  1901  			Features: &DomainFeatureList{
  1902  				PAE:     &DomainFeature{},
  1903  				ACPI:    &DomainFeature{},
  1904  				APIC:    &DomainFeatureAPIC{},
  1905  				HAP:     &DomainFeatureState{},
  1906  				PrivNet: &DomainFeature{},
  1907  				HyperV: &DomainFeatureHyperV{
  1908  					Relaxed: &DomainFeatureState{State: "on"},
  1909  					VAPIC:   &DomainFeatureState{State: "on"},
  1910  					Spinlocks: &DomainFeatureHyperVSpinlocks{
  1911  						DomainFeatureState{State: "on"}, 4096,
  1912  					},
  1913  					VPIndex: &DomainFeatureState{State: "on"},
  1914  					Runtime: &DomainFeatureState{State: "on"},
  1915  					Synic:   &DomainFeatureState{State: "on"},
  1916  					Reset:   &DomainFeatureState{State: "on"},
  1917  					VendorId: &DomainFeatureHyperVVendorId{
  1918  						DomainFeatureState{State: "on"}, "KVM Hv",
  1919  					},
  1920  				},
  1921  				KVM: &DomainFeatureKVM{
  1922  					Hidden: &DomainFeatureState{State: "on"},
  1923  				},
  1924  				PVSpinlock: &DomainFeatureState{State: "on"},
  1925  				GIC:        &DomainFeatureGIC{Version: "2"},
  1926  				Capabilities: &DomainFeatureCapabilities{
  1927  					Policy: "default",
  1928  					MkNod: &DomainFeatureCapability{
  1929  						State: "on",
  1930  					},
  1931  				},
  1932  			},
  1933  		},
  1934  		Expected: []string{
  1935  			`<domain type="kvm">`,
  1936  			`  <name>test</name>`,
  1937  			`  <features>`,
  1938  			`    <pae></pae>`,
  1939  			`    <acpi></acpi>`,
  1940  			`    <apic></apic>`,
  1941  			`    <hap></hap>`,
  1942  			`    <privnet></privnet>`,
  1943  			`    <hyperv>`,
  1944  			`      <relaxed state="on"></relaxed>`,
  1945  			`      <vapic state="on"></vapic>`,
  1946  			`      <spinlocks state="on" retries="4096"></spinlocks>`,
  1947  			`      <vpindex state="on"></vpindex>`,
  1948  			`      <runtime state="on"></runtime>`,
  1949  			`      <synic state="on"></synic>`,
  1950  			`      <reset state="on"></reset>`,
  1951  			`      <vendor_id state="on" value="KVM Hv"></vendor_id>`,
  1952  			`    </hyperv>`,
  1953  			`    <kvm>`,
  1954  			`      <hidden state="on"></hidden>`,
  1955  			`    </kvm>`,
  1956  			`    <pvspinlock state="on"></pvspinlock>`,
  1957  			`    <gic version="2"></gic>`,
  1958  			`    <capabilities policy="default">`,
  1959  			`      <mknod state="on"></mknod>`,
  1960  			`    </capabilities>`,
  1961  			`  </features>`,
  1962  			`</domain>`,
  1963  		},
  1964  	},
  1965  	{
  1966  		Object: &Domain{
  1967  			Type: "kvm",
  1968  			Name: "test",
  1969  			Devices: &DomainDeviceList{
  1970  				Controllers: []DomainController{
  1971  					DomainController{
  1972  						Type:  "usb",
  1973  						Index: &uhciIndex,
  1974  						Model: "piix3-uhci",
  1975  						Address: &DomainAddress{
  1976  							PCI: &DomainAddressPCI{
  1977  								Domain:   &uhciAddr.Domain,
  1978  								Bus:      &uhciAddr.Bus,
  1979  								Slot:     &uhciAddr.Slot,
  1980  								Function: &uhciAddr.Function,
  1981  							},
  1982  						},
  1983  					},
  1984  					DomainController{
  1985  						Type:  "usb",
  1986  						Index: nil,
  1987  						Model: "ehci",
  1988  						USB: &DomainControllerUSB{
  1989  							Master: &DomainControllerUSBMaster{
  1990  								StartPort: 0,
  1991  							},
  1992  						},
  1993  					},
  1994  				},
  1995  			},
  1996  		},
  1997  		Expected: []string{
  1998  			`<domain type="kvm">`,
  1999  			`  <name>test</name>`,
  2000  			`  <devices>`,
  2001  			`    <controller type="usb" index="0" model="piix3-uhci">`,
  2002  			`      <address type="pci" domain="0x0000" bus="0x00" slot="0x01" function="0x2"></address>`,
  2003  			`    </controller>`,
  2004  			`    <controller type="usb" model="ehci">`,
  2005  			`      <master startport="0"></master>`,
  2006  			`    </controller>`,
  2007  			`  </devices>`,
  2008  			`</domain>`,
  2009  		},
  2010  	},
  2011  	{
  2012  		Object: &Domain{
  2013  			Type: "kvm",
  2014  			Name: "test",
  2015  			Devices: &DomainDeviceList{
  2016  				Controllers: []DomainController{
  2017  					DomainController{
  2018  						Type:  "pci",
  2019  						Index: &pciIndex,
  2020  						Model: "pci-expander-bus",
  2021  						PCI: &DomainControllerPCI{
  2022  							Model: &DomainControllerPCIModel{
  2023  								Name: "pxb",
  2024  							},
  2025  							Target: &DomainControllerPCITarget{
  2026  								ChassisNr: &pciTargetChassisNr,
  2027  								Chassis:   &pciTargetChassis,
  2028  								Port:      &pciTargetPort,
  2029  								BusNr:     &pciTargetBusNr,
  2030  								Index:     &pciTargetIndex,
  2031  								NUMANode:  &pciTargetNUMANode,
  2032  							},
  2033  							Hole64: &DomainControllerPCIHole64{
  2034  								Size: 1024,
  2035  							},
  2036  						},
  2037  					},
  2038  				},
  2039  			},
  2040  		},
  2041  		Expected: []string{
  2042  			`<domain type="kvm">`,
  2043  			`  <name>test</name>`,
  2044  			`  <devices>`,
  2045  			`    <controller type="pci" index="0" model="pci-expander-bus">`,
  2046  			`      <model name="pxb"></model>`,
  2047  			`      <target chassisNr="7" chassis="23" port="78" busNr="2" index="3">`,
  2048  			`        <node>2</node>`,
  2049  			`      </target>`,
  2050  			`      <pcihole64>1024</pcihole64>`,
  2051  			`    </controller>`,
  2052  			`  </devices>`,
  2053  			`</domain>`,
  2054  		},
  2055  	},
  2056  	{
  2057  		Object: &Domain{
  2058  			Type: "kvm",
  2059  			Name: "test",
  2060  			Devices: &DomainDeviceList{
  2061  				Controllers: []DomainController{
  2062  					DomainController{
  2063  						Type:  "scsi",
  2064  						Index: &scsiIndex,
  2065  						Driver: &DomainControllerDriver{
  2066  							Queues:     &scsiQueues,
  2067  							CmdPerLUN:  &scsiCmdPerLUN,
  2068  							MaxSectors: &scsiMaxSectors,
  2069  							IOEventFD:  "yes",
  2070  							IOThread:   3,
  2071  							IOMMU:      "yes",
  2072  							ATS:        "no",
  2073  						},
  2074  					},
  2075  				},
  2076  			},
  2077  		},
  2078  		Expected: []string{
  2079  			`<domain type="kvm">`,
  2080  			`  <name>test</name>`,
  2081  			`  <devices>`,
  2082  			`    <controller type="scsi" index="0">`,
  2083  			`      <driver queues="3" cmd_per_lun="8" max_sectors="512" ioeventfd="yes" iothread="3" iommu="yes" ats="no"></driver>`,
  2084  			`    </controller>`,
  2085  			`  </devices>`,
  2086  			`</domain>`,
  2087  		},
  2088  	},
  2089  	{
  2090  		Object: &Domain{
  2091  			Type: "kvm",
  2092  			Name: "test",
  2093  			Devices: &DomainDeviceList{
  2094  				Hubs: []DomainHub{
  2095  					DomainHub{
  2096  						Type: "usb",
  2097  					},
  2098  				},
  2099  			},
  2100  		},
  2101  		Expected: []string{
  2102  			`<domain type="kvm">`,
  2103  			`  <name>test</name>`,
  2104  			`  <devices>`,
  2105  			`    <hub type="usb"></hub>`,
  2106  			`  </devices>`,
  2107  			`</domain>`,
  2108  		},
  2109  	},
  2110  	{
  2111  		Object: &Domain{
  2112  			Type: "kvm",
  2113  			Name: "test",
  2114  			Devices: &DomainDeviceList{
  2115  				IOMMU: &DomainIOMMU{
  2116  					Model: "intel",
  2117  					Driver: &DomainIOMMUDriver{
  2118  						EIM:         "on",
  2119  						IntRemap:    "on",
  2120  						CachingMode: "on",
  2121  						AWBits:      48,
  2122  					},
  2123  				},
  2124  			},
  2125  		},
  2126  		Expected: []string{
  2127  			`<domain type="kvm">`,
  2128  			`  <name>test</name>`,
  2129  			`  <devices>`,
  2130  			`    <iommu model="intel">`,
  2131  			`      <driver intremap="on" caching_mode="on" eim="on" aw_bits="48"></driver>`,
  2132  			`    </iommu>`,
  2133  			`  </devices>`,
  2134  			`</domain>`,
  2135  		},
  2136  	},
  2137  	{
  2138  		Object: &Domain{
  2139  			Type: "kvm",
  2140  			Name: "test",
  2141  			Perf: &DomainPerf{
  2142  				Events: []DomainPerfEvent{
  2143  					DomainPerfEvent{
  2144  						Name:    "cmt",
  2145  						Enabled: "yes",
  2146  					},
  2147  					DomainPerfEvent{
  2148  						Name:    "mbmt",
  2149  						Enabled: "no",
  2150  					},
  2151  				},
  2152  			},
  2153  		},
  2154  		Expected: []string{
  2155  			`<domain type="kvm">`,
  2156  			`  <name>test</name>`,
  2157  			`  <perf>`,
  2158  			`    <event name="cmt" enabled="yes"></event>`,
  2159  			`    <event name="mbmt" enabled="no"></event>`,
  2160  			`  </perf>`,
  2161  			`</domain>`,
  2162  		},
  2163  	},
  2164  	{
  2165  		Object: &Domain{
  2166  			Type: "kvm",
  2167  			Name: "test",
  2168  			Devices: &DomainDeviceList{
  2169  				Leases: []DomainLease{
  2170  					DomainLease{
  2171  						Lockspace: "foo",
  2172  						Key:       "bar",
  2173  						Target: &DomainLeaseTarget{
  2174  							Path:   "/some/file",
  2175  							Offset: 1024,
  2176  						},
  2177  					},
  2178  				},
  2179  			},
  2180  		},
  2181  		Expected: []string{
  2182  			`<domain type="kvm">`,
  2183  			`  <name>test</name>`,
  2184  			`  <devices>`,
  2185  			`    <lease>`,
  2186  			`      <lockspace>foo</lockspace>`,
  2187  			`      <key>bar</key>`,
  2188  			`      <target path="/some/file" offset="1024"></target>`,
  2189  			`    </lease>`,
  2190  			`  </devices>`,
  2191  			`</domain>`,
  2192  		},
  2193  	},
  2194  	{
  2195  		Object: &Domain{
  2196  			Type: "kvm",
  2197  			Name: "test",
  2198  			Devices: &DomainDeviceList{
  2199  				NVRAM: &DomainNVRAM{
  2200  					Address: &DomainAddress{
  2201  						SpaprVIO: &DomainAddressSpaprVIO{
  2202  							Reg: &nvramReg,
  2203  						},
  2204  					},
  2205  				},
  2206  			},
  2207  		},
  2208  		Expected: []string{
  2209  			`<domain type="kvm">`,
  2210  			`  <name>test</name>`,
  2211  			`  <devices>`,
  2212  			`    <nvram>`,
  2213  			`      <address type="spapr-vio" reg="0x4000"></address>`,
  2214  			`    </nvram>`,
  2215  			`  </devices>`,
  2216  			`</domain>`,
  2217  		},
  2218  	},
  2219  	{
  2220  		Object: &Domain{
  2221  			Type: "qemu",
  2222  			Name: "test",
  2223  			QEMUCommandline: &DomainQEMUCommandline{
  2224  				Args: []DomainQEMUCommandlineArg{
  2225  					DomainQEMUCommandlineArg{Value: "-newarg"},
  2226  					DomainQEMUCommandlineArg{Value: "-oldarg"},
  2227  				},
  2228  				Envs: []DomainQEMUCommandlineEnv{
  2229  					DomainQEMUCommandlineEnv{Name: "QEMU_ENV", Value: "VAL"},
  2230  					DomainQEMUCommandlineEnv{Name: "QEMU_VAR", Value: "VAR"},
  2231  				},
  2232  			},
  2233  		},
  2234  		Expected: []string{
  2235  			`<domain type="qemu">`,
  2236  			`  <name>test</name>`,
  2237  			`  <commandline xmlns="http://libvirt.org/schemas/domain/qemu/1.0">`,
  2238  			`    <arg value="-newarg"></arg>`,
  2239  			`    <arg value="-oldarg"></arg>`,
  2240  			`    <env name="QEMU_ENV" value="VAL"></env>`,
  2241  			`    <env name="QEMU_VAR" value="VAR"></env>`,
  2242  			`  </commandline>`,
  2243  			`</domain>`,
  2244  		},
  2245  	},
  2246  	{
  2247  		Object: &Domain{
  2248  			Type: "lxc",
  2249  			Name: "test",
  2250  			LXCNamespace: &DomainLXCNamespace{
  2251  				ShareNet: &DomainLXCNamespaceMap{
  2252  					Type:  "netns",
  2253  					Value: "red",
  2254  				},
  2255  				ShareIPC: &DomainLXCNamespaceMap{
  2256  					Type:  "pid",
  2257  					Value: "12345",
  2258  				},
  2259  				ShareUTS: &DomainLXCNamespaceMap{
  2260  					Type:  "name",
  2261  					Value: "container1",
  2262  				},
  2263  			},
  2264  		},
  2265  		Expected: []string{
  2266  			`<domain type="lxc">`,
  2267  			`  <name>test</name>`,
  2268  			`  <namespace xmlns="http://libvirt.org/schemas/domain/lxc/1.0">`,
  2269  			`    <sharenet type="netns" value="red"></sharenet>`,
  2270  			`    <shareipc type="pid" value="12345"></shareipc>`,
  2271  			`    <shareuts type="name" value="container1"></shareuts>`,
  2272  			`  </namespace>`,
  2273  			`</domain>`,
  2274  		},
  2275  	},
  2276  	{
  2277  		Object: &Domain{
  2278  			Type: "vmware",
  2279  			Name: "test",
  2280  			VMWareDataCenterPath: &DomainVMWareDataCenterPath{
  2281  				Value: "folder1/folder2/datacenter1",
  2282  			},
  2283  		},
  2284  		Expected: []string{
  2285  			`<domain type="vmware">`,
  2286  			`  <name>test</name>`,
  2287  			`  <datacenterpath xmlns="http://libvirt.org/schemas/domain/vmware/1.0">folder1/folder2/datacenter1</datacenterpath>`,
  2288  			`</domain>`,
  2289  		},
  2290  	},
  2291  	{
  2292  		Object: &Domain{
  2293  			Name:      "test",
  2294  			IOThreads: 4,
  2295  			IOThreadIDs: &DomainIOThreadIDs{
  2296  				IOThreads: []DomainIOThread{
  2297  					DomainIOThread{
  2298  						ID: 0,
  2299  					},
  2300  					DomainIOThread{
  2301  						ID: 1,
  2302  					},
  2303  					DomainIOThread{
  2304  						ID: 2,
  2305  					},
  2306  					DomainIOThread{
  2307  						ID: 3,
  2308  					},
  2309  				},
  2310  			},
  2311  			CPUTune: &DomainCPUTune{
  2312  				Shares:         &DomainCPUTuneShares{Value: 1024},
  2313  				Period:         &DomainCPUTunePeriod{Value: 500000},
  2314  				Quota:          &DomainCPUTuneQuota{Value: -1},
  2315  				GlobalPeriod:   &DomainCPUTunePeriod{Value: 500000},
  2316  				GlobalQuota:    &DomainCPUTuneQuota{Value: 500},
  2317  				EmulatorPeriod: &DomainCPUTunePeriod{Value: 900000},
  2318  				EmulatorQuota:  &DomainCPUTuneQuota{Value: 100},
  2319  				IOThreadPeriod: &DomainCPUTunePeriod{Value: 100000},
  2320  				IOThreadQuota:  &DomainCPUTuneQuota{Value: 2000},
  2321  				VCPUPin: []DomainCPUTuneVCPUPin{
  2322  					DomainCPUTuneVCPUPin{
  2323  						VCPU:   0,
  2324  						CPUSet: "0-1",
  2325  					},
  2326  					DomainCPUTuneVCPUPin{
  2327  						VCPU:   1,
  2328  						CPUSet: "2-3",
  2329  					},
  2330  				},
  2331  				EmulatorPin: &DomainCPUTuneEmulatorPin{
  2332  					CPUSet: "0-3",
  2333  				},
  2334  				IOThreadPin: []DomainCPUTuneIOThreadPin{
  2335  					DomainCPUTuneIOThreadPin{
  2336  						IOThread: 0,
  2337  						CPUSet:   "0-1",
  2338  					},
  2339  					DomainCPUTuneIOThreadPin{
  2340  						IOThread: 1,
  2341  						CPUSet:   "2-3",
  2342  					},
  2343  				},
  2344  				VCPUSched: []DomainCPUTuneVCPUSched{
  2345  					DomainCPUTuneVCPUSched{
  2346  						VCPUs:     "0-1",
  2347  						Scheduler: "fifo",
  2348  						Priority:  &vcpuPriority,
  2349  					},
  2350  				},
  2351  				IOThreadSched: []DomainCPUTuneIOThreadSched{
  2352  					DomainCPUTuneIOThreadSched{
  2353  						IOThreads: "0-1",
  2354  						Scheduler: "fifo",
  2355  						Priority:  &iothreadPriority,
  2356  					},
  2357  				},
  2358  			},
  2359  		},
  2360  		Expected: []string{
  2361  			`<domain>`,
  2362  			`  <name>test</name>`,
  2363  			`  <iothreads>4</iothreads>`,
  2364  			`  <iothreadids>`,
  2365  			`    <iothread id="0"></iothread>`,
  2366  			`    <iothread id="1"></iothread>`,
  2367  			`    <iothread id="2"></iothread>`,
  2368  			`    <iothread id="3"></iothread>`,
  2369  			`  </iothreadids>`,
  2370  			`  <cputune>`,
  2371  			`    <shares>1024</shares>`,
  2372  			`    <period>500000</period>`,
  2373  			`    <quota>-1</quota>`,
  2374  			`    <global_period>500000</global_period>`,
  2375  			`    <global_quota>500</global_quota>`,
  2376  			`    <emulator_period>900000</emulator_period>`,
  2377  			`    <emulator_quota>100</emulator_quota>`,
  2378  			`    <iothread_period>100000</iothread_period>`,
  2379  			`    <iothread_quota>2000</iothread_quota>`,
  2380  			`    <vcpupin vcpu="0" cpuset="0-1"></vcpupin>`,
  2381  			`    <vcpupin vcpu="1" cpuset="2-3"></vcpupin>`,
  2382  			`    <emulatorpin cpuset="0-3"></emulatorpin>`,
  2383  			`    <iothreadpin iothread="0" cpuset="0-1"></iothreadpin>`,
  2384  			`    <iothreadpin iothread="1" cpuset="2-3"></iothreadpin>`,
  2385  			`    <vcpusched vcpus="0-1" scheduler="fifo" priority="-5"></vcpusched>`,
  2386  			`    <iothreadsched iothreads="0-1" scheduler="fifo" priority="-3"></iothreadsched>`,
  2387  			`  </cputune>`,
  2388  			`</domain>`,
  2389  		},
  2390  	},
  2391  	{
  2392  		Object: &Domain{
  2393  			Name: "test",
  2394  			KeyWrap: &DomainKeyWrap{
  2395  				Ciphers: []DomainKeyWrapCipher{
  2396  					DomainKeyWrapCipher{
  2397  						Name:  "aes",
  2398  						State: "on",
  2399  					},
  2400  					DomainKeyWrapCipher{
  2401  						Name:  "dea",
  2402  						State: "off",
  2403  					},
  2404  				},
  2405  			},
  2406  		},
  2407  		Expected: []string{
  2408  			`<domain>`,
  2409  			`  <name>test</name>`,
  2410  			`  <keywrap>`,
  2411  			`    <cipher name="aes" state="on"></cipher>`,
  2412  			`    <cipher name="dea" state="off"></cipher>`,
  2413  			`  </keywrap>`,
  2414  			`</domain>`,
  2415  		},
  2416  	},
  2417  	{
  2418  		Object: &Domain{
  2419  			Name: "test",
  2420  			IDMap: &DomainIDMap{
  2421  				UIDs: []DomainIDMapRange{
  2422  					DomainIDMapRange{
  2423  						Start:  0,
  2424  						Target: 1000,
  2425  						Count:  50,
  2426  					},
  2427  					DomainIDMapRange{
  2428  						Start:  1000,
  2429  						Target: 5000,
  2430  						Count:  5000,
  2431  					},
  2432  				},
  2433  				GIDs: []DomainIDMapRange{
  2434  					DomainIDMapRange{
  2435  						Start:  0,
  2436  						Target: 1000,
  2437  						Count:  50,
  2438  					},
  2439  					DomainIDMapRange{
  2440  						Start:  1000,
  2441  						Target: 5000,
  2442  						Count:  5000,
  2443  					},
  2444  				},
  2445  			},
  2446  		},
  2447  		Expected: []string{
  2448  			`<domain>`,
  2449  			`  <name>test</name>`,
  2450  			`  <idmap>`,
  2451  			`    <uid start="0" target="1000" count="50"></uid>`,
  2452  			`    <uid start="1000" target="5000" count="5000"></uid>`,
  2453  			`    <gid start="0" target="1000" count="50"></gid>`,
  2454  			`    <gid start="1000" target="5000" count="5000"></gid>`,
  2455  			`  </idmap>`,
  2456  			`</domain>`,
  2457  		},
  2458  	},
  2459  	{
  2460  		Object: &Domain{
  2461  			Name: "test",
  2462  			NUMATune: &DomainNUMATune{
  2463  				Memory: &DomainNUMATuneMemory{
  2464  					Mode:      "strict",
  2465  					Nodeset:   "2-3",
  2466  					Placement: "static",
  2467  				},
  2468  				MemNodes: []DomainNUMATuneMemNode{
  2469  					DomainNUMATuneMemNode{
  2470  						CellID:  0,
  2471  						Mode:    "strict",
  2472  						Nodeset: "2",
  2473  					},
  2474  					DomainNUMATuneMemNode{
  2475  						CellID:  1,
  2476  						Mode:    "strict",
  2477  						Nodeset: "3",
  2478  					},
  2479  				},
  2480  			},
  2481  		},
  2482  		Expected: []string{
  2483  			`<domain>`,
  2484  			`  <name>test</name>`,
  2485  			`  <numatune>`,
  2486  			`    <memory mode="strict" nodeset="2-3" placement="static"></memory>`,
  2487  			`    <memnode cellid="0" mode="strict" nodeset="2"></memnode>`,
  2488  			`    <memnode cellid="1" mode="strict" nodeset="3"></memnode>`,
  2489  
  2490  			`  </numatune>`,
  2491  			`</domain>`,
  2492  		},
  2493  	},
  2494  
  2495  	/* Tests for sub-documents that can be hotplugged */
  2496  	{
  2497  		Object: &DomainController{
  2498  			Type:  "usb",
  2499  			Index: &uhciIndex,
  2500  			Model: "piix3-uhci",
  2501  			Address: &DomainAddress{
  2502  				PCI: &DomainAddressPCI{
  2503  					Domain:   &uhciAddr.Domain,
  2504  					Bus:      &uhciAddr.Bus,
  2505  					Slot:     &uhciAddr.Slot,
  2506  					Function: &uhciAddr.Function,
  2507  				},
  2508  			},
  2509  		},
  2510  		Expected: []string{
  2511  			`<controller type="usb" index="0" model="piix3-uhci">`,
  2512  			`  <address type="pci" domain="0x0000" bus="0x00" slot="0x01" function="0x2"></address>`,
  2513  			`</controller>`,
  2514  		},
  2515  	},
  2516  	{
  2517  		Object: &DomainDisk{
  2518  			Device: "cdrom",
  2519  			Driver: &DomainDiskDriver{
  2520  				Name: "qemu",
  2521  				Type: "qcow2",
  2522  			},
  2523  			Source: &DomainDiskSource{
  2524  				File: &DomainDiskSourceFile{
  2525  					File: "/var/lib/libvirt/images/demo.qcow2",
  2526  				},
  2527  			},
  2528  			BackingStore: &DomainDiskBackingStore{
  2529  				Index: 1,
  2530  				Format: &DomainDiskFormat{
  2531  					Type: "qcow2",
  2532  				},
  2533  				Source: &DomainDiskSource{
  2534  					Block: &DomainDiskSourceBlock{
  2535  						Dev: "/dev/HostVG/QEMUGuest",
  2536  					},
  2537  				},
  2538  				BackingStore: &DomainDiskBackingStore{
  2539  					Index: 2,
  2540  					Format: &DomainDiskFormat{
  2541  						Type: "qcow2",
  2542  					},
  2543  					Source: &DomainDiskSource{
  2544  						File: &DomainDiskSourceFile{
  2545  							File: "/tmp/image2.qcow2",
  2546  						},
  2547  					},
  2548  					BackingStore: &DomainDiskBackingStore{
  2549  						Index: 3,
  2550  						Format: &DomainDiskFormat{
  2551  							Type: "raw",
  2552  						},
  2553  						Source: &DomainDiskSource{
  2554  							File: &DomainDiskSourceFile{
  2555  								File: "/tmp/image3.iso",
  2556  							},
  2557  						},
  2558  						BackingStore: &DomainDiskBackingStore{},
  2559  					},
  2560  				},
  2561  			},
  2562  			Target: &DomainDiskTarget{
  2563  				Dev: "vda",
  2564  				Bus: "virtio",
  2565  			},
  2566  			Serial: "fishfood",
  2567  			WWN:    "0123456789abcdef",
  2568  		},
  2569  		Expected: []string{
  2570  			`<disk type="file" device="cdrom">`,
  2571  			`  <driver name="qemu" type="qcow2"></driver>`,
  2572  			`  <source file="/var/lib/libvirt/images/demo.qcow2"></source>`,
  2573  			`  <backingStore type="block" index="1">`,
  2574  			`    <format type="qcow2"></format>`,
  2575  			`    <source dev="/dev/HostVG/QEMUGuest"></source>`,
  2576  			`    <backingStore type="file" index="2">`,
  2577  			`      <format type="qcow2"></format>`,
  2578  			`      <source file="/tmp/image2.qcow2"></source>`,
  2579  			`      <backingStore type="file" index="3">`,
  2580  			`        <format type="raw"></format>`,
  2581  			`        <source file="/tmp/image3.iso"></source>`,
  2582  			`        <backingStore></backingStore>`,
  2583  			`      </backingStore>`,
  2584  			`    </backingStore>`,
  2585  			`  </backingStore>`,
  2586  			`  <target dev="vda" bus="virtio"></target>`,
  2587  			`  <serial>fishfood</serial>`,
  2588  			`  <wwn>0123456789abcdef</wwn>`,
  2589  			`</disk>`,
  2590  		},
  2591  	},
  2592  	{
  2593  		Object: &DomainDisk{
  2594  			Device: "cdrom",
  2595  			Driver: &DomainDiskDriver{
  2596  				Name: "qemu",
  2597  				Type: "qcow2",
  2598  			},
  2599  			Source: &DomainDiskSource{
  2600  				Block: &DomainDiskSourceBlock{
  2601  					Dev: "/dev/HostVG/QEMUGuest1",
  2602  				},
  2603  			},
  2604  			Mirror: &DomainDiskMirror{
  2605  				Job:   "copy",
  2606  				Ready: "yes",
  2607  				Source: &DomainDiskSource{
  2608  					Block: &DomainDiskSourceBlock{
  2609  						Dev: "/dev/HostVG/QEMUGuest1Copy",
  2610  					},
  2611  				},
  2612  			},
  2613  			Target: &DomainDiskTarget{
  2614  				Dev: "vda",
  2615  				Bus: "virtio",
  2616  			},
  2617  		},
  2618  		Expected: []string{
  2619  			`<disk type="block" device="cdrom">`,
  2620  			`  <driver name="qemu" type="qcow2"></driver>`,
  2621  			`  <source dev="/dev/HostVG/QEMUGuest1"></source>`,
  2622  			`  <mirror type="block" job="copy" ready="yes">`,
  2623  			`    <source dev="/dev/HostVG/QEMUGuest1Copy"></source>`,
  2624  			`  </mirror>`,
  2625  			`  <target dev="vda" bus="virtio"></target>`,
  2626  			`</disk>`,
  2627  		},
  2628  	},
  2629  	{
  2630  		Object: &DomainDisk{
  2631  			Device: "cdrom",
  2632  			Driver: &DomainDiskDriver{
  2633  				Name: "qemu",
  2634  				Type: "qcow2",
  2635  			},
  2636  			Source: &DomainDiskSource{
  2637  				NVME: &DomainDiskSourceNVME{
  2638  					PCI: &DomainDiskSourceNVMEPCI{
  2639  						Managed:   "yes",
  2640  						Namespace: 15,
  2641  						Address: &DomainAddressPCI{
  2642  							Domain:   &nvmeAddr.Domain,
  2643  							Bus:      &nvmeAddr.Bus,
  2644  							Slot:     &nvmeAddr.Slot,
  2645  							Function: &nvmeAddr.Function,
  2646  						},
  2647  					},
  2648  				},
  2649  			},
  2650  			Target: &DomainDiskTarget{
  2651  				Dev: "vda",
  2652  				Bus: "virtio",
  2653  			},
  2654  		},
  2655  		Expected: []string{
  2656  			`<disk type="nvme" device="cdrom">`,
  2657  			`  <driver name="qemu" type="qcow2"></driver>`,
  2658  			`  <source type="pci" managed="yes" namespace="15">`,
  2659  			`    <address domain="0x0000" bus="0x01" slot="0x03" function="0x0"></address>`,
  2660  			`  </source>`,
  2661  			`  <target dev="vda" bus="virtio"></target>`,
  2662  			`</disk>`,
  2663  		},
  2664  	},
  2665  	{
  2666  		Object: &DomainDisk{
  2667  			Device: "cdrom",
  2668  			Driver: &DomainDiskDriver{
  2669  				Name: "qemu",
  2670  				Type: "qcow2",
  2671  			},
  2672  			Source: &DomainDiskSource{
  2673  				File: &DomainDiskSourceFile{
  2674  					File: "/var/lib/libvirt/images/demo.qcow2",
  2675  				},
  2676  			},
  2677  			Mirror: &DomainDiskMirror{
  2678  				Job: "copy",
  2679  				Format: &DomainDiskFormat{
  2680  					Type: "qcow2",
  2681  				},
  2682  				Source: &DomainDiskSource{
  2683  					File: &DomainDiskSourceFile{
  2684  						File: "/var/lib/libvirt/images/demo-copy.qcow2",
  2685  					},
  2686  				},
  2687  			},
  2688  			Target: &DomainDiskTarget{
  2689  				Dev: "vda",
  2690  				Bus: "virtio",
  2691  			},
  2692  		},
  2693  		Expected: []string{
  2694  			`<disk type="file" device="cdrom">`,
  2695  			`  <driver name="qemu" type="qcow2"></driver>`,
  2696  			`  <source file="/var/lib/libvirt/images/demo.qcow2"></source>`,
  2697  			`  <mirror type="file" file="/var/lib/libvirt/images/demo-copy.qcow2" format="qcow2" job="copy">`,
  2698  			`    <format type="qcow2"></format>`,
  2699  			`    <source file="/var/lib/libvirt/images/demo-copy.qcow2"></source>`,
  2700  			`  </mirror>`,
  2701  			`  <target dev="vda" bus="virtio"></target>`,
  2702  			`</disk>`,
  2703  		},
  2704  	},
  2705  	{
  2706  		Object: &DomainFilesystem{
  2707  			AccessMode: "mapped",
  2708  			Driver: &DomainFilesystemDriver{
  2709  				Type:     "path",
  2710  				WRPolicy: "immediate",
  2711  			},
  2712  			Source: &DomainFilesystemSource{
  2713  				Mount: &DomainFilesystemSourceMount{
  2714  					Dir: "/home/user/test",
  2715  				},
  2716  			},
  2717  			Target: &DomainFilesystemTarget{
  2718  				Dir: "user-test-mount",
  2719  			},
  2720  			Address: &DomainAddress{
  2721  				PCI: &DomainAddressPCI{
  2722  					Domain:   &fsAddr.Domain,
  2723  					Bus:      &fsAddr.Bus,
  2724  					Slot:     &fsAddr.Slot,
  2725  					Function: &fsAddr.Function,
  2726  				},
  2727  			},
  2728  		},
  2729  
  2730  		Expected: []string{
  2731  			`<filesystem type="mount" accessmode="mapped">`,
  2732  			`  <driver type="path" wrpolicy="immediate"></driver>`,
  2733  			`  <source dir="/home/user/test"></source>`,
  2734  			`  <target dir="user-test-mount"></target>`,
  2735  			`  <address type="pci" domain="0x0000" bus="0x00" slot="0x06" function="0x0"></address>`,
  2736  			`</filesystem>`,
  2737  		},
  2738  	},
  2739  	{
  2740  		Object: &DomainInterface{
  2741  			MAC: &DomainInterfaceMAC{
  2742  				Address: "00:11:22:33:44:55",
  2743  			},
  2744  			Model: &DomainInterfaceModel{
  2745  				Type: "virtio",
  2746  			},
  2747  			Source: &DomainInterfaceSource{
  2748  				Network: &DomainInterfaceSourceNetwork{
  2749  					Network: "default",
  2750  				},
  2751  			},
  2752  		},
  2753  		Expected: []string{
  2754  			`<interface type="network">`,
  2755  			`  <mac address="00:11:22:33:44:55"></mac>`,
  2756  			`  <source network="default"></source>`,
  2757  			`  <model type="virtio"></model>`,
  2758  			`</interface>`,
  2759  		},
  2760  	},
  2761  	{
  2762  		Object: &DomainSerial{
  2763  			Source: &DomainChardevSource{
  2764  				Pty: &DomainChardevSourcePty{},
  2765  			},
  2766  			Target: &DomainSerialTarget{
  2767  				Type: "isa",
  2768  				Port: &serialPort,
  2769  				Model: &DomainSerialTargetModel{
  2770  					Name: "isa-serial",
  2771  				},
  2772  			},
  2773  			Log: &DomainChardevLog{
  2774  				File:   "/some/path",
  2775  				Append: "on",
  2776  			},
  2777  		},
  2778  
  2779  		Expected: []string{
  2780  			`<serial type="pty">`,
  2781  			`  <target type="isa" port="0">`,
  2782  			`    <model name="isa-serial"></model>`,
  2783  			`  </target>`,
  2784  			`  <log file="/some/path" append="on"></log>`,
  2785  			`</serial>`,
  2786  		},
  2787  	},
  2788  	{
  2789  		Object: &DomainParallel{
  2790  			Source: &DomainChardevSource{
  2791  				Pty: &DomainChardevSourcePty{},
  2792  			},
  2793  			Target: &DomainParallelTarget{
  2794  				Type: "isa",
  2795  				Port: &parallelPort,
  2796  			},
  2797  			Log: &DomainChardevLog{
  2798  				File:   "/some/path",
  2799  				Append: "on",
  2800  			},
  2801  		},
  2802  
  2803  		Expected: []string{
  2804  			`<parallel type="pty">`,
  2805  			`  <target type="isa" port="0"></target>`,
  2806  			`  <log file="/some/path" append="on"></log>`,
  2807  			`</parallel>`,
  2808  		},
  2809  	},
  2810  	{
  2811  		Object: &DomainConsole{
  2812  			Source: &DomainChardevSource{
  2813  				Pty: &DomainChardevSourcePty{},
  2814  			},
  2815  			Target: &DomainConsoleTarget{
  2816  				Type: "virtio",
  2817  				Port: &serialPort,
  2818  			},
  2819  		},
  2820  
  2821  		Expected: []string{
  2822  			`<console type="pty">`,
  2823  			`  <target type="virtio" port="0"></target>`,
  2824  			`</console>`,
  2825  		},
  2826  	},
  2827  	{
  2828  		Object: &DomainSmartcard{
  2829  			Host: &DomainSmartcardHost{},
  2830  			Address: &DomainAddress{
  2831  				CCID: &DomainAddressCCID{
  2832  					Controller: &smartcardController,
  2833  					Slot:       &smartcardSlot,
  2834  				},
  2835  			},
  2836  		},
  2837  
  2838  		Expected: []string{
  2839  			`<smartcard mode="host">`,
  2840  			`  <address type="ccid" controller="0" slot="7"></address>`,
  2841  			`</smartcard>`,
  2842  		},
  2843  	},
  2844  	{
  2845  		Object: &DomainSmartcard{
  2846  			Passthrough: &DomainChardevSource{
  2847  				TCP: &DomainChardevSourceTCP{
  2848  					Mode:    "connect",
  2849  					Host:    "localhost",
  2850  					Service: "12345",
  2851  				},
  2852  			},
  2853  			Protocol: &DomainChardevProtocol{
  2854  				Type: "raw",
  2855  			},
  2856  			Address: &DomainAddress{
  2857  				CCID: &DomainAddressCCID{
  2858  					Controller: &smartcardController,
  2859  					Slot:       &smartcardSlot,
  2860  				},
  2861  			},
  2862  		},
  2863  
  2864  		Expected: []string{
  2865  			`<smartcard mode="passthrough" type="tcp">`,
  2866  			`  <source mode="connect" host="localhost" service="12345"></source>`,
  2867  			`  <protocol type="raw"></protocol>`,
  2868  			`  <address type="ccid" controller="0" slot="7"></address>`,
  2869  			`</smartcard>`,
  2870  		},
  2871  	},
  2872  	{
  2873  		Object: &DomainSmartcard{
  2874  			HostCerts: []DomainSmartcardHostCert{
  2875  				DomainSmartcardHostCert{
  2876  					File: "/some/cert1",
  2877  				},
  2878  				DomainSmartcardHostCert{
  2879  					File: "/some/cert2",
  2880  				},
  2881  				DomainSmartcardHostCert{
  2882  					File: "/some/cert3",
  2883  				},
  2884  			},
  2885  			Address: &DomainAddress{
  2886  				CCID: &DomainAddressCCID{
  2887  					Controller: &smartcardController,
  2888  					Slot:       &smartcardSlot,
  2889  				},
  2890  			},
  2891  		},
  2892  
  2893  		Expected: []string{
  2894  			`<smartcard mode="host-certificates">`,
  2895  			`  <certificate>/some/cert1</certificate>`,
  2896  			`  <certificate>/some/cert2</certificate>`,
  2897  			`  <certificate>/some/cert3</certificate>`,
  2898  			`  <address type="ccid" controller="0" slot="7"></address>`,
  2899  			`</smartcard>`,
  2900  		},
  2901  	},
  2902  	{
  2903  		Object: &DomainTPM{
  2904  			Model: "tpm-tis",
  2905  			Backend: &DomainTPMBackend{
  2906  				Passthrough: &DomainTPMBackendPassthrough{
  2907  					Device: &DomainTPMBackendDevice{
  2908  						Path: "/dev/tpm0",
  2909  					},
  2910  				},
  2911  			},
  2912  		},
  2913  
  2914  		Expected: []string{
  2915  			`<tpm model="tpm-tis">`,
  2916  			`  <backend type="passthrough">`,
  2917  			`    <device path="/dev/tpm0"></device>`,
  2918  			`  </backend>`,
  2919  			`</tpm>`,
  2920  		},
  2921  	},
  2922  	{
  2923  		Object: &DomainShmem{
  2924  			Name: "demo",
  2925  			Size: &DomainShmemSize{
  2926  				Value: 1,
  2927  				Unit:  "GiB",
  2928  			},
  2929  			Model: &DomainShmemModel{
  2930  				Type: "ivshmem-doorbell",
  2931  			},
  2932  			Server: &DomainShmemServer{
  2933  				Path: "/some/server",
  2934  			},
  2935  			MSI: &DomainShmemMSI{
  2936  				Enabled:   "yes",
  2937  				Vectors:   5,
  2938  				IOEventFD: "yes",
  2939  			},
  2940  		},
  2941  
  2942  		Expected: []string{
  2943  			`<shmem name="demo">`,
  2944  			`  <size unit="GiB">1</size>`,
  2945  			`  <model type="ivshmem-doorbell"></model>`,
  2946  			`  <server path="/some/server"></server>`,
  2947  			`  <msi enabled="yes" vectors="5" ioeventfd="yes"></msi>`,
  2948  			`</shmem>`,
  2949  		},
  2950  	},
  2951  	{
  2952  		Object: &DomainInput{
  2953  			Type: "tablet",
  2954  			Bus:  "usb",
  2955  			Address: &DomainAddress{
  2956  				USB: &DomainAddressUSB{
  2957  					Bus:  &tabletBus,
  2958  					Port: tabletPort,
  2959  				},
  2960  			},
  2961  		},
  2962  
  2963  		Expected: []string{
  2964  			`<input type="tablet" bus="usb">`,
  2965  			`  <address type="usb" bus="0" port="1.1"></address>`,
  2966  			`</input>`,
  2967  		},
  2968  	},
  2969  	{
  2970  		Object: &DomainVideo{
  2971  			Driver: &DomainVideoDriver{
  2972  				VGAConf: "io",
  2973  			},
  2974  			Model: DomainVideoModel{
  2975  				Type:    "cirrus",
  2976  				Heads:   1,
  2977  				Ram:     4096,
  2978  				VRam:    8192,
  2979  				VRam64:  8192,
  2980  				VGAMem:  256,
  2981  				Primary: "yes",
  2982  				Accel: &DomainVideoAccel{
  2983  					Accel3D: "yes",
  2984  					Accel2D: "no",
  2985  				},
  2986  			},
  2987  			Address: &DomainAddress{
  2988  				PCI: &DomainAddressPCI{
  2989  					Domain:        &videoAddr.Domain,
  2990  					Bus:           &videoAddr.Bus,
  2991  					Slot:          &videoAddr.Slot,
  2992  					Function:      &videoAddr.Function,
  2993  					MultiFunction: "on",
  2994  				},
  2995  			},
  2996  		},
  2997  
  2998  		Expected: []string{
  2999  			`<video>`,
  3000  			`  <model type="cirrus" heads="1" ram="4096" vram="8192" vram64="8192" vgamem="256" primary="yes">`,
  3001  			`    <acceleration accel3d="yes" accel2d="no"></acceleration>`,
  3002  			`  </model>`,
  3003  			`  <driver vgaconf="io"></driver>`,
  3004  			`  <address type="pci" domain="0x0000" bus="0x00" slot="0x05" function="0x0" multifunction="on"></address>`,
  3005  			`</video>`,
  3006  		},
  3007  	},
  3008  	{
  3009  		Object: &DomainChannel{
  3010  			Source: &DomainChardevSource{
  3011  				Pty: &DomainChardevSourcePty{},
  3012  			},
  3013  			Target: &DomainChannelTarget{
  3014  				VirtIO: &DomainChannelTargetVirtIO{
  3015  					Name:  "org.redhat.spice",
  3016  					State: "connected",
  3017  				},
  3018  			},
  3019  		},
  3020  
  3021  		Expected: []string{
  3022  			`<channel type="pty">`,
  3023  			`  <target type="virtio" name="org.redhat.spice" state="connected"></target>`,
  3024  			`</channel>`,
  3025  		},
  3026  	},
  3027  	{
  3028  		Object: &DomainChannel{
  3029  			Source: &DomainChardevSource{
  3030  				Pty: &DomainChardevSourcePty{},
  3031  			},
  3032  			Target: &DomainChannelTarget{
  3033  				Xen: &DomainChannelTargetXen{
  3034  					Name:  "org.redhat.spice",
  3035  					State: "connected",
  3036  				},
  3037  			},
  3038  		},
  3039  
  3040  		Expected: []string{
  3041  			`<channel type="pty">`,
  3042  			`  <target type="xen" name="org.redhat.spice" state="connected"></target>`,
  3043  			`</channel>`,
  3044  		},
  3045  	},
  3046  	{
  3047  		Object: &DomainRedirDev{
  3048  			Bus: "usb",
  3049  			Source: &DomainChardevSource{
  3050  				SpiceVMC: &DomainChardevSourceSpiceVMC{},
  3051  			},
  3052  			Address: &DomainAddress{
  3053  				USB: &DomainAddressUSB{
  3054  					Bus:  &redirBus,
  3055  					Port: redirPort,
  3056  				},
  3057  			},
  3058  		},
  3059  
  3060  		Expected: []string{
  3061  			`<redirdev type="spicevmc" bus="usb">`,
  3062  			`  <address type="usb" bus="0" port="3"></address>`,
  3063  			`</redirdev>`,
  3064  		},
  3065  	},
  3066  	{
  3067  		Object: &DomainRedirDev{
  3068  			Bus: "usb",
  3069  			Source: &DomainChardevSource{
  3070  				TCP: &DomainChardevSourceTCP{
  3071  					Mode:    "connect",
  3072  					Host:    "localhost",
  3073  					Service: "1234",
  3074  				},
  3075  			},
  3076  			Protocol: &DomainChardevProtocol{
  3077  				Type: "raw",
  3078  			},
  3079  			Boot: &DomainDeviceBoot{
  3080  				Order: 1,
  3081  			},
  3082  			Address: &DomainAddress{
  3083  				USB: &DomainAddressUSB{
  3084  					Bus:  &redirBus,
  3085  					Port: redirPort,
  3086  				},
  3087  			},
  3088  		},
  3089  
  3090  		Expected: []string{
  3091  			`<redirdev type="tcp" bus="usb">`,
  3092  			`  <source mode="connect" host="localhost" service="1234"></source>`,
  3093  			`  <protocol type="raw"></protocol>`,
  3094  			`  <boot order="1"></boot>`,
  3095  			`  <address type="usb" bus="0" port="3"></address>`,
  3096  			`</redirdev>`,
  3097  		},
  3098  	},
  3099  	{
  3100  		Object: &DomainChannel{
  3101  			Source: &DomainChardevSource{
  3102  				Pty: &DomainChardevSourcePty{},
  3103  			},
  3104  			Target: &DomainChannelTarget{
  3105  				GuestFWD: &DomainChannelTargetGuestFWD{
  3106  					Address: "192.168.1.1",
  3107  					Port:    "123",
  3108  				},
  3109  			},
  3110  		},
  3111  
  3112  		Expected: []string{
  3113  			`<channel type="pty">`,
  3114  			`  <target type="guestfwd" address="192.168.1.1" port="123"></target>`,
  3115  			`</channel>`,
  3116  		},
  3117  	},
  3118  	{
  3119  		Object: &Domain{
  3120  			Name: "demo",
  3121  			Devices: &DomainDeviceList{
  3122  				Graphics: []DomainGraphic{
  3123  					DomainGraphic{
  3124  						Spice: &DomainGraphicSpice{
  3125  							Port:        5903,
  3126  							TLSPort:     5904,
  3127  							AutoPort:    "no",
  3128  							Listen:      "127.0.0.1",
  3129  							DefaultMode: "secure",
  3130  							Listeners: []DomainGraphicListener{
  3131  								DomainGraphicListener{
  3132  									Address: &DomainGraphicListenerAddress{
  3133  										Address: "127.0.0.1",
  3134  									},
  3135  								},
  3136  							},
  3137  							Channel: []DomainGraphicSpiceChannel{
  3138  								DomainGraphicSpiceChannel{
  3139  									Name: "main",
  3140  									Mode: "secure",
  3141  								},
  3142  								DomainGraphicSpiceChannel{
  3143  									Name: "inputs",
  3144  									Mode: "insecure",
  3145  								},
  3146  							},
  3147  							Image: &DomainGraphicSpiceImage{
  3148  								Compression: "auto_glz",
  3149  							},
  3150  							JPEG: &DomainGraphicSpiceJPEG{
  3151  								Compression: "auto",
  3152  							},
  3153  							ZLib: &DomainGraphicSpiceZLib{
  3154  								Compression: "auto",
  3155  							},
  3156  							Playback: &DomainGraphicSpicePlayback{
  3157  								Compression: "on",
  3158  							},
  3159  							Streaming: &DomainGraphicSpiceStreaming{
  3160  								Mode: "filter",
  3161  							},
  3162  							ClipBoard: &DomainGraphicSpiceClipBoard{
  3163  								CopyPaste: "no",
  3164  							},
  3165  							FileTransfer: &DomainGraphicSpiceFileTransfer{
  3166  								Enable: "no",
  3167  							},
  3168  						},
  3169  					},
  3170  				},
  3171  			},
  3172  		},
  3173  		Expected: []string{
  3174  			`<domain>`,
  3175  			`  <name>demo</name>`,
  3176  			`  <devices>`,
  3177  			`    <graphics type="spice" port="5903" tlsPort="5904" autoport="no" listen="127.0.0.1" defaultMode="secure">`,
  3178  			`      <listen type="address" address="127.0.0.1"></listen>`,
  3179  			`      <channel name="main" mode="secure"></channel>`,
  3180  			`      <channel name="inputs" mode="insecure"></channel>`,
  3181  			`      <image compression="auto_glz"></image>`,
  3182  			`      <jpeg compression="auto"></jpeg>`,
  3183  			`      <zlib compression="auto"></zlib>`,
  3184  			`      <playback compression="on"></playback>`,
  3185  			`      <streaming mode="filter"></streaming>`,
  3186  			`      <clipboard copypaste="no"></clipboard>`,
  3187  			`      <filetransfer enable="no"></filetransfer>`,
  3188  			`    </graphics>`,
  3189  			`  </devices>`,
  3190  			`</domain>`,
  3191  		},
  3192  	},
  3193  	{
  3194  		Object: &Domain{
  3195  			Name: "demo",
  3196  			Devices: &DomainDeviceList{
  3197  				Graphics: []DomainGraphic{
  3198  					DomainGraphic{
  3199  						VNC: &DomainGraphicVNC{
  3200  							Port:     5903,
  3201  							AutoPort: "no",
  3202  							Listeners: []DomainGraphicListener{
  3203  								DomainGraphicListener{},
  3204  							},
  3205  						},
  3206  					},
  3207  				},
  3208  			},
  3209  		},
  3210  		Expected: []string{
  3211  			`<domain>`,
  3212  			`  <name>demo</name>`,
  3213  			`  <devices>`,
  3214  			`    <graphics type="vnc" port="5903" autoport="no">`,
  3215  			`      <listen type="none"></listen>`,
  3216  			`    </graphics>`,
  3217  			`  </devices>`,
  3218  			`</domain>`,
  3219  		},
  3220  	},
  3221  	{
  3222  		Object: &DomainMemBalloon{
  3223  			Model:       "virtio",
  3224  			AutoDeflate: "on",
  3225  			Stats: &DomainMemBalloonStats{
  3226  				Period: 10,
  3227  			},
  3228  			Address: &DomainAddress{
  3229  				PCI: &DomainAddressPCI{
  3230  					Domain:   &balloonAddr.Domain,
  3231  					Bus:      &balloonAddr.Bus,
  3232  					Slot:     &balloonAddr.Slot,
  3233  					Function: &balloonAddr.Function,
  3234  				},
  3235  			},
  3236  		},
  3237  
  3238  		Expected: []string{
  3239  			`<memballoon model="virtio" autodeflate="on">`,
  3240  			`  <stats period="10"></stats>`,
  3241  			`  <address type="pci" domain="0x0000" bus="0x00" slot="0x07" function="0x0"></address>`,
  3242  			`</memballoon>`,
  3243  		},
  3244  	},
  3245  	{
  3246  		Object: &DomainWatchdog{
  3247  			Model:  "ib700",
  3248  			Action: "inject-nmi",
  3249  			Address: &DomainAddress{
  3250  				PCI: &DomainAddressPCI{
  3251  					Domain:   &watchdogAddr.Domain,
  3252  					Bus:      &watchdogAddr.Bus,
  3253  					Slot:     &watchdogAddr.Slot,
  3254  					Function: &watchdogAddr.Function,
  3255  				},
  3256  			},
  3257  		},
  3258  
  3259  		Expected: []string{
  3260  			`<watchdog model="ib700" action="inject-nmi">`,
  3261  			`  <address type="pci" domain="0x0000" bus="0x00" slot="0x08" function="0x0"></address>`,
  3262  			`</watchdog>`,
  3263  		},
  3264  	},
  3265  	{
  3266  		Object: &DomainSound{
  3267  			Model: "ich6",
  3268  			Codec: []DomainSoundCodec{
  3269  				DomainSoundCodec{
  3270  					Type: "duplex",
  3271  				},
  3272  				DomainSoundCodec{
  3273  					Type: "micro",
  3274  				},
  3275  			},
  3276  			Address: &DomainAddress{
  3277  				PCI: &DomainAddressPCI{
  3278  					Domain:   &duplexAddr.Domain,
  3279  					Bus:      &duplexAddr.Bus,
  3280  					Slot:     &duplexAddr.Slot,
  3281  					Function: &duplexAddr.Function,
  3282  				},
  3283  			},
  3284  		},
  3285  
  3286  		Expected: []string{
  3287  			`<sound model="ich6">`,
  3288  			`  <codec type="duplex"></codec>`,
  3289  			`  <codec type="micro"></codec>`,
  3290  			`  <address type="pci" domain="0x0000" bus="0x00" slot="0x08" function="0x0"></address>`,
  3291  			`</sound>`,
  3292  		},
  3293  	},
  3294  	{
  3295  		Object: &DomainConsole{
  3296  			Source: &DomainChardevSource{
  3297  				Null: &DomainChardevSourceNull{},
  3298  			},
  3299  		},
  3300  
  3301  		Expected: []string{
  3302  			`<console type="null"></console>`,
  3303  		},
  3304  	},
  3305  	{
  3306  		Object: &DomainConsole{
  3307  			Source: &DomainChardevSource{
  3308  				VC: &DomainChardevSourceVC{},
  3309  			},
  3310  		},
  3311  
  3312  		Expected: []string{
  3313  			`<console type="vc"></console>`,
  3314  		},
  3315  	},
  3316  	{
  3317  		Object: &DomainConsole{
  3318  			TTY: "/dev/pts/3",
  3319  			Source: &DomainChardevSource{
  3320  				Pty: &DomainChardevSourcePty{
  3321  					Path: "/dev/pts/3",
  3322  				},
  3323  			},
  3324  		},
  3325  
  3326  		Expected: []string{
  3327  			`<console type="pty" tty="/dev/pts/3">`,
  3328  			`  <source path="/dev/pts/3"></source>`,
  3329  			`</console>`,
  3330  		},
  3331  	},
  3332  	{
  3333  		Object: &DomainConsole{
  3334  			Source: &DomainChardevSource{
  3335  				Dev: &DomainChardevSourceDev{
  3336  					Path: "/dev/ttyS0",
  3337  				},
  3338  			},
  3339  		},
  3340  
  3341  		Expected: []string{
  3342  			`<console type="dev">`,
  3343  			`  <source path="/dev/ttyS0"></source>`,
  3344  			`</console>`,
  3345  		},
  3346  	},
  3347  	{
  3348  		Object: &DomainConsole{
  3349  			Source: &DomainChardevSource{
  3350  				File: &DomainChardevSourceFile{
  3351  					Path: "/tmp/file.log",
  3352  				},
  3353  			},
  3354  		},
  3355  
  3356  		Expected: []string{
  3357  			`<console type="file">`,
  3358  			`  <source path="/tmp/file.log"></source>`,
  3359  			`</console>`,
  3360  		},
  3361  	},
  3362  	{
  3363  		Object: &DomainConsole{
  3364  			Source: &DomainChardevSource{
  3365  				Pipe: &DomainChardevSourcePipe{
  3366  					Path: "/tmp/file.fifo",
  3367  				},
  3368  			},
  3369  		},
  3370  
  3371  		Expected: []string{
  3372  			`<console type="pipe">`,
  3373  			`  <source path="/tmp/file.fifo"></source>`,
  3374  			`</console>`,
  3375  		},
  3376  	},
  3377  	{
  3378  		Object: &DomainConsole{
  3379  			Source: &DomainChardevSource{
  3380  				StdIO: &DomainChardevSourceStdIO{},
  3381  			},
  3382  		},
  3383  
  3384  		Expected: []string{
  3385  			`<console type="stdio"></console>`,
  3386  		},
  3387  	},
  3388  	{
  3389  		Object: &DomainConsole{
  3390  			Source: &DomainChardevSource{
  3391  				UDP: &DomainChardevSourceUDP{
  3392  					ConnectHost:    "some.server",
  3393  					ConnectService: "4999",
  3394  					BindHost:       "my.server",
  3395  					BindService:    "5921",
  3396  				},
  3397  			},
  3398  		},
  3399  
  3400  		Expected: []string{
  3401  			`<console type="udp">`,
  3402  			`  <source mode="bind" host="my.server" service="5921"></source>`,
  3403  			`  <source mode="connect" host="some.server" service="4999"></source>`,
  3404  			`</console>`,
  3405  		},
  3406  	},
  3407  	{
  3408  		Object: &DomainConsole{
  3409  			Source: &DomainChardevSource{
  3410  				TCP: &DomainChardevSourceTCP{
  3411  					Mode:    "connect",
  3412  					Host:    "localhost",
  3413  					Service: "25",
  3414  				},
  3415  			},
  3416  		},
  3417  
  3418  		Expected: []string{
  3419  			`<console type="tcp">`,
  3420  			`  <source mode="connect" host="localhost" service="25"></source>`,
  3421  			`</console>`,
  3422  		},
  3423  	},
  3424  	{
  3425  		Object: &DomainConsole{
  3426  			Source: &DomainChardevSource{
  3427  				UNIX: &DomainChardevSourceUNIX{
  3428  					Mode: "connect",
  3429  					Path: "/tmp/myvm.sock",
  3430  				},
  3431  			},
  3432  		},
  3433  
  3434  		Expected: []string{
  3435  			`<console type="unix">`,
  3436  			`  <source mode="connect" path="/tmp/myvm.sock"></source>`,
  3437  			`</console>`,
  3438  		},
  3439  	},
  3440  	{
  3441  		Object: &DomainConsole{
  3442  			Source: &DomainChardevSource{
  3443  				SpiceVMC: &DomainChardevSourceSpiceVMC{},
  3444  			},
  3445  		},
  3446  
  3447  		Expected: []string{
  3448  			`<console type="spicevmc"></console>`,
  3449  		},
  3450  	},
  3451  	{
  3452  		Object: &DomainConsole{
  3453  			Source: &DomainChardevSource{
  3454  				SpicePort: &DomainChardevSourceSpicePort{
  3455  					Channel: "org.qemu.console.serial.0",
  3456  				},
  3457  			},
  3458  		},
  3459  
  3460  		Expected: []string{
  3461  			`<console type="spiceport">`,
  3462  			`  <source channel="org.qemu.console.serial.0"></source>`,
  3463  			`</console>`,
  3464  		},
  3465  	},
  3466  	{
  3467  		Object: &DomainConsole{
  3468  			Source: &DomainChardevSource{
  3469  				NMDM: &DomainChardevSourceNMDM{
  3470  					Master: "/dev/nmdm0A",
  3471  					Slave:  "/dev/nmdm0B",
  3472  				},
  3473  			},
  3474  		},
  3475  
  3476  		Expected: []string{
  3477  			`<console type="nmdm">`,
  3478  			`  <source master="/dev/nmdm0A" slave="/dev/nmdm0B"></source>`,
  3479  			`</console>`,
  3480  		},
  3481  	},
  3482  	{
  3483  		Object: &DomainRNG{
  3484  			Model: "virtio",
  3485  			Rate: &DomainRNGRate{
  3486  				Period: 2000,
  3487  				Bytes:  1234,
  3488  			},
  3489  			Backend: &DomainRNGBackend{
  3490  				Random: &DomainRNGBackendRandom{
  3491  					Device: "/dev/random",
  3492  				},
  3493  			},
  3494  			Address: &DomainAddress{
  3495  				PCI: &DomainAddressPCI{
  3496  					Domain:   &rngAddr.Domain,
  3497  					Bus:      &rngAddr.Bus,
  3498  					Slot:     &rngAddr.Slot,
  3499  					Function: &rngAddr.Function,
  3500  				},
  3501  			},
  3502  		},
  3503  
  3504  		Expected: []string{
  3505  			`<rng model="virtio">`,
  3506  			`  <rate bytes="1234" period="2000"></rate>`,
  3507  			`  <backend model="random">/dev/random</backend>`,
  3508  			`  <address type="pci" domain="0x0000" bus="0x00" slot="0x09" function="0x0"></address>`,
  3509  			`</rng>`,
  3510  		},
  3511  	},
  3512  	{
  3513  		Object: &DomainRNG{
  3514  			Model: "virtio",
  3515  			Rate: &DomainRNGRate{
  3516  				Period: 2000,
  3517  				Bytes:  1234,
  3518  			},
  3519  			Backend: &DomainRNGBackend{
  3520  				EGD: &DomainRNGBackendEGD{
  3521  					Source: &DomainChardevSource{
  3522  						UDP: &DomainChardevSourceUDP{
  3523  							BindService:    "1234",
  3524  							ConnectHost:    "1.2.3.4",
  3525  							ConnectService: "1234",
  3526  						},
  3527  					},
  3528  				},
  3529  			},
  3530  		},
  3531  
  3532  		Expected: []string{
  3533  			`<rng model="virtio">`,
  3534  			`  <rate bytes="1234" period="2000"></rate>`,
  3535  			`  <backend model="egd" type="udp">`,
  3536  			`    <source mode="bind" service="1234"></source>`,
  3537  			`    <source mode="connect" host="1.2.3.4" service="1234"></source>`,
  3538  			`  </backend>`,
  3539  			`</rng>`,
  3540  		},
  3541  	},
  3542  	{
  3543  		Object: &DomainHostdev{
  3544  			SubsysSCSI: &DomainHostdevSubsysSCSI{
  3545  				SGIO:  "unfiltered",
  3546  				RawIO: "yes",
  3547  				Source: &DomainHostdevSubsysSCSISource{
  3548  					Host: &DomainHostdevSubsysSCSISourceHost{
  3549  						Adapter: &DomainHostdevSubsysSCSIAdapter{
  3550  							Name: "scsi_host0",
  3551  						},
  3552  						Address: &DomainAddressDrive{
  3553  							Bus:    &hostdevSCSI.Bus,
  3554  							Target: &hostdevSCSI.Target,
  3555  							Unit:   &hostdevSCSI.Unit,
  3556  						},
  3557  					},
  3558  				},
  3559  			},
  3560  			Address: &DomainAddress{
  3561  				Drive: &DomainAddressDrive{
  3562  					Controller: &hostdevSCSI.Controller,
  3563  					Bus:        &hostdevSCSI.Bus,
  3564  					Target:     &hostdevSCSI.Target,
  3565  					Unit:       &hostdevSCSI.Unit,
  3566  				},
  3567  			},
  3568  		},
  3569  
  3570  		Expected: []string{
  3571  			`<hostdev mode="subsystem" type="scsi" sgio="unfiltered" rawio="yes">`,
  3572  			`  <source>`,
  3573  			`    <adapter name="scsi_host0"></adapter>`,
  3574  			`    <address bus="0" target="3" unit="0"></address>`,
  3575  			`  </source>`,
  3576  			`  <address type="drive" controller="0" bus="0" target="3" unit="0"></address>`,
  3577  			`</hostdev>`,
  3578  		},
  3579  	},
  3580  	{
  3581  		Object: &DomainHostdev{
  3582  			SubsysSCSI: &DomainHostdevSubsysSCSI{
  3583  				SGIO:  "unfiltered",
  3584  				RawIO: "yes",
  3585  				Source: &DomainHostdevSubsysSCSISource{
  3586  					ISCSI: &DomainHostdevSubsysSCSISourceISCSI{
  3587  						Name: "iqn.1992-01.com.example:storage/1",
  3588  						Host: []DomainDiskSourceHost{
  3589  							DomainDiskSourceHost{
  3590  								Name: "example.org",
  3591  								Port: "3260",
  3592  							},
  3593  						},
  3594  						Auth: &DomainDiskAuth{
  3595  							Username: "myname",
  3596  							Secret: &DomainDiskSecret{
  3597  								Type:  "iscsi",
  3598  								Usage: "mycluster_myname",
  3599  							},
  3600  						},
  3601  					},
  3602  				},
  3603  			},
  3604  			Address: &DomainAddress{
  3605  				Drive: &DomainAddressDrive{
  3606  					Controller: &hostdevSCSI.Controller,
  3607  					Bus:        &hostdevSCSI.Bus,
  3608  					Target:     &hostdevSCSI.Target,
  3609  					Unit:       &hostdevSCSI.Unit,
  3610  				},
  3611  			},
  3612  		},
  3613  
  3614  		Expected: []string{
  3615  			`<hostdev mode="subsystem" type="scsi" sgio="unfiltered" rawio="yes">`,
  3616  			`  <source protocol="iscsi" name="iqn.1992-01.com.example:storage/1">`,
  3617  			`    <host name="example.org" port="3260"></host>`,
  3618  			`    <auth username="myname">`,
  3619  			`      <secret type="iscsi" usage="mycluster_myname"></secret>`,
  3620  			`    </auth>`,
  3621  			`  </source>`,
  3622  			`  <address type="drive" controller="0" bus="0" target="3" unit="0"></address>`,
  3623  			`</hostdev>`,
  3624  		},
  3625  	},
  3626  	{
  3627  		Object: &DomainHostdev{
  3628  			SubsysSCSIHost: &DomainHostdevSubsysSCSIHost{
  3629  				Source: &DomainHostdevSubsysSCSIHostSource{
  3630  					Protocol: "vhost",
  3631  					WWPN:     "naa.5123456789abcde0",
  3632  				},
  3633  			},
  3634  		},
  3635  
  3636  		Expected: []string{
  3637  			`<hostdev mode="subsystem" type="scsi_host">`,
  3638  			`  <source protocol="vhost" wwpn="naa.5123456789abcde0"></source>`,
  3639  			`</hostdev>`,
  3640  		},
  3641  	},
  3642  	{
  3643  		Object: &DomainHostdev{
  3644  			SubsysUSB: &DomainHostdevSubsysUSB{
  3645  				Source: &DomainHostdevSubsysUSBSource{
  3646  					Address: &DomainAddressUSB{
  3647  						Bus:    &usbHostBus,
  3648  						Device: &usbHostDevice,
  3649  					},
  3650  				},
  3651  			},
  3652  		},
  3653  
  3654  		Expected: []string{
  3655  			`<hostdev mode="subsystem" type="usb">`,
  3656  			`  <source>`,
  3657  			`    <address bus="14" device="6"></address>`,
  3658  			`  </source>`,
  3659  			`</hostdev>`,
  3660  		},
  3661  	},
  3662  	{
  3663  		Object: &DomainHostdev{
  3664  			Managed: "yes",
  3665  			SubsysPCI: &DomainHostdevSubsysPCI{
  3666  				Source: &DomainHostdevSubsysPCISource{
  3667  					Address: &DomainAddressPCI{
  3668  						Domain:   &pciHostDomain,
  3669  						Bus:      &pciHostBus,
  3670  						Slot:     &pciHostSlot,
  3671  						Function: &pciHostFunction,
  3672  					},
  3673  				},
  3674  			},
  3675  		},
  3676  
  3677  		Expected: []string{
  3678  			`<hostdev mode="subsystem" type="pci" managed="yes">`,
  3679  			`  <source>`,
  3680  			`    <address domain="0x0000" bus="0x03" slot="0x0e" function="0x5"></address>`,
  3681  			`  </source>`,
  3682  			`</hostdev>`,
  3683  		},
  3684  	},
  3685  	{
  3686  		Object: &DomainHostdev{
  3687  			SubsysMDev: &DomainHostdevSubsysMDev{
  3688  				Model: "vfio-pci",
  3689  				Source: &DomainHostdevSubsysMDevSource{
  3690  					Address: &DomainAddressMDev{
  3691  						UUID: "53764d0e-85a0-42b4-af5c-2046b460b1dc",
  3692  					},
  3693  				},
  3694  			},
  3695  		},
  3696  
  3697  		Expected: []string{
  3698  			`<hostdev mode="subsystem" type="mdev" model="vfio-pci">`,
  3699  			`  <source>`,
  3700  			`    <address uuid="53764d0e-85a0-42b4-af5c-2046b460b1dc"></address>`,
  3701  			`  </source>`,
  3702  			`</hostdev>`,
  3703  		},
  3704  	},
  3705  	{
  3706  		Object: &DomainHostdev{
  3707  			CapsStorage: &DomainHostdevCapsStorage{
  3708  				Source: &DomainHostdevCapsStorageSource{
  3709  					Block: "/dev/sda",
  3710  				},
  3711  			},
  3712  		},
  3713  
  3714  		Expected: []string{
  3715  			`<hostdev mode="capabilities" type="storage">`,
  3716  			`  <source>`,
  3717  			`    <block>/dev/sda</block>`,
  3718  			`  </source>`,
  3719  			`</hostdev>`,
  3720  		},
  3721  	},
  3722  	{
  3723  		Object: &DomainHostdev{
  3724  			CapsMisc: &DomainHostdevCapsMisc{
  3725  				Source: &DomainHostdevCapsMiscSource{
  3726  					Char: "/dev/kvm",
  3727  				},
  3728  			},
  3729  		},
  3730  
  3731  		Expected: []string{
  3732  			`<hostdev mode="capabilities" type="misc">`,
  3733  			`  <source>`,
  3734  			`    <char>/dev/kvm</char>`,
  3735  			`  </source>`,
  3736  			`</hostdev>`,
  3737  		},
  3738  	},
  3739  	{
  3740  		Object: &DomainHostdev{
  3741  			CapsNet: &DomainHostdevCapsNet{
  3742  				Source: &DomainHostdevCapsNetSource{
  3743  					Interface: "eth0",
  3744  				},
  3745  				IP: []DomainIP{
  3746  					DomainIP{
  3747  						Address: "192.168.122.2",
  3748  						Family:  "ipv4",
  3749  					},
  3750  					DomainIP{
  3751  						Address: "2003:db8:1:0:214:1234:fe0b:3596",
  3752  						Family:  "ipv6",
  3753  						Prefix:  &ipv6Prefix,
  3754  					},
  3755  				},
  3756  				Route: []DomainRoute{
  3757  					DomainRoute{
  3758  						Family:  "ipv4",
  3759  						Address: "0.0.0.0",
  3760  						Gateway: "192.168.122.1",
  3761  					},
  3762  					DomainRoute{
  3763  						Family:  "ipv6",
  3764  						Address: "::",
  3765  						Gateway: "2003:db8:1:0:214:1234:fe0b:3595",
  3766  					},
  3767  				},
  3768  			},
  3769  		},
  3770  
  3771  		Expected: []string{
  3772  			`<hostdev mode="capabilities" type="net">`,
  3773  			`  <source>`,
  3774  			`    <interface>eth0</interface>`,
  3775  			`  </source>`,
  3776  			`  <ip address="192.168.122.2" family="ipv4"></ip>`,
  3777  			`  <ip address="2003:db8:1:0:214:1234:fe0b:3596" family="ipv6" prefix="24"></ip>`,
  3778  			`  <route family="ipv4" address="0.0.0.0" gateway="192.168.122.1"></route>`,
  3779  			`  <route family="ipv6" address="::" gateway="2003:db8:1:0:214:1234:fe0b:3595"></route>`,
  3780  			`</hostdev>`,
  3781  		},
  3782  	},
  3783  	{
  3784  		Object: &DomainMemorydev{
  3785  			Model:  "dimm",
  3786  			Access: "private",
  3787  			Source: &DomainMemorydevSource{
  3788  				PageSize: &DomainMemorydevSourcePagesize{
  3789  					Value: 2048,
  3790  					Unit:  "KiB",
  3791  				},
  3792  				Path:     "/tmp/nvdimm",
  3793  				NodeMask: "0-1",
  3794  			},
  3795  			Target: &DomainMemorydevTarget{
  3796  				Size: &DomainMemorydevTargetSize{
  3797  					Value: 1,
  3798  					Unit:  "GiB",
  3799  				},
  3800  				Node: &DomainMemorydevTargetNode{
  3801  					Value: 0,
  3802  				},
  3803  				Label: &DomainMemorydevTargetLabel{
  3804  					Size: &DomainMemorydevTargetSize{
  3805  						Value: 200,
  3806  						Unit:  "KiB",
  3807  					},
  3808  				},
  3809  			},
  3810  		},
  3811  
  3812  		Expected: []string{
  3813  			`<memory model="dimm" access="private">`,
  3814  			`  <source>`,
  3815  			`    <nodemask>0-1</nodemask>`,
  3816  			`    <pagesize unit="KiB">2048</pagesize>`,
  3817  			`    <path>/tmp/nvdimm</path>`,
  3818  			`  </source>`,
  3819  			`  <target>`,
  3820  			`    <size unit="GiB">1</size>`,
  3821  			`    <node>0</node>`,
  3822  			`    <label>`,
  3823  			`      <size unit="KiB">200</size>`,
  3824  			`    </label>`,
  3825  			`  </target>`,
  3826  			`</memory>`,
  3827  		},
  3828  	},
  3829  	/* Host Bootloader -- bhyve, Xen */
  3830  	{
  3831  		Object: &Domain{
  3832  			Type:           "bhyve",
  3833  			Name:           "test",
  3834  			Bootloader:     "/usr/local/sbin/grub-bhyve",
  3835  			BootloaderArgs: "-r cd0 -m /tmp/test-device.map -M 1024M linuxguest",
  3836  		},
  3837  		Expected: []string{
  3838  			`<domain type="bhyve">`,
  3839  			`  <name>test</name>`,
  3840  			`  <bootloader>/usr/local/sbin/grub-bhyve</bootloader>`,
  3841  			`  <bootloader_args>-r cd0 -m /tmp/test-device.map -M 1024M linuxguest</bootloader_args>`,
  3842  			`</domain>`,
  3843  		},
  3844  	},
  3845  	{
  3846  		Object: &Domain{
  3847  			Name: "demo",
  3848  			Devices: &DomainDeviceList{
  3849  				Graphics: []DomainGraphic{
  3850  					DomainGraphic{SDL: &DomainGraphicSDL{}},
  3851  					DomainGraphic{VNC: &DomainGraphicVNC{}},
  3852  					DomainGraphic{RDP: &DomainGraphicRDP{}},
  3853  					DomainGraphic{Desktop: &DomainGraphicDesktop{}},
  3854  					DomainGraphic{Spice: &DomainGraphicSpice{}},
  3855  				},
  3856  			},
  3857  		},
  3858  		Expected: []string{
  3859  			`<domain>`,
  3860  			`  <name>demo</name>`,
  3861  			`  <devices>`,
  3862  			`    <graphics type="sdl"></graphics>`,
  3863  			`    <graphics type="vnc"></graphics>`,
  3864  			`    <graphics type="rdp"></graphics>`,
  3865  			`    <graphics type="desktop"></graphics>`,
  3866  			`    <graphics type="spice"></graphics>`,
  3867  			`  </devices>`,
  3868  			`</domain>`,
  3869  		},
  3870  	},
  3871  }
  3872  
  3873  func TestDomain(t *testing.T) {
  3874  	for _, test := range domainTestData {
  3875  		doc, err := test.Object.Marshal()
  3876  		if err != nil {
  3877  			t.Fatal(err)
  3878  		}
  3879  
  3880  		expect := strings.Join(test.Expected, "\n")
  3881  
  3882  		if doc != expect {
  3883  			t.Fatal("Bad initial xml:\n", string(doc), "\n does not match\n", expect, "\n")
  3884  		}
  3885  
  3886  		typ := reflect.ValueOf(test.Object).Elem().Type()
  3887  
  3888  		newobj := reflect.New(typ)
  3889  
  3890  		newdocobj, ok := newobj.Interface().(Document)
  3891  		if !ok {
  3892  			t.Fatalf("Could not clone %s", newobj.Interface())
  3893  		}
  3894  
  3895  		err = newdocobj.Unmarshal(expect)
  3896  		if err != nil {
  3897  			t.Fatal(err)
  3898  		}
  3899  
  3900  		doc, err = newdocobj.Marshal()
  3901  		if err != nil {
  3902  			t.Fatal(err)
  3903  		}
  3904  
  3905  		if doc != expect {
  3906  			t.Fatal("Bad roundtrip xml:\n", string(doc), "\n does not match\n", expect, "\n")
  3907  		}
  3908  	}
  3909  }