4 * Copyright (C) 2014 Leandro Dorileo <l@dorileo.org>
6 * This work is licensed under the terms of the GNU LGPL, version 2.1 or later.
7 * See the COPYING.LIB file in the top-level directory.
10 #include "qemu/osdep.h"
11 #include "qemu/cutils.h"
12 #include "qapi/error.h"
13 #include "qapi/qmp/qstring.h"
14 #include "qemu/config-file.h"
17 static QemuOptsList opts_list_01
= {
18 .name
= "opts_list_01",
19 .head
= QTAILQ_HEAD_INITIALIZER(opts_list_01
.head
),
23 .type
= QEMU_OPT_STRING
,
26 .type
= QEMU_OPT_STRING
,
29 .type
= QEMU_OPT_STRING
,
32 .type
= QEMU_OPT_NUMBER
,
35 .type
= QEMU_OPT_NUMBER
,
41 static QemuOptsList opts_list_02
= {
42 .name
= "opts_list_02",
43 .head
= QTAILQ_HEAD_INITIALIZER(opts_list_02
.head
),
47 .type
= QEMU_OPT_STRING
,
50 .type
= QEMU_OPT_STRING
,
53 .type
= QEMU_OPT_BOOL
,
56 .type
= QEMU_OPT_BOOL
,
59 .type
= QEMU_OPT_SIZE
,
62 .type
= QEMU_OPT_SIZE
,
65 .type
= QEMU_OPT_SIZE
,
71 static QemuOptsList opts_list_03
= {
72 .name
= "opts_list_03",
73 .implied_opt_name
= "implied",
74 .head
= QTAILQ_HEAD_INITIALIZER(opts_list_03
.head
),
76 /* no elements => accept any params */
81 static void register_opts(void)
83 qemu_add_opts(&opts_list_01
);
84 qemu_add_opts(&opts_list_02
);
85 qemu_add_opts(&opts_list_03
);
88 static void test_find_unknown_opts(void)
93 /* should not return anything, we don't have an "unknown" option */
94 list
= qemu_find_opts_err("unknown", &err
);
95 g_assert(list
== NULL
);
100 static void test_qemu_find_opts(void)
104 /* we have an "opts_list_01" option, should return it */
105 list
= qemu_find_opts("opts_list_01");
106 g_assert(list
!= NULL
);
107 g_assert_cmpstr(list
->name
, ==, "opts_list_01");
110 static void test_qemu_opts_create(void)
115 list
= qemu_find_opts("opts_list_01");
116 g_assert(list
!= NULL
);
117 g_assert(QTAILQ_EMPTY(&list
->head
));
118 g_assert_cmpstr(list
->name
, ==, "opts_list_01");
120 /* should not find anything at this point */
121 opts
= qemu_opts_find(list
, NULL
);
122 g_assert(opts
== NULL
);
124 /* create the opts */
125 opts
= qemu_opts_create(list
, NULL
, 0, &error_abort
);
126 g_assert(opts
!= NULL
);
127 g_assert(!QTAILQ_EMPTY(&list
->head
));
129 /* now we've create the opts, must find it */
130 opts
= qemu_opts_find(list
, NULL
);
131 g_assert(opts
!= NULL
);
135 /* should not find anything at this point */
136 opts
= qemu_opts_find(list
, NULL
);
137 g_assert(opts
== NULL
);
140 static void test_qemu_opt_get(void)
144 const char *opt
= NULL
;
146 list
= qemu_find_opts("opts_list_01");
147 g_assert(list
!= NULL
);
148 g_assert(QTAILQ_EMPTY(&list
->head
));
149 g_assert_cmpstr(list
->name
, ==, "opts_list_01");
151 /* should not find anything at this point */
152 opts
= qemu_opts_find(list
, NULL
);
153 g_assert(opts
== NULL
);
155 /* create the opts */
156 opts
= qemu_opts_create(list
, NULL
, 0, &error_abort
);
157 g_assert(opts
!= NULL
);
158 g_assert(!QTAILQ_EMPTY(&list
->head
));
160 /* haven't set anything to str2 yet */
161 opt
= qemu_opt_get(opts
, "str2");
162 g_assert(opt
== NULL
);
164 qemu_opt_set(opts
, "str2", "value", &error_abort
);
166 /* now we have set str2, should know about it */
167 opt
= qemu_opt_get(opts
, "str2");
168 g_assert_cmpstr(opt
, ==, "value");
170 qemu_opt_set(opts
, "str2", "value2", &error_abort
);
172 /* having reset the value, the returned should be the reset one */
173 opt
= qemu_opt_get(opts
, "str2");
174 g_assert_cmpstr(opt
, ==, "value2");
178 /* should not find anything at this point */
179 opts
= qemu_opts_find(list
, NULL
);
180 g_assert(opts
== NULL
);
183 static void test_qemu_opt_get_bool(void)
190 list
= qemu_find_opts("opts_list_02");
191 g_assert(list
!= NULL
);
192 g_assert(QTAILQ_EMPTY(&list
->head
));
193 g_assert_cmpstr(list
->name
, ==, "opts_list_02");
195 /* should not find anything at this point */
196 opts
= qemu_opts_find(list
, NULL
);
197 g_assert(opts
== NULL
);
199 /* create the opts */
200 opts
= qemu_opts_create(list
, NULL
, 0, &error_abort
);
201 g_assert(opts
!= NULL
);
202 g_assert(!QTAILQ_EMPTY(&list
->head
));
204 /* haven't set anything to bool1 yet, so defval should be returned */
205 opt
= qemu_opt_get_bool(opts
, "bool1", false);
206 g_assert(opt
== false);
208 qemu_opt_set_bool(opts
, "bool1", true, &err
);
211 /* now we have set bool1, should know about it */
212 opt
= qemu_opt_get_bool(opts
, "bool1", false);
213 g_assert(opt
== true);
215 /* having reset the value, opt should be the reset one not defval */
216 qemu_opt_set_bool(opts
, "bool1", false, &err
);
219 opt
= qemu_opt_get_bool(opts
, "bool1", true);
220 g_assert(opt
== false);
224 /* should not find anything at this point */
225 opts
= qemu_opts_find(list
, NULL
);
226 g_assert(opts
== NULL
);
229 static void test_qemu_opt_get_number(void)
236 list
= qemu_find_opts("opts_list_01");
237 g_assert(list
!= NULL
);
238 g_assert(QTAILQ_EMPTY(&list
->head
));
239 g_assert_cmpstr(list
->name
, ==, "opts_list_01");
241 /* should not find anything at this point */
242 opts
= qemu_opts_find(list
, NULL
);
243 g_assert(opts
== NULL
);
245 /* create the opts */
246 opts
= qemu_opts_create(list
, NULL
, 0, &error_abort
);
247 g_assert(opts
!= NULL
);
248 g_assert(!QTAILQ_EMPTY(&list
->head
));
250 /* haven't set anything to number1 yet, so defval should be returned */
251 opt
= qemu_opt_get_number(opts
, "number1", 5);
254 qemu_opt_set_number(opts
, "number1", 10, &err
);
257 /* now we have set number1, should know about it */
258 opt
= qemu_opt_get_number(opts
, "number1", 5);
261 /* having reset it, the returned should be the reset one not defval */
262 qemu_opt_set_number(opts
, "number1", 15, &err
);
265 opt
= qemu_opt_get_number(opts
, "number1", 5);
270 /* should not find anything at this point */
271 opts
= qemu_opts_find(list
, NULL
);
272 g_assert(opts
== NULL
);
275 static void test_qemu_opt_get_size(void)
282 list
= qemu_find_opts("opts_list_02");
283 g_assert(list
!= NULL
);
284 g_assert(QTAILQ_EMPTY(&list
->head
));
285 g_assert_cmpstr(list
->name
, ==, "opts_list_02");
287 /* should not find anything at this point */
288 opts
= qemu_opts_find(list
, NULL
);
289 g_assert(opts
== NULL
);
291 /* create the opts */
292 opts
= qemu_opts_create(list
, NULL
, 0, &error_abort
);
293 g_assert(opts
!= NULL
);
294 g_assert(!QTAILQ_EMPTY(&list
->head
));
296 /* haven't set anything to size1 yet, so defval should be returned */
297 opt
= qemu_opt_get_size(opts
, "size1", 5);
301 g_assert(dict
!= NULL
);
303 qdict_put(dict
, "size1", qstring_from_str("10"));
305 qemu_opts_absorb_qdict(opts
, dict
, &error_abort
);
306 g_assert(error_abort
== NULL
);
308 /* now we have set size1, should know about it */
309 opt
= qemu_opt_get_size(opts
, "size1", 5);
313 qdict_put(dict
, "size1", qstring_from_str("15"));
315 qemu_opts_absorb_qdict(opts
, dict
, &error_abort
);
316 g_assert(error_abort
== NULL
);
318 /* test the reset value */
319 opt
= qemu_opt_get_size(opts
, "size1", 5);
322 qdict_del(dict
, "size1");
327 /* should not find anything at this point */
328 opts
= qemu_opts_find(list
, NULL
);
329 g_assert(opts
== NULL
);
332 static void test_qemu_opt_unset(void)
338 /* dynamically initialized (parsed) opts */
339 opts
= qemu_opts_parse(&opts_list_03
, "key=value", false, NULL
);
340 g_assert(opts
!= NULL
);
342 /* check default/parsed value */
343 value
= qemu_opt_get(opts
, "key");
344 g_assert_cmpstr(value
, ==, "value");
346 /* reset it to value2 */
347 qemu_opt_set(opts
, "key", "value2", &error_abort
);
349 value
= qemu_opt_get(opts
, "key");
350 g_assert_cmpstr(value
, ==, "value2");
352 /* unset, valid only for "accept any" */
353 ret
= qemu_opt_unset(opts
, "key");
356 /* after reset the value should be the parsed/default one */
357 value
= qemu_opt_get(opts
, "key");
358 g_assert_cmpstr(value
, ==, "value");
363 static void test_qemu_opts_reset(void)
370 list
= qemu_find_opts("opts_list_01");
371 g_assert(list
!= NULL
);
372 g_assert(QTAILQ_EMPTY(&list
->head
));
373 g_assert_cmpstr(list
->name
, ==, "opts_list_01");
375 /* should not find anything at this point */
376 opts
= qemu_opts_find(list
, NULL
);
377 g_assert(opts
== NULL
);
379 /* create the opts */
380 opts
= qemu_opts_create(list
, NULL
, 0, &error_abort
);
381 g_assert(opts
!= NULL
);
382 g_assert(!QTAILQ_EMPTY(&list
->head
));
384 /* haven't set anything to number1 yet, so defval should be returned */
385 opt
= qemu_opt_get_number(opts
, "number1", 5);
388 qemu_opt_set_number(opts
, "number1", 10, &err
);
391 /* now we have set number1, should know about it */
392 opt
= qemu_opt_get_number(opts
, "number1", 5);
395 qemu_opts_reset(list
);
397 /* should not find anything at this point */
398 opts
= qemu_opts_find(list
, NULL
);
399 g_assert(opts
== NULL
);
402 static void test_qemu_opts_set(void)
409 list
= qemu_find_opts("opts_list_01");
410 g_assert(list
!= NULL
);
411 g_assert(QTAILQ_EMPTY(&list
->head
));
412 g_assert_cmpstr(list
->name
, ==, "opts_list_01");
414 /* should not find anything at this point */
415 opts
= qemu_opts_find(list
, NULL
);
416 g_assert(opts
== NULL
);
418 /* implicitly create opts and set str3 value */
419 qemu_opts_set(list
, NULL
, "str3", "value", &err
);
421 g_assert(!QTAILQ_EMPTY(&list
->head
));
423 /* get the just created opts */
424 opts
= qemu_opts_find(list
, NULL
);
425 g_assert(opts
!= NULL
);
427 /* check the str3 value */
428 opt
= qemu_opt_get(opts
, "str3");
429 g_assert_cmpstr(opt
, ==, "value");
433 /* should not find anything at this point */
434 opts
= qemu_opts_find(list
, NULL
);
435 g_assert(opts
== NULL
);
438 static int opts_count_iter(void *opaque
, const char *name
, const char *value
,
441 (*(size_t *)opaque
)++;
445 static size_t opts_count(QemuOpts
*opts
)
449 qemu_opt_foreach(opts
, opts_count_iter
, &n
, NULL
);
453 static void test_opts_parse(void)
461 opts
= qemu_opts_parse(&opts_list_03
, "", false, &error_abort
);
462 g_assert_cmpuint(opts_count(opts
), ==, 0);
465 opts
= qemu_opts_parse(&opts_list_03
, "=val", false, &error_abort
);
466 g_assert_cmpuint(opts_count(opts
), ==, 1);
467 g_assert_cmpstr(qemu_opt_get(opts
, ""), ==, "val");
470 memset(long_key
, 'a', 127);
473 params
= g_strdup_printf("%s=v", long_key
);
474 opts
= qemu_opts_parse(&opts_list_03
, params
+ 1, NULL
, &error_abort
);
475 g_assert_cmpuint(opts_count(opts
), ==, 1);
476 g_assert_cmpstr(qemu_opt_get(opts
, long_key
+ 1), ==, "v");
478 /* Overlong key gets truncated */
479 opts
= qemu_opts_parse(&opts_list_03
, params
, NULL
, &error_abort
);
480 g_assert(opts_count(opts
) == 1);
482 g_assert_cmpstr(qemu_opt_get(opts
, long_key
), ==, "v");
485 /* Multiple keys, last one wins */
486 opts
= qemu_opts_parse(&opts_list_03
, "a=1,b=2,,x,a=3",
487 false, &error_abort
);
488 g_assert_cmpuint(opts_count(opts
), ==, 3);
489 g_assert_cmpstr(qemu_opt_get(opts
, "a"), ==, "3");
490 g_assert_cmpstr(qemu_opt_get(opts
, "b"), ==, "2,x");
492 /* Except when it doesn't */
493 opts
= qemu_opts_parse(&opts_list_03
, "id=foo,id=bar",
494 false, &error_abort
);
495 g_assert_cmpuint(opts_count(opts
), ==, 0);
496 g_assert_cmpstr(qemu_opts_id(opts
), ==, "foo");
498 /* TODO Cover low-level access to repeated keys */
500 /* Trailing comma is ignored */
501 opts
= qemu_opts_parse(&opts_list_03
, "x=y,", false, &error_abort
);
502 g_assert_cmpuint(opts_count(opts
), ==, 1);
503 g_assert_cmpstr(qemu_opt_get(opts
, "x"), ==, "y");
505 /* Except when it isn't */
506 opts
= qemu_opts_parse(&opts_list_03
, ",", false, &error_abort
);
507 g_assert_cmpuint(opts_count(opts
), ==, 1);
508 g_assert_cmpstr(qemu_opt_get(opts
, ""), ==, "on");
511 opts
= qemu_opts_parse(&opts_list_03
, "x=y,id=foo", false, &err
);
512 error_free_or_abort(&err
);
514 /* TODO Cover .merge_lists = true */
516 /* Buggy ID recognition */
517 opts
= qemu_opts_parse(&opts_list_03
, "x=,,id=bar", false, &error_abort
);
518 g_assert_cmpuint(opts_count(opts
), ==, 1);
519 g_assert_cmpstr(qemu_opts_id(opts
), ==, "bar"); /* BUG */
520 g_assert_cmpstr(qemu_opt_get(opts
, "x"), ==, ",id=bar");
523 opts
= qemu_opts_parse(&opts_list_01
, "id=666", false, &err
);
524 error_free_or_abort(&err
);
528 opts
= qemu_opts_parse(&opts_list_03
, "an,noaus,noaus=",
529 false, &error_abort
);
530 g_assert_cmpuint(opts_count(opts
), ==, 3);
531 g_assert_cmpstr(qemu_opt_get(opts
, "an"), ==, "on");
532 g_assert_cmpstr(qemu_opt_get(opts
, "aus"), ==, "off");
533 g_assert_cmpstr(qemu_opt_get(opts
, "noaus"), ==, "");
536 opts
= qemu_opts_parse(&opts_list_03
, "an,noaus,noaus=", true,
538 g_assert_cmpuint(opts_count(opts
), ==, 3);
539 g_assert_cmpstr(qemu_opt_get(opts
, "implied"), ==, "an");
540 g_assert_cmpstr(qemu_opt_get(opts
, "aus"), ==, "off");
541 g_assert_cmpstr(qemu_opt_get(opts
, "noaus"), ==, "");
543 /* Implied key with empty value */
544 opts
= qemu_opts_parse(&opts_list_03
, ",", true, &error_abort
);
545 g_assert_cmpuint(opts_count(opts
), ==, 1);
546 g_assert_cmpstr(qemu_opt_get(opts
, "implied"), ==, "");
548 /* Implied key with comma value */
549 opts
= qemu_opts_parse(&opts_list_03
, ",,,a=1", true, &error_abort
);
550 g_assert_cmpuint(opts_count(opts
), ==, 2);
551 g_assert_cmpstr(qemu_opt_get(opts
, "implied"), ==, ",");
552 g_assert_cmpstr(qemu_opt_get(opts
, "a"), ==, "1");
554 /* Empty key is not an implied key */
555 opts
= qemu_opts_parse(&opts_list_03
, "=val", true, &error_abort
);
556 g_assert_cmpuint(opts_count(opts
), ==, 1);
557 g_assert_cmpstr(qemu_opt_get(opts
, ""), ==, "val");
560 opts
= qemu_opts_parse(&opts_list_01
, "nonexistent=", false, &err
);
561 error_free_or_abort(&err
);
564 qemu_opts_reset(&opts_list_01
);
565 qemu_opts_reset(&opts_list_03
);
568 static void test_opts_parse_bool(void)
573 opts
= qemu_opts_parse(&opts_list_02
, "bool1=on,bool2=off",
574 false, &error_abort
);
575 g_assert_cmpuint(opts_count(opts
), ==, 2);
576 g_assert(qemu_opt_get_bool(opts
, "bool1", false));
577 g_assert(!qemu_opt_get_bool(opts
, "bool2", true));
579 opts
= qemu_opts_parse(&opts_list_02
, "bool1=offer", false, &err
);
580 error_free_or_abort(&err
);
583 qemu_opts_reset(&opts_list_02
);
586 static void test_opts_parse_number(void)
591 /* Lower limit zero */
592 opts
= qemu_opts_parse(&opts_list_01
, "number1=0", false, &error_abort
);
593 g_assert_cmpuint(opts_count(opts
), ==, 1);
594 g_assert_cmpuint(qemu_opt_get_number(opts
, "number1", 1), ==, 0);
596 /* Upper limit 2^64-1 */
597 opts
= qemu_opts_parse(&opts_list_01
,
598 "number1=18446744073709551615,number2=-1",
599 false, &error_abort
);
600 g_assert_cmpuint(opts_count(opts
), ==, 2);
601 g_assert_cmphex(qemu_opt_get_number(opts
, "number1", 1), ==, UINT64_MAX
);
602 g_assert_cmphex(qemu_opt_get_number(opts
, "number2", 0), ==, UINT64_MAX
);
604 /* Above upper limit */
605 opts
= qemu_opts_parse(&opts_list_01
, "number1=18446744073709551616",
606 false, &error_abort
);
607 /* BUG: should reject */
608 g_assert_cmpuint(opts_count(opts
), ==, 1);
609 g_assert_cmpuint(qemu_opt_get_number(opts
, "number1", 1), ==, UINT64_MAX
);
611 /* Below lower limit */
612 opts
= qemu_opts_parse(&opts_list_01
, "number1=-18446744073709551616",
613 false, &error_abort
);
614 /* BUG: should reject */
615 g_assert_cmpuint(opts_count(opts
), ==, 1);
616 g_assert_cmpuint(qemu_opt_get_number(opts
, "number1", 1), ==, UINT64_MAX
);
619 opts
= qemu_opts_parse(&opts_list_01
, "number1=0x2a,number2=052",
620 false, &error_abort
);
621 g_assert_cmpuint(opts_count(opts
), ==, 2);
622 g_assert_cmpuint(qemu_opt_get_number(opts
, "number1", 1), ==, 42);
623 g_assert_cmpuint(qemu_opt_get_number(opts
, "number2", 0), ==, 42);
626 opts
= qemu_opts_parse(&opts_list_01
, "number1=", false, &err
);
627 /* BUG: should reject */
628 g_assert_cmpuint(opts_count(opts
), ==, 1);
629 g_assert_cmpuint(qemu_opt_get_number(opts
, "number1", 1), ==, 0);
630 opts
= qemu_opts_parse(&opts_list_01
, "number1=eins", false, &err
);
631 error_free_or_abort(&err
);
634 /* Leading whitespace */
635 opts
= qemu_opts_parse(&opts_list_01
, "number1= \t42",
636 false, &error_abort
);
637 g_assert_cmpuint(opts_count(opts
), ==, 1);
638 g_assert_cmpuint(qemu_opt_get_number(opts
, "number1", 1), ==, 42);
641 opts
= qemu_opts_parse(&opts_list_01
, "number1=3.14", false, &err
);
642 error_free_or_abort(&err
);
644 opts
= qemu_opts_parse(&opts_list_01
, "number1=08", false, &err
);
645 error_free_or_abort(&err
);
647 opts
= qemu_opts_parse(&opts_list_01
, "number1=0 ", false, &err
);
648 error_free_or_abort(&err
);
651 qemu_opts_reset(&opts_list_01
);
654 static void test_opts_parse_size(void)
659 /* Lower limit zero */
660 opts
= qemu_opts_parse(&opts_list_02
, "size1=0", false, &error_abort
);
661 g_assert_cmpuint(opts_count(opts
), ==, 1);
662 g_assert_cmpuint(qemu_opt_get_size(opts
, "size1", 1), ==, 0);
664 /* Note: precision is 53 bits since we're parsing with strtod() */
666 /* Around limit of precision: 2^53-1, 2^53, 2^54 */
667 opts
= qemu_opts_parse(&opts_list_02
,
668 "size1=9007199254740991,"
669 "size2=9007199254740992,"
670 "size3=9007199254740993",
671 false, &error_abort
);
672 g_assert_cmpuint(opts_count(opts
), ==, 3);
673 g_assert_cmphex(qemu_opt_get_size(opts
, "size1", 1),
674 ==, 0x1fffffffffffff);
675 g_assert_cmphex(qemu_opt_get_size(opts
, "size2", 1),
676 ==, 0x20000000000000);
677 g_assert_cmphex(qemu_opt_get_size(opts
, "size3", 1),
678 ==, 0x20000000000000);
680 /* Close to signed upper limit 0x7ffffffffffffc00 (53 msbs set) */
681 opts
= qemu_opts_parse(&opts_list_02
,
682 "size1=9223372036854774784," /* 7ffffffffffffc00 */
683 "size2=9223372036854775295", /* 7ffffffffffffdff */
684 false, &error_abort
);
685 g_assert_cmpuint(opts_count(opts
), ==, 2);
686 g_assert_cmphex(qemu_opt_get_size(opts
, "size1", 1),
687 ==, 0x7ffffffffffffc00);
688 g_assert_cmphex(qemu_opt_get_size(opts
, "size2", 1),
689 ==, 0x7ffffffffffffc00);
691 /* Close to actual upper limit 0xfffffffffffff800 (53 msbs set) */
692 opts
= qemu_opts_parse(&opts_list_02
,
693 "size1=18446744073709549568," /* fffffffffffff800 */
694 "size2=18446744073709550591", /* fffffffffffffbff */
695 false, &error_abort
);
696 g_assert_cmpuint(opts_count(opts
), ==, 2);
697 g_assert_cmphex(qemu_opt_get_size(opts
, "size1", 1),
698 ==, 0xfffffffffffff800);
699 g_assert_cmphex(qemu_opt_get_size(opts
, "size2", 1),
700 ==, 0xfffffffffffff800);
703 opts
= qemu_opts_parse(&opts_list_02
, "size1=-1", false, &err
);
704 error_free_or_abort(&err
);
706 opts
= qemu_opts_parse(&opts_list_02
,
707 "size1=18446744073709550592", /* fffffffffffffc00 */
708 false, &error_abort
);
709 /* BUG: should reject */
710 g_assert_cmpuint(opts_count(opts
), ==, 1);
711 g_assert_cmpuint(qemu_opt_get_size(opts
, "size1", 1), ==, 0);
714 opts
= qemu_opts_parse(&opts_list_02
, "size1=8b,size2=1.5k,size3=2M",
715 false, &error_abort
);
716 g_assert_cmpuint(opts_count(opts
), ==, 3);
717 g_assert_cmphex(qemu_opt_get_size(opts
, "size1", 0), ==, 8);
718 g_assert_cmphex(qemu_opt_get_size(opts
, "size2", 0), ==, 1536);
719 g_assert_cmphex(qemu_opt_get_size(opts
, "size3", 0), ==, 2 * M_BYTE
);
720 opts
= qemu_opts_parse(&opts_list_02
, "size1=0.1G,size2=16777215T",
721 false, &error_abort
);
722 g_assert_cmpuint(opts_count(opts
), ==, 2);
723 g_assert_cmphex(qemu_opt_get_size(opts
, "size1", 0), ==, G_BYTE
/ 10);
724 g_assert_cmphex(qemu_opt_get_size(opts
, "size2", 0),
725 ==, 16777215 * T_BYTE
);
727 /* Beyond limit with suffix */
728 opts
= qemu_opts_parse(&opts_list_02
, "size1=16777216T",
729 false, &error_abort
);
730 /* BUG: should reject */
731 g_assert_cmpuint(opts_count(opts
), ==, 1);
732 g_assert_cmpuint(qemu_opt_get_size(opts
, "size1", 1), ==, 0);
735 opts
= qemu_opts_parse(&opts_list_02
, "size1=16E", false, &err
);
736 error_free_or_abort(&err
);
738 opts
= qemu_opts_parse(&opts_list_02
, "size1=16Gi", false, &error_abort
);
739 /* BUG: should reject */
740 g_assert_cmpuint(opts_count(opts
), ==, 1);
741 g_assert_cmpuint(qemu_opt_get_size(opts
, "size1", 1), ==, 16 * G_BYTE
);
743 qemu_opts_reset(&opts_list_02
);
746 int main(int argc
, char *argv
[])
749 g_test_init(&argc
, &argv
, NULL
);
750 g_test_add_func("/qemu-opts/find_unknown_opts", test_find_unknown_opts
);
751 g_test_add_func("/qemu-opts/find_opts", test_qemu_find_opts
);
752 g_test_add_func("/qemu-opts/opts_create", test_qemu_opts_create
);
753 g_test_add_func("/qemu-opts/opt_get", test_qemu_opt_get
);
754 g_test_add_func("/qemu-opts/opt_get_bool", test_qemu_opt_get_bool
);
755 g_test_add_func("/qemu-opts/opt_get_number", test_qemu_opt_get_number
);
756 g_test_add_func("/qemu-opts/opt_get_size", test_qemu_opt_get_size
);
757 g_test_add_func("/qemu-opts/opt_unset", test_qemu_opt_unset
);
758 g_test_add_func("/qemu-opts/opts_reset", test_qemu_opts_reset
);
759 g_test_add_func("/qemu-opts/opts_set", test_qemu_opts_set
);
760 g_test_add_func("/qemu-opts/opts_parse/general", test_opts_parse
);
761 g_test_add_func("/qemu-opts/opts_parse/bool", test_opts_parse_bool
);
762 g_test_add_func("/qemu-opts/opts_parse/number", test_opts_parse_number
);
763 g_test_add_func("/qemu-opts/opts_parse/size", test_opts_parse_size
);