4 * Copyright (C) 2013 Red Hat Inc.
7 * Eduardo Habkost <ehabkost@redhat.com>
9 * Permission is hereby granted, free of charge, to any person obtaining a copy
10 * of this software and associated documentation files (the "Software"), to deal
11 * in the Software without restriction, including without limitation the rights
12 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 * copies of the Software, and to permit persons to whom the Software is
14 * furnished to do so, subject to the following conditions:
16 * The above copyright notice and this permission notice shall be included in
17 * all copies or substantial portions of the Software.
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
22 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
28 #include "qemu/osdep.h"
30 #include "qemu/cutils.h"
32 static void test_parse_uint_null(void)
34 unsigned long long i
= 999;
39 r
= parse_uint(NULL
, &i
, &endptr
, 0);
41 g_assert_cmpint(r
, ==, -EINVAL
);
42 g_assert_cmpint(i
, ==, 0);
43 g_assert(endptr
== NULL
);
46 static void test_parse_uint_empty(void)
48 unsigned long long i
= 999;
54 r
= parse_uint(str
, &i
, &endptr
, 0);
56 g_assert_cmpint(r
, ==, -EINVAL
);
57 g_assert_cmpint(i
, ==, 0);
58 g_assert(endptr
== str
);
61 static void test_parse_uint_whitespace(void)
63 unsigned long long i
= 999;
66 const char *str
= " \t ";
69 r
= parse_uint(str
, &i
, &endptr
, 0);
71 g_assert_cmpint(r
, ==, -EINVAL
);
72 g_assert_cmpint(i
, ==, 0);
73 g_assert(endptr
== str
);
77 static void test_parse_uint_invalid(void)
79 unsigned long long i
= 999;
82 const char *str
= " \t xxx";
85 r
= parse_uint(str
, &i
, &endptr
, 0);
87 g_assert_cmpint(r
, ==, -EINVAL
);
88 g_assert_cmpint(i
, ==, 0);
89 g_assert(endptr
== str
);
93 static void test_parse_uint_trailing(void)
95 unsigned long long i
= 999;
98 const char *str
= "123xxx";
101 r
= parse_uint(str
, &i
, &endptr
, 0);
103 g_assert_cmpint(r
, ==, 0);
104 g_assert_cmpint(i
, ==, 123);
105 g_assert(endptr
== str
+ 3);
108 static void test_parse_uint_correct(void)
110 unsigned long long i
= 999;
113 const char *str
= "123";
116 r
= parse_uint(str
, &i
, &endptr
, 0);
118 g_assert_cmpint(r
, ==, 0);
119 g_assert_cmpint(i
, ==, 123);
120 g_assert(endptr
== str
+ strlen(str
));
123 static void test_parse_uint_octal(void)
125 unsigned long long i
= 999;
128 const char *str
= "0123";
131 r
= parse_uint(str
, &i
, &endptr
, 0);
133 g_assert_cmpint(r
, ==, 0);
134 g_assert_cmpint(i
, ==, 0123);
135 g_assert(endptr
== str
+ strlen(str
));
138 static void test_parse_uint_decimal(void)
140 unsigned long long i
= 999;
143 const char *str
= "0123";
146 r
= parse_uint(str
, &i
, &endptr
, 10);
148 g_assert_cmpint(r
, ==, 0);
149 g_assert_cmpint(i
, ==, 123);
150 g_assert(endptr
== str
+ strlen(str
));
154 static void test_parse_uint_llong_max(void)
156 unsigned long long i
= 999;
159 char *str
= g_strdup_printf("%llu", (unsigned long long)LLONG_MAX
+ 1);
162 r
= parse_uint(str
, &i
, &endptr
, 0);
164 g_assert_cmpint(r
, ==, 0);
165 g_assert_cmpint(i
, ==, (unsigned long long)LLONG_MAX
+ 1);
166 g_assert(endptr
== str
+ strlen(str
));
171 static void test_parse_uint_overflow(void)
173 unsigned long long i
= 999;
176 const char *str
= "99999999999999999999999999999999999999";
179 r
= parse_uint(str
, &i
, &endptr
, 0);
181 g_assert_cmpint(r
, ==, -ERANGE
);
182 g_assert_cmpint(i
, ==, ULLONG_MAX
);
183 g_assert(endptr
== str
+ strlen(str
));
186 static void test_parse_uint_negative(void)
188 unsigned long long i
= 999;
191 const char *str
= " \t -321";
194 r
= parse_uint(str
, &i
, &endptr
, 0);
196 g_assert_cmpint(r
, ==, -ERANGE
);
197 g_assert_cmpint(i
, ==, 0);
198 g_assert(endptr
== str
+ strlen(str
));
202 static void test_parse_uint_full_trailing(void)
204 unsigned long long i
= 999;
205 const char *str
= "123xxx";
208 r
= parse_uint_full(str
, &i
, 0);
210 g_assert_cmpint(r
, ==, -EINVAL
);
211 g_assert_cmpint(i
, ==, 0);
214 static void test_parse_uint_full_correct(void)
216 unsigned long long i
= 999;
217 const char *str
= "123";
220 r
= parse_uint_full(str
, &i
, 0);
222 g_assert_cmpint(r
, ==, 0);
223 g_assert_cmpint(i
, ==, 123);
226 static void test_qemu_strtoi_correct(void)
228 const char *str
= "12345 foo";
230 const char *endptr
= &f
;
234 err
= qemu_strtoi(str
, &endptr
, 0, &res
);
236 g_assert_cmpint(err
, ==, 0);
237 g_assert_cmpint(res
, ==, 12345);
238 g_assert(endptr
== str
+ 5);
241 static void test_qemu_strtoi_null(void)
244 const char *endptr
= &f
;
248 err
= qemu_strtoi(NULL
, &endptr
, 0, &res
);
250 g_assert_cmpint(err
, ==, -EINVAL
);
251 g_assert(endptr
== NULL
);
254 static void test_qemu_strtoi_empty(void)
256 const char *str
= "";
258 const char *endptr
= &f
;
262 err
= qemu_strtoi(str
, &endptr
, 0, &res
);
264 g_assert_cmpint(err
, ==, -EINVAL
);
265 g_assert(endptr
== str
);
268 static void test_qemu_strtoi_whitespace(void)
270 const char *str
= " \t ";
272 const char *endptr
= &f
;
276 err
= qemu_strtoi(str
, &endptr
, 0, &res
);
278 g_assert_cmpint(err
, ==, -EINVAL
);
279 g_assert(endptr
== str
);
282 static void test_qemu_strtoi_invalid(void)
284 const char *str
= " xxxx \t abc";
286 const char *endptr
= &f
;
290 err
= qemu_strtoi(str
, &endptr
, 0, &res
);
292 g_assert_cmpint(err
, ==, -EINVAL
);
293 g_assert(endptr
== str
);
296 static void test_qemu_strtoi_trailing(void)
298 const char *str
= "123xxx";
300 const char *endptr
= &f
;
304 err
= qemu_strtoi(str
, &endptr
, 0, &res
);
306 g_assert_cmpint(err
, ==, 0);
307 g_assert_cmpint(res
, ==, 123);
308 g_assert(endptr
== str
+ 3);
311 static void test_qemu_strtoi_octal(void)
313 const char *str
= "0123";
315 const char *endptr
= &f
;
319 err
= qemu_strtoi(str
, &endptr
, 8, &res
);
321 g_assert_cmpint(err
, ==, 0);
322 g_assert_cmpint(res
, ==, 0123);
323 g_assert(endptr
== str
+ strlen(str
));
327 err
= qemu_strtoi(str
, &endptr
, 0, &res
);
329 g_assert_cmpint(err
, ==, 0);
330 g_assert_cmpint(res
, ==, 0123);
331 g_assert(endptr
== str
+ strlen(str
));
334 static void test_qemu_strtoi_decimal(void)
336 const char *str
= "0123";
338 const char *endptr
= &f
;
342 err
= qemu_strtoi(str
, &endptr
, 10, &res
);
344 g_assert_cmpint(err
, ==, 0);
345 g_assert_cmpint(res
, ==, 123);
346 g_assert(endptr
== str
+ strlen(str
));
351 err
= qemu_strtoi(str
, &endptr
, 0, &res
);
353 g_assert_cmpint(err
, ==, 0);
354 g_assert_cmpint(res
, ==, 123);
355 g_assert(endptr
== str
+ strlen(str
));
358 static void test_qemu_strtoi_hex(void)
360 const char *str
= "0123";
362 const char *endptr
= &f
;
366 err
= qemu_strtoi(str
, &endptr
, 16, &res
);
368 g_assert_cmpint(err
, ==, 0);
369 g_assert_cmpint(res
, ==, 0x123);
370 g_assert(endptr
== str
+ strlen(str
));
375 err
= qemu_strtoi(str
, &endptr
, 0, &res
);
377 g_assert_cmpint(err
, ==, 0);
378 g_assert_cmpint(res
, ==, 0x123);
379 g_assert(endptr
== str
+ strlen(str
));
382 static void test_qemu_strtoi_max(void)
384 char *str
= g_strdup_printf("%d", INT_MAX
);
386 const char *endptr
= &f
;
390 err
= qemu_strtoi(str
, &endptr
, 0, &res
);
392 g_assert_cmpint(err
, ==, 0);
393 g_assert_cmpint(res
, ==, INT_MAX
);
394 g_assert(endptr
== str
+ strlen(str
));
398 static void test_qemu_strtoi_overflow(void)
400 char *str
= g_strdup_printf("%lld", (long long)INT_MAX
+ 1ll);
402 const char *endptr
= &f
;
406 err
= qemu_strtoi(str
, &endptr
, 0, &res
);
408 g_assert_cmpint(err
, ==, -ERANGE
);
409 g_assert_cmpint(res
, ==, INT_MAX
);
410 g_assert(endptr
== str
+ strlen(str
));
414 static void test_qemu_strtoi_underflow(void)
416 char *str
= g_strdup_printf("%lld", (long long)INT_MIN
- 1ll);
418 const char *endptr
= &f
;
422 err
= qemu_strtoi(str
, &endptr
, 0, &res
);
424 g_assert_cmpint(err
, ==, -ERANGE
);
425 g_assert_cmpint(res
, ==, INT_MIN
);
426 g_assert(endptr
== str
+ strlen(str
));
430 static void test_qemu_strtoi_negative(void)
432 const char *str
= " \t -321";
434 const char *endptr
= &f
;
438 err
= qemu_strtoi(str
, &endptr
, 0, &res
);
440 g_assert_cmpint(err
, ==, 0);
441 g_assert_cmpint(res
, ==, -321);
442 g_assert(endptr
== str
+ strlen(str
));
445 static void test_qemu_strtoi_full_correct(void)
447 const char *str
= "123";
451 err
= qemu_strtoi(str
, NULL
, 0, &res
);
453 g_assert_cmpint(err
, ==, 0);
454 g_assert_cmpint(res
, ==, 123);
457 static void test_qemu_strtoi_full_null(void)
460 const char *endptr
= &f
;
464 err
= qemu_strtoi(NULL
, &endptr
, 0, &res
);
466 g_assert_cmpint(err
, ==, -EINVAL
);
467 g_assert(endptr
== NULL
);
470 static void test_qemu_strtoi_full_empty(void)
472 const char *str
= "";
476 err
= qemu_strtoi(str
, NULL
, 0, &res
);
478 g_assert_cmpint(err
, ==, -EINVAL
);
481 static void test_qemu_strtoi_full_negative(void)
483 const char *str
= " \t -321";
487 err
= qemu_strtoi(str
, NULL
, 0, &res
);
489 g_assert_cmpint(err
, ==, 0);
490 g_assert_cmpint(res
, ==, -321);
493 static void test_qemu_strtoi_full_trailing(void)
495 const char *str
= "123xxx";
499 err
= qemu_strtoi(str
, NULL
, 0, &res
);
501 g_assert_cmpint(err
, ==, -EINVAL
);
504 static void test_qemu_strtoi_full_max(void)
506 char *str
= g_strdup_printf("%d", INT_MAX
);
510 err
= qemu_strtoi(str
, NULL
, 0, &res
);
512 g_assert_cmpint(err
, ==, 0);
513 g_assert_cmpint(res
, ==, INT_MAX
);
517 static void test_qemu_strtoui_correct(void)
519 const char *str
= "12345 foo";
521 const char *endptr
= &f
;
522 unsigned int res
= 999;
525 err
= qemu_strtoui(str
, &endptr
, 0, &res
);
527 g_assert_cmpint(err
, ==, 0);
528 g_assert_cmpuint(res
, ==, 12345);
529 g_assert(endptr
== str
+ 5);
532 static void test_qemu_strtoui_null(void)
535 const char *endptr
= &f
;
536 unsigned int res
= 999;
539 err
= qemu_strtoui(NULL
, &endptr
, 0, &res
);
541 g_assert_cmpint(err
, ==, -EINVAL
);
542 g_assert(endptr
== NULL
);
545 static void test_qemu_strtoui_empty(void)
547 const char *str
= "";
549 const char *endptr
= &f
;
550 unsigned int res
= 999;
553 err
= qemu_strtoui(str
, &endptr
, 0, &res
);
555 g_assert_cmpint(err
, ==, -EINVAL
);
556 g_assert(endptr
== str
);
559 static void test_qemu_strtoui_whitespace(void)
561 const char *str
= " \t ";
563 const char *endptr
= &f
;
564 unsigned int res
= 999;
567 err
= qemu_strtoui(str
, &endptr
, 0, &res
);
569 g_assert_cmpint(err
, ==, -EINVAL
);
570 g_assert(endptr
== str
);
573 static void test_qemu_strtoui_invalid(void)
575 const char *str
= " xxxx \t abc";
577 const char *endptr
= &f
;
578 unsigned int res
= 999;
581 err
= qemu_strtoui(str
, &endptr
, 0, &res
);
583 g_assert_cmpint(err
, ==, -EINVAL
);
584 g_assert(endptr
== str
);
587 static void test_qemu_strtoui_trailing(void)
589 const char *str
= "123xxx";
591 const char *endptr
= &f
;
592 unsigned int res
= 999;
595 err
= qemu_strtoui(str
, &endptr
, 0, &res
);
597 g_assert_cmpint(err
, ==, 0);
598 g_assert_cmpuint(res
, ==, 123);
599 g_assert(endptr
== str
+ 3);
602 static void test_qemu_strtoui_octal(void)
604 const char *str
= "0123";
606 const char *endptr
= &f
;
607 unsigned int res
= 999;
610 err
= qemu_strtoui(str
, &endptr
, 8, &res
);
612 g_assert_cmpint(err
, ==, 0);
613 g_assert_cmpuint(res
, ==, 0123);
614 g_assert(endptr
== str
+ strlen(str
));
618 err
= qemu_strtoui(str
, &endptr
, 0, &res
);
620 g_assert_cmpint(err
, ==, 0);
621 g_assert_cmpuint(res
, ==, 0123);
622 g_assert(endptr
== str
+ strlen(str
));
625 static void test_qemu_strtoui_decimal(void)
627 const char *str
= "0123";
629 const char *endptr
= &f
;
630 unsigned int res
= 999;
633 err
= qemu_strtoui(str
, &endptr
, 10, &res
);
635 g_assert_cmpint(err
, ==, 0);
636 g_assert_cmpuint(res
, ==, 123);
637 g_assert(endptr
== str
+ strlen(str
));
642 err
= qemu_strtoui(str
, &endptr
, 0, &res
);
644 g_assert_cmpint(err
, ==, 0);
645 g_assert_cmpuint(res
, ==, 123);
646 g_assert(endptr
== str
+ strlen(str
));
649 static void test_qemu_strtoui_hex(void)
651 const char *str
= "0123";
653 const char *endptr
= &f
;
654 unsigned int res
= 999;
657 err
= qemu_strtoui(str
, &endptr
, 16, &res
);
659 g_assert_cmpint(err
, ==, 0);
660 g_assert_cmphex(res
, ==, 0x123);
661 g_assert(endptr
== str
+ strlen(str
));
666 err
= qemu_strtoui(str
, &endptr
, 0, &res
);
668 g_assert_cmpint(err
, ==, 0);
669 g_assert_cmphex(res
, ==, 0x123);
670 g_assert(endptr
== str
+ strlen(str
));
673 static void test_qemu_strtoui_max(void)
675 char *str
= g_strdup_printf("%u", UINT_MAX
);
677 const char *endptr
= &f
;
678 unsigned int res
= 999;
681 err
= qemu_strtoui(str
, &endptr
, 0, &res
);
683 g_assert_cmpint(err
, ==, 0);
684 g_assert_cmphex(res
, ==, UINT_MAX
);
685 g_assert(endptr
== str
+ strlen(str
));
689 static void test_qemu_strtoui_overflow(void)
691 char *str
= g_strdup_printf("%lld", (long long)UINT_MAX
+ 1ll);
693 const char *endptr
= &f
;
694 unsigned int res
= 999;
697 err
= qemu_strtoui(str
, &endptr
, 0, &res
);
699 g_assert_cmpint(err
, ==, -ERANGE
);
700 g_assert_cmphex(res
, ==, UINT_MAX
);
701 g_assert(endptr
== str
+ strlen(str
));
705 static void test_qemu_strtoui_underflow(void)
707 char *str
= g_strdup_printf("%lld", (long long)INT_MIN
- 1ll);
709 const char *endptr
= &f
;
710 unsigned int res
= 999;
713 err
= qemu_strtoui(str
, &endptr
, 0, &res
);
715 g_assert_cmpint(err
, ==, -ERANGE
);
716 g_assert_cmpuint(res
, ==, (unsigned int)-1);
717 g_assert(endptr
== str
+ strlen(str
));
721 static void test_qemu_strtoui_negative(void)
723 const char *str
= " \t -321";
725 const char *endptr
= &f
;
726 unsigned int res
= 999;
729 err
= qemu_strtoui(str
, &endptr
, 0, &res
);
731 g_assert_cmpint(err
, ==, 0);
732 g_assert_cmpuint(res
, ==, (unsigned int)-321);
733 g_assert(endptr
== str
+ strlen(str
));
736 static void test_qemu_strtoui_full_correct(void)
738 const char *str
= "123";
739 unsigned int res
= 999;
742 err
= qemu_strtoui(str
, NULL
, 0, &res
);
744 g_assert_cmpint(err
, ==, 0);
745 g_assert_cmpuint(res
, ==, 123);
748 static void test_qemu_strtoui_full_null(void)
750 unsigned int res
= 999;
753 err
= qemu_strtoui(NULL
, NULL
, 0, &res
);
755 g_assert_cmpint(err
, ==, -EINVAL
);
758 static void test_qemu_strtoui_full_empty(void)
760 const char *str
= "";
761 unsigned int res
= 999;
764 err
= qemu_strtoui(str
, NULL
, 0, &res
);
766 g_assert_cmpint(err
, ==, -EINVAL
);
768 static void test_qemu_strtoui_full_negative(void)
770 const char *str
= " \t -321";
771 unsigned int res
= 999;
774 err
= qemu_strtoui(str
, NULL
, 0, &res
);
775 g_assert_cmpint(err
, ==, 0);
776 g_assert_cmpuint(res
, ==, (unsigned int)-321);
779 static void test_qemu_strtoui_full_trailing(void)
781 const char *str
= "123xxx";
785 err
= qemu_strtoui(str
, NULL
, 0, &res
);
787 g_assert_cmpint(err
, ==, -EINVAL
);
790 static void test_qemu_strtoui_full_max(void)
792 char *str
= g_strdup_printf("%u", UINT_MAX
);
793 unsigned int res
= 999;
796 err
= qemu_strtoui(str
, NULL
, 0, &res
);
798 g_assert_cmpint(err
, ==, 0);
799 g_assert_cmphex(res
, ==, UINT_MAX
);
803 static void test_qemu_strtol_correct(void)
805 const char *str
= "12345 foo";
807 const char *endptr
= &f
;
811 err
= qemu_strtol(str
, &endptr
, 0, &res
);
813 g_assert_cmpint(err
, ==, 0);
814 g_assert_cmpint(res
, ==, 12345);
815 g_assert(endptr
== str
+ 5);
818 static void test_qemu_strtol_null(void)
821 const char *endptr
= &f
;
825 err
= qemu_strtol(NULL
, &endptr
, 0, &res
);
827 g_assert_cmpint(err
, ==, -EINVAL
);
828 g_assert(endptr
== NULL
);
831 static void test_qemu_strtol_empty(void)
833 const char *str
= "";
835 const char *endptr
= &f
;
839 err
= qemu_strtol(str
, &endptr
, 0, &res
);
841 g_assert_cmpint(err
, ==, -EINVAL
);
842 g_assert(endptr
== str
);
845 static void test_qemu_strtol_whitespace(void)
847 const char *str
= " \t ";
849 const char *endptr
= &f
;
853 err
= qemu_strtol(str
, &endptr
, 0, &res
);
855 g_assert_cmpint(err
, ==, -EINVAL
);
856 g_assert(endptr
== str
);
859 static void test_qemu_strtol_invalid(void)
861 const char *str
= " xxxx \t abc";
863 const char *endptr
= &f
;
867 err
= qemu_strtol(str
, &endptr
, 0, &res
);
869 g_assert_cmpint(err
, ==, -EINVAL
);
870 g_assert(endptr
== str
);
873 static void test_qemu_strtol_trailing(void)
875 const char *str
= "123xxx";
877 const char *endptr
= &f
;
881 err
= qemu_strtol(str
, &endptr
, 0, &res
);
883 g_assert_cmpint(err
, ==, 0);
884 g_assert_cmpint(res
, ==, 123);
885 g_assert(endptr
== str
+ 3);
888 static void test_qemu_strtol_octal(void)
890 const char *str
= "0123";
892 const char *endptr
= &f
;
896 err
= qemu_strtol(str
, &endptr
, 8, &res
);
898 g_assert_cmpint(err
, ==, 0);
899 g_assert_cmpint(res
, ==, 0123);
900 g_assert(endptr
== str
+ strlen(str
));
904 err
= qemu_strtol(str
, &endptr
, 0, &res
);
906 g_assert_cmpint(err
, ==, 0);
907 g_assert_cmpint(res
, ==, 0123);
908 g_assert(endptr
== str
+ strlen(str
));
911 static void test_qemu_strtol_decimal(void)
913 const char *str
= "0123";
915 const char *endptr
= &f
;
919 err
= qemu_strtol(str
, &endptr
, 10, &res
);
921 g_assert_cmpint(err
, ==, 0);
922 g_assert_cmpint(res
, ==, 123);
923 g_assert(endptr
== str
+ strlen(str
));
928 err
= qemu_strtol(str
, &endptr
, 0, &res
);
930 g_assert_cmpint(err
, ==, 0);
931 g_assert_cmpint(res
, ==, 123);
932 g_assert(endptr
== str
+ strlen(str
));
935 static void test_qemu_strtol_hex(void)
937 const char *str
= "0123";
939 const char *endptr
= &f
;
943 err
= qemu_strtol(str
, &endptr
, 16, &res
);
945 g_assert_cmpint(err
, ==, 0);
946 g_assert_cmpint(res
, ==, 0x123);
947 g_assert(endptr
== str
+ strlen(str
));
952 err
= qemu_strtol(str
, &endptr
, 0, &res
);
954 g_assert_cmpint(err
, ==, 0);
955 g_assert_cmpint(res
, ==, 0x123);
956 g_assert(endptr
== str
+ strlen(str
));
959 static void test_qemu_strtol_max(void)
961 char *str
= g_strdup_printf("%ld", LONG_MAX
);
963 const char *endptr
= &f
;
967 err
= qemu_strtol(str
, &endptr
, 0, &res
);
969 g_assert_cmpint(err
, ==, 0);
970 g_assert_cmpint(res
, ==, LONG_MAX
);
971 g_assert(endptr
== str
+ strlen(str
));
975 static void test_qemu_strtol_overflow(void)
977 const char *str
= "99999999999999999999999999999999999999999999";
979 const char *endptr
= &f
;
983 err
= qemu_strtol(str
, &endptr
, 0, &res
);
985 g_assert_cmpint(err
, ==, -ERANGE
);
986 g_assert_cmpint(res
, ==, LONG_MAX
);
987 g_assert(endptr
== str
+ strlen(str
));
990 static void test_qemu_strtol_underflow(void)
992 const char *str
= "-99999999999999999999999999999999999999999999";
994 const char *endptr
= &f
;
998 err
= qemu_strtol(str
, &endptr
, 0, &res
);
1000 g_assert_cmpint(err
, ==, -ERANGE
);
1001 g_assert_cmpint(res
, ==, LONG_MIN
);
1002 g_assert(endptr
== str
+ strlen(str
));
1005 static void test_qemu_strtol_negative(void)
1007 const char *str
= " \t -321";
1009 const char *endptr
= &f
;
1013 err
= qemu_strtol(str
, &endptr
, 0, &res
);
1015 g_assert_cmpint(err
, ==, 0);
1016 g_assert_cmpint(res
, ==, -321);
1017 g_assert(endptr
== str
+ strlen(str
));
1020 static void test_qemu_strtol_full_correct(void)
1022 const char *str
= "123";
1026 err
= qemu_strtol(str
, NULL
, 0, &res
);
1028 g_assert_cmpint(err
, ==, 0);
1029 g_assert_cmpint(res
, ==, 123);
1032 static void test_qemu_strtol_full_null(void)
1035 const char *endptr
= &f
;
1039 err
= qemu_strtol(NULL
, &endptr
, 0, &res
);
1041 g_assert_cmpint(err
, ==, -EINVAL
);
1042 g_assert(endptr
== NULL
);
1045 static void test_qemu_strtol_full_empty(void)
1047 const char *str
= "";
1051 err
= qemu_strtol(str
, NULL
, 0, &res
);
1053 g_assert_cmpint(err
, ==, -EINVAL
);
1056 static void test_qemu_strtol_full_negative(void)
1058 const char *str
= " \t -321";
1062 err
= qemu_strtol(str
, NULL
, 0, &res
);
1064 g_assert_cmpint(err
, ==, 0);
1065 g_assert_cmpint(res
, ==, -321);
1068 static void test_qemu_strtol_full_trailing(void)
1070 const char *str
= "123xxx";
1074 err
= qemu_strtol(str
, NULL
, 0, &res
);
1076 g_assert_cmpint(err
, ==, -EINVAL
);
1079 static void test_qemu_strtol_full_max(void)
1081 char *str
= g_strdup_printf("%ld", LONG_MAX
);
1085 err
= qemu_strtol(str
, NULL
, 0, &res
);
1087 g_assert_cmpint(err
, ==, 0);
1088 g_assert_cmpint(res
, ==, LONG_MAX
);
1092 static void test_qemu_strtoul_correct(void)
1094 const char *str
= "12345 foo";
1096 const char *endptr
= &f
;
1097 unsigned long res
= 999;
1100 err
= qemu_strtoul(str
, &endptr
, 0, &res
);
1102 g_assert_cmpint(err
, ==, 0);
1103 g_assert_cmpuint(res
, ==, 12345);
1104 g_assert(endptr
== str
+ 5);
1107 static void test_qemu_strtoul_null(void)
1110 const char *endptr
= &f
;
1111 unsigned long res
= 999;
1114 err
= qemu_strtoul(NULL
, &endptr
, 0, &res
);
1116 g_assert_cmpint(err
, ==, -EINVAL
);
1117 g_assert(endptr
== NULL
);
1120 static void test_qemu_strtoul_empty(void)
1122 const char *str
= "";
1124 const char *endptr
= &f
;
1125 unsigned long res
= 999;
1128 err
= qemu_strtoul(str
, &endptr
, 0, &res
);
1130 g_assert_cmpint(err
, ==, -EINVAL
);
1131 g_assert(endptr
== str
);
1134 static void test_qemu_strtoul_whitespace(void)
1136 const char *str
= " \t ";
1138 const char *endptr
= &f
;
1139 unsigned long res
= 999;
1142 err
= qemu_strtoul(str
, &endptr
, 0, &res
);
1144 g_assert_cmpint(err
, ==, -EINVAL
);
1145 g_assert(endptr
== str
);
1148 static void test_qemu_strtoul_invalid(void)
1150 const char *str
= " xxxx \t abc";
1152 const char *endptr
= &f
;
1153 unsigned long res
= 999;
1156 err
= qemu_strtoul(str
, &endptr
, 0, &res
);
1158 g_assert_cmpint(err
, ==, -EINVAL
);
1159 g_assert(endptr
== str
);
1162 static void test_qemu_strtoul_trailing(void)
1164 const char *str
= "123xxx";
1166 const char *endptr
= &f
;
1167 unsigned long res
= 999;
1170 err
= qemu_strtoul(str
, &endptr
, 0, &res
);
1172 g_assert_cmpint(err
, ==, 0);
1173 g_assert_cmpuint(res
, ==, 123);
1174 g_assert(endptr
== str
+ 3);
1177 static void test_qemu_strtoul_octal(void)
1179 const char *str
= "0123";
1181 const char *endptr
= &f
;
1182 unsigned long res
= 999;
1185 err
= qemu_strtoul(str
, &endptr
, 8, &res
);
1187 g_assert_cmpint(err
, ==, 0);
1188 g_assert_cmpuint(res
, ==, 0123);
1189 g_assert(endptr
== str
+ strlen(str
));
1193 err
= qemu_strtoul(str
, &endptr
, 0, &res
);
1195 g_assert_cmpint(err
, ==, 0);
1196 g_assert_cmpuint(res
, ==, 0123);
1197 g_assert(endptr
== str
+ strlen(str
));
1200 static void test_qemu_strtoul_decimal(void)
1202 const char *str
= "0123";
1204 const char *endptr
= &f
;
1205 unsigned long res
= 999;
1208 err
= qemu_strtoul(str
, &endptr
, 10, &res
);
1210 g_assert_cmpint(err
, ==, 0);
1211 g_assert_cmpuint(res
, ==, 123);
1212 g_assert(endptr
== str
+ strlen(str
));
1217 err
= qemu_strtoul(str
, &endptr
, 0, &res
);
1219 g_assert_cmpint(err
, ==, 0);
1220 g_assert_cmpuint(res
, ==, 123);
1221 g_assert(endptr
== str
+ strlen(str
));
1224 static void test_qemu_strtoul_hex(void)
1226 const char *str
= "0123";
1228 const char *endptr
= &f
;
1229 unsigned long res
= 999;
1232 err
= qemu_strtoul(str
, &endptr
, 16, &res
);
1234 g_assert_cmpint(err
, ==, 0);
1235 g_assert_cmphex(res
, ==, 0x123);
1236 g_assert(endptr
== str
+ strlen(str
));
1241 err
= qemu_strtoul(str
, &endptr
, 0, &res
);
1243 g_assert_cmpint(err
, ==, 0);
1244 g_assert_cmphex(res
, ==, 0x123);
1245 g_assert(endptr
== str
+ strlen(str
));
1248 static void test_qemu_strtoul_max(void)
1250 char *str
= g_strdup_printf("%lu", ULONG_MAX
);
1252 const char *endptr
= &f
;
1253 unsigned long res
= 999;
1256 err
= qemu_strtoul(str
, &endptr
, 0, &res
);
1258 g_assert_cmpint(err
, ==, 0);
1259 g_assert_cmphex(res
, ==, ULONG_MAX
);
1260 g_assert(endptr
== str
+ strlen(str
));
1264 static void test_qemu_strtoul_overflow(void)
1266 const char *str
= "99999999999999999999999999999999999999999999";
1268 const char *endptr
= &f
;
1269 unsigned long res
= 999;
1272 err
= qemu_strtoul(str
, &endptr
, 0, &res
);
1274 g_assert_cmpint(err
, ==, -ERANGE
);
1275 g_assert_cmphex(res
, ==, ULONG_MAX
);
1276 g_assert(endptr
== str
+ strlen(str
));
1279 static void test_qemu_strtoul_underflow(void)
1281 const char *str
= "-99999999999999999999999999999999999999999999";
1283 const char *endptr
= &f
;
1284 unsigned long res
= 999;
1287 err
= qemu_strtoul(str
, &endptr
, 0, &res
);
1289 g_assert_cmpint(err
, ==, -ERANGE
);
1290 g_assert_cmpuint(res
, ==, -1ul);
1291 g_assert(endptr
== str
+ strlen(str
));
1294 static void test_qemu_strtoul_negative(void)
1296 const char *str
= " \t -321";
1298 const char *endptr
= &f
;
1299 unsigned long res
= 999;
1302 err
= qemu_strtoul(str
, &endptr
, 0, &res
);
1304 g_assert_cmpint(err
, ==, 0);
1305 g_assert_cmpuint(res
, ==, -321ul);
1306 g_assert(endptr
== str
+ strlen(str
));
1309 static void test_qemu_strtoul_full_correct(void)
1311 const char *str
= "123";
1312 unsigned long res
= 999;
1315 err
= qemu_strtoul(str
, NULL
, 0, &res
);
1317 g_assert_cmpint(err
, ==, 0);
1318 g_assert_cmpuint(res
, ==, 123);
1321 static void test_qemu_strtoul_full_null(void)
1323 unsigned long res
= 999;
1326 err
= qemu_strtoul(NULL
, NULL
, 0, &res
);
1328 g_assert_cmpint(err
, ==, -EINVAL
);
1331 static void test_qemu_strtoul_full_empty(void)
1333 const char *str
= "";
1334 unsigned long res
= 999;
1337 err
= qemu_strtoul(str
, NULL
, 0, &res
);
1339 g_assert_cmpint(err
, ==, -EINVAL
);
1341 static void test_qemu_strtoul_full_negative(void)
1343 const char *str
= " \t -321";
1344 unsigned long res
= 999;
1347 err
= qemu_strtoul(str
, NULL
, 0, &res
);
1348 g_assert_cmpint(err
, ==, 0);
1349 g_assert_cmpuint(res
, ==, -321ul);
1352 static void test_qemu_strtoul_full_trailing(void)
1354 const char *str
= "123xxx";
1358 err
= qemu_strtoul(str
, NULL
, 0, &res
);
1360 g_assert_cmpint(err
, ==, -EINVAL
);
1363 static void test_qemu_strtoul_full_max(void)
1365 char *str
= g_strdup_printf("%lu", ULONG_MAX
);
1366 unsigned long res
= 999;
1369 err
= qemu_strtoul(str
, NULL
, 0, &res
);
1371 g_assert_cmpint(err
, ==, 0);
1372 g_assert_cmphex(res
, ==, ULONG_MAX
);
1376 static void test_qemu_strtoi64_correct(void)
1378 const char *str
= "12345 foo";
1380 const char *endptr
= &f
;
1384 err
= qemu_strtoi64(str
, &endptr
, 0, &res
);
1386 g_assert_cmpint(err
, ==, 0);
1387 g_assert_cmpint(res
, ==, 12345);
1388 g_assert(endptr
== str
+ 5);
1391 static void test_qemu_strtoi64_null(void)
1394 const char *endptr
= &f
;
1398 err
= qemu_strtoi64(NULL
, &endptr
, 0, &res
);
1400 g_assert_cmpint(err
, ==, -EINVAL
);
1401 g_assert(endptr
== NULL
);
1404 static void test_qemu_strtoi64_empty(void)
1406 const char *str
= "";
1408 const char *endptr
= &f
;
1412 err
= qemu_strtoi64(str
, &endptr
, 0, &res
);
1414 g_assert_cmpint(err
, ==, -EINVAL
);
1415 g_assert(endptr
== str
);
1418 static void test_qemu_strtoi64_whitespace(void)
1420 const char *str
= " \t ";
1422 const char *endptr
= &f
;
1426 err
= qemu_strtoi64(str
, &endptr
, 0, &res
);
1428 g_assert_cmpint(err
, ==, -EINVAL
);
1429 g_assert(endptr
== str
);
1432 static void test_qemu_strtoi64_invalid(void)
1434 const char *str
= " xxxx \t abc";
1436 const char *endptr
= &f
;
1440 err
= qemu_strtoi64(str
, &endptr
, 0, &res
);
1442 g_assert_cmpint(err
, ==, -EINVAL
);
1443 g_assert(endptr
== str
);
1446 static void test_qemu_strtoi64_trailing(void)
1448 const char *str
= "123xxx";
1450 const char *endptr
= &f
;
1454 err
= qemu_strtoi64(str
, &endptr
, 0, &res
);
1456 g_assert_cmpint(err
, ==, 0);
1457 g_assert_cmpint(res
, ==, 123);
1458 g_assert(endptr
== str
+ 3);
1461 static void test_qemu_strtoi64_octal(void)
1463 const char *str
= "0123";
1465 const char *endptr
= &f
;
1469 err
= qemu_strtoi64(str
, &endptr
, 8, &res
);
1471 g_assert_cmpint(err
, ==, 0);
1472 g_assert_cmpint(res
, ==, 0123);
1473 g_assert(endptr
== str
+ strlen(str
));
1477 err
= qemu_strtoi64(str
, &endptr
, 0, &res
);
1479 g_assert_cmpint(err
, ==, 0);
1480 g_assert_cmpint(res
, ==, 0123);
1481 g_assert(endptr
== str
+ strlen(str
));
1484 static void test_qemu_strtoi64_decimal(void)
1486 const char *str
= "0123";
1488 const char *endptr
= &f
;
1492 err
= qemu_strtoi64(str
, &endptr
, 10, &res
);
1494 g_assert_cmpint(err
, ==, 0);
1495 g_assert_cmpint(res
, ==, 123);
1496 g_assert(endptr
== str
+ strlen(str
));
1501 err
= qemu_strtoi64(str
, &endptr
, 0, &res
);
1503 g_assert_cmpint(err
, ==, 0);
1504 g_assert_cmpint(res
, ==, 123);
1505 g_assert(endptr
== str
+ strlen(str
));
1508 static void test_qemu_strtoi64_hex(void)
1510 const char *str
= "0123";
1512 const char *endptr
= &f
;
1516 err
= qemu_strtoi64(str
, &endptr
, 16, &res
);
1518 g_assert_cmpint(err
, ==, 0);
1519 g_assert_cmpint(res
, ==, 0x123);
1520 g_assert(endptr
== str
+ strlen(str
));
1525 err
= qemu_strtoi64(str
, &endptr
, 0, &res
);
1527 g_assert_cmpint(err
, ==, 0);
1528 g_assert_cmpint(res
, ==, 0x123);
1529 g_assert(endptr
== str
+ strlen(str
));
1532 static void test_qemu_strtoi64_max(void)
1534 char *str
= g_strdup_printf("%lld", LLONG_MAX
);
1536 const char *endptr
= &f
;
1540 err
= qemu_strtoi64(str
, &endptr
, 0, &res
);
1542 g_assert_cmpint(err
, ==, 0);
1543 g_assert_cmpint(res
, ==, LLONG_MAX
);
1544 g_assert(endptr
== str
+ strlen(str
));
1548 static void test_qemu_strtoi64_overflow(void)
1550 const char *str
= "99999999999999999999999999999999999999999999";
1552 const char *endptr
= &f
;
1556 err
= qemu_strtoi64(str
, &endptr
, 0, &res
);
1558 g_assert_cmpint(err
, ==, -ERANGE
);
1559 g_assert_cmpint(res
, ==, LLONG_MAX
);
1560 g_assert(endptr
== str
+ strlen(str
));
1563 static void test_qemu_strtoi64_underflow(void)
1565 const char *str
= "-99999999999999999999999999999999999999999999";
1567 const char *endptr
= &f
;
1571 err
= qemu_strtoi64(str
, &endptr
, 0, &res
);
1573 g_assert_cmpint(err
, ==, -ERANGE
);
1574 g_assert_cmpint(res
, ==, LLONG_MIN
);
1575 g_assert(endptr
== str
+ strlen(str
));
1578 static void test_qemu_strtoi64_negative(void)
1580 const char *str
= " \t -321";
1582 const char *endptr
= &f
;
1586 err
= qemu_strtoi64(str
, &endptr
, 0, &res
);
1588 g_assert_cmpint(err
, ==, 0);
1589 g_assert_cmpint(res
, ==, -321);
1590 g_assert(endptr
== str
+ strlen(str
));
1593 static void test_qemu_strtoi64_full_correct(void)
1595 const char *str
= "123";
1599 err
= qemu_strtoi64(str
, NULL
, 0, &res
);
1601 g_assert_cmpint(err
, ==, 0);
1602 g_assert_cmpint(res
, ==, 123);
1605 static void test_qemu_strtoi64_full_null(void)
1610 err
= qemu_strtoi64(NULL
, NULL
, 0, &res
);
1612 g_assert_cmpint(err
, ==, -EINVAL
);
1615 static void test_qemu_strtoi64_full_empty(void)
1617 const char *str
= "";
1621 err
= qemu_strtoi64(str
, NULL
, 0, &res
);
1623 g_assert_cmpint(err
, ==, -EINVAL
);
1626 static void test_qemu_strtoi64_full_negative(void)
1628 const char *str
= " \t -321";
1632 err
= qemu_strtoi64(str
, NULL
, 0, &res
);
1634 g_assert_cmpint(err
, ==, 0);
1635 g_assert_cmpint(res
, ==, -321);
1638 static void test_qemu_strtoi64_full_trailing(void)
1640 const char *str
= "123xxx";
1644 err
= qemu_strtoi64(str
, NULL
, 0, &res
);
1646 g_assert_cmpint(err
, ==, -EINVAL
);
1649 static void test_qemu_strtoi64_full_max(void)
1652 char *str
= g_strdup_printf("%lld", LLONG_MAX
);
1656 err
= qemu_strtoi64(str
, NULL
, 0, &res
);
1658 g_assert_cmpint(err
, ==, 0);
1659 g_assert_cmpint(res
, ==, LLONG_MAX
);
1663 static void test_qemu_strtou64_correct(void)
1665 const char *str
= "12345 foo";
1667 const char *endptr
= &f
;
1671 err
= qemu_strtou64(str
, &endptr
, 0, &res
);
1673 g_assert_cmpint(err
, ==, 0);
1674 g_assert_cmpuint(res
, ==, 12345);
1675 g_assert(endptr
== str
+ 5);
1678 static void test_qemu_strtou64_null(void)
1681 const char *endptr
= &f
;
1685 err
= qemu_strtou64(NULL
, &endptr
, 0, &res
);
1687 g_assert_cmpint(err
, ==, -EINVAL
);
1688 g_assert(endptr
== NULL
);
1691 static void test_qemu_strtou64_empty(void)
1693 const char *str
= "";
1695 const char *endptr
= &f
;
1699 err
= qemu_strtou64(str
, &endptr
, 0, &res
);
1701 g_assert_cmpint(err
, ==, -EINVAL
);
1702 g_assert(endptr
== str
);
1705 static void test_qemu_strtou64_whitespace(void)
1707 const char *str
= " \t ";
1709 const char *endptr
= &f
;
1713 err
= qemu_strtou64(str
, &endptr
, 0, &res
);
1715 g_assert_cmpint(err
, ==, -EINVAL
);
1716 g_assert(endptr
== str
);
1719 static void test_qemu_strtou64_invalid(void)
1721 const char *str
= " xxxx \t abc";
1723 const char *endptr
= &f
;
1727 err
= qemu_strtou64(str
, &endptr
, 0, &res
);
1729 g_assert_cmpint(err
, ==, -EINVAL
);
1730 g_assert(endptr
== str
);
1733 static void test_qemu_strtou64_trailing(void)
1735 const char *str
= "123xxx";
1737 const char *endptr
= &f
;
1741 err
= qemu_strtou64(str
, &endptr
, 0, &res
);
1743 g_assert_cmpint(err
, ==, 0);
1744 g_assert_cmpuint(res
, ==, 123);
1745 g_assert(endptr
== str
+ 3);
1748 static void test_qemu_strtou64_octal(void)
1750 const char *str
= "0123";
1752 const char *endptr
= &f
;
1756 err
= qemu_strtou64(str
, &endptr
, 8, &res
);
1758 g_assert_cmpint(err
, ==, 0);
1759 g_assert_cmpuint(res
, ==, 0123);
1760 g_assert(endptr
== str
+ strlen(str
));
1764 err
= qemu_strtou64(str
, &endptr
, 0, &res
);
1766 g_assert_cmpint(err
, ==, 0);
1767 g_assert_cmpuint(res
, ==, 0123);
1768 g_assert(endptr
== str
+ strlen(str
));
1771 static void test_qemu_strtou64_decimal(void)
1773 const char *str
= "0123";
1775 const char *endptr
= &f
;
1779 err
= qemu_strtou64(str
, &endptr
, 10, &res
);
1781 g_assert_cmpint(err
, ==, 0);
1782 g_assert_cmpuint(res
, ==, 123);
1783 g_assert(endptr
== str
+ strlen(str
));
1788 err
= qemu_strtou64(str
, &endptr
, 0, &res
);
1790 g_assert_cmpint(err
, ==, 0);
1791 g_assert_cmpuint(res
, ==, 123);
1792 g_assert(endptr
== str
+ strlen(str
));
1795 static void test_qemu_strtou64_hex(void)
1797 const char *str
= "0123";
1799 const char *endptr
= &f
;
1803 err
= qemu_strtou64(str
, &endptr
, 16, &res
);
1805 g_assert_cmpint(err
, ==, 0);
1806 g_assert_cmphex(res
, ==, 0x123);
1807 g_assert(endptr
== str
+ strlen(str
));
1812 err
= qemu_strtou64(str
, &endptr
, 0, &res
);
1814 g_assert_cmpint(err
, ==, 0);
1815 g_assert_cmphex(res
, ==, 0x123);
1816 g_assert(endptr
== str
+ strlen(str
));
1819 static void test_qemu_strtou64_max(void)
1821 char *str
= g_strdup_printf("%llu", ULLONG_MAX
);
1823 const char *endptr
= &f
;
1827 err
= qemu_strtou64(str
, &endptr
, 0, &res
);
1829 g_assert_cmpint(err
, ==, 0);
1830 g_assert_cmphex(res
, ==, ULLONG_MAX
);
1831 g_assert(endptr
== str
+ strlen(str
));
1835 static void test_qemu_strtou64_overflow(void)
1837 const char *str
= "99999999999999999999999999999999999999999999";
1839 const char *endptr
= &f
;
1843 err
= qemu_strtou64(str
, &endptr
, 0, &res
);
1845 g_assert_cmpint(err
, ==, -ERANGE
);
1846 g_assert_cmphex(res
, ==, ULLONG_MAX
);
1847 g_assert(endptr
== str
+ strlen(str
));
1850 static void test_qemu_strtou64_underflow(void)
1852 const char *str
= "-99999999999999999999999999999999999999999999";
1854 const char *endptr
= &f
;
1858 err
= qemu_strtou64(str
, &endptr
, 0, &res
);
1860 g_assert_cmpint(err
, ==, -ERANGE
);
1861 g_assert_cmphex(res
, ==, -1ull);
1862 g_assert(endptr
== str
+ strlen(str
));
1865 static void test_qemu_strtou64_negative(void)
1867 const char *str
= " \t -321";
1869 const char *endptr
= &f
;
1873 err
= qemu_strtou64(str
, &endptr
, 0, &res
);
1875 g_assert_cmpint(err
, ==, 0);
1876 g_assert_cmpuint(res
, ==, -321ull);
1877 g_assert(endptr
== str
+ strlen(str
));
1880 static void test_qemu_strtou64_full_correct(void)
1882 const char *str
= "18446744073709551614";
1886 err
= qemu_strtou64(str
, NULL
, 0, &res
);
1888 g_assert_cmpint(err
, ==, 0);
1889 g_assert_cmpuint(res
, ==, 18446744073709551614ull);
1892 static void test_qemu_strtou64_full_null(void)
1897 err
= qemu_strtou64(NULL
, NULL
, 0, &res
);
1899 g_assert_cmpint(err
, ==, -EINVAL
);
1902 static void test_qemu_strtou64_full_empty(void)
1904 const char *str
= "";
1908 err
= qemu_strtou64(str
, NULL
, 0, &res
);
1910 g_assert_cmpint(err
, ==, -EINVAL
);
1913 static void test_qemu_strtou64_full_negative(void)
1915 const char *str
= " \t -321";
1919 err
= qemu_strtou64(str
, NULL
, 0, &res
);
1921 g_assert_cmpint(err
, ==, 0);
1922 g_assert_cmpuint(res
, ==, -321ull);
1925 static void test_qemu_strtou64_full_trailing(void)
1927 const char *str
= "18446744073709551614xxxxxx";
1931 err
= qemu_strtou64(str
, NULL
, 0, &res
);
1933 g_assert_cmpint(err
, ==, -EINVAL
);
1936 static void test_qemu_strtou64_full_max(void)
1938 char *str
= g_strdup_printf("%lld", ULLONG_MAX
);
1942 err
= qemu_strtou64(str
, NULL
, 0, &res
);
1944 g_assert_cmpint(err
, ==, 0);
1945 g_assert_cmphex(res
, ==, ULLONG_MAX
);
1949 static void test_qemu_strtosz_simple(void)
1952 char *endptr
= NULL
;
1954 uint64_t res
= 0xbaadf00d;
1957 err
= qemu_strtosz(str
, &endptr
, &res
);
1958 g_assert_cmpint(err
, ==, 0);
1959 g_assert_cmpint(res
, ==, 0);
1960 g_assert(endptr
== str
+ 1);
1963 err
= qemu_strtosz(str
, &endptr
, &res
);
1964 g_assert_cmpint(err
, ==, 0);
1965 g_assert_cmpint(res
, ==, 12345);
1966 g_assert(endptr
== str
+ 5);
1968 err
= qemu_strtosz(str
, NULL
, &res
);
1969 g_assert_cmpint(err
, ==, 0);
1970 g_assert_cmpint(res
, ==, 12345);
1972 /* Note: precision is 53 bits since we're parsing with strtod() */
1974 str
= "9007199254740991"; /* 2^53-1 */
1975 err
= qemu_strtosz(str
, &endptr
, &res
);
1976 g_assert_cmpint(err
, ==, 0);
1977 g_assert_cmpint(res
, ==, 0x1fffffffffffff);
1978 g_assert(endptr
== str
+ 16);
1980 str
= "9007199254740992"; /* 2^53 */
1981 err
= qemu_strtosz(str
, &endptr
, &res
);
1982 g_assert_cmpint(err
, ==, 0);
1983 g_assert_cmpint(res
, ==, 0x20000000000000);
1984 g_assert(endptr
== str
+ 16);
1986 str
= "9007199254740993"; /* 2^53+1 */
1987 err
= qemu_strtosz(str
, &endptr
, &res
);
1988 g_assert_cmpint(err
, ==, 0);
1989 g_assert_cmpint(res
, ==, 0x20000000000000); /* rounded to 53 bits */
1990 g_assert(endptr
== str
+ 16);
1992 str
= "18446744073709549568"; /* 0xfffffffffffff800 (53 msbs set) */
1993 err
= qemu_strtosz(str
, &endptr
, &res
);
1994 g_assert_cmpint(err
, ==, 0);
1995 g_assert_cmpint(res
, ==, 0xfffffffffffff800);
1996 g_assert(endptr
== str
+ 20);
1998 str
= "18446744073709550591"; /* 0xfffffffffffffbff */
1999 err
= qemu_strtosz(str
, &endptr
, &res
);
2000 g_assert_cmpint(err
, ==, 0);
2001 g_assert_cmpint(res
, ==, 0xfffffffffffff800); /* rounded to 53 bits */
2002 g_assert(endptr
== str
+ 20);
2004 /* 0x7ffffffffffffe00..0x7fffffffffffffff get rounded to
2005 * 0x8000000000000000, thus -ERANGE; see test_qemu_strtosz_erange() */
2008 static void test_qemu_strtosz_units(void)
2010 const char *none
= "1";
2011 const char *b
= "1B";
2012 const char *k
= "1K";
2013 const char *m
= "1M";
2014 const char *g
= "1G";
2015 const char *t
= "1T";
2016 const char *p
= "1P";
2017 const char *e
= "1E";
2019 char *endptr
= NULL
;
2020 uint64_t res
= 0xbaadf00d;
2023 err
= qemu_strtosz_MiB(none
, &endptr
, &res
);
2024 g_assert_cmpint(err
, ==, 0);
2025 g_assert_cmpint(res
, ==, M_BYTE
);
2026 g_assert(endptr
== none
+ 1);
2028 err
= qemu_strtosz(b
, &endptr
, &res
);
2029 g_assert_cmpint(err
, ==, 0);
2030 g_assert_cmpint(res
, ==, 1);
2031 g_assert(endptr
== b
+ 2);
2033 err
= qemu_strtosz(k
, &endptr
, &res
);
2034 g_assert_cmpint(err
, ==, 0);
2035 g_assert_cmpint(res
, ==, K_BYTE
);
2036 g_assert(endptr
== k
+ 2);
2038 err
= qemu_strtosz(m
, &endptr
, &res
);
2039 g_assert_cmpint(err
, ==, 0);
2040 g_assert_cmpint(res
, ==, M_BYTE
);
2041 g_assert(endptr
== m
+ 2);
2043 err
= qemu_strtosz(g
, &endptr
, &res
);
2044 g_assert_cmpint(err
, ==, 0);
2045 g_assert_cmpint(res
, ==, G_BYTE
);
2046 g_assert(endptr
== g
+ 2);
2048 err
= qemu_strtosz(t
, &endptr
, &res
);
2049 g_assert_cmpint(err
, ==, 0);
2050 g_assert_cmpint(res
, ==, T_BYTE
);
2051 g_assert(endptr
== t
+ 2);
2053 err
= qemu_strtosz(p
, &endptr
, &res
);
2054 g_assert_cmpint(err
, ==, 0);
2055 g_assert_cmpint(res
, ==, P_BYTE
);
2056 g_assert(endptr
== p
+ 2);
2058 err
= qemu_strtosz(e
, &endptr
, &res
);
2059 g_assert_cmpint(err
, ==, 0);
2060 g_assert_cmpint(res
, ==, E_BYTE
);
2061 g_assert(endptr
== e
+ 2);
2064 static void test_qemu_strtosz_float(void)
2066 const char *str
= "12.345M";
2068 char *endptr
= NULL
;
2069 uint64_t res
= 0xbaadf00d;
2071 err
= qemu_strtosz(str
, &endptr
, &res
);
2072 g_assert_cmpint(err
, ==, 0);
2073 g_assert_cmpint(res
, ==, 12.345 * M_BYTE
);
2074 g_assert(endptr
== str
+ 7);
2077 static void test_qemu_strtosz_invalid(void)
2080 char *endptr
= NULL
;
2082 uint64_t res
= 0xbaadf00d;
2085 err
= qemu_strtosz(str
, &endptr
, &res
);
2086 g_assert_cmpint(err
, ==, -EINVAL
);
2087 g_assert(endptr
== str
);
2090 err
= qemu_strtosz(str
, &endptr
, &res
);
2091 g_assert_cmpint(err
, ==, -EINVAL
);
2092 g_assert(endptr
== str
);
2095 err
= qemu_strtosz(str
, &endptr
, &res
);
2096 g_assert_cmpint(err
, ==, -EINVAL
);
2097 g_assert(endptr
== str
);
2100 static void test_qemu_strtosz_trailing(void)
2103 char *endptr
= NULL
;
2105 uint64_t res
= 0xbaadf00d;
2108 err
= qemu_strtosz_MiB(str
, &endptr
, &res
);
2109 g_assert_cmpint(res
, ==, 123 * M_BYTE
);
2110 g_assert(endptr
== str
+ 3);
2112 err
= qemu_strtosz(str
, NULL
, &res
);
2113 g_assert_cmpint(err
, ==, -EINVAL
);
2116 err
= qemu_strtosz(str
, &endptr
, &res
);
2117 g_assert_cmpint(err
, ==, 0);
2118 g_assert_cmpint(res
, ==, 1024);
2119 g_assert(endptr
== str
+ 2);
2121 err
= qemu_strtosz(str
, NULL
, &res
);
2122 g_assert_cmpint(err
, ==, -EINVAL
);
2125 static void test_qemu_strtosz_erange(void)
2128 char *endptr
= NULL
;
2130 uint64_t res
= 0xbaadf00d;
2133 err
= qemu_strtosz(str
, &endptr
, &res
);
2134 g_assert_cmpint(err
, ==, -ERANGE
);
2135 g_assert(endptr
== str
+ 2);
2137 str
= "18446744073709550592"; /* 0xfffffffffffffc00 */
2138 err
= qemu_strtosz(str
, &endptr
, &res
);
2139 g_assert_cmpint(err
, ==, -ERANGE
);
2140 g_assert(endptr
== str
+ 20);
2142 str
= "18446744073709551615"; /* 2^64-1 */
2143 err
= qemu_strtosz(str
, &endptr
, &res
);
2144 g_assert_cmpint(err
, ==, -ERANGE
);
2145 g_assert(endptr
== str
+ 20);
2147 str
= "18446744073709551616"; /* 2^64 */
2148 err
= qemu_strtosz(str
, &endptr
, &res
);
2149 g_assert_cmpint(err
, ==, -ERANGE
);
2150 g_assert(endptr
== str
+ 20);
2153 err
= qemu_strtosz(str
, &endptr
, &res
);
2154 g_assert_cmpint(err
, ==, -ERANGE
);
2155 g_assert(endptr
== str
+ 3);
2158 static void test_qemu_strtosz_metric(void)
2160 const char *str
= "12345k";
2162 char *endptr
= NULL
;
2163 uint64_t res
= 0xbaadf00d;
2165 err
= qemu_strtosz_metric(str
, &endptr
, &res
);
2166 g_assert_cmpint(err
, ==, 0);
2167 g_assert_cmpint(res
, ==, 12345000);
2168 g_assert(endptr
== str
+ 6);
2171 int main(int argc
, char **argv
)
2173 g_test_init(&argc
, &argv
, NULL
);
2175 g_test_add_func("/cutils/parse_uint/null", test_parse_uint_null
);
2176 g_test_add_func("/cutils/parse_uint/empty", test_parse_uint_empty
);
2177 g_test_add_func("/cutils/parse_uint/whitespace",
2178 test_parse_uint_whitespace
);
2179 g_test_add_func("/cutils/parse_uint/invalid", test_parse_uint_invalid
);
2180 g_test_add_func("/cutils/parse_uint/trailing", test_parse_uint_trailing
);
2181 g_test_add_func("/cutils/parse_uint/correct", test_parse_uint_correct
);
2182 g_test_add_func("/cutils/parse_uint/octal", test_parse_uint_octal
);
2183 g_test_add_func("/cutils/parse_uint/decimal", test_parse_uint_decimal
);
2184 g_test_add_func("/cutils/parse_uint/llong_max", test_parse_uint_llong_max
);
2185 g_test_add_func("/cutils/parse_uint/overflow", test_parse_uint_overflow
);
2186 g_test_add_func("/cutils/parse_uint/negative", test_parse_uint_negative
);
2187 g_test_add_func("/cutils/parse_uint_full/trailing",
2188 test_parse_uint_full_trailing
);
2189 g_test_add_func("/cutils/parse_uint_full/correct",
2190 test_parse_uint_full_correct
);
2192 /* qemu_strtoi() tests */
2193 g_test_add_func("/cutils/qemu_strtoi/correct",
2194 test_qemu_strtoi_correct
);
2195 g_test_add_func("/cutils/qemu_strtoi/null",
2196 test_qemu_strtoi_null
);
2197 g_test_add_func("/cutils/qemu_strtoi/empty",
2198 test_qemu_strtoi_empty
);
2199 g_test_add_func("/cutils/qemu_strtoi/whitespace",
2200 test_qemu_strtoi_whitespace
);
2201 g_test_add_func("/cutils/qemu_strtoi/invalid",
2202 test_qemu_strtoi_invalid
);
2203 g_test_add_func("/cutils/qemu_strtoi/trailing",
2204 test_qemu_strtoi_trailing
);
2205 g_test_add_func("/cutils/qemu_strtoi/octal",
2206 test_qemu_strtoi_octal
);
2207 g_test_add_func("/cutils/qemu_strtoi/decimal",
2208 test_qemu_strtoi_decimal
);
2209 g_test_add_func("/cutils/qemu_strtoi/hex",
2210 test_qemu_strtoi_hex
);
2211 g_test_add_func("/cutils/qemu_strtoi/max",
2212 test_qemu_strtoi_max
);
2213 g_test_add_func("/cutils/qemu_strtoi/overflow",
2214 test_qemu_strtoi_overflow
);
2215 g_test_add_func("/cutils/qemu_strtoi/underflow",
2216 test_qemu_strtoi_underflow
);
2217 g_test_add_func("/cutils/qemu_strtoi/negative",
2218 test_qemu_strtoi_negative
);
2219 g_test_add_func("/cutils/qemu_strtoi_full/correct",
2220 test_qemu_strtoi_full_correct
);
2221 g_test_add_func("/cutils/qemu_strtoi_full/null",
2222 test_qemu_strtoi_full_null
);
2223 g_test_add_func("/cutils/qemu_strtoi_full/empty",
2224 test_qemu_strtoi_full_empty
);
2225 g_test_add_func("/cutils/qemu_strtoi_full/negative",
2226 test_qemu_strtoi_full_negative
);
2227 g_test_add_func("/cutils/qemu_strtoi_full/trailing",
2228 test_qemu_strtoi_full_trailing
);
2229 g_test_add_func("/cutils/qemu_strtoi_full/max",
2230 test_qemu_strtoi_full_max
);
2232 /* qemu_strtoui() tests */
2233 g_test_add_func("/cutils/qemu_strtoui/correct",
2234 test_qemu_strtoui_correct
);
2235 g_test_add_func("/cutils/qemu_strtoui/null",
2236 test_qemu_strtoui_null
);
2237 g_test_add_func("/cutils/qemu_strtoui/empty",
2238 test_qemu_strtoui_empty
);
2239 g_test_add_func("/cutils/qemu_strtoui/whitespace",
2240 test_qemu_strtoui_whitespace
);
2241 g_test_add_func("/cutils/qemu_strtoui/invalid",
2242 test_qemu_strtoui_invalid
);
2243 g_test_add_func("/cutils/qemu_strtoui/trailing",
2244 test_qemu_strtoui_trailing
);
2245 g_test_add_func("/cutils/qemu_strtoui/octal",
2246 test_qemu_strtoui_octal
);
2247 g_test_add_func("/cutils/qemu_strtoui/decimal",
2248 test_qemu_strtoui_decimal
);
2249 g_test_add_func("/cutils/qemu_strtoui/hex",
2250 test_qemu_strtoui_hex
);
2251 g_test_add_func("/cutils/qemu_strtoui/max",
2252 test_qemu_strtoui_max
);
2253 g_test_add_func("/cutils/qemu_strtoui/overflow",
2254 test_qemu_strtoui_overflow
);
2255 g_test_add_func("/cutils/qemu_strtoui/underflow",
2256 test_qemu_strtoui_underflow
);
2257 g_test_add_func("/cutils/qemu_strtoui/negative",
2258 test_qemu_strtoui_negative
);
2259 g_test_add_func("/cutils/qemu_strtoui_full/correct",
2260 test_qemu_strtoui_full_correct
);
2261 g_test_add_func("/cutils/qemu_strtoui_full/null",
2262 test_qemu_strtoui_full_null
);
2263 g_test_add_func("/cutils/qemu_strtoui_full/empty",
2264 test_qemu_strtoui_full_empty
);
2265 g_test_add_func("/cutils/qemu_strtoui_full/negative",
2266 test_qemu_strtoui_full_negative
);
2267 g_test_add_func("/cutils/qemu_strtoui_full/trailing",
2268 test_qemu_strtoui_full_trailing
);
2269 g_test_add_func("/cutils/qemu_strtoui_full/max",
2270 test_qemu_strtoui_full_max
);
2272 /* qemu_strtol() tests */
2273 g_test_add_func("/cutils/qemu_strtol/correct",
2274 test_qemu_strtol_correct
);
2275 g_test_add_func("/cutils/qemu_strtol/null",
2276 test_qemu_strtol_null
);
2277 g_test_add_func("/cutils/qemu_strtol/empty",
2278 test_qemu_strtol_empty
);
2279 g_test_add_func("/cutils/qemu_strtol/whitespace",
2280 test_qemu_strtol_whitespace
);
2281 g_test_add_func("/cutils/qemu_strtol/invalid",
2282 test_qemu_strtol_invalid
);
2283 g_test_add_func("/cutils/qemu_strtol/trailing",
2284 test_qemu_strtol_trailing
);
2285 g_test_add_func("/cutils/qemu_strtol/octal",
2286 test_qemu_strtol_octal
);
2287 g_test_add_func("/cutils/qemu_strtol/decimal",
2288 test_qemu_strtol_decimal
);
2289 g_test_add_func("/cutils/qemu_strtol/hex",
2290 test_qemu_strtol_hex
);
2291 g_test_add_func("/cutils/qemu_strtol/max",
2292 test_qemu_strtol_max
);
2293 g_test_add_func("/cutils/qemu_strtol/overflow",
2294 test_qemu_strtol_overflow
);
2295 g_test_add_func("/cutils/qemu_strtol/underflow",
2296 test_qemu_strtol_underflow
);
2297 g_test_add_func("/cutils/qemu_strtol/negative",
2298 test_qemu_strtol_negative
);
2299 g_test_add_func("/cutils/qemu_strtol_full/correct",
2300 test_qemu_strtol_full_correct
);
2301 g_test_add_func("/cutils/qemu_strtol_full/null",
2302 test_qemu_strtol_full_null
);
2303 g_test_add_func("/cutils/qemu_strtol_full/empty",
2304 test_qemu_strtol_full_empty
);
2305 g_test_add_func("/cutils/qemu_strtol_full/negative",
2306 test_qemu_strtol_full_negative
);
2307 g_test_add_func("/cutils/qemu_strtol_full/trailing",
2308 test_qemu_strtol_full_trailing
);
2309 g_test_add_func("/cutils/qemu_strtol_full/max",
2310 test_qemu_strtol_full_max
);
2312 /* qemu_strtoul() tests */
2313 g_test_add_func("/cutils/qemu_strtoul/correct",
2314 test_qemu_strtoul_correct
);
2315 g_test_add_func("/cutils/qemu_strtoul/null",
2316 test_qemu_strtoul_null
);
2317 g_test_add_func("/cutils/qemu_strtoul/empty",
2318 test_qemu_strtoul_empty
);
2319 g_test_add_func("/cutils/qemu_strtoul/whitespace",
2320 test_qemu_strtoul_whitespace
);
2321 g_test_add_func("/cutils/qemu_strtoul/invalid",
2322 test_qemu_strtoul_invalid
);
2323 g_test_add_func("/cutils/qemu_strtoul/trailing",
2324 test_qemu_strtoul_trailing
);
2325 g_test_add_func("/cutils/qemu_strtoul/octal",
2326 test_qemu_strtoul_octal
);
2327 g_test_add_func("/cutils/qemu_strtoul/decimal",
2328 test_qemu_strtoul_decimal
);
2329 g_test_add_func("/cutils/qemu_strtoul/hex",
2330 test_qemu_strtoul_hex
);
2331 g_test_add_func("/cutils/qemu_strtoul/max",
2332 test_qemu_strtoul_max
);
2333 g_test_add_func("/cutils/qemu_strtoul/overflow",
2334 test_qemu_strtoul_overflow
);
2335 g_test_add_func("/cutils/qemu_strtoul/underflow",
2336 test_qemu_strtoul_underflow
);
2337 g_test_add_func("/cutils/qemu_strtoul/negative",
2338 test_qemu_strtoul_negative
);
2339 g_test_add_func("/cutils/qemu_strtoul_full/correct",
2340 test_qemu_strtoul_full_correct
);
2341 g_test_add_func("/cutils/qemu_strtoul_full/null",
2342 test_qemu_strtoul_full_null
);
2343 g_test_add_func("/cutils/qemu_strtoul_full/empty",
2344 test_qemu_strtoul_full_empty
);
2345 g_test_add_func("/cutils/qemu_strtoul_full/negative",
2346 test_qemu_strtoul_full_negative
);
2347 g_test_add_func("/cutils/qemu_strtoul_full/trailing",
2348 test_qemu_strtoul_full_trailing
);
2349 g_test_add_func("/cutils/qemu_strtoul_full/max",
2350 test_qemu_strtoul_full_max
);
2352 /* qemu_strtoi64() tests */
2353 g_test_add_func("/cutils/qemu_strtoi64/correct",
2354 test_qemu_strtoi64_correct
);
2355 g_test_add_func("/cutils/qemu_strtoi64/null",
2356 test_qemu_strtoi64_null
);
2357 g_test_add_func("/cutils/qemu_strtoi64/empty",
2358 test_qemu_strtoi64_empty
);
2359 g_test_add_func("/cutils/qemu_strtoi64/whitespace",
2360 test_qemu_strtoi64_whitespace
);
2361 g_test_add_func("/cutils/qemu_strtoi64/invalid"
2363 test_qemu_strtoi64_invalid
);
2364 g_test_add_func("/cutils/qemu_strtoi64/trailing",
2365 test_qemu_strtoi64_trailing
);
2366 g_test_add_func("/cutils/qemu_strtoi64/octal",
2367 test_qemu_strtoi64_octal
);
2368 g_test_add_func("/cutils/qemu_strtoi64/decimal",
2369 test_qemu_strtoi64_decimal
);
2370 g_test_add_func("/cutils/qemu_strtoi64/hex",
2371 test_qemu_strtoi64_hex
);
2372 g_test_add_func("/cutils/qemu_strtoi64/max",
2373 test_qemu_strtoi64_max
);
2374 g_test_add_func("/cutils/qemu_strtoi64/overflow",
2375 test_qemu_strtoi64_overflow
);
2376 g_test_add_func("/cutils/qemu_strtoi64/underflow",
2377 test_qemu_strtoi64_underflow
);
2378 g_test_add_func("/cutils/qemu_strtoi64/negative",
2379 test_qemu_strtoi64_negative
);
2380 g_test_add_func("/cutils/qemu_strtoi64_full/correct",
2381 test_qemu_strtoi64_full_correct
);
2382 g_test_add_func("/cutils/qemu_strtoi64_full/null",
2383 test_qemu_strtoi64_full_null
);
2384 g_test_add_func("/cutils/qemu_strtoi64_full/empty",
2385 test_qemu_strtoi64_full_empty
);
2386 g_test_add_func("/cutils/qemu_strtoi64_full/negative",
2387 test_qemu_strtoi64_full_negative
);
2388 g_test_add_func("/cutils/qemu_strtoi64_full/trailing",
2389 test_qemu_strtoi64_full_trailing
);
2390 g_test_add_func("/cutils/qemu_strtoi64_full/max",
2391 test_qemu_strtoi64_full_max
);
2393 /* qemu_strtou64() tests */
2394 g_test_add_func("/cutils/qemu_strtou64/correct",
2395 test_qemu_strtou64_correct
);
2396 g_test_add_func("/cutils/qemu_strtou64/null",
2397 test_qemu_strtou64_null
);
2398 g_test_add_func("/cutils/qemu_strtou64/empty",
2399 test_qemu_strtou64_empty
);
2400 g_test_add_func("/cutils/qemu_strtou64/whitespace",
2401 test_qemu_strtou64_whitespace
);
2402 g_test_add_func("/cutils/qemu_strtou64/invalid",
2403 test_qemu_strtou64_invalid
);
2404 g_test_add_func("/cutils/qemu_strtou64/trailing",
2405 test_qemu_strtou64_trailing
);
2406 g_test_add_func("/cutils/qemu_strtou64/octal",
2407 test_qemu_strtou64_octal
);
2408 g_test_add_func("/cutils/qemu_strtou64/decimal",
2409 test_qemu_strtou64_decimal
);
2410 g_test_add_func("/cutils/qemu_strtou64/hex",
2411 test_qemu_strtou64_hex
);
2412 g_test_add_func("/cutils/qemu_strtou64/max",
2413 test_qemu_strtou64_max
);
2414 g_test_add_func("/cutils/qemu_strtou64/overflow",
2415 test_qemu_strtou64_overflow
);
2416 g_test_add_func("/cutils/qemu_strtou64/underflow",
2417 test_qemu_strtou64_underflow
);
2418 g_test_add_func("/cutils/qemu_strtou64/negative",
2419 test_qemu_strtou64_negative
);
2420 g_test_add_func("/cutils/qemu_strtou64_full/correct",
2421 test_qemu_strtou64_full_correct
);
2422 g_test_add_func("/cutils/qemu_strtou64_full/null",
2423 test_qemu_strtou64_full_null
);
2424 g_test_add_func("/cutils/qemu_strtou64_full/empty",
2425 test_qemu_strtou64_full_empty
);
2426 g_test_add_func("/cutils/qemu_strtou64_full/negative",
2427 test_qemu_strtou64_full_negative
);
2428 g_test_add_func("/cutils/qemu_strtou64_full/trailing",
2429 test_qemu_strtou64_full_trailing
);
2430 g_test_add_func("/cutils/qemu_strtou64_full/max",
2431 test_qemu_strtou64_full_max
);
2433 g_test_add_func("/cutils/strtosz/simple",
2434 test_qemu_strtosz_simple
);
2435 g_test_add_func("/cutils/strtosz/units",
2436 test_qemu_strtosz_units
);
2437 g_test_add_func("/cutils/strtosz/float",
2438 test_qemu_strtosz_float
);
2439 g_test_add_func("/cutils/strtosz/invalid",
2440 test_qemu_strtosz_invalid
);
2441 g_test_add_func("/cutils/strtosz/trailing",
2442 test_qemu_strtosz_trailing
);
2443 g_test_add_func("/cutils/strtosz/erange",
2444 test_qemu_strtosz_erange
);
2445 g_test_add_func("/cutils/strtosz/metric",
2446 test_qemu_strtosz_metric
);
2448 return g_test_run();