2 * Copyright (C) 2011-2014 Red Hat, Inc.
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library. If not, see
16 * <http://www.gnu.org/licenses/>.
22 #include "testutils.h"
23 #include "testutilsqemu.h"
24 #include "testutilsqemuschema.h"
25 #include "qemumonitortestutils.h"
26 #include "qemu/qemu_domain.h"
27 #include "qemu/qemu_block.h"
28 #include "qemu/qemu_monitor_json.h"
29 #include "qemu/qemu_qapi.h"
30 #include "virthread.h"
32 #include "virstring.h"
34 #include "qemu/qemu_monitor.h"
35 #include "qemu/qemu_migration_params.h"
36 #define LIBVIRT_QEMU_MIGRATION_PARAMSPRIV_H_ALLOW
37 #include "qemu/qemu_migration_paramspriv.h"
39 #define VIR_FROM_THIS VIR_FROM_NONE
41 typedef struct _testQemuMonitorJSONSimpleFuncData testQemuMonitorJSONSimpleFuncData
;
42 typedef testQemuMonitorJSONSimpleFuncData
*testQemuMonitorJSONSimpleFuncDataPtr
;
43 struct _testQemuMonitorJSONSimpleFuncData
{
45 int (* func
) (qemuMonitorPtr mon
);
46 virDomainXMLOptionPtr xmlopt
;
48 virHashTablePtr schema
;
51 typedef struct _testGenericData testGenericData
;
52 struct _testGenericData
{
53 virDomainXMLOptionPtr xmlopt
;
54 virHashTablePtr schema
;
57 const char *queryBlockReply
=
61 " \"io-status\": \"ok\","
62 " \"device\": \"drive-virtio-disk0\","
64 " \"removable\": false,"
69 " \"backing_file_depth\": 0,"
70 " \"drv\": \"qcow2\","
73 " \"encrypted\": false,"
80 " \"iops_rd_max\": 11,"
81 " \"iops_wr_max\": 12,"
83 " \"group\": \"group14\","
84 " \"bps_max_length\": 15,"
85 " \"bps_rd_max_length\": 16,"
86 " \"bps_wr_max_length\": 17,"
87 " \"iops_max_length\": 18,"
88 " \"iops_rd_max_length\": 19,"
89 " \"iops_wr_max_length\": 20,"
90 " \"file\": \"/home/zippy/work/tmp/gentoo.qcow2\","
91 " \"encryption_key_missing\": false"
93 " \"type\": \"unknown\""
96 " \"io-status\": \"ok\","
97 " \"device\": \"drive-virtio-disk1\","
99 " \"removable\": false,"
104 " \"backing_file_depth\": 0,"
108 " \"encrypted\": false,"
111 " \"file\": \"/home/zippy/test.bin\","
112 " \"encryption_key_missing\": false"
114 " \"type\": \"unknown\""
117 " \"io-status\": \"ok\","
118 " \"device\": \"drive-ide0-1-0\","
120 " \"removable\": true,"
125 " \"backing_file_depth\": 0,"
129 " \"encrypted\": false,"
132 " \"file\": \"/home/zippy/tmp/install-amd64-minimal-20121210.iso\","
133 " \"encryption_key_missing\": false"
135 " \"tray_open\": false,"
136 " \"type\": \"unknown\""
139 " \"io-status\": \"ok\","
140 " \"device\": \"drive-ide0-1-1\","
141 " \"locked\": false,"
142 " \"removable\": true,"
143 " \"tray_open\": false,"
144 " \"type\": \"unknown\""
147 " \"id\": \"libvirt-10\""
151 testQemuMonitorJSONGetStatus(const void *opaque
)
153 const testGenericData
*data
= opaque
;
154 virDomainXMLOptionPtr xmlopt
= data
->xmlopt
;
155 bool running
= false;
156 virDomainPausedReason reason
= 0;
157 VIR_AUTOPTR(qemuMonitorTest
) test
= NULL
;
159 if (!(test
= qemuMonitorTestNewSchema(xmlopt
, data
->schema
)))
162 if (qemuMonitorTestAddItem(test
, "query-status",
165 " \"status\": \"running\", "
166 " \"singlestep\": false, "
167 " \"running\": true "
171 if (qemuMonitorTestAddItem(test
, "query-status",
174 " \"singlestep\": false, "
175 " \"running\": false "
179 if (qemuMonitorTestAddItem(test
, "query-status",
182 " \"status\": \"inmigrate\", "
183 " \"singlestep\": false, "
184 " \"running\": false "
189 if (qemuMonitorGetStatus(qemuMonitorTestGetMonitor(test
),
190 &running
, &reason
) < 0)
194 virReportError(VIR_ERR_INTERNAL_ERROR
, "%s",
195 "Running was not true");
199 if (reason
!= VIR_DOMAIN_PAUSED_UNKNOWN
) {
200 virReportError(VIR_ERR_INTERNAL_ERROR
,
201 "Reason was unexpectedly set to %d", reason
);
205 if (qemuMonitorGetStatus(qemuMonitorTestGetMonitor(test
),
206 &running
, &reason
) < 0)
210 virReportError(VIR_ERR_INTERNAL_ERROR
, "%s",
211 "Running was not false");
215 if (reason
!= VIR_DOMAIN_PAUSED_UNKNOWN
) {
216 virReportError(VIR_ERR_INTERNAL_ERROR
,
217 "Reason was unexpectedly set to %d", reason
);
221 if (qemuMonitorGetStatus(qemuMonitorTestGetMonitor(test
),
222 &running
, &reason
) < 0)
226 virReportError(VIR_ERR_INTERNAL_ERROR
, "%s",
227 "Running was not false");
231 if (reason
!= VIR_DOMAIN_PAUSED_MIGRATION
) {
232 virReportError(VIR_ERR_INTERNAL_ERROR
,
233 "Reason was unexpectedly set to %d", reason
);
241 testQemuMonitorJSONGetVersion(const void *opaque
)
243 const testGenericData
*data
= opaque
;
244 virDomainXMLOptionPtr xmlopt
= data
->xmlopt
;
249 char *package
= NULL
;
250 VIR_AUTOPTR(qemuMonitorTest
) test
= NULL
;
252 if (!(test
= qemuMonitorTestNewSchema(xmlopt
, data
->schema
)))
255 if (qemuMonitorTestAddItem(test
, "query-version",
268 if (qemuMonitorTestAddItem(test
, "query-version",
276 " \"package\":\"2.283.el6\""
281 if (qemuMonitorGetVersion(qemuMonitorTestGetMonitor(test
),
282 &major
, &minor
, µ
,
287 virReportError(VIR_ERR_INTERNAL_ERROR
,
288 "Major %d was not 1", major
);
292 virReportError(VIR_ERR_INTERNAL_ERROR
,
293 "Minor %d was not 2", major
);
297 virReportError(VIR_ERR_INTERNAL_ERROR
,
298 "Micro %d was not 3", major
);
302 if (STRNEQ(package
, "")) {
303 virReportError(VIR_ERR_INTERNAL_ERROR
,
304 "Package %s was not ''", package
);
309 if (qemuMonitorGetVersion(qemuMonitorTestGetMonitor(test
),
310 &major
, &minor
, µ
,
315 virReportError(VIR_ERR_INTERNAL_ERROR
,
316 "Major %d was not 0", major
);
320 virReportError(VIR_ERR_INTERNAL_ERROR
,
321 "Minor %d was not 11", major
);
325 virReportError(VIR_ERR_INTERNAL_ERROR
,
326 "Micro %d was not 6", major
);
330 if (STRNEQ(package
, "2.283.el6")) {
331 virReportError(VIR_ERR_INTERNAL_ERROR
,
332 "Package %s was not '2.283.el6'", package
);
344 testQemuMonitorJSONGetMachines(const void *opaque
)
346 const testGenericData
*data
= opaque
;
347 virDomainXMLOptionPtr xmlopt
= data
->xmlopt
;
349 qemuMonitorMachineInfoPtr
*info
;
351 const char *null
= NULL
;
354 VIR_AUTOPTR(qemuMonitorTest
) test
= NULL
;
356 if (!(test
= qemuMonitorTestNewSchema(xmlopt
, data
->schema
)))
359 if (qemuMonitorTestAddItem(test
, "query-machines",
363 " \"name\": \"pc-1.0\" "
366 " \"name\": \"pc-1.1\" "
369 " \"name\": \"pc-1.2\", "
370 " \"is-default\": true, "
371 " \"alias\": \"pc\" "
377 if ((ninfo
= qemuMonitorGetMachines(qemuMonitorTestGetMonitor(test
),
382 virReportError(VIR_ERR_INTERNAL_ERROR
,
383 "ninfo %d is not 3", ninfo
);
387 #define CHECK(i, wantname, wantisDefault, wantalias) \
389 if (STRNEQ(info[i]->name, (wantname))) { \
390 virReportError(VIR_ERR_INTERNAL_ERROR, \
391 "name %s is not %s", \
392 info[i]->name, (wantname)); \
395 if (info[i]->isDefault != (wantisDefault)) { \
396 virReportError(VIR_ERR_INTERNAL_ERROR, \
397 "isDefault %d is not %d", \
398 info[i]->isDefault, (wantisDefault)); \
401 if (STRNEQ_NULLABLE(info[i]->alias, (wantalias))) { \
402 virReportError(VIR_ERR_INTERNAL_ERROR, \
403 "alias %s is not %s", \
404 info[i]->alias, NULLSTR(wantalias)); \
409 CHECK(0, "pc-1.0", false, null
);
410 CHECK(1, "pc-1.1", false, null
);
411 CHECK(2, "pc-1.2", true, "pc");
418 for (i
= 0; i
< ninfo
; i
++)
419 qemuMonitorMachineInfoFree(info
[i
]);
427 testQemuMonitorJSONGetCPUDefinitions(const void *opaque
)
429 const testGenericData
*data
= opaque
;
430 virDomainXMLOptionPtr xmlopt
= data
->xmlopt
;
432 qemuMonitorCPUDefInfoPtr
*cpus
= NULL
;
435 VIR_AUTOPTR(qemuMonitorTest
) test
= NULL
;
437 if (!(test
= qemuMonitorTestNewSchema(xmlopt
, data
->schema
)))
440 if (qemuMonitorTestAddItem(test
, "query-cpu-definitions",
444 " \"name\": \"qemu64\" "
447 " \"name\": \"Opteron_G4\", "
448 " \"unavailable-features\": [\"vme\"]"
451 " \"name\": \"Westmere\", "
452 " \"unavailable-features\": []"
458 if ((ncpus
= qemuMonitorGetCPUDefinitions(qemuMonitorTestGetMonitor(test
),
463 virReportError(VIR_ERR_INTERNAL_ERROR
,
464 "ncpus %d is not 3", ncpus
);
468 #define CHECK_FULL(i, wantname, Usable) \
470 if (STRNEQ(cpus[i]->name, (wantname))) { \
471 virReportError(VIR_ERR_INTERNAL_ERROR, \
472 "name %s is not %s", \
473 cpus[i]->name, (wantname)); \
476 if (cpus[i]->usable != (Usable)) { \
477 virReportError(VIR_ERR_INTERNAL_ERROR, \
478 "%s: expecting usable flag %d, got %d", \
479 cpus[i]->name, Usable, cpus[i]->usable); \
484 #define CHECK(i, wantname) \
485 CHECK_FULL(i, wantname, VIR_TRISTATE_BOOL_ABSENT)
487 #define CHECK_USABLE(i, wantname, usable) \
488 CHECK_FULL(i, wantname, \
489 usable ? VIR_TRISTATE_BOOL_YES : VIR_TRISTATE_BOOL_NO)
492 CHECK_USABLE(1, "Opteron_G4", false);
493 CHECK_USABLE(2, "Westmere", true);
502 for (i
= 0; i
< ncpus
; i
++)
503 qemuMonitorCPUDefInfoFree(cpus
[i
]);
510 testQemuMonitorJSONGetCommands(const void *opaque
)
512 const testGenericData
*data
= opaque
;
513 virDomainXMLOptionPtr xmlopt
= data
->xmlopt
;
515 char **commands
= NULL
;
518 VIR_AUTOPTR(qemuMonitorTest
) test
= NULL
;
520 if (!(test
= qemuMonitorTestNewSchema(xmlopt
, data
->schema
)))
523 if (qemuMonitorTestAddItem(test
, "query-commands",
527 " \"name\": \"system_wakeup\" "
530 " \"name\": \"cont\" "
533 " \"name\": \"quit\" "
539 if ((ncommands
= qemuMonitorGetCommands(qemuMonitorTestGetMonitor(test
),
543 if (ncommands
!= 3) {
544 virReportError(VIR_ERR_INTERNAL_ERROR
,
545 "ncommands %d is not 3", ncommands
);
549 #define CHECK(i, wantname) \
551 if (STRNEQ(commands[i], (wantname))) { \
552 virReportError(VIR_ERR_INTERNAL_ERROR, \
553 "name %s is not %s", \
554 commands[i], (wantname)); \
559 CHECK(0, "system_wakeup");
567 for (i
= 0; i
< ncommands
; i
++)
568 VIR_FREE(commands
[i
]);
575 testQemuMonitorJSONGetTPMModels(const void *opaque
)
577 const testGenericData
*data
= opaque
;
578 virDomainXMLOptionPtr xmlopt
= data
->xmlopt
;
580 char **tpmmodels
= NULL
;
582 VIR_AUTOPTR(qemuMonitorTest
) test
= NULL
;
584 if (!(test
= qemuMonitorTestNewSchema(xmlopt
, data
->schema
)))
587 if (qemuMonitorTestAddItem(test
, "query-tpm-models",
595 if ((ntpmmodels
= qemuMonitorGetTPMModels(qemuMonitorTestGetMonitor(test
),
599 if (ntpmmodels
!= 1) {
600 virReportError(VIR_ERR_INTERNAL_ERROR
,
601 "ntpmmodels %d is not 1", ntpmmodels
);
605 #define CHECK(i, wantname) \
607 if (STRNEQ(tpmmodels[i], (wantname))) { \
608 virReportError(VIR_ERR_INTERNAL_ERROR, \
609 "name %s is not %s", \
610 tpmmodels[i], (wantname)); \
615 CHECK(0, "passthrough");
622 virStringListFree(tpmmodels
);
628 testQemuMonitorJSONGetCommandLineOptionParameters(const void *opaque
)
630 const testGenericData
*data
= opaque
;
631 virDomainXMLOptionPtr xmlopt
= data
->xmlopt
;
633 char **params
= NULL
;
636 VIR_AUTOPTR(qemuMonitorTest
) test
= NULL
;
638 if (!(test
= qemuMonitorTestNewSchema(xmlopt
, data
->schema
)))
641 if (qemuMonitorTestAddItem(test
, "query-command-line-options",
644 " {\"parameters\": [], \"option\": \"acpi\" },"
645 " {\"parameters\": ["
646 " {\"name\": \"romfile\", "
647 " \"type\": \"string\"}, "
648 " {\"name\": \"bootindex\", "
649 " \"type\": \"number\"}], "
650 " \"option\": \"option-rom\"}"
655 /* present with params */
656 if ((nparams
= qemuMonitorGetCommandLineOptionParameters(qemuMonitorTestGetMonitor(test
),
663 virReportError(VIR_ERR_INTERNAL_ERROR
,
664 "nparams was %d, expected 2", nparams
);
668 #define CHECK(i, wantname) \
670 if (STRNEQ(params[i], (wantname))) { \
671 virReportError(VIR_ERR_INTERNAL_ERROR, \
672 "name was %s, expected %s", \
673 params[i], (wantname)); \
679 CHECK(1, "bootindex");
683 virStringListFree(params
);
686 /* present but empty */
687 if ((nparams
= qemuMonitorGetCommandLineOptionParameters(qemuMonitorTestGetMonitor(test
),
694 virReportError(VIR_ERR_INTERNAL_ERROR
,
695 "nparams was %d, expected 0", nparams
);
699 virReportError(VIR_ERR_INTERNAL_ERROR
, "%s",
700 "found was false, expected true");
703 if (params
&& params
[0]) {
704 virReportError(VIR_ERR_INTERNAL_ERROR
, "%s",
705 "unexpected array contents");
709 virStringListFree(params
);
713 if ((nparams
= qemuMonitorGetCommandLineOptionParameters(qemuMonitorTestGetMonitor(test
),
720 virReportError(VIR_ERR_INTERNAL_ERROR
,
721 "nparams was %d, expected 0", nparams
);
725 virReportError(VIR_ERR_INTERNAL_ERROR
, "%s",
726 "found was true, expected false");
729 if (params
&& params
[0]) {
730 virReportError(VIR_ERR_INTERNAL_ERROR
, "%s",
731 "unexpected array contents");
738 virStringListFree(params
);
743 struct qemuMonitorJSONTestAttachChardevData
{
744 qemuMonitorTestPtr test
;
745 virDomainChrSourceDefPtr chr
;
746 const char *expectPty
;
751 testQemuMonitorJSONAttachChardev(const void *opaque
)
753 const struct qemuMonitorJSONTestAttachChardevData
*data
= opaque
;
756 if ((rc
= qemuMonitorAttachCharDev(qemuMonitorTestGetMonitor(data
->test
),
757 "alias", data
->chr
)) < 0)
760 if (data
->chr
->type
== VIR_DOMAIN_CHR_TYPE_PTY
) {
761 if (STRNEQ_NULLABLE(data
->expectPty
, data
->chr
->data
.file
.path
)) {
762 virReportError(VIR_ERR_INTERNAL_ERROR
,
763 "expected PTY path: %s got: %s",
764 NULLSTR(data
->expectPty
),
765 NULLSTR(data
->chr
->data
.file
.path
));
769 VIR_FREE(data
->chr
->data
.file
.path
);
773 if ((rc
!= 0) != data
->fail
)
781 qemuMonitorJSONTestAttachOneChardev(virDomainXMLOptionPtr xmlopt
,
782 virHashTablePtr schema
,
784 virDomainChrSourceDefPtr chr
,
785 const char *expectargs
,
787 const char *expectPty
,
791 struct qemuMonitorJSONTestAttachChardevData data
= {0};
792 char *jsonreply
= NULL
;
793 char *fulllabel
= NULL
;
799 if (virAsprintf(&jsonreply
, "{\"return\": {%s}}", reply
) < 0)
802 if (virAsprintf(&fulllabel
, "qemuMonitorJSONTestAttachChardev(%s)", label
) < 0)
807 data
.expectPty
= expectPty
;
808 if (!(data
.test
= qemuMonitorTestNewSchema(xmlopt
, schema
)))
811 if (qemuMonitorTestAddItemExpect(data
.test
, "chardev-add",
812 expectargs
, true, jsonreply
) < 0)
815 if (virTestRun(fulllabel
, &testQemuMonitorJSONAttachChardev
, &data
) < 0)
821 qemuMonitorTestFree(data
.test
);
828 qemuMonitorJSONTestAttachChardev(virDomainXMLOptionPtr xmlopt
,
829 virHashTablePtr schema
)
831 virDomainChrSourceDef chr
;
834 #define CHECK(label, fail, expectargs) \
835 if (qemuMonitorJSONTestAttachOneChardev(xmlopt, schema, label, &chr, \
836 expectargs, NULL, NULL, fail) < 0) \
839 chr
= (virDomainChrSourceDef
) { .type
= VIR_DOMAIN_CHR_TYPE_NULL
};
841 "{'id':'alias','backend':{'type':'null','data':{}}}");
843 chr
= (virDomainChrSourceDef
) { .type
= VIR_DOMAIN_CHR_TYPE_VC
};
845 "{'id':'alias','backend':{'type':'null','data':{}}}");
847 chr
= (virDomainChrSourceDef
) { .type
= VIR_DOMAIN_CHR_TYPE_PTY
};
848 if (qemuMonitorJSONTestAttachOneChardev(xmlopt
, schema
, "pty", &chr
,
850 "'backend':{'type':'pty',"
852 "\"pty\" : \"/dev/pts/0\"",
853 "/dev/pts/0", false) < 0)
856 chr
= (virDomainChrSourceDef
) { .type
= VIR_DOMAIN_CHR_TYPE_PTY
};
857 CHECK("pty missing path", true,
858 "{'id':'alias','backend':{'type':'pty','data':{}}}");
860 memset(&chr
, 0, sizeof(chr
));
861 chr
.type
= VIR_DOMAIN_CHR_TYPE_FILE
;
862 chr
.data
.file
.path
= (char *) "/test/path";
864 "{'id':'alias','backend':{'type':'file','data':{'out':'/test/path'}}}");
866 memset(&chr
, 0, sizeof(chr
));
867 chr
.type
= VIR_DOMAIN_CHR_TYPE_DEV
;
868 chr
.data
.file
.path
= (char *) "/test/path";
869 CHECK("device", false,
870 "{'id':'alias','backend':{'type':'serial','data':{'device':'/test/path'}}}");
872 memset(&chr
, 0, sizeof(chr
));
873 chr
.type
= VIR_DOMAIN_CHR_TYPE_TCP
;
874 chr
.data
.tcp
.host
= (char *) "example.com";
875 chr
.data
.tcp
.service
= (char *) "1234";
878 "'backend':{'type':'socket',"
879 "'data':{'addr':{'type':'inet',"
880 "'data':{'host':'example.com',"
883 "'server':false}}}");
885 memset(&chr
, 0, sizeof(chr
));
886 chr
.type
= VIR_DOMAIN_CHR_TYPE_UDP
;
887 chr
.data
.udp
.connectHost
= (char *) "example.com";
888 chr
.data
.udp
.connectService
= (char *) "1234";
891 "'backend':{'type':'udp',"
892 "'data':{'remote':{'type':'inet',"
893 "'data':{'host':'example.com',"
894 "'port':'1234'}}}}}");
896 chr
.data
.udp
.bindHost
= (char *) "localhost";
897 chr
.data
.udp
.bindService
= (char *) "4321";
900 "'backend':{'type':'udp',"
901 "'data':{'remote':{'type':'inet',"
902 "'data':{'host':'example.com',"
904 "'local':{'type':'inet',"
905 "'data':{'host':'localhost',"
906 "'port':'4321'}}}}}");
908 chr
.data
.udp
.bindHost
= NULL
;
909 chr
.data
.udp
.bindService
= (char *) "4321";
912 "'backend':{'type':'udp',"
913 "'data':{'remote':{'type':'inet',"
914 "'data':{'host':'example.com',"
916 "'local':{'type':'inet',"
918 "'port':'4321'}}}}}");
919 memset(&chr
, 0, sizeof(chr
));
920 chr
.type
= VIR_DOMAIN_CHR_TYPE_UNIX
;
921 chr
.data
.nix
.path
= (char *) "/path/to/socket";
924 "'backend':{'type':'socket',"
925 "'data':{'addr':{'type':'unix',"
926 "'data':{'path':'/path/to/socket'}},"
927 "'server':false}}}");
929 chr
= (virDomainChrSourceDef
) { .type
= VIR_DOMAIN_CHR_TYPE_SPICEVMC
};
930 CHECK("spicevmc", false,
931 "{'id':'alias','backend':{'type':'spicevmc','"
932 "data':{'type':'vdagent'}}}");
934 chr
= (virDomainChrSourceDef
) { .type
= VIR_DOMAIN_CHR_TYPE_PIPE
};
935 CHECK("pipe", true, "");
937 chr
= (virDomainChrSourceDef
) { .type
= VIR_DOMAIN_CHR_TYPE_STDIO
};
938 CHECK("stdio", true, "");
946 testQemuMonitorJSONDetachChardev(const void *opaque
)
948 const testGenericData
*data
= opaque
;
949 virDomainXMLOptionPtr xmlopt
= data
->xmlopt
;
950 VIR_AUTOPTR(qemuMonitorTest
) test
= NULL
;
952 if (!(test
= qemuMonitorTestNewSchema(xmlopt
, data
->schema
)))
955 if (qemuMonitorTestAddItem(test
, "chardev-remove", "{\"return\": {}}") < 0)
958 if (qemuMonitorDetachCharDev(qemuMonitorTestGetMonitor(test
),
966 * This test will request to return a list of paths for "/". It should be
967 * a simple list of 1 real element that being the "machine". The following
968 * is the execution and expected return:
970 * {"execute":"qom-list", "arguments": { "path": "/"}}"
971 * {"return": [{"name": "machine", "type": "child<container>"}, \
972 * {"name": "type", "type": "string"}]}
975 testQemuMonitorJSONGetListPaths(const void *opaque
)
977 const testGenericData
*data
= opaque
;
978 virDomainXMLOptionPtr xmlopt
= data
->xmlopt
;
980 qemuMonitorJSONListPathPtr
*paths
;
983 VIR_AUTOPTR(qemuMonitorTest
) test
= NULL
;
985 if (!(test
= qemuMonitorTestNewSchema(xmlopt
, data
->schema
)))
988 if (qemuMonitorTestAddItem(test
, "qom-list",
991 " {\"name\": \"machine\", "
992 " \"type\": \"child<container>\"}, "
993 " {\"name\": \"type\", "
994 " \"type\": \"string\"} "
999 /* present with path */
1000 if ((npaths
= qemuMonitorJSONGetObjectListPaths(
1001 qemuMonitorTestGetMonitor(test
),
1007 virReportError(VIR_ERR_INTERNAL_ERROR
,
1008 "npaths was %d, expected 1", npaths
);
1012 #define CHECK(i, wantname, wanttype) \
1014 if (STRNEQ(paths[i]->name, (wantname))) { \
1015 virReportError(VIR_ERR_INTERNAL_ERROR, \
1016 "name was %s, expected %s", \
1017 paths[i]->name, (wantname)); \
1020 if (STRNEQ_NULLABLE(paths[i]->type, (wanttype))) { \
1021 virReportError(VIR_ERR_INTERNAL_ERROR, \
1022 "type was %s, expected %s", \
1023 NULLSTR(paths[i]->type), (wanttype)); \
1028 CHECK(0, "machine", "child<container>");
1035 for (i
= 0; i
< npaths
; i
++)
1036 qemuMonitorJSONListPathFree(paths
[i
]);
1043 * This test will use a path to /machine/i440fx which should exist in order
1044 * to ensure that the qom-get property fetch works properly. The following
1045 * is the execution and expected return:
1048 * { "execute": "qom-get","arguments": \
1049 * { "path": "/machine/i440fx","property": "realized"}}
1053 testQemuMonitorJSONGetObjectProperty(const void *opaque
)
1055 const testGenericData
*data
= opaque
;
1056 virDomainXMLOptionPtr xmlopt
= data
->xmlopt
;
1057 qemuMonitorJSONObjectProperty prop
;
1058 VIR_AUTOPTR(qemuMonitorTest
) test
= NULL
;
1060 if (!(test
= qemuMonitorTestNewSchema(xmlopt
, data
->schema
)))
1063 if (qemuMonitorTestAddItem(test
, "qom-get",
1064 "{ \"return\": true }") < 0)
1067 /* Present with path and property */
1068 memset(&prop
, 0, sizeof(qemuMonitorJSONObjectProperty
));
1069 prop
.type
= QEMU_MONITOR_OBJECT_PROPERTY_BOOLEAN
;
1070 if (qemuMonitorJSONGetObjectProperty(qemuMonitorTestGetMonitor(test
),
1077 virReportError(VIR_ERR_INTERNAL_ERROR
, "%s",
1078 "expected true, but false returned");
1087 * This test will use a path to /machine/i440fx which should exist in order
1088 * to ensure that the qom-set property set works properly. The test will
1089 * set a true property to true just as a proof of concept. Setting it to
1090 * false is not a good idea...
1093 testQemuMonitorJSONSetObjectProperty(const void *opaque
)
1095 const testGenericData
*data
= opaque
;
1096 virDomainXMLOptionPtr xmlopt
= data
->xmlopt
;
1097 qemuMonitorJSONObjectProperty prop
;
1098 VIR_AUTOPTR(qemuMonitorTest
) test
= NULL
;
1100 if (!(test
= qemuMonitorTestNewSchema(xmlopt
, data
->schema
)))
1103 if (qemuMonitorTestAddItem(test
, "qom-set",
1104 "{ \"return\": {} }") < 0)
1106 if (qemuMonitorTestAddItem(test
, "qom-get",
1107 "{ \"return\": true }") < 0)
1110 /* Let's attempt the setting */
1111 memset(&prop
, 0, sizeof(qemuMonitorJSONObjectProperty
));
1112 prop
.type
= QEMU_MONITOR_OBJECT_PROPERTY_BOOLEAN
;
1114 if (qemuMonitorJSONSetObjectProperty(qemuMonitorTestGetMonitor(test
),
1120 /* To make sure it worked, fetch the property - if this succeeds then
1121 * we didn't hose things
1123 memset(&prop
, 0, sizeof(qemuMonitorJSONObjectProperty
));
1124 prop
.type
= QEMU_MONITOR_OBJECT_PROPERTY_BOOLEAN
;
1125 if (qemuMonitorJSONGetObjectProperty(qemuMonitorTestGetMonitor(test
),
1132 virReportError(VIR_ERR_INTERNAL_ERROR
, "%s",
1133 "expected true, but false returned");
1142 testQemuMonitorJSONGetDeviceAliases(const void *opaque
)
1144 const testGenericData
*data
= opaque
;
1145 virDomainXMLOptionPtr xmlopt
= data
->xmlopt
;
1147 char **aliases
= NULL
;
1149 const char *expected
[] = {
1150 "virtio-disk25", "video0", "serial0", "ide0-0-0", "usb", NULL
};
1151 VIR_AUTOPTR(qemuMonitorTest
) test
= NULL
;
1153 if (!(test
= qemuMonitorTestNewSchema(xmlopt
, data
->schema
)))
1156 if (qemuMonitorTestAddItem(test
,
1159 " {\"name\": \"virtio-disk25\","
1160 " \"type\": \"child<virtio-blk-pci>\"},"
1161 " {\"name\": \"video0\","
1162 " \"type\": \"child<VGA>\"},"
1163 " {\"name\": \"serial0\","
1164 " \"type\": \"child<isa-serial>\"},"
1165 " {\"name\": \"ide0-0-0\","
1166 " \"type\": \"child<ide-cd>\"},"
1167 " {\"name\": \"usb\","
1168 " \"type\": \"child<piix3-usb-uhci>\"},"
1169 " {\"name\": \"type\", \"type\": \"string\"}"
1173 if (qemuMonitorJSONGetDeviceAliases(qemuMonitorTestGetMonitor(test
),
1178 virReportError(VIR_ERR_INTERNAL_ERROR
, "%s", "no aliases returned");
1183 for (alias
= (const char **) aliases
; *alias
; alias
++) {
1184 if (!virStringListHasString(expected
, *alias
)) {
1185 fprintf(stderr
, "got unexpected device alias '%s'\n", *alias
);
1189 for (alias
= expected
; *alias
; alias
++) {
1190 if (!virStringListHasString((const char **) aliases
, *alias
)) {
1191 fprintf(stderr
, "missing expected alias '%s'\n", *alias
);
1197 virStringListFree(aliases
);
1202 testQemuMonitorJSONCPU(const void *opaque
)
1204 const testGenericData
*data
= opaque
;
1205 virDomainXMLOptionPtr xmlopt
= data
->xmlopt
;
1206 bool running
= false;
1207 virDomainPausedReason reason
= 0;
1208 VIR_AUTOPTR(qemuMonitorTest
) test
= NULL
;
1210 if (!(test
= qemuMonitorTestNewSchema(xmlopt
, data
->schema
)))
1213 if (qemuMonitorTestAddItem(test
, "stop", "{\"return\": {}}") < 0 ||
1214 qemuMonitorTestAddItem(test
, "query-status",
1216 " \"status\": \"paused\","
1217 " \"singlestep\": false,"
1218 " \"running\": false}}") < 0 ||
1219 qemuMonitorTestAddItem(test
, "cont", "{\"return\": {}}") < 0 ||
1220 qemuMonitorTestAddItem(test
, "query-status",
1222 " \"status\": \"running\","
1223 " \"singlestep\": false,"
1224 " \"running\": true}}") < 0)
1227 if (qemuMonitorJSONStopCPUs(qemuMonitorTestGetMonitor(test
)) < 0)
1230 if (qemuMonitorGetStatus(qemuMonitorTestGetMonitor(test
),
1231 &running
, &reason
) < 0)
1235 virReportError(VIR_ERR_INTERNAL_ERROR
, "%s",
1236 "Running was not false");
1240 if (qemuMonitorJSONStartCPUs(qemuMonitorTestGetMonitor(test
)) < 0)
1243 if (qemuMonitorGetStatus(qemuMonitorTestGetMonitor(test
),
1244 &running
, &reason
) < 0)
1248 virReportError(VIR_ERR_INTERNAL_ERROR
, "%s",
1249 "Running was not true");
1257 testQemuMonitorJSONSimpleFunc(const void *opaque
)
1259 testQemuMonitorJSONSimpleFuncDataPtr data
=
1260 (testQemuMonitorJSONSimpleFuncDataPtr
) opaque
;
1261 virDomainXMLOptionPtr xmlopt
= data
->xmlopt
;
1262 const char *reply
= data
->reply
;
1263 VIR_AUTOPTR(qemuMonitorTest
) test
= NULL
;
1265 if (!(test
= qemuMonitorTestNewSchema(xmlopt
, data
->schema
)))
1269 reply
= "{\"return\":{}}";
1271 if (qemuMonitorTestAddItem(test
, data
->cmd
, reply
) < 0)
1274 if (data
->func(qemuMonitorTestGetMonitor(test
)) < 0)
1280 #define GEN_TEST_FUNC(funcName, ...) \
1282 testQemuMonitorJSON ## funcName(const void *opaque) \
1284 const testQemuMonitorJSONSimpleFuncData *data = opaque; \
1285 virDomainXMLOptionPtr xmlopt = data->xmlopt; \
1286 const char *reply = data->reply; \
1287 VIR_AUTOPTR(qemuMonitorTest) test = NULL; \
1289 if (!(test = qemuMonitorTestNewSchema(xmlopt, data->schema))) \
1293 reply = "{\"return\":{}}"; \
1295 if (qemuMonitorTestAddItem(test, data->cmd, reply) < 0) \
1298 if (funcName(qemuMonitorTestGetMonitor(test), __VA_ARGS__) < 0) \
1304 GEN_TEST_FUNC(qemuMonitorJSONSetLink
, "vnet0", VIR_DOMAIN_NET_INTERFACE_LINK_STATE_DOWN
)
1305 GEN_TEST_FUNC(qemuMonitorJSONBlockResize
, "vda", "asdf", 123456)
1306 GEN_TEST_FUNC(qemuMonitorJSONSetPassword
, "spice", "secret_password", "disconnect")
1307 GEN_TEST_FUNC(qemuMonitorJSONExpirePassword
, "spice", "123456")
1308 GEN_TEST_FUNC(qemuMonitorJSONSetBalloon
, 1024)
1309 GEN_TEST_FUNC(qemuMonitorJSONSetCPU
, 1, true)
1310 GEN_TEST_FUNC(qemuMonitorJSONEjectMedia
, "hdc", true)
1311 GEN_TEST_FUNC(qemuMonitorJSONChangeMedia
, "hdc", "/foo/bar", "formatstr")
1312 GEN_TEST_FUNC(qemuMonitorJSONSaveVirtualMemory
, 0, 1024, "/foo/bar")
1313 GEN_TEST_FUNC(qemuMonitorJSONSavePhysicalMemory
, 0, 1024, "/foo/bar")
1314 GEN_TEST_FUNC(qemuMonitorJSONSetMigrationSpeed
, 1024)
1315 GEN_TEST_FUNC(qemuMonitorJSONSetMigrationDowntime
, 1)
1316 GEN_TEST_FUNC(qemuMonitorJSONMigrate
, QEMU_MONITOR_MIGRATE_BACKGROUND
|
1317 QEMU_MONITOR_MIGRATE_NON_SHARED_DISK
|
1318 QEMU_MONITOR_MIGRATE_NON_SHARED_INC
, "tcp:localhost:12345")
1319 GEN_TEST_FUNC(qemuMonitorJSONDump
, "dummy_protocol", "elf",
1321 GEN_TEST_FUNC(qemuMonitorJSONGraphicsRelocate
, VIR_DOMAIN_GRAPHICS_TYPE_SPICE
,
1322 "localhost", 12345, 12346, "certsubjectval")
1323 GEN_TEST_FUNC(qemuMonitorJSONAddNetdev
, "id=net0,type=test")
1324 GEN_TEST_FUNC(qemuMonitorJSONRemoveNetdev
, "net0")
1325 GEN_TEST_FUNC(qemuMonitorJSONDelDevice
, "ide0")
1326 GEN_TEST_FUNC(qemuMonitorJSONAddDevice
, "some_dummy_devicestr")
1327 GEN_TEST_FUNC(qemuMonitorJSONDriveMirror
, "vdb", "/foo/bar", "formatstr", 1024, 1234, 31234, true, true)
1328 GEN_TEST_FUNC(qemuMonitorJSONBlockdevMirror
, "jobname", true, "vdb", "targetnode", 1024, 1234, 31234, true)
1329 GEN_TEST_FUNC(qemuMonitorJSONBlockStream
, "vdb", "jobname", true, "/foo/bar1", "backingnode", "backingfilename", 1024)
1330 GEN_TEST_FUNC(qemuMonitorJSONBlockCommit
, "vdb", "jobname", true, "/foo/bar1", "topnode", "/foo/bar2", "basenode", "backingfilename", 1024)
1331 GEN_TEST_FUNC(qemuMonitorJSONDrivePivot
, "vdb")
1332 GEN_TEST_FUNC(qemuMonitorJSONScreendump
, "devicename", 1, "/foo/bar")
1333 GEN_TEST_FUNC(qemuMonitorJSONOpenGraphics
, "spice", "spicefd", false)
1334 GEN_TEST_FUNC(qemuMonitorJSONNBDServerAdd
, "vda", "export", true, "bitmap")
1335 GEN_TEST_FUNC(qemuMonitorJSONDetachCharDev
, "serial1")
1336 GEN_TEST_FUNC(qemuMonitorJSONBlockdevTrayOpen
, "foodev", true)
1337 GEN_TEST_FUNC(qemuMonitorJSONBlockdevTrayClose
, "foodev")
1338 GEN_TEST_FUNC(qemuMonitorJSONBlockdevMediumRemove
, "foodev")
1339 GEN_TEST_FUNC(qemuMonitorJSONBlockdevMediumInsert
, "foodev", "newnode")
1340 GEN_TEST_FUNC(qemuMonitorJSONAddBitmap
, "node", "bitmap", true)
1341 GEN_TEST_FUNC(qemuMonitorJSONEnableBitmap
, "node", "bitmap")
1342 GEN_TEST_FUNC(qemuMonitorJSONDeleteBitmap
, "node", "bitmap")
1343 GEN_TEST_FUNC(qemuMonitorJSONJobDismiss
, "jobname")
1344 GEN_TEST_FUNC(qemuMonitorJSONJobCancel
, "jobname", false)
1345 GEN_TEST_FUNC(qemuMonitorJSONJobComplete
, "jobname")
1348 testQemuMonitorJSONqemuMonitorJSONNBDServerStart(const void *opaque
)
1350 const testGenericData
*data
= opaque
;
1351 virDomainXMLOptionPtr xmlopt
= data
->xmlopt
;
1352 virStorageNetHostDef server_tcp
= {
1353 .name
= (char *)"localhost",
1355 .transport
= VIR_STORAGE_NET_HOST_TRANS_TCP
,
1357 virStorageNetHostDef server_unix
= {
1358 .socket
= (char *)"/tmp/sock",
1359 .transport
= VIR_STORAGE_NET_HOST_TRANS_UNIX
,
1361 VIR_AUTOPTR(qemuMonitorTest
) test
= NULL
;
1363 if (!(test
= qemuMonitorTestNewSchema(xmlopt
, data
->schema
)))
1366 if (qemuMonitorTestAddItem(test
, "nbd-server-start",
1367 "{\"return\":{}}") < 0)
1370 if (qemuMonitorTestAddItem(test
, "nbd-server-start",
1371 "{\"return\":{}}") < 0)
1374 if (qemuMonitorJSONNBDServerStart(qemuMonitorTestGetMonitor(test
),
1375 &server_tcp
, "test-alias") < 0)
1378 if (qemuMonitorJSONNBDServerStart(qemuMonitorTestGetMonitor(test
),
1379 &server_unix
, "test-alias") < 0)
1386 testQemuMonitorJSONqemuMonitorJSONMergeBitmaps(const void *opaque
)
1388 const testGenericData
*data
= opaque
;
1389 virDomainXMLOptionPtr xmlopt
= data
->xmlopt
;
1390 VIR_AUTOPTR(qemuMonitorTest
) test
= NULL
;
1391 VIR_AUTOPTR(virJSONValue
) arr
= NULL
;
1393 if (!(test
= qemuMonitorTestNewSchema(xmlopt
, data
->schema
)))
1396 if (!(arr
= virJSONValueNewArray()))
1399 if (virJSONValueArrayAppendString(arr
, "b1") < 0 ||
1400 virJSONValueArrayAppendString(arr
, "b2") < 0)
1403 if (qemuMonitorTestAddItem(test
, "block-dirty-bitmap-merge",
1404 "{\"return\":{}}") < 0)
1407 if (qemuMonitorJSONMergeBitmaps(qemuMonitorTestGetMonitor(test
),
1408 "node", "dst", &arr
) < 0)
1412 VIR_TEST_VERBOSE("arr should have been cleared");
1420 testQemuMonitorJSONqemuMonitorJSONQueryCPUsEqual(struct qemuMonitorQueryCpusEntry
*a
,
1421 struct qemuMonitorQueryCpusEntry
*b
)
1423 if (a
->tid
!= b
->tid
||
1424 STRNEQ_NULLABLE(a
->qom_path
, b
->qom_path
))
1432 testQEMUMonitorJSONqemuMonitorJSONQueryCPUsHelper(qemuMonitorTestPtr test
,
1433 struct qemuMonitorQueryCpusEntry
*expect
,
1437 struct qemuMonitorQueryCpusEntry
*cpudata
= NULL
;
1438 size_t ncpudata
= 0;
1442 if (qemuMonitorJSONQueryCPUs(qemuMonitorTestGetMonitor(test
),
1443 &cpudata
, &ncpudata
, true, fast
) < 0)
1446 if (ncpudata
!= num
) {
1447 virReportError(VIR_ERR_INTERNAL_ERROR
,
1448 "Expecting ncpupids = %zu but got %zu", num
, ncpudata
);
1452 for (i
= 0; i
< ncpudata
; i
++) {
1453 if (!testQemuMonitorJSONqemuMonitorJSONQueryCPUsEqual(cpudata
+ i
,
1455 virReportError(VIR_ERR_INTERNAL_ERROR
,
1456 "vcpu entry %zu does not match expected data", i
);
1464 qemuMonitorQueryCpusFree(cpudata
, ncpudata
);
1470 testQemuMonitorJSONqemuMonitorJSONQueryCPUs(const void *opaque
)
1472 const testGenericData
*data
= opaque
;
1473 virDomainXMLOptionPtr xmlopt
= data
->xmlopt
;
1474 struct qemuMonitorQueryCpusEntry expect_slow
[] = {
1475 {0, 17622, (char *) "/machine/unattached/device[0]", true},
1476 {1, 17624, (char *) "/machine/unattached/device[1]", true},
1477 {2, 17626, (char *) "/machine/unattached/device[2]", true},
1478 {3, 17628, NULL
, true},
1480 struct qemuMonitorQueryCpusEntry expect_fast
[] = {
1481 {0, 17629, (char *) "/machine/unattached/device[0]", false},
1482 {1, 17630, (char *) "/machine/unattached/device[1]", false},
1484 VIR_AUTOPTR(qemuMonitorTest
) test
= NULL
;
1486 if (!(test
= qemuMonitorTestNewSchema(xmlopt
, data
->schema
)))
1489 if (qemuMonitorTestAddItem(test
, "query-cpus",
1493 " \"current\": true,"
1495 " \"qom_path\": \"/machine/unattached/device[0]\","
1496 " \"pc\": -2130530478,"
1497 " \"halted\": true,"
1498 " \"thread_id\": 17622"
1501 " \"current\": false,"
1503 " \"qom_path\": \"/machine/unattached/device[1]\","
1504 " \"pc\": -2130530478,"
1505 " \"halted\": true,"
1506 " \"thread_id\": 17624"
1509 " \"current\": false,"
1511 " \"qom_path\": \"/machine/unattached/device[2]\","
1512 " \"pc\": -2130530478,"
1513 " \"halted\": true,"
1514 " \"thread_id\": 17626"
1517 " \"current\": false,"
1519 " \"pc\": -2130530478,"
1520 " \"halted\": true,"
1521 " \"thread_id\": 17628"
1524 " \"id\": \"libvirt-7\""
1528 if (qemuMonitorTestAddItem(test
, "query-cpus-fast",
1532 " \"cpu-index\": 0,"
1533 " \"qom-path\": \"/machine/unattached/device[0]\","
1534 " \"thread-id\": 17629"
1537 " \"cpu-index\": 1,"
1538 " \"qom-path\": \"/machine/unattached/device[1]\","
1539 " \"thread-id\": 17630"
1542 " \"id\": \"libvirt-8\""
1547 if (testQEMUMonitorJSONqemuMonitorJSONQueryCPUsHelper(test
, expect_slow
,
1551 /* query-cpus-fast */
1552 if (testQEMUMonitorJSONqemuMonitorJSONQueryCPUsHelper(test
, expect_fast
,
1560 testQemuMonitorJSONqemuMonitorJSONGetBalloonInfo(const void *opaque
)
1562 const testGenericData
*data
= opaque
;
1563 virDomainXMLOptionPtr xmlopt
= data
->xmlopt
;
1564 unsigned long long currmem
;
1565 VIR_AUTOPTR(qemuMonitorTest
) test
= NULL
;
1567 if (!(test
= qemuMonitorTestNewSchema(xmlopt
, data
->schema
)))
1570 if (qemuMonitorTestAddItem(test
, "query-balloon",
1573 " \"actual\": 18446744073709551615"
1575 " \"id\": \"libvirt-9\""
1579 if (qemuMonitorJSONGetBalloonInfo(qemuMonitorTestGetMonitor(test
), &currmem
) < 0)
1582 if (currmem
!= (18446744073709551615ULL/1024)) {
1583 virReportError(VIR_ERR_INTERNAL_ERROR
,
1584 "Unexpected currmem value: %llu", currmem
);
1592 testQemuMonitorJSONqemuMonitorJSONGetVirtType(const void *opaque
)
1594 const testGenericData
*data
= opaque
;
1595 virDomainXMLOptionPtr xmlopt
= data
->xmlopt
;
1596 virDomainVirtType virtType
;
1597 VIR_AUTOPTR(qemuMonitorTest
) test
= NULL
;
1599 if (!(test
= qemuMonitorTestNewSchema(xmlopt
, data
->schema
)))
1602 if (qemuMonitorTestAddItem(test
, "query-kvm",
1605 " \"enabled\": true,"
1606 " \"present\": true"
1608 " \"id\": \"libvirt-8\""
1610 qemuMonitorTestAddItem(test
, "query-kvm",
1613 " \"enabled\": false,"
1614 " \"present\": true"
1616 " \"id\": \"libvirt-7\""
1620 if (qemuMonitorJSONGetVirtType(qemuMonitorTestGetMonitor(test
), &virtType
) < 0)
1623 if (virtType
!= VIR_DOMAIN_VIRT_KVM
) {
1624 virReportError(VIR_ERR_INTERNAL_ERROR
,
1625 "Unexpected virt type: %d, expecting %d", virtType
, VIR_DOMAIN_VIRT_KVM
);
1629 if (qemuMonitorJSONGetVirtType(qemuMonitorTestGetMonitor(test
), &virtType
) < 0)
1632 if (virtType
!= VIR_DOMAIN_VIRT_QEMU
) {
1633 virReportError(VIR_ERR_INTERNAL_ERROR
,
1634 "Unexpected virt type: %d, expecting %d", virtType
, VIR_DOMAIN_VIRT_QEMU
);
1643 testQemuMonitorJSONGetBlockInfoPrint(const struct qemuDomainDiskInfo
*d
)
1645 VIR_TEST_VERBOSE("removable: %d, tray: %d, tray_open: %d, empty: %d, "
1646 "io_status: %d, nodename: '%s'\n",
1647 d
->removable
, d
->tray
, d
->tray_open
, d
->empty
,
1648 d
->io_status
, NULLSTR(d
->nodename
));
1653 testHashEqualQemuDomainDiskInfo(const void *value1
, const void *value2
)
1655 const struct qemuDomainDiskInfo
*info1
= value1
, *info2
= value2
;
1658 if ((ret
= memcmp(info1
, info2
, sizeof(*info1
))) != 0) {
1659 testQemuMonitorJSONGetBlockInfoPrint(info1
);
1660 testQemuMonitorJSONGetBlockInfoPrint(info2
);
1667 testQemuMonitorJSONqemuMonitorJSONGetBlockInfo(const void *opaque
)
1669 const testGenericData
*data
= opaque
;
1670 virDomainXMLOptionPtr xmlopt
= data
->xmlopt
;
1672 virHashTablePtr blockDevices
= NULL
, expectedBlockDevices
= NULL
;
1673 struct qemuDomainDiskInfo
*info
;
1674 VIR_AUTOPTR(qemuMonitorTest
) test
= NULL
;
1676 if (!(test
= qemuMonitorTestNewSchema(xmlopt
, data
->schema
)))
1679 if (!(blockDevices
= virHashCreate(32, virHashValueFree
)) ||
1680 !(expectedBlockDevices
= virHashCreate(32, virHashValueFree
)))
1683 if (VIR_ALLOC(info
) < 0)
1686 if (virHashAddEntry(expectedBlockDevices
, "virtio-disk0", info
) < 0) {
1687 virReportError(VIR_ERR_INTERNAL_ERROR
, "%s",
1688 "Unable to create expectedBlockDevices hash table");
1692 if (VIR_ALLOC(info
) < 0)
1695 if (virHashAddEntry(expectedBlockDevices
, "virtio-disk1", info
) < 0) {
1696 virReportError(VIR_ERR_INTERNAL_ERROR
, "%s",
1697 "Unable to create expectedBlockDevices hash table");
1701 if (VIR_ALLOC(info
) < 0)
1704 info
->removable
= true;
1707 if (virHashAddEntry(expectedBlockDevices
, "ide0-1-0", info
) < 0) {
1708 virReportError(VIR_ERR_INTERNAL_ERROR
, "%s",
1709 "Unable to create expectedBlockDevices hash table");
1713 if (VIR_ALLOC(info
) < 0)
1716 info
->removable
= true;
1720 if (virHashAddEntry(expectedBlockDevices
, "ide0-1-1", info
) < 0) {
1721 virReportError(VIR_ERR_INTERNAL_ERROR
, "%s",
1722 "Unable to create expectedBlockDevices hash table");
1726 if (qemuMonitorTestAddItem(test
, "query-block", queryBlockReply
) < 0)
1729 if (qemuMonitorJSONGetBlockInfo(qemuMonitorTestGetMonitor(test
), blockDevices
) < 0)
1732 if (!virHashEqual(blockDevices
, expectedBlockDevices
, testHashEqualQemuDomainDiskInfo
)) {
1733 virReportError(VIR_ERR_INTERNAL_ERROR
, "%s",
1734 "Hashtable is different to the expected one");
1740 virHashFree(blockDevices
);
1741 virHashFree(expectedBlockDevices
);
1746 testQemuMonitorJSONqemuMonitorJSONGetAllBlockStatsInfo(const void *opaque
)
1748 const testGenericData
*data
= opaque
;
1749 virDomainXMLOptionPtr xmlopt
= data
->xmlopt
;
1750 virHashTablePtr blockstats
= NULL
;
1751 qemuBlockStatsPtr stats
;
1753 VIR_AUTOPTR(qemuMonitorTest
) test
= NULL
;
1759 " \"device\": \"drive-virtio-disk0\","
1762 " \"flush_total_time_ns\": 0,"
1763 " \"wr_highest_offset\": 5256018944,"
1764 " \"wr_total_time_ns\": 0,"
1766 " \"rd_total_time_ns\": 0,"
1767 " \"flush_operations\": 0,"
1768 " \"wr_operations\": 0,"
1770 " \"rd_operations\": 0"
1774 " \"flush_total_time_ns\": 0,"
1775 " \"wr_highest_offset\": 10406001664,"
1776 " \"wr_total_time_ns\": 530699221,"
1777 " \"wr_bytes\": 2845696,"
1778 " \"rd_total_time_ns\": 640616474,"
1779 " \"flush_operations\": 0,"
1780 " \"wr_operations\": 174,"
1781 " \"rd_bytes\": 28505088,"
1782 " \"rd_operations\": 1279"
1786 " \"device\": \"drive-virtio-disk1\","
1789 " \"flush_total_time_ns\": 0,"
1790 " \"wr_highest_offset\": 0,"
1791 " \"wr_total_time_ns\": 0,"
1793 " \"rd_total_time_ns\": 0,"
1794 " \"flush_operations\": 0,"
1795 " \"wr_operations\": 0,"
1797 " \"rd_operations\": 0"
1801 " \"flush_total_time_ns\": 0,"
1802 " \"wr_highest_offset\": 0,"
1803 " \"wr_total_time_ns\": 0,"
1805 " \"rd_total_time_ns\": 8232156,"
1806 " \"flush_operations\": 0,"
1807 " \"wr_operations\": 0,"
1808 " \"rd_bytes\": 348160,"
1809 " \"rd_operations\": 85"
1813 " \"device\": \"drive-ide0-1-0\","
1816 " \"flush_total_time_ns\": 0,"
1817 " \"wr_total_time_ns\": 0,"
1819 " \"rd_total_time_ns\": 0,"
1820 " \"flush_operations\": 0,"
1821 " \"wr_operations\": 0,"
1823 " \"rd_operations\": 0"
1827 " \"flush_total_time_ns\": 0,"
1828 " \"wr_highest_offset\": 0,"
1829 " \"wr_total_time_ns\": 0,"
1831 " \"rd_total_time_ns\": 1004952,"
1832 " \"flush_operations\": 0,"
1833 " \"wr_operations\": 0,"
1834 " \"rd_bytes\": 49250,"
1835 " \"rd_operations\": 16"
1839 " \"id\": \"libvirt-11\""
1842 if (!(test
= qemuMonitorTestNewSchema(xmlopt
, data
->schema
)))
1845 if (!(blockstats
= virHashCreate(10, virHashValueFree
)))
1848 if (qemuMonitorTestAddItem(test
, "query-blockstats", reply
) < 0)
1851 #define CHECK0FULL(var, value, varformat, valformat) \
1852 if (stats->var != value) { \
1853 virReportError(VIR_ERR_INTERNAL_ERROR, \
1854 "Invalid " #var " value: " varformat \
1855 ", expected " valformat, \
1856 stats->var, value); \
1860 #define CHECK0(var, value) CHECK0FULL(var, value, "%lld", "%d")
1862 #define CHECK(NAME, RD_REQ, RD_BYTES, RD_TOTAL_TIMES, WR_REQ, WR_BYTES, \
1863 WR_TOTAL_TIMES, FLUSH_REQ, FLUSH_TOTAL_TIMES, \
1864 WR_HIGHEST_OFFSET, WR_HIGHEST_OFFSET_VALID) \
1865 if (!(stats = virHashLookup(blockstats, NAME))) { \
1866 virReportError(VIR_ERR_INTERNAL_ERROR, \
1867 "block stats for device '%s' is missing", NAME); \
1870 CHECK0(rd_req, RD_REQ) \
1871 CHECK0(rd_bytes, RD_BYTES) \
1872 CHECK0(rd_total_times, RD_TOTAL_TIMES) \
1873 CHECK0(wr_req, WR_REQ) \
1874 CHECK0(wr_bytes, WR_BYTES) \
1875 CHECK0(wr_total_times, WR_TOTAL_TIMES) \
1876 CHECK0(flush_req, FLUSH_REQ) \
1877 CHECK0(flush_total_times, FLUSH_TOTAL_TIMES) \
1878 CHECK0FULL(wr_highest_offset, WR_HIGHEST_OFFSET, "%llu", "%llu") \
1879 CHECK0FULL(wr_highest_offset_valid, WR_HIGHEST_OFFSET_VALID, "%d", "%d")
1881 if (qemuMonitorJSONGetAllBlockStatsInfo(qemuMonitorTestGetMonitor(test
),
1882 blockstats
, false) < 0)
1886 virReportError(VIR_ERR_INTERNAL_ERROR
, "%s",
1887 "qemuMonitorJSONGetAllBlockStatsInfo didn't return stats");
1891 CHECK("virtio-disk0", 1279, 28505088, 640616474, 174, 2845696, 530699221, 0, 0, 5256018944ULL, true)
1892 CHECK("virtio-disk1", 85, 348160, 8232156, 0, 0, 0, 0, 0, 0ULL, true)
1893 CHECK("ide0-1-0", 16, 49250, 1004952, 0, 0, 0, 0, 0, 0ULL, false)
1902 virHashFree(blockstats
);
1908 testQemuMonitorJSONqemuMonitorJSONGetMigrationCacheSize(const void *opaque
)
1910 const testGenericData
*data
= opaque
;
1911 virDomainXMLOptionPtr xmlopt
= data
->xmlopt
;
1912 unsigned long long cacheSize
;
1913 VIR_AUTOPTR(qemuMonitorTest
) test
= NULL
;
1915 if (!(test
= qemuMonitorTestNewSchema(xmlopt
, data
->schema
)))
1918 if (qemuMonitorTestAddItem(test
, "query-migrate-cache-size",
1920 " \"return\": 67108864,"
1921 " \"id\": \"libvirt-12\""
1925 if (qemuMonitorJSONGetMigrationCacheSize(qemuMonitorTestGetMonitor(test
),
1929 if (cacheSize
!= 67108864) {
1930 virReportError(VIR_ERR_INTERNAL_ERROR
,
1931 "Invalid cacheSize: %llu, expected 67108864",
1940 testQemuMonitorJSONqemuMonitorJSONGetMigrationStats(const void *opaque
)
1942 const testGenericData
*data
= opaque
;
1943 virDomainXMLOptionPtr xmlopt
= data
->xmlopt
;
1945 qemuMonitorMigrationStats stats
, expectedStats
;
1947 VIR_AUTOPTR(qemuMonitorTest
) test
= NULL
;
1949 if (!(test
= qemuMonitorTestNewSchema(xmlopt
, data
->schema
)))
1952 memset(&expectedStats
, 0, sizeof(expectedStats
));
1954 expectedStats
.status
= QEMU_MONITOR_MIGRATION_STATUS_ACTIVE
;
1955 expectedStats
.total_time
= 47;
1956 expectedStats
.ram_total
= 1611038720;
1957 expectedStats
.ram_remaining
= 1605013504;
1958 expectedStats
.ram_transferred
= 3625548;
1960 if (qemuMonitorTestAddItem(test
, "query-migrate",
1963 " \"status\": \"active\","
1964 " \"total-time\": 47,"
1966 " \"total\": 1611038720,"
1967 " \"remaining\": 1605013504,"
1968 " \"transferred\": 3625548"
1971 " \"id\": \"libvirt-13\""
1973 qemuMonitorTestAddItem(test
, "query-migrate",
1976 " \"status\": \"failed\","
1977 " \"error-desc\": \"It's broken\""
1979 " \"id\": \"libvirt-14\""
1983 if (qemuMonitorJSONGetMigrationStats(qemuMonitorTestGetMonitor(test
),
1984 &stats
, &error
) < 0)
1987 if (memcmp(&stats
, &expectedStats
, sizeof(stats
)) != 0 || error
) {
1988 virReportError(VIR_ERR_INTERNAL_ERROR
, "%s",
1989 "Invalid migration statistics");
1993 memset(&stats
, 0, sizeof(stats
));
1994 if (qemuMonitorJSONGetMigrationStats(qemuMonitorTestGetMonitor(test
),
1995 &stats
, &error
) < 0)
1998 if (stats
.status
!= QEMU_MONITOR_MIGRATION_STATUS_ERROR
||
1999 STRNEQ_NULLABLE(error
, "It's broken")) {
2000 virReportError(VIR_ERR_INTERNAL_ERROR
, "%s",
2001 "Invalid failed migration status");
2012 testHashEqualChardevInfo(const void *value1
, const void *value2
)
2014 const qemuMonitorChardevInfo
*info1
= value1
;
2015 const qemuMonitorChardevInfo
*info2
= value2
;
2017 if (info1
->state
!= info2
->state
)
2020 if (STRNEQ_NULLABLE(info1
->ptyPath
, info2
->ptyPath
))
2026 fprintf(stderr
, "\n"
2027 "info1->state: %d info2->state: %d\n"
2028 "info1->ptyPath: %s info2->ptyPath: %s\n",
2029 info1
->state
, info2
->state
, info1
->ptyPath
, info2
->ptyPath
);
2035 testQemuMonitorJSONqemuMonitorJSONGetChardevInfo(const void *opaque
)
2037 const testGenericData
*data
= opaque
;
2038 virDomainXMLOptionPtr xmlopt
= data
->xmlopt
;
2040 virHashTablePtr info
= NULL
, expectedInfo
= NULL
;
2041 qemuMonitorChardevInfo info0
= { NULL
, VIR_DOMAIN_CHR_DEVICE_STATE_DEFAULT
};
2042 qemuMonitorChardevInfo info1
= { (char *) "/dev/pts/21", VIR_DOMAIN_CHR_DEVICE_STATE_CONNECTED
};
2043 qemuMonitorChardevInfo info2
= { (char *) "/dev/pts/20", VIR_DOMAIN_CHR_DEVICE_STATE_DEFAULT
};
2044 qemuMonitorChardevInfo info3
= { NULL
, VIR_DOMAIN_CHR_DEVICE_STATE_DISCONNECTED
};
2045 VIR_AUTOPTR(qemuMonitorTest
) test
= NULL
;
2047 if (!(test
= qemuMonitorTestNewSchema(xmlopt
, data
->schema
)))
2050 if (!(info
= virHashCreate(32, qemuMonitorChardevInfoFree
)) ||
2051 !(expectedInfo
= virHashCreate(32, NULL
)))
2054 if (virHashAddEntry(expectedInfo
, "charserial1", &info1
) < 0 ||
2055 virHashAddEntry(expectedInfo
, "charserial0", &info2
) < 0 ||
2056 virHashAddEntry(expectedInfo
, "charmonitor", &info0
) < 0 ||
2057 virHashAddEntry(expectedInfo
, "charserial2", &info3
) < 0) {
2058 virReportError(VIR_ERR_INTERNAL_ERROR
, "%s",
2059 "Unable to create expectedInfo hash table");
2063 if (qemuMonitorTestAddItem(test
, "query-chardev",
2067 " \"filename\": \"pty:/dev/pts/21\","
2068 " \"label\": \"charserial1\","
2069 " \"frontend-open\": true"
2072 " \"filename\": \"pty:/dev/pts/20\","
2073 " \"label\": \"charserial0\""
2076 " \"filename\": \"unix:/var/lib/libvirt/qemu/gentoo.monitor,server\","
2077 " \"label\": \"charmonitor\""
2080 " \"filename\": \"unix:/path/to/socket,server\","
2081 " \"label\": \"charserial2\","
2082 " \"frontend-open\": false"
2085 " \"id\": \"libvirt-15\""
2089 if (qemuMonitorJSONGetChardevInfo(qemuMonitorTestGetMonitor(test
),
2093 if (!virHashEqual(info
, expectedInfo
, testHashEqualChardevInfo
)) {
2094 virReportError(VIR_ERR_INTERNAL_ERROR
, "%s",
2095 "Hashtable is different to the expected one");
2102 virHashFree(expectedInfo
);
2108 testValidateGetBlockIoThrottle(const virDomainBlockIoTuneInfo
*info
,
2109 const virDomainBlockIoTuneInfo
*expectedInfo
)
2111 #define VALIDATE_IOTUNE(field) \
2112 if (info->field != expectedInfo->field) { \
2113 virReportError(VIR_ERR_INTERNAL_ERROR, \
2114 "info->%s=%llu != expected=%llu", \
2115 #field, info->field, expectedInfo->field); \
2118 if (info->field##_max != expectedInfo->field##_max) { \
2119 virReportError(VIR_ERR_INTERNAL_ERROR, \
2120 "info->%s_max=%llu != expected=%llu", \
2121 #field, info->field##_max, expectedInfo->field##_max); \
2124 if (info->field##_max_length != expectedInfo->field##_max_length) { \
2125 virReportError(VIR_ERR_INTERNAL_ERROR, \
2126 "info->%s_max_length=%llu != expected=%llu", \
2127 #field, info->field##_max_length, \
2128 expectedInfo->field##_max_length); \
2131 VALIDATE_IOTUNE(total_bytes_sec
);
2132 VALIDATE_IOTUNE(read_bytes_sec
);
2133 VALIDATE_IOTUNE(write_bytes_sec
);
2134 VALIDATE_IOTUNE(total_iops_sec
);
2135 VALIDATE_IOTUNE(read_iops_sec
);
2136 VALIDATE_IOTUNE(write_iops_sec
);
2137 if (info
->size_iops_sec
!= expectedInfo
->size_iops_sec
) {
2138 virReportError(VIR_ERR_INTERNAL_ERROR
,
2139 "info->size_iops_sec=%llu != expected=%llu",
2140 info
->size_iops_sec
, expectedInfo
->size_iops_sec
);
2143 if (STRNEQ(info
->group_name
, expectedInfo
->group_name
)) {
2144 virReportError(VIR_ERR_INTERNAL_ERROR
,
2145 "info->group_name=%s != expected=%s",
2146 info
->group_name
, expectedInfo
->group_name
);
2149 #undef VALIDATE_IOTUNE
2156 testQemuMonitorJSONqemuMonitorJSONSetBlockIoThrottle(const void *opaque
)
2158 const testGenericData
*data
= opaque
;
2159 virDomainXMLOptionPtr xmlopt
= data
->xmlopt
;
2161 virDomainBlockIoTuneInfo info
, expectedInfo
;
2162 VIR_AUTOPTR(qemuMonitorTest
) test
= NULL
;
2164 if (!(test
= qemuMonitorTestNewSchema(xmlopt
, data
->schema
)))
2167 expectedInfo
= (virDomainBlockIoTuneInfo
) {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, NULL
, 15, 16, 17, 18, 19, 20};
2168 if (VIR_STRDUP(expectedInfo
.group_name
, "group14") < 0)
2171 if (qemuMonitorTestAddItem(test
, "query-block", queryBlockReply
) < 0 ||
2172 qemuMonitorTestAddItemParams(test
, "block_set_io_throttle",
2174 "device", "\"drive-virtio-disk1\"",
2175 "bps", "1", "bps_rd", "2", "bps_wr", "3",
2176 "iops", "4", "iops_rd", "5", "iops_wr", "6",
2177 "bps_max", "7", "bps_rd_max", "8",
2179 "iops_max", "10", "iops_rd_max", "11",
2180 "iops_wr_max", "12", "iops_size", "13",
2181 "group", "\"group14\"",
2182 "bps_max_length", "15",
2183 "bps_rd_max_length", "16",
2184 "bps_wr_max_length", "17",
2185 "iops_max_length", "18",
2186 "iops_rd_max_length", "19",
2187 "iops_wr_max_length", "20",
2191 if (qemuMonitorJSONGetBlockIoThrottle(qemuMonitorTestGetMonitor(test
),
2192 "drive-virtio-disk0", NULL
, &info
) < 0)
2195 if (testValidateGetBlockIoThrottle(&info
, &expectedInfo
) < 0)
2198 if (qemuMonitorJSONSetBlockIoThrottle(qemuMonitorTestGetMonitor(test
),
2199 "drive-virtio-disk1", NULL
, &info
, true,
2205 VIR_FREE(info
.group_name
);
2206 VIR_FREE(expectedInfo
.group_name
);
2211 testQemuMonitorJSONqemuMonitorJSONGetTargetArch(const void *opaque
)
2213 const testGenericData
*data
= opaque
;
2214 virDomainXMLOptionPtr xmlopt
= data
->xmlopt
;
2217 VIR_AUTOPTR(qemuMonitorTest
) test
= NULL
;
2219 if (!(test
= qemuMonitorTestNewSchema(xmlopt
, data
->schema
)))
2222 if (qemuMonitorTestAddItem(test
, "query-target",
2225 " \"arch\": \"x86_64\""
2227 " \"id\": \"libvirt-21\""
2231 if (!(arch
= qemuMonitorJSONGetTargetArch(qemuMonitorTestGetMonitor(test
))))
2234 if (STRNEQ(arch
, "x86_64")) {
2235 virReportError(VIR_ERR_INTERNAL_ERROR
,
2236 "Unexpected architecture %s, expecting x86_64",
2248 testQemuMonitorJSONqemuMonitorJSONGetMigrationCapabilities(const void *opaque
)
2250 const testGenericData
*data
= opaque
;
2251 virDomainXMLOptionPtr xmlopt
= data
->xmlopt
;
2255 virBitmapPtr bitmap
= NULL
;
2256 virJSONValuePtr json
= NULL
;
2261 " \"state\": false,"
2262 " \"capability\": \"xbzrle\""
2265 " \"id\": \"libvirt-22\""
2267 VIR_AUTOPTR(qemuMonitorTest
) test
= NULL
;
2269 if (!(test
= qemuMonitorTestNewSchema(xmlopt
, data
->schema
)))
2272 if (qemuMonitorTestAddItem(test
, "query-migrate-capabilities", reply
) < 0 ||
2273 qemuMonitorTestAddItem(test
, "migrate-set-capabilities",
2274 "{\"return\":{}}") < 0)
2277 if (qemuMonitorGetMigrationCapabilities(qemuMonitorTestGetMonitor(test
),
2281 cap
= qemuMigrationCapabilityTypeToString(QEMU_MIGRATION_CAP_XBZRLE
);
2282 if (!virStringListHasString((const char **) caps
, cap
)) {
2283 virReportError(VIR_ERR_INTERNAL_ERROR
,
2284 "Expected capability %s is missing", cap
);
2288 bitmap
= virBitmapNew(QEMU_MIGRATION_CAP_LAST
);
2292 ignore_value(virBitmapSetBit(bitmap
, QEMU_MIGRATION_CAP_XBZRLE
));
2293 if (!(json
= qemuMigrationCapsToJSON(bitmap
, bitmap
)))
2296 ret
= qemuMonitorJSONSetMigrationCapabilities(qemuMonitorTestGetMonitor(test
),
2301 virJSONValueFree(json
);
2302 virStringListFree(caps
);
2303 virBitmapFree(bitmap
);
2308 testQemuMonitorJSONqemuMonitorJSONSendKey(const void *opaque
)
2310 const testGenericData
*data
= opaque
;
2311 virDomainXMLOptionPtr xmlopt
= data
->xmlopt
;
2312 unsigned int keycodes
[] = {43, 26, 46, 32};
2313 VIR_AUTOPTR(qemuMonitorTest
) test
= NULL
;
2315 if (!(test
= qemuMonitorTestNewSchema(xmlopt
, data
->schema
)))
2318 if (qemuMonitorTestAddItem(test
, "send-key",
2319 "{\"return\": {}, \"id\": \"libvirt-16\"}") < 0)
2322 if (qemuMonitorJSONSendKey(qemuMonitorTestGetMonitor(test
),
2323 0, keycodes
, ARRAY_CARDINALITY(keycodes
)) < 0)
2330 testQemuMonitorJSONqemuMonitorJSONSendKeyHoldtime(const void *opaque
)
2332 const testGenericData
*data
= opaque
;
2333 virDomainXMLOptionPtr xmlopt
= data
->xmlopt
;
2334 unsigned int keycodes
[] = {43, 26, 46, 32};
2335 VIR_AUTOPTR(qemuMonitorTest
) test
= NULL
;
2337 if (!(test
= qemuMonitorTestNewSchema(xmlopt
, data
->schema
)))
2340 if (qemuMonitorTestAddItemParams(test
, "send-key",
2342 "hold-time", "31337",
2343 "keys", "[{\"type\":\"number\",\"data\":43},"
2344 "{\"type\":\"number\",\"data\":26},"
2345 "{\"type\":\"number\",\"data\":46},"
2346 "{\"type\":\"number\",\"data\":32}]",
2350 if (qemuMonitorJSONSendKey(qemuMonitorTestGetMonitor(test
),
2352 ARRAY_CARDINALITY(keycodes
)) < 0)
2359 testQemuMonitorJSONqemuMonitorSupportsActiveCommit(const void *opaque
)
2361 const testGenericData
*data
= opaque
;
2362 virDomainXMLOptionPtr xmlopt
= data
->xmlopt
;
2363 const char *error1
=
2366 " \"class\": \"DeviceNotFound\","
2367 " \"desc\": \"Device 'bogus' not found\""
2370 const char *error2
=
2373 " \"class\": \"GenericError\","
2374 " \"desc\": \"Parameter 'top' is missing\""
2377 VIR_AUTOPTR(qemuMonitorTest
) test
= NULL
;
2379 if (!(test
= qemuMonitorTestNewSchema(xmlopt
, data
->schema
)))
2382 if (qemuMonitorTestAddItemParams(test
, "block-commit", error1
,
2383 "device", "\"bogus\"",
2387 if (!qemuMonitorSupportsActiveCommit(qemuMonitorTestGetMonitor(test
)))
2390 if (qemuMonitorTestAddItemParams(test
, "block-commit", error2
,
2391 "device", "\"bogus\"",
2395 if (qemuMonitorSupportsActiveCommit(qemuMonitorTestGetMonitor(test
)))
2402 testQemuMonitorJSONqemuMonitorJSONGetDumpGuestMemoryCapability(const void *opaque
)
2404 const testGenericData
*data
= opaque
;
2405 virDomainXMLOptionPtr xmlopt
= data
->xmlopt
;
2417 " \"id\": \"libvirt-9\""
2419 VIR_AUTOPTR(qemuMonitorTest
) test
= NULL
;
2421 if (!(test
= qemuMonitorTestNewSchema(xmlopt
, data
->schema
)))
2424 if (qemuMonitorTestAddItem(test
, "query-dump-guest-memory-capability",
2428 cap
= qemuMonitorJSONGetDumpGuestMemoryCapability(
2429 qemuMonitorTestGetMonitor(test
), "elf");
2432 virReportError(VIR_ERR_INTERNAL_ERROR
,
2433 "Unexpected capability: %d, expecting 1",
2441 struct testCPUData
{
2443 virDomainXMLOptionPtr xmlopt
;
2444 virHashTablePtr schema
;
2449 testQemuMonitorJSONGetCPUData(const void *opaque
)
2451 const struct testCPUData
*data
= opaque
;
2452 virCPUDataPtr cpuData
= NULL
;
2453 char *jsonFile
= NULL
;
2454 char *dataFile
= NULL
;
2455 char *jsonStr
= NULL
;
2456 char *actual
= NULL
;
2458 VIR_AUTOPTR(qemuMonitorTest
) test
= NULL
;
2460 if (!(test
= qemuMonitorTestNewSchema(data
->xmlopt
, data
->schema
)))
2463 if (virAsprintf(&jsonFile
,
2464 "%s/qemumonitorjsondata/qemumonitorjson-getcpu-%s.json",
2465 abs_srcdir
, data
->name
) < 0 ||
2466 virAsprintf(&dataFile
,
2467 "%s/qemumonitorjsondata/qemumonitorjson-getcpu-%s.data",
2468 abs_srcdir
, data
->name
) < 0)
2471 if (virTestLoadFile(jsonFile
, &jsonStr
) < 0)
2474 if (qemuMonitorTestAddItem(test
, "qom-list",
2478 " \"name\": \"filtered-features\","
2479 " \"type\": \"X86CPUFeatureWordInfo\""
2482 " \"name\": \"feature-words\","
2483 " \"type\": \"X86CPUFeatureWordInfo\""
2486 " \"id\": \"libvirt-19\""
2490 if (qemuMonitorTestAddItem(test
, "qom-get", jsonStr
) < 0)
2493 if (qemuMonitorJSONGetGuestCPUx86(qemuMonitorTestGetMonitor(test
),
2494 &cpuData
, NULL
) < 0)
2497 if (!(actual
= virCPUDataFormat(cpuData
)))
2500 if (virTestCompareToFile(actual
, dataFile
) < 0)
2509 virCPUDataFree(cpuData
);
2514 testQemuMonitorJSONGetNonExistingCPUData(const void *opaque
)
2516 const testGenericData
*data
= opaque
;
2517 virDomainXMLOptionPtr xmlopt
= data
->xmlopt
;
2518 virCPUDataPtr cpuData
= NULL
;
2520 VIR_AUTOPTR(qemuMonitorTest
) test
= NULL
;
2522 if (!(test
= qemuMonitorTestNewSchema(xmlopt
, data
->schema
)))
2525 if (qemuMonitorTestAddItem(test
, "qom-list",
2527 " \"id\": \"libvirt-7\","
2529 " \"class\": \"CommandNotFound\","
2530 " \"desc\": \"The command qom-list has not been found\""
2535 rv
= qemuMonitorJSONGetGuestCPUx86(qemuMonitorTestGetMonitor(test
),
2538 virReportError(VIR_ERR_INTERNAL_ERROR
,
2539 "Unexpected return value %d, expecting -2", rv
);
2544 virReportError(VIR_ERR_INTERNAL_ERROR
,
2545 "Unexpected allocation of data = %p, expecting NULL",
2552 virCPUDataFree(cpuData
);
2557 testQemuMonitorJSONGetIOThreads(const void *opaque
)
2559 const testGenericData
*data
= opaque
;
2560 virDomainXMLOptionPtr xmlopt
= data
->xmlopt
;
2561 qemuMonitorIOThreadInfoPtr
*info
;
2565 VIR_AUTOPTR(qemuMonitorTest
) test
= NULL
;
2567 if (!(test
= qemuMonitorTestNewSchema(xmlopt
, data
->schema
)))
2570 if (qemuMonitorTestAddItem(test
, "query-iothreads",
2574 " \"id\": \"iothread1\", "
2575 " \"thread-id\": 30992 "
2578 " \"id\": \"iothread2\", "
2579 " \"thread-id\": 30993 "
2585 if ((ninfo
= qemuMonitorGetIOThreads(qemuMonitorTestGetMonitor(test
),
2590 virReportError(VIR_ERR_INTERNAL_ERROR
,
2591 "ninfo %d is not 2", ninfo
);
2595 #define CHECK(i, wantiothread_id, wantthread_id) \
2597 if (info[i]->iothread_id != (wantiothread_id)) { \
2598 virReportError(VIR_ERR_INTERNAL_ERROR, \
2599 "iothread_id %u is not %u", \
2600 info[i]->iothread_id, (wantiothread_id)); \
2603 if (info[i]->thread_id != (wantthread_id)) { \
2604 virReportError(VIR_ERR_INTERNAL_ERROR, \
2605 "thread_id %d is not %d", \
2606 info[i]->thread_id, (wantthread_id)); \
2619 for (i
= 0; i
< ninfo
; i
++)
2626 struct testCPUInfoData
{
2629 virDomainXMLOptionPtr xmlopt
;
2631 virHashTablePtr schema
;
2636 testQemuMonitorCPUInfoFormat(qemuMonitorCPUInfoPtr vcpus
,
2639 virBuffer buf
= VIR_BUFFER_INITIALIZER
;
2640 qemuMonitorCPUInfoPtr vcpu
;
2643 for (i
= 0; i
< nvcpus
; i
++) {
2646 virBufferAsprintf(&buf
, "[vcpu libvirt-id='%zu']\n", i
);
2647 virBufferAdjustIndent(&buf
, 4);
2649 virBufferAsprintf(&buf
, "online=%s\n", vcpu
->online
? "yes" : "no");
2650 virBufferAsprintf(&buf
, "hotpluggable=%s\n", vcpu
->hotpluggable
? "yes" : "no");
2653 virBufferAsprintf(&buf
, "thread-id='%llu'\n",
2654 (unsigned long long) vcpu
->tid
);
2657 virBufferAsprintf(&buf
, "enable-id='%d'\n", vcpu
->id
);
2659 if (vcpu
->qemu_id
!= -1)
2660 virBufferAsprintf(&buf
, "query-cpus-id='%d'\n", vcpu
->qemu_id
);
2663 virBufferAsprintf(&buf
, "type='%s'\n", vcpu
->type
);
2666 virBufferAsprintf(&buf
, "alias='%s'\n", vcpu
->alias
);
2668 virBufferAsprintf(&buf
, "qom_path='%s'\n", vcpu
->qom_path
);
2670 if (vcpu
->socket_id
!= -1 || vcpu
->core_id
!= -1 ||
2671 vcpu
->thread_id
!= -1 || vcpu
->vcpus
!= 0) {
2672 virBufferAddLit(&buf
, "topology:");
2673 if (vcpu
->socket_id
!= -1)
2674 virBufferAsprintf(&buf
, " socket='%d'", vcpu
->socket_id
);
2675 if (vcpu
->core_id
!= -1)
2676 virBufferAsprintf(&buf
, " core='%d'", vcpu
->core_id
);
2677 if (vcpu
->thread_id
!= -1)
2678 virBufferAsprintf(&buf
, " thread='%d'", vcpu
->thread_id
);
2679 if (vcpu
->node_id
!= -1)
2680 virBufferAsprintf(&buf
, " node='%d'", vcpu
->node_id
);
2681 if (vcpu
->vcpus
!= 0)
2682 virBufferAsprintf(&buf
, " vcpus='%u'", vcpu
->vcpus
);
2683 virBufferAddLit(&buf
, "\n");
2687 virBufferAddLit(&buf
, "halted\n");
2689 virBufferAdjustIndent(&buf
, -4);
2692 return virBufferContentAndReset(&buf
);
2697 testQemuMonitorCPUInfo(const void *opaque
)
2699 const struct testCPUInfoData
*data
= opaque
;
2700 virDomainObjPtr vm
= NULL
;
2701 char *queryCpusFile
= NULL
;
2702 char *queryHotpluggableFile
= NULL
;
2703 char *dataFile
= NULL
;
2704 char *queryCpusStr
= NULL
;
2705 char *queryHotpluggableStr
= NULL
;
2706 char *actual
= NULL
;
2707 const char *queryCpusFunction
;
2708 qemuMonitorCPUInfoPtr vcpus
= NULL
;
2711 VIR_AUTOPTR(qemuMonitorTest
) test
= NULL
;
2713 if (!(test
= qemuMonitorTestNewSchema(data
->xmlopt
, data
->schema
)))
2716 if (virAsprintf(&queryCpusFile
,
2717 "%s/qemumonitorjsondata/qemumonitorjson-cpuinfo-%s-cpus.json",
2718 abs_srcdir
, data
->name
) < 0 ||
2719 virAsprintf(&queryHotpluggableFile
,
2720 "%s/qemumonitorjsondata/qemumonitorjson-cpuinfo-%s-hotplug.json",
2721 abs_srcdir
, data
->name
) < 0 ||
2722 virAsprintf(&dataFile
,
2723 "%s/qemumonitorjsondata/qemumonitorjson-cpuinfo-%s.data",
2724 abs_srcdir
, data
->name
) < 0)
2727 if (virTestLoadFile(queryCpusFile
, &queryCpusStr
) < 0)
2730 if (virTestLoadFile(queryHotpluggableFile
, &queryHotpluggableStr
) < 0)
2733 if (qemuMonitorTestAddItem(test
, "query-hotpluggable-cpus",
2734 queryHotpluggableStr
) < 0)
2738 queryCpusFunction
= "query-cpus-fast";
2740 queryCpusFunction
= "query-cpus";
2742 if (qemuMonitorTestAddItem(test
, queryCpusFunction
, queryCpusStr
) < 0)
2745 vm
= qemuMonitorTestGetDomainObj(test
);
2749 rc
= qemuMonitorGetCPUInfo(qemuMonitorTestGetMonitor(test
),
2750 &vcpus
, data
->maxvcpus
, true, data
->fast
);
2755 actual
= testQemuMonitorCPUInfoFormat(vcpus
, data
->maxvcpus
);
2757 if (virTestCompareToFile(actual
, dataFile
) < 0)
2762 VIR_FREE(queryCpusFile
);
2763 VIR_FREE(queryHotpluggableFile
);
2765 VIR_FREE(queryCpusStr
);
2766 VIR_FREE(queryHotpluggableStr
);
2768 qemuMonitorCPUInfoFree(vcpus
, data
->maxvcpus
);
2774 testBlockNodeNameDetectFormat(void *payload
,
2778 qemuBlockNodeNameBackingChainDataPtr entry
= payload
;
2779 const char *diskalias
= name
;
2780 virBufferPtr buf
= opaque
;
2782 virBufferSetIndent(buf
, 0);
2784 virBufferAdd(buf
, diskalias
, -1);
2785 virBufferAddLit(buf
, "\n");
2788 virBufferAsprintf(buf
, "filename : '%s'\n", entry
->qemufilename
);
2789 virBufferAsprintf(buf
, "format node : '%s'\n",
2790 NULLSTR(entry
->nodeformat
));
2791 virBufferAsprintf(buf
, "format drv : '%s'\n", NULLSTR(entry
->drvformat
));
2792 virBufferAsprintf(buf
, "storage node: '%s'\n",
2793 NULLSTR(entry
->nodestorage
));
2794 virBufferAsprintf(buf
, "storage drv : '%s'\n", NULLSTR(entry
->drvstorage
));
2796 virBufferAdjustIndent(buf
, 2);
2798 entry
= entry
->backing
;
2801 virBufferSetIndent(buf
, 0);
2802 virBufferAddLit(buf
, "\n");
2808 testBlockNodeNameDetect(const void *opaque
)
2810 const char *testname
= opaque
;
2811 const char *pathprefix
= "qemumonitorjsondata/qemumonitorjson-nodename-";
2812 char *resultFile
= NULL
;
2813 char *actual
= NULL
;
2814 virJSONValuePtr namedNodesJson
= NULL
;
2815 virJSONValuePtr blockstatsJson
= NULL
;
2816 virHashTablePtr nodedata
= NULL
;
2817 virBuffer buf
= VIR_BUFFER_INITIALIZER
;
2820 if (virAsprintf(&resultFile
, "%s/%s%s.result",
2821 abs_srcdir
, pathprefix
, testname
) < 0)
2824 if (!(namedNodesJson
= virTestLoadFileJSON(pathprefix
, testname
,
2825 "-named-nodes.json", NULL
)))
2828 if (!(blockstatsJson
= virTestLoadFileJSON(pathprefix
, testname
,
2829 "-blockstats.json", NULL
)))
2832 if (!(nodedata
= qemuBlockNodeNameGetBackingChain(namedNodesJson
,
2836 virHashForEach(nodedata
, testBlockNodeNameDetectFormat
, &buf
);
2838 virBufferTrim(&buf
, "\n", -1);
2840 if (virBufferCheckError(&buf
) < 0)
2843 actual
= virBufferContentAndReset(&buf
);
2845 if (virTestCompareToFile(actual
, resultFile
) < 0)
2851 VIR_FREE(resultFile
);
2853 virHashFree(nodedata
);
2854 virJSONValueFree(namedNodesJson
);
2855 virJSONValueFree(blockstatsJson
);
2861 struct testQAPISchemaData
{
2862 virHashTablePtr schema
;
2873 testQAPISchemaQuery(const void *opaque
)
2875 const struct testQAPISchemaData
*data
= opaque
;
2876 virJSONValuePtr replyobj
= NULL
;
2879 rc
= virQEMUQAPISchemaPathGet(data
->query
, data
->schema
, &replyobj
);
2881 if (data
->rc
!= rc
|| data
->replyobj
!= !!replyobj
) {
2882 VIR_TEST_VERBOSE("\n success: expected '%d' got '%d', replyobj: expected '%d' got '%d'",
2883 data
->rc
, rc
, data
->replyobj
, !!replyobj
);
2892 testQAPISchemaValidate(const void *opaque
)
2894 const struct testQAPISchemaData
*data
= opaque
;
2895 virBuffer debug
= VIR_BUFFER_INITIALIZER
;
2896 virJSONValuePtr schemaroot
;
2897 virJSONValuePtr json
= NULL
;
2900 if (virQEMUQAPISchemaPathGet(data
->query
, data
->schema
, &schemaroot
) < 0)
2903 if (!(json
= virJSONValueFromString(data
->json
)))
2906 if ((testQEMUSchemaValidate(json
, schemaroot
, data
->schema
, &debug
) == 0) != data
->success
) {
2908 VIR_TEST_VERBOSE("\nschema validation should have failed\n");
2913 if (virTestGetDebug() >= 3 ||
2914 (ret
< 0 && virTestGetVerbose())) {
2915 char *debugstr
= virBufferContentAndReset(&debug
);
2916 fprintf(stderr
, "\n%s\n", debugstr
);
2922 virBufferFreeAndReset(&debug
);
2923 virJSONValueFree(json
);
2929 testQueryJobsPrintJob(virBufferPtr buf
,
2930 qemuMonitorJobInfoPtr job
)
2932 virBufferAddLit(buf
, "[job]\n");
2933 virBufferAsprintf(buf
, "id=%s\n", NULLSTR(job
->id
));
2934 virBufferAsprintf(buf
, "type=%s\n", NULLSTR(qemuMonitorJobTypeToString(job
->type
)));
2935 virBufferAsprintf(buf
, "status=%s\n", NULLSTR(qemuMonitorJobStatusTypeToString(job
->status
)));
2936 virBufferAsprintf(buf
, "error=%s\n", NULLSTR(job
->error
));
2937 virBufferAddLit(buf
, "\n");
2941 struct testQueryJobsData
{
2943 virDomainXMLOptionPtr xmlopt
;
2948 testQueryJobs(const void *opaque
)
2950 const struct testQueryJobsData
*data
= opaque
;
2951 qemuMonitorTestPtr test
= qemuMonitorTestNewSimple(data
->xmlopt
);
2952 VIR_AUTOFREE(char *) filenameJSON
= NULL
;
2953 VIR_AUTOFREE(char *) fileJSON
= NULL
;
2954 VIR_AUTOFREE(char *) filenameResult
= NULL
;
2955 VIR_AUTOFREE(char *) actual
= NULL
;
2956 qemuMonitorJobInfoPtr
*jobs
= NULL
;
2957 virBuffer buf
= VIR_BUFFER_INITIALIZER
;
2965 if (virAsprintf(&filenameJSON
,
2966 abs_srcdir
"/qemumonitorjsondata/query-jobs-%s.json",
2968 virAsprintf(&filenameResult
,
2969 abs_srcdir
"/qemumonitorjsondata/query-jobs-%s.result",
2973 if (virTestLoadFile(filenameJSON
, &fileJSON
) < 0)
2976 if (qemuMonitorTestAddItem(test
, "query-jobs", fileJSON
) < 0)
2979 if (qemuMonitorJSONGetJobInfo(qemuMonitorTestGetMonitor(test
),
2983 for (i
= 0; i
< njobs
; i
++)
2984 testQueryJobsPrintJob(&buf
, jobs
[i
]);
2986 virBufferTrim(&buf
, "\n", -1);
2988 if (virBufferCheckError(&buf
) < 0)
2991 actual
= virBufferContentAndReset(&buf
);
2993 if (virTestCompareToFile(actual
, filenameResult
) < 0)
2999 for (i
= 0; i
< njobs
; i
++)
3000 qemuMonitorJobInfoFree(jobs
[i
]);
3002 qemuMonitorTestFree(test
);
3011 virQEMUDriver driver
;
3012 testQemuMonitorJSONSimpleFuncData simpleFunc
;
3013 struct testQAPISchemaData qapiData
;
3014 virJSONValuePtr metaschema
= NULL
;
3015 char *metaschemastr
= NULL
;
3018 fputs("libvirt not compiled with JSON support, skipping this test\n", stderr
);
3019 return EXIT_AM_SKIP
;
3022 if (virThreadInitialize() < 0 ||
3023 qemuTestDriverInit(&driver
) < 0)
3024 return EXIT_FAILURE
;
3026 virEventRegisterDefaultImpl();
3028 if (!(qapiData
.schema
= testQEMUSchemaLoad())) {
3029 VIR_TEST_VERBOSE("failed to load qapi schema\n");
3034 #define DO_TEST(name) \
3036 testGenericData data = { driver.xmlopt, qapiData.schema }; \
3037 if (virTestRun(# name, testQemuMonitorJSON ## name, &data) < 0) \
3041 #define DO_TEST_SIMPLE(CMD, FNC, ...) \
3042 simpleFunc = (testQemuMonitorJSONSimpleFuncData) {.cmd = CMD, .func = FNC, \
3043 .xmlopt = driver.xmlopt, \
3044 .schema = qapiData.schema, \
3046 if (virTestRun(# FNC, testQemuMonitorJSONSimpleFunc, &simpleFunc) < 0) \
3049 #define DO_TEST_GEN(name, ...) \
3050 simpleFunc = (testQemuMonitorJSONSimpleFuncData) {.xmlopt = driver.xmlopt, \
3051 .schema = qapiData.schema \
3053 if (virTestRun(# name, testQemuMonitorJSON ## name, &simpleFunc) < 0) \
3056 #define DO_TEST_CPU_DATA(name) \
3058 struct testCPUData data = { name, driver.xmlopt, qapiData.schema }; \
3059 const char *label = "GetCPUData(" name ")"; \
3060 if (virTestRun(label, testQemuMonitorJSONGetCPUData, &data) < 0) \
3064 #define DO_TEST_CPU_INFO(name, maxvcpus) \
3066 struct testCPUInfoData data = {name, maxvcpus, driver.xmlopt, false, \
3068 if (virTestRun("GetCPUInfo(" name ")", testQemuMonitorCPUInfo, \
3073 #define DO_TEST_CPU_INFO_FAST(name, maxvcpus) \
3075 struct testCPUInfoData data = {name, maxvcpus, driver.xmlopt, true, \
3076 qapiData.schema }; \
3077 if (virTestRun("GetCPUInfo(" name ")", testQemuMonitorCPUInfo, \
3083 DO_TEST(GetVersion
);
3084 DO_TEST(GetMachines
);
3085 DO_TEST(GetCPUDefinitions
);
3086 DO_TEST(GetCommands
);
3087 DO_TEST(GetTPMModels
);
3088 DO_TEST(GetCommandLineOptionParameters
);
3089 if (qemuMonitorJSONTestAttachChardev(driver
.xmlopt
, qapiData
.schema
) < 0)
3091 DO_TEST(DetachChardev
);
3092 DO_TEST(GetListPaths
);
3093 DO_TEST(GetObjectProperty
);
3094 DO_TEST(SetObjectProperty
);
3095 DO_TEST(GetDeviceAliases
);
3097 DO_TEST(GetNonExistingCPUData
);
3098 DO_TEST(GetIOThreads
);
3099 DO_TEST_SIMPLE("qmp_capabilities", qemuMonitorJSONSetCapabilities
);
3100 DO_TEST_SIMPLE("system_powerdown", qemuMonitorJSONSystemPowerdown
);
3101 DO_TEST_SIMPLE("system_reset", qemuMonitorJSONSystemReset
);
3102 DO_TEST_SIMPLE("migrate_cancel", qemuMonitorJSONMigrateCancel
);
3103 DO_TEST_SIMPLE("inject-nmi", qemuMonitorJSONInjectNMI
);
3104 DO_TEST_SIMPLE("system_wakeup", qemuMonitorJSONSystemWakeup
);
3105 DO_TEST_SIMPLE("nbd-server-stop", qemuMonitorJSONNBDServerStop
);
3106 DO_TEST_SIMPLE("rtc-reset-reinjection", qemuMonitorJSONRTCResetReinjection
);
3107 DO_TEST_GEN(qemuMonitorJSONSetLink
);
3108 DO_TEST_GEN(qemuMonitorJSONBlockResize
);
3109 DO_TEST_GEN(qemuMonitorJSONSetPassword
);
3110 DO_TEST_GEN(qemuMonitorJSONExpirePassword
);
3111 DO_TEST_GEN(qemuMonitorJSONSetBalloon
);
3112 DO_TEST_GEN(qemuMonitorJSONSetCPU
);
3113 DO_TEST_GEN(qemuMonitorJSONEjectMedia
);
3114 DO_TEST_GEN(qemuMonitorJSONChangeMedia
);
3115 DO_TEST_GEN(qemuMonitorJSONSaveVirtualMemory
);
3116 DO_TEST_GEN(qemuMonitorJSONSavePhysicalMemory
);
3117 DO_TEST_GEN(qemuMonitorJSONSetMigrationSpeed
);
3118 DO_TEST_GEN(qemuMonitorJSONSetMigrationDowntime
);
3119 DO_TEST_GEN(qemuMonitorJSONMigrate
);
3120 DO_TEST_GEN(qemuMonitorJSONDump
);
3121 DO_TEST_GEN(qemuMonitorJSONGraphicsRelocate
);
3122 DO_TEST_GEN(qemuMonitorJSONAddNetdev
);
3123 DO_TEST_GEN(qemuMonitorJSONRemoveNetdev
);
3124 DO_TEST_GEN(qemuMonitorJSONDelDevice
);
3125 DO_TEST_GEN(qemuMonitorJSONAddDevice
);
3126 DO_TEST_GEN(qemuMonitorJSONDriveMirror
);
3127 DO_TEST_GEN(qemuMonitorJSONBlockdevMirror
);
3128 DO_TEST_GEN(qemuMonitorJSONBlockStream
);
3129 DO_TEST_GEN(qemuMonitorJSONBlockCommit
);
3130 DO_TEST_GEN(qemuMonitorJSONDrivePivot
);
3131 DO_TEST_GEN(qemuMonitorJSONScreendump
);
3132 DO_TEST_GEN(qemuMonitorJSONOpenGraphics
);
3133 DO_TEST_GEN(qemuMonitorJSONNBDServerAdd
);
3134 DO_TEST_GEN(qemuMonitorJSONDetachCharDev
);
3135 DO_TEST_GEN(qemuMonitorJSONBlockdevTrayOpen
);
3136 DO_TEST_GEN(qemuMonitorJSONBlockdevTrayClose
);
3137 DO_TEST_GEN(qemuMonitorJSONBlockdevMediumRemove
);
3138 DO_TEST_GEN(qemuMonitorJSONBlockdevMediumInsert
);
3139 DO_TEST_GEN(qemuMonitorJSONAddBitmap
);
3140 DO_TEST_GEN(qemuMonitorJSONEnableBitmap
);
3141 DO_TEST_GEN(qemuMonitorJSONDeleteBitmap
);
3142 DO_TEST_GEN(qemuMonitorJSONJobDismiss
);
3143 DO_TEST_GEN(qemuMonitorJSONJobCancel
);
3144 DO_TEST_GEN(qemuMonitorJSONJobComplete
);
3145 DO_TEST(qemuMonitorJSONGetBalloonInfo
);
3146 DO_TEST(qemuMonitorJSONGetBlockInfo
);
3147 DO_TEST(qemuMonitorJSONGetAllBlockStatsInfo
);
3148 DO_TEST(qemuMonitorJSONGetMigrationCacheSize
);
3149 DO_TEST(qemuMonitorJSONGetMigrationStats
);
3150 DO_TEST(qemuMonitorJSONGetChardevInfo
);
3151 DO_TEST(qemuMonitorJSONSetBlockIoThrottle
);
3152 DO_TEST(qemuMonitorJSONGetTargetArch
);
3153 DO_TEST(qemuMonitorJSONGetMigrationCapabilities
);
3154 DO_TEST(qemuMonitorJSONQueryCPUs
);
3155 DO_TEST(qemuMonitorJSONGetVirtType
);
3156 DO_TEST(qemuMonitorJSONSendKey
);
3157 DO_TEST(qemuMonitorJSONGetDumpGuestMemoryCapability
);
3158 DO_TEST(qemuMonitorJSONSendKeyHoldtime
);
3159 DO_TEST(qemuMonitorSupportsActiveCommit
);
3160 DO_TEST(qemuMonitorJSONNBDServerStart
);
3161 DO_TEST(qemuMonitorJSONMergeBitmaps
);
3163 DO_TEST_CPU_DATA("host");
3164 DO_TEST_CPU_DATA("full");
3165 DO_TEST_CPU_DATA("ecx");
3167 DO_TEST_CPU_INFO("x86-basic-pluggable", 8);
3168 DO_TEST_CPU_INFO("x86-full", 11);
3169 DO_TEST_CPU_INFO("x86-node-full", 8);
3170 DO_TEST_CPU_INFO_FAST("x86-full-fast", 11);
3172 DO_TEST_CPU_INFO("ppc64-basic", 24);
3173 DO_TEST_CPU_INFO("ppc64-hotplug-1", 24);
3174 DO_TEST_CPU_INFO("ppc64-hotplug-2", 24);
3175 DO_TEST_CPU_INFO("ppc64-hotplug-4", 24);
3176 DO_TEST_CPU_INFO("ppc64-no-threads", 16);
3178 DO_TEST_CPU_INFO_FAST("s390-fast", 2);
3180 #define DO_TEST_BLOCK_NODE_DETECT(testname) \
3182 if (virTestRun("node-name-detect(" testname ")", \
3183 testBlockNodeNameDetect, testname) < 0) \
3187 DO_TEST_BLOCK_NODE_DETECT("basic");
3188 DO_TEST_BLOCK_NODE_DETECT("same-backing");
3189 DO_TEST_BLOCK_NODE_DETECT("relative");
3190 DO_TEST_BLOCK_NODE_DETECT("gluster");
3191 DO_TEST_BLOCK_NODE_DETECT("blockjob");
3192 DO_TEST_BLOCK_NODE_DETECT("luks");
3193 DO_TEST_BLOCK_NODE_DETECT("iscsi");
3194 DO_TEST_BLOCK_NODE_DETECT("old");
3195 DO_TEST_BLOCK_NODE_DETECT("empty");
3197 #undef DO_TEST_BLOCK_NODE_DETECT
3199 #define DO_TEST_QAPI_QUERY(nme, qry, scc, rplobj) \
3201 qapiData.name = nme; \
3202 qapiData.query = qry; \
3203 qapiData.rc = scc; \
3204 qapiData.replyobj = rplobj; \
3205 if (virTestRun("qapi schema query" nme, testQAPISchemaQuery, &qapiData) < 0)\
3209 DO_TEST_QAPI_QUERY("command", "blockdev-add", 1, true);
3210 DO_TEST_QAPI_QUERY("event", "RTC_CHANGE", 1, true);
3211 DO_TEST_QAPI_QUERY("object property", "screendump/arg-type/device", 1, true);
3212 DO_TEST_QAPI_QUERY("optional property", "block-commit/arg-type/*top", 1, true);
3213 DO_TEST_QAPI_QUERY("variant", "blockdev-add/arg-type/+file", 1, true);
3214 DO_TEST_QAPI_QUERY("variant property", "blockdev-add/arg-type/+file/filename", 1, true);
3215 DO_TEST_QAPI_QUERY("enum value", "query-status/ret-type/status/^debug", 1, false);
3216 DO_TEST_QAPI_QUERY("builtin type", "query-qmp-schema/ret-type/name/!string", 1, false);
3217 DO_TEST_QAPI_QUERY("alternate variant 1", "blockdev-add/arg-type/+qcow2/backing/!null", 1, false);
3218 DO_TEST_QAPI_QUERY("alternate variant 2", "blockdev-add/arg-type/+qcow2/backing/!string", 1, false);
3219 DO_TEST_QAPI_QUERY("alternate variant 3", "blockdev-add/arg-type/+qcow2/backing/+file/filename", 1, true);
3221 DO_TEST_QAPI_QUERY("nonexistent command", "nonexistent", 0, false);
3222 DO_TEST_QAPI_QUERY("nonexistent attr", "screendump/arg-type/nonexistent", 0, false);
3223 DO_TEST_QAPI_QUERY("nonexistent variant", "blockdev-add/arg-type/+nonexistent", 0, false);
3224 DO_TEST_QAPI_QUERY("nonexistent enum value", "query-status/ret-type/status/^nonexistentdebug", 0, false);
3225 DO_TEST_QAPI_QUERY("broken query for enum value", "query-status/ret-type/status/^debug/test", -1, false);
3226 DO_TEST_QAPI_QUERY("builtin type", "query-qmp-schema/ret-type/name/!number", 0, false);
3228 #undef DO_TEST_QAPI_QUERY
3231 #define DO_TEST_QAPI_VALIDATE(nme, rootquery, scc, jsonstr) \
3233 qapiData.name = nme; \
3234 qapiData.query = rootquery; \
3235 qapiData.success = scc; \
3236 qapiData.json = jsonstr; \
3237 if (virTestRun("qapi schema validate" nme, testQAPISchemaValidate, &qapiData) < 0)\
3242 DO_TEST_QAPI_VALIDATE("string", "trace-event-get-state/arg-type", true,
3243 "{\"name\":\"test\"}");
3244 DO_TEST_QAPI_VALIDATE("all attrs", "trace-event-get-state/arg-type", true,
3245 "{\"name\":\"test\", \"vcpu\":123}");
3246 DO_TEST_QAPI_VALIDATE("attr type mismatch", "trace-event-get-state/arg-type", false,
3248 DO_TEST_QAPI_VALIDATE("missing mandatory attr", "trace-event-get-state/arg-type", false,
3250 DO_TEST_QAPI_VALIDATE("attr name not present", "trace-event-get-state/arg-type", false,
3251 "{\"name\":\"test\", \"blah\":123}");
3252 DO_TEST_QAPI_VALIDATE("variant", "blockdev-add/arg-type", true,
3253 "{\"driver\":\"file\", \"filename\":\"ble\"}");
3254 DO_TEST_QAPI_VALIDATE("variant wrong", "blockdev-add/arg-type", false,
3255 "{\"driver\":\"filefilefilefile\", \"filename\":\"ble\"}");
3256 DO_TEST_QAPI_VALIDATE("variant missing mandatory", "blockdev-add/arg-type", false,
3257 "{\"driver\":\"file\", \"pr-manager\":\"ble\"}");
3258 DO_TEST_QAPI_VALIDATE("variant missing discriminator", "blockdev-add/arg-type", false,
3259 "{\"node-name\":\"dfgfdg\"}");
3260 DO_TEST_QAPI_VALIDATE("alternate 1", "blockdev-add/arg-type", true,
3261 "{\"driver\":\"qcow2\","
3262 "\"file\": { \"driver\":\"file\", \"filename\":\"ble\"}}");
3263 DO_TEST_QAPI_VALIDATE("alternate 2", "blockdev-add/arg-type", true,
3264 "{\"driver\":\"qcow2\",\"file\": \"somepath\"}");
3265 DO_TEST_QAPI_VALIDATE("alternate 2", "blockdev-add/arg-type", false,
3266 "{\"driver\":\"qcow2\",\"file\": 1234}");
3268 if (!(metaschema
= testQEMUSchemaGetLatest()) ||
3269 !(metaschemastr
= virJSONValueToString(metaschema
, false))) {
3270 VIR_TEST_VERBOSE("failed to load latest qapi schema\n");
3275 DO_TEST_QAPI_VALIDATE("schema-meta", "query-qmp-schema/ret-type", true,
3279 #undef DO_TEST_QAPI_VALIDATE
3281 #define DO_TEST_QUERY_JOBS(name) \
3283 struct testQueryJobsData data = { name, driver.xmlopt}; \
3284 if (virTestRun("query-jobs-" name, testQueryJobs, &data) < 0) \
3288 DO_TEST_QUERY_JOBS("empty");
3289 DO_TEST_QUERY_JOBS("create");
3291 #undef DO_TEST_QUERY_JOBS
3294 VIR_FREE(metaschemastr
);
3295 virJSONValueFree(metaschema
);
3296 virHashFree(qapiData
.schema
);
3297 qemuTestDriverFree(&driver
);
3298 return (ret
== 0) ? EXIT_SUCCESS
: EXIT_FAILURE
;
3301 VIR_TEST_MAIN_PRELOAD(mymain
, abs_builddir
"/.libs/virdeterministichashmock.so")